[ Index ]

PHP Cross Reference of Web Application Component Toolkit

title

Body

[close]

/framework/template/compiler/ -> tagdictionary.inc.php (source)

   1  <?php
   2  //--------------------------------------------------------------------------------
   3  // Copyright 2003 Procata, Inc.
   4  // Released under the LGPL license (http://www.gnu.org/copyleft/lesser.html)
   5  //--------------------------------------------------------------------------------
   6  /**
   7  * @package WACT_TEMPLATE
   8  * @version $Id: tagdictionary.inc.php,v 1.15 2004/11/18 05:05:25 jeffmoore Exp $
   9  */
  10  
  11  require_once WACT_ROOT . 'template/compiler/common/dictionary.inc.php';
  12  
  13  /**
  14  * The tag must have a closing tag
  15  */
  16  define('ENDTAG_REQUIRED', 1);
  17  /**
  18  * The tag may have a closing tag
  19  */
  20  define('ENDTAG_OPTIONAL', 2);
  21  /**
  22  * The tag may not have a closing tag
  23  */
  24  define('ENDTAG_FORBIDDEN', 3);
  25  
  26  
  27  define('LOCATION_SERVER', 'server');
  28  define('LOCATION_CLIENT', 'client');
  29  
  30  /**
  31  * Define the attribute which "triggers" components
  32  */
  33  define('PARSER_TRIGGER_ATTR_NAME','runat'); // Must be lower case! See TreeBuilder::addAttributeNode
  34  define('PARSER_TRIGGER_ATTR_VALUE','server');
  35  
  36  /**
  37  * Define attribute for using known children
  38  * Referenced in ParserState::ComponentParsingState::open()
  39  */
  40  define('PARSER_USEKNOWN_ATTR','useknown');
  41  
  42  /**
  43  * @package WACT_TEMPLATE
  44  */
  45  class TagInfo {
  46      var $Tag = '';
  47      var $EndTag = ENDTAG_REQUIRED;
  48      var $TagClass = '';
  49      var $CompilerAttributes = array();
  50      var $KnownParent;
  51      var $DefaultLocation = LOCATION_SERVER;
  52      var $File;
  53      
  54      function TagInfo($tag, $class) {
  55          $this->Tag = $tag;
  56          $this->TagClass = $class;
  57      }
  58      
  59      function setEndTag($end) {
  60          $this->EndTag = $end;
  61      }
  62      
  63      function setCompilerAttributes($attributes) {
  64          $this->CompilerAttributes = $attributes;
  65      }
  66      
  67      function setKnownParent($parent) {
  68          $this->KnownParent = $parent;
  69      }
  70      
  71      function setDefaultLocation($location) {
  72          $this->DefaultLocation = $location;
  73      }
  74      
  75      function load() {
  76          if (!class_exists($this->TagClass) && isset($this->File)) {
  77              require_once $this->File;
  78          }
  79      }
  80  }
  81  
  82  /**
  83  * The TagDictionary, which exists as a global variable, acting as a registry
  84  * of compile time components.
  85  * @see http://wact.sourceforge.net/index.php/TagDictionary
  86  * @access protected
  87  * @package WACT_TEMPLATE
  88  */
  89  class TagDictionary extends CompilerArtifactDictionary {
  90      /**
  91      * Associative array of TagInfo objects
  92      * @var array
  93      * @access private
  94      */
  95      var $TagInformation = array();
  96  
  97      function TagDictionary() {
  98          parent::CompilerArtifactDictionary();
  99      }    
 100  
 101      /**
 102      * Registers a tag in the dictionary, called from the global registerTag()
 103      * function.
 104      * @param object TagInfo class
 105      * @return void
 106      * @access protected
 107      */
 108  	function _registerTag($taginfo) {
 109          $tag = strtolower($taginfo->Tag);
 110          $this->TagInformation[$tag] =& $taginfo;
 111      }
 112  
 113      /**
 114      * Registers information about a compile time tag in the global tag dictionary.
 115      * This function is called from the respective compile time component class
 116      * file.
 117      * @param object instance of a TagInfo class
 118      * @return void
 119      * @access protected
 120      */
 121      function registerTag(&$taginfo, $file) {
 122          $taginfo->File = $file;
 123          $GLOBALS['TagDictionary']->_registerTag($taginfo);
 124      }
 125  
 126      /**
 127      * Gets the tag information about a given tag.
 128      * Called from the SourceFileParser
 129      * @see SourceFileParser
 130      * @param string name of a tag
 131      * @return object TagInfo class
 132      * @access protected
 133      */
 134      function &getTagInfo($tag) {
 135          if (isset($this->TagInformation[strtolower($tag)])) {
 136              return $this->TagInformation[strtolower($tag)];
 137          }
 138      }
 139  
 140      /**
 141      * Returns the global instance of the tag dictionary
 142      * Used so less direct references scattered around to global location
 143      * @static
 144      * @return TagDictionary
 145      * @access protected
 146      */
 147      function &getInstance() {
 148          return parent::_getInstance('TagDictionary', 'TagDictionary', 'tag');
 149      }
 150  
 151      /*
 152      * Determines whether a tag is a server component, examining attributes and class
 153      * Called from ComponentParsingState::open() only to check for components
 154      * @param string tag name
 155      * @param array tag attributes
 156      * @param boolean whether it's an empty tag for GenericTags
 157      * @return boolean TRUE if it's a component
 158      * @access private
 159      */
 160      function &findComponent($tag, $attrs, $isEmpty, &$Component) {
 161  
 162          // Does the tag have the runat attribute? If so it might be a component
 163          if ( isset ( $attrs[PARSER_TRIGGER_ATTR_NAME] ) ) {
 164          
 165              // Does runat ="server"? If so it's definately a component
 166              if ( strtolower($attrs[PARSER_TRIGGER_ATTR_NAME]) == PARSER_TRIGGER_ATTR_VALUE ) {
 167                  if (isset($this->TagInformation[strtolower($tag)])) {
 168                      return $this->TagInformation[strtolower($tag)];
 169                  } else {
 170                      // we are a generic tag.  We run at the server, but have no
 171                      // specific TagInfo record in the dictionary.
 172                      if ( !$isEmpty ) {
 173                          $generic =& new TagInfo($tag, 'GenericContainerTag');
 174                          $generic->File = WACT_ROOT . 'template/compiler/generictag.inc.php';
 175  
 176                          $generic->setEndTag(ENDTAG_REQUIRED);
 177                      } else {
 178                          $generic =& new TagInfo($tag, 'GenericTag');
 179                          $generic->File = WACT_ROOT . 'template/compiler/generictag.inc.php';
 180                          $generic->setEndTag(ENDTAG_FORBIDDEN);
 181                      }
 182                      $generic->setDefaultLocation(LOCATION_CLIENT);
 183      
 184                      return $generic;
 185                  }
 186              }
 187          } else if ( isset($this->TagInformation[strtolower($tag)]) ) {
 188  
 189              $TagInfo =& $this->TagInformation[strtolower($tag)];
 190  
 191              // DefaultLocation allows the location of some tags to be specified without
 192              // a corresponding runat="" attribute.
 193              if ($TagInfo->DefaultLocation == LOCATION_SERVER) {
 194                  return $TagInfo;
 195              }
 196  
 197              //----------------------------------------------------------------------------
 198              // Is the tag a known child? This applies only to sub classes of 
 199              // ServerTagComponentTag (tags that match HTML) and helps save adding
 200              // runat="server" excessively. The only tags at this time using this are
 201              // the form related tags.
 202              //----------------------------------------------------------------------------
 203              if ( isset($TagInfo->KnownParent) ) {
 204                  if ( $KnownParent = & $Component->findSelfOrParentByClass($TagInfo->KnownParent) ) {
 205                      if ( $KnownParent->getBoolAttribute('useknown',TRUE) ) {
 206                          return $TagInfo;
 207                      }
 208                  }
 209              }
 210          }
 211          return NULL;
 212      }
 213  
 214  }
 215  ?>


Generated: Sun Nov 28 19:36:09 2004 Cross-referenced by PHPXref 0.5