Skip to content

Commit 895de85

Browse files
committed
[WIP] Node edit command
- One edit command to rule them all - Will be able to edit entire nodes or single properties - Will use Serializer component to serialize nodes to and from different formats (YAML/XML f.e.)
1 parent 9e7d72e commit 895de85

File tree

3 files changed

+95
-1
lines changed

3 files changed

+95
-1
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"jackalope/jackalope": "~1.1",
99
"phpcr/phpcr": "~2.1",
1010
"phpcr/phpcr-utils": "~1.2",
11-
"symfony/finder": "~2.3"
11+
"symfony/finder": "~2.3",
12+
"symfony/serializer": "~2.3"
1213
},
1314
"minimum-stability": "dev",
1415
"require-dev": {
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
namespace spec\PHPCR\Shell\Serializer;
4+
5+
use PhpSpec\ObjectBehavior;
6+
use Prophecy\Argument;
7+
use PHPCR\NodeInterface;
8+
use PHPCR\PropertyInterface;
9+
use PHPCR\PropertyType;
10+
11+
class NodeNormalizerSpec extends ObjectBehavior
12+
{
13+
function it_is_initializable()
14+
{
15+
$this->shouldHaveType('PHPCR\Shell\Serializer\NodeNormalizer');
16+
}
17+
18+
function it_can_normalize_a_node_to_an_array(
19+
NodeInterface $node,
20+
PropertyInterface $p1,
21+
PropertyInterface $p2,
22+
PropertyInterface $p3
23+
)
24+
{
25+
$node->getProperties()->willReturn(array(
26+
$p1, $p2, $p3
27+
));
28+
29+
$p1->getName()->willReturn('my:property.1');
30+
$p1->getType()->willReturn(PropertyType::STRING);
31+
$p1->getValue()->willReturn('P1 Val');
32+
$p2->getName()->willReturn('my:property.2');
33+
$p2->getType()->willReturn(PropertyType::DOUBLE);
34+
$p2->getValue()->willReturn('P2 Val');
35+
$p3->getName()->willReturn('my:property.3');
36+
$p3->getType()->willReturn(PropertyType::STRING);
37+
$p3->getValue()->willReturn('P3 Val');
38+
39+
$this->normalize($node)->shouldReturn(array(
40+
'my:property.1' => array(
41+
'type' => 'String',
42+
'value' => 'P1 Val',
43+
),
44+
'my:property.2' => array(
45+
'type' => 'Double',
46+
'value' => 'P2 Val',
47+
),
48+
'my:property.3' => array(
49+
'type' => 'String',
50+
'value' => 'P3 Val',
51+
),
52+
));
53+
}
54+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace PHPCR\Shell\Serializer;
4+
5+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
6+
use PHPCR\NodeInterface;
7+
use PHPCR\PropertyType;
8+
9+
class NodeNormalizer implements NormalizerInterface
10+
{
11+
/**
12+
* {@inheritDoc}
13+
*/
14+
public function normalize($node, $format = null, array $context = array())
15+
{
16+
$res = array();
17+
18+
foreach ($node->getProperties() as $property) {
19+
$propertyType = $property->getType();
20+
$propertyValue = $property->getValue();
21+
$propertyName = $property->getName();
22+
23+
$res[$propertyName] = array(
24+
'type' => PropertyType::nameFromValue($propertyType),
25+
'value' => $propertyValue
26+
);
27+
}
28+
29+
return $res;
30+
}
31+
32+
/**
33+
* {@inheritDoc}
34+
*/
35+
public function supportsNormalization($data, $format = null)
36+
{
37+
return is_object($data) && $data instanceof NodeInterface;
38+
}
39+
}

0 commit comments

Comments
 (0)