Insert path to class in composer, so I can remove it in “use” in php
Insert path to class in composer, so I can remove it in “use” in php
In this case I have multiple footer classes. Now I have to edit the "Moduler" file to switch footers. Is it possible to declare the version of the footer in composer and change the "use" path to something more static like:
use ModulesFooter;
And specify the version of the footer in composer like:
App\Helpers\Moduler\Modules\Views\Footer\Footer__2\Footer
This is the code I'm using right now
<?php namespace AppHelpersModuler;
use AppHelpersModulerModulesViewsFooterFooter__2Footer;
class Moduler
use Footer;
public function footer()
return $this->call_footer();
public static function instance()
return new Moduler();
use
1 Answer
1
You can use class aliases for this:
class_alias('AppHelpersModulerModulesViews\ooterFooter__2Footer', 'ModulesFooter');
You can put this in some file and include it automatically using files
setting in composer.json
.
files
composer.json
But honestly, it looks like really ugly magic and you (or someone else which will need to deal with that in future) will regret that. Use separate helper class and/or dependency injection instead - it will be more clear and predictable than magic traits driven by aliases.
Thanks You, I'll look forward other options
– Jeroen de Beer
Sep 4 '18 at 9:33
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy
I dont really understand your problem. But it seems like something which should be very simple to solve and u just over engineered it so u can use
use
and composer and everything else possible.– Itay Moav -Malimovka
Sep 3 '18 at 14:45