Skip to content

Commit

Permalink
Adopt to new apiato core changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Apr 14, 2021
1 parent 2fc6711 commit 5c422b9
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 23 deletions.
3 changes: 1 addition & 2 deletions Actions/GetAllLocalizationsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,6 +10,6 @@ class GetAllLocalizationsAction extends Action
{
public function run(): Collection
{
return Apiato::call(GetAllLocalizationsTask::class);
return app(GetAllLocalizationsTask::class)->run();
}
}
File renamed without changes.
5 changes: 2 additions & 3 deletions Middlewares/LocalizationMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")!
Expand All @@ -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');
Expand Down
3 changes: 1 addition & 2 deletions Tasks/GetAllLocalizationsTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
13 changes: 5 additions & 8 deletions Tests/Unit/GetLocalizationsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -18,33 +16,32 @@ 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);
}

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);
}

public function testIfWrongLocaleIsNotReturned(): void
{
$localizations = App::make(GetAllLocalizationsTask::class)->run();
$localizations = app(GetAllLocalizationsTask::class)->run();

$unsupportedLocale = new Localization('xxx');
self::assertNotContainsEquals($unsupportedLocale, $localizations);
Expand Down
3 changes: 1 addition & 2 deletions UI/API/Controllers/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
3 changes: 1 addition & 2 deletions UI/API/Tests/Functional/CheckLocalizationMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -24,7 +23,7 @@ public function testIfMiddlewareSetsDefaultAppLanguage(): void
{
$data = [];
$requestHeaders = [];
$defaultLanguage = Config::get('app.locale');
$defaultLanguage = config('app.locale');

$response = $this->makeCall($data, $requestHeaders);

Expand Down
3 changes: 1 addition & 2 deletions Values/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions Values/Region.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 5c422b9

Please sign in to comment.