src/Factory/Validator/BirthdayVerifyValidatorFactory.php
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $services = $serviceLocator->getServiceLocator();

        /* @var $options InputFilterOptionsInterface */
        $options = $services->get(ModuleOptions::class);

        /* @var $userMapper \CmsUser\Persistence\UserMapperInterface */
        $userMapper = $services->get('MapperManager')->get($options->getUserEntityClass());
        $identityField = $services->get('FormElementManager')->get('CmsAuthenticationIdentity')->getName();

        $validatorChain = new ValidatorChain();
        $validatorChain->attachByName('Callback', [
            'messages' => [
                Callback::INVALID_VALUE => 'Your birthday is wrong. '
                    . 'Please provide the correct birthday',
            ],
            'callback' => function($value, $context = []) use ($userMapper, $identityField) {
                if (!empty($context[$identityField])) {
                    if ($identity = $userMapper->findByIdentity($context[$identityField])) {
                        return (new \DateTime($value)) == $identity->getBirthday();
                    }
                }
                return true;
            },
        ], true);

        return $validatorChain;
    }
public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $services = $serviceLocator->getServiceLocator();

        /* @var $options InputFilterOptionsInterface */
        $options = $services->get(ModuleOptions::class);

        /* @var $userMapper \CmsUser\Persistence\UserMapperInterface */
        $userMapper = $services->get('MapperManager')->get($options->getUserEntityClass());
        $identityField = $services->get('FormElementManager')->get('CmsAuthenticationIdentity')->getName();

        $validatorChain = new ValidatorChain();
        $validatorChain->attachByName('Callback', [
            'messages' => [
                Callback::INVALID_VALUE => 'Your birthday is wrong. '
                    . 'Please provide the correct birthday',
            ],
            'callback' => function($value, $context = []) use ($userMapper, $identityField) {
                if (!empty($context[$identityField])) {
                    if ($identity = $userMapper->findByIdentity($context[$identityField])) {
                        return (new \DateTime($value)) == $identity->getBirthday();
                    }
                }
                return true;
            },
        ], true);

        return $validatorChain;
    }
{@inheritDoc}

@return ValidatorInterface