The Command-Line
The command-line interface is the easiest way to try and learn the basic Reflect features.
Command-Line Options
Without plugins
and analysers
sections in your phpreflect.json
configuration file,
when you invoke the phpreflect
command, you should obtain the following commands and options :
phpReflect version 2.0.0 build b45be1d0d1b5a46253f9cda894dd7717f0a64abd Usage: [options] command [arguments] Options: --help -h Display this help message. --quiet -q Do not output any message. --verbose -v|vv|vvv Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug --version -V Display this application version. --ansi Force ANSI output. --no-ansi Disable ANSI output. --no-interaction -n Do not ask any interactive question. --profile Display timing and memory usage information. Available commands: help Displays help for a command list Lists commands plugin plugin:list List all plugins installed. provider provider:display Show source of a file in a data source. provider:list List all data source providers. provider:show Show list of files in a data source.
- plugin:list
-
List all plugins configured (and correctly installed) in
plugins
section of yourphpreflect.json
config file.Without plugins, you will get$ phpreflect plugin:list [Json Configuration] No plugins detected.
With onlyAnalyser
plugin configured, you will get$ phpreflect plugin:list Plugin Name Plugin Class Events Subscribed Analyser Bartlett\Reflect\Plugin\Analyser\AnalyserPlugin reflect.complete
- provider:list
-
List all data source providers configured in
source-providers
section of yourphpreflect.json
config file.Result may vary depending of your current directory, but you will get something like$ phpreflect provider:list Source Alias Files . current 46
- provider:show
-
Show list of files corresponding to the (Symfony) Finder rules defined.
With Reflect source files
$ phpreflect provider:show .
Possible alternative
$ phpreflect provider:show --alias current
Source Files . 46 Relative Path Name Date Size Bartlett\Reflect\Analyser\AbstractAnalyser.php 2014-02-03T17:25:07+01:00 3475 Bartlett\Reflect\Analyser\AnalyserInterface.php 2014-02-03T17:26:50+01:00 835 Bartlett\Reflect\Analyser\StructureAnalyser.php 2014-02-23T17:31:16+01:00 12798 <... more lines ...>
- provider:display
-
Show source code of a file in one of the data source identified.
With
Bartlett\Reflect.php
in the current data source$ phpreflect provider:display . Bartlett\Reflect.php
Possible alternative
$ phpreflect provider:display --alias current Bartlett\Reflect.php
Source . Relative Path Name Date Size Id Token Line Text 0 T_OPEN_TAG 1 <?php 1 T_DOC_COMMENT 2 /** * Reflect * Reverse-engineer 2 T_WHITESPACE 15 3 T_NAMESPACE 17 namespace 4 T_WHITESPACE 17 5 T_STRING 17 Bartlett 6 T_SEMICOLON 17 ; <... more lines ...>
When the Analyser
plugin is installed, following lines added into analysers
section
{ "name": "Analyser", "class": "Bartlett\\Reflect\\Plugin\\Analyser\\AnalyserPlugin" }
you will get two additionnal commands.
- analyser:list
-
List all analysers configured in
analysers
section of yourphpreflect.json
config file.Without analysers, you will get$ phpreflect analyser:list [Json Configuration] No analysers detected.
With onlyAnalyser
plugin configured, you will get$ phpreflect analyser:list Analyser Name Analyser Class Structure Bartlett\Reflect\Analyser\StructureAnalyser
- analyser:run
-
Parse a data source and display results. May wary depending of the data source and analyser used.
With
structure
analyser and the Reflect source code, you will get something like$ phpreflect analyser:run .
Possible alternative
$ phpreflect analyser:run --alias current
Data Source Analysed Directories 16 Files 46 Structure Namespaces 16 Interfaces 0 Traits 0 Classes 38 Abstract Classes 5 (13.16%) Concrete Classes 33 (86.84%) Methods 256 Scope Non-Static Methods 251 (98.05%) Static Methods 5 (1.95%) Visibility Public Method 232 (90.62%) Protected Method 24 (9.38%) Private Method 0 (0.00%) Functions 5 Named Functions 0 (0.00%) Anonymous Functions 5 (100.00%) Constants 102 Global Constants 101 (99.02%) Class Constants 1 (0.98%)
When the plantUML
plugin is installed, following lines added into plugins
section
{ "name": "PlantUML", "class": "Bartlett\\Reflect\\Plugin\\PlantUML\\PlantUMLPlugin" }
you will get one additionnal command.
- plantUML:run
-
Parse a data source and draw corresponding UML diagrams (package or class)
with the PlantUML syntax.
Build a package diagram corresponding to
Bartlett\Reflect\Model
$ phpreflect plantUML:run --package=Bartlett\Reflect\Model .
Possible Alternative
$ phpreflect plantUML:run --package=Bartlett\Reflect\Model --alias current
PlantUML package diagram package "Bartlett\\Reflect\\Model" { abstract AbstractFunctionModel abstract AbstractModel class ClassModel class ConstantModel class DependencyModel class FunctionModel class IncludeModel class MethodModel class PackageModel class ParameterModel class PropertyModel }
It’s now time to produce PNG images. Put previous PlantUML code syntax into a text file (e.g named
packageDiagram.plantuml
), and run the following command.$ java -jar plantuml.jar packageDiagram.plantuml
And you should obtain a PNG image like this one
Build a class diagram corresponding toBartlett\Reflect\Builder
$ phpreflect plantUML:run --class=Bartlett\Reflect\Builder .
Possible Alternative
$ phpreflect plantUML:run --class=Bartlett\Reflect\Builder --alias current
PlantUML class diagram set namespaceSeparator none namespace Bartlett.Reflect { class Builder { -packages -classes -interfaces -traits -functions -constants -includes -dependencies -file -namespace -- +setCurrentFile() +beforeTraverse() +enterNode() +leaveNode() #parseNewStatement() #parseUserConstant() #parseUserFunction() #parseInternalFunction() #parseFunctionArguments() +buildPackage() +buildClass() +buildInterface() +buildTrait() +buildFunction() +buildConstant() +buildInclude() +buildDependency() +buildFromCache() +getPackages() +getClasses() +getInterfaces() +getTraits() +getFunctions() +getConstants() +getIncludes() +getDependencies() } }
It’s now time to produce PNG images. Put previous PlantUML code syntax into a text file (e.g named
classDiagram.plantuml
), and run the following command.$ java -jar plantuml.jar classDiagram.plantuml
And you should obtain a PNG image like this one
Summary
Let’s review what we’ve learned about the command-line interface :
-
It’s a Symfony Console Component that can be extended to infinite via plugins and analysers.
-
Default analyser produced results such as PHPLoc by Sebastian Bergmann.
-
May generate class and package UML diagrams with PlantUML.
Next
For PHP developers only.