Skip to content

Instantly share code, notes, and snippets.

@TiMESPLiNTER
Created February 24, 2015 07:58
Show Gist options
  • Save TiMESPLiNTER/dfc8d2ac570481520f12 to your computer and use it in GitHub Desktop.
Save TiMESPLiNTER/dfc8d2ac570481520f12 to your computer and use it in GitHub Desktop.
Doctrine2 helper methods
<?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