diff --git a/src/PHPCR/Shell/Console/Application/.SessionApplication.php.swn b/src/PHPCR/Shell/Console/Application/.SessionApplication.php.swn
new file mode 100644
index 00000000..de637d24
Binary files /dev/null and b/src/PHPCR/Shell/Console/Application/.SessionApplication.php.swn differ
diff --git a/src/PHPCR/Shell/Console/Application/.ShellApplication.php.swn b/src/PHPCR/Shell/Console/Application/.ShellApplication.php.swn
new file mode 100644
index 00000000..ea19fcc5
Binary files /dev/null and b/src/PHPCR/Shell/Console/Application/.ShellApplication.php.swn differ
diff --git a/src/PHPCR/Shell/Console/Application/ShellApplication.php b/src/PHPCR/Shell/Console/Application/ShellApplication.php
index a5e98894..587e1d2c 100644
--- a/src/PHPCR/Shell/Console/Application/ShellApplication.php
+++ b/src/PHPCR/Shell/Console/Application/ShellApplication.php
@@ -34,6 +34,7 @@
use PHPCR\Shell\Console\Command\Shell\ExitCommand;
use PHPCR\Shell\Console\TransportInterface;
use PHPCR\Shell\Console\Command\Shell\WorkspaceChangeCommand;
+use PHPCR\Shell\Console\Command\Shell\ListTreeCommand;
class ShellApplication extends Application
{
@@ -60,12 +61,14 @@ public function __construct($appName, $version, InputInterface $input, $transpor
// wrap phpcr-util commands
$this->add($this->wrap(new NodeDumpCommand())
- ->setName('ls')
+ ->setName('dump')
->setDescription('Alias for dump')
);
- $ls = $this->get('ls');
+ $ls = $this->get('dump');
$ls->getDefinition()->getArgument('identifier')->setDefault(null);
+ $this->add(new ListTreeCommand());
+
$this->add($this->wrap(new NodeMoveCommand())
->setName('mv')
);
diff --git a/src/PHPCR/Shell/Console/Command/Shell/ListTreeCommand.php b/src/PHPCR/Shell/Console/Command/Shell/ListTreeCommand.php
new file mode 100644
index 00000000..c9fb87ba
--- /dev/null
+++ b/src/PHPCR/Shell/Console/Command/Shell/ListTreeCommand.php
@@ -0,0 +1,96 @@
+setName('ls');
+ $this->setDescription('List tree');
+ $this->addOption('max-depth', 'd', InputOption::VALUE_REQUIRED, 'Depth', 1);
+ $this->addOption('limit', 'l', InputOption::VALUE_REQUIRED, 'Limit results', null);
+ $this->addOption('show-system', null, InputOption::VALUE_NONE, 'Show system nodes');
+ }
+
+ public function execute(InputInterface $input, OutputInterface $output)
+ {
+ $this->nodeCount = 0;
+
+ $session = $this->getHelper('phpcr')->getSession();
+ $node = $session->getNode($session->getCwd());
+ $this->maxDepth = $input->getOption('max-depth');
+ $this->maxResults = $input->getOption('limit');
+ $this->showSystem = $input->getOption('show-system');
+
+ $rows = new \ArrayObject();
+ $this->iterateTree($node, $rows);
+
+ $table = clone $this->getHelper('table');
+ $table->setHeaders(array('Node / Prop', 'Type', 'Value'));
+
+ foreach ($rows as $row) {
+ $table->addRow($row);
+ }
+
+ $table->render($output);
+
+ $output->writeln('');
+ $output->writeln($this->nodeCount . ' node(s)');
+ }
+
+ public function iterateTree(NodeInterface $node, $rows, $depth = -1)
+ {
+ if (null !== $this->maxResults && $this->nodeCount >= $this->maxResults) {
+ return;
+ }
+
+ if (true === NodeHelper::isSystemItem($node) && false === $this->showSystem) {
+ return;
+ }
+
+ $this->nodeCount++;
+
+ $formatter = $this->getHelper('result_formatter');
+ $properties = $node->getProperties();
+
+ $rows[] = array(
+ str_repeat(' ', $depth + 1) . '' . $node->getName() . '/',
+ '' . $node->getPrimaryNodeType()->getName() . '',
+ '',
+ );
+
+ $depth++;
+ if ($depth >= $this->maxDepth) {
+ return;
+ }
+
+ foreach ($properties as $key => $property) {
+ $rows[] = array(
+ sprintf('%s -%s', str_repeat(' ', $depth), $key),
+ $formatter->getPropertyTypeName($property->getType()) . ($property->isMultiple() ? '[]' : ''),
+ substr($formatter->formatValue($property), 0, 55),
+ );
+ }
+
+ foreach ($node->getNodes() as $child) {
+ if ($depth < $this->maxDepth) {
+ $this->iterateTree($child, $rows, $depth);
+ }
+ }
+ }
+}
+
diff --git a/src/PHPCR/Shell/Console/Helper/ResultFormatterHelper.php b/src/PHPCR/Shell/Console/Helper/ResultFormatterHelper.php
index 7cdae8b5..6018c030 100644
--- a/src/PHPCR/Shell/Console/Helper/ResultFormatterHelper.php
+++ b/src/PHPCR/Shell/Console/Helper/ResultFormatterHelper.php
@@ -16,6 +16,16 @@ public function getName()
return 'result_formatter';
}
+ public function getPropertyTypeName($typeInteger)
+ {
+ $refl = new \ReflectionClass('PHPCR\PropertyType');
+ foreach ($refl->getConstants() as $key => $value) {
+ if ($typeInteger == $value) {
+ return $key;
+ }
+ }
+ }
+
public function format(QueryResultInterface $result, OutputInterface $output, $elapsed)
{
$selectorNames = $result->getSelectorNames();
@@ -50,7 +60,7 @@ public function format(QueryResultInterface $result, OutputInterface $output, $e
$output->writeln(sprintf('%s rows in set (%s sec)', count($result->getRows()), number_format($elapsed, 2)));
}
- protected function formatValue($value)
+ public function formatValue($value)
{
$v = $value->getValue();
if (is_array($v)) {