Skip to content

Commit

Permalink
routing + view
Browse files Browse the repository at this point in the history
  • Loading branch information
schpill committed Jun 8, 2017
1 parent eb4bec1 commit da5cc5d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 18 deletions.
33 changes: 28 additions & 5 deletions lib/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1470,7 +1470,7 @@ function response($message = 'Forbidden', $code = 200)
function partial($file, $args = [])
{
vue(
'partials.' . $file, $args
$file, $args
)->partial(
actual('vue')
);
Expand All @@ -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,
Expand Down Expand Up @@ -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
);
Expand Down Expand Up @@ -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) {
Expand Down
11 changes: 8 additions & 3 deletions lib/router.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions lib/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 2 additions & 7 deletions lib/testcase.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<?php
namespace Octo;

use Mockery;
use PHPUnit_Framework_TestCase;
use PHPUnit\Framework\TestCase as PTC;

abstract class TestCase extends PHPUnit_Framework_TestCase
abstract class TestCase extends PTC
{
protected $app;

Expand Down Expand Up @@ -38,9 +37,5 @@ protected function tearDown()
if (property_exists($this, 'serverVariables')) {
$this->serverVariables = [];
}

if (class_exists('Mockery')) {
Mockery::close();
}
}
}

0 comments on commit da5cc5d

Please sign in to comment.