OneupFlysystemBundle динамически изменяет / внедряет файловые системы в Symfony - PullRequest
0 голосов
/ 01 февраля 2020

Технология: Symfony 5 OneupFlysystemBundle

Я не знаю, как динамически изменять / вводить файловые системы, используя Depency Ingection. Мне нужно решение, в котором $ firstFilesystem в Service не жестко задан, а зависит от переменной, отправленной из контроллера

Заранее благодарю за помощь

Это мой упрощенный проект:

#   config/packages/oneup_filesystem.yaml
oneup_flysystem:
    adapters:
        first_adapter:
            local:
                directory: '%kernel.project_dir%/resources/storage_test_one'
        second_adapter:
            local:
                directory: '%kernel.project_dir%/resources/storage_test_second'
        third_adapter:
            local:
                directory: '%kernel.project_dir%/resources/storage_test_third'
    filesystems:
        first_filesystem:
            adapter: first_adapter
            alias: League\Flysystem\Filesystem
        second_filesystem:
            adapter: second_adapter
            alias: League\Flysystem\Filesystem
        third_filesystem:
            adapter: third_adapter
            alias: League\Flysystem\Filesystem

...

namespace App\Controller;

use App\Service\Storage\StorageConnector;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;

/**
 * @Route("/", name="home")
 */
class HomeTest extends AbstractController
{

    public $Storage;

    /**
     * @Route("/test/{storage}", name="test")
     */
    public function test($storage, StorageConnector $StorageConnector)
    {

        $this->Storage = $StorageConnector;

        return new JsonResponse([
            'status' => ['test'],
            'content' => $this->Storage->test_content(),
            ]);
    }
}

...

<?php
#   src/Service/Storage/StorageConnector.php

namespace App\Service\Storage;

use League\Flysystem\FilesystemInterface;

class StorageConnector
{

    public $storageName;
    public $storageSystem;
    public $storageSyncReport = [];
    public $containerBuilder;

    public function __construct(FilesystemInterface $firstFilesystem)
    {
        $this->storageSystem = $firstFilesystem;
    }


    public function test_content()
    {
        return $this->storageSystem->read('test.md');
    }
}

все работает, json ответ:

{"status":["test"],"content":"this is content of file test.md in resources/storage_test"}

, но не может изменить файловую систему

...