With the default options, the container created is appropriate for the development environment. Example: $builder = new ContainerBuilder(); $container = $builder->build();
Since: 3.2
Author: Matthieu Napoli (matthieu@mnapoli.fr)
コード例 #1
1
ファイル: Environment.php プロジェクト: akentner/incoming-ftp
 /**
  * @param $env
  * @return Container
  */
 public function getContainer($env)
 {
     $container = null;
     $builder = new ContainerBuilder(Container::class);
     //        $builder = new ContainerBuilder();
     foreach (glob(APP_HOME . '/conf/conf.d/*.conf.php') as $filename) {
         $builder->addDefinitions($filename);
     }
     $definitionsEnumFile = APP_HOME . '/conf/config.' . $env . '.php';
     if (file_exists($definitionsEnumFile)) {
         $builder->addDefinitions($definitionsEnumFile);
     }
     $builder->useAnnotations(false);
     $builder->useAutowiring(true);
     switch ($env) {
         case EnvironmentEnum::DEV:
             $builder->setDefinitionCache(new ArrayCache());
             break;
         case EnvironmentEnum::PROD:
         default:
             $cache = $this->getCache();
             $builder->setDefinitionCache($cache);
             $builder->writeProxiesToFile(true, APP_HOME . '/var/cache/proxies');
             break;
     }
     $container = $builder->build();
     return $container;
 }
コード例 #2
0
ファイル: Application.php プロジェクト: air-php/website
 /**
  * Configure the DI container.
  */
 private function configureContainer()
 {
     // Build the DI container.
     $builder = new ContainerBuilder();
     $builder->addDefinitions(__DIR__ . '/config/di.php');
     $this->container = $builder->build();
 }
コード例 #3
0
 protected function createContainer()
 {
     $builder = new ContainerBuilder();
     $builder->setDefinitionCache(new \Doctrine\Common\Cache\ArrayCache());
     $builder->addDefinitions(dirname(__DIR__) . '/DI/config.php');
     $this->container = $builder->build();
 }
コード例 #4
0
ファイル: App.php プロジェクト: vonalbert/Slim-Bridge
 public function __construct()
 {
     $containerBuilder = new ContainerBuilder();
     $containerBuilder->addDefinitions(__DIR__ . '/config.php');
     $container = $containerBuilder->build();
     parent::__construct($container);
 }
コード例 #5
0
ファイル: App.php プロジェクト: butkimtinh/penny
 /**
  * Container compilation.
  *
  * @param mixed $config Configuration file/array.
  *
  * @link http://php-di.org/doc/php-definitions.html
  *
  * @return ContainerInterface
  */
 private function buildContainer($config)
 {
     $builder = new DI\ContainerBuilder();
     $builder->useAnnotations(true);
     $builder->addDefinitions($config);
     return $builder->build();
 }
コード例 #6
0
 /**
  * @inheritDoc
  */
 protected function setUp()
 {
     parent::setUp();
     $builder = new ContainerBuilder();
     $builder->useAutowiring(true);
     $builder->useAnnotations(true);
     $this->container = $builder->build();
 }
コード例 #7
0
ファイル: ConfigTest.php プロジェクト: mnapoli/TwigModule
 private function createContainer($definitions = [])
 {
     $builder = new ContainerBuilder();
     $builder->addDefinitions(__DIR__ . '/../res/config/config.php');
     $builder->addDefinitions([ResourceRepository::class => new InMemoryRepository()]);
     $builder->addDefinitions($definitions);
     return $builder->build();
 }
コード例 #8
0
 private function createContainer(array $definitions = [])
 {
     $builder = new ContainerBuilder();
     $builder->addDefinitions(__DIR__ . '/../../res/config/config.php');
     $builder->addDefinitions([ContainerInterface::class => get(Container::class), Twig_LoaderInterface::class => object(Twig_Loader_Array::class)->constructor([]), ResourceRepository::class => object(NullRepository::class)]);
     $builder->addDefinitions($definitions);
     return $builder->build();
 }
コード例 #9
0
ファイル: PHPDiFactory.php プロジェクト: amir20202000/penny
 /**
  * Initial setup of DI\ContainerBuilder.
  *
  * @param bool $annotation annotation usage.
  *
  * @return DI\ContainerBuilder
  */
 protected static function initialSetupContainerBuilder($annotation)
 {
     $builder = new DI\ContainerBuilder();
     $builder->useAnnotations($annotation);
     $builder->addDefinitions(['request' => ServerRequestFactory::fromGlobals(), 'response' => DI\object(Response::class), 'http_flow_event' => DI\object(ZendHttpFlowEvent::class)->constructor('bootstrap', DI\get('request'), DI\get('response')), 'event_manager' => DI\object(ZendEvmProxy::class), 'dispatcher' => DI\factory(function ($container) {
         return new Dispatcher($container->get('router'), $container);
     })]);
     return $builder;
 }
コード例 #10
0
 public function __invoke(AppBuilder $appBuilder)
 {
     $containerBuilder = new ContainerBuilder();
     $containerBuilder->addDefinitions($appBuilder->getConfigService()->get('php-di'));
     $containerBuilder->addDefinitions([BundleService::class => $appBuilder->getBundleService(), ConfigService::class => $appBuilder->getConfigService()]);
     $container = $containerBuilder->build();
     $container->set(Container::class, $container);
     $appBuilder->setContainer($container);
 }
コード例 #11
0
 public function load(ContainerBuilder $container)
 {
     if (empty($this->sources)) {
         return;
     }
     foreach ($this->sources as $source) {
         $container->addDefinitions($source);
     }
 }
コード例 #12
0
ファイル: App.php プロジェクト: sheerockoff/marabu
 /**
  * Настраиваем контейнер.
  */
 protected function setContainer()
 {
     $builder = new ContainerBuilder();
     $builder->useAnnotations(false);
     if ($this->options['dependencies']) {
         $builder->addDefinitions($this->options['dependencies']);
     }
     $builder->writeProxiesToFile((bool) $this->options['containerProxy'], is_string($this->options['containerProxy']) ? $this->options['containerProxy'] : sys_get_temp_dir());
     $this->container = $builder->build();
 }
コード例 #13
0
 /**
  *
  */
 function __construct()
 {
     // Initialize dependency injection framework.
     $builder = new ContainerBuilder();
     $container = $builder->build();
     $nullOutput = new NullOutput();
     $output = new Output($nullOutput);
     $container->set('Box\\TestScribe\\Output', $output);
     $this->container = $container;
 }
コード例 #14
0
ファイル: DiTest.php プロジェクト: butkimtinh/penny
 public function setUp()
 {
     $this->router = FastRoute\simpleDispatcher(function (FastRoute\RouteCollector $router) {
         $router->addRoute('GET', '/', ['TestApp\\Controller\\Index', 'diTest']);
     });
     $builder = new ContainerBuilder();
     $builder->useAnnotations(true);
     $dic = $builder->build();
     $this->container = $dic;
 }
コード例 #15
0
 /**
  * @param string $token
  * @param string $uri
  */
 public function __construct($token, $uri = 'http://www.ifsistem.com/api/v1')
 {
     $builder = new ContainerBuilder(Container::class);
     $builder->useAnnotations(true);
     $builder->addDefinitions(['sayfa' => \DI\get(SayfaService::class), 'menu' => \DI\get(MenuService::class), 'manset' => \DI\get(MansetService::class), 'haber' => \DI\get(HaberService::class), 'galeri' => \DI\get(GaleriService::class), 'iletisimMesaj' => \DI\get(IletisimMesajService::class), 'site' => \DI\get(SiteService::class), 'sehir' => \DI\get(SehirService::class), 'ilce' => \DI\get(IlceService::class), 'semt' => \DI\get(SemtService::class), 'emlak' => \DI\get(EmlakService::class), 'urun' => \DI\get(UrunService::class), 'kullanici' => \DI\get(KullaniciService::class), 'resim' => \DI\get(ResimService::class), 'reklam' => \DI\get(ReklamService::class), 'siparis' => \DI\get(SiparisService::class), 'sanat' => \DI\get(SanatService::class), 'grup' => \DI\get(GrupService::class), 'reference' => \DI\get(ReferenceService::class), 'api' => function () use($token, $uri) {
         return new ApiService($token, $uri);
     }, ApiService::class => \DI\get('api')]);
     // test
     $this->container = $builder->build();
 }
コード例 #16
0
 public function setUp($useReflection = true, $useAnnotations = true, Cache $cache = null)
 {
     parent::setUp();
     $builder = new ContainerBuilder();
     $builder->useReflection($useReflection)->useAnnotations($useAnnotations);
     if (!is_null($cache)) {
         $builder->setDefinitionCache($cache);
     }
     $this->DIContainer = $builder->build();
     $this->registerMocks();
 }
コード例 #17
0
ファイル: ApplicationTest.php プロジェクト: gianarb/pan
 protected function setUp()
 {
     $config = ['app' => "this is my app", "test" => "prova", "version" => "0.0.1", 'routes' => [['name' => 'hello', 'route' => "--name=", 'short_description' => "Good morning!! This is a beautiful day", "handler" => ['App\\Command\\Hello', 'run']]], "service_manager" => ["invokables" => [], "factories" => []]];
     $builder = new ContainerBuilder();
     $builder->useAnnotations(true);
     $builder->addDefinitions($config);
     $container = $builder->build();
     $configServiceManager = new Config($config['service_manager']);
     $container->set("service_manager", new ServiceManager($configServiceManager));
     $this->application = new Application($config['app'], $config['version'], $config['routes'], Console::getInstance(), new Dispatcher($container));
 }
コード例 #18
0
ファイル: AppLoaderTest.php プロジェクト: butkimtinh/penny
 public function testCorrectInjectionWithExternalContainer()
 {
     $builder = new ContainerBuilder();
     $builder->addDefinitions(Loader::load());
     $builder->useAnnotations(true);
     $app = new App($this->router, $builder->build());
     $request = (new Request())->withUri(new Uri('/load'))->withMethod('GET');
     $response = new Response();
     $response = $app->run($request, $response);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('eureka', $response->getBody()->__toString());
 }
コード例 #19
0
ファイル: PHPDiFactory.php プロジェクト: userlond/penny
 /**
  * Container compilation.
  *
  * @param mixed $config Configuration file/array.
  *
  * @link http://php-di.org/doc/php-definitions.html
  *
  * @return ContainerInterface
  */
 public static function buildContainer($config = [])
 {
     $builder = new DI\ContainerBuilder();
     $builder->useAnnotations(true);
     $builder->addDefinitions(['request' => \Zend\Diactoros\ServerRequestFactory::fromGlobals(), 'response' => DI\object('Zend\\Diactoros\\Response'), 'http_flow_event' => DI\object('Penny\\Event\\HttpFlowEvent')->constructor('bootstrap', DI\get('request'), DI\get('response')), 'event_manager' => DI\object('Zend\\EventManager\\EventManager'), 'dispatcher' => DI\factory(function ($container) {
         return new \Penny\Dispatcher($container->get('router'), $container);
     })]);
     $builder->addDefinitions($config);
     $container = $builder->build();
     $container->set('di', $container);
     return $container;
 }
コード例 #20
0
ファイル: ContainerFactory.php プロジェクト: snipe/Couscous
 /**
  * @return Container
  */
 public function createContainer()
 {
     $builder = new ContainerBuilder();
     $builder->addDefinitions(__DIR__ . '/config.php');
     $moduleConfigs = new Finder();
     $moduleConfigs->files()->in(__DIR__ . '/../Module')->path('/.+/')->name('config.php');
     foreach ($moduleConfigs as $moduleConfig) {
         /** @var SplFileInfo $moduleConfig */
         $builder->addDefinitions($moduleConfig->getPathname());
     }
     return $builder->build();
 }
コード例 #21
0
ファイル: KernelFactory.php プロジェクト: somos/framework
 /**
  * Adds or replaces the service definitions in the given Container Builder with the provided services and
  * parameters.
  *
  * @param callable|array|DefinitionSource|string $configuration a list of services and parameters to load as an array or
  *    Definition Source, or a filename where to load a list of services from.
  * @param ContainerBuilder $builder
  *
  * @link http://php-di.org/ for more information on the format of the Service Definition.
  *
  * @return void
  */
 private function loadConfiguration($configuration, ContainerBuilder $builder)
 {
     if (is_callable($configuration)) {
         $configuration = $configuration();
     }
     if ($configuration === null) {
         return;
     }
     if (is_array($configuration)) {
         $configuration = new DefinitionArray($configuration);
     }
     $builder->addDefinitions($configuration);
 }
コード例 #22
0
ファイル: Application.php プロジェクト: ozag/slim-skeleton
 /**
  * @param ConfigRepository $config
  * @return \DI\Container
  */
 private function initContainer(ConfigRepository $config)
 {
     $builder = new ContainerBuilder();
     // Register ConfigRepository
     $builder->addDefinitions([ConfigRepository::class => $config]);
     // Register container definitions
     $definitions = $config->get('container')['definitions'];
     foreach ($definitions as $definition) {
         $builder->addDefinitions($definition);
     }
     $container = $builder->build();
     return $container;
 }
コード例 #23
0
ファイル: AbstractCase.php プロジェクト: marviktintor/pos-1
 /**
  * Returns the dependency injection container
  *
  * @return \DI\Container
  */
 public function getDiContainer()
 {
     if (!$this->diContainer) {
         $builder = new ContainerBuilder();
         //			$builder->setDefinitionCache(new \Doctrine\Common\Cache\ArrayCache());
         $builder->setDefinitionCache(new FilesystemCache(__DIR__ . '/../../var/Cache/'));
         $builder->addDefinitions(__DIR__ . '/../../Classes/Configuration/dependencyInjectionConfiguration.php');
         $this->diContainer = $builder->build();
         //			$this->diContainer = ContainerBuilder::buildDevContainer();
         $this->diContainer->get('Cundd\\PersistentObjectStore\\Event\\SharedEventEmitter');
     }
     return $this->diContainer;
 }
コード例 #24
0
ファイル: Bootstrap.php プロジェクト: marviktintor/pos-1
 /**
  * Returns the dependency injection container
  *
  * @return \DI\Container
  */
 public function getDiContainer()
 {
     if (!$this->diContainer) {
         $builder = new ContainerBuilder();
         //			$builder->setDefinitionCache(new ArrayCache());
         $builder->setDefinitionCache(new FilesystemCache(ConfigurationManager::getSharedInstance()->getConfigurationForKeyPath('cachePath')));
         $this->diContainer = $builder->build();
         $builder->addDefinitions(__DIR__ . '/Configuration/dependencyInjectionConfiguration.php');
         $this->diContainer = $builder->build();
         //			$this->diContainer = ContainerBuilder::buildDevContainer();
     }
     return $this->diContainer;
 }
コード例 #25
0
 public function setUp()
 {
     $containerBuilder = new ContainerBuilder();
     $containerBuilder->addDefinitions(__DIR__ . '/../../app/config.php');
     $container = $containerBuilder->build();
     $this->checkRepository = $container->get(CheckRepository::class);
     $this->check = new DatabaseCheck();
     $this->exercise = $this->createMock(DatabaseExerciseInterface::class);
     $this->exercise->expects($this->any())->method('getType')->willReturn(ExerciseType::CLI());
     $this->dbDir = sprintf('%s/PhpSchool_PhpWorkshop_Check_DatabaseCheck', str_replace('\\', '/', realpath(sys_get_temp_dir())));
     $this->assertEquals('Database Verification Check', $this->check->getName());
     $this->assertEquals(DatabaseExerciseCheck::class, $this->check->getExerciseInterface());
 }
コード例 #26
0
ファイル: Container.php プロジェクト: jlaso/notify
 /**
  * @throws \Exception
  */
 protected function __construct()
 {
     $builder = new ContainerBuilder();
     $builder->useAutowiring(false);
     $builder->useAnnotations(false);
     $configFile = sprintf(dirname(dirname(dirname(dirname(dirname(__DIR__))))) . '/config/' . self::CONFIG_FILE_PATTERN, self::$env);
     if (!file_exists($configFile)) {
         throw new \Exception(sprintf("The config file expected '%s' doesn't exist", $configFile));
     }
     $builder->addDefinitions($configFile);
     $container = $builder->build();
     self::$instance = $container;
 }
コード例 #27
0
ファイル: Environment.php プロジェクト: akentner/incoming-ftp
 /**
  * @param $env
  * @return \DI\Container
  */
 public function getContainer($env)
 {
     $builder = new ContainerBuilder();
     foreach (glob(APP_HOME . '/conf/conf.d/*.conf.php') as $filename) {
         $builder->addDefinitions($filename);
     }
     $builder->addDefinitions(APP_HOME . '/conf/config.' . $env . '.php');
     switch ($env) {
         case EnvironmentEnum::DEV:
             $builder->setDefinitionCache(new ArrayCache());
             break;
         case EnvironmentEnum::PROD:
             $redis = new Redis();
             $redis->pconnect('localhost');
             $redis->setOption(Redis::OPT_PREFIX, 'homeservice:cache:di:');
             $cache = new RedisCache();
             $cache->setRedis($redis);
             $builder->setDefinitionCache($cache);
             $builder->writeProxiesToFile(true, APP_HOME . '/var/cache/proxies');
             break;
     }
     $builder->useAnnotations(true);
     $container = $builder->build();
     return $container;
 }
コード例 #28
0
 /**
  * @test
  */
 public function shows_error_page_with_dev_environment()
 {
     $containerBuilder = new ContainerBuilder();
     $containerBuilder->addDefinitions(__DIR__ . '/../res/config/config.php');
     $containerBuilder->addDefinitions(__DIR__ . '/../res/config/env/dev.php');
     $container = $containerBuilder->build();
     /** @var ErrorHandlerMiddleware $middleware */
     $middleware = $container->get(ErrorHandlerMiddleware::class);
     $response = $middleware->__invoke(new ServerRequest(), function () {
         throw new \Exception('Hello world');
     });
     $this->assertContains('Error', (string) $response->getBody());
     $this->assertContains('Hello world', (string) $response->getBody());
 }
コード例 #29
0
ファイル: PHPDIAdapterTest.php プロジェクト: njasm/container
 public function testDIMultiInstance()
 {
     $key1 = 'hello';
     $value1 = 'world';
     $key2 = 'Night';
     $value2 = 'all';
     //register key1 in first instance, key2 in second instance
     $this->phpDI->set($key1, $value1);
     $builder = new ContainerBuilder();
     $phpDi = $builder->build();
     $phpDi->set($key2, $value2);
     $adapter = new PHPDIAdapter($phpDi);
     $this->container->provider($adapter);
     $this->assertEquals($value1, $this->container->get($key1));
     $this->assertEquals($value2, $this->container->get($key2));
 }
コード例 #30
0
 /**
  * Executes the current command.
  *
  * @param InputInterface  $input An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return null|integer null or 0 if everything went fine, or an error code
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Initialize dependency injection framework.
     $builder = new ContainerBuilder();
     $container = $builder->build();
     $container->set('Symfony\\Component\\Console\\Output\\OutputInterface', $output);
     // Make sure App class is initialized before calling the bootstrap script.
     // The presence of this class sends a signal to the code executing later
     // that this execution is for generating tests.
     App::setOutput($output);
     /**
      * @var EngineStarter $engineStarter
      */
     $engineStarter = $container->get("Box\\TestScribe\\EngineStarter");
     $engineStarter->configAndStart($input, $output);
     return 0;
 }