2017 © Pedro Peláez
 

library handler

A simple library for calling function and method

image

prob/handler

A simple library for calling function and method

  • Sunday, October 23, 2016
  • by jongpak
  • Repository
  • 1 Watchers
  • 2 Stars
  • 313 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Prob/Handler

A simple library for calling function and method, (*1)

Build Status codecov, (*2)

Usage

calling function

function in global namespace

<?php

use Prob\Handler\ProcFactory;

$procA = ProcFactory::getProc('pi');
echo $pro;                  // 3.141592...

$procB = ProcFactory::getProc('abs');
echo $proc->exec(-32);      // 32

function in user namespace

<?php

use Prob\Handler\ProcFactory;

$proc = ProcFactory::getProc('testFunc', 'Apple\\Banana');
print_r($proc->exec('one', 'two', 'three'));        // Array ( 'three', 'two', 'one' )

someFunc.php, (*3)

<?php

namespace Apple\Banana;

function testFunc($a, $b, $c)
{
    return [$c, $b, $a];
}

calling class method

<?php

use Prob\Handler\ProcFactory;

$proc = ProcFactory::getProc('Orange.testFunc', 'Apple\\Banana');
echo $proc->exec(10, 5);            // 15

someClass.php, (*4)

<?php

namespace Apple\Banana;

class Orange
{
    public function testFunc($a, $b)
    {
        return $a + $b;
    }
}

binding parameters

<?php

use Prob\Handler\ProcFactory;
use Prob\Handler\ParameterMap;
use Prob\Handler\Parameter\Named;
use Prob\Handler\Parameter\Typed;
use Prob\Handler\Parameter\TypedAndNamed;

use Apple\Banana\ValueObject;

$proc = ProcFactory::getProc('testFuncWithBinding', 'Apple\\Banana');

$vo = new ValueObject();
$vo->value = 'Welcome ';

$parameterMap = new ParameterMap();
$parameterMap->bindBy(new Named('arg3'), 'World!');
$parameterMap->bindBy(new Typed('array'), ['str' => 'Hello']);
$parameterMap->bindBy(new TypedAndNamed(ValueObject::class, 'arg1'), $vo);

// Welcome HelloWorld!
echo $proc->execWithParameterMap($parameterMap);

someFuncWithBinding.php, (*5)

<?php

namespace Apple\Banana;

function testFuncWithBinding(ValueObject $arg1, array $arg2, $arg3)
{
    return $arg1->value . $arg2['str'] . $arg3;
}

class ValueObject
{
    public $value;
}

The Versions

23/10 2016

dev-master

9999999-dev https://github.com/jongpak/prob-handler

A simple library for calling function and method

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

function handler method call prodecure