Supported Versions: PHP 5 >= 5.1.0, PHP 7, PHP 8
Copy the iterator into an array
<?php iterator_to_array(Traversable|array $iterator, bool $preserve_keys = true): array
<?php $listing = $this->adapter()->listContents('some', false);
$items = iterator_to_array($listing);
$this->assertInstanceOf(Generator::class, $listing);
$this->assertContainsOnlyInstancesOf(StorageAttributes::class, $items);
<?php $listing = $adapter->listContents('', true);
$items = iterator_to_array($listing);
$this->assertCount(2, $items, $this->formatIncorrectListingCount($items));
});
}
<?php $this->givenWeHaveAnExistingFile('path2.txt');
$this->runScenario(function () {
$contents = iterator_to_array($this->adapter()->listContents('', true));
$this->assertCount(2, $contents);
});
<?php $adapter->createDirectory('path', new Config());
$contents = iterator_to_array($adapter->listContents('', false));
$this->assertCount(1, $contents, $this->formatIncorrectListingCount($contents));
$directory = $contents[0];
<?php $adapter->write('something/0/here.txt', 'contents', new Config());
$adapter->write('something/1/also/here.txt', 'contents', new Config());
$contents = iterator_to_array($adapter->listContents('', true));
$this->assertCount(2, $contents);
$this->assertContainsOnlyInstancesOf(FileAttributes::class, $contents);
<?php $adapter->write('something/0/here.txt', 'contents', new Config());
$adapter->write('something/1/also/here.txt', 'contents', new Config());
$contents = iterator_to_array($adapter->listContents('', true));
$this->assertCount(2, $contents);
$this->assertContainsOnlyInstancesOf(FileAttributes::class, $contents);
<?php public function toArray(): array
{
return $this->listing instanceof Traversable
? iterator_to_array($this->listing, false)
: (array) $this->listing;
}
}
<?php self::expectNotToPerformAssertions();
iterator_to_array($listing->sortByPath());
}
<?php $this->assertInstanceOf(DirectoryListing::class, $listing);
$this->assertInstanceOf(IteratorAggregate::class, $listing);
$attributeListing = iterator_to_array($listing);
$this->assertContainsOnlyInstancesOf(StorageAttributes::class, $attributeListing);
$this->assertCount(1, $attributeListing);
}
<?php $adapter = $this->adapter();
static::$connectivityChecker->failNextCall();
$contents = iterator_to_array($adapter->listContents('', false));
$this->assertIsArray($contents);
});
}
<?php $this->runScenario(function () {
$adapter = $this->adapter();
$contents = iterator_to_array($adapter->listContents('/', false), false);
$this->assertCount(1, $contents);
$this->assertContainsOnlyInstancesOf(FileAttributes::class, $contents);
<?php $this->runScenario(function () {
$adapter = $this->adapter();
$contents = iterator_to_array($adapter->listContents('/', false), false);
$this->assertCount(2, $contents);
$this->assertContainsOnlyInstancesOf(StorageAttributes::class, $contents);
<?php $this->runScenario(function () {
$adapter = $this->adapter();
iterator_to_array($adapter->listContents('/', false), false);
});
}
<?php $this->runScenario(function () {
$adapter = $this->adapter();
iterator_to_array($adapter->listContents('/', false), false);
});
}
<?php $this->runScenario(function () use ($options) {
$adapter = new FtpAdapter($options);
$contents = iterator_to_array($adapter->listContents('somewhere', true), false);
$this->assertCount(4, $contents);
$this->assertContainsOnlyInstancesOf(StorageAttributes::class, $contents);