Skip to content
This repository has been archived by the owner on Jan 30, 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
thomasweidner committed Jun 26, 2011
7 parents 39b19e2 + 26666c9 + c993e85 + 4e037a4 + 965637a + 64de913 + b400e6b commit 526722c
Show file tree
Hide file tree
Showing 12 changed files with 63 additions and 547 deletions.
3 changes: 2 additions & 1 deletion src/AutoloaderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ public static function factory($options)

foreach ($options as $class => $opts) {
if (!class_exists($class)) {
if (!self::getStandardAutoloader()->autoload($class)) {
$autoloader = self::getStandardAutoloader();
if (!class_exists($class) && !$autoloader->autoload($class)) {
require_once 'Exception/InvalidArgumentException.php';
throw new Exception\InvalidArgumentException(sprintf('Autoloader class "%s" not loaded', $class));
}
Expand Down
6 changes: 3 additions & 3 deletions src/Broker.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ public function unregister($name);
/**
* Set class loader to use when resolving plugin names to classes
*
* @param ShortNameLocater $loader
* @param ShortNameLocator $loader
* @return void
*/
public function setClassLoader(ShortNameLocater $loader);
public function setClassLoader(ShortNameLocator $loader);

/**
* Retrieve the plugin class loader
*
* @return ShortNameLocater
* @return ShortNameLocator
*/
public function getClassLoader();
}
12 changes: 6 additions & 6 deletions src/PluginBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class PluginBroker implements Broker
protected $defaultClassLoader = 'Zend\Loader\PluginClassLoader';

/**
* @var ShortNameLocater Plugin class loader used by this instance
* @var ShortNameLocator Plugin class loader used by this instance
*/
protected $classLoader;

Expand Down Expand Up @@ -96,7 +96,7 @@ public function setOptions($options)
}
$value = new $value;
}
if ($value instanceof ShortNameLocater) {
if ($value instanceof ShortNameLocator) {
$this->setClassLoader($value);
break;
}
Expand Down Expand Up @@ -256,10 +256,10 @@ public function unregister($name)
/**
* Set class loader to use when resolving plugin names to class names
*
* @param ShortNameLocater $loader
* @param ShortNameLocator $loader
* @return PluginBroker
*/
public function setClassLoader(ShortNameLocater $loader)
public function setClassLoader(ShortNameLocator $loader)
{
$this->classLoader = $loader;
return $this;
Expand All @@ -268,9 +268,9 @@ public function setClassLoader(ShortNameLocater $loader)
/**
* Retrieve the class loader
*
* Lazy-loads an instance of PluginClassLocater if no loader is registered.
* Lazy-loads an instance of PluginClassLocator if no loader is registered.
*
* @return ShortNameLocater
* @return ShortNameLocator
*/
public function getClassLoader()
{
Expand Down
6 changes: 3 additions & 3 deletions src/PluginClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
Traversable;

/**
* Plugin class locater interface
* Plugin class locator interface
*
* @category Zend
* @package Zend_Loader
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class PluginClassLoader implements PluginClassLocater
class PluginClassLoader implements PluginClassLocator
{
/**
* List of plugin name => class name pairs
Expand Down Expand Up @@ -109,7 +109,7 @@ public function registerPlugin($shortName, $className)
* Register many plugins at once
*
* If $map is a string, assumes that the map is the class name of a
* Traversable object (likely a ShortNameLocater); it will then instantiate
* Traversable object (likely a ShortNameLocator); it will then instantiate
* this class and use it to register plugins.
*
* If $map is an array or Traversable object, it will iterate it to
Expand Down
6 changes: 3 additions & 3 deletions src/PluginClassLocater.php → src/PluginClassLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@
namespace Zend\Loader;

/**
* Plugin class locater interface
* Plugin class locator interface
*
* @category Zend
* @package Zend_Loader
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface PluginClassLocater extends ShortNameLocater, \IteratorAggregate
interface PluginClassLocator extends ShortNameLocator, \IteratorAggregate
{
/**
* Register a class to a given short name
*
* @param string $shortName
* @param string $className
* @return PluginClassLocater
* @return PluginClassLocator
*/
public function registerPlugin($shortName, $className);

Expand Down
2 changes: 1 addition & 1 deletion src/PrefixPathLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
class PrefixPathLoader implements ShortNameLocater, PrefixPathMapper
class PrefixPathLoader implements ShortNameLocator, PrefixPathMapper
{
/**
* Map of class names to files
Expand Down
2 changes: 1 addition & 1 deletion src/PrefixPathMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface PrefixPathMapper extends ShortNameLocater
interface PrefixPathMapper extends ShortNameLocator
{
/**
* Add prefixed paths to the registry of paths
Expand Down
36 changes: 22 additions & 14 deletions src/ResourceAutoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ResourceAutoloader implements SplAutoloader
* Constructor
*
* @param array|Traversable $options Configuration options for resource autoloader
* @throws Exception\InvalidArgumentException
* @return void
*/
public function __construct($options = null)
Expand Down Expand Up @@ -102,23 +103,24 @@ public function __construct($options = null)
* @param string $method
* @param array $args
* @return mixed
* @throws Zend_Loader_Exception if method not beginning with 'get' or not matching a valid resource type is called
* @throws Exception\InvalidArgumentException if method not beginning with 'get' or not matching a valid resource type is called
* @throws Exception\BadMethodCallException
*/
public function __call($method, $args)
{
if ('get' == substr($method, 0, 3)) {
$type = strtolower(substr($method, 3));
if (!$this->hasResourceType($type)) {
throw new InvalidArgumentException("Invalid resource type $type; cannot load resource");
throw new Exception\InvalidArgumentException("Invalid resource type $type; cannot load resource");
}
if (empty($args)) {
throw new InvalidArgumentException("Cannot load resources; no resource specified");
throw new Exception\InvalidArgumentException("Cannot load resources; no resource specified");
}
$resource = array_shift($args);
return $this->load($resource, $type);
}

throw new BadMethodCallException("Method '$method' is not supported");
throw new Exception\BadMethodCallException("Method '$method' is not supported");
}

/**
Expand All @@ -130,7 +132,9 @@ public function __call($method, $args)
public function getClassPath($class)
{
if (null !== $this->getNamespace()) {
return $this->getNamespacedClassPath($class);
if (false !== ($path = $this->getNamespacedClassPath($class))) {
return $path;
}
}
return $this->getPrefixedClassPath($class);
}
Expand Down Expand Up @@ -268,7 +272,8 @@ public function register()
* Set class state from options
*
* @param array $options
* @return Zend_Loader_Autoloader_Resource
* @throws Exception\InvalidArgumentExceptions
* @return \Zend\Loader\Autoloader\Resource
*/
public function setOptions($options)
{
Expand Down Expand Up @@ -370,14 +375,16 @@ public function getBasePath()
* @param string $type identifier for the resource type being loaded
* @param string $path path relative to resource base path containing the resource types
* @param null|string $namespace sub-component namespace to append to base namespace that qualifies this resource type
* @throws Exception\MissingResourceNamespaceException
* @throws Exception\InvalidPathException
* @return Zend_Loader_Autoloader_Resource
*/
public function addResourceType($type, $path, $namespace = null)
{
$type = strtolower($type);
if (!isset($this->_resourceTypes[$type])) {
if (null === $namespace) {
throw new MissingResourceNamespaceException('Initial definition of a resource type must include a namespace');
throw new Exception\MissingResourceNamespaceException('Initial definition of a resource type must include a namespace');
}
if (null !== $this->getNamespace()) {
$this->_addNamespaceResource($type, $namespace);
Expand All @@ -386,7 +393,7 @@ public function addResourceType($type, $path, $namespace = null)
}
}
if (!is_string($path)) {
throw new InvalidPathException('Invalid path specification provided; must be string');
throw new Exception\InvalidPathException('Invalid path specification provided; must be string');
}
$this->_resourceTypes[$type]['path'] = $this->getBasePath() . '/' . rtrim($path, '\/');

Expand Down Expand Up @@ -451,16 +458,17 @@ protected function _addPrefixResource($type, $prefix)
* </code>
*
* @param array $types
* @return Zend_Loader_Autoloader_Resource
* @throws Exception\InvalidArgumentException
* @return \Zend\Loader\Autoloader\Resource
*/
public function addResourceTypes(array $types)
{
foreach ($types as $type => $spec) {
if (!is_array($spec)) {
throw new InvalidArgumentException('addResourceTypes() expects an array of arrays');
throw new Exception\InvalidArgumentException('addResourceTypes() expects an array of arrays');
}
if (!isset($spec['path'])) {
throw new InvalidArgumentException('addResourceTypes() expects each array to include a paths element');
throw new Exception\InvalidArgumentException('addResourceTypes() expects each array to include a paths element');
}
$paths = $spec['path'];
$namespace = null;
Expand Down Expand Up @@ -568,18 +576,18 @@ public function getDefaultResourceType()
* @param string $resource
* @param string $type
* @return object
* @throws Zend_Loader_Exception if resource type not specified or invalid
* @throws Exception\InvalidArgumentException if resource type not specified or invalid
*/
public function load($resource, $type = null)
{
if (null === $type) {
$type = $this->getDefaultResourceType();
if (empty($type)) {
throw new InvalidArgumentException('No resource type specified');
throw new Exception\InvalidArgumentException('No resource type specified');
}
}
if (!$this->hasResourceType($type)) {
throw new InvalidArgumentException('Invalid resource type specified');
throw new Exception\InvalidArgumentException('Invalid resource type specified');
}
$namespace = $this->_resourceTypes[$type]['namespace'];
if (null !== $this->getNamespace()) {
Expand Down
4 changes: 2 additions & 2 deletions src/ShortNameLocater.php → src/ShortNameLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@
namespace Zend\Loader;

/**
* Short name locater interface
* Short name locator interface
*
* @category Zend
* @package Zend_Loader
* @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface ShortNameLocater
interface ShortNameLocator
{
/**
* Whether or not a Helper by a specific name
Expand Down
2 changes: 1 addition & 1 deletion test/PluginBrokerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function setUp()
public function testUsesEmptyPluginClassLoaderByDefault()
{
$loader = $this->broker->getClassLoader();
$this->assertType('Zend\Loader\ShortNameLocater', $loader);
$this->assertType('Zend\Loader\ShortNameLocator', $loader);
$this->assertType('Zend\Loader\PluginClassLoader', $loader);
$this->assertEquals(array(), $loader->getRegisteredPlugins());
}
Expand Down
Loading

0 comments on commit 526722c

Please sign in to comment.