本文整理汇总了PHP中Definition::getConstructor方法的典型用法代码示例。如果您正苦于以下问题:PHP Definition::getConstructor方法的具体用法?PHP Definition::getConstructor怎么用?PHP Definition::getConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Definition
的用法示例。
在下文中一共展示了Definition::getConstructor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createService
/**
* Creates a service for a service definition.
*
* @param Definition $definition A service definition instance
* @param string $id The service identifier
*
* @return object The service described by the service definition
*/
protected function createService(Definition $definition, $id)
{
if (null !== $definition->getFile()) {
require_once self::resolveValue($definition->getFile(), $this->parameters);
}
$r = new \ReflectionClass(self::resolveValue($definition->getClass(), $this->parameters));
$arguments = $this->resolveServices(self::resolveValue($definition->getArguments(), $this->parameters));
if (null !== $definition->getConstructor()) {
$service = call_user_func_array(array(self::resolveValue($definition->getClass(), $this->parameters), $definition->getConstructor()), $arguments);
} else {
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
}
if ($definition->isShared()) {
$this->services[$id] = $service;
}
foreach ($definition->getMethodCalls() as $call) {
$services = self::getServiceConditionals($call[1]);
$ok = true;
foreach ($services as $s) {
if (!$this->hasService($s)) {
$ok = false;
break;
}
}
if ($ok) {
call_user_func_array(array($service, $call[0]), $this->resolveServices(self::resolveValue($call[1], $this->parameters)));
}
}
if ($callable = $definition->getConfigurator()) {
if (is_array($callable) && is_object($callable[0]) && $callable[0] instanceof Reference) {
$callable[0] = $this->getService((string) $callable[0]);
} elseif (is_array($callable)) {
$callable[0] = self::resolveValue($callable[0], $this->parameters);
}
if (!is_callable($callable)) {
throw new \InvalidArgumentException(sprintf('The configure callable for class "%s" is not a callable.', get_class($service)));
}
call_user_func($callable, $service);
}
return $service;
}