src/Charcoal/User/AbstractUser.php
public function validate(ValidatorInterface &$v = null)
    {
        $result = parent::validate($v);
        $objType = self::objType();
        $previousModel = $this->modelFactory()->create($objType)->load($this->id());

        $email = $this->email();
        if (empty($email)) {
            $this->validator()->error(
                'Email is required.',
                'email'
            );
        } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $this->validator()->error(
                'Email format is incorrect.',
                'email'
            );
        /** Check if updating/changing email. */
        } elseif ($previousModel->email() !== $email) {
            $existingModel = $this->modelFactory()->create($objType)->loadFrom('email', $email);
            /** Check for existing user with given email. */
            if (!empty($existingModel->id())) {
                $this->validator()->error(
                    'This email is not available.',
                    'email'
                );
            }
        }

        return count($this->validator()->errorResults()) === 0 && $result;
    }
public function validate(ValidatorInterface &$v = null)
    {
        $result = parent::validate($v);
        $objType = self::objType();
        $previousModel = $this->modelFactory()->create($objType)->load($this->id());

        $email = $this->email();
        if (empty($email)) {
            $this->validator()->error(
                'Email is required.',
                'email'
            );
        } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
            $this->validator()->error(
                'Email format is incorrect.',
                'email'
            );
        /** Check if updating/changing email. */
        } elseif ($previousModel->email() !== $email) {
            $existingModel = $this->modelFactory()->create($objType)->loadFrom('email', $email);
            /** Check for existing user with given email. */
            if (!empty($existingModel->id())) {
                $this->validator()->error(
                    'This email is not available.',
                    'email'
                );
            }
        }

        return count($this->validator()->errorResults()) === 0 && $result;
    }
public function validate ( ValidatorInterface & $ v = null ) { $ result = parent :: validate ( $ v ) ; $ objType = self :: objType ( ) ; $ previousModel = $ this -> modelFactory ( ) -> create ( $ objType ) -> load ( $ this -> id ( ) ) ; $ email = $ this -> email ( ) ; if ( empty ( $ email ) ) { $ this -> validator ( ) -> error ( 'Email is required.' , 'email' ) ; } elseif ( ! filter_var ( $ email , FILTER_VALIDATE_EMAIL ) ) { $ this -> validator ( ) -> error ( 'Email format is incorrect.' , 'email' ) ; /** Check if updating/changing email. */ } elseif ( $ previousModel -> email ( ) !== $ email ) { $ existingModel = $ this -> modelFactory ( ) -> create ( $ objType ) -> loadFrom ( 'email' , $ email ) ; /** Check for existing user with given email. */ if ( ! empty ( $ existingModel -> id ( ) ) ) { $ this -> validator ( ) -> error ( 'This email is not available.' , 'email' ) ; } } return count ( $ this -> validator ( ) -> errorResults ( ) ) === 0 && $ result ; }
Validate the model.

@see   \Charcoal\Validator\ValidatorInterface
@param ValidatorInterface $v Optional. A custom validator object to use for validation. If null, use object's.
@return boolean
Validate the model .