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

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Quoc Vu committed May 9, 2013
163 parents c36f6c0 + 3ead99d + be05873 + 34e7aec + 2fcaf1c + 8c5c414 + a7502a7 + 5058513 + 68f3d6e + f0a44c8 + 921096f + acfe55c + 35c857a + a9dd8d2 + 44d8daf + d1f9e24 + a36339c + 86f0f77 + 7ed9bcc + 754bd9a + 3f9b994 + ea3acc3 + fe35f10 + 45cc91b + aa77760 + 4959b82 + 35e2edb + 7717bd8 + 127fcbd + fc52973 + 528f461 + 8e251cd + d95b25a + 0f89697 + c941b0e + 3dc45ae + 180e140 + 67c3033 + 533cd3e + 29e7718 + 936c9be + 2d11657 + fa66751 + 2b778cc + ba628cd + ff761e1 + 5b64ee3 + 9456811 + 1c2d797 + 46b0d8f + 82264b3 + 39c88ce + cee064b + c303bed + ea247e3 + 1f87514 + 8896fc2 + 313a38d + 42848d4 + 8f5c457 + e035a2a + 544e341 + 467f8b2 + 30bb6f0 + f8cc896 + 2ee0afd + 656f0b0 + 7092cb4 + 5e1b259 + abb3ff8 + 39a873f + b6e6c92 + 83055d8 + 1dd5d72 + 9bc304a + 479b8c7 + 41fab24 + 80aee85 + 3962f1e + 6c6b004 + acb7af7 + 39aca71 + 9d55623 + c2210f2 + 50b7a31 + 327d366 + 00cfdb8 + 77c12db + 4a66170 + 4bd5c7f + 9549d20 + d3a95e2 + 5e04377 + d9da2cf + 1049b39 + 001d281 + ca437e5 + a5cb2da + e2db3b8 + 27f50b4 + 8008d6f + 4a6bead + e2df9ad + 9045ea9 + 0d18a05 + 48cc7df + dc08391 + ceec2bd + c5fc623 + 6335bda + 2a78ec6 + 56c198e + 3fab1eb + 6e15982 + 75f672f + 6efac6a + 7818a15 + fc61f7c + 0f89452 + 4ce1a3e + 8e87de6 + ff8bdbb + 30d8776 + df9df5b + 95173ad + 6f9a231 + b28d0cf + d4be36e + 335a3c1 + 6b736dd + 303ab92 + 4594eeb + 7db8ed5 + fecc97b + 5a47e2a + fdab45c + a4698e4 + 0eb7480 + d73e943 + cda61b2 + f5875b9 + 485d763 + e23536a + 7981849 + 388d6df + b3220c5 + 112a8ed + 9f981d8 + 5d39422 + 7bbeff8 + d9b366d + 2e1a8ce + 6c95b5a + 831b797 + 4a459ec + 18d7a25 + 90f630e + 0c71387 + 2f90b43 + c8deb2c + 4d3a9b8 + 0d718c7 + 7d9869d commit c07a4ae
Show file tree
Hide file tree
Showing 51 changed files with 1,313 additions and 243 deletions.
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
"suggest": {
"zendframework/zend-di": "Zend\\Di component"
},
"extra": {
"branch-alias": {
"dev-master": "2.2-dev",
"dev-develop": "2.3-dev"
}
},
"homepage": "https://github.com/zendframework/zend-service-manager",
"autoload-dev": {
"psr-4": {
Expand Down
7 changes: 1 addition & 6 deletions src/AbstractFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ServiceManager
*/

namespace Zend\ServiceManager;

/**
* @category Zend
* @package Zend_ServiceManager
*/
interface AbstractFactoryInterface
{
/**
Expand Down
47 changes: 36 additions & 11 deletions src/AbstractPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ServiceManager
*/

namespace Zend\ServiceManager;
Expand All @@ -19,9 +18,6 @@
* the plugin when retrieved. Finally, enables the allowOverride property by
* default to allow registering factories, aliases, and invokables to take
* the place of those provided by the implementing class.
*
* @category Zend
* @package Zend_ServiceManager
*/
abstract class AbstractPluginManager extends ServiceManager implements ServiceLocatorAwareInterface
{
Expand All @@ -30,7 +26,7 @@ abstract class AbstractPluginManager extends ServiceManager implements ServiceLo
*
* @var bool
*/
protected $allowOverride = true;
protected $allowOverride = true;

/**
* Whether or not to auto-add a class as an invokable class if it exists
Expand Down Expand Up @@ -69,9 +65,6 @@ public function __construct(ConfigInterface $configuration = null)
if ($instance instanceof ServiceLocatorAwareInterface) {
$instance->setServiceLocator($self);
}
if ($instance instanceof ServiceManagerAwareInterface) {
$instance->setServiceManager($self);
}
});
}

Expand Down Expand Up @@ -195,9 +188,11 @@ protected function createFromInvokable($canonicalName, $requestedName)
*/
protected function createFromFactory($canonicalName, $requestedName)
{
$factory = $this->factories[$canonicalName];
$factory = $this->factories[$canonicalName];
$hasCreationOptions = !(null === $this->creationOptions || (is_array($this->creationOptions) && empty($this->creationOptions)));

if (is_string($factory) && class_exists($factory, true)) {
if (null === $this->creationOptions || (is_array($this->creationOptions) && empty($this->creationOptions))) {
if (!$hasCreationOptions) {
$factory = new $factory();
} else {
$factory = new $factory($this->creationOptions);
Expand All @@ -219,4 +214,34 @@ protected function createFromFactory($canonicalName, $requestedName)
return $instance;
}

/**
* Create service via callback
*
* @param callable $callable
* @param string $cName
* @param string $rName
* @throws Exception\ServiceNotCreatedException
* @throws Exception\ServiceNotFoundException
* @throws Exception\CircularDependencyFoundException
* @return object
*/
protected function createServiceViaCallback($callable, $cName, $rName)
{
if (is_object($callable)) {
$factory = $callable;
} elseif (is_array($callable)) {
// reset both rewinds and returns the value of the first array element
$factory = reset($callable);
}

if (isset($factory)
&& ($factory instanceof MutableCreationOptionsInterface)
&& is_array($this->creationOptions)
&& !empty($this->creationOptions)
) {
$factory->setCreationOptions($this->creationOptions);
}

return parent::createServiceViaCallback($callable, $cName, $rName);
}
}
25 changes: 18 additions & 7 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ServiceManager
*/

namespace Zend\ServiceManager;

/**
* @category Zend
* @package Zend_ServiceManager
*/
class Config implements ConfigInterface
{
/**
Expand Down Expand Up @@ -111,6 +106,17 @@ public function getShared()
return (isset($this->config['shared'])) ? $this->config['shared'] : array();
}

/**
* Get the delegator services map, with keys being the services acting as delegates,
* and values being the delegator factories names
*
* @return array
*/
public function getDelegators()
{
return (isset($this->config['delegators'])) ? $this->config['delegators'] : array();
}

/**
* Configure service manager
*
Expand Down Expand Up @@ -150,6 +156,11 @@ public function configureServiceManager(ServiceManager $serviceManager)
foreach ($this->getShared() as $name => $isShared) {
$serviceManager->setShared($name, $isShared);
}
}

foreach ($this->getDelegators() as $originalServiceName => $delegators) {
foreach ($delegators as $delegator) {
$serviceManager->addDelegator($originalServiceName, $delegator);
}
}
}
}
7 changes: 1 addition & 6 deletions src/ConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ServiceManager
*/

namespace Zend\ServiceManager;

/**
* @category Zend
* @package Zend_ServiceManager
*/
interface ConfigInterface
{
/**
Expand Down
28 changes: 28 additions & 0 deletions src/DelegatorFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\ServiceManager;

/**
* Interface for factories that can create delegates for services
*/
interface DelegatorFactoryInterface
{
/**
* A factory that creates delegates of a given service
*
* @param ServiceLocatorInterface $serviceLocator the service locator which requested the service
* @param string $name the normalized service name
* @param string $requestedName the requested service name
* @param callable $callback the callback that is responsible for creating the service
*
* @return mixed
*/
public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback);
}
8 changes: 3 additions & 5 deletions src/Di/DiAbstractServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ServiceManager
*/

namespace Zend\ServiceManager\Di;
Expand Down Expand Up @@ -41,11 +40,10 @@ public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $
{
$this->serviceLocator = $serviceLocator;
if ($requestedName) {
return $this->get($requestedName, array(), true);
} else {
return $this->get($serviceName, array(), true);
return $this->get($requestedName, array());
}

return $this->get($serviceName, array());
}

/**
Expand Down
7 changes: 3 additions & 4 deletions src/Di/DiInstanceManagerProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ServiceManager
*/

namespace Zend\ServiceManager\Di;
Expand Down Expand Up @@ -65,8 +64,8 @@ public function getSharedInstance($classOrAlias)
{
if ($this->serviceLocator->has($classOrAlias)) {
return $this->serviceLocator->get($classOrAlias);
} else {
return $this->diInstanceManager->getSharedInstance($classOrAlias);
}

return $this->diInstanceManager->getSharedInstance($classOrAlias);
}
}
6 changes: 2 additions & 4 deletions src/Di/DiServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ServiceManager
*/

namespace Zend\ServiceManager\Di;
Expand Down Expand Up @@ -82,7 +81,7 @@ public function __construct(Di $di, $name, array $parameters = array(), $useServ
public function createService(ServiceLocatorInterface $serviceLocator)
{
$this->serviceLocator = $serviceLocator;
return $this->get($this->name, $this->parameters, true);
return $this->get($this->name, $this->parameters);
}

/**
Expand Down Expand Up @@ -120,5 +119,4 @@ public function get($name, array $params = array())
}

}

}
4 changes: 1 addition & 3 deletions src/Di/DiServiceInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ServiceManager
*/

namespace Zend\ServiceManager\Di;
Expand Down Expand Up @@ -65,5 +64,4 @@ public function initialize($instance, ServiceLocatorInterface $serviceLocator)
throw $e;
}
}

}
8 changes: 1 addition & 7 deletions src/Exception/CircularDependencyFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ServiceManager
*/

namespace Zend\ServiceManager\Exception;

/**
* @category Zend
* @package Zend_ServiceManager
* @subpackage Exception
*/
class CircularDependencyFoundException extends RuntimeException
{
}
8 changes: 1 addition & 7 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ServiceManager
*/

namespace Zend\ServiceManager\Exception;

/**
* @category Zend
* @package Zend_ServiceManager
* @subpackage Exception
*/
interface ExceptionInterface
{
}
8 changes: 1 addition & 7 deletions src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ServiceManager
*/

namespace Zend\ServiceManager\Exception;

/**
* @category Zend
* @package Zend_ServiceManager
* @subpackage Exception
*/
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
{
}
8 changes: 1 addition & 7 deletions src/Exception/InvalidServiceNameException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,12 @@
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
* @package Zend_ServiceManager
*/

namespace Zend\ServiceManager\Exception;

/**
* @category Zend
* @package Zend_ServiceManager
* @subpackage Exception
*/
class InvalidServiceNameException extends RuntimeException
{
}
Loading

0 comments on commit c07a4ae

Please sign in to comment.