Created
March 7, 2018 13:30
-
-
Save belackriv/b1161696d6f8d6f6f4d1fc45f5f76478 to your computer and use it in GitHub Desktop.
Query Unit Of Work
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 | |
namespace App\Library\Mixin; | |
trait QueryUnitOfWorkMixin | |
{ | |
public function queryUow($className, array $properties) | |
{ | |
foreach($this->getEntityManager()->getUnitOfWork()->getScheduledEntityInsertions() as $entity){ | |
if(is_a($entity, $className)){ | |
$matches = true; | |
foreach($properties as $propertName => $value){ | |
$getMethodName = 'get'.ucfirst($propertName); | |
if(is_a($value, \DateTime::class)){ | |
if($entity->$getMethodName() != $value){ | |
$matches = false; | |
} | |
}else{ | |
if($entity->$getMethodName() !== $value){ | |
$matches = false; | |
} | |
} | |
} | |
if($matches){ | |
return $entity; | |
} | |
} | |
} | |
return null; | |
} | |
public function getUowInsertions($className) | |
{ | |
$entities = []; | |
foreach($this->getEntityManager()->getUnitOfWork()->getScheduledEntityInsertions() as $entity){ | |
if(is_a($entity, $className)){ | |
$entities[] = $entity; | |
} | |
} | |
return $entities; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment