| Current Path : /home/jeromecohp/www/tmp/yooessentials/modules/vendor/league/flysystem/src/ |
| Current File : /home/jeromecohp/www/tmp/yooessentials/modules/vendor/league/flysystem/src/DirectoryListing.php |
<?php
declare (strict_types=1);
namespace ZOOlanders\YOOessentials\Vendor\League\Flysystem;
use ArrayIterator;
use Generator;
use IteratorAggregate;
use Traversable;
/**
* @template T
*/
class DirectoryListing implements \IteratorAggregate
{
/**
* @var iterable<T>
*/
private $listing;
/**
* @param iterable<T> $listing
*/
public function __construct(iterable $listing)
{
$this->listing = $listing;
}
public function filter(callable $filter) : \ZOOlanders\YOOessentials\Vendor\League\Flysystem\DirectoryListing
{
$generator = (static function (iterable $listing) use($filter) : Generator {
foreach ($listing as $item) {
if ($filter($item)) {
(yield $item);
}
}
})($this->listing);
return new \ZOOlanders\YOOessentials\Vendor\League\Flysystem\DirectoryListing($generator);
}
public function map(callable $mapper) : \ZOOlanders\YOOessentials\Vendor\League\Flysystem\DirectoryListing
{
$generator = (static function (iterable $listing) use($mapper) : Generator {
foreach ($listing as $item) {
(yield $mapper($item));
}
})($this->listing);
return new \ZOOlanders\YOOessentials\Vendor\League\Flysystem\DirectoryListing($generator);
}
public function sortByPath() : \ZOOlanders\YOOessentials\Vendor\League\Flysystem\DirectoryListing
{
$listing = $this->toArray();
\usort($listing, function (\ZOOlanders\YOOessentials\Vendor\League\Flysystem\StorageAttributes $a, \ZOOlanders\YOOessentials\Vendor\League\Flysystem\StorageAttributes $b) {
return $a->path() <=> $b->path();
});
return new \ZOOlanders\YOOessentials\Vendor\League\Flysystem\DirectoryListing($listing);
}
/**
* @return Traversable<T>
*/
public function getIterator() : \Traversable
{
return $this->listing instanceof \Traversable ? $this->listing : new \ArrayIterator($this->listing);
}
/**
* @return T[]
*/
public function toArray() : array
{
return $this->listing instanceof \Traversable ? \iterator_to_array($this->listing, \false) : (array) $this->listing;
}
}