Skip to content
This repository was archived by the owner on Sep 16, 2021. It is now read-only.

Commit 44d803c

Browse files
committed
PhpcrNode serialization
1 parent 0cb2c56 commit 44d803c

File tree

22 files changed

+405
-93
lines changed

22 files changed

+405
-93
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ before_script:
2626
- composer require symfony/symfony:${SYMFONY_VERSION} --prefer-source
2727
- vendor/symfony-cmf/testing/bin/travis/phpcr_odm_doctrine_dbal.sh
2828

29-
script: phpunit --coverage-text
29+
script:
30+
- phpunit --coverage-text
31+
- ./vendor/bin/behat
3032

3133
notifications:
3234
irc: "irc.freenode.org#symfony-cmf"

CmfResourceRestBundle.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
use Symfony\Component\HttpKernel\Bundle\Bundle;
1515
use Symfony\Component\DependencyInjection\ContainerBuilder;
16-
use Symfony\Cmf\Bundle\ResourceRestBundle\DependencyInjection\Compiler\FactoryPass;
17-
use Symfony\Cmf\Bundle\ResourceRestBundle\DependencyInjection\Compiler\CompositeRepositoryPass;
1816

1917
class CmfResourceRestBundle extends Bundle
2018
{

Controller/ResourceController.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@
33
namespace Symfony\Cmf\Bundle\ResourceRestBundle\Controller;
44

55
use Symfony\Cmf\Component\Resource\RepositoryRegistryInterface;
6-
use Symfony\Component\HttpFoundation\Request;
7-
use Symfony\Component\HttpFoundation\JsonResponse;
8-
use Hateoas\HateoasBuilder;
96
use Symfony\Component\HttpFoundation\Response;
107
use Hateoas\UrlGenerator\UrlGeneratorInterface;
11-
use JMS\Serializer\SerializerBuilder;
128
use JMS\Serializer\SerializerInterface;
139
use JMS\Serializer\SerializationContext;
1410

@@ -24,6 +20,9 @@ class ResourceController
2420
*/
2521
private $urlGenerator;
2622

23+
/**
24+
* @var SerializerInterface
25+
*/
2726
private $serializer;
2827

2928
/**
@@ -33,8 +32,7 @@ public function __construct(
3332
SerializerInterface $serializer,
3433
RepositoryRegistryInterface $registry,
3534
UrlGeneratorInterface $urlGenerator
36-
)
37-
{
35+
) {
3836
$this->serializer = $serializer;
3937
$this->registry = $registry;
4038
$this->urlGenerator = $urlGenerator;

DependencyInjection/CmfResourceRestExtension.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,8 @@
1313

1414
use Symfony\Component\DependencyInjection\ContainerBuilder;
1515
use Symfony\Component\Config\FileLocator;
16-
use Symfony\Component\Config\Definition\Processor;
1716
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
1817
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
19-
use Symfony\Component\DependencyInjection\Definition;
20-
use Symfony\Component\DependencyInjection\Reference;
2118
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
2219

2320
class CmfResourceRestExtension extends Extension implements PrependExtensionInterface

Helper/PathHelper.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@
1111

1212
namespace Symfony\Cmf\Bundle\ResourceRestBundle\Helper;
1313

14+
/**
15+
* Path helper.
16+
*
17+
* Used in the BazingaHateoasBundle expression language to provide
18+
* the correct value for the route generator.
19+
*
20+
* Should be removed once BazingaHateoasBundle supports custom provider
21+
* registration.
22+
*
23+
* @author Daniel Leech <[email protected]>
24+
*/
1425
class PathHelper
1526
{
1627
/**
@@ -22,7 +33,6 @@ class PathHelper
2233
* @return string
2334
*/
2435
public function relativize($path)
25-
2636
{
2737
if (substr($path, 0, 1) == '/') {
2838
return substr($path, 1);

README.md

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
[![Latest Stable Version](https://poser.pugx.org/symfony-cmf/resource-rest-bundle/version.png)](https://packagist.org/packages/symfony-cmf/resource-bundle)
55
[![Total Downloads](https://poser.pugx.org/symfony-cmf/resource-rest-bundle/d/total.png)](https://packagist.org/packages/symfony-cmf/resource-bundle)
66

7-
WIP: This bundle provides a REST API for resources
7+
This Bundle provides a REST API to [Puli](https://github.com/puliphp/puli)
8+
resources as provided by the
9+
[CmfResource](https://github.com/symfony-cmf/Resource) component.
810

911
## Requirements
1012

@@ -18,6 +20,74 @@ Not yet.
1820
* [All Symfony CMF documentation](http://symfony.com/doc/master/cmf/index.html) - complete Symfony CMF reference
1921
* [Symfony CMF Website](http://cmf.symfony.com/) - introduction, live demo, support and community links
2022

23+
## Example
24+
25+
````bash
26+
$ curl http://localhost:8000/api/phpcrodm_repo/foo | python -m json.tool
27+
{
28+
"_links": {
29+
"self": {
30+
"href": "/api/phpcrodm_repo/foo"
31+
}
32+
},
33+
"children": {
34+
"bar": {
35+
"_links": {
36+
"self": {
37+
"href": "/api/phpcrodm_repo/foo/bar"
38+
}
39+
},
40+
"children": [],
41+
"document": {
42+
"_links": {
43+
"self": {
44+
"href": "/path/to/this"
45+
}
46+
},
47+
"body": "This is my second article",
48+
"id": "/tests/cmf/articles/foo/bar",
49+
"title": "Article 2"
50+
},
51+
"path": "/foo/bar",
52+
"repo_path": "/foo/bar"
53+
},
54+
"boo": {
55+
"_links": {
56+
"self": {
57+
"href": "/api/phpcrodm_repo/foo/boo"
58+
}
59+
},
60+
"children": [],
61+
"document": {
62+
"_links": {
63+
"self": {
64+
"href": "/path/to/this"
65+
}
66+
},
67+
"body": "This is my third article",
68+
"id": "/tests/cmf/articles/foo/boo",
69+
"title": "Article 2"
70+
},
71+
"path": "/foo/boo",
72+
"repo_path": "/foo/boo"
73+
}
74+
},
75+
"document": {
76+
"_links": {
77+
"self": {
78+
"href": "/path/to/this"
79+
}
80+
},
81+
"body": "This is my article",
82+
"id": "/tests/cmf/articles/foo",
83+
"title": "Article 1"
84+
},
85+
"path": "/foo",
86+
"repo_path": "/foo"
87+
}
88+
````
89+
90+
2191
## Contributing
2292

2393
Pull requests are welcome. Please see our

Resources/config/routing.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
_cmf_resource:
2+
pattern: /api/{repositoryName}/{path}
3+
requirements:
4+
path: .*
5+
defaults:
6+
_controller: cmf_resource_rest.controller.resource:resourceAction
7+
_format: json

Resources/config/serializer.xml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,23 @@
55
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
66

77
<parameters>
8-
<parameter key="cmf_resource_rest.serializer.collection_handler.class">Symfony\Cmf\Bundle\ResourceRestBundle\Serializer\CollectionHandler</parameter>
8+
<parameter key="cmf_resource_rest.serializer.handler.collection.class">Symfony\Cmf\Bundle\ResourceRestBundle\Serializer\Handler\CollectionHandler</parameter>
9+
<parameter key="cmf_resource_rest.serializer.handler.phpcr_node.class">Symfony\Cmf\Bundle\ResourceRestBundle\Serializer\Handler\PhpcrNodeHandler</parameter>
10+
<parameter key="cmf_resource_rest.serializer.subscriber.phpcr_node.class">Symfony\Cmf\Bundle\ResourceRestBundle\Serializer\EventSubscriber\PhpcrNodeSubscriber</parameter>
911
</parameters>
1012

1113
<services>
1214

13-
<service id="jms_serializer.event_handler" class="%cmf_resource_rest.serializer.collection_handler.class%">
15+
<service id="cmf_resource_rest.serializer.handler.collection" class="%cmf_resource_rest.serializer.handler.collection.class%">
1416
<tag name="jms_serializer.subscribing_handler"/>
1517
</service>
1618

19+
<service id="cmf_resource_rest.serializer.handler.phpcr_node" class="%cmf_resource_rest.serializer.handler.phpcr_node.class%">
20+
<tag name="jms_serializer.subscribing_handler"/>
21+
</service>
22+
23+
<service id="cmf_resource_rest.serializer.subscriber.phpcr_node" class="%cmf_resource_rest.serializer.subscriber.phpcr_node.class%">
24+
<tag name="jms_serializer.event_subscriber" />
25+
</service>
1726
</services>
1827
</container>
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<serializer>
3-
<class name="PHPCR\NodeInterface" xmlns:h="https://github.com/willdurand/Hateoas" exclude-policy="all" exclude="true">
3+
<class name="PHPCR\NodeInterface" xmlns:h="https://github.com/willdurand/Hateoas">
44
</class>
55
</serializer>
6-

Resources/config/serializer/PhpcrResource.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
<h:parameter name="path" value="expr(service('cmf_resource_rest.path_helper').relativize(object.getPath()))" />
88
</h:href>
99
</h:relation>
10+
<virtual-property serialized-name="children" max-depth="3" method="listChildren"/>
1011
</class>
1112
</serializer>

0 commit comments

Comments
 (0)