ride/lib-api

API library of the Ride framework.

1.0.0 2016-10-11 17:28 UTC

This package is auto-updated.

Last update: 2024-12-13 01:22:41 UTC


README

Library to browse the API of your PHP code through reflection.

What's In This Library

DocParser

The DocParser class parses a doc comment string into a Doc instance.

An example of a doc comment string:

    /**
     * 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

The Doc class is a data container for the doc comment information as parsed by the DocParser.

DocParameter

The DocParameter class is a data container for the doc comment information of an argument of a function or method.

TagParser

The TagParser class is used by the DocParser to process the different tags (eg @param, @return, ...) of a doc comment.

Tag

The Tag interface is used to implement a specific doc comment tag.

ReflectionClass

The ReflectionClass extends from the PHP core class and adds methods to access the parsed Doc instances and other usefull things to generate an API doc.

ReflectionMethod

The ReflectionClass class extends from the PHP core class and adds methods to access the parsed Doc instances and the source code.

ReflectionProperty

The ReflectionProperty class extends from the PHP core class and adds methods to access the parsed Doc instances.

ApiBrowser

The ApiBrowser class is the facade to this library. Use this instance to check the available namespaces, the classes which reside therein or the full detail of an individual class.

Code Sample

Check the following code sample to see some of the possibilities of this library.

<?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) {
        
    }
}

Related Modules

Installation

You can use Composer to install this library.

composer require ride/lib-api