/** * Create project * * @param string $name * @param User $owner * * @return project */ public function create($name, $owner, $budget, $description = '') { if (empty($name)) { throw new Exception('Project name cannot be empty!', 2000); } $this->_validateOwner($owner); $this->_validateBudget($budget); // Existing name $existing = $this->repo->findOneBy(array('name' => $name, 'budget' => $budget)); if (!is_null($existing)) { throw new Exception('Project name already registered within budget ("' . $budget->getName() . '")!', 2001); } $project = new project(); $project->setName($name); $project->setOwner($owner->getId()); $project->setBudget($budget); $project->setDescription($description); $this->_persistAndFlush($project); return $project; }