ride/lib-api

Ride 框架的 API 库。

1.0.0 2016-10-11 17:28 UTC

This package is auto-updated.

Last update: 2024-09-13 00:32:36 UTC


README

通过反射浏览您的 PHP 代码 API 的库。

本库包含内容

DocParser

DocParser 类将文档注释字符串解析为 Doc 实例。

一个文档注释字符串的示例

    /**
     * Gets a list of namespaces
     * @param string $namespace Filter namespaces with the provided namespace
     * @return array Ordered array with the namespace as key and value
     */

Doc

Doc 类是用于存储由 DocParser 解析的文档注释信息的容器。

DocParameter

DocParameter 类是用于存储函数或方法的参数的文档注释信息的容器。

TagParser

TagParser 类由 DocParser 使用,以处理文档注释中的不同标签(例如 @param, @return, ...)。

Tag

Tag 接口用于实现特定的文档注释标签。

ReflectionClass

ReflectionClass 类继承自 PHP 核心类,并添加了访问解析的 Doc 实例和其他生成 API 文档的有用方法。

ReflectionMethod

ReflectionClass 类继承自 PHP 核心类,并添加了访问解析的 Doc 实例和源代码的方法。

ReflectionProperty

ReflectionProperty 类继承自 PHP 核心类,并添加了访问解析的 Doc 实例的方法。

ApiBrowser

ApiBrowser 类是本库的代理。使用此实例检查可用的命名空间、其中包含的类或单个类的详细信息。

代码示例

查看以下代码示例,以了解本库的一些可能性。

<?php

use ride\library\api\doc\DocParser;
use ride\library\api\ApiBrowser;
use ride\library\system\file\FileSystem;

function createApiBrowser(FileSystem $fileSystem) {
    $includePaths = array(
        '/path/to/source1',
        '/path/to/source2',
    );
    
    $tagParser = new TagParser();
    $docParser = new DocParser($tagParser);
    
    $apiBrowser = new ApiBrowser($docParser, $fileSystem, $includePaths);
    
    return $apiBrowser;
}

function useApiBrowser(ApiBrowser $apiBrowser) {
    // get all available namespaces
    $namespaces = $apiBrowser->getNamespaces();
    
    // get all namespaces in a specific namespace
    $subNamespaces = $apiBrowser->getNamespaces('ride\\library\\api');
    // array(
    //     'ride\\library\\api' => 'ride\\library\\api', 
    //     'ride\\library\\api\\doc' => 'ride\\library\\api\\doc', 
    //     'ride\\library\\api\\doc\\tag' => 'ride\\library\\api\\doc\\tag', 
    //     'ride\\library\\api\\io' => 'ride\\library\\api\\io', 
    //     'ride\\library\\api\\reflection' => 'ride\\library\\api\\reflection', 
    // );
    
    $classes = $apiBrowser->getClassesForNamespace('ride\\library\\api');
    // array(
    //     'ride\\library\\api\\ApiBrowser' => 'ApiBrowser',
    // );
    
    $class = $apiBrowser->getClass('ride\\library\\api\\ApiBrowser');
    
    $doc = $class->getDoc();
    $type = $class->getTypeAsString(); // abstract class, interface
    
    // an array with for each class, the methods it overrides or implements 
    $inheritance = $class->getInheritance();
    // array(
    //     'className' => array(
    //          'methodName' => 'ReflectionMethod',
    //     ), 
    // );
    
    // an array with all classes it extends or implements
    $parents = $class->getParentArray();
    // array(
    // );
    
    $methods = $class->getMethods();
    foreach ($methods as $methodName => $method) {
        $doc = $method->getDoc();
        $type = $method->getTypeAsString(); // abstract protected, ...
        $source = $method->getSource();
        
        $forInterface = $class->getMethodInterface($methodName);
        $false = $method->isInherited('ride\\library\\api\\ApiBrowser');
    }
    
    $properties = $class->getProperties();
    foreach ($properties as $propertyName => $property) {
        $doc = $property->getDoc();
        $type = $property->getTypeAsString();
    }
    
    $constants = $class->getConstants();
    foreach ($constants as $name => $value) {
        
    }
}

相关模块

安装

您可以使用 Composer 安装此库。

composer require ride/lib-api