Skip to content

Commit f402bf2

Browse files
committed
Merge pull request #55 from dantleech/type_list
[RFC] Added list node types command and changed n/s of register
2 parents d6a3659 + 08104a7 commit f402bf2

File tree

3 files changed

+77
-1
lines changed

3 files changed

+77
-1
lines changed

bin/phpcr

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ $cli->addCommands(array(
4545
new \PHPCR\Util\Console\Command\DumpCommand(),
4646
new \PHPCR\Util\Console\Command\PurgeCommand(),
4747
new \PHPCR\Util\Console\Command\RegisterNodeTypesCommand(),
48+
new \PHPCR\Util\Console\Command\ListNodeTypesCommand(),
4849
new \PHPCR\Util\Console\Command\QueryCommand(),
4950
new \PHPCR\Util\Console\Command\MoveCommand(),
5051
));
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
}

src/PHPCR/Util/Console/Command/RegisterNodeTypesCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class RegisterNodeTypesCommand extends Command
4747
protected function configure()
4848
{
4949
$this
50-
->setName('phpcr:register-node-types')
50+
->setName('phpcr:type:register')
5151
->setDescription('Register node types in the PHPCR repository')
5252
->setDefinition(array(
5353
new InputArgument(

0 commit comments

Comments
 (0)