mcvalidator/mcvalidator-php 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mcvalidator/mcvalidator-php

Composer 安装命令:

composer require mcvalidator/mcvalidator-php

包简介

It's always [undefined index] somewhere in PHP

README 文档

README

It's always [undefined index] somewhere in PHP.

McValidator is written to provide a way to validate and sanitize data

Example 1:

use McValidator as MV;

// Builder is important because we can chain validator with them without
// too much work.
$builder = MV\valid('rule/is-string');

// Build the pipe
$pipe = $builder->build();

// Pump the value through the pipe
// Result contains the value and also informations about
// the runtime, such as errors and messages
$result = $pipe->pump(10);

// Gets the runtime state
$state = $result->getState();

// Gets the message of the head(first item) of errors
echo $state->getErrors()->head()->getMessage(); // Value is not a string

// We need more!
$builder2 = MV\shape_of([
    'a' => $builder
]);

$pipe2 = $builder2->build();

$result2 = $pipe2->pump(dict([
    'a' => 10
]));

// Gets the runtime state
$state2 = $result2->getState();

// Gets the message of the head(first item) of errors
echo $state2->getErrors()->head()->getMessage(); // outputs `Value is not a string`

// Gets the field path of the error!
echo $state2->getErrors()->head()->getStringPath('/' // <-- separator); // outputs `$/a`
// `$` means root of path 

You should be thinking now: this s**t s**ks you loser, it's way too verbose than j**a. And we know, McValidator is not intended to be "simple" and "not verbose", but intended to provide ways to:

  • write validators and also provide runtime information
  • track errors without making you lose your mind asking what the freaking freak is happening when you just threw a freaking exception from nowhere
  • no exception will be thrown in runtime, except on structure configuration
  • value history, yeah, every value has an history of values inside which get updated once every mutation, which is in development
  • structure serialization, this s**t is good for caching, we can also cache closure, why the f**k not? It's PHP. This is also good because building validator structure may be expensive, if you cache the validator you can use it without building on every request(it's PHP).
  • write once, validate everywhere, the main intention on that library is to focus on provide a way to write a validator and use it on JavaScript(web, node), Python, Ruby, etc., we have a Manifesto which is being written to define the McValidator's implementation pattern.
  • we support YAML, you can build your validator only using YAML, and this will make you productive, because you can write a single YAML which will be valid in any other implementation of McValidator.
  • we respect data structures, McValidator works together with Heterogeny on PHP, thus respecting the way data should be, arrays being arrays and dictionaries being dictionaries, thus making developing less confusing at least in PHP. We will not support at any point any way to write a code that will mix those structures, do not open an issue or PR about it.
  • You can validate on the depth of hell, McValidator provides a way to track errors even on nested structures, and when we say deep, it's deep. An example of error path: a/0/b/1/c, which means that an error(happened on field c , of element 1, of field b, of element 0, of field a), this is possible because McValidator is about chains and recursiveness, there's hardcore or such thing in our code.
  • Immutability is our focus, sanitization or validation will not mutate data that is not on it's reach

Value's type table

NonExistentValue ExplicitNonExistentValue InvalidValue
isValid false true false
exists false false true
  • NonExistentValue: a value that was not sent and does not exists, example: a key configured for a shape that was not "pumped"
  • ExplicitNonExistentValue: a value that was sent explicitly null, example: a key configured for a shape that was "pumped" null
  • InvalidValue: an invalid value which source is sections, example: a value that was sent and reported invalid in sections

Performance is not guaranteed at this point.

mcvalidator/mcvalidator-php 适用场景与选型建议

mcvalidator/mcvalidator-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.81k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 01 月 11 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 mcvalidator/mcvalidator-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 mcvalidator/mcvalidator-php 我们能提供哪些服务?
定制开发 / 二次开发

基于 mcvalidator/mcvalidator-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 3.81k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 12
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-01-11