本文整理汇总了PHP中Closure::factory方法的典型用法代码示例。如果您正苦于以下问题:PHP Closure::factory方法的具体用法?PHP Closure::factory怎么用?PHP Closure::factory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Closure
的用法示例。
在下文中一共展示了Closure::factory方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getServiceInstance
/**
* Get service instance
*
* @param ServiceLocatorInterface $serviceLocator Service Locator instance
* @return mixed
*/
public function getServiceInstance(ServiceLocatorInterface $serviceLocator)
{
if ($this->instance === null) {
/**
* Instance must be created using factory
*/
if ($this->factory instanceof \Closure) {
$instance = call_user_func($this->factory, $serviceLocator);
} else {
$instance = $this->factory->factory($serviceLocator);
}
if (!$this->isShared()) {
return $instance;
// new instance must be returned
} else {
$this->instance = $instance;
// cache instance
return $this->instance;
// same instance must be returned
}
} else {
/**
* Instance either was passed directly or has been created earlier
*/
if (!$this->isShared()) {
return $this->instance;
// new instance must be returned
} else {
return clone $this->instance;
// same instance must be returned
}
}
}