* @since Thelia v 2.4 */ class VarDumper extends AbstractSmartyPlugin { /** @var bool */ protected $debug; /** * VarDumper constructor. * @param bool $debug */ public function __construct($debug) { $this->debug = $debug; } public function dump($params, $template = null) { if (!$this->debug) { throw new \Exception('The smarty function "dump" is available only in debug mode.'); } if (!function_exists('dump')) { throw new \Exception('The function "dump" was no available. Check that this project has the package symfony/var-dumper in the composer.json file,' . ' and that you have installed dev dependencies : composer.phar install --dev'); } ob_start(); foreach ($params as $name => $param) { $type = gettype($param); echo '
' . $name . ' : ' . ($type === 'object' ? get_class($param) : $type) . '
'; dump($param); } $dump = ob_get_contents(); ob_end_clean(); return $dump; } /** * @return array an array of SmartyPluginDescriptor */ public function getPluginDescriptors() { return array( new SmartyPluginDescriptor('function', 'dump', $this, 'dump') ); } }