Skip to content

Commit

Permalink
Merge branch 'hotfix/sm-cleanup' of https://github.com/coss/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Jul 31, 2012
2 parents 310ade9 + 5486eef commit 59929bf
Showing 1 changed file with 56 additions and 56 deletions.
112 changes: 56 additions & 56 deletions library/Zend/ServiceManager/ServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class ServiceManager implements ServiceLocatorInterface
protected $retrieveFromPeeringManagerFirst = false;

/**
* @var bool Track whether not ot throw exceptions during create()
* @var bool Track whether not to throw exceptions during create()
*/
protected $throwExceptionInCreate = true;

Expand Down Expand Up @@ -160,7 +160,7 @@ public function shareByDefault()
}

/**
* @param bool $throwExceptionInCreate
* @param bool $throwExceptionInCreate
* @return ServiceManager
*/
public function setThrowExceptionInCreate($throwExceptionInCreate)
Expand Down Expand Up @@ -200,9 +200,9 @@ public function retrieveFromPeeringManagerFirst()
}

/**
* @param $name
* @param $invokableClass
* @param bool $shared
* @param string $name
* @param string $invokableClass
* @param bool $shared
* @throws Exception\InvalidServiceNameException
*/
public function setInvokableClass($name, $invokableClass, $shared = true)
Expand All @@ -216,14 +216,17 @@ public function setInvokableClass($name, $invokableClass, $shared = true)
$cName
));
}

$this->invokableClasses[$cName] = $invokableClass;
$this->shared[$cName] = $shared;
$this->shared[$cName] = (bool) $shared;

return $this;
}

/**
* @param $name
* @param $factory
* @param string $name
* @param string|FactoryInterface|callable $factory
* @param bool $shared
* @throws Exception\InvalidServiceNameException
*/
public function setFactory($name, $factory, $shared = true)
Expand All @@ -245,13 +248,14 @@ public function setFactory($name, $factory, $shared = true)
}

$this->factories[$cName] = $factory;
$this->shared[$cName] = $shared;
$this->shared[$cName] = (bool) $shared;

return $this;
}

/**
* @param AbstractFactoryInterface|string $factory
* @param bool $topOfStack
* @param AbstractFactoryInterface|string $factory
* @param bool $topOfStack
* @throws Exception\InvalidArgumentException if the abstract factory is invalid
*/
public function addAbstractFactory($factory, $topOfStack = true)
Expand Down Expand Up @@ -284,7 +288,7 @@ public function addAbstractFactory($factory, $topOfStack = true)
}

/**
* @param $initializer
* @param callable|InitializerInterface $initializer
* @return ServiceManager
* @throws Exception\InvalidArgumentException
*/
Expand All @@ -310,10 +314,9 @@ public function addInitializer($initializer, $topOfStack = true)
/**
* Register a service with the locator
*
* @param string $name
* @param mixed $service
* @param bool $shared
* @param bool $shared
* @param string $name
* @param mixed $service
* @param bool $shared
* @return ServiceManager
* @throws Exception\InvalidServiceNameException
*/
Expand All @@ -334,13 +337,13 @@ public function setService($name, $service, $shared = true)
*/

$this->instances[$cName] = $service;
$this->shared[$cName] = (bool) $shared;
$this->shared[$cName] = (bool) $shared;
return $this;
}

/**
* @param $name
* @param $isShared
* @param string $name
* @param bool $isShared
* @return ServiceManager
* @throws Exception\ServiceNotFoundException
*/
Expand All @@ -363,9 +366,9 @@ public function setShared($name, $isShared)
/**
* Retrieve a registered instance
*
* @param string $cName
* @param array $params
* @return mixed
* @param string $cName
* @param bool $usePeeringServiceManagers
* @return object|array
*/
public function get($name, $usePeeringServiceManagers = true)
{
Expand All @@ -385,26 +388,22 @@ public function get($name, $usePeeringServiceManagers = true)
}
}

$instance = null;

if (isset($this->instances[$cName])) {
$instance = $this->instances[$cName];
return $this->instances[$cName];
}

$selfException = null;
$instance = null;
$retrieveFromPeeringManagerFirst = $this->retrieveFromPeeringManagerFirst();

if (!$instance && !is_array($instance)) {
$retrieveFromPeeringManagerFirst = $this->retrieveFromPeeringManagerFirst();
if ($usePeeringServiceManagers && $retrieveFromPeeringManagerFirst) {
if ($usePeeringServiceManagers && $retrieveFromPeeringManagerFirst) {
$instance = $this->retrieveFromPeeringManager($name);
}
if (!$instance) {
if ($this->canCreate(array($cName, $rName))) {
$instance = $this->create(array($cName, $rName));
} elseif ($usePeeringServiceManagers && !$retrieveFromPeeringManagerFirst) {
$instance = $this->retrieveFromPeeringManager($name);
}
if (!$instance) {
if ($this->canCreate(array($cName, $rName))) {
$instance = $this->create(array($cName, $rName));
} elseif ($usePeeringServiceManagers && !$retrieveFromPeeringManagerFirst) {
$instance = $this->retrieveFromPeeringManager($name);
}
}
}

// Still no instance? raise an exception
Expand All @@ -413,15 +412,11 @@ public function get($name, $usePeeringServiceManagers = true)
'%s was unable to fetch or create an instance for %s',
__METHOD__,
$name
),
null,
($selfException === null) ? null : $selfException->getPrevious()
)
);
}

if ($this->shareByDefault()
&& !isset($this->instances[$cName])
&& (!isset($this->shared[$cName]) || $this->shared[$cName] === true)
if ($this->shareByDefault() && (!isset($this->shared[$cName]) || $this->shared[$cName] === true)
) {
$this->instances[$cName] = $instance;
}
Expand All @@ -430,7 +425,7 @@ public function get($name, $usePeeringServiceManagers = true)
}

/**
* @param string|array $name
* @param string|array $name
* @return false|object
* @throws Exception\ServiceNotCreatedException
* @throws Exception\InvalidServiceNameException
Expand Down Expand Up @@ -482,7 +477,8 @@ public function create($name)

/**
* Determine if we can create an instance.
* @param $name
*
* @param string|array $name
* @return bool
*/
public function canCreate($name, $checkAbstractFactories = true)
Expand Down Expand Up @@ -511,7 +507,9 @@ public function canCreate($name, $checkAbstractFactories = true)
}

/**
* @param $name
* @param string|array $name
* @param bool $checkAbstractFactories
* @param bool $usePeeringServiceManagers
* @return bool
*/
public function has($name, $checkAbstractFactories = true, $usePeeringServiceManagers = true)
Expand Down Expand Up @@ -569,8 +567,8 @@ public function canCreateFromAbstractFactory($cName, $rName)
}

/**
* @param $alias
* @param $nameOrAlias
* @param string $alias
* @param string $nameOrAlias
* @return ServiceManager
* @throws Exception\ServiceNotFoundException
* @throws Exception\InvalidServiceNameException
Expand All @@ -597,7 +595,7 @@ public function setAlias($alias, $nameOrAlias)
}

/**
* @param $alias
* @param string $alias
* @return bool
*/
public function hasAlias($alias)
Expand All @@ -607,7 +605,7 @@ public function hasAlias($alias)
}

/**
* @param string $peering
* @param string $peering
* @return ServiceManager
*/
public function createScopedServiceManager($peering = self::SCOPE_PARENT)
Expand All @@ -626,8 +624,8 @@ public function createScopedServiceManager($peering = self::SCOPE_PARENT)
* Add a peering relationship
*
* @param ServiceManager $manager
* @param string $peering
* @return ServiceManager Current instance
* @param string $peering
* @return ServiceManager
*/
public function addPeeringServiceManager(ServiceManager $manager, $peering = self::SCOPE_PARENT)
{
Expand All @@ -641,7 +639,7 @@ public function addPeeringServiceManager(ServiceManager $manager, $peering = sel
}

/**
* @param $name
* @param string $name
* @return string
*/
protected function canonicalizeName($name)
Expand All @@ -655,9 +653,9 @@ protected function canonicalizeName($name)
}

/**
* @param callable $callable
* @param $cName
* @param $rName
* @param callable $callable
* @param string $cName
* @param string $rName
* @throws Exception\ServiceNotCreatedException
* @throws Exception\CircularDependencyFoundException
* @return object
Expand Down Expand Up @@ -729,6 +727,8 @@ public function getCanonicalNames()
public function setCanonicalNames($canonicalNames)
{
$this->canonicalNames = $canonicalNames;

return $this;
}

/**
Expand Down Expand Up @@ -805,7 +805,7 @@ protected function createFromFactory($canonicalName, $requestedName)
*
* @param string $canonicalName
* @param string $requestedName
* @return \stdClass|null
* @return object|null
* @throws Exception\ServiceNotCreatedException If abstract factory is not callable
*/
protected function createFromAbstractFactory($canonicalName, $requestedName)
Expand Down

0 comments on commit 59929bf

Please sign in to comment.