From 88a2de5d00cb74afa0d3abdff5771c157638d71d Mon Sep 17 00:00:00 2001 From: povilas Date: Fri, 11 Jan 2013 17:40:42 +0200 Subject: [PATCH 1/3] [HttpFoundation] moved file hash calculation to own method --- .../Component/HttpFoundation/BinaryFileResponse.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php index a5c77f0ab7446..43dbeaaf1a015 100644 --- a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php +++ b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php @@ -22,6 +22,7 @@ * @author Igor Wiedler * @author Jordan Alliot * @author Sergey Linnik + * @author Povilas Skruibis */ class BinaryFileResponse extends Response { @@ -123,11 +124,21 @@ public function setAutoLastModified() */ public function setAutoEtag() { - $this->setEtag(sha1_file($this->file->getPathname())); + $this->setEtag($this->calculateFileHash()); return $this; } + /** + * Calculate file hash + * + * @return string + */ + protected function calculateFileHash() + { + return sha1_file($this->file->getPathname()); + } + /** * Sets the Content-Disposition header with the given filename. * From fec73080962ceaf3b03c1040dc384c8ecdf5e81c Mon Sep 17 00:00:00 2001 From: povilas Date: Wed, 16 Jan 2013 14:14:09 +0200 Subject: [PATCH 2/3] [HttpFoundation] inject file path as argument --- .../Component/HttpFoundation/BinaryFileResponse.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php index 43dbeaaf1a015..1490669ca0889 100644 --- a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php +++ b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php @@ -124,7 +124,8 @@ public function setAutoLastModified() */ public function setAutoEtag() { - $this->setEtag($this->calculateFileHash()); + $hash = $this->calculateFileHash($this->file->getPathname()); + $this->setEtag($hash); return $this; } @@ -132,11 +133,13 @@ public function setAutoEtag() /** * Calculate file hash * + * @param string $filename The path to the file + * * @return string */ - protected function calculateFileHash() + protected function calculateFileHash($filename) { - return sha1_file($this->file->getPathname()); + return sha1_file($filename); } /** From 75825c83b2d92782a26db8b7e1e9497384975656 Mon Sep 17 00:00:00 2001 From: povilas Date: Wed, 16 Jan 2013 17:41:31 +0200 Subject: [PATCH 3/3] [HttpFoundation] removed _one time_ variable --- src/Symfony/Component/HttpFoundation/BinaryFileResponse.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php index 1490669ca0889..61af1e4d99457 100644 --- a/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php +++ b/src/Symfony/Component/HttpFoundation/BinaryFileResponse.php @@ -124,8 +124,7 @@ public function setAutoLastModified() */ public function setAutoEtag() { - $hash = $this->calculateFileHash($this->file->getPathname()); - $this->setEtag($hash); + $this->setEtag($this->calculateFileHash($this->file->getPathname())); return $this; }