本文整理汇总了PHP中League\Flysystem\FilesystemInterface::getMetadata方法的典型用法代码示例。如果您正苦于以下问题:PHP FilesystemInterface::getMetadata方法的具体用法?PHP FilesystemInterface::getMetadata怎么用?PHP FilesystemInterface::getMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\FilesystemInterface
的用法示例。
在下文中一共展示了FilesystemInterface::getMetadata方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: load
public function load($spiBinaryFileId)
{
try {
$info = $this->filesystem->getMetadata($spiBinaryFileId);
} catch (FileNotFoundException $e) {
throw new BinaryFileNotFoundException($spiBinaryFileId);
}
$spiBinaryFile = new SPIBinaryFile();
$spiBinaryFile->id = $spiBinaryFileId;
$spiBinaryFile->mtime = new DateTime('@' . $info['timestamp']);
$spiBinaryFile->size = $info['size'];
return $spiBinaryFile;
}
示例2: uploadContents
/**
* Uploads raw contents to the service.
*
* @param string $contents
* @return array The meta of the file.
*/
public function uploadContents($name, $contents)
{
$this->filesystem->write($name, $contents);
$meta = $this->filesystem->getMetadata($name);
$urlGenerator = app('Flarum\\Forum\\UrlGenerator');
if (empty($this->settings->get('flagrow.image-upload.cdnUrl'))) {
// if there is no cdnUrl
$meta['url'] = $urlGenerator->toPath('assets/images/' . $name);
} else {
// if there is
$meta['url'] = $this->settings->get('flagrow.image-upload.cdnUrl') . 'assets/images/' . $name;
}
return $meta;
}
示例3: _stat
/**
* Return stat for given path.
* Stat contains following fields:
* - (int) size file size in b. required
* - (int) ts file modification time in unix time. required
* - (string) mime mimetype. required for folders, others - optionally
* - (bool) read read permissions. required
* - (bool) write write permissions. required
* - (bool) locked is object locked. optionally
* - (bool) hidden is object hidden. optionally
* - (string) alias for symlinks - link target path relative to root path. optionally
* - (string) target for symlinks - link target path. optionally
*
* If file does not exists - returns empty array or false.
*
* @param string $path file path
* @return array|false
**/
protected function _stat($path)
{
$stat = array('mime' => 'directory', 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'size' => 0);
// If root, just return from above
if ($this->root == $path) {
$stat['name'] = $this->root;
return $stat;
}
// If not exists, return empty
if (!$this->fs->has($path)) {
return array();
}
$meta = $this->fs->getMetadata($path);
// Get timestamp/size
$stat['ts'] = isset($meta['timestamp']) ? $meta['timestamp'] : $this->fs->getTimestamp($path);
$stat['size'] = isset($meta['size']) ? $meta['size'] : $this->fs->getSize($path);
// Check if file, if so, check mimetype
if ($meta['type'] == 'file') {
$stat['mime'] = isset($meta['mimetype']) ? $meta['mimetype'] : $this->fs->getMimetype($path);
$imgMimes = ['image/jpeg', 'image/png', 'image/gif'];
if ($this->urlBuilder && in_array($stat['mime'], $imgMimes)) {
$stat['url'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts']]);
$stat['tmb'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts'], 'w' => $this->tmbSize, 'h' => $this->tmbSize, 'fit' => $this->options['tmbCrop'] ? 'crop' : 'contain']);
}
}
if (!isset($stat['url']) && $this->fs->getUrl()) {
$stat['url'] = 1;
}
return $stat;
}
示例4: _stat
/**
* Return stat for given path.
* Stat contains following fields:
* - (int) size file size in b. required
* - (int) ts file modification time in unix time. required
* - (string) mime mimetype. required for folders, others - optionally
* - (bool) read read permissions. required
* - (bool) write write permissions. required
* - (bool) locked is object locked. optionally
* - (bool) hidden is object hidden. optionally
* - (string) alias for symlinks - link target path relative to root path. optionally
* - (string) target for symlinks - link target path. optionally
*
* If file does not exists - returns empty array or false.
*
* @param string $path file path
* @return array|false
**/
protected function _stat($path)
{
$stat = array('size' => 0, 'ts' => time(), 'read' => true, 'write' => true, 'locked' => false, 'hidden' => false, 'mime' => 'directory');
// If root, just return from above
if ($this->root == $path) {
$stat['name'] = $this->root;
return $stat;
}
// If not exists, return empty
if (!$this->fs->has($path)) {
// Check if the parent doesn't have this path
if ($this->_dirExists($path)) {
return $stat;
}
// Neither a file or directory exist, return empty
return array();
}
try {
$meta = $this->fs->getMetadata($path);
} catch (\Exception $e) {
return array();
}
if (false === $meta) {
return $stat;
}
// Set item filename.extension to `name` if exists
if (isset($meta['filename']) && isset($meta['extension'])) {
$stat['name'] = $meta['filename'];
if ($meta['extension'] !== '') {
$stat['name'] .= '.' . $meta['extension'];
}
}
// Get timestamp/size if available
if (isset($meta['timestamp'])) {
$stat['ts'] = $meta['timestamp'];
}
if (isset($meta['size'])) {
$stat['size'] = $meta['size'];
}
// Check if file, if so, check mimetype when available
if ($meta['type'] == 'file') {
if (isset($meta['mimetype'])) {
$stat['mime'] = $meta['mimetype'];
} else {
$stat['mime'] = $this->fs->getMimetype($path);
}
$imgMimes = ['image/jpeg', 'image/png', 'image/gif'];
if ($this->urlBuilder && in_array($stat['mime'], $imgMimes)) {
$stat['url'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts']]);
$stat['tmb'] = $this->urlBuilder->getUrl($path, ['ts' => $stat['ts'], 'w' => $this->tmbSize, 'h' => $this->tmbSize, 'fit' => $this->options['tmbCrop'] ? 'crop' : 'contain']);
}
}
if (!isset($stat['url']) && $this->fs->getUrl()) {
$stat['url'] = 1;
}
return $stat;
}
示例5: getType
/**
* @override
* @inheritDoc
*/
public function getType($path)
{
try {
return $this->fs->getMetadata($path)['type'];
} catch (Error $ex) {
} catch (Exception $ex) {
}
throw new ReadException("File {$path} type could not be determined.", $ex);
}
示例6: getSpecificFileInformation
/**
* Extracts a specific FileInformation from the FileSystems.
*
* @param string $fileIdentifier
* @param string $containerPath
* @param string $property
*
* @return bool|int|string
* @throws \InvalidArgumentException
*/
public function getSpecificFileInformation($fileIdentifier, $containerPath, $property)
{
$baseName = basename($fileIdentifier);
$parts = explode('/', $fileIdentifier);
$identifier = $this->canonicalizeAndCheckFileIdentifier($containerPath . PathUtility::basename($fileIdentifier));
$file = $this->filesystem->getMetadata($fileIdentifier);
switch ($property) {
case 'size':
return $file['size'];
case 'atime':
return $file['timestamp'];
case 'mtime':
return $file['timestamp'];
case 'ctime':
return $file['timestamp'];
case 'name':
return $baseName;
case 'mimetype':
return 'application/octet-stream';
case 'identifier':
return $identifier;
case 'storage':
return $this->storageUid;
case 'identifier_hash':
return $this->hashIdentifier($identifier);
case 'folder_hash':
if (1 < count($parts)) {
return $this->hashIdentifier($this->getParentFolderIdentifierOfIdentifier($identifier));
} elseif (1 === count($parts)) {
return sha1('/');
} else {
return '';
}
default:
throw new \InvalidArgumentException(sprintf('The information "%s" is not available.', $property));
}
}
示例7: getType
/**
* Retrieve the entree type (file|dir).
*
* @return string file or dir
*/
public function getType()
{
$metadata = $this->filesystem->getMetadata($this->path);
return $metadata['type'];
}
示例8: getMetadata
/**
* Get a file's metadata.
*
* @param string $path The path to the file.
*
* @throws FileNotFoundException
*
* @return array|false The file metadata or false on failure.
*/
public function getMetadata($path)
{
return $this->fileSystem->getMetadata($path);
}