The Json Configuration File
CompatInfo 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 COMPATINFO
environment variable it is possible to set the filename
of phpcompatinfo.json
to something else.
E.g: COMPATINFO=my-phpcompatinfo.json
The minimalist JSON file phpcompatinfo.json
is :
{
"source-providers": [
{
"in": ". as current",
"name": "/\\.(php|inc|phtml)$/"
}
],
"plugins": [
{
"name": "Analyser",
"class": "Bartlett\\Reflect\\Plugin\\Analyser\\AnalyserPlugin"
}
],
"analysers" : [
{
"name": "Namespace",
"class": "Bartlett\\CompatInfo\\Analyser\\NamespaceAnalyser"
},
{
"name": "Extension",
"class": "Bartlett\\CompatInfo\\Analyser\\ExtensionAnalyser"
},
{
"name": "Interface",
"class": "Bartlett\\CompatInfo\\Analyser\\InterfaceAnalyser"
},
{
"name": "Trait",
"class": "Bartlett\\CompatInfo\\Analyser\\TraitAnalyser"
},
{
"name": "Class",
"class": "Bartlett\\CompatInfo\\Analyser\\ClassAnalyser"
},
{
"name": "Function",
"class": "Bartlett\\CompatInfo\\Analyser\\FunctionAnalyser"
},
{
"name": "Constant",
"class": "Bartlett\\CompatInfo\\Analyser\\ConstantAnalyser"
},
{
"name": "Summary",
"class": "Bartlett\\CompatInfo\\Analyser\\SummaryAnalyser"
},
{
"name": "Condition",
"class": "Bartlett\\CompatInfo\\Analyser\\CodeCondAnalyser"
},
{
"name": "Structure",
"class": "Bartlett\\Reflect\\Analyser\\StructureAnalyser"
},
{
"name": "Composer",
"class": "Bartlett\\CompatInfo\\Analyser\\ComposerAnalyser"
}
]
}
- 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.
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"]
}
Plugins
There are a number of optional plugins you can use along with CompatInfo to add more capabilities.
The Analyser
is the only mandatory plugin you should add to parse your data source.
In your phpcompatinfo.json
configuration file, add in plugins
section the following entry:
{
"name": "Analyser",
"class": "Bartlett\\Reflect\\Plugin\\Analyser\\AnalyserPlugin"
}
Analyser
plugin is a component from Reflect, and not from CompatInfo. Take care of namespace !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 phpcompatinfo.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 phpcompatinfo.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.
Analysers
There are a number of optional analysers you can use along with the Reflect Analyser Plugin.
The Summary
is the default analyser you should add to obtain results when you parse your data source.
In your phpcompatinfo.json
configuration file, add in analysers
section the following entry:
{
"name": "Structure",
"class": "Bartlett\\CompatInfo\\Analyser\\SummaryAnalyser"
}
The name
key identify the name you can optionally invoke with the analyser:run
command.
The two following commands do the same:
$ phpcompatinfo analyser:run .
$ phpcompatinfo analyser:run . summary
name
key must be unique to avoid conflicts.The class
key identify the name of the class that implement the analyser features.
Conditional Code
CompatInfo is now capable to detect conditional code, mark each element in all analysers reporting, and exclude their versions from PHP min/max final results.
Let’s see with CompatInfo source code, and explain results.
The new condition analyser (CodeCondAnalyser
), is able to produce such kind of report :
Data Source Analysed Directories 7 Files 127 Conditional Code Analysis Condition REF EXT min/Max PHP min/Max class_exists(\PHP_Timer) user 4.0.0 defined(INTL_ICU_VERSION) intl 2.0.0b1 5.3.7 defined(OPENSSL_VERSION_NUMBER) openssl 5.2.0 5.2.0 defined(OPENSSL_VERSION_TEXT) openssl 5.2.0 5.2.0 function_exists(curl_version) curl 4.0.2 4.0.2 function_exists(event_priority_set) libevent 0.0.5 5.3.0 Total [6] 5.3.7
That meens CompatInfo need at least PHP 5.3.7 if you used all conditional features. But remember, that the minimum version is only PHP 5.3.0 (see summary report).
Data Source Analysed Directories 7 Files 127 Global Analysis Count Cond PHP min Elements highlight Extensions 11 4 5.3.0 Core Namespaces 14 0 5.3.0 Bartlett\CompatInfo\Reference Interfaces 3 0 5.3.0 Bartlett\CompatInfo\Reference\ReferenceInterface Traits 0 0 Classes 140 1 5.3.0 Bartlett\CompatInfo\Reference\Extension\RarExtension User Functions 5 0 5.3.0 Bartlett\CompatInfo\Reference\closure-335-372 Internal Functions 47 2 5.2.0 json_encode Constants 13 3 5.3.0 __DIR__ Total 5.3.0
The new Cond
column tell you how many condition where found in each category.
And of course the condition analyser give you the details.
And finally, all other analysers show you with a C
mark in front of element name
when it’s excluded from PHP min/max versions, and considered as conditional code.