Skip to content

Commit 8e5eb2d

Browse files
authored
Merge pull request #81 from Agontuk/master
Remove facade dependency
2 parents 03d5cb9 + 579586e commit 8e5eb2d

File tree

3 files changed

+29
-25
lines changed

3 files changed

+29
-25
lines changed

README.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ Install via composer
4242
composer require rap2hpoutre/laravel-log-viewer
4343
```
4444

45-
Enable facades by uncommenting this line in `bootstrap/app.php`:
46-
```php
47-
$app->withFacades();
48-
```
49-
5045
Add the following in `bootstrap/app.php`:
5146
```php
5247
$app->register(Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class);

src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?php
22
namespace Rap2hpoutre\LaravelLogViewer;
33

4-
use Illuminate\Support\Facades\File;
54
use Psr\Log\LogLevel;
65
use ReflectionClass;
76

@@ -48,7 +47,7 @@ public static function setFile($file)
4847
{
4948
$file = self::pathToLogFile($file);
5049

51-
if (File::exists($file)) {
50+
if (app('files')->exists($file)) {
5251
self::$file = $file;
5352
}
5453
}
@@ -57,7 +56,7 @@ public static function pathToLogFile($file)
5756
{
5857
$logsPath = storage_path('logs');
5958

60-
if (File::exists($file)) { // try the absolute path
59+
if (app('files')->exists($file)) { // try the absolute path
6160
return $file;
6261
}
6362

@@ -98,9 +97,9 @@ public static function all()
9897
self::$file = $log_file[0];
9998
}
10099

101-
if (File::size(self::$file) > self::MAX_FILE_SIZE) return null;
100+
if (app('files')->size(self::$file) > self::MAX_FILE_SIZE) return null;
102101

103-
$file = File::get(self::$file);
102+
$file = app('files')->get(self::$file);
104103

105104
preg_match_all($pattern, $file, $headings);
106105

src/controllers/LogViewerController.php

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,32 @@ class BaseController extends \Illuminate\Routing\Controller {}
77
class BaseController extends \Laravel\Lumen\Routing\Controller {}
88
}
99

10-
use Illuminate\Support\Facades\File;
11-
use Illuminate\Support\Facades\View;
12-
use Illuminate\Support\Facades\Redirect;
13-
use Illuminate\Support\Facades\Request;
14-
use Illuminate\Support\Facades\Response;
15-
1610
class LogViewerController extends BaseController
1711
{
12+
protected $request;
13+
14+
public function __construct ()
15+
{
16+
$this->request = app('request');
17+
}
1818

1919
public function index()
2020
{
2121

22-
if (Request::input('l')) {
23-
LaravelLogViewer::setFile(base64_decode(Request::input('l')));
22+
if ($this->request->input('l')) {
23+
LaravelLogViewer::setFile(base64_decode($this->request->input('l')));
2424
}
2525

26-
if (Request::input('dl')) {
27-
return Response::download(LaravelLogViewer::pathToLogFile(base64_decode(Request::input('dl'))));
28-
} elseif (Request::has('del')) {
29-
File::delete(LaravelLogViewer::pathToLogFile(base64_decode(Request::input('del'))));
30-
return $this->redirect(Request::url());
26+
if ($this->request->input('dl')) {
27+
return $this->download(LaravelLogViewer::pathToLogFile(base64_decode($this->request->input('dl'))));
28+
} elseif ($this->request->has('del')) {
29+
app('files')->delete(LaravelLogViewer::pathToLogFile(base64_decode($this->request->input('del'))));
30+
return $this->redirect($this->request->url());
3131
}
3232

3333
$logs = LaravelLogViewer::all();
3434

35-
return View::make('laravel-log-viewer::log', [
35+
return app('view')->make('laravel-log-viewer::log', [
3636
'logs' => $logs,
3737
'files' => LaravelLogViewer::getFiles(true),
3838
'current_file' => LaravelLogViewer::getFileName()
@@ -45,6 +45,16 @@ private function redirect($to)
4545
return redirect($to);
4646
}
4747

48-
return Redirect::to($to);
48+
return app('redirect')->to($to);
49+
}
50+
51+
private function download($data)
52+
{
53+
if (function_exists('response')) {
54+
return response()->download($data);
55+
}
56+
57+
// For laravel 4.2
58+
return app('\Illuminate\Support\Facades\Response')->download($data);
4959
}
5060
}

0 commit comments

Comments
 (0)