web/lib/Zend/InfoCard/Xml/EncryptedData.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: EncryptedData.php 20096 2010-01-06 02:05:09Z bkarwin $
       
    21  */
       
    22 
       
    23 /**
       
    24  * A factory class for producing Zend_InfoCard_Xml_EncryptedData objects based on
       
    25  * the type of XML document provided
       
    26  *
       
    27  * @category   Zend
       
    28  * @package    Zend_InfoCard
       
    29  * @subpackage Zend_InfoCard_Xml
       
    30  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    31  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    32  */
       
    33 final class Zend_InfoCard_Xml_EncryptedData
       
    34 {
       
    35     /**
       
    36      * Constructor (disabled)
       
    37      *
       
    38      * @return void
       
    39      */
       
    40     private function __construct()
       
    41     {
       
    42     }
       
    43 
       
    44     /**
       
    45      * Returns an instance of the class
       
    46      *
       
    47      * @param string $xmlData The XML EncryptedData String
       
    48      * @return Zend_InfoCard_Xml_EncryptedData_Abstract
       
    49      * @throws Zend_InfoCard_Xml_Exception
       
    50      */
       
    51     static public function getInstance($xmlData)
       
    52     {
       
    53 
       
    54         if($xmlData instanceof Zend_InfoCard_Xml_Element) {
       
    55             $strXmlData = $xmlData->asXML();
       
    56         } else if (is_string($xmlData)) {
       
    57             $strXmlData = $xmlData;
       
    58         } else {
       
    59             require_once 'Zend/InfoCard/Xml/Exception.php';
       
    60             throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance");
       
    61         }
       
    62 
       
    63         $sxe = simplexml_load_string($strXmlData);
       
    64 
       
    65         switch($sxe['Type']) {
       
    66             case 'http://www.w3.org/2001/04/xmlenc#Element':
       
    67                 include_once 'Zend/InfoCard/Xml/EncryptedData/XmlEnc.php';
       
    68                 return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_EncryptedData_XmlEnc');
       
    69             default:
       
    70                 require_once 'Zend/InfoCard/Xml/Exception.php';
       
    71                 throw new Zend_InfoCard_Xml_Exception("Unknown EncryptedData type found");
       
    72                 break;
       
    73         }
       
    74     }
       
    75 }