[Flow] Using aspects to change EmailAddressValidator
Steffen Wickham
steffen at gaming-inc.de
Mon Jan 6 15:32:04 CET 2014
Hello Bastian, hello Pankaj,
first of all: thank you very much for your help! :)
I achieved a solution for my problem by changing the "isValid()" method
of ElectronicAddressValidator class of TYPO3.Party package via AOP. It
is no clean way, anyway it works at the moment.
I wrote an Aspect for the ElectronicAddressValidator which checks if the
argument "value" is of type Email, if it's true it checks its
identifiert against my own EmailAddressValidator (as seen in Flow 1.X)
and handle it's result. If the type of the given valie is not "Email",
it dispatch the request to the original function and procceed as normal
(except the included switch block will execute the default action
always). So that is my cleanest solution I could find. If you are
interested in my code, I could provide it. Please leave a comment on the
prefered web service as I#m not very familiar with it.
But I will have a look on the behaviour of AOP in conjunction with the
validatorResolver in a few days. There seems to be a bug which prevents
the framework to apply aspects to the called methods. Will keep you updated.
Thanks guys! :)
Am 06.01.14 12:00, schrieb Steffen Wickham:
> Hello Bastian,
>
> I aggree to achieve my changes in a clean way, but I can't afford it
> by my own atm. Using AOP doesn't work for me (and I still don't know
> why), using annotations is not suitable for me as the validator is
> called by TYPO3.Party package and therefore also 3rd party code and
> the total replacement of original implementations by using
> Objects.yaml does work on interfaces only. :-/
>
> So I'm totally stuck. I even had a look in Neos code which does rely
> on AOP in many ways but can't figure out why their code work and mine
> not. :-(
>
> Greetings
> Steffen
>
>
>
> Am 06.01.14 10:36, schrieb Bastian Waidelich:
>> Pankaj Lele wrote:
>>
>> Hi Steffen & Pankaj,
>>
>>> If you want a different EmailAddressValidator then instead of
>>> changing the existing EmailAddressValidator
>>> using AOP you can develop a new validator itself and use it
>>> directly. This would be a clean way.
>>
>> +1
>>
>> You can extend the original EmailAddressValidator[1] to
>> \Your\Package\Validation\Validator\EmailAddressValidator, override
>> its validEmail() method and refer to it via:
>>
>> @Flow\Validate(type="Your.Package:EmailAddress")
>>
>> If you want to change the behavior for 3rd party code you should be
>> able to replace the original implementation via Objects.yaml.
>>
>>
>>> Happy New Year!
>>
>> +2 ;)
>>
>>
>> [1]
>> https://git.typo3.org/Packages/TYPO3.Flow.git/blob/HEAD:/Classes/TYPO3/Flow/Validation/Validator/EmailAddressValidator.php
>>
>>
>
> _______________________________________________
> Flow mailing list
> Flow at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/flow
More information about the Flow
mailing list