2017 © Pedro Peláez
 

library invoke

Invocation Utility

image

krak/invoke

Invocation Utility

  • Thursday, September 7, 2017
  • by ragboyjr
  • Repository
  • 1 Watchers
  • 0 Stars
  • 615 Installations
  • PHP
  • 3 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 8 % Grown

The README.md

Invoke

Simple abstractions for invoking functions with parameters., (*1)

Installation

Install with composer at krak/invoke, (*2)

Usage

Each invoker implements the simple interface:, (*3)

<?php

interface Invoke {
    public function invoke($func, ...$args);
}

Here's a simple example of the default invoker which uses call_user_func., (*4)

<?php

use Krak\Invoke;

function hello($arg) {
    echo "Hello {$arg}\n";
}

$invoke = new Invoke\CallableInvoke();
$invoke->invoke('hello', 'World');

Container Invoke

<?php

// some psr container
$container['service'] = function() {};
$invoke = Invoke\ContainerInvoke::create($container);
$invoke->invoke('service'); // will invoke the function returned from the container
$invoke->invoke('str_repeat', 'a', 10); // if not in container, will try to normally invoke

Container with Separator

In addition to just invoking services, you can invoke service object methods if you pass in a separator into the container factory method., (*5)

<?php

$container['service'] = function() { return new ArrayObject([1]); };
$invoke = Invoke\ContainerInvoke::createWithSeparator($container, '@');
$invoke->invoke('service@count'); // retrieves the service and invokes the count method which outputs 1 in this case

Method Invoke

<?php

// this will invoke any object with the append method
$invoke = Invoke\MethodInvoke::create('append');

$data = new ArrayObject();
$invoke->invoke($data, 1);
$invoke->invoke($data, 2);
assert(count($data) == 2);

The Versions

07/09 2017

dev-master

9999999-dev

Invocation Utility

  Sources   Download

MIT

The Development Requires

19/03 2017

v0.1.0

0.1.0.0

Invocation Utility

  Sources   Download

MIT

The Development Requires