From 27e9859b8a23c23ea9c5a6c2e06f1818fed9488c Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Fri, 26 Jun 2009 01:34:21 -0600 Subject: [PATCH] Added Horde_SessionObjects::prune() --- .../SessionObjects/lib/Horde/SessionObjects.php | 41 ++++++++++++++++++---- framework/SessionObjects/package.xml | 3 +- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/framework/SessionObjects/lib/Horde/SessionObjects.php b/framework/SessionObjects/lib/Horde/SessionObjects.php index 1213e7d94..e9c693909 100644 --- a/framework/SessionObjects/lib/Horde/SessionObjects.php +++ b/framework/SessionObjects/lib/Horde/SessionObjects.php @@ -101,17 +101,18 @@ class Horde_SessionObjects if (isset($_SESSION[$this->_name]['__prune']) && ($_SESSION[$this->_name]['__prune'] > $this->_size)) { $pruneList = array(); + $prune_count = $_SESSION[$this->_name]['__prune'] - $this->_size; + foreach ($_SESSION[$this->_name] as $key => $val) { if ($val['prune']) { $pruneList[] = $key; + if (!--$prune_count) { + break; + } } } - $pruneOids = array_slice($pruneList, 0, $_SESSION[$this->_name]['__prune'] - $this->_size); - foreach ($pruneOids as $val) { - unset($_SESSION[$this->_name][$val]); - } - $_SESSION[$this->_name]['__prune'] -= count($pruneOids); + $this->prune($pruneList); } } @@ -223,7 +224,8 @@ class Horde_SessionObjects } /** - * Sets the prune flag on a store object. + * Sets the prune flag on a store object. The object will be pruned + * when the maximum storage size is reached. * * @param string $oid The object ID. * @param boolean $prune True to allow pruning, false for no pruning. @@ -242,6 +244,33 @@ class Horde_SessionObjects } /** + * Immediately prune an object. + * + * @param mixed $oid The object ID or an array of object IDs. + */ + public function prune($oid) + { + if (!isset($_SESSION[$this->_name])) { + return; + } + + if (!is_array($oid)) { + $oid = array($oid); + } + + $prune_count = 0; + + foreach ($oid as $val) { + if (isset($_SESSION[$this->_name][$val])) { + ++$prune_count; + unset($_SESSION[$this->_name][$val]); + } + } + + $_SESSION[$this->_name]['__prune'] -= $prune_count; + } + + /** * Generates an OID for an object. * * @param mixed $data The data to store in the store. diff --git a/framework/SessionObjects/package.xml b/framework/SessionObjects/package.xml index 48ca22cb1..008a4ecaf 100644 --- a/framework/SessionObjects/package.xml +++ b/framework/SessionObjects/package.xml @@ -26,7 +26,8 @@ http://pear.php.net/dtd/package-2.0.xsd"> beta LGPL - * Initial Horde 4 package + * Added prune() function. + * Initial Horde 4 package -- 2.11.0