Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6982f4b

Browse files
committed
Merge branch '2.2'
* 2.2: [Swiftmailer] bumped allowed versions remove validation related headers when needed use while loop for iterating [Filesystem] copy() is not working when open_basedir is set
2 parents 2dc012e + 9f02b05 commit 6982f4b

File tree

7 files changed

+79
-20
lines changed

7 files changed

+79
-20
lines changed

src/Symfony/Bridge/Swiftmailer/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=5.3.3",
20-
"swiftmailer/swiftmailer": ">=4.2.0,<4.4-dev"
20+
"swiftmailer/swiftmailer": ">=4.2.0,<5.1-dev"
2121
},
2222
"suggest": {
2323
"symfony/http-kernel": "2.2.*"

src/Symfony/Component/Filesystem/Filesystem.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ class Filesystem
3535
*/
3636
public function copy($originFile, $targetFile, $override = false)
3737
{
38+
if (!is_file($originFile)) {
39+
throw new IOException(sprintf('Failed to copy %s because file not exists', $originFile));
40+
}
41+
3842
$this->mkdir(dirname($targetFile));
3943

4044
if (!$override && is_file($targetFile)) {
@@ -44,7 +48,15 @@ public function copy($originFile, $targetFile, $override = false)
4448
}
4549

4650
if ($doCopy) {
47-
if (true !== @copy($originFile, $targetFile)) {
51+
// https://bugs.php.net/bug.php?id=64634
52+
$source = fopen($originFile, 'r');
53+
$target = fopen($targetFile, 'w+');
54+
stream_copy_to_stream($source, $target);
55+
fclose($source);
56+
fclose($target);
57+
unset($source, $target);
58+
59+
if (!is_file($targetFile)) {
4860
throw new IOException(sprintf('Failed to copy %s to %s', $originFile, $targetFile));
4961
}
5062
}

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

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,12 @@
2929
class EsiResponseCacheStrategy implements EsiResponseCacheStrategyInterface
3030
{
3131
private $cacheable = true;
32+
private $embeddedResponses = 0;
3233
private $ttls = array();
3334
private $maxAges = array();
3435

3536
/**
36-
* Adds a Response.
37-
*
38-
* @param Response $response
37+
* {@inheritdoc}
3938
*/
4039
public function add(Response $response)
4140
{
@@ -45,26 +44,38 @@ public function add(Response $response)
4544
$this->ttls[] = $response->getTtl();
4645
$this->maxAges[] = $response->getMaxAge();
4746
}
47+
48+
$this->embeddedResponses++;
4849
}
4950

5051
/**
51-
* Updates the Response HTTP headers based on the embedded Responses.
52-
*
53-
* @param Response $response
52+
* {@inheritdoc}
5453
*/
5554
public function update(Response $response)
5655
{
57-
// if we only have one Response, do nothing
58-
if (1 === count($this->ttls)) {
56+
// if we have no embedded Response, do nothing
57+
if (0 === $this->embeddedResponses) {
5958
return;
6059
}
6160

61+
// Remove validation related headers in order to avoid browsers using
62+
// their own cache, because some of the response content comes from
63+
// at least one embedded response (which likely has a different caching strategy).
64+
if ($response->isValidateable()) {
65+
$response->setEtag(null);
66+
$response->setLastModified(null);
67+
$this->cacheable = false;
68+
}
69+
6270
if (!$this->cacheable) {
6371
$response->headers->set('Cache-Control', 'no-cache, must-revalidate');
6472

6573
return;
6674
}
6775

76+
$this->ttls[] = $response->getTtl();
77+
$this->maxAges[] = $response->getMaxAge();
78+
6879
if (null !== $maxAge = min($this->maxAges)) {
6980
$response->setSharedMaxAge($maxAge);
7081
$response->headers->set('Age', $maxAge - min($this->ttls));

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,10 @@ public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQ
205205
}
206206

207207
if (null !== $this->esi) {
208-
$this->esiCacheStrategy->add($response);
209-
210208
if (HttpKernelInterface::MASTER_REQUEST === $type) {
211209
$this->esiCacheStrategy->update($response);
210+
} else {
211+
$this->esiCacheStrategy->add($response);
212212
}
213213
}
214214

src/Symfony/Component/HttpKernel/Profiler/FileProfilerStorage.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,7 @@ public function find($ip, $url, $limit, $method, $start = null, $end = null)
6060
fseek($file, 0, SEEK_END);
6161

6262
$result = array();
63-
64-
for (;$limit > 0; $limit--) {
65-
$line = $this->readLineFromFile($file);
66-
67-
if (null === $line) {
68-
break;
69-
}
70-
63+
while (count($result) < $limit && $line = $this->readLineFromFile($file)) {
7164
list($csvToken, $csvIp, $csvMethod, $csvUrl, $csvTime, $csvParent) = str_getcsv($line);
7265

7366
$csvTime = (int) $csvTime;

src/Symfony/Component/HttpKernel/Tests/HttpCache/HttpCacheTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,4 +1075,32 @@ public function testXForwarderForHeaderForPassRequests()
10751075

10761076
$this->assertEquals('10.0.0.1', $this->kernel->getBackendRequest()->headers->get('X-Forwarded-For'));
10771077
}
1078+
1079+
public function testEsiCacheRemoveValidationHeadersIfEmbeddedResponses()
1080+
{
1081+
$time = new \DateTime;
1082+
1083+
$responses = array(
1084+
array(
1085+
'status' => 200,
1086+
'body' => '<esi:include src="/hey" />',
1087+
'headers' => array(
1088+
'Surrogate-Control' => 'content="ESI/1.0"',
1089+
'ETag' => 'hey',
1090+
'Last-Modified' => $time->format(DATE_RFC2822),
1091+
),
1092+
),
1093+
array(
1094+
'status' => 200,
1095+
'body' => 'Hey!',
1096+
'headers' => array(),
1097+
),
1098+
);
1099+
1100+
$this->setNextResponses($responses);
1101+
1102+
$this->request('GET', '/', array(), array(), true);
1103+
$this->assertNull($this->response->getETag());
1104+
$this->assertNull($this->response->getLastModified());
1105+
}
10781106
}

src/Symfony/Component/HttpKernel/Tests/Profiler/AbstractProfilerStorageTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,21 @@ public function testRetrieveByEmptyUrlAndIp()
189189
$this->getStorage()->purge();
190190
}
191191

192+
public function testRetrieveByMethodAndLimit()
193+
{
194+
foreach (array('POST', 'GET') as $method) {
195+
for ($i = 0; $i < 5; $i++) {
196+
$profile = new Profile('token_'.$i.$method);
197+
$profile->setMethod($method);
198+
$this->getStorage()->write($profile);
199+
}
200+
}
201+
202+
$this->assertCount(5, $this->getStorage()->find('', '', 5, 'POST'));
203+
204+
$this->getStorage()->purge();
205+
}
206+
192207
public function testPurge()
193208
{
194209
$profile = new Profile('token1');

0 commit comments

Comments
 (0)