/** * @param User $owner * @return PageAnimal * @throws HistoryException */ public function create(User $owner) { $pageAnimalBranch = new PageAnimalBranch(); $pageAnimalBranch->setOwner($owner); $noms = file($this->fileLocator->locate('@AppBundle/Resources/noms-animaux/noms.txt')); $nom = trim($noms[rand(0, count($noms) - 1)]); $pageAnimalBranch->setCommit(new PageAnimalCommit(null, $nom, $this->timeService->now(), null, PageAnimal::DISPONIBLE, PageAnimal::MALE, null)); $this->doctrine->persist($pageAnimalBranch->getCommit()); $this->doctrine->persist($pageAnimalBranch); $this->doctrine->flush([$pageAnimalBranch->getCommit(), $pageAnimalBranch]); return self::fromBranch($pageAnimalBranch); }
public function preUpdate(LifecycleEventArgs $event) { $entity = $event->getEntity(); if ($entity instanceof IdentityPersistableInterface) { /** @var IdentityPersistableInterface $entity */ $entity->setModifiedAt($this->timeService->now()); // @codeCoverageIgnoreStart } else { if ($entity instanceof StatePersistableInterface) { throw new \Exception('Une instance de ' . StatePersistableInterface::class . ' ne doit pas être modifiée : ' . $entity); } } // @codeCoverageIgnoreEnd }
/** * @return DateTime */ public function now() { return $this->now != null ? clone $this->now : parent::now(); }