Skip to content

Commit 9894a06

Browse files
committed
cleaning up the dump command parameters
1 parent 2f586fb commit 9894a06

File tree

4 files changed

+140
-72
lines changed

4 files changed

+140
-72
lines changed

README.md

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -28,36 +28,35 @@ NOTE: If you are using PHPCR inside of Symfony, the DoctrinePHPCRBundle
2828
provides the commands inside the normal Symfony console and you don't need to
2929
prepare anything special.
3030

31-
* ``phpcr:workspace:create <name>``: Create the workspace name in the configured repository
32-
* ``phpcr:register-node-types --allow-update [cnd-file]``: Register namespaces and node types from a "Compact Node Type Definition" .cnd file
33-
* ``phpcr:dump [--sys_nodes[="..."]] [--props[="..."]] [path]``: Show the node names
34-
under the specified path. If you set sys_nodes=yes you will also see system nodes.
35-
If you set props=yes you will additionally see all properties of the dumped nodes.
36-
* ``phpcr:purge``: Remove all content from the configured repository in the
37-
configured workspace
38-
* ``phpcr:sql2``: Run a query in the JCR SQL2 language against the repository and dump
39-
the resulting rows to the console.
40-
41-
**TODO:**
42-
43-
* Implement commands for phpcr:import and phpcr:export to import and export the
44-
PHPCR document view and system view XML dumps.
45-
* Implement a simple .cnd parser in PHP and use it to make register-node-types
46-
work with all repositories
47-
31+
To get a list of the available commands, run `bin/phpcr` or set the commands up
32+
in your application. Running `bin/phpcr help <command-name>` outputs the
33+
documentation of that command.
4834

4935
## Helper Classes
5036

5137
The helper classes provide implementations for basic common tasks to help users
52-
and implementors of PHPCR. They are all in the namespace PHPCR\Util
38+
and implementers of PHPCR. They are all in the namespace PHPCR\Util
5339

40+
### PathHelper
5441

55-
### TraversingItemVisitor
42+
Used to manipulate paths. Implementations are recommended to use this, and
43+
applications also profit from it. Using `dirname` and similar file system
44+
operations on paths is not compatible with Microsoft Windows systems, thus you
45+
should always use the methods in PathHelper.
5646

57-
This ``ItemVisitorInterface`` implementation is a basic implementation of crawling
58-
a PHPCR tree. You can extend it to define what it should do while crawling the
59-
tree.
47+
### NodeHelper
48+
49+
This helper has some generally useful methods like one to generate empty
50+
`nt:unstructured` nodes to make sure a parent path exists. It also provides
51+
some useful helper methods for implementations.
52+
53+
### UUIDHelper
6054

55+
This little helper is mainly of interest for PHPCR implementers. It generates
56+
valid *Universally Unique IDs* and can determine whether a given string is a
57+
valid UUID.
58+
We recommend all implementations to use this implementation to guarantee
59+
consistent behaviour.
6160

6261
### QOM QueryBuilder
6362

@@ -66,25 +65,15 @@ The ``QueryBuilder`` is a fluent query builder with method names matching the
6665
on top of the QOM factory. It is the easiest way to programmatically build a
6766
PHPCR query.
6867

69-
7068
### Query Object Model Converter
7169

7270
In the PHPCR\Util\QOM namespace we provide, implementation-independant code to
7371
convert between SQL2 and QOM. ``Sql2ToQomQueryConverter`` parses SQL2 queries
7472
into QOM . ``QomToSql2QueryConverter`` generates SQL2 out of a QOM.
7573

74+
### TraversingItemVisitor
7675

77-
### UUIDHelper
78-
79-
This little helper is mainly of interest for PHPCR implementors. It generates
80-
valid *Universally Unique IDs* and can determine wheter a given string is a
81-
valid UUID.
82-
We recommend all implementations to use this implementation to guarantee
83-
constistent behaviour.
84-
85-
86-
# TODO
87-
88-
Move tests about the query converter from phpcr-api-tests tests/06_Query/QOM to
89-
the tests folder. How to do the tests without a QOM factory implementation?
76+
This ``ItemVisitorInterface`` implementation is a basic implementation of crawling
77+
a PHPCR tree. You can extend it to define what it should do while crawling the
78+
tree.
9079

src/PHPCR/Util/Console/Command/NodeDumpCommand.php

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,18 @@
2121

2222
namespace PHPCR\Util\Console\Command;
2323

24-
use PHPCR\Util\UUIDHelper;
2524
use PHPCR\ItemNotFoundException;
2625
use PHPCR\RepositoryException;
2726
use PHPCR\PathNotFoundException;
27+
28+
use PHPCR\Util\UUIDHelper;
29+
use PHPCR\Util\Console\Helper\PhpcrConsoleDumperHelper;
30+
2831
use Symfony\Component\Console\Input\InputArgument;
2932
use Symfony\Component\Console\Input\InputOption;
3033
use Symfony\Component\Console\Input\InputInterface;
3134
use Symfony\Component\Console\Output\OutputInterface;
3235

33-
use PHPCR\Util\TreeWalker;
34-
use PHPCR\Util\Console\Helper\TreeDumper\ConsoleDumperNodeVisitor;
35-
use PHPCR\Util\Console\Helper\TreeDumper\ConsoleDumperPropertyVisitor;
36-
use PHPCR\Util\Console\Helper\TreeDumper\SystemNodeFilter;
37-
3836
/**
3937
* Command subtrees under a path to the console
4038
*
@@ -43,21 +41,14 @@
4341
*/
4442
class NodeDumpCommand extends BaseCommand
4543
{
46-
/**
47-
* Limit after which to cut lines when dumping properties
48-
*
49-
* @var int
50-
*/
51-
private $dump_max_line_length = 120;
52-
5344
/**
5445
* {@inheritDoc}
5546
*/
5647
protected function configure()
5748
{
5849
$this
5950
->setName('phpcr:node:dump')
60-
->addOption('sys_nodes', null, InputOption::VALUE_NONE, 'Also dump system nodes')
51+
->addOption('sys-nodes', null, InputOption::VALUE_NONE, 'Also dump system nodes (recommended to use with a depth limit)')
6152
->addOption('props', null, InputOption::VALUE_NONE, 'Also dump properties of the nodes')
6253
->addOption('identifiers', null, InputOption::VALUE_NONE, 'Also output node UUID')
6354
->addOption('depth', null, InputOption::VALUE_OPTIONAL, 'Limit how many level of children to show', "-1")
@@ -72,29 +63,20 @@ protected function configure()
7263
displayed as yaml arrays.
7364
7465
By default the command filters out system nodes and properties (i.e. nodes and
75-
properties with names starting with 'jcr:'), the <info>sys_nodes</info> option
66+
properties with names starting with 'jcr:'), the <info>--sys-nodes</info> option
7667
allows to turn this filter off.
7768
HERE
7869
)
7970
;
8071
}
8172

82-
/**
83-
* Change at which length lines in the dump get cut.
84-
*
85-
* @param int $length maximum line length after which to cut the output.
86-
*/
87-
public function setDumpMaxLineLength($length)
88-
{
89-
$this->dump_max_line_length = $length;
90-
}
91-
9273
/**
9374
* {@inheritDoc}
9475
*/
9576
protected function execute(InputInterface $input, OutputInterface $output)
9677
{
9778
$session = $this->getPhpcrSession();
79+
/** @var $dumperHelper PhpcrConsoleDumperHelper */
9880
$dumperHelper = $this->getHelper('phpcr_console_dumper');
9981

10082
// node to dump

src/PHPCR/Util/PathHelper.php

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ class PathHelper
3636
/**
3737
* Do not create an instance of this class
3838
*/
39+
// @codeCoverageIgnoreStart
3940
private function __construct()
4041
{
4142
}
43+
// @codeCoverageIgnoreEnd
4244

4345
/**
4446
* Check whether this is a syntactically valid absolute path.
@@ -141,15 +143,21 @@ public static function assertValidLocalName($name, $throw = true)
141143
public static function normalizePath($path, $destination = false, $throw = true)
142144
{
143145
if (!is_string($path)) {
144-
throw new RepositoryException('Expected string but got ' . gettype($path));
145-
}
146+
if ($throw) {
147+
throw new RepositoryException('Expected string but got ' . gettype($path));
148+
}
146149

150+
return false;
151+
}
147152
if (strlen($path) === 0) {
148-
throw new RepositoryException('Path must not be of zero length');
153+
if ($throw) {
154+
throw new RepositoryException('Path must not be of zero length');
155+
}
156+
157+
return false;
149158
}
150159

151160
if ('/' === $path) {
152-
153161
return '/';
154162
}
155163

@@ -211,9 +219,28 @@ public static function normalizePath($path, $destination = false, $throw = true)
211219
*/
212220
public static function absolutizePath($path, $context, $destination = false, $throw = true)
213221
{
214-
if (! $path) {
215-
throw new RepositoryException('empty path');
222+
if (!is_string($path)) {
223+
if ($throw) {
224+
throw new RepositoryException('Expected string path but got ' . gettype($path));
225+
}
226+
227+
return false;
216228
}
229+
if (!is_string($context)) {
230+
if ($throw) {
231+
throw new RepositoryException('Expected string context but got ' . gettype($context));
232+
}
233+
234+
return false;
235+
}
236+
if (strlen($path) === 0) {
237+
if ($throw) {
238+
throw new RepositoryException('Path must not be of zero length');
239+
}
240+
241+
return false;
242+
}
243+
217244
if ('/' !== $path[0]) {
218245
$path = ('/' === $context) ? "/$path" : "$context/$path";
219246
}

tests/PHPCR/Tests/Util/Console/Command/NodeDumpCommandTest.php

Lines changed: 75 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,18 @@
22

33
namespace PHPCR\Tests\Util\Console\Command;
44

5+
use PHPCR\ItemNotFoundException;
6+
use PHPCR\Util\UUIDHelper;
57
use Symfony\Component\Console\Application;
8+
9+
use PHPCR\Util\TreeWalker;
610
use PHPCR\Util\Console\Command\NodeDumpCommand;
711

812
class NodeDumpCommandTest extends BaseCommandTest
913
{
14+
/** @var TreeWalker|\PHPUnit_Framework_MockObject_MockObject */
15+
protected $treeWalker;
16+
1017
public function setUp()
1118
{
1219
parent::setUp();
@@ -17,15 +24,78 @@ public function setUp()
1724

1825
public function testCommand()
1926
{
20-
$this->dumperHelper->expects($this->once())
27+
$this->dumperHelper
28+
->expects($this->once())
29+
->method('getTreeWalker')
30+
->will($this->returnValue($this->treeWalker))
31+
;
32+
$this->session
33+
->expects($this->once())
34+
->method('getNode')
35+
->with('/')
36+
->will($this->returnValue($this->node1))
37+
;
38+
$this->treeWalker
39+
->expects($this->once())
40+
->method('traverse')
41+
->with($this->node1)
42+
;
43+
44+
$this->application->add(new NodeDumpCommand());
45+
46+
$this->executeCommand('phpcr:node:dump', array());
47+
}
48+
49+
public function testCommandIdentifier()
50+
{
51+
$uuid = UUIDHelper::generateUUID();
52+
53+
$this->dumperHelper
54+
->expects($this->once())
2155
->method('getTreeWalker')
22-
->will($this->returnValue($this->treeWalker));
23-
$this->session->expects($this->once())
56+
->will($this->returnValue($this->treeWalker))
57+
;
58+
$this->session
59+
->expects($this->once())
60+
->method('getNodeByIdentifier')
61+
->with($uuid)
62+
->will($this->returnValue($this->node1))
63+
;
64+
$this->treeWalker
65+
->expects($this->once())
66+
->method('traverse')
67+
->with($this->node1)
68+
;
69+
70+
$this->application->add(new NodeDumpCommand());
71+
72+
$this->executeCommand('phpcr:node:dump', array('identifier' => $uuid));
73+
}
74+
75+
public function testInvalidRefFormat()
76+
{
77+
$this->application->add(new NodeDumpCommand());
78+
79+
try {
80+
$this->executeCommand('phpcr:node:dump', array('--ref-format' => 'xy'));
81+
$this->fail('invalid ref-format did not produce exception');
82+
} catch (\Exception $e) {
83+
// success
84+
}
85+
}
86+
87+
public function testNotFound()
88+
{
89+
$this->session
90+
->expects($this->once())
2491
->method('getNode')
25-
->will($this->returnValue($this->node1));
92+
->with('/')
93+
->will($this->throwException(new ItemNotFoundException()))
94+
;
2695

2796
$this->application->add(new NodeDumpCommand());
2897

29-
$ct = $this->executeCommand('phpcr:node:dump', array());
98+
$ct = $this->executeCommand('phpcr:node:dump', array(), 1);
99+
$this->assertContains('does not exist', $ct->getDisplay());
30100
}
31101
}

0 commit comments

Comments
 (0)