Skip to content

Commit

Permalink
Merge branch '2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhemN committed Nov 11, 2016
2 parents bb017f8 + 62a2813 commit 79816b7
Show file tree
Hide file tree
Showing 13 changed files with 98 additions and 33 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Expand Up @@ -24,8 +24,6 @@ matrix:
env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_DEPRECATIONS_HELPER=weak
- php: 7.0
env: SYMFONY_VERSION='2.8.*'
- php: 7.0
env: SYMFONY_VERSION='3.0.*'
- php: 7.0
env: SYMFONY_VERSION='3.1.*'

Expand Down
5 changes: 1 addition & 4 deletions Controller/ExceptionController.php
Expand Up @@ -114,10 +114,7 @@ protected function getStatusCode(\Exception $exception)
}

/**
* Determines the parameters to pass to the view layer.
*
* Overwrite it in a custom ExceptionController class to add additionally parameters
* that should be passed to the view layer.
* Determines the template parameters to pass to the view layer.
*
* @param string $currentContent
* @param int $code
Expand Down
13 changes: 12 additions & 1 deletion DependencyInjection/FOSRestExtension.php
Expand Up @@ -16,6 +16,8 @@
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\FormType;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\HttpFoundation\Response;

Expand Down Expand Up @@ -88,7 +90,16 @@ private function loadForm(array $config, XmlFileLoader $loader, ContainerBuilder
{
if (!empty($config['disable_csrf_role'])) {
$loader->load('forms.xml');
$container->getDefinition('fos_rest.form.extension.csrf_disable')->replaceArgument(1, $config['disable_csrf_role']);

$definition = $container->getDefinition('fos_rest.form.extension.csrf_disable');
$definition->replaceArgument(1, $config['disable_csrf_role']);

// BC for Symfony < 2.8: the extended_type attribute is used on higher versions
if (!method_exists(AbstractType::class, 'getBlockPrefix')) {
$definition->addTag('form.type_extension', ['alias' => 'form']);
} else {
$definition->addTag('form.type_extension', ['extended_type' => FormType::class]);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -17,6 +17,11 @@ applications with Symfony. Features include:
[![Latest Stable Version](https://poser.pugx.org/FriendsOfSymfony/rest-bundle/v/stable.svg)](https://packagist.org/packages/FriendsOfSymfony/rest-bundle)
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/0be23389-2e85-49cf-b333-caaa36d11c62/mini.png)](https://insight.sensiolabs.com/projects/0be23389-2e85-49cf-b333-caaa36d11c62)

Note
----

FOSRestBundle 1.x is no longer maintained, 1.8 only receives security fixes. Please upgrade to FOSRestBundle 2.x as soon as possible.

Documentation
-------------

Expand Down
2 changes: 0 additions & 2 deletions Resources/config/forms.xml
Expand Up @@ -6,8 +6,6 @@

<services>
<service id="fos_rest.form.extension.csrf_disable" class="FOS\RestBundle\Form\Extension\DisableCSRFExtension">
<!-- "alias" option for SF <2.8 -->
<tag name="form.type_extension" alias="form" extended-type="Symfony\Component\Form\Extension\Core\Type\FormType" />
<argument type="service" id="security.token_storage" />
<argument /> <!-- disable CSRF role -->
<argument type="service" id="security.authorization_checker" />
Expand Down
2 changes: 1 addition & 1 deletion Resources/doc/2-the-view-layer.rst
Expand Up @@ -185,7 +185,7 @@ Then:
leads to a "validation failed" response.
- In a rendered template, the form is passed as 'form' and ``createView()``
is called automatically.
- ``$form->getData()`` is passed into the view as template as ``'data'`` if the
- ``$form->getData()`` is passed into the view template as ``'data'`` if the
form is the only view data.
- An invalid form will be wrapped into an exception.

Expand Down
2 changes: 2 additions & 0 deletions Routing/Loader/Reader/RestActionReader.php
Expand Up @@ -16,6 +16,7 @@
use FOS\RestBundle\Inflector\InflectorInterface;
use FOS\RestBundle\Request\ParamReaderInterface;
use FOS\RestBundle\Routing\RestRouteCollection;
use Psr\Http\Message\MessageInterface;
use Symfony\Component\Routing\Route;

/**
Expand Down Expand Up @@ -476,6 +477,7 @@ private function getMethodArguments(\ReflectionMethod $method)
\FOS\RestBundle\Request\ParamFetcherInterface::class,
\Symfony\Component\Validator\ConstraintViolationListInterface::class,
\Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter::class,
MessageInterface::class,
];

$arguments = [];
Expand Down
41 changes: 41 additions & 0 deletions Tests/Fixtures/Controller/TypeHintedController.php
@@ -0,0 +1,41 @@
<?php

/*
* This file is part of the FOSRestBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace FOS\RestBundle\Tests\Fixtures\Controller;

use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController;
use FOS\RestBundle\Routing\ClassResourceInterface;
use Psr\Http\Message\MessageInterface;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\HttpFoundation\Request;

/**
* @Rest\RouteResource("Article")
*/
class TypeHintedController implements ClassResourceInterface
{
public function cgetAction(Request $request)
{
}

public function cpostAction(MessageInterface $request)
{
}

public function getAction(Request $request, $id)
{
}

public function postAction(ServerRequestInterface $request, $id)
{
}
}
Expand Up @@ -25,13 +25,13 @@
class ParamFetcherController extends FOSRestController
{
/**
* @RequestParam(name="raw", requirements=@IdenticalTo({"foo"="raw", "bar"="foo"}), default="invalid")
* @RequestParam(name="map", map=true, requirements=@IdenticalTo({"foo"="map", "foobar"="foo"}), default="%invalid2% %%")
* @RequestParam(name="bar", map=true, requirements="%bar% foo", strict=true)
* @RequestParam(name="raw", requirements=@IdenticalTo({"foo"="raw", "bar"="foo"}), default="invalid", strict=false)
* @RequestParam(name="map", map=true, requirements=@IdenticalTo({"foo"="map", "foobar"="foo"}), default="%invalid2% %%", strict=false)
* @RequestParam(name="bar", nullable=true, requirements="%bar%\ foo")
*/
public function paramsAction(ParamFetcherInterface $fetcher)
{
return new JsonResponse($fetcher->all(false));
return new JsonResponse($fetcher->all());
}

/**
Expand Down
18 changes: 2 additions & 16 deletions Tests/Functional/ParamFetcherTest.php
Expand Up @@ -52,23 +52,9 @@ public function testValidMapParameter()
'foo' => $this->validMap,
'bar' => $this->validMap,
];
$this->client->request('POST', '/params', ['raw' => 'bar', 'map' => $map]);
$this->client->request('POST', '/params', ['raw' => 'bar', 'map' => $map, 'bar' => 'bar foo']);

$this->assertEquals(['raw' => 'invalid', 'map' => $map, 'bar' => null], $this->getData());
}

public function testFooParameter()
{
$value = ['bar foo', 'bar foo'];
$this->client->request('POST', '/params', ['foo' => $value]);

$map = array(
'foo' => $this->validMap,
'bar' => $this->validMap,
);
$this->client->request('POST', '/params', array('raw' => 'bar', 'map' => $map));

$this->assertEquals(array('raw' => 'invalid', 'map' => $map, 'bar' => null), $this->getData());
$this->assertEquals(['raw' => 'invalid', 'map' => $map, 'bar' => 'bar foo'], $this->getData());
}

public function testWithSubRequests()
Expand Down
18 changes: 18 additions & 0 deletions Tests/Routing/Loader/RestRouteLoaderTest.php
Expand Up @@ -342,6 +342,24 @@ public function testNameMethodPrefixIsPrependingCorrectly()
$this->assertNotNull($collection->get('post_users_bar'), 'route for "post_users_bar" does not exist');
}

/**
* RestActionReader::getMethodArguments should ignore certain types of
* parameters.
*/
public function testRequestTypeHintsIgnoredCorrectly()
{
$collection = $this->loadFromControllerFixture('TypeHintedController');

$this->assertNotNull($collection->get('get_articles'), 'route for "get_articles" does not exist');
$this->assertEquals('/articles.{_format}', $collection->get('get_articles')->getPath());
$this->assertNotNull($collection->get('post_articles'), 'route for "post_articles" does not exist');
$this->assertEquals('/articles.{_format}', $collection->get('post_articles')->getPath());
$this->assertNotNull($collection->get('get_article'), 'route for "get_article" does not exist');
$this->assertEquals('/articles/{id}.{_format}', $collection->get('get_article')->getPath());
$this->assertNotNull($collection->get('post_article'), 'route for "post_article" does not exist');
$this->assertEquals('/articles/{id}.{_format}', $collection->get('post_article')->getPath());
}

/**
* Load routes collection from fixture class under Tests\Fixtures directory.
*
Expand Down
2 changes: 1 addition & 1 deletion Validator/Constraints/Regex.php
Expand Up @@ -20,7 +20,7 @@
*
* @author Ener-Getick <egetick@gmail.com>
*/
class Regex extends BaseRegex
class Regex extends BaseRegex implements ResolvableConstraintInterface
{
use ResolverTrait;

Expand Down
13 changes: 11 additions & 2 deletions composer.json
Expand Up @@ -23,9 +23,17 @@
"require": {
"php": "^5.5.9|~7.0",
"psr/log": "^1.0",
"symfony/framework-bundle": "^2.7|^3.0",
"symfony/config": "^2.7|^3.0",
"symfony/debug": "^2.7|^3.0",
"symfony/dependency-injection": "^2.7|^3.0",
"symfony/event-dispatcher": "^2.7|^3.0",
"symfony/finder": "^2.7|^3.0",
"symfony/framework-bundle": "^2.7|^3.0",
"symfony/http-foundation": "^2.7|^3.0",
"symfony/http-kernel": "^2.7|^3.0",
"symfony/routing": "^2.7|^3.0",
"symfony/security-core": "^2.7|^3.0",
"symfony/templating": "^2.7|^3.0",
"doctrine/inflector": "^1.0",
"willdurand/negotiation": "^2.0",
"willdurand/jsonp-callback-validator": "^1.0"
Expand All @@ -46,7 +54,8 @@
"symfony/expression-language": "~2.7|^3.0",
"symfony/css-selector": "^2.7|^3.0",
"phpoption/phpoption": "^1.1",
"jms/serializer-bundle": "^1.0"
"jms/serializer-bundle": "^1.0",
"psr/http-message": "^1.0"
},

"suggest": {
Expand Down

0 comments on commit 79816b7

Please sign in to comment.