Skip to content

Commit

Permalink
prepare for 2.0
Browse files Browse the repository at this point in the history
* Compatibility with Symfony <2.7, JMS Serializer/SerializerBundle <1.0 and SensioFrameworkExtraBundle <3.0 was dropped
* Removed all deprecated features
  • Loading branch information
lsmith77 committed Aug 29, 2015
1 parent db5da50 commit afab6cc
Show file tree
Hide file tree
Showing 35 changed files with 108 additions and 778 deletions.
23 changes: 5 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
language: php

php:
- 5.3
- 5.4
- 5.5
- 5.6
- nightly
- 7.0
- hhvm

sudo: false
Expand All @@ -22,22 +21,10 @@ branches:
matrix:
fast_finish: true
include:
- php: 5.3
env: SYMFONY_VERSION=2.3.* COMPOSER_FLAGS="--prefer-lowest"
- php: 5.5
env: SYMFONY_VERSION='2.3.* symfony/expression-language:2.4.*'
- php: 5.5
env: SYMFONY_VERSION='2.3.* sensio/framework-extra-bundle:2.*'
- php: 5.5
env: SYMFONY_VERSION=2.4.*
- php: 5.5
env: SYMFONY_VERSION=2.6.*
- php: 5.5
env: SYMFONY_VERSION='2.7.*'
- php: 5.4
env: COMPOSER_FLAGS="--prefer-lowest"
- php: 5.5
env: SYMFONY_VERSION='2.8.*@dev symfony/security-acl:2.8.*@dev'
allow_failures:
- php: nightly

before_install:
- composer self-update
Expand All @@ -48,5 +35,5 @@ install: composer update $COMPOSER_FLAGS --prefer-dist
script: phpunit --coverage-clover=coverage.clover

after_script:
- if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
- if [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "7.0" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
27 changes: 5 additions & 22 deletions Controller/ExceptionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@
use FOS\RestBundle\Util\StopFormatListenerException;
use FOS\RestBundle\View\ExceptionWrapperHandlerInterface;
use Symfony\Bundle\FrameworkBundle\Templating\TemplateReference;
use Symfony\Component\HttpKernel\Exception\FlattenException as HttpFlattenException;
use Symfony\Component\Debug\Exception\FlattenException as DebugFlattenException;
use Symfony\Component\HttpKernel\Exception\FlattenException;
use Symfony\Component\DependencyInjection\ContainerAware;
use Symfony\Component\HttpKernel\Log\DebugLoggerInterface;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -49,32 +48,16 @@ protected function createExceptionWrapper(array $parameters)
/**
* Converts an Exception to a Response.
*
* @param Request $request
* @param HttpFlattenException|DebugFlattenException $exception
* @param DebugLoggerInterface $logger
* @param Request $request
* @param FlattenException $exception
* @param DebugLoggerInterface $logger
*
* @return Response
*
* @throws \InvalidArgumentException
*/
public function showAction(Request $request, $exception, DebugLoggerInterface $logger = null)
public function showAction(Request $request, FlattenException $exception, DebugLoggerInterface $logger = null)
{
/**
* Validates that the exception that is handled by the Exception controller is either a DebugFlattenException
* or HttpFlattenException.
* Type hinting has been removed due to a BC change in symfony/symfony 2.3.5.
*
* @see https://github.com/FriendsOfSymfony/FOSRestBundle/pull/565
*/
if (!$exception instanceof DebugFlattenException && !$exception instanceof HttpFlattenException) {
throw new \InvalidArgumentException(sprintf(
'ExceptionController::showAction can only accept some exceptions (%s, %s), "%s" given',
'Symfony\Component\HttpKernel\Exception\FlattenException',
'Symfony\Component\Debug\Exception\FlattenException',
get_class($exception)
));
}

$format = $this->getFormat($request, $request->getRequestFormat());
if (null === $format) {
$message = 'No matching accepted Response format could be determined, while handling: ';
Expand Down
34 changes: 0 additions & 34 deletions DependencyInjection/Compiler/CsrfExtensionPass.php

This file was deleted.

1 change: 0 additions & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,6 @@ private function addViewSection(ArrayNodeDefinition $rootNode)
->canBeUnset()
->children()
->scalarNode('callback_param')->defaultValue('callback')->end()
->scalarNode('callback_filter')->defaultValue('/(^[a-z0-9_]+$)|(^YUI\.Env\.JSONP\._[0-9]+$)/i')->end()
->scalarNode('mime_type')->defaultValue('application/javascript+jsonp')->end()
->end()
->end()
Expand Down
26 changes: 1 addition & 25 deletions DependencyInjection/FOSRestExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,26 +202,6 @@ private function loadBodyConverter(array $config, $validator, XmlFileLoader $loa
{
if (!empty($config['body_converter'])) {
if (!empty($config['body_converter']['enabled'])) {
$parameter = new \ReflectionParameter(
array(
'Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface',
'supports',
),
'configuration'
);

if ('Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter' === $parameter->getClass()->getName()) {
$container->setParameter(
'fos_rest.converter.request_body.class',
'FOS\RestBundle\Request\RequestBodyParamConverter'
);
} else {
$container->setParameter(
'fos_rest.converter.request_body.class',
'FOS\RestBundle\Request\RequestBodyParamConverter20'
);
}

$loader->load('request_body_param_converter.xml');
}

Expand All @@ -241,7 +221,7 @@ private function loadBodyConverter(array $config, $validator, XmlFileLoader $loa
private function loadView(array $config, XmlFileLoader $loader, ContainerBuilder $container)
{
if (!empty($config['view']['exception_wrapper_handler'])) {
$container->setParameter('fos_rest.view.exception_wrapper_handler', $config['view']['exception_wrapper_handler']);
$container->setAlias('fos_rest.view.exception_wrapper_handler', $config['view']['exception_wrapper_handler']);
}

if (!empty($config['view']['jsonp_handler'])) {
Expand All @@ -254,10 +234,6 @@ private function loadView(array $config, XmlFileLoader $loader, ContainerBuilder

$container->setParameter('fos_rest.view_handler.jsonp.callback_param', $config['view']['jsonp_handler']['callback_param']);

if ('/(^[a-z0-9_]+$)|(^YUI\.Env\.JSONP\._[0-9]+$)/i' !== $config['view']['jsonp_handler']['callback_filter']) {
throw new \LogicException('As of 1.2.0, the "callback_filter" parameter is deprecated, and is not used anymore. For more information, read: https://github.com/FriendsOfSymfony/FOSRestBundle/pull/642.');
}

if (empty($config['view']['mime_types']['jsonp'])) {
$config['view']['mime_types']['jsonp'] = $config['view']['jsonp_handler']['mime_type'];
}
Expand Down
12 changes: 0 additions & 12 deletions EventListener/BodyListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,18 +53,6 @@ public function __construct(
$this->normalizeForms = $normalizeForms;
}

/**
* Sets the array normalizer.
*
* @param ArrayNormalizerInterface $arrayNormalizer
*
* @deprecated To be removed in FOSRestBundle 2.0.0 (constructor injection is used instead).
*/
public function setArrayNormalizer(ArrayNormalizerInterface $arrayNormalizer)
{
$this->arrayNormalizer = $arrayNormalizer;
}

/**
* Sets the fallback format if there's no Content-Type in the request.
*
Expand Down
2 changes: 0 additions & 2 deletions FOSRestBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use FOS\RestBundle\DependencyInjection\Compiler\ExceptionWrapperHandlerPass;
use FOS\RestBundle\DependencyInjection\Compiler\FormatListenerRulesPass;
use FOS\RestBundle\DependencyInjection\Compiler\TwigExceptionPass;
use FOS\RestBundle\DependencyInjection\Compiler\CsrfExtensionPass;

/**
* @author Lukas Kahwe Smith <smith@pooteeweet.org>
Expand All @@ -36,6 +35,5 @@ public function build(ContainerBuilder $container)
$container->addCompilerPass(new FormatListenerRulesPass());
$container->addCompilerPass(new TwigExceptionPass());
$container->addCompilerPass(new ExceptionWrapperHandlerPass());
$container->addCompilerPass(new CsrfExtensionPass());
}
}
40 changes: 13 additions & 27 deletions Form/Extension/DisableCSRFExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,54 +26,40 @@
class DisableCSRFExtension extends AbstractTypeExtension
{
/**
* @var SecurityContextInterface|TokenStorageInterface
* @var TokenStorageInterface
*/
private $tokenStorage;
/**
* @var string
*/
private $role;
/**
* @var AuthorizationCheckerInterface
*/
private $authorizationChecker;

public function __construct($tokenStorage, $role, $authorizationChecker = null)
public function __construct(TokenStorageInterface $tokenStorage, $role, AuthorizationCheckerInterface $authorizationChecker)
{
$this->tokenStorage = $tokenStorage;
$this->role = $role;
$this->authorizationChecker = $authorizationChecker;

if (!$tokenStorage instanceof TokenStorageInterface && !$tokenStorage instanceof SecurityContextInterface) {
throw new \InvalidArgumentException('Argument 1 should be an instance of Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface or Symfony\Component\Security\Core\SecurityContextInterface');
}
}

public function configureOptions(OptionsResolver $resolver)
{
if ($this->authorizationChecker instanceof AuthorizationCheckerInterface) {
if (!$this->tokenStorage->getToken()) {
return;
}

if (!$this->authorizationChecker->isGranted($this->role)) {
return;
}
} else {
if (!$this->tokenStorage->getToken()) {
return;
}
if (!$this->tokenStorage->getToken()) {
return;
}

if (!$this->tokenStorage->isGranted($this->role)) {
return;
}
if (!$this->authorizationChecker->isGranted($this->role)) {
return;
}

$resolver->setDefaults(array(
'csrf_protection' => false,
));
}

// BC for < 2.7
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$this->configureOptions($resolver);
}

public function getExtendedType()
{
return 'form';
Expand Down
40 changes: 0 additions & 40 deletions Request/RequestBodyParamConverter20.php

This file was deleted.

3 changes: 1 addition & 2 deletions Resources/config/access_denied_listener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@

<parameters>

<parameter key="fos_rest.access_denied_listener.class">FOS\RestBundle\EventListener\AccessDeniedListener</parameter>
<parameter key="fos_rest.access_denied_listener.formats" type="collection"/>
<parameter key="fos_rest.access_denied_listener.unauthorized_challenge" type="string" />

</parameters>

<services>

<service id="fos_rest.access_denied_listener" class="%fos_rest.access_denied_listener.class%">
<service id="fos_rest.access_denied_listener" class="FOS\RestBundle\EventListener\AccessDeniedListener">
<tag name="kernel.event_subscriber" />
<tag name="monolog.logger" channel="request" />
<argument>%fos_rest.access_denied_listener.formats%</argument>
Expand Down
11 changes: 2 additions & 9 deletions Resources/config/allowed_methods_listener.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,14 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<parameters>

<parameter key="fos_rest.allowed_methods_listener.class">FOS\RestBundle\EventListener\AllowedMethodsListener</parameter>
<parameter key="fos_rest.allowed_methods_loader.class">FOS\RestBundle\Response\AllowedMethodsLoader\AllowedMethodsRouterLoader</parameter>

</parameters>

<services>

<service id="fos_rest.allowed_methods_listener" class="%fos_rest.allowed_methods_listener.class%">
<service id="fos_rest.allowed_methods_listener" class="FOS\RestBundle\EventListener\AllowedMethodsListener">
<tag name="kernel.event_listener" event="kernel.response" method="onKernelResponse" />
<argument type="service" id="fos_rest.allowed_methods_loader" />
</service>

<service id="fos_rest.allowed_methods_loader" class="%fos_rest.allowed_methods_loader.class%">
<service id="fos_rest.allowed_methods_loader" class="FOS\RestBundle\Response\AllowedMethodsLoader\AllowedMethodsRouterLoader">
<tag name="kernel.cache_warmer" />
<argument type="service" id="router" />
<argument>%fos_rest.cache_dir%</argument>
Expand Down
Loading

0 comments on commit afab6cc

Please sign in to comment.