Changeset 2064

Show
Ignore:
Timestamp:
08/23/07 01:13:19 (17 months ago)
Author:
impl
Message:

BREAKING CHANGES: Make Agavi PHP6-compatible, closes #563
- Rename AgaviConfigCache::import() to load()
- Rename AgaviConfig::import() to fromArray()
- Deprecate AgaviConfig::export() in favor of toArray()

Location:
branches/0.11
Files:
11 modified

Legend:

Unmodified
Added
Removed
  • branches/0.11/src/config/AgaviConfig.class.php

    r1991 r2064  
    1515 
    1616/** 
    17  * AgaviConfig acts as global registry of agavi related configuration settings  
     17 * AgaviConfig acts as global registry of agavi related configuration settings 
    1818 * 
    1919 * @package    agavi 
     
    143143   * @since      0.11.0 
    144144   */ 
    145   public static function import($data) 
     145  public static function fromArray($data) 
    146146  { 
    147147    self::$config = array_merge(array_merge(self::$config, $data), self::$readonlies); 
     
    156156   * @since      0.11.0 
    157157   */ 
     158  public static function toArray() 
     159  { 
     160    return self::$config; 
     161  } 
     162 
     163  /** 
     164   * Get all configuration directives and values. 
     165   * 
     166   * @return     array An associative array of configuration values. 
     167   * 
     168   * @deprecated Use toArray() instead. 
     169   * 
     170   * @author     David Zülke <dz@bitxtender.com> 
     171   * @since      0.11.0 
     172   */ 
    158173  public static function export() 
    159174  { 
    160     return self::$config; 
     175    return self::toArray(); 
    161176  } 
    162177 
  • branches/0.11/src/config/AgaviConfigCache.class.php

    r1983 r2064  
    6363      self::loadConfigHandlers(); 
    6464    } 
    65      
     65 
    6666    // grab the base name of the handler 
    6767    $basename = basename($name); 
    68      
     68 
    6969    $handlerInfo = null; 
    70      
     70 
    7171    if(isset(self::$handlers[$name])) { 
    7272      // we have a handler associated with the full configuration path 
     
    8181        // replace wildcard chars in the configuration and create the pattern 
    8282        $pattern = sprintf('#%s#', str_replace('\*', '.*?', preg_quote($key))); 
    83          
     83 
    8484        if(preg_match($pattern, $name)) { 
    8585          $handlerInfo = $value; 
     
    8888      } 
    8989    } 
    90      
     90 
    9191    if($handlerInfo === null) { 
    9292      // we do not have a registered handler for this file 
     
    9595      throw new AgaviConfigurationException($error); 
    9696    } 
    97      
     97 
    9898    // call the handler and retrieve the cache data 
    9999    $handler = new $handlerInfo['class']; 
     
    103103      $parser = new AgaviXmlConfigParser(); 
    104104      $docs = $parser->parseAll($config, $handlerInfo['validation']); 
    105        
     105 
    106106      if($context !== null) { 
    107107        $context = AgaviContext::getInstance($context); 
    108108      } 
    109        
     109 
    110110      $handler->initialize($context, $handlerInfo['parameters']); 
    111        
     111 
    112112      try { 
    113113        $data = $handler->execute($docs); 
     
    123123      $data = $handler->execute($config, $context); 
    124124    } 
    125      
     125 
    126126    self::writeCacheFile($config, $cache, $data, false); 
    127127  } 
     
    141141   *                    associated with this specified configuration file. 
    142142   * 
    143    * @throws     <b>AgaviUnreadableException</b> If a requested configuration  
     143   * @throws     <b>AgaviUnreadableException</b> If a requested configuration 
    144144   *                                             file does not exist. 
    145145   * 
     
    167167    return $cache; 
    168168  } 
    169    
     169 
    170170  /** 
    171171   * Check if the cached version of a file is up to date. 
     
    249249   * @since      0.9.0 
    250250   */ 
    251   public static function import($config, $context = null, $once = true) 
     251  public static function load($config, $context = null, $once = true) 
    252252  { 
    253253    $cache = self::checkConfig($config, $context); 
     
    287287    // manually create our config_handlers.xml handler 
    288288    self::$handlers['config_handlers.xml'] = array( 
    289       'class' => 'AgaviConfigHandlersConfigHandler',  
     289      'class' => 'AgaviConfigHandlersConfigHandler', 
    290290      'parameters' => array( 
    291291      ), 
     
    366366  { 
    367367    $parser = new AgaviConfigParser(); 
    368      
     368 
    369369    return $parser->parse($config, $validationFile); 
    370370  } 
  • branches/0.11/src/config/AgaviModuleConfigHandler.class.php

    r1969 r2064  
    1616 
    1717/** 
    18  * AgaviModuleConfigHandler reads module configuration files to determine the  
     18 * AgaviModuleConfigHandler reads module configuration files to determine the 
    1919 * status of a module. 
    2020 * 
     
    8888    } 
    8989 
    90     $code = 'AgaviConfig::import(' . var_export($data, true) . ');'; 
     90    $code = 'AgaviConfig::fromArray(' . var_export($data, true) . ');'; 
    9191 
    9292    return $this->generate($code); 
  • branches/0.11/src/config/AgaviSettingConfigHandler.class.php

    r1969 r2064  
    7979        } 
    8080      } 
    81        
     81 
    8282      if($cfg->hasChildren('exception_templates')) { 
    8383        foreach($cfg->exception_templates->getChildren() as $exception_template) { 
     
    9797    } 
    9898 
    99     $code = 'AgaviConfig::import(' . var_export($data, true) . ');'; 
     99    $code = 'AgaviConfig::fromArray(' . var_export($data, true) . ');'; 
    100100 
    101101    return $this->generate($code); 
  • branches/0.11/src/controller/AgaviExecutionContainer.class.php

    r2061 r2064  
    1717 * A container used for each action execution that holds neecessary information, 
    1818 * such as the output type, the response etc. 
    19  *  
     19 * 
    2020 * @package    agavi 
    2121 * @subpackage controller 
    22  *  
     22 * 
    2323 * @author     David Zülke <dz@bitxtender.com> 
    2424 * @copyright  Authors 
     
    3535   */ 
    3636  protected $context = null; 
    37    
     37 
    3838  /** 
    3939   * @var        AgaviValidationManager The validation manager instance. 
    4040   */ 
    4141  protected $validationManager = null; 
    42    
     42 
    4343  /** 
    4444   * @var        AgaviRequestDataHolder A request data holder with request info. 
    4545   */ 
    4646  protected $requestData = null; 
    47    
     47 
    4848  /** 
    4949   * @var        AgaviRequestDataHolder A request data holder with arguments. 
    5050   */ 
    5151  protected $arguments = null; 
    52    
     52 
    5353  /** 
    5454   * @var        AgaviResponse A response instance holding the Action's output. 
    5555   */ 
    5656  protected $response = null; 
    57    
     57 
    5858  /** 
    5959   * @var        AgaviOutputType The output type for this container. 
    6060   */ 
    6161  protected $outputType = null; 
    62    
     62 
    6363  /** 
    6464   * @var        float The microtime at which this container was initialized. 
    6565   */ 
    6666  protected $microtime = null; 
    67    
     67 
    6868  /** 
    6969   * @var        AgaviAction The Action instance that belongs to this container. 
     
    8080   */ 
    8181  protected $moduleName = null; 
    82    
     82 
    8383  /** 
    8484   * @var        string The name of the Action. 
    8585   */ 
    8686  protected $actionName = null; 
    87    
     87 
    8888  /** 
    8989   * @var        string Name of the module of the View returned by the Action. 
    9090   */ 
    9191  protected $viewModuleName = null; 
    92    
     92 
    9393  /** 
    9494   * @var        string The name of the View returned by the Action. 
    9595   */ 
    9696  protected $viewName = null; 
    97    
     97 
    9898  /** 
    9999   * @var        AgaviExecutionContainer The next container to execute. 
    100100   */ 
    101101  protected $next = null; 
    102    
     102 
    103103  /** 
    104104   * Pre-serialization callback. 
     
    118118    return array_keys($arr); 
    119119  } 
    120    
     120 
    121121  /** 
    122122   * Post-unserialization callback. 
     
    134134    unset($this->contextName, $this->outputTypeName); 
    135135  } 
    136    
     136 
    137137  /** 
    138138   * Initialize the container. This will create a response instance. 
     
    147147  { 
    148148    $this->microtime = microtime(true); 
    149      
     149 
    150150    $this->context = $context; 
    151      
     151 
    152152    $this->parameters = $parameters; 
    153153  } 
    154    
     154 
    155155  /** 
    156156   * Creates a new container instance with the same output type as this one. 
     
    176176    return $this->context->getController()->createExecutionContainer($moduleName, $actionName, $arguments, $outputType); 
    177177  } 
    178    
     178 
    179179  /** 
    180180   * Start execution. 
     
    196196  { 
    197197    $controller = $this->context->getController(); 
    198      
     198 
    199199    $request = $this->context->getRequest(); 
    200      
     200 
    201201    $controller->countExecution(); 
    202      
     202 
    203203    $moduleName = $this->getModuleName(); 
    204204    $actionName = $this->getActionName(); 
    205      
     205 
    206206    if(!AgaviConfig::get('core.available', false)) { 
    207207      // application is unavailable 
     
    248248      } 
    249249    } 
    250      
     250 
    251251    $this->setModuleName($moduleName); 
    252252    $this->setActionName($actionName); 
    253      
     253 
    254254    // include the module configuration 
    255     // laoded only once due to the way import() works 
     255    // loaded only once due to the way load() (former import()) works 
    256256    if(is_readable(AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/module.xml')) { 
    257       AgaviConfigCache::import(AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/module.xml', $this->context->getName()); 
     257      AgaviConfigCache::load(AgaviConfig::get('core.module_dir') . '/' . $moduleName . '/config/module.xml', $this->context->getName()); 
    258258    } else { 
    259259      AgaviConfig::set('modules.' . strtolower($moduleName) . '.enabled', true); 
     
    262262    // save autoloads so we can restore them later 
    263263    $oldAutoloads = Agavi::$autoloads; 
    264      
     264 
    265265    static $moduleAutoloads = array(); 
    266266    if(!isset($moduleAutoloads[$moduleName])) { 
     
    274274      Agavi::$autoloads = array_merge($moduleAutoloads[$moduleName], Agavi::$autoloads); 
    275275    } 
    276      
     276 
    277277    if(AgaviConfig::get('modules.' . strtolower($moduleName) . '.enabled')) { 
    278278      // check for a module config.php 
     
    281281        require_once($moduleConfig); 
    282282      } 
    283        
     283 
    284284      $this->actionInstance = $controller->createActionInstance($this->moduleName, $this->actionName); 
    285        
     285 
    286286      // initialize the action 
    287287      $this->actionInstance->initialize($this); 
    288        
     288 
    289289      if($this->actionInstance->isSimple()) { 
    290290        if($this->arguments !== null) { 
     
    298298      } else { 
    299299        $this->requestData = clone $request->getRequestData(); 
    300          
     300 
    301301        if($this->arguments !== null) { 
    302302          $this->requestData->merge($this->arguments); 
    303303        } 
    304        
     304 
    305305        // create a new filter chain 
    306306        $fcfi = $this->context->getFactoryInfo('filter_chain'); 
     
    329329        $filterChain->execute($this); 
    330330      } 
    331        
     331 
    332332      // restore autoloads 
    333333      Agavi::$autoloads = $oldAutoloads; 
    334334 
    335335    } else { 
    336        
     336 
    337337      $request->setAttributes(array( 
    338338        'requested_module' => $moduleName, 
     
    350350        throw new AgaviConfigurationException($error); 
    351351      } 
    352        
     352 
    353353      $this->setNext($controller->createExecutionContainer($moduleName, $actionName)); 
    354354    } 
    355      
     355 
    356356    if($this->next !== null) { 
    357357      return $this->next->execute(); 
     
    360360    } 
    361361  } 
    362    
     362 
    363363  /** 
    364364   * Get the Context. 
     
    373373    return $this->context; 
    374374  } 
    375    
     375 
    376376  /** 
    377377   * Retrieve the ValidationManager 
    378378   * 
    379    * @return     AgaviValidationManager The container's ValidationManager  
     379   * @return     AgaviValidationManager The container's ValidationManager 
    380380   *                                    implementation instance. 
    381381   * 
     
    392392    return $this->validationManager; 
    393393  } 
    394    
     394 
    395395  /** 
    396396   * Retrieve this container's request data holder instance. 
     
    405405    return $this->requestData; 
    406406  } 
    407    
     407 
    408408  /** 
    409409   * Get this container's request data holder instance for additional arguments. 
     
    418418    return $this->arguments; 
    419419  } 
    420    
     420 
    421421  /** 
    422422   * Set this container's request data holder instance for additional arguments. 
     
    431431    $this->arguments = $arguments; 
    432432  } 
    433    
     433 
    434434  /** 
    435435   * Retrieve this container's response instance. 
     
    444444    return $this->response; 
    445445  } 
    446    
     446 
    447447  /** 
    448448   * Set a new response. 
     
    457457    $this->response = $response; 
    458458  } 
    459    
     459 
    460460  /** 
    461461   * Retrieve the output type of this container. 
     
    470470    return $this->outputType; 
    471471  } 
    472    
     472 
    473473  /** 
    474474   * Set a different output type for this container. 
     
    483483    $this->outputType = $outputType; 
    484484  } 
    485    
     485 
    486486  /** 
    487487   * Retrieve this container's microtime. 
     
    497497    return $this->microtime; 
    498498  } 
    499    
     499 
    500500  /** 
    501501   * Retrieve this container's action instance. 
     
    510510    return $this->actionInstance; 
    511511  } 
    512    
     512 
    513513  /** 
    514514   * Retrieve this container's view instance. 
     
    523523    return $this->viewInstance; 
    524524  } 
    525    
     525 
    526526  /** 
    527527   * Set this container's view instance. 
     
    536536    return $this->viewInstance = $viewInstance; 
    537537  } 
    538    
     538 
    539539  /** 
    540540   * Retrieve this container's module name. 
     
    549549    return $this->moduleName; 
    550550  } 
    551    
     551 
    552552  /** 
    553553   * Retrieve this container's action name. 
     
    562562    return $this->actionName; 
    563563  } 
    564    
    565   /** 
    566    * Retrieve this container's view module name. This is the name of the module of  
     564 
     565  /** 
     566   * Retrieve this container's view module name. This is the name of the module of 
    567567   * the View returned by the Action. 
    568568   * 
     
    576576    return $this->viewModuleName; 
    577577  } 
    578    
     578 
    579579  /** 
    580580   * Retrieve this container's view name. 
     
    589589    return $this->viewName; 
    590590  } 
    591    
     591 
    592592  /** 
    593593   * Set the module name for this container. 
     
    602602    $this->moduleName = preg_replace('/[^a-z0-9\-_]+/i', '', $moduleName); 
    603603  } 
    604    
     604 
    605605  /** 
    606606   * Set the action name for this container. 
     
    615615    $this->actionName = preg_replace(array('/\./', '/[^a-z0-9\-_\/]+/i'), array('/', ''), $actionName); 
    616616  } 
    617    
     617 
    618618  /** 
    619619   * Set the view module name for this container. 
     
    628628    $this->viewModuleName = $viewModuleName; 
    629629  } 
    630    
     630 
    631631  /** 
    632632   * Set the module name for this container. 
     
    641641    $this->viewName = $viewName; 
    642642  } 
    643    
     643 
    644644   /** 
    645645   * Check if a "next" container has been set. 
     
    654654    return $this->next !== null; 
    655655  } 
    656    
     656 
    657657  /** 
    658658   * Get the "next" container. 
     
    667667    return $this->next; 
    668668  } 
    669    
     669 
    670670  /** 
    671671   * Set the container that should be executed once this one finished running. 
     
    680680    $this->next = $container; 
    681681  } 
    682    
     682