blynx Posted December 2, 2016 Posted December 2, 2016 Hi, given there is a class with some namespace like "Super\Project\NiceClass", how could I put that class into a module so that when I load that module via "$nice = $modules->get('NiceClass')", $nice is an instance of that class. I think thats simple but failed somehow - I tried to return the instance in the constructor or in the init() function, also in a separate function of that module - but had no luck. Any hint would be nice, thanks!
LostKobrakai Posted December 3, 2016 Posted December 3, 2016 Your NiceClass does need to be the module class, too. $modules->get() will only ever return module instances and nothing else. If you cannot control NiceClass you can always create a module that acts as an Interface/EntryPoint into NiceClass.
blynx Posted December 3, 2016 Author Posted December 3, 2016 Yup yup, actually I also think it's quite odd what I wanted to do from the languages standpoint. I had a look into this discussion then: http://stackoverflow.com/questions/7026487/how-to-add-methods-dynamically I haven't tried anything of that stuff there since I just use the class directly now, but maybe it is somehow possible with __call() and http://php.net/manual/en/function.get-class-methods.php
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now