cvs: pear /Cache Application.php Cache.php Container.php Error.php Function.php Graphics.php HTTP_Request.php Output.php OutputCompression.php
/Cache/Container db.php dbx.php file.php mdb.php msession.php phplib.php shm.php trifile.php
| From: | Helgi �ormar �orbj�rnsson | Date: | Wed, 15 Dec 2004 09:09:34 +0000 |
| Subject: | cvs: pear /Cache Application.php Cache.php Container.php Error.php Function.php Graphics.php HTTP_Request.php Output.php OutputCompression.php /Cache/Container db.php dbx.php file.php mdb.php msession.php phplib.php shm.php trifile.php |
||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-27423@lists.php.net to get a copy of this message | ||
dufuz Wed Dec 15 04:09:34 2004 EDT
Modified files:
/pear/Cache/Container db.php dbx.php file.php mdb.php msession.php
phplib.php shm.php trifile.php
/pear/Cache Application.php Cache.php Container.php Error.php
Function.php Graphics.php HTTP_Request.php
OutputCompression.php Output.php
Log:
Added a little better error handling in trifile container, and bunch of CS fixes all around.
http://cvs.php.net/diff.php/pear/Cache/Container/db.php?r1=1.6&r2=1.7&ty=u Index: pear/Cache/Container/db.php diff -u pear/Cache/Container/db.php:1.6 pear/Cache/Container/db.php:1.7 --- pear/Cache/Container/db.php:1.6 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container/db.php Wed Dec 15 04:09:29 2004 @@ -17,7 +17,7 @@ // | Chuck Hagenbuch <chuck@horde.org> | // +----------------------------------------------------------------------+ // -// $Id: db.php,v 1.6 2004/12/14 04:48:27 dufuz Exp $ +// $Id: db.php,v 1.7 2004/12/15 09:09:29 dufuz Exp $ require_once 'DB.php'; require_once 'Cache/Container.php'; @@ -52,10 +52,11 @@ * ) * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> -* @version $Id: db.php,v 1.6 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: db.php,v 1.7 2004/12/15 09:09:29 dufuz Exp $ * @package Cache */ -class Cache_Container_db extends Cache_Container { +class Cache_Container_db extends Cache_Container +{ /** * Name of the DB table to store caching data @@ -86,15 +87,14 @@ $this->setOptions($options, array_merge($this->allowed_options, array('dsn', 'cache_table'))); - if (!$this->dsn) + if (!$this->dsn) { return new Cache_Error('No dsn specified!', __FILE__, __LINE__); - + } $this->db = DB::connect($this->dsn, true); - if (DB::isError($this->db)) { + if (PEAR::isError($this->db)) { return new Cache_Error('DB::connect failed: ' . DB::errorMessage($this->db), __FILE__, __LINE__); - } else { - $this->db->setFetchMode(DB_FETCHMODE_ASSOC); } + $this->db->setFetchMode(DB_FETCHMODE_ASSOC); } function fetch($id, $group) @@ -107,15 +107,15 @@ $res = $this->db->query($query); - if (DB::isError($res)) + if (PEAR::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); - + } $row = $res->fetchRow(); - if (is_array($row)) + if (is_array($row)) { $data = array($row['expires'], $this->decode($row['cachedata']), $row['userdata']); - else + } else { $data = array(null, null, null); - + } // last used required by the garbage collection // WARNING: might be MySQL specific $query = sprintf("UPDATE %s SET changed = (NOW() + 0) WHERE id = '%s' AND cachegroup = '%s'", @@ -126,9 +126,9 @@ $res = $this->db->query($query); - if (DB::isError($res)) + if (PEAR::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); - + } return $data; } @@ -154,7 +154,7 @@ $res = $this->db->query($query); - if (DB::isError($res)) { + if (PEAR::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res) , __FILE__, __LINE__); } } @@ -171,8 +171,9 @@ $res = $this->db->query($query); - if (DB::isError($res)) + if (PEAR::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); + } } function flush($group = '') @@ -187,7 +188,7 @@ $res = $this->db->query($query); - if (DB::isError($res)) + if (PEAR::isError($res)) return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); } @@ -201,16 +202,15 @@ $res = $this->db->query($query); - if (DB::isError($res)) + if (PEAR::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); - + } $row = $res->fetchRow(); if (is_array($row)) { return true; - } else { - return false; } + return false; } function garbageCollection($maxlifetime) @@ -229,19 +229,18 @@ $this->cache_table ); $cachesize = $this->db->GetOne($query); - if (DB::isError($cachesize)) { + if (PEAR::isError($cachesize)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($cachesize), __FILE__, __LINE__); } //if cache is to big. - if ($cachesize > $this->highwater) - { + if ($cachesize > $this->highwater) { //find the lowwater mark. $query = sprintf('select length(cachedata) as size, changed from %s order by changed DESC', $this->cache_table ); $res = $this->db->query($query); - if (DB::isError($res)) { + if (PEAR::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); } @@ -259,7 +258,7 @@ $res = $this->db->query($query); } - if (DB::isError($res)) { + if (PEAR::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); } } http://cvs.php.net/diff.php/pear/Cache/Container/dbx.php?r1=1.5&r2=1.6&ty=u Index: pear/Cache/Container/dbx.php diff -u pear/Cache/Container/dbx.php:1.5 pear/Cache/Container/dbx.php:1.6 --- pear/Cache/Container/dbx.php:1.5 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container/dbx.php Wed Dec 15 04:09:29 2004 @@ -15,7 +15,7 @@ // | Authors: Christian Stocker <chregu@phant.ch> | // +----------------------------------------------------------------------+ // -// $Id: dbx.php,v 1.5 2004/12/14 04:48:27 dufuz Exp $ +// $Id: dbx.php,v 1.6 2004/12/15 09:09:29 dufuz Exp $ require_once 'Cache/Container.php'; @@ -50,10 +50,11 @@ * ) * * @author Christian Stocker <chregu@phant.ch> -* @version $Id: dbx.php,v 1.5 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: dbx.php,v 1.6 2004/12/15 09:09:29 dufuz Exp $ * @package Cache */ -class Cache_Container_dbx extends Cache_Container { +class Cache_Container_dbx extends Cache_Container +{ /** * Name of the DB table to store caching data @@ -145,16 +146,16 @@ ); $res = dbx_query($this->db, $query); - if (dbx_error($this->db)) + if (dbx_error($this->db)) { return new Cache_Error('DBx query failed: ' . dbx_error($this->db), __FILE__, __LINE__); - + } $row = $res->data[0]; - if (is_array($row)) + if (is_array($row)) { $data = array($row['expires'], $this->decode($row['cachedata']), $row['userdata']); - else + } else { $data = array(null, null, null); - + } // last used required by the garbage collection // WARNING: might be MySQL specific $query = sprintf("UPDATE %s SET changed = (NOW() + 0) WHERE id = '%s' AND cachegroup = '%s'", @@ -164,9 +165,9 @@ ); $res = dbx_query($this->db, $query); - if (dbx_error($this->db)) + if (dbx_error($this->db)) { return new Cache_Error('DBx query failed: ' . dbx_error($this->db), __FILE__, __LINE__); - + } return $data; } @@ -209,8 +210,9 @@ $res = dbx_query($this->db, $query); - if (dbx_error($this->db)) + if (dbx_error($this->db)) { return new Cache_Error('DBx query failed: ' . dbx_error($this->db), __FILE__, __LINE__); + } } function flush($group = '') @@ -225,8 +227,9 @@ $res = dbx_query($this->db,$query); - if (dbx_error($this->db)) + if (dbx_error($this->db)) { return new Cache_Error('DBx query failed: ' . dbx_error($this->db), __FILE__, __LINE__); + } } function idExists($id, $group) @@ -239,17 +242,16 @@ $res = dbx_query($this->db, $query); - if (dbx_error($this->db)) + if (dbx_error($this->db)) { return new Cache_Error('DBx query failed: ' . dbx_error($this->db), __FILE__, __LINE__); - + } $row = $res[0]; if (is_array($row)) { return true; - } else { - return false; } + return false; } function garbageCollection($maxlifetime) @@ -265,31 +267,28 @@ $res = dbx_query($this->db, $query); - if (dbx_error($this->db)) + if (dbx_error($this->db)) { return new Cache_Error('DBx query failed: ' . dbx_error($this->db), __FILE__, __LINE__); - + } $query = sprintf('select sum(length(cachedata)) as CacheSize from %s', $this->cache_table ); $res = dbx_query($this->db, $query); //if cache is to big. - if ($res->data[0][CacheSize] > $this->highwater) - { + if ($res->data[0][CacheSize] > $this->highwater) { //find the lowwater mark. $query = sprintf('select length(cachedata) as size, changed from %s order by changed DESC', $this->cache_table ); $res = dbx_query($this->db, $query); - $keep_size=0; - $i=0; - while ($keep_size < $this->lowwater && $i < $res->rows ) - { - + $keep_size = 0; + $i = 0; + while ($keep_size < $this->lowwater && $i < $res->rows ) { $keep_size += $res->data[$i][size]; $i++; - } + } //delete all entries, which were changed before the "lowwwater mark" $query = sprintf('delete from %s where changed <= %s', http://cvs.php.net/diff.php/pear/Cache/Container/file.php?r1=1.15&r2=1.16&ty=u Index: pear/Cache/Container/file.php diff -u pear/Cache/Container/file.php:1.15 pear/Cache/Container/file.php:1.16 --- pear/Cache/Container/file.php:1.15 Tue Dec 14 04:15:02 2004 +++ pear/Cache/Container/file.php Wed Dec 15 04:09:29 2004 @@ -16,7 +16,7 @@ // | Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // -// $Id: file.php,v 1.15 2004/12/14 09:15:02 dufuz Exp $ +// $Id: file.php,v 1.16 2004/12/15 09:09:29 dufuz Exp $ require_once 'Cache/Container.php'; @@ -24,9 +24,10 @@ * Stores cache contents in a file. * * @author Ulf Wendel <ulf.wendel@phpdoc.de> -* @version $Id: file.php,v 1.15 2004/12/14 09:15:02 dufuz Exp $ +* @version $Id: file.php,v 1.16 2004/12/15 09:09:29 dufuz Exp $ */ -class Cache_Container_file extends Cache_Container { +class Cache_Container_file extends Cache_Container +{ /** * File locking @@ -134,13 +135,13 @@ return array(null, null, null); } // retrive the content - if (!($fh = @fopen($file, 'rb'))) + if (!($fh = @fopen($file, 'rb'))) { return new Cache_Error("Can't access cache file '$file'. Check access rights and path.", __FILE__, __LINE__); - + } // File locking (shared lock) - if ($this->fileLocking) + if ($this->fileLocking) { flock($fh, LOCK_SH); - + } // file format: // 1st line: expiration date // 2nd line: user data @@ -183,9 +184,9 @@ } // File locking (exclusive lock) - if ($this->fileLocking) + if ($this->fileLocking) { flock($fh, LOCK_EX); - + } // file format: // 1st line: expiration date // 2nd line: user data @@ -324,8 +325,9 @@ $this->total_size += filesize($file); // remove if expired - if (( ($expire && $expire <= time()) || ($lastused <= (time() - $maxlifetime)) ) && !unlink($file)) + if (( ($expire && $expire <= time()) || ($lastused <= (time() - $maxlifetime)) ) && !unlink($file)) { new Cache_Error("Can't unlink cache file '$file', skipping. Check permissions and path.", __FILE__, __LINE__); + } } closedir($dh); http://cvs.php.net/diff.php/pear/Cache/Container/mdb.php?r1=1.4&r2=1.5&ty=u Index: pear/Cache/Container/mdb.php diff -u pear/Cache/Container/mdb.php:1.4 pear/Cache/Container/mdb.php:1.5 --- pear/Cache/Container/mdb.php:1.4 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container/mdb.php Wed Dec 15 04:09:30 2004 @@ -18,7 +18,7 @@ // | Author: Lorenzo Alberton <l.alberton at quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: mdb.php,v 1.4 2004/12/14 04:48:27 dufuz Exp $ +// $Id: mdb.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $ require_once 'MDB.php'; require_once 'Cache/Container.php'; @@ -61,10 +61,11 @@ * ------------------------------------------ * * @author Lorenzo Alberton <l.alberton at quipo.it> -* @version $Id: mdb.php,v 1.4 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: mdb.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $ * @package Cache */ -class Cache_Container_mdb extends Cache_Container { +class Cache_Container_mdb extends Cache_Container +{ /** * Name of the MDB table to store caching data @@ -88,7 +89,7 @@ function Cache_Container_mdb($options) { $this->db = &MDB::Connect($options); - if(MDB::isError($this->db)) { + if (MDB::isError($this->db)) { return new Cache_Error('MDB::connect failed: ' . $this->db->getMessage(), __FILE__, __LINE__); } else { @@ -111,16 +112,16 @@ $query = 'SELECT cachedata FROM ' . $this->cache_table .' WHERE id=' . $this->db->getTextValue($id) .' AND cachegroup=' . $this->db->getTextValue($group); - if($res = $this->db->query($query)) { - if($this->db->endOfResult($res)) { + if ($res = $this->db->query($query)) { + if ($this->db->endOfResult($res)) { //no rows returned $data = array(null, null, null); } else { $clob = $this->db->fetchClob($res,0,'cachedata'); - if(!MDB::isError($clob)) { + if (!MDB::isError($clob)) { $cached_data = ''; while(!$this->db->endOfLOB($clob)) { - if(MDB::isError($error = + if (MDB::isError($error = $this->db->readLob($clob,$data,8000)<0)) { return new Cache_Error('MDB::query failed: ' . $error->getMessage(), __FILE__, __LINE__); @@ -135,7 +136,7 @@ $query = 'SELECT userdata, expires FROM ' . $this->cache_table .' WHERE id=' . $this->db->getTextValue($id) .' AND cachegroup=' . $this->db->getTextValue($group); - if($res = $this->db->query($query)) { + if ($res = $this->db->query($query)) { $row = $this->db->fetchInto($res); if (is_array($row)) { $data = array( @@ -216,7 +217,7 @@ $result = $this->db->replace($this->cache_table, $fields); - if(MDB::isError($result)) { + if (MDB::isError($result)) { //Var_Dump::display($result); return new Cache_Error('MDB::query failed: ' . $this->db->errorMessage($result), __FILE__, __LINE__); @@ -226,13 +227,13 @@ .' SET cachedata=?' .' WHERE id='. $this->db->getTextValue($id); - if(($prepared_query = $this->db->prepareQuery($query2))) { + if (($prepared_query = $this->db->prepareQuery($query2))) { $char_lob = array( 'Error' => '', 'Type' => 'data', 'Data' => $this->encode($data) ); - if(!MDB::isError($clob = $this->db->createLob($char_lob))) { + if (!MDB::isError($clob = $this->db->createLob($char_lob))) { $this->db->setParamClob($prepared_query,1,$clob,'cachedata'); if(MDB::isError($error=$this->db->executeQuery($prepared_query))) { return new Cache_Error('MDB::query failed: ' @@ -319,9 +320,8 @@ if (is_array($row)) { return true; - } else { - return false; } + return false; } /** @@ -347,8 +347,7 @@ . $this->db->errorMessage($cachesize), __FILE__, __LINE__); } //if cache is to big. - if ($cachesize > $this->highwater) - { + if ($cachesize > $this->highwater) { //find the lowwater mark. $query = 'SELECT length(cachedata) as size, changed FROM ' . $this->cache_table .' ORDER BY changed DESC'; http://cvs.php.net/diff.php/pear/Cache/Container/msession.php?r1=1.6&r2=1.7&ty=u Index: pear/Cache/Container/msession.php diff -u pear/Cache/Container/msession.php:1.6 pear/Cache/Container/msession.php:1.7 --- pear/Cache/Container/msession.php:1.6 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container/msession.php Wed Dec 15 04:09:30 2004 @@ -15,7 +15,7 @@ // | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> | // +----------------------------------------------------------------------+ // -// $Id: msession.php,v 1.6 2004/12/14 04:48:27 dufuz Exp $ +// $Id: msession.php,v 1.7 2004/12/15 09:09:30 dufuz Exp $ require_once 'Cache/Container.php'; @@ -25,11 +25,10 @@ * WARNING: experimental, untested * * @author Ulf Wendel <ulf.wendel@phpdoc.de> -* @version $Id: msession.php,v 1.6 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: msession.php,v 1.7 2004/12/15 09:09:30 dufuz Exp $ */ -class Cache_Container_msession extends Cache_Container { - - +class Cache_Container_msession extends Cache_Container +{ /** * Length of the Cache-Identifier * @@ -82,30 +81,33 @@ var $ms = null; - function Cache_Container_msession($options = '') { - if (is_array($options)) + function Cache_Container_msession($options = '') + { + if (is_array($options)) { $this->setOptions($options, array_merge($this->allowed_options, array('id_length', 'uniq', 'host', 'port', 'connect'))); - + } if ($connect) { - if (null == $this->host) + if (null == $this->host) { new Cache_Error('No host specified.', __FILE__, __LINE__); - if (null == $this->port) + } + if (null == $this->port) { new Cache_Error('No port specified.', __FILE__, __LINE__); - - if (!($this->ms = msession_connect($this->host, $this->port))) + } + if (!($this->ms = msession_connect($this->host, $this->port))) { new Cache_Error('Can not connect to the sever using host "' . $this->host . '" on port "' . $this->port . '"', __FILE__, __LINE__); + } } } // end func contructor - function fetch($id, $group) { - + function fetch($id, $group) + { $id = strtoupper(md5($group)) . $id; $group = msession_get($id, '_pear_cache_data', null); - if (null == $data) + if (null == $data) { return array(null, null, null); - + } return array($data['expires'], $data['cachedata'], $data['userdata']); } // end func fetch @@ -115,7 +117,8 @@ * WARNING: If you supply userdata it must not contain any linebreaks, * otherwise it will break the filestructure. */ - function save($id, $cachedata, $expires, $group, $userdata) { + function save($id, $cachedata, $expires, $group, $userdata) + { $this->flushPreload($id, $group); $cachedata = $this->encode($cachedata); @@ -157,21 +160,22 @@ // note that msession works different from the PEAR Cache. // msession deletes an entry if it has not been used for n-seconds. // PEAR Cache deletes after n-seconds. - if (0 != $expires) + if (0 != $expires) { msession_timeout($id, $expires); - + } msession_unlock($id); return true; } // end func save - function remove($id, $group) { + function remove($id, $group) + { $this->flushPreload($id, $group); - return msession_destroy(strtoupper(md5($group)) . $id); } // end func remove - function flush($group) { + function flush($group) + { $this->flushPreload(); $sessions = msession_find('_pear_cache_group', $group); @@ -184,8 +188,8 @@ return count($sessions); } // end func flush - function idExists($id, $group) { - + function idExists($id, $group) + { return (null == msession_get(strtoupper(md5($group)) . $id, '_pear_cache_group', null)) ? false : true; } // end func idExists @@ -197,7 +201,8 @@ * @param integer Maximum lifetime in seconds of an no longer used/touched entry * @throws Cache_Error */ - function garbageCollection($maxlifetime) { + function garbageCollection($maxlifetime) + { $this->flushPreload(); $sessions = msession_find('_pear_cache', true); @@ -209,9 +214,10 @@ foreach ($sessions as $k => $id) { $data = msession_get($id, '_pear_cache_data', null); - if (null == $data) + if (null == $data) { continue; - + } + if ($data['expires'] <= time()) { msession_destroy($id); continue; http://cvs.php.net/diff.php/pear/Cache/Container/phplib.php?r1=1.4&r2=1.5&ty=u Index: pear/Cache/Container/phplib.php diff -u pear/Cache/Container/phplib.php:1.4 pear/Cache/Container/phplib.php:1.5 --- pear/Cache/Container/phplib.php:1.4 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container/phplib.php Wed Dec 15 04:09:30 2004 @@ -16,7 +16,7 @@ // | Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // -// $Id: phplib.php,v 1.4 2004/12/14 04:48:27 dufuz Exp $ +// $Id: phplib.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $ require_once 'Cache/Container.php'; @@ -50,12 +50,12 @@ * * * @author Ulf Wendel <ulf.wendel@phpdoc.de>, Sebastian Bergmann <sb@sebastian-bergmann.de> -* @version $Id: phplib.php,v 1.4 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: phplib.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $ * @package Cache * @see save() */ -class Cache_Container_phplib extends Cache_Container { - +class Cache_Container_phplib extends Cache_Container +{ /** * Name of the DB table to store caching data * @@ -116,34 +116,36 @@ * see $local_path for some hints.s * @see $local_path */ - function Cache_Container_phplib($options = '') { - if (is_array($options)) + function Cache_Container_phplib($options = '') + { + if (is_array($options)) { $this->setOptions($options, array_merge($this->allowed_options, array('db_class', 'db_file', 'db_path', 'local_file', 'local_path'))); - - if (!$this->db_class) + } + if (!$this->db_class) { return new Cache_Error('No database class specified.', __FILE__, __LINE__); - + } // include the required files - if ($this->db_file) - include_once($this->db_path . $this->db_file); - - if ($this->local_file) - include_once($this->local_path . $this->local_file); - + if ($this->db_file) { + include_once $this->db_path . $this->db_file; + } + if ($this->local_file) { + include_once $this->local_path . $this->local_file; + } // create a db object $this->db = new $this->db_class; } // end constructor - function fetch($id, $group) { + function fetch($id, $group) + { $query = sprintf("SELECT expires, cachedata, userdata FROM %s WHERE id = '%s' AND cachegroup = '%s'", $this->cache_table, $id, $group ); $this->db->query($query); - if (!$this->db->Next_Record()) + if (!$this->db->Next_Record()) { return array(null, null, null); - + } // last used required by the garbage collection // WARNING: might be MySQL specific $query = sprintf("UPDATE %s SET changed = (NOW() + 0) WHERE id = '%s' AND cachegroup = '%s'", @@ -162,7 +164,8 @@ * MySQL specific. As MySQL is very popular the method should * work fine for 95% of you. */ - function save($id, $data, $expires, $group) { + function save($id, $data, $expires, $group) + { $this->flushPreload($id, $group); $query = sprintf("REPLACE INTO %s (cachedata, expires, id, cachegroup) VALUES ('%s', %d, '%s', '%s')", @@ -177,7 +180,8 @@ return (boolean)$this->db->affected_rows(); } // end func save - function remove($id, $group) { + function remove($id, $group) + { $this->flushPreload($id, $group); $this->db->query( sprintf("DELETE FROM %s WHERE id = '%s' AND cachegroup = '%s'", @@ -190,7 +194,8 @@ return (boolean)$this->db->affected_rows(); } // end func remove - function flush($group) { + function flush($group) + { $this->flushPreload(); if ($group) { @@ -202,7 +207,8 @@ return $this->db->affected_rows(); } // end func flush - function idExists($id, $group) { + function idExists($id, $group) + { $this->db->query( sprintf("SELECT id FROM %s WHERE ID = '%s' AND cachegroup = '%s'", $this->cache_table, @@ -214,7 +220,8 @@ return (boolean)$this->db->nf(); } // end func isExists - function garbageCollection($maxlifetime) { + function garbageCollection($maxlifetime) + { $this->flushPreload(); $this->db->query( @@ -234,8 +241,7 @@ $this->db->Next_Record(); $cachesize = $this->db->f('CacheSize'); //if cache is to big. - if ($cachesize > $this->highwater) - { + if ($cachesize > $this->highwater) { //find the lowwater mark. $query = sprintf('select length(cachedata) as size, changed from %s order by changed DESC', $this->cache_table @@ -243,8 +249,7 @@ $this->db->query($query); $keep_size=0; - while ($keep_size < $this->lowwater && $this->db->Next_Record() ) - { + while ($keep_size < $this->lowwater && $this->db->Next_Record()) { $keep_size += $this->db->f('size'); } //delete all entries, which were changed before the "lowwwater mark" http://cvs.php.net/diff.php/pear/Cache/Container/shm.php?r1=1.4&r2=1.5&ty=u Index: pear/Cache/Container/shm.php diff -u pear/Cache/Container/shm.php:1.4 pear/Cache/Container/shm.php:1.5 --- pear/Cache/Container/shm.php:1.4 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container/shm.php Wed Dec 15 04:09:30 2004 @@ -16,7 +16,7 @@ // | Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // -// $Id: shm.php,v 1.4 2004/12/14 04:48:27 dufuz Exp $ +// $Id: shm.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $ require_once 'Cache/Container.php'; @@ -29,10 +29,11 @@ * caching algorithm using PHP. * * @author Ulf Wendel <ulf.wendel@phpdoc.de> -* @version $Id: shm.php,v 1.4 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: shm.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $ * @package Cache */ -class Cache_Container_shm extends Cache_Container { +class Cache_Container_shm extends Cache_Container +{ /** * Key of the semaphore used to sync the SHM access * @@ -105,8 +106,9 @@ * * @param array shm_key, sem_key, shm_size, sem_perm, shm_perm */ - function Cache_Container_shm($options = '') { - if (is_array($options)) + function Cache_Container_shm($options = '') + { + if (is_array($options)) { $this->setOptions($options, array_merge($this->allowed_options, array('shm_key', 'sem_key', 'shm_size', 'sem_perm', @@ -114,33 +116,35 @@ ) ) ); - + } // Cache::Container high- and lowwater defaults should be overridden if // not already done by the user - if (!isset($options['highwater'])) + if (!isset($options['highwater'])) { $this->highwater = round(0.75 * 131072); - if (!isset($options['lowwater'])) + } + if (!isset($options['lowwater'])) { $this->lowwater = round(0.5 * 131072); - - if (!isset($options['shm_size'])) + } + if (!isset($options['shm_size'])) { $this->shm_size = 131072; - + } //get SHM and Semaphore handles - if (!($this->shm_id = shmop_open($this->shm_key, 'c', $this->shm_perm, $this->shm_size))) + if (!($this->shm_id = shmop_open($this->shm_key, 'c', $this->shm_perm, $this->shm_size))) { new Cache_Error("Can't open SHM segment '{$this->shm_key}', size '{$this->shm_size}'.", __FILE__, __LINE__ ); - - if (!($this->sem_id = sem_get($this->sem_key, 1, $this->sem_perm))) + } + if (!($this->sem_id = sem_get($this->sem_key, 1, $this->sem_perm))) { new Cache_Error("Can't get semaphore '{$this->sem_key}' using perms '{$this->sem_perm}'.", __FILE__, __LINE__ ); - + } } // end constructor - function fetch($id, $group) { + function fetch($id, $group) + { sem_acquire($this->sem_id); $cachedata = shmop_read($this->shm_id, 0, $this->shm_size); @@ -149,18 +153,19 @@ $cachedata = $this->decode($cachedata); - if (!isset($cachedata[$group][$id])) + if (!isset($cachedata[$group][$id])) { return array(null, null, null); - else + } else { $cachedata = $cachedata[$group][$id]; - + } return array($cachedata['expire'], $cachedata['cachedata'], $cachedata['userdata'] ); } // end func fetch - function save($id, $data, $expire, $group, $userdata) { + function save($id, $data, $expire, $group, $userdata) + { $this->flushPreload($id, $group); sem_acquire($this->sem_id); @@ -172,9 +177,9 @@ 'changed' => time() ); - if (strlen($newdata = $this->encode($cachedata)) > $this->shm_size) + if (strlen($newdata = $this->encode($cachedata)) > $this->shm_size) { $cachedata = $this->garbageCollection(time(), $cachedata); - + } shmop_write($this->shm_id, $newdata, 0); sem_release($this->sem_id); @@ -182,7 +187,8 @@ return true; } // end func save - function remove($id, $group) { + function remove($id, $group) + { $this->flushPreload($id, $group); sem_acquire($this->sem_id); @@ -194,7 +200,8 @@ sem_release($this->sem_id); } // end func remove - function flush($group = '') { + function flush($group = '') + { $this->flushPreload(); sem_acquire($this->sem_id); @@ -204,7 +211,8 @@ sem_release($this->sem_id); } // end func flush - function idExists($id, $group) { + function idExists($id, $group) + { sem_acquire($this->sem_id); $cachedata = shm_read($this->shm_id, 0, $this->shm_size); @@ -216,7 +224,8 @@ return isset($cachedata[$group][$id]); } // end func isExists - function garbageCollection($maxlifetime, $cachedata = array()) { + function garbageCollection($maxlifetime, $cachedata = array()) + { if ($lock = empty($cachedata)) { sem_acquire($this->sem_id); $cachedata = $this->decode(shmop_read($this->shm_id, 0, $this->shm_size)); @@ -237,16 +246,17 @@ } } - if ($lock) + if ($lock) { sem_release($this->sem_id); - + } $this->entries = array(); $this->total_size = 0; return $cachedata; } // end func garbageCollection - function doGarbageCollection($maxlifetime, &$cachedata) { + function doGarbageCollection($maxlifetime, &$cachedata) + { $changed = time() - $maxlifetime; $removed = 0; http://cvs.php.net/diff.php/pear/Cache/Container/trifile.php?r1=1.3&r2=1.4&ty=u Index: pear/Cache/Container/trifile.php diff -u pear/Cache/Container/trifile.php:1.3 pear/Cache/Container/trifile.php:1.4 --- pear/Cache/Container/trifile.php:1.3 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container/trifile.php Wed Dec 15 04:09:30 2004 @@ -17,7 +17,7 @@ // | Ian Eure <ieure@php.net> | // +----------------------------------------------------------------------+ // -// $Id: trifile.php,v 1.3 2004/12/14 04:48:27 dufuz Exp $ +// $Id: trifile.php,v 1.4 2004/12/15 09:09:30 dufuz Exp $ require_once 'Cache/Container/file.php'; @@ -33,7 +33,8 @@ * @author Ian Eure <ieure@php.net> * @version 1.0 */ -class Cache_Container_trifile extends Cache_Container_file { +class Cache_Container_trifile extends Cache_Container_file +{ /** * Fetch cached file. * @@ -44,9 +45,13 @@ function fetch($id, $group) { $file = $this->getFilename($id, $group); - if (!file_exists($file)) + if (PEAR::isError($file)) { + return $file; + } + + if (!file_exists($file)) { return array(null, null, null); - + } return array( file_get_contents($this->_getExpFile($file)), file_get_contents($file), @@ -104,13 +109,17 @@ $this->flushPreload($id, $group); $file = $this->getFilename($id, $group); + if (PEAR::isError($file)) { + return $file; + } + if (PEAR::isError($res = $this->_saveData($file, $cachedata))) { return $res; } if (PEAR::isError($res = $this->_saveData($this->_getExpFile($file), $expires))) { return $res; } - if(PEAR::isError($res = $this->_saveData($this->_getUDFile($file), $userdata))) { + if (PEAR::isError($res = $this->_saveData($this->_getUDFile($file), $userdata))) { return $res; } @@ -124,7 +133,8 @@ * @param string $data Data to save * @return mixed true on success, Cache_Error otherwise */ - function _saveData($file, $data) { + function _saveData($file, $data) + { // Save data if (!($fh = @fopen($file, 'wb'))) return new Cache_Error("Can't access '$file' to store cache data. Check access rights and path.", __FILE__, __LINE__); @@ -135,7 +145,7 @@ fwrite($fh, $data); - if($this->fileLocking) { + if ($this->fileLocking) { flock($fh, LOCK_UN); } http://cvs.php.net/diff.php/pear/Cache/Application.php?r1=1.6&r2=1.7&ty=u Index: pear/Cache/Application.php diff -u pear/Cache/Application.php:1.6 pear/Cache/Application.php:1.7 --- pear/Cache/Application.php:1.6 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Application.php Wed Dec 15 04:09:33 2004 @@ -16,7 +16,7 @@ // | Authors: Richard Heyes <richard@phpguru.org> | // +----------------------------------------------------------------------+ // -// $Id: Application.php,v 1.6 2004/12/14 04:48:27 dufuz Exp $ +// $Id: Application.php,v 1.7 2004/12/15 09:09:33 dufuz Exp $ require_once 'Cache.php'; @@ -70,7 +70,8 @@ // (In fact if you use the register() function with register_globals Off, you have to // use the $_APP method to get at the data). -class Cache_Application extends Cache { +class Cache_Application extends Cache +{ var $data; var $id; http://cvs.php.net/diff.php/pear/Cache/Cache.php?r1=1.6&r2=1.7&ty=u Index: pear/Cache/Cache.php diff -u pear/Cache/Cache.php:1.6 pear/Cache/Cache.php:1.7 --- pear/Cache/Cache.php:1.6 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Cache.php Wed Dec 15 04:09:33 2004 @@ -16,7 +16,7 @@ // | Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // -// $Id: Cache.php,v 1.6 2004/12/14 04:48:27 dufuz Exp $ +// $Id: Cache.php,v 1.7 2004/12/15 09:09:33 dufuz Exp $ require_once 'PEAR.php'; require_once 'Cache/Error.php'; @@ -59,11 +59,12 @@ * bad circumstances (especially with the file container) * * @author Ulf Wendel <ulf.wendel@phpdoc.de> -* @version $Id: Cache.php,v 1.6 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: Cache.php,v 1.7 2004/12/15 09:09:33 dufuz Exp $ * @package Cache * @access public */ -class Cache extends PEAR { +class Cache extends PEAR +{ /** * Enables / disables caching. @@ -172,13 +173,15 @@ * @return mixed cached data or null on failure * @access public */ - function get($id, $group = 'default') { - if (!$this->caching) + function get($id, $group = 'default') + { + if (!$this->caching) { return ''; + } - if ($this->isCached($id, $group) && !$this->isExpired($id, $group)) + if ($this->isCached($id, $group) && !$this->isExpired($id, $group)) { return $this->load($id, $group); - + } return null; } // end func get @@ -192,10 +195,11 @@ * @return boolean * @access public */ - function save($id, $data, $expires = 0, $group = 'default') { - if (!$this->caching) + function save($id, $data, $expires = 0, $group = 'default') + { + if (!$this->caching) { return true; - + } return $this->extSave($id, $data, '',$expires, $group); } // end func save @@ -212,10 +216,11 @@ * @access public * @see getUserdata() */ - function extSave($id, $cachedata, $userdata, $expires = 0, $group = 'default') { - if (!$this->caching) + function extSave($id, $cachedata, $userdata, $expires = 0, $group = 'default') + { + if (!$this->caching) { return true; - + } return $this->container->save($id, $cachedata, $expires, $group, $userdata); } // end func extSave @@ -227,10 +232,11 @@ * @return mixed cached data or null on failure * @access public */ - function load($id, $group = 'default') { - if (!$this->caching) + function load($id, $group = 'default') + { + if (!$this->caching) { return ''; - + } return $this->container->load($id, $group); } // end func load @@ -243,10 +249,11 @@ * @access public * @see extSave() */ - function getUserdata($id, $group = 'default') { - if (!$this->caching) + function getUserdata($id, $group = 'default') + { + if (!$this->caching) { return ''; - + } return $this->container->getUserdata($id, $group); } // end func getUserdata @@ -258,10 +265,11 @@ * @return boolean * @access public */ - function remove($id, $group = 'default') { - if (!$this->caching) + function remove($id, $group = 'default') + { + if (!$this->caching) { return true; - + } return $this->container->remove($id, $group); } // end func remove @@ -271,10 +279,11 @@ * @param string cache group, if empty all groups will be flashed * @return integer number of removed datasets */ - function flush($group = 'default') { - if (!$this->caching) + function flush($group = 'default') + { + if (!$this->caching) { return true; - + } return $this->container->flush($group); } // end func flush @@ -288,10 +297,11 @@ * @return boolean * @access public */ - function isCached($id, $group = 'default') { - if (!$this->caching) + function isCached($id, $group = 'default') + { + if (!$this->caching) { return false; - + } return $this->container->isCached($id, $group); } // end func isCached @@ -309,10 +319,11 @@ * @return boolean * @access public */ - function isExpired($id, $group = 'default', $max_age = 0) { - if (!$this->caching) + function isExpired($id, $group = 'default', $max_age = 0) + { + if (!$this->caching) { return true; - + } return $this->container->isExpired($id, $group, $max_age); } // end func isExpired @@ -326,7 +337,8 @@ * @return string "unique" ID * @access public */ - function generateID($variable) { + function generateID($variable) + { // WARNING: ID clashes are possible although unlikely return md5(serialize($variable)); } @@ -337,12 +349,13 @@ * @param boolean Force a garbage collection run? * @see $gc_probability, $gc_time */ - function garbageCollection($force = false) { + function garbageCollection($force = false) + { static $last_run = 0; - if (!$this->caching) + if (!$this->caching) { return; - + } srand((double) microtime() * 1000000); // time and probability based http://cvs.php.net/diff.php/pear/Cache/Container.php?r1=1.5&r2=1.6&ty=u Index: pear/Cache/Container.php diff -u pear/Cache/Container.php:1.5 pear/Cache/Container.php:1.6 --- pear/Cache/Container.php:1.5 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container.php Wed Dec 15 04:09:33 2004 @@ -17,7 +17,7 @@ // | Christian Stocker <chregu@phant.ch> | // +----------------------------------------------------------------------+ // -// $Id: Container.php,v 1.5 2004/12/14 04:48:27 dufuz Exp $ +// $Id: Container.php,v 1.6 2004/12/15 09:09:33 dufuz Exp $ require_once 'Cache/Error.php'; @@ -39,12 +39,13 @@ * not recommended! * * @author Ulf Wendel <ulf.wendel@phpdoc.de> -* @version $Id: Container.php,v 1.5 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: Container.php,v 1.6 2004/12/15 09:09:33 dufuz Exp $ * @package Cache * @access public * @abstract */ -class Cache_Container { +class Cache_Container +{ /** * Flag indicating wheter to preload datasets. @@ -143,11 +144,12 @@ * @return mixed dataset value or null on failure * @access public */ - function load($id, $group) { + function load($id, $group) + { if ($this->preload) { - if ($this->id != $id || $this->group != $group) + if ($this->id != $id || $this->group != $group) { $this->preload($id, $group); - + } return $this->cachedata; } else { list( , $data, ) = $this->fetch($id, $group); @@ -163,11 +165,12 @@ * @return string userdata * @access public */ - function getUserdata($id, $group) { + function getUserdata($id, $group) + { if ($this->preload) { - if ($this->id != $id || $this->group != $group) + if ($this->id != $id || $this->group != $group) { $this->preload($id, $group); - + } return $this->userdata; } else { list( , , $userdata) = $this->fetch($id, $group); @@ -184,26 +187,28 @@ * @return boolean * @access public */ - function isExpired($id, $group, $max_age) { + function isExpired($id, $group, $max_age) + { if ($this->preload) { - if ($this->id != $id || $this->group != $group) - $this->preload($id, $group); - - if ($this->unknown) - return false; + if ($this->id != $id || $this->group != $group) { + $this->preload($id, $group); + } + if ($this->unknown) { + return false; + } } else { // check if at all it is cached - if (!$this->isCached($id, $group)) + if (!$this->isCached($id, $group)) { return false; - + } // I'm lazy... list($this->expires, , ) = $this->fetch($id, $group); } // endless - if (0 == $this->expires) + if (0 == $this->expires) { return false; - + } // you feel fine, Ulf? if ($expired = ($this->expires <= time() || ($max_age && ($this->expires <= $max_age))) ) { @@ -220,15 +225,15 @@ * @param string cache group * @return boolean */ - function isCached($id, $group) { + function isCached($id, $group) + { if ($this->preload) { - if ($this->id != $id || $this->group != $group) + if ($this->id != $id || $this->group != $group) { $this->preload($id, $group); - + } return !($this->unknown); - } else { - return $this->idExists($id, $group); } + return $this->idExists($id, $group); } // end func isCached // @@ -244,7 +249,8 @@ * @throws Cache_Error * @abstract */ - function fetch($id, $group) { + function fetch($id, $group) + { return array(null, null, null); } // end func fetch @@ -261,11 +267,11 @@ * @access public * @abstract */ - function save($id, $data, $expire, $group, $userdata) { + function save($id, $data, $expire, $group, $userdata) + { // QUESTION: Should we update the preload buffer instead? // Don't think so as the sequence save()/load() is unlikely. $this->flushPreload($id, $group); - return null; } // end func save @@ -278,7 +284,8 @@ * @access public * @abstract */ - function remove($id, $group) { + function remove($id, $group) + { $this->flushPreload($id, $group); return null; } // end func remove @@ -291,7 +298,8 @@ * @access public * @abstract */ - function flush($group) { + function flush($group) + { $this->flushPreload(); return null; } // end func flush @@ -305,7 +313,8 @@ * @access public * @abstract */ - function idExists($id, $group) { + function idExists($id, $group) + { return null; } // end func idExists @@ -315,7 +324,8 @@ * @access public * @abstract */ - function garbageCollection() { + function garbageCollection() + { $this->flushPreload(); } // end func garbageCollection @@ -326,7 +336,8 @@ * @param string cache group * @return boolean */ - function preload($id, $group) { + function preload($id, $group) + { // whatever happens, remember the preloaded ID $this->id = $id; $this->group = $group; @@ -336,7 +347,6 @@ if (null === $this->expires) { // Uuups, unknown ID $this->flushPreload(); - return false; } @@ -358,7 +368,8 @@ * @param string cache group * @see preload() */ - function flushPreload($id = '', $group = 'default') { + function flushPreload($id = '', $group = 'default') + { if (!$id || ($this->id == $id && $this->group == $group)) { // clear the internal preload values $this->id = ''; @@ -376,11 +387,13 @@ * @param array List of fields to be imported as object variables * @param array List of allowed datafields */ - function setOptions($requested, $allowed) { - foreach ($allowed as $k => $field) - if (isset($requested[$field])) + function setOptions($requested, $allowed) + { + foreach ($allowed as $k => $field) { + if (isset($requested[$field])) { $this->$field = $requested[$field]; - + } + } } // end func setOptions /** @@ -388,11 +401,13 @@ * * @var mixed data to encode */ - function encode($data) { - if ('base64' == $this->encoding_mode) + function encode($data) + { + if ('base64' == $this->encoding_mode) { return base64_encode(serialize($data)); - else + } else { return serialize($data); + } } // end func encode @@ -401,11 +416,13 @@ * * @var mixed */ - function decode($data) { - if ('base64' == $this->encoding_mode) + function decode($data) + { + if ('base64' == $this->encoding_mode) { return unserialize(base64_decode($data)); - else + } else { return unserialize($data); + } } // end func decode @@ -422,24 +439,20 @@ */ function getExpiresAbsolute($expires) { - if (!$expires) + if (!$expires) { return 0; + } //for api-compatibility, one has not to provide a "+", // if integer is < 946681200 (= Jan 01 2000 00:00:00) - if ('+' == $expires[0] || $expires < 946681200) - { + if ('+' == $expires[0] || $expires < 946681200) { return(time() + $expires); - } - //if integer is < 100000000000 (= in 3140 years), - // it must be an absolut unixtime - // (since the "human readable" definition asks for a higher number) - elseif ($expires < 100000000000) - { + } elseif ($expires < 100000000000) { + //if integer is < 100000000000 (= in 3140 years), + // it must be an absolut unixtime + // (since the "human readable" definition asks for a higher number) return $expires; - } - // else it's "human readable"; - else - { + } else { + // else it's "human readable"; $year = substr($expires, 0, 4); $month = substr($expires, 4, 2); $day = substr($expires, 6, 2); http://cvs.php.net/diff.php/pear/Cache/Error.php?r1=1.3&r2=1.4&ty=u Index: pear/Cache/Error.php diff -u pear/Cache/Error.php:1.3 pear/Cache/Error.php:1.4 --- pear/Cache/Error.php:1.3 Sat Jan 4 06:54:45 2003 +++ pear/Cache/Error.php Wed Dec 15 04:09:33 2004 @@ -15,7 +15,7 @@ // | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> | // +----------------------------------------------------------------------+ // -// $Id: Error.php,v 1.3 2003/01/04 11:54:45 mj Exp $ +// $Id: Error.php,v 1.4 2004/12/15 09:09:33 dufuz Exp $ require_once 'PEAR.php'; @@ -24,7 +24,8 @@ * * @package Cache */ -class Cache_Error extends PEAR_Error { +class Cache_Error extends PEAR_Error +{ /** http://cvs.php.net/diff.php/pear/Cache/Function.php?r1=1.7&r2=1.8&ty=u Index: pear/Cache/Function.php diff -u pear/Cache/Function.php:1.7 pear/Cache/Function.php:1.8 --- pear/Cache/Function.php:1.7 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Function.php Wed Dec 15 04:09:33 2004 @@ -15,7 +15,7 @@ // | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // -// $Id: Function.php,v 1.7 2004/12/14 04:48:27 dufuz Exp $ +// $Id: Function.php,v 1.8 2004/12/15 09:09:33 dufuz Exp $ require_once 'Cache.php'; @@ -65,10 +65,11 @@ * @module Function_Cache * @modulegroup Function_Cache * @package Cache -* @version $Revision: 1.7 $ +* @version $Revision: 1.8 $ * @access public */ -class Cache_Function extends Cache { +class Cache_Function extends Cache +{ var $expires; /** @@ -93,7 +94,8 @@ * PEAR-Deconstructor * Call deconstructor of parent */ - function _Cache_Function() { + function _Cache_Function() + { $this->_Cache(); } @@ -103,7 +105,8 @@ * @return mixed $result * @access public */ - function call() { + function call() + { // get arguments $arguments = func_get_args(); @@ -130,18 +133,14 @@ list($class, $method) = explode('::', $target); $result = call_user_func_array(array($class, $method), $arguments); - } - - // object->method - elseif (strstr($target, '->')) { + } elseif (strstr($target, '->')) { + // object->method list($object, $method) = explode('->', $target); global $$object; $result = call_user_func_array(array($$object, $method), $arguments); - } - - // function - else { + } else { + // function $result = call_user_func_array($target, $arguments); } http://cvs.php.net/diff.php/pear/Cache/Graphics.php?r1=1.5&r2=1.6&ty=u Index: pear/Cache/Graphics.php diff -u pear/Cache/Graphics.php:1.5 pear/Cache/Graphics.php:1.6 --- pear/Cache/Graphics.php:1.5 Sat Jan 4 06:54:45 2003 +++ pear/Cache/Graphics.php Wed Dec 15 04:09:33 2004 @@ -15,7 +15,7 @@ // | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> | // +----------------------------------------------------------------------+ // -// $Id: Graphics.php,v 1.5 2003/01/04 11:54:45 mj Exp $ +// $Id: Graphics.php,v 1.6 2004/12/15 09:09:33 dufuz Exp $ require_once 'Cache.php'; @@ -66,10 +66,11 @@ * the output buffer. Modify it if required! * * @author Ulf Wendel <ulf.wendel@phpdoc.de> -* @version $Id: Graphics.php,v 1.5 2003/01/04 11:54:45 mj Exp $ +* @version $Id: Graphics.php,v 1.6 2004/12/15 09:09:33 dufuz Exp $ * @package Cache */ -class Cache_Graphics extends Cache { +class Cache_Graphics extends Cache +{ /** @@ -135,8 +136,8 @@ * Instantiates a cache file container. * */ - function Cache_Graphics() { - + function Cache_Graphics() + { $this->Cache('file', array('cache_dir' => $this->cache_dir, 'filename_prefix' => $this->cache_file_prefix)); } // end constructor @@ -156,9 +157,9 @@ * @return string Image file contents if a cached file exists otherwise an empty string * @see cacheImage() */ - function getImage($id, $format = 'png') { + function getImage($id, $format = 'png') + { $id = $this->generateID($id, $format); - return $this->get($id, $this->cache_group); } // end func getImage @@ -175,11 +176,12 @@ * @throw Cache_Error * @see cacheImageLink() */ - function getImageLink($id, $format = 'png') { + function getImageLink($id, $format = 'png') + { $id = $this->generateID($id, $format); - if (!$this->container->idExists($id, $this->cache_group)) + if (!$this->container->idExists($id, $this->cache_group)) { return array(); - + } $file = $this->cache_url . $this->cache_file_prefix . $id; return array($this->container->getFilename($id, $this->cache_group), $file); @@ -206,10 +208,11 @@ * @access public * @see getImage() */ - function cacheImage($id, $img, $format = 'png') { - if (!$id) + function cacheImage($id, $img, $format = 'png') + { + if (!$id) { return new Cache_Error('You must provide an ID for and image to be cached!', __FILE__, __LINE__); - + } $id = $this->generateID($id, $format); $types = ImageTypes(); @@ -225,9 +228,9 @@ } } - if ($image = $this->get($id, $this->cache_group)) + if ($image = $this->get($id, $this->cache_group)) { return $image; - + } // save the image to the output buffer, write it to disk and // return the image. ob_end_clean(); @@ -271,10 +274,11 @@ * @throws Cache_Error * @access public */ - function cacheImageLink($id, &$img, $format = 'png') { - if (!$id) + function cacheImageLink($id, &$img, $format = 'png') + { + if (!$id) { return new Cache_Error ('You must provide an ID for and image to be cached!', __FILE__, __LINE__); - + } $id = $this->generateID($id, $format); $types = ImageTypes(); @@ -282,17 +286,19 @@ // If not, try a callback to the first available image type. if (!isset($this->imagetypes[$format]) || !($types & $this->imagetypes[$format])) { foreach ($this->imagetypes as $supported => $bitmask) - if ($types & $bitmask) + if ($types & $bitmask) { new Cache_Error("The build in GD lib does not support the image type $format. Fallback to $supported.", __FILE__, __LINE__); - else + } else { return new Cache_Error("Hmm, is your PHP build with GD support? Can't find any supported types.", __FILE__, __LINE__); + } } $url = $this->cache_url . $this->cache_file_prefix . $id; $ffile = $this->container->getFilename($id, $this->cache_group); - if ($this->isCached($id, $this->cache_group) && !isExpired($id, $this->cache_group)) + if ($this->isCached($id, $this->cache_group) && !isExpired($id, $this->cache_group)) { return array($ffile, $url); + } if (strtoupper($format) == "JPG") { $genFormat = "JPEG"; @@ -319,10 +325,11 @@ * @access public * @see setCacheDir() */ - function setCacheURL($cache_url) { - if ($cache_url && '/' != substr($cache_url, 1)) + function setCacheURL($cache_url) + { + if ($cache_url && '/' != substr($cache_url, 1)) { $cache_url .= '/'; - + } $this->cache_url = $cache_url; } // end func setCacheURL @@ -335,16 +342,18 @@ * @access public * @see setCacheURL() */ - function setCacheDir($cache_dir) { - if ($cache_dir && '/' != substr($cache_dir, 1)) + function setCacheDir($cache_dir) + { + if ($cache_dir && '/' != substr($cache_dir, 1)) { $cache_dir .= '/'; - + } $this->cache_dir = $cache_dir; $this->container->cache_dir = $cache_dir; } // end func setCacheDir - function generateID($variable, $format = 'png') { + function generateID($variable, $format = 'png') + { return md5(serialize($variable)) . '.' . $format; } // end func generateID http://cvs.php.net/diff.php/pear/Cache/HTTP_Request.php?r1=1.10&r2=1.11&ty=u Index: pear/Cache/HTTP_Request.php diff -u pear/Cache/HTTP_Request.php:1.10 pear/Cache/HTTP_Request.php:1.11 --- pear/Cache/HTTP_Request.php:1.10 Mon Dec 13 23:48:27 2004 +++ pear/Cache/HTTP_Request.php Wed Dec 15 04:09:33 2004 @@ -15,7 +15,7 @@ // | Authors: Fabien MARTY <fabien.marty@free.fr> | // +----------------------------------------------------------------------+ // -// $Id: HTTP_Request.php,v 1.10 2004/12/14 04:48:27 dufuz Exp $ +// $Id: HTTP_Request.php,v 1.11 2004/12/15 09:09:33 dufuz Exp $ require_once 'Cache.php'; require_once 'HTTP/Request.php'; @@ -56,7 +56,7 @@ * ?> * * @author Fabien MARTY <fabien.marty@free.fr> -* @version $Id: HTTP_Request.php,v 1.10 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: HTTP_Request.php,v 1.11 2004/12/15 09:09:33 dufuz Exp $ * @package Cache */ @@ -132,7 +132,10 @@ $containerOptions = null, $expires = 3600, $mode = CACHE_HTTP_REQUEST_KEEP_LOCAL_COPY) { - if (!isset($params)) $params = array(); + if (!isset($params)) { + $params = array(); + } + if (!isset($containerOptions)) { $containerOptions = array ( 'cache_dir' => '/tmp/', http://cvs.php.net/diff.php/pear/Cache/OutputCompression.php?r1=1.7&r2=1.8&ty=u Index: pear/Cache/OutputCompression.php diff -u pear/Cache/OutputCompression.php:1.7 pear/Cache/OutputCompression.php:1.8 --- pear/Cache/OutputCompression.php:1.7 Sat Jan 4 06:54:45 2003 +++ pear/Cache/OutputCompression.php Wed Dec 15 04:09:33 2004 @@ -50,12 +50,13 @@ * * Based upon a case study from Christian Stocker and inspired by jpcache. * -* @version $Id: OutputCompression.php,v 1.7 2003/01/04 11:54:45 mj Exp $ +* @version $Id: OutputCompression.php,v 1.8 2004/12/15 09:09:33 dufuz Exp $ * @author Ulf Wendel <ulf.wendel@phpdoc.de>, Christian Stocker <chregu@phant.ch> * @access public * @package Cache */ -class Cache_OutputCompression extends Cache_Output { +class Cache_OutputCompression extends Cache_Output +{ /** * Encoding, what the user (its browser) of your website accepts @@ -84,8 +85,8 @@ * @param array Array with container class options * @param string content encoding mode - auto => test which encoding the user accepts */ - function Cache_OutputCompression($container, $container_options = '', $encoding = 'auto') { - + function Cache_OutputCompression($container, $container_options = '', $encoding = 'auto') + { $this->setEncoding($encoding); $this->Cache($container, $container_options); @@ -95,28 +96,30 @@ /** * Call parent deconstructor. */ - function _Cache_OutputCompression() { + function _Cache_OutputCompression() + { $this->_Cache(); } // end deconstructor - function generateID($variable) { - + function generateID($variable) + { $this->compression = $this->getEncoding(); - return md5(serialize($variable) . serialize($this->compression)); } // end generateID - function get($id, $group) { + function get($id, $group) + { $this->content = ''; - if (!$this->caching) + if (!$this->caching) { return ''; - - if ($this->isCached($id, $group) && !$this->isExpired($id, $group)) + } + + if ($this->isCached($id, $group) && !$this->isExpired($id, $group)) { $this->content = $this->load($id, $group); - + } return $this->content; } // end func get @@ -127,7 +130,8 @@ * If you need the uncompressed content for further procession before * it's saved in the cache use endGet(). endGet() does _not compress_. */ - function end($expire = 0, $userdata = '') { + function end($expire = 0, $userdata = '') + { $content = ob_get_contents(); ob_end_clean(); @@ -141,7 +145,8 @@ } // end func end() - function endPrint($expire = 0, $userdata = '') { + function endPrint($expire = 0, $userdata = '') + { $this->printContent($this->end($expire, $userdata)); } // end func endPrint @@ -150,21 +155,19 @@ * Saves the given data to the cache. * */ - function extSave($id, $cachedata, $userdata, $expires = 0, $group = 'default') { - if (!$this->caching) + function extSave($id, $cachedata, $userdata, $expires = 0, $group = 'default') + { + if (!$this->caching) { return true; + } - if ($this->compression) { - + if ($this->compression) { $len = strlen($cachedata); $crc = crc32($cachedata); $cachedata = gzcompress($cachedata, 9); $this->content = substr($cachedata, 0, strlen($cachedata) - 4) . pack('V', $crc) . pack('V', $len); - } else { - $this->content = $cachedata; - } return $this->container->save($id, $this->content, $expires, $group, $userdata); } // end func extSave @@ -175,22 +178,22 @@ * @param string * @access public */ - function printContent($content = '') { + function printContent($content = '') + { $server = &$this->_importGlobalVariable("server"); - if ('' == $content) + if ('' == $content) { $content = &$this->container->cachedata; - + } + if ($this->compression && $this->caching) { - - $etag = 'PEAR-Cache-' . md5(substr($content, -40)); + $etag = '"PEAR-Cache-' . md5(substr($content, -40)) .'"'; header("ETag: $etag"); if (isset($server['HTTP_IF_NONE_MATCH']) && strstr(stripslashes($server['HTTP_IF_NONE_MATCH']), $etag)) { // not modified header('HTTP/1.0 304'); return; } else { - // client acceppts some encoding - send headers & data header("Content-Encoding: {$this->compression}"); header('Vary: Accept-Encoding'); @@ -209,7 +212,8 @@ * @access public * @return string Empty string (which evaluates to false) means no compression */ - function isCompressed() { + function isCompressed() + { return $this->compression; } // end func isCompressed @@ -220,7 +224,8 @@ * @access public * @see $encoding */ - function setEncoding($encoding = 'auto') { + function setEncoding($encoding = 'auto') + { $this->encoding = $encoding; } // end func setEncoding @@ -230,19 +235,21 @@ * * @see setEncoding() */ - function getEncoding() { + function getEncoding() + { $server = &$this->_importGlobalVariable("server"); // encoding set by user - if ('auto' != $this->encoding) + if ('auto' != $this->encoding) { return $this->encoding; - + } // check what the client accepts - if (false !== strpos($server['HTTP_ACCEPT_ENCODING'], 'x-gzip')) + if (false !== strpos($server['HTTP_ACCEPT_ENCODING'], 'x-gzip')) { return 'x-gzip'; - if (false !== strpos($server['HTTP_ACCEPT_ENCODING'], 'gzip')) + } + if (false !== strpos($server['HTTP_ACCEPT_ENCODING'], 'gzip')) { return 'gzip'; - + } // no compression return ''; @@ -264,7 +271,7 @@ switch (strtolower($variable)) { - case "server" : + case 'server': if (isset($_SERVER)) { $var = &$_SERVER; } else { @@ -272,7 +279,7 @@ } break; - case "session" : + case 'session': if (isset($_SESSION)) { $var = &$_SESSION; } else { @@ -280,7 +287,7 @@ } break; - case "post" : + case 'post': if (isset($_POST)) { $var = &$_POST; } else { http://cvs.php.net/diff.php/pear/Cache/Output.php?r1=1.6&r2=1.7&ty=u Index: pear/Cache/Output.php diff -u pear/Cache/Output.php:1.6 pear/Cache/Output.php:1.7 --- pear/Cache/Output.php:1.6 Sat Jan 4 06:54:45 2003 +++ pear/Cache/Output.php Wed Dec 15 04:09:33 2004 @@ -17,7 +17,7 @@ // | Vinai Kopp <kopp@netzarbeiter.de> | // +----------------------------------------------------------------------+ // -// $Id: Output.php,v 1.6 2003/01/04 11:54:45 mj Exp $ +// $Id: Output.php,v 1.7 2004/12/15 09:09:33 dufuz Exp $ require_once 'Cache.php'; @@ -94,7 +94,8 @@ * @package Cache * @access public */ -class Cache_Output extends Cache { +class Cache_Output extends Cache +{ /** * ID passed to start() @@ -129,15 +130,16 @@ * @return string * @access public */ - function start($id, $group = 'default') { - if (!$this->caching) + function start($id, $group = 'default') + { + if (!$this->caching) { return ''; - + } // this is already cached return it from the cache so that the user // can use the cache content and stop script execution - if ($content = $this->get($id, $group)) + if ($content = $this->get($id, $group)) { return $content; - + } // remember some data to be able to fill the cache on calling end() $this->output_id = $id; $this->output_group = $group; @@ -158,14 +160,15 @@ * @access public * @see endPrint(), endGet(), Container::getExpiresAbsolute() */ - function end($expire = 0, $userdata = '') { + function end($expire = 0, $userdata = '') + { $content = ob_get_contents(); ob_end_clean(); // store in the cache - if ($this->caching) + if ($this->caching) { $this->container->save($this->output_id, $content, $expire, $this->output_group, $userdata); - + } return $content; } // end func end() @@ -174,7 +177,8 @@ * * @brother end() */ - function endPrint($expire = 0, $userdata = '') { + function endPrint($expire = 0, $userdata = '') + { $this->printContent($this->end($expire, $userdata)); } // end func endPrint @@ -185,10 +189,11 @@ * @param string * @access public */ - function printContent($content = '') { - if ('' == $content) + function printContent($content = '') + { + if ('' == $content) { $content = &$this->container->cachedata; - + } print $content; } /** @@ -202,7 +207,8 @@ * @access public * @see endPrint(), end() */ - function endGet() { + function endGet() + { $content = ob_get_contents(); ob_end_clean();
http://cvs.php.net/diff.php/pear/Cache/Container/db.php?r1=1.6&r2=1.7&ty=u Index: pear/Cache/Container/db.php diff -u pear/Cache/Container/db.php:1.6 pear/Cache/Container/db.php:1.7 --- pear/Cache/Container/db.php:1.6 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container/db.php Wed Dec 15 04:09:29 2004 @@ -17,7 +17,7 @@ // | Chuck Hagenbuch <chuck@horde.org> | // +----------------------------------------------------------------------+ // -// $Id: db.php,v 1.6 2004/12/14 04:48:27 dufuz Exp $ +// $Id: db.php,v 1.7 2004/12/15 09:09:29 dufuz Exp $ require_once 'DB.php'; require_once 'Cache/Container.php'; @@ -52,10 +52,11 @@ * ) * * @author Sebastian Bergmann <sb@sebastian-bergmann.de> -* @version $Id: db.php,v 1.6 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: db.php,v 1.7 2004/12/15 09:09:29 dufuz Exp $ * @package Cache */ -class Cache_Container_db extends Cache_Container { +class Cache_Container_db extends Cache_Container +{ /** * Name of the DB table to store caching data @@ -86,15 +87,14 @@ $this->setOptions($options, array_merge($this->allowed_options, array('dsn', 'cache_table'))); - if (!$this->dsn) + if (!$this->dsn) { return new Cache_Error('No dsn specified!', __FILE__, __LINE__); - + } $this->db = DB::connect($this->dsn, true); - if (DB::isError($this->db)) { + if (PEAR::isError($this->db)) { return new Cache_Error('DB::connect failed: ' . DB::errorMessage($this->db), __FILE__, __LINE__); - } else { - $this->db->setFetchMode(DB_FETCHMODE_ASSOC); } + $this->db->setFetchMode(DB_FETCHMODE_ASSOC); } function fetch($id, $group) @@ -107,15 +107,15 @@ $res = $this->db->query($query); - if (DB::isError($res)) + if (PEAR::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); - + } $row = $res->fetchRow(); - if (is_array($row)) + if (is_array($row)) { $data = array($row['expires'], $this->decode($row['cachedata']), $row['userdata']); - else + } else { $data = array(null, null, null); - + } // last used required by the garbage collection // WARNING: might be MySQL specific $query = sprintf("UPDATE %s SET changed = (NOW() + 0) WHERE id = '%s' AND cachegroup = '%s'", @@ -126,9 +126,9 @@ $res = $this->db->query($query); - if (DB::isError($res)) + if (PEAR::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); - + } return $data; } @@ -154,7 +154,7 @@ $res = $this->db->query($query); - if (DB::isError($res)) { + if (PEAR::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res) , __FILE__, __LINE__); } } @@ -171,8 +171,9 @@ $res = $this->db->query($query); - if (DB::isError($res)) + if (PEAR::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); + } } function flush($group = '') @@ -187,7 +188,7 @@ $res = $this->db->query($query); - if (DB::isError($res)) + if (PEAR::isError($res)) return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); } @@ -201,16 +202,15 @@ $res = $this->db->query($query); - if (DB::isError($res)) + if (PEAR::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); - + } $row = $res->fetchRow(); if (is_array($row)) { return true; - } else { - return false; } + return false; } function garbageCollection($maxlifetime) @@ -229,19 +229,18 @@ $this->cache_table ); $cachesize = $this->db->GetOne($query); - if (DB::isError($cachesize)) { + if (PEAR::isError($cachesize)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($cachesize), __FILE__, __LINE__); } //if cache is to big. - if ($cachesize > $this->highwater) - { + if ($cachesize > $this->highwater) { //find the lowwater mark. $query = sprintf('select length(cachedata) as size, changed from %s order by changed DESC', $this->cache_table ); $res = $this->db->query($query); - if (DB::isError($res)) { + if (PEAR::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); } @@ -259,7 +258,7 @@ $res = $this->db->query($query); } - if (DB::isError($res)) { + if (PEAR::isError($res)) { return new Cache_Error('DB::query failed: ' . DB::errorMessage($res), __FILE__, __LINE__); } } http://cvs.php.net/diff.php/pear/Cache/Container/dbx.php?r1=1.5&r2=1.6&ty=u Index: pear/Cache/Container/dbx.php diff -u pear/Cache/Container/dbx.php:1.5 pear/Cache/Container/dbx.php:1.6 --- pear/Cache/Container/dbx.php:1.5 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container/dbx.php Wed Dec 15 04:09:29 2004 @@ -15,7 +15,7 @@ // | Authors: Christian Stocker <chregu@phant.ch> | // +----------------------------------------------------------------------+ // -// $Id: dbx.php,v 1.5 2004/12/14 04:48:27 dufuz Exp $ +// $Id: dbx.php,v 1.6 2004/12/15 09:09:29 dufuz Exp $ require_once 'Cache/Container.php'; @@ -50,10 +50,11 @@ * ) * * @author Christian Stocker <chregu@phant.ch> -* @version $Id: dbx.php,v 1.5 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: dbx.php,v 1.6 2004/12/15 09:09:29 dufuz Exp $ * @package Cache */ -class Cache_Container_dbx extends Cache_Container { +class Cache_Container_dbx extends Cache_Container +{ /** * Name of the DB table to store caching data @@ -145,16 +146,16 @@ ); $res = dbx_query($this->db, $query); - if (dbx_error($this->db)) + if (dbx_error($this->db)) { return new Cache_Error('DBx query failed: ' . dbx_error($this->db), __FILE__, __LINE__); - + } $row = $res->data[0]; - if (is_array($row)) + if (is_array($row)) { $data = array($row['expires'], $this->decode($row['cachedata']), $row['userdata']); - else + } else { $data = array(null, null, null); - + } // last used required by the garbage collection // WARNING: might be MySQL specific $query = sprintf("UPDATE %s SET changed = (NOW() + 0) WHERE id = '%s' AND cachegroup = '%s'", @@ -164,9 +165,9 @@ ); $res = dbx_query($this->db, $query); - if (dbx_error($this->db)) + if (dbx_error($this->db)) { return new Cache_Error('DBx query failed: ' . dbx_error($this->db), __FILE__, __LINE__); - + } return $data; } @@ -209,8 +210,9 @@ $res = dbx_query($this->db, $query); - if (dbx_error($this->db)) + if (dbx_error($this->db)) { return new Cache_Error('DBx query failed: ' . dbx_error($this->db), __FILE__, __LINE__); + } } function flush($group = '') @@ -225,8 +227,9 @@ $res = dbx_query($this->db,$query); - if (dbx_error($this->db)) + if (dbx_error($this->db)) { return new Cache_Error('DBx query failed: ' . dbx_error($this->db), __FILE__, __LINE__); + } } function idExists($id, $group) @@ -239,17 +242,16 @@ $res = dbx_query($this->db, $query); - if (dbx_error($this->db)) + if (dbx_error($this->db)) { return new Cache_Error('DBx query failed: ' . dbx_error($this->db), __FILE__, __LINE__); - + } $row = $res[0]; if (is_array($row)) { return true; - } else { - return false; } + return false; } function garbageCollection($maxlifetime) @@ -265,31 +267,28 @@ $res = dbx_query($this->db, $query); - if (dbx_error($this->db)) + if (dbx_error($this->db)) { return new Cache_Error('DBx query failed: ' . dbx_error($this->db), __FILE__, __LINE__); - + } $query = sprintf('select sum(length(cachedata)) as CacheSize from %s', $this->cache_table ); $res = dbx_query($this->db, $query); //if cache is to big. - if ($res->data[0][CacheSize] > $this->highwater) - { + if ($res->data[0][CacheSize] > $this->highwater) { //find the lowwater mark. $query = sprintf('select length(cachedata) as size, changed from %s order by changed DESC', $this->cache_table ); $res = dbx_query($this->db, $query); - $keep_size=0; - $i=0; - while ($keep_size < $this->lowwater && $i < $res->rows ) - { - + $keep_size = 0; + $i = 0; + while ($keep_size < $this->lowwater && $i < $res->rows ) { $keep_size += $res->data[$i][size]; $i++; - } + } //delete all entries, which were changed before the "lowwwater mark" $query = sprintf('delete from %s where changed <= %s', http://cvs.php.net/diff.php/pear/Cache/Container/file.php?r1=1.15&r2=1.16&ty=u Index: pear/Cache/Container/file.php diff -u pear/Cache/Container/file.php:1.15 pear/Cache/Container/file.php:1.16 --- pear/Cache/Container/file.php:1.15 Tue Dec 14 04:15:02 2004 +++ pear/Cache/Container/file.php Wed Dec 15 04:09:29 2004 @@ -16,7 +16,7 @@ // | Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // -// $Id: file.php,v 1.15 2004/12/14 09:15:02 dufuz Exp $ +// $Id: file.php,v 1.16 2004/12/15 09:09:29 dufuz Exp $ require_once 'Cache/Container.php'; @@ -24,9 +24,10 @@ * Stores cache contents in a file. * * @author Ulf Wendel <ulf.wendel@phpdoc.de> -* @version $Id: file.php,v 1.15 2004/12/14 09:15:02 dufuz Exp $ +* @version $Id: file.php,v 1.16 2004/12/15 09:09:29 dufuz Exp $ */ -class Cache_Container_file extends Cache_Container { +class Cache_Container_file extends Cache_Container +{ /** * File locking @@ -134,13 +135,13 @@ return array(null, null, null); } // retrive the content - if (!($fh = @fopen($file, 'rb'))) + if (!($fh = @fopen($file, 'rb'))) { return new Cache_Error("Can't access cache file '$file'. Check access rights and path.", __FILE__, __LINE__); - + } // File locking (shared lock) - if ($this->fileLocking) + if ($this->fileLocking) { flock($fh, LOCK_SH); - + } // file format: // 1st line: expiration date // 2nd line: user data @@ -183,9 +184,9 @@ } // File locking (exclusive lock) - if ($this->fileLocking) + if ($this->fileLocking) { flock($fh, LOCK_EX); - + } // file format: // 1st line: expiration date // 2nd line: user data @@ -324,8 +325,9 @@ $this->total_size += filesize($file); // remove if expired - if (( ($expire && $expire <= time()) || ($lastused <= (time() - $maxlifetime)) ) && !unlink($file)) + if (( ($expire && $expire <= time()) || ($lastused <= (time() - $maxlifetime)) ) && !unlink($file)) { new Cache_Error("Can't unlink cache file '$file', skipping. Check permissions and path.", __FILE__, __LINE__); + } } closedir($dh); http://cvs.php.net/diff.php/pear/Cache/Container/mdb.php?r1=1.4&r2=1.5&ty=u Index: pear/Cache/Container/mdb.php diff -u pear/Cache/Container/mdb.php:1.4 pear/Cache/Container/mdb.php:1.5 --- pear/Cache/Container/mdb.php:1.4 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container/mdb.php Wed Dec 15 04:09:30 2004 @@ -18,7 +18,7 @@ // | Author: Lorenzo Alberton <l.alberton at quipo.it> | // +----------------------------------------------------------------------+ // -// $Id: mdb.php,v 1.4 2004/12/14 04:48:27 dufuz Exp $ +// $Id: mdb.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $ require_once 'MDB.php'; require_once 'Cache/Container.php'; @@ -61,10 +61,11 @@ * ------------------------------------------ * * @author Lorenzo Alberton <l.alberton at quipo.it> -* @version $Id: mdb.php,v 1.4 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: mdb.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $ * @package Cache */ -class Cache_Container_mdb extends Cache_Container { +class Cache_Container_mdb extends Cache_Container +{ /** * Name of the MDB table to store caching data @@ -88,7 +89,7 @@ function Cache_Container_mdb($options) { $this->db = &MDB::Connect($options); - if(MDB::isError($this->db)) { + if (MDB::isError($this->db)) { return new Cache_Error('MDB::connect failed: ' . $this->db->getMessage(), __FILE__, __LINE__); } else { @@ -111,16 +112,16 @@ $query = 'SELECT cachedata FROM ' . $this->cache_table .' WHERE id=' . $this->db->getTextValue($id) .' AND cachegroup=' . $this->db->getTextValue($group); - if($res = $this->db->query($query)) { - if($this->db->endOfResult($res)) { + if ($res = $this->db->query($query)) { + if ($this->db->endOfResult($res)) { //no rows returned $data = array(null, null, null); } else { $clob = $this->db->fetchClob($res,0,'cachedata'); - if(!MDB::isError($clob)) { + if (!MDB::isError($clob)) { $cached_data = ''; while(!$this->db->endOfLOB($clob)) { - if(MDB::isError($error = + if (MDB::isError($error = $this->db->readLob($clob,$data,8000)<0)) { return new Cache_Error('MDB::query failed: ' . $error->getMessage(), __FILE__, __LINE__); @@ -135,7 +136,7 @@ $query = 'SELECT userdata, expires FROM ' . $this->cache_table .' WHERE id=' . $this->db->getTextValue($id) .' AND cachegroup=' . $this->db->getTextValue($group); - if($res = $this->db->query($query)) { + if ($res = $this->db->query($query)) { $row = $this->db->fetchInto($res); if (is_array($row)) { $data = array( @@ -216,7 +217,7 @@ $result = $this->db->replace($this->cache_table, $fields); - if(MDB::isError($result)) { + if (MDB::isError($result)) { //Var_Dump::display($result); return new Cache_Error('MDB::query failed: ' . $this->db->errorMessage($result), __FILE__, __LINE__); @@ -226,13 +227,13 @@ .' SET cachedata=?' .' WHERE id='. $this->db->getTextValue($id); - if(($prepared_query = $this->db->prepareQuery($query2))) { + if (($prepared_query = $this->db->prepareQuery($query2))) { $char_lob = array( 'Error' => '', 'Type' => 'data', 'Data' => $this->encode($data) ); - if(!MDB::isError($clob = $this->db->createLob($char_lob))) { + if (!MDB::isError($clob = $this->db->createLob($char_lob))) { $this->db->setParamClob($prepared_query,1,$clob,'cachedata'); if(MDB::isError($error=$this->db->executeQuery($prepared_query))) { return new Cache_Error('MDB::query failed: ' @@ -319,9 +320,8 @@ if (is_array($row)) { return true; - } else { - return false; } + return false; } /** @@ -347,8 +347,7 @@ . $this->db->errorMessage($cachesize), __FILE__, __LINE__); } //if cache is to big. - if ($cachesize > $this->highwater) - { + if ($cachesize > $this->highwater) { //find the lowwater mark. $query = 'SELECT length(cachedata) as size, changed FROM ' . $this->cache_table .' ORDER BY changed DESC'; http://cvs.php.net/diff.php/pear/Cache/Container/msession.php?r1=1.6&r2=1.7&ty=u Index: pear/Cache/Container/msession.php diff -u pear/Cache/Container/msession.php:1.6 pear/Cache/Container/msession.php:1.7 --- pear/Cache/Container/msession.php:1.6 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container/msession.php Wed Dec 15 04:09:30 2004 @@ -15,7 +15,7 @@ // | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> | // +----------------------------------------------------------------------+ // -// $Id: msession.php,v 1.6 2004/12/14 04:48:27 dufuz Exp $ +// $Id: msession.php,v 1.7 2004/12/15 09:09:30 dufuz Exp $ require_once 'Cache/Container.php'; @@ -25,11 +25,10 @@ * WARNING: experimental, untested * * @author Ulf Wendel <ulf.wendel@phpdoc.de> -* @version $Id: msession.php,v 1.6 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: msession.php,v 1.7 2004/12/15 09:09:30 dufuz Exp $ */ -class Cache_Container_msession extends Cache_Container { - - +class Cache_Container_msession extends Cache_Container +{ /** * Length of the Cache-Identifier * @@ -82,30 +81,33 @@ var $ms = null; - function Cache_Container_msession($options = '') { - if (is_array($options)) + function Cache_Container_msession($options = '') + { + if (is_array($options)) { $this->setOptions($options, array_merge($this->allowed_options, array('id_length', 'uniq', 'host', 'port', 'connect'))); - + } if ($connect) { - if (null == $this->host) + if (null == $this->host) { new Cache_Error('No host specified.', __FILE__, __LINE__); - if (null == $this->port) + } + if (null == $this->port) { new Cache_Error('No port specified.', __FILE__, __LINE__); - - if (!($this->ms = msession_connect($this->host, $this->port))) + } + if (!($this->ms = msession_connect($this->host, $this->port))) { new Cache_Error('Can not connect to the sever using host "' . $this->host . '" on port "' . $this->port . '"', __FILE__, __LINE__); + } } } // end func contructor - function fetch($id, $group) { - + function fetch($id, $group) + { $id = strtoupper(md5($group)) . $id; $group = msession_get($id, '_pear_cache_data', null); - if (null == $data) + if (null == $data) { return array(null, null, null); - + } return array($data['expires'], $data['cachedata'], $data['userdata']); } // end func fetch @@ -115,7 +117,8 @@ * WARNING: If you supply userdata it must not contain any linebreaks, * otherwise it will break the filestructure. */ - function save($id, $cachedata, $expires, $group, $userdata) { + function save($id, $cachedata, $expires, $group, $userdata) + { $this->flushPreload($id, $group); $cachedata = $this->encode($cachedata); @@ -157,21 +160,22 @@ // note that msession works different from the PEAR Cache. // msession deletes an entry if it has not been used for n-seconds. // PEAR Cache deletes after n-seconds. - if (0 != $expires) + if (0 != $expires) { msession_timeout($id, $expires); - + } msession_unlock($id); return true; } // end func save - function remove($id, $group) { + function remove($id, $group) + { $this->flushPreload($id, $group); - return msession_destroy(strtoupper(md5($group)) . $id); } // end func remove - function flush($group) { + function flush($group) + { $this->flushPreload(); $sessions = msession_find('_pear_cache_group', $group); @@ -184,8 +188,8 @@ return count($sessions); } // end func flush - function idExists($id, $group) { - + function idExists($id, $group) + { return (null == msession_get(strtoupper(md5($group)) . $id, '_pear_cache_group', null)) ? false : true; } // end func idExists @@ -197,7 +201,8 @@ * @param integer Maximum lifetime in seconds of an no longer used/touched entry * @throws Cache_Error */ - function garbageCollection($maxlifetime) { + function garbageCollection($maxlifetime) + { $this->flushPreload(); $sessions = msession_find('_pear_cache', true); @@ -209,9 +214,10 @@ foreach ($sessions as $k => $id) { $data = msession_get($id, '_pear_cache_data', null); - if (null == $data) + if (null == $data) { continue; - + } + if ($data['expires'] <= time()) { msession_destroy($id); continue; http://cvs.php.net/diff.php/pear/Cache/Container/phplib.php?r1=1.4&r2=1.5&ty=u Index: pear/Cache/Container/phplib.php diff -u pear/Cache/Container/phplib.php:1.4 pear/Cache/Container/phplib.php:1.5 --- pear/Cache/Container/phplib.php:1.4 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container/phplib.php Wed Dec 15 04:09:30 2004 @@ -16,7 +16,7 @@ // | Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // -// $Id: phplib.php,v 1.4 2004/12/14 04:48:27 dufuz Exp $ +// $Id: phplib.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $ require_once 'Cache/Container.php'; @@ -50,12 +50,12 @@ * * * @author Ulf Wendel <ulf.wendel@phpdoc.de>, Sebastian Bergmann <sb@sebastian-bergmann.de> -* @version $Id: phplib.php,v 1.4 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: phplib.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $ * @package Cache * @see save() */ -class Cache_Container_phplib extends Cache_Container { - +class Cache_Container_phplib extends Cache_Container +{ /** * Name of the DB table to store caching data * @@ -116,34 +116,36 @@ * see $local_path for some hints.s * @see $local_path */ - function Cache_Container_phplib($options = '') { - if (is_array($options)) + function Cache_Container_phplib($options = '') + { + if (is_array($options)) { $this->setOptions($options, array_merge($this->allowed_options, array('db_class', 'db_file', 'db_path', 'local_file', 'local_path'))); - - if (!$this->db_class) + } + if (!$this->db_class) { return new Cache_Error('No database class specified.', __FILE__, __LINE__); - + } // include the required files - if ($this->db_file) - include_once($this->db_path . $this->db_file); - - if ($this->local_file) - include_once($this->local_path . $this->local_file); - + if ($this->db_file) { + include_once $this->db_path . $this->db_file; + } + if ($this->local_file) { + include_once $this->local_path . $this->local_file; + } // create a db object $this->db = new $this->db_class; } // end constructor - function fetch($id, $group) { + function fetch($id, $group) + { $query = sprintf("SELECT expires, cachedata, userdata FROM %s WHERE id = '%s' AND cachegroup = '%s'", $this->cache_table, $id, $group ); $this->db->query($query); - if (!$this->db->Next_Record()) + if (!$this->db->Next_Record()) { return array(null, null, null); - + } // last used required by the garbage collection // WARNING: might be MySQL specific $query = sprintf("UPDATE %s SET changed = (NOW() + 0) WHERE id = '%s' AND cachegroup = '%s'", @@ -162,7 +164,8 @@ * MySQL specific. As MySQL is very popular the method should * work fine for 95% of you. */ - function save($id, $data, $expires, $group) { + function save($id, $data, $expires, $group) + { $this->flushPreload($id, $group); $query = sprintf("REPLACE INTO %s (cachedata, expires, id, cachegroup) VALUES ('%s', %d, '%s', '%s')", @@ -177,7 +180,8 @@ return (boolean)$this->db->affected_rows(); } // end func save - function remove($id, $group) { + function remove($id, $group) + { $this->flushPreload($id, $group); $this->db->query( sprintf("DELETE FROM %s WHERE id = '%s' AND cachegroup = '%s'", @@ -190,7 +194,8 @@ return (boolean)$this->db->affected_rows(); } // end func remove - function flush($group) { + function flush($group) + { $this->flushPreload(); if ($group) { @@ -202,7 +207,8 @@ return $this->db->affected_rows(); } // end func flush - function idExists($id, $group) { + function idExists($id, $group) + { $this->db->query( sprintf("SELECT id FROM %s WHERE ID = '%s' AND cachegroup = '%s'", $this->cache_table, @@ -214,7 +220,8 @@ return (boolean)$this->db->nf(); } // end func isExists - function garbageCollection($maxlifetime) { + function garbageCollection($maxlifetime) + { $this->flushPreload(); $this->db->query( @@ -234,8 +241,7 @@ $this->db->Next_Record(); $cachesize = $this->db->f('CacheSize'); //if cache is to big. - if ($cachesize > $this->highwater) - { + if ($cachesize > $this->highwater) { //find the lowwater mark. $query = sprintf('select length(cachedata) as size, changed from %s order by changed DESC', $this->cache_table @@ -243,8 +249,7 @@ $this->db->query($query); $keep_size=0; - while ($keep_size < $this->lowwater && $this->db->Next_Record() ) - { + while ($keep_size < $this->lowwater && $this->db->Next_Record()) { $keep_size += $this->db->f('size'); } //delete all entries, which were changed before the "lowwwater mark" http://cvs.php.net/diff.php/pear/Cache/Container/shm.php?r1=1.4&r2=1.5&ty=u Index: pear/Cache/Container/shm.php diff -u pear/Cache/Container/shm.php:1.4 pear/Cache/Container/shm.php:1.5 --- pear/Cache/Container/shm.php:1.4 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container/shm.php Wed Dec 15 04:09:30 2004 @@ -16,7 +16,7 @@ // | Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // -// $Id: shm.php,v 1.4 2004/12/14 04:48:27 dufuz Exp $ +// $Id: shm.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $ require_once 'Cache/Container.php'; @@ -29,10 +29,11 @@ * caching algorithm using PHP. * * @author Ulf Wendel <ulf.wendel@phpdoc.de> -* @version $Id: shm.php,v 1.4 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: shm.php,v 1.5 2004/12/15 09:09:30 dufuz Exp $ * @package Cache */ -class Cache_Container_shm extends Cache_Container { +class Cache_Container_shm extends Cache_Container +{ /** * Key of the semaphore used to sync the SHM access * @@ -105,8 +106,9 @@ * * @param array shm_key, sem_key, shm_size, sem_perm, shm_perm */ - function Cache_Container_shm($options = '') { - if (is_array($options)) + function Cache_Container_shm($options = '') + { + if (is_array($options)) { $this->setOptions($options, array_merge($this->allowed_options, array('shm_key', 'sem_key', 'shm_size', 'sem_perm', @@ -114,33 +116,35 @@ ) ) ); - + } // Cache::Container high- and lowwater defaults should be overridden if // not already done by the user - if (!isset($options['highwater'])) + if (!isset($options['highwater'])) { $this->highwater = round(0.75 * 131072); - if (!isset($options['lowwater'])) + } + if (!isset($options['lowwater'])) { $this->lowwater = round(0.5 * 131072); - - if (!isset($options['shm_size'])) + } + if (!isset($options['shm_size'])) { $this->shm_size = 131072; - + } //get SHM and Semaphore handles - if (!($this->shm_id = shmop_open($this->shm_key, 'c', $this->shm_perm, $this->shm_size))) + if (!($this->shm_id = shmop_open($this->shm_key, 'c', $this->shm_perm, $this->shm_size))) { new Cache_Error("Can't open SHM segment '{$this->shm_key}', size '{$this->shm_size}'.", __FILE__, __LINE__ ); - - if (!($this->sem_id = sem_get($this->sem_key, 1, $this->sem_perm))) + } + if (!($this->sem_id = sem_get($this->sem_key, 1, $this->sem_perm))) { new Cache_Error("Can't get semaphore '{$this->sem_key}' using perms '{$this->sem_perm}'.", __FILE__, __LINE__ ); - + } } // end constructor - function fetch($id, $group) { + function fetch($id, $group) + { sem_acquire($this->sem_id); $cachedata = shmop_read($this->shm_id, 0, $this->shm_size); @@ -149,18 +153,19 @@ $cachedata = $this->decode($cachedata); - if (!isset($cachedata[$group][$id])) + if (!isset($cachedata[$group][$id])) { return array(null, null, null); - else + } else { $cachedata = $cachedata[$group][$id]; - + } return array($cachedata['expire'], $cachedata['cachedata'], $cachedata['userdata'] ); } // end func fetch - function save($id, $data, $expire, $group, $userdata) { + function save($id, $data, $expire, $group, $userdata) + { $this->flushPreload($id, $group); sem_acquire($this->sem_id); @@ -172,9 +177,9 @@ 'changed' => time() ); - if (strlen($newdata = $this->encode($cachedata)) > $this->shm_size) + if (strlen($newdata = $this->encode($cachedata)) > $this->shm_size) { $cachedata = $this->garbageCollection(time(), $cachedata); - + } shmop_write($this->shm_id, $newdata, 0); sem_release($this->sem_id); @@ -182,7 +187,8 @@ return true; } // end func save - function remove($id, $group) { + function remove($id, $group) + { $this->flushPreload($id, $group); sem_acquire($this->sem_id); @@ -194,7 +200,8 @@ sem_release($this->sem_id); } // end func remove - function flush($group = '') { + function flush($group = '') + { $this->flushPreload(); sem_acquire($this->sem_id); @@ -204,7 +211,8 @@ sem_release($this->sem_id); } // end func flush - function idExists($id, $group) { + function idExists($id, $group) + { sem_acquire($this->sem_id); $cachedata = shm_read($this->shm_id, 0, $this->shm_size); @@ -216,7 +224,8 @@ return isset($cachedata[$group][$id]); } // end func isExists - function garbageCollection($maxlifetime, $cachedata = array()) { + function garbageCollection($maxlifetime, $cachedata = array()) + { if ($lock = empty($cachedata)) { sem_acquire($this->sem_id); $cachedata = $this->decode(shmop_read($this->shm_id, 0, $this->shm_size)); @@ -237,16 +246,17 @@ } } - if ($lock) + if ($lock) { sem_release($this->sem_id); - + } $this->entries = array(); $this->total_size = 0; return $cachedata; } // end func garbageCollection - function doGarbageCollection($maxlifetime, &$cachedata) { + function doGarbageCollection($maxlifetime, &$cachedata) + { $changed = time() - $maxlifetime; $removed = 0; http://cvs.php.net/diff.php/pear/Cache/Container/trifile.php?r1=1.3&r2=1.4&ty=u Index: pear/Cache/Container/trifile.php diff -u pear/Cache/Container/trifile.php:1.3 pear/Cache/Container/trifile.php:1.4 --- pear/Cache/Container/trifile.php:1.3 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container/trifile.php Wed Dec 15 04:09:30 2004 @@ -17,7 +17,7 @@ // | Ian Eure <ieure@php.net> | // +----------------------------------------------------------------------+ // -// $Id: trifile.php,v 1.3 2004/12/14 04:48:27 dufuz Exp $ +// $Id: trifile.php,v 1.4 2004/12/15 09:09:30 dufuz Exp $ require_once 'Cache/Container/file.php'; @@ -33,7 +33,8 @@ * @author Ian Eure <ieure@php.net> * @version 1.0 */ -class Cache_Container_trifile extends Cache_Container_file { +class Cache_Container_trifile extends Cache_Container_file +{ /** * Fetch cached file. * @@ -44,9 +45,13 @@ function fetch($id, $group) { $file = $this->getFilename($id, $group); - if (!file_exists($file)) + if (PEAR::isError($file)) { + return $file; + } + + if (!file_exists($file)) { return array(null, null, null); - + } return array( file_get_contents($this->_getExpFile($file)), file_get_contents($file), @@ -104,13 +109,17 @@ $this->flushPreload($id, $group); $file = $this->getFilename($id, $group); + if (PEAR::isError($file)) { + return $file; + } + if (PEAR::isError($res = $this->_saveData($file, $cachedata))) { return $res; } if (PEAR::isError($res = $this->_saveData($this->_getExpFile($file), $expires))) { return $res; } - if(PEAR::isError($res = $this->_saveData($this->_getUDFile($file), $userdata))) { + if (PEAR::isError($res = $this->_saveData($this->_getUDFile($file), $userdata))) { return $res; } @@ -124,7 +133,8 @@ * @param string $data Data to save * @return mixed true on success, Cache_Error otherwise */ - function _saveData($file, $data) { + function _saveData($file, $data) + { // Save data if (!($fh = @fopen($file, 'wb'))) return new Cache_Error("Can't access '$file' to store cache data. Check access rights and path.", __FILE__, __LINE__); @@ -135,7 +145,7 @@ fwrite($fh, $data); - if($this->fileLocking) { + if ($this->fileLocking) { flock($fh, LOCK_UN); } http://cvs.php.net/diff.php/pear/Cache/Application.php?r1=1.6&r2=1.7&ty=u Index: pear/Cache/Application.php diff -u pear/Cache/Application.php:1.6 pear/Cache/Application.php:1.7 --- pear/Cache/Application.php:1.6 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Application.php Wed Dec 15 04:09:33 2004 @@ -16,7 +16,7 @@ // | Authors: Richard Heyes <richard@phpguru.org> | // +----------------------------------------------------------------------+ // -// $Id: Application.php,v 1.6 2004/12/14 04:48:27 dufuz Exp $ +// $Id: Application.php,v 1.7 2004/12/15 09:09:33 dufuz Exp $ require_once 'Cache.php'; @@ -70,7 +70,8 @@ // (In fact if you use the register() function with register_globals Off, you have to // use the $_APP method to get at the data). -class Cache_Application extends Cache { +class Cache_Application extends Cache +{ var $data; var $id; http://cvs.php.net/diff.php/pear/Cache/Cache.php?r1=1.6&r2=1.7&ty=u Index: pear/Cache/Cache.php diff -u pear/Cache/Cache.php:1.6 pear/Cache/Cache.php:1.7 --- pear/Cache/Cache.php:1.6 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Cache.php Wed Dec 15 04:09:33 2004 @@ -16,7 +16,7 @@ // | Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // -// $Id: Cache.php,v 1.6 2004/12/14 04:48:27 dufuz Exp $ +// $Id: Cache.php,v 1.7 2004/12/15 09:09:33 dufuz Exp $ require_once 'PEAR.php'; require_once 'Cache/Error.php'; @@ -59,11 +59,12 @@ * bad circumstances (especially with the file container) * * @author Ulf Wendel <ulf.wendel@phpdoc.de> -* @version $Id: Cache.php,v 1.6 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: Cache.php,v 1.7 2004/12/15 09:09:33 dufuz Exp $ * @package Cache * @access public */ -class Cache extends PEAR { +class Cache extends PEAR +{ /** * Enables / disables caching. @@ -172,13 +173,15 @@ * @return mixed cached data or null on failure * @access public */ - function get($id, $group = 'default') { - if (!$this->caching) + function get($id, $group = 'default') + { + if (!$this->caching) { return ''; + } - if ($this->isCached($id, $group) && !$this->isExpired($id, $group)) + if ($this->isCached($id, $group) && !$this->isExpired($id, $group)) { return $this->load($id, $group); - + } return null; } // end func get @@ -192,10 +195,11 @@ * @return boolean * @access public */ - function save($id, $data, $expires = 0, $group = 'default') { - if (!$this->caching) + function save($id, $data, $expires = 0, $group = 'default') + { + if (!$this->caching) { return true; - + } return $this->extSave($id, $data, '',$expires, $group); } // end func save @@ -212,10 +216,11 @@ * @access public * @see getUserdata() */ - function extSave($id, $cachedata, $userdata, $expires = 0, $group = 'default') { - if (!$this->caching) + function extSave($id, $cachedata, $userdata, $expires = 0, $group = 'default') + { + if (!$this->caching) { return true; - + } return $this->container->save($id, $cachedata, $expires, $group, $userdata); } // end func extSave @@ -227,10 +232,11 @@ * @return mixed cached data or null on failure * @access public */ - function load($id, $group = 'default') { - if (!$this->caching) + function load($id, $group = 'default') + { + if (!$this->caching) { return ''; - + } return $this->container->load($id, $group); } // end func load @@ -243,10 +249,11 @@ * @access public * @see extSave() */ - function getUserdata($id, $group = 'default') { - if (!$this->caching) + function getUserdata($id, $group = 'default') + { + if (!$this->caching) { return ''; - + } return $this->container->getUserdata($id, $group); } // end func getUserdata @@ -258,10 +265,11 @@ * @return boolean * @access public */ - function remove($id, $group = 'default') { - if (!$this->caching) + function remove($id, $group = 'default') + { + if (!$this->caching) { return true; - + } return $this->container->remove($id, $group); } // end func remove @@ -271,10 +279,11 @@ * @param string cache group, if empty all groups will be flashed * @return integer number of removed datasets */ - function flush($group = 'default') { - if (!$this->caching) + function flush($group = 'default') + { + if (!$this->caching) { return true; - + } return $this->container->flush($group); } // end func flush @@ -288,10 +297,11 @@ * @return boolean * @access public */ - function isCached($id, $group = 'default') { - if (!$this->caching) + function isCached($id, $group = 'default') + { + if (!$this->caching) { return false; - + } return $this->container->isCached($id, $group); } // end func isCached @@ -309,10 +319,11 @@ * @return boolean * @access public */ - function isExpired($id, $group = 'default', $max_age = 0) { - if (!$this->caching) + function isExpired($id, $group = 'default', $max_age = 0) + { + if (!$this->caching) { return true; - + } return $this->container->isExpired($id, $group, $max_age); } // end func isExpired @@ -326,7 +337,8 @@ * @return string "unique" ID * @access public */ - function generateID($variable) { + function generateID($variable) + { // WARNING: ID clashes are possible although unlikely return md5(serialize($variable)); } @@ -337,12 +349,13 @@ * @param boolean Force a garbage collection run? * @see $gc_probability, $gc_time */ - function garbageCollection($force = false) { + function garbageCollection($force = false) + { static $last_run = 0; - if (!$this->caching) + if (!$this->caching) { return; - + } srand((double) microtime() * 1000000); // time and probability based http://cvs.php.net/diff.php/pear/Cache/Container.php?r1=1.5&r2=1.6&ty=u Index: pear/Cache/Container.php diff -u pear/Cache/Container.php:1.5 pear/Cache/Container.php:1.6 --- pear/Cache/Container.php:1.5 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Container.php Wed Dec 15 04:09:33 2004 @@ -17,7 +17,7 @@ // | Christian Stocker <chregu@phant.ch> | // +----------------------------------------------------------------------+ // -// $Id: Container.php,v 1.5 2004/12/14 04:48:27 dufuz Exp $ +// $Id: Container.php,v 1.6 2004/12/15 09:09:33 dufuz Exp $ require_once 'Cache/Error.php'; @@ -39,12 +39,13 @@ * not recommended! * * @author Ulf Wendel <ulf.wendel@phpdoc.de> -* @version $Id: Container.php,v 1.5 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: Container.php,v 1.6 2004/12/15 09:09:33 dufuz Exp $ * @package Cache * @access public * @abstract */ -class Cache_Container { +class Cache_Container +{ /** * Flag indicating wheter to preload datasets. @@ -143,11 +144,12 @@ * @return mixed dataset value or null on failure * @access public */ - function load($id, $group) { + function load($id, $group) + { if ($this->preload) { - if ($this->id != $id || $this->group != $group) + if ($this->id != $id || $this->group != $group) { $this->preload($id, $group); - + } return $this->cachedata; } else { list( , $data, ) = $this->fetch($id, $group); @@ -163,11 +165,12 @@ * @return string userdata * @access public */ - function getUserdata($id, $group) { + function getUserdata($id, $group) + { if ($this->preload) { - if ($this->id != $id || $this->group != $group) + if ($this->id != $id || $this->group != $group) { $this->preload($id, $group); - + } return $this->userdata; } else { list( , , $userdata) = $this->fetch($id, $group); @@ -184,26 +187,28 @@ * @return boolean * @access public */ - function isExpired($id, $group, $max_age) { + function isExpired($id, $group, $max_age) + { if ($this->preload) { - if ($this->id != $id || $this->group != $group) - $this->preload($id, $group); - - if ($this->unknown) - return false; + if ($this->id != $id || $this->group != $group) { + $this->preload($id, $group); + } + if ($this->unknown) { + return false; + } } else { // check if at all it is cached - if (!$this->isCached($id, $group)) + if (!$this->isCached($id, $group)) { return false; - + } // I'm lazy... list($this->expires, , ) = $this->fetch($id, $group); } // endless - if (0 == $this->expires) + if (0 == $this->expires) { return false; - + } // you feel fine, Ulf? if ($expired = ($this->expires <= time() || ($max_age && ($this->expires <= $max_age))) ) { @@ -220,15 +225,15 @@ * @param string cache group * @return boolean */ - function isCached($id, $group) { + function isCached($id, $group) + { if ($this->preload) { - if ($this->id != $id || $this->group != $group) + if ($this->id != $id || $this->group != $group) { $this->preload($id, $group); - + } return !($this->unknown); - } else { - return $this->idExists($id, $group); } + return $this->idExists($id, $group); } // end func isCached // @@ -244,7 +249,8 @@ * @throws Cache_Error * @abstract */ - function fetch($id, $group) { + function fetch($id, $group) + { return array(null, null, null); } // end func fetch @@ -261,11 +267,11 @@ * @access public * @abstract */ - function save($id, $data, $expire, $group, $userdata) { + function save($id, $data, $expire, $group, $userdata) + { // QUESTION: Should we update the preload buffer instead? // Don't think so as the sequence save()/load() is unlikely. $this->flushPreload($id, $group); - return null; } // end func save @@ -278,7 +284,8 @@ * @access public * @abstract */ - function remove($id, $group) { + function remove($id, $group) + { $this->flushPreload($id, $group); return null; } // end func remove @@ -291,7 +298,8 @@ * @access public * @abstract */ - function flush($group) { + function flush($group) + { $this->flushPreload(); return null; } // end func flush @@ -305,7 +313,8 @@ * @access public * @abstract */ - function idExists($id, $group) { + function idExists($id, $group) + { return null; } // end func idExists @@ -315,7 +324,8 @@ * @access public * @abstract */ - function garbageCollection() { + function garbageCollection() + { $this->flushPreload(); } // end func garbageCollection @@ -326,7 +336,8 @@ * @param string cache group * @return boolean */ - function preload($id, $group) { + function preload($id, $group) + { // whatever happens, remember the preloaded ID $this->id = $id; $this->group = $group; @@ -336,7 +347,6 @@ if (null === $this->expires) { // Uuups, unknown ID $this->flushPreload(); - return false; } @@ -358,7 +368,8 @@ * @param string cache group * @see preload() */ - function flushPreload($id = '', $group = 'default') { + function flushPreload($id = '', $group = 'default') + { if (!$id || ($this->id == $id && $this->group == $group)) { // clear the internal preload values $this->id = ''; @@ -376,11 +387,13 @@ * @param array List of fields to be imported as object variables * @param array List of allowed datafields */ - function setOptions($requested, $allowed) { - foreach ($allowed as $k => $field) - if (isset($requested[$field])) + function setOptions($requested, $allowed) + { + foreach ($allowed as $k => $field) { + if (isset($requested[$field])) { $this->$field = $requested[$field]; - + } + } } // end func setOptions /** @@ -388,11 +401,13 @@ * * @var mixed data to encode */ - function encode($data) { - if ('base64' == $this->encoding_mode) + function encode($data) + { + if ('base64' == $this->encoding_mode) { return base64_encode(serialize($data)); - else + } else { return serialize($data); + } } // end func encode @@ -401,11 +416,13 @@ * * @var mixed */ - function decode($data) { - if ('base64' == $this->encoding_mode) + function decode($data) + { + if ('base64' == $this->encoding_mode) { return unserialize(base64_decode($data)); - else + } else { return unserialize($data); + } } // end func decode @@ -422,24 +439,20 @@ */ function getExpiresAbsolute($expires) { - if (!$expires) + if (!$expires) { return 0; + } //for api-compatibility, one has not to provide a "+", // if integer is < 946681200 (= Jan 01 2000 00:00:00) - if ('+' == $expires[0] || $expires < 946681200) - { + if ('+' == $expires[0] || $expires < 946681200) { return(time() + $expires); - } - //if integer is < 100000000000 (= in 3140 years), - // it must be an absolut unixtime - // (since the "human readable" definition asks for a higher number) - elseif ($expires < 100000000000) - { + } elseif ($expires < 100000000000) { + //if integer is < 100000000000 (= in 3140 years), + // it must be an absolut unixtime + // (since the "human readable" definition asks for a higher number) return $expires; - } - // else it's "human readable"; - else - { + } else { + // else it's "human readable"; $year = substr($expires, 0, 4); $month = substr($expires, 4, 2); $day = substr($expires, 6, 2); http://cvs.php.net/diff.php/pear/Cache/Error.php?r1=1.3&r2=1.4&ty=u Index: pear/Cache/Error.php diff -u pear/Cache/Error.php:1.3 pear/Cache/Error.php:1.4 --- pear/Cache/Error.php:1.3 Sat Jan 4 06:54:45 2003 +++ pear/Cache/Error.php Wed Dec 15 04:09:33 2004 @@ -15,7 +15,7 @@ // | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> | // +----------------------------------------------------------------------+ // -// $Id: Error.php,v 1.3 2003/01/04 11:54:45 mj Exp $ +// $Id: Error.php,v 1.4 2004/12/15 09:09:33 dufuz Exp $ require_once 'PEAR.php'; @@ -24,7 +24,8 @@ * * @package Cache */ -class Cache_Error extends PEAR_Error { +class Cache_Error extends PEAR_Error +{ /** http://cvs.php.net/diff.php/pear/Cache/Function.php?r1=1.7&r2=1.8&ty=u Index: pear/Cache/Function.php diff -u pear/Cache/Function.php:1.7 pear/Cache/Function.php:1.8 --- pear/Cache/Function.php:1.7 Mon Dec 13 23:48:27 2004 +++ pear/Cache/Function.php Wed Dec 15 04:09:33 2004 @@ -15,7 +15,7 @@ // | Authors: Sebastian Bergmann <sb@sebastian-bergmann.de> | // +----------------------------------------------------------------------+ // -// $Id: Function.php,v 1.7 2004/12/14 04:48:27 dufuz Exp $ +// $Id: Function.php,v 1.8 2004/12/15 09:09:33 dufuz Exp $ require_once 'Cache.php'; @@ -65,10 +65,11 @@ * @module Function_Cache * @modulegroup Function_Cache * @package Cache -* @version $Revision: 1.7 $ +* @version $Revision: 1.8 $ * @access public */ -class Cache_Function extends Cache { +class Cache_Function extends Cache +{ var $expires; /** @@ -93,7 +94,8 @@ * PEAR-Deconstructor * Call deconstructor of parent */ - function _Cache_Function() { + function _Cache_Function() + { $this->_Cache(); } @@ -103,7 +105,8 @@ * @return mixed $result * @access public */ - function call() { + function call() + { // get arguments $arguments = func_get_args(); @@ -130,18 +133,14 @@ list($class, $method) = explode('::', $target); $result = call_user_func_array(array($class, $method), $arguments); - } - - // object->method - elseif (strstr($target, '->')) { + } elseif (strstr($target, '->')) { + // object->method list($object, $method) = explode('->', $target); global $$object; $result = call_user_func_array(array($$object, $method), $arguments); - } - - // function - else { + } else { + // function $result = call_user_func_array($target, $arguments); } http://cvs.php.net/diff.php/pear/Cache/Graphics.php?r1=1.5&r2=1.6&ty=u Index: pear/Cache/Graphics.php diff -u pear/Cache/Graphics.php:1.5 pear/Cache/Graphics.php:1.6 --- pear/Cache/Graphics.php:1.5 Sat Jan 4 06:54:45 2003 +++ pear/Cache/Graphics.php Wed Dec 15 04:09:33 2004 @@ -15,7 +15,7 @@ // | Authors: Ulf Wendel <ulf.wendel@phpdoc.de> | // +----------------------------------------------------------------------+ // -// $Id: Graphics.php,v 1.5 2003/01/04 11:54:45 mj Exp $ +// $Id: Graphics.php,v 1.6 2004/12/15 09:09:33 dufuz Exp $ require_once 'Cache.php'; @@ -66,10 +66,11 @@ * the output buffer. Modify it if required! * * @author Ulf Wendel <ulf.wendel@phpdoc.de> -* @version $Id: Graphics.php,v 1.5 2003/01/04 11:54:45 mj Exp $ +* @version $Id: Graphics.php,v 1.6 2004/12/15 09:09:33 dufuz Exp $ * @package Cache */ -class Cache_Graphics extends Cache { +class Cache_Graphics extends Cache +{ /** @@ -135,8 +136,8 @@ * Instantiates a cache file container. * */ - function Cache_Graphics() { - + function Cache_Graphics() + { $this->Cache('file', array('cache_dir' => $this->cache_dir, 'filename_prefix' => $this->cache_file_prefix)); } // end constructor @@ -156,9 +157,9 @@ * @return string Image file contents if a cached file exists otherwise an empty string * @see cacheImage() */ - function getImage($id, $format = 'png') { + function getImage($id, $format = 'png') + { $id = $this->generateID($id, $format); - return $this->get($id, $this->cache_group); } // end func getImage @@ -175,11 +176,12 @@ * @throw Cache_Error * @see cacheImageLink() */ - function getImageLink($id, $format = 'png') { + function getImageLink($id, $format = 'png') + { $id = $this->generateID($id, $format); - if (!$this->container->idExists($id, $this->cache_group)) + if (!$this->container->idExists($id, $this->cache_group)) { return array(); - + } $file = $this->cache_url . $this->cache_file_prefix . $id; return array($this->container->getFilename($id, $this->cache_group), $file); @@ -206,10 +208,11 @@ * @access public * @see getImage() */ - function cacheImage($id, $img, $format = 'png') { - if (!$id) + function cacheImage($id, $img, $format = 'png') + { + if (!$id) { return new Cache_Error('You must provide an ID for and image to be cached!', __FILE__, __LINE__); - + } $id = $this->generateID($id, $format); $types = ImageTypes(); @@ -225,9 +228,9 @@ } } - if ($image = $this->get($id, $this->cache_group)) + if ($image = $this->get($id, $this->cache_group)) { return $image; - + } // save the image to the output buffer, write it to disk and // return the image. ob_end_clean(); @@ -271,10 +274,11 @@ * @throws Cache_Error * @access public */ - function cacheImageLink($id, &$img, $format = 'png') { - if (!$id) + function cacheImageLink($id, &$img, $format = 'png') + { + if (!$id) { return new Cache_Error ('You must provide an ID for and image to be cached!', __FILE__, __LINE__); - + } $id = $this->generateID($id, $format); $types = ImageTypes(); @@ -282,17 +286,19 @@ // If not, try a callback to the first available image type. if (!isset($this->imagetypes[$format]) || !($types & $this->imagetypes[$format])) { foreach ($this->imagetypes as $supported => $bitmask) - if ($types & $bitmask) + if ($types & $bitmask) { new Cache_Error("The build in GD lib does not support the image type $format. Fallback to $supported.", __FILE__, __LINE__); - else + } else { return new Cache_Error("Hmm, is your PHP build with GD support? Can't find any supported types.", __FILE__, __LINE__); + } } $url = $this->cache_url . $this->cache_file_prefix . $id; $ffile = $this->container->getFilename($id, $this->cache_group); - if ($this->isCached($id, $this->cache_group) && !isExpired($id, $this->cache_group)) + if ($this->isCached($id, $this->cache_group) && !isExpired($id, $this->cache_group)) { return array($ffile, $url); + } if (strtoupper($format) == "JPG") { $genFormat = "JPEG"; @@ -319,10 +325,11 @@ * @access public * @see setCacheDir() */ - function setCacheURL($cache_url) { - if ($cache_url && '/' != substr($cache_url, 1)) + function setCacheURL($cache_url) + { + if ($cache_url && '/' != substr($cache_url, 1)) { $cache_url .= '/'; - + } $this->cache_url = $cache_url; } // end func setCacheURL @@ -335,16 +342,18 @@ * @access public * @see setCacheURL() */ - function setCacheDir($cache_dir) { - if ($cache_dir && '/' != substr($cache_dir, 1)) + function setCacheDir($cache_dir) + { + if ($cache_dir && '/' != substr($cache_dir, 1)) { $cache_dir .= '/'; - + } $this->cache_dir = $cache_dir; $this->container->cache_dir = $cache_dir; } // end func setCacheDir - function generateID($variable, $format = 'png') { + function generateID($variable, $format = 'png') + { return md5(serialize($variable)) . '.' . $format; } // end func generateID http://cvs.php.net/diff.php/pear/Cache/HTTP_Request.php?r1=1.10&r2=1.11&ty=u Index: pear/Cache/HTTP_Request.php diff -u pear/Cache/HTTP_Request.php:1.10 pear/Cache/HTTP_Request.php:1.11 --- pear/Cache/HTTP_Request.php:1.10 Mon Dec 13 23:48:27 2004 +++ pear/Cache/HTTP_Request.php Wed Dec 15 04:09:33 2004 @@ -15,7 +15,7 @@ // | Authors: Fabien MARTY <fabien.marty@free.fr> | // +----------------------------------------------------------------------+ // -// $Id: HTTP_Request.php,v 1.10 2004/12/14 04:48:27 dufuz Exp $ +// $Id: HTTP_Request.php,v 1.11 2004/12/15 09:09:33 dufuz Exp $ require_once 'Cache.php'; require_once 'HTTP/Request.php'; @@ -56,7 +56,7 @@ * ?> * * @author Fabien MARTY <fabien.marty@free.fr> -* @version $Id: HTTP_Request.php,v 1.10 2004/12/14 04:48:27 dufuz Exp $ +* @version $Id: HTTP_Request.php,v 1.11 2004/12/15 09:09:33 dufuz Exp $ * @package Cache */ @@ -132,7 +132,10 @@ $containerOptions = null, $expires = 3600, $mode = CACHE_HTTP_REQUEST_KEEP_LOCAL_COPY) { - if (!isset($params)) $params = array(); + if (!isset($params)) { + $params = array(); + } + if (!isset($containerOptions)) { $containerOptions = array ( 'cache_dir' => '/tmp/', http://cvs.php.net/diff.php/pear/Cache/OutputCompression.php?r1=1.7&r2=1.8&ty=u Index: pear/Cache/OutputCompression.php diff -u pear/Cache/OutputCompression.php:1.7 pear/Cache/OutputCompression.php:1.8 --- pear/Cache/OutputCompression.php:1.7 Sat Jan 4 06:54:45 2003 +++ pear/Cache/OutputCompression.php Wed Dec 15 04:09:33 2004 @@ -50,12 +50,13 @@ * * Based upon a case study from Christian Stocker and inspired by jpcache. * -* @version $Id: OutputCompression.php,v 1.7 2003/01/04 11:54:45 mj Exp $ +* @version $Id: OutputCompression.php,v 1.8 2004/12/15 09:09:33 dufuz Exp $ * @author Ulf Wendel <ulf.wendel@phpdoc.de>, Christian Stocker <chregu@phant.ch> * @access public * @package Cache */ -class Cache_OutputCompression extends Cache_Output { +class Cache_OutputCompression extends Cache_Output +{ /** * Encoding, what the user (its browser) of your website accepts @@ -84,8 +85,8 @@ * @param array Array with container class options * @param string content encoding mode - auto => test which encoding the user accepts */ - function Cache_OutputCompression($container, $container_options = '', $encoding = 'auto') { - + function Cache_OutputCompression($container, $container_options = '', $encoding = 'auto') + { $this->setEncoding($encoding); $this->Cache($container, $container_options); @@ -95,28 +96,30 @@ /** * Call parent deconstructor. */ - function _Cache_OutputCompression() { + function _Cache_OutputCompression() + { $this->_Cache(); } // end deconstructor - function generateID($variable) { - + function generateID($variable) + { $this->compression = $this->getEncoding(); - return md5(serialize($variable) . serialize($this->compression)); } // end generateID - function get($id, $group) { + function get($id, $group) + { $this->content = ''; - if (!$this->caching) + if (!$this->caching) { return ''; - - if ($this->isCached($id, $group) && !$this->isExpired($id, $group)) + } + + if ($this->isCached($id, $group) && !$this->isExpired($id, $group)) { $this->content = $this->load($id, $group); - + } return $this->content; } // end func get @@ -127,7 +130,8 @@ * If you need the uncompressed content for further procession before * it's saved in the cache use endGet(). endGet() does _not compress_. */ - function end($expire = 0, $userdata = '') { + function end($expire = 0, $userdata = '') + { $content = ob_get_contents(); ob_end_clean(); @@ -141,7 +145,8 @@ } // end func end() - function endPrint($expire = 0, $userdata = '') { + function endPrint($expire = 0, $userdata = '') + { $this->printContent($this->end($expire, $userdata)); } // end func endPrint @@ -150,21 +155,19 @@ * Saves the given data to the cache. * */ - function extSave($id, $cachedata, $userdata, $expires = 0, $group = 'default') { - if (!$this->caching) + function extSave($id, $cachedata, $userdata, $expires = 0, $group = 'default') + { + if (!$this->caching) { return true; + } - if ($this->compression) { - + if ($this->compression) { $len = strlen($cachedata); $crc = crc32($cachedata); $cachedata = gzcompress($cachedata, 9); $this->content = substr($cachedata, 0, strlen($cachedata) - 4) . pack('V', $crc) . pack('V', $len); - } else { - $this->content = $cachedata; - } return $this->container->save($id, $this->content, $expires, $group, $userdata); } // end func extSave @@ -175,22 +178,22 @@ * @param string * @access public */ - function printContent($content = '') { + function printContent($content = '') + { $server = &$this->_importGlobalVariable("server"); - if ('' == $content) + if ('' == $content) { $content = &$this->container->cachedata; - + } + if ($this->compression && $this->caching) { - - $etag = 'PEAR-Cache-' . md5(substr($content, -40)); + $etag = '"PEAR-Cache-' . md5(substr($content, -40)) .'"'; header("ETag: $etag"); if (isset($server['HTTP_IF_NONE_MATCH']) && strstr(stripslashes($server['HTTP_IF_NONE_MATCH']), $etag)) { // not modified header('HTTP/1.0 304'); return; } else { - // client acceppts some encoding - send headers & data header("Content-Encoding: {$this->compression}"); header('Vary: Accept-Encoding'); @@ -209,7 +212,8 @@ * @access public * @return string Empty string (which evaluates to false) means no compression */ - function isCompressed() { + function isCompressed() + { return $this->compression; } // end func isCompressed @@ -220,7 +224,8 @@ * @access public * @see $encoding */ - function setEncoding($encoding = 'auto') { + function setEncoding($encoding = 'auto') + { $this->encoding = $encoding; } // end func setEncoding @@ -230,19 +235,21 @@ * * @see setEncoding() */ - function getEncoding() { + function getEncoding() + { $server = &$this->_importGlobalVariable("server"); // encoding set by user - if ('auto' != $this->encoding) + if ('auto' != $this->encoding) { return $this->encoding; - + } // check what the client accepts - if (false !== strpos($server['HTTP_ACCEPT_ENCODING'], 'x-gzip')) + if (false !== strpos($server['HTTP_ACCEPT_ENCODING'], 'x-gzip')) { return 'x-gzip'; - if (false !== strpos($server['HTTP_ACCEPT_ENCODING'], 'gzip')) + } + if (false !== strpos($server['HTTP_ACCEPT_ENCODING'], 'gzip')) { return 'gzip'; - + } // no compression return ''; @@ -264,7 +271,7 @@ switch (strtolower($variable)) { - case "server" : + case 'server': if (isset($_SERVER)) { $var = &$_SERVER; } else { @@ -272,7 +279,7 @@ } break; - case "session" : + case 'session': if (isset($_SESSION)) { $var = &$_SESSION; } else { @@ -280,7 +287,7 @@ } break; - case "post" : + case 'post': if (isset($_POST)) { $var = &$_POST; } else { http://cvs.php.net/diff.php/pear/Cache/Output.php?r1=1.6&r2=1.7&ty=u Index: pear/Cache/Output.php diff -u pear/Cache/Output.php:1.6 pear/Cache/Output.php:1.7 --- pear/Cache/Output.php:1.6 Sat Jan 4 06:54:45 2003 +++ pear/Cache/Output.php Wed Dec 15 04:09:33 2004 @@ -17,7 +17,7 @@ // | Vinai Kopp <kopp@netzarbeiter.de> | // +----------------------------------------------------------------------+ // -// $Id: Output.php,v 1.6 2003/01/04 11:54:45 mj Exp $ +// $Id: Output.php,v 1.7 2004/12/15 09:09:33 dufuz Exp $ require_once 'Cache.php'; @@ -94,7 +94,8 @@ * @package Cache * @access public */ -class Cache_Output extends Cache { +class Cache_Output extends Cache +{ /** * ID passed to start() @@ -129,15 +130,16 @@ * @return string * @access public */ - function start($id, $group = 'default') { - if (!$this->caching) + function start($id, $group = 'default') + { + if (!$this->caching) { return ''; - + } // this is already cached return it from the cache so that the user // can use the cache content and stop script execution - if ($content = $this->get($id, $group)) + if ($content = $this->get($id, $group)) { return $content; - + } // remember some data to be able to fill the cache on calling end() $this->output_id = $id; $this->output_group = $group; @@ -158,14 +160,15 @@ * @access public * @see endPrint(), endGet(), Container::getExpiresAbsolute() */ - function end($expire = 0, $userdata = '') { + function end($expire = 0, $userdata = '') + { $content = ob_get_contents(); ob_end_clean(); // store in the cache - if ($this->caching) + if ($this->caching) { $this->container->save($this->output_id, $content, $expire, $this->output_group, $userdata); - + } return $content; } // end func end() @@ -174,7 +177,8 @@ * * @brother end() */ - function endPrint($expire = 0, $userdata = '') { + function endPrint($expire = 0, $userdata = '') + { $this->printContent($this->end($expire, $userdata)); } // end func endPrint @@ -185,10 +189,11 @@ * @param string * @access public */ - function printContent($content = '') { - if ('' == $content) + function printContent($content = '') + { + if ('' == $content) { $content = &$this->container->cachedata; - + } print $content; } /** @@ -202,7 +207,8 @@ * @access public * @see endPrint(), end() */ - function endGet() { + function endGet() + { $content = ob_get_contents(); ob_end_clean();