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

Commit 44002c0

Browse files
committed
Removed resources key
1 parent c678fbd commit 44002c0

File tree

4 files changed

+74
-0
lines changed

4 files changed

+74
-0
lines changed

DependencyInjection/CmfResourceRestExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public function prepend(ContainerBuilder $container)
4646
public function load(array $configs, ContainerBuilder $container)
4747
{
4848
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
49+
$loader->load('serializer.xml');
4950
$loader->load('resource-rest.xml');
5051
}
5152
}

Resources/config/resource-rest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,7 @@
1616
<argument type="service" id="hateoas.generator.symfony" />
1717
</service>
1818

19+
20+
1921
</services>
2022
</container>

Resources/config/serializer.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<container xmlns="http://symfony.com/schema/dic/services"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
6+
7+
<parameters>
8+
<parameter key="cmf_resource_rest.serializer.collection_handler.class">Symfony\Cmf\Bundle\ResourceRestBundle\Serializer\CollectionHandler</parameter>
9+
</parameters>
10+
11+
<services>
12+
13+
<service id="jms_serializer.event_handler" class="%cmf_resource_rest.serializer.collection_handler.class%">
14+
<tag name="jms_serializer.subscribing_handler"/>
15+
</service>
16+
17+
</services>
18+
</container>

Serializer/CollectionHandler.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony CMF package.
5+
*
6+
* (c) 2011-2014 Symfony CMF
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\Cmf\Bundle\ResourceRestBundle\Serializer;
13+
14+
use JMS\Serializer\EventDispatcher\Events;
15+
use JMS\Serializer\EventDispatcher\EventSubscriberInterface;
16+
use JMS\Serializer\EventDispatcher\ObjectEvent;
17+
use Puli\Repository\Api\ResourceCollection;
18+
use JMS\Serializer\EventDispatcher\PreSerializeEvent;
19+
use Puli\Repository\Api\Resource\Resource;
20+
use JMS\Serializer\Handler\SubscribingHandlerInterface;
21+
use JMS\Serializer\GraphNavigator;
22+
use JMS\Serializer\JsonSerializationVisitor;
23+
use JMS\Serializer\Context;
24+
25+
/**
26+
* Normalize Collection objects to flat arrays
27+
*
28+
* @author Daniel Leech <[email protected]>
29+
*/
30+
class CollectionHandler implements SubscribingHandlerInterface
31+
{
32+
public static function getSubscribingMethods()
33+
{
34+
return array(
35+
array(
36+
'event' => GraphNavigator::DIRECTION_SERIALIZATION,
37+
'format' => 'json',
38+
'type' => 'Puli\Repository\Resource\Collection\ArrayResourceCollection',
39+
'method' => 'normalizeCollection',
40+
),
41+
);
42+
}
43+
44+
public function normalizeCollection(
45+
JsonSerializationVisitor $visitor,
46+
ResourceCollection $collection,
47+
array $type,
48+
Context $context
49+
) {
50+
$res = $visitor->visitarray($collection->toArray(), array('name' => 'Symfony\Cmf\Component\Resource\Repository\Resource\PhpcrOdmResource'), $context);
51+
return $res;
52+
}
53+
}

0 commit comments

Comments
 (0)