Apply fixes from StyleCI

This commit is contained in:
Manish Verma
2016-12-13 13:14:54 +00:00
committed by StyleCI Bot
parent 857d3004eb
commit 88f3df2180
161 changed files with 4729 additions and 3879 deletions

View File

@@ -8,33 +8,32 @@ use ReflectionClass;
use UTC;
/**
* Class LaravelLogViewer
* @package Rap2hpoutre\LaravelLogViewer
* Class LaravelLogViewer.
*/
class LaravelLogViewer {
class LaravelLogViewer
{
/**
* @var string file
*/
private static $file;
private static $levels_classes = [
'debug' => 'info',
'info' => 'info',
'notice' => 'info',
'warning' => 'warning',
'error' => 'danger',
'critical' => 'danger',
'alert' => 'danger',
'debug' => 'info',
'info' => 'info',
'notice' => 'info',
'warning' => 'warning',
'error' => 'danger',
'critical' => 'danger',
'alert' => 'danger',
'emergency' => 'danger',
];
private static $levels_imgs = [
'debug' => 'info',
'info' => 'info',
'notice' => 'info',
'warning' => 'warning',
'error' => 'warning',
'critical' => 'warning',
'alert' => 'warning',
'debug' => 'info',
'info' => 'info',
'notice' => 'info',
'warning' => 'warning',
'error' => 'warning',
'critical' => 'warning',
'alert' => 'warning',
'emergency' => 'warning',
];
@@ -43,7 +42,8 @@ class LaravelLogViewer {
/**
* @param string $file
*/
public static function setFile($file) {
public static function setFile($file)
{
$file = self::pathToLogFile($file);
if (File::exists($file)) {
@@ -51,14 +51,15 @@ class LaravelLogViewer {
}
}
public static function pathToLogFile($file) {
public static function pathToLogFile($file)
{
$logsPath = storage_path('logs');
if (File::exists($file)) { // try the absolute path
return $file;
}
$file = $logsPath . '/' . $file;
$file = $logsPath.'/'.$file;
// check if requested file is really in the logs directory
if (dirname($file) !== $logsPath) {
@@ -71,15 +72,17 @@ class LaravelLogViewer {
/**
* @return string
*/
public static function getFileName() {
public static function getFileName()
{
return basename(self::$file);
}
/**
* @return array
*/
public static function all() {
$log = array();
public static function all()
{
$log = [];
$log_levels = self::getLogLevels();
@@ -93,15 +96,17 @@ class LaravelLogViewer {
self::$file = $log_file[0];
}
if (File::size(self::$file) > self::MAX_FILE_SIZE)
return null;
if (File::size(self::$file) > self::MAX_FILE_SIZE) {
return;
}
$file = File::get(self::$file);
preg_match_all($pattern, $file, $headings);
if (!is_array($headings))
if (!is_array($headings)) {
return $log;
}
$log_data = preg_split($pattern, $file);
@@ -112,38 +117,38 @@ class LaravelLogViewer {
foreach ($headings as $h) {
for ($i = 0, $j = count($h); $i < $j; $i++) {
foreach ($log_levels as $level_key => $level_value) {
if (strpos(strtolower($h[$i]), '.' . $level_value)) {
if (strpos(strtolower($h[$i]), '.'.$level_value)) {
preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?(\w+)\.'.$level_key.': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current);
preg_match('/^\[(\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2})\].*?(\w+)\.' . $level_key . ': (.*?)( in .*?:[0-9]+)?$/', $h[$i], $current);
if (!isset($current[3]))
if (!isset($current[3])) {
continue;
}
$array = explode(':-:-:-', $current[3]);
$message = $current[3];
$context = $current[2];
if (is_array($array)) {
if (array_key_exists(0, $array)) {
$message = $array[0];
}
if (array_key_exists(1, $array)) {
$context = $array[1];
}else{
} else {
$context = $current[2];
}
}
//dd($current);
$log[] = array(
'context' => $context,
'level' => $level_value,
$log[] = [
'context' => $context,
'level' => $level_value,
'level_class' => self::$levels_classes[$level_value],
'level_img' => self::$levels_imgs[$level_value],
'date' => self::date($current[1]),
'text' => $message,
'in_file' => isset($current[4]) ? $current[4] : null,
'stack' => preg_replace("/^\n*/", '', $log_data[$i])
);
'level_img' => self::$levels_imgs[$level_value],
'date' => self::date($current[1]),
'text' => $message,
'in_file' => isset($current[4]) ? $current[4] : null,
'stack' => preg_replace("/^\n*/", '', $log_data[$i]),
];
}
}
}
@@ -154,10 +159,12 @@ class LaravelLogViewer {
/**
* @param bool $basename
*
* @return array
*/
public static function getFiles($basename = false) {
$files = glob(storage_path() . '/logs/*');
public static function getFiles($basename = false)
{
$files = glob(storage_path().'/logs/*');
$files = array_reverse($files);
$files = array_filter($files, 'is_file');
if ($basename && is_array($files)) {
@@ -165,20 +172,24 @@ class LaravelLogViewer {
$files[$k] = basename($file);
}
}
return array_values($files);
}
/**
* @return array
*/
private static function getLogLevels() {
$class = new ReflectionClass(new LogLevel);
private static function getLogLevels()
{
$class = new ReflectionClass(new LogLevel());
return $class->getConstants();
}
public static function date($utc) {
public static function date($utc)
{
$system_date = UTC::usertimezone($utc);
return $system_date;
}
}

View File

@@ -4,8 +4,8 @@ namespace App\FaveoLog;
use Illuminate\Support\ServiceProvider;
class LaravelLogViewerServiceProvider extends ServiceProvider {
class LaravelLogViewerServiceProvider extends ServiceProvider
{
/**
* Indicates if loading of the provider is deferred.
*
@@ -18,17 +18,17 @@ class LaravelLogViewerServiceProvider extends ServiceProvider {
*
* @return void
*/
public function boot() {
public function boot()
{
if (method_exists($this, 'package')) {
$this->package('rap2hpoutre/laravel-log-viewer', 'laravel-log-viewer', __DIR__ . '/../../');
$this->package('rap2hpoutre/laravel-log-viewer', 'laravel-log-viewer', __DIR__.'/../../');
}
$view_path = app_path() . DIRECTORY_SEPARATOR . 'FaveoLog' . DIRECTORY_SEPARATOR . 'views';
$view_path = app_path().DIRECTORY_SEPARATOR.'FaveoLog'.DIRECTORY_SEPARATOR.'views';
$this->loadViewsFrom($view_path, 'log');
$lang_path = app_path() . DIRECTORY_SEPARATOR . 'FaveoLog' . DIRECTORY_SEPARATOR . 'lang';
$this->loadTranslationsFrom($lang_path, "log");
$lang_path = app_path().DIRECTORY_SEPARATOR.'FaveoLog'.DIRECTORY_SEPARATOR.'lang';
$this->loadTranslationsFrom($lang_path, 'log');
}
/**
@@ -36,7 +36,8 @@ class LaravelLogViewerServiceProvider extends ServiceProvider {
*
* @return void
*/
public function register() {
public function register()
{
// Add routes
$routes = app_path('/FaveoLog/routes.php');
if (file_exists($routes)) {
@@ -49,8 +50,8 @@ class LaravelLogViewerServiceProvider extends ServiceProvider {
*
* @return array
*/
public function provides() {
return array();
public function provides()
{
return [];
}
}

View File

@@ -1,40 +1,38 @@
<?php
namespace App\FaveoLog\controllers;
use App\FaveoLog\LaravelLogViewer;
use App\Http\Controllers\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;
use App\FaveoLog\LaravelLogViewer;
use Illuminate\Support\Facades\View;
class LogViewerController extends Controller
{
public function index()
{
if (Request::input('l')) {
//dd(base64_decode(Request::input('l')));
LaravelLogViewer::setFile(base64_decode(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 Redirect::to(Request::url());
}
$logs = LaravelLogViewer::all();
return View::make('log::log', [
'logs' => $logs,
'files' => LaravelLogViewer::getFiles(true),
'current_file' => LaravelLogViewer::getFileName()
'logs' => $logs,
'files' => LaravelLogViewer::getFiles(true),
'current_file' => LaravelLogViewer::getFileName(),
]);
}
}

View File

@@ -1,5 +1,5 @@
<?php
return [
'logs'=>'Logs',
'logs'=> 'Logs',
];

View File

@@ -4,7 +4,6 @@ Breadcrumbs::register('logs', function ($breadcrumbs) {
$breadcrumbs->parent('setting');
$breadcrumbs->push('System Logs', route('logs'));
});
Route::group(['middleware' => ['web', 'auth', 'roles']], function() {
Route::group(['middleware' => ['web', 'auth', 'roles']], function () {
Route::get('logs', ['as' => 'logs', 'uses' => 'App\FaveoLog\controllers\LogViewerController@index']);
});