Skip to content

Commit

Permalink
use ApiGen\EventDispatcher, Console changes
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Apr 9, 2015
1 parent dbbc495 commit f23e683
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 116 deletions.
6 changes: 3 additions & 3 deletions composer.json
Expand Up @@ -21,16 +21,16 @@

"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",
"herrera-io/phar-update": "~2.0",

"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",
Expand Down
9 changes: 9 additions & 0 deletions src/ApiGen.php
Expand Up @@ -18,4 +18,13 @@ class ApiGen
*/
const VERSION = '4.2.0-dev';


/**
* @return string
*/
public function getVersion()
{
return self::VERSION;
}

}
45 changes: 5 additions & 40 deletions src/Console/Application.php
Expand Up @@ -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;
Expand All @@ -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');
}


Expand All @@ -73,12 +50,6 @@ public function run(InputInterface $input = NULL, OutputInterface $output = NULL
}


public function setEventManager(EventManager $eventManager)
{
$this->eventManager = $eventManager;
}


/**
* @return array
*/
Expand All @@ -103,10 +74,4 @@ protected function getDefaultInputDefinition()
]);
}


private function onRun(InputInterface $input, OutputInterface $output)
{
$this->eventManager->dispatchEvent(__METHOD__, new EventArgsList([$input, $output]));
}

}
34 changes: 34 additions & 0 deletions src/Console/Event/ConsoleCommandEvent.php
@@ -0,0 +1,34 @@
<?php

/**
* This file is part of the ApiGen (http://apigen.org)
*
* For the full copyright and license information, please view
* the file LICENSE that was distributed with this source code.
*/

namespace ApiGen\Console\Event;

use ApiGen\Contracts\EventDispatcher\Event\EventInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Event\ConsoleCommandEvent as BaseConsoleCommandEvent;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;


class ConsoleCommandEvent extends BaseConsoleCommandEvent implements EventInterface
{

/**
* @var string
*/
private $name;


public function __construct($name, Command $command, InputInterface $input, OutputInterface $output)
{
$this->name = $name;
parent::__construct($command, $input, $output);
}

}
48 changes: 48 additions & 0 deletions src/Console/EventSubscriber/ConsoleIoSubscriber.php
@@ -0,0 +1,48 @@
<?php

/**
* This file is part of the ApiGen (http://apigen.org)
*
* For the full copyright and license information, please view
* the file LICENSE that was distributed with this source code.
*/

namespace ApiGen\Console\EventSubscriber;

use ApiGen\Console\Event\ConsoleCommandEvent;
use ApiGen\Console\IOInterface;
use ApiGen\Contracts\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Console\ConsoleEvents;


class ConsoleIoSubscriber implements EventSubscriberInterface
{

/**
* @var IOInterface
*/
private $consoleIO;


public function __construct(IOInterface $consoleIO)
{
$this->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());
}

}
11 changes: 6 additions & 5 deletions 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
Expand All @@ -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
Expand All @@ -27,14 +28,14 @@ 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
- ApiGen\Generator\Resolvers\RelativePathResolver

# events
- {class: ApiGen\Events\ProgressBarIncrement, tags: [kdyby.subscriber]}
- {class: ApiGen\Events\SetIoOnConsoleRun, tags: [kdyby.subscriber]}

# generator
- ApiGen\Scanner\Scanner
Expand Down
2 changes: 1 addition & 1 deletion 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
49 changes: 0 additions & 49 deletions src/Events/SetIoOnConsoleRun.php

This file was deleted.

19 changes: 2 additions & 17 deletions tests/Console/ApplicationTest.php
Expand Up @@ -4,6 +4,7 @@

use ApiGen\ApiGen;
use ApiGen\Console\Application;
use ApiGen\MemoryLimit;
use ApiGen\Tests\MethodInvoker;
use Kdyby\Events\EventManager;
use Mockery;
Expand All @@ -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);
}


Expand Down
2 changes: 1 addition & 1 deletion 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

0 comments on commit f23e683

Please sign in to comment.