* @author Kornel LesiƄski * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License * @version SVN: $Id: Node.php 610 2009-05-24 00:32:13Z kornel $ * @link http://phptal.org/ */ /** * Document node abstract class. * * @package PHPTAL * @subpackage Dom */ abstract class PHPTAL_Dom_Node { public $parentNode; private $value_escaped, $source_file, $source_line, $encoding; public function __construct($value_escaped, $encoding) { $this->value_escaped = $value_escaped; $this->encoding = $encoding; } /** * hint where this node is in source code */ public function setSource($file, $line) { $this->source_file = $file; $this->source_line = $line; } /** * file from which this node comes from */ public function getSourceFile() { return $this->source_file; } /** * line on which this node was defined */ public function getSourceLine() { return $this->source_line; } /** * depends on node type. Value will be escaped according to context that node comes from. */ function getValueEscaped() { return $this->value_escaped; } /** * get value as plain text. Depends on node type. */ function getValue() { return html_entity_decode($this->value_escaped,ENT_QUOTES, $this->encoding); } /** * encoding used by vaule of this node. */ public function getEncoding() { return $this->encoding; } /** * use CodeWriter to compile this element to PHP code */ public abstract function generateCode(PHPTAL_Php_CodeWriter $gen); /** * For backwards compatibility only! Do not use! * @deprecated */ public function generate() { $this->generateCode(self::$_codewriter_bc_hack_); } /** * @deprecated */ static $_codewriter_bc_hack_; /** * For backwards compatibility only * @deprecated */ function __get($prop) { if ($prop === 'children') return $this->childNodes; if ($prop === 'node') return $this; if ($prop === 'generator') return self::$_codewriter_bc_hack_; if ($prop === 'attributes') { $tmp = array(); foreach($this->getAttributeNodes() as $att) { $tmp[$att->getQualifiedName()] = $att->getValueEscaped(); } return $tmp; } throw new PHPTAL_Exception("There is no property $prop on ".get_class($this)); } /** * For backwards compatibility only * @deprecated */ function getName(){ return $this->getQualifiedName(); } }