/** * {@inheritdoc} */ public function storeContents($directory, array $contents, $recursive) { if ($recursive) { return $contents; } foreach ($contents as $index => $object) { $pathinfo = Util::pathinfo($object['path']); $object = array_merge($pathinfo, $object); if (!$recursive && $object['dirname'] !== $directory) { unset($contents[$index]); continue; } $contents[$index] = $object; } return $contents; }
/** * @dataProvider metaGetterProvider * * @param $method * @param $key * @param $value */ public function testMetaGetters($method, $key, $value) { $cache = new Memory(); $this->assertFalse($cache->{$method}('path.txt')); $cache->updateObject('path.txt', $object = ['path' => 'path.txt', 'type' => 'file', $key => $value] + Util::pathinfo('path.txt'), true); $this->assertEquals($object, $cache->{$method}('path.txt')); $this->assertEquals($object, $cache->getMetadata('path.txt')); }
/** * Normalize the object result array. * * @param array $response * @param string $path * * @return array */ protected function normalizeResponse(array $response, $path = null) { $result = ['path' => $path ?: $this->removePathPrefix($response['Key'])]; $result = array_merge($result, Util::pathinfo($result['path'])); if (isset($response['LastModified'])) { $result['timestamp'] = strtotime($response['LastModified']); } if (substr($result['path'], -1) === '/') { $result['type'] = 'dir'; $result['path'] = rtrim($result['path'], '/'); return $result; } return array_merge($result, Util::map($response, static::$resultMap), ['type' => 'file']); }
/** * {@inheritdoc} */ public function listContents($directory = '', $recursive = false) { $directory = Util::normalizePath($directory); $contents = $this->getAdapter()->listContents($directory, $recursive); $mapper = function ($entry) use($directory, $recursive) { if ($entry['path'] === false && (!empty($directory) && strpos($entry['path'], $directory) === false)) { return false; } $entry = $entry + Util::pathinfo($entry['path']); if ($recursive === false && Util::dirname($entry['path']) !== $directory) { return false; } return $entry; }; $listing = array_values(array_filter(array_map($mapper, $contents))); usort($listing, function ($a, $b) { return strcasecmp($a['path'], $b['path']); }); return $listing; }
/** * Ensure parent directories of an object * * @param string $path object path */ public function ensureParentDirectories($path) { $object = $this->cache[$path]; while ($object['dirname'] !== '' && !isset($this->cache[$object['dirname']])) { $object = Util::pathinfo($object['dirname']); $object['type'] = 'dir'; $this->cache[$object['path']] = $object; } }
/** * List the filesystem contents. * * @param string $directory * @param bool $recursive * * @return array contents */ public function listContents($directory = '', $recursive = false) { $directory = Util::normalizePath($directory); $contents = $this->adapter->listContents($directory, $recursive); $mapper = function ($entry) use($directory, $recursive) { $entry = $entry + Util::pathinfo($entry['path']); if (!empty($directory) && strpos($entry['path'], $directory) === false) { return false; } if ($recursive === false && Util::dirname($entry['path']) !== $directory) { return false; } return $entry; }; return array_values(array_filter(array_map($mapper, $contents))); }
private function addPathInfo(array $entry) { return $entry + Util::pathinfo($entry['path']); }
protected function getPathInfo($path) { $info = Util::pathinfo('/' . Util::normalizePath($path)); $info['path'] = ltrim($info['path'], '/'); $info['dirname'] = ltrim($info['dirname'], '/'); if (empty($info['basename'])) { $info['basename'] = '.'; } return $info; }
/** * @inheritdoc */ public function listContents($directory = '', $recursive = false) { $directory = Util::normalizePath($directory); $adapter = $this->getAdapter(); $separator = $adapter instanceof Local ? DIRECTORY_SEPARATOR : '/'; $contents = $adapter->listContents($directory, $recursive); $mapper = function ($entry) use($directory, $recursive, $separator) { if (strlen($entry['path']) === 0 || !empty($directory) && strpos($entry['path'], $directory . $separator) === false || $recursive === false && Util::dirname($entry['path']) !== $directory) { return false; } return $entry + Util::pathinfo($entry['path']); }; $listing = array_values(array_filter(array_map($mapper, $contents))); usort($listing, function ($a, $b) { return strcasecmp($a['path'], $b['path']); }); return $listing; }
public function testListContents() { $rawListing = [['path' => 'other_root/file.txt'], ['path' => 'valid/to_deep/file.txt'], ['path' => 'valid/file.txt']]; $expected = [Util::pathinfo('valid/file.txt')]; $this->prophecy->listContents('valid', false)->willReturn($rawListing); $output = $this->filesystem->listContents('valid', false); $this->assertEquals($expected, $output); }
/** * @inheritdoc */ public function listContents($directory = '', $recursive = false) { $directory = Util::normalizePath($directory); $contents = $this->getAdapter()->listContents($directory, $recursive); $filter = function (array $entry) use($directory, $recursive) { if (empty($entry['path']) && $entry['path'] !== '0') { return false; } if ($recursive) { return $directory === '' || strpos($entry['path'], $directory . '/') === 0; } return Util::dirname($entry['path']) === $directory; }; $mapper = function (array $entry) { return $entry + Util::pathinfo($entry['path']); }; $listing = array_values(array_map($mapper, array_filter($contents, $filter))); usort($listing, function ($a, $b) { return strcasecmp($a['path'], $b['path']); }); return $listing; }