Remove DeliverDataInterface::deliverData as never used

This commit is contained in:
Benoît Burnichon
2016-01-29 17:43:41 +01:00
parent 6fa37f3aee
commit ced5094355
4 changed files with 0 additions and 60 deletions

View File

@@ -69,19 +69,4 @@ trait DelivererAware
{ {
return $this->getDeliverer()->deliverFile($file, $filename, $disposition, $mimeType, $cacheDuration); return $this->getDeliverer()->deliverFile($file, $filename, $disposition, $mimeType, $cacheDuration);
} }
/**
* Return a HTTP Response ready to deliver data
*
* @param string $data
* @param string $filename
* @param string $mimeType
* @param string $disposition
* @param integer $cacheDuration
* @return Response
*/
public function deliverData($data, $filename, $mimeType, $disposition = DeliverDataInterface::DISPOSITION_INLINE, $cacheDuration = null)
{
return $this->getDeliverer()->deliverData($data, $filename, $disposition, $mimeType, $cacheDuration);
}
} }

View File

@@ -30,16 +30,4 @@ interface DeliverDataInterface
* @return Response * @return Response
*/ */
public function deliverFile($file, $filename = null, $disposition = self::DISPOSITION_INLINE, $mimeType = null, $cacheDuration = null); public function deliverFile($file, $filename = null, $disposition = self::DISPOSITION_INLINE, $mimeType = null, $cacheDuration = null);
/**
* Return a HTTP Response ready to deliver data
*
* @param string $data
* @param string $filename
* @param string $mimeType
* @param string $disposition
* @param integer $cacheDuration
* @return Response
*/
public function deliverData($data, $filename, $mimeType, $disposition = self::DISPOSITION_INLINE, $cacheDuration = null);
} }

View File

@@ -38,22 +38,6 @@ class ServeFileResponseFactory implements DeliverDataInterface
return $response; return $response;
} }
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) private function sanitizeFilename($filename)
{ {
return str_replace(['/', '\\'], '', $filename); return str_replace(['/', '\\'], '', $filename);

View File

@@ -139,21 +139,4 @@ class ServeFileResponseFactoryTest extends \PhraseanetWebTestCase
$this->assertEquals('attachment; filename="PhraseanetTestCase.php"', $response->headers->get('content-disposition')); $this->assertEquals('attachment; filename="PhraseanetTestCase.php"', $response->headers->get('content-disposition'));
$this->assertEquals(realpath($file), $response->headers->get('x-accel-redirect')); $this->assertEquals(realpath($file), $response->headers->get('x-accel-redirect'));
} }
public function testDeliverDatas()
{
$this->factory = new ServeFileResponseFactory(new \unicode());
$data = 'Sex,Name,Birthday
M,Alphonse,1932
F,Béatrice,1964
F,Charlotte,1988';
$response = $this->factory->deliverData($data, 'data.csv', 'text/csv', 'attachment');
$this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
$this->assertEquals('attachment; filename="data.csv"', $response->headers->get('content-disposition'));
$this->assertEquals('text/csv', $response->headers->get('content-type'));
$this->assertEquals($data, $response->getContent());
}
} }