/** * {@inheritdoc} */ public function get($path, HandlerInterface $handler = null) { $path = $this->normalizePath($path); if ($handler === null) { $this->assertPresent($path); $type = $this->doGetType($path); if ($type === 'dir') { $handler = new Handler\Directory($this, $path); } elseif ($type === 'image') { $handler = new Handler\Image($this, $path); } elseif ($type === 'json') { $handler = new Handler\JsonFile($this, $path); } elseif ($type === 'yaml') { $handler = new Handler\YamlFile($this, $path); } else { $handler = new Handler\File($this, $path); } } $handler->setPath($path); $handler->setFilesystem($this); if ($handler instanceof MountPointAwareInterface) { $handler->setMountPoint($this->mountPoint); } return $handler; }
/** * {@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); if ($type === 'dir') { $handler = new Handler\Directory($this, $entry['path']); } elseif ($type === 'image') { $handler = new Handler\Image($this, $entry['path']); } else { $handler = new Handler\File($this, $entry['path']); } $handler->setMountPoint($this->mountPoint); return $handler; }, $contents); return $contents; }