SimpleSAML\Utils\XML::isDOMElementOfType PHP Метод

isDOMElementOfType() публичный статический Метод

We also define the following shortcuts for namespaces: - '@ds': 'http://www.w3.org/2000/09/xmldsig#' - '@md': 'urn:oasis:names:tc:SAML:2.0:metadata' - '@saml1': 'urn:oasis:names:tc:SAML:1.0:assertion' - '@saml1md': 'urn:oasis:names:tc:SAML:profiles:v1metadata' - '@saml1p': 'urn:oasis:names:tc:SAML:1.0:protocol' - '@saml2': 'urn:oasis:names:tc:SAML:2.0:assertion' - '@saml2p': 'urn:oasis:names:tc:SAML:2.0:protocol'
Автор: Andreas Solberg, UNINETT AS ([email protected])
Автор: Olav Morken, UNINETT AS ([email protected])
public static isDOMElementOfType ( DOMNode $element, string $name, string $nsURI ) : boolean
$element DOMNode The element we should check.
$name string The local name the element should have.
$nsURI string The namespaceURI the element should have.
Результат boolean True if both namespace and local name matches, false otherwise.
    public static function isDOMElementOfType(\DOMNode $element, $name, $nsURI)
    {
        if (!$element instanceof \DOMElement || !is_string($name) || !is_string($nsURI) || strlen($nsURI) === 0) {
            // most likely a comment-node
            return false;
        }
        // check if the namespace is a shortcut, and expand it if it is
        if ($nsURI[0] === '@') {
            // the defined shortcuts
            $shortcuts = array('@ds' => 'http://www.w3.org/2000/09/xmldsig#', '@md' => 'urn:oasis:names:tc:SAML:2.0:metadata', '@saml1' => 'urn:oasis:names:tc:SAML:1.0:assertion', '@saml1md' => 'urn:oasis:names:tc:SAML:profiles:v1metadata', '@saml1p' => 'urn:oasis:names:tc:SAML:1.0:protocol', '@saml2' => 'urn:oasis:names:tc:SAML:2.0:assertion', '@saml2p' => 'urn:oasis:names:tc:SAML:2.0:protocol', '@shibmd' => 'urn:mace:shibboleth:metadata:1.0');
            // check if it is a valid shortcut
            if (!array_key_exists($nsURI, $shortcuts)) {
                throw new \InvalidArgumentException('Unknown namespace shortcut: ' . $nsURI);
            }
            // expand the shortcut
            $nsURI = $shortcuts[$nsURI];
        }
        if ($element->localName !== $name) {
            return false;
        }
        if ($element->namespaceURI !== $nsURI) {
            return false;
        }
        return true;
    }