ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
FlySystemLocalFilesystemFactory.php
Go to the documentation of this file.
1<?php
2declare(strict_types=1);
3
5
9use League\Flysystem\Adapter\Local;
10
21{
22 const PRIVATE_ACCESS_KEY = 'private';
23 const PUBLIC_ACCESS_KEY = 'public';
24 const FILE_ACCESS_KEY = 'file';
25 const DIRECTORY_ACCESS_KEY = 'dir';
26
35 {
36 $this->validateFileLockMode($config->getLockMode());
37
38 $adapter = new Local(
39 $config->getRootPath(),
40 $config->getLockMode(),
41 $this->mapConfigLinkToLocalLinks($config->getLinkBehaviour()),
42 [
43 self::FILE_ACCESS_KEY => [
44 self::PRIVATE_ACCESS_KEY => $config->getFileAccessPrivate(),
45 self::PUBLIC_ACCESS_KEY => $config->getFileAccessPublic()
46 ],
47 self::DIRECTORY_ACCESS_KEY => [
48 self::PRIVATE_ACCESS_KEY => $config->getDirectoryAccessPrivate(),
49 self::PUBLIC_ACCESS_KEY => $config->getDirectoryAccessPublic()
50 ]
51 ]
52 );
53
54 //switch the path separator to a forward slash, see Mantis 0022554
55 $reflection = new \ReflectionObject($adapter);
56 $property = $reflection->getProperty("pathSeparator");
57 $property->setAccessible(true);
58 $property->setValue($adapter, '/');
59
60 /* set new path separator in path prefix, the library will replace the old path ending
61 while setting the path prefix.
62 */
63 $adapter->setPathPrefix($adapter->getPathPrefix());
64
65
66 $filesystem = new \League\Flysystem\Filesystem($adapter);
67 $fileAccess = new FlySystemFileAccess($filesystem);
68 $facade = new FilesystemFacade(
69 new FlySystemFileStreamAccess($filesystem),
70 $fileAccess,
71 new FlySystemDirectoryAccess($filesystem, $fileAccess)
72 );
73
74 return $facade;
75 }
76
77
87 private function mapConfigLinkToLocalLinks($configLinkBehaviour)
88 {
89 switch ($configLinkBehaviour) {
91 return Local::DISALLOW_LINKS;
93 return Local::SKIP_LINKS;
94 default:
95 throw new \InvalidArgumentException("The supplied value \"$configLinkBehaviour\" is not a valid LocalConfig link behaviour constant.");
96 }
97 }
98
99
112 private function validateFileLockMode($code)
113 {
114 if ($code === LOCK_EX || $code === LOCK_SH) {
115 return;
116 }
117
118 throw new \InvalidArgumentException("The supplied value \"$code\" is not a valid file lock mode please check your local file storage configurations.");
119 }
120}
An exception for terminatinating execution or to throw for unit testing.
const DISALLOW_LINKS
This is the default behaviour because links violate the root filesystem constraint.
Definition: LocalConfig.php:22
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.
Definition: Filesystem.php:27
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:68