1<?php 2declare(strict_types=1); 3 4/** 5 * PHPTAL templating engine 6 * 7 * @category HTML 8 * @package PHPTAL 9 * @author Laurent Bedubourg <lbedubourg@motion-twin.com> 10 * @author Kornel Lesiński <kornel@aardvarkmedia.co.uk> 11 * @license http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License 12 * @link http://phptal.org/ 13 */ 14 15namespace PhpTal; 16 17/** 18 * Information about TAL attributes (in which order they are executed and how they generate the code) 19 * 20 * From http://dev.zope.org/Wikis/DevSite/Projects/ZPT/TAL%20Specification%201.4 21 * 22 * Order of Operations 23 * 24 * When there is only one TAL statement per element, the order in which 25 * they are executed is simple. Starting with the root element, each 26 * element's statements are executed, then each of its child elements is 27 * visited, in order, to do the same. 28 * 29 * Any combination of statements may appear on the same elements, except 30 * that the content and replace statements may not appear together. 31 * 32 * When an element has multiple statements, they are executed in this 33 * order: 34 * 35 * * define 36 * * condition 37 * * repeat 38 * * content or replace 39 * * attributes 40 * * omit-tag 41 * 42 * Since the on-error statement is only invoked when an error occurs, it 43 * does not appear in the list. 44 * 45 * The reasoning behind this ordering goes like this: You often want to set 46 * up variables for use in other statements, so define comes first. The 47 * very next thing to do is decide whether this element will be included at 48 * all, so condition is next; since the condition may depend on variables 49 * you just set, it comes after define. It is valuable be able to replace 50 * various parts of an element with different values on each iteration of a 51 * repeat, so repeat is next. It makes no sense to replace attributes and 52 * then throw them away, so attributes is last. The remaining statements 53 * clash, because they each replace or edit the statement element. 54 * 55 * If you want to override this ordering, you must do so by enclosing the 56 * element in another element, possibly div or span, and placing some of 57 * the statements on this new element. 58 * 59 * 60 * @package PHPTAL 61 */ 62abstract class TalNamespaceAttribute 63{ 64 /** 65 * @var string Attribute name without the namespace: prefix 66 */ 67 private $local_name; 68 69 /** 70 * @var int [0 - 1000] 71 */ 72 private $priority; 73 74 /** 75 * @var TalNamespace 76 */ 77 private $namespace; 78 79 /** 80 * @param string $local_name The attribute name 81 * @param int $priority Attribute execution priority 82 */ 83 public function __construct(string $local_name, int $priority) 84 { 85 $this->local_name = $local_name; 86 $this->priority = $priority; 87 } 88 89 /** 90 * @return string 91 */ 92 public function getLocalName(): string 93 { 94 return $this->local_name; 95 } 96 97 /** 98 * @return int 99 */ 100 public function getPriority(): int 101 { 102 return $this->priority; 103 } 104 105 /** 106 * @return TalNamespace 107 */ 108 public function getNamespace(): TalNamespace 109 { 110 return $this->namespace; 111 } 112 113 /** 114 * @param TalNamespace $ns 115 * @return void 116 */ 117 public function setNamespace(TalNamespace $ns): void 118 { 119 $this->namespace = $ns; 120 } 121 122 /** 123 * @param Dom\Element $tag 124 * @param $expression 125 * @return mixed 126 */ 127 public function createAttributeHandler(Dom\Element $tag, $expression) 128 { 129 return $this->namespace->createAttributeHandler($this, $tag, $expression); 130 } 131} 132