Source for file jCmdLineRequest.class.php

Documentation is available at jCmdLineRequest.class.php

  1. <?php
  2. /**
  3. * @package     jelix
  4. * @subpackage  core_request
  5. * @author      Laurent Jouanneau
  6. * @contributor Loic Mathaud
  7. * @contributor Thibault Piront (nuKs)
  8. * @contributor Christophe Thiriot
  9. * @copyright   2005-2010 Laurent Jouanneau, 2006-2007 Loic Mathaud
  10. * @copyright   2007 Thibault Piront
  11. * @copyright   2008 Christophe Thiriot
  12. * @link        http://www.jelix.org
  13. * @licence     GNU Lesser General Public Licence see LICENCE file or http://www.gnu.org/licenses/lgpl.html
  14. */
  15.  
  16. /**
  17.  * a request object for scripts used in a command line
  18.  * @package     jelix
  19.  * @subpackage  core_request
  20.  */
  21. class jCmdLineRequest extends jRequest {
  22.  
  23.     public $type = 'cmdline';
  24.  
  25.     public $defaultResponseType = 'cmdline';
  26.  
  27.     protected $onlyDefaultAction = false;
  28.     
  29.     /**
  30.      * If you want to have a CLI script dedicated to the default action,
  31.      * tell it by given true, so you haven't to indicate the action
  32.      * on the command line. It means of course you couldn't execute any other
  33.      * actions with this script.
  34.      * @param boolean $onlyDefaultAction 
  35.      */
  36.     function __construct($onlyDefaultAction = false){
  37.         $this->onlyDefaultAction = $onlyDefaultAction;
  38.     }
  39.  
  40.     public function isAllowedResponse($respclass){
  41.         return ('jResponseCmdline' == $respclass);
  42.     }
  43.  
  44.     protected function _initUrlData(){
  45.         $this->urlScriptPath = '/'; 
  46.         $this->urlScriptName = $this->urlScript = $_SERVER['SCRIPT_NAME']; 
  47.         $this->urlPathInfo = ''; 
  48.     }
  49.  
  50.     protected function _initParams(){
  51.         global $gJConfig;
  52.  
  53.         $argv = $_SERVER['argv'];
  54.         $scriptName = array_shift($argv); // shift the script name
  55.  
  56.         if ($this->onlyDefaultAction) {
  57.             $mod = $gJConfig->startModule;
  58.             $act = $gJConfig->startAction;
  59.             if ($_SERVER['argc'] > 1 && $argv[0] == 'help') {
  60.                 $mod = 'jelix';
  61.                 $act = 'help:index';
  62.                 $argv[0] = $gJConfig->startModule.'~'.$gJConfig->startAction;
  63.             }
  64.         }
  65.         else {
  66.             // note: we cannot use jSelectorAct to parse the action
  67.             // because in the opt edition, jSelectorAct needs an initialized jCoordinator
  68.             // and this is not the case here. see bug #725.
  69.     
  70.             if ($_SERVER['argc'] == 1) {
  71.                 $mod = $gJConfig->startModule;
  72.                 $act = $gJConfig->startAction;
  73.             } else {
  74.                 $argsel = array_shift($argv); // get the module~action selector
  75.                 if ($argsel == 'help') {
  76.                     $mod = 'jelix';
  77.                     $act = 'help:index';
  78.                 }else if (($pos = strpos($argsel,'~')) !== false) {
  79.                     $mod = substr($argsel,0,$pos);
  80.                     $act = substr($argsel,$pos+1);
  81.                 }else {
  82.                     $mod= $gJConfig->startModule;
  83.                     $act= $argsel;
  84.                 }
  85.             }
  86.         }
  87.         $this->params = $argv;
  88.         $this->params['module'] = $mod;
  89.         $this->params['action'] = $act;
  90.     }
  91.  
  92.     /**
  93.      * return the ip address of the user
  94.      * @return string the ip
  95.      */
  96.     function getIP() {
  97.         return '127.0.0.1';
  98.     }
  99. }

Documentation generated on Thu, 19 Sep 2013 00:02:35 +0200 by phpDocumentor 1.4.3