本文整理汇总了PHP中League\Flysystem\Util::normalizePath方法的典型用法代码示例。如果您正苦于以下问题:PHP Util::normalizePath方法的具体用法?PHP Util::normalizePath怎么用?PHP Util::normalizePath使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Flysystem\Util
的用法示例。
在下文中一共展示了Util::normalizePath方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: prefix
/**
* Prefix a path with the root
*
* @param string $path
* @return string prefixed path
*/
protected function prefix($path)
{
if (empty($path)) {
return $this->root;
}
$path = str_replace('/', DIRECTORY_SEPARATOR, $path);
return $this->root . Util::normalizePath($path, DIRECTORY_SEPARATOR);
}
示例2: prefix
/**
* Prefix a path with the root
*
* @param string $path
* @return string prefixed path
*/
public function prefix($path)
{
if ($path === '') {
return $this->root;
}
$path = str_replace('/', DIRECTORY_SEPARATOR, $path);
return $this->root . Util::normalizePath($path, DIRECTORY_SEPARATOR);
}
示例3: handle
/**
* Emulates touch().
*
* @param string $path
*
* @return bool True on success, false on failure.
*/
public function handle($path)
{
$path = Util::normalizePath($path);
$adapter = $this->filesystem->getAdapter();
if ($adapter->has($path)) {
return true;
}
return (bool) $adapter->write($path, '', $this->defaultConfig());
}
示例4: getFinder
/**
* @param string $path child path to find in
*
* @return Finder
*/
public function getFinder($path = '')
{
$path = Util::normalizePath($path);
$adapter = $this->getAdapter();
if (!$adapter instanceof FindableAdapterInterface) {
throw new NotSupportedException("Adapter doesn't support getFinder action. Adapter in use is: " . get_class($adapter));
}
return $adapter->getFinder($path);
}
示例5: handle
/**
* Creates a directory.
*
* @param string $dirname
* @param int $mode
* @param int $options
*
* @return bool True on success, false on failure.
*/
public function handle($dirname, $mode, $options)
{
$dirname = Util::normalizePath($dirname);
$adapter = $this->filesystem->getAdapter();
// If recursive, or a single level directory, just create it.
if ($options & STREAM_MKDIR_RECURSIVE || strpos($dirname, '/') === false) {
return (bool) $adapter->createDir($dirname, $this->defaultConfig());
}
if (!$adapter->has(dirname($dirname))) {
throw new FileNotFoundException($dirname);
}
return (bool) $adapter->createDir($dirname, $this->defaultConfig());
}
示例6: handle
/**
* Renames a file.
*
* @param string $path path to file
* @param string $newpath new path
*
* @throws \League\Flysystem\FileNotFoundException
* @throws \Twistor\Flysystem\Exception\DirectoryExistsException
* @throws \Twistor\Flysystem\Exception\DirectoryNotEmptyException
* @throws \Twistor\Flysystem\Exception\NotADirectoryException
*
* @return bool
*/
public function handle($path, $newpath)
{
$path = Util::normalizePath($path);
$newpath = Util::normalizePath($newpath);
// Ignore useless renames.
if ($path === $newpath) {
return true;
}
if (!$this->isValidRename($path, $newpath)) {
// Returns false if a Flysystem call fails.
return false;
}
return (bool) $this->filesystem->getAdapter()->rename($path, $newpath);
}
示例7: handle
/**
* Delete a directory.
*
* @param string $dirname path to directory
* @param int $options
*
* @return bool
*/
public function handle($dirname, $options)
{
$dirname = Util::normalizePath($dirname);
if ($dirname === '') {
throw new RootViolationException('Root directories can not be deleted.');
}
$adapter = $this->filesystem->getAdapter();
if ($options & STREAM_MKDIR_RECURSIVE) {
// I don't know how this gets triggered.
return (bool) $adapter->deleteDir($dirname);
}
$contents = $this->filesystem->listContents($dirname);
if (!empty($contents)) {
throw new DirectoryNotEmptyException();
}
return (bool) $adapter->deleteDir($dirname);
}
示例8: onGetClassGenerateFile
/**
* Use flysystem to save the file in the desired location.
*
* @param \Onema\ClassyFile\Event\GetClassEvent $event
*/
public function onGetClassGenerateFile(GetClassEvent $event)
{
$statement = $event->getStatements();
$fileLocation = $event->getFileLocation();
$code = $event->getCode();
$name = $statement->name;
if (!$this->filesystem->has($fileLocation)) {
// dir doesn't exist, make it
$this->filesystem->createDir($fileLocation);
}
$location = sprintf('%s/%s.php', $fileLocation, $name);
$this->filesystem->put($location, $code);
$adapter = $this->filesystem->getAdapter();
if ($adapter instanceof AbstractAdapter) {
$prefix = $adapter->getPathPrefix();
$location = Util::normalizePath($location);
$event->setFileLocation(sprintf('%s%s', $prefix, $location));
}
}
示例9: _joinPath
/**
* Join dir name and file name and return full path
*
* @param string $dir
* @param string $name
* @return string
* @author Dmitry (dio) Levashov
**/
protected function _joinPath($dir, $name)
{
return Util::normalizePath($dir . $this->separator . $name);
}
示例10: createFile
/**
* @param string $path
* @param array $config
*
* @throws \LogicException
* @throws \InvalidArgumentException
* @throws \Exception|\Throwable
*
* @return MediaEntity
*/
protected function createFile($path, array $config)
{
$path = Util::normalizePath($path);
$pathInfo = pathinfo($path);
return (new MediaEntity())->getConnection()->transaction(function () use($path, $pathInfo, $config) {
$parent = $this->ensureDirectory(dirname($path));
$media = MediaEntity::create(['hash' => array_key_exists('hash', $config) ? $config['hash'] : md5(uniqid('media', true)), 'ext' => null, 'type' => MediaEntity::TYPE_FILE, 'caption' => array_key_exists('caption ', $config) ? $config['caption'] : $pathInfo['basename'], 'parent_id' => array_key_exists('parent_id', $config) ? $config['parent_id'] : null]);
$dir = dirname($media->realPath);
if (@mkdir($dir, 0755, true) && !is_dir($dir)) {
throw new \InvalidArgumentException();
}
if ($parent) {
$media->makeChildOf($parent);
} else {
$media->makeRoot();
}
return $media;
});
}
示例11: getMetadata
/**
* @inheritdoc
*/
public function getMetadata($path)
{
$path = Util::normalizePath($path);
$this->assertPresent($path);
return $this->getAdapter()->getMetadata($path);
}
示例12: getRealPathName
/**
* {@inheritdoc}
*/
public function getRealPathName($file)
{
return Util::normalizePath($file);
}
示例13: openLockHandle
/**
* Creates an advisory lock handle.
*
* @return resource|false
*/
protected function openLockHandle()
{
// PHP allows periods, '.', to be scheme names. Normalize the scheme
// name to something that won't cause problems. Also, avoid problems
// with case-insensitive filesystems. We use bin2hex() rather than a
// hashing function since most scheme names are small, and bin2hex()
// only doubles the string length.
$sub_dir = bin2hex($this->getProtocol());
// Since we're flattening out whole filesystems, at least create a
// sub-directory for each scheme to attempt to reduce the number of
// files per directory.
$temp_dir = sys_get_temp_dir() . '/flysystem-stream-wrapper/' . $sub_dir;
// Race free directory creation. If @mkdir() fails, fopen() will fail
// later, so there's no reason to test again.
!is_dir($temp_dir) && @mkdir($temp_dir, 0777, true);
// Normalize paths so that locks are consistent.
// We are using sha1() to avoid the file name limits, and case
// insensitivity on Windows. This is not security sensitive.
$lock_key = sha1(Util::normalizePath($this->getTarget()));
// Relay the lock to a real filesystem lock.
return fopen($temp_dir . '/' . $lock_key, 'c');
}
示例14: _joinPath
/**
* Join dir name and file name and return full path
*
* @param string $dir
* @param string $name
* @return string
* @author Dmitry (dio) Levashov
*
*/
protected function _joinPath($dir, $name)
{
$phash = $this->encode($dir);
// do not recursive search
$searchExDirReg = $this->options['searchExDirReg'];
$this->options['searchExDirReg'] = '/.*/';
$search = $this->search($name, array(), $phash);
$this->options['searchExDirReg'] = $searchExDirReg;
if ($search) {
foreach ($search as $r) {
if ($r['phash'] === $phash && $r['name'] === $name) {
return Util::normalizePath($this->decode($r['hash']));
}
}
}
// reset stat cache of parent directory
$this->clearcaches($phash);
return Util::normalizePath($dir . $this->separator . $name);
}
示例15: normalizePath
protected function normalizePath($path)
{
// Strip mount point from path, if needed
if ($this->mountPoint && strpos($path, $this->mountPoint . '://') === 0) {
$path = substr($path, strlen($this->mountPoint) + 3);
}
try {
return Flysystem\Util::normalizePath($path);
} catch (\LogicException $e) {
throw new Ex\RootViolationException($e->getMessage(), $e->getCode(), $e);
}
}