2 Commits

Author SHA1 Message Date
mdesouza 54365abf1d Merge pull request 'Release-v1.0.0' (#1) from release-v1.0.0 into master
Reviewed-on: #1
2025-09-24 10:00:23 -04:00
mdesouza 758abcaf48 Release-v1.0.0 2025-09-24 09:59:38 -04:00
6 changed files with 13 additions and 146 deletions
+1 -3
View File
@@ -1,5 +1,3 @@
# mdesouza
Utils classes
Release-v1.0.3
Utils classes by mdesouza3@gmail.com
-57
View File
@@ -1,57 +0,0 @@
<?php
namespace Mdesouza\Utils;
/**
* @file
* Implementation of cookies.
*/
/**
* Class implementation for cookies.
*/
class Cookie {
/**
* Content of $_COOKIE array.
*
* @var array
*/
private $cookie = [];
/**
* Constructor.
*/
public function __construct() {
$this->cookie = $_COOKIE;
}
/**
* Checks if a cookie exists.
*/
public function cookieExists($name) {
return isset($this->cookie[$name]);
}
/**
* Get value of a cookie.
*/
public function getCookie($name) : string {
return $this->cookieExists($name) ? $this->cookie[$name] : "";
}
/**
* Set a cookie.
*/
public function setCookie(array $options) {
setcookie(
$options['name'],
$options['value'],
$options['expires'],
$options['path'],
$options['domain'],
$options['secure'],
$options['httponly']
);
}
}
+1 -1
View File
@@ -1,6 +1,6 @@
<?php
namespace Mdesouza\Utils;
namespace Mdesouza\Utils\DB;
/**
* @file
+3 -1
View File
@@ -1,12 +1,14 @@
<?php
namespace Mdesouza\Utils;
namespace Mdesouza\Utils\DB;
/**
* @file
* A database class around the PDO object.
*/
include_once 'db.inc.php';
/**
* A mysql class around the PDO object.
*/
-48
View File
@@ -1,48 +0,0 @@
<?php
namespace Mdesouza\Utils;
/**
* Show variables and exit or continue.
*/
class ShowVars {
/**
* Print vars and exit.
*/
public static function printAndExit($data, $trace = TRUE) {
$bt = debug_backtrace();
echo "<pre>";
if (TRUE == $trace) {
echo "Trace: " . PHP_EOL;
foreach ($bt as $atrace) {
echo "$atrace[file]:$atrace[line]" . PHP_EOL;
}
echo PHP_EOL;
}
print_r($data);
echo "</pre>";
die("");
}
/**
* Print vars and continue.
*/
public static function printAndContinue($data, $trace = TRUE) {
$bt = debug_backtrace();
echo "<pre>";
if (TRUE == $trace) {
echo "Trace: " . PHP_EOL;
foreach ($bt as $atrace) {
echo "$atrace[file]:$atrace[line]" . PHP_EOL;
}
echo PHP_EOL;
}
print_r($data);
echo "</pre>";
}
}
+8 -36
View File
@@ -21,12 +21,10 @@ class TwigRender {
*/
private $template;
/**
* Templates paths.
*
* @var string
*/
private $templatesPath;
/**
* Templates paths
*/
private $templates_path;
/**
* Template data.
@@ -38,9 +36,9 @@ class TwigRender {
/**
* Constructor.
*/
public function __construct(string $template, string $templates_path, array $data = []) {
public function __construct(string $template, array $templates_path, array $data = []) {
$this->template = $template;
$this->templatesPath = $templates_path;
$this->templates_path = $templates_path;
$this->data = $data;
}
@@ -49,12 +47,10 @@ class TwigRender {
*/
public function render() : string {
$this->data['host'] = $_SERVER['HTTP_HOST'];
$html = "";
$data['host'] = $_SERVER['HTTP_HOST'];
try {
$loader = new FilesystemLoader([]);
$loader = $this->addPaths($loader);
$loader = new FilesystemLoader($this->templates_path);
$twig = new Environment($loader, ['debug' => TRUE]);
$twig->addExtension(new DebugExtension());
$twig->addExtension(new MFDESTwigExtension());
@@ -76,28 +72,4 @@ 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;
}
}