Skip to content

Commit f0def3c

Browse files
committed
Show template nodes / properties
1 parent 2e6930c commit f0def3c

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ private function configureFormatter(OutputFormatter $formatter)
250250
$style = new OutputFormatterStyle(null, null, array('bold'));
251251
$formatter->setStyle('node', $style);
252252

253+
$style = new OutputFormatterStyle('blue', null, array('bold'));
254+
$formatter->setStyle('templatenode', $style);
255+
256+
$style = new OutputFormatterStyle('blue', null, array());
257+
$formatter->setStyle('templateproperty', $style);
258+
253259
$style = new OutputFormatterStyle(null, null, array());
254260
$formatter->setStyle('property', $style);
255261

src/PHPCR/Shell/Console/Command/Phpcr/NodeListCommand.php

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Symfony\Component\Console\Output\OutputInterface;
88
use Symfony\Component\Console\Input\InputArgument;
99
use Symfony\Component\Console\Input\InputOption;
10+
use PHPCR\PropertyType;
1011

1112
class NodeListCommand extends Command
1213
{
@@ -24,8 +25,14 @@ protected function configure()
2425
$this->addOption('properties', null, InputOption::VALUE_NONE, 'List only the properties of this node');
2526
$this->addOption('filter', 'f', InputOption::VALUE_REQUIRED|InputOption::VALUE_IS_ARRAY, 'Optional filter to apply');
2627
$this->addOption('level', 'L', InputOption::VALUE_REQUIRED, 'Depth of tree to show');
28+
$this->addOption('no-template', 'T', InputOption::VALUE_REQUIRED, 'Do not show template nodes and properties');
2729
$this->setHelp(<<<HERE
2830
List both or one of the children and properties of this node.
31+
32+
Multiple levels can be shown by using the <info>--level</info> option.
33+
34+
The <info>node:list</info> command also shows template nodes and properties as defined a nodes node-type.
35+
These can be suppressed using the <info>--no-template</info> option.
2936
HERE
3037
);
3138
}
@@ -72,9 +79,20 @@ private function renderChildren($currentNode, $table, $spacers)
7279
{
7380
$children = $currentNode->getNodes($this->filters ? : null);
7481

82+
$nodeType = $currentNode->getPrimaryNodeType();
83+
$childNodeDefinitions = $nodeType->getDeclaredChildNodeDefinitions();
84+
$childNodeNames = array();
85+
foreach ($childNodeDefinitions as $childNodeDefinition) {
86+
$childNodeNames[$childNodeDefinition->getName()] = $childNodeDefinition;
87+
}
88+
7589
$i = 0;
7690
foreach ($children as $child) {
7791
$i++;
92+
if (isset($childNodeNames[$child->getName()])) {
93+
unset($childNodeNames[$child->getName()]);
94+
}
95+
7896
$isLast = count($children) === $i;
7997

8098
$table->addRow(array(
@@ -94,20 +112,50 @@ private function renderChildren($currentNode, $table, $spacers)
94112
$this->renderNode($child, $table, $newSpacers);
95113
}
96114
}
115+
116+
// render empty schematic children
117+
foreach ($childNodeNames as $childNodeName => $childNodeDefinition) {
118+
// @todo: Determine and show cardinality, 1..*, *..*, 0..1, etc.
119+
$table->addRow(array(
120+
'<templatenode>' . implode('', $spacers) . '@' . $childNodeName . '</templatenode>',
121+
implode('|', $childNodeDefinition->getRequiredPrimaryTypeNames()),
122+
'',
123+
));
124+
}
97125
}
98126

99127
private function renderProperties($currentNode, $table, $spacers)
100128
{
101129
$properties = $currentNode->getProperties($this->filters ? : null);
102130

131+
$nodeType = $currentNode->getPrimaryNodeType();
132+
$propertyDefinitions = $nodeType->getDeclaredPropertyDefinitions();
133+
134+
$propertyNames = array();
135+
foreach ($propertyDefinitions as $name => $propertyDefinition) {
136+
$propertyNames[$propertyDefinition->getName()] = $propertyDefinition;
137+
}
138+
103139
$i = 0;
104140
foreach ($properties as $name => $property) {
105141
$i++;
142+
if (isset($propertyNames[$name])) {
143+
unset($propertyNames[$name]);
144+
}
145+
106146
$table->addRow(array(
107147
'<property>' . implode('', $spacers). $name . '</property>',
108148
'<property-type>' . $this->formatter->getPropertyTypeName($property->getType()) . '</property-type>',
109149
$this->textHelper->truncate($this->formatter->formatValue($property), 55),
110150
));
111151
}
152+
153+
foreach ($propertyNames as $propertyName => $property) {
154+
$table->addRow(array(
155+
'<templateproperty>' . implode('', $spacers). '@' . $propertyName . '</templateproperty>',
156+
'<property-type>' . strtoupper(PropertyType::nameFromValue($property->getRequiredType())) . '</property-type>',
157+
''
158+
));
159+
}
112160
}
113161
}

src/PHPCR/Shell/Resources/config.dist/alias.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exit: shell:exit
1616

1717
# Node commands
1818
ls: node:list {arg1}
19-
sl: node:clone {arg1} {arg2} # symlink, as in ln -s
19+
ln: node:clone {arg1} {arg2} # symlink, as in ln -s
2020
cp: node:copy {arg1} {arg2}
2121
cat: node:property:show {arg1}
2222
touch: node:property:set {arg1} {arg2} {arg3}

0 commit comments

Comments
 (0)