/** * Transform a node with a stylesheet. * * @param DOMNode The node to transform. * * @return AgaviXmlConfigDomDocument The resulting DOMDocument. * * @author Noah Fontes <*****@*****.**> * @author David Zülke <*****@*****.**> * @since 1.0.0 */ public function transformToDoc($doc) { $luie = libxml_use_internal_errors(true); libxml_clear_errors(); $result = parent::transformToDoc($doc); // check if result is false, too, as that means the transformation failed for reasons like infinite template recursion if ($result === false || libxml_get_last_error() !== false || count(libxml_get_errors())) { $errors = array(); foreach (libxml_get_errors() as $error) { $errors[] = sprintf('[%s #%d] Line %d: %s', $error->level == LIBXML_ERR_WARNING ? 'Warning' : ($error->level == LIBXML_ERR_ERROR ? 'Error' : 'Fatal'), $error->code, $error->line, $error->message); } libxml_clear_errors(); libxml_use_internal_errors($luie); throw new Exception(sprintf('Error%s occurred while transforming the document using an XSL stylesheet: ' . "\n\n%s", count($errors) > 1 ? 's' : '', implode("\n", $errors))); } libxml_use_internal_errors($luie); // turn this into an Agavi DOMDocument rather than a regular one $document = new AgaviXmlConfigDomDocument(); $document->loadXML($result->saveXML()); // save the URI just in case $document->documentURI = $result->documentURI; unset($result); return $document; }
/** * @group Configuration */ public function testDOMProvider() { $dom = '<?xml version="1.0" encoding="UTF-8"?> <ae:configurations xmlns:ae="http://agavi.org/agavi/config/global/envelope/1.0" xmlns="http://icinga.org/appkit/config/parts/routing/1.0"> <ae:configuration context="web"> <routes> <route name="route1" module="AppKit" pattern="xyz"> <route name="s1_route1" action="Login" pattern="^/test"></route> <route name="s2_route1" action="Logout" pattern="^/test2" api_provider="true"></route> <route name="s2_route1" action="Secure" pattern="^/test3" > <route name="subtest" pattern="test4" api_provider="true"/> </route> </route> <route name="route2" module="Web" action="Index" pattern="test" api_provider="true"/> <route name="route3" module="Web" action="Index" pattern="test" api_provider="true"/> </routes> </ae:configuration> </ae:configurations> '; $domDoc = new AgaviXmlConfigDomDocument(); $domDoc->loadXML($dom); $extRoutes = array(array("module" => "AppKit", "action" => "Logout"), array("module" => "AppKit", "action" => "Secure"), array("module" => "Web", "action" => "Index")); return array(array($domDoc, $extRoutes)); }