-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat: Adding BaseService::updateServicesCache. Adds ablity to update Services Cache at runtime. #8896
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
Conversation
… new services class post Autoload.
@paulbalandan In this PR branch, (4.6-servicesreload $)$ composer update
Loading composer repositories with package information
Updating dependencies
Lock file operations: 0 installs, 1 update, 0 removals
- Downgrading codeigniter/phpstan-codeigniter (v1.4.3.70400 => v1.4.2.70400)
Writing lock file
Installing dependencies from lock file (including require-dev)
Package operations: 0 installs, 1 update, 0 removals
- Downgrading codeigniter/phpstan-codeigniter (v1.4.3.70400 => v1.4.2.70400): Extracting archive
Generating optimized autoload files
64 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
phpstan/extension-installer: Extensions installed
> codeigniter/phpstan-codeigniter: installed
> phpstan/phpstan-strict-rules: installed
infection/extension-installer: No extensions found
> CodeIgniter\ComposerScripts::postUpdate
> composer update --working-dir=tools/phpmetrics
Loading composer repositories with package information
Updating dependencies
Nothing to modify in lock file
Installing dependencies from lock file (including require-dev)
Nothing to install, update or remove
Generating autoload files
infection/extension-installer: No extensions found
No security vulnerability advisories found.
No security vulnerability advisories found. |
@@ -75,6 +75,9 @@ Helpers and Functions | |||
|
|||
Others | |||
====== | |||
- **Services:** Added ``BaseService::updateServicesCache`` method to allow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- **Services:** Added ``BaseService::updateServicesCache`` method to allow | |
+ | |
- **Services:** Added ``BaseService::updateServicesCache()`` method to allow |
There may be times when you need to have Service Discovery refresh it's cache after the inital autoload proccess. This can be done by running :php:meth:`Config\\Services::updateServicesCache()`. | ||
This will force the service discovery to re-scan the directories for any new services files. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about this?
There may be times when you need to have Service Discovery refresh it's cache after the inital autoload proccess. This can be done by running :php:meth:`Config\\Services::updateServicesCache()`. | |
This will force the service discovery to re-scan the directories for any new services files. | |
Updating Services Cache | |
======================= | |
.. versionadded:: 4.6.0 | |
When Services is first called fairly early in the framework initialization process, | |
the Services classes discovered by auto-discovery is cached in a property. | |
If modules are dynamically loaded later, this cache must be updated. | |
This can be done by running ``Config\Services::updateServicesCache()``. This will | |
force the service discovery to re-scan the directories for any new Services files. |
:php:meth:
is okay if there is the class reference for the method. But in this case, there is no class reference to link.Config\\Services::updateServicesCache()
Thank you for sending this!
Out of curiosity, what is your use case? |
So I'm currently designing ERP system for a customer of ours. With the project specs they gave. Everything needed to be modular and event driven for interactions between them. This is because they own multiple companies and each one has similar, but different needs and processes flows. However they also wanted to be able to turn on or off a module at will for the companies. So easiest way I figured I could approach this was to create a service that would determine which modules should get loaded and control their event priorities. I don't know if this best approach to fit there needs or how much of a impact it will have on the system as whole. So while setting up to do some testing. I decided put a call to this service in the routes file for right now. In the test I just used After drilling down I saw that classname cache only ever generates once unless you reset. So just figured why not add a "refresh" to look for anything new. |
I'm not sure, but isn't it better to just add a method to delete the cache? |
e8a59bb
to
56f1ed0
Compare
Sorry, meant to pull the changes in to develop and missed I didn't switch my branch over. Reverted that merge. If you empty $serviceNames, does that not break all the service functionality? Or are you talking about a different cache? |
We don't use |
I mean, just add a method like |
I sent another PR #9012 |
Closed by #9012 |
Description
Supersedes #8894
I need a different method to load Modules. I wanted to set it up so it was more database driven for enabling or disabling a module. This lead to problems with Services not being auto discovered by the buildServicesCache() function. As the autoloader doesn't know those files exist at the point it time it is called. Which results in any static calls to the any services class or service function would return null. So added a function that will update the service cache with and new Classes discovered since initial build.
Apologizes for previous PR. This contains the code, documentation, change log, code comments, and tests.
Checklist: