Skip to content

Commit

Permalink
feature #25166 [WebProfilerBundle] Expose dotenv variables (ro0NL)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 4.1-dev branch (closes #25166).

Discussion
----------

[WebProfilerBundle] Expose dotenv variables

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes/no
| Fixed tickets | #23951
| License       | MIT
| Doc PR        | symfony/symfony-docs#... <!--highly recommended for new features-->

Variant of #23951

![image](https://user-images.githubusercontent.com/1047696/33243493-a6c94484-d2e7-11e7-9cfc-4a886d013f8b.png)

Commits
-------

de33d87 [WebProfilerBundle] Expose dotenv variables
  • Loading branch information
fabpot committed Dec 1, 2017
2 parents 424cbcc + de33d87 commit 2edb7fa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,15 @@
{% endif %}

<h3>Server Parameters</h3>
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.requestserver }, with_context = false) }}
<h4>Defined in .env</h4>
{{ include('@WebProfiler/Profiler/bag.html.twig', { bag: collector.dotenvvars }, with_context = false) }}

<h4>Defined as regular env variables</h4>
{% set requestserver = [] %}
{% for key, value in collector.requestserver if key not in collector.dotenvvars.keys %}
{% set requestserver = requestserver|merge({(key): value}) %}
{% endfor %}
{{ include('@WebProfiler/Profiler/table.html.twig', { data: requestserver }, with_context = false) }}
</div>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ public function collect(Request $request, Response $response, \Exception $except
$responseCookies[$cookie->getName()] = $cookie;
}

$dotenvVars = array();
foreach (explode(',', getenv('SYMFONY_DOTENV_VARS')) as $name) {
if ('' !== $name && false !== $value = getenv($name)) {
$dotenvVars[$name] = $value;
}
}

$this->data = array(
'method' => $request->getMethod(),
'format' => $request->getRequestFormat(),
Expand All @@ -100,6 +107,7 @@ public function collect(Request $request, Response $response, \Exception $except
'path_info' => $request->getPathInfo(),
'controller' => 'n/a',
'locale' => $request->getLocale(),
'dotenv_vars' => $dotenvVars,
);

if (isset($this->data['request_headers']['php-auth-pw'])) {
Expand Down Expand Up @@ -254,6 +262,11 @@ public function getLocale()
return $this->data['locale'];
}

public function getDotenvVars()
{
return new ParameterBag($this->data['dotenv_vars']->getValue());
}

/**
* Gets the route name.
*
Expand Down

0 comments on commit 2edb7fa

Please sign in to comment.