Environment ProviderΒΆ
Environment providers are used to record information about the running environment, they are called before the benchmark is run.
Create a new environment provider class similar to the following:
namespace PhpBench\Examples\Extension\Environment;
use PhpBench\Environment\Information;
use PhpBench\Environment\ProviderInterface;
class HomeProvider implements ProviderInterface
{
public function isApplicable(): bool
{
// Example: this provider requires the HOME environment variable to be set.
return (bool) getenv('HOME');
}
public function getInformation(): Information
{
// Example: return the value of the HOME environment variable.
return new Information('home', [
'directory' => getenv('HOME'),
]);
}
}
And register with your DI container:
namespace PhpBench\Examples\Extension;
use PhpBench\DependencyInjection\Container;
use PhpBench\DependencyInjection\ExtensionInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class AcmeExtension implements ExtensionInterface
{
public function configure(OptionsResolver $resolver): void
{
}
public function load(Container $container): void
{
$container->register(HomeProvider::class, function (Container $container) {
return new HomeProvider();
}, [
RunnerExtension::TAG_ENV_PROVIDER => [
'name' => 'home',
]
]);
}
}
Run it with:
$ phpbench run --report=env