Skip to content

Commit c5fcb8f

Browse files
committed
ADded PreRun event
todo: Make alias subscriber to create command based on alias (or not)
1 parent 1a87d41 commit c5fcb8f

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

src/PHPCR/Shell/Console/Application/ShellApplication.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ public function doRun(InputInterface $input, OutputInterface $output)
337337

338338
$name = $this->getCommandName($input);
339339

340+
$event = new Event\CommandPreRunEvent($name, $input);
341+
$this->dispatcher->dispatch(PhpcrShellEvents::COMMAND_PRE_RUN, $event);
342+
$input = $event->getInput();
343+
340344
if (!$name) {
341345
$input = new ArrayInput(array('command' => 'shell:path:show'));
342346
}
@@ -363,7 +367,7 @@ public function doRun(InputInterface $input, OutputInterface $output)
363367
*/
364368
public function renderException(\Exception $exception, OutputInterface $output)
365369
{
366-
$output->writeln(sprintf('<exception>%s</exception', $exception->getMessage()));
370+
$output->writeln(sprintf('<exception>%s</exception>', $exception->getMessage()));
367371
}
368372

369373
/**
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Event;
4+
5+
use Symfony\Component\Console\Input\InputInterface;
6+
use Symfony\Component\EventDispatcher\Event;
7+
8+
class CommandPreRunEvent extends Event
9+
{
10+
protected $commandName;
11+
protected $input;
12+
13+
public function __construct($commandName, InputInterface $input)
14+
{
15+
$this->commandName = $commandName;
16+
$this->input = $input;
17+
}
18+
19+
public function getInput()
20+
{
21+
return $this->input;
22+
}
23+
24+
public function setInput($input)
25+
{
26+
$this->input = $input;
27+
}
28+
29+
public function getCommandName()
30+
{
31+
return $this->commandName;
32+
}
33+
34+
}

src/PHPCR/Shell/Event/PhpcrShellEvents.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44

55
class PhpcrShellEvents
66
{
7-
const COMMAND_EXCEPTION = 'command_exception';
7+
const COMMAND_EXCEPTION = 'command.exception';
8+
const COMMAND_PRE_RUN = 'command.pre_run';
89
}

0 commit comments

Comments
 (0)