44
55namespace App \Utils ;
66
7- use App \Entity \ScreenLayout ;
87use App \Entity \Template ;
98use App \Enum \ResourceTypeEnum ;
109use App \Exceptions \NotImplementedException ;
1110use App \Model \ScreenLayoutData ;
1211use App \Model \TemplateData ;
12+ use App \Repository \ScreenLayoutRepository ;
13+ use App \Repository \TemplateRepository ;
1314use Doctrine \ORM \EntityManagerInterface ;
1415use JsonSchema \Constraints \Factory ;
1516use JsonSchema \SchemaStorage ;
2021readonly class ResourceLoader
2122{
2223 public function __construct (
23- private EntityManagerInterface $ entityManager ,
24+ private readonly EntityManagerInterface $ entityManager ,
25+ private readonly ScreenLayoutRepository $ screenLayoutRepository ,
26+ private readonly TemplateRepository $ templateRepository ,
2427 ) {}
2528
2629 public function getResourceJsonInDirectory (string $ path , string $ resourceType , ResourceTypeEnum $ type ): array
@@ -48,11 +51,9 @@ private function getResourceData(iterable $finder, string $resourceType, Resourc
4851
4952 switch ($ resourceType ) {
5053 case ScreenLayoutData::class:
51- $ repository = $ this ->entityManager ->getRepository (ScreenLayout::class);
5254 $ jsonSchemaObject = $ this ->getScreenLayoutJsonSchema ();
5355 break ;
5456 case TemplateData::class:
55- $ repository = $ this ->entityManager ->getRepository (Template::class);
5657 $ jsonSchemaObject = $ this ->getTemplateJsonSchema ();
5758 break ;
5859 default :
@@ -81,10 +82,10 @@ private function getResourceData(iterable $finder, string $resourceType, Resourc
8182 throw new \Exception ('The Ulid is not valid ' );
8283 }
8384
84- $ entity = $ repository ->findOneBy (['id ' => Ulid::fromString ($ content ->id )]);
85-
8685 switch ($ resourceType ) {
8786 case ScreenLayoutData::class:
87+ $ entity = $ this ->screenLayoutRepository ->find (Ulid::fromString ($ content ->id ));
88+
8889 $ results [] = new ScreenLayoutData (
8990 $ content ->id ,
9091 $ content ->title ,
@@ -98,6 +99,8 @@ private function getResourceData(iterable $finder, string $resourceType, Resourc
9899
99100 break ;
100101 case TemplateData::class:
102+ $ entity = $ this ->templateRepository ->find (Ulid::fromString ($ content ->id ));
103+
101104 $ results [] = new TemplateData (
102105 $ content ->id ,
103106 $ content ->title ,
0 commit comments