Created
February 24, 2015 07:58
-
-
Save TiMESPLiNTER/dfc8d2ac570481520f12 to your computer and use it in GitHub Desktop.
Doctrine2 helper methods
This file contains 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 | |
/** | |
* @author Pascal Muenst <dev@timesplinter.ch> | |
* @copyright Copyright (c) 2015, TiMESPLiNTER Webdevelopment | |
*/ | |
class DoctrineHelper | |
{ | |
/** | |
* @param EntityManager $entityManager The used entity manager instance | |
* @param object $entity The entity to log a new version for | |
* @param string $logVersionMethodName The method name of the entity class to log a new version | |
* | |
* @throws CommonException Thrown if the callback to log the new version is invalid | |
*/ | |
public static function logEntityVersion(EntityManager $entityManager, $entity, $logVersionMethodName = 'logVersion') | |
{ | |
if(is_callable(array($entity, $logVersionMethodName)) === false) | |
throw new CommonException('Version callback not callable: ' . get_class($entity) . '::' . $logVersionMethodName); | |
$entityManager->beginTransaction(); | |
$entityManager->flush(); | |
$entity->$logVersionMethodName(); | |
$entityManager->flush(); | |
$entityManager->commit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment