コード例 #1
0
 public function load($file, $package = null)
 {
     // we figure out what kind of file we are given
     $type = array_pop(explode('.', $file));
     $type2method = array('yml' => 'loadYAML', 'xml' => 'loadXML');
     if (isset($type2method[$type])) {
         $method = $type2method[$type];
     } else {
         throw new sfDoctrineSchemaException(sprintf('Unkwnown method for extension "%s"', $type));
     }
     $propelDatabaseSchema = new sfPropelDatabaseSchema();
     $propelDatabaseSchema->{$method}($file);
     $data = $propelDatabaseSchema->asArray();
     foreach ($propelDatabaseSchema->getTables() as $tb_name => $tableDesc) {
         // special table class
         // propel has only such classes (no inheritance support)
         $table = new sfDoctrineTableSchema($tb_name, $package);
         $this->tables[$tb_name] = $table;
         if (!($className = $this->getAttribute($tableDesc, 'phpName'))) {
             $className = sfInflector::camelize($tb_name);
         }
         // wild guess
         $class = new sfDoctrineClassSchema($className);
         $table->addClass($class);
         // columns
         foreach ($propelDatabaseSchema->getChildren($tableDesc) as $col_name => $columnDescription) {
             if ($col_name == 'id') {
                 // id is automatically generated in doctrine
                 continue;
             }
             $docCol = new sfDoctrineColumnSchema($col_name, $columnDescription, true);
             $class->addColumn($docCol);
         }
         $this->classes[$class->getPhpName()] = $class;
     }
 }
コード例 #2
0
 /**
  * Update plugin schema
  *
  * @param string $schema_path 
  * @param sfPropelDatabaseSchema $dbSchema 
  * @param string $prefix 
  * @author Sergey Startsev
  */
 private function updatePluginSchema($schema_path, sfPropelDatabaseSchema $dbSchema, $prefix = '')
 {
     $schema_structure_updated = $schema_structure = $this->getSchemaStructure($schema_path);
     $current_schema = $dbSchema->asArray();
     foreach ($schema_structure as $connection => $tables) {
         foreach ($tables as $table_name => $table_structure) {
             if (isset($current_schema[$connection]) && in_array($table_name, $current_schema[$connection])) {
                 $schema_structure_updated[$connection][$table_name] = $table_description;
             }
         }
     }
     if (!empty($prefix)) {
         $schema_path = dirname($schema_path) . "/{$prefix}schema.yml";
     }
     $oSchema = new sfPropelDatabaseSchema();
     $oSchema->loadArray($schema_structure_updated);
     $this->logSection('schema', sprintf('putting %s', $schema_path));
     file_put_contents($schema_path, $oSchema->asYAML());
 }