Last active
August 29, 2015 14:16
-
-
Save jrenggli/d52582ed90eb5c10c83a to your computer and use it in GitHub Desktop.
Add timestamp to resource links in TYPO3 Flow. (Thanks to Sascha and Visay)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace WE\BaseBox\Aspects; | |
/* * | |
* This script belongs to the TYPO3 Flow package "WE.BaseBox". * | |
* * | |
* It is free software; you can redistribute it and/or modify it under * | |
* the terms of the GNU Lesser General Public License, either version 3 * | |
* of the License, or (at your option) any later version. * | |
* * | |
* The TYPO3 project - inspiring people to share! * | |
* */ | |
use TYPO3\Flow\Annotations as Flow; | |
/** | |
* @Flow\Aspect | |
*/ | |
class ResourceModificationTimeAspect { | |
/** | |
* @Flow\Around("method(TYPO3\Fluid\ViewHelpers\Uri\ResourceViewHelper->render())") | |
* @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current joinpoint | |
* @return string The result of the target method if it has not been intercepted | |
*/ | |
public function addModificationTime(\TYPO3\Flow\Aop\JoinPointInterface $joinPoint) { | |
$result = $joinPoint->getAdviceChain()->proceed($joinPoint); | |
if ($joinPoint->getMethodArgument('resource') !== NULL) { | |
return $result; | |
} | |
if (strpos($joinPoint->getMethodArgument('path'), 'resource://') === 0) { | |
$resourcePath = $joinPoint->getMethodArgument('path'); | |
} else if ($joinPoint->getMethodArgument('package') !== NULL) { | |
$resourcePath = 'resource://' . $joinPoint->getMethodArgument('package') . '/Public/' . $joinPoint->getMethodArgument('path'); | |
} else { | |
return $result; | |
} | |
if (!is_dir($resourcePath)) { | |
try { | |
if (strpos($result, '?') === FALSE) { | |
$result = $result . '?' . filemtime($resourcePath); | |
} else { | |
$result = $result . '&' . filemtime($resourcePath); | |
} | |
} catch (\Exception $e) { | |
} | |
} | |
return $result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment