This commit is contained in:
S170H
2023-12-17 22:17:05 +01:00
parent 67a26f6684
commit 99d78584ec
120 changed files with 9988 additions and 5 deletions

View File

@@ -0,0 +1,39 @@
name: PHP Composer
on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
permissions:
contents: read
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Validate composer.json and composer.lock
run: composer validate --strict
- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-
- name: Install dependencies
run: composer install --prefer-dist --no-progress
# Add a test script to composer.json, for instance: "test": "vendor/bin/phpunit"
# Docs: https://getcomposer.org/doc/articles/scripts.md
# - name: Run test suite
# run: composer run-script test

21
M5/emensa/vendor/eftec/bladeone/LICENSE vendored Normal file
View File

@@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Jorge Patricio Castro Castillo
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice, other copyright notices and this permission notice
shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@@ -0,0 +1,49 @@
{
"name": "eftec/bladeone",
"description": "The standalone version Blade Template Engine from Laravel in a single php file",
"type": "library",
"keywords": [
"blade",
"template",
"view",
"php",
"templating"
],
"homepage": "https://github.com/EFTEC/BladeOne",
"license": "MIT",
"authors": [
{
"name": "Jorge Patricio Castro Castillo",
"email": "jcastro@eftec.cl"
}
],
"require": {
"php": ">=7.2.5",
"ext-json": "*"
},
"suggest": {
"ext-mbstring": "This extension is used if it's active",
"eftec/bladeonehtml": "Extension to create forms"
},
"archive": {
"exclude": [
"/examples"
]
},
"autoload": {
"psr-4": {
"eftec\\bladeone\\": "lib/"
}
},
"autoload-dev": {
"psr-4": {
"eftec\\tests\\": "tests/"
}
},
"bin": [
"lib/bladeonecli"
],
"require-dev": {
"phpunit/phpunit": "^8.5.23"
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,328 @@
<?php /** @noinspection UnknownInspectionInspection */
/** @noinspection TypeUnsafeComparisonInspection */
namespace eftec\bladeone;
use Exception;
use function fclose;
use function file_put_contents;
use function filemtime;
use function filesize;
use function fopen;
use function fwrite;
use function is_array;
use function is_object;
use function ob_get_contents;
use function print_r;
use function strlen;
use function substr;
use function time;
/**
* trait BladeOneCache
* Copyright (c) 2016 Jorge Patricio Castro Castillo MIT License. Don't delete this comment, its part of the license.
* Extends the tags of the class BladeOne. Its optional
* It adds the next tags to the template
* <code>
* @ cache([cacheid],[duration=86400]). The id is optional. The duration of the cache is in seconds
* // content here
* @ endcache()
* </code>
* It also adds a new function (optional) to the business or logic layer
* <code>
* if ($blade->cacheExpired('hellocache',1,5)) { //'helloonecache' =template, =1 id cache, 5=duration (seconds)
* // cache expired, so we should do some stuff (such as read from the database)
* }
* </code>
*
* @package BladeOneCache
* @version 3.42 2020-04-25
* @link https://github.com/EFTEC/BladeOne
* @author Jorge Patricio Castro Castillo <jcastro arroba eftec dot cl>
*/
trait BladeOneCache
{
protected $curCacheId = 0;
protected $curCacheDuration = 0;
protected $curCachePosition = 0;
protected $cacheRunning = false;
protected $cachePageRunning = false;
protected $cacheLog;
/**
* @var array avoids comparing the file different times. It also avoids race conditions.
*/
private $cacheExpired = [];
/**
* @var string=['get','post','getpost','request',null][$i]
*/
private $cacheStrategy;
/** @var array|null */
private $cacheStrategyIndex;
/**
* @return null|string $cacheStrategy=['get','post','getpost','request',null][$i]
*/
public function getCacheStrategy(): ?string
{
return $this->cacheStrategy;
}
/**
* It sets the cache log. If not cache log then it does not generate a log file<br>
* The cache log stores each time a template is creates or expired.<br>
*
* @param string $file
*/
public function setCacheLog($file): void
{
$this->cacheLog=$file;
}
public function writeCacheLog($txt, $nivel): void
{
if (!$this->cacheLog) {
return; // if there is not a file assigned then it skips saving.
}
$fz = @filesize($this->cacheLog);
if (is_object($txt) || is_array($txt)) {
$txt = print_r($txt, true);
}
// Rewrite file if more than 100000 bytes
$mode=($fz > 100000) ? 'w':'a';
$fp = fopen($this->cacheLog, $mode);
if ($fp === false) {
return;
}
switch ($nivel) {
case 1:
$txtNivel='expired';
break;
case 2:
$txtNivel='new';
break;
default:
$txtNivel='other';
}
$txtarg=json_encode($this->cacheUniqueGUID(false));
fwrite($fp, date('c') . "\t$txt\t$txtNivel\t$txtarg\n");
fclose($fp);
}
/**
* It sets the strategy of the cache page.
*
* @param null|string $cacheStrategy =['get','post','getpost','request',null][$i]
* @param array|null $index if null then it reads all indexes. If not, it reads an indexes.
*/
public function setCacheStrategy($cacheStrategy, $index = null): void
{
$this->cacheStrategy = $cacheStrategy;
$this->cacheStrategyIndex = $index;
}
/**
* It obtains a unique GUID based in:<br>
* <b>get</b>= parameters from the url<br>
* <b>post</b>= parameters sends via post<br>
* <b>getpost</b> = a mix between get and post<br>
* <b>request</b> = get, post and cookies (including sessions)<br>
* MD5 could generate colisions (2^64 = 18,446,744,073,709,551,616) but the end hash is the sum of the hash of
* the page + this GUID.
*
* @param bool $serialize if true then it serializes using md5
* @return string|null
*/
private function cacheUniqueGUID($serialize = true): ?string
{
switch ($this->cacheStrategy) {
case 'get':
$r = $_GET;
break;
case 'post':
$r = $_POST;
break;
case 'getpost':
$arr = array_merge($_GET, $_POST);
$r = $arr;
break;
case 'request':
$r = $_REQUEST;
break;
default:
$r = null;
}
if ($this->cacheStrategyIndex === null || !is_array($r)) {
$r= serialize($r);
} else {
$copy=[];
foreach ($r as $key => $item) {
if (in_array($key, $this->cacheStrategyIndex, true)) {
$copy[$key]=$item;
}
}
$r=serialize($copy);
}
return $serialize===true ? md5($r): $r;
}
public function compileCache($expression): string
{
// get id of template
// if the file exists then
// compare date.
// if the date is too old then re-save.
// else
// save for the first time.
return $this->phpTag . "echo \$this->cacheStart$expression; if(!\$this->cacheRunning) { ?>";
}
public function compileEndCache($expression): string
{
return $this->phpTag . "} // if cacheRunning\necho \$this->cacheEnd$expression; ?>";
}
/**
* It gets the filename of the compiled file (cached). If cache is not enabled, then it
* returns the regular file.
*
* @param string $view
* @return string The full filename
*/
private function getCompiledFileCache($view): string
{
$id = $this->cacheUniqueGUID();
if ($id !== null) {
return str_replace($this->compileExtension, '_cache' . $id
. $this->compileExtension, $this->getCompiledFile($view));
}
return $this->getCompiledFile($view);
}
/**
* run the blade engine. It returns the result of the code.
*
* @param string $view The name of the cache. Ex: "folder.folder.view" ("/folder/folder/view.blade")
* @param array $variables An associative arrays with the values to display.
* @param int $ttl time to live (in second).
* @return string
* @throws Exception
*/
public function runCache($view, $variables = [], $ttl = 86400): string
{
$this->cachePageRunning = true;
$cacheStatus=$this->cachePageExpired($view, $ttl);
if ($cacheStatus!==0) {
$this->writeCacheLog($view, $cacheStatus);
$this->cacheStart('_page_', $ttl);
$content = $this->run($view, $variables); // if no cache, then it runs normally.
$this->fileName = $view; // sometimes the filename is replaced (@include), so we restore it
$this->cacheEnd($content); // and it stores as a cache paged.
} else {
$content = $this->getFile($this->getCompiledFileCache($view));
}
$this->cachePageRunning = false;
return $content;
}
/**
* Returns true if the block cache expired (or doesn't exist), otherwise false.
*
* @param string $templateName name of the template to use (such hello for template hello.blade.php)
* @param string $id (id of cache, optional, if not id then it adds automatically a number)
* @param int $cacheDuration (duration of the cache in seconds)
* @return int 0=cache exists, 1= cache expired, 2=not exists, string= the cache file (if any)
*/
public function cacheExpired($templateName, $id, $cacheDuration): int
{
if ($this->getMode() & 1) {
return 2; // forced mode, hence it always expires. (fast mode is ignored).
}
$compiledFile = $this->getCompiledFile($templateName) . '_cache' . $id;
return $this->cacheExpiredInt($compiledFile, $cacheDuration);
}
/**
* It returns true if the whole page expired.
*
* @param string $templateName
* @param int $cacheDuration is seconds.
* @return int 0=cache exists, 1= cache expired, 2=not exists, string= the cache content (if any)
*/
public function cachePageExpired($templateName, $cacheDuration): int
{
if ($this->getMode() & 1) {
return 2; // forced mode, hence it always expires. (fast mode is ignored).
}
$compiledFile = $this->getCompiledFileCache($templateName);
return $this->CacheExpiredInt($compiledFile, $cacheDuration);
}
/**
* This method is used by cacheExpired() and cachePageExpired()
*
* @param string $compiledFile
* @param int $cacheDuration is seconds.
* @return int|mixed 0=cache exists, 1= cache expired, 2=not exists, string= the cache content (if any)
*/
private function cacheExpiredInt($compiledFile, $cacheDuration)
{
if (isset($this->cacheExpired[$compiledFile])) {
// if the information is already in the array then returns it.
return $this->cacheExpired[$compiledFile];
}
$date = @filemtime($compiledFile);
if ($date) {
if ($date + $cacheDuration < time()) {
$this->cacheExpired[$compiledFile] = 1;
return 2; // time-out.
}
} else {
$this->cacheExpired[$compiledFile] = 2;
return 1; // no file
}
$this->cacheExpired[$compiledFile] = 0;
return 0; // cache active.
}
public function cacheStart($id = '', $cacheDuration = 86400): void
{
$this->curCacheId = ($id == '') ? ($this->curCacheId + 1) : $id;
$this->curCacheDuration = $cacheDuration;
$this->curCachePosition = strlen(ob_get_contents());
if ($this->cachePageRunning) {
$compiledFile = $this->getCompiledFileCache($this->fileName);
} else {
$compiledFile = $this->getCompiledFile() . '_cache' . $this->curCacheId;
}
if ($this->cacheExpired('', $id, $cacheDuration) !==0) {
$this->cacheRunning = false;
} else {
$this->cacheRunning = true;
$content = $this->getFile($compiledFile);
echo $content;
}
}
public function cacheEnd($txt = null): void
{
if (!$this->cacheRunning) {
$txt = $txt ?? substr(ob_get_contents(), $this->curCachePosition);
if ($this->cachePageRunning) {
$compiledFile = $this->getCompiledFileCache($this->fileName);
} else {
$compiledFile = $this->getCompiledFile() . '_cache' . $this->curCacheId;
}
file_put_contents($compiledFile, $txt);
}
$this->cacheRunning = false;
}
}

View File

@@ -0,0 +1,160 @@
<?php
namespace eftec\bladeone;
use Redis;
use function class_exists;
use function file_put_contents;
use function filemtime;
use function ob_get_contents;
use function strlen;
use function substr;
use function time;
/**
* trait BladeOneCacheRedis
* Copyright (c) 2016 Jorge Patricio Castro Castillo MIT License. Don't delete this comment, its part of the license.
* Extends the tags of the class BladeOne. Its optional
* It adds the next tags to the template
* <code>
* @ cache([cacheid],[duration=86400]). The id is optional. The duration of the cache is in seconds
* // content here
* @ endcache()
* </code>
* It also adds a new function (optional) to the business or logic layer
* <code>
* if ($blade->cacheExpired('hellocache',1,5)) { //'helloonecache' =template, =1 id cache, 5=duration (seconds)
* // cache expired, so we should do some stuff (such as read from the database)
* }
* </code>
*
* @package BladeOneCacheRedis
* @version 0.1 2017-12-15 NOT YET IMPLEMENTED, ITS A WIP!!!!!!!!
* @link https://github.com/EFTEC/BladeOne
* @author Jorge Patricio Castro Castillo <jcastro arroba eftec dot cl>
*/
const CACHEREDIS_SCOPEURL = 1;
trait BladeOneCacheRedis
{
protected $curCacheId = 0;
protected $curCacheDuration = "";
protected $curCachePosition = 0;
protected $cacheRunning = false;
/** @var \Redis $redis */
protected $redis;
protected $redisIP = '127.0.0.1';
protected $redisPort = 6379;
protected $redisTimeOut = 2.5;
protected $redisConnected = false;
protected $redisNamespace = 'bladeonecache:';
protected $redisBase = 0;
private $cacheExpired = []; // avoids to compare the file different times.
//<editor-fold desc="compile">
public function compileCache($expression)
{
// get id of template
// if the file exists then
// compare date.
// if the date is too old then re-save.
// else
// save for the first time.
return $this->phpTag . "echo \$this->cacheStart{$expression}; if(!\$this->cacheRunning) { ?>";
}
public function compileEndCache($expression)
{
return $this->phpTag . "} // if cacheRunning\necho \$this->cacheEnd{$expression}; ?>";
}
//</editor-fold>
public function connect($redisIP = null, $redisPort = null, $redisTimeOut = null)
{
if ($this->redisConnected) {
return true;
}
if (!class_exists('Redis')) {
return false; // it requires redis.
}
if ($redisIP !== null) {
$this->redisIP = $redisIP;
$this->redisPort = $redisPort;
$this->redisTimeOut = $redisTimeOut;
}
$this->redis = new Redis();
// 2.5 sec timeout.
$this->redisConnected = $this->redis->connect($this->redisIP, $this->redisPort, $this->redisTimeOut);
return $this->redisConnected;
}
/**
* Returns true if the cache expired (or doesn't exist), otherwise false.
*
* @param string $templateName name of the template to use (such hello for template hello.blade.php)
* @param string $id (id of cache, optional, if not id then it adds automatically a number)
* @param int $scope scope of the cache.
* @param int $cacheDuration (duration of the cache in seconds)
* @return bool (return if the cache expired)
*/
public function cacheExpired($templateName, $id, $scope, $cacheDuration)
{
if ($this->getMode() & 1) {
return true; // forced mode, hence it always expires. (fast mode is ignored).
}
$compiledFile = $this->getCompiledFile($templateName) . '_cache' . $id;
if (isset($this->cacheExpired[$compiledFile])) {
// if the information is already in the array then returns it.
return $this->cacheExpired[$compiledFile];
}
$date = @filemtime($compiledFile);
if ($date) {
if ($date + $cacheDuration < time()) {
$this->cacheExpired[$compiledFile] = true;
return true; // time-out.
}
} else {
$this->cacheExpired[$compiledFile] = true;
return true; // no file
}
$this->cacheExpired[$compiledFile] = false;
return false; // cache active.
}
public function cacheStart($id = "", $cacheDuration = 86400)
{
$this->curCacheId = ($id == "") ? ($this->curCacheId + 1) : $id;
$this->curCacheDuration = $cacheDuration;
$this->curCachePosition = strlen(ob_get_contents());
$compiledFile = $this->getCompiledFile() . '_cache' . $this->curCacheId;
if ($this->cacheExpired('', $id, $cacheDuration)) {
$this->cacheRunning = false;
} else {
$this->cacheRunning = true;
$content = $this->getFile($compiledFile);
echo $content;
}
// getFile($fileName)
}
public function cacheEnd()
{
if (!$this->cacheRunning) {
$txt = substr(ob_get_contents(), $this->curCachePosition);
$compiledFile = $this->getCompiledFile() . '_cache' . $this->curCacheId;
file_put_contents($compiledFile, $txt);
}
$this->cacheRunning = false;
}
private function keyByScope($scope)
{
$key = '';
if ($scope && CACHEREDIS_SCOPEURL) {
$key .= $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
}
}
}

View File

@@ -0,0 +1,59 @@
<?php /** @noinspection ReturnTypeCanBeDeclaredInspection */
/** @noinspection PhpMissingReturnTypeInspection */
/** @noinspection UnknownInspectionInspection */
/** @noinspection PhpUnused */
namespace eftec\bladeone;
/*
* It's an example of a custom set of functions for bladeone.
* in examples/TestCustom.php there is a working example
*/
use function array_pop;
trait BladeOneCustom
{
private $customItem = []; // indicates the type of the current tag. such as select/selectgroup/etc.
//<editor-fold desc="compile function">
/**
* Usage @panel('title',true,true).....@endpanel()
*
* @param $expression
* @return string
*/
protected function compilePanel($expression)
{
$this->customItem[] = 'Panel';
return $this->phpTag . "echo \$this->panel$expression; ?>";
}
protected function compileEndPanel()
{
$r = @array_pop($this->customItem);
if ($r === null) {
$this->showError('@endpanel', 'Missing @compilepanel or so many @compilepanel', true);
}
return ' </div></section><!-- end panel -->'; // we don't need to create a function for this.
}
//</editor-fold>
//<editor-fold desc="used function">
protected function panel($title = '', $toggle = true, $dismiss = true)
{
return "<section class='panel'>
<header class='panel-heading'>
<div class='panel-actions'>
" . (($toggle) ? "<a href='#' class='panel-action panel-action-toggle' data-panel-toggle></a>" : '') . '
' . (($dismiss) ? "<a href='#' class='panel-action panel-action-dismiss' data-panel-dismiss></a>" : '') . "
</div>
<h2 class='panel-title'>$title</h2>
</header>
<div class='panel-body'>";
}
//</editor-fold>
}

View File

@@ -0,0 +1,29 @@
<?php
namespace eftec;
// this code only runs on CLI but only if bladeonecli.php is called directly and via command line.
use eftec\bladeone\BladeOne;
if (!defined('PHPUNIT_COMPOSER_INSTALL') && !defined('__PHPUNIT_PHAR__')
&& isset($_SERVER['PHP_SELF']) &&
!http_response_code() &&
(basename($_SERVER['PHP_SELF']) === 'bladeonecli.php' || basename($_SERVER['PHP_SELF']) === 'bladeonecli')
) {
// we also excluded it if it is called by phpunit.
include_once __DIR__ . '/BladeOne.php';
$compilepath = BladeOne::getParameterCli('compilepath', null);
$templatepath = BladeOne::getParameterCli('templatepath', null);
if (!BladeOne::isAbsolutePath($compilepath)) {
$compilepath = getcwd() . '/' . $compilepath;
}
if (!BladeOne::isAbsolutePath($templatepath)) {
$templatepath = getcwd() . '/' . $templatepath;
}
$inst = new BladeOne($templatepath, $compilepath);
$inst->cliEngine();
} else {
@http_response_code(404);
}