ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
FlySystemLocalFilesystemFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
23use League\Flysystem\Filesystem;
26use League\Flysystem\Local\LocalFilesystemAdapter;
27use League\Flysystem\UnixVisibility\PortableVisibilityConverter;
28
34{
38 public const PRIVATE_ACCESS_KEY = 'private';
42 public const PUBLIC_ACCESS_KEY = 'public';
46 public const FILE_ACCESS_KEY = 'file';
50 public const DIRECTORY_ACCESS_KEY = 'dir';
51
57 public function getInstance(LocalConfig $config): FilesystemFacade
58 {
59 $this->validateFileLockMode($config->getLockMode());
60
61 $visibility = new PortableVisibilityConverter(
62 $config->getFileAccessPublic(),
63 $config->getFileAccessPrivate(),
64 $config->getDirectoryAccessPublic(),
66 );
67
68 $adapter = new LocalFilesystemAdapter(
69 $config->getRootPath(),
70 $visibility,
71 $config->getLockMode(),
72 $this->mapConfigLinkToLocalLinks($config->getLinkBehaviour())
73 );
74
75 $filesystem = new Filesystem($adapter);
76
77 $fileAccess = new FlySystemFileAccess($filesystem);
78
79 return new FilesystemFacade(
80 new FlySystemFileStreamAccess($filesystem),
81 $fileAccess,
82 new FlySystemDirectoryAccess($filesystem, $fileAccess)
83 );
84 }
85
95 private function mapConfigLinkToLocalLinks(int $configLinkBehaviour): int
96 {
97 return match ($configLinkBehaviour) {
98 LocalConfig::DISALLOW_LINKS => LocalFilesystemAdapter::DISALLOW_LINKS,
99 LocalConfig::SKIP_LINKS => LocalFilesystemAdapter::SKIP_LINKS,
100 default => throw new \InvalidArgumentException(
101 "The supplied value \"$configLinkBehaviour\" is not a valid LocalConfig link behaviour constant."
102 ),
103 };
104 }
105
118 private function validateFileLockMode(int $code): void
119 {
120 if ($code === LOCK_EX) {
121 return;
122 }
123 if ($code === LOCK_SH) {
124 return;
125 }
126 throw new \InvalidArgumentException(
127 "The supplied value \"$code\" is not a valid file lock mode please check your local file storage configurations."
128 );
129 }
130}
The filesystem facade is used internally to satisfy the Filesystem interface because the implementati...
This class is used to configure the local filesystem adapter.
Definition: LocalConfig.php:30
getInstance(LocalConfig $config)
Creates a new instance of the local filesystem adapter used by fly system.
mapConfigLinkToLocalLinks(int $configLinkBehaviour)
Maps a constant of the LocalConfig class into a constant of the Local class.
validateFileLockMode(int $code)
Checks if the supplied file lock mode is valid.
The filesystem interface provides the public interface for the Filesystem service API consumer.
Definition: Filesystem.php:37
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...