php - PhalconPHP DI : Initializers -


I am currently testing phalcon php for a project, and I have a self-implemented interface.

An example, where a class applies Falcon \ di \ InjectionInterprefer , it will inject DI into that class automatically.

What I want to do is equal if there is Aranea \ Db \ DbAdapterAware for a class example, then in that class DBadaptor should be automatically injected. I'm doing something similar to Z Framework 2 (), where during D config, you can specify initial as follows:

  'initializers' = & gt; Array ('logger' => function ($ service, $ sm) {if ($ Server version of LoggerAwareInterface) {$ logger = $ sm-> Mill ('logger'); $ service-> set Logger ($ logger);}}),   

If it is not automatically possible in Falcon PHP, then I would like to override the factory defaults class I was thinking and implementing it myself, what would be the right place to inject this argument? Received * in ways, or instead set * in ways? I think that no method is initiated during the initialization of the DI, but on the first call, if found * will be more suitable?

Thanks for your advice,

Genoni FLECON \ DI \ INJECTIONEVER interface Applies. , It will inject the di automatically into that class.

This is not completely true, it means that DI is injected automatically, when this service is provided, it implements the interface, D is absolutely magical Does not appear in the form because the class implements some interfaces.

If there is a Aranea \ Db \ DbAdapterAware for an example of a class, then it should be automatically injected in that class to the DB adapter.

How does this work in a way (not technically) If your class Falcon \ di \ injection (or InjectionAwareInte RFS same way as Falcon \ Di \ injection ). Inside injection is a __ go magic, which provides service to DI if the service is present. In other words, the goods are injected into DI only, and other clients search for services there.

To inject your services, you can send them to DI in your configuration or expand DI or factory default . The difference between the two is that factory default is already configured with useful services, which you do not need though.

I think that no method is initiated during the DI, on the first call, what would be more appropriate?

Yes, there is a Falcon DI service object that represents the service and when it is resolved the first time called (if it is a shared service) Or solve every time (if it is not). You generally want all your services to be shared, otherwise it often becomes an obstacle, for example, when a non-shared database resolves the adapter, every time you call the connection Installs. |

PS: Note that you can do a few things for this to work as you want it from DBADEptter :

  1. Adapters Together and Return DI :: getDefault () - & gt; GetShared ('db') ;
  2. Increase Falcon \ di \ injection and set DI when the square is created, so it can look for services.
  3. Whenever you need an adapter, get it from the DI shown in the first option.

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -