ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
League\Flysystem\MountManager Class Reference

Class MountManager. More...

+ Collaboration diagram for League\Flysystem\MountManager:

Public Member Functions

 __construct (array $filesystems=[])
 Constructor. More...
 
 mountFilesystems (array $filesystems)
 Mount filesystems. More...
 
 mountFilesystem ($prefix, FilesystemInterface $filesystem)
 Mount filesystems. More...
 
 getFilesystem ($prefix)
 Get the filesystem with the corresponding prefix. More...
 
 filterPrefix (array $arguments)
 Retrieve the prefix from an arguments array. More...
 
 listContents ($directory='', $recursive=false)
 
 __call ($method, $arguments)
 Call forwarder. More...
 
 copy ($from, $to, array $config=[])
 
 listWith (array $keys=[], $directory='', $recursive=false)
 List with plugin adapter. More...
 
 move ($from, $to, array $config=[])
 Move a file. More...
 
 invokePluginOnFilesystem ($method, $arguments, $prefix)
 Invoke a plugin on a filesystem mounted on a given prefix. More...
 

Protected Member Functions

 getPrefixAndPath ($path)
 

Protected Attributes

 $filesystems = []
 

Detailed Description

Class MountManager.

Proxies methods to Filesystem (

See also
__call):

AdapterInterface getAdapter($prefix) Config getConfig($prefix) bool has($path) bool write($path, $contents, array $config = []) bool writeStream($path, $resource, array $config = []) bool put($path, $contents, $config = []) bool putStream($path, $contents, $config = []) string readAndDelete($path) bool update($path, $contents, $config = []) bool updateStream($path, $resource, $config = []) string|false read($path) resource|false readStream($path) bool rename($path, $newpath) bool delete($path) bool deleteDir($dirname) bool createDir($dirname, $config = []) array listFiles($directory = '', $recursive = false) array listPaths($directory = '', $recursive = false) array getWithMetadata($path, array $metadata) string|false getMimetype($path) string|false getTimestamp($path) string|false getVisibility($path) int|false getSize($path); bool setVisibility($path, $visibility) array|false getMetadata($path) Handler get($path, Handler $handler = null) Filesystem flushCache() void assertPresent($path) void assertAbsent($path) Filesystem addPlugin(PluginInterface $plugin)

Definition at line 46 of file MountManager.php.

Constructor & Destructor Documentation

◆ __construct()

League\Flysystem\MountManager::__construct ( array  $filesystems = [])

Constructor.

Parameters
FilesystemInterface[]$filesystems [:prefix => Filesystem,]
Exceptions
InvalidArgumentException

Definition at line 62 of file MountManager.php.

References League\Flysystem\MountManager\$filesystems, and League\Flysystem\MountManager\mountFilesystems().

63  {
65  }
mountFilesystems(array $filesystems)
Mount filesystems.
+ Here is the call graph for this function:

Member Function Documentation

◆ __call()

League\Flysystem\MountManager::__call (   $method,
  $arguments 
)

Call forwarder.

Parameters
string$method
array$arguments
Exceptions
InvalidArgumentException
FilesystemNotFoundException
Returns
mixed

Definition at line 184 of file MountManager.php.

References League\Flysystem\MountManager\filterPrefix(), and League\Flysystem\MountManager\invokePluginOnFilesystem().

185  {
186  list($prefix, $arguments) = $this->filterPrefix($arguments);
187 
188  return $this->invokePluginOnFilesystem($method, $arguments, $prefix);
189  }
filterPrefix(array $arguments)
Retrieve the prefix from an arguments array.
invokePluginOnFilesystem($method, $arguments, $prefix)
Invoke a plugin on a filesystem mounted on a given prefix.
+ Here is the call graph for this function:

◆ copy()

League\Flysystem\MountManager::copy (   $from,
  $to,
array  $config = [] 
)
Parameters
string$from
string$to
array$config
Exceptions
InvalidArgumentException
FilesystemNotFoundException
Returns
bool

Definition at line 201 of file MountManager.php.

References $config, $from, $result, League\Flysystem\MountManager\getFilesystem(), and League\Flysystem\MountManager\getPrefixAndPath().

Referenced by League\Flysystem\MountManager\move().

202  {
203  list($prefixFrom, $from) = $this->getPrefixAndPath($from);
204 
205  $buffer = $this->getFilesystem($prefixFrom)->readStream($from);
206 
207  if ($buffer === false) {
208  return false;
209  }
210 
211  list($prefixTo, $to) = $this->getPrefixAndPath($to);
212 
213  $result = $this->getFilesystem($prefixTo)->writeStream($to, $buffer, $config);
214 
215  if (is_resource($buffer)) {
216  fclose($buffer);
217  }
218 
219  return $result;
220  }
$result
$from
getFilesystem($prefix)
Get the filesystem with the corresponding prefix.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ filterPrefix()

League\Flysystem\MountManager::filterPrefix ( array  $arguments)

Retrieve the prefix from an arguments array.

Parameters
array$arguments
Exceptions
InvalidArgumentException
Returns
array [:prefix, :arguments]

Definition at line 133 of file MountManager.php.

References $path, and League\Flysystem\MountManager\getPrefixAndPath().

Referenced by League\Flysystem\MountManager\__call().

134  {
135  if (empty($arguments)) {
136  throw new InvalidArgumentException('At least one argument needed');
137  }
138 
139  $path = array_shift($arguments);
140 
141  if ( ! is_string($path)) {
142  throw new InvalidArgumentException('First argument should be a string');
143  }
144 
145  list($prefix, $path) = $this->getPrefixAndPath($path);
146  array_unshift($arguments, $path);
147 
148  return [$prefix, $arguments];
149  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getFilesystem()

League\Flysystem\MountManager::getFilesystem (   $prefix)

Get the filesystem with the corresponding prefix.

Parameters
string$prefix
Exceptions
FilesystemNotFoundException
Returns
FilesystemInterface

Definition at line 115 of file MountManager.php.

References ILIAS\Filesystem\filesystems().

Referenced by League\Flysystem\MountManager\copy(), League\Flysystem\MountManager\invokePluginOnFilesystem(), and League\Flysystem\MountManager\listContents().

116  {
117  if ( ! isset($this->filesystems[$prefix])) {
118  throw new FilesystemNotFoundException('No filesystem mounted with prefix ' . $prefix);
119  }
120 
121  return $this->filesystems[$prefix];
122  }
static filesystems()
Returns the loaded filesystems.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getPrefixAndPath()

League\Flysystem\MountManager::getPrefixAndPath (   $path)
protected
Parameters
string$path
Exceptions
InvalidArgumentException
Returns
string[] [:prefix, :path]

Definition at line 298 of file MountManager.php.

References $path.

Referenced by League\Flysystem\MountManager\copy(), League\Flysystem\MountManager\filterPrefix(), League\Flysystem\MountManager\listContents(), and League\Flysystem\MountManager\listWith().

299  {
300  if (strpos($path, '://') < 1) {
301  throw new InvalidArgumentException('No prefix detected in path: ' . $path);
302  }
303 
304  return explode('://', $path, 2);
305  }
+ Here is the caller graph for this function:

◆ invokePluginOnFilesystem()

League\Flysystem\MountManager::invokePluginOnFilesystem (   $method,
  $arguments,
  $prefix 
)

Invoke a plugin on a filesystem mounted on a given prefix.

Parameters
string$method
array$arguments
string$prefix
Exceptions
FilesystemNotFoundException
Returns
mixed

Definition at line 276 of file MountManager.php.

References League\Flysystem\MountManager\getFilesystem(), and League\Flysystem\Plugin\invokePlugin().

Referenced by League\Flysystem\MountManager\__call(), and League\Flysystem\MountManager\listWith().

277  {
278  $filesystem = $this->getFilesystem($prefix);
279 
280  try {
281  return $this->invokePlugin($method, $arguments, $filesystem);
282  } catch (PluginNotFoundException $e) {
283  // Let it pass, it's ok, don't panic.
284  }
285 
286  $callback = [$filesystem, $method];
287 
288  return call_user_func_array($callback, $arguments);
289  }
invokePlugin($method, array $arguments, FilesystemInterface $filesystem)
Invoke a plugin by method name.
getFilesystem($prefix)
Get the filesystem with the corresponding prefix.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ listContents()

League\Flysystem\MountManager::listContents (   $directory = '',
  $recursive = false 
)
Parameters
string$directory
bool$recursive
Exceptions
InvalidArgumentException
FilesystemNotFoundException
Returns
array

Definition at line 160 of file MountManager.php.

References $file, $result, League\Flysystem\MountManager\getFilesystem(), and League\Flysystem\MountManager\getPrefixAndPath().

161  {
162  list($prefix, $directory) = $this->getPrefixAndPath($directory);
163  $filesystem = $this->getFilesystem($prefix);
164  $result = $filesystem->listContents($directory, $recursive);
165 
166  foreach ($result as &$file) {
167  $file['filesystem'] = $prefix;
168  }
169 
170  return $result;
171  }
$result
if(!file_exists("$old.txt")) if($old===$new) if(file_exists("$new.txt")) $file
getFilesystem($prefix)
Get the filesystem with the corresponding prefix.
+ Here is the call graph for this function:

◆ listWith()

League\Flysystem\MountManager::listWith ( array  $keys = [],
  $directory = '',
  $recursive = false 
)

List with plugin adapter.

Parameters
array$keys
string$directory
bool$recursive
Exceptions
InvalidArgumentException
FilesystemNotFoundException
Returns
array

Definition at line 234 of file MountManager.php.

References $keys, League\Flysystem\MountManager\getPrefixAndPath(), and League\Flysystem\MountManager\invokePluginOnFilesystem().

235  {
236  list($prefix, $directory) = $this->getPrefixAndPath($directory);
237  $arguments = [$keys, $directory, $recursive];
238 
239  return $this->invokePluginOnFilesystem('listWith', $arguments, $prefix);
240  }
$keys
invokePluginOnFilesystem($method, $arguments, $prefix)
Invoke a plugin on a filesystem mounted on a given prefix.
+ Here is the call graph for this function:

◆ mountFilesystem()

League\Flysystem\MountManager::mountFilesystem (   $prefix,
FilesystemInterface  $filesystem 
)

Mount filesystems.

Parameters
string$prefix
FilesystemInterface$filesystem
Exceptions
InvalidArgumentException
Returns
$this

Definition at line 95 of file MountManager.php.

References ILIAS\Filesystem\filesystems().

Referenced by League\Flysystem\MountManager\mountFilesystems().

96  {
97  if ( ! is_string($prefix)) {
98  throw new InvalidArgumentException(__METHOD__ . ' expects argument #1 to be a string.');
99  }
100 
101  $this->filesystems[$prefix] = $filesystem;
102 
103  return $this;
104  }
static filesystems()
Returns the loaded filesystems.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mountFilesystems()

League\Flysystem\MountManager::mountFilesystems ( array  $filesystems)

Mount filesystems.

Parameters
FilesystemInterface[]$filesystems [:prefix => Filesystem,]
Exceptions
InvalidArgumentException
Returns
$this

Definition at line 76 of file MountManager.php.

References League\Flysystem\MountManager\mountFilesystem().

Referenced by League\Flysystem\MountManager\__construct().

77  {
78  foreach ($filesystems as $prefix => $filesystem) {
79  $this->mountFilesystem($prefix, $filesystem);
80  }
81 
82  return $this;
83  }
mountFilesystem($prefix, FilesystemInterface $filesystem)
Mount filesystems.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ move()

League\Flysystem\MountManager::move (   $from,
  $to,
array  $config = [] 
)

Move a file.

Parameters
string$from
string$to
array$config
Exceptions
InvalidArgumentException
FilesystemNotFoundException
Returns
bool

Definition at line 254 of file MountManager.php.

References $config, $from, and League\Flysystem\MountManager\copy().

255  {
256  $copied = $this->copy($from, $to, $config);
257 
258  if ($copied) {
259  return $this->delete($from);
260  }
261 
262  return false;
263  }
$from
copy($from, $to, array $config=[])
+ Here is the call graph for this function:

Field Documentation

◆ $filesystems

League\Flysystem\MountManager::$filesystems = []
protected

Definition at line 53 of file MountManager.php.

Referenced by League\Flysystem\MountManager\__construct().


The documentation for this class was generated from the following file: