-
-
Save ftdysa/7362741 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
parameters: | |
templating.globals.class: Ibms\Helper\GlobalVariables |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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