Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c6caa9e418 |
@@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Mfdes\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']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
<?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>";
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
+7
-5
@@ -22,9 +22,11 @@ class TwigRender {
|
|||||||
private $template;
|
private $template;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Templates paths
|
* Templates paths.
|
||||||
|
*
|
||||||
|
* @var array
|
||||||
*/
|
*/
|
||||||
private $templates_path;
|
private $templatesPath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Template data.
|
* Template data.
|
||||||
@@ -38,7 +40,7 @@ class TwigRender {
|
|||||||
*/
|
*/
|
||||||
public function __construct(string $template, array $templates_path, array $data = []) {
|
public function __construct(string $template, array $templates_path, array $data = []) {
|
||||||
$this->template = $template;
|
$this->template = $template;
|
||||||
$this->templates_path = $templates_path;
|
$this->templatesPath = $templates_path;
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,10 +49,10 @@ class TwigRender {
|
|||||||
*/
|
*/
|
||||||
public function render() : string {
|
public function render() : string {
|
||||||
|
|
||||||
$data['host'] = $_SERVER['HTTP_HOST'];
|
$this->data['host'] = $_SERVER['HTTP_HOST'];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$loader = new FilesystemLoader($this->templates_path);
|
$loader = new FilesystemLoader($this->templatesPath);
|
||||||
$twig = new Environment($loader, ['debug' => TRUE]);
|
$twig = new Environment($loader, ['debug' => TRUE]);
|
||||||
$twig->addExtension(new DebugExtension());
|
$twig->addExtension(new DebugExtension());
|
||||||
$twig->addExtension(new MFDESTwigExtension());
|
$twig->addExtension(new MFDESTwigExtension());
|
||||||
|
|||||||
Reference in New Issue
Block a user