diff --git a/app/config/services.yml b/app/config/services.yml index f15ca55..7238f1b 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -123,6 +123,8 @@ services: # Twig AppBundle\Twig\AppExtension: + arguments: + $webDir: "%kernel.root_dir%/../web" tags: - { name: twig.extension } diff --git a/src/AppBundle/Twig/AppExtension.php b/src/AppBundle/Twig/AppExtension.php index dd134a9..d5270dc 100644 --- a/src/AppBundle/Twig/AppExtension.php +++ b/src/AppBundle/Twig/AppExtension.php @@ -9,14 +9,18 @@ class AppExtension extends \Twig_Extension /** @var FormatTransformer */ private $formatTransformer; + /** @var string */ + private $webDir; + /** * AppExtension constructor. * * @param FormatTransformer $formatTransformer */ - public function __construct(FormatTransformer $formatTransformer) + public function __construct(FormatTransformer $formatTransformer, $webDir) { $this->formatTransformer = $formatTransformer; + $this->webDir = $webDir; } public function getFilters() @@ -75,11 +79,7 @@ class AppExtension extends \Twig_Extension public function fileTimestamp($filePath) { - $changeDate = filemtime($_SERVER['DOCUMENT_ROOT'].'/'.$filePath); - if (!$changeDate) { - //Fallback if mtime could not be found: - $changeDate = mktime(0, 0, 0, date('m'), date('d'), date('Y')); - } + $changeDate = filemtime($this->webDir.DIRECTORY_SEPARATOR.$filePath); return $filePath.'?'.$changeDate; }