30 lines
678 B
PHP
30 lines
678 B
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Entity\Snip;
|
|
use App\Git\CustomGit;
|
|
use Symfony\Bundle\SecurityBundle\Security;
|
|
|
|
class SnipServiceFactory
|
|
{
|
|
|
|
public function __construct(
|
|
private readonly string $snipBasePath,
|
|
private readonly Security $security,
|
|
)
|
|
{
|
|
}
|
|
|
|
public function create(Snip $snip): SnipService
|
|
{
|
|
$git = new CustomGit();
|
|
$repoPath = sprintf('%s/%s', $this->snipBasePath, $snip->getId());
|
|
if (!is_dir($repoPath)) {
|
|
$repo = $git->init($repoPath);
|
|
} else {
|
|
$repo = $git->open($repoPath);
|
|
}
|
|
return new SnipService($repo, $this->security->getUser());
|
|
}
|
|
} |