Development

Changeset 7341

You must first sign up to be able to contribute.

Changeset 7341

Show
Ignore:
Timestamp:
02/04/08 18:07:31 (7 months ago)
Author:
fabien
Message:

made a small refactoring to sfConfigCache

Files:

Legend:

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

    r5902 r7341  
    6868    } 
    6969 
    70     // handler to call for this configuration file 
    71     $handlerToCall = null; 
     70    // handler key to call for this configuration file 
     71    $handlerKey = null; 
    7272 
    7373    $handler = str_replace(DIRECTORY_SEPARATOR, '/', $handler); 
     
    7878    { 
    7979      // we have a handler associated with the full configuration path 
    80       $handlerToCall = $this->handlers[$handler]
     80      $handlerKey = $handler
    8181    } 
    8282    else if (isset($this->handlers[$basename])) 
    8383    { 
    8484      // we have a handler associated with the configuration base name 
    85       $handlerToCall = $this->handlers[$basename]
     85      $handlerKey = $basename
    8686    } 
    8787    else 
    8888    { 
    89       // let's see if we have any wildcard handlers registered that match 
    90       // this basename 
    91       foreach ($this->handlers as $key => $handlerInstance) 
     89      // let's see if we have any wildcard handlers registered that match this basename 
     90      foreach (array_keys($this->handlers) as $key) 
    9291      { 
    9392        // replace wildcard chars in the configuration 
     
    9594 
    9695        // create pattern from config 
    97         if (preg_match('#'.$pattern.'#', $handler)) 
     96        if (preg_match('#'.$pattern.'$#', $handler)) 
    9897        { 
    99           // we found a match! 
    100           $handlerToCall = $this->handlers[$key]; 
     98          $handlerKey = $key; 
    10199 
    102100          break; 
     
    105103    } 
    106104 
    107     if ($handlerToCall) 
    108     { 
    109       // call the handler and retrieve the cache data 
    110       $data = $handlerToCall->execute($configs); 
    111  
    112       $this->writeCacheFile($handler, $cache, $data); 
    113     } 
    114     else 
     105    if (!$handlerKey) 
    115106    { 
    116107      // we do not have a registered handler for this file 
    117108      throw new sfConfigurationException(sprintf('Configuration file "%s" does not have a registered handler.', implode(', ', $configs))); 
    118109    } 
     110 
     111    // call the handler and retrieve the cache data 
     112    $data = $this->getHandler($handlerKey)->execute($configs); 
     113 
     114    $this->writeCacheFile($handler, $cache, $data); 
     115  } 
     116 
     117  /** 
     118   * Returns the config handler configured for the given name 
     119   * 
     120   * @param  string The config handler name 
     121   * 
     122   * @return sfConfigHandler A sfConfigHandler instance 
     123   */ 
     124  protected function getHandler($name) 
     125  { 
     126    if (is_array($this->handlers[$name])) 
     127    { 
     128      $class = $this->handlers[$name][0]; 
     129      $this->handlers[$name] = new $class($this->handlers[$name][1]); 
     130    } 
     131 
     132    return $this->handlers[$name]; 
    119133  } 
    120134