public static function get_tables() { $tables = array(); #$table_specification_files = self::get_table_specification_files(); # #foreach ($table_specification_files as $table_specification_file) { # $tables[] # = self # ::get_specified_table_from_table_specification_file( # $table_specification_file # ); #} foreach (HaddockProjectOrganisation_ModuleDirectoriesHelper::get_all_module_directories() as $module_directory) { foreach (glob($module_directory->get_name() . DIRECTORY_SEPARATOR . 'database' . DIRECTORY_SEPARATOR . 'table-specification' . DIRECTORY_SEPARATOR . '*') as $table_specification_directory_name) { #echo '$table_specification_directory_name: ' . $table_specification_directory_name . PHP_EOL; /* * What's the table's name? */ $table_name = $module_directory->get_database_table_name_root() . basename($table_specification_directory_name); #echo '$table_name: ' . $table_name . PHP_EOL; $specified_table = new Database_SpecifiedTable($table_name); /* * Find the fields. */ foreach (glob($table_specification_directory_name . DIRECTORY_SEPARATOR . '*.type') as $type_file) { #echo '$type_file: ' . $type_file . PHP_EOL; $field_name = basename($type_file); $field_name = preg_replace('/\\.type$/', '', $field_name); $specified_table->add_field_type($field_name, trim(file_get_contents($type_file))); } /* * Find the keys. */ foreach (glob($table_specification_directory_name . DIRECTORY_SEPARATOR . '*.index') as $index_file) { #echo '$index_file: ' . $index_file . PHP_EOL; $index_name = preg_replace('/\\.index$/', '', basename($index_file)); #echo '$index_name: ' . $index_name . PHP_EOL; #echo 'file_get_contents($index_file): ' . file_get_contents($index_file) . PHP_EOL; $lines = array(); if ($fh = fopen($index_file, 'r')) { while (!feof($fh)) { $lines[] = fgets($fh, 4096); } fclose($fh); } $index_file_vars = array(); foreach ($lines as $line) { if (preg_match('/(\\w+): (\\w+)/', $line, $matches)) { $index_file_vars[$matches[1]] = $matches[2]; } } if (isset($index_file_vars['Non_unique']) && isset($index_file_vars['Column_name'])) { $specified_table->add_index($index_name, $index_file_vars['Column_name'], $index_file_vars['Non_unique']); } #$specified_table->add_field_type( # $field_name, # trim( # file_get_contents( # $type_file # ) # ) #); } $tables[] = $specified_table; } } return $tables; }