예제 #1
0
 public function testIsMappable()
 {
     $collection = InMemory::fromArray([0, 1, 2, 3, 4]);
     $mapped = $collection->map(function ($number) {
         return $number * 2;
     });
     $this->assertTrue($mapped->contains(0));
     $this->assertTrue($mapped->contains(2));
     $this->assertTrue($mapped->contains(4));
     $this->assertTrue($mapped->contains(6));
     $this->assertTrue($mapped->contains(8));
     $this->assertEquals(5, count($mapped));
     $this->assertNotSame($mapped, $collection);
 }
예제 #2
0
 /**
  * List the files and directories in the given directory path.
  *
  * @param string   $path      The subdirectory path within this directory
  * @param bool     $recursive Find files and directories recursively
  * @param string[] $types     Entry types to return ('file' and/or 'dir')
  *
  * @return Collection<File|Directory>
  *
  * @throws \InvalidArgumentException
  */
 protected function getEntries($path = '', $recursive = true, $types = ['file', 'dir'])
 {
     $contents = $this->fs->listContents($this->getInternalPath($path), $recursive);
     if (!$contents) {
         $contents = [];
     }
     $contents = array_filter($contents, function ($metadata) use($types) {
         return in_array($metadata['type'], $types);
     });
     return Collection\InMemory::fromArray(array_map(function ($metadata) {
         if ($metadata['type'] === 'file') {
             return new File($this, $metadata['path']);
         }
         return new self($this->fs, $this->local_path, $metadata['path']);
     }, $contents));
 }