aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSilvio <silvio@devlet.com.br>2010-03-31 12:24:53 -0300
committerSilvio <silvio@devlet.com.br>2010-03-31 12:24:53 -0300
commit5eeabb67d7fa82ac230bb1a323ca3204d59b9915 (patch)
treea4294640a79931744d8e60e9f20716e943b05d90
parenta39fb6bd4670137a4d682403bf80dd5d1b50ada2 (diff)
downloadcinisis-5eeabb67d7fa82ac230bb1a323ca3204d59b9915.tar.gz
cinisis-5eeabb67d7fa82ac230bb1a323ca3204d59b9915.tar.bz2
Adding classe CinIsis
-rw-r--r--classes/CinIsis.php40
-rw-r--r--classes/MaleteDb.php4
-rw-r--r--config/config.yaml2
-rw-r--r--index.php28
4 files changed, 55 insertions, 19 deletions
diff --git a/classes/CinIsis.php b/classes/CinIsis.php
new file mode 100644
index 0000000..300bd61
--- /dev/null
+++ b/classes/CinIsis.php
@@ -0,0 +1,40 @@
+<?php
+
+/**
+ * CinIsis main class.
+ */
+class CinIsis {
+ /**
+ * @var $db
+ * Database resource.
+ */
+ var $db;
+
+ /**
+ * @var $implementation
+ * Database implementation.
+ */
+ var $implementation;
+
+ /**
+ * Constructor.
+ *
+ * @param $config
+ * Alternative config file (defaults to 'config/config.yaml').
+ */
+ function __construct($config = NULL) {
+ if ($config == NULL) {
+ $config = 'config/config.yaml';
+ }
+
+ // Load configuration.
+ $config = Spyc::YAMLLoad($config);
+
+ // Load database schema.
+ $schema = Spyc::YAMLLoad('schemas/'. $config['database'] .'.yaml');
+
+ // Setup database connection.
+ $this->implementation = $config['implementation'] .'Db';
+ $this->db = new $this->implementation($schema);
+ }
+}
diff --git a/classes/MaleteDb.php b/classes/MaleteDb.php
index 0628e9e..a2d45aa 100644
--- a/classes/MaleteDb.php
+++ b/classes/MaleteDb.php
@@ -71,11 +71,11 @@ class MaleteDb implements IsisDb {
* @see IsisDb::read()
*/
public function rows() {
- $id = 1;
+ $id = 0;
while($this->db->read($id)) {
$id++;
}
- return $id - 1;
+ return $id;
}
/**
diff --git a/config/config.yaml b/config/config.yaml
index 0275926..f40aa75 100644
--- a/config/config.yaml
+++ b/config/config.yaml
@@ -1,3 +1,3 @@
---
-implementation: Malete
+implementation: PhpIsis
database: anu10
diff --git a/index.php b/index.php
index 3887b3d..42140d6 100644
--- a/index.php
+++ b/index.php
@@ -1,36 +1,32 @@
<?php
/**
- * Isis db migration tool.
+ * CinIsis - Isis db reading tool.
*/
// Import Malete Library.
-require 'contrib/malete/php/Isis.php';
+require_once 'contrib/malete/php/Isis.php';
// Import Spyc.
-require 'contrib/spyc/spyc.php';
+require_once 'contrib/spyc/spyc.php';
// Import Isis interface.
-require 'interface.php';
+require_once 'interface.php';
// Autoloader.
-function __autoload($class) {
+function cinisis_autoload($class) {
require_once 'classes/' .$class. '.php';
}
-// Load configuration.
-$config = Spyc::YAMLLoad('config/config.yaml');
+// Register autoloader.
+spl_autoload_register("cinisis_autoload");
-// Load database schema.
-$schema = Spyc::YAMLLoad('schemas/'. $config['database'] .'.yaml');
-
-// Setup database connection.
-$implementation = $config['implementation'] .'Db';
-$db = new $implementation($schema);
+// Get a db instance.
+$isis = new CinIsis();
// Test connection.
-if ($db) {
- $result = $db->read(1);
- $rows = $db->rows();
+if ($isis->db) {
+ $result = $isis->db->read(1);
+ $rows = $isis->db->rows();
// Format output.
echo '<pre>';