matchesAttribute() public static method

Check whether the given DOMElement has the given attribute.
public static matchesAttribute ( $node, $name, $value = null, $operation = EventHandler::isExactly )
Example #1
0
 /**
  * Pseudo-class handler for :lang
  *
  * Note that this does not implement the spec in its entirety because we do
  * not presume to "know the language" of the document. If anyone is interested
  * in making this more intelligent, please do so.
  */
 protected function lang($node, $value)
 {
     // TODO: This checks for cases where an explicit language is
     // set. The spec seems to indicate that an element should inherit
     // language from the parent... but this is unclear.
     $operator = strpos($value, '-') !== FALSE ? EventHandler::isExactly : EventHandler::containsWithHyphen;
     $match = TRUE;
     foreach ($node->attributes as $attrNode) {
         if ($attrNode->localName == 'lang') {
             if ($attrNode->nodeName == $attrNode->localName) {
                 // fprintf(STDOUT, "%s in NS %s\n", $attrNode->name, $attrNode->nodeName);
                 return Util::matchesAttribute($node, 'lang', $value, $operator);
             } else {
                 $nsuri = $attrNode->namespaceURI;
                 // fprintf(STDOUT, "%s in NS %s\n", $attrNode->name, $nsuri);
                 return Util::matchesAttributeNS($node, 'lang', $nsuri, $value, $operator);
             }
         }
     }
     return FALSE;
 }
Example #2
0
 /**
  * Check to see if DOMNode has all of the given attributes.
  *
  * This can handle namespaced attributes, including namespace
  * wildcards.
  */
 protected function matchAttributes($node, $attributes)
 {
     if (empty($attributes)) {
         return TRUE;
     }
     foreach ($attributes as $attr) {
         $val = isset($attr['value']) ? $attr['value'] : NULL;
         // Namespaced attributes.
         if (isset($attr['ns']) && $attr['ns'] != '*') {
             $nsuri = $node->lookupNamespaceURI($attr['ns']);
             if (empty($nsuri) || !$node->hasAttributeNS($nsuri, $attr['name'])) {
                 return FALSE;
             }
             $matches = Util::matchesAttributeNS($node, $attr['name'], $nsuri, $val, $attr['op']);
         } elseif (isset($attr['ns']) && $attr['ns'] == '*' && $node->hasAttributes()) {
             // Cycle through all of the attributes in the node. Note that
             // these are DOMAttr objects.
             $matches = FALSE;
             $name = $attr['name'];
             foreach ($node->attributes as $attrNode) {
                 if ($attrNode->localName == $name) {
                     $nsuri = $attrNode->namespaceURI;
                     $matches = Util::matchesAttributeNS($node, $name, $nsuri, $val, $attr['op']);
                 }
             }
         } else {
             $matches = Util::matchesAttribute($node, $attr['name'], $val, $attr['op']);
         }
         if (!$matches) {
             return FALSE;
         }
     }
     return TRUE;
 }