承接 krak/invoke 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

krak/invoke

最新稳定版本:v0.1.0

Composer 安装命令:

composer require krak/invoke

包简介

Invocation Utility

README 文档

README

Simple abstractions for invoking functions with parameters.

Installation

Install with composer at krak/invoke

Usage

Each invoker implements the simple interface:

<?php

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

Here's a simple example of the default invoker which uses call_user_func.

<?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.

<?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);

统计信息

  • 总下载量: 1.28k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-19