8000 provide setup for symfony/symfony#13450 · havvg/symfony-standard@27fca86 · GitHub
[go: up one dir, main page]

Skip to content

Commit 27fca86

Browse files
committed
provide setup for symfony/symfony#13450
1 parent 920d935 commit 27fca86

File tree

7 files changed

+83
-14
lines changed

7 files changed

+83
-14
lines changed

app/config/config.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
imports:
22
- { resource: parameters.yml }
33
- { resource: security.yml }
4+
- { resource: services.yml }
45

56
framework:
67
#esi: ~

app/config/config_test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ imports:
22
- { resource: config_dev.yml }
33

44
framework:
5-
test: ~
5+
test: true
66
session:
77
storage_id: session.storage.mock_file
88
profiler:

app/config/routing.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
app:
2-
resource: @AppBundle/Controller/
3-
type: annotation
1+
example:
2+
pattern: /app/issue
3+
defaults:
4+
_controller: example_controller:issueAction

app/config/services.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
services:
2+
example_transport:
3+
class: Example
4+
factory_class: Example
5+
factory_method: fromSession
6+
arguments:
7+
- @session
8+
9+
example_controller:
10+
class: AppBundle\Controller\DefaultController
11+
arguments:
12+
- @example_transport
13+
tags:
14+
- { name: kernel.event_subscriber }

src/AppBundle/Controller/DefaultController.php

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,33 @@
33
namespace AppBundle\Controller;
44

55
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6-
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
6+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
7+
use Symfony\Component\HttpFoundation\Response;
8+
use Symfony\Component\HttpKernel\KernelEvents;
79

8-
class DefaultController extends Controller
10+
class DefaultController implements EventSubscriberInterface
911
{
10-
/**
11-
* @Route("/app/example", name="homepage")
12-
*/
13-
public function indexAction()
12+
private $example;
13+
14+
public function __construct(\Example $example)
15+
{
16+
$this->example = $example;
17+
}
18+
19+
public function issueAction()
20+
{
21+
return new Response($this->example->getUuid(), Response::HTTP_OK);
22+
}
23+
24+
public function onKernelRequest()
25+
{
26+
// This is just given to have the services created early enough.
27+
}
28+
29+
public static function getSubscribedEvents()
1430
{
15-
return $this->render('default/index.html.twig');
31+
return array(
32+
KernelEvents::REQUEST => array('onKernelRequest', -2048),
33+
);
1634
}
1735
}

src/AppBundle/Tests/Controller/DefaultControllerTest.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@
66

77
class DefaultControllerTest extends WebTestCase
88
{
9-
public function testIndex()
9+
public function testIssue()
1010
{
1111
$client = static::createClient();
1212

13-
$crawler = $client->request('GET', '/');
13+
$crawler = $client->request('GET', '/app/issue');
14+
$response = $client->getResponse();
1415

15-
$this->assertTrue($crawler->filter('html:contains("Homepage")')->count() > 0);
16+
$expected = $response->getContent();
17+
static::assertNotEmpty($expected);
18+
19+
$crawler = $client->request('GET', '/app/issue');
20+
$response = $client->getResponse();
21+
22+
$uuid = $response->getContent();
23+
static::assertNotEmpty($uuid);
24+
static::assertEquals($expected, $uuid);
1625
}
1726
}

src/Example.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
use Symfony\Component\HttpFoundation\Session\SessionInterface;
4+
5+
class Example
6+
{
7+
private $uuid;
8+
9+
public function __construct()
10+
{
11+
$this->uuid = mt_rand();
12+
}
13+
14+
public function getUuid()
15+
{
16+
return $this->uuid;
17+
}
18+
19+
public static function fromSession(SessionInterface $session)
20+
{
21+
$data = $session->get('example_transport', new static());
22+
$session->set('example_transport', $data);
23+
24+
return $data;
25+
}
26+
}

0 commit comments

Comments
 (0)
0