Skip to content

Commit 4bad004

Browse files
authored
Merge pull request #11 from jeremeamia/php-8.2-compatibilty
Fix error in PHP 8.2
2 parents b26f92b + 3e2c676 commit 4bad004

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ Templates are just PHP files—no mustaches and no frills.
9797
```php
9898
// index.php
9999
(new µ)
100-
->cfg('views', __DIR__ . '/templates')
101100
->get('/hello/(?<name>\w+)', function ($app, $params) {
102-
echo $app->view('hello', [
101+
echo $app->view(__DIR__ . '/templates', 'hello', [
103102
'greeting' => 'howdy',
104103
'name' => $params['name'],
105104
]);

examples/hello4.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44

55
require __DIR__ . '/../vendor/autoload.php';
66

7+
const VIEWS_DIR = __DIR__ . '/templates';
8+
79
(new µ)
8-
->cfg('views', __DIR__ . '/templates')
910
->get('/hello/(?<name>\w+)', function ($app, $params) {
10-
echo $app->view('hello4', [
11+
echo $app->view(VIEWS_DIR, 'hello4', [
1112
'greeting' => 'howdy',
1213
'name' => $params['name'],
1314
]);

mu.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
<?php class µ{function __call($m,$a){$c=&$this->{$m.$a[0]};$c=$a[1]??(is_callable($c)?$c($this):$c);return isset($a[1])?
2-
$this:$c;}function run(){foreach($this as$x=>$f)preg_match("@$x@i","$_SERVER[REQUEST_METHOD]$_SERVER[REQUEST_URI]",$p)&&
3-
$f($this,$p);}function view($f,$d=[]){ob_start();extract($d);require"$this->cfgviews/$f.php";return ob_get_clean();}}#JL
1+
<?php class µ{var$Δ;function __call($m,$a){$c=&$this->Δ[$m.$a[0]];$c=$a[1]??(is_callable($c)?$c($this):$c);return($a[1]
2+
??0)?$this:$c;}function view($d,$f,$s=[]){ob_start();extract($s);require"$d/$f.php";return ob_get_clean();}function run
3+
(){foreach($this->Δ as$x=>$f)preg_match("@$x@i","$_SERVER[REQUEST_METHOD]$_SERVER[REQUEST_URI]",$p)&&$f($this,$p);}}#JL

test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function ø($m,$r){$_SERVER['REQUEST_METHOD']=$m;$_SERVER['REQUEST_URI']=$r;}
5454
$file = $dir.'/tpl.php';
5555
!is_dir($dir) and mkdir($dir);
5656
file_put_contents($file, '[<?=$foo?>]');
57-
$ñ = (new µ)->cfg('views', $dir)->view('tpl', ['foo' => 'bar']);
57+
$ñ = (new µ)->view($dir, 'tpl', ['foo' => 'bar']);
5858
unlink($file);
5959
rmdir($dir);
6060
assert($ñ === "[bar]");

0 commit comments

Comments
 (0)