Skip to content

Commit

Permalink
Merge pull request #331 from RunOpenCode/feature/expose-commands-to-f…
Browse files Browse the repository at this point in the history
…rameworks

CLI commands can be owerwritten for transparent integration with frameworks
  • Loading branch information
lisachenko authored Jul 10, 2017
2 parents c6fc1db + 55fa989 commit 5d96ceb
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
14 changes: 12 additions & 2 deletions src/Console/Command/BaseAspectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,26 @@ protected function configure()
}

/**
* {@inheritDoc}
* Loads aspect kernel.
*
* Aspect kernel is loaded by executing loader and fetching singleton instance.
* If your application environment initializes aspect kernel differently, you may
* modify this metod to get aspect kernel suitable to your needs.
*
* @param InputInterface $input
* @param OutputInterface $output
*/
protected function execute(InputInterface $input, OutputInterface $output)
protected function loadAspectKernel(InputInterface $input, OutputInterface $output)
{
$loader = $input->getArgument('loader');
$path = stream_resolve_include_path($loader);
if (!is_readable($path)) {
throw new \InvalidArgumentException("Invalid loader path: {$loader}");
}

ob_start();
include_once $path;
ob_clean();

if (!class_exists(AspectKernel::class, false)) {
$message = "Kernel was not initialized yet, please configure it in the {$path}";
Expand Down
3 changes: 2 additions & 1 deletion src/Console/Command/CacheWarmupCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
$this->loadAspectKernel($input, $output);

$options = $this->aspectKernel->getOptions();

if (empty($options['cacheDir'])) {
Expand Down
3 changes: 2 additions & 1 deletion src/Console/Command/DebugAdvisorCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
$this->loadAspectKernel($input, $output);

$io = new SymfonyStyle($input, $output);
$io->title('Advisor debug information');

Expand Down
3 changes: 2 additions & 1 deletion src/Console/Command/DebugAspectCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ protected function configure()
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
parent::execute($input, $output);
$this->loadAspectKernel($input, $output);

$io = new SymfonyStyle($input, $output);

$container = $this->aspectKernel->getContainer();
Expand Down

0 comments on commit 5d96ceb

Please sign in to comment.