Пример #1
0
 /**
  * Write metadata files for all the listed tables.
  *
  * @param string $path
  * @param DbAdapter $db
  * @param array $tables
  * @return void
  */
 protected function writeMetadataFiles($path, DbAdapter $db, array $tables)
 {
     $inflector = new Inflector();
     foreach ($tables as $table) {
         $columns = $db->describeTable($table);
         $references = $db->listForeignKeyReferences($table);
         $uniqueConstraints = $db->listUniqueConstraints($table);
         $title = $inflector->titleize($table);
         $replacements = array('{{singular}}' => $inflector->singularize($title), '{{plural}}' => $inflector->pluralize($title), '{{columns}}' => var_export($columns, true), '{{references}}' => var_export($references, true), '{{uniqueConstraints}}' => var_export($uniqueConstraints, true));
         file_put_contents("{$path}/{$table}.php", str_replace(array_keys($replacements), $replacements, file_get_contents(__DIR__ . '/db-metadata/template.tpl')));
     }
 }