mamazu/partial-functions

该包最新版本(1.0.0)没有提供许可证信息。

应用部分函数

1.0.0 2020-09-29 16:29 UTC

This package is auto-updated.

Last update: 2024-09-06 18:42:28 UTC


README

这个库为PHP提供了部分函数接口。

使用方法

使用FunctionInvoker的简单用法

function f(string $greeting = 'Hello', string $name = 'you') {
    return $greeting.', '.$name;
}

echo \Mamazu\PartialFunctions\FunctionInvoker::invoke('f', ['name' => 'Anonymous']);

// Will echo "Hello, Anonymous"

面向对象

$factory = new \Mamazu\PartialFunctions\PartialFunctionFactory();
$searchInString = $factory->createForCallable('strpos');
$searchInString->apply(['haystack' => 'Hello in PHP']);

$hellopos = $searchInString->call(['needle' => 'hello']);
$phppos = $searchInString->call(['needle' => 'php']);