pixelbrackets/not-empty
Composer 安装命令:
composer require pixelbrackets/not-empty
包简介
not empty() - Adds methods to determine whether a variable is blank or present - Inspired by Ruby on Rails
README 文档
README
Add methods to determine whether a variable is blank or present.
Inspired by Ruby on Rails.
Idea
This package is a hackathon product. Idea was to port the
Ruby on Rails methods
blank and present to PHP.
PHP has the empty method,
but more often I need to check whether a variable is not empty.
That's why a notEmpty method is available as well.
See the list below to compare the different behaviour of these methods.
┌─────────────────────────┬─────────┬────────────┬─────────┬───────────┐
│ VALUE │ EMPTY() │ NOTEMPTY() │ BLANK() │ PRESENT() │
├─────────────────────────┼─────────┼────────────┼─────────┼───────────┤
│ string '' │ true │ │ true │ │
│ string 'acme' │ │ true │ │ true │
│ string ' ' │ │ true │ true │ │
│ string ' ' │ │ true │ true │ │
│ string "\t\n" │ │ true │ true │ │
│ int 0 │ true │ │ true │ │
│ float 0.0 │ true │ │ true │ │
│ int 42 │ │ true │ │ true │
│ float 3.14 │ │ true │ │ true │
│ string '0' │ true │ │ true │ │
│ string '1337' │ │ true │ │ true │
│ null │ true │ │ true │ │
│ bool true │ │ true │ │ true │
│ bool false │ true │ │ true │ │
│ array [] │ true │ │ true │ │
│ array ['acme'] │ │ true │ │ true │
│ object {} │ │ true │ true │ │
│ object {"foo" => "bar"} │ │ true │ │ true │
└─────────────────────────┴─────────┴────────────┴─────────┴───────────┘
Requirements
- PHP
Installation
Packagist Entry https://packagist.org/packages/pixelbrackets/not-empty/
Source
https://gitlab.com/pixelbrackets/not-empty/
Mirror https://github.com/pixelbrackets/not-empty/
Usage
See tests/demo.php.
use Pixelbrackets\NotEmpty\Blank;
use Pixelbrackets\NotEmpty\NotEmpty;
use Pixelbrackets\NotEmpty\Present;
# Is a string empty? → Use PHPs »empty«
if (empty('')) { … }
# Is a string not empty? → Use »empty() === false«
if (empty('acme') === false) { … }
# → …or use »notEmpty« instead
if (NotEmpty::notEmpty('acme')) { … }
# A strings with whitespaces is blank → use a combination of conditions
if (is_string(' ') && empty(trim(' '))) { … }
# → …or use »blank« instead
if (Blank::blank(' ')) { … }
# → use »present« to check the opposite of »blank«
if (Present::present('acme')) { … }
💡 If you want to use the methods as global functions (blank() instead of
the namespaced Pixelbrackets\NotEmpty\Blank::blank()) then install the
»global« branch, using composer require pixelbrackets/not-empty:dev-global.
License
GNU General Public License version 2 or later
The GNU General Public License can be found at http://www.gnu.org/copyleft/gpl.html.
Author
Dan Untenzu (mail@pixelbrackets.de / @pixelbrackets)
Changelog
See ./CHANGELOG.md
Contribution
This script is Open Source, so please use, patch, extend or fork it.
This package is not in active delopment, contributions are welcome though.
pixelbrackets/not-empty 适用场景与选型建议
pixelbrackets/not-empty 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.56k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2020 年 08 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 pixelbrackets/not-empty 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pixelbrackets/not-empty 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.56k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: GPL-2.0-or-later
- 更新时间: 2020-08-05