Skip to content

Commit 8c3121d

Browse files
Luis PabonGuilhemN
authored andcommitted
Ensure PHP 5.3 and Symfony 2.3 compat
1 parent bfa0946 commit 8c3121d

File tree

6 files changed

+56
-34
lines changed

6 files changed

+56
-34
lines changed

.travis.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ php:
55
- 5.4
66
- 5.5
77
- 5.6
8-
- 7.0
98
- hhvm
109
- nightly
1110

@@ -24,12 +23,8 @@ matrix:
2423
env: SYMFONY_VERSION=2.7.*
2524
- php: 5.6
2625
env: SYMFONY_VERSION=2.8.*
27-
- php: 7.0
28-
env: SYMFONY_VERSION=2.8.*
2926
- php: 5.6
3027
env: SYMFONY_VERSION=3.0.*
31-
- php: 7.0
32-
env: SYMFONY_VERSION=3.0.*
3328
allow_failures:
3429
- php: hhvm
3530
- php: nightly

Controller/AuthorizeController.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313

1414
use FOS\OAuthServerBundle\Event\OAuthEvent;
1515
use FOS\OAuthServerBundle\Form\Handler\AuthorizeFormHandler;
16-
use OAuth2\OAuth2;
16+
use FOS\OAuthServerBundle\Model\ClientInterface;
1717
use OAuth2\OAuth2ServerException;
18-
use Symfony\Component\DependencyInjection\ContainerAwareTrait;
18+
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
19+
use Symfony\Component\DependencyInjection\ContainerInterface;
20+
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1921
use Symfony\Component\HttpFoundation\Request;
22+
use Symfony\Component\HttpFoundation\Response;
2023
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
2124
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
2225
use Symfony\Component\Security\Core\User\UserInterface;
@@ -26,15 +29,28 @@
2629
*
2730
* @author Chris Jones <[email protected]>
2831
*/
29-
class AuthorizeController
32+
class AuthorizeController implements ContainerAwareInterface
3033
{
31-
use ContainerAwareTrait;
32-
3334
/**
3435
* @var \FOS\OAuthServerBundle\Model\ClientInterface
3536
*/
3637
private $client;
3738

39+
/**
40+
* @var ContainerInterface
41+
*/
42+
protected $container;
43+
44+
/**
45+
* Sets the container.
46+
*
47+
* @param ContainerInterface|null $container A ContainerInterface instance or null
48+
*/
49+
public function setContainer(ContainerInterface $container = null)
50+
{
51+
$this->container = $container;
52+
}
53+
3854
/**
3955
* Authorize
4056
*/
@@ -129,8 +145,13 @@ protected function getRedirectionUrl(UserInterface $user)
129145
*/
130146
protected function getClient()
131147
{
132-
$request = $this->container->get('request_stack')->getCurrentRequest();
133148
if (null === $this->client) {
149+
try {
150+
$request = $this->container->get('request_stack')->getCurrentRequest();
151+
} catch (ServiceNotFoundException $e) {
152+
$request = $this->container->get('request');
153+
}
154+
134155
if (null === $clientId = $request->get('client_id')) {
135156
$form = $this->container->get('fos_oauth_server.authorize.form');
136157
$clientId = $request->get(sprintf('%s[client_id]', $form->getName()), null, true);

DependencyInjection/Compiler/TokenStorageCompilerPass.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
*/
2121
class TokenStorageCompilerPass implements CompilerPassInterface
2222
{
23-
2423
/**
2524
* {@inheritdoc}
2625
*/
@@ -35,5 +34,4 @@ public function process(ContainerBuilder $container)
3534
}
3635
$definition->replaceArgument(0, $tokenStorageReference);
3736
}
38-
3937
}

Form/Handler/AuthorizeFormHandler.php

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,40 @@
1111

1212
namespace FOS\OAuthServerBundle\Form\Handler;
1313

14+
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
15+
use Symfony\Component\DependencyInjection\ContainerInterface;
16+
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
1417
use Symfony\Component\Form\FormInterface;
15-
use Symfony\Component\HttpFoundation\Request;
1618
use FOS\OAuthServerBundle\Form\Model\Authorize;
17-
use Symfony\Component\HttpFoundation\RequestStack;
1819

1920
/**
2021
* @author Chris Jones <[email protected]>
2122
*/
22-
class AuthorizeFormHandler
23+
class AuthorizeFormHandler implements ContainerAwareInterface
2324
{
24-
protected $request;
25+
/**
26+
* @var FormInterface
27+
*/
2528
protected $form;
2629

2730
/**
28-
* @var RequestStack
31+
* @var ContainerInterface
2932
*/
30-
private $requestStack;
33+
protected $container;
3134

32-
public function __construct(FormInterface $form, RequestStack $requestStack)
35+
/**
36+
* Sets the container.
37+
*
38+
* @param ContainerInterface|null $container A ContainerInterface instance or null
39+
*/
40+
public function setContainer(ContainerInterface $container = null)
41+
{
42+
$this->container = $container;
43+
}
44+
45+
public function __construct(FormInterface $form)
3346
{
3447
$this->form = $form;
35-
$this->requestStack = $requestStack;
3648
}
3749

3850
public function isAccepted()
@@ -47,15 +59,19 @@ public function isRejected()
4759

4860
public function process()
4961
{
50-
$this->request = $this->requestStack->getCurrentRequest();
62+
try {
63+
$request = $this->container->get('request_stack')->getCurrentRequest();
64+
} catch (ServiceNotFoundException $e) {
65+
$request = $this->container->get('request');
66+
}
5167

5268
$this->form->setData(new Authorize(
53-
$this->request->request->has('accepted'),
54-
$this->request->query->all()
69+
$request->request->has('accepted'),
70+
$request->query->all()
5571
));
5672

57-
if ('POST' === $this->request->getMethod()) {
58-
$this->form->handleRequest($this->request);
73+
if ('POST' === $request->getMethod()) {
74+
$this->form->handleRequest($request);
5975
if ($this->form->isValid()) {
6076
$this->onSuccess();
6177

Resources/config/authorize.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020

2121
<service id="fos_oauth_server.authorize.form.handler.default" class="FOS\OAuthServerBundle\Form\Handler\AuthorizeFormHandler">
2222
<argument type="service" id="fos_oauth_server.authorize.form" />
23-
<argument type="service" id="request_stack" />
2423
</service>
2524
</services>
2625

Tests/Security/Firewall/OAuthListenerTest.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,4 @@ public function testHandleResponse()
102102

103103
$this->assertEquals($response, $ret);
104104
}
105-
106-
public function testWrongTypeForOAuthListener()
107-
{
108-
$this->setExpectedException('InvalidArgumentException');
109-
$listener = new OAuthListener($this->event, $this->authManager, $this->serverService);
110-
}
111-
112105
}

0 commit comments

Comments
 (0)