AssetManager\View\Helper\Asset::__invoke PHP Method

__invoke() public method

Output the filepath with its unix modification time as query param
public __invoke ( string $filename ) : string
$filename string
return string
    public function __invoke($filename)
    {
        // nothing to append
        if (empty($this->config['view_helper']['append_timestamp'])) {
            return $filename;
        }
        // search the cache config for the specific file requested (if none, use the default one)
        if (isset($this->config['caching'][$filename])) {
            $cacheConfig = $this->config['caching'][$filename];
        } elseif (isset($this->config['caching']['default'])) {
            $cacheConfig = $this->config['caching']['default'];
        }
        // query string params
        $queryString = isset($this->config['view_helper']['query_string']) ? $this->config['view_helper']['query_string'] : '_';
        // no cache dir is defined
        if (!isset($cacheConfig['options']['dir'])) {
            // append current timestamp to the filepath and use a custom query string
            return $this->appendTimestamp($filename, $queryString);
        }
        // get the filePath from the cache (if available)
        $filePath = $this->getFilePathFromCache($filename, $queryString);
        if ($filePath !== null) {
            return $filePath;
        }
        return $this->elaborateFilePath($filename, $queryString);
    }

Usage Example

Esempio n. 1
0
 public function testSameResultWithoutCachingConfig()
 {
     $config = array('view_helper' => array('query_string' => '_', 'cache' => null));
     $filename = 'p**n-food/bac.on';
     $resolver = $this->getGenericResolver();
     $resolver->setMap(array('p**n-food/bac.on' => __FILE__));
     $helper = new Asset($resolver, null, $config);
     $newFilename = $helper->__invoke($filename);
     $this->assertSame($newFilename, $filename);
 }
All Usage Examples Of AssetManager\View\Helper\Asset::__invoke