diff --git a/components/ILIAS/Style/Content/Service/class.InternalService.php b/components/ILIAS/Style/Content/Service/class.InternalService.php index cd65110b7b76..5bd625c91daa 100755 --- a/components/ILIAS/Style/Content/Service/class.InternalService.php +++ b/components/ILIAS/Style/Content/Service/class.InternalService.php @@ -1,7 +1,5 @@ - */ class InternalService { - protected InternalDataService $data; - protected InternalRepoService $repo; - protected InternalDomainService $domain; - protected InternalGUIService $gui; + protected static array $instance = []; + protected Container $DIC; public function __construct(Container $DIC) { - $this->data = new InternalDataService(); - - $this->repo = new InternalRepoService( - $this->data(), - $DIC->database(), - $DIC->filesystem()->web(), - $DIC->upload() - ); - $this->domain = new InternalDomainService( - $DIC, - $this->repo, - $this->data - ); - $this->gui = new InternalGUIService( - $DIC, - $this->data, - $this->domain - ); + $this->DIC = $DIC; } public function data(): InternalDataService { - return $this->data; + return self::$instance["data"] ??= new InternalDataService(); } public function repo(): InternalRepoService { - return $this->repo; + return self::$instance["repo"] ??= new InternalRepoService( + $this->data(), + $this->DIC->database(), + $this->DIC->filesystem()->web(), + $this->DIC->upload() + ); } public function domain(): InternalDomainService { - return $this->domain; + return self::$instance["domain"] ??= new InternalDomainService( + $this->DIC, + $this->repo(), + $this->data() + ); } public function gui(): InternalGUIService { - return $this->gui; + return self::$instance["gui"] ??= new InternalGUIService( + $this->DIC, + $this->data(), + $this->domain() + ); } } diff --git a/components/ILIAS/Style/Content/Service/class.Service.php b/components/ILIAS/Style/Content/Service/class.Service.php index 9a1bc4d16d86..bc8617837203 100755 --- a/components/ILIAS/Style/Content/Service/class.Service.php +++ b/components/ILIAS/Style/Content/Service/class.Service.php @@ -1,7 +1,5 @@ - */ class Service { protected Container $DIC; - protected InternalService $internal; - protected DomainService $domain; - protected GUIService $gui; + protected static array $instance = []; public function __construct(Container $DIC) { $this->DIC = $DIC; - - $this->internal = new InternalService($this->DIC); - $this->gui = new GUIService( - $this->internal - ); - $this->domain = new DomainService( - $this->internal - ); } - /** - * Internal service, do not use in other components - */ public function internal(): InternalService { - return $this->internal; + return self::$instance["internal"] ??= new InternalService($this->DIC); } public function gui(): GUIService { - return $this->gui; + return self::$instance["gui"] ??= new GUIService($this->internal()); } public function domain(): DomainService { - return $this->domain; + return self::$instance["domain"] ??= new DomainService($this->internal()); } }