The Json Configuration File
CompatInfo may used an optional config file in JSON format.
It could be found either in the current, $HOME/.config/
, or /etc
directory.
By setting the BARTLETTRC
environment variable it is possible to set the filename
of phpcompatinfo.json
to something else.
E.g: BARTLETTRC=my-phpcompatinfo.json
And by setting the BARTLETT_SCAN_DIR
environment variable it is possible to change
directories where to search for the json config file.
E.g: BARTLETT_SCAN_DIR=.:/var/configs:/tmp/bartlett
(for Linux)
E.g: BARTLETT_SCAN_DIR=.;\var\configs;\tmp\bartlett
(for Windows)
Take care of different PATH_SEPARATOR and DIRECTORY_SEPARATOR in each platform.
The minimalist JSON file phpcompatinfo.json
is :
{
"source-providers": [
{
"in": ". as current",
"name": "/\\.(php|inc|phtml)$/"
}
],
"plugins": [
],
"analysers": [
],
"services": [
]
}
- 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 CompatInfo.
- analysers
-
this entry list all analysers that may be used with the
analyser:run
command. - services
- this entry list all services that may be used with this application.
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 CompatInfo to add more capabilities.
Take an example with the Logger
plugin.
In your phpcompatinfo.json
configuration file, add in plugins
section the following entry:
{
"name": "Logger",
"class": "Bartlett\\Reflect\\Plugin\\LogPlugin"
}
-
The
name
key is (since version 4.0.0-alpha1) comment only. -
The
class
key identify the name of the class that implement the plugin features (must be fully qualified).
LogPlugin
used by default the Bartlett\Reflect\Plugin\Log\DefaultLogger
class that write results to error_logCache Plugin
In your phpcompatinfo.json
configuration file, add in plugins
section the following entry:
{
"name": "Cache",
"class": "Bartlett\\Reflect\\Plugin\\CachePlugin",
"options": {
"adapter": "DoctrineCacheAdapter",
"backend": {
"class": "Doctrine\\Common\\Cache\\FilesystemCache",
"args": [
"%{TEMP}/bartlett/cache"
]
}
}
}
TEMP
, HOME
HOME
syntax is compatible Linux/Windows.If you want to used the same options (Doctrine adapter with file cache) as above, you can used shortcut syntax like this.
{
"name": "Cache",
"class": "Bartlett\\Reflect\\Plugin\\CachePlugin",
"options": []
}
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 phpcompatinfo.json
configuration file, add in plugins
section the following entry:
{
"name": "Log",
"class": "Bartlett\\Reflect\\Plugin\\LogPlugin"
}
Where options
key identify an optional class logger (fully qualified. E.g YourNamespace\YourLogger
).
When options
key is not provided, log plugin used the default Reflect logger bundled with distribution.
See Bartlett\Reflect\Plugin\Log\DefaultLogger
that write results to the error log system.
See the Developer Guide for definition examples of some loggers using private logger or using monolog
section Analysers
There are default analysers you can use, but you are free to add your owns.
In your phpcompatinfo.json
configuration file, add in analysers
section (for example) the following entry:
{
"name": "MyAnalyser",
"class": "Your\\Analysers\\MyAnalyser"
}
-
The
name
key is (since version 4.0.0-alpha1) comment only. -
The
class
key identify the name of the class that implement your analyser (must be fully qualified).
Your analyser should implement both interfaces Bartlett\Reflect\Analyser\AnalyserInterface
and PhpParser\NodeVisitor
.
Then to use it in command line :
$ phpcompatinfo analyser:run /path/to/datasource my
my
identify your analyser (prefix in lower case of MyAnalyser
class)