From df013d4f21c14849f3a0a46748929375289a4337 Mon Sep 17 00:00:00 2001 From: Nicolas Le Goff Date: Wed, 28 May 2014 13:02:10 +0200 Subject: [PATCH] Allow to specify symlink directory --- config/configuration.sample.yml | 1 + .../Http/StaticFile/StaticFileFactory.php | 21 +++++++++------- .../Http/StaticFile/Symlink/SymLinker.php | 25 +++++++++++-------- lib/conf.d/configuration.yml | 2 +- 4 files changed, 28 insertions(+), 21 deletions(-) diff --git a/config/configuration.sample.yml b/config/configuration.sample.yml index 195e68d419..5402a00fe6 100644 --- a/config/configuration.sample.yml +++ b/config/configuration.sample.yml @@ -162,6 +162,7 @@ session: static-file: enabled: false type: nginx + symlink-directory: '' crossdomain: site-control: 'master-only' allow-access-from: diff --git a/lib/Alchemy/Phrasea/Http/StaticFile/StaticFileFactory.php b/lib/Alchemy/Phrasea/Http/StaticFile/StaticFileFactory.php index a11e566165..0af3339f11 100644 --- a/lib/Alchemy/Phrasea/Http/StaticFile/StaticFileFactory.php +++ b/lib/Alchemy/Phrasea/Http/StaticFile/StaticFileFactory.php @@ -21,15 +21,16 @@ class StaticFileFactory private $enabled; private $logger; private $type; + /** @var Symlink\SymLinker */ private $symlinker; /** * Constructor * * @param LoggerInterface $logger - * @param boolean $enabled + * @param bool $enabled * @param string $type - * @param array $symlinker + * @param SymLinker $symlinker */ public function __construct(LoggerInterface $logger, $enabled, $type, SymLinker $symlinker) { @@ -40,16 +41,16 @@ class StaticFileFactory $this->mapping = array( 'mount-point' => $symlinker->getDefaultAlias(), - 'directory' => $symlinker->getPublicDir() + 'directory' => $symlinker->getSymlinkDir() ); } /** - * Creates a new instance of XSendFile Factory according to the application + * Creates a new instance of StaticFileFactory Factory according to the application * configuration. * * @param Application $app - * @return XSendFileFactory + * @return StaticFileFactory */ public static function create(Application $app) { @@ -59,11 +60,13 @@ class StaticFileFactory } /** - * Returns a new instance of ModeInterface. + * Returns a new instance of ModeInterface * - * @return ModeInterface + * @param bool $throwException + * @param bool $forceMode * - * @throws InvalidArgumentException if mode type is unknown + * @return Apache|Nginx|NullMode + * @throws InvalidArgumentException */ public function getMode($throwException = false, $forceMode = false) { @@ -92,7 +95,7 @@ class StaticFileFactory } /** - * @return Boolean + * @return bool */ public function isStaticFileModeEnabled() { diff --git a/lib/Alchemy/Phrasea/Http/StaticFile/Symlink/SymLinker.php b/lib/Alchemy/Phrasea/Http/StaticFile/Symlink/SymLinker.php index 87b53f3d7f..f0f1f6f7c1 100644 --- a/lib/Alchemy/Phrasea/Http/StaticFile/Symlink/SymLinker.php +++ b/lib/Alchemy/Phrasea/Http/StaticFile/Symlink/SymLinker.php @@ -11,22 +11,23 @@ namespace Alchemy\Phrasea\Http\StaticFile\Symlink; +use Alchemy\Phrasea\Exception\InvalidArgumentException; use Silex\Application; use Symfony\Component\Filesystem\Filesystem; use Guzzle\Http\Url; /** - * Create & retrieve symlinks from public directory + * Create & retrieve symlinks */ class SymLinker { + /** Mount Point Alias Name */ const ALIAS = 'thumb'; protected $encoder; protected $fs; - protected $publicDir; + protected $symlinkDir; protected $registry; - protected $rootPath; public static function create(Application $app) { @@ -34,22 +35,24 @@ class SymLinker $app['phraseanet.thumb-symlinker-encoder'], $app['filesystem'], $app['phraseanet.registry'], - $app['root.path'] + isset($app['phraseanet.configuration']['static-file']['symlink-directory']) ? $app['phraseanet.configuration']['static-file']['symlink-directory'] : null ); } - public function __construct(SymLinkerEncoder $encoder, Filesystem $fs, \registryInterface $registry, $rootPath) + public function __construct(SymLinkerEncoder $encoder, Filesystem $fs, \registryInterface $registry, $symlinkDir) { $this->encoder = $encoder; $this->fs = $fs; - $this->registry = $registry; - $this->rootPath = $rootPath; - $this->publicDir = sprintf('%s/public/thumbnails', rtrim($this->rootPath, '/')); + + if (!$symlinkDir) { + throw new InvalidArgumentException("Symlink directory is not defined"); + } + $this->symlinkDir = rtrim($symlinkDir, '/'); } - public function getPublicDir() + public function getSymlinkDir() { - return $this->publicDir; + return $this->symlinkDir; } public function getDefaultAlias() @@ -82,7 +85,7 @@ class SymLinker { return sprintf( '%s/%s', - $this->publicDir, + $this->symlinkDir, $this->getSymlinkBasePath($pathFile) ); } diff --git a/lib/conf.d/configuration.yml b/lib/conf.d/configuration.yml index 7b5b1ac4f8..3f5dfc2cac 100644 --- a/lib/conf.d/configuration.yml +++ b/lib/conf.d/configuration.yml @@ -165,8 +165,8 @@ session: lifetime: 604800 static-file: enabled: false - # 1 week type: nginx + symlink-directory: '' crossdomain: allow-access-from: -