當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Definition::isShared方法代碼示例

本文整理匯總了PHP中Definition::isShared方法的典型用法代碼示例。如果您正苦於以下問題:PHP Definition::isShared方法的具體用法?PHP Definition::isShared怎麽用?PHP Definition::isShared使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Definition的用法示例。


在下文中一共展示了Definition::isShared方法的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;
 }
開發者ID:CodingFabian,項目名稱:symfony,代碼行數:49,代碼來源:Builder.php


注:本文中的Definition::isShared方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。