Skip to content

Commit 4e7e177

Browse files
committed
Initial support for YAML NT edition
1 parent 1ec3e1e commit 4e7e177

File tree

6 files changed

+49
-34
lines changed

6 files changed

+49
-34
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@
88
"jackalope/jackalope": "dev-master",
99
"phpcr/phpcr": "dev-master",
1010
"phpcr/phpcr-utils": "dev-master",
11+
"dantleech/phpcr-nodetype-serializer": "dev-master",
1112
"symfony/finder": "~2.0"
1213
},
14+
"minimum-stability": "dev",
15+
"prefer-stable": true,
1316
"require-dev": {
1417
"mockery/mockery": "0.9",
1518
"symfony/process": "2.3.*",

features/phpcr_node_type_show.feature

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,8 @@ Feature: Show a node type
1212
Then the command should not fail
1313
And I should see the following:
1414
"""
15-
[nt:unstructured] > nt:base
16-
orderable query
17-
- *
18-
multiple jcr.operator.equal.to', 'jcr.operator.not.equal.to', 'jcr.operator.greater.than', 'jcr.operator.greater.than.or.equal.to', 'jcr.operator.less.than', 'jcr.operator.less.than.or.equal.to', 'jcr.operator.like
19-
- *
20-
jcr.operator.equal.to', 'jcr.operator.not.equal.to', 'jcr.operator.greater.than', 'jcr.operator.greater.than.or.equal.to', 'jcr.operator.less.than', 'jcr.operator.less.than.or.equal.to', 'jcr.operator.like
21-
+ * (nt:base)
22-
= nt:unstructured
23-
VERSION sns
15+
name: 'nt:unstructured'
16+
declared_supertypes:
2417
"""
2518

2619
Scenario: Execute the note-type show command

features/shell_connect.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Feature: Launch a new shell session
2+
In order to administer a PHPCR repository
3+
As a user
4+
I need to be able to launch the PHPCRSH
5+
6+
Scenario: Connect
7+
Given I execute the "shell:config:reload" command
8+
Then the command should not fail
9+

src/PHPCR/Shell/Console/Command/Phpcr/NodeTypeEditCommand.php

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
use Symfony\Component\Console\Input\InputInterface;
77
use Symfony\Component\Console\Output\OutputInterface;
88
use Symfony\Component\Console\Input\InputArgument;
9-
use PHPCR\Util\CND\Writer\CndWriter;
109
use PHPCR\NodeType\NoSuchNodeTypeException;
11-
use PHPCR\Util\CND\Parser\CndParser;
10+
use PHPCR\Util\NodeType\Serializer\YAMLSerializer;
11+
use PHPCR\Util\NodeType\Serializer\YAMLDeserializer;
1212

1313
class NodeTypeEditCommand extends Command
1414
{
@@ -40,10 +40,10 @@ public function execute(InputInterface $input, OutputInterface $output)
4040
$namespaceRegistry = $workspace->getNamespaceRegistry();
4141
$nodeTypeManager = $workspace->getNodeTypeManager();
4242

43+
$serializer = new YAMLSerializer();
44+
4345
try {
4446
$nodeType = $nodeTypeManager->getNodeType($nodeTypeName);
45-
$cndWriter = new CndWriter($namespaceRegistry);
46-
$out = $cndWriter->writeString(array($nodeType));
4747
$message = null;
4848
} catch (NoSuchNodeTypeException $e) {
4949
$parts = explode(':', $nodeTypeName);
@@ -55,24 +55,31 @@ public function execute(InputInterface $input, OutputInterface $output)
5555
}
5656
list($namespace, $name) = $parts;
5757
$uri = $session->getNamespaceURI($namespace);
58+
$nodeType = $nodeTypeManager->createNodeTypeTemplate();
59+
$propertyTemplate = $nodeTypeManager->createPropertyDefinitionTemplate();
60+
$propertyTemplate->setName($namespace . ':change-me');
61+
$childTemplate = $nodeTypeManager->createNodeDefinitionTemplate();
62+
$childTemplate->setName($namespace . ':change-me');
5863

59-
// so we will create one ..
60-
$out = <<<EOT
61-
<$namespace ='$uri'>
62-
[$namespace:$name] > nt:unstructured
64+
$nodeType->setName($nodeTypeName);
65+
$nodeType->getNodeDefinitionTemplates()->append($childTemplate);
66+
$nodeType->getPropertyDefinitionTemplates()->append($propertyTemplate);
6367

64-
EOT
65-
;
68+
// so we will create one ..
6669
$message = <<<EOT
6770
Creating a new node type: $nodeTypeName
71+
72+
An example property and an example node have been added. Feel free to delete or change them.
6873
EOT
6974
;
7075
}
7176

77+
$out = $serializer->serialize($nodeType);
78+
7279
$valid = false;
7380
$prefix = '# ';
7481
do {
75-
$res = $editor->fromStringWithMessage($out, $message);
82+
$res = $editor->fromStringWithMessage($out, $message, $prefix, '.yml');
7683

7784
if (empty($res)) {
7885
$output->writeln('<info>Editor emptied the CND file, doing nothing. Use node-type:delete to remove node types.</info>');
@@ -81,12 +88,9 @@ public function execute(InputInterface $input, OutputInterface $output)
8188
}
8289

8390
try {
84-
$cndParser = new CndParser($nodeTypeManager);
85-
$namespacesAndNodeTypes = $cndParser->parseString($res);
86-
87-
foreach ($namespacesAndNodeTypes['nodeTypes'] as $nodeType) {
88-
$nodeTypeManager->registerNodeType($nodeType, true);
89-
}
91+
$serializer = new YAMLDeserializer($session);
92+
$nodeType = $serializer->deserialize($res);
93+
$nodeTypeManager->registerNodeType($nodeType, true);
9094
$valid = true;
9195
} catch (\Exception $e) {
9296
$output->writeln('<error>'.$e->getMessage().'</error>');

src/PHPCR/Shell/Console/Command/Phpcr/NodeTypeShowCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@
66
use Symfony\Component\Console\Input\InputInterface;
77
use Symfony\Component\Console\Output\OutputInterface;
88
use Symfony\Component\Console\Input\InputArgument;
9-
use PHPCR\Util\CND\Writer\CndWriter;
109
use PHPCR\NodeType\NoSuchNodeTypeException;
10+
use PHPCR\Util\NodeType\Serializer\YAMLSerializer;
1111

1212
class NodeTypeShowCommand extends Command
1313
{
1414
protected function configure()
1515
{
1616
$this->setName('node-type:show');
17-
$this->setDescription('Show the CND of a node type');
17+
$this->setDescription('Show the node definition of a given node type');
1818
$this->addArgument('nodeTypeName', null, InputArgument::REQUIRED, 'The name of the node type to show');
1919
$this->setHelp(<<<HERE
20-
Show the CND (Compact Node Definition) of a given node type.
20+
Show the node type definition in YAML
2121
HERE
2222
);
2323
}
@@ -37,8 +37,8 @@ public function execute(InputInterface $input, OutputInterface $output)
3737
'The node type "%s" does not exist'
3838
, $nodeTypeName));
3939
}
40-
$cndWriter = new CndWriter($namespaceRegistry);
41-
$out = $cndWriter->writeString(array($nodeType));
40+
$cndWriter = new YAMLSerializer();
41+
$out = $cndWriter->serialize($nodeType);
4242
$output->writeln(sprintf('<comment>%s</comment>', $out));
4343
}
4444
}

src/PHPCR/Shell/Console/Helper/EditorHelper.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ class EditorHelper extends Helper
1717
* file containing the given string value.
1818
*
1919
* @param string $string
20+
* @param string $extension Optional extension for filetype hinting (e.g. .yml)
2021
*
2122
* @return string
2223
*/
23-
public function fromString($string)
24+
public function fromString($string, $extension = null)
2425
{
2526
$fs = new Filesystem();
2627
$dir = sys_get_temp_dir().DIRECTORY_SEPARATOR.'phpcr-shell';
@@ -30,6 +31,11 @@ public function fromString($string)
3031
}
3132

3233
$tmpName = tempnam($dir, '');
34+
35+
if (null !== $extension) {
36+
$tmpName .= $extension;
37+
}
38+
3339
file_put_contents($tmpName, $string);
3440
$editor = getenv('EDITOR');
3541

@@ -45,7 +51,7 @@ public function fromString($string)
4551
return $contents;
4652
}
4753

48-
public function fromStringWithMessage($string, $message, $messagePrefix = '# ')
54+
public function fromStringWithMessage($string, $message, $messagePrefix = '# ', $extension = null)
4955
{
5056
if (null !== $message) {
5157
$message = explode("\n", $message);
@@ -60,7 +66,7 @@ public function fromStringWithMessage($string, $message, $messagePrefix = '# ')
6066

6167
$source .= $string;
6268

63-
$res = $this->fromString($source);
69+
$res = $this->fromString($source, $extension);
6470
$res = explode("\n", $res);
6571

6672
$line = current($res);

0 commit comments

Comments
 (0)