summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemi Collet <fedora@famillecollet.com>2010-06-08 18:24:36 +0200
committerRemi Collet <fedora@famillecollet.com>2010-06-08 18:24:36 +0200
commitda02f485fe6a2c0a478fdd33145daf2bbb10b65e (patch)
tree77acda4cbb36238dea9513feb5703298e0d6d7ad
parenta6b39fd500d6419dc9e268efc52474e06a11458f (diff)
parenta68fe1f14112df3481479eb3f736cf2fd879a324 (diff)
create include dir
-rw-r--r--.gitignore2
-rw-r--r--all.php2
-rw-r--r--autocompleter.php2
-rw-r--r--class/CommonTable.php190
-rw-r--r--include/config.php7
-rw-r--r--include/config.php.dist (renamed from config.inc.php.dist)0
-rw-r--r--include/main.php (renamed from main.inc.php)6
-rw-r--r--index.php2
-rw-r--r--pkgdb-ajax.php2
-rw-r--r--refresh.php2
-rw-r--r--rpm.php2
-rw-r--r--zoom.php2
12 files changed, 147 insertions, 72 deletions
diff --git a/.gitignore b/.gitignore
index ad5b253..d96c607 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,4 @@
-config.inc.php
+include/config.php
*.gz
.sendate
sendbox
diff --git a/all.php b/all.php
index cfaa524..8e42e46 100644
--- a/all.php
+++ b/all.php
@@ -34,7 +34,7 @@
* @link http://github.com/remicollet/rpmphp/
* @since The begining of times.
*/
-require 'main.inc.php';
+require 'include/main.php';
$what=(isset($_GET["what"]) ? $_GET["what"] : false);
$ariane[] = array(
diff --git a/autocompleter.php b/autocompleter.php
index e693e9a..2acb21e 100644
--- a/autocompleter.php
+++ b/autocompleter.php
@@ -34,7 +34,7 @@
* @link http://github.com/remicollet/rpmphp/
* @since The begining of times.
*/
-require 'main.inc.php';
+require 'include/main.php';
$q = null;
$limit = null;
diff --git a/class/CommonTable.php b/class/CommonTable.php
index a913edd..1ed47f8 100644
--- a/class/CommonTable.php
+++ b/class/CommonTable.php
@@ -32,19 +32,19 @@
* @since The begining of times.
*/
-abstract class CommonTable {
-
+abstract class CommonTable
+{
protected $db;
protected $table;
/**
* Instanciate a CommonTable
*
- * @param $db object PDO instance of the DB connection
- * @param $table string with table name
+ * @param object $db PDO instance of the DB connection
+ * @param string $table with table name
*/
- function __construct(PDO $db, $table) {
-
+ function __construct(PDO $db, $table)
+ {
$this->db = $db;
$this->table = $table;
@@ -56,11 +56,12 @@ abstract class CommonTable {
/**
* Check if the table already exists
*
- * @param $table string with table name
+ * @param string $table with table name
*
* @return boolean
*/
- public function existsTable($table) {
+ public function existsTable($table)
+ {
$req = new TableIterator($this->db, "SHOW TABLES LIKE '$table'");
foreach ($req as $data) {
return true;
@@ -71,9 +72,10 @@ abstract class CommonTable {
/**
* Execute an SQL statement (INSERT, DELETE, ...)
*
- * @param $sql string
+ * @param string $sql The SQL clause
*/
- protected function exec($sql) {
+ protected function exec($sql)
+ {
$res = $this->db->exec($sql);
if ($res===false) {
$err = $this->db->errorInfo();
@@ -84,9 +86,10 @@ abstract class CommonTable {
/**
* Add a new row in the table
*
- * @param fields hashtable of fieldname => value
+ * @param hashtable $fields hashtable of fieldname => value
*/
- protected function add(array $fields) {
+ protected function add(array $fields)
+ {
$col = array();
$val = array();
foreach ($fields as $name => $value) {
@@ -99,8 +102,8 @@ abstract class CommonTable {
$val[] = "'$value'";
}
}
- $sql = "INSERT INTO `".$this->table."` (".implode(',',$col).")
- VALUE (".implode(',',$val).")";
+ $sql = "INSERT INTO `".$this->table."` (".implode(',', $col).")
+ VALUE (".implode(',', $val).")";
$this->exec($sql);
}
@@ -118,12 +121,22 @@ abstract class CommonTable {
* foreach ($DB->request("", "name") as $ID => $data) { ... }
* foreach ($DB->request(array("name"=>"SBEI003W","entities_id"=>1),array("serial","otherserial")) { ... }
*
- * @param $crit string or array of field/values, ex array("id"=>1), if empty => all rows
+ * @param string|array $crit string or array of field/values,
+ * ex array("id"=>1), if empty => all rows
*
* Examples =
- * array("id"=>NULL)
- * array("OR"=>array("id"=>1, "NOT"=>array("state"=>3)));
- * array("AND"=>array("id"=>1, array("NOT"=>array("state"=>array(3,4,5),"toto"=>2))))
+ * array("id"=>NULL)
+ * array("OR"=>array("id"=>1, "NOT"=>array("state"=>3)));
+ * array(
+ * "AND"=>array(
+ * "id"=>1,array(
+ * "NOT"=>array(
+ * "state"=>array(3,4,5),
+ * "toto"=>2
+ * )
+ * )
+ * )
+ * )
*
* param 'FIELDS' name or array of field names
* param 'ORDER' filed name or array of field names
@@ -132,19 +145,21 @@ abstract class CommonTable {
*
* @return DBIterator
**/
- public function request ($crit='') {
+ public function request ($crit='')
+ {
return new TableIterator ($this->db, $this->table, $crit);
}
/**
* Retrieve 2 columns of all the table's row in a hashtable
*
- * @param $fieldkey string name of the field to use as index
- * @param $fieldvalue string name of the field to use as value
+ * @param string $fieldkey name of the field to use as index
+ * @param string $fieldvalue name of the field to use as value
*
* @return hashtable
*/
- public function getAllArray($fieldkey, $fieldvalue) {
+ public function getAllArray($fieldkey, $fieldvalue)
+ {
$crit = array('FIELDS' => array($fieldkey, $fieldvalue),
'ORDER' => $fieldkey);
$tab = array();
@@ -155,19 +170,26 @@ abstract class CommonTable {
}
}
-class TablePearRepo extends CommonTable {
+class TablePearRepo extends CommonTable
+{
/**
* Instanciate a TablePearRepo to manage pearrepo table
+ *
+ * @param object $db PDO instance of the DB connection
*/
- function __construct($db) {
+ function __construct($db)
+ {
parent::__construct($db, 'pearrepo');
}
/**
* Create the table and populate it with known repo
+ *
+ * @return void
*/
- protected function createTable() {
+ protected function createTable()
+ {
// Table schema
$sql = "CREATE TABLE `pearrepo` (
@@ -204,20 +226,21 @@ class TablePearRepo extends CommonTable {
*
* @return hastable of alias => url
*/
- function getAllRepo() {
+ function getAllRepo()
+ {
return $this->getAllArray('alias', 'url');
}
}
-/*
+/**
* Helper for simple query => use directly or through CommonTable::request()
*
* Freely inspired from DBmysqlIterator class from GLPI
* (already written by Remi, and ported to PDO)
* See http://www.glpi-project.org/
*/
-class TableIterator implements Iterator {
-
+class TableIterator implements Iterator
+{
private $con;
private $sql;
private $res = false;
@@ -227,12 +250,14 @@ class TableIterator implements Iterator {
/**
* Constructor
*
- * @param $dbconnexion Database Connnexion (must be a CommonDBTM object)
- * @param $table table name
- * @param $crit string or array of filed/values, ex array("id"=>1), if empty => all rows
- *
- **/
- function __construct (PDO $dbconnexion, $table, $crit='') {
+ * @param CommonDBTM $dbconnexion Database Connnexion
+ * (must be a CommonDBTM object)
+ * @param string $table table name
+ * @param string|array $crit string or array of filed/values,
+ * ex array("id"=>1), if empty => all rows
+ */
+ function __construct (PDO $dbconnexion, $table, $crit='')
+ {
$this->conn = $dbconnexion;
if (is_string($table) && strpos($table, " ")) {
@@ -267,11 +292,14 @@ class TableIterator implements Iterator {
$this->sql = "";
foreach ($field as $t => $f) {
if (is_numeric($t)) {
- $this->sql .= (empty($this->sql) ? "SELECT " : ",") . $f;
+ $this->sql .= (empty($this->sql)
+ ? "SELECT " : ",") . $f;
} else if (is_array($f)) {
- $this->sql .= (empty($this->sql) ? "SELECT $t." : ",$t.") . implode(",$t.",$f);
+ $this->sql .= (empty($this->sql)
+ ? "SELECT $t." : ",$t.") . implode(",$t.", $f);
} else {
- $this->sql .= (empty($this->sql) ? "SELECT " : ",") . "$t.$f";
+ $this->sql .= (empty($this->sql)
+ ? "SELECT " : ",") . "$t.$f";
}
}
} else if (empty($field)) {
@@ -281,18 +309,18 @@ class TableIterator implements Iterator {
}
// FROM table list
if (is_array($table)) {
- $this->sql .= " FROM `".implode("`, `",$table)."`";
+ $this->sql .= " FROM `".implode("`, `", $table)."`";
} else {
$this->sql .= " FROM `$table`";
}
// WHERE criteria list
if (!empty($crit)) {
print_r($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`";
}
@@ -313,8 +341,11 @@ class TableIterator implements Iterator {
$this->pos = -1;
}
- function __destruct () {
-
+ /**
+ * Class destructor
+ */
+ function __destruct ()
+ {
if ($this->res) {
$this->res->closeCursor();
}
@@ -322,8 +353,14 @@ class TableIterator implements Iterator {
/**
* Build WHERE clause
+ *
+ * @param TODO $crit To document
+ * @param TODO $bool To document
+ *
+ * @return To document
*/
- private function analyseCrit ($crit, $bool="AND") {
+ private function _analyseCrit ($crit, $bool="AND")
+ {
if (!is_array($crit)) {
return $crit;
@@ -334,14 +371,14 @@ class TableIterator implements Iterator {
$ret .= " $bool ";
}
if (is_numeric($name)) {
- // No Key case => recurse.
- $ret .= "(" . $this->analyseCrit($value, $bool) . ")";
+ // No Key case => recurse.
+ $ret .= "(" . $this->_analyseCrit($value, $bool) . ")";
} else if ($name==="OR" || $name==="AND") {
- // Binary logical operator
- $ret .= "(" . $this->analyseCrit($value, $name) . ")";
+ // Binary logical operator
+ $ret .= "(" . $this->_analyseCrit($value, $name) . ")";
} else if ($name==="NOT") {
// Uninary logicial operator
- $ret .= " NOT (" . $this->analyseCrit($value, "AND") . ")";
+ $ret .= " NOT (" . $this->_analyseCrit($value, "AND") . ")";
} else if ($name==="FKEY") {
// Foreign Key condition
if (is_array($value) && count($value)==2) {
@@ -355,7 +392,7 @@ class TableIterator implements Iterator {
}
} else if (is_array($value)) {
// Array of Value
- $ret .= "$name IN ('". implode("','",$value)."')";
+ $ret .= "$name IN ('". implode("','", $value)."')";
} else if (is_null($value)) {
// NULL condition
$ret .= "$name IS NULL";
@@ -370,7 +407,13 @@ class TableIterator implements Iterator {
return $ret;
}
- public function rewind () {
+ /**
+ * To document
+ *
+ * @return To document
+ */
+ public function rewind ()
+ {
if ($this->res && $this->pos>=0) {
$this->res->closeCursor();
@@ -386,18 +429,33 @@ class TableIterator implements Iterator {
return $this->next();
}
- public function current() {
-
+ /**
+ * To document
+ *
+ * @return To document
+ */
+ public function current()
+ {
return $this->row;
}
- public function key() {
-
+ /**
+ * To document
+ *
+ * @return To document
+ */
+ public function key()
+ {
return (isset($this->row["id"]) ? $this->row["id"] : $this->pos);
}
- public function next() {
-
+ /**
+ * To document
+ *
+ * @return To document
+ */
+ public function next()
+ {
if (!$this->res) {
return false;
}
@@ -406,13 +464,23 @@ class TableIterator implements Iterator {
return $this->row;
}
- public function valid() {
-
+ /**
+ * To document
+ *
+ * @return To document
+ */
+ public function valid()
+ {
return $this->res && $this->row;
}
- public function numrows() {
-
+ /**
+ * To document
+ *
+ * @return To document
+ */
+ public function numrows()
+ {
return ($this->res ? $this->res->rowCount() : 0);
}
}
diff --git a/include/config.php b/include/config.php
new file mode 100644
index 0000000..a3ba75c
--- /dev/null
+++ b/include/config.php
@@ -0,0 +1,7 @@
+<?php
+define("MYHOST", "localhost");
+define("MYUSER", "root");
+define("MYPASS", "valentin");
+define("MYBASE", "rpmphp");
+?>
+
diff --git a/config.inc.php.dist b/include/config.php.dist
index 8895cdc..8895cdc 100644
--- a/config.inc.php.dist
+++ b/include/config.php.dist
diff --git a/main.inc.php b/include/main.php
index c9ec889..b97db02 100644
--- a/main.inc.php
+++ b/include/main.php
@@ -35,9 +35,9 @@
*/
define('RPMPHP_VERSION', '1.0.0-dev');
-require 'config.inc.php';
-require '/usr/share/php/Smarty/Smarty.class.php';
-require 'class/FedoraClient.php';
+require 'config.php';
+require 'Smarty/Smarty.class.php';
+require dirname(__FILE__).'/../class/FedoraClient.php';
$smarty = new Smarty();
diff --git a/index.php b/index.php
index f7a1546..c4ddb24 100644
--- a/index.php
+++ b/index.php
@@ -34,7 +34,7 @@
* @link http://github.com/remicollet/rpmphp/
* @since The begining of times.
*/
-require 'main.inc.php';
+require 'include/main.php';
$smarty->assign('ariane', $ariane);
$smarty->assign('page_title', 'Packages in Fedora repositories');
diff --git a/pkgdb-ajax.php b/pkgdb-ajax.php
index a07a3e4..f23b4cf 100644
--- a/pkgdb-ajax.php
+++ b/pkgdb-ajax.php
@@ -35,7 +35,7 @@
* @since The begining of times.
*/
header('Content-Type: application/json;charset=utf-8');
-require 'main.inc.php';
+require 'include/main.php';
$name = $_GET['name'];
if ( !isset($name) || !$name ) {
diff --git a/refresh.php b/refresh.php
index cc56e84..53aef84 100644
--- a/refresh.php
+++ b/refresh.php
@@ -43,7 +43,7 @@ if (isset($_SERVER["SERVER_NAME"])) {
die("This script is launched twice a day, be patient");
}
-require "config.inc.php";
+require "include/main.php";
require "class/CommonTable.php";
/**
diff --git a/rpm.php b/rpm.php
index 5073f9f..8b140a8 100644
--- a/rpm.php
+++ b/rpm.php
@@ -34,7 +34,7 @@
* @link http://github.com/remicollet/rpmphp/
* @since The begining of times.
*/
-require 'main.inc.php';
+require 'include/main.php';
$what=(isset($_GET["what"]) ? $_GET["what"] : "%fedora");
$type=(isset($_GET["type"]) ? $_GET["type"] : "pecl");
diff --git a/zoom.php b/zoom.php
index fdb340f..45a4830 100644
--- a/zoom.php
+++ b/zoom.php
@@ -34,7 +34,7 @@
* @link http://github.com/remicollet/rpmphp/
* @since The begining of times.
*/
-require 'main.inc.php';
+require 'include/main.php';
$fedcli = new FedoraPkgdb();