1
0
mirror of https://github.com/ToxicCrack/PrintABrick.git synced 2025-05-18 05:10:07 -07:00

Fix file timestamp

This commit is contained in:
Unknown 2017-06-08 22:58:47 +02:00
parent 6685658a89
commit a7f11179c9
2 changed files with 8 additions and 6 deletions

View File

@ -123,6 +123,8 @@ services:
# Twig # Twig
AppBundle\Twig\AppExtension: AppBundle\Twig\AppExtension:
arguments:
$webDir: "%kernel.root_dir%/../web"
tags: tags:
- { name: twig.extension } - { name: twig.extension }

View File

@ -9,14 +9,18 @@ class AppExtension extends \Twig_Extension
/** @var FormatTransformer */ /** @var FormatTransformer */
private $formatTransformer; private $formatTransformer;
/** @var string */
private $webDir;
/** /**
* AppExtension constructor. * AppExtension constructor.
* *
* @param FormatTransformer $formatTransformer * @param FormatTransformer $formatTransformer
*/ */
public function __construct(FormatTransformer $formatTransformer) public function __construct(FormatTransformer $formatTransformer, $webDir)
{ {
$this->formatTransformer = $formatTransformer; $this->formatTransformer = $formatTransformer;
$this->webDir = $webDir;
} }
public function getFilters() public function getFilters()
@ -75,11 +79,7 @@ class AppExtension extends \Twig_Extension
public function fileTimestamp($filePath) public function fileTimestamp($filePath)
{ {
$changeDate = filemtime($_SERVER['DOCUMENT_ROOT'].'/'.$filePath); $changeDate = filemtime($this->webDir.DIRECTORY_SEPARATOR.$filePath);
if (!$changeDate) {
//Fallback if mtime could not be found:
$changeDate = mktime(0, 0, 0, date('m'), date('d'), date('Y'));
}
return $filePath.'?'.$changeDate; return $filePath.'?'.$changeDate;
} }