properties[$name]; default: throw new ezcBasePropertyNotFoundException( $name ); } } /** * Property set */ public function __set( $name, $value ) { switch ( $name ) { case 'context': if ( $value !== null and !( $value instanceof ezcTemplateOutputContext ) ) throw new ezcBaseValueException( $name, $value, 'ezcTemplateOutputContext' ); $this->properties[$name] = $value; break; case 'template': if ( $value !== null and !( $value instanceof ezcTemplate ) ) throw new ezcBaseValueException( $name, $value, 'ezcTemplate' ); $this->properties[$name] = $value; break; case 'identifier': case 'path': throw new ezcBasePropertyPermissionException( $name, ezcBasePropertyPermissionException::READ ); default: throw new ezcBasePropertyNotFoundException( $name ); } } /** * Property isset */ public function __isset( $name ) { switch ( $name ) { case 'identifier': case 'path': case 'context': case 'template': return true; default: return false; } } /** * Initialises the object with the identifier and the full path to the PHP file. * * @param string $identifier * @param string $path */ public function __construct( $identifier, $path, /*ezcTemplateOutputContext*/ $context = null, ezcTemplate $template = null ) { $this->properties['identifier'] = $identifier; $this->properties['path'] = $path; $this->context = $context; $this->template = $template; } /** * Executes the current compiled file using the source object. * * The input template variables is taken from the template. * * @throws ezcTemplateNoManagerException if there is no template set. * @throws ezcTemplateNoOutputContextException if there is no output context set. * @throws ezcTemplateInvalidCompiledFileException if the compiled cannot be executed. */ public function execute() { if ( $this->template === null ) throw new ezcTemplateNoManagerException( __CLASS__, 'template' ); if ( $this->context === null ) throw new ezcTemplateNoOutputContextException( __CLASS__, 'context' ); if ( !$this->isValid() ) throw new ezcTemplateInvalidCompiledFileException( $this->identifier, $this->path ); $this->send = clone $this->template->send; $this->receive = $this->template->receive; return include( $this->path ); } /** * Returns a list of variable (PHP) names which are reserved when executing * compiled code. The compiler must make sure none of these are used when * generating local PHP variables. * * @return array */ public static function reservedVariableNames() { return array( 'template', 'context', 'execution', 'this' ); } /** * Returns true if the compiled code exists and is valid for execution. * * @return bool */ public function isValid() { return file_exists( $this->path ) and is_readable( $this->path ); } /** * Returns true if the compiled code exists on the filesystem. * * @return bool */ public function isAvailable() { return file_exists( $this->path ); } /** * Finds the compiled file based on the stream path and template options. * * Returns the compiled code object which can be used for execution or queried for more info. * * @param string $location The stream path of the requested template file. * @param ezcTemplateOutputContext $context The current output context handler. * @param ezcTemplateManager $template The template which contains the current settings. * @return ezcTemplateCompiledCode */ public static function findCompiled( $location, ezcTemplateOutputContext $context, ezcTemplate $template ) { $options = 'ezcTemplate::options(' . false /*(bool)$template->outputDebugEnabled*/ . '-' . false /*(bool)$template->compiledDebugEnabled*/ . ')'; $identifier = md5( 'ezcTemplateCompiledCode(' . $location . ')' ); $name = basename( $location, '.ezt' ); $path = $template->configuration->compilePath . '/' . $context->identifier() . '-' . $template->generateOptionHash() . '/' . $name . '-' . $identifier . ".php"; return new ezcTemplateCompiledCode( $identifier, $path, $context, $template ); } } ?>