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

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
Promote develop to master, becoming the next stable release.
  • Loading branch information
weierophinney committed Mar 12, 2014
189 parents f848448 + 8db253f + a464957 + 741de27 + 4d1adc8 + 8c5c414 + a7502a7 + 5058513 + 68f3d6e + f0a44c8 + 921096f + acfe55c + 35c857a + a9dd8d2 + 44d8daf + d1f9e24 + a36339c + 86f0f77 + 7ed9bcc + 754bd9a + c36f6c0 + 3ead99d + be05873 + 34e7aec + 2fcaf1c + 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 + c07a4ae + b1adcfd + 5700ed4 + fa773c1 + 5965ec2 + 64ddc63 + bdd4b7d + 70a7885 + 39f70f1 + 74575c7 + fce725c + a2237d5 + 157a03a + ec26a71 + 5cfcc45 + 30d2b4b + df1ad0c + 9ed9a14 + cb22cac + 5f907a0 + fa1a9da commit f89400a
Show file tree
Hide file tree
Showing 30 changed files with 326 additions and 124 deletions.
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,13 @@
}
},
"require": {
"php": ">=5.3.3"
"php": ">=5.3.23"
},
"require-dev": {
"zendframework/zend-di": "self.version",
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master",
"phpunit/PHPUnit": "~4.0"
},
"suggest": {
"zendframework/zend-di": "Zend\\Di component"
Expand All @@ -28,10 +34,5 @@
"psr-4": {
"ZendTest\\ServiceManager\\": "test/"
}
},
"require-dev": {
"fabpot/php-cs-fixer": "1.7.*",
"satooshi/php-coveralls": "dev-master",
"phpunit/PHPUnit": "~4.0"
}
}
21 changes: 5 additions & 16 deletions src/Proxy/LazyServiceFactoryFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public function createService(ServiceLocatorInterface $serviceLocator)

$factoryConfig = new Configuration();

if (isset($lazyServices['proxies_namespace'])) {
$factoryConfig->setProxiesNamespace($lazyServices['proxies_namespace']);
}

if (isset($lazyServices['proxies_target_dir'])) {
$factoryConfig->setProxiesTargetDir($lazyServices['proxies_target_dir']);
}
Expand All @@ -51,22 +55,7 @@ public function createService(ServiceLocatorInterface $serviceLocator)
$factoryConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
}

if (isset($lazyServices['auto_generate_proxies'])) {
$factoryConfig->setAutoGenerateProxies($lazyServices['auto_generate_proxies']);

// register the proxy autoloader if the proxies already exist
if (!$lazyServices['auto_generate_proxies']) {
spl_autoload_register($factoryConfig->getProxyAutoloader());

$factoryConfig->setGeneratorStrategy(new EvaluatingGeneratorStrategy());
}
}

//if (!isset($lazyServicesConfig['runtime_evaluate_proxies']))

if (isset($lazyServices['proxies_namespace'])) {
$factoryConfig->setProxiesNamespace($lazyServices['proxies_namespace']);
}
spl_autoload_register($factoryConfig->getProxyAutoloader());

return new LazyServiceFactory(new LazyLoadingValueHolderFactory($factoryConfig), $lazyServices['class_map']);
}
Expand Down
173 changes: 96 additions & 77 deletions src/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ class ServiceManager implements ServiceLocatorInterface
protected $pendingAbstractFactoryRequests = array();

/**
* @var string
* @var integer
*/
protected $lastAbstractFactoryUsed = null;
protected $nestedContextCounter = -1;

/**
* @var string
* @var array
*/
protected $lastCanonicalNameUsed = null;
protected $nestedContext = array();

/**
* @var array
Expand Down Expand Up @@ -494,6 +494,7 @@ public function get($name, $usePeeringServiceManagers = true)
}

if (!$instance) {
$this->checkNestedContextStart($cName);
if (
isset($this->invokableClasses[$cName])
|| isset($this->factories[$cName])
Expand All @@ -512,10 +513,12 @@ public function get($name, $usePeeringServiceManagers = true)
} elseif ($usePeeringServiceManagers && !$this->retrieveFromPeeringManagerFirst) {
$instance = $this->retrieveFromPeeringManager($name);
}
$this->checkNestedContextStop();
}

// Still no instance? raise an exception
if ($instance === null) {
$this->checkNestedContextStop(true);
if ($isAlias) {
throw new Exception\ServiceNotFoundException(sprintf(
'An alias "%s" was requested but no service could be found.',
Expand Down Expand Up @@ -612,12 +615,14 @@ public function doCreate($rName, $cName)
if ($instance === null && isset($this->invokableClasses[$cName])) {
$instance = $this->createFromInvokable($cName, $rName);
}

$this->checkNestedContextStart($cName);
if ($instance === null && $this->canCreateFromAbstractFactory($cName, $rName)) {
$instance = $this->createFromAbstractFactory($cName, $rName);
}
$this->checkNestedContextStop();

if ($instance === null && $this->throwExceptionInCreate) {
$this->checkNestedContextStop(true);
throw new Exception\ServiceNotFoundException(sprintf(
'No valid instance was found for %s%s',
$cName,
Expand All @@ -643,65 +648,57 @@ public function doCreate($rName, $cName)

/**
* Determine if we can create an instance.
* Proxies to has()
*
* @param string|array $name
* @param bool $checkAbstractFactories
* @return bool
*
* @deprecated this method is being deprecated as of zendframework 2.2, and may be removed in future major versions
* @deprecated this method is being deprecated as of zendframework 2.3, and may be removed in future major versions
*/
public function canCreate($name, $checkAbstractFactories = true)
{
if (is_array($name)) {
list($cName, $rName) = $name;
} else {
$rName = $name;
$cName = $this->canonicalizeName($rName);
}

return (
isset($this->invokableClasses[$cName])
|| isset($this->factories[$cName])
|| isset($this->aliases[$cName])
|| isset($this->instances[$cName])
|| ($checkAbstractFactories && $this->canCreateFromAbstractFactory($cName, $rName))
);
trigger_error(sprintf('%s is deprecated; please use %s::has', __METHOD__, __CLASS__), E_USER_DEPRECATED);
return $this->has($name, $checkAbstractFactories, false);
}

/**
* @param string|array $name
* Determine if an instance exists.
*
* @param string|array $name An array argument accepts exactly two values.
* Example: array('canonicalName', 'requestName')
* @param bool $checkAbstractFactories
* @param bool $usePeeringServiceManagers
* @return bool
*/
public function has($name, $checkAbstractFactories = true, $usePeeringServiceManagers = true)
{
if (is_array($name)) {
list($cName, $rName) = $name;
} else {
if (is_string($name)) {
$rName = $name;

// inlined code from ServiceManager::canonicalizeName for performance
if (isset($this->canonicalNames[$rName])) {
$cName = $this->canonicalNames[$name];
$cName = $this->canonicalNames[$rName];
} else {
$cName = $this->canonicalizeName($name);
}
} elseif (is_array($name) && count($name) >= 2) {
list($cName, $rName) = $name;
} else {
return false;
}

if (
isset($this->invokableClasses[$cName])
if (isset($this->invokableClasses[$cName])
|| isset($this->factories[$cName])
|| isset($this->aliases[$cName])
|| isset($this->instances[$cName])
|| ($checkAbstractFactories && $this->canCreateFromAbstractFactory($cName, $name))
|| ($checkAbstractFactories && $this->canCreateFromAbstractFactory($cName, $rName))
) {
return true;
}

if ($usePeeringServiceManagers) {
foreach ($this->peeringServiceManagers as $peeringServiceManager) {
if ($peeringServiceManager->has($rName)) {
if ($peeringServiceManager->has($name)) {
return true;
}
}
Expand All @@ -719,33 +716,33 @@ public function has($name, $checkAbstractFactories = true, $usePeeringServiceMan
*/
public function canCreateFromAbstractFactory($cName, $rName)
{
// check abstract factories
foreach ($this->abstractFactories as $abstractFactory) {
$factoryClass = get_class($abstractFactory);

if (
isset($this->pendingAbstractFactoryRequests[$factoryClass])
&& $this->pendingAbstractFactoryRequests[$factoryClass] == $rName
) {
if (array_key_exists($cName, $this->nestedContext)) {
$context = $this->nestedContext[$cName];
if ($context === false) {
return false;
} elseif (is_object($context)) {
return !isset($this->pendingAbstractFactoryRequests[get_class($context).$cName]);
}

$objectHash = spl_object_hash($abstractFactory);

if ($this->lastAbstractFactoryUsed === $objectHash && $this->lastCanonicalNameUsed === $cName) {
$this->lastAbstractFactoryUsed = $this->lastCanonicalNameUsed = null;
return false;
}
$this->checkNestedContextStart($cName);
// check abstract factories
$result = false;
$this->nestedContext[$cName] = false;
foreach ($this->abstractFactories as $abstractFactory) {
$pendingKey = get_class($abstractFactory).$cName;
if (isset($this->pendingAbstractFactoryRequests[$pendingKey])) {
$result = false;
break;
}

$this->lastAbstractFactoryUsed = $objectHash;
$this->lastCanonicalNameUsed = $cName;

if ($abstractFactory->canCreateServiceWithName($this, $cName, $rName)) {
$this->lastAbstractFactoryUsed = $this->lastCanonicalNameUsed = null;
return true;
$this->nestedContext[$cName] = $abstractFactory;
$result = true;
break;
}
}
return false;
$this->checkNestedContextStop();
return $result;
}

/**
Expand Down Expand Up @@ -1055,31 +1052,21 @@ protected function createFromFactory($canonicalName, $requestedName)
*/
protected function createFromAbstractFactory($canonicalName, $requestedName)
{
foreach ($this->abstractFactories as $index => $abstractFactory) {
// support factories as strings
if (is_string($abstractFactory) && class_exists($abstractFactory, true)) {
$this->abstractFactories[$index] = $abstractFactory = new $abstractFactory;
} elseif (!$abstractFactory instanceof AbstractFactoryInterface) {
throw new Exception\ServiceNotCreatedException(sprintf(
'While attempting to create %s%s an abstract factory could not produce a valid instance.',
$canonicalName,
($requestedName ? '(alias: ' . $requestedName . ')' : '')
));
}
if (isset($this->nestedContext[$canonicalName])) {
$abstractFactory = $this->nestedContext[$canonicalName];
$pendingKey = get_class($abstractFactory).$canonicalName;
try {
if ($abstractFactory->canCreateServiceWithName($this, $canonicalName, $requestedName)) {
$this->pendingAbstractFactoryRequests[get_class($abstractFactory)] = $requestedName;
$instance = $this->createServiceViaCallback(
array($abstractFactory, 'createServiceWithName'),
$canonicalName,
$requestedName
);
unset($this->pendingAbstractFactoryRequests[get_class($abstractFactory)]);
} else {
$instance = null;
}
$this->pendingAbstractFactoryRequests[$pendingKey] = true;
$instance = $this->createServiceViaCallback(
array($abstractFactory, 'createServiceWithName'),
$canonicalName,
$requestedName
);
unset($this->pendingAbstractFactoryRequests[$pendingKey]);
return $instance;
} catch (\Exception $e) {
unset($this->pendingAbstractFactoryRequests[get_class($abstractFactory)]);
unset($this->pendingAbstractFactoryRequests[$pendingKey]);
$this->checkNestedContextStop(true);
throw new Exception\ServiceNotCreatedException(
sprintf(
'An abstract factory could not create an instance of %s%s.',
Expand All @@ -1090,10 +1077,42 @@ protected function createFromAbstractFactory($canonicalName, $requestedName)
$e
);
}
if ($instance !== null) {
return $instance;
}
}
return null;
}

/**
*
* @param string $cName
* @return self
*/
protected function checkNestedContextStart($cName)
{
if ($this->nestedContextCounter === -1 || !isset($this->nestedContext[$cName])) {
$this->nestedContext[$cName] = null;
}
$this->nestedContextCounter++;
return $this;
}

/**
*
* @param bool $force
* @return self
*/
protected function checkNestedContextStop($force = false)
{
if ($force) {
$this->nestedContextCounter = -1;
$this->nestedContext = array();
return $this;
}

$this->nestedContextCounter--;
if ($this->nestedContextCounter === -1) {
$this->nestedContext = array();
}
return $this;
}

/**
Expand Down Expand Up @@ -1157,7 +1176,7 @@ protected static function isSubclassOf($className, $type)
if (is_subclass_of($className, $type)) {
return true;
}
if (version_compare(PHP_VERSION, '5.3.7', '>=')) {
if (PHP_VERSION_ID >= 50307) {
return false;
}
if (!interface_exists($type)) {
Expand Down
2 changes: 1 addition & 1 deletion test/AbstractPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/Di/DiAbstractServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/Di/DiServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down
2 changes: 1 addition & 1 deletion test/Di/DiServiceInitializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* 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)
* @copyright Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

Expand Down
Loading

0 comments on commit f89400a

Please sign in to comment.