From a1ac2b66ae4be012313396566d7c42b548134d2c Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Thu, 9 Jul 2009 15:03:04 -0600 Subject: [PATCH] PHP 5/Horde 4 coding conventions --- imp/lib/Quota.php | 11 ++++---- imp/lib/Quota/{command.php => Command.php} | 14 ++++++---- imp/lib/Quota/{hook.php => Hook.php} | 2 +- imp/lib/Quota/{imap.php => Imap.php} | 2 +- imp/lib/Quota/{logfile.php => Logfile.php} | 4 ++- imp/lib/Quota/{maildir.php => Maildir.php} | 2 ++ imp/lib/Quota/{mdaemon.php => Mdaemon.php} | 6 ++-- imp/lib/Quota/{mercury32.php => Mercury32.php} | 4 ++- imp/lib/Quota/{sql.php => Sql.php} | 38 ++++++++++---------------- imp/lib/Sentmail.php | 5 ++-- imp/lib/Sentmail/{sql.php => Sql.php} | 14 +++++----- 11 files changed, 52 insertions(+), 50 deletions(-) rename imp/lib/Quota/{command.php => Command.php} (92%) rename imp/lib/Quota/{hook.php => Hook.php} (97%) rename imp/lib/Quota/{imap.php => Imap.php} (96%) rename imp/lib/Quota/{logfile.php => Logfile.php} (98%) rename imp/lib/Quota/{maildir.php => Maildir.php} (99%) rename imp/lib/Quota/{mdaemon.php => Mdaemon.php} (97%) rename imp/lib/Quota/{mercury32.php => Mercury32.php} (97%) rename imp/lib/Quota/{sql.php => Sql.php} (81%) rename imp/lib/Sentmail/{sql.php => Sql.php} (95%) diff --git a/imp/lib/Quota.php b/imp/lib/Quota.php index f49648f57..c5e1a6a15 100644 --- a/imp/lib/Quota.php +++ b/imp/lib/Quota.php @@ -46,13 +46,13 @@ class IMP_Quota static public function singleton($driver, $params = array()) { ksort($params); - $signature = md5(serialize(array($driver, $params))); + $sig = hash('md5', serialize(array($driver, $params))); - if (!isset(self::$_instances[$signature])) { - self::$_instances[$signature] = IMP_Quota::getInstance($driver, $params); + if (!isset(self::$_instances[$sig])) { + self::$_instances[$sig] = IMP_Quota::getInstance($driver, $params); } - return self::$_instances[$signature]; + return self::$_instances[$sig]; } /** @@ -68,7 +68,7 @@ class IMP_Quota static public function getInstance($driver, $params = array()) { $driver = basename($driver); - $class = 'IMP_Quota_' . $driver; + $class = 'IMP_Quota_' . ucfirst($driver); if (class_exists($class)) { return new $class($params); @@ -156,4 +156,5 @@ class IMP_Quota return array($calc, $unit); } + } diff --git a/imp/lib/Quota/command.php b/imp/lib/Quota/Command.php similarity index 92% rename from imp/lib/Quota/command.php rename to imp/lib/Quota/Command.php index ac0b44eff..8153ff862 100644 --- a/imp/lib/Quota/command.php +++ b/imp/lib/Quota/Command.php @@ -23,19 +23,21 @@ * @author Eric Rostetter * @package IMP_Quota */ -class IMP_Quota_command extends IMP_Quota +class IMP_Quota_Command extends IMP_Quota { /** - * Constructor + * Constructor. * * @param array $params Hash containing connection parameters. */ protected function __construct($params = array()) { - $params = array_merge(array('quota_path' => 'quota', - 'grep_path' => 'grep', - 'partition' => null), - $params); + $params = array_merge(array( + 'quota_path' => 'quota', + 'grep_path' => 'grep', + 'partition' => null + ), $params); + parent::__construct($params); } diff --git a/imp/lib/Quota/hook.php b/imp/lib/Quota/Hook.php similarity index 97% rename from imp/lib/Quota/hook.php rename to imp/lib/Quota/Hook.php index 1941be6c6..7386f7020 100644 --- a/imp/lib/Quota/hook.php +++ b/imp/lib/Quota/Hook.php @@ -18,7 +18,7 @@ * @author Michael Redinger * @package IMP_Quota */ -class IMP_Quota_hook extends IMP_Quota +class IMP_Quota_Hook extends IMP_Quota { /** * Get quota information (used/allocated), in bytes. diff --git a/imp/lib/Quota/imap.php b/imp/lib/Quota/Imap.php similarity index 96% rename from imp/lib/Quota/imap.php rename to imp/lib/Quota/Imap.php index 6a30daf87..55d6ba7ae 100644 --- a/imp/lib/Quota/imap.php +++ b/imp/lib/Quota/Imap.php @@ -10,7 +10,7 @@ * @author Mike Cochrane * @package IMP_Quota */ -class IMP_Quota_imap extends IMP_Quota +class IMP_Quota_Imap extends IMP_Quota { /** * Get quota information (used/allocated), in bytes. diff --git a/imp/lib/Quota/logfile.php b/imp/lib/Quota/Logfile.php similarity index 98% rename from imp/lib/Quota/logfile.php rename to imp/lib/Quota/Logfile.php index 00a0df16f..d8e2d59fd 100644 --- a/imp/lib/Quota/logfile.php +++ b/imp/lib/Quota/Logfile.php @@ -5,6 +5,7 @@ * server. * * Requires the following parameter settings in imp/servers.php: + *
  * 'quota' => array(
  *     'driver' => 'logfile',
  *     'params' => array(
@@ -27,6 +28,7 @@
  *            number.
  * midocc - String between usage and total storage space.
  * endocc - String after the storage number.
+ * 
* * See the enclosed file COPYING for license information (GPL). If you * did not receive this file, see http://www.fsf.org/copyleft/gpl.html. @@ -34,7 +36,7 @@ * @author Tim Gorter * @package IMP_Quota */ -class IMP_Quota_logfile extends IMP_Quota +class IMP_Quota_Logfile extends IMP_Quota { /** * Constructor diff --git a/imp/lib/Quota/maildir.php b/imp/lib/Quota/Maildir.php similarity index 99% rename from imp/lib/Quota/maildir.php rename to imp/lib/Quota/Maildir.php index 804067bea..3a30788d9 100644 --- a/imp/lib/Quota/maildir.php +++ b/imp/lib/Quota/Maildir.php @@ -6,6 +6,7 @@ * configuration array. * * Requires the following parameter settings in imp/servers.php: + *
  * 'quota' => array(
  *     'driver' => 'maildir',
  *     'params' => array(
@@ -18,6 +19,7 @@
  *        two-character sequence "~U" to represent the user's account name,
  *        and the actual username will be substituted in that location.
  *        E.g., '/home/~U/Maildir/' or '/var/mail/~U/Maildir/'
+ * 
* * Copyright 2007-2009 The Horde Project (http://www.horde.org/) * diff --git a/imp/lib/Quota/mdaemon.php b/imp/lib/Quota/Mdaemon.php similarity index 97% rename from imp/lib/Quota/mdaemon.php rename to imp/lib/Quota/Mdaemon.php index 7dde77e5d..6fc13c4da 100644 --- a/imp/lib/Quota/mdaemon.php +++ b/imp/lib/Quota/Mdaemon.php @@ -3,7 +3,9 @@ * Implementation of the Quota API for MDaemon servers. * * Parameters required: - * 'app_location' -- TODO + *
+ * 'app_location'  --  TODO
+ * 
* * Copyright 2002-2009 The Horde Project (http://www.horde.org/) * @@ -13,7 +15,7 @@ * @author Mike Cochrane * @package IMP_Quota */ -class IMP_Quota_mdaemon extends IMP_Quota +class IMP_Quota_Mdaemon extends IMP_Quota { /** * Get quota information (used/allocated), in bytes. diff --git a/imp/lib/Quota/mercury32.php b/imp/lib/Quota/Mercury32.php similarity index 97% rename from imp/lib/Quota/mercury32.php rename to imp/lib/Quota/Mercury32.php index 001d47e2d..5e55aaecb 100644 --- a/imp/lib/Quota/mercury32.php +++ b/imp/lib/Quota/Mercury32.php @@ -4,6 +4,7 @@ * For reading Quota, read size folder user. * * Requires the following parameter settings in imp/servers.php: + *
  * 'quota' => array(
  *     'driver' => 'mercury32',
  *     'params' => array(
@@ -12,6 +13,7 @@
  * );
  *
  * 'mail_user_folder' --  The path to folder mail mercury
+ * 
* ***************************************************************************** * PROBLEM TO ACCESS NETWORK DIRECOTRY @@ -38,7 +40,7 @@ * @author Frank Lupo * @package IMP_Quota */ -class IMP_Quota_mercury32 extends IMP_Quota +class IMP_Quota_Mercury32 extends IMP_Quota { /** * Get quota information (used/allocated), in bytes. diff --git a/imp/lib/Quota/sql.php b/imp/lib/Quota/Sql.php similarity index 81% rename from imp/lib/Quota/sql.php rename to imp/lib/Quota/Sql.php index 5e8eef4c2..a0a44d333 100644 --- a/imp/lib/Quota/sql.php +++ b/imp/lib/Quota/Sql.php @@ -42,7 +42,7 @@ * @author Jan Schneider * @package IMP_Quota */ -class IMP_Quota_sql extends IMP_Quota +class IMP_Quota_Sql extends IMP_Quota { /** * SQL connection object. @@ -52,31 +52,22 @@ class IMP_Quota_sql extends IMP_Quota protected $_db; /** - * State of SQL connection. - * - * @var boolean - */ - protected $_connected = false; - - /** * Connects to the database * * @throws Horde_Exception */ protected function _connect() { - if (!$this->_connected) { - $this->_db = DB::connect($this->_params, - array('persistent' => !empty($this->_params['persistent']), - 'ssl' => !empty($this->_params['ssl']))); - if ($this->_db instanceof PEAR_Error) { - throw new Horde_Exception(_("Unable to connect to SQL server.")); - } - - $this->_connected = true; + if ($this->_db) { + return; } - return true; + $this->_db = DB::connect($this->_params, + array('persistent' => !empty($this->_params['persistent']), + 'ssl' => !empty($this->_params['ssl']))); + if ($this->_db instanceof PEAR_Error) { + throw new Horde_Exception(_("Unable to connect to SQL server.")); + } } /** @@ -89,7 +80,8 @@ class IMP_Quota_sql extends IMP_Quota */ public function getQuota() { - $conn = $this->_connect(); + $this->_connect(); + $user = $_SESSION['imp']['user']; $quota = array('limit' => 0, 'usage' => 0); @@ -102,7 +94,7 @@ class IMP_Quota_sql extends IMP_Quota $this->_db->quote($domain)), $this->_params['query_quota']); $result = $this->_db->query($query); - if (is_a($result, 'PEAR_Error')) { + if ($result instanceof PEAR_Error) { throw new Horde_Exception($result); } @@ -111,7 +103,7 @@ class IMP_Quota_sql extends IMP_Quota $quota['limit'] = current($row); } } else { - Horde::logMessage('IMP_Quota_sql: query_quota SQL query not set', __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage('IMP_Quota_Sql: query_quota SQL query not set', __FILE__, __LINE__, PEAR_LOG_DEBUG); } if (!empty($this->_params['query_used'])) { @@ -123,7 +115,7 @@ class IMP_Quota_sql extends IMP_Quota $this->_db->quote($domain)), $this->_params['query_used']); $result = $this->_db->query($query); - if (is_a($result, 'PEAR_Error')) { + if ($result instanceof PEAR_Error) { throw new Horde_Exception($result); } @@ -132,7 +124,7 @@ class IMP_Quota_sql extends IMP_Quota $quota['usage'] = current($row); } } else { - Horde::logMessage('IMP_Quota_sql: query_used SQL query not set', __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage('IMP_Quota_Sql: query_used SQL query not set', __FILE__, __LINE__, PEAR_LOG_DEBUG); } return $quota; diff --git a/imp/lib/Sentmail.php b/imp/lib/Sentmail.php index 03e63c276..565c18cb0 100644 --- a/imp/lib/Sentmail.php +++ b/imp/lib/Sentmail.php @@ -43,8 +43,7 @@ class IMP_Sentmail $params = Horde::getDriverConfig('sentmail', $driver); } - $driver = basename($driver); - $class = 'IMP_Sentmail_' . $driver; + $class = 'IMP_Sentmail_' . ucfirst(basename($driver)); if (class_exists($class)) { try { @@ -60,7 +59,7 @@ class IMP_Sentmail * * @throws Horde_Exception */ - public function __construct($params = array()) + protected function __construct($params = array()) { $this->_params = $params; } diff --git a/imp/lib/Sentmail/sql.php b/imp/lib/Sentmail/Sql.php similarity index 95% rename from imp/lib/Sentmail/sql.php rename to imp/lib/Sentmail/Sql.php index e8d1417fa..467389234 100644 --- a/imp/lib/Sentmail/sql.php +++ b/imp/lib/Sentmail/Sql.php @@ -22,7 +22,7 @@ * @author Jan Schneider * @package IMP */ -class IMP_Sentmail_sql extends IMP_Sentmail +class IMP_Sentmail_Sql extends IMP_Sentmail { /** * Handle for the current database connection. @@ -38,7 +38,7 @@ class IMP_Sentmail_sql extends IMP_Sentmail * * @throws Horde_Exception */ - function __construct($params = array()) + protected function __construct($params = array()) { parent::__construct($params); @@ -58,7 +58,7 @@ class IMP_Sentmail_sql extends IMP_Sentmail $this->_db = DB::connect($this->_params, array('persistent' => !empty($this->_params['persistent']), 'ssl' => !empty($this->_params['ssl']))); - if (is_a($this->_db, 'PEAR_Error')) { + if ($this->_db instanceof PEAR_Error) { throw new Horde_Exception($this->_db); } @@ -103,7 +103,7 @@ class IMP_Sentmail_sql extends IMP_Sentmail $result = $this->_db->query($query, $values); /* Log errors. */ - if (is_a($result, 'PEAR_Error')) { + if ($result instanceof PEAR_Error) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); } } @@ -140,7 +140,7 @@ class IMP_Sentmail_sql extends IMP_Sentmail /* Execute the query. */ $recipients = $this->_db->getAll($query); - if (is_a($recipients, 'PEAR_Error')) { + if ($recipients instanceof PEAR_Error) { Horde::logMessage($recipients, __FILE__, __LINE__, PEAR_LOG_ERR); throw new Horde_Exception($recipients); } @@ -179,7 +179,7 @@ class IMP_Sentmail_sql extends IMP_Sentmail /* Execute the query. */ $recipients = $this->_db->getOne($query, array(time() - $hours * 3600)); - if (is_a($recipients, 'PEAR_Error')) { + if ($recipients instanceof PEAR_Error) { Horde::logMessage($recipients, __FILE__, __LINE__, PEAR_LOG_ERR); throw new Horde_Exception($recipients); } @@ -207,7 +207,7 @@ class IMP_Sentmail_sql extends IMP_Sentmail /* Execute the query. */ $result = $this->_db->query($query, array($before)); - if (is_a($result, 'PEAR_Error')) { + if ($result instanceof PEAR_Error) { Horde::logMessage($result, __FILE__, __LINE__, PEAR_LOG_ERR); throw new Horde_Exception($result); } -- 2.11.0