src/Factory/Validator/IdentityValidatorDelegatorFactory.php
public function createDelegatorWithName(
        ServiceLocatorInterface $validators,
        $name,
        $requestedName,
        $callback
    ) {
        $identityValidator = $callback();

        if (!$identityValidator instanceof ValidatorChain
            || $requestedName !== 'CmsAuthenticationIdentity'
        ) {
            return $identityValidator;
        }

        $services = $validators->getServiceLocator();

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

        $identityFields = $options->getIdentityFields();
        if ($identityFields == ['email']) {
            $identityValidator->prependByName('EmailAddress', [], true);
        } elseif ($identityFields == ['username']) {
            $identityValidator->prependByName('Alnum', [
                'messages' => [
                    Alnum::NOT_ALNUM => 'Incorrect identity. ' .
                    'Identity must contain alphanumeric characters without spaces',
                ],
                'allowWhiteSpace' => false,
            ], true);
        }

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

        $identityValidator->attachByName('Callback', [
            'messages' => [
                Callback::INVALID_VALUE => 'A record with the supplied identity could not be found',
            ],
            'callback' => function($value) use ($userMapper) {
                return (bool) $userMapper->findByIdentity($value);
            },
        ], true);

        return $identityValidator;
    }
public function createDelegatorWithName(
        ServiceLocatorInterface $validators,
        $name,
        $requestedName,
        $callback
    ) {
        $identityValidator = $callback();

        if (!$identityValidator instanceof ValidatorChain
            || $requestedName !== 'CmsAuthenticationIdentity'
        ) {
            return $identityValidator;
        }

        $services = $validators->getServiceLocator();

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

        $identityFields = $options->getIdentityFields();
        if ($identityFields == ['email']) {
            $identityValidator->prependByName('EmailAddress', [], true);
        } elseif ($identityFields == ['username']) {
            $identityValidator->prependByName('Alnum', [
                'messages' => [
                    Alnum::NOT_ALNUM => 'Incorrect identity. ' .
                    'Identity must contain alphanumeric characters without spaces',
                ],
                'allowWhiteSpace' => false,
            ], true);
        }

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

        $identityValidator->attachByName('Callback', [
            'messages' => [
                Callback::INVALID_VALUE => 'A record with the supplied identity could not be found',
            ],
            'callback' => function($value) use ($userMapper) {
                return (bool) $userMapper->findByIdentity($value);
            },
        ], true);

        return $identityValidator;
    }
public function createDelegatorWithName ( ServiceLocatorInterface $ validators , $ name , $ requestedName , $ callback ) { $ identityValidator = $ callback ( ) ; if ( ! $ identityValidator instanceof ValidatorChain || $ requestedName !== 'CmsAuthenticationIdentity' ) { return $ identityValidator ; } $ services = $ validators -> getServiceLocator ( ) ; /* @var $options InputFilterOptionsInterface */ $ options = $ services -> get ( ModuleOptions :: class ) ; $ identityFields = $ options -> getIdentityFields ( ) ; if ( $ identityFields == [ 'email' ] ) { $ identityValidator -> prependByName ( 'EmailAddress' , [ ] , true ) ; } elseif ( $ identityFields == [ 'username' ] ) { $ identityValidator -> prependByName ( 'Alnum' , [ 'messages' => [ Alnum :: NOT_ALNUM => 'Incorrect identity. ' . 'Identity must contain alphanumeric characters without spaces' , ] , 'allowWhiteSpace' => false , ] , true ) ; } /* @var $userMapper \CmsUser\Persistence\UserMapperInterface */ $ userMapper = $ services -> get ( 'MapperManager' ) -> get ( $ options -> getUserEntityClass ( ) ) ; $ identityValidator -> attachByName ( 'Callback' , [ 'messages' => [ Callback :: INVALID_VALUE => 'A record with the supplied identity could not be found' , ] , 'callback' => function ( $ value ) use ( $ userMapper ) { return ( bool ) $ userMapper -> findByIdentity ( $ value ) ; } , ] , true ) ; return $ identityValidator ; }
{@inheritDoc}

@return ValidatorInterface
{ @inheritDoc }