sepiariver/binliner-php
Composer 安装命令:
composer require sepiariver/binliner-php
包简介
A Binary Sequence Validator for PHP
README 文档
README
Binary Sequence Validator for PHP
About
What is it?
Binliner is like a factory for state machines. Given the parameter $config['size'], an instance is endowed with a finite number of possible states, which may be configured as valid, to the exclusion of all other states, using the $config['validation'] parameter.
The isValid() method returns a boolean: whether the current state is one of those configured as valid, like an Acceptor. The instance can be coerced into a string or converted to a number, in both cases returning the respective representation of the state, like a Classifier. This output can be mapped to another set of values that serve a particular business case—the implementation on the whole then acting like a Moore machine.
By passing a function to $config['validation'], Binliner's deterministic behaviour can be side-stepped, introducing side-effects or any other custom validation logic required. At that point, Binliner's utility might be brought into question, although it does seem to help elucidate complex conditional logic.
What it is not
Binliner is not a garbage-collection utility, despite the name. It "lines up" binary flags in a sequence, and since it validates the sequence against configured rules, it can be said to catch errors aka "catch garbage" like a binliner :)
What is a binary sequence?
It is a series of bits, each of which has a value of either 0 or 1. It is typically used for data transmission, compression or storage, but also can be used for error detection and correction, among other uses. By encapsulating arbitrary boolean conditions using the implicit ordering of numerically-indexed arrays, Binliner can faciliate complex control flows in a more compact yet still transparent/readable way.
For trivial control flows, Binliner is probably ill-suited, but it can be helpful in more complex cases. It also allows re-use of the condition state.
Installation
composer require sepiariver/binliner-php
Usage
Example
If Bob's age is less than 21, reject. If his age is 21 to 65, check his license, and reject if invalid. If he is over 65 and has a valid license, re-test. If he fails the test, or lacks a valid license, reject.
Note: this example is not intended to condone ageism
use SepiaRiver\Binliner; class Bob { // define bob }; $bob = new Bob(); $ofAge = ($bob->age > 20); // Postiion 0 in the sequence $needsRetest = ($bob->age > 65); // Position 1 $validLicense = ($bob->license.valid); // Position 2 $passedTest = ($bob->test.results > 60); // Position 3 /** * Truth table * ofAge | needsRetest | validLicense | passedTest * 1 | 0 | 1 | 0 // of age, valid license, test result irrelevant * 1 | 0 | 1 | 1 // of age, valid license, test result irrelevant * 1 | 1 | 1 | 1 // of age, valid license, passed test * * ALL OTHER STATES ARE INVALID */ $config = [ 'size' => 4, 'validation' => ['1010', '1011', '1111'], ]; $binliner = new Binliner( $config, $ofAge, $needsRetest, $validLicense, $passedTest ); if (!$binliner->isValid()) { // Reject throw new Exception('Invalid state!'); } // Just for convenience you can reason about intval((string)$binliner, 2); if ($binliner->toInt() < 12) { // Accept return true; } // The only remaining valid state is '1111' return handlePassedRetest($bob);
See test/ExamplesTest.php for more.
Testing
- Clone this repo
composer installvendor/bin/phpunit
Contributing
Submit pull requests to [https://github.com/sepiariver/binliner-php/pulls]
sepiariver/binliner-php 适用场景与选型建议
sepiariver/binliner-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2022 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「tree」 「validator」 「sequence」 「binary」 「heap」 「conditional logic」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 sepiariver/binliner-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 sepiariver/binliner-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 sepiariver/binliner-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Runn Me! Validation and Sanitization Library
jsTree widget for yii2
Extension for Opis JSON Schema
Doctrine2 behavior traits - slowhop fork
A fast and dynamic Merkle tree implementation
Data structure collections, helpers and utilities for yii2 ActiveRecord models(trees, sorts and etc.)
统计信息
- 总下载量: 5
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-03-04