ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
FlySystemLocalFilesystemFactory.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 
28 
34 {
35  public const PRIVATE_ACCESS_KEY = 'private';
36  public const PUBLIC_ACCESS_KEY = 'public';
37  public const FILE_ACCESS_KEY = 'file';
38  public const DIRECTORY_ACCESS_KEY = 'dir';
39 
46  {
47  $this->validateFileLockMode($config->getLockMode());
48 
49  $visibility = new PortableVisibilityConverter(
50  $config->getFileAccessPublic(),
51  $config->getFileAccessPrivate(),
52  $config->getDirectoryAccessPublic(),
53  $config->getDirectoryAccessPrivate()
54  );
55 
56  $adapter = new LocalFilesystemAdapter(
57  $config->getRootPath(),
58  $visibility,
59  $config->getLockMode(),
61  );
62 
63  $filesystem = new \League\Flysystem\Filesystem($adapter);
64 
65  $fileAccess = new FlySystemFileAccess($filesystem);
66 
67  return new FilesystemFacade(
68  new FlySystemFileStreamAccess($filesystem),
69  $fileAccess,
70  new FlySystemDirectoryAccess($filesystem, $fileAccess)
71  );
72  }
73 
83  private function mapConfigLinkToLocalLinks(int $configLinkBehaviour): int
84  {
85  return match ($configLinkBehaviour) {
86  LocalConfig::DISALLOW_LINKS => LocalFilesystemAdapter::DISALLOW_LINKS,
87  LocalConfig::SKIP_LINKS => LocalFilesystemAdapter::SKIP_LINKS,
88  default => throw new \InvalidArgumentException(
89  "The supplied value \"$configLinkBehaviour\" is not a valid LocalConfig link behaviour constant."
90  ),
91  };
92  }
93 
106  private function validateFileLockMode(int $code): void
107  {
108  if ($code === LOCK_EX) {
109  return;
110  }
111  if ($code === LOCK_SH) {
112  return;
113  }
114  throw new \InvalidArgumentException(
115  "The supplied value \"$code\" is not a valid file lock mode please check your local file storage configurations."
116  );
117  }
118 }
Interface Observer Contains several chained tasks and infos about them.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
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.
This class is used to configure the local filesystem adapter.
Definition: LocalConfig.php:29
const DISALLOW_LINKS
This is the default behaviour because links violate the root filesystem constraint.
Definition: LocalConfig.php:35
validateFileLockMode(int $code)
Checks if the supplied file lock mode is valid.
The filesystem facade is used internally to satisfy the Filesystem interface because the implementati...