The Json Configuration File
Reflect always needs a file in JSON format to run.
It should be found either in the current, $HOME/.config/
, or /etc
directory.
By setting the REFLECT
environment variable it is possible to set the filename
of phpreflect.json
to something else.
E.g: REFLECT=my-phpreflect.json
The minimalist JSON file phpreflect.json
is :
{
"source-providers": [
{
"in": ". as current",
"name": "/\\.(php|inc|phtml)$/"
}
],
"plugins": [
{
"name": "Analyser",
"class": "Bartlett\\Reflect\\Plugin\\Analyser\\AnalyserPlugin"
}
],
"analysers" : [
{
"name": "Structure",
"class": "Bartlett\\Reflect\\Analyser\\StructureAnalyser"
}
]
}
- source-providers
- this entry provide list of your data sources to parse.
- plugins
- this entry list all plugins added to the core base code of PHP Reflect.
- analysers
-
this entry list all analysers that may be used with the
analyser:run
command.
section Source Providers
There are lot of way to filter your data source. Each rule follow the syntax of Symfony Finder Component.
The Location is the only mandatory criteria. It tells the Finder which directory to use for the search.
{
"in": ". as current"
}
as
)
is compared with the --alias
option constraint. {
"in": ". as current",
"in": "src/"
}
{
"in": "src/Bartlett/R*"
}
phar://
protocol {
"in": "phar://path/to/archive.zip"
}
{
"in": "phar://path/to/archive.zip",
"name": "*.php"
}
{
"in": "phar://path/to/archive.zip",
"name": "*.php",
"size": "< 10K"
}
{
"in": ". as current",
"date": "since yesterday"
}
By default, the Finder recursively traverse directories.
{
"in": ". as current",
"depth": "< 3"
}
{
"in": ". as current",
"exclude": "vendor"
}
{
"in": ". as current",
"exclude": ["vendor", "tests"]
}
section Plugins
There are a number of optional plugins you can use along with Reflect to add more capabilities.
The Analyser
is the only mandatory plugin you should add to parse your data source.
In your phpreflect.json
configuration file, add in plugins
section the following entry:
{
"name": "Analyser",
"class": "Bartlett\\Reflect\\Plugin\\Analyser\\AnalyserPlugin"
}
The name
key identify the namespace of optional commands the plugin may provide.
name
key must be unique to avoid conflicts.The class
key identify the name of the class that implement the plugin features.
Cache Plugin
In your phpreflect.json
configuration file, add in plugins
section the following entry:
{
"name": "Cache",
"class": "Bartlett\\Reflect\\Plugin\\Cache\\CachePlugin",
"options": {
"adapter": "DoctrineCacheAdapter",
"backend": {
"class": "Doctrine\\Common\\Cache\\FilesystemCache",
"args": [
"%{TEMP}/bartlett/cache"
]
}
}
}
TEMP
, HOME
HOME
syntax is compatible Linux/Windows.In previous configuration we used the Doctrine Cache adapter and its File system backend. See the same configuration applied with other SAPI, in developer guide
Log Plugin
In your phpreflect.json
configuration file, add in plugins
section the following entry:
{
"name": "Log",
"class": "Bartlett\\Reflect\\Plugin\\Log\\LogPlugin",
"options": {
"logger": {
"class": "YourLogger"
},
"conf": []
}
}
Where YourLogger
identify your class logger (fully qualified. E.g YourNamespace\YourLogger
).
See the Developer Guide for definition examples of some loggers using private logger or using monolog
And conf
entry are custom plugin options to apply.
For example, to suppress logging of reflect.success
event, and remove contextual data
on reflect.complete
event, modify your phpreflect.json
configuration file as follow :
{
"name": "Log",
"class": "Bartlett\\Reflect\\Plugin\\Log\\LogPlugin",
"options": {
"logger": {
"class": "YourLogger"
},
"conf": {
"reflect.success": false,
"reflect.complete": {
"context": false
}
}
}
}
All configuration options are available, see Register Plugin of Log section.
section Analysers
There are a number of optional analysers you can use along with the Reflect Analyser Plugin.
The Structure
is the default analyser you should add to obtain results when you parse your data source.
In your phpreflect.json
configuration file, add in analysers
section the following entry:
{
"name": "Structure",
"class": "Bartlett\\Reflect\\Analyser\\StructureAnalyser"
}
The name
key identify the name you can optionally invoke with the analyser:run
command.
The two following commands do the same:
$ phpreflect analyser:run .
$ phpreflect analyser:run . structure
name
key must be unique to avoid conflicts.The class
key identify the name of the class that implement the analyser features.