The following error occurs: Declaration of TelephoneConstraintValidator::initialize() must be compatible with ConstraintValidatorInterface::initialize(Symfony\Component\Validator\Context\ExecutionContextInterface $context) in TelephoneConstraintValidator.php on line 12

The class defines the following use statement:
use Symfony\Component\Validator\ExecutionContextInterface;

However the interface defines:
use Symfony\Component\Validator\Context\ExecutionContextInterface;

Comments

mpp created an issue. See original summary.

mpp’s picture

Status: Active » Needs review
StatusFileSize
new702 bytes
zaporylie’s picture

Which version of symfony/validator are you using? Which version of Drupal core? For symfony/validator:2.8 ConstraintValidatorInterface::initialize($context) expects $context to be typeof \Symfony\Component\Validator\ExecutionContextInterface

mpp’s picture

I'm using Drupal 8.4 (rc1) and indeed with that Symfony got upgraded from 2.4 to 3.2:

            "name": "symfony/validator",
            "version": "v3.2.13",
zaporylie’s picture

From 2.4? I thought 2.7 was requirement for 8.0.0.

I think maybe it's better to extend abstract Symfony\Component\Validator\ConstraintValidator than directly implement ConstraintValidatorInterface which should provide BC layer.

http://api.symfony.com/2.7/Symfony/Component/Validator/ConstraintValidat...
http://api.symfony.com/3.2/Symfony/Component/Validator/ConstraintValidat...

zaporylie’s picture

Status: Needs review » Needs work

Patch #2 makes module incompatible with D8.3 so changing status to Needs work.

Fatal error: Declaration of Drupal\telephone_validation\Plugin\Validation\Constraint\TelephoneConstraintValidator::initialize(Symfony\Component\Validator\Context\ExecutionContextInterface $context) must be compatible with Symfony\Component\Validator\ConstraintValidatorInterface::initialize(Symfony\Component\Validator\ExecutionContextInterface $context)

zaporylie’s picture

Status: Needs work » Needs review
StatusFileSize
new2 KB

I thought about something like this. What do you think @mpp?

zaporylie’s picture

Added Kernel test in #2907589: Create basic Kernel test to prove ValidtaionConstraint work which should catch Exceptions in TelephoneConstrainValidator. Requeued tests in #2 and #7

zaporylie’s picture

Tests are done. It was proven that #2 breaks BC and #7 works ok.

Leaving issue open for a day or two waiting for a comment/review.

  • zaporylie committed 807e05a on 8.x-2.x
    Issue #2907271 by zaporylie, mpp: Invalid use statement
    
zaporylie’s picture

Status: Needs review » Fixed

Committed and pushed to 8.x-2.x. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.