Skip to content

Commit a9abc28

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 7ce726e + 29a2764 commit a9abc28

File tree

15 files changed

+162
-56
lines changed

15 files changed

+162
-56
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/vendor
22
/resources/docs
3+
/public/page-cache
34
/public/api
45
/build/sami/build
56
/build/sami/cache
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php namespace App\Console\Commands;
2+
3+
use Illuminate\Console\Command;
4+
use Illuminate\Filesystem\Filesystem;
5+
6+
class ClearPageCache extends Command
7+
{
8+
/**
9+
* The name of the console command.
10+
*
11+
* @var string
12+
*/
13+
protected $name = 'docs:clear-cache';
14+
15+
/**
16+
* The console command description.
17+
*
18+
* @var string
19+
*/
20+
protected $description = 'Clears the page cache.';
21+
22+
/**
23+
* Execute the console command.
24+
*
25+
* @return mixed
26+
*/
27+
public function handle()
28+
{
29+
$path = public_path('page-cache');
30+
31+
if ($this->clearDirectory($path)) {
32+
$this->info("Page cache directory cleared at {$path}.");
33+
} else {
34+
$this->warn("Page cache directory not cleared at {$path}.");
35+
}
36+
}
37+
38+
/**
39+
* Clear all contents of the given directory recursively.
40+
*
41+
* @param string $path
42+
* @return bool
43+
*/
44+
protected function clearDirectory($path)
45+
{
46+
return $this->laravel->make(Filesystem::class)->deleteDirectory($path, true);
47+
}
48+
}

app/Console/Commands/Inspire.php

Lines changed: 0 additions & 34 deletions
This file was deleted.

app/Console/Kernel.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class Kernel extends ConsoleKernel
1111
* @var array
1212
*/
1313
protected $commands = [
14-
'App\Console\Commands\Inspire',
15-
'App\Console\Commands\IndexDocumentation',
14+
Commands\ClearPageCache::class,
15+
Commands\IndexDocumentation::class,
1616
];
1717

1818
/**

app/Http/Kernel.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@ class Kernel extends HttpKernel {
1010
* @var array
1111
*/
1212
protected $middleware = [
13-
'Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode',
14-
'Illuminate\Cookie\Middleware\EncryptCookies',
15-
'Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse',
16-
'Illuminate\Session\Middleware\StartSession',
17-
'Illuminate\View\Middleware\ShareErrorsFromSession',
18-
'App\Http\Middleware\VerifyCsrfToken',
13+
\App\Http\Middleware\CacheResponse::class,
14+
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
15+
\Illuminate\Cookie\Middleware\EncryptCookies::class,
16+
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
17+
\Illuminate\Session\Middleware\StartSession::class,
18+
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
19+
\App\Http\Middleware\VerifyCsrfToken::class,
1920
];
2021

2122
/**
@@ -24,9 +25,9 @@ class Kernel extends HttpKernel {
2425
* @var array
2526
*/
2627
protected $routeMiddleware = [
27-
'auth' => 'App\Http\Middleware\Authenticate',
28-
'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
29-
'guest' => 'App\Http\Middleware\RedirectIfAuthenticated',
28+
'auth' => \App\Http\Middleware\Authenticate::class,
29+
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
30+
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
3031
];
3132

3233
}

app/Http/Middleware/CacheResponse.php

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php namespace App\Http\Middleware;
2+
3+
use Closure;
4+
use Illuminate\Filesystem\Filesystem;
5+
6+
class CacheResponse
7+
{
8+
/**
9+
* The filesystem instance.
10+
*
11+
* @var \Illuminate\Filesystem\Filesystem
12+
*/
13+
protected $files;
14+
15+
/**
16+
* Constructor.
17+
*
18+
* @var \Illuminate\Filesystem\Filesystem $files
19+
*/
20+
public function __construct(Filesystem $files)
21+
{
22+
$this->files = $files;
23+
}
24+
25+
/**
26+
* Handle an incoming request.
27+
*
28+
* @param \Illuminate\Http\Request $request
29+
* @param \Closure $next
30+
* @return mixed
31+
*/
32+
public function handle($request, Closure $next)
33+
{
34+
$response = $next($request);
35+
36+
if ($this->shouldCache($request, $response)) {
37+
$this->cacheResponse($request, $response);
38+
}
39+
40+
return $response;
41+
}
42+
43+
/**
44+
* Determines whether the given request/response should be cached.
45+
*
46+
* @param \Illuminate\Http\Response $response
47+
* @return bool
48+
*/
49+
protected function shouldCache($request, $response)
50+
{
51+
return $request->isMethod('GET') && $response->getStatusCode() == 200;
52+
}
53+
54+
/**
55+
* Cache the response to a file.
56+
*
57+
* @param \Illuminate\Http\Request $request
58+
* @param \Illuminate\Http\Response $response
59+
* @return void
60+
*/
61+
protected function cacheResponse($request, $response)
62+
{
63+
list($path, $file) = $this->getDirectoryAndFileNames($request);
64+
65+
$this->files->makeDirectory($path, 0775, true, true);
66+
67+
$this->files->put($path.$file, $response->getContent());
68+
}
69+
70+
/**
71+
* Get the names of the directory and file.
72+
*
73+
* @param \Illuminate\Http\Request $request
74+
* @return array
75+
*/
76+
protected function getDirectoryAndFileNames($request)
77+
{
78+
$segments = explode('/', ltrim($request->getPathInfo(), '/'));
79+
80+
$file = array_pop($segments).'.html';
81+
82+
return [$this->getCachePath(implode('/', $segments)), $file];
83+
}
84+
85+
/**
86+
* Get the path to the cache directory.
87+
*
88+
* @param string $path
89+
* @return string
90+
*/
91+
protected function getCachePath($path = '')
92+
{
93+
return public_path('page-cache/'.($path ? trim($path, '/').'/' : $path));
94+
}
95+
}

public/assets/css/laravel.css

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/assets/css/laravel.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/assets/js/laravel.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/assets/css/laravel-d02b878c.css renamed to public/build/assets/css/laravel-04b3a148.css

Lines changed: 0 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/assets/css/laravel.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/assets/js/laravel.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

public/build/rev-manifest.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
2-
"assets/css/laravel.css": "assets/css/laravel-d02b878c.css",
3-
"assets/js/laravel.js": "assets/js/laravel-02364550.js"
2+
"assets/css/laravel.css": "assets/css/laravel-04b3a148.css",
3+
"assets/js/laravel.js": "assets/js/laravel-4758078a.js"
44
}

resources/assets/sass/components/_nav.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ nav.main {
7373
}
7474

7575
.responsive-sidebar-nav {
76-
.btn { background: #333; }
7776
display: none;
7877
float: right;
7978
margin-top: 25px;

0 commit comments

Comments
 (0)