/**
  * @testdox The existence of a resource can be checked
  */
 public function testExists()
 {
     $container = new Container();
     $container->set('foo', 'bar');
     $this->assertTrue($container->has('foo'), "'foo' should be present");
     $this->assertFalse($container->has('baz'), "'baz' should not be present");
 }
Пример #2
0
 /**
  * @testdox has() also resolves the alias if set.
  */
 public function testExistsResolvesAlias()
 {
     $container = new Container();
     $container->set('foo', function () {
         return new \stdClass();
     }, true, true)->alias('bar', 'foo');
     $this->assertTrue($container->has('foo'), "Original 'foo' was not resolved");
     $this->assertTrue($container->has('bar'), "Alias 'bar' was not resolved");
 }
 /**
  * @param   Container  $container  The container
  *
  * @return  \Joomla\Service\CommandBus
  */
 public function createCommandBus(Container $container)
 {
     // Construct the command handler middleware
     $middleware = [];
     if ($container->has('CommandBusMiddleware')) {
         $middleware = (array) $container->get('CommandBusMiddleware');
     }
     if ($container->has('extension_factory')) {
         $middleware[] = new ExtensionQueryMiddleware($container->get('extension_factory'));
     }
     $builder = new CommandBusBuilder($container->get('EventDispatcher'));
     $middleware = array_merge($middleware, $builder->getMiddleware());
     $builder->setMiddleware($middleware);
     return $builder->getCommandBus();
 }
Пример #4
0
 /**
  * @testdox Container can manage an alias for a resource from an arbitrary Interop compatible container
  */
 public function testDecorateArbitraryInteropContainerAlias()
 {
     $container = new Container(new \ArbitraryInteropContainer());
     $container->alias('foo', 'aic_foo');
     $this->assertTrue($container->has('foo'), "Container does not know alias 'foo'");
     $this->assertEquals('aic_foo_content', $container->get('foo'), "Container does not return the correct value for alias 'foo'");
 }
 /**
  * Add the configuration from the environment to a container
  *
  * @param   Container $container The container
  * @param   string    $alias     An optional alias, defaults to 'config'
  *
  * @return  void
  */
 public function register(Container $container, $alias = 'config')
 {
     $file = '.env';
     if ($container->has('ConfigFileName')) {
         $file = $container->get('ConfigFileName');
     }
     $dotenv = new Dotenv($container->get('ConfigDirectory'), $file);
     $dotenv->overload();
     $container->set($alias, new Registry($_ENV), true);
 }
Пример #6
0
    /**
     * @testdox Loading an invalid class
     */
    public function testLoadWithInvalidClass()
    {
        $content = <<<EOF
[providers]
foo = "\\NotAvailableServiceProvider"
EOF;
        $container = new Container();
        $loader = new IniLoader($container);
        $loader->load($content);
        $this->assertFalse($container->has('foo'));
    }
 /**
  * Creates a RepositoryFactory
  *
  * @param   Container $container The container
  *
  * @return  RepositoryFactory
  */
 public function createRepositoryFactory(Container $container)
 {
     $config = parse_ini_file(JPATH_ROOT . '/config/database.ini', true);
     $configuration = new Configuration();
     // Add logger
     $logger = new DebugStack();
     $configuration->setSQLLogger($logger);
     $connection = DriverManager::getConnection(['url' => $config['databaseUrl']], $configuration);
     $transactor = new DoctrineTransactor($connection);
     $repositoryFactory = new RepositoryFactory($config, $connection, $transactor);
     if ($container->has('dispatcher')) {
         $repositoryFactory->setDispatcher($container->get('dispatcher'));
     }
     return $repositoryFactory;
 }