hvolschenk/compose 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

hvolschenk/compose

Composer 安装命令:

composer require hvolschenk/compose

包简介

PHP function composer.

README 文档

README

PHP function composition

The composition can either be run directly from the static method or used as a trait in a class.

Directly

<?php
  namespace Test\Test;
  require('vendor/autoload.php');

  function addA(string $string) {
    return "{$string}a";
  }

  function addB(string $string) {
    return "{$string}b";
  }

  function addC(string $string) {
    return "{$string}c";
  }

  echo Hvolschenk\Utils\Compose\Compose::compose('Value',
    ['addA', 'addB', 'addC']); // ValueABC
?>

As a trait

With static methods

<?php
  class StringAdder {
    use \Hvolschenk\Traits\Compose;

    private $value;

    public function __construct(string $value) {
      $this->setValue($value);
    }

    public function getValue(): string {
      return $this->value;
    }

    private function setValue(string $value) {
      $this->value = self::composeValue($value);
    }

    private static function composeValue(string $value): string {
      return self::compose($value, ['addA', 'addB', 'addC']);
    }

    private static function addA(string $string) {
      return "{$string}a";
    }

    private static function addB(string $string) {
      return "{$string}b";
    }

    private static function addC(string $string) {
      return "{$string}c";
    }
  }

  $stringAdder = new StringAdder('Value');
  echo $stringAdder->getValue(); // ValueABC
?>

With non-static methods

<?php
  class StringAdder {
    use \Hvolschenk\Traits\Compose;

    private $value;
    private $separator = '.';

    public function __construct(string $value) {
      $this->setValue($value);
    }

    public function getValue(): string {
      return $this->value;
    }

    private function setValue(string $value) {
      $this->value = self::composeValue($value);
    }

    private function composeValue(string $value): string {
      return $this->composeNonStatic($value, ['addA', 'addB', 'addC']);
    }

    private function addA(string $string) {
      return "{$string}a{$this->separator}";
    }

    private function addB(string $string) {
      return "{$string}b{$this->separator}";
    }

    private function addC(string $string) {
      return "{$string}c{$this->separator}";
    }
  }

  $stringAdder = new StringAdder('Value');
  echo $stringAdder->getValue(); // ValueA.B.C.
?>

With static and non-static methods

<?php
  class StringAdder {
    use \Hvolschenk\Traits\Compose;

    private $value;
    private $separator = '.';

    public function __construct(string $value) {
      $this->setValue($value);
    }

    public function getValue(): string {
      return $this->value;
    }

    private function setValue(string $value) {
      $this->value = self::composeValue($value);
    }

    private function composeValue(string $value): string {
      return $this->composeMixed($value, [['self', 'addA'], ['self', 'addB'],
        [$this, 'addC']]);
    }

    private static function addA(string $string) {
      return "{$string}a";
    }

    private static function addB(string $string) {
      return "{$string}b";
    }

    private function addC(string $string) {
      return "{$string}c{$this->separator}";
    }
  }

  $stringAdder = new StringAdder('Value');
  echo $stringAdder->getValue(); // ValueABC.
?>

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-11-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固