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


PHP Container::build方法代碼示例

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


在下文中一共展示了Container::build方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: testSingletonWithPersistence

 public function testSingletonWithPersistence()
 {
     $container = new Container();
     $container->singleton('mySingleton', '\\stdClass');
     $stdClass = $container->build('mySingleton');
     $stdClass->testVar = 'value';
     $stdClass2 = $container->build('mySingleton');
     $this->assertEquals('value', $stdClass2->testVar);
 }
開發者ID:usmanhalalit,項目名稱:viocon,代碼行數:9,代碼來源:ContainerTest.php

示例2: __invoke

 /**
  * Magic method. Runs when using this class as a function.
  * Ex: $object = new Definition($container, $class);
  *     $invoked = $object();
  *
  * @return object The instantiated $class with optional args passed to the constructor and methods called.
  */
 public function __invoke()
 {
     $this->mergeInheritedDependencies();
     if (empty($this->arguments)) {
         $object = $this->container->build($this->class);
     } else {
         $reflection = new \ReflectionClass($this->class);
         $arguments = [];
         foreach ($this->arguments as $arg) {
             if (is_string($arg) && (class_exists($arg) || $this->container->bound($arg))) {
                 $arguments[] = $this->container->resolve($arg);
                 continue;
             }
             $arguments[] = $arg;
         }
         $object = $reflection->newInstanceArgs($arguments);
     }
     if ($object instanceof ContainerAwareInterface) {
         $this->withMethod('setContainer', [$this->container]);
     }
     return $this->callMethods($object);
 }
開發者ID:encorephp,項目名稱:container,代碼行數:29,代碼來源:Definition.php

示例3: __invoke

 /**
  * Magic method. Runs when using this class as a function.
  * Ex: $object = new Definition($container, $class);
  *     $invoked = $object();
  *
  * @return object The instantiated $class with optional args passed to the constructor and methods called.
  */
 public function __invoke()
 {
     if (empty($this->arguments)) {
         if (empty($this->methods)) {
             $object = $this->container->build($this->class);
         } else {
             $object = new $this->class();
         }
     } else {
         $reflection = new \ReflectionClass($this->class);
         $arguments = array();
         foreach ($this->arguments as $arg) {
             if (is_string($arg) && (class_exists($arg) || $this->container->bound($arg))) {
                 $arguments[] = $this->container->resolve($arg);
                 continue;
             }
             $arguments[] = $arg;
         }
         $object = $reflection->newInstanceArgs($arguments);
     }
     return $this->callMethods($object);
 }
開發者ID:ymnl007,項目名稱:di,代碼行數:29,代碼來源:Definition.php


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