Skip to content

Commit 8f33996

Browse files
committed
feat: Add support for excluding all environment variables
1 parent 9a9b32c commit 8f33996

3 files changed

Lines changed: 33 additions & 0 deletions

File tree

config/config.default.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
),
3333
'profiler.options' => array(),
3434
'profiler.exclude-env' => array(),
35+
'profiler.is-exclude-all-env' => false,
3536
'profiler.simple_url' => function ($url) {
3637
return preg_replace('/=\d+/', '', $url);
3738
},

src/ProfilingData.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ final class ProfilingData
1313
private $simpleUrl;
1414
/** @var callable|null */
1515
private $replaceUrl;
16+
/** @var bool */
17+
private $isExcludeAllEnv;
1618

1719
public function __construct(Config $config)
1820
{
1921
$this->excludeEnv = isset($config['profiler.exclude-env']) ? (array)$config['profiler.exclude-env'] : array();
22+
$this->isExcludeAllEnv = isset($config['profiler.is-exclude-all-env']) ? $config['profiler.is-exclude-all-env'] : false;
2023
$this->simpleUrl = isset($config['profiler.simple_url']) ? $config['profiler.simple_url'] : null;
2124
$this->replaceUrl = isset($config['profiler.replace_url']) ? $config['profiler.replace_url'] : null;
2225
}
@@ -79,6 +82,10 @@ public function getProfilingData(array $profile)
7982
*/
8083
private function getEnvironment(array $env)
8184
{
85+
if($this->isExcludeAllEnv) {
86+
return array();
87+
}
88+
8289
foreach ($this->excludeEnv as $key) {
8390
unset($env[$key]);
8491
}

tests/ProfilingDataTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace Xhgui\Profiler\Test;
4+
5+
use Xhgui\Profiler\Config;
6+
use Xhgui\Profiler\ProfilingData;
7+
8+
class ProfilingDataTest extends TestCase
9+
{
10+
public function testExcludeAllEnv()
11+
{
12+
$config = new Config([
13+
'profiler.is-exclude-all-env' => true
14+
]);
15+
$profilingData = new ProfilingData($config);
16+
17+
$profile = ['example' => 'data'];
18+
$result = $profilingData->getProfilingData($profile);
19+
20+
21+
$this->assertEmpty($result['meta']['env']);
22+
}
23+
24+
25+
}

0 commit comments

Comments
 (0)