theorx/mapper

此包的最新版本(0.1)没有可用的许可信息。

Mapper 是一个从类获取元数据的 PHP 库。

0.1 2014-10-19 00:45 UTC

This package is not auto-updated.

Last update: 2024-09-24 09:08:17 UTC


README

Mapper 是一个从类获取元数据的库。

#特性#

  • 获取整个类的元数据(Mapper\Mapper::getMap($className))
  • 获取给定类的属性的元数据(Mapper\mapper::getPropertyMeta($className, $propertyName))
  • 获取给定类的方法的元数据(Mapper\Mapper::getMethodMeta($className, $methodName))
  • 定义自己的回调函数以写入缓存(Mapper\Mapper::setCacheSaveFunction($saveMethod))
  • 定义自己的回调函数以读取缓存(Mapper\Mapper::setCacheReadFunction($readFunction))

#作者#

  • Lauri Orgla

#要求#

  • PHP 5.5 及以上版本,带有反射模块
  • packagist.org 上的 theorx/reflectionist(与 composer 一起自动安装)

安装

$ git clone https://github.com/theorx/Mapper.git

$ ./composer.phar update

$ ./composer.phar dump-autoload -o

使用

<?php

Mapper\Mapper::setCacheSaveFunction(function($className, $data, $ttl){
    //Save data to disk or interface to any other caching backend
});

Mapper\Mapper::setCacheReadFunction(function($className, $ttl){
    //Read from disk / database or any other caching backend
});

$metaData = Mapper\Mapper::getMethodMeta('\Path\To\My\Class', 'MyMethodName');
//Returns method's metadata

示例输出

Array
(
    [\Tests\Stubs\StubExampleClass::test] => Array
        (
            [parameters] => Array
                (
                    [param1] => Array
                        (
                            [name] => param1
                            [type] =>
                            [isOptional] =>
                            [position] => 0
                            [defaultValue] =>
                        )

                    [param2] => Array
                        (
                            [name] => param2
                            [type] =>
                            [isOptional] =>
                            [position] => 1
                            [defaultValue] =>
                        )

                    [param3] => Array
                        (
                            [name] => param3
                            [type] =>
                            [isOptional] => 1
                            [position] => 2
                            [defaultValue] =>
                        )

                )

            [tags] => Array
                (
                    [@author] => Array
                        (
                            [0] => Lauri Orgla <TheOrX@hotmail.com>
                        )

                    [@param] => Array
                        (
                            [0] => $param1
                            [1] => $param2
                            [2] => null $param3
                        )

                )

        )

    [\Tests\Stubs\StubExampleClass::$primaryProperty] => Array
        (
            [tags] => Array
                (
                    [@custom-tag] => Array
                        (
                            [0] => CustoMTagValue
                            [1] => CustoMTagValue2
                            [2] => CustoMTagValue3
                        )

                    [@var] => Array
                        (
                            [0] => bool
                        )

                )

        )

)