mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-11 03:53:13 +00:00

Conflicts: composer.lock lib/Alchemy/Phrasea/Application.php lib/Alchemy/Phrasea/Command/Setup/H264MappingGenerator.php lib/Alchemy/Phrasea/Controller/AbstractDelivery.php lib/Alchemy/Phrasea/Controller/Prod/DoDownload.php lib/Alchemy/Phrasea/Controller/Prod/Edit.php lib/Alchemy/Phrasea/Controller/Prod/Story.php lib/Alchemy/Phrasea/Controller/Prod/Upload.php lib/Alchemy/Phrasea/Controller/Report/Activity.php lib/Alchemy/Phrasea/Controller/Report/Root.php lib/Alchemy/Phrasea/Controller/Root/Account.php lib/Alchemy/Phrasea/Core/PhraseaEvents.php lib/Alchemy/Phrasea/Core/Version.php lib/classes/API/V1/adapter.php lib/classes/User/Adapter.php lib/classes/databox.php lib/classes/media/subdef.php lib/classes/module/report.php lib/classes/module/report/activity.php lib/classes/module/report/connexion.php lib/classes/module/report/download.php lib/classes/module/report/nav.php lib/classes/module/report/question.php lib/classes/module/report/sqlaction.php lib/classes/module/report/sqlconnexion.php lib/classes/module/report/sqldownload.php lib/classes/module/report/sqlfilter.php lib/classes/task/abstract.php locale/de_DE/LC_MESSAGES/phraseanet.mo locale/de_DE/LC_MESSAGES/phraseanet.po locale/en_GB/LC_MESSAGES/phraseanet.mo locale/en_GB/LC_MESSAGES/phraseanet.po locale/fr_FR/LC_MESSAGES/phraseanet.mo locale/fr_FR/LC_MESSAGES/phraseanet.po locale/nl_NL/LC_MESSAGES/phraseanet.mo locale/nl_NL/LC_MESSAGES/phraseanet.po locale/phraseanet.pot templates/web/prod/index.html.twig tests/Alchemy/Tests/Phrasea/Application/ApiAbstract.php tests/classes/api/v1/api_v1_adapterTest.php tests/classes/report/activityTest.php tests/classes/report/editTest.php
85 lines
2.2 KiB
PHP
85 lines
2.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* This file is part of Phraseanet
|
|
*
|
|
* (c) 2005-2014 Alchemy
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Alchemy\Phrasea\Http;
|
|
|
|
use Alchemy\Phrasea\Application;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
|
|
|
class ServeFileResponseFactory implements DeliverDataInterface
|
|
{
|
|
private $unicode;
|
|
|
|
public function __construct(\unicode $unicode)
|
|
{
|
|
$this->unicode = $unicode;
|
|
}
|
|
|
|
/**
|
|
* @param Application $app
|
|
* @return self
|
|
*/
|
|
public static function create(Application $app)
|
|
{
|
|
return new self(
|
|
$app['unicode']
|
|
);
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function deliverFile($file, $filename = '', $disposition = self::DISPOSITION_INLINE, $mimeType = null, $cacheDuration = null)
|
|
{
|
|
$response = new BinaryFileResponse($file);
|
|
$response->setContentDisposition($disposition, $this->sanitizeFilename($filename), $this->sanitizeFilenameFallback($filename));
|
|
if (null !== $cacheDuration) {
|
|
$response->setMaxAge($cacheDuration);
|
|
}
|
|
|
|
if (null !== $mimeType) {
|
|
$response->headers->set('Content-Type', $mimeType);
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function deliverData($data, $filename, $mimeType, $disposition = self::DISPOSITION_INLINE, $cacheDuration = null)
|
|
{
|
|
$response = new Response($data);
|
|
$response->headers->set('Content-Disposition', $response->headers->makeDisposition(
|
|
$disposition,
|
|
$this->sanitizeFilename($filename),
|
|
$this->sanitizeFilenameFallback($filename
|
|
)));
|
|
$response->headers->set('Content-Type', $mimeType);
|
|
if (null !== $cacheDuration) {
|
|
$response->setMaxAge($cacheDuration);
|
|
}
|
|
|
|
return $response;
|
|
}
|
|
|
|
private function sanitizeFilename($filename)
|
|
{
|
|
return str_replace(['/', '\\'], '', $filename);
|
|
}
|
|
|
|
private function sanitizeFilenameFallback($filename)
|
|
{
|
|
return $this->unicode->remove_nonazAZ09($filename, true, true, true);
|
|
}
|
|
}
|