Skip to content

Instantly share code, notes, and snippets.

@ftdysa
Forked from merk/GlobalVariables.php
Created November 7, 2013 22:11
Show Gist options
  • Save ftdysa/7362741 to your computer and use it in GitHub Desktop.
Save ftdysa/7362741 to your computer and use it in GitHub Desktop.
parameters:
templating.globals.class: Ibms\Helper\GlobalVariables
<?php
namespace Ibms\Helper;
use Symfony\Bundle\FrameworkBundle\Templating\GlobalVariables as BaseGlobalVariables;
use Symfony\Component\DependencyInjection\ContainerInterface;
use DateTime;
class GlobalVariables extends BaseGlobalVariables
{
/**
* Stores a DateTime instance.
*
* @var DateTime
*/
private $dateTime;
/**
* Stores an array of date and time formats to be used
* in the appliaction.
*
* @var array
*/
private $formats;
public function __construct(ContainerInterface $container)
{
parent::__construct($container);
$this->dateTime = new DateTime;
}
public function getDate()
{
return $this->dateTime;
}
public function getRootDir()
{
return $this->container->get('kernel')->getRootDir();
}
public function getFormats()
{
if (!$this->formats) {
$this->formats = array(
'date' => $this->container->getParameter('format.date'),
'datetime' => $this->container->getParameter('format.datetime'),
'shortdate' => $this->container->getParameter('format.shortdate'),
'time' => $this->container->getParameter('format.time'),
);
}
return $this->formats;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment