Changeset 480


Ignore:
Timestamp:
May 4, 2014 12:29:05 AM (10 years ago)
Author:
anonymous
Message:

Removed some legacy files. Improved use of array_key_exists.

Location:
trunk
Files:
3 deleted
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/docs/examples/_config.inc.php

    r468 r480  
    123123// Load preferences for the user.
    124124require_once 'codebase/lib/Prefs.inc.php';
    125 $prefs = new Prefs('permanent');
    126 $prefs->setParam(array(
    127     'persistent' => $auth->isLoggedIn(),
     125$prefs = new Prefs('permanent', array(
     126    'storagetype' => ($auth->isLoggedIn() ? 'database' : 'session'),
    128127    'user_id' => $auth->get('user_id'),
    129128));
    130129$prefs->setDefaults(array(
     130    // ...
    131131));
    132132$prefs->load();
     133// Load preferences for temporary usage.
     134require_once 'codebase/lib/Prefs.inc.php';
     135$c_prefs = new Prefs('config');
     136$c_prefs->setParam(array(
     137    'storagetype' => 'cookie',
     138));
    133139// Temporary prefs.
    134 $tmp_prefs = new Prefs('temporary');
    135 $tmp_prefs->setDefaults(array(
     140$c_prefs = new Prefs('settings');
     141$c_prefs->setDefaults(array(
    136142));
    137143
  • trunk/lib/App.inc.php

    r479 r480  
    807807                unset($this->_carry_queries[$k]);
    808808            }
    809             if ($unset && array_key_exists($k, $_REQUEST)) {
     809            if ($unset && (isset($_REQUEST) && array_key_exists($k, $_REQUEST))) {
    810810                unset($_REQUEST[$k], $_GET[$k], $_POST[$k], $_COOKIE[$k]);
    811811            }
  • trunk/lib/Cache.inc.php

    r479 r480  
    211211        }
    212212
    213         if (array_key_exists($key, $_SESSION['_cache'][$this->_ns])) {
     213        if (isset($_SESSION['_cache'][$this->_ns]) && array_key_exists($key, $_SESSION['_cache'][$this->_ns])) {
    214214            $app->logMsg(sprintf('Retreiving %s from cache.', $key), LOG_DEBUG, __FILE__, __LINE__);
    215215            // Move the accessed cached datum to the top of the stack. Maybe somebody knows a better way to do this?
     
    240240        }
    241241
    242         return array_key_exists($key, $_SESSION['_cache'][$this->_ns]);
     242        return (isset($_SESSION['_cache'][$this->_ns]) && array_key_exists($key, $_SESSION['_cache'][$this->_ns]));
    243243    }
    244244
     
    251251    public function delete($key)
    252252    {
    253         if (array_key_exists($key, $_SESSION['_cache'][$this->_ns])) {
     253        if (isset($_SESSION['_cache'][$this->_ns]) && array_key_exists($key, $_SESSION['_cache'][$this->_ns])) {
    254254            unset($_SESSION['_cache'][$this->_ns][$key]);
    255255            return true;
  • trunk/lib/Prefs.inc.php

    r479 r480  
    275275            // - or the new value is different than the default
    276276            // - or there is a previously existing saved key.
    277             if (!array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults'])
     277            if (!(isset($_SESSION['_prefs'][$this->_ns]['defaults']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults']))
    278278            || $_SESSION['_prefs'][$this->_ns]['defaults'][$key] != $val
    279             || array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved'])) {
     279            || (isset($_SESSION['_prefs'][$this->_ns]['saved']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']))) {
    280280                $_SESSION['_prefs'][$this->_ns]['saved'][$key] = $val;
    281281                $app->logMsg(sprintf('Setting session preference %s => %s', $key, getDump($val, true)), LOG_DEBUG, __FILE__, __LINE__);
     
    348348        case 'session':
    349349        case 'database':
    350             return array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']);
     350            return (isset($_SESSION['_prefs'][$this->_ns]['saved']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']));
    351351
    352352        case 'cookie':
    353353            $name = $this->_getCookieName($key);
    354             return array_key_exists($name, $_COOKIE);
     354            return (isset($_COOKIE) && array_key_exists($name, $_COOKIE));
    355355        }
    356356
  • trunk/tests/PrefsTest.php

    r468 r480  
    77 * For details visit the project site: <http://trac.strangecode.com/codebase/>
    88 * Copyright 2001-2012 Strangecode, LLC
    9  * 
     9 *
    1010 * This file is part of The Strangecode Codebase.
    1111 *
     
    1414 * Free Software Foundation, either version 3 of the License, or (at your option)
    1515 * any later version.
    16  * 
     16 *
    1717 * The Strangecode Codebase is distributed in the hope that it will be useful, but
    1818 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1919 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
    2020 * details.
    21  * 
     21 *
    2222 * You should have received a copy of the GNU General Public License along with
    2323 * The Strangecode Codebase. If not, see <http://www.gnu.org/licenses/>.
     
    4747        require dirname(__FILE__) . '/_config.inc.php';
    4848        require_once '../lib/Prefs.inc.php';
    49         $this->Prefs =& new Prefs(PARAM);
     49        $prefs = new Prefs('test', array(
     50            'storagetype' => 'session',
     51        ));
    5052    }
    5153
Note: See TracChangeset for help on using the changeset viewer.