Changeset 547 for trunk/lib


Ignore:
Timestamp:
Aug 27, 2015 3:22:39 AM (9 years ago)
Author:
anonymous
Message:

Moved CLI flag to ->cli which can be forced off for tests

Location:
trunk/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/App.inc.php

    r546 r547  
    6464    protected $_raised_msg_counter = array(MSG_NOTICE => 0, MSG_SUCCESS => 0, MSG_WARNING => 0, MSG_ERR => 0);
    6565
     66    // We're running as CLI. Public becuase we must force this as false when testing sessions via CLI.
     67    public $cli = false;
     68
    6669    // Dictionary of global application parameters.
    6770    protected $_params = array();
     
    206209        $this->timer = new ScriptTimer();
    207210        $this->timer->start('_app');
     211
     212        // Are we running as a CLI?
     213        $this->cli = ('cli' === php_sapi_name() || defined('_CLI'));
    208214    }
    209215
     
    351357            // DB credentials for CLI scripts stored in a JSON file with read rights given only to the user who will be executing the scripts: -r--------
    352358            // But not if all DB credentials have been defined already by other means.
    353             if (('cli' === php_sapi_name() || defined('_CLI')) && (!$this->getParam('db_server') || !$this->getParam('db_name') || !$this->getParam('db_user') || !$this->getParam('db_pass'))) {
     359            if ($this->cli && (!$this->getParam('db_server') || !$this->getParam('db_name') || !$this->getParam('db_user') || !$this->getParam('db_pass'))) {
    354360                if (false !== $db_auth_file = stream_resolve_include_path($this->getParam('db_auth_file'))) {
    355361                    if (is_readable($db_auth_file)) {
     
    385391         */
    386392
    387         // Skip sessions if disabled or automatically skip if run in a CLI script.
    388         if (true === $this->getParam('enable_session') && !defined('_CLI') && 'cli' !== php_sapi_name()) {
     393        // Use sessions if enabled and not a CLI script.
     394        if (true === $this->getParam('enable_session') && !$this->cli) {
    389395
    390396            // Session parameters.
     
    450456
    451457        // Character set. This should also be printed in the html header template.
    452         if (!defined('_CLI') && 'cli' !== php_sapi_name()) {
     458        if (!$this->cli) {
    453459            if (!headers_sent($h_file, $h_line)) {
    454460                header('Content-type: text/html; charset=' . $this->getParam('character_set'));
     
    464470            $codebase_version = trim(file_get_contents($codebase_version_file));
    465471            $this->setParam(array('codebase_version' => $codebase_version));
    466             if (!defined('_CLI') && 'cli' !== php_sapi_name()) {
     472            if (!$this->cli) {
    467473                if (!headers_sent($h_file, $h_line)) {
    468474                    header('X-Codebase-Version: ' . $codebase_version);
     
    487493            $this->setParam(array('site_version' => $site_version));
    488494        }
    489         if (!defined('_CLI') && 'cli' !== php_sapi_name() && $this->getParam('site_version')) {
     495        if (!$this->cli && $this->getParam('site_version')) {
    490496            if (!headers_sent($h_file, $h_line)) {
    491497                header('X-Site-Version: ' . $site_version);
  • trunk/lib/DB.inc.php

    r546 r547  
    226226    protected function _fail()
    227227    {
     228        $app =& App::getInstance();
     229
    228230        if ($this->getParam('db_die_on_failure')) {
    229             if (!defined('_CLI') && 'cli' !== php_sapi_name()) {
     231            if (!$app->cli) {
    230232                // For http requests, send a Service Unavailable header.
    231233                header(' ', true, 503);
     
    323325            $app->logMsg(sprintf('MySQL error %s: %s in query: %s', mysql_errno($this->dbh), mysql_error($this->dbh), $debugqry), LOG_EMERG, __FILE__, __LINE__);
    324326            if ($this->getParam('db_debug')) {
    325                 if (!defined('_CLI') && 'cli' !== php_sapi_name()) {
     327                if (!$app->cli) {
    326328                    echo '<pre style="padding:2em; background:#ddd; font:9px monaco;">' . wordwrap(mysql_error($this->dbh)) . '<hr>' . htmlspecialchars($debugqry) . '</pre>';
    327329                }
  • trunk/lib/Prefs.inc.php

    r546 r547  
    175175    {
    176176        // CLI scripts can't use prefs stored in HTTP-based protocols.
    177         if ((defined('_CLI') || 'cli' === php_sapi_name())
     177        if ($app->cli
    178178        && isset($params['storagetype'])
    179179        && in_array($params['storagetype'], array('cookie', 'session'))) {
  • trunk/lib/Utilities.inc.php

    r546 r547  
    3737function dump($var, $display=false, $var_dump=false, $file='', $line='')
    3838{
    39     if (defined('_CLI') || 'cli' === php_sapi_name()) {
     39    if ($app->cli) {
    4040        echo "DUMP FROM: $file $line\n";
    4141    } else {
     
    6060        }
    6161    }
    62     if (defined('_CLI') || 'cli' === php_sapi_name()) {
     62    if ($app->cli) {
    6363        echo "\n";
    6464    } else {
Note: See TracChangeset for help on using the changeset viewer.