本文整理汇总了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;
}
示例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;
}
示例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());
}
示例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);
});
}
示例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;
}
示例6: testLockedSet
/**
* @expectedException Aura\Di\Exception\ContainerLocked
*/
public function testLockedSet()
{
$this->container->lock();
$this->container->set('foo', function () {
return new StdClass();
});
}
示例7: __construct
public function __construct()
{
$this->model = new \FeatherBB\Model\Install();
$this->available_langs = Lister::getLangs();
Container::set('user', null);
View::setStyle('FeatherBB');
}
示例8: set
public function set($key, $value)
{
$k = $this->findKey($key);
if ($k === false) {
$k = $key;
}
return parent::set($k, $value);
}
示例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']);*/
}
示例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);
}
}
示例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();
}
示例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);
}
示例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]));
}
示例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;
}
示例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);
}