EncryptedData.php 2.4 KB

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