File size: 1,625 Bytes
cf14c12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php

declare(strict_types=1);

namespace Shared\Infrastructure\Bootstrappers;

use Application;
use Easy\Container\Attributes\Inject;
use Psr\Container\ContainerInterface;
use Shared\Infrastructure\BootstrapperInterface;
use Shared\Infrastructure\FileSystem\Adapters\LocalCdnAdapter;
use Shared\Infrastructure\FileSystem\Adapters\LocalFileSystemAdapter;
use Shared\Infrastructure\FileSystem\Cdn;
use Shared\Infrastructure\FileSystem\CdnAdapterCollection;
use Shared\Infrastructure\FileSystem\CdnAdapterCollectionInterface;
use Shared\Infrastructure\FileSystem\CdnInterface;
use Shared\Infrastructure\FileSystem\FileSystem;
use Shared\Infrastructure\FileSystem\FileSystemInterface;

class FileSystemBootstrapper implements BootstrapperInterface
{
    public function __construct(
        private Application $app,
        private ContainerInterface $container,

        #[Inject('config.dirs.root')]
        private string $rootDir,
    ) {
    }

    /** @inheritDoc */
    public function bootstrap(): void
    {
        $collection = new CdnAdapterCollection($this->container);
        $collection->add(LocalCdnAdapter::LOOKUP_KEY, LocalCdnAdapter::class);

        $this->app
            ->set(FileSystemInterface::class, $this->getFs())
            ->set(CdnAdapterCollectionInterface::class, $collection)
            ->set(CdnInterface::class, Cdn::class);
    }

    private function getFs(): FileSystemInterface
    {
        $adapter = new LocalFileSystemAdapter(
            $this->rootDir,
            linkHandling: LocalFilesystemAdapter::SKIP_LINKS,
        );

        return new FileSystem($adapter);
    }
}