本文整理汇总了PHP中Joomla\DI\Container::registerServiceProvider方法的典型用法代码示例。如果您正苦于以下问题:PHP Container::registerServiceProvider方法的具体用法?PHP Container::registerServiceProvider怎么用?PHP Container::registerServiceProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Joomla\DI\Container
的用法示例。
在下文中一共展示了Container::registerServiceProvider方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
public function setUp()
{
$this->dataDirectory = __DIR__ . '/tmp';
$this->mkdir($this->dataDirectory . '/entities');
$container = new Container();
$container->set('ConfigDirectory', JPATH_ROOT);
$container->registerServiceProvider(new StorageServiceProvider(), 'repository');
$container->registerServiceProvider(new EventDispatcherServiceProvider(), 'dispatcher');
$container->registerServiceProvider(new ExtensionFactoryServiceProvider(), 'extension_factory');
$this->installer = new Installer($this->dataDirectory, $container);
}
示例2: RendererAddsTheEventDecorator
public function RendererAddsTheEventDecorator(UnitTester $I)
{
$container = new Container();
$container->set('ConfigDirectory', JPATH_ROOT);
$container->registerServiceProvider(new StorageServiceProvider(), 'repository');
$container->registerServiceProvider(new EventDispatcherServiceProvider(), 'dispatcher');
$container->registerServiceProvider(new ExtensionFactoryServiceProvider(), 'extension_factory');
$app = new Application([new RendererMiddleware(new Dispatcher(), $container), function (ServerRequestInterface $request, ResponseInterface $response, callable $next) use($I) {
$body = $response->getBody();
$I->assertEquals(EventDecorator::class, get_class($body));
return $next($request, $response);
}]);
$app->run(new ServerRequest());
}
示例3: init
/**
* Init this component.
*
* @return void
*/
public function init()
{
$dispatcher = $this->container->get('event.dispatcher');
// Event
$dispatcher->trigger('onComponentBeforeInit', array($this->name, $this, $this->input));
// We build component path constant, helpe us get path easily.
$this->path['self'] = JPATH_BASE . '/components/' . strtolower($this->option);
$this->path['site'] = JPATH_ROOT . '/components/' . strtolower($this->option);
$this->path['administrator'] = JPATH_ROOT . '/administrator/components/' . strtolower($this->option);
define(strtoupper($this->name) . '_SELF', $this->path['self']);
define(strtoupper($this->name) . '_SITE', $this->path['site']);
define(strtoupper($this->name) . '_ADMIN', $this->path['administrator']);
// Register some useful object for this component.
$this->container->registerServiceProvider(new ComponentProvider($this->name, $this));
$task = $this->input->getWord('task');
$controller = $this->input->getWord('controller');
// Prepare default controller
if (!$task && !$controller) {
// If we got view, set it to display controller.
$view = $this->input->get('view');
$task = $view ? $view . '.display' : $this->defaultController;
$this->input->set('task', $task);
$this->input->set('controller', $task);
}
// Register form and fields
\JForm::addFieldPath(WINDWALKER_SOURCE . '/Form/Fields');
\JForm::addFormPath(WINDWALKER_SOURCE . '/Form/Forms');
$this->registerEventListener();
// Register elFinder controllers
// @TODO: Should use event listener
$this->registerTask('finder.elfinder.display', '\\Windwalker\\Elfinder\\Controller\\DisplayController');
$this->registerTask('finder.elfinder.connect', '\\Windwalker\\Elfinder\\Controller\\ConnectController');
// Event
$dispatcher->trigger('onComponentAfterInit', array($this->name, $this, $this->input));
}
示例4: testRegisterServiceProvider
/**
* Test registering a service provider. Make sure register get's called.
*
* @return void
*
* @since 1.0
*/
public function testRegisterServiceProvider()
{
$mock = $this->getMock('Joomla\\DI\\ServiceProviderInterface');
$mock->expects($this->once())->method('register');
$returned = $this->fixture->registerServiceProvider($mock);
$this->assertSame($returned, $this->fixture, 'When registering a service provider, the container instance should be returned.');
}
示例5: __construct
/**
* Instantiate the controller.
*
* @param \Joomla\DI\Container $container DI Container.
* @param IOInterface $io The Controller object.
*/
public function __construct(JoomlaContainer $container = null, IOInterface $io = null)
{
$this->container = $container ?: $this->getContainer();
// Set provider
$container->registerServiceProvider(new ServiceProvider());
parent::__construct($io);
}
示例6: testTheCommandBusHasAnExecuteMethodThatTakesAQueryAsAParameter
/**
* @testdox The modified command bus has an execute method that takes a Query as a parameter
*/
public function testTheCommandBusHasAnExecuteMethodThatTakesAQueryAsAParameter()
{
$this->expectOutputString(sprintf("LOG: Starting %1\$s\nLOG: Ending %1\$s\n", "Joomla\\Tests\\Unit\\Service\\Stubs\\SimpleQuery"));
$container = new Container();
$container->set('EventDispatcher', $this->getMockBuilder(DispatcherInterface::class)->getMock());
$container->set('CommandBusMiddleware', [new LoggingMiddleware(new Logger())]);
$container->registerServiceProvider(new CommandBusServiceProvider());
$commandBus = $container->get('CommandBus');
$this->assertEquals('XSome contentY', $commandBus->handle(new SimpleQuery('Some content')));
}
示例7: initialise
/**
* Custom initialisation method.
*
* Called at the end of the Base::__construct method. This is for developers to inject initialisation code for their application classes.
*
* @return void
*
* @codeCoverageIgnore
* @since 1.0
*/
protected function initialise()
{
// New DI stuff!
$container = new Container();
$input = $this->input;
$container->share('input', function (Container $c) use($input) {
return $input;
}, true);
$container->registerServiceProvider(new Providers\ConfigServiceProvider(TAGALISER_CONFIG));
$container->registerServiceProvider(new Providers\GithubServiceProvider());
$container->registerServiceProvider(new Providers\LoggerServiceProvider());
$container->registerServiceProvider(new Providers\MustacheServiceProvider());
$this->container = $container;
}
示例8: testTheDatabaseServiceProviderIsRegisteredToTheContainer
/**
* @testdox The database service provider is registered to the DI container
*
* @covers Stats\Providers\DatabaseServiceProvider::register
*/
public function testTheDatabaseServiceProviderIsRegisteredToTheContainer()
{
$container = new Container();
$container->registerServiceProvider(new DatabaseServiceProvider());
$this->assertTrue($container->exists('Joomla\\Database\\DatabaseDriver'));
}
示例9: testTheApplicationServiceProviderIsRegisteredToTheContainer
/**
* @testdox The application service provider is registered to the DI container
*
* @covers Stats\Providers\ApplicationServiceProvider::register
*/
public function testTheApplicationServiceProviderIsRegisteredToTheContainer()
{
$container = new Container();
$container->registerServiceProvider(new ApplicationServiceProvider());
$this->assertTrue($container->exists('Stats\\Application'));
}
示例10: testTheConfigServiceProviderIsRegisteredToTheContainer
/**
* @testdox The config service provider is registered to the DI container
*
* @covers Stats\Providers\ConfigServiceProvider::__construct
* @covers Stats\Providers\ConfigServiceProvider::register
*/
public function testTheConfigServiceProviderIsRegisteredToTheContainer()
{
$container = new Container();
$container->registerServiceProvider(new ConfigServiceProvider(APPROOT . '/etc/config.dist.json'));
$this->assertTrue($container->exists('config'));
}