Merge branch '2.2' into 2.3
* 2.2: Fix several instances of doubled words [Finder] Fix iteration fails with non-rewindable streams [Finder] Fix unexpected duplicate sub path related AppendIterator issue Added type of return value in VoterInterface. Fixed two bugs in HttpCache Conflicts: src/Symfony/Component/Finder/Iterator/RecursiveDirectoryIterator.php
This commit is contained in:
commit
458ce6da2b
@ -239,7 +239,7 @@ class OutputFormatter implements OutputFormatterInterface
|
||||
*
|
||||
* @param string $text Input text
|
||||
*
|
||||
* @return string string Styled text
|
||||
* @return string Styled text
|
||||
*/
|
||||
private function applyCurrentStyle($text)
|
||||
{
|
||||
|
@ -30,7 +30,14 @@ abstract class FilterIterator extends \FilterIterator
|
||||
{
|
||||
$iterator = $this;
|
||||
while ($iterator instanceof \OuterIterator) {
|
||||
if ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
|
||||
$innerIterator = $iterator->getInnerIterator();
|
||||
|
||||
if ($innerIterator instanceof RecursiveDirectoryIterator) {
|
||||
if ($innerIterator->isRewindable()) {
|
||||
$innerIterator->next();
|
||||
$innerIterator->rewind();
|
||||
}
|
||||
} elseif ($iterator->getInnerIterator() instanceof \FilesystemIterator) {
|
||||
$iterator->getInnerIterator()->next();
|
||||
$iterator->getInnerIterator()->rewind();
|
||||
}
|
||||
|
@ -26,6 +26,11 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
||||
*/
|
||||
private $ignoreUnreadableDirs;
|
||||
|
||||
/**
|
||||
* @var Boolean
|
||||
*/
|
||||
private $rewindable;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
@ -73,4 +78,42 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do nothing for non rewindable stream
|
||||
*/
|
||||
public function rewind()
|
||||
{
|
||||
if (false === $this->isRewindable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// @see https://bugs.php.net/bug.php?id=49104
|
||||
parent::next();
|
||||
|
||||
parent::rewind();
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if the stream is rewindable.
|
||||
*
|
||||
* @return Boolean true when the stream is rewindable, false otherwise
|
||||
*/
|
||||
public function isRewindable()
|
||||
{
|
||||
if (null !== $this->rewindable) {
|
||||
return $this->rewindable;
|
||||
}
|
||||
|
||||
if (false !== $stream = @opendir($this->getPath())) {
|
||||
$infos = stream_get_meta_data($stream);
|
||||
closedir($stream);
|
||||
|
||||
if ($infos['seekable']) {
|
||||
return $this->rewindable = true;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->rewindable = false;
|
||||
}
|
||||
}
|
||||
|
@ -796,4 +796,47 @@ class FinderTest extends Iterator\RealIteratorTestCase
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Searching in multiple locations with sub directories involves
|
||||
* AppendIterator which does an unnecessary rewind which leaves
|
||||
* FilterIterator with inner FilesystemIterator in an ivalid state.
|
||||
*
|
||||
* @see https://bugs.php.net/bug.php?id=49104
|
||||
*/
|
||||
public function testMultipleLocationsWithSubDirectories()
|
||||
{
|
||||
$locations = array(
|
||||
__DIR__.'/Fixtures/one',
|
||||
self::$files[8],
|
||||
);
|
||||
|
||||
$finder = new Finder();
|
||||
$finder->in($locations)->depth('< 10')->name('*.neon');
|
||||
|
||||
$expected = array(
|
||||
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'c.neon',
|
||||
__DIR__.'/Fixtures/one'.DIRECTORY_SEPARATOR.'b'.DIRECTORY_SEPARATOR.'d.neon',
|
||||
);
|
||||
|
||||
$this->assertIterator($expected, $finder);
|
||||
$this->assertIteratorInForeach($expected, $finder);
|
||||
}
|
||||
|
||||
public function testNonSeekableStream()
|
||||
{
|
||||
try {
|
||||
$i = Finder::create()->in('ftp://ftp.mozilla.org/')->depth(0)->getIterator();
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
$this->markTestSkipped(sprintf('Unsupported stream "%s".', 'ftp'));
|
||||
}
|
||||
|
||||
$contains = array(
|
||||
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'README',
|
||||
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'index.html',
|
||||
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'pub',
|
||||
);
|
||||
|
||||
$this->assertIteratorInForeach($contains, $i);
|
||||
}
|
||||
}
|
||||
|
0
src/Symfony/Component/Finder/Tests/Fixtures/one/a
Normal file
0
src/Symfony/Component/Finder/Tests/Fixtures/one/a
Normal file
@ -33,4 +33,41 @@ abstract class IteratorTestCase extends \PHPUnit_Framework_TestCase
|
||||
|
||||
$this->assertEquals($expected, array_values($values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as IteratorTestCase::assertIterator with foreach usage
|
||||
*
|
||||
* @param array $expected
|
||||
* @param \Traversable $iterator
|
||||
*/
|
||||
protected function assertIteratorInForeach($expected, \Traversable $iterator)
|
||||
{
|
||||
$values = array();
|
||||
foreach ($iterator as $file) {
|
||||
$this->assertInstanceOf('Symfony\\Component\\Finder\\SplFileInfo', $file);
|
||||
$values[] = $file->getPathname();
|
||||
}
|
||||
|
||||
sort($values);
|
||||
sort($expected);
|
||||
|
||||
$this->assertEquals($expected, array_values($values));
|
||||
}
|
||||
|
||||
/**
|
||||
* Same as IteratorTestCase::assertOrderedIterator with foreach usage
|
||||
*
|
||||
* @param array $expected
|
||||
* @param \Traversable $iterator
|
||||
*/
|
||||
protected function assertOrderedIteratorInForeach($expected, \Traversable $iterator)
|
||||
{
|
||||
$values = array();
|
||||
foreach ($iterator as $file) {
|
||||
$this->assertInstanceOf('Symfony\\Component\\Finder\\SplFileInfo', $file);
|
||||
$values[] = $file->getPathname();
|
||||
}
|
||||
|
||||
$this->assertEquals($expected, array_values($values));
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (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 Symfony\Component\Finder\Tests\Iterator;
|
||||
|
||||
use Symfony\Component\Finder\Iterator\RecursiveDirectoryIterator;
|
||||
|
||||
class RecursiveDirectoryIteratorTest extends IteratorTestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getPaths
|
||||
*
|
||||
* @param string $path
|
||||
* @param Boolean $seekable
|
||||
* @param Boolean $supports
|
||||
* @param string $message
|
||||
*/
|
||||
public function testRewind($path, $seekable, $contains, $message = null)
|
||||
{
|
||||
try {
|
||||
$i = new RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
$this->markTestSkipped(sprintf('Unsupported stream "%s".', $path));
|
||||
}
|
||||
|
||||
$i->rewind();
|
||||
|
||||
$this->assertTrue(true, $message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getPaths
|
||||
*
|
||||
* @param string $path
|
||||
* @param Boolean $seekable
|
||||
* @param Boolean $supports
|
||||
* @param string $message
|
||||
*/
|
||||
public function testSeek($path, $seekable, $contains, $message = null)
|
||||
{
|
||||
try {
|
||||
$i = new RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS);
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
$this->markTestSkipped(sprintf('Unsupported stream "%s".', $path));
|
||||
}
|
||||
|
||||
$actual = array();
|
||||
|
||||
$i->seek(0);
|
||||
$actual[] = $i->getPathname();
|
||||
|
||||
$i->seek(1);
|
||||
$actual[] = $i->getPathname();
|
||||
|
||||
$i->seek(2);
|
||||
$actual[] = $i->getPathname();
|
||||
|
||||
$this->assertEquals($contains, $actual);
|
||||
}
|
||||
|
||||
public function getPaths()
|
||||
{
|
||||
$data = array();
|
||||
|
||||
// ftp
|
||||
$contains = array(
|
||||
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'README',
|
||||
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'index.html',
|
||||
'ftp://ftp.mozilla.org'.DIRECTORY_SEPARATOR.'pub',
|
||||
);
|
||||
$data[] = array('ftp://ftp.mozilla.org/', false, $contains);
|
||||
|
||||
return $data;
|
||||
}
|
||||
}
|
@ -194,8 +194,6 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
$response = $this->lookup($request, $catch);
|
||||
}
|
||||
|
||||
$response->isNotModified($request);
|
||||
|
||||
$this->restoreResponseBody($request, $response);
|
||||
|
||||
$response->setDate(new \DateTime(null, new \DateTimeZone('UTC')));
|
||||
@ -214,6 +212,8 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
|
||||
$response->prepare($request);
|
||||
|
||||
$response->isNotModified($request);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
@ -265,6 +265,15 @@ class HttpCache implements HttpKernelInterface, TerminableInterface
|
||||
try {
|
||||
$this->store->invalidate($request, $catch);
|
||||
|
||||
// As per the RFC, invalidate Location and Content-Location URLs if present
|
||||
foreach (array('Location', 'Content-Location') as $header) {
|
||||
if ($uri = $response->headers->get($header)) {
|
||||
$subRequest = $request::create($uri, 'get', array(), array(), array(), $request->server->all());
|
||||
|
||||
$this->store->invalidate($subRequest);
|
||||
}
|
||||
}
|
||||
|
||||
$this->record($request, 'invalidate');
|
||||
} catch (\Exception $e) {
|
||||
$this->record($request, 'invalidate-failed');
|
||||
|
@ -246,15 +246,6 @@ class Store implements StoreInterface
|
||||
throw new \RuntimeException('Unable to store the metadata.');
|
||||
}
|
||||
}
|
||||
|
||||
// As per the RFC, invalidate Location and Content-Location URLs if present
|
||||
foreach (array('Location', 'Content-Location') as $header) {
|
||||
if ($uri = $request->headers->get($header)) {
|
||||
$subRequest = $request::create($uri, 'get', array(), array(), array(), $request->server->all());
|
||||
|
||||
$this->invalidate($subRequest);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -145,7 +145,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals(304, $this->response->getStatusCode());
|
||||
$this->assertEquals('text/html; charset=UTF-8', $this->response->headers->get('Content-Type'));
|
||||
$this->assertEquals('', $this->response->headers->get('Content-Type'));
|
||||
$this->assertEmpty($this->response->getContent());
|
||||
$this->assertTraceContains('miss');
|
||||
$this->assertTraceContains('store');
|
||||
@ -158,7 +158,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals(304, $this->response->getStatusCode());
|
||||
$this->assertEquals('text/html; charset=UTF-8', $this->response->headers->get('Content-Type'));
|
||||
$this->assertEquals('', $this->response->headers->get('Content-Type'));
|
||||
$this->assertTrue($this->response->headers->has('ETag'));
|
||||
$this->assertEmpty($this->response->getContent());
|
||||
$this->assertTraceContains('miss');
|
||||
@ -845,7 +845,7 @@ class HttpCacheTest extends HttpCacheTestCase
|
||||
$this->assertTraceContains('fresh');
|
||||
|
||||
// now POST to same URL
|
||||
$this->request('POST', '/');
|
||||
$this->request('POST', '/helloworld');
|
||||
$this->assertHttpKernelIsCalled();
|
||||
$this->assertEquals('/', $this->response->headers->get('Location'));
|
||||
$this->assertTraceContains('invalidate');
|
||||
|
@ -38,7 +38,7 @@ interface VoterInterface
|
||||
*
|
||||
* @param string $class A class name
|
||||
*
|
||||
* @return true if this Voter can process the class
|
||||
* @return Boolean true if this Voter can process the class
|
||||
*/
|
||||
public function supportsClass($class);
|
||||
|
||||
|
Reference in New Issue
Block a user