Last active
December 19, 2015 15:19
-
-
Save charlycoste/5975336 to your computer and use it in GitHub Desktop.
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 | |
class ezcMvcXsltViewHandler implements ezcMvcViewHandler | |
{ | |
/** | |
* Contains the template object | |
* | |
* @var XSLTProcessor | |
*/ | |
protected $template; | |
/** | |
* Contains the XSLT processor | |
* | |
* @var XSLTProcessor | |
*/ | |
protected $xslt; | |
/** | |
* Contains the zone name | |
* | |
* @var string | |
*/ | |
protected $zoneName; | |
/** | |
* Contains the result after process() has been called. | |
* | |
* @var mixed | |
*/ | |
protected $result; | |
/** | |
* Contains the path to the template file. | |
* | |
* @var string | |
*/ | |
protected $templateLocation; | |
/** | |
* Contains the DOM document | |
* | |
* @var XSLTProcessor | |
*/ | |
protected $dom; | |
/** | |
* Creates a new view handler, where $zoneName is the name of the block and | |
* $templateLocation the location of a view template. | |
* | |
* @param string $zoneName | |
* @param string $templateLocation | |
*/ | |
public function __construct( $zoneName, $templateLocation = null ) | |
{ | |
$this->zoneName = $zoneName; | |
$this->templateLocation = $templateLocation; | |
$this->xslt = new XSLTProcessor(); | |
$this->template = new ezcXslTemplate; | |
} | |
/** | |
* Adds a variable to the template, which can then be used for rendering | |
* the view. | |
* | |
* @param string $name | |
* @param mixed $value | |
*/ | |
public function send( $name, $value ) | |
{ | |
$this->dom = $value; | |
/* if( $name != $this->zoneName ) | |
{ | |
if( is_array($value) ) $value = '<ul><li>' . explode('</li><li>', $value) . '</li></ul>'; | |
$this->xslt->setParameter( '', $name, $value ); | |
} | |
else | |
{ | |
// $this->dom = DOMDocument::loadXML( $value ); | |
$this->dom = $value; | |
} | |
*/ | |
} | |
/** | |
* Processes the template with the variables added by the send() method. | |
* The result of this action should be retrievable through the getResult() method. | |
* | |
* The $last parameter is set if the view handler is the last one in the | |
* list of zones for a specific view. | |
* | |
* @param bool $last | |
*/ | |
public function process( $last ) | |
{ | |
if ( !file_exists( $this->templateLocation ) ) | |
{ | |
$fileName = ezcBaseFile::isAbsolutePath( $this->templateLocation ) ? $this->templateLocation : getcwd() . DIRECTORY_SEPARATOR . $this->templateLocation; | |
throw new ezcBaseFileNotFoundException( $fileName, 'xsl template' ); | |
} | |
$xsl = new DOMDocument('1.0', 'utf8'); | |
$xsl->load( $this->templateLocation ); | |
$this->xslt->importStylesheet( $xsl ); | |
$this->result = $this->xslt->transformToXML($this->dom); | |
} | |
/** | |
* Returns the value of the property $name. | |
* | |
* @throws ezcBasePropertyNotFoundException if the property does not exist. | |
* @param string $name | |
* @ignore | |
*/ | |
public function __get( $name ) | |
{ | |
return $this->xslt->getParameter( '', $name ); | |
} | |
/** | |
* Returns true if the property $name is set, otherwise false. | |
* | |
* @param string $name | |
* @return bool | |
* @ignore | |
*/ | |
public function __isset( $name ) | |
{ | |
return $this->xslt->getParameter( '', $name ) !== null; | |
} | |
/** | |
* Returns the name of the template, as set in the constructor. | |
* | |
* @return string | |
*/ | |
public function getName() | |
{ | |
return $this->zoneName; | |
} | |
/** | |
* Returns the result of the process() method. | |
* | |
* @return mixed | |
*/ | |
public function getResult() | |
{ | |
return $this->result; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment