inmanturbo/functional-library
Composer 安装命令:
composer require inmanturbo/functional-library
包简介
create Closure libraries with ease for functional programming with php
README 文档
README
This package makes it easy to export and autoload a library of anonymous functions or collections of anonymous functions using composer.
Installation
You can install the package via composer:
composer require inmanturbo/functional-library
Usage
To create a library you can use the HasFunctionalLibrary trait, then you just have to implement
a static library method with named bool parameters for your available functions.
You then call static::getLibrary with all your parameters as its args.
Finally, you create a static method called closures() with an associative array of your anonymous
functions with (string) keys corresponding to your library method's named params.
Example
use Inmanturbo\FunctionalLibrary\HasFunctionalLibrary; class ExampleLibrary { use HasFunctionalLibrary; public static function library(bool $addOne = false, bool $addTwo = false) { return static::getLibrary(...func_get_args()); } public static function closures() { return [ 'addOne' => fn(int $number): int => $number + 1, 'addTwo' => fn(int $number): int => $number + 2, ]; } }
Example Usage
The above example creates the following testable api (using pest):
[$addOne, $addTwo] = ExampleLibrary::library(addOne: true, addTwo: true); expect($addOne(0))->toBe(1); expect($addTwo(0))->toBe(2); // Test a single option $addOne = ExampleLibrary::library(addOne: true); expect($addOne(0))->toBe(1); // Test no options (should return all available options) [$addOne, $addTwo] = ExampleLibrary::library(); expect($addOne(0))->toBe(1); expect($addTwo(0))->toBe(2);
Now you can put your anonymous functions into scoped static libraries and find them using static analysis by their named arguments, or by inspecting the closures() method's return value.
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
inmanturbo/functional-library 适用场景与选型建议
inmanturbo/functional-library 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 33 次下载、GitHub Stars 达 2, 最近一次更新时间为 2024 年 08 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「inmanturbo」 「functional-library」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 inmanturbo/functional-library 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 inmanturbo/functional-library 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 inmanturbo/functional-library 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Fat sushi rolls
Eloquent Modelware for laravel
This is my package path-router
A simple utility package to handle contacts lists in Laravel
This is my package laravel-delegator
Eloquent copy-on-write: automatically copy all model changes to a separate table.
统计信息
- 总下载量: 33
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 18
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-08-12