Skip to content

Commit

Permalink
3.41 update BladeOneCache.php
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecc committed Apr 24, 2020
1 parent 210dca8 commit 71200c7
Show file tree
Hide file tree
Showing 8 changed files with 262 additions and 46 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "eftec/bladeone",
"description": "The standalone version Blade Template Engine from Laravel in a single php file",
"type": "library",
"version": "3.40",
"version": "3.41",
"keywords": [
"blade",
"template",
Expand Down
33 changes: 18 additions & 15 deletions examples/testcache.php
Original file line number Diff line number Diff line change
@@ -1,45 +1,48 @@
<?php
<?php /** @noinspection AutoloadingIssuesInspection */
/**
* Copyright (c) 2016 Jorge Patricio Castro Castillo MIT License.
*/
include "../lib/BladeOne.php";
include '../lib/BladeOne.php';

include "../lib/BladeOneCache.php";
include '../lib/BladeOneCache.php';

use eftec\bladeone\BladeOne;
use eftec\bladeone\BladeOneCache;

$views = __DIR__ . '/views';
$compiledFolder = __DIR__ . '/compiled';

class myBlade extends BladeOne {
class myBladeCache extends BladeOne
{
use BladeOneCache;
}

$blade=new myBlade($views,$compiledFolder);
define("BLADEONE_MODE",0); // (optional) 1=forced (test),2=run fast (production), 0=automatic, default value.
$blade=new myBladeCache($views, $compiledFolder);
define('BLADEONE_MODE', 0); // (optional) 1=forced (test),2=run fast (production), 0=automatic, default value.

//<editor-fold desc="Example data">
if ($blade->cacheExpired('TestCache.hellocache',1,5)) {
echo "<b>Logic layer</b>: cache expired, re-reading the list<br>";
$idGet=md5(serialize($_GET)).md5(serialize($_POST));

if ($blade->cacheExpired('TestCache.hellocache', $idGet, 50)) {
echo '<b>Logic layer</b>: cache expired, re-reading the list<br>';
$list = [1, 2, 3, 4, 5];
} else {
echo "<b>Logic layer</b>: cache active, i don't read the list<br>";
$list=[];
}

$random=rand(0,9999);
$time=date('h:i:s A',time());
$timeUpTo=date('h:i:s A',time()+5); // plus 5 seconds
$random=mt_rand(0, 9999);
$time=date('h:i:s A', time());
$timeUpTo=date('h:i:s A', time()+5); // plus 5 seconds
//</editor-fold>


try {
echo $blade->run("TestCache.hellocache"
, ["random" => $random
echo $blade->run('TestCache.hellocache', ['random' => $random
, 'time' => $time
, 'list' => $list
, 'timeUpTo' => $timeUpTo]);
, 'timeUpTo' => $timeUpTo
,'idGet'=>$idGet]);
} catch (Exception $e) {
echo "error found ".$e->getMessage()."<br>".$e->getTraceAsString();
echo 'error found ' .$e->getMessage(). '<br>' .$e->getTraceAsString();
}
46 changes: 46 additions & 0 deletions examples/testcachepage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php /** @noinspection AutoloadingIssuesInspection */
/**
* Copyright (c) 2016 Jorge Patricio Castro Castillo MIT License.
*/
include '../lib/BladeOne.php';

include '../lib/BladeOneCache.php';

use eftec\bladeone\BladeOne;
use eftec\bladeone\BladeOneCache;


class myBladeCache extends BladeOne
{
use BladeOneCache;
}

$blade=new myBladeCache();
$blade->setCacheStrategy('getpost');

define('BLADEONE_MODE', 0); // (optional) 1=forced (test),2=run fast (production), 0=automatic, default value.

if ($blade->cachePageExpired('TestCache.hellocache2', 5)) {
echo '<b>Logic layer</b>: cache expired, re-reading the list<br>';
$list = [1, 2, 3, 4, 5];
} else {
echo "<b>Logic layer</b>: cache active, i don't read the list<br>";
$list=[];
}


$random=mt_rand(0, 9999);
$time=date('h:i:s A', time());
$timeUpTo=date('h:i:s A', time()+5); // plus 5 seconds
//</editor-fold>


try {
echo $blade->runCache('TestCache.hellocache2', ['random' => $random
, 'time' => $time
, 'list' => $list
, 'timeUpTo' => $timeUpTo
], 5);
} catch (Exception $e) {
echo 'error found ' .$e->getMessage(). '<br>' .$e->getTraceAsString();
}
4 changes: 2 additions & 2 deletions examples/views/TestCache/hellocache.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<h1>Cache test</h1>
<h2>Test the cache system. Two part of the code is cached for 5 seconds</h2>
<h2>Additionally, in testcache.php, the code avoids to re-read a variable if the cache is still active</h2>
@cache("1",5)
@cache("1",50)
<hr>
start of the cache n1:<br>
this information should be cached {{$random}} {{$time}} unless we are past {{$timeUpTo}}<br>
Expand All @@ -15,7 +15,7 @@
<hr>
@endcache()
this information should not be cached {{$random}} {{$time}} <br>
@cache("2",5)
@cache("2",50)
<hr>
start of the cache N2:<br>
this information should also be cached {{$random}} {{$time}} unless we are past {{$timeUpTo}}<br>
Expand Down
21 changes: 21 additions & 0 deletions examples/views/TestCache/hellocache2.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<body>
<h1>Cache test</h1>
<h2>Test the cache system. Two part of the code is cached for 5 seconds</h2>
<h2>Additionally, in testcache.php, the code avoids to re-read a variable if the cache is still active</h2>
<hr>
start of the cache n1:<br>
this information should be cached {{$random}} {{$time}} unless we are past {{$timeUpTo}}<br>
@foreach($list as $item)
{{$item}}<br>
@endforeach
<hr>$_GET:<br>
@dump($_GET)
<hr>
<a href="?id=2">go to ?id=2</a><br>
<a href="?id=3">go to ?id=3</a><br>


</body>
</html>
10 changes: 5 additions & 5 deletions lib/BladeOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ public function __construct($templatePath = null, $compiledPath = null, $mode =
$this->compiledPath = $compiledPath;
$this->setMode($mode);
$this->authCallBack = function ($action = null, /** @noinspection PhpUnusedParameterInspection */ $subject = null) {
return \in_array($action, $this->currentPermission);
return \in_array($action, $this->currentPermission, true);
};

$this->authAnyCallBack = function ($array = []) {
foreach ($array as $permission) {
if (\in_array($permission, $this->currentPermission)) {
if (\in_array($permission, $this->currentPermission, true)) {
return true;
}
}
Expand Down Expand Up @@ -1515,10 +1515,10 @@ public function renderEach($view, $data, $iterator, $empty = 'raw|')
}

/**
* run the blade engine. It returns the result of the code.
* Run the blade engine. It returns the result of the code.
*
* @param string $view
* @param array $variables
* @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.
* @return string
* @throws Exception
*/
Expand Down
Loading

0 comments on commit 71200c7

Please sign in to comment.