- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
118 lines
4.3 KiB
PHP
118 lines
4.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Filesystem;
|
|
|
|
use App\Framework\DI\Container;
|
|
use App\Framework\DI\Initializer;
|
|
use App\Framework\Filesystem\Serializers\CsvSerializer;
|
|
use App\Framework\Filesystem\Serializers\JsonSerializer;
|
|
use App\Framework\Filesystem\Serializers\PhpSerializer;
|
|
|
|
/**
|
|
* Filesystem-System Initializer
|
|
*
|
|
* Registriert alle Filesystem-Komponenten im DI-Container
|
|
* entsprechend der Framework-Konventionen.
|
|
*/
|
|
final readonly class FilesystemInitializer
|
|
{
|
|
#[Initializer]
|
|
public function initializeFilesystem(Container $container): void
|
|
{
|
|
// Filesystem Config
|
|
$container->singleton(FilesystemConfig::class, function () {
|
|
return new FilesystemConfig(
|
|
defaultStorage: $_ENV['FILESYSTEM_DEFAULT_STORAGE'] ?? 'local',
|
|
storages: [
|
|
'local' => [
|
|
'type' => 'file',
|
|
'path' => $_ENV['FILESYSTEM_LOCAL_PATH'] ?? '/var/www/html/storage',
|
|
],
|
|
'temp' => [
|
|
'type' => 'file',
|
|
'path' => $_ENV['FILESYSTEM_TEMP_PATH'] ?? '/tmp',
|
|
],
|
|
'analytics' => [
|
|
'type' => 'file',
|
|
'path' => $_ENV['ANALYTICS_DATA_PATH'] ?? '/var/www/html/storage/analytics',
|
|
],
|
|
],
|
|
enableCompression: filter_var($_ENV['FILESYSTEM_COMPRESSION'] ?? 'false', FILTER_VALIDATE_BOOLEAN),
|
|
enableAtomicWrites: filter_var($_ENV['FILESYSTEM_ATOMIC_WRITES'] ?? 'true', FILTER_VALIDATE_BOOLEAN),
|
|
enableFileLocking: filter_var($_ENV['FILESYSTEM_FILE_LOCKING'] ?? 'true', FILTER_VALIDATE_BOOLEAN)
|
|
);
|
|
});
|
|
|
|
// Serializers
|
|
$container->singleton(JsonSerializer::class, function () {
|
|
return new JsonSerializer();
|
|
});
|
|
|
|
$container->singleton(PhpSerializer::class, function () {
|
|
return new PhpSerializer();
|
|
});
|
|
|
|
$container->singleton(CsvSerializer::class, function () {
|
|
return new CsvSerializer();
|
|
});
|
|
|
|
// Storage Instances
|
|
$this->registerStorages($container);
|
|
|
|
// Filesystem Manager
|
|
$container->singleton(FilesystemManager::class, function (Container $container) {
|
|
$config = $container->get(FilesystemConfig::class);
|
|
$manager = new FilesystemManager($config->defaultStorage);
|
|
|
|
// Registriere alle konfigurierten Storages
|
|
foreach ($config->getAvailableStorages() as $storageName) {
|
|
$storage = $container->get("filesystem.storage.{$storageName}");
|
|
$manager->registerStorage($storageName, $storage);
|
|
}
|
|
|
|
// Registriere Serializers
|
|
$manager->registerSerializer('json', $container->get(JsonSerializer::class));
|
|
$manager->registerSerializer('php', $container->get(PhpSerializer::class));
|
|
$manager->registerSerializer('csv', $container->get(CsvSerializer::class));
|
|
|
|
return $manager;
|
|
});
|
|
}
|
|
|
|
private function registerStorages(Container $container): void
|
|
{
|
|
$container->singleton(Storage::class, function () {
|
|
return new FileStorage('/');
|
|
});
|
|
$container->singleton(FileStorage::class, function () {
|
|
return new FileStorage('/');
|
|
});
|
|
|
|
|
|
|
|
|
|
$container->singleton('filesystem.storage.local', function (Container $container) {
|
|
$config = $container->get(FilesystemConfig::class);
|
|
$storageConfig = $config->getStorageConfig('local');
|
|
|
|
return new FileStorage($storageConfig['path']);
|
|
});
|
|
|
|
$container->singleton('filesystem.storage.temp', function (Container $container) {
|
|
$config = $container->get(FilesystemConfig::class);
|
|
$storageConfig = $config->getStorageConfig('temp');
|
|
|
|
return new FileStorage($storageConfig['path']);
|
|
});
|
|
|
|
$container->singleton('filesystem.storage.analytics', function (Container $container) {
|
|
$config = $container->get(FilesystemConfig::class);
|
|
$storageConfig = $config->getStorageConfig('analytics');
|
|
|
|
return new FileStorage($storageConfig['path']);
|
|
});
|
|
}
|
|
}
|