本文整理汇总了PHP中League\Flysystem\Util::dirname方法的典型用法代码示例。如果您正苦于以下问题:PHP Util::dirname方法的具体用法?PHP Util::dirname怎么用?PHP Util::dirname使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\Util
的用法示例。
在下文中一共展示了Util::dirname方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: listContents
public function listContents($directory = '', $recursive = false)
{
$filter = function (&$value, $path) use($directory) {
if (Util::dirname($path) !== $directory) {
$value = null;
}
};
$list = $this->client->lists($directory, $recursive ? null : $filter);
return $list;
}
示例2: rename
public function rename($path, $newpath)
{
$location = $this->applyPathPrefix($path);
$destination = $this->applyPathPrefix($newpath);
$parentDirectory = $this->applyPathPrefix(Util::dirname($newpath));
if (!$this->ensureDirectory($parentDirectory)) {
return false;
}
return rename($location, $destination);
}
示例3: isValidRename
/**
* Checks that a rename is valid.
*
* @param string $source
* @param string $dest
*
* @return bool
*/
protected function isValidRename($source, $dest)
{
$adapter = $this->filesystem->getAdapter();
if (!$adapter->has($source)) {
throw new FileNotFoundException($source);
}
$subdir = Util::dirname($dest);
if (strlen($subdir) && !$adapter->has($subdir)) {
throw new FileNotFoundException($source);
}
if (!$adapter->has($dest)) {
return true;
}
return $this->compareTypes($source, $dest);
}
示例4: write
/**
* {@inheritdoc}
*/
public function write($path, $contents, Config $config)
{
$location = $this->applyPathPrefix($path);
$dirname = Util::dirname($path);
if (!empty($dirname) && !$this->has($dirname)) {
$this->createDir($dirname, $config);
}
if (!$this->archive->addFromString($location, $contents)) {
return false;
}
$result = compact('path', 'contents');
if ($config && $config->get('visibility')) {
throw new LogicException(get_class($this) . ' does not support visibility settings.');
}
return $result;
}
示例5: listContents
/**
* @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;
}
示例6: normalizeObject
/**
* {@inheritdoc}
*/
protected function normalizeObject(DataObject $object)
{
$name = $object->getName();
$name = $this->removePathPrefix($name);
$mimetype = explode('; ', $object->getContentType());
return ['type' => in_array('application/directory', $mimetype) ? 'dir' : 'file', 'dirname' => Util::dirname($name), 'path' => $name, 'timestamp' => strtotime($object->getLastModified()), 'mimetype' => reset($mimetype), 'size' => $object->getContentLength()];
}
示例7: _dirname
/**
* Return parent directory path
*
* @param string $path file path
* @return string
**/
protected function _dirname($path)
{
return Util::dirname($path) ?: '/';
}
示例8: listContents
/**
* 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)));
}
示例9: isDirectChild
/**
* Check if the entry is a direct child of the directory.
*
* @param $entry
*
* @return bool
*/
private function isDirectChild(array $entry)
{
return Util::dirname($entry['path']) === $this->directory;
}
示例10: has
/**
* {@inheritdoc}
*/
public function has($path)
{
if (array_key_exists($path, $this->cache)) {
return $this->cache[$path] !== false;
}
if ($this->isComplete(Util::dirname($path), false)) {
return false;
}
}
示例11: normalizeObject
/**
* Normalize a result from Google
*
* @param string $object
* @param string $path
* @return array file metadata
*/
protected function normalizeObject($object, $path = null)
{
$newObject = array();
foreach ((array) $object as $key => $value) {
if (substr($key, 0, 3) == "*") {
$key = substr($key, 3);
}
$newObject[$key] = $value;
}
$object = $newObject;
if (isset($object["dirname"])) {
$result = array('path' => $object['dirname'] . "/" . $object['id']);
} else {
$result = array('path' => $object['id']);
}
if (isset($object['modifiedDate'])) {
$result['timestamp'] = strtotime($object['modifiedDate']);
}
$result["basename"] = $object["title"];
if ($object['mimeType'] == 'application/vnd.google-apps.folder') {
$result['type'] = 'dir';
$result['path'] = rtrim($result['path'], '/');
$result['dirname'] = Util::dirname($result['path']);
return $result;
}
$result = array_merge($result, Util::map($object, static::$resultMap), array('type' => 'file'));
$result['dirname'] = Util::dirname($result['path']);
if (isset($result['contents'])) {
$result['contents'] = (string) $result['contents'];
}
return $result;
}
示例12: listContents
/**
* @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;
}
示例13: writeStream
public function writeStream($path, $resource, $config = null)
{
$this->ensureDirectory(Util::dirname($path));
$config = Util::ensureConfig($config);
if (!ftp_fput($this->getConnection(), $path, $resource, FTP_BINARY)) {
return false;
}
if ($visibility = $config->get('visibility')) {
$this->setVisibility($path, $visibility);
}
return compact('path', 'visibility');
}
示例14: ensureSubDirs
/**
* Ensures that the sub-directories of a directory exist.
*
* @param string $directory The directory.
* @param Config|null $config Optionl configuration.
*
* @return bool True on success, false on failure.
*/
protected function ensureSubDirs($directory, Config $config = null)
{
$config = $config ?: new Config();
return $this->createDir(Util::dirname($directory), $config);
}
示例15: upload
/**
* Upload|Update item
*
* @param string $path
* @param string|resource $contents
* @param Config $config
*
* @return array|false item info array
*/
protected function upload($path, $contents, Config $config)
{
list($parentId, $fileName) = $this->splitPath($path);
$mode = 'update';
$mime = $config->get('mimetype');
$srcFile = $this->getFileObject($path);
$file = new Google_Service_Drive_DriveFile();
if (!$srcFile) {
$mode = 'insert';
$file->setName($fileName);
$file->setParents([$parentId]);
}
$isResource = false;
if (is_resource($contents)) {
$fstat = @fstat($contents);
if (!empty($fstat['size'])) {
$isResource = true;
}
if (!$isResource) {
$contents = stream_get_contents($contents);
}
}
if ($isResource) {
// set chunk size (max: 100MB)
$chunkSizeBytes = 100 * 1024 * 1024;
$memory = $this->getIniBytes('memory_limit');
if ($memory) {
$chunkSizeBytes = min([$chunkSizeBytes, intval($memory / 4 / 256) * 256]);
}
if ($fstat['size'] < $chunkSizeBytes) {
$isResource = false;
$contents = stream_get_contents($contents);
}
}
if (!$mime) {
$mime = Util::guessMimeType($fileName, $isResource ? '' : $contents);
}
$file->setMimeType($mime);
if ($isResource) {
$client = $this->service->getClient();
// Call the API with the media upload, defer so it doesn't immediately return.
$client->setDefer(true);
if ($mode === 'insert') {
$request = $this->service->files->create($file, ['fields' => self::FETCHFIELDS_GET]);
} else {
$request = $this->service->files->update($srcFile->getId(), $file, ['fields' => self::FETCHFIELDS_GET]);
}
// Create a media file upload to represent our upload process.
$media = new Google_Http_MediaFileUpload($client, $request, $mime, null, true, $chunkSizeBytes);
$media->setFileSize($fstat['size']);
// Upload the various chunks. $status will be false until the process is
// complete.
$status = false;
$handle = $contents;
while (!$status && !feof($handle)) {
// read until you get $chunkSizeBytes from TESTFILE
// fread will never return more than 8192 bytes if the stream is read buffered and it does not represent a plain file
// An example of a read buffered file is when reading from a URL
$chunk = $this->readFileChunk($handle, $chunkSizeBytes);
$status = $media->nextChunk($chunk);
}
// The final value of $status will be the data from the API for the object
// that has been uploaded.
if ($status != false) {
$obj = $status;
}
$client->setDefer(false);
} else {
$params = ['data' => $contents, 'uploadType' => 'media', 'fields' => self::FETCHFIELDS_GET];
if ($mode === 'insert') {
$obj = $this->service->files->create($file, $params);
} else {
$obj = $this->service->files->update($srcFile->getId(), $file, $params);
}
}
if ($obj instanceof Google_Service_Drive_DriveFile) {
$this->cacheFileObjects[$obj->getId()] = $obj;
if ($mode === 'insert') {
$this->cacheFileObjects[$fileName] = $obj;
}
$result = $this->normaliseObject($obj, Util::dirname($path));
if ($visibility = $config->get('visibility')) {
if ($this->setVisibility($path, $visibility)) {
$result['visibility'] = $visibility;
}
}
return $result;
}
return false;
}