ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
FlySystemLocalFilesystemFactory.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
6 
11 
12 /******************************************************************************
13  *
14  * This file is part of ILIAS, a powerful learning management system.
15  *
16  * ILIAS is licensed with the GPL-3.0, you should have received a copy
17  * of said license along with the source code.
18  *
19  * If this is not the case or you just want to try ILIAS, you'll find
20  * us at:
21  * https://www.ilias.de
22  * https://github.com/ILIAS-eLearning
23  *
24  *****************************************************************************/
35 {
36  public const PRIVATE_ACCESS_KEY = 'private';
37  public const PUBLIC_ACCESS_KEY = 'public';
38  public const FILE_ACCESS_KEY = 'file';
39  public const DIRECTORY_ACCESS_KEY = 'dir';
40 
47  {
48  $this->validateFileLockMode($config->getLockMode());
49 
50  $adapter = new Local(
51  $config->getRootPath(),
52  $config->getLockMode(),
54  [
55  self::FILE_ACCESS_KEY => [
56  self::PRIVATE_ACCESS_KEY => $config->getFileAccessPrivate(),
57  self::PUBLIC_ACCESS_KEY => $config->getFileAccessPublic()
58  ],
59  self::DIRECTORY_ACCESS_KEY => [
60  self::PRIVATE_ACCESS_KEY => $config->getDirectoryAccessPrivate(),
61  self::PUBLIC_ACCESS_KEY => $config->getDirectoryAccessPublic()
62  ]
63  ]
64  );
65 
66  //switch the path separator to a forward slash, see Mantis 0022554
67  $reflection = new \ReflectionObject($adapter);
68  $property = $reflection->getProperty("pathSeparator");
69  $property->setAccessible(true);
70  $property->setValue($adapter, '/');
71 
72  /* set new path separator in path prefix, the library will replace the old path ending
73  while setting the path prefix.
74  */
75  $adapter->setPathPrefix($adapter->getPathPrefix());
76 
77 
78  $filesystem = new \League\Flysystem\Filesystem($adapter);
79  $fileAccess = new FlySystemFileAccess($filesystem);
80  $facade = new FilesystemFacade(
81  new FlySystemFileStreamAccess($filesystem),
82  $fileAccess,
83  new FlySystemDirectoryAccess($filesystem, $fileAccess)
84  );
85 
86  return $facade;
87  }
88 
89 
99  private function mapConfigLinkToLocalLinks(int $configLinkBehaviour): int
100  {
101  switch ($configLinkBehaviour) {
103  return Local::DISALLOW_LINKS;
105  return Local::SKIP_LINKS;
106  default:
107  throw new \InvalidArgumentException("The supplied value \"$configLinkBehaviour\" is not a valid LocalConfig link behaviour constant.");
108  }
109  }
110 
111 
124  private function validateFileLockMode(int $code): void
125  {
126  if ($code === LOCK_EX || $code === LOCK_SH) {
127  return;
128  }
129 
130  throw new \InvalidArgumentException("The supplied value \"$code\" is not a valid file lock mode please check your local file storage configurations.");
131  }
132 }
Class ChatMainBarProvider .
if(!array_key_exists('PATH_INFO', $_SERVER)) $config
Definition: metadata.php:85
mapConfigLinkToLocalLinks(int $configLinkBehaviour)
Maps a constant of the LocalConfig class into a constant of the Local class.
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:35
Class FlySystemFileAccessTest disabled disabled disabled.
validateFileLockMode(int $code)
Checks if the supplied file lock mode is valid.