Skip to content

Commit 8268072

Browse files
committed
Workspace namespace commands
1 parent deff679 commit 8268072

File tree

7 files changed

+172
-0
lines changed

7 files changed

+172
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Feature: List workspace namespaces and their prefixes
2+
In order to list the workspaces namespaces and corresponding prefixes
3+
As a user logged into the shell
4+
I should be able to execute a command which does that
5+
6+
Background:
7+
Given that I am logged in as "testuser"
8+
And the "session_data.xml" fixtures are loaded
9+
10+
Scenario: List namespaces
11+
Given I execute the "workspace:namespace:list" command
12+
Then the command should not fail
13+
And I should see a table containing the following rows:
14+
| Prefix | URI |
15+
| jcr | http://www.jcp.org/jcr/1.0 |
16+
| sv | http://www.jcp.org/jcr/sv/1.0 |
17+
| nt | http://www.jcp.org/jcr/nt/1.0 |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Feature: Register a namespace on the workspace
2+
In order to register a namespace in the current workspace
3+
As a user logged into the shell
4+
I should be able to execute a command which does that
5+
6+
Background:
7+
Given that I am logged in as "testuser"
8+
And the "clean.xml" system view fixtures are loaded
9+
10+
Scenario: List namespaces
11+
Given I execute the "workspace:namespace:register dcms http://foobar.com/ns" command
12+
Then the command should not fail
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
Feature: Unregister a namespace on the workspace
2+
In order to unregister a namespace in the current workspace
3+
As a user logged into the shell
4+
I should be able to execute a command which does that
5+
6+
Background:
7+
Given that I am logged in as "testuser"
8+
And the "session_data.xml" fixtures are loaded
9+
10+
Scenario: List namespaces
11+
Given the namespace "http://foobar.com/ns" with prefix "foo" exists
12+
And I execute the "workspace:namespace:unregister http://foobar.com/ns" command
13+
Then the command should fail
14+
And I should see the following:
15+
"""
16+
not supported by jackrabbit backend
17+
"""

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
use PHPCR\Shell\Console\Command\WorkspaceListCommand;
5656
use PHPCR\Shell\Console\Command\WorkspaceNodeCloneCommand;
5757
use PHPCR\Shell\Console\Command\WorkspaceNodeCopyCommand;
58+
use PHPCR\Shell\Console\Command\WorkspaceNamespaceListCommand;
59+
use PHPCR\Shell\Console\Command\WorkspaceNamespaceRegisterCommand;
60+
use PHPCR\Shell\Console\Command\WorkspaceNamespaceUnregisterCommand;
5861
use PHPCR\Shell\Console\Command\NodeTypeShowCommand;
5962
use PHPCR\Shell\Console\Helper\EditorHelper;
6063
use PHPCR\Shell\Console\Command\NodeTypeEditCommand;
@@ -147,6 +150,9 @@ public function init()
147150
$this->add(new WorkspaceListCommand());
148151
$this->add(new WorkspaceNodeCloneCommand());
149152
$this->add(new WorkspaceNodeCopyCommand());
153+
$this->add(new WorkspaceNamespaceListCommand());
154+
$this->add(new WorkspaceNamespaceRegisterCommand());
155+
$this->add(new WorkspaceNamespaceUnregisterCommand());
150156
$this->add(new NodeTypeShowCommand());
151157
$this->add(new NodeTypeEditCommand());
152158
$this->add(new NodeTypeUnregisterCommand());
@@ -188,6 +194,9 @@ public function init()
188194
$this->add($this->wrap(new NodeMoveCommand())
189195
->setName('mv')
190196
);
197+
$this->add($this->wrap(new NodeListCommand())
198+
->setName('ls')
199+
);
191200
$this->add($this->wrap(new NodeRemoveCommand())
192201
->setName('rm')
193202
);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
9+
class WorkspaceNamespaceListCommand extends Command
10+
{
11+
protected function configure()
12+
{
13+
$this->setName('workspace:namespace:list');
14+
$this->setDescription('List all namespace prefix to URI mappings in current workspace');
15+
$this->setHelp(<<<HERE
16+
List all namespace prefix to URI mappings in current workspace
17+
HERE
18+
);
19+
}
20+
21+
public function execute(InputInterface $input, OutputInterface $output)
22+
{
23+
$session = $this->getHelper('phpcr')->getSession();
24+
$workspace = $session->getWorkspace();
25+
$namespaceRegistry = $workspace->getNamespaceRegistry();
26+
27+
$prefixes = $namespaceRegistry->getPrefixes();
28+
29+
$table = clone $this->getHelper('table');
30+
$table->setHeaders(array('Prefix', 'URI'));
31+
32+
foreach ($prefixes as $prefix) {
33+
$uri = $namespaceRegistry->getURI($prefix);
34+
$table->addRow(array($prefix, $uri));
35+
}
36+
37+
$table->render($output);
38+
}
39+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
10+
class WorkspaceNamespaceRegisterCommand extends Command
11+
{
12+
protected function configure()
13+
{
14+
$this->setName('workspace:namespace:register');
15+
$this->setDescription('Sets a one-to-one mapping between prefix and uri in the global namespace');
16+
$this->addArgument('prefix', null, InputArgument::REQUIRED, 'The namespace prefix to be mapped');
17+
$this->addArgument('uri', null, InputArgument::REQUIRED, 'The URI to be mapped');
18+
$this->setHelp(<<<HERE
19+
List all namespace prefix to URI mappings in current session
20+
HERE
21+
);
22+
}
23+
24+
public function execute(InputInterface $input, OutputInterface $output)
25+
{
26+
$session = $this->getHelper('phpcr')->getSession();
27+
$workspace = $session->getWorkspace();
28+
$namespaceRegistry = $workspace->getNamespaceRegistry();
29+
30+
$prefix = $input->getArgument('prefix');
31+
$uri = $input->getArgument('uri');
32+
33+
$namespaceRegistry->registerNamespace($prefix, $uri);
34+
}
35+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Console\Command;
4+
5+
use Symfony\Component\Console\Command\Command;
6+
use Symfony\Component\Console\Input\InputInterface;
7+
use Symfony\Component\Console\Output\OutputInterface;
8+
use Symfony\Component\Console\Input\InputArgument;
9+
10+
class WorkspaceNamespaceUnregisterCommand extends Command
11+
{
12+
protected function configure()
13+
{
14+
$this->setName('workspace:namespace:unregister');
15+
$this->setDescription('Sets a one-to-one mapping between prefix and uri in the global namespace');
16+
$this->addArgument('uri', null, InputArgument::REQUIRED, 'The URI to be removed');
17+
$this->setHelp(<<<HERE
18+
Removes the specified namespace URI from namespace registry.
19+
20+
The following restrictions apply:
21+
22+
- Attempting to unregister a built-in namespace (jcr, nt, mix, sv, xml or
23+
the empty namespace) will throw a NamespaceException.
24+
- An attempt to unregister a namespace that is not currently registered
25+
will throw a NamespaceException.
26+
- An implementation may prevent the unregistering of any other namespace
27+
for implementation-specific reasons by throwing a
28+
NamespaceException.
29+
HERE
30+
);
31+
}
32+
33+
public function execute(InputInterface $input, OutputInterface $output)
34+
{
35+
$session = $this->getHelper('phpcr')->getSession();
36+
$workspace = $session->getWorkspace();
37+
$namespaceRegistry = $workspace->getNamespaceRegistry();
38+
39+
$uri = $input->getArgument('uri');
40+
41+
$namespaceRegistry->unregisterNamespaceByURI($uri);
42+
}
43+
}

0 commit comments

Comments
 (0)