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
359623
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;
    }
1296045
protected function validateConfiguration($config)
    {
        $requiredFields = $this->getRequiredConfigurationFields();
        $missingFields = [];
        foreach ($requiredFields as $requiredField) {
            if (array_key_exists($requiredField, $config) === false) {
                $missingFields[] = $requiredField;
            }
        }
        if (count($missingFields) > 0) {
            throw new \RuntimeException('Some fields are not configured: ' . implode(', ', $missingFields));
        }
    }
672666
protected function validateConfiguration(array $config) : bool
    {
        if (!is_array($config)) {
            throw new DatabaseConnectionException('Could not load LDAP configuration settings.');
        }
        $config_keys = array_keys($config);
        $missing = array_diff(['server', 'port', 'domain', 'base_dn', 'username', 'password'], $config_keys);
        if (count($missing) > 0) {
            throw new DatabaseConnectionException('LDAP configuration missing ' . implode(', ', $missing));
        }
        return true;
    }
867120
protected function _applyRule($config)
    {
        if (!is_array($config)) {
            return false;
        }
        if (!$calssName = ArrayHelper::getValue($config, 'class')) {
            return false;
        }
        if (!class_exists($calssName)) {
            return false;
        }
        $rule = new $calssName;
        if (!$rule instanceof Rule) {
            return false;
        }

        if ($ruleExist = \Yii::$app->authManager->getRule($rule->name)) {
            return $ruleExist;
        }

        if (\Yii::$app->authManager->add($rule)) {
            return $rule;
        }

        return false;
    }
756022
protected static function _belongsTo(AnConfig $config)
    {
        $description = $config['description'];

        $config['child'] = $description->getEntityIdentifier();

        $config->append(array(
            'type_column' => AnInflector::underscore($config->name).'_type',
            'child_column' => AnInflector::underscore($config->name).'_id',
        ));

        if (is_string($config->type_column)) {
            $config->type_column = $description->getRepository()->getResources()->getColumn($config->type_column);
        }

        if (is_string($config->child_column)) {
            $config->child_column = $description->getRepository()->getResources()->getColumn($config->child_column);
        }

        if (!$config->child_column) {
            throw new AnDomainPropertyException('The '.$config->name.' belongs to relationship is missing a child column');
        }

        //if the relationship is not polymorphic the we need to set 
        //a parent if none is set
        if (!$config->polymorphic && !$config['parent']) {
            $parent = clone $description->getEntityIdentifier();
            $parent->name = $config['name'];
            $config->append(array(
                'parent' => $parent,
            ));
        }

        if (is_string($config->parent) && strpos($config->parent, '.') === false) {
            $parent = clone $description->getEntityIdentifier();
            $parent->name = $config->parent;
            $config->parent = $parent;
        }

        $relationship = AnDomainPropertyAbstract::getInstance('relationship.manytoone', $config);

        if ($config->inverse) {
            if (is_bool($config->inverse)) {
                $config['inverse'] = array();
            }

            $relationship->setInverse($config->inverse);
        }

        return $relationship;
    }
1195472
protected function _initialize(AnConfig $config)
    {
        if ($config->repository) {
            $config->append(array(
                'identifier' => $config->repository->getDescription()->getInheritanceColumnValue()->getIdentifier(),
                'node_type' => (string) $config->repository->getDescription()->getInheritanceColumnValue(),
                'commentable' => $config->repository->isCommentable(),
                'ownable' => $config->repository->isOwnable(),
                'hashtagable' => $config->repository->isHashtagable(),
                'geolocatable' => $config->repository->isGeolocatable()
            ));
        }

        parent::_initialize($config);
    }
964106
protected function isDatabaseConfigured(\OxidEsales\Eshop\Core\ConfigFile $config)
    {
        $isValid = true;

        // If the shop has not been configured yet the hostname has the format '<dbHost>'
        if (false  !== strpos($config->getVar('dbHost'), '<')) {
            $isValid = false;
        }

        return $isValid;
    }
34619
public function check(array $config): bool
    {
        try {
            if (Arr::get($config, 'default_connection', true)) {
                if (!$this->testConnection()) {
                    $this->message = trans('self-diagnosis::checks.redis_can_be_accessed.message.default_cache');
                    return false;
                }
            }

            foreach (Arr::get($config, 'connections', []) as $connection) {
                if (!$this->testConnection($connection)) {
                    $this->message = trans('self-diagnosis::checks.redis_can_be_accessed.message.named_cache', [
                        'name' => $connection,
                    ]);
                    return false;
                }
            }
        } catch (\Exception $e) {
            $this->message = $e->getMessage();
            return false;
        }

        return true;
    }
838925
protected function _initialize(AnConfig $config)
    {
        $identifier = clone $this->getIdentifier();

        $identifier->path = array();

        $paths[] = ANPATH_THEMES.DS.'base'.DS.$this->getFormat();
        $paths[] = ANPATH_BASE.dirname($identifier->filepath).DS.$this->getFormat();

        $config->append(array(
            'template_paths' => $paths,
        ));

        $params = '';

        if (is_readable($file = ANPATH_THEMES.DS.$this->getIdentifier()->package.DS.'params.ini')) {
            $params = parse_ini_file($file);
        }

        $config->append(array(
            'mimetype' => 'text/html',
            'params' => $params,
            'template_filters' => array('shorttag', 'html', 'alias'),
        ));

        parent::_initialize($config);
    }
9629
protected function _initialize(AnConfig $config)
    {
        $description = $this->_description;

        $properties = $description->getProperty();

        $validations = array();

        foreach ($properties as $property) {

            if ($property->isAttribute() && $property->getFormat()) {
                $validations[$property->getName()]['format'] = $property->getFormat();
            }

            if ($property->isSerializable() && $property->isRequired()) {
                $validations[$property->getName()]['required'] = true;
            }

            if ($property->isSerializable() && $property->isUnique()) {
                $validations[$property->getName()]['uniqueness'] = array('scope' => array());
            }
        }

        $config->append(array(
            'validations' => $validations,
        ));

        parent::_initialize($config);
    }
989302
protected function _initialize(AnConfig $config)
    {
        $package = $this->getIdentifier()->package;

        $config->append(array(
            'patterns' => array(
                '' => array('view' => $package),
            ),
        ));

        parent::_initialize($config);
    }
587604
protected function _initialize(AnConfig $config)
    {
        $base_url = AnRequest::base();
        $settings = $this->getService('com:settings.setting');

        if (PHP_SAPI == 'cli' && $settings->live_site != '') {
            $scheme = is_ssl() ? 'https://' : 'http://';
            $base_url = $scheme.$settings->live_site;
        }

        $config->append(array(
            'base_url' => $base_url,
            'test_options' => array(
                'enabled' => get_config_value('mailer.debug', false),
                'email' => get_config_value('mailer.redirect_email'),
                'log' => $settings->tmp_path . '/emails/',
            ),
            'template_view' => null,
        ));

        parent::_initialize($config);
    }
375427
protected function _initialize(AnConfig $config)
    {
        $identifier = clone $this->getIdentifier();

        $identifier->path = array('domain','repository');

        register_default(array('identifier' => $identifier, 'prefix' => $this));

        $config->append(array(
            'attributes' => array(),
            'relationships' => array(),
            'repository' => $identifier,
            'entity_identifier' => $this->getIdentifier(),
        ));

        parent::_initialize($config);
    }
728745
protected function _initialize(AnConfig $config)
    {
        $config->append(array(
            'max_upload_limit' => (int) ini_get('upload_max_filesize'),
        ));

        parent::_initialize($config);

        $config->append(array(
            'behaviors' => to_hash(array(
                'com:search.controller.behavior.searchable',
                'com:stories.controller.behavior.publisher',
                'com:notifications.controller.behavior.notifier',
                'followable',
                'administrable',
                'ownable',
                'privatable',
                'enablable',
                'verifiable',
                'subscribable',
                'com:hashtags.controller.behavior.hashtagable',
                'com:locations.controller.behavior.geolocatable',
                'coverable',
            )),
        ));

        $this->getService('anahita:language')->load('com_actors');
    }
912389
protected function _initialize(AnConfig $config)
    {
        $config->append(array(
            'viewer' => $this->getService('com:people.viewer'),
            'language' => 'com_'.$this->getIdentifier()->package,
            'behaviors' => to_hash('com:application.controller.behavior.message'),
        ));

        parent::_initialize($config);
    }
117274
protected function _initialize(AnConfig $config)
    {
		$config->append(array(
			'state' => self::STATE_ACTIVE,
			'expire' => LibSessionsDomainEntitySession::MAX_LIFETIME + time(),
			'security' => array('fix_browser'),
			'force_ssl' => is_ssl(),
			'namespace' => '__anahita',
			'storage' => 'database'
		));

		parent::_initialize($config);
	}
917050
private function checkConfig($config){
		$config = Hash::merge($this->configDef,$config);
		$this->include = $config['include'];
		unset($config['include']);
    	$this->config= $config;
	}