Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/contracts/Test/IbexaTestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
use Ibexa\Contracts\Core\Persistence\TransactionHandler;
use Ibexa\Contracts\Core\Repository;
use Ibexa\Contracts\Core\Test\Persistence\Fixture\YamlFixture;
use Ibexa\Core\IO\Flysystem\Adapter\LocalSiteAccessAwareFilesystemAdapter;
use JMS\TranslationBundle\JMSTranslationBundle;
use League\Flysystem\InMemory\InMemoryFilesystemAdapter;
use Liip\ImagineBundle\LiipImagineBundle;
Expand Down Expand Up @@ -218,7 +217,7 @@ private static function prepareIOServices(ContainerBuilder $container): void
}

$container->setDefinition(
LocalSiteAccessAwareFilesystemAdapter::class,
'ibexa.core.io.flysystem.adapter.site_access_aware',
new Definition(InMemoryFilesystemAdapter::class)
);
}
Expand Down
150 changes: 150 additions & 0 deletions src/lib/IO/Flysystem/Adapter/DynamicPathFilesystemAdapterDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Core\IO\Flysystem\Adapter;

use Ibexa\Core\IO\Flysystem\PathPrefixer\PathPrefixerInterface;
use League\Flysystem\Config;
use League\Flysystem\FileAttributes;
use League\Flysystem\FilesystemAdapter;

/***
* @internal
*/
final class DynamicPathFilesystemAdapterDecorator implements FilesystemAdapter
{
private FilesystemAdapter $innerAdapter;

private PathPrefixerInterface $prefixer;

public function __construct(FilesystemAdapter $innerAdapter, PathPrefixerInterface $prefixer)
{
$this->innerAdapter = $innerAdapter;
$this->prefixer = $prefixer;
}

public function fileExists(string $path): bool
{
$path = $this->prefixer->prefixPath($path);

return $this->innerAdapter->fileExists($path);
}

public function write(string $path, string $contents, Config $config): void
{
$path = $this->prefixer->prefixPath($path);

$this->innerAdapter->write($path, $contents, $config);
}

public function writeStream(string $path, $contents, Config $config): void
{
$path = $this->prefixer->prefixPath($path);

$this->innerAdapter->writeStream($path, $contents, $config);
}

public function read(string $path): string
{
$path = $this->prefixer->prefixPath($path);

return $this->innerAdapter->read($path);
}

public function readStream(string $path)
{
$path = $this->prefixer->prefixPath($path);

return $this->innerAdapter->readStream($path);
}

public function delete(string $path): void
{
$path = $this->prefixer->prefixPath($path);

$this->innerAdapter->delete($path);
}

public function deleteDirectory(string $path): void
{
$path = $this->prefixer->prefixPath($path);

$this->innerAdapter->deleteDirectory($path);
}

public function createDirectory(string $path, Config $config): void
{
$path = $this->prefixer->prefixPath($path);

$this->innerAdapter->createDirectory($path, $config);
}

public function setVisibility(string $path, string $visibility): void
{
$path = $this->prefixer->prefixPath($path);

$this->innerAdapter->setVisibility($path, $visibility);
}

public function visibility(string $path): FileAttributes
{
$path = $this->prefixer->prefixPath($path);

return $this->innerAdapter->visibility($path);
}

public function mimeType(string $path): FileAttributes
{
$path = $this->prefixer->prefixPath($path);

return $this->innerAdapter->mimeType($path);
}

public function lastModified(string $path): FileAttributes
{
$path = $this->prefixer->prefixPath($path);

return $this->innerAdapter->lastModified($path);
}

public function fileSize(string $path): FileAttributes
{
$path = $this->prefixer->prefixPath($path);

return $this->innerAdapter->fileSize($path);
}

public function listContents(string $path, bool $deep): iterable
{
$path = $this->prefixer->prefixPath($path);

foreach ($this->innerAdapter->listContents($path, $deep) as $storageAttributes) {
$itemPath = $this->prefixer->stripPrefix($storageAttributes->path());

yield $storageAttributes->withPath($itemPath);
}

yield from [];
}

public function move(string $source, string $destination, Config $config): void
{
$source = $this->prefixer->prefixPath($source);
$destination = $this->prefixer->prefixPath($destination);

$this->innerAdapter->move($source, $destination, $config);
}

public function copy(string $source, string $destination, Config $config): void
{
$sourcePath = $this->prefixer->prefixPath($source);
$destinationPath = $this->prefixer->prefixPath($destination);

$this->innerAdapter->copy($sourcePath, $destinationPath, $config);
}
}
Loading