Skip to content

Commit

Permalink
* 3.48 see changelog.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgecc committed Jan 6, 2021
1 parent 6829b32 commit ec215af
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 66 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ BladeOne is a standalone version of Blade Template Engine that uses a single PHP
[![Build Status](https://travis-ci.org/EFTEC/BladeOne.svg?branch=master)](https://travis-ci.org/EFTEC/BladeOne)
[![Packagist](https://img.shields.io/packagist/v/eftec/bladeone.svg)](https://packagist.org/packages/eftec/bladeone)
[![Total Downloads](https://poser.pugx.org/eftec/bladeone/downloads)](https://packagist.org/packages/eftec/bladeone)
[![Maintenance](https://img.shields.io/maintenance/yes/2020.svg)]()
[![Maintenance](https://img.shields.io/maintenance/yes/2021.svg)]()
[![composer](https://img.shields.io/badge/composer-%3E1.6-blue.svg)]()
[![php](https://img.shields.io/badge/php->5.6-green.svg)]()
[![php](https://img.shields.io/badge/php-7.x-green.svg)]()
Expand Down Expand Up @@ -467,6 +467,6 @@ You are welcome to use it, share it, ask for changes and whatever you want to. J

## License
MIT License.
BladeOne (c) 2016-2020 Jorge Patricio Castro Castillo
BladeOne (c) 2016-2021 Jorge Patricio Castro Castillo
Blade (c) 2012 Laravel Team (This code is based and inspired in the work of the team of Laravel, however BladeOne is mostly a original work)

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.47.3",
"version": "3.48",
"keywords": [
"blade",
"template",
Expand Down
2 changes: 1 addition & 1 deletion examples/testcomponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@


try {
echo $blade->run("TestComponent.component", []);
echo $blade->run("TestComponent.component", ['myglobal'=>'hello']);
} catch (Exception $e) {
echo "error found ".$e->getMessage()."<br>".$e->getTraceAsString();
}
9 changes: 6 additions & 3 deletions examples/views/TestComponent/alert.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<div class="alert alert-danger" style="background-color: {!! $color !!}; padding-left: 100px;">
<div>{!! $title !!}</div>
<div class="alert alert-danger" style="background-color: {!! $color !!}; padding-left: 100px;border: black 1px solid">
<div>title:{!! $title !!}</div>
<div>myglobal:{!! $myglobal !!}</div>
{!! $slot !!}
</div>
<div>end title:{!! $title !!}</div>
</div>
<br>
50 changes: 42 additions & 8 deletions examples/views/TestComponent/component.blade.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,60 @@
<h1>It is a test of the tags @@component</h1>
<h2>paramless</h2>

@component('TestComponent.paramless')
<strong>Whoops!</strong> Something went wrong! (the code is right btw), it must show a no-color background
@endcomponent

@component('TestComponent.paramless')
<strong>Whoops!</strong> Something went wrong! (the code is right btw), it must show a no-color background
@endcomponent


<h2>with parameters</h2>
@component('TestComponent.alert',array('title'=>'no title'))
<strong>Whoops!</strong> Something went wrong! (the code is right btw), it must show a no-color background
@endcomponent
<br>

@component('TestComponent.alert',array('title'=>'COMPONENT #1','color'=>"red"))
<strong>Whoops!</strong> Something went wrong! (the code is right btw)
<strong>Whoops!</strong> Something went wrong! (the code is right btw), it must show a red background
@endcomponent

@component('TestComponent.alert',['color'=>'orange'])
@slot('title')
<hr>
COMPONENT #2
@endslot
<hr>

@component('TestComponent.alert',['color'=>'yellow'])
@slot('title')
COMPONENT #2.1
@endslot
<strong>Whoops!</strong> Something went wrong! (the code is right btw)
<strong>Whoops!</strong> Something went wrong! (the code is right btw), it must show a yellow background
<hr>
COMPONENT #3 starts here:
@component('TestComponent.alert',['color'=>'lightblue'])
@slot('title')
COMPONENT #3.1
@endslot
<strong>Whoops!</strong> Something went wrong! (the code is right btw), it must show a lightblue background
@endcomponent

<hr>
@endcomponent

<hr>
@endslot
<strong>Whoops!</strong> Something went wrong! (the code is right btw)

<strong>Whoops!</strong> Something went wrong! (the code is right btw), iit must show a orange background
@endcomponent

@component('TestComponent.alert',['color'=>'lightblue'])
@slot('title', 'COMPONENT #3')

<strong>Whoops!</strong> Something went wrong! (the code is right btw)
@endcomponent
<strong>Whoops!</strong> Something went wrong! (the code is right btw), it must show a lightblue background
@endcomponent

@component('TestComponent.alert',[])
@slot('title', 'COMPONENT #3')

<strong>Whoops!</strong> Something went wrong! (the code is right btw), it must show a no-color background
@endcomponent
6 changes: 6 additions & 0 deletions examples/views/TestComponent/paramless.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<div class="alert alert-danger" style="; padding-left: 100px; border: black 1px solid">
<div>PARAMLESS (colorless)</div>
<div>myglobal:{!! $myglobal !!}</div>
{!! $slot !!}
</div>
<br>
58 changes: 27 additions & 31 deletions lib/BladeOne.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
<?php /** @noinspection PhpUnusedParameterInspection */

/** @noinspection SyntaxError
* @noinspection ForgottenDebugOutputInspection
* @noinspection UnknownInspectionInspection
Expand Down Expand Up @@ -34,7 +35,7 @@
* @copyright Copyright (c) 2016-2020 Jorge Patricio Castro Castillo MIT License.
* Don't delete this comment, its part of the license.
* Part of this code is based in the work of Laravel PHP Components.
* @version 3.47.3
* @version 3.48
* @link https://github.com/EFTEC/BladeOne
*/
class BladeOne
Expand Down Expand Up @@ -537,6 +538,7 @@ public function runString($string, $data = [])
$previousError = \error_get_last();

try {
/** @noinspection PhpExpressionResultUnusedInspection */
@eval('?' . '>' . $php);
} catch (Exception $e) {
while (\ob_get_level() > $obLevel) {
Expand Down Expand Up @@ -1004,7 +1006,13 @@ public function runChild($view, $variables = [])
if (\is_array($variables)) {
$newVariables = \array_merge($this->variables, $variables);
} else {
$this->showError('run/include', "Include/run variables should be defined as array ['idx'=>'value']", true);
if ($variables===null) {
$newVariables=$this->variables;
var_dump($newVariables);
die(1);
}

$this->showError('run/include', "RunChild: Include/run variables should be defined as array ['idx'=>'value']", true);
return '';
}
return $this->runInternal($view, $newVariables, false, false, $this->isRunFast);
Expand Down Expand Up @@ -1995,27 +2003,15 @@ protected function currentComponent()
*/
public function renderComponent()
{
//echo "<hr>render<br>";
$name = \array_pop($this->componentStack);
//return $this->runChild($name, $this->componentData());
$cd=$this->componentData();
if (!is_array($cd)) {
$keys=array_keys($cd);
foreach ($keys as $key) {
if (isset($this->variables[$key])) {
$backup[$key]=$this->variables[$key];
}
}
}
$clean=array_keys($cd);
$r=$this->runChild($name, $cd);
if (!isset($keys)) {
return $r;
}
foreach ($keys as $key) {
if (isset($backup[$key])) {
$this->variables[$key] = $backup[$key]; // this value is recovered
} else {
unset($this->variables[$key]); // this value must be deleted
}
// we clean variables defined inside the component (so they are garbaged when the component is used)
foreach ($clean as $key) {
unset($this->variables[$key]);
}
return $r;
}
Expand All @@ -2027,10 +2023,16 @@ public function renderComponent()
*/
protected function componentData()
{
return \array_merge(
$this->componentData[\count($this->componentStack)],
['slot' => \trim(\ob_get_clean())],
$this->slots[\count($this->componentStack)]
$cs=count($this->componentStack);
//echo "<hr>";
//echo "<br>data:<br>";
//var_dump($this->componentData);
//echo "<br>datac:<br>";
//var_dump(count($this->componentStack));
return array_merge(
$this->componentData[$cs],
['slot' => trim(ob_get_clean())],
$this->slots[$cs]
);
}

Expand Down Expand Up @@ -2727,12 +2729,6 @@ protected function compileStatements($value)
// it calls the function compile<name of the tag>
$match[0] = $this->$method(static::get($match, 3));
} else {
/*echo "<pre>";
var_dump($match);
echo "</pre>";
echo "operation not defined!";
*/
//todo: $this->showError("@compile", "Operation not defined:@".$match[1], true);
return $match[0];
}
}
Expand Down Expand Up @@ -3614,7 +3610,7 @@ protected function compileExtends($expression)
return $this->phpTag . '$_shouldextend[' . $this->uidCounter . ']=1; ?>';
}



/**
* Execute the @parent command. This operation works in tandem with extendSection
Expand Down
33 changes: 14 additions & 19 deletions tests/IfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
* @author G.J.W. Oolbekkink <g.j.w.oolbekkink@gmail.com>
* @since 16/09/2018
*/
class IfTest extends AbstractBladeTestCase {
class IfTest extends AbstractBladeTestCase
{
/**
* @throws \Exception
*/
public function testIf() {
public function testIf()
{
$bladeSource = /** @lang Blade */
<<<'BLADE'
@if($a == 4)
Expand All @@ -25,7 +27,8 @@ public function testIf() {
/**
* @throws \Exception
*/
public function testElse() {
public function testElse()
{
$bladeSource = /** @lang Blade */
<<<'BLADE'
@if($a == 4)
Expand All @@ -41,7 +44,8 @@ public function testElse() {
/**
* @throws \Exception
*/
public function testElseIf() {
public function testElseIf()
{
$bladeSource = /** @lang Blade */
<<<'BLADE'
@if($a == 4)
Expand All @@ -60,7 +64,8 @@ public function testElseIf() {
/**
* @throws \Exception
*/
public function testUnless() {
public function testUnless()
{
$bladeSource = /** @lang Blade */
<<<'BLADE'
@unless($a == 4)
Expand All @@ -74,7 +79,8 @@ public function testUnless() {
/**
* @throws \Exception
*/
public function testIsset() {
public function testIsset()
{
$bladeSource = /** @lang Blade */
<<<'BLADE'
@isset($a)
Expand All @@ -88,7 +94,8 @@ public function testIsset() {
/**
* @throws \Exception
*/
public function testEmpty() {
public function testEmpty()
{
$bladeSource = /** @lang Blade */
<<<'BLADE'
@empty($a)
Expand All @@ -100,17 +107,5 @@ public function testEmpty() {

}

/**
* @throws \Exception
*/
public function testInvalidIf() {
$this->expectException(\Exception::class);

/** @noinspection BladeControlDirectives */
$bladeSource = /** @lang Blade */
<<<'BLADE'
@if($a == 4)
BLADE;
$this->blade->runString($bladeSource, ['a' => 4]);
}
}
3 changes: 2 additions & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
if (file_exists(__DIR__ . '/../vendor/autoload.php')) {
require_once __DIR__ . '/../vendor/autoload.php';
} else {
function create_autoloader($prefix, $base_dir) {
function create_autoloader($prefix, $base_dir)
{
return function ($class) use ($prefix, $base_dir) {
if (strncmp($prefix, $class, strlen($prefix)) !== 0) {
return;
Expand Down

0 comments on commit ec215af

Please sign in to comment.