From 06a6a4f777272421970bb827c898f6d36f1ab669 Mon Sep 17 00:00:00 2001 From: "Johan \"Papa\" Cwiklinski" Date: Sun, 1 Aug 2010 10:55:01 +0200 Subject: Applying PEAR coding standards, refs #48 --- autocompleter.php | 4 +-- class/CommonTable.php | 13 ++++--- class/FedoraClient.php | 16 ++++----- class/FedoraPkgdb.php | 12 +++---- class/TableIterator.php | 90 +++++++++++++++++++++++++++---------------------- class/TableRRepo.php | 3 ++ include/main.php | 9 +++-- pkgdb-ajax.php | 2 +- refresh.php | 1 - 9 files changed, 82 insertions(+), 68 deletions(-) diff --git a/autocompleter.php b/autocompleter.php index 2acb21e..5dbcd5a 100644 --- a/autocompleter.php +++ b/autocompleter.php @@ -39,11 +39,11 @@ require 'include/main.php'; $q = null; $limit = null; $ret = null; -if( !isset($_GET['q']) || $_GET['q'] == '' ) { +if ( !isset($_GET['q']) || $_GET['q'] == '' ) { die(); } else { $q = $_GET['q']; - if( !isset($_GET['limit']) || $_GET['limit'] == '' ) { + if ( !isset($_GET['limit']) || $_GET['limit'] == '' ) { $limit = 10; } else { $limit = $_GET['limit']; diff --git a/class/CommonTable.php b/class/CommonTable.php index 8fd0471..51c0cd6 100644 --- a/class/CommonTable.php +++ b/class/CommonTable.php @@ -73,8 +73,8 @@ abstract class CommonTable * Execute an SQL statement (INSERT, DELETE, ...) * * @param string $sql The SQL clause - * - * @param integer number of affected rows + * + * @return integer number of affected rows */ protected function exec($sql) { @@ -148,6 +148,8 @@ abstract class CommonTable /** * Create the table + * + * @return void */ abstract protected function createTable(); @@ -158,7 +160,10 @@ abstract class CommonTable * foreach ($DB->request() as $ID => $data) { ... } * foreach ($DB->request("ID=1") as $ID => $data) { ... } * foreach ($DB->request("", "name") as $ID => $data) { ... } - * foreach ($DB->request(array("name"=>"SBEI003W","entities_id"=>1),array("serial","otherserial")) { ... } + * foreach ($DB->request(array( + * "name"=>"SBEI003W", + * "entities_id"=>1), + * array("serial","otherserial")) { ... } * * @param string|array $crit string or array of field/values, * ex array("id"=>1), if empty => all rows @@ -194,7 +199,7 @@ abstract class CommonTable * * @param string $fieldkey name of the field to use as index * @param string $fieldvalue name of the field to use as value - * @param array $crit for request + * @param array $crit for request * * @return hashtable */ diff --git a/class/FedoraClient.php b/class/FedoraClient.php index f1ce8f6..42a590b 100644 --- a/class/FedoraClient.php +++ b/class/FedoraClient.php @@ -44,8 +44,8 @@ abstract class FedoraClient { const VERSION='0.1.0-dev'; protected $url; - private $agent; - private $debug = 0; + private $_agent; + private $_debug = 0; protected $cache; function __construct ($url, array $options) @@ -62,22 +62,22 @@ abstract class FedoraClient $this->url = $url; if (isset($options['agent']) && !empty($options['agent'])) { - $this->agent = $options['agent']; + $this->_agent = $options['agent']; } else { - $this->agent = 'Fedora PHPClient/'.self::VERSION; + $this->_agent = 'Fedora PHPClient/'.self::VERSION; } if (isset($options['debug']) && intval($options['debug'])>0) { - $this->debug = intval($options['debug']); + $this->_debug = intval($options['debug']); } $this->logDebug( 3, - __CLASS__."::".__FUNCTION__.": url='$url', agent='".$this->agent."'" + __CLASS__."::".__FUNCTION__.": url='$url', agent='".$this->_agent."'" ); } function logDebug($level, $msg) { - if ($this->debug>=$level) { + if ($this->_debug>=$level) { echo "[debug][$level] $msg\n"; } } @@ -103,7 +103,7 @@ abstract class FedoraClient curl_setopt( $curl, CURLOPT_HTTPHEADER, - array('User-agent: '.$this->agent, 'Accept: application/json') + array('User-agent: '.$this->_agent, 'Accept: application/json') ); // run the request diff --git a/class/FedoraPkgdb.php b/class/FedoraPkgdb.php index d170911..15ddf50 100644 --- a/class/FedoraPkgdb.php +++ b/class/FedoraPkgdb.php @@ -37,12 +37,12 @@ class FedoraPkgdb extends FedoraClient { - private $suburl; + private $_suburl; function __construct (array $options=array()) { parent::__construct('https://admin.fedoraproject.org/pkgdb/', $options); - $this->suburl = 'acls/name/'; + $this->_suburl = 'acls/name/'; $this->logDebug( 3, @@ -80,12 +80,12 @@ class FedoraPkgdb extends FedoraClient function getPackageURL($name) { - return $this->url.$this->suburl.$name; + return $this->url.$this->_suburl.$name; } function getPackageInfo($name, $refresh=false) { - $url=$this->suburl.urlencode($name); + $url=$this->_suburl.urlencode($name); $rep = ($refresh ? false : $this->cache->get($url, __CLASS__)); if ($rep) { $this->logDebug( @@ -108,12 +108,12 @@ class FedoraPkgdb extends FedoraClient ); return false; } - $this->logDebug(8,print_r($rep,true)); + $this->logDebug(8, print_r($rep, true)); $branches = array(); foreach ($rep['packageListings'] as $pack) { $branches[$pack['collection']['branchname']] = $pack; } - $this->logDebug(7,print_r($branches,true)); + $this->logDebug(7, print_r($branches, true)); return $branches; } diff --git a/class/TableIterator.php b/class/TableIterator.php index 0903f37..dfae859 100644 --- a/class/TableIterator.php +++ b/class/TableIterator.php @@ -38,14 +38,22 @@ * Freely inspired from DBmysqlIterator class from GLPI * (already written by Remi, and ported to PDO) * See http://www.glpi-project.org/ + * + * @category Main + * @package RPMPHP + * + * @author Remi Collet + * @author Johan Cwiklinski + * @license http://www.gnu.org/licenses/agpl-3.0-standalone.html AGPL License 3.0 or (at your option) any later version + * @link http://github.com/remicollet/rpmphp/ */ class TableIterator implements Iterator { - private $con; - private $sql; - private $res = false; - private $row; - private $pos; + private $_con; + private $_sql; + private $_res = false; + private $_row; + private $_pos; /** * Constructor @@ -59,9 +67,9 @@ class TableIterator implements Iterator function __construct (PDO $dbconnexion, $table, $crit='') { - $this->conn = $dbconnexion; + $this->_conn = $dbconnexion; if (is_string($table) && strpos($table, " ")) { - $this->sql = $table; + $this->_sql = $table; } else { // check field, orderby, limit, start in criterias $field=""; @@ -89,55 +97,55 @@ class TableIterator implements Iterator // SELECT field list if (is_array($field)) { - $this->sql = ""; + $this->_sql = ""; foreach ($field as $t => $f) { if (is_numeric($t)) { - $this->sql .= (empty($this->sql) + $this->_sql .= (empty($this->_sql) ? "SELECT " : ",") . $f; } else if (is_array($f)) { - $this->sql .= (empty($this->sql) + $this->_sql .= (empty($this->_sql) ? "SELECT $t." : ",$t.") . implode(",$t.", $f); } else { - $this->sql .= (empty($this->sql) + $this->_sql .= (empty($this->_sql) ? "SELECT " : ",") . "$t.$f"; } } } else if (empty($field)) { - $this->sql = "SELECT *"; + $this->_sql = "SELECT *"; } else { - $this->sql = "SELECT `$field`"; + $this->_sql = "SELECT `$field`"; } // FROM table list if (is_array($table)) { - $this->sql .= " FROM `".implode("`, `", $table)."`"; + $this->_sql .= " FROM `".implode("`, `", $table)."`"; } else { - $this->sql .= " FROM `$table`"; + $this->_sql .= " FROM `$table`"; } // WHERE criteria list if (!empty($crit)) { - $this->sql .= " WHERE ".$this->_analyseCrit($crit); + $this->_sql .= " WHERE ".$this->_analyseCrit($crit); } // ORDER BY if (is_array($orderby)) { - $this->sql .= " ORDER BY `".implode("`, `", $orderby)."`"; + $this->_sql .= " ORDER BY `".implode("`, `", $orderby)."`"; } else if (!empty($orderby)) { - $this->sql .= " ORDER BY `$orderby`"; + $this->_sql .= " ORDER BY `$orderby`"; } if (is_numeric($limit) && $limit>0) { - $this->sql .= " LIMIT $limit"; + $this->_sql .= " LIMIT $limit"; if (is_numeric($start) && $start>0) { - $this->sql .= " OFFSET $start"; + $this->_sql .= " OFFSET $start"; } } } - //echo "SQL: ".$this->sql."\n"; - $this->res = $this->conn->prepare($this->sql); - if ($this->res===false) { + //echo "SQL: ".$this->_sql."\n"; + $this->_res = $this->_conn->prepare($this->_sql); + if ($this->_res===false) { $err = $this->db->errorInfo(); throw new Exception($err[2]); } - $this->pos = -1; + $this->_pos = -1; } /** @@ -145,8 +153,8 @@ class TableIterator implements Iterator */ function __destruct () { - if ($this->res) { - $this->res->closeCursor(); + if ($this->_res) { + $this->_res->closeCursor(); } } @@ -154,7 +162,7 @@ class TableIterator implements Iterator * Build WHERE clause * * @param string|array $crit To document - * @param string $bool logical operator between criteria + * @param string $bool logical operator between criteria * * @return To document */ @@ -214,14 +222,14 @@ class TableIterator implements Iterator public function rewind () { - if ($this->res && $this->pos>=0) { - $this->res->closeCursor(); - $this->pos = -1; + if ($this->_res && $this->_pos>=0) { + $this->_res->closeCursor(); + $this->_pos = -1; } - if ($this->res && $this->pos<0) { - if (!$this->res->execute()) { - $err = $this->res->errorInfo(); + if ($this->_res && $this->_pos<0) { + if (!$this->_res->execute()) { + $err = $this->_res->errorInfo(); throw new Exception($err[2]); } } @@ -235,7 +243,7 @@ class TableIterator implements Iterator */ public function current() { - return $this->row; + return $this->_row; } /** @@ -245,7 +253,7 @@ class TableIterator implements Iterator */ public function key() { - return (isset($this->row["id"]) ? $this->row["id"] : $this->pos); + return (isset($this->_row["id"]) ? $this->_row["id"] : $this->_pos); } /** @@ -255,12 +263,12 @@ class TableIterator implements Iterator */ public function next() { - if (!$this->res) { + if (!$this->_res) { return false; } - $this->row = $this->res->fetch(PDO::FETCH_ASSOC); - $this->pos++; - return $this->row; + $this->_row = $this->_res->fetch(PDO::FETCH_ASSOC); + $this->_pos++; + return $this->_row; } /** @@ -270,7 +278,7 @@ class TableIterator implements Iterator */ public function valid() { - return $this->res && $this->row; + return $this->_res && $this->_row; } /** @@ -280,7 +288,7 @@ class TableIterator implements Iterator */ public function numrows() { - return ($this->res ? $this->res->rowCount() : 0); + return ($this->_res ? $this->_res->rowCount() : 0); } } ?> \ No newline at end of file diff --git a/class/TableRRepo.php b/class/TableRRepo.php index 884b4e3..0eba46e 100644 --- a/class/TableRRepo.php +++ b/class/TableRRepo.php @@ -1,4 +1,7 @@ \ No newline at end of file diff --git a/refresh.php b/refresh.php index e839e93..aebeec2 100644 --- a/refresh.php +++ b/refresh.php @@ -508,7 +508,6 @@ try { // ------------------------------------------------------------------- if ($_SERVER['argc']==1 || in_array('R', $_SERVER['argv'])) { -// $tottot=0; $rrepo = new TableRRepo($db); foreach ($rrepo->request() as $repo) { -- cgit