You are here

public function XMLSecurityDSig::appendToKeyInfo in SAML SP 2.0 Single Sign On (SSO) - SAML Service Provider 7

This function appends a node to the KeyInfo.

The KeyInfo element will be created if one does not exist in the document.

Parameters

DOMNode $node The node to append to the KeyInfo.:

Return value

DOMNode The KeyInfo element node

File

includes/XMLSecurityKey.php, line 1796

Class

XMLSecurityDSig

Code

public function appendToKeyInfo($node) {
  $parentRef = $this->sigNode;
  $baseDoc = $parentRef->ownerDocument;
  $xpath = $this
    ->getXPathObj();
  if (empty($xpath)) {
    $xpath = new DOMXPath($parentRef->ownerDocument);
    $xpath
      ->registerNamespace('secdsig', self::XMLDSIGNS);
  }
  $query = "./secdsig:KeyInfo";
  $nodeset = $xpath
    ->query($query, $parentRef);
  $keyInfo = $nodeset
    ->item(0);
  if (!$keyInfo) {
    $dsig_pfx = '';
    $pfx = $parentRef
      ->lookupPrefix(self::XMLDSIGNS);
    if (!empty($pfx)) {
      $dsig_pfx = $pfx . ":";
    }
    $inserted = false;
    $keyInfo = $baseDoc
      ->createElementNS(self::XMLDSIGNS, $dsig_pfx . 'KeyInfo');
    $query = "./secdsig:Object";
    $nodeset = $xpath
      ->query($query, $parentRef);
    if ($sObject = $nodeset
      ->item(0)) {
      $sObject->parentNode
        ->insertBefore($keyInfo, $sObject);
      $inserted = true;
    }
    if (!$inserted) {
      $parentRef
        ->appendChild($keyInfo);
    }
  }
  $keyInfo
    ->appendChild($node);
  return $keyInfo;
}