Validate length.

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

@return bool Return true if it's valid or false if it's not
325366
protected function _validateLength(AnConfig $config)
    {
        $property = $config->property;
        $value = $config->value;
        $entity = $config->entity;
        $options = AnConfig::unbox($config->options);

        //if a number is just passed then treat it as max
        if (!is_array($options)) {
            $options = array('max' => $options);
        }

        if ($property->isAttribute() && $property->isScalar()) {

            $options = AnConfig::unbox($options);

            if (is_array($options)) {
                //check the min/max length
                if (isset($options['max']) || isset($options['min'])) {

                    if (isset($options['max'])) {

                        $greater = AnHelperString::strlen($value) > (int) $options['max'];

                        if ($greater) {

                            $entity->addError(array(
                                'message' => sprintf(
                                    AnTranslator::_('%s %s can not be greater than %d characters'),
                                    $this->getIdentifier()->name,
                                    $property->getName(),
                                    $options['max']
                                ),
                                'code' => AnError::INVALID_LENGTH,
                                'key' => $property->getName(),
                                'max_lenght' => $options['max'],
                            ));

                            return false;
                        }
                    }

                    if (isset($options['min'])) {

                        $lesser = AnHelperString::strlen($value) < (int) $options['min'];

                        if ($lesser) {

                            $entity->addError(array(
                                'message' => sprintf(
                                    AnTranslator::_('%s %s can not be less than %d characters'),
                                    $this->getIdentifier()->name,
                                    $property->getName(),
                                    $options['min']
                                ),
                                'code' => AnError::INVALID_LENGTH,
                                'key' => $property->getName(),
                                'min_length' => $options['min'],
                            ));

                            return false;
                        }
                    }
                }
            } else {

                if (AnHelperString::strlen($value) != (int) $options) {

                    $entity->addError(array(
                        'message' => sprintf(
                            AnTranslator::_('%s %s must be %d characters'),
                            $this->getIdentifier()->name,
                            $property->getName(),
                            $options
                        ),
                        'code' => AnError::INVALID_LENGTH,
                        'key' => $property->getName(),
                        'length' => (int) $options,
                    ));

                    return false;
                }
            }
        }

        return true;
    }
405249
protected function _initialize(AnConfig $config)
    {
        $permission = clone $this->getIdentifier();
        $permission->path = array($permission->path[0], 'permission');
        register_default(array('identifier' => $permission, 'prefix' => $this));

        $config->append(array(
            'behaviors' => array($permission),
            'request' => array('format' => 'html'),
        ))->append(array(
            'view' => $config->request->get ? $config->request->get : ($config->request->view ? $config->request->view : $this->getIdentifier()->name),
        ));

        parent::_initialize($config);
    }
475438
public function isValidCodeLengths($aCodeLengths)
    {
        $blValid = false;
        if ($this->_isNotEmptyArray($aCodeLengths)) {
            $blValid = $this->_isEachCodeLengthValid($aCodeLengths);
        }

        return $blValid;
    }
507157
protected function validate_length( $key = '' ) {
		if ( $this->check_length( $key ) === false ) {
			return $this->validate_length( md5( $key ) );
		}
		return $key;
	}
202276
private function isValidConfig(array $config)
    {
        foreach ($this->configAttributes as $attribute) {
            if (!array_key_exists($attribute, $config)) {
                return false;
            }
        }

        return !empty($config['path']);
    }
887275
public function check($config)
    {
        if ($this->key && !empty($config['allow_key']) && !in_array($this->key, $config['allow_key'])) {
            return false;
        }

        return true;
    }
447630
protected function maybeInvalidConfig(Config $config): ?Error
    {
        $groups = (array) $config->get('groups');

        return empty($groups)
            ? ResultFactory::makeError($this, ['***** Experimental *****', 'Groups is empty.'])
            : null;
    }
1325850
final protected function hasConfigs($config = null)
    {
        if (null !== $config) {
            return array_key_exists($config, self::$_configs);
        }

        return count(self::$_configs) > 0;
    }
12701
static public function validateClientConfig(array $config)
    {
        $tags = [static::T8700, static::T8915, static::T8914];

        foreach ($tags as $tag) {
            if (!array_key_exists($tag, $config) || empty($config[$tag])) {
                throw new InvalidArgumentException("Please configure value for tag " . $tag);
            }
        }
    }
648411
protected function _initialize(AnConfig $config)
    {
        parent::_initialize($config);

        if ($config->request->view) {
            $config->controller = $config->request->view;
        }
    }
892055
public function setCover($config)
    {
        $config = new AnConfig($config);

        $config->append(array(
                'mimetype' => 'image/jpeg',
        ));

        if ($config->url) {
            $config->append(array(
                'data' => file_get_contents($config->url),
            ));
        }

        $config->mimetype = strtolower($config->mimetype);

        // the allowed mimetypes
        $mimetypes = array(
            'image/jpeg' => 'jpg', 
            'image/png' => 'png'
        );

        // force mimetype to jpeg if invalid
        // @TODO is this wise ?? No it isn't, but until we find a more reliable method to detect mimetypes
        if (!isset($mimetypes[$config->mimetype])) {
            $config->mimetype = 'image/jpeg';
        }

        if ($config->data) {
            $data = $config->data;

            if (empty($data)) {
                return false;
            }

            $config->append(array(
                'image' => imagecreatefromstring($data),
            ));
        }

        $image = $config->image;

        if (empty($image)) {
            return false;
        }

        if ($this->persisted()) {
            $this->_mixer->removeCoverImage();
        }

        $images = $this->_mixer->resizeCoverImage($image);
        $this->_mixer->set('coverFilename', md5(uniqid('', true)).'.'.$mimetypes[$config->mimetype]);
        $this->_mixer->set('coverMimetype', $config->mimetype);

        $sizes = array();
        $files = array();

        foreach ($images as $key => $value) {
            $filename = $this->_mixer->getCoverFile($key);
            $sizes[$key] = $value['size'];
            $files[$filename] = AnHelperImage::output($value['data'], $config->mimetype);
        }

        imagedestroy($image);

        $this->_mixer->setValue('sizes', $sizes);
        $this->_pending_files[$this->_mixer] = $files;

        return true;
    }
748937
protected function _afterEntityInstantiate(AnConfig $config)
    {
        $data = $config->data;

        $data->append(array(
            'subscribers' => array()
        ));

        if ($data->object) {

            if (is($data->object, 'ComBaseDomainEntityComment')) {

                $data->comment = $data->object;
                $data->object = $data->comment->parent;

                $data->append(array(
                     'subscribers' => array($data->comment->author->id),
                ));

            } elseif ($data->object->isModifiable() && !is($data->object, 'ComActorsDomainEntityActor')) {

                $data->append(array(
                    'subscribers' => array($data->object->author->id),
                ));

            } elseif (is_person($data->object)) {

                $data->append(array(
                    'subscribers' => array($data->object->id),
                ));
            }

            if ($data->object->isOwnable()) {
                $data->target = $data->object->owner;
            }
        }

        if ($data->target && $data->target->isNotifiable()) {
            $data->append(array(
                'subscribers' => array($data->target->id),
            ));
        }

        parent::_afterEntityInstantiate($config);

        if ($config->data->subscribers) {
            $this->setSubscribers($config->data->subscribers);
        }
    }
844060
public static function has($key, $config = null)
    {
        $config = ($config === null) ? self::$config : $config;

        if (!isset($config[$key]) && !array_key_exists($key, $config)) {
            return false;
        }

        return true;
    }
574402
function isValidConfig(config) {
    return (config.root != null && config.root.length > 0) &&
            isNullOrFunction(config.directoryFilter) &&
            isNullOrFunction(config.filesFilter) &&
            isNullOrString(config.directoryFilterRegex) &&
            isNullOrString(config.filesFilterRegex);
}
72048
protected function _initialize(AnConfig $config)
    {
        $config->append(array(
            'cache' => true,
            'cache_key' => (string) $this->getIdentifier(),
        ));

        parent::_initialize($config);
    }
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);
    }
989302
protected function _initialize(AnConfig $config)
    {
        $package = $this->getIdentifier()->package;

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

        parent::_initialize($config);
    }