[Flow] Constructor injection and IDE
Mathis Hoffmann
mathis at hoffpost.de
Fri Aug 9 21:22:51 CEST 2013
Hey Christian,
> What i usually do is, that I do my initialisation in the
> initializeObject function, which is invoked by Flow automatically.
>
Thank's, that did it for me. Maybe I should also generally switch from
using constructors to initializeObject ;)
> I am still a bit confused however, why constructor parameter should be
> an issue for your IDE. Basically when using Flow, you should never
> need to instantiate a class on you own. You can write a whole
> application without using the NEW Keyword once.
I most cases I also do not create objects by myself. But now I have come
across a situation where I need to do that. I wrote an evaluation-class
that takes a category-object that it should evaluate. Therefore I fetch
the category-objects from repository in my controller and then create an
evaluator-object for each category-object which are the passed on to the
view. I don't know how I could do that without using the new keyword..
I have just two other questions :)
1.) Is there a possibility to configure the datetime-format for the
DateTimeConverter globally? I don't want to do all that configuration
stuff in every controller. What I did now and what does work for me is
that I wrote mit own converter and gave it a higher priority than the
default one. But maybe there is an easier solution?
2.) I have the same problem with the float converter. I currently only
accepts numbers like 13.87, but I want it to accept 13.87 as well as
13,87 (which is the german format for that).
Do you or does anyone know how to do that easily?
Cheers
Mathis
>
> Am 09.08.2013 12:21, schrieb Mathis Hoffmann:
>> Hello Christian,
>>
>> thanks for your quick reply!
>>
>> But what you suggest is, as I understand everything right, not
>> constructor injection but only dependency injection in general. This
>> works in most cases but not if you have a constructor that uses the
>> injected properties. The problem is that this "standard dependency
>> injection" happens after my constructor is called. So if I for
>> example need a repository in my own constructor and call
>> $respository->findAll() I get an error that tells me that I must not
>> call findAll() on a non object. That's why I specifically need
>> constructor injection in this case.
>>
>> I'm not really shure weather what I just wrote ist absolutely right.
>> But looking into the generated proxy class I found that the proxy
>> first calls my original constructor and only afterwards injects the
>> properties: http://pastebin.com/GG5KAy4v
>>
>> Cheers
>> Mathis
>>
>> Am 09.08.2013 11:14, schrieb Christian Loock:
>>> Am 09.08.2013 11:08, schrieb Mathis Hoffmann:
>>>> ng constructor parameter. I tried to set a default value
>>>> (__construct(..,.., \My\Injected\Type $parameter = null)) but that
>>>> disabled constructor injection.Does anyone have a solution for that?
>>> I dont understand that exactly.
>>>
>>> When you use constructor injection, you dont have to declare
>>> anything at you constructor at all. At least if I understood the
>>> concept correctly.
>>>
>>> You use constructor injection by using the Inject Annotation like this:
>>>
>>> /**
>>> * @Flow\Inject
>>> * @var TYPO3\Flow\Object\ObjectManager
>>> protected $objectManager;
>>>
>>> You dont even need a constructor to get this work, since flow
>>> generates it in its proxy classes and does the injection magics in it.
>>>
>>> Im not 100% sure if this works for your example, but then also I
>>> dont get why you dont Inject everything else that gets passed to the
>>> constructor.
>>> _______________________________________________
>>> Flow mailing list
>>> Flow at lists.typo3.org
>>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
>>
>> _______________________________________________
>> Flow mailing list
>> Flow at lists.typo3.org
>> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
>
> _______________________________________________
> Flow mailing list
> Flow at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
More information about the Flow
mailing list