Changeset 19633
- Timestamp:
- 06/28/09 09:51:55 (8 months ago)
- Files:
-
- components/dependency_injection/trunk/lib/services.xsd (modified) (1 diff)
- components/dependency_injection/trunk/lib/sfServiceContainerLoaderFile.php (modified) (1 diff)
- components/dependency_injection/trunk/lib/sfServiceContainerLoaderFileIni.php (modified) (1 diff)
- components/dependency_injection/trunk/lib/sfServiceContainerLoaderFileXml.php (modified) (10 diffs)
- components/dependency_injection/trunk/lib/sfServiceContainerLoaderFileYaml.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
components/dependency_injection/trunk/lib/services.xsd
r19562 r19633 44 44 </xs:choice> 45 45 <xs:attribute name="id" type="xs:string" /> 46 <xs:attribute name="class" type="xs:string" />46 <xs:attribute name="class" type="xs:string" use="required" /> 47 47 <xs:attribute name="shared" type="boolean" /> 48 48 <xs:attribute name="constructor" type="xs:string" /> components/dependency_injection/trunk/lib/sfServiceContainerLoaderFile.php
r19587 r19633 46 46 * A resource is a file or an array of files. 47 47 * 48 * The concrete classes always hav aaccess to an array of files49 * as this method converts single file s to arrays.48 * The concrete classes always have access to an array of files 49 * as this method converts single file argument to an array. 50 50 * 51 51 * @param mixed $resource The resource path components/dependency_injection/trunk/lib/sfServiceContainerLoaderFileIni.php
r19587 r19633 38 38 if (isset($result['parameters']) && is_array($result['parameters'])) 39 39 { 40 $parameters = array_merge($parameters, $result['parameters']); 40 foreach ($result['parameters'] as $key => $value) 41 { 42 $parameters[strtolower($key)] = $value; 43 } 41 44 } 42 45 } components/dependency_injection/trunk/lib/sfServiceContainerLoaderFileXml.php
r19587 r19633 20 20 class sfServiceContainerLoaderFileXml extends sfServiceContainerLoaderFile 21 21 { 22 /** 23 * Loads an array of XML files. 24 * 25 * If multiple files are loaded, the services and parameters are merged. 26 * 27 * Remember that services and parameters are simple key/pair stores. 28 * 29 * When overriding a value, the old one is totally replaced, even if it is 30 * a "complex" value (an array for instance): 31 * 32 * file1.xml 33 * <parameter key="complex" type="collection"> 34 * <parameter>true</parameter> 35 * <parameter>false</parameter> 36 * </parameter> 37 * 38 * file2.xml 39 * <parameter key="complex">foo</parameter> 40 * 41 * If you load file1.xml and file2.xml in this order, the value of complex 42 * will be "foo". 43 * 44 * @param array $files An array of XML files 45 * 46 * @return array An array of definitions and parameters 47 */ 22 48 public function doLoad($files) 23 49 { … … 25 51 } 26 52 27 protected function parse( $xmls)53 protected function parse(array $xmls) 28 54 { 29 55 $parameters = array(); … … 53 79 protected function parseParameters($xml, $file) 54 80 { 55 $parameters = array(); 56 foreach ($xml->parameters as $parametersXml) 57 { 58 $parameters = array_merge($parameters, $parametersXml->getArgumentsAsPhpForServices('parameter', true)); 59 } 60 61 return $parameters; 81 if (!$xml->parameters) 82 { 83 return array(); 84 } 85 86 return $xml->parameters->getArgumentsAsPhp('parameter'); 62 87 } 63 88 … … 96 121 $importedFile = $this->getAbsolutePath((string) $import['resource'], dirname($file)); 97 122 98 return call_user_func(array($loader, 'doLoad'), $importedFile);123 return call_user_func(array($loader, 'doLoad'), array($importedFile)); 99 124 } 100 125 … … 133 158 } 134 159 135 $definition->setArguments($service->getArgumentsAsPhp ForServices('argument'));160 $definition->setArguments($service->getArgumentsAsPhp('argument')); 136 161 137 162 if (isset($service->configurator)) … … 158 183 foreach ($service->call as $call) 159 184 { 160 $definition->addMethodCall((string) $call['method'], $call->getArgumentsAsPhp ForServices());185 $definition->addMethodCall((string) $call['method'], $call->getArgumentsAsPhp('argument')); 161 186 } 162 187 … … 169 194 foreach ($files as $file) 170 195 { 171 $ file= $this->getAbsolutePath($file);172 173 if (!file_exists($ file))196 $path = $this->getAbsolutePath($file); 197 198 if (!file_exists($path)) 174 199 { 175 200 throw new InvalidArgumentException(sprintf('The service file "%s" does not exist.', $file)); … … 178 203 $dom = new DOMDocument(); 179 204 libxml_use_internal_errors(true); 180 if (!$dom->load($ file))205 if (!$dom->load($path)) 181 206 { 182 207 throw new InvalidArgumentException(implode("\n", $this->getXmlErrors())); … … 185 210 $this->validate($dom); 186 211 187 $xmls[$ file] = simplexml_import_dom($dom, 'sfServiceSimpleXMLElement');212 $xmls[$path] = simplexml_import_dom($dom, 'sfServiceSimpleXMLElement'); 188 213 } 189 214 … … 198 223 // find anonymous service definitions 199 224 $nodes = $xml->xpath('//argument[@type="service"][not(@id)]'); 200 if (is_array($nodes)) 201 { 202 foreach ($nodes as $node) 203 { 204 $node['id'] = sprintf('_%s_%d', md5($file), ++$count); 205 $definitions[(string) $node['id']] = array($node->service, $file); 206 $node->service['id'] = (string) $node['id']; 207 } 225 foreach ($nodes as $node) 226 { 227 $node['id'] = sprintf('_%s_%d', md5($file), ++$count); 228 $definitions[(string) $node['id']] = array($node->service, $file); 229 $node->service['id'] = (string) $node['id']; 208 230 } 209 231 components/dependency_injection/trunk/lib/sfServiceContainerLoaderFileYaml.php
r19587 r19633 42 42 if (isset($content['parameters'])) 43 43 { 44 $parameters = array_merge($parameters, $content['parameters']); 44 foreach ($content['parameters'] as $key => $value) 45 { 46 $parameters[strtolower($key)] = $value; 47 } 45 48 } 46 49

