2017 © Pedro Peláez
 

library runnable

Static constructor and handler trait with interface.

image

aviator/runnable

Static constructor and handler trait with interface.

  • Tuesday, December 19, 2017
  • by danielsdeboer
  • Repository
  • 1 Watchers
  • 0 Stars
  • 11 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Build Status Latest Stable Version.License, (*1)

Overview

This package provides a static constructor and handler interface, and a trait that implements the interface., (*2)

Installation

Via Composer:, (*3)

composer require aviator/runnable

Testing

Via Composer:, (*4)

composer test

Usage

Use the trait:, (*5)

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:, (*6)

$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., (*7)

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

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

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

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., (*10)

Other

License

This package is licensed with the MIT License (MIT)., (*11)

The Versions

19/12 2017

dev-master

9999999-dev https://github.com/danielsdeboer/runnable

Static constructor and handler trait with interface.

  Sources   Download

MIT

The Requires

 

The Development Requires

php static php7 constructor

19/12 2017

0.1.0

0.1.0.0 https://github.com/danielsdeboer/runnable

Static constructor and handler trait with interface.

  Sources   Download

MIT

The Requires

 

The Development Requires

php static php7 constructor