Bug #40449

DateTimeValidator doesn't work as expected

Added by Cedric Ziel about 9 years ago. Updated about 8 years ago.

Status:
Resolved
Priority:
Should have
Category:
Validation
Start date:
2012-08-30
Due date:
% Done:

100%

Estimated time:
PHP Version:
Has patch:
No
Complexity:

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()

#1

Updated by Cedric Ziel about 9 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 about 9 years ago

  • Category set to Validation
  • Assignee 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 about 9 years ago

  • Status changed from New to Needs Feedback
#4

Updated by Cedric Ziel about 9 years ago

I tested it with the DateTimeRange Validator; this one works.

#5

Updated by Cedric Ziel about 9 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 about 9 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 about 9 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 almost 9 years ago

  • Target version changed from 1.1.1 to 2052
#9

Updated by Irene Höppner almost 9 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 almost 9 years ago

  • Status changed from Accepted to Under Review
  • Assignee changed from Adrian Föder to Karsten Dambekalns
#11

Updated by Karsten Dambekalns almost 9 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
#12

Updated by Gerrit Code Review over 8 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 8 years ago

  • Status changed from Under Review to Resolved
#14

Updated by Karsten Dambekalns about 8 years ago

  • Target version changed from 2052 to 1.1.1

Also available in: Atom PDF