Skip to content

Commit

Permalink
feature #609 Move easyadmin_dump to collector instead of a Twig Exten…
Browse files Browse the repository at this point in the history
…sion (ogizanagi)

This PR was merged into the master branch.

Discussion
----------

Move easyadmin_dump to collector instead of a Twig Extension

Just to know: why not this instead of defining a Twig function that does not have to be used elsewhere nor in userland ?

Commits
-------

193cee2 Move easyadmin_dump to collector instead of a Twig Extension
  • Loading branch information
javiereguiluz committed Nov 29, 2015
2 parents df17628 + 193cee2 commit a367a6d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 34 deletions.
27 changes: 27 additions & 0 deletions DataCollector/EasyAdminDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use JavierEguiluz\Bundle\EasyAdminBundle\Configuration\Configurator;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
use Symfony\Component\Yaml\Yaml;

/**
* Collects information about the requests related to EasyAdmin and displays
Expand Down Expand Up @@ -81,6 +84,30 @@ public function getBackendConfiguration()
return $this->data['backend_configuration'];
}

/**
* It dumps the contents of the given variable using the VarDumper component
* (this avoids requiring the DebugBundle which defines the dump() Twig function).
* It fallbacks to Yaml dumper or var_export() if VarDumper component is not
* available.
*
* @param mixed $variable
*
* @return string
*/
public function dump($variable)
{
if (class_exists('Symfony\Component\VarDumper\Dumper\HtmlDumper')) {
$cloner = new VarCloner();
$dumper = new HtmlDumper();

return $dumper->dump($cloner->cloneVar($variable));
} elseif (class_exists('Symfony\Component\Yaml\Yaml')) {
return sprintf('<pre class="sf-dump">%s</pre>', Yaml::dump((array) $variable, 1024));
} else {
return sprintf('<pre class="sf-dump">%s</pre>', var_export($variable, true));
}
}

public function getName()
{
return 'easyadmin';
Expand Down
12 changes: 6 additions & 6 deletions Resources/views/data_collector/easyadmin.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<div class="tab">
<h3 class="tab-title">Current Entity Configuration</h3>
<div class="tab-content">
{{ easyadmin_dump(collector.currentEntityConfiguration) }}
{{ collector.dump(collector.currentEntityConfiguration) }}
</div>

<br>
Expand All @@ -86,18 +86,18 @@
<div class="tab-content">

<h4>Basic Configuration</h4>
{{ easyadmin_dump({
{{ collector.dump({
'site_name': collector.backendConfiguration['site_name'],
'formats': collector.backendConfiguration['formats']
}) }}

<h4>Design Configuration</h4>
{{ easyadmin_dump({
{{ collector.dump({
'design': collector.backendConfiguration['design']
}) }}

<h4>Actions Configuration</h4>
{{ easyadmin_dump({
{{ collector.dump({
'disabled_actions': collector.backendConfiguration['disabled_actions'],
'list': collector.backendConfiguration['list'],
'edit': collector.backendConfiguration['edit'],
Expand All @@ -106,12 +106,12 @@
}) }}

<h4>Entities Configuration</h4>
{{ easyadmin_dump({
{{ collector.dump({
'entities': collector.backendConfiguration['entities']
}) }}

<h4>Full Backend Configuration</h4>
{{ easyadmin_dump({
{{ collector.dump({
'easy_admin': collector.backendConfiguration
}) }}
</div>
Expand Down
28 changes: 0 additions & 28 deletions Twig/EasyAdminTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@

use Doctrine\ORM\PersistentCollection;
use JavierEguiluz\Bundle\EasyAdminBundle\Configuration\Configurator;
use Symfony\Component\VarDumper\Cloner\VarCloner;
use Symfony\Component\VarDumper\Dumper\HtmlDumper;
use Symfony\Component\Yaml\Yaml;

/**
* Defines the filters and functions used to render the bundle's templates.
Expand All @@ -42,7 +39,6 @@ public function getFunctions()
new \Twig_SimpleFunction('easyadmin_action_is_enabled_for_*_view', array($this, 'isActionEnabled')),
new \Twig_SimpleFunction('easyadmin_get_action_for_*_view', array($this, 'getActionConfiguration')),
new \Twig_SimpleFunction('easyadmin_get_actions_for_*_item', array($this, 'getActionsForItem')),
new \Twig_SimpleFunction('easyadmin_dump', array($this, 'dump'), array('is_safe' => array('html'))),
);
}

Expand Down Expand Up @@ -251,30 +247,6 @@ public function getActionsForItem($view, $entityName)
});
}

/**
* It dumps the contents of the given variable using the VarDumper component
* (this avoids requiring the DebugBundle which defines the dump() Twig function).
* It fallbacks to Yaml dumper or var_export() if VarDumper component is not
* available.
*
* @param mixed $variable
*
* @return string
*/
public function dump($variable)
{
if (class_exists('Symfony\Component\VarDumper\Dumper\HtmlDumper')) {
$cloner = new VarCloner();
$dumper = new HtmlDumper();

return $dumper->dump($cloner->cloneVar($variable));
} elseif (class_exists('Symfony\Component\Yaml\Yaml')) {
return sprintf('<pre class="sf-dump">%s</pre>', Yaml::dump((array) $variable, 1024));
} else {
return sprintf('<pre class="sf-dump">%s</pre>', var_export($variable, true));
}
}

/*
* Copied from the official Text Twig extension.
*
Expand Down

0 comments on commit a367a6d

Please sign in to comment.