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


PHP Container::share方法代码示例

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


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

示例1: testCreateConsole

 /**
  * Method to test createConsole().
  *
  * @return void
  *
  * @covers Windwalker\Provider\CliProvider::createConsole
  */
 public function testCreateConsole()
 {
     $container = new Container();
     $provider = new CliProvider();
     $container->share('windwalker.config', new Registry(array('bundle' => array())));
     $container->share('io', new IO());
     $this->assertInstanceOf('Windwalker\\Console\\Application\\Console', $provider->createConsole($container));
 }
开发者ID:Biromain,项目名称:windwalker-joomla-rad,代码行数:15,代码来源:CliProviderTest.php

示例2: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container $container The DI container.
  *
  * @return  Container  Returns itself to support chaining.
  *
  * @since   1.0
  */
 public function register(Container $container)
 {
     $ioClass = 'Phoenix\\IO\\IO';
     $container->alias('io', $ioClass)->alias('Muse\\IO\\IO', $ioClass)->alias('Muse\\IO\\IOInterface', $ioClass)->share($ioClass, new IO($this->controller->getCommand()));
     $container->alias('operator.copy', 'Phoenix\\Generaotr\\FileOperator\\CopyOperator')->createObject('Phoenix\\Generaotr\\FileOperator\\CopyOperator');
     $closure = function (Container $container) {
         return new OperatorFactory($container->get('io'), $this->controller->getTagVariables());
     };
     $container->share('operator.factory', $closure);
 }
开发者ID:ventoviro,项目名称:phoenix,代码行数:19,代码来源:MuseProvider.php

示例3: testFork

 /**
  * testFork
  *
  * @return  void
  *
  * @covers Windwalker\DI\Container::fork
  */
 public function testFork()
 {
     $hello = $this->instance->fork('Hello', 'Hello2');
     $this->assertEquals('World', $hello);
     $this->assertEquals('World', $this->instance->get('Hello2'));
     $closure = function () {
         return uniqid();
     };
     $this->instance->share('uniqid', $closure);
     $uid = $this->instance->get('uniqid');
     $this->assertEquals($uid, $this->instance->fork('uniqid', 'uniqid2'));
     $this->assertEquals($uid, $this->instance->get('uniqid2'));
     $this->assertNotEquals($uid, $uid2 = $this->instance->fork('uniqid', 'uniqid3', Container::FORCE_NEW));
     $this->assertEquals($uid2, $this->instance->get('uniqid3'));
 }
开发者ID:rokite,项目名称:windwalker,代码行数:22,代码来源:ContainerTest.php

示例4: test__construct

 /**
  * Method to test __construct().
  *
  * @return void
  *
  * @covers Windwalker\Component\Component::__construct
  */
 public function test__construct()
 {
     // Test no constants
     $this->createComponent();
     $this->assertFalse(defined('STUB_ADMIN'));
     // Create with no params
     $component = new StubComponent();
     $this->assertEquals('stub', $component->getName());
     $container = Container::getInstance('com_stub');
     $this->assertSame($container, $component->getContainer());
     $this->assertSame($container->get('app'), $component->getApplication());
     $this->assertSame($container->get('app')->input, $component->getInput());
     $this->assertEquals('com_stub', $component->getOption());
     $this->assertEquals(STUB_ADMIN, $component->getAdminPath());
     $this->assertEquals(STUB_SITE, $component->getSitePath());
     $this->assertEquals(STUB_SELF, $component->getPath());
     // Create with manually set params
     $app = new TestApplication();
     $input = new \JInput();
     $container = new Container();
     $container->registerServiceProvider(new SystemProvider());
     // Mock Event
     $event = $this->getMock('JEventDispatcher', array('trigger'), array('eventName'), 'MockDispatcher');
     $event->expects($this->at(0))->method('trigger')->with('onComponentBeforeInit');
     $event->expects($this->at(1))->method('trigger')->with('onComponentAfterInit');
     $container->share('JEventDispatcher', $event)->alias('event.dispatcher', 'JEventDispatcher');
     $component = new StubComponent('flower', $input, $app, $container);
     $this->assertSame($container, $component->getContainer());
     $this->assertSame($app, $component->getApplication());
     $this->assertSame($input, $component->getInput());
     $this->assertEquals('com_flower', $component->getOption());
     $this->assertEquals('flower', $component->getName());
     // Other test
     $this->assertEquals('foo', $input->get('controller'));
     $this->assertEquals('foo', $input->get('task'));
     $paths = TestHelper::getValue('JFormHelper', 'paths');
     $this->assertTrue(in_array(WINDWALKER_SOURCE . '/Form/Fields', $paths['field']));
     $this->assertTrue(in_array(WINDWALKER_SOURCE . '/Form/Forms', $paths['form']));
 }
开发者ID:Biromain,项目名称:windwalker-joomla-rad,代码行数:46,代码来源:RealComponentTest.php

示例5: register

 /**
  * Registers the service provider with a DI container.
  *
  * @param   Container $container The DI container.
  *
  * @return  void
  */
 public function register(Container $container)
 {
     $container->share('bingo', function () {
         return 'Bingo';
     });
 }
开发者ID:rokite,项目名称:windwalker,代码行数:13,代码来源:StubServiceProvider.php


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