Compare commits
6 Commits
release-v1.0.6
...
v1.0.8
| Author | SHA1 | Date | |
|---|---|---|---|
| 75cb3f41e0 | |||
| b1435d39dc | |||
| 16270fedf8 | |||
| 49bba32a34 | |||
| ce684e0ad1 | |||
| 9b3bc83d0d |
@@ -50,6 +50,7 @@ class MDTwigExtension extends AbstractExtension {
|
|||||||
new TwigFilter('cnpj', [$this, 'formatCNPJ']),
|
new TwigFilter('cnpj', [$this, 'formatCNPJ']),
|
||||||
new TwigFilter('real', [$this, 'formatReal']),
|
new TwigFilter('real', [$this, 'formatReal']),
|
||||||
new TwigFilter('unicode', [$this, 'returnUnicode']),
|
new TwigFilter('unicode', [$this, 'returnUnicode']),
|
||||||
|
new TwigFilter('dateshort', [$this, 'formatDateShort']),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,4 +184,20 @@ class MDTwigExtension extends AbstractExtension {
|
|||||||
return $unicode;
|
return $unicode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format and translate date to portuguese.
|
||||||
|
* 2026-04-01 => 01 Apr. 2026
|
||||||
|
*/
|
||||||
|
public function formatDateShort(string $value) : string {
|
||||||
|
|
||||||
|
$df = new \IntlDateFormatter(
|
||||||
|
'pt_BR',
|
||||||
|
\IntlDateFormatter::FULL,
|
||||||
|
\IntlDateFormatter::NONE
|
||||||
|
);
|
||||||
|
|
||||||
|
$df->setPattern('d-LLL-yy');
|
||||||
|
$d = $df->format(new \DateTime($value));
|
||||||
|
return strtoupper(str_replace(".", "", $d));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-13
@@ -35,6 +35,20 @@ class TwigRender {
|
|||||||
*/
|
*/
|
||||||
private $data;
|
private $data;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Template object.
|
||||||
|
*
|
||||||
|
* @var \Twig\Environment
|
||||||
|
*/
|
||||||
|
private $twig;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Loader object.
|
||||||
|
*
|
||||||
|
* @var \Twig\Loader\FilesystemLoader
|
||||||
|
*/
|
||||||
|
private $loader;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
@@ -42,6 +56,18 @@ class TwigRender {
|
|||||||
$this->template = $template;
|
$this->template = $template;
|
||||||
$this->templatesPath = $templates_path;
|
$this->templatesPath = $templates_path;
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
|
$this->loader = new \Twig\Loader\FilesystemLoader([]);
|
||||||
|
$this->twig = new Environment($this->loader, ['debug' => TRUE]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add global variable(s) to template.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function addGlobals($name, $value) : self {
|
||||||
|
$this->twig->addGlobal($name, $value);
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -53,13 +79,11 @@ class TwigRender {
|
|||||||
$html = "";
|
$html = "";
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$loader = new FilesystemLoader([]);
|
$this->twig->addExtension(new DebugExtension());
|
||||||
$loader = $this->addPaths($loader);
|
$this->twig->addExtension(new MFDESTwigExtension());
|
||||||
$twig = new Environment($loader, ['debug' => TRUE]);
|
$this->twig->addExtension(new MDTwigExtension());
|
||||||
$twig->addExtension(new DebugExtension());
|
$this->addPaths();
|
||||||
$twig->addExtension(new MFDESTwigExtension());
|
$html = $this->twig->render($this->template, ['data' => $this->data]);
|
||||||
$twig->addGlobal('session', $_SESSION);
|
|
||||||
$html = $twig->render($this->template, ['data' => $this->data]);
|
|
||||||
}
|
}
|
||||||
catch (LoaderError $e) {
|
catch (LoaderError $e) {
|
||||||
$html .= "<br/><pre>" . print_r($e->getMessage());
|
$html .= "<br/><pre>" . print_r($e->getMessage());
|
||||||
@@ -80,11 +104,10 @@ class TwigRender {
|
|||||||
/**
|
/**
|
||||||
* Recursively add all directories under the templates base path.
|
* Recursively add all directories under the templates base path.
|
||||||
*/
|
*/
|
||||||
private function addPaths(FilesystemLoader $loader) : FilesystemLoader {
|
private function addPaths() {
|
||||||
|
|
||||||
// Add base path.
|
// Add base path.
|
||||||
$loader->addPath($this->templatesPath);
|
$this->loader->addPath($this->templatesPath);
|
||||||
|
|
||||||
// Create a recursive iterator to find all subdirectories.
|
// Create a recursive iterator to find all subdirectories.
|
||||||
$iterator = new \RecursiveIteratorIterator(
|
$iterator = new \RecursiveIteratorIterator(
|
||||||
new \RecursiveDirectoryIterator($this->templatesPath, \FilesystemIterator::SKIP_DOTS),
|
new \RecursiveDirectoryIterator($this->templatesPath, \FilesystemIterator::SKIP_DOTS),
|
||||||
@@ -94,11 +117,9 @@ class TwigRender {
|
|||||||
// Add each sub-dir under the base path.
|
// Add each sub-dir under the base path.
|
||||||
foreach ($iterator as $info) {
|
foreach ($iterator as $info) {
|
||||||
if ($info->isDir()) {
|
if ($info->isDir()) {
|
||||||
$loader->addPath($info->getPathname());
|
$this->loader->addPath($info->getPathname());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $loader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user