Hi everybody. This is my first post on the forums, but I read you all almost every day. Last days I was playing arround implementing InjectionAwareInterface. Because of the code to implement it, is the same in almost every situation, i've done it in a Trait, and then I just have to use that Trait in the classes I want to implement it. Those classes are registered in the Di using an anonymous function. Then when I want an implementation I request them via $di->get('myClass'). I was diving into the github cphalcon zephir code (very nice code), and I found that every time a service is resolved by the Di, it checks if the resolved service is an implementation of InjectionAwareInterface, and if so, the SetDI(DiInterface $di) method is called. That's ok but, what if I want to access the Di inside the constructor of the requested class?. I've found that the Di instance isn't set yet, because not all constructors are fully called (I think). So I have to set it by calling $this->getDI(). Then after the service is resolved, the SetDI(DiInterface $di) is called, although this is already a valid instance. I've seen that when the same class extends Injectable, instead of implementing InjectionAwareInterface, I'm able to access the internal dependencyInjector in the constructor cause it's set in the magical get when it's requested. I'm not a zephir / php gurú, so my question is... how can I access that magical method if the class who extends it isn't resolved yet?. It's because Injectable is an abstract class and it lacks of constructor?. I know that in php, parent constructors are not called automatically if you implement one in the child class, and i've seen that that's not happening on zephir, it seems that parents constructors are authomatically called. When I extend Injectable, is this class available before the class who extends it is 'fully constructed'?
It would be nice if there were a call to an initialization method, in those classes who implement InjectionAwareInterface (same as dispatcher calls initialize() method in controllers), so we can initialize other objects via the dependency injector without worring about if the Di is already a valid instance.
Keep going developing Phalcon! It's a really nice framework with a very interesting code implementation. I'm a .NET and SqlServer developer, and if i didn't find Phalcon I weren't playing with php as much as I'm playing now. It's very funny to write code with it. Saludos desde España!