Skip to content

Commit

Permalink
Tweaking the method names of the recently added feature which allows …
Browse files Browse the repository at this point in the history
…custom hydration modes.
  • Loading branch information
jwage committed Jun 3, 2010
1 parent 5b148c7 commit bf9f7f8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
23 changes: 11 additions & 12 deletions lib/Doctrine/ORM/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -464,26 +464,25 @@ public function setCustomDatetimeFunctions(array $functions)
}

/**
* Get a custom hydrator class name if it exists or return null if it
* does not.
* Get the hydrator class for the given hydration mode name.
*
* @param string $name
* @return string $className
* @param string $modeName The hydration mode name.
* @return string $hydrator The hydrator class name.
*/
public function getHydrator($name)
public function getCustomHydrationMode($modeName)
{
return isset($this->_attributes['customHydrators'][$name]) ?
$this->_attributes['customHydrators'][$name] : null;
return isset($this->_attributes['customHydrationModes'][$modeName]) ?
$this->_attributes['customHydrationModes'][$modeName] : null;
}

/**
* Add a hydrator class associated with a hydration mode name.
* Add a custom hydration mode.
*
* @param string $name The name of the hydration mode.
* @param string $class The class name associated with the name.
* @param string $modeName The hydration mode name.
* @param string $hydrator The hydrator class name.
*/
public function addHydrator($name, $class)
public function addCustomHydrationMode($modeName, $hydrator)
{
$this->_attributes['customHydrators'][$name] = $class;
$this->_attributes['customHydrationModes'][$modeName] = $hydrator;
}
}
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/EntityManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ public function newHydrator($hydrationMode)
$hydrator = new Internal\Hydration\SingleScalarHydrator($this);
break;
default:
if ($class = $this->_config->getHydrator($hydrationMode)) {
if ($class = $this->_config->getCustomHydrationMode($hydrationMode)) {
$hydrator = new $class($this);
break;
}
Expand Down
25 changes: 13 additions & 12 deletions tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,22 @@

class CustomHydratorTest extends HydrationTestCase
{
public function testCustomHydrator()
{
$em = $this->_getTestEntityManager();
$config = $em->getConfiguration();
$config->addHydrator('CustomHydrator', 'Doctrine\Tests\ORM\Hydration\CustomHydrator');

$hydrator = $em->newHydrator('CustomHydrator');
$this->assertTrue($hydrator instanceof \Doctrine\Tests\ORM\Hydration\CustomHydrator);
}
public function testCustomHydrator()
{
$em = $this->_getTestEntityManager();
$config = $em->getConfiguration();
$config->addCustomHydrationMode('CustomHydrator', 'Doctrine\Tests\ORM\Hydration\CustomHydrator');

$hydrator = $em->newHydrator('CustomHydrator');
$this->assertTrue($hydrator instanceof \Doctrine\Tests\ORM\Hydration\CustomHydrator);
$this->assertNull($config->getCustomHydrationMode('does not exist'));
}
}

class CustomHydrator extends AbstractHydrator
{
protected function _hydrateAll()
protected function _hydrateAll()
{
return $this->_stmt->fetchAll(PDO::FETCH_ASSOC);
}
return $this->_stmt->fetchAll(PDO::FETCH_ASSOC);
}
}

0 comments on commit bf9f7f8

Please sign in to comment.