当前位置: 首页>>代码示例>>PHP>>正文


PHP Container::set方法代码示例

本文整理汇总了PHP中Container::set方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::set方法的具体用法?PHP Container::set怎么用?PHP Container::set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Container的用法示例。


在下文中一共展示了Container::set方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: load

 /**
  * Load services from PHP file.
  * 
  * @param string
  * @return self
  */
 public function load($file)
 {
     $items = (array) (include $file);
     foreach ($items as $id => $service) {
         $this->container->set($id, $service);
     }
     return $this;
 }
开发者ID:minchal,项目名称:vero,代码行数:14,代码来源:MapLoader.php

示例2: load

 public function load(array $files)
 {
     foreach ($files as $file) {
         $baseKey = $this->namespace . "." . $this->_getBaseKey($file);
         $this->container->set($baseKey, require_once $file);
     }
     return true;
 }
开发者ID:AdrianPop,项目名称:sense,代码行数:8,代码来源:Config.php

示例3: testGetObjectConstructorArguments

 public function testGetObjectConstructorArguments()
 {
     $container = new Container();
     $container->set('foo', new \stdClass());
     $container->set('foo_bar', new \stdClass());
     $builder = new ObjectBuilder($container);
     $object = $builder->getObject('PSX\\Dependency\\FooService', array('foo'), 'PSX\\Dependency\\FooService');
     $this->assertEquals('foo', $object->getProperty());
 }
开发者ID:seytar,项目名称:psx,代码行数:9,代码来源:ObjectBuilderTest.php

示例4: register

 public function register(Container $container)
 {
     $db = $container->get("db");
     $container->set("UserService", function () use($db) {
         return new UserService($db);
     });
     $container->set("UserApplicationService", function () use($db) {
         return new UserApplicationService($db);
     });
 }
开发者ID:savicmi,项目名称:tasks,代码行数:10,代码来源:UserServiceProvider.php

示例5: getContainer

 protected function getContainer()
 {
     $container = new Container();
     $container->set('test.param', 'parameterValue');
     $container->set('callable', function ($c) {
         return 'callValue';
     });
     $container->set('shared', function ($c) {
         $a = new \stdClass();
         $a->mt = microtime(true);
         return $a;
     }, true);
     return $container;
 }
开发者ID:fwk,项目名称:di,代码行数:14,代码来源:ReferenceTest.php

示例6: testLockedSet

 /**
  * @expectedException Aura\Di\Exception\ContainerLocked
  */
 public function testLockedSet()
 {
     $this->container->lock();
     $this->container->set('foo', function () {
         return new StdClass();
     });
 }
开发者ID:walterjrp,项目名称:form-builder,代码行数:10,代码来源:ContainerTest.php

示例7: __construct

 public function __construct()
 {
     $this->model = new \FeatherBB\Model\Install();
     $this->available_langs = Lister::getLangs();
     Container::set('user', null);
     View::setStyle('FeatherBB');
 }
开发者ID:featherbb,项目名称:featherbb,代码行数:7,代码来源:Install.php

示例8: set

 public function set($key, $value)
 {
     $k = $this->findKey($key);
     if ($k === false) {
         $k = $key;
     }
     return parent::set($k, $value);
 }
开发者ID:RUSHUI,项目名称:course-offcn-php-framework,代码行数:8,代码来源:casecontainer.php

示例9: testTags

 public function testTags()
 {
     $container = new Container();
     $container->set('container_tags', []);
     $func = function () {
         $item = new $this->testClassName(42);
         return $item;
     };
     $container->set('func', $func, ['name' => 'function', 'param' => 'p42']);
     /*
         $functions = $container->getTags('function');
         
         $this->assertEquals(1,count($functions));
         
         $tag = $functions[0];
         $this->assertEquals('p42',$tag['param']);*/
 }
开发者ID:cerad,项目名称:di,代码行数:17,代码来源:ContainerTest.php

示例10: __construct

 /**
  * Constructor
  *
  * Instantiate the service locator object.
  *
  * @param  array $services
  */
 public function __construct(array $services = null)
 {
     if (null !== $services) {
         $this->setServices($services);
     }
     if (!Container::has('default')) {
         Container::set('default', $this);
     }
 }
开发者ID:popphp,项目名称:popphp,代码行数:16,代码来源:Locator.php

示例11: toArray

 /**
  * @return array
  */
 public function toArray()
 {
     $tmp = new Container(null, []);
     foreach ($this->changesTracker as $itemKey => $opType) {
         if ($opType == ITEM_OPERATION_ADD || $opType == ITEM_OPERATION_NEW_VALUE) {
             $tmp->set($this->get($itemKey));
         }
     }
     return $tmp->toArray();
 }
开发者ID:phpcrystal,项目名称:phpcrystal,代码行数:13,代码来源:FlashContainer.php

示例12: set

 /**
  * Set value of specific variable
  *
  * @access public
  * @param string $var Variable name
  * @param string $value Variable value
  * @return null
  * @throws InvalidInstanceException
  */
 public function set($var, $value)
 {
     // Get accept class
     $class = $this->getAcceptClass();
     // Check value instance...
     if (!$value instanceof $class) {
         throw new InvalidInstanceException('$value', $value, $class);
     }
     // if
     // Set var...
     return parent::set($var, $value);
 }
开发者ID:bklein01,项目名称:Project-Pier,代码行数:21,代码来源:ObjectContainer.class.php

示例13: testGetReferenceValue3

 /**
  * get parameter => service refere
  *
  * @covers Phossa\Di\Factory\DereferenceTrait::getReferenceValue
  */
 public function testGetReferenceValue3()
 {
     include_once dirname(__DIR__) . '/testData1.php';
     // autowiring
     $aa = $this->object->get('AA');
     $this->object->set('cache.test1', '@AA@');
     $this->object->set('cache.test2', '%cache.test1%');
     $ref1 = new ParameterReference('cache.test2');
     // cache.test2 => %cache.test1% => @AA@
     $this->assertEquals($aa, $this->invokeMethod('getReferenceValue', [$ref1]));
     // @BB@
     $ref2 = new ServiceReference('BB');
     $this->assertTrue($aa->getB() === $this->invokeMethod('getReferenceValue', [$ref2]));
 }
开发者ID:phossa,项目名称:phossa-di,代码行数:19,代码来源:DereferenceTraitTest.php

示例14: newInstance

 /**
  *
  * Creates a new DI container, adds pre-existing service objects, applies
  * Config classes to define() services, locks the container, and applies
  * the Config instances to modify() services.
  *
  * @param array $services Pre-existing service objects to set into the
  * container.
  *
  * @param array $config_classes A list of Config classes to instantiate and
  * invoke for configuring the container.
  *
  * @param bool $auto_resolve Enable or disable auto-resolve after the
  * define() step?
  *
  * @return Container
  *
  */
 public function newInstance(array $services = array(), array $config_classes = array(), $auto_resolve = self::ENABLE_AUTO_RESOLVE)
 {
     $di = new Container(new Factory());
     $di->setAutoResolve($auto_resolve);
     foreach ($services as $key => $val) {
         $di->set($key, $val);
     }
     $configs = array();
     foreach ($config_classes as $class) {
         $config = $di->newInstance($class);
         $config->define($di);
         $configs[] = $config;
     }
     $di->lock();
     foreach ($configs as $config) {
         $config->modify($di);
     }
     return $di;
 }
开发者ID:watsonad,项目名称:opendocman,代码行数:37,代码来源:ContainerBuilder.php

示例15: testResolvePseudoCallable

 /**
  * @covers Phossa\Di\Factory\CallableTrait::resolvePseudoCallable
  */
 public function testResolvePseudoCallable()
 {
     // pseudo callable => [ $aa, 'setX']
     $call1 = ['@AA@', 'setX'];
     $res1 = $this->invokeMethod('resolvePseudoCallable', [$call1]);
     $this->assertTrue($res1[0] === $this->object->get('AA'));
     $this->assertTrue(is_callable($res1));
     // map cache.test => '@AA@'
     $this->object->set('cache.test', '@AA@');
     $call2 = ['%cache.test%', 'setX'];
     $res2 = $this->invokeMethod('resolvePseudoCallable', [$call2]);
     $this->assertTrue($res2[0] === $this->object->get('AA'));
     $this->assertTrue(is_callable($res2));
     // real callable
     $call3 = function () {
     };
     $res3 = $this->invokeMethod('resolvePseudoCallable', [$call3]);
     $this->assertTrue($res3 === $call3);
 }
开发者ID:phossa,项目名称:phossa-di,代码行数:22,代码来源:CallableTraitTest.php


注:本文中的Container::set方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。