ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
FlySystemLocalFilesystemFactory.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types=1);
3 
5 
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 
34  public function getInstance(LocalConfig $config)
35  {
36  $this->validateFileLockMode($config->getLockMode());
37 
38  $adapter = new Local(
39  $config->getRootPath(),
40  $config->getLockMode(),
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 }
$config
Definition: bootstrap.php:15
$code
Definition: example_050.php:99
mapConfigLinkToLocalLinks($configLinkBehaviour)
Maps a constant of the LocalConfig class into a constant of the Local class.
setPathPrefix($prefix)
Set the path prefix.
getInstance(LocalConfig $config)
Creates a new instance of the local filesystem adapter used by fly system.
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.