Created
March 15, 2011 19:41
-
-
Save yethee/871301 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class DoctrineRepository extends \Doctrine\ORM\EntityRepository | |
{ | |
public function add($entity) | |
{ | |
$this->checkEntity($entity); | |
$this->_em->persist($entity); | |
} | |
public function remove($entity) | |
{ | |
$this->checkEntity($entity); | |
$this->_em->remove($entity); | |
} | |
private function checkEntity($entity) | |
{ | |
if (!is_object($entity)) { | |
throw new \UnexpectedValueException(sprintf( | |
'An object was expected, given %s.', gettype($entity))); | |
} | |
if (!$entity instanceOf $this->_class->name) { | |
throw new \UnexpectedValueException(sprintf( | |
'%s is not an instance of %s.', get_class($entity), $this->getEntityName())); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment