mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-12 13:24:25 +00:00
minor changes review: comments removed, logicexception, more test cases passed
This commit is contained in:
parent
7dd42c3fa2
commit
aa852ec924
@ -7,14 +7,13 @@ namespace Chill\PersonBundle\EventListener;
|
||||
use Chill\PersonBundle\Entity\Person;
|
||||
use Chill\PersonBundle\Entity\PersonAltName;
|
||||
use Doctrine\Persistence\Event\LifecycleEventArgs;
|
||||
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
|
||||
use LogicException;
|
||||
use Symfony\Component\Validator\Exception\LogicException as ExceptionLogicException;
|
||||
|
||||
class PersonEventListener
|
||||
{
|
||||
public function onPrePersist(LifecycleEventArgs $event): void
|
||||
{
|
||||
// $em = $event->getObjectManager();
|
||||
|
||||
if($event->getObject() instanceof Person){
|
||||
|
||||
$person = $event->getObject();
|
||||
@ -25,22 +24,16 @@ class PersonEventListener
|
||||
$lastnameCaps = mb_strtoupper($person->getLastName(), 'UTF-8');
|
||||
$person->setLastName($lastnameCaps);
|
||||
|
||||
|
||||
// $em->persist($person);
|
||||
// $em->flush();
|
||||
|
||||
} elseif ($event->getObject() instanceof PersonAltName){
|
||||
|
||||
$altname = $event->getObject();
|
||||
$altnameCaps = ucwords(strtolower($altname->getLabel()), " \t\r\n\f\v'-");
|
||||
$altnameCaps = mb_convert_case(mb_strtolower($altname->getLabel()), MB_CASE_TITLE, 'UTF-8');
|
||||
$altnameCaps = ucwords(strtolower($altnameCaps), " \t\r\n\f\v'-");
|
||||
$altname->setLabel($altnameCaps);
|
||||
|
||||
// $em->persist($altname);
|
||||
// $em->flush();
|
||||
|
||||
} else {
|
||||
|
||||
throw new NotFoundHttpException('Entity must be a person or an altname');
|
||||
throw new LogicException('Entity must be a person or an altname');
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -63,6 +63,8 @@ class PersonCreateEventTest extends TestCase
|
||||
{
|
||||
yield ['vinCENT', 'Vincent'];
|
||||
yield ['jean-marie', 'Jean-Marie'];
|
||||
yield ['fastré', 'Fastré'];
|
||||
yield ['émile', 'Émile'];
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user