public function load($file, $package = null) { $schema = sfYaml::load($file); foreach ($schema as $className => $cd) { if (!isset($cd['tableName']) && !isset($cd['inheritance'])) { throw new sfDoctrineSchemaException(sprintf('Class "%s" must have either a table or a parent', $className)); } $class = new sfDoctrineClassSchema($className, $cd); // add a table if necessary if (isset($cd['tableName'])) { // this top class is actually a table $table = new sfDoctrineTableSchema($cd['tableName'], $package); $table->addClass($class); $this->tables[$cd['tableName']] = $table; } $this->classes[$className] = $class; } }
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; } }
* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * @package symfony.plugins * @subpackage sfDoctrine * @author Pavel Kunc * @author Olivier Verdier <*****@*****.**> * @version SVN: $Id: sfDoctrineTableTest.php 3455 2007-02-14 16:17:48Z chtito $ */ //We need bootStrap require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; //TODO: add planned tests $t = new lime_test(null, new lime_output_color()); $tableName = 'test'; $package = 'package'; $table = new sfDoctrineTableSchema($tableName, $package); // ->__construct() $t->diag('->construct()'); $t->is($table->getName(), $tableName, '->__construct() takes first parameter as Table name'); $t->is($table->getPackage(), $package, '->__construct() takes second parameter as package name'); // ->setName() $t->diag('->setName()'); $tableName = 'myTest'; $table->setName($tableName); $t->is($table->getName(), $tableName, '->setName() sets new table name'); // ->addClass() //TODO: need test // ->addPropelXmlClasses() //TODO: need test