Skip to content

Commit

Permalink
Merge pull request #81 from Agontuk/master
Browse files Browse the repository at this point in the history
Remove facade dependency
  • Loading branch information
rap2hpoutre authored Dec 15, 2016
2 parents 03d5cb9 + 579586e commit 8e5eb2d
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 25 deletions.
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 4 additions & 5 deletions src/Rap2hpoutre/LaravelLogViewer/LaravelLogViewer.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<?php
namespace Rap2hpoutre\LaravelLogViewer;

use Illuminate\Support\Facades\File;
use Psr\Log\LogLevel;
use ReflectionClass;

Expand Down Expand Up @@ -48,7 +47,7 @@ public static function setFile($file)
{
$file = self::pathToLogFile($file);

if (File::exists($file)) {
if (app('files')->exists($file)) {
self::$file = $file;
}
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);

Expand Down
40 changes: 25 additions & 15 deletions src/controllers/LogViewerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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);
}
}

0 comments on commit 8e5eb2d

Please sign in to comment.