Drop class `Icinga\File\Storage\LocalFileStorageIterator`
This commit is contained in:
parent
707677eebd
commit
42815f02e6
|
@ -38,7 +38,14 @@ class LocalFileStorage implements StorageInterface
|
|||
public function getIterator()
|
||||
{
|
||||
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) {
|
||||
throw new NotReadableError('Couldn\'t read the directory "%s": %s', $this->baseDir, $e);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -51,7 +51,10 @@ class LocalFileStorageTest extends BaseTestCase
|
|||
{
|
||||
$lfs = new TemporaryLocalFileStorage();
|
||||
$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()
|
||||
|
|
Loading…
Reference in New Issue