Download src/Shared/Infrastructure/FileSystem/Cdn.php from pnacorp/AIKEEDO: direct link, hf CLI and curl.
- Browser
- Download file 1.82 kB
-
https://huggingface.co/pnacorp/AIKEEDO/resolve/main/src/Shared/Infrastructure/FileSystem/Cdn.php
- Command line
-
hf download hf://pnacorp/AIKEEDO/src/Shared/Infrastructure/FileSystem/Cdn.php
-
curl -L -o Cdn.php https://huggingface.co/pnacorp/AIKEEDO/resolve/main/src/Shared/Infrastructure/FileSystem/Cdn.php
1.82 kB
| declare(strict_types=1); | |
| namespace Shared\Infrastructure\FileSystem; | |
| use Easy\Container\Attributes\Inject; | |
| use League\Flysystem\Visibility; | |
| use Override; | |
| use Shared\Infrastructure\FileSystem\Adapters\CdnAdapterInterface; | |
| use Shared\Infrastructure\FileSystem\Adapters\LocalCdnAdapter; | |
| use Shared\Infrastructure\FileSystem\Exceptions\AdapterNotFoundException; | |
| class Cdn extends FileSystem implements CdnInterface | |
| { | |
| private CdnAdapterInterface $adapter; | |
| public function __construct( | |
| private CdnAdapterCollectionInterface $collection, | |
| #[Inject('option.cdn.adapter')] | |
| private ?string $adapterLookupKey = LocalCdnAdapter::LOOKUP_KEY | |
| ) { | |
| if (is_null($this->adapterLookupKey)) { | |
| $this->adapterLookupKey = LocalCdnAdapter::LOOKUP_KEY; | |
| } | |
| try { | |
| $this->adapter = $this->collection->get($this->adapterLookupKey); | |
| } catch (AdapterNotFoundException $th) { | |
| if ($adapterLookupKey == LocalCdnAdapter::LOOKUP_KEY) { | |
| throw $th; | |
| } | |
| $this->adapter = $this->collection->get(LocalCdnAdapter::LOOKUP_KEY); | |
| $this->adapterLookupKey = LocalCdnAdapter::LOOKUP_KEY; | |
| } | |
| parent::__construct($this->adapter); | |
| } | |
| public function getUrl(string $path): ?string | |
| { | |
| return $this->adapter->getUrl($path); | |
| } | |
| public function getAdapterLookupKey(): string | |
| { | |
| return $this->adapterLookupKey; | |
| } | |
| public function write( | |
| string $location, | |
| string $contents, | |
| array $config = [] | |
| ): void { | |
| if (!isset($config['visibility'])) { | |
| $config['visibility'] = Visibility::PUBLIC; | |
| } | |
| parent::write($location, $contents, $config); | |
| } | |
| } | |