Skip to content

Commit

Permalink
chore: Revert using repository services in Bags constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
ambroisemaupate committed Feb 12, 2024
1 parent 173a4fb commit 256acf0
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
8 changes: 7 additions & 1 deletion lib/RoadizCoreBundle/src/Bag/NodeTypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,26 @@

namespace RZ\Roadiz\CoreBundle\Bag;

use Doctrine\Persistence\ManagerRegistry;
use RZ\Roadiz\Bag\LazyParameterBag;
use RZ\Roadiz\Contracts\NodeType\NodeTypeResolverInterface;
use RZ\Roadiz\CoreBundle\Entity\NodeType;
use RZ\Roadiz\CoreBundle\Repository\NodeTypeRepository;

final class NodeTypes extends LazyParameterBag implements NodeTypeResolverInterface
{
public function __construct(private readonly NodeTypeRepository $repository)
private ?NodeTypeRepository $repository = null;

public function __construct(private readonly ManagerRegistry $managerRegistry)
{
parent::__construct();
}

public function getRepository(): NodeTypeRepository
{
if (null === $this->repository) {
$this->repository = $this->managerRegistry->getRepository(NodeType::class);
}
return $this->repository;
}

Expand Down
11 changes: 7 additions & 4 deletions lib/RoadizCoreBundle/src/Bag/Roles.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,18 @@

final class Roles extends LazyParameterBag
{
public function __construct(
private readonly RoleRepository $repository,
private readonly ManagerRegistry $managerRegistry
) {
private ?RoleRepository $repository = null;

public function __construct(private readonly ManagerRegistry $managerRegistry)
{
parent::__construct();
}

public function getRepository(): RoleRepository
{
if (null === $this->repository) {
$this->repository = $this->managerRegistry->getRepository(Role::class);
}
return $this->repository;
}

Expand Down
16 changes: 11 additions & 5 deletions lib/RoadizCoreBundle/src/Bag/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@

namespace RZ\Roadiz\CoreBundle\Bag;

use Doctrine\Persistence\ManagerRegistry;
use RZ\Roadiz\Bag\LazyParameterBag;
use RZ\Roadiz\CoreBundle\Entity\Document;
use RZ\Roadiz\CoreBundle\Entity\Setting;
use RZ\Roadiz\CoreBundle\Repository\DocumentRepository;
use RZ\Roadiz\CoreBundle\Repository\SettingRepository;
use Symfony\Component\Stopwatch\Stopwatch;

final class Settings extends LazyParameterBag
class Settings extends LazyParameterBag
{
private ?SettingRepository $repository = null;

public function __construct(
private readonly SettingRepository $repository,
private readonly DocumentRepository $documentRepository,
private readonly ManagerRegistry $managerRegistry,
private readonly Stopwatch $stopwatch
) {
parent::__construct();
}

public function getRepository(): SettingRepository
{
if (null === $this->repository) {
$this->repository = $this->managerRegistry->getRepository(Setting::class);
}
return $this->repository;
}

Expand Down Expand Up @@ -63,7 +67,9 @@ public function getDocument(string $key): ?Document
{
try {
$id = $this->getInt($key);
return $this->documentRepository->findOneById($id);
return $this->managerRegistry
->getRepository(Document::class)
->findOneById($id);
} catch (\Exception $e) {
return null;
}
Expand Down

0 comments on commit 256acf0

Please sign in to comment.