|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * This file is part of the PHPCR Utils |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + * |
| 18 | + * @license http://www.apache.org/licenses/LICENSE-2.0 Apache Software License 2.0 |
| 19 | + * @link http://phpcr.github.com/ |
| 20 | + */ |
| 21 | + |
| 22 | +namespace PHPCR\Util\Console\Helper; |
| 23 | + |
| 24 | +use Symfony\Component\Console\Helper\Helper; |
| 25 | +use Symfony\Component\Console\Output\OutputInterface; |
| 26 | +use PHPCR\Util\Console\Helper\TreeDumper\ConsoleDumperNodeVisitor; |
| 27 | +use PHPCR\Util\Console\Helper\TreeDumper\ConsoleDumperPropertyVisitor; |
| 28 | +use PHPCR\Util\TreeWalker; |
| 29 | +use PHPCR\Util\Console\Helper\TreeDumper\SystemNodeFilter; |
| 30 | + |
| 31 | +/** |
| 32 | + * Helper class to make the session instance available to console commands |
| 33 | + */ |
| 34 | +class PhpcrConsoleDumperHelper extends Helper |
| 35 | +{ |
| 36 | + public function getTreeWalker(OutputInterface $output, $options) |
| 37 | + { |
| 38 | + $options = array_merge(array( |
| 39 | + 'dump_uuids' => false, |
| 40 | + 'ref_format' => 'uuid', |
| 41 | + 'show_props' => false, |
| 42 | + 'show_sys_nodes' => false, |
| 43 | + ), $options); |
| 44 | + |
| 45 | + $propVisitor = null; |
| 46 | + $nodeVisitor = new ConsoleDumperNodeVisitor($output, $options['dump_uuids']); |
| 47 | + |
| 48 | + if (true === $options['show_props']) { |
| 49 | + new ConsoleDumperPropertyVisitor($output, $options); |
| 50 | + } |
| 51 | + |
| 52 | + $treeWalker = new TreeWalker($nodeVisitor, $propVisitor); |
| 53 | + if (false === $options['show_sys_nodes']) { |
| 54 | + $filter = new SystemNodeFilter(); |
| 55 | + $treeWalker->addNodeFilter($filter); |
| 56 | + $treeWalker->addPropertyFilter($filter); |
| 57 | + } |
| 58 | + |
| 59 | + return $treeWalker; |
| 60 | + } |
| 61 | + |
| 62 | + /** |
| 63 | + * {@inheritDoc} |
| 64 | + */ |
| 65 | + public function getName() |
| 66 | + { |
| 67 | + return 'phpcr_console_dumper'; |
| 68 | + } |
| 69 | +} |
| 70 | + |
0 commit comments