Skip to content

Commit 2829b4e

Browse files
committed
Merge pull request #129 from phpcr/instantiation
Instantiation
2 parents c48d0c2 + f6d1a3a commit 2829b4e

File tree

12 files changed

+114
-60
lines changed

12 files changed

+114
-60
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ Changelog
44
dev-master
55
----------
66

7+
### BC Break
8+
9+
- [DoctrinePhpcrBundle] Shell must now be initiated in a different way in
10+
embedded mode. The DoctrinePhpcrBundle will need to be updated.
11+
712
### Bug fixes
813

914
- [config] Do not override CLI options with profile options

bin/phpcrsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ if (file_exists($file)) {
1212
exit(1);
1313
}
1414

15-
$shell = new PHPCR\Shell\Console\Application\SessionApplication();
15+
$shell = \PHPCR\Shell\PhpcrShell::createShell();
1616
$shell->run();

spec/PHPCR/Shell/Console/Application/EmbeddedApplicationSpec.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,16 @@
55
use PhpSpec\ObjectBehavior;
66
use PHPCR\Shell\Console\Application\EmbeddedApplication;
77
use Symfony\Component\DependencyInjection\ContainerInterface;
8+
use PHPCR\Shell\PhpcrShell;
9+
use PHPCR\Shell\DependencyInjection\Container;
810

911
class EmbeddedApplicationSpec extends ObjectBehavior
1012
{
1113
public function let(
12-
ContainerInterface $container
14+
Container $container
1315
)
1416
{
15-
$this->beConstructedWith($container, EmbeddedApplication::MODE_COMMAND);
17+
$this->beConstructedWith($container);
1618
}
1719

1820
public function it_is_initializable()

spec/PHPCR/Shell/Console/Application/ShellApplicationSpec.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
use PhpSpec\ObjectBehavior;
66
use Symfony\Component\DependencyInjection\ContainerInterface;
77
use PHPCR\Shell\Console\Application\EmbeddedApplication;
8+
use PHPCR\Shell\PhpcrShell;
89

910
class ShellApplicationSpec extends ObjectBehavior
1011
{
1112
public function let(
1213
ContainerInterface $container
1314
)
1415
{
15-
$this->beConstructedWith($container, EmbeddedApplication::MODE_COMMAND);
16+
$this->beConstructedWith($container, PhpcrShell::MODE_EMBEDDED_COMMAND);
1617
}
1718

1819
public function it_is_initializable()

src/PHPCR/Shell/Config/Config.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ public function offsetGet($offset)
3636
{
3737
if (isset($this->data[$offset])) {
3838
$value = $this->data[$offset];
39+
3940
if (is_array($value)) {
4041
return new self($value);
41-
} else {
42-
return $value;
4342
}
43+
44+
return $value;
4445
}
4546
}
4647

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

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

55
use PHPCR\Shell\DependencyInjection\Container;
66
use PHPCR\Shell\Console\Helper\PhpcrHelper;
7+
use PHPCR\Shell\PhpcrShell;
78

89
/**
910
* Subclass of the full ShellApplication for running as an EmbeddedApplication
@@ -13,35 +14,20 @@
1314
*/
1415
class EmbeddedApplication extends ShellApplication
1516
{
16-
/**
17-
* @deprecated remove after DoctrinePhpcrBundle is upgraded
18-
*/
19-
const MODE_COMMAND = Container::MODE_EMBEDDED_COMMAND;
20-
21-
/**
22-
* @deprecated remove after DoctrinePhpcrBundle is upgraded
23-
*/
24-
const MODE_SHELL = Container::MODE_EMBEDDED_SHELL;
25-
2617
protected $mode;
2718

2819
/**
29-
* The $mode can be one of EmbeddedApplication::MODE_SHELL or EmbeddedApplication::MODE_COMMAND.
20+
* The $mode can be one of PhpcrShell::MODE_SHELL or PhpcrShell::MODE_COMMAND.
3021
*
3122
* - Shell mode initializes the whole environement
3223
* - Command mode initailizes only enough to run commands
3324
*
3425
* @param string $mode
3526
*/
36-
public function __construct($mode)
27+
public function __construct(Container $container)
3728
{
38-
$this->mode = $mode;
39-
$container = new Container($this->mode);
40-
parent::__construct($container, SessionApplication::APP_NAME, SessionApplication::APP_VERSION);
29+
parent::__construct($container);
4130
$this->setAutoExit(false);
42-
43-
// @deprecated This will be removed in 1.0
44-
$this->getHelperSet()->set(new PhpcrHelper($container->get('phpcr.session_manager')));
4531
}
4632

4733
/**
@@ -51,7 +37,7 @@ public function init()
5137
{
5238
$this->registerPhpcrCommands();
5339

54-
if ($this->container->getMode() === self::MODE_SHELL) {
40+
if ($this->container->getMode() === PhpcrShell::MODE_EMBEDDED_SHELL) {
5541
$this->registerShellCommands();
5642
}
5743
}
@@ -61,6 +47,6 @@ public function init()
6147
*/
6248
protected function getDefaultCommand()
6349
{
64-
return $this->mode === self::MODE_SHELL ? 'shell:path:show' : 'list';
50+
return $this->mode === PhpcrShell::MODE_EMBEDDED_SHELL ? 'shell:path:show' : 'list';
6551
}
6652
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Symfony\Component\Console\Input\InputInterface;
88
use PHPCR\Shell\Console\Command\ShellCommand;
99
use PHPCR\Shell\DependencyInjection\Container;
10+
use PHPCR\Shell\PhpcrShell;
1011

1112
/**
1213
* This application wraps a single command which accepts
@@ -16,9 +17,6 @@
1617
*/
1718
class SessionApplication extends BaseApplication
1819
{
19-
const APP_NAME = 'PHPCRSH';
20-
const APP_VERSION = '1.0.0-alpha6';
21-
2220
protected $shellApplication;
2321

2422
/**
@@ -27,10 +25,10 @@ class SessionApplication extends BaseApplication
2725
*/
2826
public function __construct()
2927
{
30-
parent::__construct(self::APP_NAME, self::APP_VERSION);
28+
parent::__construct(PhpcrShell::APP_NAME, PhpcrShell::APP_VERSION);
3129

3230
$container = new Container();
33-
$this->shellApplication = $container->get('console.application.shell');
31+
$this->shellApplication = $container->get('application');
3432

3533
$command = new ShellCommand($this->shellApplication);
3634
$command->setApplication($this);

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ class Shell
1818
private $output;
1919
private $hasReadline;
2020
private $prompt;
21-
private $processIsolation;
2221

2322
/**
2423
* Constructor.
@@ -35,7 +34,6 @@ public function __construct(Application $application)
3534
$this->history = getenv('HOME').'/.history_'.$application->getName();
3635
$this->output = new ConsoleOutput();
3736
$this->prompt = $application->getName().' > ';
38-
$this->processIsolation = false;
3937
}
4038

4139
/**
@@ -129,14 +127,4 @@ private function readline()
129127

130128
return $line;
131129
}
132-
133-
public function getProcessIsolation()
134-
{
135-
return $this->processIsolation;
136-
}
137-
138-
public function setProcessIsolation($processIsolation)
139-
{
140-
$this->processIsolation = (Boolean) $processIsolation;
141-
}
142130
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use PHPCR\Shell\Event\PhpcrShellEvents;
2121
use PHPCR\Shell\Console\Command\Phpcr\PhpcrShellCommand;
2222
use PHPCR\Shell\Config\Profile;
23+
use PHPCR\Shell\PhpcrShell;
2324

2425
/**
2526
* Main application for PHPCRSH
@@ -50,7 +51,7 @@ class ShellApplication extends Application
5051
*/
5152
public function __construct($container)
5253
{
53-
parent::__construct(SessionApplication::APP_NAME, SessionApplication::APP_VERSION);
54+
parent::__construct(PhpcrShell::APP_NAME, PhpcrShell::APP_VERSION);
5455
$this->dispatcher = $container->get('event.dispatcher') ? : new EventDispatcher();
5556
$this->setDispatcher($this->dispatcher);
5657
$this->container = $container;

src/PHPCR/Shell/DependencyInjection/Container.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44

55
use Symfony\Component\DependencyInjection\Reference;
66
use Symfony\Component\DependencyInjection\ContainerBuilder;
7+
use PHPCR\Shell\PhpcrShell;
78

89
class Container extends ContainerBuilder
910
{
10-
const MODE_EMBEDDED_SHELL = 'shell';
11-
const MODE_EMBEDDED_COMMAND = 'command';
12-
const MODE_STANDALONE = 'standalon';
13-
1411
protected $mode;
1512

1613
/**
@@ -22,7 +19,7 @@ class Container extends ContainerBuilder
2219
'transport.transport.fs' => 'PHPCR\Shell\Transport\Transport\JackalopeFs',
2320
);
2421

25-
public function __construct($mode = self::MODE_STANDALONE)
22+
public function __construct($mode = PhpcrShell::MODE_STANDALONE)
2623
{
2724
parent::__construct();
2825
$this->mode = $mode;
@@ -97,7 +94,7 @@ public function registerPhpcr()
9794

9895
public function registerEvent()
9996
{
100-
if ($this->mode === self::MODE_STANDALONE) {
97+
if ($this->mode === PhpcrShell::MODE_STANDALONE) {
10198
$this->register(
10299
'event.subscriber.profile_loader',
103100
'PHPCR\Shell\Subscriber\ProfileLoaderSubscriber'
@@ -148,10 +145,16 @@ public function registerEvent()
148145

149146
public function registerConsole()
150147
{
151-
$this->register('console.application.shell', 'PHPCR\Shell\Console\Application\ShellApplication')
152-
->addArgument(new Reference('container'));
148+
if ($this->mode === PhpcrShell::MODE_STANDALONE) {
149+
$this->register('application', 'PHPCR\Shell\Console\Application\ShellApplication')
150+
->addArgument(new Reference('container'));
151+
} else {
152+
$this->register('application', 'PHPCR\Shell\Console\Application\EmbeddedApplication')
153+
->addArgument(new Reference('container'));
154+
}
155+
153156
$this->register('console.input.autocomplete', 'PHPCR\Shell\Console\Input\AutoComplete')
154-
->addArgument(new Reference('console.application.shell'))
157+
->addArgument(new Reference('application'))
155158
->addArgument(new Reference('phpcr.session'));
156159
}
157160

0 commit comments

Comments
 (0)