Changeset 1949
- Timestamp:
- 05/23/07 23:46:15 (20 months ago)
- Location:
- branches/0.11
- Files:
-
- 21 modified
- 17 copied
-
samples/app/config/factories.xml (modified) (4 diffs)
-
samples/app/config/output_types.xml (modified) (1 diff)
-
samples/app/config/routing.xml (modified) (2 diffs)
-
samples/app/modules/Default/actions/SendWsdlAction.class.php (copied) (copied from branches/david-xml_config_handlers/samples/app/modules/Default/actions/SendWsdlAction.class.php)
-
samples/app/modules/Default/templates/SendWsdlError.php (copied) (copied from branches/david-xml_config_handlers/samples/app/modules/Default/templates/SendWsdlError.php)
-
samples/app/modules/Default/templates/SendWsdlSuccess.php (copied) (copied from branches/david-xml_config_handlers/samples/app/modules/Default/templates/SendWsdlSuccess.php)
-
samples/app/modules/Default/views/SendWsdlErrorView.class.php (copied) (copied from branches/david-xml_config_handlers/samples/app/modules/Default/views/SendWsdlErrorView.class.php)
-
samples/app/modules/Default/views/SendWsdlSuccessView.class.php (copied) (copied from branches/david-xml_config_handlers/samples/app/modules/Default/views/SendWsdlSuccessView.class.php)
-
samples/pub/soap-test.php (modified) (1 diff)
-
samples/pub/wsdl.php (copied) (copied from branches/david-xml_config_handlers/samples/pub/wsdl.php)
-
src/config/AgaviBaseConfigHandler.class.php (copied) (copied from branches/david-xml_config_handlers/src/config/AgaviBaseConfigHandler.class.php)
-
src/config/AgaviConfigCache.class.php (modified) (8 diffs)
-
src/config/AgaviConfigHandler.class.php (modified) (2 diffs)
-
src/config/AgaviConfigHandlersConfigHandler.class.php (modified) (1 diff)
-
src/config/AgaviConfigParser.class.php (modified) (2 diffs)
-
src/config/AgaviILegacyConfigHandler.interface.php (copied) (copied from branches/david-xml_config_handlers/src/config/AgaviILegacyConfigHandler.interface.php)
-
src/config/AgaviWsdlConfigHandler.class.php (copied) (copied from branches/david-xml_config_handlers/src/config/AgaviWsdlConfigHandler.class.php)
-
src/config/AgaviXmlConfigHandler.class.php (copied) (copied from branches/david-xml_config_handlers/src/config/AgaviXmlConfigHandler.class.php)
-
src/config/AgaviXmlConfigParser.class.php (modified) (20 diffs)
-
src/config/defaults/autoload.xml (modified) (3 diffs)
-
src/config/defaults/config_handlers.xml (modified) (1 diff)
-
src/config/xsd/default_tags.xsd (modified) (2 diffs)
-
src/config/xsd/routing.xsd (modified) (1 diff)
-
src/controller/AgaviSoapController.class.php (modified) (1 diff)
-
src/controller/AgaviSoapControllerCallHandler.class.php (modified) (3 diffs)
-
src/core/Agavi.class.php (modified) (1 diff)
-
src/filter/AgaviExecutionFilter.class.php (modified) (1 diff)
-
src/request/AgaviSoapRequest.class.php (modified) (1 diff)
-
src/request/AgaviSoapRequestDataHolder.class.php (copied) (copied from branches/david-xml_config_handlers/src/request/AgaviSoapRequestDataHolder.class.php)
-
src/request/AgaviWebserviceRequest.class.php (modified) (3 diffs)
-
src/request/AgaviWebserviceRequestDataHolder.class.php (copied) (copied from branches/david-xml_config_handlers/src/request/AgaviWebserviceRequestDataHolder.class.php)
-
src/routing/AgaviRouting.class.php (modified) (2 diffs)
-
src/routing/AgaviSoapRouting.class.php (copied) (copied from branches/david-xml_config_handlers/src/routing/AgaviSoapRouting.class.php)
-
src/routing/AgaviWebserviceRouting.class.php (modified) (1 diff)
-
src/routing/AgaviXmlrpcepiphpRouting.class.php (copied) (copied from branches/david-xml_config_handlers/src/routing/AgaviXmlrpcepiphpRouting.class.php)
-
src/routing/soap (copied) (copied from branches/david-xml_config_handlers/src/routing/soap)
-
src/routing/soap/wsdl.xml (copied) (copied from branches/david-xml_config_handlers/src/routing/soap/wsdl.xml)
-
src/routing/soap/wsdl.xsl (copied) (copied from branches/david-xml_config_handlers/src/routing/soap/wsdl.xsl)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.11/samples/app/config/factories.xml
r1910 r1949 18 18 <logger_manager class="AgaviLoggerManager" /> 19 19 20 <request class="AgaviWebRequest"> 21 <parameter name="throw_exception_when_locked">false</parameter> 22 </request> 20 <request class="AgaviWebRequest" /> 23 21 24 22 <response class="AgaviWebResponse" /> … … 52 50 <configuration context="soap"> 53 51 54 <controller class="AgaviSoapController"> 55 <parameter name="wsdl">%core.app_dir%/data/test.wsdl</parameter> 56 <parameter name="options"> 57 <parameter name="uri">http://localhost</parameter> 58 </parameter> 59 </controller> 52 <controller class="AgaviSoapController" /> 60 53 61 54 <request class="AgaviSoapRequest" /> … … 63 56 <response class="AgaviSoapResponse" /> 64 57 65 <routing class="AgaviWebserviceRouting" /> 58 <routing class="AgaviSoapRouting"> 59 <parameter name="wsdl_generator"> 60 <parameter name="soap"> 61 <parameter name="address"> 62 <parameter name="location">http://localhost/~dzuelke/_projects/agavi/branches/david-xml_config_handlers/samples/pub/soap.php</parameter> 63 </parameter> 64 </parameter> 65 </parameter> 66 </routing> 67 68 <user class="AgaviSecurityUser" /> 69 70 </configuration> 71 72 <configuration context="wsdl"> 73 74 <storage class="AgaviSessionStorage"> 75 <parameter name="auto_start">false</parameter> 76 </storage> 77 78 <user class="AgaviSecurityUser" /> 66 79 67 80 </configuration> … … 73 86 <response class="AgaviXmlrpcepiphpResponse" /> 74 87 75 <routing class="AgaviWebserviceRouting" /> 88 <routing class="AgaviXmlrpcepiphpRouting" /> 89 90 <user class="AgaviSecurityUser" /> 76 91 77 92 </configuration> -
branches/0.11/samples/app/config/output_types.xml
r1910 r1949 79 79 </configuration> 80 80 81 <configuration context="wsdl"> 82 <output_types default="wsdl"> 83 84 <output_type name="wsdl"> 85 <parameter name="http_headers"> 86 <parameter name="Content-Type">text/xml; charset=UTF-8</parameter> 87 </parameter> 88 </output_type> 89 90 </output_types> 91 </configuration> 92 81 93 </configurations> -
branches/0.11/samples/app/config/routing.xml
r1910 r1949 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 <?xml-stylesheet type="application/xsl+xml" href="#yay"?> 3 <configurations xmlns="http://agavi.org/agavi/1.0/config"> 4 5 <xsl:stylesheet id="yay" version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 6 7 <xsl:output indent="yes" method="xml" /> 8 9 <xsl:key name="no-localized-patterns" match="route" use="pattern[@locale]" /> 10 11 <xsl:template match="/configurations/configuration"> 12 <xsl:apply-templates select="key('no-localized-patterns', route)" /> 13 </xsl:template> 14 15 <xsl:template match="@* | node() "> 16 <xsl:copy> 17 <xsl:apply-templates select="@* | node() " /> 18 </xsl:copy> 19 </xsl:template> 20 21 </xsl:stylesheet> 22 <sandbox> 23 24 </sandbox> 2 <configurations xmlns="http://agavi.org/agavi/1.0/config" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:yay="http://agavi.org/sampleapp" targetNamespace="http://agavi.org/sampleapp"> 25 3 26 4 <configuration context="web"> … … 64 42 <routes> 65 43 <!-- SOAP calls include the name of a remote method to call. The WebserviceRouting applies patterns to this method name, not to the URL of the request. We set the request method to "read" here so executeRead() is run in the Action. --> 66 <route pattern="^getItemPrice$" module="Default" action="SearchEngineSpam" method="read" /> 44 <route pattern="^getItemPrice$" module="Default" action="SearchEngineSpam" method="read"> 45 <wsdl:input> 46 <wsdl:part name="name" type="xsd:string" /> 47 </wsdl:input> 48 <wsdl:output> 49 <wsdl:part name="price" type="xsd:float" /> 50 </wsdl:output> 51 </route> 52 </routes> 53 </configuration> 54 55 <configuration context="wsdl"> 56 <routes> 57 <route pattern="(dummy:.*)" module="Default" action="SendWsdl" /> 67 58 </routes> 68 59 </configuration> -
branches/0.11/samples/pub/soap-test.php
r1898 r1949 9 9 <?php 10 10 11 define('USE_WSDL', true);12 13 11 if(!isset($_GET['item'])) { 14 12 $_GET['item'] = 'nonsense'; 15 13 } 16 14 17 if(USE_WSDL) { 18 19 ini_set('soap.wsdl_cache_enabled', 0); 20 21 // this test.wsdl contains the URL to the service. You have to edit it to match your setup. 22 $client = new SoapClient('../app/data/test.wsdl', array( 23 /* so we can get last request and response */ 24 'trace' => true, 25 )); 26 27 try { 28 $result = $client->getItemPrice($_GET['item']); 29 } catch(SoapFault $e) { 30 $result = $e->__toString(); 31 } 32 33 } else { 34 35 $client = new SoapClient(null, array( 36 "location" => "http://localhost/~dzuelke/_projects/agavi/branches/0.11/samples/pub/soap.php", 37 "uri" => "getItemPrice", 38 "style" => SOAP_RPC, 39 "use" => SOAP_ENCODED 40 )); 15 ini_set('soap.wsdl_cache_enabled', 0); 41 16 42 $result = $client->__call( 43 /* SOAP Method Name */ 44 "getItemPrice", 45 /* Parameters */ 46 array( 47 new SoapParam( 48 /* Parameter Value */ 49 $_GET['item'], 50 /* Parameter Name */ 51 "name" 52 ) 53 ), 54 /* Options */ 55 array( 56 /* so we can get last request and response */ 57 'trace' => true, 58 /* SOAP Method Namespace */ 59 "uri" => "urn:agavi-sampleapp", 60 /* SOAPAction HTTP Header for SOAP Method */ 61 "soapaction" => "urn:agavi-sampleapp#getItemPrice" 62 ) 63 ); 17 // this test.wsdl contains the URL to the service. You have to edit it to match your setup. 18 $client = new SoapClient('http://localhost/~dzuelke/_projects/agavi/branches/david-xml_config_handlers/samples/pub/wsdl.php', array( 19 /* so we can get last request and response */ 20 'trace' => true, 21 )); 64 22 23 try { 24 $result = $client->getItemPrice('nonsense'); 25 } catch(SoapFault $e) { 26 $result = $e->__toString(); 65 27 } 66 28 -
branches/0.11/src/config/AgaviConfigCache.class.php
r1914 r1949 56 56 * @since 0.9.0 57 57 */ 58 private static function callHandler($handler, $config, $cache, $context) 59 { 60 58 private static function callHandler($name, $config, $cache, $context) 59 { 61 60 if(self::$handlers === null) { 62 61 // we need to load the handlers first … … 64 63 self::loadConfigHandlers(); 65 64 } 66 65 67 66 // grab the base name of the handler 68 $basename = basename($handler); 69 70 if(isset(self::$handlers[$handler])) { 67 $basename = basename($name); 68 69 $handlerInfo = null; 70 71 if(isset(self::$handlers[$name])) { 71 72 // we have a handler associated with the full configuration path 72 // call the handler and retrieve the cache data 73 $data = self::$handlers[$handler]->execute($config, $context); 74 self::writeCacheFile($config, $cache, $data, false); 75 return; 73 $handlerInfo = self::$handlers[$name]; 76 74 } elseif(isset(self::$handlers[$basename])) { 77 75 // we have a handler associated with the configuration base name 78 // call the handler and retrieve the cache data 79 $data = self::$handlers[$basename]->execute($config, $context); 80 self::writeCacheFile($config, $cache, $data, false); 81 return; 76 $handlerInfo = self::$handlers[$basename]; 82 77 } else { 83 78 // let's see if we have any wildcard handlers registered that match 84 79 // this basename 85 foreach(self::$handlers as $key => $ handlerInstance) {80 foreach(self::$handlers as $key => $value) { 86 81 // replace wildcard chars in the configuration and create the pattern 87 82 $pattern = sprintf('#%s#', str_replace('\*', '.*?', preg_quote($key))); 88 89 if(preg_match($pattern, $handler)) { 90 // call the handler and retrieve the cache data 91 $data = $handlerInstance->execute($config, $context); 92 self::writeCacheFile($config, $cache, $data, false); 93 return; 83 84 if(preg_match($pattern, $name)) { 85 $handlerInfo = $value; 86 break; 94 87 } 95 88 } 96 89 } 97 98 // we do not have a registered handler for this file 99 $error = 'Configuration file "%s" does not have a registered handler'; 100 $error = sprintf($error, $config); 101 throw new AgaviConfigurationException($error); 90 91 if($handlerInfo === null) { 92 // we do not have a registered handler for this file 93 $error = 'Configuration file "%s" does not have a registered handler'; 94 $error = sprintf($error, $config); 95 throw new AgaviConfigurationException($error); 96 } 97 98 // call the handler and retrieve the cache data 99 $handler = new $handlerInfo['class']; 100 if($handler instanceof AgaviIXmlConfigHandler) { 101 // a new-style config handler 102 // it does not parse the config itself; instead, it is given an array of parsed DOM documents (with parents!) 103 $parser = new AgaviXmlConfigParser(); 104 $docs = $parser->parseAll($config, $handlerInfo['validation']); 105 106 if($context !== null) { 107 $context = AgaviContext::getInstance($context); 108 } 109 110 $handler->initialize($context, $handlerInfo['parameters']); 111 112 try { 113 $data = $handler->execute($docs); 114 } catch(AgaviException $e) { 115 throw new $e(sprintf("Compliation of configuration file '%s' failed for the following reason(s):\n\n%s", $config, $e->getMessage())); 116 } 117 } else { 118 $validationFile = null; 119 if(isset($handlerInfo['validation'][AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA][0])) { 120 $validationFile = $handlerInfo['validation'][AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA][0]; 121 } 122 $handler->initialize($validationFile, null, $handlerInfo['parameters']); 123 $data = $handler->execute($config, $context); 124 } 125 126 self::writeCacheFile($config, $cache, $data, false); 102 127 } 103 128 … … 135 160 $cache = self::getCacheName($config, $context); 136 161 137 if( !is_readable($cache) || filemtime($filename) > filemtime($cache)){162 if(self::isModified($filename, $cache)) { 138 163 // configuration file has changed so we need to reparse it 139 164 self::callHandler($config, $filename, $cache, $context); … … 141 166 142 167 return $cache; 143 168 } 169 170 /** 171 * Check if the cached version of a file is up to date. 172 * 173 * @param string The source file. 174 * @param string The name of the cached version. 175 * 176 * @return bool Whether or not the cached file must be updated. 177 * 178 * @author David Zülke <dz@bitxtender.com> 179 * @since 0.11.0 180 */ 181 public static function isModified($filename, $cachename) 182 { 183 return (!is_readable($cachename) || filemtime($filename) > filemtime($cachename)); 144 184 } 145 185 … … 234 274 // since we only need the parser and handlers when the config is not cached 235 275 // it is sufficient to include them at this stage 276 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviILegacyConfigHandler.interface.php'); 277 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviIXmlConfigHandler.interface.php'); 278 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviBaseConfigHandler.class.php'); 279 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviConfigHandler.class.php'); 280 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviXmlConfigHandler.class.php'); 281 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviAutoloadConfigHandler.class.php'); 236 282 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviConfigHandlersConfigHandler.class.php'); 237 283 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviConfigValueHolder.class.php'); … … 240 286 241 287 // manually create our config_handlers.xml handler 242 self::$handlers['config_handlers.xml'] = new AgaviConfigHandlersConfigHandler(); 243 self::$handlers['config_handlers.xml']->initialize(AgaviConfig::get('core.agavi_dir') . '/config/xsd/config_handlers.xsd'); 288 self::$handlers['config_handlers.xml'] = array( 289 'class' => 'AgaviConfigHandlersConfigHandler', 290 'parameters' => array( 291 ), 292 'validation' => array( 293 AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA => array( 294 AgaviConfig::get('core.agavi_dir') . '/config/xsd/config_handlers.xsd', 295 ), 296 ), 297 ); 244 298 245 299 $cfg = AgaviConfig::get('core.config_dir') . '/config_handlers.xml'; … … 265 319 * @since 0.9.0 266 320 */ 267 p rivate static function writeCacheFile($config, $cache, &$data, $append)321 public static function writeCacheFile($config, $cache, $data, $append = false) 268 322 { 269 323 $perms = fileperms(AgaviConfig::get('core.cache_dir')) ^ 0x4000; … … 303 357 * extension couldn't be found. 304 358 * 359 * @deprecated New-style config handlers don't call this method anymore. 360 * 305 361 * @author Dominik del Bondio <ddb@bitxtender.com> 362 * @author David Zülke <dz@bitxtender.com> 306 363 * @since 0.11.0 307 364 */ 308 public static function parseConfig($config, $autoloadParser = true, $validateFile = null, $parserClass = null) 309 { 310 static $parsers = array(); 311 312 if($parserClass) { 313 $parser = new $parserClass(); 314 return $parser->parse($config, $validateFile); 315 } else { 316 $path = pathinfo($config); 317 $ext = ucfirst(strtolower($path['extension'])); 318 if(!isset($parsers[$ext])) { 319 $class = $ext . 'ConfigParser'; 320 if(!class_exists($class, $autoloadParser)) { 321 $class = 'Agavi' . $class; 322 if(!class_exists($class, $autoloadParser)) { 323 throw new AgaviConfigurationException('Couldn\'t find parser for file extension .' . $path['extension']); 324 } 325 } 326 327 $parsers[$ext] = new $class(); 328 } 329 330 return $parsers[$ext]->parse($config, $validateFile); 331 } 332 } 333 365 public static function parseConfig($config, $autoloadParser = true, $validationFile = null, $parserClass = null) 366 { 367 $parser = new AgaviConfigParser(); 368 369 return $parser->parse($config, $validationFile); 370 } 334 371 } 335 372 -
branches/0.11/src/config/AgaviConfigHandler.class.php
r1846 r1949 33 33 * @version $Id$ 34 34 */ 35 abstract class AgaviConfigHandler extends Agavi ParameterHolder35 abstract class AgaviConfigHandler extends AgaviBaseConfigHandler implements AgaviILegacyConfigHandler 36 36 { 37 /**38 * @var string An absolute filesystem path to a validation filename.39 */40 protected $validationFile = null;41 42 /**43 * @var string A class name of the class which should be used to parse44 * Input files of this config handler.45 */46 protected $parser = null;47 48 /**49 * Retrieves the stored validation filename.50 *51 * @return string An absolute filesystem path to a validation filename.52 *53 * @author Dominik del Bondio <ddb@bitxtender.com>54 * @since 0.11.055 */56 public function getValidationFile()57 {58 return $this->validationFile;59 }60 61 /**62 * Retrieve the parameter node values of the given item's parameters element.63 *64 * @param ConfigValueHolder The node that contains a parameters chiild.65 * @param array As associative array of parameters that will66 * be overwritten if appropriate.67 * @param boolean Whether or not values should be literalized.68 *69 * @return array An associative array of parameters70 *71 * @author Dominik del Bondio <ddb@bitxtender.com>72 * @since 0.11.073 */74 protected function getItemParameters($itemNode, $oldValues = array(), $literalize = true)75 {76 $data = array();77 if($itemNode->hasChildren('parameters')) {78 foreach($itemNode->parameters as $node) {79 if(!$node->hasAttribute('name')) {80 // create a new entry in in the array and get they key of the new81 // created entry (the last in the array). The value doesn't matter82 // since it will be overwritten anyways83 $data[] = 0;84 end($data);85 $name = key($data);86 } else {87 $name = $node->getAttribute('name');88 }89 if($node->hasChildren('parameters')) {90 $data[$name] = (isset($oldValues[$name]) && is_array($oldValues[$name])) ? $oldValues[$name] : array();91 $data[$name] = $this->getItemParameters($node, $data[$name], $literalize);92 } else {93 $data[$name] = $literalize ? $this->literalize($node->getValue()) : $node->getValue();94 }95 }96 }97 // we can NOT use array_merge here, since it would break numeric keys98 foreach($data as $key => $value) {99 $oldValues[$key] = $value;100 }101 return $oldValues;102 }103 104 /**105 * Execute this configuration handler.106 *107 * @param string An absolute filesystem path to a configuration file.108 * @param string Name of the executing context (if any).109 *110 * @return string Data to be written to a cache file.111 *112 * @throws <b>AgaviUnreadableException</b> If a requested configuration113 * file does not exist or is not114 * readable.115 * @throws <b>AgaviParseException</b> If a requested configuration file is116 * improperly formatted.117 *118 * @author Sean Kerr <skerr@mojavi.org>119 * @since 0.9.0120 */121 abstract function execute($config, $context = null);122 123 /**124 * Generate the code for returning from execute().125 *126 * @param mixed A string with the code, or an array of code lines.127 *128 * @return string PHP code.129 *130 * @author David Zuelke <dz@bitxtender.com>131 * @since 0.11.0132 */133 protected function generate($code)134 {135 if(is_array($code)) {136 $code = implode("\n", $code);137 }138 139 return sprintf(140 "<?php\n\n// This is a compiled Agavi configuration file\n// Generated by: %s\n// Date: %s\n\n%s\n\n?>",141 get_class($this),142 date('c'),143 $code144 );145 }146 147 37 /** 148 38 * Initialize this ConfigHandler. … … 165 55 $this->setParameters($parameters); 166 56 } 167 168 /**169 * Literalize a string value.170 *171 * @param string The value to literalize.172 *173 * @return string A literalized value.174 *175 * @author Sean Kerr <skerr@mojavi.org>176 * @author Dominik del Bondio <ddb@bitxtender.com>177 * @since 0.9.0178 */179 public static function literalize($value)180 {181 if($value == null) {182 // null value183 return null;184 }185 186 if(!is_string($value)) {187 return $value;188 }189 190 // lowercase our value for comparison191 $value = trim($value);192 $lvalue = strtolower($value);193 194 if($lvalue == 'on' || $lvalue == 'yes' || $lvalue == 'true') {195 196 // replace values 'on' and 'yes' with a boolean true value197 return true;198 199 } elseif($lvalue == 'off' || $lvalue == 'no' || $lvalue == 'false') {200 201 // replace values 'off' and 'no' with a boolean false value202 return false;203 204 } elseif(!is_numeric($value)) {205 206 return self::replaceConstants($value);207 208 }209 210 // numeric value211 return $value;212 213 }214
