aviator/runnable 问题修复 & 功能扩展

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

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

aviator/runnable

最新稳定版本:0.1.0

Composer 安装命令:

composer require aviator/runnable

包简介

Static constructor and handler trait with interface.

README 文档

README

Build Status Latest Stable Version.License

Overview

This package provides a static constructor and handler interface, and a trait that implements the interface.

Installation

Via Composer:

composer require aviator/runnable

Testing

Via Composer:

composer test

Usage

Use the trait:

class Something
{
    use RunnableTrait;
}

Then the class can be instantiated and handled using Class::run()(). The static run method returns a closure which accepts any arguments the method (by default get()) requires:

$closure = Something::run($arg1);
$result = $closure($arg2); 

// Or just:

$result = Something::run($arg1)($arg2);

The trait also pulls in Aviator\Makeable, so you get the static constructor make() out of the box.

The interface is optional, though it can be useful in composite interfaces to specify that a static constructor should be present:

interface SomeInterface extends Runnable, SomeOtherInterface
{
    /* etc */
}

By default the trait will call get(), but this can be overridden:

class Something
{
    use RunnableTrait;
    
    protected static $method = 'handle';
    
    public function handle ($arg)
    {
        /* etc */
    }
}

$result = Something::run()('arg');

// Calls the handle() method.

The magic of late static binding means you can override the default method on classes extending abstract classes and classes extending classes, etc.

Other

License

This package is licensed with the MIT License (MIT).

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-12-19