From 5649c0bc37d8941a2408ed99d0f6f87a83f3eead Mon Sep 17 00:00:00 2001 From: Iftekhar Rifat Date: Thu, 15 Dec 2016 12:06:16 +0600 Subject: [PATCH 1/3] Remove facade dependency --- .../LaravelLogViewer/LaravelLogViewer.php | 9 +++--- src/controllers/LogViewerController.php | 30 +++++++++---------- 2 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php index b0a79e7..4c67a3c 100644 --- a/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php +++ b/src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php @@ -1,7 +1,6 @@ exists($file)) { self::$file = $file; } } @@ -57,7 +56,7 @@ public static function pathToLogFile($file) { $logsPath = storage_path('logs'); - if (File::exists($file)) { // try the absolute path + if (app('files')->exists($file)) { // try the absolute path return $file; } @@ -98,9 +97,9 @@ public static function all() self::$file = $log_file[0]; } - if (File::size(self::$file) > self::MAX_FILE_SIZE) return null; + if (app('files')->size(self::$file) > self::MAX_FILE_SIZE) return null; - $file = File::get(self::$file); + $file = app('files')->get(self::$file); preg_match_all($pattern, $file, $headings); diff --git a/src/controllers/LogViewerController.php b/src/controllers/LogViewerController.php index bb543e1..1ef59f3 100644 --- a/src/controllers/LogViewerController.php +++ b/src/controllers/LogViewerController.php @@ -7,32 +7,32 @@ class BaseController extends \Illuminate\Routing\Controller {} class BaseController extends \Laravel\Lumen\Routing\Controller {} } -use Illuminate\Support\Facades\File; -use Illuminate\Support\Facades\View; -use Illuminate\Support\Facades\Redirect; -use Illuminate\Support\Facades\Request; -use Illuminate\Support\Facades\Response; - class LogViewerController extends BaseController { + protected $request; + + public function __construct () + { + $this->request = app('request'); + } public function index() { - if (Request::input('l')) { - LaravelLogViewer::setFile(base64_decode(Request::input('l'))); + if ($this->request->input('l')) { + LaravelLogViewer::setFile(base64_decode($this->request->input('l'))); } - if (Request::input('dl')) { - return Response::download(LaravelLogViewer::pathToLogFile(base64_decode(Request::input('dl')))); - } elseif (Request::has('del')) { - File::delete(LaravelLogViewer::pathToLogFile(base64_decode(Request::input('del')))); - return $this->redirect(Request::url()); + if ($this->request->input('dl')) { + return response()->download(LaravelLogViewer::pathToLogFile(base64_decode($this->request->input('dl')))); + } elseif ($this->request->has('del')) { + app('files')->delete(LaravelLogViewer::pathToLogFile(base64_decode($this->request->input('del')))); + return $this->redirect($this->request->url()); } $logs = LaravelLogViewer::all(); - return View::make('laravel-log-viewer::log', [ + return app('view')->make('laravel-log-viewer::log', [ 'logs' => $logs, 'files' => LaravelLogViewer::getFiles(true), 'current_file' => LaravelLogViewer::getFileName() @@ -45,6 +45,6 @@ private function redirect($to) return redirect($to); } - return Redirect::to($to); + return app('redirect')->to($to); } } From 9196888638982723c5171be61d9bfc683416a74e Mon Sep 17 00:00:00 2001 From: Iftekhar Rifat Date: Thu, 15 Dec 2016 12:08:58 +0600 Subject: [PATCH 2/3] Remove facade instructions from README --- README.md | 5 ----- 1 file changed, 5 deletions(-) diff --git a/README.md b/README.md index 3f32397..ed6f03b 100644 --- a/README.md +++ b/README.md @@ -42,11 +42,6 @@ Install via composer composer require rap2hpoutre/laravel-log-viewer ``` -Enable facades by uncommenting this line in `bootstrap/app.php`: -```php -$app->withFacades(); -``` - Add the following in `bootstrap/app.php`: ```php $app->register(Rap2hpoutre\LaravelLogViewer\LaravelLogViewerServiceProvider::class); From 579586e3e49a299334b29447484df4f3087ff325 Mon Sep 17 00:00:00 2001 From: Iftekhar Rifat Date: Thu, 15 Dec 2016 22:00:12 +0600 Subject: [PATCH 3/3] Fix laravel 4.2 compatibility --- src/controllers/LogViewerController.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/controllers/LogViewerController.php b/src/controllers/LogViewerController.php index 1ef59f3..c6cc417 100644 --- a/src/controllers/LogViewerController.php +++ b/src/controllers/LogViewerController.php @@ -24,7 +24,7 @@ public function index() } if ($this->request->input('dl')) { - return response()->download(LaravelLogViewer::pathToLogFile(base64_decode($this->request->input('dl')))); + return $this->download(LaravelLogViewer::pathToLogFile(base64_decode($this->request->input('dl')))); } elseif ($this->request->has('del')) { app('files')->delete(LaravelLogViewer::pathToLogFile(base64_decode($this->request->input('del')))); return $this->redirect($this->request->url()); @@ -47,4 +47,14 @@ private function redirect($to) return app('redirect')->to($to); } + + private function download($data) + { + if (function_exists('response')) { + return response()->download($data); + } + + // For laravel 4.2 + return app('\Illuminate\Support\Facades\Response')->download($data); + } }