Commit 54be4f51 authored by Igor Wiedler's avatar Igor Wiedler

[1.1] Remove symfony <2.3 hacks

parent 2b45f600
...@@ -28,9 +28,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse; ...@@ -28,9 +28,7 @@ use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\StreamedResponse; use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\Routing\RouteCollection; use Symfony\Component\Routing\RouteCollection;
use Silex\RequestContext; use Symfony\Component\Routing\RequestContext;
use Silex\RedirectableUrlMatcher;
use Silex\ControllerResolver;
use Silex\EventListener\LocaleListener; use Silex\EventListener\LocaleListener;
use Silex\EventListener\MiddlewareListener; use Silex\EventListener\MiddlewareListener;
use Silex\EventListener\ConverterListener; use Silex\EventListener\ConverterListener;
...@@ -437,10 +435,6 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte ...@@ -437,10 +435,6 @@ class Application extends \Pimple implements HttpKernelInterface, TerminableInte
*/ */
public function sendFile($file, $status = 200, $headers = array(), $contentDisposition = null) public function sendFile($file, $status = 200, $headers = array(), $contentDisposition = null)
{ {
if (!class_exists('Symfony\Component\HttpFoundation\BinaryFileResponse')) {
throw new \RuntimeException('The "sendFile" method is only supported as of Http Foundation 2.2.');
}
return new BinaryFileResponse($file, $status, $headers, true, $contentDisposition); return new BinaryFileResponse($file, $status, $headers, true, $contentDisposition);
} }
......
...@@ -101,11 +101,6 @@ class RememberMeServiceProvider implements ServiceProviderInterface ...@@ -101,11 +101,6 @@ class RememberMeServiceProvider implements ServiceProviderInterface
throw new \LogicException('You must register the SecurityServiceProvider to use the RememberMeServiceProvider'); throw new \LogicException('You must register the SecurityServiceProvider to use the RememberMeServiceProvider');
} }
// In Symfony 2.2, this is a proper subscriber $app['dispatcher']->addSubscriber($app['security.remember_me.response_listener']);
if ($app['security.remember_me.response_listener'] instanceof EventSubscriberInterface) {
$app['dispatcher']->addSubscriber($app['security.remember_me.response_listener']);
} else {
$app['dispatcher']->addListener('kernel.response', array($app['security.remember_me.response_listener'], 'onKernelResponse'));
}
} }
} }
...@@ -33,7 +33,6 @@ use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter; ...@@ -33,7 +33,6 @@ use Symfony\Component\Security\Core\Authorization\Voter\AuthenticatedVoter;
use Symfony\Component\Security\Core\Authorization\AccessDecisionManager; use Symfony\Component\Security\Core\Authorization\AccessDecisionManager;
use Symfony\Component\Security\Core\Role\RoleHierarchy; use Symfony\Component\Security\Core\Role\RoleHierarchy;
use Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator; use Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator;
use Symfony\Component\Security\Core\Validator\Constraint\UserPasswordValidator as DeprecatedUserPasswordValidator;
use Symfony\Component\Security\Http\Firewall; use Symfony\Component\Security\Http\Firewall;
use Symfony\Component\Security\Http\FirewallMap; use Symfony\Component\Security\Http\FirewallMap;
use Symfony\Component\Security\Http\Firewall\AbstractAuthenticationListener; use Symfony\Component\Security\Http\Firewall\AbstractAuthenticationListener;
...@@ -524,13 +523,7 @@ class SecurityServiceProvider implements ServiceProviderInterface ...@@ -524,13 +523,7 @@ class SecurityServiceProvider implements ServiceProviderInterface
if (isset($app['validator'])) { if (isset($app['validator'])) {
$app['security.validator.user_password_validator'] = $app->share(function ($app) { $app['security.validator.user_password_validator'] = $app->share(function ($app) {
// FIXME: in Symfony 2.2 Symfony\Component\Security\Core\Validator\Constraint return new UserPasswordValidator($app['security'], $app['security.encoder_factory']);
// is replaced by Symfony\Component\Security\Core\Validator\Constraints
if (class_exists('Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator')) {
return new UserPasswordValidator($app['security'], $app['security.encoder_factory']);
}
return new DeprecatedUserPasswordValidator($app['security'], $app['security.encoder_factory']);
}); });
if (!isset($app['validator.validator_service_ids'])) { if (!isset($app['validator.validator_service_ids'])) {
...@@ -543,9 +536,7 @@ class SecurityServiceProvider implements ServiceProviderInterface ...@@ -543,9 +536,7 @@ class SecurityServiceProvider implements ServiceProviderInterface
public function boot(Application $app) public function boot(Application $app)
{ {
// FIXME: in Symfony 2.2, this is a proper subscriber $app['dispatcher']->addSubscriber($app['security.firewall']);
//$app['dispatcher']->addSubscriber($app['security.firewall']);
$app['dispatcher']->addListener('kernel.request', array($app['security.firewall'], 'onKernelRequest'), 8);
foreach ($this->fakeRoutes as $route) { foreach ($this->fakeRoutes as $route) {
list($method, $pattern, $name) = $route; list($method, $pattern, $name) = $route;
......
...@@ -36,22 +36,11 @@ class ValidatorServiceProvider implements ServiceProviderInterface ...@@ -36,22 +36,11 @@ class ValidatorServiceProvider implements ServiceProviderInterface
$app['translator']->addResource('xliff', dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf', $app['locale'], 'validators'); $app['translator']->addResource('xliff', dirname($r->getFilename()).'/Resources/translations/validators.'.$app['locale'].'.xlf', $app['locale'], 'validators');
} }
$params = $r->getConstructor()->getParameters(); return new Validator(
if ('validatorInitializers' === $params[2]->getName()) { $app['validator.mapping.class_metadata_factory'],
// BC: to be removed before 1.0 $app['validator.validator_factory'],
// Compatibility with symfony/validator 2.1 isset($app['translator']) ? $app['translator'] : new DefaultTranslator()
// can be removed once silex requires 2.2 );
return new Validator(
$app['validator.mapping.class_metadata_factory'],
$app['validator.validator_factory']
);
} else {
return new Validator(
$app['validator.mapping.class_metadata_factory'],
$app['validator.validator_factory'],
isset($app['translator']) ? $app['translator'] : new DefaultTranslator()
);
}
}); });
$app['validator.mapping.class_metadata_factory'] = $app->share(function ($app) { $app['validator.mapping.class_metadata_factory'] = $app->share(function ($app) {
......
...@@ -28,12 +28,7 @@ class RedirectableUrlMatcher extends BaseRedirectableUrlMatcher ...@@ -28,12 +28,7 @@ class RedirectableUrlMatcher extends BaseRedirectableUrlMatcher
public function redirect($path, $route, $scheme = null) public function redirect($path, $route, $scheme = null)
{ {
$url = $this->context->getBaseUrl().$path; $url = $this->context->getBaseUrl().$path;
$query = $this->context->getQueryString() ?: '';
// Query string support was added to RequestContext in 2.3
// Fall back to parameter injected by url_matcher closure for earlier versions
$query = method_exists($this->context, 'getQueryString')
? $this->context->getQueryString()
: $this->context->getParameter('QUERY_STRING') ?: '';
if ($query !== '') { if ($query !== '') {
$url .= '?'.$query; $url .= '?'.$query;
......
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Silex;
use Symfony\Component\Routing\RequestContext as BaseRequestContext;
use Symfony\Component\HttpFoundation\Request;
/**
* Request Context for Symfony <= 2.2
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class RequestContext extends BaseRequestContext
{
public function fromRequest(Request $request)
{
parent::fromRequest($request);
// Inject the query string as a parameter for Symfony versions <= 2.2
if (!method_exists($this, 'getQueryString') && '' !== $qs = $request->server->get('QUERY_STRING')) {
$this->setParameter('QUERY_STRING', $qs);
}
}
}
...@@ -89,8 +89,6 @@ class Route extends BaseRoute ...@@ -89,8 +89,6 @@ class Route extends BaseRoute
/** /**
* Sets the requirement of host on this Route. * Sets the requirement of host on this Route.
* *
* Note that this only works with at least version 2.2 of the Symfony Routing component.
*
* @param string $host The host for which this route should be enabled * @param string $host The host for which this route should be enabled
* *
* @return Route $this The current Route instance * @return Route $this The current Route instance
......
...@@ -142,13 +142,7 @@ class SecurityServiceProviderTest extends WebTestCase ...@@ -142,13 +142,7 @@ class SecurityServiceProviderTest extends WebTestCase
$app->boot(); $app->boot();
// FIXME: in Symfony 2.2 Symfony\Component\Security\Core\Validator\Constraint $this->assertInstanceOf('Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator', $app['security.validator.user_password_validator']);
// is replaced by Symfony\Component\Security\Core\Validator\Constraints
if (class_exists('Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator')) {
$this->assertInstanceOf('Symfony\Component\Security\Core\Validator\Constraints\UserPasswordValidator', $app['security.validator.user_password_validator']);
} else {
$this->assertInstanceOf('Symfony\Component\Security\Core\Validator\Constraint\UserPasswordValidator', $app['security.validator.user_password_validator']);
}
} }
public function createApplication($authenticationMethod = 'form') public function createApplication($authenticationMethod = 'form')
......
...@@ -87,9 +87,8 @@ class ValidatorServiceProviderTest extends \PHPUnit_Framework_TestCase ...@@ -87,9 +87,8 @@ class ValidatorServiceProviderTest extends \PHPUnit_Framework_TestCase
)); ));
$builder = $app['form.factory']->createBuilder('form', array(), array( $builder = $app['form.factory']->createBuilder('form', array(), array(
'validation_constraint' => $constraints, // symfony/validator >=2.1,<2.3 'constraints' => $constraints,
'constraints' => $constraints, // symfony/validator ~2.3 'csrf_protection' => false,
'csrf_protection' => false,
)); ));
$form = $builder $form = $builder
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment