diff --git a/composer.json b/composer.json index a3a5c6ace..4612a9955 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,6 @@ "kukulich/fshl": "~2.1", "michelf/php-markdown": "~1.4", - "kdyby/events": "~2.0", "symfony/options-resolver": "~2.6.1", "symfony/console": "~2.6", "symfony/yaml": "~2.6", @@ -29,8 +28,9 @@ "apigen/theme-default": "1.0.*", "apigen/theme-bootstrap": "1.1.*", - "apigen/utils": "0.1.*", - "apigen/parser": "0.1.*" + "apigen/event-dispatcher": "0.1.*", + "apigen/parser": "0.1.*", + "apigen/utils": "0.1.*" }, "require-dev": { "mockery/mockery": "~0.9", diff --git a/src/ApiGen.php b/src/ApiGen.php index 0937636af..43230b406 100644 --- a/src/ApiGen.php +++ b/src/ApiGen.php @@ -18,4 +18,13 @@ class ApiGen */ const VERSION = '4.2.0-dev'; + + /** + * @return string + */ + public function getVersion() + { + return self::VERSION; + } + } diff --git a/src/Console/Application.php b/src/Console/Application.php index fa692300e..d9d06308c 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -12,9 +12,7 @@ use ApiGen\ApiGen; use ApiGen\Console\Input\LiberalFormatArgvInput; use ApiGen\MemoryLimit; -use Kdyby\Events\EventArgsList; -use Kdyby\Events\EventManager; -use Symfony; +use Symfony\Component\Console\Application as BaseApplication; use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Formatter\OutputFormatterStyle; use Symfony\Component\Console\Input\InputArgument; @@ -25,37 +23,16 @@ use Symfony\Component\Console\Output\OutputInterface; -class Application extends Symfony\Component\Console\Application +class Application extends BaseApplication { - /** - * @var array - */ - public $onRun = []; - - /** - * @var EventManager - */ - private $eventManager; - - /** * {@inheritDoc} */ - public function __construct() - { - parent::__construct('ApiGen', ApiGen::VERSION); - (new MemoryLimit)->setMemoryLimitTo('1024M'); - } - - - /** - * {@inheritdoc} - */ - public function doRun(InputInterface $input, OutputInterface $output) + public function __construct(ApiGen $apiGen, MemoryLimit $memoryLimit) { - $this->onRun($input, $output); - return parent::doRun($input, $output); + parent::__construct('ApiGen', $apiGen->getVersion()); + $memoryLimit->setMemoryLimitTo('1024M'); } @@ -73,12 +50,6 @@ public function run(InputInterface $input = NULL, OutputInterface $output = NULL } - public function setEventManager(EventManager $eventManager) - { - $this->eventManager = $eventManager; - } - - /** * @return array */ @@ -103,10 +74,4 @@ protected function getDefaultInputDefinition() ]); } - - private function onRun(InputInterface $input, OutputInterface $output) - { - $this->eventManager->dispatchEvent(__METHOD__, new EventArgsList([$input, $output])); - } - } diff --git a/src/Console/Event/ConsoleCommandEvent.php b/src/Console/Event/ConsoleCommandEvent.php new file mode 100644 index 000000000..64eded501 --- /dev/null +++ b/src/Console/Event/ConsoleCommandEvent.php @@ -0,0 +1,34 @@ +name = $name; + parent::__construct($command, $input, $output); + } + +} diff --git a/src/Console/EventSubscriber/ConsoleIoSubscriber.php b/src/Console/EventSubscriber/ConsoleIoSubscriber.php new file mode 100644 index 000000000..8be6b70c8 --- /dev/null +++ b/src/Console/EventSubscriber/ConsoleIoSubscriber.php @@ -0,0 +1,48 @@ +consoleIO = $consoleIO; + } + + + /** + * {@inheritdoc} + */ + public function getSubscribedEvents() + { + return [ConsoleEvents::COMMAND => 'setupConsoleIo']; + } + + + public function setupConsoleIo(ConsoleCommandEvent $event) + { + $this->consoleIO->setInput($event->getInput()); + $this->consoleIO->setOutput($event->getOutput()); + } + +} diff --git a/src/DI/apigen.services.neon b/src/DI/apigen.services.neon index 26820d2e2..05f14dea8 100644 --- a/src/DI/apigen.services.neon +++ b/src/DI/apigen.services.neon @@ -1,7 +1,6 @@ services: - # commands - - ApiGen\Command\GenerateCommand - - ApiGen\Command\SelfUpdateCommand + - ApiGen\ApiGen + - ApiGen\MemoryLimit # configuration - ApiGen\Configuration\Configuration @@ -14,10 +13,12 @@ services: - ApiGen\Configuration\Theme\ThemeConfigOptionsResolver # console + - ApiGen\Command\GenerateCommand + - ApiGen\Command\SelfUpdateCommand - class: ApiGen\Console\Application setup: - - setEventManager + - setDispatcher - ApiGen\Console\IO - ApiGen\Console\ProgressBar - Symfony\Component\Console\Helper\ProgressHelper @@ -27,6 +28,7 @@ services: setup: - set(@Symfony\Component\Console\Helper\ProgressHelper, 'progress') - set(@Symfony\Component\Console\Helper\QuestionHelper, 'question') + - ApiGen\Console\EventSubscriber\ConsoleIoSubscriber # elements - ApiGen\Generator\Resolvers\ElementResolver @@ -34,7 +36,6 @@ services: # events - {class: ApiGen\Events\ProgressBarIncrement, tags: [kdyby.subscriber]} - - {class: ApiGen\Events\SetIoOnConsoleRun, tags: [kdyby.subscriber]} # generator - ApiGen\Scanner\Scanner diff --git a/src/DI/config.neon b/src/DI/config.neon index d66ed911a..477ac9e70 100644 --- a/src/DI/config.neon +++ b/src/DI/config.neon @@ -1,5 +1,5 @@ extensions: - ApiGen\DI\ApiGenExtension + - ApiGen\EventDispatcher\DI\EventDispatcherExtension - ApiGen\Parser\DI\ParserExtension - ApiGen\Utils\DI\UtilsExtension - - Kdyby\Events\DI\EventsExtension diff --git a/src/Events/SetIoOnConsoleRun.php b/src/Events/SetIoOnConsoleRun.php deleted file mode 100644 index 3c8bda5fd..000000000 --- a/src/Events/SetIoOnConsoleRun.php +++ /dev/null @@ -1,49 +0,0 @@ -consoleIO = $consoleIO; - } - - - /** - * @return string[] - */ - public function getSubscribedEvents() - { - return [Application::class . '::onRun']; - } - - - public function onRun(InputInterface $input, OutputInterface $output) - { - $this->consoleIO->setInput($input); - $this->consoleIO->setOutput($output); - } - -} diff --git a/tests/Console/ApplicationTest.php b/tests/Console/ApplicationTest.php index 27216c7c8..3ace134c7 100644 --- a/tests/Console/ApplicationTest.php +++ b/tests/Console/ApplicationTest.php @@ -4,6 +4,7 @@ use ApiGen\ApiGen; use ApiGen\Console\Application; +use ApiGen\MemoryLimit; use ApiGen\Tests\MethodInvoker; use Kdyby\Events\EventManager; use Mockery; @@ -24,23 +25,7 @@ class ApplicationTest extends PHPUnit_Framework_TestCase protected function setUp() { - $this->application = new Application; - } - - - public function testDoRun() - { - $inputMock = Mockery::mock(InputInterface::class); - $inputMock->shouldReceive('hasParameterOption'); - $inputMock->shouldReceive('getFirstArgument'); - - $outputMock = Mockery::mock(OutputInterface::class); - $outputMock->shouldReceive('write'); - $eventManagerMock = Mockery::mock(EventManager::class); - $eventManagerMock->shouldReceive('dispatchEvent'); - - $this->application->setEventManager($eventManagerMock); - $this->application->doRun($inputMock, $outputMock); + $this->application = new Application(new ApiGen, new MemoryLimit); } diff --git a/tests/config/default.neon b/tests/config/default.neon index d66ed911a..477ac9e70 100644 --- a/tests/config/default.neon +++ b/tests/config/default.neon @@ -1,5 +1,5 @@ extensions: - ApiGen\DI\ApiGenExtension + - ApiGen\EventDispatcher\DI\EventDispatcherExtension - ApiGen\Parser\DI\ParserExtension - ApiGen\Utils\DI\UtilsExtension - - Kdyby\Events\DI\EventsExtension