From 3d139a86f53f8c2bd354c5474dbe5a0eec3a830b Mon Sep 17 00:00:00 2001 From: dantleech Date: Fri, 17 Jan 2014 23:21:34 +0000 Subject: [PATCH] Replacing node dump command --- .../Application/.SessionApplication.php.swn | Bin 0 -> 12288 bytes .../Application/.ShellApplication.php.swn | Bin 0 -> 20480 bytes .../Console/Application/ShellApplication.php | 7 +- .../Console/Command/Shell/ListTreeCommand.php | 96 ++++++++++++++++++ .../Console/Helper/ResultFormatterHelper.php | 12 ++- 5 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 src/PHPCR/Shell/Console/Application/.SessionApplication.php.swn create mode 100644 src/PHPCR/Shell/Console/Application/.ShellApplication.php.swn create mode 100644 src/PHPCR/Shell/Console/Command/Shell/ListTreeCommand.php 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 0000000000000000000000000000000000000000..de637d24587ac35ed901f431dff8ccda071573fe GIT binary patch literal 12288 zcmeI2O=}ZD7{{kxwJI%wf`?J7dBJ4UDhO?@)fQ>Qm(r>SDU|7E(kyIdmz`PDP^+In zym`@!S3iQFC$H)^(34&~i3eX!{%4Z5TT@y*7N3RRPIh*ldHK!c5b`Wl?pAN`3+3|+ z*I~vUzx*)w<#>@jKgL*1s6dAH#m*Pnl~zV7m7QBL_OR2T*J`!AxDoqF=U&nc8HS!t zd~bGUc52R>ch6Ii(orbA%W)hAzA!}s z6MS&s4rw6+WPl8i0Wv@a$N(8217zSoGGO99_6Y0U*Io1JZrS%&*?pvf43GgbKnBPF z86X2>fDDiUGC&5%02$bW21JdqxBD402QYd3|G)nG|Mwxreu4Mk9e4unfivLeLB@W7 z@8A`90NUUhxC)MdLGZ1gv9I6_cnzL{Cb$KvUV2>GCV;ooKZa*c`q>17=mlV9{(t&eh%)VK5_c)1+^o^|X zda8Vz3Cx$JnTncCp=vipQ|7BGPEA!Anbd_Z`A}e=3(Q6LjH6_WyMSp~4^&|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MvxrnEC&6A_j3DzWwvyNpL@?g9Bhc_y_#^H^IxG0}cZNRKeTu^Dlv4 zfNy{n_&C@LF2moy1kM5L!xC~ef;XL>mcnW+Kd;uH* zHvkPVt=?jKsgF`XDWDWk3Md7xNd=PlLLOy!MDMm8m*_@?upk2AQH2FcHXT0>;mYQ* z1RbA>&(}cpsV;RQ;(A6Hz_*WDM)hcG{TSAdQ@4dj8{)7E_c*!VDJ*eJIQBL9ezq^- z4}%?Yc=R@*vs)HP!cG_B|F1|GCTy2IGb3pvWP?) z1xchGT>GR7#Z_Y#bm&=u?j}n`)L^Il_?rPyMuaPpDi6~+4c zP%$aa{%=E$>^UT7q@()H?!x8eC+FApT? z2W|@wAi|@!%}v68REyEAs7?JY?;Qw0Y$6P0r*YT3d!_?HOY`A9!wK=CroULdYSfCI zCo4azE>n|tP(CtGix_N{B#qpPZbY3;M8xy37JA-t8pSgPcBeuk5AKW>4}oTZ3!~Ca zUmq2WS!g2f_S?kH2DtTpq`t(#>nwg~Xvvwc&)-_;JJgI|7?-;~k z|4Uan@`nOu#VeDaTl%$KHeRK;70ZqJ|M$YDz6hBApYHE}8-D();D>;{`~N(c2h-pt z@HhDSe*)hJPk=`Od;fnBjDy$V@BawA2s&UI;J+VhSK!zG2K*d60an2>_#k*AEyp#v zmQsaQ3Md7X0!jg;fKosypcGIF{4XfLoE7#d<4+)#qIQk4cxLa;*upM`QN1*TCrWQj q%>1;%28ePws$HXGS=wb$PPA)v*QgYK=xmk?Ik0Ug(jF0}kMadd($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)) {