My first commit of codes
This commit is contained in:
86
vendor/league/flysystem/src/Adapter/AbstractAdapter.php
vendored
Normal file
86
vendor/league/flysystem/src/Adapter/AbstractAdapter.php
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace League\Flysystem\Adapter;
|
||||
|
||||
use League\Flysystem\AdapterInterface;
|
||||
|
||||
abstract class AbstractAdapter implements AdapterInterface
|
||||
{
|
||||
/**
|
||||
* @var string path prefix
|
||||
*/
|
||||
protected $pathPrefix;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $pathSeparator = '/';
|
||||
|
||||
/**
|
||||
* Set the path prefix.
|
||||
*
|
||||
* @param string $prefix
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function setPathPrefix($prefix)
|
||||
{
|
||||
$is_empty = empty($prefix);
|
||||
|
||||
if (! $is_empty) {
|
||||
$prefix = rtrim($prefix, $this->pathSeparator).$this->pathSeparator;
|
||||
}
|
||||
|
||||
$this->pathPrefix = $is_empty ? null : $prefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the path prefix.
|
||||
*
|
||||
* @return string path prefix
|
||||
*/
|
||||
public function getPathPrefix()
|
||||
{
|
||||
return $this->pathPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prefix a path.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return string prefixed path
|
||||
*/
|
||||
public function applyPathPrefix($path)
|
||||
{
|
||||
$path = ltrim($path, '\\/');
|
||||
|
||||
if (strlen($path) === 0) {
|
||||
return $this->getPathPrefix() ?: '';
|
||||
}
|
||||
|
||||
if ($prefix = $this->getPathPrefix()) {
|
||||
$path = $prefix.$path;
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a path prefix.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return string path without the prefix
|
||||
*/
|
||||
public function removePathPrefix($path)
|
||||
{
|
||||
$pathPrefix = $this->getPathPrefix();
|
||||
|
||||
if ($pathPrefix === null) {
|
||||
return $path;
|
||||
}
|
||||
|
||||
return substr($path, strlen($pathPrefix));
|
||||
}
|
||||
}
|
||||
459
vendor/league/flysystem/src/Adapter/AbstractFtpAdapter.php
vendored
Normal file
459
vendor/league/flysystem/src/Adapter/AbstractFtpAdapter.php
vendored
Normal file
@@ -0,0 +1,459 @@
|
||||
<?php
|
||||
|
||||
namespace League\Flysystem\Adapter;
|
||||
|
||||
use League\Flysystem\AdapterInterface;
|
||||
use League\Flysystem\Config;
|
||||
use Net_SFTP;
|
||||
|
||||
abstract class AbstractFtpAdapter extends AbstractAdapter
|
||||
{
|
||||
protected $connection;
|
||||
protected $host;
|
||||
protected $port = 21;
|
||||
protected $username;
|
||||
protected $password;
|
||||
protected $ssl = false;
|
||||
protected $timeout = 90;
|
||||
protected $passive = true;
|
||||
protected $separator = '/';
|
||||
protected $root;
|
||||
protected $permPublic = 0744;
|
||||
protected $permPrivate = 0700;
|
||||
protected $configurable = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param array $config
|
||||
*/
|
||||
public function __construct(array $config)
|
||||
{
|
||||
$this->setConfig($config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the config.
|
||||
*
|
||||
* @param array $config
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setConfig(array $config)
|
||||
{
|
||||
foreach ($this->configurable as $setting) {
|
||||
if (! isset($config[$setting])) {
|
||||
continue;
|
||||
}
|
||||
$this->{'set'.ucfirst($setting)}($config[$setting]);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the host.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getHost()
|
||||
{
|
||||
return $this->host;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the host.
|
||||
*
|
||||
* @param string $host
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setHost($host)
|
||||
{
|
||||
$this->host = $host;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the public permission value.
|
||||
*
|
||||
* @param int $permPublic
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPermPublic($permPublic)
|
||||
{
|
||||
$this->permPublic = $permPublic;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the private permission value.
|
||||
*
|
||||
* @param int $permPrivate
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPermPrivate($permPrivate)
|
||||
{
|
||||
$this->permPrivate = $permPrivate;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ftp port.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPort()
|
||||
{
|
||||
return $this->port;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the root folder to work from.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRoot()
|
||||
{
|
||||
return $this->root;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ftp port.
|
||||
*
|
||||
* @param int|string $port
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPort($port)
|
||||
{
|
||||
$this->port = (int) $port;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the root folder to work from.
|
||||
*
|
||||
* @param string $root
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setRoot($root)
|
||||
{
|
||||
$this->root = rtrim($root, '\\/').$this->separator;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the ftp username.
|
||||
*
|
||||
* @return string username
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return empty($this->username) ? 'anonymous' : $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ftp username.
|
||||
*
|
||||
* @param string $username
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->username = $username;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the password.
|
||||
*
|
||||
* @return string password
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the ftp password.
|
||||
*
|
||||
* @param string $password
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the amount of seconds before the connection will timeout.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getTimeout()
|
||||
{
|
||||
return $this->timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the amount of seconds before the connection should timeout.
|
||||
*
|
||||
* @param int $timeout
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTimeout($timeout)
|
||||
{
|
||||
$this->timeout = (int) $timeout;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function listContents($directory = '', $recursive = false)
|
||||
{
|
||||
return $this->listDirectoryContents($directory, $recursive);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a directory listing.
|
||||
*
|
||||
* @param array $listing
|
||||
* @param string $prefix
|
||||
*
|
||||
* @return array directory listing
|
||||
*/
|
||||
protected function normalizeListing(array $listing, $prefix = '')
|
||||
{
|
||||
$base = $prefix;
|
||||
$result = [];
|
||||
$listing = $this->removeDotDirectories($listing);
|
||||
|
||||
while ($item = array_shift($listing)) {
|
||||
if (preg_match('#^.*:$#', $item)) {
|
||||
$base = trim($item, ':');
|
||||
continue;
|
||||
}
|
||||
|
||||
$result[] = $this->normalizeObject($item, $base);
|
||||
}
|
||||
|
||||
return $this->sortListing($result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort a directory listing.
|
||||
*
|
||||
* @param array $result
|
||||
*
|
||||
* @return array sorted listing
|
||||
*/
|
||||
protected function sortListing(array $result)
|
||||
{
|
||||
$compare = function ($one, $two) {
|
||||
return strnatcmp($one['path'], $two['path']);
|
||||
};
|
||||
|
||||
usort($result, $compare);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a file entry.
|
||||
*
|
||||
* @param string $item
|
||||
* @param string $base
|
||||
*
|
||||
* @return array normalized file array
|
||||
*/
|
||||
protected function normalizeObject($item, $base)
|
||||
{
|
||||
$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;
|
||||
|
||||
if ($type === 'dir') {
|
||||
return compact('type', 'path');
|
||||
}
|
||||
|
||||
$permissions = $this->normalizePermissions($permissions);
|
||||
$visibility = $permissions & 0044 ? AdapterInterface::VISIBILITY_PUBLIC : AdapterInterface::VISIBILITY_PRIVATE;
|
||||
$size = (int) $size;
|
||||
|
||||
return compact('type', 'path', 'visibility', 'size');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the file type from the permissions.
|
||||
*
|
||||
* @param string $permissions
|
||||
*
|
||||
* @return string file type
|
||||
*/
|
||||
protected function detectType($permissions)
|
||||
{
|
||||
return substr($permissions, 0, 1) === 'd' ? 'dir' : 'file';
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize a permissions string.
|
||||
*
|
||||
* @param string $permissions
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
protected function normalizePermissions($permissions)
|
||||
{
|
||||
// remove the type identifier
|
||||
$permissions = substr($permissions, 1);
|
||||
|
||||
// map the string rights to the numeric counterparts
|
||||
$map = ['-' => '0', 'r' => '4', 'w' => '2', 'x' => '1'];
|
||||
$permissions = strtr($permissions, $map);
|
||||
|
||||
// split up the permission groups
|
||||
$parts = str_split($permissions, 3);
|
||||
|
||||
// convert the groups
|
||||
$mapper = function ($part) {
|
||||
return array_sum(str_split($part));
|
||||
};
|
||||
|
||||
// get the sum of the groups
|
||||
return array_sum(array_map($mapper, $parts));
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter out dot-directories.
|
||||
*
|
||||
* @param array $list
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function removeDotDirectories(array $list)
|
||||
{
|
||||
$filter = function ($line) {
|
||||
if (! empty($line) && ! preg_match('#.* \.(\.)?$|^total#', $line)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
return array_filter($list, $filter);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has($path)
|
||||
{
|
||||
return $this->getMetadata($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSize($path)
|
||||
{
|
||||
return $this->getMetadata($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTimestamp($path)
|
||||
{
|
||||
$timestamp = ftp_mdtm($this->getConnection(), $path);
|
||||
|
||||
return ($timestamp !== -1) ? ['timestamp' => $timestamp] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getVisibility($path)
|
||||
{
|
||||
return $this->getMetadata($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure a directory exists.
|
||||
*
|
||||
* @param string $dirname
|
||||
*/
|
||||
public function ensureDirectory($dirname)
|
||||
{
|
||||
if (! empty($dirname) && ! $this->has($dirname)) {
|
||||
$this->createDir($dirname, new Config());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return resource|Net_SFTP
|
||||
*/
|
||||
public function getConnection()
|
||||
{
|
||||
if (! $this->connection) {
|
||||
$this->connect();
|
||||
}
|
||||
|
||||
return $this->connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the public permission value.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPermPublic()
|
||||
{
|
||||
return $this->permPublic;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the private permission value.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getPermPrivate()
|
||||
{
|
||||
return $this->permPrivate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect on destruction.
|
||||
*/
|
||||
public function __destruct()
|
||||
{
|
||||
$this->disconnect();
|
||||
}
|
||||
|
||||
/**
|
||||
* Establish a connection.
|
||||
*/
|
||||
abstract public function connect();
|
||||
|
||||
/**
|
||||
* Close the connection.
|
||||
*/
|
||||
abstract public function disconnect();
|
||||
}
|
||||
396
vendor/league/flysystem/src/Adapter/Ftp.php
vendored
Normal file
396
vendor/league/flysystem/src/Adapter/Ftp.php
vendored
Normal file
@@ -0,0 +1,396 @@
|
||||
<?php
|
||||
|
||||
namespace League\Flysystem\Adapter;
|
||||
|
||||
use League\Flysystem\Adapter\Polyfill\StreamedCopyTrait;
|
||||
use League\Flysystem\AdapterInterface;
|
||||
use League\Flysystem\Config;
|
||||
use League\Flysystem\Util;
|
||||
use RuntimeException;
|
||||
|
||||
class Ftp extends AbstractFtpAdapter
|
||||
{
|
||||
use StreamedCopyTrait;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $transferMode = FTP_BINARY;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
protected $configurable = [
|
||||
'host', 'port', 'username',
|
||||
'password', 'ssl', 'timeout',
|
||||
'root', 'permPrivate',
|
||||
'permPublic', 'passive',
|
||||
'transferMode',
|
||||
];
|
||||
|
||||
/**
|
||||
* Set the transfer mode.
|
||||
*
|
||||
* @param int $mode
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setTransferMode($mode)
|
||||
{
|
||||
$this->transferMode = $mode;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if Ssl is enabled.
|
||||
*
|
||||
* @param bool $ssl
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function setSsl($ssl)
|
||||
{
|
||||
$this->ssl = (bool) $ssl;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set if passive mode should be used.
|
||||
*
|
||||
* @param bool $passive
|
||||
*/
|
||||
public function setPassive($passive = true)
|
||||
{
|
||||
$this->passive = $passive;
|
||||
}
|
||||
|
||||
/**
|
||||
* Connect to the FTP server.
|
||||
*/
|
||||
public function connect()
|
||||
{
|
||||
if ($this->ssl) {
|
||||
$this->connection = ftp_ssl_connect($this->getHost(), $this->getPort(), $this->getTimeout());
|
||||
} else {
|
||||
$this->connection = ftp_connect($this->getHost(), $this->getPort(), $this->getTimeout());
|
||||
}
|
||||
|
||||
if (! $this->connection) {
|
||||
throw new RuntimeException('Could not connect to host: '.$this->getHost().', port:'.$this->getPort());
|
||||
}
|
||||
|
||||
$this->login();
|
||||
$this->setConnectionPassiveMode();
|
||||
$this->setConnectionRoot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the connections to passive mode.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function setConnectionPassiveMode()
|
||||
{
|
||||
if (! ftp_pasv($this->getConnection(), $this->passive)) {
|
||||
throw new RuntimeException('Could not set passive mode for connection: '.$this->getHost().'::'.$this->getPort());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the connection root.
|
||||
*/
|
||||
protected function setConnectionRoot()
|
||||
{
|
||||
$root = $this->getRoot();
|
||||
$connection = $this->getConnection();
|
||||
|
||||
if ($root && ! ftp_chdir($connection, $root)) {
|
||||
throw new RuntimeException('Root is invalid or does not exist: '.$this->getRoot());
|
||||
}
|
||||
|
||||
// Store absolute path for further reference.
|
||||
// This is needed when creating directories and
|
||||
// initial root was a relative path, else the root
|
||||
// would be relative to the chdir'd path.
|
||||
$this->root = ftp_pwd($connection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Login.
|
||||
*
|
||||
* @throws RuntimeException
|
||||
*/
|
||||
protected function login()
|
||||
{
|
||||
set_error_handler(function () {});
|
||||
$isLoggedIn = ftp_login($this->getConnection(), $this->getUsername(), $this->getPassword());
|
||||
restore_error_handler();
|
||||
|
||||
if (! $isLoggedIn) {
|
||||
$this->disconnect();
|
||||
throw new RuntimeException('Could not login with connection: '.$this->getHost().'::'.$this->getPort().', username: '.$this->getUsername());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Disconnect from the FTP server.
|
||||
*/
|
||||
public function disconnect()
|
||||
{
|
||||
if ($this->connection) {
|
||||
ftp_close($this->connection);
|
||||
}
|
||||
|
||||
$this->connection = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($path, $contents, Config $config)
|
||||
{
|
||||
$mimetype = Util::guessMimeType($path, $contents);
|
||||
$config = Util::ensureConfig($config);
|
||||
$stream = tmpfile();
|
||||
fwrite($stream, $contents);
|
||||
rewind($stream);
|
||||
$result = $this->writeStream($path, $stream, $config);
|
||||
$result = fclose($stream) && $result;
|
||||
|
||||
if ($result === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($visibility = $config->get('visibility')) {
|
||||
$this->setVisibility($path, $visibility);
|
||||
}
|
||||
|
||||
return compact('path', 'contents', 'mimetype', 'visibility');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function writeStream($path, $resource, Config $config)
|
||||
{
|
||||
$this->ensureDirectory(Util::dirname($path));
|
||||
$config = Util::ensureConfig($config);
|
||||
|
||||
if (! ftp_fput($this->getConnection(), $path, $resource, $this->transferMode)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($visibility = $config->get('visibility')) {
|
||||
$this->setVisibility($path, $visibility);
|
||||
}
|
||||
|
||||
return compact('path', 'visibility');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function update($path, $contents, Config $config)
|
||||
{
|
||||
return $this->write($path, $contents, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updateStream($path, $resource, Config $config)
|
||||
{
|
||||
return $this->writeStream($path, $resource, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rename($path, $newpath)
|
||||
{
|
||||
return ftp_rename($this->getConnection(), $path, $newpath);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($path)
|
||||
{
|
||||
return ftp_delete($this->getConnection(), $path);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteDir($dirname)
|
||||
{
|
||||
$connection = $this->getConnection();
|
||||
$contents = array_reverse($this->listDirectoryContents($dirname));
|
||||
|
||||
foreach ($contents as $object) {
|
||||
if ($object['type'] === 'file') {
|
||||
if (! ftp_delete($connection, $object['path'])) {
|
||||
return false;
|
||||
}
|
||||
} elseif (! ftp_rmdir($connection, $object['path'])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return ftp_rmdir($connection, $dirname);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createDir($dirname, Config $config)
|
||||
{
|
||||
$result = false;
|
||||
$connection = $this->getConnection();
|
||||
$directories = explode('/', $dirname);
|
||||
|
||||
foreach ($directories as $directory) {
|
||||
$result = $this->createActualDirectory($directory, $connection);
|
||||
|
||||
if (! $result) {
|
||||
break;
|
||||
}
|
||||
|
||||
ftp_chdir($connection, $directory);
|
||||
}
|
||||
|
||||
$this->setConnectionRoot();
|
||||
|
||||
if (! $result) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ['path' => $dirname];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a directory.
|
||||
*
|
||||
* @param string $directory
|
||||
* @param resource $connection
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function createActualDirectory($directory, $connection)
|
||||
{
|
||||
// List the current directory
|
||||
$listing = ftp_nlist($connection, '.');
|
||||
|
||||
foreach ($listing as $key => $item) {
|
||||
if (preg_match('~^\./.*~', $item)) {
|
||||
$listing[$key] = substr($item, 2);
|
||||
}
|
||||
}
|
||||
|
||||
if (in_array($directory, $listing)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return (boolean) ftp_mkdir($connection, $directory);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadata($path)
|
||||
{
|
||||
$listing = ftp_rawlist($this->getConnection(), $path);
|
||||
|
||||
if (empty($listing)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$metadata = $this->normalizeObject($listing[0], '');
|
||||
|
||||
if ($metadata['path'] === '.') {
|
||||
$metadata['path'] = $path;
|
||||
}
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMimetype($path)
|
||||
{
|
||||
if (! $metadata = $this->read($path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$metadata['mimetype'] = Util::guessMimeType($path, $metadata['contents']);
|
||||
|
||||
return $metadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($path)
|
||||
{
|
||||
if (! $object = $this->readStream($path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$object['contents'] = stream_get_contents($object['stream']);
|
||||
fclose($object['stream']);
|
||||
unset($object['stream']);
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function readStream($path)
|
||||
{
|
||||
$stream = fopen('php://temp', 'w+');
|
||||
$result = ftp_fget($this->getConnection(), $stream, $path, $this->transferMode);
|
||||
rewind($stream);
|
||||
|
||||
if (! $result) {
|
||||
fclose($stream);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return compact('stream');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setVisibility($path, $visibility)
|
||||
{
|
||||
$mode = $visibility === AdapterInterface::VISIBILITY_PUBLIC ? $this->getPermPublic() : $this->getPermPrivate();
|
||||
|
||||
if (! ftp_chmod($this->getConnection(), $mode, $path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return compact('visibility');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @param string $directory
|
||||
*/
|
||||
protected function listDirectoryContents($directory, $recursive = true)
|
||||
{
|
||||
$listing = ftp_rawlist($this->getConnection(), '-lna '.$directory, $recursive);
|
||||
|
||||
if ($listing === false) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->normalizeListing($listing, $directory);
|
||||
}
|
||||
}
|
||||
390
vendor/league/flysystem/src/Adapter/Local.php
vendored
Normal file
390
vendor/league/flysystem/src/Adapter/Local.php
vendored
Normal file
@@ -0,0 +1,390 @@
|
||||
<?php
|
||||
|
||||
namespace League\Flysystem\Adapter;
|
||||
|
||||
use DirectoryIterator;
|
||||
use FilesystemIterator;
|
||||
use Finfo;
|
||||
use League\Flysystem\AdapterInterface;
|
||||
use League\Flysystem\Config;
|
||||
use League\Flysystem\Util;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
use SplFileInfo;
|
||||
|
||||
class Local extends AbstractAdapter
|
||||
{
|
||||
protected static $permissions = [
|
||||
'public' => 0744,
|
||||
'private' => 0700,
|
||||
];
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $pathSeparator = DIRECTORY_SEPARATOR;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param string $root
|
||||
*/
|
||||
public function __construct($root)
|
||||
{
|
||||
$realRoot = $this->ensureDirectory($root);
|
||||
|
||||
if ( ! is_dir($realRoot) || ! is_readable($realRoot)) {
|
||||
throw new \LogicException('The root path '.$root.' is not readable.');
|
||||
}
|
||||
|
||||
$this->setPathPrefix($realRoot);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure the root directory exists.
|
||||
*
|
||||
* @param string $root root directory path
|
||||
*
|
||||
* @return string real path to root
|
||||
*/
|
||||
protected function ensureDirectory($root)
|
||||
{
|
||||
if (is_dir($root) === false) {
|
||||
mkdir($root, 0755, true);
|
||||
}
|
||||
|
||||
return realpath($root);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function has($path)
|
||||
{
|
||||
$location = $this->applyPathPrefix($path);
|
||||
|
||||
return file_exists($location);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($path, $contents, Config $config)
|
||||
{
|
||||
$location = $this->applyPathPrefix($path);
|
||||
$this->ensureDirectory(dirname($location));
|
||||
|
||||
if (($size = file_put_contents($location, $contents, LOCK_EX)) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$type = 'file';
|
||||
$result = compact('contents', 'type', 'size', 'path');
|
||||
|
||||
if ($visibility = $config->get('visibility')) {
|
||||
$result['visibility'] = $visibility;
|
||||
$this->setVisibility($path, $visibility);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function writeStream($path, $resource, Config $config)
|
||||
{
|
||||
$location = $this->applyPathPrefix($path);
|
||||
$this->ensureDirectory(dirname($location));
|
||||
|
||||
if (! $stream = fopen($location, 'w+')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
while (! feof($resource)) {
|
||||
fwrite($stream, fread($resource, 1024), 1024);
|
||||
}
|
||||
|
||||
if (! fclose($stream)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($visibility = $config->get('visibility')) {
|
||||
$this->setVisibility($path, $visibility);
|
||||
}
|
||||
|
||||
return compact('path', 'visibility');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function readStream($path)
|
||||
{
|
||||
$location = $this->applyPathPrefix($path);
|
||||
$stream = fopen($location, 'r');
|
||||
|
||||
return compact('stream', 'path');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function updateStream($path, $resource, Config $config)
|
||||
{
|
||||
return $this->writeStream($path, $resource, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function update($path, $contents, Config $config)
|
||||
{
|
||||
$location = $this->applyPathPrefix($path);
|
||||
$mimetype = Util::guessMimeType($path, $contents);
|
||||
|
||||
if (($size = file_put_contents($location, $contents, LOCK_EX)) === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return compact('path', 'size', 'contents', 'mimetype');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($path)
|
||||
{
|
||||
$location = $this->applyPathPrefix($path);
|
||||
$contents = file_get_contents($location);
|
||||
|
||||
if ($contents === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return compact('contents', 'path');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rename($path, $newpath)
|
||||
{
|
||||
$location = $this->applyPathPrefix($path);
|
||||
$destination = $this->applyPathPrefix($newpath);
|
||||
$parentDirectory = $this->applyPathPrefix(Util::dirname($newpath));
|
||||
$this->ensureDirectory($parentDirectory);
|
||||
|
||||
return rename($location, $destination);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function copy($path, $newpath)
|
||||
{
|
||||
$location = $this->applyPathPrefix($path);
|
||||
$destination = $this->applyPathPrefix($newpath);
|
||||
$this->ensureDirectory(dirname($destination));
|
||||
|
||||
return copy($location, $destination);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($path)
|
||||
{
|
||||
$location = $this->applyPathPrefix($path);
|
||||
|
||||
return unlink($location);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function listContents($directory = '', $recursive = false)
|
||||
{
|
||||
$result = [];
|
||||
$location = $this->applyPathPrefix($directory).$this->pathSeparator;
|
||||
|
||||
if (! is_dir($location)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$iterator = $recursive ? $this->getRecursiveDirectoryIterator($location) : $this->getDirectoryIterator($location);
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
$path = $this->getFilePath($file);
|
||||
if (preg_match('#(^|/|\\\\)\.{1,2}$#', $path)) {
|
||||
continue;
|
||||
}
|
||||
$result[] = $this->normalizeFileInfo($file);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadata($path)
|
||||
{
|
||||
$location = $this->applyPathPrefix($path);
|
||||
$info = new SplFileInfo($location);
|
||||
|
||||
return $this->normalizeFileInfo($info);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSize($path)
|
||||
{
|
||||
return $this->getMetadata($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMimetype($path)
|
||||
{
|
||||
$location = $this->applyPathPrefix($path);
|
||||
$finfo = new Finfo(FILEINFO_MIME_TYPE);
|
||||
|
||||
return ['mimetype' => $finfo->file($location)];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTimestamp($path)
|
||||
{
|
||||
return $this->getMetadata($path);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getVisibility($path)
|
||||
{
|
||||
$location = $this->applyPathPrefix($path);
|
||||
clearstatcache(false, $location);
|
||||
$permissions = octdec(substr(sprintf('%o', fileperms($location)), -4));
|
||||
$visibility = $permissions & 0044 ? AdapterInterface::VISIBILITY_PUBLIC : AdapterInterface::VISIBILITY_PRIVATE;
|
||||
|
||||
return compact('visibility');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setVisibility($path, $visibility)
|
||||
{
|
||||
$location = $this->applyPathPrefix($path);
|
||||
chmod($location, static::$permissions[$visibility]);
|
||||
|
||||
return compact('visibility');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createDir($dirname, Config $config)
|
||||
{
|
||||
$location = $this->applyPathPrefix($dirname);
|
||||
|
||||
if (! is_dir($location) && ! mkdir($location, 0777, true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return ['path' => $dirname, 'type' => 'dir'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteDir($dirname)
|
||||
{
|
||||
$location = $this->applyPathPrefix($dirname);
|
||||
|
||||
if (! is_dir($location)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$contents = $this->listContents($dirname, true);
|
||||
$contents = array_reverse($contents);
|
||||
|
||||
foreach ($contents as $file) {
|
||||
if ($file['type'] === 'file') {
|
||||
unlink($this->applyPathPrefix($file['path']));
|
||||
} else {
|
||||
rmdir($this->applyPathPrefix($file['path']));
|
||||
}
|
||||
}
|
||||
|
||||
return rmdir($location);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalize the file info.
|
||||
*
|
||||
* @param SplFileInfo $file
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function normalizeFileInfo(SplFileInfo $file)
|
||||
{
|
||||
$normalized = [
|
||||
'type' => $file->getType(),
|
||||
'path' => $this->getFilePath($file),
|
||||
'timestamp' => $file->getMTime(),
|
||||
];
|
||||
|
||||
if ($normalized['type'] === 'file') {
|
||||
$normalized['size'] = $file->getSize();
|
||||
}
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the normalized path from a SplFileInfo object.
|
||||
*
|
||||
* @param SplFileInfo $file
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getFilePath(SplFileInfo $file)
|
||||
{
|
||||
$path = $file->getPathname();
|
||||
$path = $this->removePathPrefix($path);
|
||||
|
||||
return trim($path, '\\/');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*
|
||||
* @return RecursiveIteratorIterator
|
||||
*/
|
||||
protected function getRecursiveDirectoryIterator($path)
|
||||
{
|
||||
$directory = new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS);
|
||||
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
|
||||
|
||||
return $iterator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*
|
||||
* @return DirectoryIterator
|
||||
*/
|
||||
protected function getDirectoryIterator($path)
|
||||
{
|
||||
$iterator = new DirectoryIterator($path);
|
||||
|
||||
return $iterator;
|
||||
}
|
||||
}
|
||||
146
vendor/league/flysystem/src/Adapter/NullAdapter.php
vendored
Normal file
146
vendor/league/flysystem/src/Adapter/NullAdapter.php
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
<?php
|
||||
|
||||
namespace League\Flysystem\Adapter;
|
||||
|
||||
use League\Flysystem\Adapter\Polyfill\StreamedCopyTrait;
|
||||
use League\Flysystem\Adapter\Polyfill\StreamedTrait;
|
||||
use League\Flysystem\Config;
|
||||
use League\Flysystem\Util;
|
||||
|
||||
class NullAdapter extends AbstractAdapter
|
||||
{
|
||||
use StreamedTrait;
|
||||
use StreamedCopyTrait;
|
||||
|
||||
/**
|
||||
* Check whether a file is present.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function has($path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function write($path, $contents, Config $config)
|
||||
{
|
||||
$type = 'file';
|
||||
$config = Util::ensureConfig($config);
|
||||
$result = compact('contents', 'type', 'size', 'path');
|
||||
|
||||
if ($visibility = $config->get('visibility')) {
|
||||
$result['visibility'] = $visibility;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function update($path, $contents, Config $config)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function read($path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function rename($path, $newpath)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function delete($path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function listContents($directory = '', $recursive = false)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadata($path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getSize($path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMimetype($path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getTimestamp($path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getVisibility($path)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setVisibility($path, $visibility)
|
||||
{
|
||||
return compact('visibility');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function createDir($dirname, Config $config)
|
||||
{
|
||||
return ['path' => $dirname, 'type' => 'dir'];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function deleteDir($dirname)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
33
vendor/league/flysystem/src/Adapter/Polyfill/NotSupportingVisibilityTrait.php
vendored
Normal file
33
vendor/league/flysystem/src/Adapter/Polyfill/NotSupportingVisibilityTrait.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace League\Flysystem\Adapter\Polyfill;
|
||||
|
||||
use LogicException;
|
||||
|
||||
trait NotSupportingVisibilityTrait
|
||||
{
|
||||
/**
|
||||
* Get the visibility of a file.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function getVisibility($path)
|
||||
{
|
||||
throw new LogicException(get_class($this).' does not support visibility. Path: '.$path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the visibility for a file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $visibility
|
||||
*
|
||||
* @throws LogicException
|
||||
*/
|
||||
public function setVisibility($path, $visibility)
|
||||
{
|
||||
throw new LogicException(get_class($this).' does not support visibility. Path: '.$path.', visibility: '.$visibility);
|
||||
}
|
||||
}
|
||||
45
vendor/league/flysystem/src/Adapter/Polyfill/StreamedCopyTrait.php
vendored
Normal file
45
vendor/league/flysystem/src/Adapter/Polyfill/StreamedCopyTrait.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace League\Flysystem\Adapter\Polyfill;
|
||||
|
||||
use League\Flysystem\Config;
|
||||
|
||||
trait StreamedCopyTrait
|
||||
{
|
||||
/**
|
||||
* Copy a file.
|
||||
*
|
||||
* @param string $path
|
||||
* @param string $newpath
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function copy($path, $newpath)
|
||||
{
|
||||
$response = $this->readStream($path);
|
||||
|
||||
if ($response === false || ! is_resource($response['stream'])) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$result = $this->writeStream($newpath, $response['stream'], new Config());
|
||||
|
||||
if ($result !== false && is_resource($response['stream'])) {
|
||||
fclose($response['stream']);
|
||||
}
|
||||
|
||||
return $result !== false;
|
||||
}
|
||||
|
||||
// Required abstract method
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*/
|
||||
abstract public function readStream($path);
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*/
|
||||
abstract public function writeStream($path, $resource, Config $config);
|
||||
}
|
||||
37
vendor/league/flysystem/src/Adapter/Polyfill/StreamedReadingTrait.php
vendored
Normal file
37
vendor/league/flysystem/src/Adapter/Polyfill/StreamedReadingTrait.php
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace League\Flysystem\Adapter\Polyfill;
|
||||
|
||||
trait StreamedReadingTrait
|
||||
{
|
||||
/**
|
||||
* Get the contents of a file in a stream.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return resource|false false when not found, or a resource
|
||||
*/
|
||||
public function readStream($path)
|
||||
{
|
||||
if (! $data = $this->read($path)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$stream = tmpfile();
|
||||
fwrite($stream, $data['contents']);
|
||||
rewind($stream);
|
||||
$data['stream'] = $stream;
|
||||
unset($data['contents']);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
// Required abstract method
|
||||
|
||||
/**
|
||||
* @param string $path
|
||||
*
|
||||
* @return resource
|
||||
*/
|
||||
abstract public function read($path);
|
||||
}
|
||||
9
vendor/league/flysystem/src/Adapter/Polyfill/StreamedTrait.php
vendored
Normal file
9
vendor/league/flysystem/src/Adapter/Polyfill/StreamedTrait.php
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace League\Flysystem\Adapter\Polyfill;
|
||||
|
||||
trait StreamedTrait
|
||||
{
|
||||
use StreamedReadingTrait;
|
||||
use StreamedWritingTrait;
|
||||
}
|
||||
60
vendor/league/flysystem/src/Adapter/Polyfill/StreamedWritingTrait.php
vendored
Normal file
60
vendor/league/flysystem/src/Adapter/Polyfill/StreamedWritingTrait.php
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace League\Flysystem\Adapter\Polyfill;
|
||||
|
||||
use League\Flysystem\Config;
|
||||
use League\Flysystem\Util;
|
||||
|
||||
trait StreamedWritingTrait
|
||||
{
|
||||
/**
|
||||
* Stream fallback delegator.
|
||||
*
|
||||
* @param string $path
|
||||
* @param resource $resource
|
||||
* @param Config $config
|
||||
* @param string $fallback
|
||||
*
|
||||
* @return mixed fallback result
|
||||
*/
|
||||
protected function stream($path, $resource, Config $config, $fallback)
|
||||
{
|
||||
Util::rewindStream($resource);
|
||||
$contents = stream_get_contents($resource);
|
||||
$fallbackCall = [$this, $fallback];
|
||||
|
||||
return call_user_func($fallbackCall, $path, $contents, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write using a stream.
|
||||
*
|
||||
* @param string $path
|
||||
* @param resource $resource
|
||||
* @param Config $config
|
||||
*
|
||||
* @return mixed false or file metadata
|
||||
*/
|
||||
public function writeStream($path, $resource, Config $config)
|
||||
{
|
||||
return $this->stream($path, $resource, $config, 'write');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a file using a stream.
|
||||
*
|
||||
* @param string $path
|
||||
* @param resource $resource
|
||||
* @param Config $config Config object or visibility setting
|
||||
*
|
||||
* @return mixed false of file metadata
|
||||
*/
|
||||
public function updateStream($path, $resource, Config $config)
|
||||
{
|
||||
return $this->stream($path, $resource, $config, 'update');
|
||||
}
|
||||
|
||||
// Required abstract methods
|
||||
abstract public function write($pash, $contents, Config $config);
|
||||
abstract public function update($pash, $contents, Config $config);
|
||||
}
|
||||
36
vendor/league/flysystem/src/Adapter/SynologyFtp.php
vendored
Normal file
36
vendor/league/flysystem/src/Adapter/SynologyFtp.php
vendored
Normal file
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace League\Flysystem\Adapter;
|
||||
|
||||
class SynologyFtp extends Ftp
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getMetadata($path)
|
||||
{
|
||||
if (empty($path) || ! ($object = ftp_raw($this->getConnection(), 'STAT '.$path)) || count($object) < 3) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (substr($object[1], 0, 5) === "ftpd:") {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $this->normalizeObject($object[1], '');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function listDirectoryContents($directory, $recursive = true)
|
||||
{
|
||||
$listing = ftp_rawlist($this->getConnection(), $directory, $recursive);
|
||||
|
||||
if ($listing === false || (!empty($listing) && substr($listing[0], 0, 5) === "ftpd:")) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->normalizeListing($listing, $directory);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user