Changeset 547 for trunk/lib/App.inc.php


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

File:
1 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);
Note: See TracChangeset for help on using the changeset viewer.