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

Commit 32c89c0

Browse files
committed
Include body if resource is BodyResource
1 parent 402e68f commit 32c89c0

File tree

4 files changed

+55
-0
lines changed

4 files changed

+55
-0
lines changed

Serializer/Jms/Handler/ResourceHandler.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use JMS\Serializer\Context;
1717
use PHPCR\NodeInterface;
1818
use PHPCR\Util\PathHelper;
19+
use Puli\Repository\Api\Resource\BodyResource;
1920
use Puli\Repository\Api\Resource\Resource;
2021
use Symfony\Cmf\Component\Resource\RepositoryRegistryInterface;
2122
use Symfony\Cmf\Bundle\ResourceRestBundle\Registry\PayloadAliasRegistry;
@@ -101,6 +102,10 @@ private function doSerializeResource(Resource $resource, $depth = 0)
101102
}
102103
$data['children'] = $children;
103104

105+
if ($resource instanceof BodyResource) {
106+
$data['body'] = $resource->getBody();
107+
}
108+
104109
foreach ($enhancers as $enhancer) {
105110
$data = $enhancer->enhance($data, $resource);
106111
}

Tests/Features/Context/ResourceContext.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,18 @@ public function givenTheApplicationHasTheConfiguration(PyStringNode $config)
6666
file_put_contents(self::getConfigurationFile(), $config->getRaw());
6767
}
6868

69+
/**
70+
* @Given there is a file named :filename with:
71+
*/
72+
public function createFile($filename, PyStringNode $content)
73+
{
74+
$filesytem = new Filesystem();
75+
$file = str_replace('%kernel.root_dir%', $this->kernel->getRootDir(), $filename);
76+
$filesytem->mkdir(dirname($file));
77+
78+
file_put_contents($file, (string) $content);
79+
}
80+
6981
/**
7082
* @Given there exists a ":class" document at ":path":
7183
*/
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
Feature: Filesystem resource repository
2+
In order to retrieve data from the resource webservice
3+
As a webservice user
4+
I need to be able to query the webservice
5+
6+
Background:
7+
Given the test application has the following configuration:
8+
"""
9+
cmf_resource:
10+
repositories:
11+
default:
12+
type: filesystem
13+
base_dir: "%kernel.root_dir%/Resources/views/snippets"
14+
"""
15+
And there is a file named "%kernel.root_dir%/Resources/views/snippets/snippet1.html" with:
16+
"""
17+
<h1>Snippet 1</h1>
18+
"""
19+
20+
21+
Scenario: Retrieve filesystem resource
22+
When I send a GET request to "/api/default/snippet1.html"
23+
Then the response should contain json:
24+
"""
25+
{
26+
"repository_alias": "default",
27+
"repository_type": "filesystem",
28+
"payload_alias": null,
29+
"payload_type": null,
30+
"path": "\/snippet1.html",
31+
"node_name": "snippet1.html",
32+
"label": "snippet1.html",
33+
"repository_path": "\/snippet1.html",
34+
"children": [],
35+
"body": "<h1>Snippet 1</h1>"
36+
}
37+
"""
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<h1>Snippet 1</h1>

0 commit comments

Comments
 (0)