Skip to content

Commit

Permalink
Merge pull request #777 from cedricziel/flysystemVisibility
Browse files Browse the repository at this point in the history
Add visibility argument to flysystem resolver
  • Loading branch information
lsmith77 authored Sep 2, 2016
2 parents 9246fd2 + b1335f8 commit 9da07e3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
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

0 comments on commit 9da07e3

Please sign in to comment.