This repository has been archived by the owner on Feb 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of git://github.com/zendframework/zf2 into string
- Loading branch information
103 parents
7007d61
+
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
+
fdab45c
+
a4698e4
+
34e7aec
+
2fcaf1c
+
0eb7480
+
4594eeb
+
3fab1eb
+
ea3acc3
+
fe35f10
+
45cc91b
+
aa77760
+
4959b82
+
35e2edb
+
7717bd8
+
127fcbd
+
fc52973
+
528f461
+
8e251cd
+
d95b25a
+
0f89697
+
c941b0e
+
3dc45ae
+
180e140
+
67c3033
+
533cd3e
+
29e7718
+
936c9be
+
2d11657
+
9549d20
+
d3a95e2
+
5e04377
+
d9da2cf
+
1049b39
+
001d281
+
ca437e5
+
a5cb2da
+
e2db3b8
+
27f50b4
+
8008d6f
+
4a6bead
+
e2df9ad
+
9045ea9
+
0d18a05
+
48cc7df
+
dc08391
+
ceec2bd
+
c5fc623
+
6335bda
+
2a78ec6
+
56c198e
+
3f9b994
+
303ab92
+
7db8ed5
+
d73e943
commit 7981849
Showing
40 changed files
with
1,250 additions
and
423 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,38 @@ | ||
<?php | ||
/** | ||
* 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) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @package Zend_ServiceManager | ||
*/ | ||
|
||
namespace Zend\ServiceManager; | ||
|
||
/** | ||
* @category Zend | ||
* @package Zend_ServiceManager | ||
*/ | ||
interface AbstractFactoryInterface | ||
{ | ||
/** | ||
* Determine if we can create a service with name | ||
* | ||
* @param ServiceLocatorInterface $serviceLocator | ||
* @param $name | ||
* @param $requestedName | ||
* @return bool | ||
*/ | ||
public function canCreateServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName); | ||
|
||
/** | ||
* Create service with name | ||
* | ||
* @param ServiceLocatorInterface $serviceLocator | ||
* @param $name | ||
* @param $requestedName | ||
* @return mixed | ||
*/ | ||
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,15 @@ | ||
<?php | ||
/** | ||
* Zend Framework | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* LICENSE | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* It is also available through the world-wide-web at this URL: | ||
* http://framework.zend.com/license/new-bsd | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so we can send you a copy immediately. | ||
* | ||
* @category Zend | ||
* @package Zend_ServiceManager | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2012 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; | ||
|
||
use Zend\Code\Reflection\ClassReflection; | ||
|
||
/** | ||
* ServiceManager implementation for managing plugins | ||
* | ||
|
@@ -34,8 +22,6 @@ | |
* | ||
* @category Zend | ||
* @package Zend_ServiceManager | ||
* @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
abstract class AbstractPluginManager extends ServiceManager implements ServiceLocatorAwareInterface | ||
{ | ||
|
@@ -44,10 +30,19 @@ abstract class AbstractPluginManager extends ServiceManager implements ServiceLo | |
* | ||
* @var bool | ||
*/ | ||
protected $allowOverride = true; | ||
protected $allowOverride = true; | ||
|
||
/** | ||
* @var mixed Options to use when creating an instance | ||
* Whether or not to auto-add a class as an invokable class if it exists | ||
* | ||
* @var bool | ||
*/ | ||
protected $autoAddInvokableClass = true; | ||
|
||
/** | ||
* Options to use when creating an instance | ||
* | ||
* @var mixed | ||
*/ | ||
protected $creationOptions = null; | ||
|
||
|
@@ -64,16 +59,15 @@ abstract class AbstractPluginManager extends ServiceManager implements ServiceLo | |
* Add a default initializer to ensure the plugin is valid after instance | ||
* creation. | ||
* | ||
* @param null|ConfigurationInterface $configuration | ||
* @return void | ||
* @param null|ConfigInterface $configuration | ||
*/ | ||
public function __construct(ConfigurationInterface $configuration = null) | ||
public function __construct(ConfigInterface $configuration = null) | ||
{ | ||
parent::__construct($configuration); | ||
$self = $this; | ||
$this->addInitializer(function ($instance) use ($self) { | ||
if ($instance instanceof ServiceManagerAwareInterface) { | ||
$instance->setServiceManager($self); | ||
if ($instance instanceof ServiceLocatorAwareInterface) { | ||
$instance->setServiceLocator($self); | ||
} | ||
}); | ||
} | ||
|
@@ -105,7 +99,7 @@ abstract public function validatePlugin($plugin); | |
public function get($name, $options = array(), $usePeeringServiceManagers = true) | ||
{ | ||
// Allow specifying a class name directly; registers as an invokable class | ||
if (!$this->has($name) && class_exists($name)) { | ||
if (!$this->has($name) && $this->autoAddInvokableClass && class_exists($name)) { | ||
$this->setInvokableClass($name, $name); | ||
} | ||
|
||
|
@@ -173,15 +167,6 @@ public function getServiceLocator() | |
protected function createFromInvokable($canonicalName, $requestedName) | ||
{ | ||
$invokable = $this->invokableClasses[$canonicalName]; | ||
if (!class_exists($invokable)) { | ||
throw new Exception\ServiceNotCreatedException(sprintf( | ||
'%s: failed retrieving "%s%s" via invokable class "%s"; class does not exist', | ||
__METHOD__, | ||
$canonicalName, | ||
($requestedName ? '(alias: ' . $requestedName . ')' : ''), | ||
$canonicalName | ||
)); | ||
} | ||
|
||
if (null === $this->creationOptions | ||
|| (is_array($this->creationOptions) && empty($this->creationOptions)) | ||
|
@@ -195,23 +180,40 @@ protected function createFromInvokable($canonicalName, $requestedName) | |
} | ||
|
||
/** | ||
* Determine if a class implements a given interface | ||
* Attempt to create an instance via a factory class | ||
* | ||
* For PHP versions >= 5.3.7, uses is_subclass_of; otherwise, uses | ||
* reflection to determine the interfaces implemented. | ||
* Overrides parent implementation by passing $creationOptions to the | ||
* constructor, if non-null. | ||
* | ||
* @param string $class | ||
* @param string $type | ||
* @return bool | ||
* @param string $canonicalName | ||
* @param string $requestedName | ||
* @return mixed | ||
* @throws Exception\ServiceNotCreatedException If factory is not callable | ||
*/ | ||
protected function isSubclassOf($class, $type) | ||
protected function createFromFactory($canonicalName, $requestedName) | ||
{ | ||
if (version_compare(PHP_VERSION, '5.3.7', 'gte')) { | ||
return is_subclass_of($class, $type); | ||
$factory = $this->factories[$canonicalName]; | ||
if (is_string($factory) && class_exists($factory, true)) { | ||
if (null === $this->creationOptions || (is_array($this->creationOptions) && empty($this->creationOptions))) { | ||
$factory = new $factory(); | ||
} else { | ||
$factory = new $factory($this->creationOptions); | ||
} | ||
|
||
$this->factories[$canonicalName] = $factory; | ||
} | ||
|
||
$r = new ClassReflection($class); | ||
$interfaces = $r->getInterfaceNames(); | ||
return (in_array($type, $interfaces)); | ||
if ($factory instanceof FactoryInterface) { | ||
$instance = $this->createServiceViaCallback(array($factory, 'createService'), $canonicalName, $requestedName); | ||
} elseif (is_callable($factory)) { | ||
$instance = $this->createServiceViaCallback($factory, $canonicalName, $requestedName); | ||
} else { | ||
throw new Exception\ServiceNotCreatedException(sprintf( | ||
'While attempting to create %s%s an invalid factory was registered for this instance type.', $canonicalName, ($requestedName ? '(alias: ' . $requestedName . ')' : '') | ||
)); | ||
} | ||
|
||
return $instance; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
<?php | ||
/** | ||
* 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) | ||
* @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 | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $config = array(); | ||
|
||
/** | ||
* Constructor | ||
* | ||
* @param array $config | ||
*/ | ||
public function __construct($config = array()) | ||
{ | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* Get allow override | ||
* | ||
* @return null|bool | ||
*/ | ||
public function getAllowOverride() | ||
{ | ||
return (isset($this->config['allow_override'])) ? $this->config['allow_override'] : null; | ||
} | ||
|
||
/** | ||
* Get factories | ||
* | ||
* @return array | ||
*/ | ||
public function getFactories() | ||
{ | ||
return (isset($this->config['factories'])) ? $this->config['factories'] : array(); | ||
} | ||
|
||
/** | ||
* Get abstract factories | ||
* | ||
* @return array | ||
*/ | ||
public function getAbstractFactories() | ||
{ | ||
return (isset($this->config['abstract_factories'])) ? $this->config['abstract_factories'] : array(); | ||
} | ||
|
||
/** | ||
* Get invokables | ||
* | ||
* @return array | ||
*/ | ||
public function getInvokables() | ||
{ | ||
return (isset($this->config['invokables'])) ? $this->config['invokables'] : array(); | ||
} | ||
|
||
/** | ||
* Get services | ||
* | ||
* @return array | ||
*/ | ||
public function getServices() | ||
{ | ||
return (isset($this->config['services'])) ? $this->config['services'] : array(); | ||
} | ||
|
||
/** | ||
* Get aliases | ||
* | ||
* @return array | ||
*/ | ||
public function getAliases() | ||
{ | ||
return (isset($this->config['aliases'])) ? $this->config['aliases'] : array(); | ||
} | ||
|
||
/** | ||
* Get initializers | ||
* | ||
* @return array | ||
*/ | ||
public function getInitializers() | ||
{ | ||
return (isset($this->config['initializers'])) ? $this->config['initializers'] : array(); | ||
} | ||
|
||
/** | ||
* Get shared | ||
* | ||
* @return array | ||
*/ | ||
public function getShared() | ||
{ | ||
return (isset($this->config['shared'])) ? $this->config['shared'] : array(); | ||
} | ||
|
||
/** | ||
* Configure service manager | ||
* | ||
* @param ServiceManager $serviceManager | ||
* @return void | ||
*/ | ||
public function configureServiceManager(ServiceManager $serviceManager) | ||
{ | ||
if (($allowOverride = $this->getAllowOverride()) !== null) { | ||
$serviceManager->setAllowOverride($allowOverride); | ||
} | ||
|
||
foreach ($this->getFactories() as $name => $factory) { | ||
$serviceManager->setFactory($name, $factory); | ||
} | ||
|
||
foreach ($this->getAbstractFactories() as $factory) { | ||
$serviceManager->addAbstractFactory($factory); | ||
} | ||
|
||
foreach ($this->getInvokables() as $name => $invokable) { | ||
$serviceManager->setInvokableClass($name, $invokable); | ||
} | ||
|
||
foreach ($this->getServices() as $name => $service) { | ||
$serviceManager->setService($name, $service); | ||
} | ||
|
||
foreach ($this->getAliases() as $alias => $nameOrAlias) { | ||
$serviceManager->setAlias($alias, $nameOrAlias); | ||
} | ||
|
||
foreach ($this->getInitializers() as $initializer) { | ||
$serviceManager->addInitializer($initializer); | ||
} | ||
|
||
foreach ($this->getShared() as $name => $isShared) { | ||
$serviceManager->setShared($name, $isShared); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.