定制 datahihi1/pipefn 二次开发

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

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

datahihi1/pipefn

Composer 安装命令:

composer require datahihi1/pipefn

包简介

Polyfill for PHP 8.5 pipe operator supporting closures, functions, and methods.

README 文档

README

A lightweight polyfill that provides a pipe() function for method chaining and functional pipelines in PHP 5.6+ applications. This function allows you to chain method calls, closures, functions, and more in a clean, readable way.

Installation

Via Composer

composer require datahihi1/pipefn:dev-main

Manual Installation

  1. Download the pipefn.php file
  2. Include it in your project:
    require_once 'pipefn.php';

Usage

The pipe() function takes an initial value and chains it through multiple steps (functions, closures, methods, callables, etc).

Basic Syntax

$result = pipe($value, ...$steps);

Parameters

  • $value - The initial value to be piped through the steps
  • ...$steps - Variable number of steps, which can be:
    • String function/method names (global, static, or object methods)
    • Arrays in format [callable, [arguments]] or [methodName, [arguments]]
    • Closures/functions
    • Callable arrays (e.g. [$object, 'method'])

Supported Usages

1. Chain closures/functions

pipe(" hi ", fn($v) => trim($v), fn($v) => strtoupper($v), fn($v) => $v . "!");
// Result: "HI!"

2. Global function names

pipe(" test ", 'trim', 'strtoupper');
// Result: "TEST"

3. Static method (Class::method)

pipe("hey", 'MyClass::upper');
pipe("a", ['MyClass::append', ['b']]);
// Result: "HEY", "ab"

4. Object method (with or without arguments)

$user = new class('john') {
    public $name;
    public function __construct($n){$this->name = $n;}
    public function setName($n){$this->name=$n; return $this;}
    public function upper(){ $this->name = strtoupper($this->name); return $this; }
    public function get(){return $this->name;}
};
pipe($user, ['setName', ['jane']], 'upper', 'get');
// Result: "JANE"

5. Callable array (e.g. [[$obj, 'method'], [args]])

pipe("x", [[$obj, 'method'], ['y']]);
// Calls $obj->method("x", "y")

6. Closure with multiple arguments

pipe("a", [fn($v, $x, $y) => $v . $x . $y, ['b', 'c']]);
// Result: "abc"

7. Function with callback (e.g. array_map)

pipe([1,2,3], ['array_map', [fn($x)=>$x*2]], 'array_sum');
// Result: 12

8. No steps (returns value unchanged)

pipe("hello"); // Result: "hello"

9. Error handling

If a step is not callable or invalid, an InvalidArgumentException is thrown with a clear message.

Requirements

  • PHP >= 5.6
  • No additional dependencies

Features

  • ✅ PHP 5.6+ compatibility
  • ✅ Method chaining with arguments
  • ✅ Closure/function/callable support
  • ✅ Callable array (e.g. [$obj, 'method'])
  • ✅ Lightweight (single file)
  • ✅ No external dependencies
  • ✅ Automatic function/method existence check
  • ✅ Clear error messages for debugging

License

This project is open source and available under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Give it a star if you find it useful! ⭐ :v

datahihi1/pipefn 适用场景与选型建议

datahihi1/pipefn 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 10 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-10-28