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


Ignore:
Timestamp:
Mar 4, 2024 12:30:57 AM (2 months ago)
Author:
anonymous
Message:

Enable setting db_timezone during runtime. Refactor setParam() in App, DB, and PDO.

File:
1 edited

Legend:

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

    r805 r810  
    288288     *
    289289     * @access public
    290      * @param  array    $param     Array of parameters (key => val pairs).
    291      */
    292     public function setParam($param=null)
    293     {
    294         if (isset($param) && is_array($param)) {
    295             // Merge new parameters with old overriding old ones that are passed.
    296             $this->_params = array_merge($this->_params, $param);
    297 
    298             if ($this->running) {
    299                 // Params that require additional processing if set during runtime.
    300                 foreach ($param as $key => $val) {
    301                     switch ($key) {
    302                     case 'namespace':
    303                         $this->logMsg(sprintf('Setting namespace not allowed', null), LOG_WARNING, __FILE__, __LINE__);
    304                         return false;
    305 
    306                     case 'session_name':
    307                         session_name($val);
    308                         return true;
    309 
    310                     case 'session_use_cookies':
    311                         if (session_status() !== PHP_SESSION_ACTIVE) {
    312                             ini_set('session.use_cookies', $val);
    313                         } else {
    314                             $this->logMsg('Unable to set session_use_cookies; session is already active', LOG_NOTICE, __FILE__, __LINE__);
    315                         }
    316                         return true;
    317 
    318                     case 'error_reporting':
    319                         ini_set('error_reporting', $val);
    320                         return true;
    321 
    322                     case 'display_errors':
    323                         ini_set('display_errors', $val);
    324                         return true;
    325 
    326                     case 'log_errors':
    327                         ini_set('log_errors', true);
    328                         return true;
    329 
    330                     case 'log_directory':
    331                         if (is_dir($val) && is_writable($val)) {
    332                             ini_set('error_log', $val . '/' . $this->getParam('php_error_log'));
    333                         }
    334                         return true;
     290     * @param  array    $params     Array of parameters (key => val pairs).
     291     */
     292    public function setParam(Array $params)
     293    {
     294        if (!isset($params) || !is_array($params)) {
     295            trigger_error(sprintf('%s failed; not an array: %s', __METHOD__, getDump($params, false, SC_DUMP_PRINT_R)), E_USER_ERROR);
     296        }
     297
     298        // Merge new parameters with old overriding old ones that are passed.
     299        $this->_params = array_merge($this->_params, $params);
     300
     301        if ($this->running) {
     302            // Params that require additional processing if set during runtime.
     303            foreach ($params as $key => $val) {
     304                switch ($key) {
     305                case 'namespace':
     306                    $this->logMsg(sprintf('Setting namespace not allowed', null), LOG_WARNING, __FILE__, __LINE__);
     307                    break;
     308
     309                case 'session_name':
     310                    session_name($val);
     311                    break;
     312
     313                case 'session_use_cookies':
     314                    if (session_status() !== PHP_SESSION_ACTIVE) {
     315                        ini_set('session.use_cookies', $val);
     316                    } else {
     317                        $this->logMsg('Unable to set session_use_cookies; session is already active', LOG_NOTICE, __FILE__, __LINE__);
    335318                    }
     319                    break;
     320
     321                case 'error_reporting':
     322                    ini_set('error_reporting', $val);
     323                    break;
     324
     325                case 'php_timezone':
     326                    // Set timezone used by PHP.
     327                    $this->setTimezone($val);
     328                    break;
     329
     330                case 'db_timezone':
     331                    // Set timezone used by MySQL.
     332                    if (true === $this->getParam('enable_db_pdo')) {
     333                        $this->pdo->setParam(['timezone' => $val]);
     334                    }
     335                    if (true === $this->getParam('enable_db')) {
     336                        $this->db->setParam(['timezone' => $val]);
     337                    }
     338                    break;
     339
     340                case 'display_errors':
     341                    ini_set('display_errors', $val);
     342                    break;
     343
     344                case 'log_errors':
     345                    ini_set('log_errors', true);
     346                    break;
     347
     348                case 'log_directory':
     349                    if (is_dir($val) && is_writable($val)) {
     350                        ini_set('error_log', $val . '/' . $this->getParam('php_error_log'));
     351                    }
     352                    break;
    336353                }
    337354            }
Note: See TracChangeset for help on using the changeset viewer.