Git Product home page Git Product logo

reflection's Introduction

phpDocumentor/Reflection

Build Status Scrutinizer Code Quality Code Coverage

Using this library it is possible to statically reflect one or more files and create an object graph representing your application's structure, including accompanying in-source documentation using DocBlocks.

The information that this library provides is similar to what the (built-in) Reflection extension of PHP provides; there are however several advantages to using this library:

  • Due to its Static nature it does not execute procedural code in your reflected files where Dynamic Reflection does.
  • Because the none of the code is interpreted by PHP (and executed) Static Reflection uses less memory.
  • Can reflect complete files
  • Can reflect a whole project by reflecting multiple files.
  • Reflects the contents of a DocBlock instead of just mentioning there is one.
  • Is capable of analyzing code written for any PHP version (starting at 5.2) up to and including your installed PHP version.

Features

  • [Creates an object graph] containing the structure of your application much like a site map shows the structure of a website.
  • Can read and interpret code of any PHP version starting with 5.2 up to and including your currently installed version of PHP.
  • Due it's clean interface it can be in any application without a complex setup.

Installation

In order to inspect a codebase you need to tell composer to include the phpdocumentor/reflection package. This can easily be done using the following command in your command line terminal:

composer require "phpdocumentor/reflection: ~2.0"

After the installation is complete no further configuration is necessary and you can immediately start using it.

Basic Usage

This Reflection library uses PSR-4 and it is recommended to use a PSR-4 compatible autoloader to load all the files containing the classes for this library.

An easy way to do this is by including the composer autoloader as shown here:

include 'vendor/autoload.php';

Once that is done you can use the createIntance() method of the \phpDocumentor\Reflection\Php\ProjectFactory class to instantiate a new project factory and pre-configure it with sensible defaults.

$projectFactory = \phpDocumentor\Reflection\Php\ProjectFactory::createInstance();

At this point we are ready to analyze your complete project or just one file at the time. Just pass an array of file paths to the create method of the project factory.

$projectFiles = ['tests/example.file.php'];
$project = $projectFactory->create('My Project', $projectFiles);

When the process is ready a new object of type phpDocumentor\Reflection\Php\Project will be returned that contains a complete hierarchy of all files with their classes, traits and interfaces (and everything in there), but also all namespaces and packages as a hierarchical tree.

See the example script for a detailed and commented example

reflection's People

Contributors

adrianhardy avatar ashnazg avatar benji07 avatar boenrobot avatar cebe avatar flip111 avatar gammamatrix avatar gquemener avatar grahamcampbell avatar jaapio avatar joncave avatar ksimka avatar mvriel avatar scrutinizer-auto-fixer avatar tommygnr avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.