diff --git a/lib/lib.php b/lib/lib.php index 460a3e5..11c4298 100755 --- a/lib/lib.php +++ b/lib/lib.php @@ -1470,7 +1470,7 @@ function response($message = 'Forbidden', $code = 200) function partial($file, $args = []) { vue( - 'partials.' . $file, $args + $file, $args )->partial( actual('vue') ); @@ -1485,7 +1485,7 @@ function layout($file, $page = null, $sections = null) : array_merge(['content', 'js', 'css'], $sections); vue( - 'layouts.' . $file, + $file, $page->getArgs() )->layout( $page, @@ -1555,9 +1555,27 @@ function vue($file, $args = [], $status = 200) $layoutContent = File::read($vue->getPath()); $pageContent = File::read($page->getPath()); - foreach ($sections as $section) { + $includes = explode("@include(", $pageContent); + array_shift($includes); + + foreach ($includes as $include) { + $inc = cut("'", "'", $include); + $pathFile = path('app') . '/views/' . str_replace('.', '/', $inc) . '.phtml'; + + if (File::exists($pathFile)) { + $incContent = File::read($pathFile); + $pageContent = str_replace("@include('$inc')", $incContent, $pageContent); + } + } + + $sections = explode("@section(", $pageContent); + array_shift($sections); + + foreach ($sections as $sub) { + $section = cut("'", "'", $sub); + $sectionContent = cut( - "@section $section", + "@section('$section')", "@endsection", $pageContent ); @@ -5897,12 +5915,17 @@ function remember($key, $callback, $minutes = null) $minutes = !is_null($minutes) ? $minutes * 60 : null; if (!is_callable($callback)) { - $callback = voidToCallback($callback); + $callback = toClosure($callback); } return fmr()->getOr($key, $callback, $minutes); } + function toClosure($concern) + { + return voidToCallback($concern); + } + function voidToCallback($concern) { return function () use ($concern) { diff --git a/lib/router.php b/lib/router.php index ef381fd..2a56319 100644 --- a/lib/router.php +++ b/lib/router.php @@ -481,9 +481,14 @@ public function handling($routes, $quit = true) if ($this->uri) { route($route); - if ($middleware = Route::getMiddleware($this->uri->getName())) { - if (is_callable($middleware)) { - call($middleware, [$this->uri]); + if ($middleware = $route->getMiddleware()) { + if (!is_array($middleware)) { + $middleware = [$middleware]; + } + + foreach ($middleware as $handler) { + $handler = maker($handler); + $handler->handle(); } } } diff --git a/lib/routes.php b/lib/routes.php index ed58155..c2e634f 100644 --- a/lib/routes.php +++ b/lib/routes.php @@ -154,10 +154,15 @@ public static function resource($model, $controller = null) } } + public static function json(array $array) + { + return toClosure($array); + } + public static function __callStatic($m, $a) { if ('array' == $m) { - return voidToCallback($a); + return toClosure($a); } $uri = array_shift($a); @@ -291,8 +296,8 @@ public static function __callStatic($m, $a) return $route->setName($name); }); - $route->macro('middleware', function (callable $cb) use ($route) { - return $route->setMiddleware($cb); + $route->macro('middleware', function ($middleware) use ($route) { + return $route->setMiddleware($middleware); }); $route->macro('uses', function ($string) use ($route) { diff --git a/lib/testcase.php b/lib/testcase.php index e289fdb..bfecf4e 100644 --- a/lib/testcase.php +++ b/lib/testcase.php @@ -1,10 +1,9 @@ serverVariables = []; } - - if (class_exists('Mockery')) { - Mockery::close(); - } } }