ILIAS  trunk Revision v13.0_alpha-62-g3b72d83f2e5
DelegatingFilesystemFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
36
45{
47
51 public function __construct(
52 private FilenameSanitizer $sanitizer,
53 private DirectoryPathConfig $directory_path_config
54 ) {
55 /*
56 * ---------- ABSTRACTION SWITCH -------------
57 * Change the factory to switch to another filesystem abstraction!
58 * current: FlySystem from the php league
59 * -------------------------------------------
60 */
61 $this->implementation = new FlySystemFilesystemFactory();
62 }
63
67 public function getLocal(LocalConfig $config, bool $read_only = false): Filesystem
68 {
69 if ($read_only) {
70 return new ReadOnlyDecorator(
71 new FilesystemWhitelistDecorator($this->implementation->getLocal($config), $this->sanitizer)
72 );
73 }
74 return new FilesystemWhitelistDecorator($this->implementation->getLocal($config), $this->sanitizer);
75 }
76
77 public function buildFor(string $fqdn_interface, bool $read_only = false): Filesystem
78 {
79 $config = match ($fqdn_interface) {
80 FilesystemWeb::class => new LocalConfig($this->directory_path_config->getWebDirectoryPath()),
81 FilesystemStorage::class => new LocalConfig($this->directory_path_config->getStorageDirectoryPath()),
82 FilesystemTemp::class => new LocalConfig($this->directory_path_config->getTempDirectoryPath()),
83 FilesystemCustomizing::class => new LocalConfig(
84 $this->directory_path_config->getCustomizingDirectoryPath()
85 ),
86 FilesystemLibs::class => new LocalConfig($this->directory_path_config->getLibsDirectoryPath()),
87 FilesystemNodeModules::class => new LocalConfig(
88 $this->directory_path_config->getNodeModulesDirectoryPath()
89 ),
90 default => throw new \InvalidArgumentException("Unknown filesystem interface $fqdn_interface")
91 };
92
93 // the code directories are never written to at runtime
94 $read_only = $read_only || in_array(
95 $fqdn_interface,
96 [FilesystemLibs::class, FilesystemNodeModules::class],
97 true
98 );
99
100 if ($read_only) {
101 return new ReadOnlyDecorator(
102 new FilesystemWhitelistDecorator($this->implementation->getLocal($config), $this->sanitizer)
103 );
104 }
105 return new FilesystemWhitelistDecorator($this->implementation->getLocal($config), $this->sanitizer);
106 }
107
108}
The filesystem white list decorator rewrites forbidden file endings and delegates the rest of the ope...
The filesystem ready only decorator provides read only access and will throw an Exception whenever co...
This class is used to configure the local filesystem adapter.
Definition: LocalConfig.php:30
The delegating filesystem factory delegates the instance creation to the factory of the concrete impl...
buildFor(string $fqdn_interface, bool $read_only=false)
getLocal(LocalConfig $config, bool $read_only=false)
@deprectaed
__construct(private FilenameSanitizer $sanitizer, private DirectoryPathConfig $directory_path_config)
DelegatingFilesystemFactory constructor.
The filesystem interface provides the public interface for the Filesystem service API consumer.
Definition: Filesystem.php:37
The filename sanitizer verifies and fixes file name endings.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...