/** * Initialize the DIC. */ protected function initialize() { $this->container = new Container(); $containerProvider = new ContainerProvider($this->disabledMethods, $this->disabledFormats); $this->container->register($containerProvider); $this->initialized = false; }
/** * @param Container $container A Pimple DI container. * @return void */ public function register(Container $container) { $container->register(new DashboardServiceProvider()); $container->register(new FormServiceProvider()); $container->register(new LayoutServiceProvider()); $container->register(new MenuServiceProvider()); }
public function testCreateTemplating() { $pimple = new Container(['debug' => false, 'charset' => '']); $pimple->register(new TwigEngineServiceProvider()); $pimple->register(new TwigServiceProvider()); $this->assertInstanceOf(TwigEngine::class, $pimple['templating']); }
/** * @param array $providers */ public function __construct(array $providers) { $this->container = new PimpleContainer(); foreach ($providers as $provider) { $this->container->register($provider); } }
protected function execute(InputInterface $input, OutputInterface $output) { /** * set context inside container */ $this->container->register(new LoggerProvider($output)); try { /** @var LoggerInterface $logger */ $logger = $this->container['logger']; $connection = ['host' => $input->getArgument('host'), 'port' => $input->getArgument('port'), 'user' => $input->getArgument('username'), 'password' => $input->getArgument('password')]; $client = $this->container['curl_client_factory']->createClient($connection); $queueManager = $this->container['manager_rabbitmq_queue']; $exchangeManager = $this->container['manager_rabbitmq_exchange']; $policygeManager = $this->container['manager_rabbitmq_policy']; $manager = new DeleteManager($exchangeManager, $queueManager, $policygeManager, $logger); if ($input->hasOption('queues') && null !== $input->getOption('queues')) { $queueManager->setClient($client); $manager->deleteQueues($input->getOption('vhost'), $input->getOption('queues')); } if ($input->hasOption('exchanges') && null !== $input->getOption('exchanges')) { $exchangeManager->setClient($client); $manager->deleteExchanges($input->getOption('vhost'), $input->getOption('exchanges')); } if ($input->hasOption('policies') && null !== $input->getOption('policies')) { $policygeManager->setClient($client); $manager->deletePolicies($input->getOption('vhost'), $input->getOption('policies')); } } catch (\Exception $e) { $logger->critical($e->getMessage()); return 1; } return 0; }
public function testDump() { $container = new Container(); $container['debug'] = false; $container['charset'] = 'utf-8'; $logger = $this->getLogger(); $container['logger'] = $logger; $container->register(new TwigServiceProvider()); $twigPath = $this->getTwigPath(); $container['twig.loader.filesystem'] = $container->extend('twig.loader.filesystem', function (\Twig_Loader_Filesystem $twigLoaderFilesystem) use($twigPath) { $twigLoaderFilesystem->addPath($twigPath, 'SaxulumAsseticTwig'); return $twigLoaderFilesystem; }); $container->register(new AsseticTwigProvider(), array('assetic.asset.root' => $this->getFixturesPath(), 'assetic.asset.asset_root' => $this->getAssetPath())); /** @var Dumper $dumper */ $dumper = $container['assetic.asset.dumper']; $dumper->dump(); if (count($logger->entries)) { var_dump($logger->entries); } $this->assertCount(0, $logger->entries); $this->fileComparsion('css/test-copyfile.css'); $this->fileComparsion('image/test.png'); $this->fileComparsion('css/test-less.css'); $this->fileComparsion('css/test-scss.css'); $this->fileComparsion('css/test-cssmin.css'); $this->fileComparsion('css/test-csscompress.css'); $this->fileComparsion('js/test.js'); }
/** * @test */ public function shouldReturnTheCommands() { $app = new Container(); $app->register(new DoctrineServiceProvider()); $app->register(new ConsoleServiceProvider()); $app->register(new DoctrineMigrationsServiceProvider(), ['migrations.options' => ['name' => 'Doctrine Migrations', 'namespace' => 'DoctrineMigrations', 'table_name' => 'doctrine_migration_versions', 'directory' => sys_get_temp_dir()]]); $this->assertCount(5, $app['console']->all('migrations')); }
/** * Registers a service provider. * * @param \Pimple\ServiceProviderInterface $provider A ServiceProviderInterface instance * @param array $values An array of values that customizes the provider * @return \Pimple\Container */ public function register(ServiceProviderInterface $provider, array $values = []) { $this->container->register($provider, $values); // register event subcriber if ($provider instanceof EventSubscriberInterface) { $this->eventSubscribers[] = $provider; } return $this; }
/** * @return \Pimple\Container */ public static function getApplication() { if (!self::$application) { self::$application = new \Pimple\Container(); self::$application->register(new Providers\DefaultObjectProvider()); self::$application->register(new Providers\ApplicationParametersProvider()); } return self::$application; }
/** * Register the ServiceProvider in the container. * * @return Container */ public function compile() { if (!$this->compiled) { $this->compiled = true; $this->container->register(new ServiceProvider(), $this->config); $this->container->offsetGet('console')->addCommands($this->commands); } return $this->container; }
public function setUp() { $_SERVER['ENV'] = 'test'; $path = ROOT . '/test/resources/'; $provider = new ConfigurationProvider(); $this->container = new Container(); $this->container['config.driver'] = new IniDriver($path); $this->container->register($provider); }
public function createApplication() { $app = new Container(); $app['debug'] = true; $app->register(new ValidatorServiceProvider()); $app->register(new DoctrineServiceProvider(), array('db.options' => array('driver' => 'pdo_sqlite', 'path' => $this->getCacheDir() . '/app.db'))); $app->register(new DoctrineOrmServiceProvider(), array('orm.proxies_dir' => $this->getCacheDir() . '/doctrine/proxies', 'orm.em.options' => array('mappings' => array(array('type' => 'annotation', 'namespace' => 'Saxulum\\Tests\\DoctrineOrmManagerRegistry\\Entity', 'path' => __DIR__ . '/../Entity', 'use_simple_annotation_reader' => false))))); $app->register(new DoctrineOrmManagerRegistryProvider()); return $app; }
protected function execute(InputInterface $input, OutputInterface $output) { /** * set context inside container */ $this->container->register(new LoggerProvider($output)); $parser = new ParseExpertConfig(); $parser->parse($input->getArgument('configFile')); $this->container['logger']->info('<info>File don\'t show errors.</info>'); }
public function getContainer() { $container = new Container(); $container['debug'] = true; $container->register(new ValidatorServiceProvider()); $container->register(new DoctrineMongoDbProvider(), array('mongodb.options' => array('server' => 'mongodb://localhost:27017'))); $container->register(new DoctrineMongoDbOdmProvider(), array("mongodbodm.proxies_dir" => $this->getCacheDir() . '/doctrine/proxies', "mongodbodm.hydrator_dir" => $this->getCacheDir() . '/doctrine/hydrator', 'mongodbodm.dm.options' => array('mappings' => array(array('type' => 'annotation', 'namespace' => 'Saxulum\\Tests\\DoctrineMongodbOdmManagerRegistry\\Document', 'path' => __DIR__ . '/../Document', 'use_simple_annotation_reader' => false))))); $container->register(new DoctrineMongodbOdmManagerRegistryProvider()); return $container; }
/** * @test */ public function register() { $app = new Container(); $app->register(new ValidatorServiceProvider()); $app->register(new DoctrineServiceProvider()); $app->register(new DoctrineCacheServiceProvider()); $app->register(new DoctrineOrmServiceProvider()); $app->register(new DoctrineManagerRegistryServiceProvider()); $this->assertArrayHasKey('doctrine', $app); }
public function register(Container $app) { if (class_exists('Symfony\\Component\\Config\\ConfigCache') and class_exists('Symfony\\Component\\Form\\Form')) { $app->register(new CsrfServiceProvider()); $app->register(new SilexFormServiceProvider()); $app->register(new ValidatorServiceProvider()); return; } throw new IncompleteFormServiceRequirement('You must install the `symfony/config` and `symfony/form` packages to use Core Form Service Providers.'); }
/** * @param Container $app */ public function register(Container $app) { $app->register(new SecurityServiceProvider(), $this->config['auth']); $app['security.encoder.digest'] = function () use($app) { return new UserPasswordEncoder($app['security.encoder_factory']); }; $app['security.utils'] = function ($app) { return new AuthenticationUtils($app['request_stack']); }; $app->register(new RememberMeServiceProvider()); // note: use `formula nine:password <password>` command to generate a password hash. }
protected function setUp() { parent::setUp(); $this->client = $this->getMockBuilder('Metfan\\RabbitSetup\\Http\\CurlClient')->disableOriginalConstructor()->getMock(); $clientFactory = $this->getMock('Metfan\\RabbitSetup\\Factory\\CurlClientFactory'); $clientFactory->expects($this->any())->method('createClient')->willReturn($this->client); $container = new Container(); $container->register(new HttpClientProvider()); $container->register(new RabbitMQManagerProvider()); $container['curl_client_factory'] = $clientFactory; $this->command = new DeleteCommand($container); }
/** * @param string $env */ public function __construct($env) { $this->registerErrorHandler(); parent::__construct('Shopware Installer', '1.0.0'); $config = (require __DIR__ . '/../../config/' . $env . '.php'); $this->container = new Container(); $this->container->register(new ContainerProvider($config)); $this->getDefinition()->addOption(new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', $env)); $command = new InstallCommand(); $this->add($command); $this->setDefaultCommand($command->getName()); }
/** * @test */ public function register() { $app = new Container(); $app->register(new ConsoleServiceProvider()); $app->register(new DoctrineServiceProvider()); $app->register(new DoctrineCacheServiceProvider()); $app->register(new DoctrineOrmServiceProvider()); $app->register(new DoctrineConsoleServiceProvider()); $app['orm.proxy_dir'] = sys_get_temp_dir(); $app['orm.proxy_namespace'] = 'Acme\\Entity'; $this->assertInstanceOf(ConsoleApplication::class, $app['console']); $this->assertInstanceOf(InfoCommand::class, $app['console']->get('orm:info')); }
/** * @param Container $container */ public function register(Container $container) { $container["security.jwt"] = $container["config"]->get("jwt"); $container->register(new SecurityJWTServiceProvider()); $container->register(new SecurityServiceProvider()); $container["security.firewalls"] = $container["config"]->get("firewall"); /** * alias for auto injection */ $container[SecurityContext::class] = function () use($container) { return $container["security"]; }; }
public function register(Container $app) { $config = $this->config; // optionally include the Blade templating engine. if ($config['view.blade.enabled'] && class_exists(BladeViewServiceProvider::class)) { $app->register(new BladeViewServiceProvider($this->app)); $this->app->bootProvider(BladeViewServiceProvider::class); } // optionally include the Twig templating engine if ($config['view.twig.enabled'] && class_exists(TwigViewServiceProvider::class)) { $app->register(new TwigViewServiceProvider($this->app)); $app['twig.options'] = $config['view.twig.defaults.options']; $app['twig.form.templates'] = $config['view.twig.defaults.form.templates']; $app['twig.path'] = $config['view.twig.defaults.filesystem']; $app['twig.templates'] = $config['view.twig.defaults.templates']; $this->app->bootProvider(TwigViewServiceProvider::class); $app['twig'] = $app->extend('twig', function ($twig, $app) { // during normal routing, the current request is non-NULL. // however, there are test conditions under which we still need // access to the base path, so here we cover that use case. $current_request = $app['request_stack']->getCurrentRequest(); $base_path = $current_request ? $current_request->getBasePath() : ''; // add the `asset` function for twig // The asset function takes a path to a resource based on the ASSETS constant path. $twig->addFunction(new \Twig_SimpleFunction('asset', function ($asset) use($app, $base_path) { $base = $base_path . ASSETS; return sprintf($base . $asset, ltrim($asset, '/')); })); // The asset function takes a path to a resource based on the ASSETS constant path. $twig->addFunction(new \Twig_SimpleFunction('image', function ($asset) use($app, $base_path) { $base = $base_path . IMAGES; return sprintf($base . $asset, ltrim($asset, '/')); })); // The asset function takes a path to a resource based on the ASSETS constant path. $twig->addFunction(new \Twig_SimpleFunction('script', function ($asset) use($app, $base_path) { $base = $base_path . SCRIPTS; return sprintf($base . $asset, ltrim($asset, '/')); })); // The asset function takes a path to a resource based on the ASSETS constant path. $twig->addFunction(new \Twig_SimpleFunction('style', function ($asset) use($app, $base_path) { $base = $base_path . STYLESHEETS; return sprintf($base . $asset, ltrim($asset, '/')); })); // The asset function takes a path to a resource based on the ASSETS constant path. $twig->addFunction(new \Twig_SimpleFunction('glyph', function ($glyph) use($app) { return "<span class='glyphicon glyphicon-{$glyph}'></span>"; })); return $twig; }); } }
/** * Initializes needed but yet missing service providers. * * @param Container $app * the application container */ protected function initMissingServiceProviders(Container $app) { if (!$app->offsetExists('translator')) { $app->register(new LocaleServiceProvider()); $app->register(new TranslationServiceProvider(), ['locale_fallbacks' => ['en']]); } if (!$app->offsetExists('session')) { $app->register(new SessionServiceProvider()); } if (!$app->offsetExists('twig')) { $app->register(new TwigServiceProvider()); $app['twig.loader.filesystem']->addPath(__DIR__ . '/../views/', 'crud'); } }
/** * @param Container|Application $app */ public function register(Container $app) { if (!$app->offsetExists('annot.useServiceControllers')) { $app['annot.useServiceControllers'] = true; } $app["annot"] = function (Container $app) { return new AnnotationService($app); }; // A custom auto loader for Doctrine Annotations since it can't handle PSR-4 directory structure AnnotationRegistry::registerLoader(function ($class) { return class_exists($class); }); // Register ServiceControllerServiceProvider here so the user doesn't have to. if ($app['annot.useServiceControllers']) { $app->register(new ServiceControllerServiceProvider()); } // this service registers the service controller and can be overridden by the user $app['annot.registerServiceController'] = $app->protect(function ($controllerName) use($app) { if ($app['annot.useServiceControllers']) { $app["{$controllerName}"] = function (Application $app) use($controllerName) { return new $controllerName($app); }; } }); $app['annot.controllerFinder'] = $app->protect(function (Application $app, $dir) { return $app['annot']->getFiles($dir, $app['annot.controllerNamespace']); }); /** @noinspection PhpUnusedParameterInspection */ $app['annot.controller_factory'] = $app->protect(function (Application $app, $controllerName, $methodName, $separator) { return $controllerName . $separator . $methodName; }); $app['annot.controllerNamespace'] = ''; }
/** * @expectedException LogicException */ public function testRegisterMissingMetadata() { $app = new Container(); $app->register(new MondatorServiceProvider()); $app['mongator.metadata.class'] = 'Model\\Mapping\\Metadata'; $app['mondator']; }
public function testConfigurationNotExists() { $c = new Container(); $c->register(new MySQLiServiceProvider()); $this->setExpectedException('\\LogicException', 'mysqli.configuration is not defined'); $c['mysqli']; }
protected function execute(InputInterface $input, OutputInterface $output) { $this->container->register(new LoggerProvider($output)); $this->container['http_client_pool']->overrideUser($input->getOption('user'))->overridePassword($input->getOption('password')); try { $logger = $this->container['logger']; $parser = new ParseExpertConfig(); $config = $parser->parse($input->getArgument('configFile')); $manager = new ConfigExpertManager($this->container['http_client_pool'], $this->container['manager_rabbitmq_vhost'], $logger); $manager->manageConfig($config); } catch (\Exception $e) { $logger->critical($e->getMessage()); return 1; } return 0; }
/** * {@inheritdoc} */ public function register(ServiceProviderInterface $provider, array $values = array()) { // Não pode ser "elseif" pois um provider pode ser ao mesmo // tempo todos os tipos de provider if ($provider instanceof BootableProviderInterface) { if (!isset($this->bootableProviders[$provider->getPriority()])) { $this->bootableProviders[$provider->getPriority()] = array(); } $this->bootableProviders[$provider->getPriority()][] = $provider; } if ($provider instanceof RouteProviderInterface) { $this->routeProviders[] = $provider; } if ($provider instanceof SubscriberProviderInterface) { $this->subscribeProviders[] = $provider; } if ($provider instanceof DoctrineSubscriberProviderInterface) { $this->doctrineSubscribeProviders[] = $provider; } if ($provider instanceof TwigExtensionableProviderInterface) { $this->twigExtensionsProviders[] = $provider; } if ($provider instanceof FormExtensionableProviderInterface) { $this->formExtensionsProviders[] = $provider; } parent::register($provider, $values); return $this; }
/** * @param Container $container */ public function register(Container $container) { if (!$container instanceof Application) { throw new \InvalidArgumentException("invalid application"); } /** * pimple aware event dispatcher */ $container->register(new PimpleAwareEventDispatcherServiceProvider()); /** * alias for auto injection */ $container[PimpleAwareEventDispatcher::class] = function () use($container) { return $container["dispatcher"]; }; /** * register default event subscriber */ $container->registerSubscriber(ExceptionHandler::class, function () use($container) { return new ExceptionHandler($container["config"], $container["monolog"]); }); $container->registerSubscriber(CliExceptionHandler::class, function () use($container) { return new CliExceptionHandler($container["config"], $container["monolog"]); }); }
public function test() { $container = new Container(); $container->register(new HttpClientProvider()); $this->assertInstanceOf('Metfan\\RabbitSetup\\Factory\\CurlClientFactory', $container['curl_client_factory']); $this->assertInstanceOf('Metfan\\RabbitSetup\\Http\\ClientPool', $container['http_client_pool']); }