File tree Expand file tree Collapse file tree 4 files changed +55
-15
lines changed
DependencyInjection/CompilerPass Expand file tree Collapse file tree 4 files changed +55
-15
lines changed Original file line number Diff line number Diff line change 1414namespace Silverback \ApiComponentsBundle \DependencyInjection \CompilerPass ;
1515
1616use League \Flysystem \Filesystem ;
17+ use Silverback \ApiComponentsBundle \Flysystem \FilesystemFactory ;
1718use Silverback \ApiComponentsBundle \Flysystem \FilesystemProvider ;
1819use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
1920use Symfony \Component \DependencyInjection \ContainerBuilder ;
@@ -33,13 +34,16 @@ public function process(ContainerBuilder $container): void
3334 $ definition = new Definition ();
3435 $ definition
3536 ->setClass (Filesystem::class)
36- ->setFactory ([new Reference (FilesystemProvider ::class), 'getFilesystem ' ])
37+ ->setFactory ([new Reference (FilesystemFactory ::class), 'create ' ])
3738 ->setArguments ([
3839 $ attributes ['alias ' ],
3940 $ attributes ['config ' ] ?? []
4041 ]);
4142 $ serviceName = sprintf ('api_components.filesystem.%s ' , $ attributes ['alias ' ]);
42- $ container ->setDefinition ($ serviceName , $ definition )->addTag (FilesystemProvider::FILESYSTEM_TAG , [ 'alias ' => $ attributes ['alias ' ] ]);
43+ $ container
44+ ->setDefinition ($ serviceName , $ definition )
45+ ->addTag (FilesystemProvider::FILESYSTEM_TAG , [ 'alias ' => $ attributes ['alias ' ] ])
46+ ;
4347 }
4448 }
4549 }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ /*
4+ * This file is part of the Silverback API Components Bundle Project
5+ *
6+ * (c) Daniel West <daniel@silverback.is>
7+ *
8+ * For the full copyright and license information, please view the LICENSE
9+ * file that was distributed with this source code.
10+ */
11+
12+ declare (strict_types=1 );
13+
14+ namespace Silverback \ApiComponentsBundle \Flysystem ;
15+
16+ use League \Flysystem \Filesystem ;
17+ use Symfony \Component \DependencyInjection \Exception \RuntimeException ;
18+ use Symfony \Component \DependencyInjection \ServiceLocator ;
19+
20+ /**
21+ * @author Daniel West <daniel@silverback.is>
22+ */
23+ class FilesystemFactory
24+ {
25+ public function __construct (private readonly ServiceLocator $ adapters )
26+ {}
27+
28+ /**
29+ * @throws RuntimeException
30+ */
31+ public function create (string $ name , array $ config = []): Filesystem
32+ {
33+ return new Filesystem ($ this ->adapters ->get ($ name ), $ config );
34+ }
35+ }
Original file line number Diff line number Diff line change 1414namespace Silverback \ApiComponentsBundle \Flysystem ;
1515
1616use League \Flysystem \Filesystem ;
17+ use Psr \Container \ContainerExceptionInterface ;
18+ use Psr \Container \NotFoundExceptionInterface ;
1719use Symfony \Component \DependencyInjection \Exception \RuntimeException ;
1820use Symfony \Component \DependencyInjection \ServiceLocator ;
1921
2426class FilesystemProvider
2527{
2628 public const FILESYSTEM_ADAPTER_TAG = 'silverback.api_components.filesystem_adapter ' ;
27- public const FILESYSTEM_TAG = 'silverback.api_components.filesystem_adapter ' ;
29+ public const FILESYSTEM_TAG = 'silverback.api_components.filesystem ' ;
2830
29- private array $ filesystems = [];
30-
31- public function __construct (private readonly ServiceLocator $ adapters )
31+ public function __construct (private readonly ServiceLocator $ filesystems )
3232 {}
3333
3434 /**
35- * @throws RuntimeException
35+ * @throws ContainerExceptionInterface
36+ * @throws NotFoundExceptionInterface
3637 */
37- private function createFilesystem (string $ name , array $ config = []): Filesystem
38- {
39- return $ this ->filesystems [$ name ] = new Filesystem ($ this ->adapters ->get ($ name ), $ config );
40- }
41-
42- public function getFilesystem (string $ name , array $ config = []): ?Filesystem
38+ public function getFilesystem (string $ name ): ?Filesystem
4339 {
44- return $ this ->filesystems [ $ name ] ?? $ this -> createFilesystem ($ name, $ config );
40+ return $ this ->filesystems -> get ($ name );
4541 }
4642}
Original file line number Diff line number Diff line change 9393use Silverback \ApiComponentsBundle \Factory \User \Mailer \WelcomeEmailFactory ;
9494use Silverback \ApiComponentsBundle \Factory \User \UserFactory ;
9595use Silverback \ApiComponentsBundle \Filter \OrSearchFilter ;
96+ use Silverback \ApiComponentsBundle \Flysystem \FilesystemFactory ;
9697use Silverback \ApiComponentsBundle \Flysystem \FilesystemProvider ;
9798use Silverback \ApiComponentsBundle \Form \Type \User \ChangePasswordType ;
9899use Silverback \ApiComponentsBundle \Form \Type \User \NewEmailAddressType ;
387388 ->tag ('doctrine.repository_service ' );
388389
389390 $ services
390- ->set (FilesystemProvider ::class)
391+ ->set (FilesystemFactory ::class)
391392 ->args ([tagged_locator (FilesystemProvider::FILESYSTEM_ADAPTER_TAG , 'alias ' )]);
392393
394+ $ services
395+ ->set (FilesystemProvider::class)
396+ ->args ([tagged_locator (FilesystemProvider::FILESYSTEM_TAG , 'alias ' )]);
397+
393398 $ services
394399 ->set (FlysystemDataLoader::class)
395400 ->args (
You can’t perform that action at this time.
0 commit comments