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 into cach…
Browse files Browse the repository at this point in the history
…e_interfaces
  • Loading branch information
Show file tree
Hide file tree
Showing 20 changed files with 143 additions and 102 deletions.
2 changes: 1 addition & 1 deletion .travis/run-tests.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash
travisdir=$(dirname $(readlink /proc/$$/fd/255))
travisdir=$(dirname "$0")
testdir="$travisdir/../tests"
testedcomponents=(`cat "$travisdir/tested-components"`)
result=0
Expand Down
1 change: 1 addition & 0 deletions .travis/skipped-components
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Zend/Amf
Zend/Date
Zend/Dojo
Zend/Queue
Zend/Service
Zend/Test
Expand Down
4 changes: 3 additions & 1 deletion .travis/tested-components
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ Zend/Form
Zend/GData
Zend/Http
Zend/InfoCard
Zend/InputFilter
Zend/Json
Zend/Ldap
Zend/Loader
Zend/Locale
Zend/Log
Zend/Mail
Zend/Markup
Zend/Math
Zend/Measure
Zend/Memory
Zend/Mime
Zend/Module
Zend/ModuleManager
Zend/Mvc
Zend/Navigation
Zend/OAuth
Expand Down
9 changes: 4 additions & 5 deletions src/Exception/BadMethodCallException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@


namespace Zend\Loader\Exception;
require_once __DIR__ . '/../Exception.php';
use Zend\Loader\Exception;

require_once __DIR__ . '/ExceptionInterface.php';

/**
* @category Zend
Expand All @@ -31,8 +31,7 @@
* @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 BadMethodCallException
extends \BadMethodCallException
implements Exception
class BadMethodCallException extends \BadMethodCallException implements
ExceptionInterface
{
}
9 changes: 4 additions & 5 deletions src/Exception/DomainException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/

namespace Zend\Loader\Exception;
require_once __DIR__ . '/../Exception.php';
use Zend\Loader\Exception;

require_once __DIR__ . '/ExceptionInterface.php';

/**
* @category Zend
Expand All @@ -30,6 +30,5 @@
* @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 DomainException extends \DomainException implements Exception
{
}
class DomainException extends \DomainException implements ExceptionInterface
{}
6 changes: 3 additions & 3 deletions src/Exception.php → src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Loader;
namespace Zend\Loader\Exception;

/**
* @category Zend
* @package Zend_Loader
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
interface Exception
{}
interface ExceptionInterface
{}
12 changes: 5 additions & 7 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@


namespace Zend\Loader\Exception;
require_once __DIR__ . '/../Exception.php';
use Zend\Loader\Exception;

require_once __DIR__ . '/ExceptionInterface.php';

/**
* @category Zend
Expand All @@ -31,8 +31,6 @@
* @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 InvalidArgumentException
extends \InvalidArgumentException
implements Exception
{
}
class InvalidArgumentException extends \InvalidArgumentException implements
ExceptionInterface
{}
11 changes: 4 additions & 7 deletions src/Exception/InvalidPathException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/

namespace Zend\Loader\Exception;
require_once __DIR__ . '/../Exception.php';
use Zend\Loader\Exception;

require_once __DIR__ . '/ExceptionInterface.php';

/**
* @category Zend
Expand All @@ -30,8 +30,5 @@
* @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 InvalidPathException
extends \Exception
implements Exception
{
}
class InvalidPathException extends \Exception implements ExceptionInterface
{}
12 changes: 5 additions & 7 deletions src/Exception/MissingResourceNamespaceException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/

namespace Zend\Loader\Exception;
require_once __DIR__ . '/../Exception.php';
use Zend\Loader\Exception;

require_once __DIR__ . '/ExceptionInterface.php';

/**
* @category Zend
Expand All @@ -30,8 +30,6 @@
* @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 MissingResourceNamespaceException
extends \Exception
implements Exception
{
}
class MissingResourceNamespaceException extends \Exception implements
ExceptionInterface
{}
6 changes: 3 additions & 3 deletions src/Exception/PluginLoaderException.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
*/

namespace Zend\Loader\Exception;
require_once __DIR__ . '/../Exception.php';
use Zend\Loader\Exception;

require_once __DIR__ . '/DomainException.php';

/**
* Plugin class loader exceptions
Expand All @@ -33,6 +33,6 @@
* @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 PluginLoaderException extends \DomainException implements Exception
class PluginLoaderException extends DomainException
{
}
9 changes: 4 additions & 5 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/

namespace Zend\Loader\Exception;
require_once __DIR__ . '/../Exception.php';
use Zend\Loader\Exception;

require_once __DIR__ . '/ExceptionInterface.php';

/**
* @category Zend
Expand All @@ -30,6 +30,5 @@
* @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 RuntimeException extends \DomainException implements Exception
{
}
class RuntimeException extends \RuntimeException implements ExceptionInterface
{}
9 changes: 4 additions & 5 deletions src/Exception/SecurityException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/

namespace Zend\Loader\Exception;
require_once __DIR__ . '/../Exception.php';
use Zend\Loader\Exception;

require_once __DIR__ . '/DomainException.php';

/**
* @category Zend
Expand All @@ -30,6 +30,5 @@
* @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 SecurityException extends \DomainException implements Exception
{
}
class SecurityException extends DomainException
{}
11 changes: 0 additions & 11 deletions src/LocatorAware.php

This file was deleted.

93 changes: 62 additions & 31 deletions src/PluginBroker.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@

namespace Zend\Loader;

use Zend\Di\LocatorInterface;
use ReflectionClass;
use Zend\ServiceManager\Exception\ExceptionInterface as ServiceManagerException;
use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* Plugin broker base implementation
Expand All @@ -31,7 +34,7 @@
* @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 PluginBroker implements Broker, LocatorAware
class PluginBroker implements Broker, ServiceLocatorAwareInterface
{
/**
* @var string Default class loader to utilize with this broker
Expand Down Expand Up @@ -186,36 +189,64 @@ public function load($plugin, array $options = null)
return $this->plugins[$pluginName];
}

if (class_exists($plugin)) {
// Allow loading fully-qualified class names via the broker
$class = $plugin;
} else {
// Unqualified class names are then passed to the class loader
$class = $this->getClassLoader()->load($plugin);
if (empty($class)) {
throw new Exception\RuntimeException('Unable to locate class associated with "' . $pluginName . '"');
$locator = $this->getServiceLocator();
// Pulling by alias
if ($locator) {
try {
$instance = $locator->get($plugin);
} catch (ServiceManagerException $e) {
// not returning an instance is okay; there are other ways to
// retrieve the plugin later
$instance = false;
}

if ($instance) {
if ($this->getRegisterPluginsOnLoad()) {
$this->register($pluginName, $instance);
}
return $instance;
}
}

if ($this->getLocator()) {
if (empty($options)) {
$instance = $this->getLocator()->get($class);
} elseif ($this->isAssocArray($options)) {
// This might be inconsistent with what $options should be?
$instance = $this->getLocator()->get($class, $options);
} else {
// @TODO: Clean this up, somehow?
$instance = $this->getLocator()->get($class);
$class = $this->getClassLoader()->load($plugin);
if (empty($class) && !class_exists($plugin)) {
throw new Exception\RuntimeException('Unable to locate class associated with "' . $pluginName . '"');
}

if (empty($class) && class_exists($plugin)) {
$class = $plugin;
}

// Pulling by resolved class name
if ($locator) {
try {
$instance = $locator->get($class);
} catch (ServiceManagerException $e) {
// not returning an instance is okay; there are other ways to
// retrieve the plugin later
$instance = false;
}
} else {
if (empty($options)) {
$instance = new $class();
} elseif ($this->isAssocArray($options)) {
$instance = new $class($options);
} else {
$r = new \ReflectionClass($class);
$instance = $r->newInstanceArgs($options);

if ($instance) {
if ($this->getRegisterPluginsOnLoad()) {
$this->register($pluginName, $instance);
}
return $instance;
}
}

if (!class_exists($class)) {
throw new Exception\RuntimeException('Unable to locate class associated with "' . $pluginName . '"');
}

// Did not find in the locator, so instantiate directly
if (empty($options)) {
$instance = new $class();
} elseif ($this->isAssocArray($options)) {
$instance = new $class($options);
} else {
$r = new ReflectionClass($class);
$instance = $r->newInstanceArgs($options);
}

if ($this->getRegisterPluginsOnLoad()) {
Expand Down Expand Up @@ -395,19 +426,19 @@ protected function isAssocArray($value)
/**
* Get locator.
*
* @return Zend\Di\LocatorInterface
* @return ServiceLocatorInterface
*/
public function getLocator()
public function getServiceLocator()
{
return $this->locator;
}

/**
* Set locator.
*
* @param Zend\Di\LocatorInterface $locator
* @param ServiceLocatorInterface $locator
*/
public function setLocator(LocatorInterface $locator)
public function setServiceLocator(ServiceLocatorInterface $locator)
{
$this->locator = $locator;
return $this;
Expand Down
9 changes: 9 additions & 0 deletions src/PluginClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,15 @@ public function registerPlugins($map)
}

foreach ($map as $name => $class) {
if ((is_int($name) || is_numeric($name))
&& (is_object($class) || class_exists($class))
&& is_subclass_of($class, 'Traversable')
) {
$subMap = new $class();
$this->registerPlugins($subMap);
continue;
}

$this->registerPlugin($name, $class);
}

Expand Down
Loading

0 comments on commit 2b12a57

Please sign in to comment.