diff --git a/composer.json b/composer.json index 0d05065b..e3116913 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": { "php": ">=5.6", "psr/log": "~1.0", - "arcanedev/support": "~3.20" + "arcanedev/support": "~4.0" }, "require-dev": { "phpunit/phpcov": "~3.0", diff --git a/src/Commands/CheckCommand.php b/src/Commands/CheckCommand.php index 47217b0a..2e84f3ba 100644 --- a/src/Commands/CheckCommand.php +++ b/src/Commands/CheckCommand.php @@ -1,5 +1,7 @@ laravel[LogCheckerContract::class]; + } /* ------------------------------------------------------------------------------------------------ | Main Functions @@ -46,19 +59,20 @@ class CheckCommand extends Command public function handle() { $this->displayLogViewer(); - - $this->checker = $this->laravel['arcanedev.log-viewer.checker']; - $this->displayRequirements(); $this->displayMessages(); } + /* ------------------------------------------------------------------------------------------------ + | Other Functions + | ------------------------------------------------------------------------------------------------ + */ /** * Display LogViewer requirements. */ private function displayRequirements() { - $requirements = $this->checker->requirements(); + $requirements = $this->getChecker()->requirements(); $this->frame('Application requirements'); @@ -74,7 +88,7 @@ private function displayRequirements() */ private function displayMessages() { - $messages = $this->checker->messages(); + $messages = $this->getChecker()->messages(); $rows = []; foreach ($messages['files'] as $file => $message) { diff --git a/src/Commands/Command.php b/src/Commands/Command.php index 30414e8e..0f5b147b 100644 --- a/src/Commands/Command.php +++ b/src/Commands/Command.php @@ -53,7 +53,7 @@ protected function displayLogViewer() $this->line(''); // Copyright - $this->comment('Version ' . $this->logViewer->version() . ' - Created by ARCANEDEV' . chr(169)); + $this->comment('Version '.$this->logViewer->version().' - Created by ARCANEDEV'.chr(169)); $this->line(''); } } diff --git a/src/Commands/PublishCommand.php b/src/Commands/PublishCommand.php index 09c451b0..222c2791 100644 --- a/src/Commands/PublishCommand.php +++ b/src/Commands/PublishCommand.php @@ -51,14 +51,10 @@ public function handle() ]; if ((bool) $this->option('force')) { - $args['--force'] = true; + $args['--force'] = true; } - $tag = $this->option('tag'); - - if ( ! is_null($tag)) { - $args['--tag'] = version_compare(laravel_version(), '5.1.0', '>=') ? [$tag] : $tag; - } + $args['--tag'] = [$this->option('tag')]; $this->displayLogViewer(); $this->call('vendor:publish', $args); diff --git a/src/Entities/LogCollection.php b/src/Entities/LogCollection.php index 20d2c926..861ee921 100644 --- a/src/Entities/LogCollection.php +++ b/src/Entities/LogCollection.php @@ -31,7 +31,7 @@ class LogCollection extends Collection */ public function __construct($items = []) { - $this->setFilesystem(app('arcanedev.log-viewer.filesystem')); + $this->setFilesystem(app(FilesystemContract::class)); parent::__construct($items); diff --git a/src/Entities/LogEntry.php b/src/Entities/LogEntry.php index c2dd1a41..d497606e 100644 --- a/src/Entities/LogEntry.php +++ b/src/Entities/LogEntry.php @@ -201,10 +201,10 @@ public function isSameLevel($level) public function toArray() { return [ - 'level' => $this->level, - 'datetime' => $this->datetime->format('Y-m-d H:i:s'), - 'header' => $this->header, - 'stack' => $this->stack + 'level' => $this->level, + 'datetime' => $this->datetime->format('Y-m-d H:i:s'), + 'header' => $this->header, + 'stack' => $this->stack ]; } @@ -257,7 +257,7 @@ public function hasStack() */ private function cleanHeader($header) { - return preg_replace('/\[' . REGEX_DATETIME_PATTERN . '\][ ]/', '', $header); + return preg_replace('/\['.REGEX_DATETIME_PATTERN.'\][ ]/', '', $header); } /** @@ -269,6 +269,6 @@ private function cleanHeader($header) */ private function extractDatetime($header) { - return preg_replace('/^\[(' . REGEX_DATETIME_PATTERN . ')\].*/', '$1', $header); + return preg_replace('/^\[('.REGEX_DATETIME_PATTERN.')\].*/', '$1', $header); } } diff --git a/src/Facades/LogMenu.php b/src/Facades/LogMenu.php index 70d84881..be65e254 100644 --- a/src/Facades/LogMenu.php +++ b/src/Facades/LogMenu.php @@ -1,5 +1,6 @@ logViewer = app('arcanedev.log-viewer'); + $this->logViewer = app(\Arcanedev\LogViewer\Contracts\LogViewer::class); } /* ------------------------------------------------------------------------------------------------ diff --git a/src/Http/Routes/LogViewerRoute.php b/src/Http/Routes/LogViewerRoute.php index 9f801cbd..26837bdc 100644 --- a/src/Http/Routes/LogViewerRoute.php +++ b/src/Http/Routes/LogViewerRoute.php @@ -1,7 +1,6 @@ get('/', [ 'as' => 'log-viewer::dashboard', @@ -41,9 +38,7 @@ public function map(Router $router) */ private function registerLogsRoutes() { - $this->group([ - 'prefix' => 'logs', - ], function() { + $this->prefix('logs')->group(function() { $this->get('/', [ 'as' => 'log-viewer::logs.list', 'uses' => 'LogViewerController@listLogs', @@ -63,9 +58,7 @@ private function registerLogsRoutes() */ private function registerSingleLogRoutes() { - $this->group([ - 'prefix' => '{date}', - ], function() { + $this->prefix('{date}')->group(function() { $this->get('/', [ 'as' => 'log-viewer::logs.show', 'uses' => 'LogViewerController@show', diff --git a/src/LogViewerServiceProvider.php b/src/LogViewerServiceProvider.php index d23aa6ad..56ad23e9 100644 --- a/src/LogViewerServiceProvider.php +++ b/src/LogViewerServiceProvider.php @@ -71,7 +71,6 @@ public function boot() public function provides() { return [ - 'arcanedev.log-viewer', Contracts\LogViewer::class, ]; } @@ -86,7 +85,6 @@ public function provides() private function registerLogViewer() { $this->singleton(Contracts\LogViewer::class, LogViewer::class); - $this->singleton('arcanedev.log-viewer', Contracts\LogViewer::class); // Registering the Facade $this->alias( diff --git a/src/Providers/UtilitiesServiceProvider.php b/src/Providers/UtilitiesServiceProvider.php index 154269a7..d839ceec 100644 --- a/src/Providers/UtilitiesServiceProvider.php +++ b/src/Providers/UtilitiesServiceProvider.php @@ -3,6 +3,7 @@ use Arcanedev\LogViewer\Contracts; use Arcanedev\LogViewer\Utilities; use Arcanedev\Support\ServiceProvider; +use Illuminate\Support\Arr; /** * Class UtilitiesServiceProvider @@ -37,17 +38,11 @@ public function register() public function provides() { return [ - 'arcanedev.log-viewer.levels', Contracts\Utilities\LogLevels::class, - 'arcanedev.log-viewer.styler', Contracts\Utilities\LogStyler::class, - 'arcanedev.log-viewer.menu', Contracts\Utilities\LogMenu::class, - 'arcanedev.log-viewer.filesystem', Contracts\Utilities\Filesystem::class, - 'arcanedev.log-viewer.factory', Contracts\Utilities\Factory::class, - 'arcanedev.log-viewer.checker', Contracts\Utilities\LogChecker::class, ]; } @@ -71,8 +66,6 @@ private function registerLogLevels() return new Utilities\LogLevels($translator, $config->get('log-viewer.locale')); }); - - $this->singleton('arcanedev.log-viewer.levels', Contracts\Utilities\LogLevels::class); } /** @@ -81,7 +74,6 @@ private function registerLogLevels() private function registerStyler() { $this->singleton(Contracts\Utilities\LogStyler::class, Utilities\LogStyler::class); - $this->singleton('arcanedev.log-viewer.styler', Contracts\Utilities\LogStyler::class); } /** @@ -90,7 +82,6 @@ private function registerStyler() private function registerLogMenu() { $this->singleton(Contracts\Utilities\LogMenu::class, Utilities\LogMenu::class); - $this->singleton('arcanedev.log-viewer.menu', Contracts\Utilities\LogMenu::class); } /** @@ -107,16 +98,16 @@ private function registerFilesystem() $files = $app['files']; $filesystem = new Utilities\Filesystem($files, $config->get('log-viewer.storage-path')); + $pattern = $config->get('log-viewer.pattern', []); + $filesystem->setPattern( - $config->get('log-viewer.pattern.prefix', Utilities\Filesystem::PATTERN_PREFIX), - $config->get('log-viewer.pattern.date', Utilities\Filesystem::PATTERN_DATE), - $config->get('log-viewer.pattern.extension', Utilities\Filesystem::PATTERN_EXTENSION) + Arr::get($pattern, 'prefix', Utilities\Filesystem::PATTERN_PREFIX), + Arr::get($pattern, 'date', Utilities\Filesystem::PATTERN_DATE), + Arr::get($pattern, 'extension', Utilities\Filesystem::PATTERN_EXTENSION) ); return $filesystem; }); - - $this->singleton('arcanedev.log-viewer.filesystem', Contracts\Utilities\Filesystem::class); } /** @@ -125,7 +116,6 @@ private function registerFilesystem() private function registerFactory() { $this->singleton(Contracts\Utilities\Factory::class, Utilities\Factory::class); - $this->singleton('arcanedev.log-viewer.factory', Contracts\Utilities\Factory::class); } /** @@ -134,6 +124,5 @@ private function registerFactory() private function registerChecker() { $this->singleton(Contracts\Utilities\LogChecker::class, Utilities\LogChecker::class); - $this->singleton('arcanedev.log-viewer.checker', Contracts\Utilities\LogChecker::class); } } diff --git a/tests/LogViewerServiceProviderTest.php b/tests/LogViewerServiceProviderTest.php index 0e51f583..5e3750e2 100644 --- a/tests/LogViewerServiceProviderTest.php +++ b/tests/LogViewerServiceProviderTest.php @@ -58,7 +58,6 @@ public function it_can_be_instantiated() public function it_can_provides() { $expected = [ - 'arcanedev.log-viewer', \Arcanedev\LogViewer\Contracts\LogViewer::class, ]; diff --git a/tests/LogViewerTest.php b/tests/LogViewerTest.php index 2fa6dddc..c8d25701 100644 --- a/tests/LogViewerTest.php +++ b/tests/LogViewerTest.php @@ -26,7 +26,7 @@ public function setUp() { parent::setUp(); - $this->logViewer = $this->app['arcanedev.log-viewer']; + $this->logViewer = $this->app->make(\Arcanedev\LogViewer\Contracts\LogViewer::class); } public function tearDown() diff --git a/tests/Providers/UtilitiesServiceProviderTest.php b/tests/Providers/UtilitiesServiceProviderTest.php index a5f3e6ba..9bed0c07 100644 --- a/tests/Providers/UtilitiesServiceProviderTest.php +++ b/tests/Providers/UtilitiesServiceProviderTest.php @@ -60,17 +60,11 @@ public function it_can_be_instantiated() public function it_can_provides() { $expected = [ - 'arcanedev.log-viewer.levels', Contracts\Utilities\LogLevels::class, - 'arcanedev.log-viewer.styler', Contracts\Utilities\LogStyler::class, - 'arcanedev.log-viewer.menu', Contracts\Utilities\LogMenu::class, - 'arcanedev.log-viewer.filesystem', Contracts\Utilities\Filesystem::class, - 'arcanedev.log-viewer.factory', Contracts\Utilities\Factory::class, - 'arcanedev.log-viewer.checker', Contracts\Utilities\LogChecker::class, ]; diff --git a/tests/RoutesTest.php b/tests/RoutesTest.php index bce6370e..27d73777 100644 --- a/tests/RoutesTest.php +++ b/tests/RoutesTest.php @@ -19,7 +19,8 @@ public function it_can_see_dashboard_page() { $response = $this->route('GET', 'log-viewer::dashboard'); - $this->assertResponseOk(); + $response->isOk(); + $this->assertContains( '

Dashboard

', $response->getContent() diff --git a/tests/Tables/StatsTableTest.php b/tests/Tables/StatsTableTest.php index 97a70148..330b2b36 100644 --- a/tests/Tables/StatsTableTest.php +++ b/tests/Tables/StatsTableTest.php @@ -29,10 +29,9 @@ public function setUp() { parent::setUp(); - $this->rawData = $this->app['arcanedev.log-viewer']->stats(); $this->table = new StatsTable( - $this->rawData, - $this->app['arcanedev.log-viewer.levels'] + $this->rawData = $this->getLogViewerInstance()->stats(), + $this->getLogLevelsInstance() ); } @@ -57,8 +56,8 @@ public function it_can_be_instantiated() public function it_can_make_instance() { $this->table = StatsTable::make( - $this->app['arcanedev.log-viewer']->stats(), - $this->app['arcanedev.log-viewer.levels'] + $this->getLogViewerInstance()->stats(), + $this->getLogLevelsInstance() ); $this->assertTable($this->table); @@ -106,4 +105,28 @@ public function it_can_get_json_data_for_chart() $this->assertJson($json); } + + /* ------------------------------------------------------------------------------------------------ + | Other Functions + | ------------------------------------------------------------------------------------------------ + */ + /** + * Get the LogViewer instance. + * + * @return \Arcanedev\LogViewer\Contracts\LogViewer + */ + protected function getLogViewerInstance() + { + return $this->app->make(\Arcanedev\LogViewer\Contracts\LogViewer::class); + } + + /** + * Get the LogLevels instance. + * + * @return \Arcanedev\LogViewer\Contracts\Utilities\LogLevels + */ + protected function getLogLevelsInstance() + { + return $this->app->make(\Arcanedev\LogViewer\Contracts\Utilities\LogLevels::class); + } } diff --git a/tests/TestCase.php b/tests/TestCase.php index 28a8862f..a7290eac 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -5,8 +5,7 @@ use Arcanedev\LogViewer\Entities\LogEntry; use Arcanedev\LogViewer\Entities\LogEntryCollection; use Carbon\Carbon; -use Illuminate\Contracts\Support\Jsonable; -use Illuminate\Foundation\Application; +use Illuminate\Support\Arr; use Orchestra\Testbench\BrowserKit\TestCase as BaseTestCase; use Psr\Log\LogLevel; use ReflectionClass; @@ -57,7 +56,7 @@ public static function tearDownAfterClass() /** * Get package providers. * - * @param Application $app + * @param \Illuminate\Foundation\Application $app * * @return array */ @@ -71,7 +70,7 @@ protected function getPackageProviders($app) /** * Define environment setup. * - * @param Application $app + * @param \Illuminate\Foundation\Application $app */ protected function getEnvironmentSetUp($app) { @@ -90,8 +89,8 @@ protected function getEnvironmentSetUp($app) /** * Asserts that a string is a valid JSON string. * - * @param Jsonable|mixed $object - * @param string $message + * @param \Illuminate\Contracts\Support\Jsonable|mixed $object + * @param string $message */ public static function assertJsonObject($object, $message = '') { @@ -138,7 +137,7 @@ protected function assertLogEntry($date, LogEntry $entry) $dt = Carbon::createFromFormat('Y-m-d', $date); $this->assertInLogLevels($entry->level); - $this->assertInstanceOf(\Carbon\Carbon::class, $entry->datetime); + $this->assertInstanceOf(Carbon::class, $entry->datetime); $this->assertTrue($entry->datetime->isSameDay($dt)); $this->assertNotEmpty($entry->header); $this->assertNotEmpty($entry->stack); @@ -335,7 +334,7 @@ protected function assertHexColor($color, $message = '') */ public function illuminateFile() { - return app('files'); + return $this->app->make('files'); } /** @@ -345,7 +344,7 @@ public function illuminateFile() */ protected function filesystem() { - return app('arcanedev.log-viewer.filesystem'); + return $this->app->make(\Arcanedev\LogViewer\Contracts\Utilities\Filesystem::class); } /** @@ -355,7 +354,7 @@ protected function filesystem() */ protected function trans() { - return $this->app['translator']; + return $this->app->make('translator'); } /** @@ -365,7 +364,7 @@ protected function trans() */ protected function config() { - return $this->app['config']; + return $this->app->make('config'); } /** @@ -468,7 +467,7 @@ protected function createDummyLog($date) */ private function getTranslatedLevel($locale, $key) { - return array_get($this->getTranslatedLevels(), "$locale.$key"); + return Arr::get($this->getTranslatedLevels(), "$locale.$key"); } /** @@ -478,10 +477,8 @@ private function getTranslatedLevel($locale, $key) */ protected function getTranslatedLevels() { - $translator = $this->app['translator']; - - return array_map(function ($locale) use ($translator) { - return $translator->get('log-viewer::levels', [], $locale); + return array_map(function ($locale) { + return $this->trans()->get('log-viewer::levels', [], $locale); }, array_combine(self::$locales, self::$locales)); } diff --git a/tests/Utilities/FactoryTest.php b/tests/Utilities/FactoryTest.php index 86c9fe1c..0ef7a88f 100644 --- a/tests/Utilities/FactoryTest.php +++ b/tests/Utilities/FactoryTest.php @@ -26,7 +26,7 @@ public function setUp() { parent::setUp(); - $this->logFactory = $this->app['arcanedev.log-viewer.factory']; + $this->logFactory = $this->app->make(\Arcanedev\LogViewer\Contracts\Utilities\Factory::class); } public function tearDown() diff --git a/tests/Utilities/LogCheckerTest.php b/tests/Utilities/LogCheckerTest.php index 06ef2263..e2185cbc 100644 --- a/tests/Utilities/LogCheckerTest.php +++ b/tests/Utilities/LogCheckerTest.php @@ -26,7 +26,7 @@ public function setUp() { parent::setUp(); - $this->checker = app('arcanedev.log-viewer.checker'); + $this->checker = $this->app->make(\Arcanedev\LogViewer\Contracts\Utilities\LogChecker::class); } public function tearDown() diff --git a/tests/Utilities/LogLevelsTest.php b/tests/Utilities/LogLevelsTest.php index abd69400..71b55a85 100644 --- a/tests/Utilities/LogLevelsTest.php +++ b/tests/Utilities/LogLevelsTest.php @@ -26,7 +26,7 @@ public function setUp() { parent::setUp(); - $this->levels = $this->app['arcanedev.log-viewer.levels']; + $this->levels = $this->app->make(\Arcanedev\LogViewer\Contracts\Utilities\LogLevels::class); } public function tearDown() diff --git a/tests/Utilities/LogMenuTest.php b/tests/Utilities/LogMenuTest.php index 8bf2ccea..40048d6c 100644 --- a/tests/Utilities/LogMenuTest.php +++ b/tests/Utilities/LogMenuTest.php @@ -26,7 +26,7 @@ public function setUp() { parent::setUp(); - $this->menu = $this->app['arcanedev.log-viewer.menu']; + $this->menu = $this->app->make(\Arcanedev\LogViewer\Contracts\Utilities\LogMenu::class); } public function tearDown() diff --git a/tests/Utilities/LogStylerTest.php b/tests/Utilities/LogStylerTest.php index 6466388e..5d239d75 100644 --- a/tests/Utilities/LogStylerTest.php +++ b/tests/Utilities/LogStylerTest.php @@ -25,7 +25,7 @@ public function setUp() { parent::setUp(); - $this->styler = $this->app['arcanedev.log-viewer.styler']; + $this->styler = $this->app->make(\Arcanedev\LogViewer\Contracts\Utilities\LogStyler::class); } public function tearDown()