5 Commits

Author SHA1 Message Date
mdesouza 000ed4c093 Release-v1.0.3 2025-09-25 11:52:03 -04:00
mdesouza 2dc9c8df1a Code improvements. 2025-09-25 11:47:43 -04:00
mdesouza 60f3508b36 Merge pull request 'Release-v1.0.2' (#3) from release-v1.0.2 into master
Reviewed-on: #3
2025-09-24 16:25:21 -04:00
mdesouza bd8c4f42eb Release-v1.0.2 2025-09-24 16:24:24 -04:00
mdesouza 7b807c015f fix paths. 2025-09-24 16:22:53 -04:00
5 changed files with 33 additions and 9 deletions
+1 -1
View File
@@ -2,4 +2,4 @@
Utils classes
Release-v1.0.1
Release-v1.0.3
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
namespace Mfdes\Utils;
namespace Mdesouza\Utils;
/**
* @file
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
namespace Mdesouza\Utils\DB;
namespace Mdesouza\Utils;
/**
* @file
+1 -3
View File
@@ -1,14 +1,12 @@
<?php
namespace Mdesouza\Utils\DB;
namespace Mdesouza\Utils;
/**
* @file
* A database class around the PDO object.
*/
include_once 'db.inc.php';
/**
* A mysql class around the PDO object.
*/
+29 -3
View File
@@ -24,7 +24,7 @@ class TwigRender {
/**
* Templates paths.
*
* @var array
* @var string
*/
private $templatesPath;
@@ -38,7 +38,7 @@ class TwigRender {
/**
* Constructor.
*/
public function __construct(string $template, array $templates_path, array $data = []) {
public function __construct(string $template, string $templates_path, array $data = []) {
$this->template = $template;
$this->templatesPath = $templates_path;
$this->data = $data;
@@ -50,9 +50,11 @@ class TwigRender {
public function render() : string {
$this->data['host'] = $_SERVER['HTTP_HOST'];
$html = "";
try {
$loader = new FilesystemLoader($this->templatesPath);
$loader = new FilesystemLoader([]);
$loader = $this->addPaths($loader);
$twig = new Environment($loader, ['debug' => TRUE]);
$twig->addExtension(new DebugExtension());
$twig->addExtension(new MFDESTwigExtension());
@@ -74,4 +76,28 @@ class TwigRender {
return $html;
}
/**
* Recursively add all directories under the templates base path.
*/
private function addPaths(FilesystemLoader $loader) : FilesystemLoader {
// Add base path.
$loader->addPath($this->templatesPath);
// Create a recursive iterator to find all subdirectories.
$iterator = new \RecursiveIteratorIterator(
new \RecursiveDirectoryIterator($this->templatesPath, \FilesystemIterator::SKIP_DOTS),
\RecursiveIteratorIterator::SELF_FIRST
);
// Add each sub-dir under the base path.
foreach ($iterator as $info) {
if ($info->isDir()) {
$loader->addPath($info->getPathname());
}
}
return $loader;
}
}