Skip to content

Commit 3971683

Browse files
committed
Event subscribers use tags
1 parent 423605a commit 3971683

File tree

9 files changed

+70
-60
lines changed

9 files changed

+70
-60
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ php:
44
- 5.4
55

66
before_script:
7+
- composer require "symfony/symfony" "2.6" --no-update
78
- composer install
89
- bash tests/bin/travis_jackrabbit.sh
910

1011
script:
1112
- phpunit
12-
- php vendor/behat/behat/bin/behat
1313
- php vendor/bin/phpspec run
14+
- php vendor/behat/behat/bin/behat --suite=standalone

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ class EmbeddedApplication extends ShellApplication
2424
*/
2525
const MODE_SHELL = Container::MODE_EMBEDDED_SHELL;
2626

27+
protected $mode;
28+
2729
/**
2830
* The $mode can be one of EmbeddedApplication::MODE_SHELL or EmbeddedApplication::MODE_COMMAND.
2931
*
@@ -34,7 +36,8 @@ class EmbeddedApplication extends ShellApplication
3436
*/
3537
public function __construct($mode)
3638
{
37-
$container = new Container($mode);
39+
$this->mode = $mode;
40+
$container = new Container($this->mode);
3841
parent::__construct($container, SessionApplication::APP_NAME, SessionApplication::APP_VERSION);
3942
$this->setAutoExit(false);
4043
}
@@ -62,6 +65,6 @@ public function init()
6265
*/
6366
protected function getDefaultCommand()
6467
{
65-
return 'shell:path:show';
68+
return $this->mode === self::MODE_SHELL ? 'shell:path:show' : 'list';
6669
}
6770
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private function autocompleter($text)
103103
{
104104
$info = readline_info();
105105
$text = substr($info['line_buffer'], 0, $info['end']);
106-
$list = $this->get('phpcr.session')->autocomplete($text);
106+
$list = $this->application->getContainer()->get('phpcr.session')->autocomplete($text);
107107

108108
return $list;
109109
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,9 @@ public function dispatchProfileInitEvent(InputInterface $sessionInput, OutputInt
301301
$event = new Event\ProfileInitEvent($this->container->get('config.profile'), $sessionInput, $output);
302302
$this->dispatcher->dispatch(PhpcrShellEvents::PROFILE_INIT, $event);
303303
}
304+
305+
public function getContainer()
306+
{
307+
return $this->container;
308+
}
304309
}

src/PHPCR/Shell/DependencyInjection/Container.php

Lines changed: 39 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,16 @@ public function registerPhpcr()
7171
$registry->addMethodCall('register', array(new Reference($transportId)));
7272
}
7373

74-
$this->register('phpcr.session_manager', 'PHPCR\Shell\Phpcr\SessionManager')
74+
$this->register('phpcr.session_manager.active', 'PHPCR\Shell\Phpcr\SessionManager')
7575
->addArgument(new Reference('phpcr.transport_registry'))
7676
->addArgument(new Reference('config.profile'));
7777

78+
$this->register('phpcr.session_manager.passive', 'PHPCR\Shell\Phpcr\SessionManager')
79+
->addArgument(new Reference('phpcr.transport_registry'))
80+
->addArgument(new Reference('config.profile'));
81+
82+
$this->setAlias('phpcr.session_manager', 'phpcr.session_manager.active');
83+
7884
$repositoryDefinition = $this->register('phpcr.repository');
7985
$sessionDefinition = $this->register('phpcr.session');
8086

@@ -89,46 +95,45 @@ public function registerPhpcr()
8995

9096
public function registerEvent()
9197
{
92-
$ids = array();
93-
$subscribers = array();
94-
95-
$subscribers[] = $this->register(
96-
$ids[] = 'event.subscriber.profile_from_session_input',
98+
$this->register(
99+
'event.subscriber.profile_from_session_input',
97100
'PHPCR\Shell\Subscriber\ProfileFromSessionInputSubscriber'
98-
);
99-
$subscribers[] = $this->register(
100-
$ids[] = 'event.subscriber.exception',
101+
)->addTag('event.subscriber');
102+
103+
$this->register(
104+
'event.subscriber.exception',
101105
'PHPCR\Shell\Subscriber\ExceptionSubscriber'
102-
);
103-
$subscribers[] = $this->register(
104-
$ids[] = 'event.subscriber.alias',
106+
)->addTag('event.subscriber');
107+
$this->register(
108+
'event.subscriber.alias',
105109
'PHPCR\Shell\Subscriber\AliasSubscriber'
106110
)
107-
->addArgument(new Reference('config.manager'));
108-
109-
if ($this->mode === self::MODE_STANDALONE) {
110-
$subscribers[] = $this->register(
111-
$ids[] = 'event.subscriber.profile_writer',
112-
'PHPCR\Shell\Subscriber\ProfileWriterSubscriber'
113-
)
114-
->addArgument(new Reference('config.profile_loader'))
115-
->addArgument(new Reference('helper.question'));
116-
$subscribers[] = $this->register(
117-
$ids[] = 'event.subscriber.profile_loader',
118-
'PHPCR\Shell\Subscriber\ProfileLoaderSubscriber'
119-
)
120-
->addArgument(new Reference('config.profile_loader'))
121-
->addArgument(new Reference('helper.question'));
122-
$subscribers[] = $this->register(
123-
$ids[] = 'event.subscriber.config_init',
124-
'PHPCR\Shell\Subscriber\ConfigInitSubscriber'
125-
)
126-
->addArgument(new Reference('config.manager'));
127-
}
111+
->addArgument(new Reference('config.manager'))
112+
->addTag('event.subscriber');
113+
$this->register(
114+
'event.subscriber.profile_writer',
115+
'PHPCR\Shell\Subscriber\ProfileWriterSubscriber'
116+
)
117+
->addArgument(new Reference('config.profile_loader'))
118+
->addArgument(new Reference('helper.question'))
119+
->addTag('event.subscriber');
120+
$this->register(
121+
'event.subscriber.profile_loader',
122+
'PHPCR\Shell\Subscriber\ProfileLoaderSubscriber'
123+
)
124+
->addArgument(new Reference('config.profile_loader'))
125+
->addArgument(new Reference('helper.question'))
126+
->addTag('event.subscriber');
127+
$this->register(
128+
'event.subscriber.config_init',
129+
'PHPCR\Shell\Subscriber\ConfigInitSubscriber'
130+
)
131+
->addArgument(new Reference('config.manager'))
132+
->addTag('event.subscriber');
128133

129134
$dispatcher = $this->register('event.dispatcher', 'Symfony\Component\EventDispatcher\EventDispatcher');
130135

131-
foreach ($ids as $id) {
136+
foreach (array_keys($this->findTaggedServiceIds('event.subscriber')) as $id) {
132137
$dispatcher->addMethodCall('addSubscriber', array(new Reference($id)));
133138
}
134139
}

src/PHPCR/Shell/Test/ApplicationTester.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Symfony\Component\Console\Output\StreamOutput;
1010
use PHPCR\Shell\Console\Input\StringInput;
1111
use PHPCR\Shell\Console\Application\SessionApplication;
12+
use PHPCR\Shell\Console\Application\ShellApplication;
1213

1314
/**
1415
* Eases the testing of console applications.
@@ -23,6 +24,7 @@
2324
class ApplicationTester
2425
{
2526
private $application;
27+
private $shellApplication;
2628
private $input;
2729
private $output;
2830
private $lastExitCode;
@@ -32,9 +34,12 @@ class ApplicationTester
3234
*
3335
* @param Application $application An Application instance to test.
3436
*/
35-
public function __construct(Application $application)
37+
public function __construct(Application $application, ShellApplication $shellApplication = null)
3638
{
39+
$this->output = new StreamOutput(fopen('php://memory', 'w', false));
40+
3741
$this->application = $application;
42+
$this->shellApplication = $shellApplication;
3843
}
3944

4045
/**
@@ -55,7 +60,6 @@ public function run(array $input, $options = array())
5560
{
5661
$this->input = new ArrayInput($input);
5762

58-
$this->output = new StreamOutput(fopen('php://memory', 'w', false));
5963
if (isset($options['decorated'])) {
6064
$this->output->setDecorated($options['decorated']);
6165
}
@@ -64,6 +68,10 @@ public function run(array $input, $options = array())
6468
}
6569

6670
$this->application->setAutoExit(false);
71+
72+
if ($this->shellApplication) {
73+
$this->shellApplication->setAutoExit(false);
74+
}
6775
$this->application->setCatchExceptions(false);
6876

6977
return $this->application->run($this->input, $this->output);
@@ -123,12 +131,13 @@ public function getOutput()
123131

124132
public function runShellCommand($command)
125133
{
126-
if ($this->application instanceof SessionApplication) {
127-
$ret = $this->application->getShellApplication()->run(new StringInput($command), $this->output);
134+
if ($this->shellApplication) {
135+
$ret = $this->shellApplication->run(new StringInput($command), $this->output);
128136
} else {
129-
$ret = $this->application->run(new StringInput($command), $this->output);
137+
$ret = $this->application->run(new StringInput($command, $this->output));
130138
}
131139

140+
132141
$this->lastExitCode = $ret;
133142

134143
return $ret;

src/PHPCR/Shell/Test/ContextBase.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ public function beforeScenario()
5555
$this->filesystem = new Filesystem();
5656

5757
$this->applicationTester = $this->createTester();
58-
$this->applicationTester->run(array(
59-
'--transport' => 'jackrabbit',
60-
'--no-interaction' => true,
61-
'--unsupported' => true, // test all the commands, even if they are unsupported (we test for the fail)
62-
), array(
63-
'interactive' => true,
64-
));
6558
}
6659

6760
/**

src/PHPCR/Shell/Test/EmbeddedContext.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,8 @@ class EmbeddedContext extends ContextBase
1212
{
1313
protected function createTester()
1414
{
15-
$tester = new ApplicationTester(new EmbeddedApplication(EmbeddedApplication::MODE_COMMAND));
16-
$tester->run(array(
17-
'--transport' => 'jackrabbit',
18-
'--no-interaction' => true,
19-
'--unsupported' => true, // test all the commands, even if they are unsupported (we test for the fail)
20-
), array(
21-
'interactive' => true,
22-
));
15+
$application = new EmbeddedApplication(EmbeddedApplication::MODE_COMMAND);
16+
$tester = new ApplicationTester($application);
2317

2418
return $tester;
2519
}

src/PHPCR/Shell/Test/StandaloneContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ class StandaloneContext extends ContextBase
1313
protected function createTester()
1414
{
1515
$sessionApplication = new SessionApplication();
16-
$sessionApplication->getShellApplication()->setAutoExit(false);
17-
$tester = new ApplicationTester($sessionApplication);
16+
$shellApplication = $sessionApplication->getShellApplication();
17+
$tester = new ApplicationTester($sessionApplication, $shellApplication);
1818
$tester->run(array(
1919
'--transport' => 'jackrabbit',
2020
'--no-interaction' => true,

0 commit comments

Comments
 (0)