2
0

Assertion.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_Assertion_Interface
  24. */
  25. require_once 'Zend/InfoCard/Xml/Assertion/Interface.php';
  26. /**
  27. * Factory object to retrieve an Assertion object based on the type of XML document provided
  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. final class Zend_InfoCard_Xml_Assertion
  36. {
  37. /**
  38. * The namespace for a SAML-formatted Assertion document
  39. */
  40. const TYPE_SAML = 'urn:oasis:names:tc:SAML:1.0:assertion';
  41. /**
  42. * Constructor (disabled)
  43. *
  44. * @return void
  45. */
  46. private function __construct()
  47. {
  48. }
  49. /**
  50. * Returns an instance of a InfoCard Assertion object based on the XML data provided
  51. *
  52. * @throws Zend_InfoCard_Xml_Exception
  53. * @param string $xmlData The XML-Formatted Assertion
  54. * @return Zend_InfoCard_Xml_Assertion_Interface
  55. * @throws Zend_InfoCard_Xml_Exception
  56. */
  57. static public function getInstance($xmlData)
  58. {
  59. if($xmlData instanceof Zend_InfoCard_Xml_Element) {
  60. $strXmlData = $xmlData->asXML();
  61. } else if (is_string($xmlData)) {
  62. $strXmlData = $xmlData;
  63. } else {
  64. require_once 'Zend/InfoCard/Xml/Exception.php';
  65. throw new Zend_InfoCard_Xml_Exception("Invalid Data provided to create instance");
  66. }
  67. $sxe = simplexml_load_string($strXmlData);
  68. $namespaces = $sxe->getDocNameSpaces();
  69. foreach($namespaces as $namespace) {
  70. switch($namespace) {
  71. case self::TYPE_SAML:
  72. include_once 'Zend/InfoCard/Xml/Assertion/Saml.php';
  73. return simplexml_load_string($strXmlData, 'Zend_InfoCard_Xml_Assertion_Saml', null);
  74. }
  75. }
  76. require_once 'Zend/InfoCard/Xml/Exception.php';
  77. throw new Zend_InfoCard_Xml_Exception("Unable to determine Assertion type by Namespace");
  78. }
  79. }