public function findOneFolderByPath($path) { //Find a folder entity in db $folder = $this->folderRepo->findOneByPath($path); if (!$folder) { $class = $this->folderRepo->getClassName(); $folder = new $class(); $folder->setName(basename($path)); $folder->setPath($path); $this->em->persist($folder); } return $folder; }