Skip to content

Commit 7748134

Browse files
committed
Refactoring
1 parent d989623 commit 7748134

File tree

12 files changed

+130
-107
lines changed

12 files changed

+130
-107
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"require": {
55
"symfony/console": "2.1.*",
66
"jackalope/jackalope-doctrine-dbal": "dev-master",
7+
"jackalope/jackalope-jackrabbit": "dev-master",
78
"jackalope/jackalope": "dev-master",
89
"phpcr/phpcr": "dev-master",
910
"phpcr/phpcr-utils": "dev-master"

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use Symfony\Component\Process\PhpExecutableFinder;
99
use Symfony\Component\Console\Shell as BaseShell;
1010
use PHPCR\Shell\Console\Input\StringInput;
11-
use PHPCR\Shell\Context;
1211

1312
class Shell
1413
{
@@ -44,7 +43,6 @@ public function run()
4443
{
4544
$this->application->setAutoExit(false);
4645
$this->application->setCatchExceptions(true);
47-
$context = new Context('/');
4846

4947
if ($this->hasReadline) {
5048
readline_read_history($this->history);

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

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,31 @@
3333
use Symfony\Component\Console\Command\Command;
3434
use Symfony\Component\Console\Input\ArrayInput;
3535
use PHPCR\Shell\Console\Command\Shell\ExitCommand;
36+
use PHPCR\Shell\Console\TransportInterface;
3637

3738
class ShellApplication extends Application
3839
{
39-
public function __construct(InputInterface $input)
40+
protected $transports;
41+
42+
public function __construct(InputInterface $input, $transports = array())
4043
{
4144
parent::__construct('PHPCR', '1.0');
4245

46+
// initialize transports
47+
foreach (array_merge(array(
48+
new \PHPCR\Shell\Transport\DoctrineDbal($input),
49+
new \PHPCR\Shell\Transport\Jackrabbit($input),
50+
), $transports) as $transport) {
51+
$this->transports[$transport->getName()] = $transport;;
52+
}
53+
54+
// add shell-specific commands
4355
$this->add(new SelectCommand());
4456
$this->add(new ChangePathCommand());
4557
$this->add(new PwdCommand());
4658
$this->add(new ExitCommand());
4759

60+
// wrap phpcr-util commands
4861
$this->add($this->wrap(new NodeDumpCommand())
4962
->setName('ls')
5063
->setDescription('Alias for dump')
@@ -89,7 +102,7 @@ public function __construct(InputInterface $input)
89102
->setName('workspace-purge')
90103
);
91104

92-
$session = $this->getSession($input, $workspace);
105+
$session = $this->getSession($input);
93106

94107
$this->getHelperSet()->set(new PhpcrConsoleDumperHelper());
95108
$this->getHelperSet()->set(new ResultFormatterHelper());
@@ -114,23 +127,16 @@ private function getSession($input)
114127

115128
private function getTransport(InputInterface $input)
116129
{
117-
foreach (array(
118-
new \PHPCR\Shell\Transport\DoctrineDbal($input),
119-
new \PHPCR\Shell\Transport\Jackrabbit($input),
120-
) as $transport) {
121-
$transports[$transport->getName()] = $transport;
122-
}
123-
124130
$transportName = $input->getOption('transport');
125131

126-
if (!isset($transports[$transportName])) {
132+
if (!isset($this->transports[$transportName])) {
127133
throw new \InvalidArgumentException(sprintf(
128134
'Unknown transport "%s", I have "%s"',
129-
$transportName, implode(', ', array_keys($transports))
135+
$transportName, implode(', ', array_keys($this->transports))
130136
));
131137
}
132138

133-
$transport = $transports[$transportName];
139+
$transport = $this->transports[$transportName];
134140

135141
return $transport;
136142
}

src/PHPCR/Shell/Console/Command/AbstractSessionCommand.php

Lines changed: 0 additions & 24 deletions
This file was deleted.

src/PHPCR/Shell/Console/Command/Query/SelectCommand.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22

33
namespace PHPCR\Shell\Console\Command\Query;
44

5-
use PHPCR\Shell\Console\ShellQueryCommand;
5+
use Symfony\Component\Console\Command\Command;
66
use Symfony\Component\Console\Input\InputInterface;
7-
use Symfony\Component\Console\Output\OutputInterface;
87
use Symfony\Component\Console\Input\InputOption;
9-
use PHPCR\Shell\Console\Command\AbstractSessionCommand;
8+
use Symfony\Component\Console\Output\OutputInterface;
109

11-
class SelectCommand extends AbstractSessionCommand
10+
class SelectCommand extends Command
1211
{
1312
protected function configure()
1413
{

src/PHPCR/Shell/Console/Command/Shell/ChangePathCommand.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
namespace PHPCR\Shell\Console\Command\Shell;
44

5-
use PHPCR\Shell\Console\ShellQueryCommand;
5+
use PHPCR\PathNotFoundException;
6+
use Symfony\Component\Console\Command\Command;
67
use Symfony\Component\Console\Input\InputInterface;
78
use Symfony\Component\Console\Output\OutputInterface;
8-
use Symfony\Component\Console\Input\InputOption;
9-
use PHPCR\Shell\Console\Command\AbstractSessionCommand;
10-
use PHPCR\ItemNotFoundException;
11-
use PHPCR\PathNotFoundException;
129

13-
class ChangePathCommand extends AbstractSessionCommand
10+
class ChangePathCommand extends Command
1411
{
1512
protected function configure()
1613
{

src/PHPCR/Shell/Console/Command/Shell/PwdCommand.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
namespace PHPCR\Shell\Console\Command\Shell;
44

5-
use PHPCR\Shell\Console\ShellQueryCommand;
65
use Symfony\Component\Console\Input\InputInterface;
76
use Symfony\Component\Console\Output\OutputInterface;
8-
use Symfony\Component\Console\Input\InputOption;
9-
use PHPCR\Shell\Console\Command\AbstractSessionCommand;
7+
use Symfony\Component\Console\Command\Command;
108

11-
class PwdCommand extends AbstractSessionCommand
9+
class PwdCommand extends Command
1210
{
1311
protected function configure()
1412
{
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Command\Shell;
4+
5+
use Symfony\Component\Console\Input\InputInterface;
6+
use Symfony\Component\Console\Output\OutputInterface;
7+
use Symfony\Component\Console\Command\Command;
8+
9+
class WorkspaceChangeCommand extends Command
10+
{
11+
protected function configure()
12+
{
13+
$this->setName('workspace-change');
14+
$this->addArgument('workspace');
15+
$this->setDescription('Change to a different workspace');
16+
}
17+
18+
public function execute(InputInterface $input, OutputInterface $output)
19+
{
20+
}
21+
}
22+
23+
24+

src/PHPCR/Shell/Console/Command/ShellCommand.php

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use Symfony\Component\Console\Input\InputOption;
99
use PHPCR\Shell\Console\Application\ShellApplication;
1010
use PHPCR\Shell\Console\Application\Shell;
11-
use PHPCR\SimpleCredentials;
12-
use PHPCR\Shell\PhpcrSession;
1311

1412
class ShellCommand extends Command
1513
{
@@ -42,41 +40,7 @@ public function configure()
4240

4341
public function execute(InputInterface $input, OutputInterface $output)
4442
{
45-
$transport = $this->getTransport($input);
46-
$repository = $transport->getRepository();
47-
48-
$credentials = new SimpleCredentials(
49-
$input->getOption('phpcr-username'),
50-
$input->getOption('phpcr-password')
51-
);
52-
53-
$session = $repository->login($credentials);
54-
$session = new PhpcrSession($session);
55-
56-
$application = new Shell(new ShellApplication($session));
43+
$application = new Shell(new ShellApplication($input));
5744
$application->run($input, $output);
5845
}
59-
60-
protected function getTransport(InputInterface $input)
61-
{
62-
foreach (array(
63-
new \PHPCR\Shell\Transport\DoctrineDbal($input),
64-
new \PHPCR\Shell\Transport\Jackrabbit($input),
65-
) as $transport) {
66-
$transports[$transport->getName()] = $transport;
67-
}
68-
69-
$transportName = $input->getOption('transport');
70-
71-
if (!isset($transports[$transportName])) {
72-
throw new \InvalidArgumentException(sprintf(
73-
'Unknown transport "%s", I have "%s"',
74-
$transportName, implode(', ', array_keys($transports))
75-
));
76-
}
77-
78-
$transport = $transports[$transportName];
79-
80-
return $transport;
81-
}
8246
}

src/PHPCR/Shell/Context.php

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)