protected function checkTTL($ttl)
 {
     $statements = array();
     if ($ttl !== null) {
         // Create the if statement that checks whether the cache file exists.
         $if = new ezcTemplateIfAstNode();
         $if->conditions[] = $cb = new ezcTemplateConditionBodyAstNode();
         $time = new ezcTemplateFunctionCallAstNode("time", array());
         $time->checkAndSetTypeHint();
         $cb->condition = new ezcTemplateLogicalAndOperatorAstNode(new ezcTemplateFunctionCallAstNode("file_exists", array(new ezcTemplateVariableAstNode("_ezcTemplateCache" . $this->cacheLevel))), new ezcTemplateLessThanOperatorAstNode(new ezcTemplateAdditionOperatorAstNode(new ezcTemplateFunctionCallAstNode("filemtime", array(new ezcTemplateVariableAstNode("_ezcTemplateCache" . $this->cacheLevel))), new ezcTemplateParenthesisAstNode($ttl)), $time));
         $cb->body = new ezcTemplateBodyAstNode();
         $cb->body->statements = array();
         $cb->body->statements[] = new ezcTemplateGenericStatementAstNode(new ezcTemplateFunctionCallAstNode("unlink", array(new ezcTemplateVariableAstNode("_ezcTemplateCache" . $this->cacheLevel))));
         $statements[] = $if;
     }
     return $statements;
 }
Esempio n. 2
0
 /**
  * Returns the corresponding AST tree to the function name $functionName and its parameters.
  *
  * The function name will, most likely, be translated from a Template function name to 
  * the PHP function. The parameters are ordered, if needed.
  *
  * @param string $functionName
  * @param array(ezcTemplateAstNode) $parameters 
  * @throws ezcTemplateException if the parameters are not valid (Too many, not enough parameters, etc).
  * @return ezcTemplateAstNode
  */
 public function getAstTree($functionName, $parameters)
 {
     // Try the built-in template functions.
     $class = $this->getClass($functionName);
     if ($class !== null) {
         $f = call_user_func(array($class, "getFunctionSubstitution"), $functionName, $parameters);
         if ($f !== null) {
             return $this->createAstNodes($functionName, $f, $parameters);
         }
     }
     // Try the custom template functions.
     $def = $this->getCustomFunction($functionName);
     if ($def !== false) {
         $reflectionParameters = $this->getReflectionParameters($def);
         $a = new ezcTemplateFunctionCallAstNode(($def->class ? $def->class . "::" : "") . $def->method);
         $a->checkAndSetTypeHint();
         if (isset($def->sendTemplateObject) && $def->sendTemplateObject) {
             array_shift($reflectionParameters);
             $a->appendParameter(new ezcTemplateVariableAstNode("this->template"));
         }
         $this->checkDefinition($def, $reflectionParameters);
         $this->checkGivenParameters($def, $reflectionParameters, $parameters, $functionName);
         $parameters = $this->orderParameters($reflectionParameters, $parameters, $functionName);
         foreach ($parameters as $p) {
             $a->appendParameter($p);
         }
         return $a;
     }
     throw new ezcTemplateException(sprintf(ezcTemplateSourceToTstErrorMessages::MSG_UNKNOWN_FUNCTION, $functionName));
 }