Skip to content

Commit 5a399bb

Browse files
committed
Merge branch '2.0' into 2.1
2 parents c2ab644 + 62a2813 commit 5a399bb

File tree

16 files changed

+112
-51
lines changed

16 files changed

+112
-51
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ matrix:
2424
env: COMPOSER_FLAGS="--prefer-lowest" SYMFONY_DEPRECATIONS_HELPER=weak
2525
- php: 7.0
2626
env: SYMFONY_VERSION='2.8.*'
27-
- php: 7.0
28-
env: SYMFONY_VERSION='3.0.*'
2927
- php: 7.0
3028
env: SYMFONY_VERSION='3.1.*'
3129

Controller/ExceptionController.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,7 @@ protected function getStatusCode(\Exception $exception)
114114
}
115115

116116
/**
117-
* Determines the parameters to pass to the view layer.
118-
*
119-
* Overwrite it in a custom ExceptionController class to add additionally parameters
120-
* that should be passed to the view layer.
117+
* Determines the template parameters to pass to the view layer.
121118
*
122119
* @param string $currentContent
123120
* @param int $code

DependencyInjection/FOSRestExtension.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
use Symfony\Component\DependencyInjection\DefinitionDecorator;
1717
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
1818
use Symfony\Component\DependencyInjection\Reference;
19+
use Symfony\Component\Form\AbstractType;
20+
use Symfony\Component\Form\Extension\Core\Type\FormType;
1921
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
2022
use Symfony\Component\HttpFoundation\Response;
2123

@@ -88,7 +90,16 @@ private function loadForm(array $config, XmlFileLoader $loader, ContainerBuilder
8890
{
8991
if (!empty($config['disable_csrf_role'])) {
9092
$loader->load('forms.xml');
91-
$container->getDefinition('fos_rest.form.extension.csrf_disable')->replaceArgument(1, $config['disable_csrf_role']);
93+
94+
$definition = $container->getDefinition('fos_rest.form.extension.csrf_disable');
95+
$definition->replaceArgument(1, $config['disable_csrf_role']);
96+
97+
// BC for Symfony < 2.8: the extended_type attribute is used on higher versions
98+
if (!method_exists(AbstractType::class, 'getBlockPrefix')) {
99+
$definition->addTag('form.type_extension', ['alias' => 'form']);
100+
} else {
101+
$definition->addTag('form.type_extension', ['extended_type' => FormType::class]);
102+
}
92103
}
93104
}
94105

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ applications with Symfony. Features include:
1717
[![Latest Stable Version](https://poser.pugx.org/FriendsOfSymfony/rest-bundle/v/stable.svg)](https://packagist.org/packages/FriendsOfSymfony/rest-bundle)
1818
[![SensioLabsInsight](https://insight.sensiolabs.com/projects/0be23389-2e85-49cf-b333-caaa36d11c62/mini.png)](https://insight.sensiolabs.com/projects/0be23389-2e85-49cf-b333-caaa36d11c62)
1919

20+
Note
21+
----
22+
23+
FOSRestBundle 1.x is no longer maintained, 1.8 only receives security fixes. Please upgrade to FOSRestBundle 2.x as soon as possible.
24+
2025
Documentation
2126
-------------
2227

Request/ParamFetcher.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,17 +101,19 @@ public function get($name, $strict = null)
101101
/** @var ParamInterface $param */
102102
$param = $params[$name];
103103
$default = $param->getDefault();
104+
$default = $this->resolveValue($this->container, $default);
104105
$strict = (null !== $strict ? $strict : $param->isStrict());
105106

106107
$paramValue = $param->getValue($this->getRequest(), $default);
107108

108-
return $this->cleanParamWithRequirements($param, $paramValue, $strict);
109+
return $this->cleanParamWithRequirements($param, $paramValue, $strict, $default);
109110
}
110111

111112
/**
112113
* @param ParamInterface $param
113114
* @param mixed $paramValue
114115
* @param bool $strict
116+
* @param mixed $default
115117
*
116118
* @throws BadRequestHttpException
117119
* @throws \RuntimeException
@@ -120,11 +122,8 @@ public function get($name, $strict = null)
120122
*
121123
* @internal
122124
*/
123-
protected function cleanParamWithRequirements(ParamInterface $param, $paramValue, $strict)
125+
protected function cleanParamWithRequirements(ParamInterface $param, $paramValue, $strict, $default)
124126
{
125-
$default = $param->getDefault();
126-
$default = $this->resolveValue($this->container, $default);
127-
128127
$this->checkNotIncompatibleParams($param);
129128
if ($default !== null && $default === $paramValue) {
130129
return $paramValue;

Resources/config/forms.xml

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

77
<services>
88
<service id="fos_rest.form.extension.csrf_disable" class="FOS\RestBundle\Form\Extension\DisableCSRFExtension">
9-
<!-- "alias" option for SF <2.8 -->
10-
<tag name="form.type_extension" alias="form" extended-type="Symfony\Component\Form\Extension\Core\Type\FormType" />
119
<argument type="service" id="security.token_storage" />
1210
<argument /> <!-- disable CSRF role -->
1311
<argument type="service" id="security.authorization_checker" />

Resources/doc/2-the-view-layer.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ Then:
185185
leads to a "validation failed" response.
186186
- In a rendered template, the form is passed as 'form' and ``createView()``
187187
is called automatically.
188-
- ``$form->getData()`` is passed into the view as template as ``'data'`` if the
188+
- ``$form->getData()`` is passed into the view template as ``'data'`` if the
189189
form is the only view data.
190190
- An invalid form will be wrapped into an exception.
191191

Routing/Loader/Reader/RestActionReader.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use FOS\RestBundle\Inflector\InflectorInterface;
1717
use FOS\RestBundle\Request\ParamReaderInterface;
1818
use FOS\RestBundle\Routing\RestRouteCollection;
19+
use Psr\Http\Message\MessageInterface;
1920
use Symfony\Component\Routing\Route;
2021

2122
/**
@@ -476,6 +477,7 @@ private function getMethodArguments(\ReflectionMethod $method)
476477
\FOS\RestBundle\Request\ParamFetcherInterface::class,
477478
\Symfony\Component\Validator\ConstraintViolationListInterface::class,
478479
\Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter::class,
480+
MessageInterface::class,
479481
];
480482

481483
$arguments = [];
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the FOSRestBundle package.
5+
*
6+
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
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 FOS\RestBundle\Tests\Fixtures\Controller;
13+
14+
use FOS\RestBundle\Controller\Annotations as Rest;
15+
use FOS\RestBundle\Controller\FOSRestController;
16+
use FOS\RestBundle\Routing\ClassResourceInterface;
17+
use Psr\Http\Message\MessageInterface;
18+
use Psr\Http\Message\ServerRequestInterface;
19+
use Symfony\Component\HttpFoundation\Request;
20+
21+
/**
22+
* @Rest\RouteResource("Article")
23+
*/
24+
class TypeHintedController implements ClassResourceInterface
25+
{
26+
public function cgetAction(Request $request)
27+
{
28+
}
29+
30+
public function cpostAction(MessageInterface $request)
31+
{
32+
}
33+
34+
public function getAction(Request $request, $id)
35+
{
36+
}
37+
38+
public function postAction(ServerRequestInterface $request, $id)
39+
{
40+
}
41+
}

Tests/Functional/Bundle/TestBundle/Controller/ParamFetcherController.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@
2525
class ParamFetcherController extends FOSRestController
2626
{
2727
/**
28-
* @RequestParam(name="raw", requirements=@IdenticalTo({"foo"="raw", "bar"="foo"}), default="invalid")
29-
* @RequestParam(name="map", map=true, requirements=@IdenticalTo({"foo"="map", "foobar"="foo"}), default="%invalid% %%")
30-
* @RequestParam(name="bar", map=true, requirements="%foo% foo", strict=true)
28+
* @RequestParam(name="raw", requirements=@IdenticalTo({"foo"="raw", "bar"="foo"}), default="invalid", strict=false)
29+
* @RequestParam(name="map", map=true, requirements=@IdenticalTo({"foo"="map", "foobar"="foo"}), default="%invalid2% %%", strict=false)
30+
* @RequestParam(name="bar", nullable=true, requirements="%bar%\ foo")
3131
*/
3232
public function paramsAction(ParamFetcherInterface $fetcher)
3333
{
34-
return new JsonResponse($fetcher->all(false));
34+
return new JsonResponse($fetcher->all());
3535
}
3636

3737
/**
3838
* @QueryParam(name="foo", default="invalid")
39-
* @RequestParam(name="bar", default="foo")
39+
* @RequestParam(name="bar", default="%foo%")
4040
*/
4141
public function testAction(Request $request, ParamFetcherInterface $fetcher)
4242
{

0 commit comments

Comments
 (0)