定制 angle/falsy 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

angle/falsy

Composer 安装命令:

composer require angle/falsy

包简介

Falsy helps you manage half-truths with PHP

README 文档

README

  • Tiny library (< 200 lines total, adds 2 functions to the global namespace)
  • No dependencies
  • Fully tested
  • Requires PHP version ^7.0

Functions

falsy(...$vars) : bool

Returns false whenever a variable is falsy.

truthy(...$vars) : bool

Returns true only when all variables are truthy (opposite of falsy).

Examples

If anything is falsy, the function returns true.

falsy(true, false, null); // true
truthy(true, false, null); // false

If all variables are truthy, the function returns false.

falsy(true, 1, [1]); // false
truthy(true, 1, [1]); // true

Null strings and empty arrays are falsy.

falsy('0', '', [], ['']); // true
truthy('0', '', [], ['']); // false

// Note: (bool) [''] returns true in plain PHP. Falsy interprets it as false, as it should.

Arrays are recursively audited.

$array = [
    'foo' => false,
    'bar'=> [
        'baz' => false
    ]
];

falsy($array); // true
truthy($array); // false

$array = [
    'foo' => true,
    'bar'=> [
        'baz' => 1
    ]
];

falsy($array); // false
truthy($array); // true

Objects are audited on their properties.

$object = new stdClass;

falsy($object); // true
truthy($object); // false

$object->foo = false;
$object->bar = null;
$object->baz = 0;

falsy($object); // true
truthy($object); // false

$object->foo = true;
$object->bar = 'string';
$object->baz = 1;

falsy($object); // false
truthy($object); // true

Closures are audited on their return value.

$void = function () { return; };

falsy($void); // true
truthy($void); // false

$false = function () { return false; };

falsy($false); // true
truthy($false); // false

$string = function () { return 'string'; };

falsy($string); // false
truthy($string); // true

falsy($void, $false, $string); // true
truthy($void, $false, $string); // false

Finally, you may pass as many statements as you need.

falsy(
    false,
    null,
    0,
    0.0,
    '0',
    [],
    [''], // Php would consider this as being true, but really, is it? No.
    ['' => ''],
    [false, null],
    ['' => '', 0 => ['key' => null, 'foo' => [''], 'empty' => []]], // Array keys are ignored
    new stdClass, // Objects with empty attributes are falsy
    function () { return; }, // Void closures are falsy
    function () { return false; },
    function () { return null; },
    function () { return ''; },
    function () { return 0; },
    function () { return []; },
    function () { return ['']; }
); // true

$object = new stdClass;
$object->foo = 'bar';

truthy(
    true,
    1,
    0.1,
    '1',
    ['foo'],
    ['foo' => 'bar'],
    [true],
    $object,
    function () { return true; },
    function () { return 1; },
    function () { return 0.1; },
    function () { return '1'; },
    function () { return ['foo']; },
    function () { return ['foo' => 'bar']; },
    function () { return [true]; },
    function () use ($object) { return $object; }
); // true

Testing

Run the test suite by executing:

    composer install
    ./vendor/bin/phpunit

Contributing

Contributions are welcomed! Feel free to submit a pull request anytime.

Licence

MIT License

Copyright © 2019 Angle Software

angle/falsy 适用场景与选型建议

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

它主要适用于以下技术方向: 「php」 「helpers」 「falsy」 「truthy」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

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

围绕 angle/falsy 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-01-18