Skip to content

Commit 5d96ceb

Browse files
authored
Merge pull request #331 from RunOpenCode/feature/expose-commands-to-frameworks
CLI commands can be owerwritten for transparent integration with frameworks
2 parents c6fc1db + 55fa989 commit 5d96ceb

File tree

4 files changed

+18
-5
lines changed

4 files changed

+18
-5
lines changed

src/Console/Command/BaseAspectCommand.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,26 @@ protected function configure()
3737
}
3838

3939
/**
40-
* {@inheritDoc}
40+
* Loads aspect kernel.
41+
*
42+
* Aspect kernel is loaded by executing loader and fetching singleton instance.
43+
* If your application environment initializes aspect kernel differently, you may
44+
* modify this metod to get aspect kernel suitable to your needs.
45+
*
46+
* @param InputInterface $input
47+
* @param OutputInterface $output
4148
*/
42-
protected function execute(InputInterface $input, OutputInterface $output)
49+
protected function loadAspectKernel(InputInterface $input, OutputInterface $output)
4350
{
4451
$loader = $input->getArgument('loader');
4552
$path = stream_resolve_include_path($loader);
4653
if (!is_readable($path)) {
4754
throw new \InvalidArgumentException("Invalid loader path: {$loader}");
4855
}
56+
57+
ob_start();
4958
include_once $path;
59+
ob_clean();
5060

5161
if (!class_exists(AspectKernel::class, false)) {
5262
$message = "Kernel was not initialized yet, please configure it in the {$path}";

src/Console/Command/CacheWarmupCommand.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ protected function configure()
4545
*/
4646
protected function execute(InputInterface $input, OutputInterface $output)
4747
{
48-
parent::execute($input, $output);
48+
$this->loadAspectKernel($input, $output);
49+
4950
$options = $this->aspectKernel->getOptions();
5051

5152
if (empty($options['cacheDir'])) {

src/Console/Command/DebugAdvisorCommand.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ protected function configure()
4949
*/
5050
protected function execute(InputInterface $input, OutputInterface $output)
5151
{
52-
parent::execute($input, $output);
52+
$this->loadAspectKernel($input, $output);
53+
5354
$io = new SymfonyStyle($input, $output);
5455
$io->title('Advisor debug information');
5556

src/Console/Command/DebugAspectCommand.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ protected function configure()
4646
*/
4747
protected function execute(InputInterface $input, OutputInterface $output)
4848
{
49-
parent::execute($input, $output);
49+
$this->loadAspectKernel($input, $output);
50+
5051
$io = new SymfonyStyle($input, $output);
5152

5253
$container = $this->aspectKernel->getContainer();

0 commit comments

Comments
 (0)