Development

Changeset 19677

You must first sign up to be able to contribute.

Changeset 19677

Show
Ignore:
Timestamp:
06/29/09 16:03:28 (4 years ago)
Author:
fabien
Message:

[dependency_injection] optimized the PHP dumper

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • components/dependency_injection/trunk/lib/sfServiceContainerDumperPhp.php

    r19655 r19677  
    8787    $class = $this->dumpValue($definition->getClass()); 
    8888 
    89     if (is_string($definition->getArguments())) 
    90     { 
    91       $arguments = array($this->dumpValue($definition->getArguments())); 
    92     } 
    93     else 
    94     { 
    95       $arguments = array(); 
    96       foreach ($definition->getArguments() as $value) 
    97       { 
    98         $arguments[] = $this->dumpValue($value); 
    99       } 
     89    $arguments = array(); 
     90    foreach ($definition->getArguments() as $value) 
     91    { 
     92      $arguments[] = $this->dumpValue($value); 
    10093    } 
    10194 
     
    122115    foreach ($definition->getMethodCalls() as $call) 
    123116    { 
    124       if (is_string($call[1])) 
    125       { 
    126         $arguments = array($this->dumpValue($call[1])); 
     117      $arguments = array(); 
     118      foreach ($call[1] as $value) 
     119      { 
     120        $arguments[] = $this->dumpValue($value); 
     121      } 
     122 
     123      $calls .= sprintf("    \$instance->%s(%s);\n", $call[0], implode(', ', $arguments)); 
     124    } 
     125 
     126    return $calls; 
     127  } 
     128 
     129  protected function addServiceConfigurator($id, $definition) 
     130  { 
     131    if (!$callable = $definition->getConfigurator()) 
     132    { 
     133      return ''; 
     134    } 
     135 
     136    if (is_array($callable)) 
     137    { 
     138      if (is_object($callable[0]) && $callable[0] instanceof sfServiceReference) 
     139      { 
     140        return sprintf("    %s->%s(\$instance);\n", $this->getServiceCall((string) $callable[0]), $callable[1]); 
    127141      } 
    128142      else 
    129143      { 
    130         $arguments = array(); 
    131         foreach ($call[1] as $value) 
    132         { 
    133           $arguments[] = $this->dumpValue($value); 
    134         } 
    135       } 
    136  
    137       $calls .= sprintf("    \$instance->%s(%s);\n", $call[0], implode(', ', $arguments)); 
    138     } 
    139  
    140     return $calls; 
    141   } 
    142  
    143   protected function addServiceConfigurator($id, $definition) 
    144   { 
    145     if ($callable = $definition->getConfigurator()) 
    146     { 
    147       if (is_array($callable)) 
    148       { 
    149         if (is_object($callable[0]) && $callable[0] instanceof sfServiceReference) 
    150         { 
    151           return sprintf("    %s->%s(\$instance);\n", $this->getServiceCall((string) $callable[0]), $callable[1]); 
    152         } 
    153         else 
    154         { 
    155           return sprintf("    call_user_func(array(%s, '%s'), \$instance);\n", $this->dumpValue($callable[0]), $callable[1]); 
    156         } 
    157       } 
    158       else 
    159       { 
    160         return sprintf("    %s(\$instance);\n", $callable); 
    161       } 
     144        return sprintf("    call_user_func(array(%s, '%s'), \$instance);\n", $this->dumpValue($callable[0]), $callable[1]); 
     145      } 
     146    } 
     147    else 
     148    { 
     149      return sprintf("    %s(\$instance);\n", $callable); 
    162150    } 
    163151  } 
     
    271259      else 
    272260      { 
    273         $code = preg_replace_callback('/(%{1,2})([^%]+)\1/', array($this, 'replaceParameter'), var_export($value, true)); 
     261        $code = str_replace('%%', '%', preg_replace_callback('/(?<!%)(%)([^%]+)\1/', array($this, 'replaceParameter'), var_export($value, true))); 
    274262 
    275263        // optimize string 
     
    291279  public function replaceParameter($match) 
    292280  { 
    293     if ('%%' == $match[1]) 
    294     { 
    295       // % escaping 
    296       return '%'.$match[2].'%'; 
    297     } 
    298  
    299281    return sprintf("'.\$this->getParameter('%s').'", strtolower($match[2])); 
    300282  }