2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
4 // Copyright (c) 2003 Laurent Bedubourg
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // Authors: Laurent Bedubourg <laurent.bedubourg@free.fr>
26 class PHPTAL_Macro
extends PHPTAL_Template
34 * @param PHPTAL_Template $caller
35 * The macro caller may be a template or a macro.
39 function PHPTAL_Macro(&$caller, $path)
43 // extract macro path part, if none found, we'll assume macro is
44 // in the caller template.
46 if (preg_match('/(.*?)\/([a-zA-Z0-9_]*?)$/', $this->_name
, $match)) {
47 list(, $this->_path
, $this->_name
) = $match;
49 $this->_sourceFile
= $caller->_sourceFile
;
52 // call parent constructor
53 $this->PHPTAL_Template($this->_path
,
57 $this->setParent($caller);
58 $this->setEncoding($caller->getEncoding());
62 * Execute macro with caller context.
68 if ($this->_path
!== false) {
69 $err = $this->_prepare();
70 if (PEAR
::isError($err)) {
74 return $this->_cacheManager
->macro($this,
77 $this->_parent
->getContext());
81 * Really process macro parsing/invocation.
87 if ($this->_path
!== false) {
88 $err = $this->_load();
89 if (PEAR
::isError($err)) {
93 $this->_funcName
= $this->_parent
->_funcName
;
96 $func = $this->_funcName
. '_' . $this->_name
;
98 if (!function_exists($func)) {
99 $err = "Unknown macro '$this->_name'";
100 return PEAR
::raiseError($err);
103 return $func($this->_parent
);