/** * @param ConfiguratorInterface $configurator * @param ContainerInterface $container */ public function __construct(ConfiguratorInterface $configurator, ContainerInterface $container) { $this->modules = $configurator->getConfig('modules'); $this->container = $container; foreach ($this->modules as $module) { foreach ($module['bindings'] as $alias => $resolver) { $this->container->bind($alias, $resolver); } //Some modules may request initialization if ($module['bootstrap']) { $this->container->get($module['class'])->bootstrap(); } } }
/** * {@inheritdoc} */ public function start() { //Some console commands utilizes benchmarking, let's help them $this->container->bind(BenchmarkerInterface::class, Debugger::class); //Let's disable loader in console mode $this->loader->disable(); $this->application()->run(); }
/** * {@inheritdoc} */ public function start(ConsoleHandler $handler = null) { //Some console commands utilizes benchmarking, let's help them $this->container->bind(BenchmarkerInterface::class, Debugger::class); $output = new ConsoleOutput(); $this->debugger->shareHandler($this->consoleHandler($output)); $scope = $this->container->replace(LogsInterface::class, $this->debugger); try { $this->application()->run(null, $output); } finally { $this->container->restore($scope); } }
/** * @param Debugger $debugger * @param ORM $orm * @param ContainerInterface $container * @param ClassLocator $locator */ public function perform(Debugger $debugger, ORM $orm, ContainerInterface $container, ClassLocator $locator) { //We don't really need location errors here $locator->setLogger(new NullLogger()); $benchmark = $debugger->benchmark($this, 'update'); $builder = $orm->schemaBuilder($locator); //To make builder available for other commands (in sequence) $container->bind(get_class($builder), $builder); if (!$this->option('sync')) { $this->writeln("<comment>Silent mode on, no databases to be altered.</comment>"); } $orm->updateSchema($builder, $this->option('sync')); $elapsed = number_format($debugger->benchmark($this, $benchmark), 3); $countModels = count($builder->getRecords()); $this->write("<info>ORM Schema has been updated: <comment>{$elapsed} s</comment>"); $this->writeln(", found records: <comment>{$countModels}</comment></info>"); }
/** * Bind declared bindings. * * @param ContainerInterface $container * @param array $bootSchema */ protected function initBindings(ContainerInterface $container, array $bootSchema) { foreach ($bootSchema['bindings'] as $aliases => $resolver) { $container->bind($aliases, $resolver); } foreach ($bootSchema['singletons'] as $aliases => $resolver) { $container->bindSingleton($aliases, $resolver); } }