15
15
class NodeListCommand extends Command
16
16
{
17
17
protected $ formatter ;
18
- protected $ filters ;
19
18
protected $ textHelper ;
20
19
protected $ maxLevel ;
21
20
@@ -26,7 +25,6 @@ protected function configure()
26
25
$ this ->addArgument ('path ' , InputArgument::OPTIONAL , 'Path of node ' , '. ' );
27
26
$ this ->addOption ('children ' , null , InputOption::VALUE_NONE , 'List only the children of this node ' );
28
27
$ this ->addOption ('properties ' , null , InputOption::VALUE_NONE , 'List only the properties of this node ' );
29
- $ this ->addOption ('filter ' , 'f ' , InputOption::VALUE_REQUIRED |InputOption::VALUE_IS_ARRAY , 'Optional filter to apply ' );
30
28
$ this ->addOption ('level ' , 'L ' , InputOption::VALUE_REQUIRED , 'Depth of tree to show ' );
31
29
$ this ->addOption ('template ' , 't ' , InputOption::VALUE_NONE , 'Show template nodes and properties ' );
32
30
$ this ->setHelp (<<<HERE
@@ -37,10 +35,12 @@ protected function configure()
37
35
The <info>node:list</info> command can also shows template nodes and properties as defined a nodes node-type by
38
36
using the <info>--template</info> option. Template nodes and properties are prefixed with the "@" symbol.
39
37
40
- The command accepts wither a path (relative or absolute) to the node or a UUID.
38
+ The command accepts either a path (relative or absolute) to the node, a UUID or a pattern:
41
39
42
40
PHPCRSH> node:list 842e61c0-09ab-42a9-87c0-308ccc90e6f4
43
41
PHPCRSH> node:list /tests/foobar
42
+ PHPCRSH> node:list /tests/*/foobar
43
+ PHPCRSH> node:list /tests/*/foo*
44
44
HERE
45
45
);
46
46
}
@@ -49,7 +49,6 @@ public function execute(InputInterface $input, OutputInterface $output)
49
49
{
50
50
$ this ->formatter = $ this ->getHelper ('result_formatter ' );
51
51
$ this ->textHelper = $ this ->getHelper ('text ' );
52
- $ this ->filters = $ input ->getOption ('filter ' );
53
52
$ this ->maxLevel = $ input ->getOption ('level ' );
54
53
55
54
$ this ->showChildren = $ input ->getOption ('children ' );
@@ -58,35 +57,53 @@ public function execute(InputInterface $input, OutputInterface $output)
58
57
59
58
$ session = $ this ->getHelper ('phpcr ' )->getSession ();
60
59
$ path = $ input ->getArgument ('path ' );
60
+ $ filter = null ;
61
61
62
- $ currentNode = $ session ->getNodeByPathOrIdentifier ($ path );
62
+ try {
63
+ $ nodes = array ($ session ->getNodeByPathOrIdentifier ($ path ));
64
+ } catch (\Exception $ e ) {
65
+ $ parentPath = $ this ->getHelper ('path ' )->getParentPath ($ path );
66
+
67
+ $ filter = substr ($ path , strlen ($ parentPath ));
68
+
69
+ if ($ filter [0 ] == '/ ' ) {
70
+ $ filter = substr ($ filter , 1 );
71
+ }
72
+
73
+ $ nodes = $ session ->findNodes ($ parentPath );
74
+ }
63
75
64
76
if (!$ this ->showChildren && !$ this ->showProperties ) {
65
77
$ this ->showChildren = true ;
66
78
$ this ->showProperties = true ;
67
79
}
68
80
69
- $ table = $ this ->getHelper ('table ' )->create ();
81
+ foreach ($ nodes as $ node ) {
82
+ $ table = $ this ->getHelper ('table ' )->create ();
83
+ $ this ->renderNode ($ node , $ table , array (), $ filter );
70
84
71
- $ this ->renderNode ($ currentNode , $ table );
85
+ if ($ table ->getNumberOfRows () > 0 ) {
86
+ $ output ->writeln ('<info> ' . $ node ->getPath () . '</info> ' );
87
+ $ table ->render ($ output );
88
+ }
89
+ }
72
90
73
- $ table ->render ($ output );
74
91
}
75
92
76
- private function renderNode ($ currentNode , $ table , $ spacers = array ())
93
+ private function renderNode ($ currentNode , $ table , $ spacers = array (), $ filter = null )
77
94
{
78
95
if ($ this ->showChildren ) {
79
- $ this ->renderChildren ($ currentNode , $ table , $ spacers );
96
+ $ this ->renderChildren ($ currentNode , $ table , $ spacers, $ filter );
80
97
}
81
98
82
99
if ($ this ->showProperties ) {
83
- $ this ->renderProperties ($ currentNode , $ table , $ spacers );
100
+ $ this ->renderProperties ($ currentNode , $ table , $ spacers, $ filter );
84
101
}
85
102
}
86
103
87
- private function renderChildren ($ currentNode , $ table , $ spacers )
104
+ private function renderChildren ($ currentNode , $ table , $ spacers, $ filter = null )
88
105
{
89
- $ children = $ currentNode ->getNodes ($ this -> filters ? : null );
106
+ $ children = $ currentNode ->getNodes ($ filter ? : null );
90
107
91
108
$ nodeType = $ currentNode ->getPrimaryNodeType ();
92
109
$ childNodeDefinitions = $ nodeType ->getDeclaredChildNodeDefinitions ();
@@ -147,9 +164,9 @@ private function renderChildren($currentNode, $table, $spacers)
147
164
}
148
165
}
149
166
150
- private function renderProperties ($ currentNode , $ table , $ spacers )
167
+ private function renderProperties ($ currentNode , $ table , $ spacers, $ filter = null )
151
168
{
152
- $ properties = $ currentNode ->getProperties ($ this -> filters ? : null );
169
+ $ properties = $ currentNode ->getProperties ($ filter ? : null );
153
170
154
171
try {
155
172
$ primaryItem = $ currentNode ->getPrimaryItem ();
0 commit comments