- Added tests suite for haanga-cli.php
[haanga.git] / lib / tags.php
bloba69d104702222ececa36daadb5be7d921d7a5277
1 <?php
2 /*
3 +---------------------------------------------------------------------------------+
4 | Copyright (c) 2010 Haanga |
5 +---------------------------------------------------------------------------------+
6 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: |
8 | 1. Redistributions of source code must retain the above copyright |
9 | notice, this list of conditions and the following disclaimer. |
10 | |
11 | 2. Redistributions in binary form must reproduce the above copyright |
12 | notice, this list of conditions and the following disclaimer in the |
13 | documentation and/or other materials provided with the distribution. |
14 | |
15 | 3. All advertising materials mentioning features or use of this software |
16 | must display the following acknowledgement: |
17 | This product includes software developed by César D. Rodas. |
18 | |
19 | 4. Neither the name of the César D. Rodas nor the |
20 | names of its contributors may be used to endorse or promote products |
21 | derived from this software without specific prior written permission. |
22 | |
23 | THIS SOFTWARE IS PROVIDED BY CÉSAR D. RODAS ''AS IS'' AND ANY |
24 | EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
25 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
26 | DISCLAIMED. IN NO EVENT SHALL CÉSAR D. RODAS BE LIABLE FOR ANY |
27 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
29 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
30 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
31 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE |
33 +---------------------------------------------------------------------------------+
34 | Authors: César Rodas <crodas@php.net> |
35 +---------------------------------------------------------------------------------+
39 class Haanga_Tag extends Haanga_Extensions
41 /**
42 * isValid
44 * Check if the current $tag (string) is registered as a custom
45 * tag, if so, it check wether it is just a custom tag or a custom block.
47 * This method is called from the lexer for each alpha (within {% %}),
48 * to avoid parsing conflicts.
50 * @param string $tag Tag to check
52 * @return int|bool Parser::T_CUSTOM_TAG, Parser::T_CUSTOM_TAG or FALSE
54 final function isValid($tag)
56 static $cache = array();
57 $tag = strtolower($tag);
59 if (!isset($cache[$tag])) {
60 $file = $this->getFilePath($tag);
61 if (is_readable($file)) {
62 /* Load custom tag definition */
63 require_once $file;
64 $class_name = $this->getClassName($tag);
65 if (class_exists($class_name)) {
66 $properties = get_class_vars($class_name);
67 $is_block = FALSE;
68 if (isset($properties['is_block'])) {
69 $is_block = (bool)$properties['is_block'];
71 $cache[$tag] = $is_block ? Parser::T_CUSTOM_BLOCK : Parser::T_CUSTOM_TAG;
74 if (!isset($cache[$tag])) {
75 $cache[$tag] = FALSE;
79 return $cache[$tag];
82 final function getFilePath($file, $rel=TRUE)
84 return parent::getFilePath($file, $rel, 'tags');
87 final function getClassName($tag)
89 return "{$tag}_tag";
96 * Local variables:
97 * tab-width: 4
98 * c-basic-offset: 4
99 * End:
100 * vim600: sw=4 ts=4 fdm=marker
101 * vim<600: sw=4 ts=4