Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add visibility argument to flysystem resolver #777

Merged
merged 1 commit into from
Sep 2, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public function create(ContainerBuilder $container, $resolverName, array $config
$resolverDefinition->replaceArgument(0, new Reference($config['filesystem_service']));
$resolverDefinition->replaceArgument(2, $config['root_url']);
$resolverDefinition->replaceArgument(3, $config['cache_prefix']);
$resolverDefinition->addArgument($config['visibility']);
$resolverDefinition->addTag('liip_imagine.cache.resolver', array(
'resolver' => $resolverName,
));
Expand Down Expand Up @@ -46,6 +47,7 @@ public function addConfiguration(ArrayNodeDefinition $builder)
->scalarNode('filesystem_service')->isRequired()->cannotBeEmpty()->end()
->scalarNode('cache_prefix')->defaultValue(null)->end()
->scalarNode('root_url')->isRequired()->cannotBeEmpty()->end()
->enumNode('visibility')->values(array('public', 'private'))->defaultValue('public')->end()
->end()
;
}
Expand Down
22 changes: 18 additions & 4 deletions Imagine/Cache/Resolver/FlysystemResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Liip\ImagineBundle\Imagine\Cache\Resolver;

use League\Flysystem\AdapterInterface;
use League\Flysystem\Filesystem;
use Liip\ImagineBundle\Binary\BinaryInterface;
use Liip\ImagineBundle\Exception\Imagine\Cache\Resolver\NotResolvableException;
Expand Down Expand Up @@ -34,26 +35,38 @@ class FlysystemResolver implements ResolverInterface
*/
protected $cacheRoot;

/**
* Flysystem specific visibility.
*
* @see AdapterInterface
*
* @var string
*/
protected $visibility;

/**
* FlysystemResolver constructor.
*
* @param Filesystem $flysystem
* @param RequestContext $requestContext
* @param $rootUrl
* @param string $cachePrefix
* @param string $rootUrl
* @param string $cachePrefix
* @param string $visibility
*/
public function __construct(
Filesystem $flysystem,
RequestContext $requestContext,
$rootUrl,
$cachePrefix = 'media/cache'
$cachePrefix = 'media/cache',
$visibility = AdapterInterface::VISIBILITY_PUBLIC
) {
$this->flysystem = $flysystem;
$this->requestContext = $requestContext;

$this->webRoot = rtrim($rootUrl, '/');
$this->cachePrefix = ltrim(str_replace('//', '/', $cachePrefix), '/');
$this->cacheRoot = $this->cachePrefix;
$this->visibility = $visibility;
}

/**
Expand Down Expand Up @@ -118,7 +131,8 @@ public function store(BinaryInterface $binary, $path, $filter)
{
$this->flysystem->put(
$this->getFilePath($path, $filter),
$binary->getContent()
$binary->getContent(),
['visibility' => $this->visibility]
);
}

Expand Down
6 changes: 6 additions & 0 deletions Resources/doc/cache-resolver/flysystem.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Create resolver
filesystem_service: oneup_flysystem.profile_photos_filesystem
root_url: http://images.example.com
cache_prefix: media/cache
visibility: public
oneup_flysystem:
adapters:
profile_photos:
Expand All @@ -39,6 +40,11 @@ There are several configuration options available:
* ``cache_prefix`` - this is used for the image path generation. This will be the
prefix inside the given Flysystem.
Default value: ``media/cache``
* ``visibility`` - one of the two predefined flysystem visibility constants
(``AdapterInterface::VISIBILITY_PUBLIC`` [``public``] / ``AdapterInterface::VISIBILITY_PRIVATE`` [``private``])
The visibility is applied, when the objects are stored on a flysystem filesystem.
You will most probably want to leave the default or explicitly set ``public``.
Default value: ``public``

Usage
-----
Expand Down