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:
enabled: false
type: nginx
symlink-directory: ''
crossdomain:
site-control: 'master-only'
allow-access-from:

View File

@@ -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()
{

View File

@@ -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)
);
}

View File

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