Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add container handling to ResourceRelationServiceProxy #4198

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

bartlomiejmarszal
Copy link
Contributor

This change will allow using containers and configurable services in ResourceRelationServiceProxy

@bartlomiejmarszal bartlomiejmarszal requested review from a team, tikhanovichA, KirylHatalski, pnal, Karol-Stelmaczonek and viktar-dzmitryieu-tao and removed request for a team January 30, 2025 17:06
Copy link

github-actions bot commented Jan 30, 2025

Front-end summary Node 18

💯 Total ✅ Passed ⏭️ Skipped ❌ Failed
241 241 0 0

@bartlomiejmarszal bartlomiejmarszal changed the title feat: add container handling to /ResourceRelationServiceProxy feat: add container handling to ResourceRelationServiceProxy Jan 30, 2025
Comment on lines 99 to 104
if (
$this->getServiceManager()->has($serviceId)
|| $this->getServiceManager()->getContainer()->has($serviceId)
) {
return true;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bartlomiejmarszal there is no need for double checking, the DI container implementation also supports checking the legacy registry.

Suggested change
if (
$this->getServiceManager()->has($serviceId)
|| $this->getServiceManager()->getContainer()->has($serviceId)
) {
return true;
}
if ($this->getServiceManager()->getContainer()->has($serviceId)) {
return true;
}

@@ -65,6 +67,11 @@ public function findRelations(FindAllQuery $query): ResourceRelationCollection
}

foreach ($services as $serviceId) {
// Instead of throwing error when service does not exist, we just skip it
if (!$this->serviceExist($serviceId, $type)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better performance, rather than creating a new method, I suggest the following:

1 - create a variable $container = $this->getServiceManager()->getContainer() on the line 68.
2 - on the like 70, just to the following

if (!$container->has($serviceId)) {
    continue;
}

In this way, you do not need to keep calling service manager and container inside the foreach.

Copy link
Contributor

@gabrielfs7 gabrielfs7 Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, why do we need to do this check at all?

Better thinking about this, the service existing check is not required at all. Either we add or remove those services via DI or existing migrations, so the services must always exist.

If there is a corrupted installation that left a wrong service registered, the exception will be triggered, which is better than masking the error, but this is highly unlink to happen.

Comment on lines 90 to 94
try {
return $this->getServiceManager()->get($serviceId);
} catch (ServiceNotFoundException $exception) {
return $this->getServiceManager()->getContainer()->get($serviceId);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need for it, the container does it automatically for you :)

Suggested change
try {
return $this->getServiceManager()->get($serviceId);
} catch (ServiceNotFoundException $exception) {
return $this->getServiceManager()->getContainer()->get($serviceId);
}
return $this->getServiceManager()->getContainer()->get($serviceId);

}
}

private function serviceExist(string $serviceId, string $type): bool
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need this method as per better performance, you can apply this logic here https://github.com/oat-sa/tao-core/pull/4198/files#r1944649031

return true;
}

common_Logger::w(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you still want to log it (in the new place I mentioned), please use the proper LoggerService as this static call is not recommended. Thank you!

Copy link
Contributor

@gabrielfs7 gabrielfs7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better thinking about this, the service existing check is not required at all. Either we add or remove those services via DI or existing migrations, so the services must always exist.

If there is a corrupted installation that left a wrong service registered, the exception will be triggered, which is better than masking the error, but this is highly unlink to happen.

Copy link

Version

Target Version 54.33.0
Last version 54.32.1

There are 0 BREAKING CHANGE, 3 features, 1 fix

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants