update v1.0.4

This commit is contained in:
sujitprasad
2016-01-04 18:05:45 +05:30
parent 372485336b
commit 4864e5a3f1
529 changed files with 20956 additions and 8178 deletions

View File

@@ -18,7 +18,7 @@
},
"require-dev": {
"ext-fileinfo": "*",
"phpunit/phpunit": "~4.1",
"phpunit/phpunit": "~4.8",
"mockery/mockery": "~0.9",
"phpspec/phpspec": "^2.2",
"phpspec/prophecy-phpunit": "~1.0"

View File

@@ -27,8 +27,8 @@ abstract class AbstractAdapter implements AdapterInterface
{
$is_empty = empty($prefix);
if (! $is_empty) {
$prefix = rtrim($prefix, $this->pathSeparator).$this->pathSeparator;
if ( ! $is_empty) {
$prefix = rtrim($prefix, $this->pathSeparator) . $this->pathSeparator;
}
$this->pathPrefix = $is_empty ? null : $prefix;
@@ -60,7 +60,7 @@ abstract class AbstractAdapter implements AdapterInterface
}
if ($prefix = $this->getPathPrefix()) {
$path = $prefix.$path;
$path = $prefix . $path;
}
return $path;

View File

@@ -99,11 +99,11 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
public function setConfig(array $config)
{
foreach ($this->configurable as $setting) {
if (! isset($config[$setting])) {
if ( ! isset($config[$setting])) {
continue;
}
$method = 'set'.ucfirst($setting);
$method = 'set' . ucfirst($setting);
if (method_exists($this, $method)) {
$this->$method($config[$setting]);
@@ -208,7 +208,7 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
*/
public function setRoot($root)
{
$this->root = rtrim($root, '\\/').$this->separator;
$this->root = rtrim($root, '\\/') . $this->separator;
return $this;
}
@@ -397,7 +397,7 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
$item = preg_replace('#\s+#', ' ', trim($item), 7);
list($permissions, /* $number */, /* $owner */, /* $group */, $size, /* $month */, /* $day */, /* $time*/, $name) = explode(' ', $item, 9);
$type = $this->detectType($permissions);
$path = empty($base) ? $name : $base.$this->separator.$name;
$path = empty($base) ? $name : $base . $this->separator . $name;
if ($type === 'dir') {
return compact('type', 'path');
@@ -422,11 +422,11 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
{
$item = preg_replace('#\s+#', ' ', trim($item), 3);
list($date, $time, $size, $name) = explode(' ', $item, 4);
$path = empty($base) ? $name : $base.$this->separator.$name;
$path = empty($base) ? $name : $base . $this->separator . $name;
// Check for the correct date/time format
$format = strlen($date) === 8 ? 'm-d-yH:iA' : 'Y-m-dH:i';
$timestamp = DateTime::createFromFormat($format, $date.$time)->getTimestamp();
$timestamp = DateTime::createFromFormat($format, $date . $time)->getTimestamp();
if ($size === '<DIR>') {
$type = 'dir';
@@ -507,7 +507,7 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
public function removeDotDirectories(array $list)
{
$filter = function ($line) {
if (! empty($line) && !preg_match('#.* \.(\.)?$|^total#', $line)) {
if ( ! empty($line) && ! preg_match('#.* \.(\.)?$|^total#', $line)) {
return true;
}
@@ -548,7 +548,7 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
*/
public function ensureDirectory($dirname)
{
if (! empty($dirname) && !$this->has($dirname)) {
if ( ! empty($dirname) && ! $this->has($dirname)) {
$this->createDir($dirname, new Config());
}
}
@@ -558,7 +558,7 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
*/
public function getConnection()
{
if (! $this->isConnected()) {
if ( ! $this->isConnected()) {
$this->disconnect();
$this->connect();
}

View File

@@ -17,6 +17,11 @@ class Ftp extends AbstractFtpAdapter
*/
protected $transferMode = FTP_BINARY;
/**
* @var null|bool
*/
protected $ignorePassiveAddress = null;
/**
* @var array
*/
@@ -33,6 +38,7 @@ class Ftp extends AbstractFtpAdapter
'passive',
'transferMode',
'systemType',
'ignorePassiveAddress',
];
/**
@@ -73,6 +79,14 @@ class Ftp extends AbstractFtpAdapter
$this->passive = $passive;
}
/**
* @param bool $ignorePassiveAddress
*/
public function setIgnorePassiveAddress($ignorePassiveAddress)
{
$this->ignorePassiveAddress = $ignorePassiveAddress;
}
/**
* Connect to the FTP server.
*/
@@ -84,7 +98,7 @@ class Ftp extends AbstractFtpAdapter
$this->connection = ftp_connect($this->getHost(), $this->getPort(), $this->getTimeout());
}
if (! $this->connection) {
if ( ! $this->connection) {
throw new RuntimeException('Could not connect to host: ' . $this->getHost() . ', port:' . $this->getPort());
}
@@ -100,7 +114,11 @@ class Ftp extends AbstractFtpAdapter
*/
protected function setConnectionPassiveMode()
{
if (! ftp_pasv($this->connection, $this->passive)) {
if (is_bool($this->ignorePassiveAddress) && defined('FTP_USEPASVADDRESS')) {
ftp_set_option($this->connection, FTP_USEPASVADDRESS, ! $this->ignorePassiveAddress);
}
if ( ! ftp_pasv($this->connection, $this->passive)) {
throw new RuntimeException(
'Could not set passive mode for connection: ' . $this->getHost() . '::' . $this->getPort()
);
@@ -140,7 +158,7 @@ class Ftp extends AbstractFtpAdapter
$isLoggedIn = ftp_login($this->connection, $this->getUsername(), $this->getPassword());
restore_error_handler();
if (! $isLoggedIn) {
if ( ! $isLoggedIn) {
$this->disconnect();
throw new RuntimeException(
'Could not login with connection: ' . $this->getHost() . '::' . $this->getPort(
@@ -189,7 +207,7 @@ class Ftp extends AbstractFtpAdapter
{
$this->ensureDirectory(Util::dirname($path));
if (! ftp_fput($this->getConnection(), $path, $resource, $this->transferMode)) {
if ( ! ftp_fput($this->getConnection(), $path, $resource, $this->transferMode)) {
return false;
}
@@ -242,10 +260,10 @@ class Ftp extends AbstractFtpAdapter
foreach ($contents as $object) {
if ($object['type'] === 'file') {
if (! ftp_delete($connection, $object['path'])) {
if ( ! ftp_delete($connection, $object['path'])) {
return false;
}
} elseif (! ftp_rmdir($connection, $object['path'])) {
} elseif ( ! ftp_rmdir($connection, $object['path'])) {
return false;
}
}
@@ -319,12 +337,16 @@ class Ftp extends AbstractFtpAdapter
return ['type' => 'dir', 'path' => $path];
}
$listing = ftp_rawlist($connection, $path);
$listing = ftp_rawlist($connection, str_replace('*', '\\*', $path));
if (empty($listing)) {
return false;
}
if (preg_match('/.* not found/', $listing[0])) {
return false;
}
return $this->normalizeObject($listing[0], '');
}
@@ -333,7 +355,7 @@ class Ftp extends AbstractFtpAdapter
*/
public function getMimetype($path)
{
if (! $metadata = $this->read($path)) {
if ( ! $metadata = $this->read($path)) {
return false;
}
@@ -357,7 +379,7 @@ class Ftp extends AbstractFtpAdapter
*/
public function read($path)
{
if (! $object = $this->readStream($path)) {
if ( ! $object = $this->readStream($path)) {
return false;
}
@@ -377,7 +399,7 @@ class Ftp extends AbstractFtpAdapter
$result = ftp_fget($this->getConnection(), $stream, $path, $this->transferMode);
rewind($stream);
if (! $result) {
if ( ! $result) {
fclose($stream);
return false;
@@ -393,7 +415,7 @@ class Ftp extends AbstractFtpAdapter
{
$mode = $visibility === AdapterInterface::VISIBILITY_PUBLIC ? $this->getPermPublic() : $this->getPermPrivate();
if (! ftp_chmod($this->getConnection(), $mode, $path)) {
if ( ! ftp_chmod($this->getConnection(), $mode, $path)) {
return false;
}
@@ -407,7 +429,9 @@ class Ftp extends AbstractFtpAdapter
*/
protected function listDirectoryContents($directory, $recursive = true)
{
$listing = ftp_rawlist($this->getConnection(), '-lna ' . $directory, $recursive);
$directory = str_replace('*', '\\*', $directory);
$options = $recursive ? '-alnR' : '-aln';
$listing = ftp_rawlist($this->getConnection(), $options . ' ' . $directory);
return $listing ? $this->normalizeListing($listing, $directory) : [];
}
@@ -419,6 +443,6 @@ class Ftp extends AbstractFtpAdapter
*/
public function isConnected()
{
return ! is_null($this->connection) && ftp_systype($this->connection) !== false;
return is_resource($this->connection) && ftp_systype($this->connection) !== false;
}
}

View File

@@ -9,7 +9,7 @@ class Ftpd extends Ftp
*/
public function getMetadata($path)
{
if (empty($path) || !($object = ftp_raw($this->getConnection(), 'STAT '.$path)) || count($object) < 3) {
if (empty($path) || ! ($object = ftp_raw($this->getConnection(), 'STAT ' . $path)) || count($object) < 3) {
return false;
}
@@ -27,7 +27,7 @@ class Ftpd extends Ftp
{
$listing = ftp_rawlist($this->getConnection(), $directory, $recursive);
if ($listing === false || (!empty($listing) && substr($listing[0], 0, 5) === "ftpd:")) {
if ($listing === false || ( ! empty($listing) && substr($listing[0], 0, 5) === "ftpd:")) {
return [];
}

View File

@@ -4,10 +4,11 @@ namespace League\Flysystem\Adapter;
use DirectoryIterator;
use FilesystemIterator;
use Finfo;
use finfo as Finfo;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Config;
use League\Flysystem\NotSupportedException;
use League\Flysystem\UnreadableFileException;
use League\Flysystem\Util;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
@@ -72,8 +73,8 @@ class Local extends AbstractAdapter
$this->permissionMap = array_replace_recursive(static::$permissions, $permissions);
$realRoot = $this->ensureDirectory($root);
if (! is_dir($realRoot) || !is_readable($realRoot)) {
throw new \LogicException('The root path '.$root.' is not readable.');
if ( ! is_dir($realRoot) || ! is_readable($realRoot)) {
throw new \LogicException('The root path ' . $root . ' is not readable.');
}
$this->setPathPrefix($realRoot);
@@ -90,7 +91,7 @@ class Local extends AbstractAdapter
*/
protected function ensureDirectory($root)
{
if (! is_dir($root)) {
if ( ! is_dir($root)) {
$umask = umask(0);
mkdir($root, $this->permissionMap['dir']['public'], true);
umask($umask);
@@ -141,13 +142,13 @@ class Local extends AbstractAdapter
$this->ensureDirectory(dirname($location));
$stream = fopen($location, 'w+');
if (! $stream) {
if ( ! $stream) {
return false;
}
stream_copy_to_stream($resource, $stream);
if (! fclose($stream)) {
if ( ! fclose($stream)) {
return false;
}
@@ -249,9 +250,9 @@ class Local extends AbstractAdapter
public function listContents($directory = '', $recursive = false)
{
$result = [];
$location = $this->applyPathPrefix($directory).$this->pathSeparator;
$location = $this->applyPathPrefix($directory) . $this->pathSeparator;
if (! is_dir($location)) {
if ( ! is_dir($location)) {
return [];
}
@@ -328,7 +329,11 @@ class Local extends AbstractAdapter
{
$location = $this->applyPathPrefix($path);
$type = is_dir($location) ? 'dir' : 'file';
chmod($location, $this->permissionMap[$type][$visibility]);
$success = chmod($location, $this->permissionMap[$type][$visibility]);
if ($success === false) {
return false;
}
return compact('visibility');
}
@@ -342,7 +347,7 @@ class Local extends AbstractAdapter
$umask = umask(0);
$visibility = $config->get('visibility', 'public');
if (! is_dir($location) && !mkdir($location, $this->permissionMap['dir'][$visibility], true)) {
if ( ! is_dir($location) && ! mkdir($location, $this->permissionMap['dir'][$visibility], true)) {
$return = false;
} else {
$return = ['path' => $dirname, 'type' => 'dir'];
@@ -360,32 +365,38 @@ class Local extends AbstractAdapter
{
$location = $this->applyPathPrefix($dirname);
if (! is_dir($location)) {
if ( ! is_dir($location)) {
return false;
}
$contents = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($location, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::CHILD_FIRST
);
$contents = $this->getRecursiveDirectoryIterator($location, RecursiveIteratorIterator::CHILD_FIRST);
/** @var SplFileInfo $file */
foreach ($contents as $file) {
switch ($file->getType()) {
case 'dir':
rmdir($file->getRealPath());
break;
case 'link':
unlink($file->getPathname());
break;
default:
unlink($file->getRealPath());
}
$this->guardAgainstUnreadableFileInfo($file);
$this->deleteFileInfoObject($file);
}
return rmdir($location);
}
/**
* @param $file
*/
protected function deleteFileInfoObject($file)
{
switch ($file->getType()) {
case 'dir':
rmdir($file->getRealPath());
break;
case 'link':
unlink($file->getPathname());
break;
default:
unlink($file->getRealPath());
}
}
/**
* Normalize the file info.
*
@@ -395,7 +406,7 @@ class Local extends AbstractAdapter
*/
protected function normalizeFileInfo(SplFileInfo $file)
{
if (! $file->isLink()) {
if ( ! $file->isLink()) {
return $this->mapFileInfo($file);
}
@@ -421,15 +432,16 @@ class Local extends AbstractAdapter
/**
* @param string $path
* @param int $mode
*
* @return RecursiveIteratorIterator
*/
protected function getRecursiveDirectoryIterator($path)
protected function getRecursiveDirectoryIterator($path, $mode = RecursiveIteratorIterator::SELF_FIRST)
{
$directory = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
return $iterator;
return new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS),
$mode
);
}
/**
@@ -474,4 +486,16 @@ class Local extends AbstractAdapter
return str_replace('/', DIRECTORY_SEPARATOR, $prefixedPath);
}
/**
* @param SplFileInfo $file
*
* @throws UnreadableFileException
*/
protected function guardAgainstUnreadableFileInfo(SplFileInfo $file)
{
if ( ! $file->isReadable()) {
throw UnreadableFileException::forFileInfo($file);
}
}
}

View File

@@ -15,7 +15,7 @@ trait NotSupportingVisibilityTrait
*/
public function getVisibility($path)
{
throw new LogicException(get_class($this).' does not support visibility. Path: '.$path);
throw new LogicException(get_class($this) . ' does not support visibility. Path: ' . $path);
}
/**
@@ -28,6 +28,6 @@ trait NotSupportingVisibilityTrait
*/
public function setVisibility($path, $visibility)
{
throw new LogicException(get_class($this).' does not support visibility. Path: '.$path.', visibility: '.$visibility);
throw new LogicException(get_class($this) . ' does not support visibility. Path: ' . $path . ', visibility: ' . $visibility);
}
}

View File

@@ -18,7 +18,7 @@ trait StreamedCopyTrait
{
$response = $this->readStream($path);
if ($response === false || !is_resource($response['stream'])) {
if ($response === false || ! is_resource($response['stream'])) {
return false;
}

View File

@@ -13,7 +13,7 @@ trait StreamedReadingTrait
*/
public function readStream($path)
{
if (! $data = $this->read($path)) {
if ( ! $data = $this->read($path)) {
return false;
}

View File

@@ -34,7 +34,7 @@ class Config
*/
public function get($key, $default = null)
{
if (! array_key_exists($key, $this->settings)) {
if ( ! array_key_exists($key, $this->settings)) {
return $this->getDefault($key, $default);
}
@@ -63,7 +63,7 @@ class Config
*/
protected function getDefault($key, $default)
{
if (! $this->fallback) {
if ( ! $this->fallback) {
return $default;
}

View File

@@ -22,7 +22,7 @@ class FileExistsException extends Exception
{
$this->path = $path;
parent::__construct('File already exists at path: '.$this->getPath(), $code, $previous);
parent::__construct('File already exists at path: ' . $this->getPath(), $code, $previous);
}
/**

View File

@@ -22,7 +22,7 @@ class FileNotFoundException extends Exception
{
$this->path = $path;
parent::__construct('File not found at path: '.$this->getPath(), $code, $previous);
parent::__construct('File not found at path: ' . $this->getPath(), $code, $previous);
}
/**

View File

@@ -71,7 +71,7 @@ class Filesystem implements FilesystemInterface
*/
public function writeStream($path, $resource, array $config = [])
{
if (! is_resource($resource)) {
if ( ! is_resource($resource)) {
throw new InvalidArgumentException(__METHOD__ . ' expects argument #2 to be a valid resource.');
}
@@ -104,7 +104,7 @@ class Filesystem implements FilesystemInterface
*/
public function putStream($path, $resource, array $config = [])
{
if (! is_resource($resource)) {
if ( ! is_resource($resource)) {
throw new InvalidArgumentException(__METHOD__ . ' expects argument #2 to be a valid resource.');
}
@@ -155,7 +155,7 @@ class Filesystem implements FilesystemInterface
*/
public function updateStream($path, $resource, array $config = [])
{
if (! is_resource($resource)) {
if ( ! is_resource($resource)) {
throw new InvalidArgumentException(__METHOD__ . ' expects argument #2 to be a valid resource.');
}
@@ -175,7 +175,7 @@ class Filesystem implements FilesystemInterface
$path = Util::normalizePath($path);
$this->assertPresent($path);
if (! ($object = $this->getAdapter()->read($path))) {
if ( ! ($object = $this->getAdapter()->read($path))) {
return false;
}
@@ -190,7 +190,7 @@ class Filesystem implements FilesystemInterface
$path = Util::normalizePath($path);
$this->assertPresent($path);
if (! $object = $this->getAdapter()->readStream($path)) {
if ( ! $object = $this->getAdapter()->readStream($path)) {
return false;
}
@@ -278,7 +278,7 @@ class Filesystem implements FilesystemInterface
$path = Util::normalizePath($path);
$this->assertPresent($path);
if (! $object = $this->getAdapter()->getMimetype($path)) {
if ( ! $object = $this->getAdapter()->getMimetype($path)) {
return false;
}
@@ -293,7 +293,7 @@ class Filesystem implements FilesystemInterface
$path = Util::normalizePath($path);
$this->assertPresent($path);
if (! $object = $this->getAdapter()->getTimestamp($path)) {
if ( ! $object = $this->getAdapter()->getTimestamp($path)) {
return false;
}
@@ -322,7 +322,7 @@ class Filesystem implements FilesystemInterface
{
$path = Util::normalizePath($path);
if (($object = $this->getAdapter()->getSize($path)) === false || !isset($object['size'])) {
if (($object = $this->getAdapter()->getSize($path)) === false || ! isset($object['size'])) {
return false;
}
@@ -357,7 +357,7 @@ class Filesystem implements FilesystemInterface
{
$path = Util::normalizePath($path);
if (! $handler) {
if ( ! $handler) {
$metadata = $this->getMetadata($path);
$handler = $metadata['type'] === 'file' ? new File($this, $path) : new Directory($this, $path);
}
@@ -377,7 +377,7 @@ class Filesystem implements FilesystemInterface
*/
public function assertPresent($path)
{
if (! $this->has($path)) {
if ( ! $this->has($path)) {
throw new FileNotFoundException($path);
}
}

View File

@@ -126,8 +126,8 @@ abstract class Handler
} catch (BadMethodCallException $e) {
throw new BadMethodCallException(
'Call to undefined method '
.get_called_class()
.'::'.$method
. get_called_class()
. '::' . $method
);
}
}

View File

@@ -88,8 +88,8 @@ class MountManager
*/
public function mountFilesystem($prefix, FilesystemInterface $filesystem)
{
if (! is_string($prefix)) {
throw new InvalidArgumentException(__METHOD__.' expects argument #1 to be a string.');
if ( ! is_string($prefix)) {
throw new InvalidArgumentException(__METHOD__ . ' expects argument #1 to be a string.');
}
$this->filesystems[$prefix] = $filesystem;
@@ -108,8 +108,8 @@ class MountManager
*/
public function getFilesystem($prefix)
{
if (! isset($this->filesystems[$prefix])) {
throw new LogicException('No filesystem mounted with prefix '.$prefix);
if ( ! isset($this->filesystems[$prefix])) {
throw new LogicException('No filesystem mounted with prefix ' . $prefix);
}
return $this->filesystems[$prefix];
@@ -130,12 +130,12 @@ class MountManager
$path = array_shift($arguments);
if (! is_string($path)) {
if ( ! is_string($path)) {
throw new InvalidArgumentException('First argument should be a string');
}
if (! preg_match('#^.+\:\/\/.*#', $path)) {
throw new InvalidArgumentException('No prefix detected in path: '.$path);
if ( ! preg_match('#^.+\:\/\/.*#', $path)) {
throw new InvalidArgumentException('No prefix detected in path: ' . $path);
}
list($prefix, $path) = explode('://', $path, 2);

View File

@@ -18,7 +18,7 @@ class NotSupportedException extends RuntimeException
{
$message = 'Links are not supported, encountered link at ';
return new static($message.$file->getPathname());
return new static($message . $file->getPathname());
}
/**

View File

@@ -30,15 +30,15 @@ class GetWithMetadata extends AbstractPlugin
{
$object = $this->filesystem->getMetadata($path);
if (! $object) {
if ( ! $object) {
return false;
}
$keys = array_diff($metadata, array_keys($object));
foreach ($keys as $key) {
if (! method_exists($this->filesystem, $method = 'get'.ucfirst($key))) {
throw new InvalidArgumentException('Could not fetch metadata: '.$key);
if ( ! method_exists($this->filesystem, $method = 'get' . ucfirst($key))) {
throw new InvalidArgumentException('Could not fetch metadata: ' . $key);
}
$object[$key] = $this->filesystem->{$method}($path);

View File

@@ -47,10 +47,10 @@ class ListWith extends AbstractPlugin
*/
protected function getMetadataByName(array $object, $key)
{
$method = 'get'.ucfirst($key);
$method = 'get' . ucfirst($key);
if (! method_exists($this->filesystem, $method)) {
throw new \InvalidArgumentException('Could not get meta-data for key: '.$key);
if ( ! method_exists($this->filesystem, $method)) {
throw new \InvalidArgumentException('Could not get meta-data for key: ' . $key);
}
$object[$key] = $this->filesystem->{$method}($object['path']);

View File

@@ -39,12 +39,12 @@ trait PluggableTrait
*/
protected function findPlugin($method)
{
if (! isset($this->plugins[$method])) {
throw new PluginNotFoundException('Plugin not found for method: '.$method);
if ( ! isset($this->plugins[$method])) {
throw new PluginNotFoundException('Plugin not found for method: ' . $method);
}
if (! method_exists($this->plugins[$method], 'handle')) {
throw new LogicException(get_class($this->plugins[$method]).' does not have a handle method.');
if ( ! method_exists($this->plugins[$method], 'handle')) {
throw new LogicException(get_class($this->plugins[$method]) . ' does not have a handle method.');
}
return $this->plugins[$method];
@@ -84,8 +84,8 @@ trait PluggableTrait
} catch (PluginNotFoundException $e) {
throw new BadMethodCallException(
'Call to undefined method '
.get_class($this)
.'::'.$method
. get_class($this)
. '::' . $method
);
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace League\Flysystem;
use SplFileInfo;
class UnreadableFileException extends Exception
{
public static function forFileInfo(SplFileInfo $fileInfo)
{
return new static(
sprintf(
'Unreadable file encountered: %s',
$fileInfo->getRealPath()
)
);
}
}

View File

@@ -17,9 +17,7 @@ class Util
public static function pathinfo($path)
{
$pathinfo = pathinfo($path) + compact('path');
$pathinfo['dirname'] = array_key_exists('dirname', $pathinfo)
? static::normalizeDirname($pathinfo['dirname'])
: '';
$pathinfo['dirname'] = static::normalizeDirname($pathinfo['dirname']);
return $pathinfo;
}
@@ -65,7 +63,7 @@ class Util
$result = [];
foreach ($map as $from => $to) {
if (! isset($object[$from])) {
if ( ! isset($object[$from])) {
continue;
}
@@ -161,7 +159,7 @@ class Util
{
$mimeType = MimeType::detectByContent($content);
if (empty($mimeType) || $mimeType === 'text/plain') {
if (empty($mimeType) || in_array($mimeType, ['text/plain', 'application/x-empty'])) {
$extension = pathinfo($path, PATHINFO_EXTENSION);
if ($extension) {
@@ -281,7 +279,7 @@ class Util
$parent = $object['dirname'];
while (! empty($parent) && ! in_array($parent, $directories)) {
while ( ! empty($parent) && ! in_array($parent, $directories)) {
$directories[] = $parent;
$parent = static::dirname($parent);
}

View File

@@ -18,7 +18,7 @@ class MimeType
*/
public static function detectByContent($content)
{
if (! class_exists('Finfo')) {
if ( ! class_exists('Finfo')) {
return;
}
@@ -39,7 +39,7 @@ class MimeType
{
static $extensionToMimeTypeMap;
if (! $extensionToMimeTypeMap) {
if ( ! $extensionToMimeTypeMap) {
$extensionToMimeTypeMap = static::getExtensionToMimeTypeMap();
}