This commit is contained in:
Manish Verma
2016-12-13 18:18:25 +05:30
parent fc98add11c
commit 2d8e640e9b
2314 changed files with 97798 additions and 75664 deletions

View File

@@ -6,7 +6,6 @@ use DateTime;
use League\Flysystem\AdapterInterface;
use League\Flysystem\Config;
use League\Flysystem\NotSupportedException;
use League\Flysystem\SafeStorage;
use RuntimeException;
abstract class AbstractFtpAdapter extends AbstractAdapter
@@ -26,6 +25,16 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
*/
protected $port = 21;
/**
* @var string|null
*/
protected $username;
/**
* @var string|null
*/
protected $password;
/**
* @var bool
*/
@@ -76,11 +85,6 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
*/
protected $alternativeRecursion = false;
/**
* @var SafeStorage
*/
protected $safeStorage;
/**
* Constructor.
*
@@ -88,7 +92,6 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
*/
public function __construct(array $config)
{
$this->safeStorage = new SafeStorage();
$this->setConfig($config);
}
@@ -223,7 +226,7 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
*/
public function getUsername()
{
return $this->safeStorage->retrieveSafely('username') ?: 'anonymous';
return empty($this->username) ? 'anonymous' : $this->username;
}
/**
@@ -235,7 +238,7 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
*/
public function setUsername($username)
{
$this->safeStorage->storeSafely('username', $username);
$this->username = $username;
return $this;
}
@@ -247,7 +250,7 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
*/
public function getPassword()
{
return $this->safeStorage->retrieveSafely('password');
return $this->password;
}
/**
@@ -259,7 +262,7 @@ abstract class AbstractFtpAdapter extends AbstractAdapter
*/
public function setPassword($password)
{
$this->safeStorage->storeSafely('password', $password);
$this->password = $password;
return $this;
}

View File

@@ -73,13 +73,13 @@ class Local extends AbstractAdapter
{
$root = is_link($root) ? realpath($root) : $root;
$this->permissionMap = array_replace_recursive(static::$permissions, $permissions);
$this->ensureDirectory($root);
$realRoot = $this->ensureDirectory($root);
if ( ! is_dir($root) || ! is_readable($root)) {
if ( ! is_dir($realRoot) || ! is_readable($realRoot)) {
throw new LogicException('The root path ' . $root . ' is not readable.');
}
$this->setPathPrefix($root);
$this->setPathPrefix($realRoot);
$this->writeFlags = $writeFlags;
$this->linkHandling = $linkHandling;
}
@@ -89,7 +89,7 @@ class Local extends AbstractAdapter
*
* @param string $root root directory path
*
* @return void
* @return string real path to root
*
* @throws Exception in case the root directory can not be created
*/
@@ -104,6 +104,8 @@ class Local extends AbstractAdapter
throw new Exception(sprintf('Impossible to create the root directory "%s".', $root));
}
}
return realpath($root);
}
/**
@@ -256,7 +258,7 @@ class Local extends AbstractAdapter
public function listContents($directory = '', $recursive = false)
{
$result = [];
$location = $this->applyPathPrefix($directory);
$location = $this->applyPathPrefix($directory) . $this->pathSeparator;
if ( ! is_dir($location)) {
return [];

View File

@@ -1,39 +0,0 @@
<?php
namespace League\Flysystem;
final class SafeStorage
{
/**
* @var string
*/
private $hash;
/**
* @var array
*/
protected static $safeStorage = [];
public function __construct()
{
$this->hash = spl_object_hash($this);
static::$safeStorage[$this->hash] = [];
}
public function storeSafely($key, $value)
{
static::$safeStorage[$this->hash][$key] = $value;
}
public function retrieveSafely($key)
{
if (array_key_exists($key, static::$safeStorage[$this->hash])) {
return static::$safeStorage[$this->hash][$key];
}
}
public function __destruct()
{
unset(static::$safeStorage[$this->hash]);
}
}

View File

@@ -85,7 +85,7 @@ class Util
$normalized = preg_replace('#\p{C}+|^\./#u', '', $path);
$normalized = static::normalizeRelativePath($normalized);
if (preg_match('#(^|/)\.{2}(/|$)#', $normalized)) {
if (preg_match('#/\.{2}|^\.{2}/|^\.{2}$#', $normalized)) {
throw new LogicException(
'Path is outside of the defined root, path: [' . $path . '], resolved: [' . $normalized . ']'
);
@@ -110,7 +110,7 @@ class Util
$path = preg_replace('#/\.(?=/)|^\./|(/|^)\./?$#', '', $path);
// Regex for resolving relative paths
$regex = '#/*[^/\.]+/\.\.(?=/|$)#Uu';
$regex = '#/*[^/\.]+/\.\.#Uu';
while (preg_match($regex, $path)) {
$path = preg_replace($regex, '', $path);