Allow to specify symlink directory

This commit is contained in:
Nicolas Le Goff
2014-05-28 13:02:10 +02:00
parent e72a8ebda3
commit df013d4f21
4 changed files with 28 additions and 21 deletions

View File

@@ -162,6 +162,7 @@ session:
static-file: static-file:
enabled: false enabled: false
type: nginx type: nginx
symlink-directory: ''
crossdomain: crossdomain:
site-control: 'master-only' site-control: 'master-only'
allow-access-from: allow-access-from:

View File

@@ -21,15 +21,16 @@ class StaticFileFactory
private $enabled; private $enabled;
private $logger; private $logger;
private $type; private $type;
/** @var Symlink\SymLinker */
private $symlinker; private $symlinker;
/** /**
* Constructor * Constructor
* *
* @param LoggerInterface $logger * @param LoggerInterface $logger
* @param boolean $enabled * @param bool $enabled
* @param string $type * @param string $type
* @param array $symlinker * @param SymLinker $symlinker
*/ */
public function __construct(LoggerInterface $logger, $enabled, $type, SymLinker $symlinker) public function __construct(LoggerInterface $logger, $enabled, $type, SymLinker $symlinker)
{ {
@@ -40,16 +41,16 @@ class StaticFileFactory
$this->mapping = array( $this->mapping = array(
'mount-point' => $symlinker->getDefaultAlias(), '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. * configuration.
* *
* @param Application $app * @param Application $app
* @return XSendFileFactory * @return StaticFileFactory
*/ */
public static function create(Application $app) 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) public function getMode($throwException = false, $forceMode = false)
{ {
@@ -92,7 +95,7 @@ class StaticFileFactory
} }
/** /**
* @return Boolean * @return bool
*/ */
public function isStaticFileModeEnabled() public function isStaticFileModeEnabled()
{ {

View File

@@ -11,22 +11,23 @@
namespace Alchemy\Phrasea\Http\StaticFile\Symlink; namespace Alchemy\Phrasea\Http\StaticFile\Symlink;
use Alchemy\Phrasea\Exception\InvalidArgumentException;
use Silex\Application; use Silex\Application;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Guzzle\Http\Url; use Guzzle\Http\Url;
/** /**
* Create & retrieve symlinks from public directory * Create & retrieve symlinks
*/ */
class SymLinker class SymLinker
{ {
/** Mount Point Alias Name */
const ALIAS = 'thumb'; const ALIAS = 'thumb';
protected $encoder; protected $encoder;
protected $fs; protected $fs;
protected $publicDir; protected $symlinkDir;
protected $registry; protected $registry;
protected $rootPath;
public static function create(Application $app) public static function create(Application $app)
{ {
@@ -34,22 +35,24 @@ class SymLinker
$app['phraseanet.thumb-symlinker-encoder'], $app['phraseanet.thumb-symlinker-encoder'],
$app['filesystem'], $app['filesystem'],
$app['phraseanet.registry'], $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->encoder = $encoder;
$this->fs = $fs; $this->fs = $fs;
$this->registry = $registry;
$this->rootPath = $rootPath; if (!$symlinkDir) {
$this->publicDir = sprintf('%s/public/thumbnails', rtrim($this->rootPath, '/')); 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() public function getDefaultAlias()
@@ -82,7 +85,7 @@ class SymLinker
{ {
return sprintf( return sprintf(
'%s/%s', '%s/%s',
$this->publicDir, $this->symlinkDir,
$this->getSymlinkBasePath($pathFile) $this->getSymlinkBasePath($pathFile)
); );
} }

View File

@@ -165,8 +165,8 @@ session:
lifetime: 604800 lifetime: 604800
static-file: static-file:
enabled: false enabled: false
# 1 week
type: nginx type: nginx
symlink-directory: ''
crossdomain: crossdomain:
allow-access-from: allow-access-from:
- -