|
| 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\Command; |
| 23 | + |
| 24 | +use Symfony\Component\Console\Command\Command; |
| 25 | +use Symfony\Component\Console\Input\InputInterface; |
| 26 | +use Symfony\Component\Console\Output\OutputInterface; |
| 27 | + |
| 28 | +/** |
| 29 | + * A command to list all node types |
| 30 | + * |
| 31 | + * @author Daniel Leech <daniel@dantleech.com> |
| 32 | + */ |
| 33 | +class ListNodeTypesCommand extends Command |
| 34 | +{ |
| 35 | + /** |
| 36 | + * {@inheritDoc} |
| 37 | + */ |
| 38 | + protected function configure() |
| 39 | + { |
| 40 | + $this |
| 41 | + ->setName('phpcr:type:list') |
| 42 | + ->setDescription('List all available node types in the repository') |
| 43 | + ->setHelp(<<<EOT |
| 44 | +This command lists all of the available node types and their subtypes |
| 45 | +in the PHPCR repository. |
| 46 | +EOT |
| 47 | + ) |
| 48 | + ; |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * {@inheritDoc} |
| 53 | + */ |
| 54 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 55 | + { |
| 56 | + $session = $this->getHelper('phpcr')->getSession(); |
| 57 | + $ntm = $session->getWorkspace()->getNodeTypeManager(); |
| 58 | + |
| 59 | + $nodeTypes = $ntm->getAllNodeTypes(); |
| 60 | + |
| 61 | + foreach ($nodeTypes as $name => $nodeType) { |
| 62 | + $output->writeln('<info>'.$name.'</info>'); |
| 63 | + |
| 64 | + $superTypes = $nodeType->getSupertypeNames(); |
| 65 | + if (count($superTypes)) { |
| 66 | + $output->writeln(' <comment>Supertypes:</comment>'); |
| 67 | + foreach ($superTypes as $stName) { |
| 68 | + $output->writeln(' <comment>></comment> '.$stName); |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | + |
| 73 | + return 0; |
| 74 | + } |
| 75 | +} |
0 commit comments