Skip to content
This repository has been archived by the owner on Jan 31, 2020. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'SpiffyJr/feature/navigation-service-fac…
Browse files Browse the repository at this point in the history
…tory'
  • Loading branch information
EvanDotPro committed Jun 2, 2012
3 parents 4444c37 + d157fcb + 4e07682 commit 192d20c
Show file tree
Hide file tree
Showing 15 changed files with 299 additions and 284 deletions.
80 changes: 43 additions & 37 deletions src/Helper/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@

namespace Zend\View\Helper;

use Zend\Loader\ShortNameLocator,
Zend\Loader\PluginClassLoader,
Zend\Navigation\Container,
Zend\View\Helper\Navigation\AbstractHelper as AbstractNavigationHelper,
Zend\View\Helper\Navigation\HelperInterface as NavigationHelper,
Zend\View\Exception;
use Zend\Loader\ShortNameLocator;
use Zend\Loader\PluginClassLoader;
use Zend\Navigation\AbstractContainer;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\View\Helper\Navigation\AbstractHelper as AbstractNavigationHelper;
use Zend\View\Helper\Navigation\HelperInterface as NavigationHelper;
use Zend\View\Exception;

/**
* Proxy helper for retrieving navigational helpers and forwarding calls
Expand Down Expand Up @@ -56,45 +57,43 @@ class Navigation extends AbstractNavigationHelper
*
* @var string
*/
protected $_defaultProxy = 'menu';
protected $defaultProxy = 'menu';

/**
* Contains references to proxied helpers
*
* @var array
*/
protected $_helpers = array();
protected $helpers = array();

/**
* Whether container should be injected when proxying
*
* @var bool
*/
protected $_injectContainer = true;
protected $injectContainer = true;

/**
* Whether ACL should be injected when proxying
*
* @var bool
*/
protected $_injectAcl = true;
protected $injectAcl = true;

/**
* Whether translator should be injected when proxying
*
* @var bool
*/
protected $_injectTranslator = true;
protected $injectTranslator = true;

/**
* Helper entry point
*
* @param \Zend\Navigation\Container $container [optional] container to
* operate on
* @return \Zend\View\Helper\Navigation fluent interface, returns
* self
* @param string|AbstractContainer $container container to operate on
* @return Navigation
*/
public function __invoke(Container $container = null)
public function __invoke($container = null)
{
if (null !== $container) {
$this->setContainer($container);
Expand Down Expand Up @@ -133,6 +132,9 @@ public function __call($method, array $arguments = array())
// check if call should proxy to another helper
$helper = $this->findHelper($method, false);
if ($helper) {
if ($helper instanceof ServiceLocatorAwareInterface && $this->getServiceLocator()) {
$helper->setServiceLocator($this->getServiceLocator());
}
return call_user_func_array($helper, $arguments);
}

Expand Down Expand Up @@ -187,22 +189,26 @@ public function getPluginLoader()
*/
public function findHelper($proxy, $strict = true)
{
if (isset($this->_helpers[$proxy])) {
return $this->_helpers[$proxy];
if (isset($this->helpers[$proxy])) {
return $this->helpers[$proxy];
}

$loader = $this->getPluginLoader();
$class = $loader->load($proxy);

if ($strict) {
$class = $loader->load($proxy);
} else {
try {
$class = $loader->load($proxy);
} catch (\Zend\Loader\Exception $e) {
return null;
}
if ($strict && !$class) {
throw new Exception\RuntimeException(sprintf(
'Failed to find plugin for %s',
$proxy
));
}

if (!class_exists($class)) {
if ($strict) {
throw new Exception\RuntimeException('Failed to find a class to proxy to');
}
return false;
}
$helper = new $class();

if (!$helper instanceof AbstractNavigationHelper) {
Expand All @@ -219,7 +225,7 @@ public function findHelper($proxy, $strict = true)

$helper->setView($this->view);
$this->_inject($helper);
$this->_helpers[$proxy] = $helper;
$this->helpers[$proxy] = $helper;

return $helper;
}
Expand Down Expand Up @@ -261,7 +267,7 @@ protected function _inject(NavigationHelper $helper)
*/
public function setDefaultProxy($proxy)
{
$this->_defaultProxy = (string) $proxy;
$this->defaultProxy = (string) $proxy;
return $this;
}

Expand All @@ -272,7 +278,7 @@ public function setDefaultProxy($proxy)
*/
public function getDefaultProxy()
{
return $this->_defaultProxy;
return $this->defaultProxy;
}

/**
Expand All @@ -285,7 +291,7 @@ public function getDefaultProxy()
*/
public function setInjectContainer($injectContainer = true)
{
$this->_injectContainer = (bool) $injectContainer;
$this->injectContainer = (bool) $injectContainer;
return $this;
}

Expand All @@ -296,7 +302,7 @@ public function setInjectContainer($injectContainer = true)
*/
public function getInjectContainer()
{
return $this->_injectContainer;
return $this->injectContainer;
}

/**
Expand All @@ -309,7 +315,7 @@ public function getInjectContainer()
*/
public function setInjectAcl($injectAcl = true)
{
$this->_injectAcl = (bool) $injectAcl;
$this->injectAcl = (bool) $injectAcl;
return $this;
}

Expand All @@ -320,7 +326,7 @@ public function setInjectAcl($injectAcl = true)
*/
public function getInjectAcl()
{
return $this->_injectAcl;
return $this->injectAcl;
}

/**
Expand All @@ -333,7 +339,7 @@ public function getInjectAcl()
*/
public function setInjectTranslator($injectTranslator = true)
{
$this->_injectTranslator = (bool) $injectTranslator;
$this->injectTranslator = (bool) $injectTranslator;
return $this;
}

Expand All @@ -344,15 +350,15 @@ public function setInjectTranslator($injectTranslator = true)
*/
public function getInjectTranslator()
{
return $this->_injectTranslator;
return $this->injectTranslator;
}

// Zend\View\Helper\Navigation\Helper:

/**
* Renders helper
*
* @param \Zend\Navigation\Container $container [optional] container to
* @param \Zend\Navigation\AbstractContainer $container [optional] container to
* render. Default is to
* render the container
* registered in the helper.
Expand All @@ -362,7 +368,7 @@ public function getInjectTranslator()
* the interface specified in
* {@link findHelper()}
*/
public function render(Container $container = null)
public function render($container = null)
{
$helper = $this->findHelper($this->getDefaultProxy());
return $helper->render($container);
Expand Down
Loading

0 comments on commit 192d20c

Please sign in to comment.