Move CLI app to use DIC.

This commit is contained in:
Marco Vito Moscaritolo 2015-05-31 11:01:40 +02:00
parent 3eb1648e13
commit 063bec407d
3 changed files with 63 additions and 25 deletions

24
console
View file

@ -12,29 +12,9 @@ define('PHPCI_IS_CONSOLE', true);
require('bootstrap.php');
use PHPCI\Command\RunCommand;
use PHPCI\Command\RebuildCommand;
use PHPCI\Command\GenerateCommand;
use PHPCI\Command\UpdateCommand;
use PHPCI\Command\InstallCommand;
use PHPCI\Command\DaemonCommand;
use PHPCI\Command\PollCommand;
use PHPCI\Command\CreateAdminCommand;
use PHPCI\Command\CreateBuildCommand;
use PHPCI\Service\BuildService;
use Symfony\Component\Console\Application;
use b8\Store\Factory;
$application = new Application();
$application->add(new RunCommand($loggerConfig->getFor('RunCommand')));
$application->add(new RebuildCommand($loggerConfig->getFor('RunCommand')));
$application->add(new InstallCommand);
$application->add(new UpdateCommand($loggerConfig->getFor('UpdateCommand')));
$application->add(new GenerateCommand);
$application->add(new DaemonCommand($loggerConfig->getFor('DaemonCommand')));
$application->add(new PollCommand($loggerConfig->getFor('PollCommand')));
$application->add(new CreateAdminCommand(Factory::getStore('User')));
$application->add(new CreateBuildCommand(Factory::getStore('Project'), new BuildService(Factory::getStore('Build'))));
/** @var Application */
$application = $container->get('console.application');
$application->run();

View file

@ -1,6 +1,8 @@
parameters:
config_file: ./../PHPCI/config.yml
storage.factory: b8\Store\Factory
application.name: PHPCI
application.version: 1.7-dev
config_file: PHPCI/config.yml
storage.factory: b8\Store\Factory
services:
storage.user:
@ -35,3 +37,59 @@ services:
application:
class: PHPCI\Application
arguments: [@config, @http.request, @http.response, @storage.user, @storage.project]
build:
class: PHPCI\Service\BuildService
arguments: [@storage.build]
console.application:
class: Symfony\Component\Console\Application
arguments:
- %application.name%
- %application.version%
calls:
- [add, ['@console.command.run']]
- [add, ['@console.command.rebuild']]
- [add, ['@console.command.install']]
- [add, ['@console.command.update']]
- [add, ['@console.command.generate']]
- [add, ['@console.command.daemon']]
- [add, ['@console.command.poll']]
- [add, ['@console.command.create_admin']]
- [add, ['@console.command.create_build']]
console.logger:
class: Monolog\Logger
arguments:
- cli
console.command.run:
class: PHPCI\Command\RunCommand
arguments:
- @console.logger
console.command.rebuild:
class: PHPCI\Command\RebuildCommand
arguments:
- @console.logger
console.command.update:
class: PHPCI\Command\UpdateCommand
arguments:
- @console.logger
console.command.daemon:
class: PHPCI\Command\DaemonCommand
arguments:
- @console.logger
console.command.poll:
class: PHPCI\Command\PollCommand
arguments:
- @console.logger
console.command.create_admin:
class: PHPCI\Command\CreateAdminCommand
arguments:
- @storage.user
console.command.create_build:
class: PHPCI\Command\CreateBuildCommand
arguments:
- @storage.project
- @build
console.command.install:
class: PHPCI\Command\InstallCommand
console.command.generate:
class: PHPCI\Command\GenerateCommand

View file

@ -2,7 +2,7 @@
// Define our APPLICATION_PATH, if not already defined:
if (!defined('APPLICATION_PATH')) {
define('APPLICATION_PATH', dirname(__FILE__) . '/');
define('APPLICATION_PATH', __DIR__ . '/');
define('PHPCI_DIR', APPLICATION_PATH);
}