update v1.0.4
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
50
vendor/league/flysystem/src/Adapter/Ftp.php
vendored
50
vendor/league/flysystem/src/Adapter/Ftp.php
vendored
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
4
vendor/league/flysystem/src/Adapter/Ftpd.php
vendored
4
vendor/league/flysystem/src/Adapter/Ftpd.php
vendored
@@ -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 [];
|
||||
}
|
||||
|
||||
|
||||
86
vendor/league/flysystem/src/Adapter/Local.php
vendored
86
vendor/league/flysystem/src/Adapter/Local.php
vendored
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ trait StreamedReadingTrait
|
||||
*/
|
||||
public function readStream($path)
|
||||
{
|
||||
if (! $data = $this->read($path)) {
|
||||
if ( ! $data = $this->read($path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user