summaryrefslogtreecommitdiff
path: root/lib/phptal/PHPTAL/NamespaceAttribute.php
blob: db1fd9563ad32bb3940a8a0b484b5af7280dfb52 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
 * PHPTAL templating engine
 *
 * PHP Version 5
 *
 * @category HTML
 * @package  PHPTAL
 * @author   Laurent Bedubourg <lbedubourg@motion-twin.com>
 * @author   Kornel Lesiński <kornel@aardvarkmedia.co.uk>
 * @license  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
 * @version  SVN: $Id$
 * @link     http://phptal.org/
 */

/**
 * Information about TAL attributes (in which order they are executed and how they generate the code)
 *
 * From http://dev.zope.org/Wikis/DevSite/Projects/ZPT/TAL%20Specification%201.4
 *
 * Order of Operations
 *
 * When there is only one TAL statement per element, the order in which
 * they are executed is simple. Starting with the root element, each
 * element's statements are executed, then each of its child elements is
 * visited, in order, to do the same.
 *
 * Any combination of statements may appear on the same elements, except
 * that the content and replace statements may not appear together.
 *
 * When an element has multiple statements, they are executed in this
 * order:
 *
 *     * define
 *     * condition
 *     * repeat
 *     * content or replace
 *     * attributes
 *     * omit-tag
 *
 * Since the on-error statement is only invoked when an error occurs, it
 * does not appear in the list.
 *
 * The reasoning behind this ordering goes like this: You often want to set
 * up variables for use in other statements, so define comes first. The
 * very next thing to do is decide whether this element will be included at
 * all, so condition is next; since the condition may depend on variables
 * you just set, it comes after define. It is valuable be able to replace
 * various parts of an element with different values on each iteration of a
 * repeat, so repeat is next. It makes no sense to replace attributes and
 * then throw them away, so attributes is last. The remaining statements
 * clash, because they each replace or edit the statement element.
 *
 * If you want to override this ordering, you must do so by enclosing the
 * element in another element, possibly div or span, and placing some of
 * the statements on this new element.
 *
 *
 * @package PHPTAL
 * @subpackage Namespace
 */
abstract class PHPTAL_NamespaceAttribute
{
    /** Attribute name without the namespace: prefix */
    private $local_name;

    /** [0 - 1000] */
    private $_priority;

    /** PHPTAL_Namespace */
    private $_namespace;

    /**
     * @param string $name The attribute name
     * @param int $priority Attribute execution priority
     */
    public function __construct($local_name, $priority)
    {
        $this->local_name = $local_name;
        $this->_priority = $priority;
    }

    /**
     * @return string
     */
    public function getLocalName()
    {
        return $this->local_name;
    }

    public function getPriority() { return $this->_priority; }
    public function getNamespace() { return $this->_namespace; }
    public function setNamespace(PHPTAL_Namespace $ns) { $this->_namespace = $ns; }

    public function createAttributeHandler(PHPTAL_Dom_Element $tag, $expression)
    {
        return $this->_namespace->createAttributeHandler($this, $tag, $expression);
    }
}