ephpicman/boolean-utility
Composer 安装命令:
composer require ephpicman/boolean-utility
包简介
A comprehensive Boolean utility for PHP, supporting logical operations, counting, and majority evaluation.
README 文档
README
A comprehensive PHP utility for working with booleans and boolean-like values.
Designed to simplify boolean checks, logical operations, counting, and majority logic in PHP projects.
Table of Contents
Installation
Use Composer to install:
composer require ephpicman/boolean-utility
Autoloading is PSR-4 compliant:
use EphpicMan\BooleanUtility\BooleanUtility;
Usage
The BooleanUtility class provides tools for:
- Boolean type checks
- Conversion of various values to boolean
- Logical operations (
AND,OR,XOR, etc.) - Counting true/false values
- Determining majority
- Aliases and toggle operations
Class: BooleanUtility
Checking Methods
| Method | Description |
|---|---|
is(mixed $variable): bool | Checks if a variable is strictly boolean. |
isNot(mixed $variable): bool | Checks if a variable is not boolean. |
isTruthy(mixed $variable): bool | Checks if a value evaluates to true. |
isFalsy(mixed $variable): bool | Checks if a value evaluates to false. |
Conversion
| Method | Description | |
|---|---|---|
toBoolean(mixed ...$variables): bool | array | Converts values to boolean. Strings matching true values, numbers, booleans, and arrays are all supported. |
Logical Operations
| Method | Description | |
|---|---|---|
and(mixed ...$variables): bool | Logical AND across multiple values. | |
nand(mixed ...$variables): bool | Logical NAND across multiple values. | |
or(mixed ...$variables): bool | Logical OR across multiple values. | |
nor(mixed ...$variables): bool | Logical NOR across multiple values. | |
xor(mixed ...$variables): bool | Logical XOR across multiple values. | |
xnor(mixed ...$variables): bool | Logical XNOR across multiple values. | |
not(bool ...$variables): bool | array | Logical NOT / toggle boolean values. |
Counting Methods
| Method | Description |
|---|---|
countTrue(mixed ...$variables): int | Counts how many inputs are true. |
countFalse(mixed ...$variables): int | Counts how many inputs are false. |
Majority Methods
| Method | Description | |
|---|---|---|
majorityTrue(mixed ...$variables): bool | Returns true if the majority of inputs are true. | |
majorityFalse(mixed ...$variables): bool | Returns true if the majority of inputs are false. | |
majority(mixed ...$variables): bool | null | Returns the majority value (true or false). Returns null if tie. |
Aliases
| Method | Description |
|---|---|
allTrue(...$vars): bool | Alias for and(). |
allFalse(...$vars): bool | Alias for nor(). |
xand(...$vars): bool | Alias for and(). |
xnand(...$vars): bool | Alias for nand(). |
anyTrue(...$vars): bool | Alias for or(). |
anyFalse(...$vars): bool | Alias for nor(). |
Toggle
| Method | Description | |
|---|---|---|
toggle(bool ...$variables): bool | array | Alias for not(). |
Examples
use EphpicMan\BooleanUtility\BooleanUtility;
// Simple boolean checks
BooleanUtility::is(true); // true
BooleanUtility::isNot('test'); // true
// Convert mixed values
BooleanUtility::toBoolean('yes'); // true
BooleanUtility::toBoolean(0); // false
BooleanUtility::toBoolean([1, 'no']); // [true, false]
// Logical operations
BooleanUtility::and(true, 'yes', 1); // true
BooleanUtility::or(false, 0, 'ok'); // true
BooleanUtility::xor(true, true, false); // false
// Counting
BooleanUtility::countTrue(true, false, 'yes'); // 2
BooleanUtility::countFalse(true, false, 'yes'); // 1
// Majority
BooleanUtility::majorityTrue(true, false, 'yes'); // true
BooleanUtility::majority(false, false, true, true); // null (tie)
// Toggle
BooleanUtility::toggle(true, false); // [false, true]
License
This package is released under the MIT License. Anyone may use, modify, or distribute it personally or commercially.
Git Repository
ephpicman/boolean-utility 适用场景与选型建议
ephpicman/boolean-utility 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 12 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「utility」 「logic」 「boolean」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ephpicman/boolean-utility 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ephpicman/boolean-utility 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ephpicman/boolean-utility 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Addons to the display-logic module by UncleCheese
A collection of enhancements and utilities for the Silverstripe UserForms module
Extends TYPO3 EXT:seo hreflang functionality
Routes HTTP requests to your code.
Extension provide very simply use enum for models (and others) in yii2
PHP7 utility classes
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 28
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-12-04