File tree Expand file tree Collapse file tree 3 files changed +95
-1
lines changed
spec/PHPCR/Shell/Serializer
src/PHPCR/Shell/Serializer Expand file tree Collapse file tree 3 files changed +95
-1
lines changed Original file line number Diff line number Diff line change 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" : {
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments