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

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
wdalmut committed Jun 28, 2012
Show file tree
Hide file tree
Showing 10 changed files with 220 additions and 230 deletions.
2 changes: 1 addition & 1 deletion src/Helper/HeadLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public function itemToString(\stdClass $item)
}
}

if ($this->view instanceof \Zend\Loader\Pluggable) {
if (method_exists($this->view, 'plugin')) {
$link .= ($this->view->plugin('doctype')->isXhtml()) ? '/>' : '>';
} else {
$link .= '/>';
Expand Down
2 changes: 1 addition & 1 deletion src/Helper/HeadMeta.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public function itemToString(\stdClass $item)
$modifiersString .= $key . '="' . $this->_escape($value) . '" ';
}

if ($this->view instanceof \Zend\Loader\Pluggable) {
if (method_exists($this->view, 'plugin')) {
if ($this->view->plugin('doctype')->isHtml5()
&& $type == 'charset'
) {
Expand Down
71 changes: 27 additions & 44 deletions src/Helper/Navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

namespace Zend\View\Helper;

use Zend\Loader\ShortNameLocator;
use Zend\Loader\PluginClassLoader;
use Zend\Navigation\AbstractContainer;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\View\Helper\Navigation\AbstractHelper as AbstractNavigationHelper;
Expand All @@ -48,9 +46,9 @@ class Navigation extends AbstractNavigationHelper
const NS = 'Zend\View\Helper\Navigation';

/**
* @var ShortNameLocator
* @var Navigation\PluginManager
*/
protected $loader;
protected $plugins;

/**
* Default proxy to use in {@link render()}
Expand All @@ -60,11 +58,11 @@ class Navigation extends AbstractNavigationHelper
protected $defaultProxy = 'menu';

/**
* Contains references to proxied helpers
* Indicates whether or not a given helper has been injected
*
* @var array
*/
protected $helpers = array();
protected $injected = array();

/**
* Whether container should be injected when proxying
Expand Down Expand Up @@ -143,14 +141,18 @@ public function __call($method, array $arguments = array())
}

/**
* Set plugin loader for retrieving navigation helpers
* Set manager for retrieving navigation helpers
*
* @param ShortNameLocator $loader
* @param Navigation\PluginManager $plugins
* @return Navigation
*/
public function setPluginLoader(ShortNameLocator $loader)
public function setPluginManager(Navigation\PluginManager $plugins)
{
$this->loader = $loader;
$renderer = $this->getView();
if ($renderer) {
$plugins->setRenderer($renderer);
}
$this->plugins = $plugins;
return $this;
}

Expand All @@ -162,12 +164,12 @@ public function setPluginLoader(ShortNameLocator $loader)
*
* @return ShortNameLocator
*/
public function getPluginLoader()
public function getPluginManager()
{
if (null === $this->loader) {
$this->setPluginLoader(new Navigation\HelperLoader());
if (null === $this->plugins) {
$this->setPluginManager(new Navigation\PluginManager());
}
return $this->loader;
return $this->plugins;
}

/**
Expand All @@ -189,44 +191,25 @@ public function getPluginLoader()
*/
public function findHelper($proxy, $strict = true)
{
if (isset($this->helpers[$proxy])) {
return $this->helpers[$proxy];
}

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

if ($strict && !$class) {
throw new Exception\RuntimeException(sprintf(
'Failed to find plugin for %s',
$proxy
));
}

if (!class_exists($class)) {
$plugins = $this->getPluginManager();
if (!$plugins->has($proxy)) {
if ($strict) {
throw new Exception\RuntimeException('Failed to find a class to proxy to');
throw new Exception\RuntimeException(sprintf(
'Failed to find plugin for %s',
$proxy
));
}
return false;
}
$helper = new $class();

if (!$helper instanceof AbstractNavigationHelper) {
if ($strict) {
throw new Exception\InvalidArgumentException(sprintf(
'Proxy helper "%s" is not an instance of ' .
'Zend\View\Helper\Navigation\Helper',
get_class($helper)
));
}
$helper = $plugins->get($proxy);
$class = get_class($helper);

return null;
if (!isset($this->injected[$class])) {
$this->_inject($helper);
$this->injected[$class] = true;
}

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

return $helper;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,56 @@

namespace Zend\View\Helper\Navigation;

use Zend\Loader\PluginClassLoader;
use Zend\View\Exception;
use Zend\View\HelperPluginManager;

/**
* Plugin map for navigation helpers
* Plugin manager implementation for navigation helpers
*
* Enforces that helpers retrieved are instances of
* Navigation\HelperInterface. Additionally, it registers a number of default
* helpers.
*
* @category Zend
* @package Zend_View
* @subpackage Helper
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class HelperLoader extends PluginClassLoader
class PluginManager extends HelperPluginManager
{
protected $plugins = array(
/**
* Default set of helpers
*
* @var array
*/
protected $invokableClasses = array(
'breadcrumbs' => 'Zend\View\Helper\Navigation\Breadcrumbs',
'links' => 'Zend\View\Helper\Navigation\Links',
'menu' => 'Zend\View\Helper\Navigation\Menu',
'sitemap' => 'Zend\View\Helper\Navigation\Sitemap',
);

/**
* Validate the plugin
*
* Checks that the helper loaded is an instance of AbstractHelper.
*
* @param mixed $plugin
* @return void
* @throws Exception\InvalidArgumentException if invalid
*/
public function validatePlugin($plugin)
{
if ($plugin instanceof AbstractHelper) {
// we're okay
return;
}

throw new Exception\InvalidArgumentException(sprintf(
'Plugin of type %s is invalid; must implement %s\AbstractHelper',
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
__NAMESPACE__
));
}
}
104 changes: 0 additions & 104 deletions src/HelperBroker.php

This file was deleted.

Loading

0 comments on commit 3a4b62c

Please sign in to comment.