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-2012 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.     public $authorizedResponseClass = 'jResponseCmdline';
  28.  
  29.     protected $onlyDefaultAction = false;
  30.     
  31.     /**
  32.      * If you want to have a CLI script dedicated to the default action,
  33.      * tell it by given true, so you haven't to indicate the action
  34.      * on the command line. It means of course you couldn't execute any other
  35.      * actions with this script.
  36.      * @param boolean $onlyDefaultAction 
  37.      */
  38.     function __construct($onlyDefaultAction = false){
  39.         $this->onlyDefaultAction = $onlyDefaultAction;
  40.     }
  41.  
  42.     protected function _initUrlData(){
  43.         $this->urlScriptPath = '/'; 
  44.         $this->urlScriptName = $this->urlScript = $_SERVER['SCRIPT_NAME']; 
  45.         $this->urlPathInfo = ''; 
  46.     }
  47.  
  48.     protected function _initParams(){
  49.         $argv = $_SERVER['argv'];
  50.         $scriptName = array_shift($argv); // shift the script name
  51.  
  52.         $mod = jApp::config()->startModule;
  53.         $act = jApp::config()->startAction;
  54.  
  55.         if ($this->onlyDefaultAction) {
  56.             if ($_SERVER['argc'] > 1 && $argv[0] == 'help') {
  57.                 $argv[0] = $mod.'~'.$act;
  58.                 $mod = 'jelix';
  59.                 $act = 'help:index';
  60.             }
  61.         }
  62.         else {
  63.             // note: we cannot use jSelectorAct to parse the action
  64.             // because in the opt edition, jSelectorAct needs an initialized jCoordinator
  65.             // and this is not the case here. see bug #725.
  66.     
  67.             if ($_SERVER['argc'] != 1) {
  68.                 $argsel = array_shift($argv); // get the module~action selector
  69.                 if ($argsel == 'help') {
  70.                     $mod = 'jelix';
  71.                     $act = 'help:index';
  72.                 }else if (($pos = strpos($argsel,'~')) !== false) {
  73.                     $mod = substr($argsel,0,$pos);
  74.                     $act = substr($argsel,$pos+1);
  75.                 }else {
  76.                     $act= $argsel;
  77.                 }
  78.             }
  79.         }
  80.         $this->params = $argv;
  81.         $this->params['module'] = $mod;
  82.         $this->params['action'] = $act;
  83.     }
  84.  
  85.     /**
  86.      * return the ip address of the user
  87.      * @return string the ip
  88.      */
  89.     function getIP() {
  90.         return '127.0.0.1';
  91.     }
  92.  
  93.     public function isAllowedResponse($response){
  94.         return ($response instanceof $this->authorizedResponseClass);
  95.     }
  96. }

Documentation generated on Wed, 04 Jan 2017 22:52:29 +0100 by phpDocumentor 1.4.3