8000 [WebProfilerBundle] Add a pane with loaded envs by voronkovich · Pull Request #23951 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[WebProfilerBundle] Add a pane with loaded envs #23951

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Symfony/Bundle/FrameworkBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
3.4.0
-----

* Added `DotenvDataCollector` to collect envs loaded by the Dotenv component
* Deprecated `profiler.matcher` option
* Added support for `EventSubscriberInterface` on `MicroKernelTrait`
* Removed `doctrine/cache` from the list of required dependencies in `composer.json`
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\DataCollector;

use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;

/**
* Collects environment variables loaded by the Dotenv component.
*
* @author Oleg Voronkovich <oleg-voronkovich@yandex.ru>
*/
class DotenvDataCollector extends DataCollector
{
/**
* {@inheritdoc}
*/
public function collect(Request $request, Response $response, \Exception $exception = null)
{
$this->data['envs'] = array();

$loadedVars = array_filter(explode(',', getenv('SYMFONY_DOTENV_VARS')));

foreach ($loadedVars as $var) {
if (false !== getenv($var)) {
$this->data['envs'][$var] = getenv($var);
}
}
}

/**
* Gets loaded environment variables.
*
* @return array
*/
public function getEnvs()
{
return $this->data['envs'];
}

/**
* {@inheritdoc}
*/
public function getName()
{
return 'dotenv';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@
<tag name="kernel.event_listener" event="kernel.controller" method="onKernelController"/>
<tag name="data_collector" template="@WebProfiler/Collector/router.html.twig" id="router" priority="285" />
</service>

<service id="data_collector.dotenv" class="Symfony\Bundle\FrameworkBundle\DataCollector\DotenvDataCollector">
<tag name="data_collector" id="dotenv" />
</service>
</services>
</container>
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\FrameworkBundle\Tests\DataCollector;

use PHPUnit\Framework\TestCase;
use Symfony\Bundle\FrameworkBundle\DataCollector\DotenvDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class DotenvDataCollectorTest extends TestCase
{
public function testCollect()
{
putenv('SYMFONY_DOTENV_VARS=APP_DEBUG,DATABASE_URL,DELETED_VAR');

putenv('APP_DEBUG=1');
putenv('DATABASE_URL=sqlite:///var/data/db.sqlite');
putenv('DELETED_VAR');

$collector = new DotenvDataCollector();
$collector->collect(new Request(), new Response());

$this->assertEquals(array('APP_DEBUG' => '1', 'DATABASE_URL' => 'sqlite:///var/data/db.sqlite'), $collector->getEnvs());
}

public function testSpecialVariableNotExists()
{
putenv('SYMFONY_DOTENV_VARS');

$collector = new DotenvDataCollector();
$collector->collect(new Request(), new Response());

$this->assertEmpty($collector->getEnvs());
}
}
1 change: 1 addition & 0 deletions src/Symfony/Bundle/WebProfilerBundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CHANGELOG
3.4.0
-----

* added a pane with envs loaded by the Dotenv component
* Deprecated the `web_profiler.position` config option (in 4.0 version the toolbar
will always be displayed at the bottom) and the `web_profiler.debug_toolbar.position`
container parameter.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,24 @@
</div>
</div>

{% if profile.hasCollector('dotenv') %}
<div class="tab {{ profile.collector('dotenv').envs is empty ? 'disabled' }}">
<h3 class="tab-title">.env</h3>

<div class="tab-content">
<h3>Loaded variables</h3>

{% if profile.collector('dotenv').envs is empty %}
<div class="empty">
<p>No variables were loaded.</p>
</div>
{% else %}
{{ include('@WebProfiler/Profiler/table.html.twig', { data: profile.collector('dotenv').envs }, with_context = false) }}
{% endif %}
</div>
</div>
{% endif %}

{% if profile.parent %}
<div class="tab">
<h3 class="tab-title">Parent Request</h3>
Expand Down
0