示例#1
0
 public function testGetSizeFormatted()
 {
     $file2 = File::createFromListingEntry($this->filesystem, ['path' => 'fixtures/images/2-top-right.jpg', 'size' => 123]);
     $this->assertSame('123 B', $file2->getSizeFormatted(true));
     $file = new File($this->filesystem, 'fixtures/images/2-top-right.jpg');
     $this->assertSame('6.86 KiB', $file->getSizeFormatted(false));
     $file2 = File::createFromListingEntry($this->filesystem, ['path' => 'fixtures/images/2-top-right.jpg', 'size' => 12345678]);
     $this->assertSame('11.77 MiB', $file2->getSizeFormatted(true));
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function listContents($directory = '', $recursive = false)
 {
     $directory = $this->normalizePath($directory);
     try {
         $contents = $this->getAdapter()->listContents($directory, $recursive);
     } catch (Exception $e) {
         throw $this->handleEx($e, $directory);
     }
     $formatter = new Flysystem\Util\ContentListingFormatter($directory, $recursive);
     $contents = $formatter->formatListing($contents);
     $contents = array_map(function ($entry) {
         $type = $this->getTypeFromMetadata($entry);
         $entry['type'] = $type;
         if ($type === 'dir') {
             $handler = new Handler\Directory($this, $entry['path']);
         } elseif ($type === 'image') {
             $handler = Handler\Image::createFromListingEntry($this, $entry);
         } else {
             $handler = Handler\File::createFromListingEntry($this, $entry);
         }
         $handler->setMountPoint($this->mountPoint);
         return $handler;
     }, $contents);
     return $contents;
 }
 /**
  * @dataProvider getAcceptData
  */
 public function testAccept($mode, array $expected)
 {
     $iterator = new \ArrayIterator([File::createFromListingEntry($this->filesystem, ['timestamp' => 1, 'path' => 'fixtures/js/script.js']), File::createFromListingEntry($this->filesystem, ['timestamp' => 9, 'path' => 'fixtures/css/reset.css']), File::createFromListingEntry($this->filesystem, ['timestamp' => 2, 'path' => 'fixtures']), File::createFromListingEntry($this->filesystem, ['timestamp' => 8, 'path' => 'fixtures/css/old/old_style.css']), File::createFromListingEntry($this->filesystem, ['timestamp' => 4, 'path' => 'fixtures/base.css']), File::createFromListingEntry($this->filesystem, ['timestamp' => 7, 'path' => 'fixtures/css/style.css']), File::createFromListingEntry($this->filesystem, ['timestamp' => 5, 'path' => 'fixtures/css/old']), File::createFromListingEntry($this->filesystem, ['timestamp' => 6, 'path' => 'fixtures/js']), File::createFromListingEntry($this->filesystem, ['timestamp' => 3, 'path' => 'fixtures/css'])]);
     $iterator = new SortableIterator($iterator, $mode);
     $this->assertOrderedIterator($expected, $iterator);
 }