Development

Changeset 19633

You must first sign up to be able to contribute.

Changeset 19633

Show
Ignore:
Timestamp:
06/28/09 09:51:55 (8 months ago)
Author:
fabien
Message:

[dependency_injection] ensured that parameter keys are always lowercased + simplified XML parsing

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • components/dependency_injection/trunk/lib/services.xsd

    r19562 r19633  
    4444    </xs:choice> 
    4545    <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" /> 
    4747    <xs:attribute name="shared" type="boolean" /> 
    4848    <xs:attribute name="constructor" type="xs:string" /> 
  • components/dependency_injection/trunk/lib/sfServiceContainerLoaderFile.php

    r19587 r19633  
    4646   * A resource is a file or an array of files. 
    4747   * 
    48    * The concrete classes always hava access to an array of files 
    49    * as this method converts single files 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
    5050   * 
    5151   * @param mixed $resource The resource path 
  • components/dependency_injection/trunk/lib/sfServiceContainerLoaderFileIni.php

    r19587 r19633  
    3838      if (isset($result['parameters']) && is_array($result['parameters'])) 
    3939      { 
    40         $parameters = array_merge($parameters, $result['parameters']); 
     40        foreach ($result['parameters'] as $key => $value) 
     41        { 
     42          $parameters[strtolower($key)] = $value; 
     43        } 
    4144      } 
    4245    } 
  • components/dependency_injection/trunk/lib/sfServiceContainerLoaderFileXml.php

    r19587 r19633  
    2020class sfServiceContainerLoaderFileXml extends sfServiceContainerLoaderFile 
    2121{ 
     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   */ 
    2248  public function doLoad($files) 
    2349  { 
     
    2551  } 
    2652 
    27   protected function parse($xmls) 
     53  protected function parse(array $xmls) 
    2854  { 
    2955    $parameters = array(); 
     
    5379  protected function parseParameters($xml, $file) 
    5480  { 
    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'); 
    6287  } 
    6388 
     
    96121    $importedFile = $this->getAbsolutePath((string) $import['resource'], dirname($file)); 
    97122 
    98     return call_user_func(array($loader, 'doLoad'), $importedFile); 
     123    return call_user_func(array($loader, 'doLoad'), array($importedFile)); 
    99124  } 
    100125 
     
    133158    } 
    134159 
    135     $definition->setArguments($service->getArgumentsAsPhpForServices('argument')); 
     160    $definition->setArguments($service->getArgumentsAsPhp('argument')); 
    136161 
    137162    if (isset($service->configurator)) 
     
    158183    foreach ($service->call as $call) 
    159184    { 
    160       $definition->addMethodCall((string) $call['method'], $call->getArgumentsAsPhpForServices()); 
     185      $definition->addMethodCall((string) $call['method'], $call->getArgumentsAsPhp('argument')); 
    161186    } 
    162187 
     
    169194    foreach ($files as $file) 
    170195    { 
    171       $file = $this->getAbsolutePath($file); 
    172  
    173       if (!file_exists($file)) 
     196      $path = $this->getAbsolutePath($file); 
     197 
     198      if (!file_exists($path)) 
    174199      { 
    175200        throw new InvalidArgumentException(sprintf('The service file "%s" does not exist.', $file)); 
     
    178203      $dom = new DOMDocument(); 
    179204      libxml_use_internal_errors(true); 
    180       if (!$dom->load($file)) 
     205      if (!$dom->load($path)) 
    181206      { 
    182207        throw new InvalidArgumentException(implode("\n", $this->getXmlErrors())); 
     
    185210      $this->validate($dom); 
    186211 
    187       $xmls[$file] = simplexml_import_dom($dom, 'sfServiceSimpleXMLElement'); 
     212      $xmls[$path] = simplexml_import_dom($dom, 'sfServiceSimpleXMLElement'); 
    188213    } 
    189214 
     
    198223    // find anonymous service definitions 
    199224    $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']; 
    208230    } 
    209231 
  • components/dependency_injection/trunk/lib/sfServiceContainerLoaderFileYaml.php

    r19587 r19633  
    4242      if (isset($content['parameters'])) 
    4343      { 
    44         $parameters = array_merge($parameters, $content['parameters']); 
     44        foreach ($content['parameters'] as $key => $value) 
     45        { 
     46          $parameters[strtolower($key)] = $value; 
     47        } 
    4548      } 
    4649 

The Sensio Labs Network

Since 1998, Sensio Labs has been promoting the Open-Source software movement by providing quality web application development, training, consulting.
Sensio Labs also supports several large Open-Source projects.