Example #1
0
 /**
  * Iterates backwards through the tag stack to find a container
  * tag of the specified name 
  **/
 public static function getContainer($name = NULL, $depth = 1)
 {
     // Rekey the tagStack array incase its gotten out of step
     self::$tagStack = array_values(self::$tagStack);
     end(self::$tagStack);
     $i = key(self::$tagStack);
     if ($name === NULL) {
         while ($depth > 1) {
             $depth--;
             prev(self::$tagStack);
         }
         return current(self::$tagStack[$i]);
     } else {
         while ($depth > 0 && $i >= 0) {
             $elem = self::$tagStack[$i];
             // Loop up the tagStack looking for a tag with a matching name, until we reach the top
             while (($ret = !isset($elem->token['tag']) || $elem->token['tag'] != $name) && $i > 0) {
                 --$i;
                 $elem = self::$tagStack[$i];
             }
             --$depth;
             --$i;
         }
         // If no tags matched the specified name, return nothing
         if ($ret) {
             return NULL;
         }
         return $elem;
     }
 }
Example #2
0
 public static function &getParent($name = NULL)
 {
     self::$tagStack = array_values(self::$tagStack);
     $i = count(self::$tagStack) - 1;
     if ($name === NULL) {
         return self::$tagStack[$i];
     } else {
         $elem =& self::$tagStack[$i];
         while ($elem->token['tag'] != $name && $i > 0) {
             --$i;
             $elem =& self::$tagStack[$i];
         }
         return $elem;
     }
 }