承接 8fold/php-foldable 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

8fold/php-foldable

最新稳定版本:1.3.1

Composer 安装命令:

composer require 8fold/php-foldable

包简介

Foundation for developing Fluent Interfaces and the Pipeline Pattern

README 文档

README

Foldable is a low-level, lighweight library to facilitate the creation of higher-level wrappers and fluent interfaces.

Installation

composer require 8fold/php-foldable

Usage

Foldables can either extend the Fold class, use the FoldableImp default implementation, or implement the Foldable interface. Note: The Fold class uses and implements the Foldable default implementation and interface.

class MyFoldable extends Fold
{
  public function append(string $string): MyFoldable
  {
    $this->main = $this->main . $string;

    return $this;

    // Note: If you prefer immutability, you can always create a new instance
    //       of the MyFoldable class:
    //
    //       return MyFoldable::fold(...$this->args(true));
  }
}

print MyFoldable::fold("Hello")->append(", World!")->unfold();
// output: Hello, World!

The fold() static initializer (or named constructor) can take an infinite number of arguments. For the defulat implementation, the first argument is stored as main while the others are stored as an array called args. To help facilitate immutability, you can retrieve the arguments provided by calling the args method; you can also specify that you want the completely list, including main, by calling args(true).

Filters are PHP classes implementing the __invoke magic method; thereby becoming more like a namespaced global function in the standard library.

class Append extends Filter
{
  public function __invoke($using): string
  {
      if (is_a($using, Pipe::class)) {
          return $using->unfold() . $this->main;
      }
      return $using . $this->main;
  }
}

print Apply::append(", World!")->unfoldUsing("Hello");
// output: Hello, World!

class MyFoldable extends Fold
{
  public function append(string $string): MyFoldable
  {
    $this->main = Append::applyWith($string)->unfoldUsing($this->main);

    return $this;
  }
}

print MyFoldable::fold("Hello")->append(", World!")->unfold();
// output: Hello, World!

Pipes can be used to apply multiple filters in sequence from a starting point.

class Prepend extends Filter
{
  public function __invoke(string $using): string
  {
      return Append::applyWith($using)->unfoldUsing($this->main);
  }
}

$result = Pipe::fold("World",
  Apply::prepend("Hello, "),
  Apply::append("!")
)->unfold();
// output: Hello, World!

// you can allow filters to take pipes as well
$result = Pipe::fold("World",
  Apply::prepend(
    Pipe::fold("ello",
      Apply::prepend("H"),
      Apply::append(","),
      Apply::append(" ")
    )
  ),
  Apply::append("!")
)->unfold();

We also provide an assertion filter in the tests directory call PerformantEqualsTestFilter, which can be used to test equality and performance of Foldables and Filters.

use PHPUnit\Framework\TestCase as PHPUnitTestCase;

use Eightfold\Foldable\Tests\PerformantEqualsTestFilter as AssertEquals;

class TestCase extends PHPUnitTestCase
{
  /**
  * @test
  */
  public function test_something()
  {
    AssertEquals::applyWith(
      "expected result",
      "expected type",
      0.4 // maximum milliseconds
    )->unfoldUsing(
      Pipe::fold("World",
        Apply::prepend(
          Pipe::fold("ello",
            Apply::prepend("H"),
            Apply::append(","),
            Apply::append(" ")
          )
        ),
        Apply::append("!")
      )
    );
  }
}

The start time is start at initialization and stopped after unfolding the passed Foldable or assigning the passed value.

Details

Primary goals are:

  1. Allow for type-safety while giving you flexibility in what that means.
  2. Speed. This is a low-level library meant for high-extensibility adding as little processing overhead as possible. Our baseline for performance tests (which is most of them) is 0.3 milliseconds. (If you know of ways to improve the speed, feel free to submit an issue or PR).
  3. Anit-null. Whenever possible, we do not accept null as a required paramater and do avoid returning null whenever possible. We are not defensive with it; so, much of that responsbility is left to the user.

Other

8fold/php-foldable 适用场景与选型建议

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

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

围绕 8fold/php-foldable 我们能提供哪些服务?
定制开发 / 二次开发

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-10