承接 chubbyphp/chubbyphp-validation 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

chubbyphp/chubbyphp-validation

最新稳定版本:4.0.0

Composer 安装命令:

composer require chubbyphp/chubbyphp-validation

包简介

Chubbyphp Validate

README 文档

README

chubbyphp-validation

CI Coverage Status Mutation testing badge Latest Stable Version Total Downloads Monthly Downloads

bugs code_smells coverage duplicated_lines_density ncloc sqale_rating alert_status reliability_rating security_rating sqale_index vulnerabilities

Description

A simple validation.

DEPRECATED: No personal interest anymore and based on stats nobody seems to use it. Feel free to create an issue if you disagree. Please take a look to chubbyphp-parsing its a different concept. But i believe parsing is the way to go instead of deserialze/validate.

Requirements

  • php: ^8.1
  • psr/log: ^2.0|^3.0

Suggest

  • chubbyphp/chubbyphp-container: ^2.2
  • pimple/pimple: ^3.5
  • psr/container: ^2.0.2

Installation

Through Composer as chubbyphp/chubbyphp-validation.

composer require chubbyphp/chubbyphp-validation "^4.0"

Usage

Accessor

Constraint

Doctrine

Symfony

Error

Mapping

ValidationMappingProvider

<?php

namespace MyProject\Model;

final class Model
{
    /**
     * @var array<\DateTime>
     */
    private $dates;
}
<?php

namespace MyProject\Mapping\Validation;

use Chubbyphp\Validation\Constraint\AllConstraint;
use Chubbyphp\Validation\Constraint\DateTimeConstraint;
use Chubbyphp\Validation\Constraint\NotBlankConstraint;
use Chubbyphp\Validation\Constraint\NotNullConstraint;
use Chubbyphp\Validation\Mapping\ValidationClassMappingBuilder;
use Chubbyphp\Validation\Mapping\ValidationClassMappingInterface;
use Chubbyphp\Validation\Mapping\ValidationMappingProviderInterface;
use Chubbyphp\Validation\Mapping\ValidationPropertyMappingBuilder;
use Chubbyphp\Validation\Mapping\ValidationPropertyMappingInterface;
use MyProject\Model\Model;

final class ModelValidationMappingProvider implements ValidationMappingProviderInterface
{
    /**
     * @return string
     */
    public function getClass(): string
    {
        return Model::class;
    }

    /**
     * @param string $path
     *
     * @return ValidationClassMappingInterface
     */
    public function getValidationClassMapping(string $path): ValidationClassMappingInterface
    {
        return ValidationClassMappingBuilder::create([])->getMapping();
    }

    /**
     * @param string      $path
     * @param string|null $type
     *
     * @return ValidationPropertyMappingInterface[]
     */
    public function getValidationPropertyMappings(string $path, string $type = null): array
    {
        return [
            ValidationPropertyMappingBuilder::create('dates', [
                new AllConstraint([
                    new NotNullConstraint(),
                    new NotBlankConstraint(),
                    new DateTimeConstraint('d.m.Y'),
                ]),
            ])->getMapping(),
        ];
    }
}

ServiceFactory

chubbyphp-container

chubbyphp-laminas-config-factory

ServiceProvider

Validator

<?php

namespace MyProject;

use Chubbyphp\Validation\Mapping\ValidationMappingProviderRegistry;
use Chubbyphp\Validation\ValidatorContextInterface;
use Chubbyphp\Validation\Validator;
use MyProject\Mapping\Validation\ModelValidationMappingProvider;
use MyProject\Model\Model;

$logger = ...;

$validator = new Validator(
    new ValidationMappingProviderRegistry([
        new ModelValidationMappingProvider()
    ]),
    $logger
);

$model = new Model;

/** @var ValidatorContextInterface $context */
$context = ...;

$errors = $validator->validate(
    $model,
    $context
);

Copyright

2024 Dominik Zogg

统计信息

  • 总下载量: 17.66k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 0
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 2
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-10-01

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固