ILIAS  release_7 Revision v7.30-3-g800a261c036
FlySystemLocalFilesystemFactory.php
Go to the documentation of this file.
1<?php
2declare(strict_types=1);
3
5
9use League\Flysystem\Adapter\Local;
10
19{
20 const PRIVATE_ACCESS_KEY = 'private';
21 const PUBLIC_ACCESS_KEY = 'public';
22 const FILE_ACCESS_KEY = 'file';
23 const DIRECTORY_ACCESS_KEY = 'dir';
24
31 {
32 $this->validateFileLockMode($config->getLockMode());
33
34 $adapter = new Local(
35 $config->getRootPath(),
36 $config->getLockMode(),
37 $this->mapConfigLinkToLocalLinks($config->getLinkBehaviour()),
38 [
39 self::FILE_ACCESS_KEY => [
40 self::PRIVATE_ACCESS_KEY => $config->getFileAccessPrivate(),
41 self::PUBLIC_ACCESS_KEY => $config->getFileAccessPublic()
42 ],
43 self::DIRECTORY_ACCESS_KEY => [
44 self::PRIVATE_ACCESS_KEY => $config->getDirectoryAccessPrivate(),
45 self::PUBLIC_ACCESS_KEY => $config->getDirectoryAccessPublic()
46 ]
47 ]
48 );
49
50 //switch the path separator to a forward slash, see Mantis 0022554
51 $reflection = new \ReflectionObject($adapter);
52 $property = $reflection->getProperty("pathSeparator");
53 $property->setAccessible(true);
54 $property->setValue($adapter, '/');
55
56 /* set new path separator in path prefix, the library will replace the old path ending
57 while setting the path prefix.
58 */
59 $adapter->setPathPrefix($adapter->getPathPrefix());
60
61 $filesystem = new \League\Flysystem\Filesystem($adapter);
62 $fileAccess = new FlySystemFileAccess($filesystem);
63 $facade = new FilesystemFacade(
64 new FlySystemFileStreamAccess($filesystem),
65 $fileAccess,
66 new FlySystemDirectoryAccess($filesystem, $fileAccess)
67 );
68
69 return $facade;
70 }
71
78 private function mapConfigLinkToLocalLinks($configLinkBehaviour)
79 {
80 switch ($configLinkBehaviour) {
82 return Local::DISALLOW_LINKS;
84 return Local::SKIP_LINKS;
85 default:
86 throw new \InvalidArgumentException("The supplied value \"$configLinkBehaviour\" is not a valid LocalConfig link behaviour constant.");
87 }
88 }
89
99 private function validateFileLockMode($code)
100 {
101 if ($code === LOCK_EX || $code === LOCK_SH) {
102 return;
103 }
104
105 throw new \InvalidArgumentException("The supplied value \"$code\" is not a valid file lock mode please check your local file storage configurations.");
106 }
107}
An exception for terminatinating execution or to throw for unit testing.
Class LocalConfig This class is used to configure the local filesystem adapter.
Definition: LocalConfig.php:14
const DISALLOW_LINKS
This is the default behaviour because links violate the root filesystem constraint.
Definition: LocalConfig.php:20
Class FlySystemFileAccess Fly system file access implementation.
Class FlySystemFileStreamAccess Streaming access implementation of the fly system library.
Class FlySystemLocalFilesystemFactory The local fly system filesystem factory creates instances of th...
validateFileLockMode($code)
Checks if the supplied file lock mode is valid.
getInstance(LocalConfig $config)
Creates a new instance of the local filesystem adapter used by fly system.
mapConfigLinkToLocalLinks($configLinkBehaviour)
Maps a constant of the LocalConfig class into a constant of the Local class.
Interface Filesystem The filesystem interface provides the public interface for the Filesystem servic...
Definition: Filesystem.php:22
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68