diff --git a/config/config.default.php b/config/config.default.php index d086ca0..ba0291a 100644 --- a/config/config.default.php +++ b/config/config.default.php @@ -32,6 +32,7 @@ ), 'profiler.options' => array(), 'profiler.exclude-env' => array(), + 'profiler.exclude-all-env' => false, 'profiler.simple_url' => function ($url) { return preg_replace('/=\d+/', '', $url); }, diff --git a/examples/autoload.php b/examples/autoload.php index 13a451a..e689932 100644 --- a/examples/autoload.php +++ b/examples/autoload.php @@ -118,6 +118,11 @@ 'profiler.replace_url' => function ($url) { return str_replace('token', '', $url); }, + /** + * If true, excludes all environment variables from profiling data. + * @return bool + */ + 'profiler.exclude-all-env' => false, ); /** diff --git a/src/ProfilingData.php b/src/ProfilingData.php index 5ab12aa..6b44928 100644 --- a/src/ProfilingData.php +++ b/src/ProfilingData.php @@ -13,10 +13,13 @@ final class ProfilingData private $simpleUrl; /** @var callable|null */ private $replaceUrl; + /** @var bool */ + private $excludeAllEnv; public function __construct(Config $config) { $this->excludeEnv = isset($config['profiler.exclude-env']) ? (array)$config['profiler.exclude-env'] : array(); + $this->excludeAllEnv = isset($config['profiler.exclude-all-env']) ? $config['profiler.exclude-all-env'] : false; $this->simpleUrl = isset($config['profiler.simple_url']) ? $config['profiler.simple_url'] : null; $this->replaceUrl = isset($config['profiler.replace_url']) ? $config['profiler.replace_url'] : null; } @@ -79,6 +82,10 @@ public function getProfilingData(array $profile) */ private function getEnvironment(array $env) { + if ($this->excludeAllEnv) { + return array(); + } + foreach ($this->excludeEnv as $key) { unset($env[$key]); } diff --git a/tests/ProfilingDataTest.php b/tests/ProfilingDataTest.php new file mode 100644 index 0000000..ac0171f --- /dev/null +++ b/tests/ProfilingDataTest.php @@ -0,0 +1,39 @@ + true, + ]); + $profilingData = new ProfilingData($config); + + $profile = ['example' => 'data']; + $result = $profilingData->getProfilingData($profile); + + $this->assertEmpty($result['meta']['env']); + } + + public function testNotExcludeAllEnv() + { + $_ENV['TEST_EXCLUDE_ENV'] = 'TEST'; + + $config = new Config([ + 'profiler.exclude-all-env' => false, + ]); + $profilingData = new ProfilingData($config); + + $profile = ['example' => 'data']; + $result = $profilingData->getProfilingData($profile); + + $this->assertEquals('TEST', $result['meta']['env']['TEST_EXCLUDE_ENV']); + } +}