/** * @param string $nom * @param User $owner * @return PageEleveur * @throws HistoryException */ public function create($nom, User $owner) { if ($this->pageEleveurBranchRepository->findByOwner($owner)) { $this->logger->notice('', debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)); throw new HistoryException(HistoryException::DEJA_OWNER); } $commit = new PageEleveurCommit(null, $nom, null, null, null, null, null, null); $pageEleveurBranch = new PageEleveurBranch(); $pageEleveurBranch->setCommit($commit); try { $pageEleveurBranch->setSlug(static::slug($nom)); } catch (InvalidArgumentException $e) { throw new HistoryException(HistoryException::NOM_INVALIDE); } $pageEleveurBranch->setOwner($owner); if ($this->pageEleveurBranchRepository->findBySlug($pageEleveurBranch->getSlug())) { throw new HistoryException(HistoryException::SLUG_DEJA_EXISTANT); } $this->doctrine->persist($pageEleveurBranch->getCommit()); $this->doctrine->persist($pageEleveurBranch); $this->doctrine->flush([$pageEleveurBranch->getCommit(), $pageEleveurBranch]); return $this->fromBranch($pageEleveurBranch); }