KeyInfo.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. * Zend_InfoCard_Xml_Element
  24. */
  25. require_once 'Zend/InfoCard/Xml/Element.php';
  26. /**
  27. * Factory class to return a XML KeyInfo block based on input XML
  28. *
  29. * @category Zend
  30. * @package Zend_InfoCard
  31. * @subpackage Zend_InfoCard_Xml
  32. * @copyright Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
  33. * @license http://framework.zend.com/license/new-bsd New BSD License
  34. */
  35. class Zend_InfoCard_Xml_KeyInfo
  36. {
  37. /**
  38. * Constructor (disabled)
  39. *
  40. * @return void
  41. */
  42. private function __construct()
  43. {
  44. }
  45. /**
  46. * Returns an instance of KeyInfo object based on the input KeyInfo XML block
  47. *
  48. * @param string $xmlData The KeyInfo XML Block
  49. * @return Zend_InfoCard_Xml_KeyInfo_Abstract
  50. * @throws Zend_InfoCard_Xml_Exception
  51. */
  52. static public function getInstance($xmlData)
  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. throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance");
  60. }
  61. $sxe = simplexml_load_string($strXmlData);
  62. $namespaces = $sxe->getDocNameSpaces();
  63. if(!empty($namespaces)) {
  64. foreach($sxe->getDocNameSpaces() as $namespace) {
  65. switch($namespace) {
  66. case 'http://www.w3.org/2000/09/xmldsig#':
  67. include_once 'Zend/InfoCard/Xml/KeyInfo/XmlDSig.php';
  68. return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_KeyInfo_XmlDSig');
  69. default:
  70. throw new Zend_InfoCard_Xml_Exception("Unknown KeyInfo Namespace provided");
  71. // We are ignoring these lines, as XDebug reports each as a "non executed" line
  72. // which breaks my coverage %
  73. // @codeCoverageIgnoreStart
  74. }
  75. }
  76. }
  77. // @codeCoverageIgnoreEnd
  78. include_once 'Zend/InfoCard/Xml/KeyInfo/Default.php';
  79. return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_KeyInfo_Default');
  80. }
  81. }