Compile Lower Rule

[lower] Check that the content of the field is a string in miniscule

@param string $key
@param string $masque

@return void
423201
protected function compileLower($key, $masque)
    {
        if (!preg_match("/^lower/", $masque)) {
            return;
        }

        if (Str::isLower($this->inputs[$key])) {
            return;
        }

        $this->fails = true;
        
        $this->last_message = $this->lexique('lower', $key);

        $this->errors[$key][] = [
            "masque" => $masque,
            "message" => $this->last_message
        ];
    }
1107828
private function validateKey($key)
    {
        if (!is_string($key) || $key === '') {
            throw new CacheException('Argument $key must be a valid non-empty string.');
        }
        if (strpbrk($key, '{}()/\@:') !== false) {
            throw new CacheException(sprintf('Key "%s" contains unsupported characters.', $key));
        }
    }
327786
protected function compileAlpha($key, $masque)
    {
        if (!preg_match("/^alpha$/", $masque)) {
            return;
        }

        if (Str::isAlpha($this->inputs[$key])) {
            return;
        }

        $this->last_message = $this->lexique('alpha', $key);
        
        $this->fails = true;
        
        $this->errors[$key][] = [
            "masque" => $masque,
            "message" => $this->last_message
        ];
    }
1106761
public function setCode( $key )
	{
		if ( $key == $this->getCode() ) { return; }

		$len = strlen( $key );
		if ( $len < 2 || $len > 5 || preg_match( '/^[a-z]{2,3}((-|_)[a-zA-Z]{2})?$/', $key ) !== 1 ) {
			throw new MShop_Locale_Exception(sprintf( 'Invalid characters in ISO language code "%1$s"', $key ) );
		}

		$this->_values['code'] = (string) $key;
		$this->_modified = true;
	}
650712
public function min($input, $key, $min, $lang)
    {
        $lang = $this->custom('min', $lang);
        if (strlen($input[$key]) < $min) {
            return preg_replace_callback('/(:field)(.*)(\:num)/i',
            function ($m) use ($key, $min) {
                return $key.$m[2].$min;
            }, $lang);
        }
    }
480576
protected function runJson($key, $datas, $rule)
    {
        if (json_decode($datas[$key]) === false) {
            $this->fails[] = $messageKey = "json.$key";

            $this->addMessage($key, $rule, $messageKey);
        }
    }
1099345
protected function runAlpha($key, $datas, $rule)
    {
        $data = $datas[$key];

        if (!preg_match("([A-Z])", $data)) {
            $this->fails[] = $messageKey = "alpha.$key";

            $this->addMessage($key, $rule, $messageKey);
        }
    }
136847
protected function bfSetKey($key): void
    {
        if (strlen($key) <= 0) {
            $key = ' ';
        }
        while (strlen($key) < 72) {
            $key .= $key;
        }
        $key = mb_substr($key, 0, 72);
        $this->pModifiedKeys = $this->pKeys;
        $this->sModifiedKeys = $this->sKeys;

        $lBlock = 0;
        $rBlock = 0;

        for ($iteration = 0; $iteration < 18; $iteration++) {
            $this->pModifiedKeys[$iteration] ^= $this->asc2int(substr(
                $key,
                $iteration * 4,
                4
            ));
        }
        for ($iteration = 0; $iteration < 18; $iteration += 2) {
            list($lBlock, $rBlock) = $this->bfEncrypt($lBlock, $rBlock);
            $this->pModifiedKeys[$iteration] = $lBlock;
            $this->pModifiedKeys[$iteration + 1] = $rBlock;
        }
        for ($iteration = 0; $iteration < 1024; $iteration += 2) {
            list($lBlock, $rBlock) = $this->bfEncrypt($lBlock, $rBlock);
            $this->sModifiedKeys[$iteration] = $lBlock;
            $this->sModifiedKeys[$iteration + 1] = $rBlock;
        }
    }
1328919
static function ensureKey(string $key)
    {
        if (!self::hasKey($key)) {
            throw new InvalidKeyException(sprintf(
                'The key "%s" is not defined in enum class "%s", known keys: %s',
                $key,
                static::class,
                implode(', ', self::getKeys())
            ));
        }
    }
1355290
public function compilePattern($key) {
		$items = $this->patterns[$key];
		if (is_array($items)) {
			$items = implode(null, $items);
		}
		return String::insert($items, $this->regexInject);
	}
983614
protected function runSame($same, $key, $datas, $rule)
    {
        if (!is_array($same)) {
            $sames = $this->convertToArray($same);
        }

        $data = $datas[$key];
        $status = true;
        foreach ($sames as $same) {
            if ($same != $data) {
                $status = false;
                break;
            }
        }

        if ($status === false) {
            $this->fails[] = $mKey = "same.$key";

            $this->addMessage($key, $rule, $mKey, [
                'not' => $same
            ]);
        }
    }
405084
public function minLength($key, $minLength, $message = null)
    {
        if (is_array($key)) {
            foreach ($key as $k => $name) {
                $this->minLength($name, is_array($minLength) ? $minLength[$k] : $minLength, $message);
            }
        } else {
            if (isset($this->scope[$key]) && mb_strlen($this->scope[$key]) < $minLength) {
                $this->errors[$key] = sprintf($message !== null ? $message : self::$minLengthMessage, $key, $minLength);
            }
        }

        return $this;
    }
21339
private static function annotateAndValidateModelEntry($modelState, $key) {
        $entry = $modelState[$key];

        if (($dataAnnotation = $modelState->getAnnotation($key)) !== null) {
            $displayName = $key;

            if (!empty($dataAnnotation->displayName)) {
                $displayName = $dataAnnotation->displayName;
            }

            // required field
            if (isset($dataAnnotation->required) && !($entry->validationState = !empty($entry->value))) {
                if (!empty($dataAnnotation->required[0])) {
                    $modelState->addError($key, $dataAnnotation->required[0]);
                }
                else {
                    $modelState->addError($key, $displayName . ' is required. Value must not be empty.');
                }
            }

            // compareWith
            if (!empty($dataAnnotation->compareWith)) {
                if (!empty($entry2 = $modelState[$dataAnnotation->compareWith[0]])) {
                    if (!($entry->validationState = ($entry->value == $entry2->value))) {
                        $displayName2 = $entry2->key;

                        if (($dataAnnotation2 = $modelState->getAnnotation($entry2->key)) !== null) {
                            if (!empty($dataAnnotation2->displayName)) {
                                $displayName2 = $dataAnnotation2->displayName;
                            }
                        }

                        if (!empty($dataAnnotation->compareWith[1])) {
                            $modelState->addError($key, $dataAnnotation->compareWith[1]);
                        } else {
                            $modelState->addError($key, 'The value of '. $displayName2 . ' must match the value of ' . $displayName . '.');
                        }
                    }
                }
                else {
                    // TODO: exception or not exception?
                }
            }

            // stringLength
            if (!empty($dataAnnotation->stringLength)) {
                $max = (int)$dataAnnotation->stringLength[0];
                $min = (int)$dataAnnotation->stringLength[1];
                $len = strlen($entry->value);

                if (!($entry->validationState = ($len >= $min && $len <= $max))) {
                    if (!empty($dataAnnotation->stringLength[2])) {
                        $modelState->addError($key, $dataAnnotation->stringLength[2]);
                    }
                    else {
                        // TODO: split messages (max only if min is zero)
                        $modelState->addError($key, 'The value must be at least ' . $min . ' character and not more than ' . $max . ' characters.');
                    }
                }
            }

            // range
            if (!empty($dataAnnotation->range)) {
                $min = (int)$dataAnnotation->range[0];
                $max = (int)$dataAnnotation->range[1];
                $value = (int)$entry->value;
                
                if (!($entry->validationState = ($value >= $min && $value <= $max))) {
                    if (!empty($dataAnnotation->range[2])) {
                        $modelState->addError($key, $dataAnnotation->range[2]);
                    }
                    else {
                        $modelState->addError($key, 'The value must be between ' . $min . ' and ' . $max . '.');
                    }
                }
            }

            // custom validation
            if (!empty($dataAnnotation->customValidation)) {
                $errorMessage = $displayName . ' is not valid.';

                if (!empty($dataAnnotation->customValidation[1])) {
                    $errorMessage = $dataAnnotation->customValidation[1];
                }

                try {
                    $entry->validationState = $dataAnnotation->customValidation[0]($entry->value, $errorMessage);
                }
                catch (\Exception $ex) {
                    $modelState->addError($key, $ex);
                    $entry->validationState = false;
                }

                if (!$entry->validationState) {
                    $modelState->addError($key, $errorMessage);
                }
            }
        }
    }
336307
private static function isCustomer_header($key)
    {
        if ($key == 'Cache-Control' 
		|| $key == 'Content-Type' 
		|| $key == 'Content-Disposition' 
		|| $key == 'Content-Language'
		|| substr($key,0,strlen('x-cos-meta-')) == 'x-cos-meta-')
	    {
            return true;
	    }
	    return false;
    }
1352855
private function copyKey(string $key): void
    {
        $source = $this->sourceDictionary->get($key);
        if ($source->isSourceEmpty()) {
            $this->logger->debug(
                '{key}: Is empty in source language and therefore skipped.',
                ['key' => $key]
            );
            return;
        }

        if (!$this->targetDictionary->has($key)) {
            $this->logger->log($this->logLevel, 'Adding key {key}.', ['key' => $key]);
            if ($this->dryRun) {
                return;
            }

            $this->targetDictionary->add($key);
        }
        $target = $this->targetDictionary->getWritable($key);

        $this->copySource($source, $target);
        $this->copyTarget($source, $target);
    }
834930
public function setRulesFor($key, $rules)
    {
        if (is_array($rules) || is_string($rules))
            $this->_rules[$key] = $rules;

        return $this;
    }
718530
protected function runEmail($key, $datas, $rule)
    {

        $email = $datas[$key];
        if (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
            $this->fails[] = $messageKey = "email.$key";

            $this->addMessage($key, $rule, $messageKey);
        }

    }