Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit915f440

Browse files
author
vagrant
committed
[HttpKernel] removed BC breaks, introduced new TerminableInterface
1 parent7efe4bc commit915f440

File tree

8 files changed

+91
-58
lines changed

8 files changed

+91
-58
lines changed

‎src/Symfony/Component/HttpKernel/Event/PostResponseEvent.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class PostResponseEvent extends Event
2323
{
2424
/**
2525
* The kernel in which this event was thrown
26-
* @varSymfony\Component\HttpKernel\HttpKernelInterface
26+
* @var HttpKernelInterface
2727
*/
2828
private$kernel;
2929

@@ -35,10 +35,10 @@ public function __construct(HttpKernelInterface $kernel)
3535
/**
3636
* Returns the kernel in which this event was thrown
3737
*
38-
* @returnSymfony\Component\HttpKernel\HttpKernelInterface
38+
* @return HttpKernelInterface
3939
*/
4040
publicfunctiongetKernel()
4141
{
4242
return$this->kernel;
4343
}
44-
}
44+
}

‎src/Symfony/Component/HttpKernel/HttpCache/HttpCache.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
namespaceSymfony\Component\HttpKernel\HttpCache;
1717

1818
useSymfony\Component\HttpKernel\HttpKernelInterface;
19+
useSymfony\Component\HttpKernel\TerminableInterface;
1920
useSymfony\Component\HttpFoundation\Request;
2021
useSymfony\Component\HttpFoundation\Response;
2122

@@ -26,7 +27,7 @@
2627
*
2728
* @api
2829
*/
29-
class HttpCacheimplements HttpKernelInterface
30+
class HttpCacheimplements HttpKernelInterface, TerminableInterface
3031
{
3132
private$kernel;
3233
private$store;
@@ -216,15 +217,17 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
216217
}
217218

218219
/**
219-
* Terminates a request/response cycle
220+
* Terminates a request/response cycle.
220221
*
221-
* Should be calledbefore shutdown, butafter sending the response
222+
* Should be called after sending the response and before shutting down the kernel.
222223
*
223224
* @api
224225
*/
225226
publicfunctionterminate()
226227
{
227-
$this->kernel->terminate();
228+
if ($this->getKernel()instanceof TerminableInterface) {
229+
$this->getKernel()->terminate();
230+
}
228231
}
229232

230233
/**

‎src/Symfony/Component/HttpKernel/HttpKernel.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,6 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
7979
}
8080
}
8181

82-
/**
83-
* Terminates a request/response cycle
84-
*
85-
* Should be called before shutdown, but after sending the response
86-
*
87-
* @api
88-
*/
89-
publicfunctionterminate()
90-
{
91-
$event =newPostResponseEvent($this);
92-
$this->dispatcher->dispatch(KernelEvents::TERMINATE,$event);
93-
}
94-
9582
/**
9683
* Handles a request to convert it to a response.
9784
*

‎src/Symfony/Component/HttpKernel/HttpKernelInterface.php

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,4 @@ interface HttpKernelInterface
4444
* @api
4545
*/
4646
functionhandle(Request$request,$type =self::MASTER_REQUEST,$catch =true);
47-
48-
/**
49-
* Terminates a request/response cycle
50-
*
51-
* Should be called after sending the response
52-
*/
53-
functionterminate();
5447
}

‎src/Symfony/Component/HttpKernel/Kernel.php

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
*
4545
* @api
4646
*/
47-
abstractclass Kernelimplements KernelInterface
47+
abstractclass Kernelimplements KernelInterface, TerminableInterface
4848
{
4949
protected$bundles;
5050
protected$bundleMap;
@@ -134,6 +134,17 @@ public function boot()
134134
$this->booted =true;
135135
}
136136

137+
/**
138+
* Terminates a request/response cycle.
139+
*
140+
* Should be called after sending the response and before shutting down the kernel.
141+
*
142+
* @api
143+
*/
144+
publicfunctionterminate()
145+
{
146+
}
147+
137148
/**
138149
* Shutdowns the kernel.
139150
*
@@ -171,22 +182,6 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
171182
return$this->getHttpKernel()->handle($request,$type,$catch);
172183
}
173184

174-
/**
175-
* Terminates a request/response cycle
176-
*
177-
* Should be called before shutdown, but after sending the response
178-
*
179-
* @api
180-
*/
181-
publicfunctionterminate()
182-
{
183-
if (false ===$this->booted) {
184-
thrownew \LogicException('The kernel has been shutdown already');
185-
}
186-
187-
$this->getHttpKernel()->terminate();
188-
}
189-
190185
/**
191186
* Gets a http kernel from the container
192187
*
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.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+
namespaceSymfony\Component\HttpKernel;
13+
14+
useSymfony\Component\HttpFoundation\Request;
15+
useSymfony\Component\HttpFoundation\Response;
16+
17+
/**
18+
* Terminable extends the Kernel request/response cycle with dispatching a post
19+
* response event after sending the response and before shutting down the kernel.
20+
*
21+
* @author Jordi Boggiano <j.boggiano@seld.be>
22+
* @author Pierre Minnieur <pierre.minnieur@sensiolabs.de>
23+
*
24+
* @api
25+
*/
26+
interface TerminableInterface
27+
{
28+
/**
29+
* Terminates a request/response cycle.
30+
*
31+
* Should be called after sending the response and before shutting down the kernel.
32+
*
33+
* @api
34+
*/
35+
functionterminate();
36+
}

‎tests/Symfony/Tests/Component/HttpKernel/HttpCache/HttpCacheTest.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,43 @@
1111

1212
namespaceSymfony\Tests\Component\HttpKernel\HttpCache;
1313

14+
useSymfony\Component\HttpKernel\HttpCache\HttpCache;
15+
useSymfony\Component\HttpKernel\HttpCache\StoreInterface;
16+
useSymfony\Component\HttpKernel\HttpKernelInterface;
1417
require_once__DIR__.'/HttpCacheTestCase.php';
1518

1619
class HttpCacheTestextends HttpCacheTestCase
1720
{
21+
publicfunctiontestTerminateDelegatesTerminationOnlyForTerminableInterface()
22+
{
23+
$storeMock =$this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpCache\\StoreInterface')
24+
->disableOriginalConstructor()
25+
->getMock();
26+
27+
// does not implement TerminableInterface
28+
$kernelMock =$this->getMockBuilder('Symfony\\Component\\HttpKernel\\HttpKernelInterface')
29+
->disableOriginalConstructor()
30+
->getMock();
31+
32+
$kernelMock->expects($this->never())
33+
->method('terminate');
34+
35+
$kernel =newHttpCache($kernelMock,$storeMock);
36+
$kernel->terminate();
37+
38+
// does implement TerminableInterface
39+
$kernelMock =$this->getMockBuilder('Symfony\\Component\\HttpKernel\\Kernel')
40+
->disableOriginalConstructor()
41+
->setMethods(array('terminate','registerBundles','registerContainerConfiguration'))
42+
->getMock();
43+
44+
$kernelMock->expects($this->once())
45+
->method('terminate');
46+
47+
$kernel =newHttpCache($kernelMock,$storeMock);
48+
$kernel->terminate();
49+
}
50+
1851
publicfunctiontestPassesOnNonGetHeadRequests()
1952
{
2053
$this->setNextResponse(200);

‎tests/Symfony/Tests/Component/HttpKernel/HttpKernelTest.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,6 @@ public function testHandleWithAResponseListener()
164164
$this->assertEquals('foo',$kernel->handle(newRequest())->getContent());
165165
}
166166

167-
publicfunctiontestTerminate()
168-
{
169-
$dispatcher =newEventDispatcher();
170-
$kernel =newHttpKernel($dispatcher,$this->getResolver());
171-
$dispatcher->addListener(KernelEvents::TERMINATE,function ($event)use (&$called, &$capturedKernel) {
172-
$called =true;
173-
$capturedKernel =$event->getKernel();
174-
});
175-
176-
$kernel->terminate();
177-
$this->assertTrue($called);
178-
$this->assertEquals($kernel,$capturedKernel);
179-
}
180-
181167
protectedfunctiongetResolver($controller =null)
182168
{
183169
if (null ===$controller) {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp