dataPattern = '{FOLDER}/{KEY}'; if (!isset($options['formatter']) && isset($options['pattern'])) { $options['formatter'] = $this->detectDataFormatter($options['pattern']); } parent::__construct($options); } /** * {@inheritdoc} * @see FlexStorageInterface::getMediaPath() */ public function getMediaPath(string $key = null): string { return $key ? \dirname($this->getStoragePath($key)) . '/' . $key : $this->getStoragePath(); } /** * {@inheritdoc} */ protected function getKeyFromPath(string $path): string { return basename($path, $this->dataFormatter->getDefaultFileExtension()); } /** * {@inheritdoc} */ protected function buildIndex(): array { if (!file_exists($this->getStoragePath())) { return []; } $flags = \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::UNIX_PATHS; $iterator = new \FilesystemIterator($this->getStoragePath(), $flags); $list = []; /** @var \SplFileInfo $info */ foreach ($iterator as $filename => $info) { if (!$info->isFile() || !($key = $this->getKeyFromPath($filename)) || strpos($info->getFilename(), '.') === 0) { continue; } $list[$key] = [ 'storage_key' => $key, 'storage_timestamp' => $info->getMTime() ]; } ksort($list, SORT_NATURAL); return $list; } }