Exemple #1
0
 /**
  * Last update time.
  *
  * @param string $key
  * @return int
  */
 public function getTimestamp($key)
 {
     if (!$this->environment->cachable()) {
         //Always expired
         return 0;
     }
     if ($this->files->exists($key)) {
         return $this->files->time($key);
     }
     return 0;
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function generateKey($name, $className)
 {
     $hash = hash('md5', $className . '.' . $this->environment->getID());
     return $this->environment->cacheDirectory() . '/' . $hash[0] . $hash[1] . '/' . $hash . '.php';
 }
Exemple #3
0
 /**
  * Modify given source.
  *
  * @param string $source    Source.
  * @param string $namespace View namespace.
  * @param string $name      View name (no extension included).
  * @return mixed
  */
 public function modify($source, $namespace, $name)
 {
     return preg_replace_callback($this->pattern, function ($matches) {
         return $this->environment->getValue($matches[1]);
     }, $source);
 }
Exemple #4
0
 /**
  * {@inheritdoc}
  *
  * @return $this
  */
 public function setEnvironment(EnvironmentInterface $environment)
 {
     $this->environment = $environment;
     if (!$environment->cachable()) {
         $this->twig->setCache(false);
         return $this;
     }
     $this->twig->setCache(new TwigCache($this->files, $environment));
     return $this;
 }