2017 © Pedro Peláez
 

library callback

Allows you execute callbacks in a more dynamic way

image

phpfluent/callback

Allows you execute callbacks in a more dynamic way

  • Wednesday, June 3, 2015
  • by henriquemoody
  • Repository
  • 3 Watchers
  • 10 Stars
  • 7,160 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 3 Versions
  • 13 % Grown

The README.md

PHPFluent\Callback

Build Status Code Quality Code Coverage Latest Version Total Downloads License, (*1)

Allows you execute callbacks in a more dynamic way., (*2)

Installation

The package is available on Packagist. You can install it using Composer., (*3)

composer require phpfluent/callback

Dependencies

  • PHP 5.4+

Usage

All examples within this document assume you have the following statement at the beginning of the file:, (*4)

use PHPFluent\Callback\Callback;

Define your callable

Closures

$callback = new Callback(
    function () {
        // My callable content.
    }
);

Object methods

$callback = new Callback(array($object, 'methodName'));

User defined functions

$callback = new Callback('my_function');

PHP native functions

$callback = new Callback('str_replace');

Executing your callable

There are many ways you can execute the callable., (*5)

invoke()

$callback->invoke($arg1, $arg2, $arg3);

invokeArguments()

$callback->invokeArguments($arrayArguments);

__invoke()

$callback($arg1, $arg2, $arg3); // call_user_func() and call_user_func_array() will work like a charm

Arguments

If you're reading this document you may be wondering why this library was written since everything written on it is already possible just using native PHP features., (*6)

This library provides more flexibility when defining the arguments to be used when you call your callback. That's useful when you working with callbacks in a predefined structure but you don't want all arguments., (*7)

Names

Callback will execute your callback based on its parameters name., (*8)

$callable = new Callback(
    function ($foo, $bar = true) {
        // My callable body
    }
);
$callable->invokeArguments(
    array(
        'foo' => 'PHPFluent',
    )
);

Types

Doesn't matter the order of the arguments, Callback will put it in the right order before execute your callable., (*9)

$callable = new Callback(
    function (array $array, TypeTwo $typeTwo, $string, $int, TypeThree $typeThree, $optional = 42) {
        // My callable body
    }
);
$callable(array(), new TypeTwo(), new TypeThree(), 'string', 123);

The Versions

03/06 2015

dev-master

9999999-dev https://github.com/PHPFluent/Callback

Allows you execute callbacks in a more dynamic way

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

callable callback closure

03/06 2015

1.1.0

1.1.0.0 https://github.com/PHPFluent/Callback

Allows you execute callbacks in a more dynamic way

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

callable callback closure

03/12 2014

1.0.0

1.0.0.0 https://github.com/PHPFluent/Callback

Allows you execute callbacks in a more dynamic way

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

callable callback closure