Start on removing git and better integrate db
This commit is contained in:
@ -3,48 +3,17 @@
|
||||
namespace App\Service;
|
||||
|
||||
use App\Entity\Snip;
|
||||
use App\Git\CustomGit;
|
||||
use App\Service\SnipContent\SnipContentDB;
|
||||
use App\Service\SnipContent\SnipContentGit;
|
||||
use App\Service\SnipContent\SnipContentInterface;
|
||||
use App\Service\SnipContent\SnipContentService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\SecurityBundle\Security;
|
||||
|
||||
class SnipServiceFactory
|
||||
{
|
||||
public function __construct(
|
||||
private readonly string $gitStoragePath,
|
||||
private readonly string $storageType,
|
||||
private readonly Security $security,
|
||||
private readonly EntityManagerInterface $em,
|
||||
) {}
|
||||
|
||||
public function create(Snip $snip): SnipContentInterface
|
||||
public function create(Snip $snip): SnipContentService
|
||||
{
|
||||
return match ($this->storageType) {
|
||||
'git' => $this->createGit($snip),
|
||||
'db' => $this->createDB($snip),
|
||||
default => throw new \Exception('Unknown storage type'),
|
||||
};
|
||||
}
|
||||
|
||||
private function createGit(Snip $snip): SnipContentGit
|
||||
{
|
||||
$git = new CustomGit();
|
||||
$repoPath = sprintf('%s/%s', $this->gitStoragePath, $snip->getId());
|
||||
if (!is_dir($repoPath)) {
|
||||
$repo = $git->init($repoPath);
|
||||
touch(sprintf('%s/.gitignore', $repoPath));
|
||||
$repo->addFile('.gitignore');
|
||||
$repo->commit('Initial commit');
|
||||
} else {
|
||||
$repo = $git->open($repoPath);
|
||||
}
|
||||
return new SnipContentGit($repo, $this->security->getUser());
|
||||
}
|
||||
|
||||
private function createDB(Snip $snip): SnipContentDB
|
||||
{
|
||||
return new SnipContentDB($snip, $this->security->getUser(), $this->em);
|
||||
return new SnipContentService($snip, $this->em);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user