|
57 | 57 | use PHPCR\Shell\Console\Command\WorkspaceNamespaceListCommand; |
58 | 58 | use PHPCR\Shell\Console\Command\WorkspaceNamespaceRegisterCommand; |
59 | 59 | use PHPCR\Shell\Console\Command\WorkspaceNamespaceUnregisterCommand; |
| 60 | +use PHPCR\Shell\Console\Command\WorkspaceUseCommand; |
60 | 61 | use PHPCR\Shell\Console\Command\NodeTypeShowCommand; |
61 | 62 | use PHPCR\Shell\Console\Helper\EditorHelper; |
62 | 63 | use PHPCR\Shell\Console\Command\NodeTypeEditCommand; |
|
98 | 99 | class ShellApplication extends Application |
99 | 100 | { |
100 | 101 | protected $transports; |
101 | | - protected $credentials; |
102 | 102 | protected $initialized; |
103 | 103 | protected $sessionInput; |
104 | 104 |
|
| 105 | + /** |
| 106 | + * @var SessionInterface |
| 107 | + */ |
| 108 | + private $session; |
| 109 | + |
105 | 110 | /** |
106 | 111 | * Input from the shell command, containing the connection |
107 | 112 | * parameters etc. |
@@ -163,6 +168,7 @@ public function init() |
163 | 168 | $this->add(new WorkspaceNamespaceListCommand()); |
164 | 169 | $this->add(new WorkspaceNamespaceRegisterCommand()); |
165 | 170 | $this->add(new WorkspaceNamespaceUnregisterCommand()); |
| 171 | + $this->add(new WorkspaceUseCommand()); |
166 | 172 | $this->add(new NodeTypeShowCommand()); |
167 | 173 | $this->add(new NodeTypeEditCommand()); |
168 | 174 | $this->add(new NodeTypeUnregisterCommand()); |
@@ -233,31 +239,46 @@ public function init() |
233 | 239 | ->setName('workspace-purge') |
234 | 240 | ); |
235 | 241 |
|
236 | | - $session = $this->getSession($this->sessionInput); |
| 242 | + $this->initSession(); |
237 | 243 |
|
238 | | - $this->getHelperSet()->set(new EditorHelper($session)); |
| 244 | + $this->getHelperSet()->set(new EditorHelper($this->session)); |
239 | 245 | $this->getHelperSet()->set(new PhpcrConsoleDumperHelper()); |
240 | | - $this->getHelperSet()->set(new PhpcrHelper($session)); |
| 246 | + $this->getHelperSet()->set(new PhpcrHelper($this->session)); |
241 | 247 | $this->getHelperSet()->set(new ResultFormatterHelper()); |
242 | 248 | $this->getHelperSet()->set(new TextHelper()); |
243 | | - $this->getHelperSet()->set(new NodeHelper($session)); |
| 249 | + $this->getHelperSet()->set(new NodeHelper($this->session)); |
244 | 250 |
|
245 | 251 | $this->initialized = true; |
246 | 252 | } |
247 | 253 |
|
248 | | - private function getSession($input) |
| 254 | + private function initSession() |
249 | 255 | { |
250 | | - $transport = $this->getTransport($input); |
| 256 | + $transport = $this->getTransport($this->sessionInput); |
251 | 257 | $repository = $transport->getRepository(); |
252 | 258 | $credentials = new SimpleCredentials( |
253 | | - $input->getOption('phpcr-username'), |
254 | | - $input->getOption('phpcr-password') |
| 259 | + $this->sessionInput->getOption('phpcr-username'), |
| 260 | + $this->sessionInput->getOption('phpcr-password') |
255 | 261 | ); |
256 | 262 |
|
257 | | - $session = $repository->login($credentials, $input->getOption('phpcr-workspace')); |
258 | | - $session = new PhpcrSession($session); |
| 263 | + $session = $repository->login($credentials, $this->sessionInput->getOption('phpcr-workspace')); |
259 | 264 |
|
260 | | - return $session; |
| 265 | + if (!$this->session) { |
| 266 | + $this->session = new PhpcrSession($session); |
| 267 | + } else { |
| 268 | + $this->session->setPhpcrSession($session); |
| 269 | + } |
| 270 | + } |
| 271 | + |
| 272 | + /** |
| 273 | + * Change the current workspace |
| 274 | + * |
| 275 | + * @param string $workspaceName |
| 276 | + */ |
| 277 | + public function changeWorkspace($workspaceName) |
| 278 | + { |
| 279 | + $this->session->logout(); |
| 280 | + $this->sessionInput->setOption('phpcr-workspace', $workspaceName); |
| 281 | + $this->initSession($this->sessionInput); |
261 | 282 | } |
262 | 283 |
|
263 | 284 | private function getTransport(InputInterface $input) |
|
0 commit comments