Changeset 1923
- Timestamp:
- 05/11/07 10:30:50 (20 months ago)
- Location:
- branches/david-xml_config_handlers/src/config
- Files:
-
- 1 added
- 8 modified
-
AgaviBaseConfigHandler.class.php (modified) (2 diffs)
-
AgaviConfigCache.class.php (modified) (3 diffs)
-
AgaviConfigHandler.class.php (modified) (1 diff)
-
AgaviConfigParser.class.php (modified) (1 diff)
-
AgaviILegacyConfigHandler.interface.php (added)
-
AgaviIXmlConfigHandler.class.php (modified) (1 diff)
-
AgaviXmlConfigHandler.class.php (modified) (1 diff)
-
AgaviXmlConfigParser.class.php (modified) (2 diffs)
-
defaults/config_handlers.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/david-xml_config_handlers/src/config/AgaviBaseConfigHandler.class.php
r1917 r1923 103 103 104 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 105 * Generate the code for returning from execute(). 125 106 * … … 145 126 } 146 127 147 /**148 * Initialize this ConfigHandler.149 *150 * @param string The path to a validation file for this config handler.151 * @param string The parser class to use.152 * @param array An associative array of initialization parameters.153 *154 * @throws <b>AgaviInitializationException</b> If an error occurs while155 * initializing the156 * ConfigHandler157 *158 * @author Dominik del Bondio <ddb@bitxtender.com>159 * @since 0.9.0160 */161 public function initialize($validationFile = null, $parser = null, $parameters = array())162 {163 $this->validationFile = $validationFile;164 $this->parser = $parser;165 $this->setParameters($parameters);166 }167 168 128 /** 169 129 * Literalize a string value. -
branches/david-xml_config_handlers/src/config/AgaviConfigCache.class.php
r1920 r1923 99 99 $handler = new $handlerInfo['class']; 100 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']); 101 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 } 102 117 } else { 103 if(isset($handlerInfo['validation'])) 104 $handler->initialize($handlerInfo['validation'], null, $handlerInfo['parameters']); 105 } 106 107 $data = $handler->execute($config, $context); 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 108 126 self::writeCacheFile($config, $cache, $data, false); 109 127 } … … 240 258 // since we only need the parser and handlers when the config is not cached 241 259 // it is sufficient to include them at this stage 260 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviILegacyConfigHandler.interface.php'); 261 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviIXmlConfigHandler.class.php'); 242 262 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviBaseConfigHandler.class.php'); 243 263 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviConfigHandler.class.php'); 244 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviIXmlConfigHandler.class.php');245 264 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviXmlConfigHandler.class.php'); 246 265 require(AgaviConfig::get('core.agavi_dir') . '/config/AgaviAutoloadConfigHandler.class.php'); … … 328 347 * @since 0.11.0 329 348 */ 330 public static function parseConfig($config, $autoloadParser = true, $validat eFile = null, $parserClass = null)349 public static function parseConfig($config, $autoloadParser = true, $validationFile = null, $parserClass = null) 331 350 { 332 351 $parser = new AgaviConfigParser(); 333 352 334 return $parser->parse($config, $validat eFile);353 return $parser->parse($config, $validationFile); 335 354 } 336 355 } -
branches/david-xml_config_handlers/src/config/AgaviConfigHandler.class.php
r1917 r1923 33 33 * @version $Id$ 34 34 */ 35 abstract class AgaviConfigHandler extends AgaviBaseConfigHandler 35 abstract class AgaviConfigHandler extends AgaviBaseConfigHandler implements AgaviILegacyConfigHandler 36 36 { 37 /** 38 * Initialize this ConfigHandler. 39 * 40 * @param string The path to a validation file for this config handler. 41 * @param string The parser class to use. 42 * @param array An associative array of initialization parameters. 43 * 44 * @throws <b>AgaviInitializationException</b> If an error occurs while 45 * initializing the 46 * ConfigHandler 47 * 48 * @author Dominik del Bondio <ddb@bitxtender.com> 49 * @since 0.9.0 50 */ 51 public function initialize($validationFile = null, $parser = null, $parameters = array()) 52 { 53 $this->validationFile = $validationFile; 54 $this->parser = $parser; 55 $this->setParameters($parameters); 56 } 37 57 } 38 58 -
branches/david-xml_config_handlers/src/config/AgaviConfigParser.class.php
r1920 r1923 48 48 * @since 0.11.0 49 49 */ 50 public function parse($config, array $validationInfo = array())50 public function parse($config, $validationFile = null) 51 51 { 52 52 $parser = new AgaviXmlConfigParser(); 53 53 54 $doc = $parser->parse($config, $validationInfo); 54 $validation = array(); 55 if($validationFile !== null) { 56 $validation[AgaviXmlConfigParser::VALIDATION_TYPE_XMLSCHEMA] = array($validationFile); 57 } 58 $doc = $parser->parse($config, $validation); 55 59 56 60 $this->encoding = $doc->encoding; -
branches/david-xml_config_handlers/src/config/AgaviIXmlConfigHandler.class.php
r1917 r1923 31 31 interface AgaviIXmlConfigHandler 32 32 { 33 /** 34 * Initialize this ConfigHandler. 35 * 36 * @param AgaviContext The context to work with (if available). 37 * @param array An associative array of initialization parameters. 38 * 39 * @throws <b>AgaviInitializationException</b> If an error occurs while 40 * initializing the 41 * ConfigHandler 42 * 43 * @author David Zülke <dz@bitxtender.com> 44 * @since 0.11.0 45 */ 46 public function initialize(AgaviContext $context = null, $parameters = array()); 47 48 /** 49 * Execute this configuration handler. 50 * 51 * @param array An array of DOMDocuments (the config and all parents). 52 * 53 * @return string Data to be written to a cache file. 54 * 55 * @throws <b>AgaviParseException</b> If a requested configuration file is 56 * improperly formatted. 57 * 58 * @author David Zülke <dz@bitxtender.com> 59 * @since 0.11.0 60 */ 61 public function execute(array $array = array()); 33 62 } 63 64 ?> -
branches/david-xml_config_handlers/src/config/AgaviXmlConfigHandler.class.php
r1920 r1923 28 28 * @version $Id$ 29 29 */ 30 class AgaviXmlConfigHandler extends AgaviBaseConfigHandler implements AgaviIXmlConfigHandler30 abstract class AgaviXmlConfigHandler extends AgaviBaseConfigHandler implements AgaviIXmlConfigHandler 31 31 { 32 public function execute($config, $context = null) 32 /** 33 * @var AgaviContext The context to work with (if available). 34 */ 35 protected $context = null; 36 37 /** 38 * Initialize this ConfigHandler. 39 * 40 * @param AgaviContext The context to work with (if available). 41 * @param array An associative array of initialization parameters. 42 * 43 * @throws <b>AgaviInitializationException</b> If an error occurs while 44 * initializing the 45 * ConfigHandler 46 * 47 * @author David Zülke <dz@bitxtender.com> 48 * @since 0.11.0 49 */ 50 public function initialize(AgaviContext $context = null, $parameters = array()) 33 51 { 52 $this->context = $context; 53 $this->setParameters($parameters); 34 54 } 35 55 } 56 57 ?> -
branches/david-xml_config_handlers/src/config/AgaviXmlConfigParser.class.php
r1920 r1923 29 29 * @version $Id$ 30 30 */ 31 class AgaviXmlConfigParser extends AgaviConfigParser31 class AgaviXmlConfigParser 32 32 { 33 33 const XML_NAMESPACE = 'http://agavi.org/agavi/1.0/config'; … … 44 44 * 45 45 * @return array An array of DOMDocuments (from child to parent). 46 * 47 * @author David Zülke <dz@bitxtender.com> 48 * @author Dominik del Bondio <ddb@bitxtender.com> 49 * @since 0.11.0 50 */ 51 public function parseAll($config, array $validation = array()) 52 { 53 $retval = array(); 54 55 $nextConfig = $config; 56 57 while($nextConfig !== null) { 58 $doc = $this->parse($nextConfig, $validation); 59 60 if($doc->documentElement->hasAttribute('parent')) { 61 $nextConfig = AgaviBaseConfigHandler::literalize($doc->documentElement->getAttribute('parent')); 62 } else { 63 $nextConfig = null; 64 } 65 66 $retval[] = $doc; 67 } 68 69 return $retval; 70 } 71 72 /** 73 * @param string An absolute filesystem path to a configuration file. 74 * @param array An associative array of validation information. 75 * 76 * @return DOMDocument A DOMDocument. 46 77 * 47 78 * @author David Zülke <dz@bitxtender.com> -
branches/david-xml_config_handlers/src/config/defaults/config_handlers.xml
r1910 r1923 36 36 <handler pattern="%core.config_dir%/routing.xml" validate="%core.agavi_dir%/config/xsd/routing.xsd" class="AgaviRoutingConfigHandler" /> 37 37 38 <handler pattern="%core.config_dir%/wsdl.xml" validate="%core.agavi_dir%/config/xsd/routing.xsd" class="AgaviWsdlConfigHandler" /> 39 38 40 <handler pattern="%core.config_dir%/translation.xml" validate="%core.agavi_dir%/config/xsd/translation.xsd" class="AgaviTranslationConfigHandler" /> 39 41

