-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Replace Core Services #3943
Replace Core Services #3943
Conversation
This will be very useful feature. It will be great if we can also add the support to load Common.php from Code Modules as well. In my example I have the Template module which is used to manage frontend templates. It relies on overriding the view() method to load the appropriate view depending on currently set template. So i had to use App/Common.php but this will be much better if the file can be located inside the code module. Of course in such case only the method from first loaded file will be used as this will be handled with function_exists() method The implementation of this should be quite simple. We just need to check fi Common.php exist in any of the namespaces defined in Autoload $psr4 and just load the file from there |
I like this idea 👍 |
I'm a little uncomfortable building on top of Common.php. It has always seemed to me like a bit of a catch-all that should have better ways of handling. For example, we have a very nice |
To be more precise - I like the idea of extending services functionality. |
f6784cc
to
3643732
Compare
People in this thread check out my edit to the PR above, and new commits. |
The goal behind loading Common.php is to override the core function from framework. So this preloaded helper will have to be loaded before CI Common php. Also the idea is to have it autolad if it existi in module. So it might be better to have config for it in modules confguration. And then load helper from each module where it exist |
I understand the goal but the part I am wary of is scanning all namespaces for such a core file, some of whose functions might be used in scanning namespaces for files. Since Common.php amounts to a list of function definitions (identical to Helpers) I am proposing that we have a way to bootstrap pre-defined Helpers instead, and they can trump definitions in system/Common.php. We do need to maintain precedence though, so app/Common.php should always come first. Regardless of the implementation, I believe it is beyond the scope of this PR. I would recommend opening a new Issue (or PR if you have the time) to continue these thoughts. |
Thanks @michalsn @najdanovicivan Anything else for this PR? |
@MGatner I'm ok with all the changes here. Will this one be a BC as it requires changing the parent class in App/Config/Services ? |
@najdanovicivan I don't believe so. We aren't actually instantiating the class since the methods are static, so there should be no concerns about Anyone else think of how this might break? @michalsn ? |
@MGatner what will happen if App\Config\Services is not updated so it still extends Services instead of BaseService ? |
Everything will work fine. It will preclude third-party namespaces from superseding core services, since the methods will be accessible to |
We should be good. |
Ok then, It should all be good. |
@MGatner I just want to know what's the problem when modules and other namespaces cannot offer core service replacements? If the only way to replace a core service is to create a new version in the extended version |
@kenjis I don't understand your question. The point of this PR was to allow third-party namespaces to provide overriding core services. For example, prior to this PR if you wanted to use your own |
Im not 100% sure but 99 :D |
@element-code You can use |
I believe this is a valid point. @element-code have you confirmed the issue? I think the solution is for |
Jup, confirmed this, lets move to #4483 |
Right now the only way to replace a core service is to create a new version in the extended version app/Config/Services.php. This means that modules and other namespaces cannot offer service replacements.
The problem is twofold:
__callStatic
’s lookupThis PR provides a test case demonstrating the failure. If we want this as a "feature" (namespace replacement of core services) I could come back later and add it to this PR.EDIT: This PR now applies the changes necessary to replace core services from any namespace. I took a different approach than outlined above because
method_exists()
is stilltrue
for protected static methods yetis_callable()
is always true when there is a__callStatic()
definition. This PR changesConfig\Services
to extendBaseServices
which will skip anything defined inCodeIgniter\Config\Services
and thus force discovery. Class precedence (number 2 above) has also been reworked to this priority:App
, any other namespace,CodeIgniter
(system).