Skip to content

Commit 1124d21

Browse files
committed
Repaired embedded application
1 parent 0ae0b3c commit 1124d21

File tree

2 files changed

+48
-37
lines changed

2 files changed

+48
-37
lines changed

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

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use PHPCR\Shell\Subscriber;
66
use Symfony\Component\DependencyInjection\ContainerInterface;
7+
use PHPCR\Shell\DependencyInjection\Container;
78

89
/**
910
* Subclass of the full ShellApplication for running as an EmbeddedApplication
@@ -13,10 +14,15 @@
1314
*/
1415
class EmbeddedApplication extends ShellApplication
1516
{
16-
const MODE_SHELL = 'shell';
17-
const MODE_COMMAND = 'command';
17+
/**
18+
* @deprecated remove after DoctrinePhpcrBundle is upgraded
19+
*/
20+
const MODE_COMMAND = Container::MODE_EMBEDDED_COMMAND;
1821

19-
protected $mode = self::MODE_SHELL;
22+
/**
23+
* @deprecated remove after DoctrinePhpcrBundle is upgraded
24+
*/
25+
const MODE_SHELL = Container::MODE_EMBEDDED_SHELL;
2026

2127
/**
2228
* The $mode can be one of EmbeddedApplication::MODE_SHELL or EmbeddedApplication::MODE_COMMAND.
@@ -26,10 +32,10 @@ class EmbeddedApplication extends ShellApplication
2632
*
2733
* @param string $mode
2834
*/
29-
public function __construct(ContainerInterface $container, $mode)
35+
public function __construct($mode)
3036
{
37+
$container = new Container($mode);
3138
parent::__construct($container, SessionApplication::APP_NAME, SessionApplication::APP_VERSION);
32-
$this->mode = $mode;
3339
$this->setAutoExit(false);
3440
}
3541

@@ -44,7 +50,7 @@ public function init()
4450

4551
$this->registerPhpcrCommands();
4652

47-
if ($this->mode === self::MODE_SHELL) {
53+
if ($this->container->getMode() === self::MODE_SHELL) {
4854
$this->registerShellCommands();
4955
}
5056

@@ -58,16 +64,4 @@ protected function getDefaultCommand()
5864
{
5965
return 'shell:path:show';
6066
}
61-
62-
/**
63-
* {@inheritDoc}
64-
*/
65-
protected function registerEventListeners()
66-
{
67-
throw new \Exception('Implement me');
68-
$this->dispatcher->addSubscriber(new Subscriber\ProfileFromSessionInputSubscriber());
69-
$this->dispatcher->addSubscriber(new Subscriber\ExceptionSubscriber());
70-
$this->dispatcher->addSubscriber(new Subscriber\AliasSubscriber($this->getHelperSet()));
71-
$this->dispatcher->addSubscriber(new Subscriber\AutoSaveSubscriber());
72-
}
7367
}

src/PHPCR/Shell/DependencyInjection/Container.php

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
class Container extends ContainerBuilder
99
{
10+
const MODE_EMBEDDED_SHELL = 'shell';
11+
const MODE_EMBEDDED_COMMAND = 'command';
12+
const MODE_STANDALONE = 'standalon';
13+
14+
protected $mode;
15+
1016
/**
1117
* @var array Transports
1218
*/
@@ -15,9 +21,11 @@ class Container extends ContainerBuilder
1521
'transport.transport.jackrabbit' => 'PHPCR\Shell\Transport\Transport\Jackrabbit',
1622
);
1723

18-
public function __construct()
24+
public function __construct($mode = self::MODE_STANDALONE)
1925
{
2026
parent::__construct();
27+
$this->mode = $mode;
28+
2129
$this->registerHelpers();
2230
$this->registerConfig();
2331
$this->registerPhpcr();
@@ -75,27 +83,11 @@ public function registerEvent()
7583
{
7684
$ids = array();
7785
$subscribers = array();
86+
7887
$subscribers[] = $this->register(
7988
$ids[] = 'event.subscriber.profile_from_session_input',
8089
'PHPCR\Shell\Subscriber\ProfileFromSessionInputSubscriber'
8190
);
82-
$subscribers[] = $this->register(
83-
$ids[] = 'event.subscriber.profile_writer',
84-
'PHPCR\Shell\Subscriber\ProfileWriterSubscriber'
85-
)
86-
->addArgument(new Reference('config.profile_loader'))
87-
->addArgument(new Reference('helper.question'));
88-
$subscribers[] = $this->register(
89-
$ids[] = 'event.subscriber.profile_loader',
90-
'PHPCR\Shell\Subscriber\ProfileLoaderSubscriber'
91-
)
92-
->addArgument(new Reference('config.profile_loader'))
93-
->addArgument(new Reference('helper.question'));
94-
$subscribers[] = $this->register(
95-
$ids[] = 'event.subscriber.config_init',
96-
'PHPCR\Shell\Subscriber\ConfigInitSubscriber'
97-
)
98-
->addArgument(new Reference('config.manager'));
9991
$subscribers[] = $this->register(
10092
$ids[] = 'event.subscriber.exception',
10193
'PHPCR\Shell\Subscriber\ExceptionSubscriber'
@@ -104,12 +96,37 @@ public function registerEvent()
10496
$ids[] = 'event.subscriber.alias',
10597
'PHPCR\Shell\Subscriber\AliasSubscriber'
10698
)
107-
->addArgument(new Reference('config.manager'));
99+
->addArgument(new Reference('config.manager'));
100+
101+
if ($this->mode === self::MODE_STANDALONE) {
102+
$subscribers[] = $this->register(
103+
$ids[] = 'event.subscriber.profile_writer',
104+
'PHPCR\Shell\Subscriber\ProfileWriterSubscriber'
105+
)
106+
->addArgument(new Reference('config.profile_loader'))
107+
->addArgument(new Reference('helper.question'));
108+
$subscribers[] = $this->register(
109+
$ids[] = 'event.subscriber.profile_loader',
110+
'PHPCR\Shell\Subscriber\ProfileLoaderSubscriber'
111+
)
112+
->addArgument(new Reference('config.profile_loader'))
113+
->addArgument(new Reference('helper.question'));
114+
$subscribers[] = $this->register(
115+
$ids[] = 'event.subscriber.config_init',
116+
'PHPCR\Shell\Subscriber\ConfigInitSubscriber'
117+
)
118+
->addArgument(new Reference('config.manager'));
119+
}
108120

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

111123
foreach ($ids as $id) {
112124
$dispatcher->addMethodCall('addSubscriber', array(new Reference($id)));
113125
}
114126
}
127+
128+
public function getMode()
129+
{
130+
return $this->mode;
131+
}
115132
}

0 commit comments

Comments
 (0)