jonpemby/phlash
Composer 安装命令:
composer require jonpemby/phlash
包简介
Lodash inspired helper functions for PHP
README 文档
README
A lodash inspired library of helper functions for PHP.
Fits Into Your Existing Code
Phlash is meant to be a helpful addition to your code. Phlash adheres directly to your coding style with the help of PHP's dynamic __call method. Phlash automatically checks for a function signature matching the one you called for a myriad of styles. While Phlash is written in the camelCased style, it will work with any style.
For example:
$collection = phlash([1, 2, 3, 4, 5, 6])->dropRight(3); // [1, 2, 3] $collection = phlash([1, 2, 3, 4, 5, 6])->drop_right(3); // [1, 2, 3] $collection = phlash([1, 2, 3, 4, 5, 6])->DropRight(3); // [1, 2, 3]
Will all work!
Immutability
Every Phlash collection method returns a new collection. No collection will ever be mutated.
Phlash takes advantage of PHP's copy-on-write principle and assigns the current value to a new variable before mutating it. Nice!
Check it out with PsySh:
$collection = phlash([1, 2, 3, 4, 5, 6]); // Phlash\Arr {#210} $another = $collection->map(function ($value) { return $value * 2; }); // Phlash\Arr {#217}
Object Oriented With Functional Support
Phlash supports a variety of paradigms but most importantly the OO and functional paradigms. Methods can easily be chained from a new object. If you would rather call a function without having to deal with an object you can!
For example:
Phlash\Arr::from()->fill(null, 0, 3); // [null, null, null] phlash([])->fill(null, 0, 3); // [null, null, null] fill([], null, 0, 3); // [null, null, null]
While under the hood Phlash uses objects, Phlash supports your favorite paradigm as best it can.
Higher Order Property Accessors
Phlash supports higher order property accessors for collections. For example:
$array = phlash([ ['foo' => 1], ['foo' => 2], ['foo' => 3], ['foo' => 4], ['foo' => 5], ['foo' => 6], ]); $array->foo; // [1, 2, 3, 4, 5, 6]
And yes, this method is chainable to other methods of the same collection. This makes it so much easier to map collections of objects to properties without having to write a map function to handle it for you.
Learn More
Documentation site is coming soon!
Thanks
- Nan Pemberton for supporting my dream to become a programmer and for being by my side no matter what!
- Taylor Otwell for writing Laravel and inspiring me to be awesome
- You for reading this and showing interest in Phlash. Even if you don't use Phlash, writing PHP keeps the project alive! Thanks for being awesome.
jonpemby/phlash 适用场景与选型建议
jonpemby/phlash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 10 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 jonpemby/phlash 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jonpemby/phlash 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 12
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-10-05
