Skip to content

Commit

Permalink
Merge pull request #299 from ARCANEDEV/patch-deferred_provider
Browse files Browse the repository at this point in the history
Defer properly the services + cleaning
  • Loading branch information
arcanedev-maroc authored Oct 3, 2019
2 parents d420908 + 3f95117 commit 84baf1f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 26 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
"extra": {
"laravel": {
"providers": [
"Arcanedev\\LogViewer\\LogViewerServiceProvider"
"Arcanedev\\LogViewer\\LogViewerServiceProvider",
"Arcanedev\\LogViewer\\Providers\\ServicesProvider"
]
}
}
Expand Down
5 changes: 1 addition & 4 deletions src/LogViewerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ public function register(): void

$this->registerConfig();

$this->registerProviders([
Providers\ServicesProvider::class,
Providers\RouteServiceProvider::class,
]);
$this->registerProvider(Providers\RouteServiceProvider::class);

$this->registerCommands([
Commands\PublishCommand::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
use Arcanedev\LogViewer\{Contracts, LogViewer, Utilities};
use Arcanedev\Support\Providers\ServiceProvider;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\Arr;

/**
* Class ServicesProvider
* Class DeferredServicesProvider
*
* @package Arcanedev\LogViewer\Providers
* @author ARCANEDEV <[email protected]>
*/
class ServicesProvider extends ServiceProvider implements DeferrableProvider
class DeferredServicesProvider extends ServiceProvider implements DeferrableProvider
{
/* -----------------------------------------------------------------
| Main Methods
Expand Down Expand Up @@ -69,14 +68,10 @@ private function registerLogViewer(): void
private function registerLogLevels(): void
{
$this->singleton(Contracts\Utilities\LogLevels::class, function ($app) {
/**
* @var \Illuminate\Config\Repository $config
* @var \Illuminate\Translation\Translator $translator
*/
$config = $app['config'];
$translator = $app['translator'];

return new Utilities\LogLevels($translator, $config->get('log-viewer.locale'));
return new Utilities\LogLevels(
$app['translator'],
$app['config']->get('log-viewer.locale')
);
});
}

Expand Down Expand Up @@ -104,13 +99,12 @@ private function registerFilesystem(): void
$this->singleton(Contracts\Utilities\Filesystem::class, function ($app) {
/** @var \Illuminate\Config\Repository $config */
$config = $app['config'];
$pattern = $config->get('log-viewer.pattern', []);
$filesystem = new Utilities\Filesystem($app['files'], $config->get('log-viewer.storage-path'));

return $filesystem->setPattern(
Arr::get($pattern, 'prefix', Utilities\Filesystem::PATTERN_PREFIX),
Arr::get($pattern, 'date', Utilities\Filesystem::PATTERN_DATE),
Arr::get($pattern, 'extension', Utilities\Filesystem::PATTERN_EXTENSION)
$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)
);
});
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
<?php namespace Arcanedev\LogViewer\Tests\Providers;

use Arcanedev\LogViewer\Contracts;
use Arcanedev\LogViewer\Providers\ServicesProvider;
use Arcanedev\LogViewer\Providers\DeferredServicesProvider;
use Arcanedev\LogViewer\Tests\TestCase;

/**
* Class UtilitiesServiceProviderTest
* Class DeferredServicesProviderTest
*
* @package Arcanedev\LogViewer\Tests\Providers
* @author ARCANEDEV <[email protected]>
*/
class UtilitiesServiceProviderTest extends TestCase
class DeferredServicesProviderTest extends TestCase
{
/* -----------------------------------------------------------------
| Properties
| -----------------------------------------------------------------
*/

/** @var \Arcanedev\LogViewer\Providers\ServicesProvider */
/** @var \Arcanedev\LogViewer\Providers\DeferredServicesProvider */
private $provider;

/* -----------------------------------------------------------------
Expand All @@ -29,7 +29,7 @@ protected function setUp(): void
{
parent::setUp();

$this->provider = $this->app->getProvider(ServicesProvider::class);
$this->provider = $this->app->getProvider(DeferredServicesProvider::class);
}

protected function tearDown(): void
Expand All @@ -52,7 +52,7 @@ public function it_can_be_instantiated()
\Illuminate\Support\ServiceProvider::class,
\Illuminate\Contracts\Support\DeferrableProvider::class,
\Arcanedev\Support\Providers\ServiceProvider::class,
ServicesProvider::class,
DeferredServicesProvider::class,
];

foreach ($expectations as $expected) {
Expand Down
1 change: 1 addition & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ protected function getPackageProviders($app)
{
return [
\Arcanedev\LogViewer\LogViewerServiceProvider::class,
\Arcanedev\LogViewer\Providers\DeferredServicesProvider::class,
];
}

Expand Down

0 comments on commit 84baf1f

Please sign in to comment.