share(function () use ($name, $version) { return new Console\Application($name, $version); }); $this['dispatcher'] = $this->share( $this->extend('dispatcher', function (EventDispatcher $dispatcher, Application $app) { $dispatcher->addListener('phraseanet.notification.sent', function () use ($app) { $app['swiftmailer.spooltransport']->getSpool()->flushQueue($app['swiftmailer.transport']); }); $dispatcher->addSubscriber(new BridgeSubscriber($app)); return $dispatcher; }) ); $this->register(new PluginServiceProvider()); $this->register(new ComposerSetupServiceProvider()); $this->register(new CLIDriversServiceProvider()); $this->register(new SignalHandlerServiceProvider()); $this->register(new TaskManagerServiceProvider()); $this->register(new TranslationExtractorServiceProvider()); $this->register(new DoctrineMigrationServiceProvider()); $this->bindRoutes(); $logger = false; if ($this['configuration.store']->isSetup()){ $config = $this['configuration.store']->getConfig(); if ((isset($config['console_logger_enabled_environments']) && in_array($environment, $config['console_logger_enabled_environments']))){ $logger = true; } } if ($environment == self::ENV_DEV){ $logger = true; } if ($logger){ $this['logger'] = $this->extend('logger', function () { return new Console\Logger\ConsoleLogger(new Console\Output\ConsoleOutput(Console\Output\ConsoleOutput::VERBOSITY_DEBUG)); }); } error_reporting(-1); ErrorHandler::register(); PhraseaCLIExceptionHandler::register(); } /** * Executes this application. * * @param bool $interactive runs in an interactive shell if true. */ public function runCLI($interactive = false) { $this->boot(); $app = $this['console']; if ($interactive) { $app = new Console\Shell($app); } $app->run(); } public function boot() { parent::boot(); $this['console']->setDispatcher($this['dispatcher']); } public function run(\Symfony\Component\HttpFoundation\Request $request = null) { if (null !== $request) { throw new RuntimeException('Phraseanet Konsole can not run Http Requests.'); } $this->runCLI(); } /** * Adds a command object. * * If a command with the same name already exists, it will be overridden. * * @param Command|CommandInterface $command A Command object */ public function command($command) { if ($command instanceof CommandInterface) { $command->setContainer($this); } $this['console']->add($command); } /** * {@inheritdoc} */ public function loadPlugins() { parent::loadPlugins(); call_user_func(function ($cli) { if (file_exists($cli['plugin.path'] . '/commands.php')) { require $cli['plugin.path'] . '/commands.php'; } }, $this); } }