colorium/runtime 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

colorium/runtime

Composer 安装命令:

composer require colorium/runtime

包简介

Runtime Resolver, Annotation and Injector

README 文档

README

  • Read docblock annotations
  • Resolve any callable into a formalized Invokable instance

Exemple :

/**
 * @top notch
 */
class Some
{

    /**
     * @var int
     */
    protected $prop;

    /**
     * @foo bar
     * @param string $name
     */
    public function thing($name)
    {
        return 'Hello ' . $name . ' !';
    }
}

/**
 * @hell o
 */
 function hello()
 {
    return 'Hello !';
 }

Annotation

Read any meta tag existing in docblock.

use Colorium\Runtime\Annotation;

$annotations = Annotation::ofClass('Some'); // ['top' => 'notch']
$top = Annotation::ofClass('Some', 'top'); // 'notch'

$annotations = Annotation::ofProperty('Some', 'prop'); // ['var' => 'int']
$var = Annotation::ofProperty('Some', 'prop', 'var'); // 'int'

$annotations = Annotation::ofMethod('Some', 'thing'); // ['foo' => 'bar', 'param' => 'string $name']
$foo = Annotation::ofMethod('Some', 'thing', 'foo'); // 'bar'

$annotations = Annotation::ofFunction('hello'); // ['hell' => 'o']
$hell = Annotation::ofFunction('hello', 'hell'); // 'o'

The value is automaticaly and recursively casted as string, int, float, bool, array or object.

/**
 * @key -> null (but exists as annotation)
 * @key true -> bool
 * @key false -> bool
 * @key 10 -> int
 * @key 10.1 -> float
 * @key [10, 10] -> array (inner values are casted as well)
 * @key {foo: bar} -> stdClass with property foo set as 'bar'
 * @key othervalue -> string
 */

Resolver

Translate any valid callable into a resource instance. Callable can be :

  • an user closure: function(){}
  • an existing function name: 'function_name_that_exists'
  • a class-method couple name: 'Classname::method'
  • a class-method couple array name: ['Classname', 'method']
  • a class-method couple array instance: [$instance, 'method']
  • an invokable class name: 'Classname' (same as Classname::__invoke)
  • an invokable class instance: $instance (same as [$instance, '__invoke'])
use Colorium\Runtime\Resolver;

$invokable = Resolver::of('Some::thing');
if(!$invokable){
    // not a valid callable
}

$invokable->isStaticMethod(); // false
$invokable->isClassMethod(); // true
$invokable->isClosure(); // false

$foo = $invokable->annotation('foo'); // 'bar'
$annotations = $invokable->annotations(); // ['foo' => 'bar']

echo $invokable->call('You'); // Hello You !
echo $invokable('You'); // Hello You !

Install

composer require colorium/runtime

统计信息

  • 总下载量: 77
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-01-05

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固