Config\Services is a class made to reduce huge code development on singleton. Unfortunately I have committed an error.
When repositoryFacade is got from getShared,
Services::repositoryFacade(Services::userRepository(), TRUE);
The code will fail and says:
Config\Services::repositoryFacade(): Return value must be of type App\Domain\Core\IRepositoryFacade, null returned
The following code has been set in app/Config/Service.php
public static function repositoryFacade(IRepository $repository, bool $getShared = false): IRepositoryFacade{
if ($getShared) {
return self::getSharedInstance('resourceFacade');
}
return new RepositoryFacade($repository);
}
public static function userRepository(bool $getShared = true): IRepository
{
if ($getShared) {
return self::getSharedInstance('userRepository');
}
return new UserRepository(model(UserModel::class));
}
RepositoryFacade is in infrastructure layer to serve IRepository domain interface one by one, while UserRepository is a concrete class in infrastructure layer, its duty is to let RepositoryFacade to perform ORM, without any touch to domain layer.
Is the getShared not useful at all? There is no error when TRUE value has been removed.
Services::repositoryFacade(Services::userRepository());