Development

Changeset 7811

You must first sign up to be able to contribute.

Changeset 7811

Show
Ignore:
Timestamp:
03/12/08 01:55:10 (1 year ago)
Author:
fabien
Message:

refactored configuration parsing in config handler classes in a ::getConfiguration() method

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/config/sfAutoloadConfigHandler.class.php

    r7792 r7811  
    3333  { 
    3434    // set our required categories list and initialize our handler 
    35     $categories = array('required_categories' => array('autoload')); 
    36  
    37     $this->initialize($categories); 
     35    $this->initialize(array('required_categories' => array('autoload'))); 
    3836 
    3937    // parse the yaml 
    40     $myConfig = $this->parseYamls($configFiles); 
     38    $config = self::getConfiguration($configFiles); 
    4139 
    4240    // init our data array 
     
    4442 
    4543    // let's do our fancy work 
    46     foreach ($myConfig['autoload'] as $name => $entry) 
     44    foreach ($config['autoload'] as $name => $entry) 
    4745    { 
    4846      if (isset($entry['name'])) 
     
    5755        foreach ($entry['files'] as $class => $path) 
    5856        { 
    59           $path   = $this->replaceConstants($path); 
    60  
    6157          $data[] = sprintf("'%s' => '%s',", $class, $path); 
    6258        } 
     
    6763        $ext  = isset($entry['ext']) ? $entry['ext'] : '.php'; 
    6864        $path = $entry['path']; 
    69  
    70         $path = $this->replaceConstants($path); 
    71         $path = $this->replacePath($path); 
    7265 
    7366        // we automatically add our php classes 
     
    128121    return $retval; 
    129122  } 
     123 
     124  /** 
     125   * @see sfConfigHandler 
     126   */ 
     127  static public function getConfiguration(array $configFiles) 
     128  { 
     129    $config = self::replaceConstants(self::parseYamls($configFiles)); 
     130 
     131    foreach ($config['autoload'] as $name => $values) 
     132    { 
     133      if (isset($values['path'])) 
     134      { 
     135        $config['autoload'][$name]['path'] = self::replacePath($values['path']); 
     136      } 
     137    } 
     138 
     139    return $config; 
     140  } 
    130141} 
  • branches/1.1/lib/config/sfCacheConfigHandler.class.php

    r6458 r7811  
    3636  { 
    3737    // parse the yaml 
    38     $myConfig = $this->parseYamls($configFiles); 
    39  
    40     $myConfig['all'] = sfToolkit::arrayDeepMerge( 
    41       isset($myConfig['default']) && is_array($myConfig['default']) ? $myConfig['default'] : array(), 
    42       isset($myConfig['all']) && is_array($myConfig['all']) ? $myConfig['all'] : array() 
    43     ); 
    44  
    45     unset($myConfig['default']); 
    46  
    47     $this->yamlConfig = $myConfig; 
     38    $this->yamlConfig = self::getConfiguration($configFiles); 
    4839 
    4940    // iterate through all action names 
     
    113104    return implode("\n", $data); 
    114105  } 
     106 
     107  /** 
     108   * @see sfConfigHandler 
     109   */ 
     110  static public function getConfiguration(array $configFiles) 
     111  { 
     112    return self::flattenConfiguration(self::parseYamls($configFiles)); 
     113  } 
    115114} 
  • branches/1.1/lib/config/sfCompileConfigHandler.class.php

    r7792 r7811  
    3535  { 
    3636    // parse the yaml 
    37     $config = array(); 
    38     foreach ($configFiles as $configFile) 
    39     { 
    40       $config = array_merge($config, $this->parseYaml($configFile)); 
    41     } 
     37    $config = self::getConfiguration($configFiles); 
    4238 
    4339    // init our data 
     
    4743    foreach ($config as $file) 
    4844    { 
    49       $file = $this->replaceConstants($file); 
    50       $file = $this->replacePath($file); 
    51  
    5245      if (!is_readable($file)) 
    5346      { 
     
    110103    return $config; 
    111104  } 
     105 
     106  /** 
     107   * @see sfConfigHandler 
     108   */ 
     109  static public function getConfiguration(array $configFiles) 
     110  { 
     111    $config = array(); 
     112    foreach ($configFiles as $configFile) 
     113    { 
     114      $config = array_merge($config, self::parseYaml($configFile)); 
     115    } 
     116 
     117    return self::replacePath(self::replaceConstants($config)); 
     118  } 
    112119} 
  • branches/1.1/lib/config/sfConfigHandler.class.php

    r7792 r7811  
    7272   * @return string The new value 
    7373   */ 
    74   public static function replaceConstants($value) 
     74  static public function replaceConstants($value) 
    7575  { 
    7676    if (is_array($value)) 
     
    113113    return $this->parameterHolder; 
    114114  } 
     115 
     116  /** 
     117   * Returns the configuration for the current config handler. 
     118   * 
     119   * @param array An array of ordered configuration files 
     120   * 
     121   * @param array A configuration array 
     122   */ 
     123  static public function getConfiguration(array $configFiles) 
     124  { 
     125    throw new LogicException('You must call the ::getConfiguration() method on a concrete config handler class'); 
     126  } 
    115127} 
  • branches/1.1/lib/config/sfDatabaseConfigHandler.class.php

    r7792 r7811  
    3636  { 
    3737    // parse the yaml 
    38     $myConfig = $this->parseYamls($configFiles); 
    39  
    40     $myConfig = sfToolkit::arrayDeepMerge( 
    41       isset($myConfig['default']) && is_array($myConfig['default']) ? $myConfig['default'] : array(), 
    42       isset($myConfig['all']) && is_array($myConfig['all']) ? $myConfig['all'] : array(), 
    43       isset($myConfig[sfConfig::get('sf_environment')]) && is_array($myConfig[sfConfig::get('sf_environment')]) ? $myConfig[sfConfig::get('sf_environment')] : array() 
    44     ); 
     38    $config = self::getConfiguration($configFiles); 
    4539 
    4640    // init our data and includes arrays 
     
    5044 
    5145    // get a list of database connections 
    52     foreach ($myConfig as $name => $dbConfig) 
     46    foreach ($config as $name => $dbConfig) 
    5347    { 
    5448      // is this category already registered? 
     
    7266      { 
    7367        // we have a file to include 
    74         $file = $this->replacePath($this->replaceConstants($dbConfig['file'])); 
    75  
    76         if (!is_readable($file)) 
     68        if (!is_readable($dbConfig['file'])) 
    7769        { 
    7870          // database file doesn't exist 
    79           throw new sfParseException(sprintf('Configuration file "%s" specifies class "%s" with nonexistent or unreadable file "%s".', $configFiles[0], $dbConfig['class'], $file)); 
     71          throw new sfParseException(sprintf('Configuration file "%s" specifies class "%s" with nonexistent or unreadable file "%s".', $configFiles[0], $dbConfig['class'], $dbConfig['file'])); 
    8072        } 
    8173 
    8274        // append our data 
    83         $includes[] = sprintf("require_once('%s');", $file); 
     75        $includes[] = sprintf("require_once('%s');", $dbConfig['file']); 
    8476      } 
    8577 
     
    8880      if (isset($dbConfig['param'])) 
    8981      { 
    90         foreach ($dbConfig['param'] as $key => $value) 
    91         { 
    92           $parameters[$key] = $this->replaceConstants($value); 
    93         } 
     82        $parameters = $dbConfig['param']; 
    9483      } 
    9584      $parameters['name'] = $name; 
     
    10594                      date('Y/m/d H:i:s'), implode("\n", $includes), implode("\n", $data)); 
    10695  } 
     96 
     97  /** 
     98   * @see sfConfigHandler 
     99   */ 
     100  static public function getConfiguration(array $configFiles) 
     101  { 
     102    $config = self::replaceConstants(self::flattenConfigurationWithEnvironment(self::parseYamls($configFiles))); 
     103 
     104    foreach ($config as $name => $dbConfig) 
     105    { 
     106      if (isset($dbConfig['file'])) 
     107      { 
     108        $config[$name]['file'] = $this->replacePath($dbConfig['file']); 
     109      } 
     110    } 
     111 
     112    return $config; 
     113  } 
    107114} 
  • branches/1.1/lib/config/sfDefineEnvironmentConfigHandler.class.php

    r3254 r7811  
    4040 
    4141    // parse the yaml 
    42     $myConfig = $this->mergeEnvironment($this->parseYamls($configFiles)); 
     42    $config = self::getConfiguration($configFiles); 
    4343 
    4444    $values = array(); 
    45     foreach ($myConfig as $category => $keys) 
     45    foreach ($config as $category => $keys) 
    4646    { 
    4747      $values = array_merge($values, $this->getValues($prefix, $category, $keys)); 
     
    110110  protected function fixCategoryValue($category, $key, $value) 
    111111  { 
    112     // prefix the key 
    113     $key = $category.$key; 
    114  
    115     // replace constant values 
    116     $value = $this->replaceConstants($value); 
    117  
    118     return array($key, $value); 
     112    return array($category.$key, $value); 
    119113  } 
    120114 
     
    143137 
    144138  /** 
    145    * Merges default, all and current environment configurations. 
    146    * 
    147    * @param array The main configuratino array 
    148    * 
    149    * @param array The merged configuration 
     139   * @see sfConfigHandler 
    150140   */ 
    151   protected function mergeEnvironment($config
     141  static public function getConfiguration(array $configFiles
    152142  { 
    153     return sfToolkit::arrayDeepMerge( 
    154       isset($config['default']) && is_array($config['default']) ? $config['default'] : array(), 
    155       isset($config['all']) && is_array($config['all']) ? $config['all'] : array(), 
    156       isset($config[sfConfig::get('sf_environment')]) && is_array($config[sfConfig::get('sf_environment')]) ? $config[sfConfig::get('sf_environment')] : array() 
    157     ); 
     143    return self::replaceConstants(self::flattenConfigurationWithEnvironment(self::parseYamls($configFiles))); 
    158144  } 
    159145} 
  • branches/1.1/lib/config/sfFactoryConfigHandler.class.php

    r7792 r7811  
    3535  { 
    3636    // parse the yaml 
    37     $myConfig = $this->parseYamls($configFiles); 
    38  
    39     $myConfig = sfToolkit::arrayDeepMerge( 
    40       isset($myConfig['default']) && is_array($myConfig['default']) ? $myConfig['default'] : array(), 
    41       isset($myConfig['all']) && is_array($myConfig['all']) ? $myConfig['all'] : array(), 
    42       isset($myConfig[sfConfig::get('sf_environment')]) && is_array($myConfig[sfConfig::get('sf_environment')]) ? $myConfig[sfConfig::get('sf_environment')] : array() 
    43     ); 
     37    $config = self::getConfiguration($configFiles); 
    4438 
    4539    // init our data and includes arrays 
     
    5448    { 
    5549      // see if the factory exists for this controller 
    56       $keys = $myConfig[$factory]; 
     50      $keys = $config[$factory]; 
    5751 
    5852      if (!isset($keys['class'])) 
     
    6761      { 
    6862        // we have a file to include 
    69         $file = $this->replaceConstants($keys['file']); 
    70         $file = $this->replacePath($file); 
    71  
    72         if (!is_readable($file)) 
     63        if (!is_readable($keys['file'])) 
    7364        { 
    7465          // factory file doesn't exist 
    75           throw new sfParseException(sprintf('Configuration file "%s" specifies class "%s" with nonexistent or unreadable file "%s".', $configFiles[0], $class, $file)); 
     66          throw new sfParseException(sprintf('Configuration file "%s" specifies class "%s" with nonexistent or unreadable file "%s".', $configFiles[0], $class, $keys['file'])); 
    7667        } 
    7768 
    7869        // append our data 
    79         $includes[] = sprintf("require_once('%s');", $file); 
     70        $includes[] = sprintf("require_once('%s');", $keys['file']); 
    8071      } 
    8172 
     
    8980        } 
    9081 
    91         foreach ($keys['param'] as $key => $value) 
    92         { 
    93           $parameters[$key] = $this->replaceConstants($value); 
    94         } 
     82        $parameters = $keys['param']; 
    9583      } 
    9684 
     
    180168            foreach ($parameters['loggers'] as $name => $keys) 
    181169            { 
    182               if (isset($keys['enabled']) && !$this->replaceConstants($keys['enabled'])
     170              if (isset($keys['enabled']) && !$keys['enabled']
    183171              { 
    184172                continue; 
     
    194182              if (isset($keys['param']['condition'])) 
    195183              { 
    196                 $condition = $this->replaceConstants($keys['param']['condition'])
     184                $condition = $keys['param']['condition']
    197185                unset($keys['param']['condition']); 
    198186              } 
     
    228216    return $retval; 
    229217  } 
     218 
     219  /** 
     220   * @see sfConfigHandler 
     221   */ 
     222  static public function getConfiguration(array $configFiles) 
     223  { 
     224    $config = self::replaceConstants(self::flattenConfigurationWithEnvironment(self::parseYamls($configFiles))); 
     225 
     226    foreach ($config as $factory => $values) 
     227    { 
     228      if (isset($values['file'])) 
     229      { 
     230        $config[$factory]['file'] = $this->replacePath($values['file']); 
     231      } 
     232    } 
     233 
     234    return $config; 
     235  } 
    230236} 
  • branches/1.1/lib/config/sfFilterConfigHandler.class.php

    r7792 r7811  
    3434  { 
    3535    // parse the yaml 
    36     $config = $this->parseYaml($configFiles[0]); 
    37     foreach (array_slice($configFiles, 1) as $i => $configFile) 
    38     { 
    39       // we get the order of the new file and merge with the previous configurations 
    40       $previous = $config; 
    41  
    42       $config = array(); 
    43       foreach ($this->parseYaml($configFile) as $key => $value) 
    44       { 
    45         $value = (array) $value; 
    46         $config[$key] = isset($previous[$key]) ? sfToolkit::arrayDeepMerge($previous[$key], $value) : $value; 
    47       } 
    48  
    49       // check that every key in previous array is still present (to avoid problem when upgrading) 
    50       foreach (array_keys($previous) as $key) 
    51       { 
    52         if (!isset($config[$key])) 
    53         { 
    54           throw new sfConfigurationException(sprintf('The filter name "%s" is defined in "%s" but not present in "%s" file. To disable a filter, add a "enabled" key with a false value.', $key, $configFiles[$i], $configFile)); 
    55         } 
    56       } 
    57     } 
     36    $config = self::getConfiguration($configFiles); 
    5837 
    5938    // init our data and includes arrays 
     
    8261      if (isset($keys['file'])) 
    8362      { 
    84         // we have a file to include 
    85         $file = $this->replaceConstants($keys['file']); 
    86         $file = $this->replacePath($file); 
    87  
    88         if (!is_readable($file)) 
     63        if (!is_readable($keys['file'])) 
    8964        { 
    9065          // filter file doesn't exist 
    91           throw new sfParseException(sprintf('Configuration file "%s" specifies class "%s" with nonexistent or unreadable file "%s".', $configFiles[0], $class, $file)); 
     66          throw new sfParseException(sprintf('Configuration file "%s" specifies class "%s" with nonexistent or unreadable file "%s".', $configFiles[0], $class, $keys['file'])); 
    9267        } 
    9368 
    9469        // append our data 
    95         $includes[] = sprintf("require_once('%s');\n", $file); 
     70        $includes[] = sprintf("require_once('%s');\n", $keys['file']); 
    9671      } 
    9772 
     
    9974      if (isset($keys['param']['condition'])) 
    10075      { 
    101         $condition = $this->replaceConstants($keys['param']['condition'])
     76        $condition = $keys['param']['condition']
    10277        unset($keys['param']['condition']); 
    10378      } 
     
    189164EOF; 
    190165  } 
     166 
     167  /** 
     168   * @see sfConfigHandler 
     169   */ 
     170  static public function getConfiguration(array $configFiles) 
     171  { 
     172    $config = self::parseYaml($configFiles[0]); 
     173    foreach (array_slice($configFiles, 1) as $i => $configFile) 
     174    { 
     175      // we get the order of the new file and merge with the previous configurations 
     176      $previous = $config; 
     177 
     178      $config = array(); 
     179      foreach (self::parseYaml($configFile) as $key => $value) 
     180      { 
     181        $value = (array) $value; 
     182        $config[$key] = isset($previous[$key]) ? sfToolkit::arrayDeepMerge($previous[$key], $value) : $value; 
     183      } 
     184 
     185      // check that every key in previous array is still present (to avoid problem when upgrading) 
     186      foreach (array_keys($previous) as $key) 
     187      { 
     188        if (!isset($config[$key])) 
     189        { 
     190          throw new sfConfigurationException(sprintf('The filter name "%s" is defined in "%s" but not present in "%s" file. To disable a filter, add a "enabled" key with a false value.', $key, $configFiles[$i], $configFile)); 
     191        } 
     192      } 
     193    } 
     194 
     195    $config = self::replaceConstants($config); 
     196 
     197    foreach ($config as $category => $keys) 
     198    { 
     199      if (isset($keys['file'])) 
     200      { 
     201        $config['category']['file'] = $this->replacePath($keys['file']); 
     202      } 
     203    } 
     204 
     205    return $config; 
     206  } 
    191207} 
  • branches/1.1/lib/config/sfGeneratorConfigHandler.class.php

    r7691 r7811  
    3333  { 
    3434    // parse the yaml 
    35     $config = $this->parseYamls($configFiles); 
     35    $config = self::getConfiguration($configFiles); 
    3636    if (!$config) 
    3737    { 
     
    7979    return $retval; 
    8080  } 
     81 
     82  /** 
     83   * @see sfConfigHandler 
     84   */ 
     85  static public function getConfiguration(array $configFiles) 
     86  { 
     87    return self::parseYamls($configFiles); 
     88  } 
    8189} 
  • branches/1.1/lib/config/sfRootConfigHandler.class.php

    r7509 r7811  
    3333  { 
    3434    // parse the yaml 
    35     $config = $this->parseYamls($configFiles); 
     35    $config = self::getConfiguration($configFiles); 
    3636 
    3737    // determine if we're loading the system config_handlers.yml or a module config_handlers.yml 
     
    6868      if (isset($keys['file'])) 
    6969      { 
    70         // we have a file to include 
    71         $file = $this->replaceConstants($keys['file']); 
    72         $file = $this->replacePath($file); 
    73  
    74         if (!is_readable($file)) 
     70        if (!is_readable($keys['file'])) 
    7571        { 
    7672          // handler file doesn't exist 
    77           throw new sfParseException(sprintf('Configuration file "%s" specifies class "%s" with nonexistent or unreadable file "%s".', $configFiles[0], $class, $file)); 
     73          throw new sfParseException(sprintf('Configuration file "%s" specifies class "%s" with nonexistent or unreadable file "%s".', $configFiles[0], $class, $keys['file'])); 
    7874        } 
    7975 
    8076        // append our data 
    81         $includes[] = sprintf("require_once('%s');", $file); 
     77        $includes[] = sprintf("require_once('%s');", $keys['file']); 
    8278      } 
    8379 
     
    9793    return $retval; 
    9894  } 
     95 
     96  /** 
     97   * @see sfConfigHandler 
     98   */ 
     99  static public function getConfiguration(array $configFiles) 
     100  { 
     101    $config = self::replaceConstants(self::parseYamls($configFiles)); 
     102 
     103    foreach ($config as $category => $keys) 
     104    { 
     105      if (isset($keys['file'])) 
     106      { 
     107        $config['category']['file'] = $this->replacePath($keys['file']); 
     108      } 
     109    } 
     110 
     111    return $config; 
     112  } 
    99113} 
  • branches/1.1/lib/config/sfRoutingConfigHandler.class.php

    r7616 r7811  
    3030  { 
    3131    // parse the yaml 
    32     $config = $this->parseYamls($configFiles); 
     32    $config = self::getConfiguration($configFiles); 
    3333 
    3434    // connect routes 
     
    4949    ); 
    5050  } 
     51 
     52  /** 
     53   * @see sfConfigHandler 
     54   */ 
     55  static public function getConfiguration(array $configFiles) 
     56  { 
     57    return self::parseYamls($configFiles); 
     58  } 
    5159} 
  • branches/1.1/lib/config/sfSecurityConfigHandler.class.php

    r3625 r7811  
    3333  { 
    3434    // parse the yaml 
    35     $myConfig = $this->parseYamls($configFiles); 
    36  
    37     $myConfig['all'] = sfToolkit::arrayDeepMerge( 
    38       isset($myConfig['default']) && is_array($myConfig['default']) ? $myConfig['default'] : array(), 
    39       isset($myConfig['all']) && is_array($myConfig['all']) ? $myConfig['all'] : array() 
    40     ); 
    41  
    42     unset($myConfig['default']); 
    43  
    44     // change all of the keys to lowercase 
    45     $myConfig = array_change_key_case($myConfig); 
     35    $config = self::getConfiguration($configFiles); 
    4636 
    4737    // compile data 
     
    4939                      "// auto-generated by sfSecurityConfigHandler\n". 
    5040                      "// date: %s\n\$this->security = %s;\n", 
    51                       date('Y/m/d H:i:s'), var_export($myConfig, true)); 
     41                      date('Y/m/d H:i:s'), var_export($config, true)); 
    5242 
    5343    return $retval; 
    5444  } 
     45 
     46  /** 
     47   * @see sfConfigHandler 
     48   */ 
     49  static public function getConfiguration(array $configFiles) 
     50  { 
     51    $config = self::flattenConfiguration(self::parseYamls($configFiles)); 
     52 
     53    // change all of the keys to lowercase 
     54    $config = array_change_key_case($config); 
     55 
     56    return $config; 
     57  } 
    5558} 
  • branches/1.1/lib/config/sfSimpleYamlConfigHandler.class.php

    r3203 r7811  
    2828  public function execute($configFiles) 
    2929  { 
    30     $config = $this->parseYamls($configFiles); 
     30    $config = self::getConfiguration($configFiles); 
    3131 
    3232    // compile data 
     
    3838    return $retval; 
    3939  } 
     40 
     41  /** 
     42   * @see sfConfigHandler 
     43   */ 
     44  static public function getConfiguration(array $configFiles) 
     45  { 
     46    return self::parseYamls($configFiles); 
     47  } 
    4048} 
  • branches/1.1/lib/config/sfViewConfigHandler.class.php

    r5214 r7811  
    3232  public function execute($configFiles) 
    3333  { 
    34     // set our required categories list and initialize our handler 
    35     $categories = array('required_categories' => array()); 
    36     $this->initialize($categories); 
    37  
    3834    // parse the yaml 
    39     $this->mergeConfig($this->parseYamls($configFiles)); 
     35    $this->yamlConfig = self::getConfiguration($configFiles); 
    4036 
    4137    // init our data array 
     
    108104 
    109105    return $retval; 
    110   } 
    111  
    112   /** 
    113    * Merges assets and environement configuration. 
    114    * 
    115    * @param array A configuration array 
    116    */ 
    117   protected function mergeConfig($myConfig) 
    118   { 
    119     // merge javascripts and stylesheets 
    120     $myConfig['all']['stylesheets'] = array_merge(isset($myConfig['default']['stylesheets']) && is_array($myConfig['default']['stylesheets']) ? $myConfig['default']['stylesheets'] : array(), isset($myConfig['all']['stylesheets']) && is_array($myConfig['all']['stylesheets']) ? $myConfig['all']['stylesheets'] : array()); 
    121     unset($myConfig['default']['stylesheets']); 
    122  
    123     $myConfig['all']['javascripts'] = array_merge(isset($myConfig['default']['javascripts']) && is_array($myConfig['default']['javascripts']) ? $myConfig['default']['javascripts'] : array(), isset($myConfig['all']['javascripts']) && is_array($myConfig['all']['javascripts']) ? $myConfig['all']['javascripts'] : array()); 
    124     unset($myConfig['default']['javascripts']); 
    125  
    126     // merge default and all 
    127     $myConfig['all'] = sfToolkit::arrayDeepMerge( 
    128       isset($myConfig['default']) && is_array($myConfig['default']) ? $myConfig['default'] : array(), 
    129       isset($myConfig['all']) && is_array($myConfig['all']) ? $myConfig['all'] : array() 
    130     ); 
    131  
    132     unset($myConfig['default']); 
    133  
    134     $this->yamlConfig = $myConfig; 
    135106  } 
    136107 
     
    268239      } 
    269240 
    270       $key = $this->replaceConstants($key); 
    271  
    272241      if ('-*' == $key) 
    273242      { 
     
    311280      } 
    312281 
    313       $key = $this->replaceConstants($key); 
    314  
    315282      if ('-*' == $key) 
    316283      { 
     
    352319    return implode("\n", $data)."\n"; 
    353320  } 
     321 
     322  /** 
     323   * @see sfConfigHandler 
     324   */ 
     325  static public function getConfiguration(array $configFiles) 
     326  { 
     327    return self::mergeConfig(self::parseYamls($configFiles)); 
     328  } 
     329 
     330  static protected function mergeConfig($config) 
     331  { 
     332    // merge javascripts and stylesheets 
     333    $config['all']['stylesheets'] = array_merge(isset($config['default']['stylesheets']) && is_array($config['default']['stylesheets']) ? $config['default']['stylesheets'] : array(), isset($config['all']['stylesheets']) && is_array($config['all']['stylesheets']) ? $config['all']['stylesheets'] : array()); 
     334    unset($config['default']['stylesheets']); 
     335 
     336    $config['all']['javascripts'] = array_merge(isset($config['default']['javascripts']) && is_array($config['default']['javascripts']) ? $config['default']['javascripts'] : array(), isset($config['all']['javascripts']) && is_array($config['all']['javascripts']) ? $config['all']['javascripts'] : array()); 
     337    unset($config['default']['javascripts']); 
     338 
     339    // merge default and all 
     340    $config['all'] = sfToolkit::arrayDeepMerge( 
     341      isset($config['default']) && is_array($config['default']) ? $config['default'] : array(), 
     342      isset($config['all']) && is_array($config['all']) ? $config['all'] : array() 
     343    ); 
     344 
     345    unset($config['default']); 
     346 
     347    return self::replaceConstants($config); 
     348  } 
    354349} 
  • branches/1.1/lib/config/sfYamlConfigHandler.class.php

    r6456 r7811  
    3030   * @return array A merged configuration array 
    3131   */ 
    32   protected function parseYamls($configFiles) 
     32  static public function parseYamls($configFiles) 
    3333  { 
    3434    $config = array(); 
    3535    foreach ($configFiles as $configFile) 
    3636    { 
    37       $config = sfToolkit::arrayDeepMerge($config, $this->parseYaml($configFile)); 
     37      $config = sfToolkit::arrayDeepMerge($config, self::parseYaml($configFile)); 
    3838    } 
    3939 
     
    5151   * @throws sfParseException If a requested configuration file is improperly formatted 
    5252   */ 
    53   protected function parseYaml($configFile) 
     53  static public function parseYaml($configFile) 
    5454  { 
    5555    if (!is_readable($configFile)) 
     
    118118    return $defaultValue; 
    119119  } 
     120 
     121  static public function flattenConfiguration($config) 
     122  { 
     123    $config['all'] = sfToolkit::arrayDeepMerge( 
     124      isset($config['default']) && is_array($config['default']) ? $config['default'] : array(), 
     125      isset($config['all']) && is_array($config['all']) ? $config['all'] : array() 
     126    ); 
     127 
     128    unset($config['default']); 
     129 
     130    return $config; 
     131  } 
     132 
     133  /** 
     134   * Merges default, all and current environment configurations. 
     135   * 
     136   * @param array The main configuratino array 
     137   * 
     138   * @param array The merged configuration 
     139   */ 
     140  static public function flattenConfigurationWithEnvironment($config) 
     141  { 
     142    return sfToolkit::arrayDeepMerge( 
     143      isset($config['default']) && is_array($config['default']) ? $config['default'] : array(), 
     144      isset($config['all']) && is_array($config['all']) ? $config['all'] : array(), 
     145      isset($config[sfConfig::get('sf_environment')]) && is_array($config[sfConfig::get('sf_environment')]) ? $config[sfConfig::get('sf_environment')] : array() 
     146    ); 
     147  } 
    120148} 

The Sensio Labs Network

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