// require_once PHPTAL_DIR.'PHPTAL/Dom/Node.php'; /** * Base class for all PHPTAL attributes. * * Attributes are first ordered by PHPTAL then called depending on their * priority before and after the element printing. * * An attribute must implements start() and end(). * * @package phptal.php * @author Laurent Bedubourg */ abstract class PHPTAL_Php_Attribute { const ECHO_TEXT = 'text'; const ECHO_STRUCTURE = 'structure'; /** Attribute name (ie: 'tal:content'). */ public $name; /** Attribute value specified by the element. */ public $expression; /** Element using this attribute (xml node). */ public $tag; /** Called before element printing. */ public abstract function start(); /** Called after element printing. */ public abstract function end(); /** * Remove structure|text keyword from expression and stores it for later * doEcho() usage. * * $expression = 'stucture my/path'; * $expression = $this->extractEchoType($expression); * * ... * * $this->doEcho($code); */ protected function extractEchoType($expression) { $echoType = self::ECHO_TEXT; $expression = trim($expression); if (preg_match('/^(text|structure)\s+(.*?)$/ism', $expression, $m)) { list(, $echoType, $expression) = $m; } $this->_echoType = strtolower($echoType); return trim($expression); } protected function doEcho($code) { if ($this->_echoType == self::ECHO_TEXT) $this->tag->generator->doEcho($code); else $this->tag->generator->doEchoRaw($code); } protected function parseSetExpression($exp) { $exp = trim($exp); // (dest) (value) if (preg_match('/^([a-z0-9:\-_]+)\s+(.*?)$/i', $exp, $m)){ array_shift($m); return $m; } // (dest) return array($exp, null); } protected $_echoType = PHPTAL_Php_Attribute::ECHO_TEXT; } ?>