Development

Changeset 10232

You must first sign up to be able to contribute.

Changeset 10232

Show
Ignore:
Timestamp:
07/11/08 22:12:28 (4 months ago)
Author:
Kris.Wallsmith
Message:

sfGenerateControllerTaskPlugin:

  • Added option to check server for configuration values
  • Added exception if file already exists and force option to overwrite
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/sfGenerateControllerTaskPlugin/trunk/README

    r10195 r10232  
    3535}}} 
    3636 
     37The controller can be configured to listen to the server for configuration variables using the `check-server` option: 
     38 
     39{{{ 
     40$ ./symfony generate:controller frontend prod --check-server 
     41}}} 
     42 
     43This option will add logic to your controller to first look for `SF_APPLICATION`, `SF_ENVIRONMENT` and `SF_DEBUG` keys in the `$_SERVER` array. If these keys are not found, the command arguments are used as fallback values. 
     44 
     45Using the `check-server` option you can create an `index.php` controller that can dispatch any application, depending on what `SetEnv` directives exist in the requested `VirtualHost` configuration. This feature is Apache-specific. 
     46 
     47{{{ 
     48$ ./symfony generate:controller frontend prod --filename="index" --check-server --force 
     49}}} 
     50 
    3751== Changelog == 
     52 
     53=== 1.1.0-DEV === 
     54 
     55 * Added option to check server for configuration values 
     56 * Added exception if file already exists and `force` option to overwrite 
    3857 
    3958=== 1.0.0 === 
  • plugins/sfGenerateControllerTaskPlugin/trunk/lib/task/sfGenerateControllerTask.class.php

    r10193 r10232  
    2525      new sfCommandOption('debug', null, sfCommandOption::PARAMETER_NONE, 'Controller debug mode'), 
    2626      new sfCommandOption('allowed-ip', null, sfCommandOption::PARAMETER_REQUIRED | sfCommandOption::IS_ARRAY, 'Restrict traffic by IP address'), 
     27      new sfCommandOption('check-server', null, sfCommandOption::PARAMETER_NONE, 'Check for configuration variables in the $_SERVER array'), 
     28      new sfCommandOption('force', null, sfCommandOption::PARAMETER_NONE, 'Overwrite any existing file of the same name'), 
    2729    )); 
    2830 
     
    3739directory: 
    3840 
    39   [./symfony generate:controller frontend dev|INFO] 
     41  [./symfony generate:controller frontend dev --debug|INFO] 
    4042 
    4143Traffic to this controller can be restricted by IP address by using the  
    4244[allowed-ip|COMMENT] option: 
    4345 
    44   [./symfony generate:controller frontend dev --allowed-ip="127.0.0.1"|INFO] 
     46  [./symfony generate:controller frontend dev --allowed-ip="127.0.0.1" --debug|INFO] 
    4547 
    4648This common use case can also be accomplished using the [localhost|COMMENT] shortcut: 
    4749 
    48   [./symfony generate:controller frontend dev --allowed-ip="localhost"|INFO] 
     50  [./symfony generate:controller frontend dev --allowed-ip="localhost" --debug|INFO] 
    4951 
    5052If you want to use a filename other than the symfony default filename, use  
    5153the [filename|COMMENT] option: 
    5254 
    53   [./symfony generate:controller frontend dev --filename="index"|INFO] 
     55  [./symfony generate:controller frontend prod --filename="index"|INFO] 
     56 
     57The controller can be configured to listen to the server for configuration 
     58variables using the [check-server|COMMENT] option: 
     59 
     60  [./symfony generate:controller frontend prod --check-server|INFO] 
     61 
     62This option will add logic to your controller to first look for  
     63[SF_APPLICATION|COMMENT], [SF_ENVIRONMENT|COMMENT] and [SF_DEBUG|COMMENT] keys in the [\$ SERVER|COMMENT] array. If 
     64these keys are not found, the command arguments are used as fallback values. 
     65 
     66Using the [check-server|COMMENT] option you can create an [index.php|COMMENT] controller that can 
     67dispatch any application, depending on what [SetEnv|COMMENT] directives exist in the  
     68requested [VirtualHost|COMMENT] configuration. This feature is Apache-specific. 
     69 
     70  [./symfony generate:controller frontend prod --filename="index" --check-server --force|INFO] 
    5471 
    5572EOF; 
     
    106123    } 
    107124 
     125    if (file_exists(sfConfig::get('sf_web_dir').'/'.$filename)) 
     126    { 
     127      if (isset($options['force']) && $options['force']) 
     128      { 
     129        $this->getFilesystem()->remove(sfConfig::get('sf_web_dir').'/'.$filename); 
     130      } 
     131      else 
     132      { 
     133        throw new InvalidArgumentException(sprintf('A "%s" controller already exists. Use the --force option to overwrite.', $filename)); 
     134      } 
     135    } 
     136 
    108137    $this->getFilesystem()->copy(dirname(__FILE__).'/skeleton/index.php', sfConfig::get('sf_web_dir').'/'.$filename); 
    109     $this->getFilesystem()->replaceTokens(sfConfig::get('sf_web_dir').'/'.$filename, '##', '##', array( 
    110       'APP_NAME'    => $app, 
    111       'ENVIRONMENT' => $env, 
    112       'IS_DEBUG'    => isset($options['debug']) && $options['debug'] ? 'true' : 'false', 
    113       'IP_CHECK'    => $ipCheck, 
    114     )); 
     138    if (isset($options['check-server']) && $options['check-server']) 
     139    { 
     140      $this->getFilesystem()->replaceTokens(sfConfig::get('sf_web_dir').'/'.$filename, '##', '##', array( 
     141        'APP_NAME'    => "\n  ".'isset($_SERVER[\'SF_APPLICATION\']) ? $_SERVER[\'SF_APPLICATION\'] : '.var_export($app, true), 
     142        'ENVIRONMENT' => "\n  ".'isset($_SERVER[\'SF_ENVIRONMENT\']) ? $_SERVER[\'SF_ENVIRONMENT\'] : '.var_export($env, true), 
     143        'IS_DEBUG'    => "\n  ".'isset($_SERVER[\'SF_DEBUG\']) ? (boolean) $_SERVER[\'SF_DEBUG\'] : '.(isset($options['debug']) && $options['debug'] ? 'true' : 'false'), 
     144        'IP_CHECK'    => $ipCheck, 
     145      )); 
     146    } 
     147    else 
     148    { 
     149      $this->getFilesystem()->replaceTokens(sfConfig::get('sf_web_dir').'/'.$filename, '##', '##', array( 
     150        'APP_NAME'    => var_export($app, true), 
     151        'ENVIRONMENT' => var_export($env, true), 
     152        'IS_DEBUG'    => isset($options['debug']) && $options['debug'] ? 'true' : 'false', 
     153        'IP_CHECK'    => $ipCheck, 
     154      )); 
     155    } 
    115156  } 
    116157 
  • plugins/sfGenerateControllerTaskPlugin/trunk/lib/task/skeleton/index.php

    r10194 r10232  
    33require_once(dirname(__FILE__).'/../config/ProjectConfiguration.class.php'); 
    44 
    5 $configuration = ProjectConfiguration::getApplicationConfiguration('##APP_NAME##', '##ENVIRONMENT##', ##IS_DEBUG##); 
     5$configuration = ProjectConfiguration::getApplicationConfiguration(##APP_NAME##, ##ENVIRONMENT##, ##IS_DEBUG##); 
    66sfContext::createInstance($configuration)->dispatch();