View Source

<ac:macro ac:name="unmigrated-inline-wiki-markup"><ac:plain-text-body><![CDATA[{zone-template-instance:ZFPROP:Proposal Zone Template}

{zone-data:component-name}
Zend_View_Helper_Abstract
{zone-data}

{zone-data:proposer-list}
[Jurriƫn Stutterheim|mailto:j.stutterheim@hccnet.nl]
{zone-data}

{zone-data:liaison}
[~matthew]
{zone-data}

{zone-data:revision}
1.0 - 11 June 2008: Initial Draft.
1.1 - 05 Aug 2008: Addition of direct() method.
{zone-data}

{zone-data:overview}
Zend_View_Helper_Abstract is a very simple abstract class for view helpers. It provides the setView() method and the public $view attribute. At the moment these two are being copy/pasted in every view helper that needs it. Most helpers however can just as easily take this abstract class as parent to save duplicate code.

Additionally a Zend_View_Helper_Interface could be added. It would contain the signature for the setView() method. This would allow for more complex view helpers, like HeadTitle, which already inherit from another class to be identified as well.

Finally, a long-term goal for view helpers is to remove the tedious and difficult to understand naming of the helper method and instead implement the strategy pattern: all helpers would use the same method name. This would simplify implementation of calling helpers within Zend_View, and make it easier to visually identify the method that does the helper work. The proposal is to use the method name 'direct', which is already currently used in action helpers and is a fairly standard name for use with the strategy pattern. In the short term, it would go un-used, but would be available for future compatibility.
{zone-data}

{zone-data:references}
* [Zym_View_Helper_Abstract|http://trac2.assembla.com/zym/browser/trunk/library/Zym/View/Helper/Abstract.php]
* [Matthew's post about naming and PHP 5.3|http://weierophinney.net/matthew/archives/181-Migrating-OOP-Libraries-and-Frameworks-to-PHP-5.3.html]
{zone-data}

{zone-data:requirements}
* This component *will* provide the basic setView() implementation for view helpers
* This component *will* provide an interface with a setView() signature
* This component *will* provide an interface with a direct() signature
* This component *will not* implement any functionality around direct() at this time.
{zone-data}

{zone-data:dependencies}
{zone-data}

{zone-data:operation}
{zone-data}

{zone-data:milestones}
* Milestone 1: \[DONE\] Prototype available
* Milestone 2: \[DONE\] Unit tests available
* Milestone 3: \[DONE\] Component checked into incubator
* Milestone 4: \[DONE\] View helper documentation is updated
* Milestone 5: \[DONE\] Component checked into core
* Milestone 6: \[DONE\] Update the existing helpers to utilize these classes.
{zone-data}

{zone-data:class-list}
* Zend_View_Helper_Abstract
* Zend_View_Helper_Interface

These classes should get another name, because of ZF's future adoptation of PHP 5.3 namespaces. See the link to Matthew's blog post in the references section. Suggestions:

* Interface:
** Zend::View::Helper::IHelper
** Zend::View::Helper::Helper
* Abstract:
** Zend::View::Helper::HelperAbstract
** Zend::View::Helper::Base
{zone-data}

{zone-data:use-cases}
||UC-01||
{code}
class Zend_View_Helper_Form { .. }
{code}
Would become:
{code}
class Zend_View_Helper_Form extends Zend_View_Helper_Abstract { .. }
{code}
This allows:
{code}
/**
* @var Zend_View_Instance
*/
public $view;

/**
* Set view object
*
* @param Zend_View_Interface $view
* @return Zend_View_Helper_Form
*/
public function setView(Zend_View_Interface $view)
{
$this->view = $view;
return $this;
}
{code}
To be removed from the Form helper

||UC-02||
{code}
abstract class Zend_View_Helper_Placeholder_Container_Standalone implements IteratorAggregate, Countable, ArrayAccess { }
{code}
Could become:
{code}
abstract class Zend_View_Helper_Placeholder_Container_Standalone extends Zend_View_Helper_Abstract implements IteratorAggregate, Countable, ArrayAccess { }
{code}

||UC-03||
Currently helpers are checked if they have setView like so:
{code}
if (method_exists($store[$name], 'setView')) {
$store[$name]->setView($this);
}
{code}
This can be done much nicer now:
{code}
if ($store[$name] instanceof Zend_View_Helper_Interface) {
$store[$name]->setView($this);
}
{code}
Additionally, eventually instead of creating a formatted version of the helper method name, we will simply be able to call direct:
{code}
return call_user_func_array(array($store[$name], 'direct'), $args)
{code}
{zone-data}

{zone-data:skeletons}
{code}
interface Zend_View_Helper_Interface
{
public function setView(Zend_View_Interface $view);
public function direct();
}
{code}
{code}
abstract class Zend_View_Helper_Abstract implements Zend_View_Helper_Interface
{
public $view;

public function setView(Zend_View_Interface $view)
{
$this->view = $view;
return $this;
}

public function direct()
{
}
}
{code}
{zone-data}

{zone-template-instance}]]></ac:plain-text-body></ac:macro>