|
8 | 8 | use Symfony\Component\Console\Input\InputInterface;
|
9 | 9 | use Symfony\Component\Console\Output\OutputInterface;
|
10 | 10 |
|
11 |
| -use PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper; |
| 11 | +use PHPCR\Shell\Console\Command\Query\SelectCommand; |
| 12 | +use PHPCR\Shell\Console\Command\Shell\ChangePathCommand; |
| 13 | +use PHPCR\Shell\Console\Command\Shell\PwdCommand; |
12 | 14 | use PHPCR\Shell\Console\Helper\ResultFormatterHelper;
|
13 |
| -use PHPCR\Util\Console\Helper\PhpcrHelper; |
14 |
| -use PHPCR\Util\Console\Helper\PhpcrCliHelper; |
| 15 | +use PHPCR\Shell\PhpcrSession; |
| 16 | +use PHPCR\SimpleCredentials; |
15 | 17 | use PHPCR\Util\Console\Command\NodeDumpCommand;
|
16 |
| -use PHPCR\Shell\Console\Command\Query\SelectCommand; |
17 | 18 | use PHPCR\Util\Console\Command\NodeMoveCommand;
|
18 | 19 | use PHPCR\Util\Console\Command\NodeRemoveCommand;
|
19 |
| -use PHPCR\Util\Console\Command\NodesUpdateCommand; |
20 | 20 | use PHPCR\Util\Console\Command\NodeTouchCommand;
|
21 | 21 | use PHPCR\Util\Console\Command\NodeTypeListCommand;
|
22 | 22 | use PHPCR\Util\Console\Command\NodeTypeRegisterCommand;
|
| 23 | +use PHPCR\Util\Console\Command\NodesUpdateCommand; |
23 | 24 | use PHPCR\Util\Console\Command\WorkspaceCreateCommand;
|
24 | 25 | use PHPCR\Util\Console\Command\WorkspaceDeleteCommand;
|
25 | 26 | use PHPCR\Util\Console\Command\WorkspaceExportCommand;
|
26 | 27 | use PHPCR\Util\Console\Command\WorkspaceImportCommand;
|
27 | 28 | use PHPCR\Util\Console\Command\WorkspaceListCommand;
|
28 | 29 | use PHPCR\Util\Console\Command\WorkspacePurgeCommand;
|
| 30 | +use PHPCR\Util\Console\Helper\PhpcrCliHelper; |
| 31 | +use PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper; |
| 32 | +use PHPCR\Util\Console\Helper\PhpcrHelper; |
29 | 33 | use Symfony\Component\Console\Command\Command;
|
30 |
| -use PHPCR\Shell\Console\Command\Shell\ChangePathCommand; |
31 |
| -use PHPCR\Shell\Console\Command\Shell\PwdCommand; |
32 | 34 | use Symfony\Component\Console\Input\ArrayInput;
|
| 35 | +use PHPCR\Shell\Console\Command\Shell\ExitCommand; |
33 | 36 |
|
34 | 37 | class ShellApplication extends Application
|
35 | 38 | {
|
36 |
| - public function __construct(SessionInterface $session) |
| 39 | + public function __construct(InputInterface $input) |
37 | 40 | {
|
38 | 41 | parent::__construct('PHPCR', '1.0');
|
39 | 42 |
|
40 | 43 | $this->add(new SelectCommand());
|
41 | 44 | $this->add(new ChangePathCommand());
|
42 | 45 | $this->add(new PwdCommand());
|
| 46 | + $this->add(new ExitCommand()); |
43 | 47 |
|
44 | 48 | $this->add($this->wrap(new NodeDumpCommand())
|
45 | 49 | ->setName('ls')
|
@@ -85,12 +89,52 @@ public function __construct(SessionInterface $session)
|
85 | 89 | ->setName('workspace-purge')
|
86 | 90 | );
|
87 | 91 |
|
| 92 | + $session = $this->getSession($input, $workspace); |
| 93 | + |
88 | 94 | $this->getHelperSet()->set(new PhpcrConsoleDumperHelper());
|
89 | 95 | $this->getHelperSet()->set(new ResultFormatterHelper());
|
90 | 96 | $this->getHelperSet()->set(new PhpcrHelper($session));
|
91 | 97 | $this->getHelperSet()->set(new PhpcrCliHelper($session));
|
92 | 98 | }
|
93 | 99 |
|
| 100 | + private function getSession($input) |
| 101 | + { |
| 102 | + $transport = $this->getTransport($input); |
| 103 | + $repository = $transport->getRepository(); |
| 104 | + $credentials = new SimpleCredentials( |
| 105 | + $input->getOption('phpcr-username'), |
| 106 | + $input->getOption('phpcr-password') |
| 107 | + ); |
| 108 | + |
| 109 | + $session = $repository->login($credentials, $input->getOption('phpcr-workspace')); |
| 110 | + $session = new PhpcrSession($session); |
| 111 | + |
| 112 | + return $session; |
| 113 | + } |
| 114 | + |
| 115 | + private function getTransport(InputInterface $input) |
| 116 | + { |
| 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 | + |
| 124 | + $transportName = $input->getOption('transport'); |
| 125 | + |
| 126 | + if (!isset($transports[$transportName])) { |
| 127 | + throw new \InvalidArgumentException(sprintf( |
| 128 | + 'Unknown transport "%s", I have "%s"', |
| 129 | + $transportName, implode(', ', array_keys($transports)) |
| 130 | + )); |
| 131 | + } |
| 132 | + |
| 133 | + $transport = $transports[$transportName]; |
| 134 | + |
| 135 | + return $transport; |
| 136 | + } |
| 137 | + |
94 | 138 | public function wrap(Command $command)
|
95 | 139 | {
|
96 | 140 | return $command;
|
|
0 commit comments