web/lib/Zend/InfoCard/Xml/KeyInfo.php
changeset 64 162c1de6545a
parent 19 1c2f13fd785c
child 68 ecaf28ffe26e
equal deleted inserted replaced
63:5b37998e522e 64:162c1de6545a
       
     1 <?php
       
     2 /**
       
     3  * Zend Framework
       
     4  *
       
     5  * LICENSE
       
     6  *
       
     7  * This source file is subject to the new BSD license that is bundled
       
     8  * with this package in the file LICENSE.txt.
       
     9  * It is also available through the world-wide-web at this URL:
       
    10  * http://framework.zend.com/license/new-bsd
       
    11  * If you did not receive a copy of the license and are unable to
       
    12  * obtain it through the world-wide-web, please send an email
       
    13  * to license@zend.com so we can send you a copy immediately.
       
    14  *
       
    15  * @category   Zend
       
    16  * @package    Zend_InfoCard
       
    17  * @subpackage Zend_InfoCard_Xml
       
    18  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    19  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    20  * @version    $Id: KeyInfo.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /**
       
    24  * Zend_InfoCard_Xml_Element
       
    25  */
       
    26 require_once 'Zend/InfoCard/Xml/Element.php';
       
    27 
       
    28 /**
       
    29  * Factory class to return a XML KeyInfo block based on input XML
       
    30  *
       
    31  * @category   Zend
       
    32  * @package    Zend_InfoCard
       
    33  * @subpackage Zend_InfoCard_Xml
       
    34  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    35  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    36  */
       
    37 class Zend_InfoCard_Xml_KeyInfo
       
    38 {
       
    39     /**
       
    40      * Constructor (disabled)
       
    41      *
       
    42      * @return void
       
    43      */
       
    44     private function __construct()
       
    45     {
       
    46     }
       
    47 
       
    48     /**
       
    49      * Returns an instance of KeyInfo object based on the input KeyInfo XML block
       
    50      *
       
    51      * @param string $xmlData The KeyInfo XML Block
       
    52      * @return Zend_InfoCard_Xml_KeyInfo_Abstract
       
    53      * @throws Zend_InfoCard_Xml_Exception
       
    54      */
       
    55     static public function getInstance($xmlData)
       
    56     {
       
    57 
       
    58         if($xmlData instanceof Zend_InfoCard_Xml_Element) {
       
    59             $strXmlData = $xmlData->asXML();
       
    60         } else if (is_string($xmlData)) {
       
    61             $strXmlData = $xmlData;
       
    62         } else {
       
    63             throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance");
       
    64         }
       
    65 
       
    66         $sxe = simplexml_load_string($strXmlData);
       
    67 
       
    68         $namespaces = $sxe->getDocNameSpaces();
       
    69 
       
    70         if(!empty($namespaces)) {
       
    71             foreach($sxe->getDocNameSpaces() as $namespace) {
       
    72                 switch($namespace) {
       
    73                     case 'http://www.w3.org/2000/09/xmldsig#':
       
    74                         include_once 'Zend/InfoCard/Xml/KeyInfo/XmlDSig.php';
       
    75                         return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_KeyInfo_XmlDSig');
       
    76                     default:
       
    77 
       
    78                         throw new Zend_InfoCard_Xml_Exception("Unknown KeyInfo Namespace provided");
       
    79                     // We are ignoring these lines, as XDebug reports each as a "non executed" line
       
    80                     // which breaks my coverage %
       
    81                     // @codeCoverageIgnoreStart
       
    82                 }
       
    83             }
       
    84         }
       
    85         // @codeCoverageIgnoreEnd
       
    86 
       
    87         include_once 'Zend/InfoCard/Xml/KeyInfo/Default.php';
       
    88         return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_KeyInfo_Default');
       
    89     }
       
    90 }