Bug #40449
DateTimeValidator doesn't work as expected
Status: | Resolved | Start date: | 2012-08-30 | |
---|---|---|---|---|
Priority: | Should have | Due date: | ||
Assigned To: | Karsten Dambekalns | % Done: | 100% |
|
Category: | Validation | |||
Target version: | TYPO3 Flow Base Distribution - 1.1.1 | |||
PHP Version: | Complexity: | |||
Has patch: | No | Affected Flow version: | FLOW3 1.1.0 |
Description
I have a fairly simple Model which has a property $date:
/** * The actual date of the transaction * @var \DateTime * @FLOW3\Validate(type="DateTime") */ protected $date;
My thoughts were to use the DateTime Validator bundled with TYPO3.FLOW3.
If I submit the form and (of what I understood, the validators do some serious business..) I get an error:
Invalid validate annotation in Cziel\F3finances\Domain\Model\Transaction::date: Could not resolve class name for validator "DateTime"
Stacktrace:
TYPO3\FLOW3\Validation\ValidatorResolver_Original::buildBaseValidatorConjunction("Cziel\F3finances\Domain\Model\Transaction##Default##Controller", "Cziel\F3finances\Domain\Model\Transaction", array) 17 TYPO3\FLOW3\Validation\ValidatorResolver_Original::getBaseValidatorConjunction("Cziel\F3finances\Domain\Model\Transaction", array) 16 TYPO3\FLOW3\Mvc\Controller\ActionController_Original::initializeActionMethodValidators() 15 TYPO3\FLOW3\Mvc\Controller\ActionController_Original::processRequest(TYPO3\FLOW3\Mvc\ActionRequest, TYPO3\FLOW3\Http\Response) 14 TYPO3\FLOW3\Mvc\Dispatcher_Original::dispatch(TYPO3\FLOW3\Mvc\ActionRequest, TYPO3\FLOW3\Http\Response) 13 TYPO3\FLOW3\Mvc\Dispatcher::dispatch(TYPO3\FLOW3\Mvc\ActionRequest, TYPO3\FLOW3\Http\Response) 12 call_user_func_array(array, array) 11 TYPO3\FLOW3\Mvc\Dispatcher::FLOW3_Aop_Proxy_invokeJoinPoint(TYPO3\FLOW3\Aop\JoinPoint) 10 TYPO3\FLOW3\Aop\Advice\AdviceChain::proceed(TYPO3\FLOW3\Aop\JoinPoint) 9 TYPO3\FLOW3\Security\Aspect\RequestDispatchingAspect_Original::setAccessDeniedResponseHeader(TYPO3\FLOW3\Aop\JoinPoint) 8 TYPO3\FLOW3\Aop\Advice\AroundAdvice::invoke(TYPO3\FLOW3\Aop\JoinPoint) 7 TYPO3\FLOW3\Aop\Advice\AdviceChain::proceed(TYPO3\FLOW3\Aop\JoinPoint) 6 TYPO3\FLOW3\Security\Aspect\RequestDispatchingAspect_Original::blockIllegalRequestsAndForwardToAuthenticationEntryPoints(TYPO3\FLOW3\Aop\JoinPoint) 5 TYPO3\FLOW3\Aop\Advice\AroundAdvice::invoke(TYPO3\FLOW3\Aop\JoinPoint) 4 TYPO3\FLOW3\Aop\Advice\AdviceChain::proceed(TYPO3\FLOW3\Aop\JoinPoint) 3 TYPO3\FLOW3\Mvc\Dispatcher::dispatch(TYPO3\FLOW3\Mvc\ActionRequest, TYPO3\FLOW3\Http\Response) 2 TYPO3\FLOW3\Http\RequestHandler::handleRequest() 1 TYPO3\FLOW3\Core\Bootstrap::run()
Associated revisions
[BUGFIX] Make use of DateTimeValidator possible
When one used Validate(type="DateTime") the ValidatorResolver would try
to use DateTime as the validator itself. This change fixes that.
Change-Id: I5506e8f989b83b201a0c0e820261a9c97a3f514d
Fixes: #40449
Releases: master, 2.0, 1.1
[BUGFIX] Make use of DateTimeValidator possible
When one used Validate(type="DateTime") the ValidatorResolver would try
to use DateTime as the validator itself. This change fixes that.
Change-Id: I5506e8f989b83b201a0c0e820261a9c97a3f514d
Fixes: #40449
Releases: master, 2.0, 1.1
[BUGFIX] Make use of DateTimeValidator possible
When one used Validate(type="DateTime") the ValidatorResolver would try
to use DateTime as the validator itself. This change fixes that.
Change-Id: I5506e8f989b83b201a0c0e820261a9c97a3f514d
Fixes: #40449
Releases: master, 2.0, 1.1
History
#1 Updated by Cedric Ziel almost 3 years ago
I just wanted to add, that I think, I am using Validators the right way.. others do their job just as "NotEmpty".
If I missed something, please help me with more Information on this specific validator..
#2 Updated by Adrian Föder almost 3 years ago
- Category set to Validation
- Assigned To set to Adrian Föder
This is indeed strange, what you did Looks perfectly correct as far as I can see.
Are you sure your code snippet is exactly the one that FLOW3 is currently working on?
Do you have own validators running, and, just to go very sure; your source is complete and not modified in any way, especially regarding the DateTime validator?
What happens, for example, if you replace it with the DateTimeRange validator?
Thanks for your Feedback!
#3 Updated by Adrian Föder almost 3 years ago
- Status changed from New to Needs Feedback
#4 Updated by Cedric Ziel almost 3 years ago
I tested it with the DateTimeRange Validator; this one works.
#5 Updated by Cedric Ziel almost 3 years ago
Well, I verified this one according to your questions:
- Yes, this is the actual snippet, that is being processed.
- I have no own validators running, which could confuse the resolver
- No modifications
- The DateTimeRangeValidator is being found by the resolver, such as NotEmpty Validator for example.
#6 Updated by Adrian Föder almost 3 years ago
- Status changed from Needs Feedback to Accepted
Cedric, thanks for your information. I will check if I can reproduce it with a Functional Test, because I have no clue why this is...
#7 Updated by Karsten Dambekalns almost 3 years ago
- Target version set to 1.1.1
I think I know what is wrong… This is the code in resolveValidatorObjectName()
inside ValidatorResolver
. The first if is TRUE, as DateTime
is known. But it fails the check for implementing ValidatorInterface
a few lines down…
if ($this->objectManager->isRegistered($validatorType)) { $possibleClassName = $validatorType; } else { if (strpos($validatorType, ':') !== FALSE) { list($packageName, $packageValidatorType) = explode(':', $validatorType); $possibleClassName = sprintf('%s\Validation\Validator\%sValidator', str_replace('.', '\\', $packageName), $this->getValidatorType($packageValidatorType)); } else { $possibleClassName = sprintf('TYPO3\FLOW3\Validation\Validator\%sValidator', $this->getValidatorType($validatorType)); } if (!$this->objectManager->isRegistered($possibleClassName)) { return FALSE; } }
Could you check what $possibleClassName
is found after this block of code?
#8 Updated by Karsten Dambekalns over 2 years ago
- Target version changed from 1.1.1 to 2052
#9 Updated by Irene Höppner over 2 years ago
The $possibleClassName found is 'DateTime' instead of 'TYPO3\Flow\Validation\Validator\DateTimeValidator'. That means the first if statement of that block finds the php class 'DateTime' registered and thus doesn't do the resolving in the else part.
I'm going to create a test and a patch for that. Should I check for 'DateTime' explicitly or do have an idea for a more general approach?
#10 Updated by Karsten Dambekalns over 2 years ago
- Status changed from Accepted to Under Review
- Assigned To changed from Adrian Föder to Karsten Dambekalns
#11 Updated by Karsten Dambekalns over 2 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 0a4f1ca4260156fd981bf642048e3f825158887a.
#12 Updated by Gerrit Code Review over 2 years ago
- Status changed from Resolved to Under Review
Patch set 2 for branch FLOW3-1.1 has been pushed to the review server.
It is available at https://review.typo3.org/17546
#13 Updated by Karsten Dambekalns about 2 years ago
- Status changed from Under Review to Resolved
#14 Updated by Karsten Dambekalns almost 2 years ago
- Target version changed from 2052 to 1.1.1