update v 1.0.7.5

This commit is contained in:
Sujit Prasad
2016-06-13 20:41:55 +05:30
parent aa9786d829
commit 283d97e3ea
5078 changed files with 339851 additions and 175995 deletions

View File

@@ -6,6 +6,7 @@ use DateTime;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Config;
use League\Flysystem\NotSupportedException;
use RuntimeException;
abstract class AbstractFtpAdapter extends AbstractAdapter
{
@@ -79,6 +80,11 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
*/
protected $systemType;
/**
* @var bool
*/
protected $alternativeRecursion = false;
/**
* Constructor.
*
@@ -317,6 +323,8 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
return $this->listDirectoryContents($directory, $recursive);
}
abstract protected function listDirectoryContents($directory, $recursive = false);
/**
* Normalize a directory listing.
*
@@ -395,6 +403,11 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
protected function normalizeUnixObject($item, $base)
{
$item = preg_replace('#\s+#', ' ', trim($item), 7);
if (count(explode(' ', $item, 9)) !== 9) {
throw new RuntimeException("Metadata can't be parsed from item '$item' , not enough parts.");
}
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;
@@ -421,6 +434,11 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
protected function normalizeWindowsObject($item, $base)
{
$item = preg_replace('#\s+#', ' ', trim($item), 3);
if (count(explode(' ', $item, 4)) !== 4) {
throw new RuntimeException("Metadata can't be parsed from item '$item' , not enough parts.");
}
list($date, $time, $size, $name) = explode(' ', $item, 4);
$path = empty($base) ? $name : $base . $this->separator . $name;

View File

@@ -2,6 +2,7 @@
namespace League\Flysystem\Adapter;
use ErrorException;
use League\Flysystem\Adapter\Polyfill\StreamedCopyTrait;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Config;
@@ -22,6 +23,11 @@ class Ftp extends AbstractFtpAdapter
*/
protected $ignorePassiveAddress = null;
/**
* @var bool
*/
protected $recurseManually = false;
/**
* @var array
*/
@@ -39,6 +45,7 @@ class Ftp extends AbstractFtpAdapter
'transferMode',
'systemType',
'ignorePassiveAddress',
'recurseManually',
];
/**
@@ -87,6 +94,14 @@ class Ftp extends AbstractFtpAdapter
$this->ignorePassiveAddress = $ignorePassiveAddress;
}
/**
* @param bool $recurseManually
*/
public function setRecurseManually($recurseManually)
{
$this->recurseManually = $recurseManually;
}
/**
* Connect to the FTP server.
*/
@@ -306,7 +321,7 @@ class Ftp extends AbstractFtpAdapter
{
// List the current directory
$listing = ftp_nlist($connection, '.') ?: [];
foreach ($listing as $key => $item) {
if (preg_match('~^\./.*~', $item)) {
$listing[$key] = substr($item, 2);
@@ -347,6 +362,10 @@ class Ftp extends AbstractFtpAdapter
return false;
}
if (preg_match('/^total [0-9]*$/', $listing[0])) {
array_shift($listing);
}
return $this->normalizeObject($listing[0], '');
}
@@ -430,19 +449,56 @@ class Ftp extends AbstractFtpAdapter
protected function listDirectoryContents($directory, $recursive = true)
{
$directory = str_replace('*', '\\*', $directory);
if ($recursive && $this->recurseManually) {
return $this->listDirectoryContentsRecursive($directory);
}
$options = $recursive ? '-alnR' : '-aln';
$listing = ftp_rawlist($this->getConnection(), $options . ' ' . $directory);
return $listing ? $this->normalizeListing($listing, $directory) : [];
}
/**
* @inheritdoc
*
* @param string $directory
*/
protected function listDirectoryContentsRecursive($directory)
{
$listing = $this->normalizeListing(ftp_rawlist($this->getConnection(), '-aln' . ' ' . $directory) ?: []);
$output = [];
foreach ($listing as $directory) {
$output[] = $directory;
if ($directory['type'] !== 'dir') continue;
$output = array_merge($output, $this->listDirectoryContentsRecursive($directory['path']));
}
return $output;
}
/**
* Check if the connection is open.
*
* @return bool
* @throws ErrorException
*/
public function isConnected()
{
return is_resource($this->connection) && ftp_systype($this->connection) !== false;
try {
return is_resource($this->connection) && ftp_rawlist($this->connection, '/') !== false;
} catch (ErrorException $e) {
fclose($this->connection);
$this->connection = null;
if (strpos($e->getMessage(), 'ftp_rawlist') === false) {
throw $e;
}
return false;
}
}
}

View File

@@ -7,9 +7,11 @@ use FilesystemIterator;
use finfo as Finfo;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Config;
use League\Flysystem\Exception;
use League\Flysystem\NotSupportedException;
use League\Flysystem\UnreadableFileException;
use League\Flysystem\Util;
use LogicException;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use SplFileInfo;
@@ -31,8 +33,8 @@ class Local extends AbstractAdapter
*/
protected static $permissions = [
'file' => [
'public' => 0744,
'private' => 0700,
'public' => 0644,
'private' => 0600,
],
'dir' => [
'public' => 0755,
@@ -69,12 +71,11 @@ class Local extends AbstractAdapter
*/
public function __construct($root, $writeFlags = LOCK_EX, $linkHandling = self::DISALLOW_LINKS, array $permissions = [])
{
// permissionMap needs to be set before ensureDirectory() is called.
$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.');
throw new LogicException('The root path ' . $root . ' is not readable.');
}
$this->setPathPrefix($realRoot);
@@ -88,6 +89,8 @@ class Local extends AbstractAdapter
* @param string $root root directory path
*
* @return string real path to root
*
* @throws Exception in case the root directory can not be created
*/
protected function ensureDirectory($root)
{
@@ -95,6 +98,10 @@ class Local extends AbstractAdapter
$umask = umask(0);
mkdir($root, $this->permissionMap['dir']['public'], true);
umask($umask);
if ( ! is_dir($root)) {
throw new Exception(sprintf('Impossible to create the root directory "%s".', $root));
}
}
return realpath($root);
@@ -381,9 +388,9 @@ class Local extends AbstractAdapter
}
/**
* @param $file
* @param SplFileInfo $file
*/
protected function deleteFileInfoObject($file)
protected function deleteFileInfoObject(SplFileInfo $file)
{
switch ($file->getType()) {
case 'dir':

View File

@@ -51,7 +51,7 @@ class Filesystem implements FilesystemInterface
{
$path = Util::normalizePath($path);
return (bool) $this->getAdapter()->has($path);
return strlen($path) === 0 ? false : (bool) $this->getAdapter()->has($path);
}
/**

View File

@@ -182,10 +182,11 @@ class MountManager
/**
* @param $from
* @param $to
* @param array $config
*
* @return bool
*/
public function copy($from, $to)
public function copy($from, $to, array $config = [])
{
list($prefixFrom, $arguments) = $this->filterPrefix([$from]);
@@ -199,7 +200,7 @@ class MountManager
list($prefixTo, $arguments) = $this->filterPrefix([$to]);
$fsTo = $this->getFilesystem($prefixTo);
$result = call_user_func_array([$fsTo, 'writeStream'], array_merge($arguments, [$buffer]));
$result = call_user_func_array([$fsTo, 'writeStream'], array_merge($arguments, [$buffer, $config]));
if (is_resource($buffer)) {
fclose($buffer);
@@ -229,12 +230,13 @@ class MountManager
*
* @param $from
* @param $to
* @param array $config
*
* @return bool
*/
public function move($from, $to)
public function move($from, $to, array $config = [])
{
$copied = $this->copy($from, $to);
$copied = $this->copy($from, $to, $config);
if ($copied) {
return $this->delete($from);

View File

@@ -17,7 +17,8 @@ class Util
public static function pathinfo($path)
{
$pathinfo = pathinfo($path) + compact('path');
$pathinfo['dirname'] = static::normalizeDirname($pathinfo['dirname']);
$pathinfo['dirname'] = array_key_exists('dirname', $pathinfo)
? static::normalizeDirname($pathinfo['dirname']) : '';
return $pathinfo;
}
@@ -106,7 +107,7 @@ class Util
public static function normalizeRelativePath($path)
{
// Path remove self referring paths ("/./").
$path = preg_replace('#/\.(?=/)|^\./|/\./?$#', '', $path);
$path = preg_replace('#/\.(?=/)|^\./|(/|^)\./?$#', '', $path);
// Regex for resolving relative paths
$regex = '#/*[^/\.]+/\.\.#Uu';
@@ -147,7 +148,7 @@ class Util
* Guess MIME Type based on the path of the file and it's content.
*
* @param string $path
* @param string $content
* @param string|resource $content
*
* @return string|null MIME Type or NULL if no extension detected
*/
@@ -155,15 +156,11 @@ class Util
{
$mimeType = MimeType::detectByContent($content);
if (empty($mimeType) || in_array($mimeType, ['application/x-empty', 'text/plain', 'text/x-asm'])) {
$extension = pathinfo($path, PATHINFO_EXTENSION);
if ($extension) {
$mimeType = MimeType::detectByFileExtension($extension) ?: 'text/plain';
}
if ( ! (empty($mimeType) || in_array($mimeType, ['application/x-empty', 'text/plain', 'text/x-asm']))) {
return $mimeType;
}
return $mimeType;
return MimeType::detectByFilename($path);
}
/**

View File

@@ -12,17 +12,20 @@ class MimeType
/**
* Detects MIME Type based on given content.
*
* @param string $content
* @param mixed $content
*
* @return string|null MIME Type or NULL if no mime type detected
*/
public static function detectByContent($content)
{
if ( ! class_exists('Finfo')) {
if ( ! class_exists('Finfo') || ! is_string($content)) {
return;
}
return (new Finfo(FILEINFO_MIME_TYPE))->buffer($content) ?: null;
$finfo = new Finfo(FILEINFO_MIME_TYPE);
$mimeType = $finfo->buffer($content);
return $mimeType ?: null;
}
/**
@@ -36,13 +39,27 @@ class MimeType
{
static $extensionToMimeTypeMap;
if ( ! $extensionToMimeTypeMap) {
if (! $extensionToMimeTypeMap) {
$extensionToMimeTypeMap = static::getExtensionToMimeTypeMap();
}
if (isset($extensionToMimeTypeMap[$extension])) {
return $extensionToMimeTypeMap[$extension];
}
return 'text/plain';
}
/**
* @param string $filename
*
* @return string
*/
public static function detectByFilename($filename)
{
$extension = pathinfo($filename, PATHINFO_EXTENSION);
return empty($extension) ? 'text/plain' : static::detectByFileExtension($extension);
}
/**