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

Commit e109581

Browse files
committed
Develop
1 parent 48fe03a commit e109581

File tree

19 files changed

+399
-0
lines changed

19 files changed

+399
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Changelog
2+
=========
3+

CONTRIBUTING.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
Contributing
2+
------------
3+
4+
Symfony2 CMF is an open source, community-driven project. We follow the same
5+
guidelines as core Symfony2. If you'd like to contribute, please read the
6+
[Contributing Code][1] part of the documentation. If you're submitting a pull
7+
request, please follow the guidelines in the [Submitting a Patch][2] section
8+
and use the [Pull Request Template][3].
9+
10+
[1]: http://symfony.com/doc/current/contributing/code/index.html
11+
[2]: http://symfony.com/doc/current/contributing/code/patches.html#check-list
12+
[3]: http://symfony.com/doc/current/contributing/code/patches.html#make-a-pull-request

Controller/ResourceController.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\ResourceRestBundle\Controller;
4+
5+
class ResourceController
6+
{
7+
/**
8+
* @var RepositoryInterface
9+
*/
10+
private $repository;
11+
12+
/**
13+
* @param RepositoryInterface
14+
*/
15+
public function __construct(
16+
RepositoryInterface $repository
17+
)
18+
{
19+
$this->repository = $repository;
20+
}
21+
22+
public function resourceAction(Request $request)
23+
{
24+
$path = $request->query->get('path');
25+
var_dump($path);die();;
26+
}
27+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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\DependencyInjection;
13+
14+
use Symfony\Component\DependencyInjection\ContainerBuilder;
15+
use Symfony\Component\Config\FileLocator;
16+
use Symfony\Component\Config\Definition\Processor;
17+
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
18+
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
19+
use Symfony\Component\DependencyInjection\Definition;
20+
use Symfony\Component\DependencyInjection\Reference;
21+
22+
class CmfResourceRestExtension extends Extension
23+
{
24+
/**
25+
* {@inheritDoc}
26+
*/
27+
public function load(array $configs, ContainerBuilder $container)
28+
{
29+
}
30+
}

Resources/config/resource.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
j
4+
<container xmlns="http://symfony.com/schema/dic/services"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">
7+
8+
<parameters>
9+
<parameter key="cmf_resource_rest.controller.class"></parameter>
10+
</parameters>
11+
12+
<services>
13+
14+
<service id="cmf_resource_rest.controller" class=
15+
16+
</services>
17+
</container>

Resources/config/routing.yml

Whitespace-only changes.

Resources/meta/LICENSE

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
ResourceRestBundle
2+
3+
The MIT License
4+
5+
Copyright (c) 2011-2014 Symfony2 CMF
6+
7+
Permission is hereby granted, free of charge, to any person obtaining a copy
8+
of this software and associated documentation files (the "Software"), to deal
9+
in the Software without restriction, including without limitation the rights
10+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
copies of the Software, and to permit persons to whom the Software is
12+
furnished to do so, subject to the following conditions:
13+
14+
The above copyright notice and this permission notice shall be included in
15+
all copies or substantial portions of the Software.
16+
17+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
THE SOFTWARE.
24+
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\ResourceRestBundle\Tests\Features\Context;
4+
5+
require_once(__DIR__ . '/../../Resources/app/AppKernel.php');
6+
7+
use Behat\WebApiExtension\Context\WebApiContext;
8+
use Behat\Symfony2Extension\Context\KernelDictionary;
9+
use Behat\Gherkin\Node\PyStringNode;
10+
use Behat\Behat\Hook\Scope\BeforeScenarioScope;
11+
use Behat\Gherkin\Node\TableNode;
12+
use PHPCR\Util\NodeHelper;
13+
use PHPCR\Util\PathHelper;
14+
15+
class ResourceContext extends WebApiContext
16+
{
17+
use KernelDictionary;
18+
19+
private $session;
20+
private $manager;
21+
22+
public static function getConfigurationFile()
23+
{
24+
return __DIR__ . '/../../Resources/app/cache/resource.yml';
25+
}
26+
27+
/**
28+
* @BeforeScenario
29+
*/
30+
public function beforeScenario(BeforeScenarioScope $scope)
31+
{
32+
if (file_exists(self::getConfigurationFile())) {
33+
unlink(self::getConfigurationFile());
34+
}
35+
36+
$this->manager = $this->getContainer()->get('doctrine_phpcr.odm.document_manager');
37+
$this->session = $this->manager->getPhpcrSession();
38+
39+
if ($this->session->getRootNode()->hasNode('tests')) {
40+
$this->session->removeItem('/tests');
41+
$this->session->save();
42+
}
43+
}
44+
45+
/**
46+
* @Given the test application has the following configuration:
47+
*/
48+
public function givenTheApplicationHasTheConfiguration(PyStringNode $config)
49+
{
50+
file_put_contents(self::getConfigurationFile(), $config->getRaw());
51+
}
52+
53+
/**
54+
* @Given there exists a ":class" document at ":path":
55+
*/
56+
public function givenThereExistsDocument($class, $path, TableNode $fields)
57+
{
58+
$class = 'Symfony\\Cmf\\Bundle\\ResourceRestBundle\\Tests\\Resources\\TestBundle\\Document\\' . $class;
59+
$path = '/tests' . $path;
60+
61+
$parentPath = PathHelper::getParentPath($path);
62+
63+
if (!$this->session->nodeExists($parentPath)) {
64+
NodeHelper::createPath($this->session, $parentPath);
65+
}
66+
67+
if (!class_exists($class)) {
68+
throw new \InvalidArgumentException(sprintf(
69+
'Class "%s" does not exist',
70+
$class
71+
));
72+
}
73+
74+
$document = new $class;
75+
$document->id = $path;
76+
77+
foreach ($fields->getRowsHash() as $field => $value) {
78+
$document->$field = $value;
79+
}
80+
81+
$this->manager->persist($document);
82+
$this->manager->flush();
83+
}
84+
}

Tests/Features/resource_api.feature

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Feature: Request Resources from the REST API
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+
repository:
11+
doctrine_phpcr_odm:
12+
testrepo:
13+
basepath: /cmf/articles
14+
"""
15+
16+
17+
Scenario: Retrieve a resource
18+
Given there exists a "Article" document at "/cmf/articles/foo":
19+
| title | Article 1 |
20+
| body | This is my article |
21+
Then I send a GET request to "/api/testrepo/foo"
22+
Then open response
23+
And the response code should be 200
24+
And the response should contain json:
25+
"""
26+
{
27+
"name": "foo"
28+
"path": "/foo"
29+
"type": "PhpcrOdmResource
30+
}
31+
"""
32+
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Symfony\Cmf\Bundle\ResourceRestBundle\Tests\Resources\TestBundle\Document;
4+
5+
use Doctrine\ODM\PHPCR\Mapping\Annotations as PHPCR;
6+
7+
/**
8+
* @PHPCR\Document()
9+
*/
10+
class Article
11+
{
12+
/**
13+
* @PHPCR\Id()
14+
*/
15+
public $id;
16+
17+
/**
18+
* @PHPCR\String()
19+
*/
20+
public $title;
21+
22+
/**
23+
* @PHPCR\String()
24+
*/
25+
public $body;
26+
}

0 commit comments

Comments
 (0)