Changeset 115
- Timestamp:
- 11/11/07 15:24:40 (10 months ago)
- Files:
-
- trunk/XJConf/DefinedTag.php (modified) (1 diff)
- trunk/XJConf/DefinitionParser.php (modified) (3 diffs)
- trunk/XJConf/GenericTag.php (modified) (1 diff)
- trunk/XJConf/Tag.php (modified) (2 diffs)
- trunk/XJConf/XJConfClassLoader.php (modified) (1 diff)
- trunk/XJConf/XJConfFacade.php (modified) (2 diffs)
- trunk/XJConf/XJConfLoader.php (modified) (4 diffs)
- trunk/XJConf/XmlParser.php (modified) (4 diffs)
- trunk/XJConf/converters/AbstractObjectValueConverter.php (modified) (6 diffs)
- trunk/XJConf/converters/ArrayValueConverter.php (modified) (1 diff)
- trunk/XJConf/converters/AutoPrimitiveValueConverter.php (modified) (2 diffs)
- trunk/XJConf/converters/ConstructorValueConverter.php (modified) (4 diffs)
- trunk/XJConf/converters/FactoryMethodValueConverter.php (modified) (3 diffs)
- trunk/XJConf/converters/PrimitiveValueConverter.php (modified) (2 diffs)
- trunk/XJConf/converters/StaticClassValueConverter.php (modified) (6 diffs)
- trunk/XJConf/converters/ValueConverter.php (modified) (1 diff)
- trunk/XJConf/converters/factories/ArrayValueConverterFactory.php (modified) (1 diff)
- trunk/XJConf/converters/factories/AutoPrimitiveValueConverterFactory.php (modified) (2 diffs)
- trunk/XJConf/converters/factories/ConstructorValueConverterFactory.php (modified) (1 diff)
- trunk/XJConf/converters/factories/FactoryMethodValueConverterFactory.php (modified) (3 diffs)
- trunk/XJConf/converters/factories/PrimitiveValueConverterFactory.php (modified) (1 diff)
- trunk/XJConf/converters/factories/StaticClassValueConverterFactory.php (modified) (2 diffs)
- trunk/XJConf/converters/factories/ValueConverterFactory.php (modified) (2 diffs)
- trunk/XJConf/converters/factories/ValueConverterFactoryChain.php (modified) (2 diffs)
- trunk/XJConf/definitions/AbstractTagDefinition.php (modified) (5 diffs)
- trunk/XJConf/definitions/AttributeDefinition.php (modified) (4 diffs)
- trunk/XJConf/definitions/CDataDefinition.php (modified) (2 diffs)
- trunk/XJConf/definitions/ChildDefinition.php (modified) (4 diffs)
- trunk/XJConf/definitions/ConcreteTagDefinition.php (modified) (1 diff)
- trunk/XJConf/definitions/ConstructorDefinition.php (modified) (1 diff)
- trunk/XJConf/definitions/Definition.php (modified) (2 diffs)
- trunk/XJConf/definitions/FactoryMethodDefinition.php (modified) (2 diffs)
- trunk/XJConf/definitions/MethodCallTagDefinition.php (modified) (5 diffs)
- trunk/XJConf/definitions/NamespaceDefinition.php (modified) (1 diff)
- trunk/XJConf/definitions/NamespaceDefinitions.php (modified) (1 diff)
- trunk/XJConf/definitions/TagDefinition.php (modified) (5 diffs)
- trunk/XJConf/definitions/ValueModifier.php (modified) (1 diff)
- trunk/XJConf/definitions/handler/AbstractTagDefinitionHandler.php (modified) (1 diff)
- trunk/XJConf/definitions/handler/AttributeDefinitionHandler.php (modified) (2 diffs)
- trunk/XJConf/definitions/handler/CDataDefinitionHandler.php (modified) (2 diffs)
- trunk/XJConf/definitions/handler/ChildDefinitionHandler.php (modified) (2 diffs)
- trunk/XJConf/definitions/handler/ConcreteTagDefinitionHandler.php (modified) (1 diff)
- trunk/XJConf/definitions/handler/ConstructorDefinitionHandler.php (modified) (2 diffs)
- trunk/XJConf/definitions/handler/DefinitionHandler.php (modified) (4 diffs)
- trunk/XJConf/definitions/handler/DefinitionHandlerFactory.php (modified) (3 diffs)
- trunk/XJConf/definitions/handler/EmptyDefinitionHandler.php (modified) (1 diff)
- trunk/XJConf/definitions/handler/FactoryMethodDefinitionHandler.php (modified) (2 diffs)
- trunk/XJConf/definitions/handler/MethodCallTagDefinitionHandler.php (modified) (3 diffs)
- trunk/XJConf/definitions/handler/TagDefinitionHandler.php (modified) (1 diff)
- trunk/XJConf/exceptions/InvalidNamespaceDefinitionException.php (modified) (1 diff)
- trunk/XJConf/exceptions/InvalidTagDefinitionException.php (modified) (1 diff)
- trunk/XJConf/exceptions/MissingAttributeException.php (modified) (1 diff)
- trunk/XJConf/exceptions/UnknownNamespaceException.php (modified) (1 diff)
- trunk/XJConf/exceptions/UnknownTagException.php (modified) (1 diff)
- trunk/XJConf/exceptions/UnsupportedOperationException.php (modified) (1 diff)
- trunk/XJConf/exceptions/ValueConversionException.php (modified) (1 diff)
- trunk/XJConf/exceptions/XJConfException.php (modified) (1 diff)
- trunk/XJConf/ext/Extension.php (modified) (2 diffs)
- trunk/XJConf/ext/xinc/XInclude.php (modified) (2 diffs)
- trunk/XJConf/ext/xinc/XIncludeException.php (modified) (1 diff)
- trunk/package.php (modified) (3 diffs)
- trunk/tests/definitions/AttributeDefinitionTestCase.php (modified) (3 diffs)
- trunk/tests/definitions/CDataDefinitionTestCase.php (modified) (1 diff)
- trunk/tests/definitions/ConstructorDefinitionTestCase.php (modified) (1 diff)
- trunk/tests/definitions/FactoryMethodDefinitionTestCase.php (modified) (3 diffs)
- trunk/tests/definitions/NamespaceDefinitionTestCase.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/XJConf/DefinedTag.php
r94 r115 6 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 7 */ 8 XJConfLoader::load('Tag', 9 'definitions.TagDefinition' 10 ); 8 namespace net::xjconf; 9 use net::xjconf::Tag; 10 use net::xjconf::definitions::ConcreteTagDefinition; 11 use net::xjconf::definitions::TagDefinition; 11 12 /** 12 13 * Contains data of tag in the default namespace. trunk/XJConf/DefinitionParser.php
r98 r115 6 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 7 */ 8 XJConfLoader::load('definitions.AttributeDefinition', 9 'definitions.CDataDefinition', 10 'definitions.ChildDefinition', 11 'definitions.ConstructorDefinition', 12 'definitions.FactoryMethodDefinition', 13 'definitions.MethodCallTagDefinition', 14 'definitions.NamespaceDefinition', 15 'definitions.NamespaceDefinitions', 16 'definitions.TagDefinition', 17 'definitions.handler.DefinitionHandlerFactory', 18 'exceptions.InvalidNamespaceDefinitionException' 19 );8 namespace net::xjconf; 9 use net::xjconf::definitions::AttributeDefinition; 10 use net::xjconf::definitions::CDataDefinition; 11 use net::xjconf::definitions::ChildDefinition; 12 use net::xjconf::definitions::ConstructorDefinition; 13 use net::xjconf::definitions::FactoryMethodDefinition; 14 use net::xjconf::definitions::MethodCallTagDefinition; 15 use net::xjconf::definitions::NamespaceDefinition; 16 use net::xjconf::definitions::NamespaceDefinitions; 17 use net::xjconf::definitions::TagDefinition; 18 use net::xjconf::definitions::handler.DefinitionHandlerFactory; 19 use net::xjconf::exceptions::InvalidNamespaceDefinitionException; 20 20 /** 21 21 * Parse tag definitions files. … … 93 93 $this->currentNamespace = self::DEFAULT_NAMESPACE; 94 94 $this->classLoaders = $classLoaders; 95 96 if (!defined('XMLREADER_ELEMENT')) { 97 $this->nodeTypes = array('startTag' => XMLReader::ELEMENT, 98 'text' => XMLReader::TEXT, 99 'endTag' => XMLReader::END_ELEMENT 100 ); 101 } else { 102 $this->nodeTypes = array('startTag' => XMLREADER_ELEMENT, 103 'text' => XMLREADER_TEXT, 104 'endTag' => XMLREADER_END_ELEMENT 105 ); 106 } 95 $this->nodeTypes = array('startTag' => XMLReader::ELEMENT, 96 'text' => XMLReader::TEXT, 97 'endTag' => XMLReader::END_ELEMENT 98 ); 107 99 } 108 100 … … 173 165 { 174 166 if (null == $this->reader) { 175 $this->reader = new XMLReader();167 $this->reader = new ::XMLReader(); 176 168 } 177 169 } trunk/XJConf/GenericTag.php
r94 r115 6 6 * @author Stephan Schmidt <me@schst.net> 7 7 */ 8 XJConfLoader::load('Tag');8 namespace net::xjconf; 9 9 /** 10 10 * Generic Tag wrapper that can be used by extensions to dynamically add trunk/XJConf/Tag.php
r94 r115 6 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 7 */ 8 namespace net::xjconf; 8 9 /** 9 10 * Interface for holding tag data. … … 124 125 public function getSetterMethod(); 125 126 127 /** 128 * returns the definition for this tag 129 * 130 * @return Definition 131 */ 126 132 public function getDefinition(); 127 133 trunk/XJConf/XJConfClassLoader.php
r46 r115 5 5 * @author Frank Kleine <mikey@xjconf.net> 6 6 */ 7 namespace net::xjconf; 7 8 /** 8 9 * Interface for class loaders that can be used to load classes at runtime. trunk/XJConf/XJConfFacade.php
r102 r115 6 6 * @package XJConf 7 7 */ 8 XJConfLoader::load('DefinitionParser', 9 'XmlParser', 10 'ext.Extension', 11 'definitions.NamespaceDefinitions' 12 ); 8 namespace net::xjconf; 9 use net::xjconf::definitions::NamespaceDefinitions; 10 use net::xjconf::ext::Extension; 13 11 /** 14 12 * Facade for XJConf. … … 79 77 public function enableXIncludes() 80 78 { 81 XJConfLoader::load('ext.xinc.XInclude'); 82 $xincludeExtension = new XInclude(); 79 $xincludeExtension = new net::xjeconf::ext::xinc::XInclude(); 83 80 $this->addExtension($xincludeExtension); 84 81 } trunk/XJConf/XJConfLoader.php
r101 r115 3 3 * Class loader for all XJConf classes. 4 4 * 5 * @author Frank Kleine <frank.kleine@schlund.de> 5 * @author Frank Kleine <frank.kleine@schlund.de> 6 * @package XJConf 6 7 */ 8 namespace net::xjconf; 7 9 /** 8 10 * Class loader for all XJConf classes. … … 17 19 { 18 20 /** 19 * list of loaded files20 *21 * @var array<String>22 */23 private static $loadedClasses = array();24 25 /**26 21 * method to load files from source path 27 *28 * Usage: XJConfLoader::load('path.to.Classfile');29 * or load more than one at once:30 * XJConfLoader::load('path.to.first.Class',31 'path.to.second.Class'32 );33 * You may name as many files as you like, there is no restriction34 * on the number of arguments.35 22 * 36 23 * @param string list of file names to load 37 24 */ 38 public static function load( )25 public static function load($className) 39 26 { 40 $classes = func_get_args(); 41 if (count($classes) == 0) { 42 // its ok to call this without any arguments, this won't cause any harm 27 if (self::providesClass($className) === false) { 43 28 return; 44 29 } 30 31 if (substr(__FILE__, 0, 7) === 'star://') { 32 include str_replace('net::xjconf::XJConfLoader', '', __FILE__) . $className; 33 } 45 34 46 $realFiles = array(); 47 foreach ($classes as $className) { 48 if (in_array(str_replace('net.xjconf.', '', $className), self::$loadedClasses) == TRUE) { 49 continue; // step to next file if file is already loaded 50 } 51 52 $uri = null; 53 array_push(self::$loadedClasses, str_replace('net.xjconf.', '', $className)); 54 if (class_exists('StarClassRegistry', false) === true) { 55 if (substr($className, 0, 11) != 'net.xjconf.') { 56 $uri = StarClassRegistry::getUriForClass('net.xjconf.' . $className); 57 } else { 58 $uri = StarClassRegistry::getUriForClass($className); 59 } 60 } 61 if ($uri === null) { 62 $uri = dirname(__FILE__) . '/' . self::mapClassname($className); 63 } 64 65 require $uri; 66 } 35 include dirname(__FILE__) . '/' . self::mapClassname($className); 67 36 } 68 37 … … 73 42 * @return bool 74 43 */ 75 public static function classFileExists($className)44 public static function providesClass($className) 76 45 { 77 if (class_exists('StarClassRegistry') == false) { 78 return file_exists(dirname(__FILE__) . '/' . self::mapClassname($className)); 79 } 80 81 if (substr($className, 0, 11) != 'net.xjconf.') { 82 $fqClassName = 'net.xjconf.' . $className; 83 } else { 84 $fqClassName = $className; 85 } 86 87 if (StarClassRegistry::getFileForClass($fqClassName) != null) { 88 return true; 89 } 90 if (substr(dirname(__FILE__), 0, 7) == 'star://') { 91 return false; 46 if (substr(__FILE__, 0, 7) === 'star://') { 47 return file_exists(str_replace('net::xjconf::XJConfLoader', '', __FILE__) . $className); 92 48 } 93 49 … … 103 59 private static function mapClassname($classname) 104 60 { 105 return str_replace(' .', '/', $classname) . '.php';61 return str_replace('::', '/', str_replace('net::xjconf::', '', $classname)) . '.php'; 106 62 } 107 63 } 64 /** 65 * register with __autoload() 66 */ 67 spl_autoload_register(array('net::xjconf::XJConfLoader', 'load')); 108 68 ?> trunk/XJConf/XmlParser.php
r99 r115 6 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 7 */ 8 XJConfLoader::load('DefinedTag', 9 'GenericTag', 10 'definitions.NamespaceDefinition', 11 'definitions.NamespaceDefinitions', 12 'exceptions.UnknownNamespaceException', 13 'exceptions.UnknownTagException' 14 ); 8 namespace net::xjconf; 9 use net::xjconf::definitions::NamespaceDefinition; 10 use net::xjconf::definitions::NamespaceDefinitions; 11 use net::xjconf::exceptions::UnknownNamespaceException; 12 use net::xjconf::exceptions::UnknownTagException; 13 use net::xjconf::ext::Extension; 15 14 /** 16 15 * Parser that reads xml files and generates the data structure. … … 82 81 public function __construct() 83 82 { 84 if (!defined('XMLREADER_ELEMENT')) { 85 $this->nodeTypes = array('startTag' => XMLReader::ELEMENT, 86 'text' => XMLReader::TEXT, 87 'endTag' => XMLReader::END_ELEMENT 88 ); 89 } else { 90 $this->nodeTypes = array('startTag' => XMLREADER_ELEMENT, 91 'text' => XMLREADER_TEXT, 92 'endTag' => XMLREADER_END_ELEMENT 93 ); 94 } 83 $this->nodeTypes = array('startTag' => XMLReader::ELEMENT, 84 'text' => XMLReader::TEXT, 85 'endTag' => XMLReader::END_ELEMENT 86 ); 95 87 } 96 88 … … 232 224 private function initParser() 233 225 { 234 $reader = new XMLReader();226 $reader = new ::XMLReader(); 235 227 return $reader; 236 228 } … … 242 234 * onto the stack. 243 235 * 244 * @param string $namespaceURI namespace of start tag 245 * @param string $sName name of start tag 246 * @param array $atts attributes of tag 236 * @param string $namespaceURI namespace of start tag 237 * @param string $sName name of start tag 238 * @param array $atts attributes of tag 239 * @throws UnknownNamespaceException 240 * @throws UnknownTagException 247 241 */ 248 242 private function startElement($namespaceURI, $sName, $atts) trunk/XJConf/converters/AbstractObjectValueConverter.php
r110 r115 3 3 * Base class to convert a value to an object. 4 4 * 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 * @author Frank Kleine <frank.kleine@schlund.de> 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 * @package XJConf 8 * @subpackage converters 7 9 */ 8 XJConfLoader::load('converters.ValueConverter', 9 'exceptions.ValueConversionException' 10 ); 10 namespace net::xjconf::converters; 11 use net::xjconf::Tag; 12 use net::xjconf::definitions::Definition; 13 use net::xjconf::definitions::TagDefinition; 14 use net::xjconf::definitions::ValueModifier; 15 use net::xjconf::exceptions::ValueConversionException; 11 16 /** 12 17 * Base class to convert a value to an object. … … 50 55 protected function addAttributesToValue(Tag $tag, TagDefinition $def, $instance) 51 56 { 52 $class = new ReflectionClass(get_class($instance));57 $class = new ::ReflectionClass(get_class($instance)); 53 58 // set all attributes 54 59 foreach ($def->getAttributes() as $att) { … … 82 87 $method->invokeArgs($instance, array($att->getName(), $val)); 83 88 } 84 } catch ( ReflectionException $re) {89 } catch (::ReflectionException $re) { 85 90 throw new ValueConversionException('Could not set attribute "' . $att->getName() . '" of "' . $this->getType() . '" using "' . $att->getSetterMethod($tag) . '()" or "__set()" or public property "' . $att->getName() . '", exception message: "' . $re->getMessage() . '".'); 86 91 } … … 104 109 } 105 110 106 $class = new ReflectionClass(get_class($instance));111 $class = new ::ReflectionClass(get_class($instance)); 107 112 foreach ($children as $child) { 108 113 … … 141 146 $method->invokeArgs($instance, array($child->getName(), $child->getConvertedValue())); 142 147 } 143 } catch ( ReflectionException $re) {148 } catch (::ReflectionException $re) { 144 149 throw new ValueConversionException('Could not add child "' . $child->getKey() . '" to "' . $this->getType() . '" using "' . $child->getSetterMethod() . '()" or "' . $child->getKey() . '" or "__set()" or public property "' . $child->getKey() . '", exception message: "' . $re->getMessage() . '".'); 145 150 } … … 164 169 $value = $cDataDefinition->convertValue($tag); 165 170 try { 166 $class = new ReflectionClass(get_class($instance));171 $class = new ::ReflectionClass(get_class($instance)); 167 172 $class->getMethod($cDataDefinition->getSetterMethod($tag))->invoke($instance, $value); 168 } catch ( ReflectionException $re) {173 } catch (::ReflectionException $re) { 169 174 throw new ValueConversionException('Could not add cdata to "' . $this->getType() . '" using "' . $cDataDefinition->getSetterMethod($tag) . '()", exception message: "' . $re->getMessage() . '".'); 170 175 } trunk/XJConf/converters/ArrayValueConverter.php
r62 r115 3 3 * Converter to convert a value to an array. 4 4 * 5 * @author Frank Kleine <frank.kleine@schlund.de> 5 * @author Frank Kleine <frank.kleine@schlund.de> 6 * @package XJConf 7 * @subpackage converters 6 8 */ 7 XJConfLoader::load('converters.ValueConverter', 8 'definitions.Definition', 9 'definitions.TagDefinition' 10 );9 namespace net::xjconf::converters; 10 use net::xjconf::Tag; 11 use net::xjconf::definitions::Definition; 12 use net::xjconf::definitions::TagDefinition; 11 13 /** 12 14 * Converter to convert a value to an array. trunk/XJConf/converters/AutoPrimitiveValueConverter.php
r91 r115 4 4 * by trying to guess its type 5 5 * 6 * @package XJConf 7 * @author Stephan Schmidt <schst@xjconf.net> 6 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 7 * @author Frank Kleine <frank.kleine@schlund.de> 8 * @package XJConf 9 * @subpackage converters 8 10 */ 9 XJConfLoader::load('converters.ValueConverter', 10 'exceptions.ValueConversionException' 11 );11 namespace net::xjconf::converters; 12 use net::xjconf::Tag; 13 use net::xjconf::definitions::Definition; 12 14 /** 13 15 * Converter to convert a value into a primitive 14 16 * by trying to guess its type 15 17 * 16 * @package XJConf 18 * @package XJConf 19 * @subpackage converters 17 20 */ 18 21 class AutoPrimitiveValueConverter implements ValueConverter { … … 23 26 * @param array $values list of values to convert 24 27 * @return mixed the converted value 25 * @throws ValueConversionException26 28 */ 27 29 public function convertValue(Tag $tag, Definition $def) { trunk/XJConf/converters/ConstructorValueConverter.php
r100 r115 3 3 * Class to convert a value to an object using the constructor of the object. 4 4 * 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 * @author Frank Kleine <frank.kleine@schlund.de> 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 * @package XJConf 8 * @subpackage converters 7 9 */ 8 XJConfLoader::load('converters.ValueConverter', 9 'converters.AbstractObjectValueConverter', 10 'exceptions.ValueConversionException' 11 ); 10 namespace net::xjconf::converters; 11 use net::xjconf::Tag; 12 use net::xjconf::definitions::Definition; 13 use net::xjconf::definitions::TagDefinition; 14 use net::xjconf::exceptions::ValueConversionException; 12 15 /** 13 16 * Class to convert a value to an object using the constructor of the object. … … 51 54 // try to create a new instance 52 55 try { 53 $refClass = new ReflectionClass($this->className);56 $refClass = new ::ReflectionClass($this->className); 54 57 if (count($cParams) > 1 && method_exists($refClass, 'newInstanceArgs') == true) { 55 58 $instance = $refClass->newInstanceArgs($cParams); … … 73 76 try { 74 77 $instance = $refClass->newInstance($cParams[0]); 75 } catch ( ReflectionException $re) {78 } catch (::ReflectionException $re) { 76 79 $instance = $refClass->newInstance(); 77 80 } … … 81 84 throw new ValueConversionException('Could not create instance of "' . $this->className . '" as Reflection does not support newInstanceArgs().'); 82 85 } 83 } catch ( ReflectionException $re) {86 } catch (::ReflectionException $re) { 84 87 throw new ValueConversionException('Could not create instance of "' . $this->className . '": ' . $re->getMessage()); 85 88 } trunk/XJConf/converters/FactoryMethodValueConverter.php
r75 r115 3 3 * Value converter that uses a factory method to create an object. 4 4 * 5 * @author Stephan Schmidt <me@schst.net> 6 * @author Frank Kleine <frank.kleine@schlund.de> 5 * @author Stephan Schmidt <me@schst.net> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 * @package XJConf 8 * @subpackage converters 7 9 */ 8 XJConfLoader::load('converters.ValueConverter', 9 'converters.AbstractObjectValueConverter', 10 'exceptions.ValueConversionException' 11 ); 10 namespace net::xjconf::converters; 11 use net::xjconf::Tag; 12 use net::xjconf::definitions::Definition; 13 use net::xjconf::definitions::TagDefinition; 14 use net::xjconf::exceptions::ValueConversionException; 12 15 /** 13 16 * Value converter that uses a factory method to create an object. … … 59 62 60 63 try { 61 $refClass = new ReflectionClass($this->className);64 $refClass = new ::ReflectionClass($this->className); 62 65 $refMethod = $refClass->getMethod($this->methodName); 63 66 if (!$refMethod->isStatic()) { 64 67 throw new ValueConversionException('Could not create instance of "' . $this->className . '" using the factory method "' . $this->methodName . '" as it is no static method.'); 65 68 } 69 66 70 if (method_exists($refMethod, 'invokeArgs') == true) { 67 71 $instance = $refMethod->invokeArgs(null, $cParams); … … 73 77 throw new ValueConversionException('Could not create instance of "' . $this->className . '" as Reflection does not support invokeArgs().'); 74 78 } 75 } catch ( ReflectionException $re) {79 } catch (::ReflectionException $re) { 76 80 throw new ValueConversionException('Could not create instance of "' . $this->className . '" using the factory method "' . $this->methodName . '": ' . $re->getMessage()); 77 81 } trunk/XJConf/converters/PrimitiveValueConverter.php
r36 r115 1 1 <?php 2 XJConfLoader::load('converters.ValueConverter',3 'converters.PrimitiveValueConverter',4 'exceptions.ValueConversionException'5 );6 2 /** 7 * Converter to convert a value to a primitive type 3 * Converter to convert a value to a primitive type. 8 4 * 9 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 * @author Frank Kleine <mikey@xjconf.net> 7 * @package XJConf 8 * @subpackage converters 9 */ 10 namespace net::xjconf::converters; 11 use net::xjconf::Tag; 12 use net::xjconf::definitions::Definition; 13 14 /** 15 * Converter to convert a value to a primitive type. 16 * 17 * @package XJConf 18 * @subpackage converters 10 19 */ 11 20 class PrimitiveValueConverter implements ValueConverter 12 21 { 13 14 22 /** 15 23 * Type of the primitive … … 33 41 * @param array $values list of values to convert 34 42 * @return mixed the converted value 35 * @throws ValueConversionException36 43 */ 37 44 public function convertValue(Tag $tag, Definition $def) { trunk/XJConf/converters/StaticClassValueConverter.php
r88 r115 8 8 * @subpackage converters 9 9 */ 10 XJConfLoader::load('converters.ValueConverter', 11 'exceptions.ValueConversionException' 12 ); 10 namespace net::xjconf::converters; 11 use net::xjconf::Tag; 12 use net::xjconf::definitions::Definition; 13 use net::xjconf::definitions::TagDefinition; 14 use net::xjconf::exceptions::ValueConversionException; 13 15 /** 14 16 * Class to convert a value to an object using the constructor of the object. … … 56 58 } 57 59 60 /** 61 * returns the type 62 * 63 * @return string 64 */ 58 65 public function getType() { 59 66 return null; … … 70 77 protected function addAttributesToValue(Tag $tag, TagDefinition $def) 71 78 { 72 $class = new ReflectionClass($this->className);79 $class = new ::ReflectionClass($this->className); 73 80 // set all attributes 74 81 foreach ($def->getAttributes() as $att) { … … 85 92 throw new ValueConversionException('Could not set attribute "' . $att->getName() . '" of "' . $this->getType() . '" using "' . $att->getSetterMethod() . '()" as the method is not static.'); 86 93 } 94 87 95 $method->invoke(null, $val); 88 } catch ( ReflectionException $re) {96 } catch (::ReflectionException $re) { 89 97 throw new ValueConversionException('Could not set attribute "' . $att->getName() . '" of "' . $this->getType() . '" using "' . $att->getSetterMethod() . '()", exception message: "' . $re->getMessage() . '".'); 90 98 } … … 108 116 } 109 117 110 $class = new ReflectionClass($this->className);118 $class = new ::ReflectionClass($this->className); 111 119 foreach ($children as $child) { 112 120 try { … … 116 124 } 117 125 $method->invoke(null, $child->getConvertedValue()); 118 } catch ( ReflectionException $re) {126 } catch (::ReflectionException $re) { 119 127 throw new ValueConversionException('Could not add child "' . $child->getKey() . '" to "' . $this->getType() . '" using "' . $child->getSetterMethod() . '()", exception message: "' . $re->getMessage() . '".'); 120 128 } trunk/XJConf/converters/ValueConverter.php
r14 r115 1 1 <?php 2 2 /** 3 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 3 * Interface for a value converter. 4 * 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 * @package XJConf 8 * @subpackage converters 9 */ 10 namespace net::xjconf::converters; 11 use net::xjconf::Tag; 12 use net::xjconf::definitions::Definition; 13 /** 14 * Interface for a value converter. 15 * 16 * @package XJConf 17 * @subpackage converters 4 18 */ 5 19 interface ValueConverter trunk/XJConf/converters/factories/ArrayValueConverterFactory.php
r12 r115 3 3 * Factory to create an ArrayValueConverter. 4 4 * 5 * @author Frank Kleine <frank.kleine@schlund.de> 5 * @author Frank Kleine <frank.kleine@schlund.de> 6 * @package XJConf 7 * @subpackage converters_factories 6 8 */ 7 XJConfLoader::load('converters.factories.ValueConverterFactory', 8 'converters.ArrayValueConverter' 9 );9 namespace net::xjconf::converters::factories; 10 use net::xjconf::converters::ArrayValueConverter; 11 use net::xjconf::definitions::Definition; 10 12 /** 11 13 * Factory to create an ArrayValueConverter. 12 14 * 13 15 * @package XJConf 14 * @subpackage converters 16 * @subpackage converters_factories 15 17 */ 16 18 class ArrayValueConverterFactory implements ValueConverterFactory trunk/XJConf/converters/factories/AutoPrimitiveValueConverterFactory.php
r91 r115 1 1 <?php 2 2 /** 3 * Factory for AutoPrimitiveValueConverter objects 3 * Factory for AutoPrimitiveValueConverter objects. 4 4 * 5 * @author Stephan Schmidt <schst@xjconf.net> 6 * @package XJConf 5 * @author Stephan Schmidt <schst@xjconf.net> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 * @package XJConf 8 * @subpackage converters_factories 7 9 */ 8 XJConfLoader::load('converters.factories.ValueConverterFactory', 9 'converters.AutoPrimitiveValueConverter');10 10 namespace net::xjconf::converters::factories; 11 use net::xjconf::converters::AutoPrimitiveValueConverter; 12 use net::xjconf::definitions::Definition; 11 13 /** 12 * Factory for AutoPrimitiveValueConverter objects 14 * Factory for AutoPrimitiveValueConverter objects. 13 15 * 14 * @package XJConf 16 * @package XJConf 17 * @subpackage converters_factories 15 18 */ 16 class AutoPrimitiveValueConverterFactory implements ValueConverterFactory {17 19 class AutoPrimitiveValueConverterFactory implements ValueConverterFactory 20 { 18 21 /** 19 22 * This factory is only responsible, if the type 20 23 * is set to "xjconf:auto-primitive" 21 24 * 22 * @param Definition $def23 * @return boolean25 * @param Definition $def 26 * @return boolean 24 27 */ 25 public function isResponsible(Definition $def) { 28 public function isResponsible(Definition $def) 29 { 26 30 return 'xjconf:auto-primitive' === $def->getType(); 27 31 } … … 30 34 * Create a value converter 31 35 * 32 * @param Definition $def33 * @return ValueConverter36 * @param Definition $def 37 * @return ValueConverter 34 38 */ 35 public function createValueConverter(Definition $def) { 39 public function createValueConverter(Definition $def) 40 { 36 41 $converter = new AutoPrimitiveValueConverter(); 37 42 return $converter; trunk/XJConf/converters/factories/ConstructorValueConverterFactory.php
r22 r115 3 3 * Factory to create a ConstructorValueConverter. 4 4 * 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 * @author Frank Kleine <frank.kleine@schlund.de> 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6 * @author Frank Kleine <frank.kleine@schlund.de> 7 * @package XJConf 8 * @subpackage converters_factories 7 9 */ 8 XJConfLoader::load('converters.factories.ValueConverterFactory', 9 'converters.ConstructorValueConverter'); 10 namespace net::xjconf::converters::factories; 11 use net::xjconf::converters::ConstructorValueConverter; 12 use net::xjconf::definitions::Definition; 10 13 /** 11 14 * Factory to create an ConstructorValueConverter. 12 * 15 * 13 16 * @package XJConf 14 * @subpackage converters 17 * @subpackage converters_factories 15 18 */ 16 19 class ConstructorValueConverterFactory implements ValueConverterFactory 17 20 { 18 19 21 /** 20 22 * Decides whether the ConstructorValueConverter is responsible for the given Definition. trunk/XJConf/converters/factories/FactoryMethodValueConverterFactory.php
r22 r115 3 3 * Factory to create a FactoryMethodValueConverter. 4 4 * 5 * @author Stephan Schmidt <stephan.schmidt@schlund.de> 6
