當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。