ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
FlySystemLocalFilesystemFactory.php
Go to the documentation of this file.
1 <?php
2 
4 
9 
20 {
21  const PRIVATE_ACCESS_KEY = 'private';
22  const PUBLIC_ACCESS_KEY = 'public';
23  const FILE_ACCESS_KEY = 'file';
24  const DIRECTORY_ACCESS_KEY = 'dir';
25 
33  public function getInstance(LocalConfig $config)
34  {
35  $this->validateFileLockMode($config->getLockMode());
36 
37  $adapter = new Local(
38  $config->getRootPath(),
39  $config->getLockMode(),
41  [
42  self::FILE_ACCESS_KEY => [
43  self::PRIVATE_ACCESS_KEY => $config->getFileAccessPrivate(),
44  self::PUBLIC_ACCESS_KEY => $config->getFileAccessPublic()
45  ],
46  self::DIRECTORY_ACCESS_KEY => [
47  self::PRIVATE_ACCESS_KEY => $config->getDirectoryAccessPrivate(),
48  self::PUBLIC_ACCESS_KEY => $config->getDirectoryAccessPublic()
49  ]
50  ]
51  );
52 
53  //switch the path separator to a forward slash, see Mantis 0022554
54  $reflection = new \ReflectionObject($adapter);
55  $property = $reflection->getProperty("pathSeparator");
56  $property->setAccessible(true);
57  $property->setValue($adapter, '/');
58 
59  /* set new path separator in path prefix, the library will replace the old path ending
60  while setting the path prefix.
61  */
62  $adapter->setPathPrefix($adapter->getPathPrefix());
63 
64 
65  $filesystem = new \League\Flysystem\Filesystem($adapter);
66  $fileAccess = new FlySystemFileAccess($filesystem);
67  $facade = new FilesystemFacade(
68  new FlySystemFileStreamAccess($filesystem),
69  $fileAccess,
70  new FlySystemDirectoryAccess($filesystem, $fileAccess)
71  );
72 
73  return $facade;
74  }
75 
76 
86  private function mapConfigLinkToLocalLinks($configLinkBehaviour)
87  {
88  switch ($configLinkBehaviour) {
90  return Local::DISALLOW_LINKS;
92  return Local::SKIP_LINKS;
93  default:
94  throw new \InvalidArgumentException("The supplied value \"$configLinkBehaviour\" is not a valid LocalConfig link behaviour constant.");
95  }
96  }
97 
98 
111  private function validateFileLockMode($code)
112  {
113  if ($code === LOCK_EX || $code === LOCK_SH) {
114  return;
115  }
116 
117  throw new \InvalidArgumentException("The supplied value \"$code\" is not a valid file lock mode please check your local file storage configurations.");
118  }
119 }
$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:21
validateFileLockMode($code)
Checks if the supplied file lock mode is valid.