protected function _validateRequired(AnConfig $config)
    {
        $entity = $config->entity;
        $property = $config->property;
        $value = AnConfig::unbox($config['value']);
        $present = true;

        if ($entity->getEntityState() === AnDomain::STATE_DELETED) {
            return true;
        }

        //if the serial id is missing for a new entity, then don't validate
        //@TODO this causes no-incremental primary keys
        //to pass the validation. Need a new serial type the represet
        //incremental identity property
        if (
            $property === $entity->getEntityDescription()->getIdentityProperty() &&
            ! $entity->persisted())
        {
            return true;
        }

        if ($property->isAttribute()) {
            //if string and value can not be null
            //then return false if values are either empty strings
            //or just whitespace
            if (
                $property->getType() === 'string' &&
                $property->isRequired() === AnDomain::VALUE_NOT_EMPTY
            ) {

                //strip out html tags before measuring the lenght
                $value = strip_tags($value);

                //check if the value exists
                if (AnHelperString::strlen($value) <= 0 || ctype_space($value)) {

                    $entity->addError(array(
                        'message' => sprintf(
                            AnTranslator::_('%s %s can not be empty!'),
                            $entity->getIdentifier()->name,
                            $property->getName()
                        ),
                        'code' => AnError::MISSING_VALUE,
                        'key' => $property->getName(),
                    ));

                    return false;
                }

            } else {

                if ($property->isRequired() === AnDomain::VALUE_NOT_EMPTY) {
                    $present = !empty($value);
                } else {
                    $present = !is_null($value);
                }

            }

        } elseif ($property->isRelationship() && $property->isManyToOne()) {

            $present = !is_null($value);
            //if not null and the entity state is not new then check if it's serilized values are acceptable
            //i.e. not null or having an id = 0
            //is to prevent having non null mock objects. i.e. viewer as a guest
            //or an empty entity
            if ($present && $value->getEntityState() != AnDomain::STATE_NEW) {
                //check if the many to one object is null or not
                $values = $property->serialize($value);

                foreach ($values as $value) {

                    if (!$value) {
                        $present = false;
                        break;
                    }
                }
            }
        }

        if (!$present) {

            $entity->addError(array(
                'message' => sprintf(
                    AnTranslator::_('%s %s can not be empty!'),
                    $entity->getIdentifier()->name,
                    $property->getName()
                ),
                'code' => AnError::MISSING_VALUE,
                'key' => $property->getName(),
            ));

            return false;
        }

        return true;
    }
protected function _validateRequired(AnConfig $config)
    {
        $entity = $config->entity;
        $property = $config->property;
        $value = AnConfig::unbox($config['value']);
        $present = true;

        if ($entity->getEntityState() === AnDomain::STATE_DELETED) {
            return true;
        }

        //if the serial id is missing for a new entity, then don't validate
        //@TODO this causes no-incremental primary keys
        //to pass the validation. Need a new serial type the represet
        //incremental identity property
        if (
            $property === $entity->getEntityDescription()->getIdentityProperty() &&
            ! $entity->persisted())
        {
            return true;
        }

        if ($property->isAttribute()) {
            //if string and value can not be null
            //then return false if values are either empty strings
            //or just whitespace
            if (
                $property->getType() === 'string' &&
                $property->isRequired() === AnDomain::VALUE_NOT_EMPTY
            ) {

                //strip out html tags before measuring the lenght
                $value = strip_tags($value);

                //check if the value exists
                if (AnHelperString::strlen($value) <= 0 || ctype_space($value)) {

                    $entity->addError(array(
                        'message' => sprintf(
                            AnTranslator::_('%s %s can not be empty!'),
                            $entity->getIdentifier()->name,
                            $property->getName()
                        ),
                        'code' => AnError::MISSING_VALUE,
                        'key' => $property->getName(),
                    ));

                    return false;
                }

            } else {

                if ($property->isRequired() === AnDomain::VALUE_NOT_EMPTY) {
                    $present = !empty($value);
                } else {
                    $present = !is_null($value);
                }

            }

        } elseif ($property->isRelationship() && $property->isManyToOne()) {

            $present = !is_null($value);
            //if not null and the entity state is not new then check if it's serilized values are acceptable
            //i.e. not null or having an id = 0
            //is to prevent having non null mock objects. i.e. viewer as a guest
            //or an empty entity
            if ($present && $value->getEntityState() != AnDomain::STATE_NEW) {
                //check if the many to one object is null or not
                $values = $property->serialize($value);

                foreach ($values as $value) {

                    if (!$value) {
                        $present = false;
                        break;
                    }
                }
            }
        }

        if (!$present) {

            $entity->addError(array(
                'message' => sprintf(
                    AnTranslator::_('%s %s can not be empty!'),
                    $entity->getIdentifier()->name,
                    $property->getName()
                ),
                'code' => AnError::MISSING_VALUE,
                'key' => $property->getName(),
            ));

            return false;
        }

        return true;
    }
protected function _validateRequired ( AnConfig $ config ) { $ entity = $ config -> entity ; $ property = $ config -> property ; $ value = AnConfig :: unbox ( $ config [ 'value' ] ) ; $ present = true ; if ( $ entity -> getEntityState ( ) === AnDomain :: STATE_DELETED ) { return true ; } //if the serial id is missing for a new entity, then don't validate //@TODO this causes no-incremental primary keys //to pass the validation. Need a new serial type the represet //incremental identity property if ( $ property === $ entity -> getEntityDescription ( ) -> getIdentityProperty ( ) && ! $ entity -> persisted ( ) ) { return true ; } if ( $ property -> isAttribute ( ) ) { //if string and value can not be null //then return false if values are either empty strings //or just whitespace if ( $ property -> getType ( ) === 'string' && $ property -> isRequired ( ) === AnDomain :: VALUE_NOT_EMPTY ) { //strip out html tags before measuring the lenght $ value = strip_tags ( $ value ) ; //check if the value exists if ( AnHelperString :: strlen ( $ value ) <= 0 || ctype_space ( $ value ) ) { $ entity -> addError ( array ( 'message' => sprintf ( AnTranslator :: _ ( '%s %s can not be empty!' ) , $ entity -> getIdentifier ( ) -> name , $ property -> getName ( ) ) , 'code' => AnError :: MISSING_VALUE , 'key' => $ property -> getName ( ) , ) ) ; return false ; } } else { if ( $ property -> isRequired ( ) === AnDomain :: VALUE_NOT_EMPTY ) { $ present = ! empty ( $ value ) ; } else { $ present = ! is_null ( $ value ) ; } } } elseif ( $ property -> isRelationship ( ) && $ property -> isManyToOne ( ) ) { $ present = ! is_null ( $ value ) ; //if not null and the entity state is not new then check if it's serilized values are acceptable //i.e. not null or having an id = 0 //is to prevent having non null mock objects. i.e. viewer as a guest //or an empty entity if ( $ present && $ value -> getEntityState ( ) != AnDomain :: STATE_NEW ) { //check if the many to one object is null or not $ values = $ property -> serialize ( $ value ) ; foreach ( $ values as $ value ) { if ( ! $ value ) { $ present = false ; break ; } } } } if ( ! $ present ) { $ entity -> addError ( array ( 'message' => sprintf ( AnTranslator :: _ ( '%s %s can not be empty!' ) , $ entity -> getIdentifier ( ) -> name , $ property -> getName ( ) ) , 'code' => AnError :: MISSING_VALUE , 'key' => $ property -> getName ( ) , ) ) ; return false ; } return true ; }
Validate precense.

@param AnConfig $config Configuration. Contains keys property,value,entity

@return bool Return true if it's valid or false if it's not
Validate precense .