From 5c422b9391699346d6fdda33f564a7c2729924ed Mon Sep 17 00:00:00 2001 From: Mohammad Alavi Date: Wed, 14 Apr 2021 19:56:43 +0430 Subject: [PATCH] Adopt to new apiato core changes --- Actions/GetAllLocalizationsAction.php | 3 +-- ...container.php => vendorSection-localization.php} | 0 Middlewares/LocalizationMiddleware.php | 5 ++--- Tasks/GetAllLocalizationsTask.php | 3 +-- Tests/Unit/GetLocalizationsTest.php | 13 +++++-------- UI/API/Controllers/Controller.php | 3 +-- .../Functional/CheckLocalizationMiddlewareTest.php | 3 +-- Values/Localization.php | 3 +-- Values/Region.php | 3 +-- 9 files changed, 13 insertions(+), 23 deletions(-) rename Configs/{localization-container.php => vendorSection-localization.php} (100%) diff --git a/Actions/GetAllLocalizationsAction.php b/Actions/GetAllLocalizationsAction.php index c05d95d..635b436 100644 --- a/Actions/GetAllLocalizationsAction.php +++ b/Actions/GetAllLocalizationsAction.php @@ -2,7 +2,6 @@ namespace App\Containers\VendorSection\Localization\Actions; -use Apiato\Core\Foundation\Facades\Apiato; use App\Containers\VendorSection\Localization\Tasks\GetAllLocalizationsTask; use App\Ship\Parents\Actions\Action; use Illuminate\Support\Collection; @@ -11,6 +10,6 @@ class GetAllLocalizationsAction extends Action { public function run(): Collection { - return Apiato::call(GetAllLocalizationsTask::class); + return app(GetAllLocalizationsTask::class)->run(); } } diff --git a/Configs/localization-container.php b/Configs/vendorSection-localization.php similarity index 100% rename from Configs/localization-container.php rename to Configs/vendorSection-localization.php diff --git a/Middlewares/LocalizationMiddleware.php b/Middlewares/LocalizationMiddleware.php index e440dc2..65a76db 100644 --- a/Middlewares/LocalizationMiddleware.php +++ b/Middlewares/LocalizationMiddleware.php @@ -8,7 +8,6 @@ use Closure; use Illuminate\Http\Request; use Illuminate\Support\Facades\App; -use Illuminate\Support\Facades\Config; use Illuminate\Support\Str; class LocalizationMiddleware extends Middleware @@ -82,7 +81,7 @@ private function getSupportedLanguages(): array { $supported_locales = []; - $locales = Config::get('localization-container.supported_languages'); + $locales = config('vendorSection-localization.supported_languages'); foreach ($locales as $key => $value) { // it is a "simple" language code (e.g., "en")! @@ -108,7 +107,7 @@ private function findLanguage($request) * read the accept-language from the request * if the header is missing, use the default local language */ - $language = Config::get('app.locale'); + $language = config('app.locale'); if ($request->hasHeader('Accept-Language')) { $language = $request->header('Accept-Language'); diff --git a/Tasks/GetAllLocalizationsTask.php b/Tasks/GetAllLocalizationsTask.php index 787ee7f..06ccfb4 100644 --- a/Tasks/GetAllLocalizationsTask.php +++ b/Tasks/GetAllLocalizationsTask.php @@ -5,13 +5,12 @@ use App\Containers\VendorSection\Localization\Values\Localization; use App\Ship\Parents\Tasks\Task; use Illuminate\Support\Collection; -use Illuminate\Support\Facades\Config; class GetAllLocalizationsTask extends Task { public function run(): Collection { - $supported_localizations = Config::get('localization-container.supported_languages'); + $supported_localizations = config('vendorSection-localization.supported_languages'); $localizations = new Collection(); diff --git a/Tests/Unit/GetLocalizationsTest.php b/Tests/Unit/GetLocalizationsTest.php index 37a1710..c980c9f 100644 --- a/Tests/Unit/GetLocalizationsTest.php +++ b/Tests/Unit/GetLocalizationsTest.php @@ -5,8 +5,6 @@ use App\Containers\VendorSection\Localization\Tasks\GetAllLocalizationsTask; use App\Containers\VendorSection\Localization\Tests\TestCase; use App\Containers\VendorSection\Localization\Values\Localization; -use Illuminate\Support\Facades\App; -use Illuminate\Support\Facades\Config; /** * Class GetLocalizationsTest. @@ -18,17 +16,16 @@ class GetLocalizationsTest extends TestCase { public function testIfAllSupportedLanguagesAreReturned(): void { - $class = App::make(GetAllLocalizationsTask::class); - $localizations = $class->run(); + $localizations = app(GetAllLocalizationsTask::class)->run(); - $configuredLocalizations = Config::get('localization-container.supported_languages', []); + $configuredLocalizations = config('vendorSection-localization.supported_languages', []); self::assertEquals(count($configuredLocalizations), $localizations->count()); } public function testIfSpecificLocaleIsReturned(): void { - $localizations = App::make(GetAllLocalizationsTask::class)->run(); + $localizations = app(GetAllLocalizationsTask::class)->run(); $unsupportedLocale = new Localization('fr'); self::assertContainsEquals($unsupportedLocale, $localizations); @@ -36,7 +33,7 @@ public function testIfSpecificLocaleIsReturned(): void public function testIfSpecificLocaleWithRegionsIsReturned(): void { - $localizations = App::make(GetAllLocalizationsTask::class)->run(); + $localizations = app(GetAllLocalizationsTask::class)->run(); $unsupportedLocale = new Localization('en', ['en-GB', 'en-US']); self::assertContainsEquals($unsupportedLocale, $localizations); @@ -44,7 +41,7 @@ public function testIfSpecificLocaleWithRegionsIsReturned(): void public function testIfWrongLocaleIsNotReturned(): void { - $localizations = App::make(GetAllLocalizationsTask::class)->run(); + $localizations = app(GetAllLocalizationsTask::class)->run(); $unsupportedLocale = new Localization('xxx'); self::assertNotContainsEquals($unsupportedLocale, $localizations); diff --git a/UI/API/Controllers/Controller.php b/UI/API/Controllers/Controller.php index 0ac24ee..7f3d956 100644 --- a/UI/API/Controllers/Controller.php +++ b/UI/API/Controllers/Controller.php @@ -2,7 +2,6 @@ namespace App\Containers\VendorSection\Localization\UI\API\Controllers; -use Apiato\Core\Foundation\Facades\Apiato; use App\Containers\VendorSection\Localization\Actions\GetAllLocalizationsAction; use App\Containers\VendorSection\Localization\UI\API\Requests\GetAllLocalizationsRequest; use App\Containers\VendorSection\Localization\UI\API\Transformers\LocalizationTransformer; @@ -12,7 +11,7 @@ class Controller extends ApiController { public function getAllLocalizations(GetAllLocalizationsRequest $request): array { - $localizations = Apiato::call(GetAllLocalizationsAction::class); + $localizations = app(GetAllLocalizationsAction::class)->run(); return $this->transform($localizations, LocalizationTransformer::class); } } diff --git a/UI/API/Tests/Functional/CheckLocalizationMiddlewareTest.php b/UI/API/Tests/Functional/CheckLocalizationMiddlewareTest.php index 4fc12e7..0ba60e3 100644 --- a/UI/API/Tests/Functional/CheckLocalizationMiddlewareTest.php +++ b/UI/API/Tests/Functional/CheckLocalizationMiddlewareTest.php @@ -3,7 +3,6 @@ namespace App\Containers\VendorSection\Localization\UI\API\Tests\Functional; use App\Containers\VendorSection\Localization\Tests\ApiTestCase; -use Illuminate\Support\Facades\Config; /** * Class CheckLocalizationMiddlewareTest. @@ -24,7 +23,7 @@ public function testIfMiddlewareSetsDefaultAppLanguage(): void { $data = []; $requestHeaders = []; - $defaultLanguage = Config::get('app.locale'); + $defaultLanguage = config('app.locale'); $response = $this->makeCall($data, $requestHeaders); diff --git a/Values/Localization.php b/Values/Localization.php index 2c9a9b3..4423a91 100644 --- a/Values/Localization.php +++ b/Values/Localization.php @@ -3,7 +3,6 @@ namespace App\Containers\VendorSection\Localization\Values; use App\Ship\Parents\Values\Value; -use Illuminate\Support\Facades\Config; use Locale; class Localization extends Value @@ -26,7 +25,7 @@ public function __construct($language, array $regions = []) public function getDefaultName(): string { - return Locale::getDisplayLanguage($this->language, Config::get('app.locale')); + return Locale::getDisplayLanguage($this->language, config('app.locale')); } public function getLocaleName(): string diff --git a/Values/Region.php b/Values/Region.php index 9eabbc6..882671e 100644 --- a/Values/Region.php +++ b/Values/Region.php @@ -3,7 +3,6 @@ namespace App\Containers\VendorSection\Localization\Values; use App\Ship\Parents\Values\Value; -use Illuminate\Support\Facades\Config; use Locale; class Region extends Value @@ -21,7 +20,7 @@ public function __construct($region) public function getDefaultName(): string { - return Locale::getDisplayRegion($this->region, Config::get('app.locale')); + return Locale::getDisplayRegion($this->region, config('app.locale')); } public function getLocaleName(): string