OneLogin_Saml2_Utils::query PHP Method

query() public static method

Extracts nodes from the DOMDocument.
public static query ( DOMDocument $dom, string $query, DomElement $context = null ) : DOMNodeList
$dom DOMDocument The DOMDocument
$query string Xpath Expresion
$context DomElement Context Node (DomElement)
return DOMNodeList The queried nodes
    public static function query($dom, $query, $context = null)
    {
        $xpath = new DOMXPath($dom);
        $xpath->registerNamespace('samlp', OneLogin_Saml2_Constants::NS_SAMLP);
        $xpath->registerNamespace('saml', OneLogin_Saml2_Constants::NS_SAML);
        $xpath->registerNamespace('ds', OneLogin_Saml2_Constants::NS_DS);
        $xpath->registerNamespace('xenc', OneLogin_Saml2_Constants::NS_XENC);
        if (isset($context)) {
            $res = $xpath->query($query, $context);
        } else {
            $res = $xpath->query($query);
        }
        return $res;
    }

Usage Example

Example #1
0
 /**
  * Gets the SessionIndexes from the Logout Request.
  * Notice: Our Constructor only support 1 SessionIndex but this parser
  *         extracts an array of all the  SessionIndex found on a  
  *         Logout Request, that could be many.
  *
  * @param string|DOMDocument $request Logout Request Message
  * 
  * @return array The SessionIndex value
  */
 public static function getSessionIndexes($request)
 {
     if ($request instanceof DOMDocument) {
         $dom = $request;
     } else {
         $dom = new DOMDocument();
         $dom = OneLogin_Saml2_Utils::loadXML($dom, $request);
     }
     $sessionIndexes = array();
     $sessionIndexNodes = OneLogin_Saml2_Utils::query($dom, '/samlp:LogoutRequest/samlp:SessionIndex');
     foreach ($sessionIndexNodes as $sessionIndexNode) {
         $sessionIndexes[] = $sessionIndexNode->textContent;
     }
     return $sessionIndexes;
 }
All Usage Examples Of OneLogin_Saml2_Utils::query