diff options
author | Silvio <silvio@devlet.com.br> | 2010-08-18 15:22:43 -0300 |
---|---|---|
committer | Silvio <silvio@devlet.com.br> | 2010-08-18 15:22:43 -0300 |
commit | ad8d8568b683e6935bec64abe88f79bf31706dd7 (patch) | |
tree | 43d00493cf8676acbcf4bec74bf44c717107ecd6 /classes/backends/SchemaDb.php | |
parent | 219aa7f6b4a19b723b0c25683801b1b5d502e9f4 (diff) | |
download | cinisis-ad8d8568b683e6935bec64abe88f79bf31706dd7.tar.gz cinisis-ad8d8568b683e6935bec64abe88f79bf31706dd7.tar.bz2 |
Adding audit and finder classes, cleanup and organization
Diffstat (limited to 'classes/backends/SchemaDb.php')
-rw-r--r-- | classes/backends/SchemaDb.php | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/classes/backends/SchemaDb.php b/classes/backends/SchemaDb.php new file mode 100644 index 0000000..db9ca30 --- /dev/null +++ b/classes/backends/SchemaDb.php @@ -0,0 +1,96 @@ +<?php + +/** + * SchemaDb class with standard database procedures and + * configuration. + */ +class SchemaDb { + /** + * Return the required database config. + * + * @return + * Array with required config. + */ + static function required() { + $schema = array( + 'db' => array( + 'name' => 'dbname', + ), + 'fields' => array( + ), + ); + + return $schema; + } + + /** + * Return the optional database config. + * + * @return + * Array with optional config. + */ + public function optional() { + $schema = array( + 'db' => array( + 'charset' => 'charset', + ), + ); + + return $schema; + } + + /** + * Return an example database schema. + * + * @see IsisDb::example() + */ + public function example() { + $required = SchemaDb::required(); + $optional = SchemaDb::optional(); + $schema = array( + 'db' => array( + 'charset' => 'charset', + ), + 'fields' => array( + 1 => array( + 'name' => 'field_name', + 'size' => 1000, + 'format' => 'numeric', + 'repeat' => TRUE, + 'subfields' => array( + 'a' => 'test', + 'b' => 'test2', + ), + ), + ), + ); + + return array_merge_recursive($required, $optional, $schema); + } + + /** + * Recursively check for required fields in a database schema. + * + * @see IsisDb::check() + */ + static function check($schema, $section = NULL) { + if ($section === NULL) { + $section = SchemaDb::required(); + } + + foreach ($section as $key => $value) { + if (!isset($schema[$key])) { + throw new Exception('Undefined required parameter '. $key .' on database configuration.'); + return FALSE; + } + + if (is_array($value)) { + if (SchemaDb::check($schema[$key], $section[$key]) == FALSE) { + return FALSE; + } + } + } + + return $schema; + } +} |