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); 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..c6cc417 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 $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()); } $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,16 @@ private function redirect($to) return redirect($to); } - return Redirect::to($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); } }