|
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; |
|
91 | 92 | class ShellApplication extends Application |
92 | 93 | { |
93 | 94 | protected $transports; |
94 | | - protected $credentials; |
95 | 95 | protected $initialized; |
96 | 96 | protected $sessionInput; |
97 | 97 |
|
| 98 | + /** |
| 99 | + * @var SessionInterface |
| 100 | + */ |
| 101 | + private $session; |
| 102 | + |
98 | 103 | /** |
99 | 104 | * Input from the shell command, containing the connection |
100 | 105 | * parameters etc. |
@@ -156,6 +161,7 @@ public function init() |
156 | 161 | $this->add(new WorkspaceNamespaceListCommand()); |
157 | 162 | $this->add(new WorkspaceNamespaceRegisterCommand()); |
158 | 163 | $this->add(new WorkspaceNamespaceUnregisterCommand()); |
| 164 | + $this->add(new WorkspaceUseCommand()); |
159 | 165 | $this->add(new NodeTypeShowCommand()); |
160 | 166 | $this->add(new NodeTypeEditCommand()); |
161 | 167 | $this->add(new NodeTypeUnregisterCommand()); |
@@ -219,31 +225,46 @@ public function init() |
219 | 225 | ->setName('workspace-purge') |
220 | 226 | ); |
221 | 227 |
|
222 | | - $session = $this->getSession($this->sessionInput); |
| 228 | + $this->initSession(); |
223 | 229 |
|
224 | | - $this->getHelperSet()->set(new EditorHelper($session)); |
| 230 | + $this->getHelperSet()->set(new EditorHelper($this->session)); |
225 | 231 | $this->getHelperSet()->set(new PhpcrConsoleDumperHelper()); |
226 | | - $this->getHelperSet()->set(new PhpcrHelper($session)); |
| 232 | + $this->getHelperSet()->set(new PhpcrHelper($this->session)); |
227 | 233 | $this->getHelperSet()->set(new ResultFormatterHelper()); |
228 | 234 | $this->getHelperSet()->set(new TextHelper()); |
229 | | - $this->getHelperSet()->set(new NodeHelper($session)); |
| 235 | + $this->getHelperSet()->set(new NodeHelper($this->session)); |
230 | 236 |
|
231 | 237 | $this->initialized = true; |
232 | 238 | } |
233 | 239 |
|
234 | | - private function getSession($input) |
| 240 | + private function initSession() |
235 | 241 | { |
236 | | - $transport = $this->getTransport($input); |
| 242 | + $transport = $this->getTransport($this->sessionInput); |
237 | 243 | $repository = $transport->getRepository(); |
238 | 244 | $credentials = new SimpleCredentials( |
239 | | - $input->getOption('phpcr-username'), |
240 | | - $input->getOption('phpcr-password') |
| 245 | + $this->sessionInput->getOption('phpcr-username'), |
| 246 | + $this->sessionInput->getOption('phpcr-password') |
241 | 247 | ); |
242 | 248 |
|
243 | | - $session = $repository->login($credentials, $input->getOption('phpcr-workspace')); |
244 | | - $session = new PhpcrSession($session); |
| 249 | + $session = $repository->login($credentials, $this->sessionInput->getOption('phpcr-workspace')); |
245 | 250 |
|
246 | | - return $session; |
| 251 | + if (!$this->session) { |
| 252 | + $this->session = new PhpcrSession($session); |
| 253 | + } else { |
| 254 | + $this->session->setPhpcrSession($session); |
| 255 | + } |
| 256 | + } |
| 257 | + |
| 258 | + /** |
| 259 | + * Change the current workspace |
| 260 | + * |
| 261 | + * @param string $workspaceName |
| 262 | + */ |
| 263 | + public function changeWorkspace($workspaceName) |
| 264 | + { |
| 265 | + $this->session->logout(); |
| 266 | + $this->sessionInput->setOption('phpcr-workspace', $workspaceName); |
| 267 | + $this->initSession($this->sessionInput); |
247 | 268 | } |
248 | 269 |
|
249 | 270 | private function getTransport(InputInterface $input) |
|
0 commit comments