-
Notifications
You must be signed in to change notification settings - Fork 2k
Local Namespace #4079
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
Local Namespace #4079
Conversation
|
|
Sorry to be unclear, hope this helps. OSS = Open Source Software (edited original) Simplistic example, I create a new CI4 project and create a Model, Views, and Controller for basic management of Users. I brand it, add a license and publish it on GitHub. You think its great, clone it and serve it from your Docker instance. You decide you want a new route to return a JSON representation of a User, so you add the route in app/Config/Routes.php and create a new Obviously the above happens all the time, but what I'm interested in are tools either to assist with the process or mitigate the situations where the conflict happens. With this Does that help explain it? |
|
I don't think I understand the concept completely, yet. Is the OSS (which means Open Source Software, I think) in our case CodeIgniter itself, a ThirdParty Module or something totally different? It would be nice if you could provide an example with CodeIgniter (whatever use case) :-) |
|
@sfadschm Thanks for the reply! I think we crossed paths, see my reply above. |
|
Jup, 42 seconds :-D Thanks for the details, that makes it clear I think. Seems like a really useful addition to me. I think publishing whole apps instead of modules might/should be a thing and this will definitely ease the process. That's a +1 from my side. |
|
@MGatner I like this but I'd suggest adding an additional constant for LOCAL_NAMESPACE to be able to change the name if needed. I'd also add local directory in .gitignore so that it makes it easier for future framework development. I usually have some test controllers/models/entities when I'm doing framework changes so this one can be used to keep those files. |
|
I'm not sure if such functionality will make a lot of sense in real life cases. Not that the idea is wrong, but more like... changes made by developers to their projects are hard to predict and trying to handle them in this way (false sense of safety?) may be dangeous. I will stick to your example with user management. Let's say that we added something to the project's configuration file (maybe email address from which emails are sent during user registration). A new version comes out with new options in the config file, but we have our own version in "Locals", so after udate the whole component stops working because some new required config variables are missing. I don't thing that our own version of files in "Locals" can guarantee stability of the package we're using. If we're changing something in the the local version of package, then manual verification is always required during update. If project we're using have no build-in way to make some overrides in a not invasive manner, then there are small chances that we will be able to accomplist it in a safe way. I'm not saying no to this, but I have mixed feelings so far. |
|
@MGatner thanks for the explanations. I think I understand what you mean. You want to hard-code functionality that not everyone needs. Example based on your explanation Let's say we have a application with the following structure Next, we use the replace/extend tool. To whom we say that instead of the \CodeIgniter\CodeIgniter class, should use the \MGatner\GreatOSS\Core\CodeIgniter class. In class \MGatner\GreatOSS\Core\CodeIgniter, we first load routes from vendor/mgatner/great-oss/Config/Routes.php and then from APPPATH . Config/Routes.php As a result, little-used functionality is not added to the framework. OSS has its own directory. The end developer will still use the default application directory. |
@najdanovicivan Good idea! Also this will definitely be in .gitignore - still lots to implement, I just wanted to float the idea first. |
|
@michalsn Your logic is sound but I think it misses the point. This could be a tool for the end user, but really it is a tool for the penultimate user, the app developer. An analogy...
I will add about this analogy that the process I describe for the |
|
@iRedds Thanks for your comment. I believe you've just describe modules/libraries which, while very important to the future of the framework, already have good representation and are not really being addressed here. If I have misunderstood please correct me. |
|
@MGatner Perhaps my example looks like a module. But I tried to show interaction. It seems to me that what you are proposing is a private case. And if I were in your place, I would fork the framework and make the appropriate changes necessary to work correctly with my application. I think it would be better to conduct a survey among the users of the framework. |
|
@iRedds All opinions are worth hearing! In this case I'm not too worried about "extra unused functionality" because it amounts to one config value and a single Maybe I am not understanding the "class replacement tool" part of it, on how this is different from a module. We brought up class aliases as part of the framework but decided against them - maybe you're suggesting the same thing just implemented per project? I should add that I am already implementing this myself in projects, and will do so if we decided this does not belong as part of the framework. Right now I adding the namespace to Autoload config and then checking for the Composer autoload file in Common.php - see for example this project commit. It works fine, but I think we could expand the offering if it were part of the core - things like discovery priority over |
|
@MGatner Hmm... maybe I understood it in the wrong way... Others seem to be enthusiastic about it, so I guess it can be a useful feature. |
|
@MGatner I have an idea on how to handle this. Why hardcode composer loading to the local namespace only. Why don't we add additional property in Config/Autoload containing string array of namespace for which composer should be loaded So as we have Local in $composerPsr4 the framework will require `ROOTPATH . 'local/src/vendor/autoload.php', So in the end |
|
@najdanovicivan I see some merit to expanding the Composer autoload. If we're doing that it probably would make sense to make them actual file paths, instead of namespaces which don't technically have autoload - so in your example above it would be:
The Composer autoloading was one small extension of the larger goal: differentiating a preset modular namespace and giving it priority over |
|
@MGatner any movement on this? My personal opinion is that it adds some unnecessary complication to the app, but if I'm in the minority that's cool. Might be worth a discussion on the forums if we're still up in the air? |
|
I use this in my own open-source published apps. I am still baffled what people do without it, and believe it's an important feature for supporting developers who want to make "distributable apps". Maybe the thing to do would be to finish this PR in earnest and ask for updated reviews and opinions? |
| public $psr4 = [ | ||
| APP_NAMESPACE => APPPATH, // For custom app namespace | ||
| 'Config' => APPPATH . 'Config', | ||
| 'Local' => ROOTPATH . 'local/src', |
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.
| 'Local' => ROOTPATH . 'local/src', | |
| 'Local' => ROOTPATH . 'local', |
|
Well I haven't touched this. I still believe in it but it doesn't seem a priority to anyone else and it only takes me about 30s to set it up in my local apps so I'm going to consider this abandoned. |

Concept
Defines a third namespace sector for downstream application modification,
Local.Description
This is something I am starting to incorporate into my open-source applications. The problem this solves is something like this:
By defining a
Localnamespace that resides outside of the repository it allows for modifications while leaving the application code untouched. Think of this as the equivalent of applications using code in System without modifying it.This PR is the initial concept to feel out the maintainers and community before extending the concept deeper into the system code, User Guide, tests.
Checklist: