rm trailing white space
[mediawiki.git] / PHPTAL-NP-0.7.0 / libs / PHPTAL / Macro.php
blobfacdd0378043cb2e3abad7ba7b804199b809f53f
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4: */
3 //
4 // Copyright (c) 2003 Laurent Bedubourg
5 //
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.
10 //
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.
15 //
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
19 //
20 // Authors: Laurent Bedubourg <laurent.bedubourg@free.fr>
21 //
24 * Macro invoker.
26 class PHPTAL_Macro extends PHPTAL_Template
28 var $_path = false;
29 var $_name;
31 /**
32 * Macro constructor.
34 * @param PHPTAL_Template $caller
35 * The macro caller may be a template or a macro.
36 * @param string $path
37 * The macro path/name
39 function PHPTAL_Macro(&$caller, $path)
41 $this->_name = $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;
48 } else {
49 $this->_sourceFile = $caller->_sourceFile;
52 // call parent constructor
53 $this->PHPTAL_Template($this->_path,
54 $caller->_repository,
55 $caller->_cacheDir);
57 $this->setParent($caller);
58 $this->setEncoding($caller->getEncoding());
61 /**
62 * Execute macro with caller context.
64 * @return string
66 function execute()
68 if ($this->_path !== false) {
69 $err = $this->_prepare();
70 if (PEAR::isError($err)) {
71 return $err;
74 return $this->_cacheManager->macro($this,
75 $this->_sourceFile,
76 $this->_name,
77 $this->_parent->getContext());
80 /**
81 * Really process macro parsing/invocation.
83 * @return string
85 function _process()
87 if ($this->_path !== false) {
88 $err = $this->_load();
89 if (PEAR::isError($err)) {
90 return $err;
92 } else {
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);