当前位置: 首页>>代码示例>>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;未经允许,请勿转载。