diff options
author | Silvio <silvio@devlet.com.br> | 2010-04-09 15:50:43 -0300 |
---|---|---|
committer | Silvio <silvio@devlet.com.br> | 2010-04-09 15:50:43 -0300 |
commit | 4234c6f306ed6f25069e0b5cc6edc40c7dacb564 (patch) | |
tree | 4533e3db68c28a06d400a6242fa142f42401acac | |
parent | 1996dbfb572285bbba3805fe9073d62a736615c2 (diff) | |
download | cinisis-4234c6f306ed6f25069e0b5cc6edc40c7dacb564.tar.gz cinisis-4234c6f306ed6f25069e0b5cc6edc40c7dacb564.tar.bz2 |
Initial code for perl backend
-rw-r--r-- | classes/BiblioIsisDb.php | 75 | ||||
-rw-r--r-- | classes/PhpIsisDb.php | 4 | ||||
-rw-r--r-- | config/config.yaml | 2 |
3 files changed, 72 insertions, 9 deletions
diff --git a/classes/BiblioIsisDb.php b/classes/BiblioIsisDb.php index 35404bb..3f51945 100644 --- a/classes/BiblioIsisDb.php +++ b/classes/BiblioIsisDb.php @@ -11,10 +11,9 @@ class BiblioIsisDb implements IsisDb { var $fdt; /** - * @var $db - * Database resource. + * Class instance of a perl interpreter; */ - var $db; + var $perl; /** * @var $format @@ -28,17 +27,71 @@ class BiblioIsisDb implements IsisDb { * @see IsisDb::__construct() */ public function __construct($schema) { + // Save db schema. + $this->format = $schema; + + // Setup $fdt. + foreach ($schema['fields'] as $field => $info) { + $this->fdt[$field] = $info['name']; + } + + // Create a perl instance. + $this->perl = new Perl(); + } + + /** + * Send requests to the perl backend. + * + * @param $method + * Backend method name to invoke. + * + * @param $args + * Backend method arguments. + * + * @return + * Backend return value. + */ + function backend($method = 'count', $args = NULL) { + // Setup the database. + $name = $this->format['db']['name']; + $db = CinisisDb::file("$name/$name", 'db'); + + // Setup arguments. + if ($args != NULL) { + $args = '('. $args .')'; + } + + try { + // Call backend. + return $this->perl->eval(' + use Biblio::Isis; + + my $isis = new Biblio::Isis( + isisdb => "'. $db .'", + ); + + return $isis->'. $method . $args .';'); + } + catch (PerlException $exception) { + echo __CLASS__ .': Perl error: ' . $exception->getMessage(); + return FALSE; + } } /** * Read an entry. * * @see IsisDb::read() - * - * @todo - * Subfields. */ public function read($id) { + // Database query. + $results = $this->backend('to_hash', $id); + + // Tag results. + $data = $this->tag($results); + + // Return the result. + return $data; } /** @@ -51,6 +104,7 @@ class BiblioIsisDb implements IsisDb { * @see IsisDb::read() */ public function rows() { + return $this->backend('count'); } /** @@ -84,7 +138,16 @@ class BiblioIsisDb implements IsisDb { * * @return * Tagged database result. + * + * @todo + * Subfields. */ function tag($results) { + foreach ($results as $key => $value) { + $name = $this->format['fields'][$key]['name']; + $data[$name] = $value; + } + + return $data; } } diff --git a/classes/PhpIsisDb.php b/classes/PhpIsisDb.php index 9e885d9..136b657 100644 --- a/classes/PhpIsisDb.php +++ b/classes/PhpIsisDb.php @@ -25,7 +25,7 @@ class PhpIsisDb implements IsisDb { // Save db schema. $this->format = $schema; - // Setup $fdt used by malete. + // Setup $fdt. foreach ($schema['fields'] as $field => $info) { $this->fdt[$field] = $info['name']; } @@ -105,7 +105,7 @@ class PhpIsisDb implements IsisDb { function tag($results) { foreach ($results as $key => $value) { if ($key != 'mfn') { - $name = $this->format['fields'][$key]['name']; + $name = $this->format['fields'][$key]['name']; $data[$name] = $value; } } diff --git a/config/config.yaml b/config/config.yaml index cffeef1..92b6897 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -1,3 +1,3 @@ --- -implementation: Malete +implementation: BiblioIsis database: tupi |