组建消息

@param array|object $data
@param \Imi\Validate\Annotation\Condition $annotation
@return string
324326
protected function buildMessage($data, $annotation)
    {
        $message = $annotation->message;
        if(false !== strpos($message, '{:value}'))
        {
            $message = str_replace('{:value}', ObjectArrayHelper::get($data, $annotation->name), $message);
        }
        $message = preg_replace_callback('/\{([^\}]+)\}/', function($matches) use($annotation){
            $name = $matches[1];
            if(isset($name[0]) && ':' === $name[0])
            {
                $name = substr($name, 1);
                $list = explode('.', $name, 2);
                if('data' === $list[0])
                {
                    if(isset($list[1]))
                    {
                        return ObjectArrayHelper::get($data, $list[1]);
                    }
                    else
                    {
                        return $data;
                    }
                }
            }
            else
            {
                return ObjectArrayHelper::get($annotation, $name);
            }
        }, $message);
        return $message;
    }
710112
public static function parse($model, $propertyName, $annotation)
    {
        if(!$model->$propertyName)
        {
            return;
        }
        $className = BeanFactory::getObjectClass($model);
        $autoInsert = AnnotationManager::getPropertyAnnotations($className, $propertyName, AutoInsert::class)[0] ?? null;
        $autoSave = AnnotationManager::getPropertyAnnotations($className, $propertyName, AutoSave::class)[0] ?? null;

        if($autoInsert)
        {
            if(!$autoInsert->status)
            {
                return;
            }
        }
        else if(!$autoSave || !$autoSave->status)
        {
            return;
        }

        if($annotation instanceof \Imi\Model\Annotation\Relation\OneToOne)
        {
            static::parseByOneToOne($model, $propertyName, $annotation);
        }
        else if($annotation instanceof \Imi\Model\Annotation\Relation\OneToMany)
        {
            static::parseByOneToMany($model, $propertyName, $annotation);
        }
        else if($annotation instanceof \Imi\Model\Annotation\Relation\ManyToMany)
        {
            static::parseByManyToMany($model, $propertyName, $annotation);
        }
        else if($annotation instanceof \Imi\Model\Annotation\Relation\PolymorphicOneToOne)
        {
            static::parseByPolymorphicOneToOne($model, $propertyName, $annotation);
        }
        else if($annotation instanceof \Imi\Model\Annotation\Relation\PolymorphicOneToMany)
        {
            static::parseByPolymorphicOneToMany($model, $propertyName, $annotation);
        }
        else if($annotation instanceof \Imi\Model\Annotation\Relation\PolymorphicManyToMany)
        {
            static::parseByPolymorphicManyToMany($model, $propertyName, $annotation);
        }
    }
807032
public function cart(array $condition, array $data)
    {
        $is_cart = (int) isset($data['cart_id']);
        $value = (int) filter_var(reset($condition['value']), FILTER_VALIDATE_BOOLEAN);
        return $this->compare($is_cart, $value, $condition['operator']);
    }
540961
public function parse($value, $annotation = null)
    {
        if ('' === $value) return true; // implicit boolean

        $json = JsonType::jsonDecode($value);

        if (JSON_ERROR_NONE === json_last_error()) {
            return $json;
        }
        elseif (false !== ($int = filter_var($value, FILTER_VALIDATE_INT))) {
            return $int;
        }
        elseif (false !== ($float = filter_var($value, FILTER_VALIDATE_FLOAT))) {
            return $float;
        }

        return $value;
    }
216875
public function validate($data) {
    if ($data === NULL) throw $this->emptyException();
    if (!is_array($data)) throw $this->invalidArgument(1, $data, 'Array', __FUNCTION__);
    
    foreach ($this->languages as $lang) {
      if (!array_key_exists($lang, $data)) {
        throw $this->emptyException();
      }
      
      try {
        $data[$lang] = $this->wrappedRule->validate($data[$lang]);
      } catch (EmptyDataException $e) {
        throw $this->emptyException($e);
      }
    }
    
    return $data;
  }
400578
private void validateAnnotation(final FieldAccessor accessor, final XlsLabelledArrayCells anno) {

        // 左側のとき、水平方向の配列はサポートしない
        if(anno.type().equals(LabelledCellType.Left) && anno.direction().equals(ArrayDirection.Horizon)) {
            throw new AnnotationInvalidException(anno, MessageBuilder.create("anno.XlsLabelledArrayCell.notSupportTypeAndDirection")
                    .var("property", accessor.getNameWithClass())
                    .varWithAnno("anno", XlsLabelledArrayCells.class)
                    .varWithEnum("typeValue", anno.type())
                    .varWithEnum("directionValue", anno.direction())
                    .format());
        }

    }
856935
public function filterCondition(array $data, $condition)
    {
        if (empty($condition)) {
            return $data;
        }

        if (!is_array($condition)) {
            throw new InvalidParamException('Condition must be an array');
        }

        if (isset($condition[0])) { // operator format: operator, operand 1, operand 2, ...
            $operator = strtoupper($condition[0]);
            if (isset($this->conditionFilters[$operator])) {
                $method = $this->conditionFilters[$operator];
            } else {
                $method = 'filterSimpleCondition';
            }

            array_shift($condition);

            return $this->$method($data, $operator, $condition);
        } else { // hash format: 'column1' => 'value1', 'column2' => 'value2', ...
            return $this->filterHashCondition($data, $condition);
        }
    }
190660
private function nested($annotation, $nestedContext)
    {
        if (property_exists($annotation, '_context') && $annotation->_context === $this->_context) {
            $annotation->_context = $nestedContext;
        }
        return $annotation;
    }
324609
protected function getValidator($name, $annotation) {
        $validate = array();
        switch($name) {
            case 'NotBlank':
            case 'NotNull':
                $validate['type'] = "presence";
                break;
            case 'Email':
                $validate['type'] = "email";
                break;
            case 'Length':
                $validate['type'] = "length";
                $validate['max'] = (int)$annotation->max;
                $validate['min'] = (int)$annotation->min;
                break;
            case 'Regex':
                if ($annotation->match) {
                    $validate['type'] = "format";
                    $validate['matcher']['skipEncode'] = true;
                    $validate['matcher']['value'] = $annotation->pattern;
                }
                break;
            case 'MaxLength':
            case 'MinLength':
                $validate['type'] = "length";
                if ($name == "MaxLength") {
                    $validate['max'] = (int)$annotation->limit;
                } else {
                    $validate['min'] = (int)$annotation->limit;
                }
                break;
            case 'Choice':
                $validate['type'] = "inclusion";
                $validate['list'] = $annotation->choices;
                break;
            default:
                $validate['type'] = strtolower($name);
                $validate += get_object_vars($annotation);
                break;
        }
        return $validate;
    }
484864
protected function annotationToArray($annotation)
    {
        $options = array();
        foreach ((array) $annotation as $key => $value) {
            if ($value !== null) {
                $options[$key] = $value;
            }
        }

        return $options;
    }
382986
public function update($table, $data, $condition)
    {
        if ( empty($condition) ) return false;
        $_T_fields = $this->getTableFields($table);
        $_keys = '';
        foreach ( $data as $_key => $_val ) {

            //过滤不存在的字段
            if ( !in_array($_key, $_T_fields) ) continue;
            if ( is_null($_val) ) {
                $_val = 'NULL';
            } else {
                $_val = "'{$_val}'";
            }
            $_keys .= $_keys == ''? "`{$_key}`={$_val}" : ", `{$_key}`={$_val}";
        }
        if ( $_keys !== '' ) {
            $_query = "UPDATE {$table} SET " . $_keys . $condition;
            $result = $this->execute($_query);
            if ( $result != false ) {
                return $result->rowCount() > 0 ? $result->rowCount() : true;
            }
        }
        return false;
    }
1025546
public function setData(Condition $condition, $data)
    {
        $this->clearData();
        $this->addData($condition, $data);
    }
140568
public static function create($method, DataSource $annotation = null) {
        Str::assert($method, 'method');

        $annotationStatusCodes = !empty($annotation) && $annotation->getStatusCodes() !== null ? $annotation->getStatusCodes() : array();
        return $annotationStatusCodes ?: self::$expectedStatusCodes[$method];
    }
644651
private function normalizeAnnotation(Annotation $annotation)
    {
        return [
            'value' => $annotation->getValue(),
            'timestamp' => $annotation->getTimestamp(),
            'endpoint' => null !== $annotation->getHost() ? $this->normalizeEndpoint($annotation->getHost()) : null,
        ];
    }
846538
private function source(Annotation $annotation): string
    {
        if ($annotation->hasValueByName('source')) {
            return ucfirst(strtolower($annotation->getSource()));
        }

        return 'Param';
    }
472119
public function mapConditions(array $data): array
    {
        $conditions = [];

        foreach ($data as $dataItem) {
            $conditions[] = Condition::fromArray(
                [
                    'id' => (int) $dataItem['id'],
                    'status' => (int) $dataItem['status'],
                    'ruleId' => (int) $dataItem['rule_id'],
                    'type' => $dataItem['type'],
                    'value' => json_decode($dataItem['value'], true),
                ]
            );
        }

        return $conditions;
    }
306878
public function renderWhen($condition, $view, $data = [], $mergeData = [])
    {
        if (! $condition) {
            return '';
        }

        return $this->make($view, $this->parseData($data), $mergeData)->render();
    }