Skip to content

Commit

Permalink
Merge pull request #11 from jeremeamia/php-8.2-compatibilty
Browse files Browse the repository at this point in the history
Fix error in PHP 8.2
  • Loading branch information
jeremeamia authored Mar 27, 2023
2 parents b26f92b + 3e2c676 commit 4bad004
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ Templates are just PHP files—no mustaches and no frills.
```php
// index.php
(new µ)
->cfg('views', __DIR__ . '/templates')
->get('/hello/(?<name>\w+)', function ($app, $params) {
echo $app->view('hello', [
echo $app->view(__DIR__ . '/templates', 'hello', [
'greeting' => 'howdy',
'name' => $params['name'],
]);
Expand Down
5 changes: 3 additions & 2 deletions examples/hello4.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

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

const VIEWS_DIR = __DIR__ . '/templates';

(new µ)
->cfg('views', __DIR__ . '/templates')
->get('/hello/(?<name>\w+)', function ($app, $params) {
echo $app->view('hello4', [
echo $app->view(VIEWS_DIR, 'hello4', [
'greeting' => 'howdy',
'name' => $params['name'],
]);
Expand Down
6 changes: 3 additions & 3 deletions mu.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php class µ{function __call($m,$a){$c=&$this->{$m.$a[0]};$c=$a[1]??(is_callable($c)?$c($this):$c);return isset($a[1])?
$this:$c;}function run(){foreach($this as$x=>$f)preg_match("@$x@i","$_SERVER[REQUEST_METHOD]$_SERVER[REQUEST_URI]",$p)&&
$f($this,$p);}function view($f,$d=[]){ob_start();extract($d);require"$this->cfgviews/$f.php";return ob_get_clean();}}#JL
<?php class µ{var$Δ;function __call($m,$a){$c=&$this->Δ[$m.$a[0]];$c=$a[1]??(is_callable($c)?$c($this):$c);return($a[1]
??0)?$this:$c;}function view($d,$f,$s=[]){ob_start();extract($s);require"$d/$f.php";return ob_get_clean();}function run
(){foreach($this->Δ as$x=>$f)preg_match("@$x@i","$_SERVER[REQUEST_METHOD]$_SERVER[REQUEST_URI]",$p)&&$f($this,$p);}}#JL
2 changes: 1 addition & 1 deletion test.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function ø($m,$r){$_SERVER['REQUEST_METHOD']=$m;$_SERVER['REQUEST_URI']=$r;}
$file = $dir.'/tpl.php';
!is_dir($dir) and mkdir($dir);
file_put_contents($file, '[<?=$foo?>]');
$ñ = (new µ)->cfg('views', $dir)->view('tpl', ['foo' => 'bar']);
$ñ = (new µ)->view($dir, 'tpl', ['foo' => 'bar']);
unlink($file);
rmdir($dir);
assert($ñ === "[bar]");

0 comments on commit 4bad004

Please sign in to comment.