Drop class `Icinga\File\Storage\LocalFileStorageIterator`

This commit is contained in:
Johannes Meyer 2022-01-18 14:53:25 +01:00
parent 707677eebd
commit 42815f02e6
3 changed files with 12 additions and 46 deletions

View File

@ -38,7 +38,14 @@ class LocalFileStorage implements StorageInterface
public function getIterator() public function getIterator()
{ {
try { try {
return new LocalFileStorageIterator($this->baseDir); return new RecursiveIteratorIterator(
new RecursiveDirectoryIterator(
$this->baseDir,
RecursiveDirectoryIterator::CURRENT_AS_FILEINFO
| RecursiveDirectoryIterator::KEY_AS_PATHNAME
| RecursiveDirectoryIterator::SKIP_DOTS
)
);
} catch (UnexpectedValueException $e) { } catch (UnexpectedValueException $e) {
throw new NotReadableError('Couldn\'t read the directory "%s": %s', $this->baseDir, $e); throw new NotReadableError('Couldn\'t read the directory "%s": %s', $this->baseDir, $e);
} }

View File

@ -1,44 +0,0 @@
<?php
/* Icinga Web 2 | (c) 2017 Icinga Development Team | GPLv2+ */
namespace Icinga\File\Storage;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
/**
* @deprecated This class will be removed once we require PHP 5.6
*/
class LocalFileStorageIterator extends RecursiveIteratorIterator
{
/**
* Constructor
*
* @param string $baseDir
*/
public function __construct($baseDir)
{
parent::__construct(new RecursiveDirectoryIterator($baseDir, RecursiveDirectoryIterator::SKIP_DOTS));
}
public function key()
{
parent::key();
return $this->current();
}
public function current()
{
/** @var RecursiveDirectoryIterator $innerIterator */
$innerIterator = $this->getInnerIterator();
/** @var \SplFileInfo $current */
$current = parent::current();
$subPath = $innerIterator->getSubPath();
return $subPath === ''
? $current->getFilename()
: str_replace(DIRECTORY_SEPARATOR, '/', $subPath) . '/' . $current->getFilename();
}
}

View File

@ -51,7 +51,10 @@ class LocalFileStorageTest extends BaseTestCase
{ {
$lfs = new TemporaryLocalFileStorage(); $lfs = new TemporaryLocalFileStorage();
$lfs->create('foobar', 'Hello world!'); $lfs->create('foobar', 'Hello world!');
static::assertSame(array('foobar'), array_values(iterator_to_array($lfs->getIterator())));
foreach ($lfs as $path => $_) {
$this->assertEquals($lfs->resolvePath('foobar'), $path);
}
} }
public function testGetIteratorThrowsNotReadableError() public function testGetIteratorThrowsNotReadableError()