1515class NodeListCommand extends Command
1616{
1717 protected $ formatter ;
18- protected $ filters ;
1918 protected $ textHelper ;
2019 protected $ maxLevel ;
2120
@@ -26,7 +25,6 @@ protected function configure()
2625 $ this ->addArgument ('path ' , InputArgument::OPTIONAL , 'Path of node ' , '. ' );
2726 $ this ->addOption ('children ' , null , InputOption::VALUE_NONE , 'List only the children of this node ' );
2827 $ 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 ' );
3028 $ this ->addOption ('level ' , 'L ' , InputOption::VALUE_REQUIRED , 'Depth of tree to show ' );
3129 $ this ->addOption ('template ' , 't ' , InputOption::VALUE_NONE , 'Show template nodes and properties ' );
3230 $ this ->setHelp (<<<HERE
@@ -37,10 +35,12 @@ protected function configure()
3735The <info>node:list</info> command can also shows template nodes and properties as defined a nodes node-type by
3836using the <info>--template</info> option. Template nodes and properties are prefixed with the "@" symbol.
3937
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:
4139
4240 PHPCRSH> node:list 842e61c0-09ab-42a9-87c0-308ccc90e6f4
4341 PHPCRSH> node:list /tests/foobar
42+ PHPCRSH> node:list /tests/*/foobar
43+ PHPCRSH> node:list /tests/*/foo*
4444HERE
4545 );
4646 }
@@ -49,7 +49,6 @@ public function execute(InputInterface $input, OutputInterface $output)
4949 {
5050 $ this ->formatter = $ this ->getHelper ('result_formatter ' );
5151 $ this ->textHelper = $ this ->getHelper ('text ' );
52- $ this ->filters = $ input ->getOption ('filter ' );
5352 $ this ->maxLevel = $ input ->getOption ('level ' );
5453
5554 $ this ->showChildren = $ input ->getOption ('children ' );
@@ -58,35 +57,53 @@ public function execute(InputInterface $input, OutputInterface $output)
5857
5958 $ session = $ this ->getHelper ('phpcr ' )->getSession ();
6059 $ path = $ input ->getArgument ('path ' );
60+ $ filter = null ;
6161
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+ }
6375
6476 if (!$ this ->showChildren && !$ this ->showProperties ) {
6577 $ this ->showChildren = true ;
6678 $ this ->showProperties = true ;
6779 }
6880
69- $ table = $ this ->getHelper ('table ' )->create ();
81+ foreach ($ nodes as $ node ) {
82+ $ table = $ this ->getHelper ('table ' )->create ();
83+ $ this ->renderNode ($ node , $ table , array (), $ filter );
7084
71- $ this ->renderNode ($ currentNode , $ table );
85+ if ($ table ->getNumberOfRows () > 0 ) {
86+ $ output ->writeln ('<info> ' . $ node ->getPath () . '</info> ' );
87+ $ table ->render ($ output );
88+ }
89+ }
7290
73- $ table ->render ($ output );
7491 }
7592
76- private function renderNode ($ currentNode , $ table , $ spacers = array ())
93+ private function renderNode ($ currentNode , $ table , $ spacers = array (), $ filter = null )
7794 {
7895 if ($ this ->showChildren ) {
79- $ this ->renderChildren ($ currentNode , $ table , $ spacers );
96+ $ this ->renderChildren ($ currentNode , $ table , $ spacers, $ filter );
8097 }
8198
8299 if ($ this ->showProperties ) {
83- $ this ->renderProperties ($ currentNode , $ table , $ spacers );
100+ $ this ->renderProperties ($ currentNode , $ table , $ spacers, $ filter );
84101 }
85102 }
86103
87- private function renderChildren ($ currentNode , $ table , $ spacers )
104+ private function renderChildren ($ currentNode , $ table , $ spacers, $ filter = null )
88105 {
89- $ children = $ currentNode ->getNodes ($ this -> filters ? : null );
106+ $ children = $ currentNode ->getNodes ($ filter ? : null );
90107
91108 $ nodeType = $ currentNode ->getPrimaryNodeType ();
92109 $ childNodeDefinitions = $ nodeType ->getDeclaredChildNodeDefinitions ();
@@ -147,9 +164,9 @@ private function renderChildren($currentNode, $table, $spacers)
147164 }
148165 }
149166
150- private function renderProperties ($ currentNode , $ table , $ spacers )
167+ private function renderProperties ($ currentNode , $ table , $ spacers, $ filter = null )
151168 {
152- $ properties = $ currentNode ->getProperties ($ this -> filters ? : null );
169+ $ properties = $ currentNode ->getProperties ($ filter ? : null );
153170
154171 try {
155172 $ primaryItem = $ currentNode ->getPrimaryItem ();
0 commit comments