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.
16 * @package Zend_InfoCard
17 * @subpackage Zend_InfoCard_Xml_Security
18 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
19 * @license http://framework.zend.com/license/new-bsd New BSD License
20 * @version $Id: Transform.php 16214 2009-06-21 19:34:03Z thomas $
24 * A class to create a transform rule set based on XML URIs and then apply those rules
25 * in the correct order to a given XML input
28 * @package Zend_InfoCard
29 * @subpackage Zend_InfoCard_Xml_Security
30 * @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
31 * @license http://framework.zend.com/license/new-bsd New BSD License
33 class Zend_InfoCard_Xml_Security_Transform
36 * A list of transforms to apply
40 protected $_transformList = array();
43 * Returns the name of the transform class based on a given URI
45 * @throws Zend_InfoCard_Xml_Security_Exception
46 * @param string $uri The transform URI
47 * @return string The transform implementation class name
49 protected function _findClassbyURI($uri)
52 case 'http://www.w3.org/2000/09/xmldsig#enveloped-signature':
53 return 'Zend_InfoCard_Xml_Security_Transform_EnvelopedSignature';
54 case 'http://www.w3.org/2001/10/xml-exc-c14n#':
55 return 'Zend_InfoCard_Xml_Security_Transform_XmlExcC14N';
57 require_once 'Zend/InfoCard/Xml/Security/Exception.php';
58 throw new Zend_InfoCard_Xml_Security_Exception("Unknown or Unsupported Transformation Requested");
63 * Add a Transform URI to the list of transforms to perform
65 * @param string $uri The Transform URI
66 * @return Zend_InfoCard_Xml_Security_Transform
68 public function addTransform($uri)
70 $class = $this->_findClassbyURI($uri);
72 $this->_transformList
[] = array('uri' => $uri,
78 * Return the list of transforms to perform
80 * @return array The list of transforms
82 public function getTransformList()
84 return $this->_transformList
;
88 * Apply the transforms in the transform list to the input XML document
90 * @param string $strXmlDocument The input XML
91 * @return string The XML after the transformations have been applied
93 public function applyTransforms($strXmlDocument)
95 foreach($this->_transformList
as $transform) {
96 if (!class_exists($transform['class'])) {
97 require_once 'Zend/Loader.php';
98 Zend_Loader
::loadClass($transform['class']);
101 $transformer = new $transform['class'];
103 // We can't really test this check because it would require logic changes in the component itself
104 // @codeCoverageIgnoreStart
105 if(!($transformer instanceof Zend_InfoCard_Xml_Security_Transform_Interface
)) {
106 require_once 'Zend/InfoCard/Xml/Security/Exception.php';
107 throw new Zend_InfoCard_Xml_Security_Exception("Transforms must implement the Transform Interface");
109 // @codeCoverageIgnoreEnd
111 $strXmlDocument = $transformer->transform($strXmlDocument);
114 return $strXmlDocument;