Skip to content

Commit

Permalink
Merge pull request #30 from ranza/master
Browse files Browse the repository at this point in the history
Fix migration variable typo and add support for custom hydrators
  • Loading branch information
beberlei committed Jun 12, 2011
2 parents 3aa7662 + e785ff6 commit aca9643
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
21 changes: 21 additions & 0 deletions library/ZFDoctrine/Application/Resource/Doctrine.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ protected function _setAttributes(Doctrine_Configurable $object, array $attribut
}
}

/**
*
* @param Doctrine_Configurable $object
* @param array $attributes
* @return void
*/
protected function _setHydrators(Doctrine_Configurable $object, array $attributes)
{
foreach ($attributes as $key => $value) {
if (!isset($key)) {
throw new Zend_Application_Resource_Exception('No name for hydrator defined. ' . $value);
}
$object->registerHydrator($key, $value);
}
}

/**
* Set connection listeners
*
Expand Down Expand Up @@ -270,6 +286,11 @@ protected function _initManager()
$manager = Doctrine_Manager::getInstance();
$manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, ZFDoctrine_Core::MODEL_LOADING_ZEND); // default


if (array_key_exists('hydrators', $this->_managerOptions)) {
$this->_setHydrators($manager, $this->_managerOptions['hydrators']);
}

if (array_key_exists('attributes', $this->_managerOptions)) {
$this->_setAttributes($manager, $this->_managerOptions['attributes']);
}
Expand Down
8 changes: 4 additions & 4 deletions library/ZFDoctrine/Tool/DoctrineProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,16 @@ public function generateMigration($className=null, $dFromDatabase=false, $mFromM
} else if ($dFromDatabase) {

$yamlSchemaPath = $this->_getYamlDirectoryPath();
$migration = new Doctrine_Migration($migrationsPath);
$migration = new Doctrine_Migration($migratePath);
$result1 = false;
if ( ! count($migration->getMigrationClasses())) {
$result1 = Doctrine_Core::generateMigrationsFromDb($migrationsPath);
$result1 = Doctrine_Core::generateMigrationsFromDb($migratePath);
}
$connections = array();
foreach (Doctrine_Manager::getInstance() as $connection) {
$connections[] = $connection->getName();
}
$changes = Doctrine_Core::generateMigrationsFromDiff($migrationsPath, $connections, $yamlSchemaPath);
$changes = Doctrine_Core::generateMigrationsFromDiff($migratePath, $connections, $yamlSchemaPath);
$numChanges = count($changes, true) - count($changes);
$result = ($result1 || $numChanges) ? true:false;

Expand All @@ -336,7 +336,7 @@ public function generateMigration($className=null, $dFromDatabase=false, $mFromM
} else if ($mFromModels) {
$this->_loadDoctrineModels();

Doctrine_Core::generateMigrationsFromModels($migrationsPath, null);
Doctrine_Core::generateMigrationsFromModels($migratePath, null);

$this->_print('Generated migration classes from the model successfully.');
}
Expand Down

0 comments on commit aca9643

Please sign in to comment.