mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-17 15:03:25 +00:00
Use power of symfony binary file response
Add commands Fix typo Remove extra line
This commit is contained in:

committed by
Romain Neutron

parent
7fc9eb3010
commit
01a36ee9f7
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2013 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Event\Subscriber;
|
||||
|
||||
use Silex\Application;
|
||||
use Symfony\Component\HttpKernel\KernelEvents;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
|
||||
|
||||
class XSendFileSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
private $app;
|
||||
|
||||
public function __construct(Application $app)
|
||||
{
|
||||
$this->app = $app;
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents()
|
||||
{
|
||||
return array(
|
||||
KernelEvents::REQUEST => array('applyHeaders', 16),
|
||||
);
|
||||
}
|
||||
|
||||
public function applyHeaders(GetResponseEvent $event)
|
||||
{
|
||||
if ($this->app['phraseanet.configuration']['xsendfile']['enable']) {
|
||||
$request = $event->getRequest();
|
||||
$request->headers->set('X-Sendfile-Type', 'X-Accel-Redirect');
|
||||
$request->headers->set('X-Accel-Mapping', (string) $this->app['phraseanet.xsendfile-mapping']);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,47 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
* (c) 2005-2013 Alchemy
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Alchemy\Phrasea\Core\Provider;
|
||||
|
||||
use Alchemy\Phrasea\XSendFile\Mapping;
|
||||
use Alchemy\Phrasea\Exception\InvalidArgumentException;
|
||||
use Silex\Application;
|
||||
use Silex\ServiceProviderInterface;
|
||||
|
||||
class XSendFileMappingServiceProvider implements ServiceProviderInterface
|
||||
{
|
||||
public function register(Application $app)
|
||||
{
|
||||
if (!isset($app['xsendfile.mapping'])) {
|
||||
$app['xsendfile.mapping'] = array();
|
||||
}
|
||||
|
||||
if (!is_array($app['xsendfile.mapping'])) {
|
||||
throw new InvalidArgumentException('XSendFile mapping must be an array');
|
||||
}
|
||||
|
||||
$app['phraseanet.xsendfile-mapping'] = $app->share(function($app) {
|
||||
$mapping = array();
|
||||
foreach($app['xsendfile.mapping'] as $path => $mountPoint) {
|
||||
$mapping[] = array(
|
||||
'directory' => $path,
|
||||
'mount-point' => $mountPoint,
|
||||
);
|
||||
}
|
||||
|
||||
return Mapping::create($app, $mapping);
|
||||
});
|
||||
}
|
||||
|
||||
public function boot(Application $app)
|
||||
{
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user