From 44d37d4138e4240a275c31fe9bbbeb32218ef928 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 4 Sep 2017 14:51:46 +0100 Subject: [PATCH] Updating the package for Laravel 5.5 --- .scrutinizer.yml | 2 +- .travis.yml | 3 +-- README.md | 2 +- _docs/0-Home.md | 2 +- _docs/1-Installation-and-Setup.md | 7 ++++++- composer.json | 27 +++++++++++++++------------ src/Entities/Locale.php | 2 +- src/Entities/LocaleCollection.php | 11 ++++++----- src/Events/TranslationHasBeenSet.php | 14 +++++++------- src/Middleware/Middleware.php | 14 ++++++-------- src/Traits/HasTranslations.php | 4 ++-- tests/TranslatableModelTest.php | 2 ++ 12 files changed, 49 insertions(+), 41 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 748304d..ba44fae 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -22,7 +22,7 @@ checks: tools: external_code_coverage: timeout: 1200 - runs: 3 + runs: 2 php_code_sniffer: enabled: true config: diff --git a/.travis.yml b/.travis.yml index daadc6a..254ab22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,6 @@ language: php sudo: false php: - - 5.6 - 7.0 - 7.1 - nightly @@ -13,7 +12,7 @@ matrix: - php: nightly env: - - TESTBENCH_VERSION=3.4.* + - TESTBENCH_VERSION=3.5.* before_script: - travis_retry composer self-update diff --git a/README.md b/README.md index 286ab12..37b1e2a 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Feel free to check out the [releases](https://github.com/ARCANEDEV/Localization/ ### Features * Easy setup & configuration. - * Laravel `5.0 | 5.1 | 5.2 | 5.3 | 5.4` are supported. + * Laravel `5.0 | 5.1 | 5.2 | 5.3 | 5.4 | 5.5` are supported. * SEO-Friendly (Search engine optimization). * New extended Router to manage your localized routes. * Translated Eloquent Models. diff --git a/_docs/0-Home.md b/_docs/0-Home.md index 5681238..5f36715 100644 --- a/_docs/0-Home.md +++ b/_docs/0-Home.md @@ -7,7 +7,7 @@ Feel free to check out the [Releases](https://github.com/ARCANEDEV/Localization/ ### Features * Easy setup & configuration. - * Laravel `5.0 | 5.1 | 5.2 | 5.3 | 5.4` are supported. + * Laravel `5.0 | 5.1 | 5.2 | 5.3 | 5.4 | 5.5` are supported. * SEO-Friendly (Search engine optimization). * New extended Router to manage your localized routes. * Locales selector menu (Publishable & Customizable). diff --git a/_docs/1-Installation-and-Setup.md b/_docs/1-Installation-and-Setup.md index 9183a8c..1a7b103 100644 --- a/_docs/1-Installation-and-Setup.md +++ b/_docs/1-Installation-and-Setup.md @@ -11,7 +11,7 @@ The Localization package has a few system requirements: - - PHP >= 5.6 + - PHP >= 7.0 ##### Optional @@ -25,15 +25,18 @@ PHP extensions: |:---------------------------------------|:--------------------------------------------------------------------------------------------------------------------| | ![Localization v0.x][localization_0_x] | ![Laravel v5.0][laravel_5_0] ![Laravel v5.1][laravel_5_1] ![Laravel v5.2][laravel_5_2] ![Laravel v5.3][laravel_5_3] | | ![Localization v1.x][localization_1_x] | ![Laravel v5.4][laravel_5_4] | +| ![Localization v2.x][localization_2_x] | ![Laravel v5.5][laravel_5_5] | [laravel_5_0]: https://img.shields.io/badge/v5.0-supported-brightgreen.svg?style=flat-square "Laravel v5.0" [laravel_5_1]: https://img.shields.io/badge/v5.1-supported-brightgreen.svg?style=flat-square "Laravel v5.1" [laravel_5_2]: https://img.shields.io/badge/v5.2-supported-brightgreen.svg?style=flat-square "Laravel v5.2" [laravel_5_3]: https://img.shields.io/badge/v5.3-supported-brightgreen.svg?style=flat-square "Laravel v5.3" [laravel_5_4]: https://img.shields.io/badge/v5.4-supported-brightgreen.svg?style=flat-square "Laravel v5.4" +[laravel_5_5]: https://img.shields.io/badge/v5.5-supported-brightgreen.svg?style=flat-square "Laravel v5.5" [localization_0_x]: https://img.shields.io/badge/version-0.*-blue.svg?style=flat-square "Localization v0.*" [localization_1_x]: https://img.shields.io/badge/version-1.*-blue.svg?style=flat-square "Localization v1.*" +[localization_2_x]: https://img.shields.io/badge/version-2.*-blue.svg?style=flat-square "Localization v2.*" ## Composer @@ -47,6 +50,8 @@ composer require arcanedev/localization ### Setup +> **NOTE :** The package will automatically register itself if you're using Laravel `>= v5.5`, so you can skip this section. + Once the package is installed, you can register the service provider in `config/app.php` in the `providers` array: ```php diff --git a/composer.json b/composer.json index 88b9686..fb3217f 100644 --- a/composer.json +++ b/composer.json @@ -14,12 +14,12 @@ "type": "library", "license": "MIT", "require": { - "php": ">=5.6.4", + "php": ">=7.0", "arcanedev/support": "~4.1" }, "require-dev": { - "phpunit/phpcov": "~3.0", - "phpunit/phpunit": "~5.0", + "phpunit/phpcov": "~4.0", + "phpunit/phpunit": "~6.0", "mockery/mockery": "^0.9.4" }, "autoload": { @@ -33,17 +33,20 @@ "Arcanedev\\Localization\\Tests\\": "tests/" } }, + "extra": { + "laravel": { + "providers": [ + "Arcanedev\\Localization\\LocalizationServiceProvider" + ], + "aliases": { + "Localization": "Arcanedev\\Localization\\Facades\\Localization" + } + } + }, "scripts": { - "testbench": "composer require --dev \"orchestra/testbench-browser-kit=~3.4\" \"orchestra/database=~3.4\"" + "testbench": "composer require --dev \"orchestra/testbench-browser-kit=~3.5\" \"orchestra/database=~3.5\"" }, "suggest": { "ext-intl": "Use Intl extension for 'Locale' class (an identifier used to get language)." - }, - "extra": { - "branch-alias": { - "dev-master": "1.0.x-dev" - } - }, - "minimum-stability": "dev", - "prefer-stable" : true + } } diff --git a/src/Entities/Locale.php b/src/Entities/Locale.php index 44247fd..3a159ee 100644 --- a/src/Entities/Locale.php +++ b/src/Entities/Locale.php @@ -84,7 +84,7 @@ public function __construct($key, array $data) $this->setScript($data['script']); $this->setDirection($data['dir']); $this->setNative($data['native']); - $this->setRegional(isset($data['regional']) ? $data['regional'] : ''); + $this->setRegional($data['regional'] ?? ''); } /* ----------------------------------------------------------------- diff --git a/src/Entities/LocaleCollection.php b/src/Entities/LocaleCollection.php index 332be0f..fb4782e 100644 --- a/src/Entities/LocaleCollection.php +++ b/src/Entities/LocaleCollection.php @@ -78,11 +78,12 @@ public function getSupported() */ public function loadFromConfig() { - $locales = config('localization.locales', []); - $supported = config('localization.supported-locales', []); - - $this->loadFromArray($locales); - $this->setSupportedKeys($supported); + $this->loadFromArray( + config('localization.locales', []) + ); + $this->setSupportedKeys( + config('localization.supported-locales', []) + ); return $this; } diff --git a/src/Events/TranslationHasBeenSet.php b/src/Events/TranslationHasBeenSet.php index 9716e3f..e669366 100644 --- a/src/Events/TranslationHasBeenSet.php +++ b/src/Events/TranslationHasBeenSet.php @@ -15,7 +15,7 @@ class TranslationHasBeenSet | ----------------------------------------------------------------- */ - /** @var \Illuminate\Database\Eloquent\Model */ + /** @var mixed */ public $model; /** @var string */ @@ -38,13 +38,13 @@ class TranslationHasBeenSet /** * TranslationHasBeenSet constructor. * - * @param \Illuminate\Database\Eloquent\Model $model - * @param string $attribute - * @param string $locale - * @param mixed $oldValue - * @param mixed $newValue + * @param mixed $model + * @param string $attribute + * @param string $locale + * @param mixed $oldValue + * @param mixed $newValue */ - public function __construct(Model $model, $attribute, $locale, $oldValue, $newValue) + public function __construct($model, $attribute, $locale, $oldValue, $newValue) { $this->model = $model; $this->attribute = $attribute; diff --git a/src/Middleware/Middleware.php b/src/Middleware/Middleware.php index d9d2c28..2ce9b69 100644 --- a/src/Middleware/Middleware.php +++ b/src/Middleware/Middleware.php @@ -3,8 +3,8 @@ use Arcanedev\Localization\Contracts\Localization; use Arcanedev\Localization\Entities\LocaleCollection; use Arcanedev\Localization\Exceptions\UndefinedSupportedLocalesException; -use Arcanedev\Support\Bases\Middleware as BaseMiddleware; use Illuminate\Http\RedirectResponse; +use Illuminate\Http\Request; /** * Class Middleware @@ -12,7 +12,7 @@ * @package Arcanedev\Localization\Bases * @author ARCANEDEV */ -abstract class Middleware extends BaseMiddleware +abstract class Middleware { /* ----------------------------------------------------------------- | Properties @@ -119,7 +119,7 @@ protected function isDefaultLocaleHidden($locale) * * @return bool */ - protected function shouldIgnore($request) + protected function shouldIgnore(Request $request) { foreach ($this->except as $except) { if ($except !== '/') @@ -146,11 +146,9 @@ protected function shouldIgnore($request) */ protected function getLocalizedRedirect($locale) { - $localizedUrl = $this->localization->getLocalizedURL($locale); - - if ( ! is_string($localizedUrl)) return null; - - return $this->makeRedirectResponse($localizedUrl); + return is_string($localizedUrl = $this->localization->getLocalizedURL($locale)) + ? $this->makeRedirectResponse($localizedUrl) + : null; } /** diff --git a/src/Traits/HasTranslations.php b/src/Traits/HasTranslations.php index 0f3cb6e..95185d9 100644 --- a/src/Traits/HasTranslations.php +++ b/src/Traits/HasTranslations.php @@ -64,7 +64,7 @@ public function getTranslation($key, $locale, $useFallback = true) { $locale = $this->normalizeLocale($key, $locale, $useFallback); $translations = $this->getTranslations($key); - $translation = isset($translations[$locale]) ? $translations[$locale] : ''; + $translation = $translations[$locale] ?? ''; return $this->hasGetMutator($key) ? $this->mutateAttribute($key, $translation) @@ -99,7 +99,7 @@ public function setTranslation($key, $locale, $value) $this->guardAgainstUntranslatableAttribute($key); $translations = $this->getTranslations($key); - $oldValue = isset($translations[$locale]) ? $translations[$locale] : ''; + $oldValue = $translations[$locale] ?? ''; if ($this->hasSetMutator($key)) $value = $this->{'set'.Str::studly($key).'Attribute'}($value); diff --git a/tests/TranslatableModelTest.php b/tests/TranslatableModelTest.php index 1521788..216c79c 100644 --- a/tests/TranslatableModelTest.php +++ b/tests/TranslatableModelTest.php @@ -253,6 +253,8 @@ public function it_will_fire_an_event_when_a_translation_has_been_set() $this->expectsEvents([TranslationHasBeenSet::class]); $this->model->setTranslation('name', 'en', 'Name'); + + $this->assertSame(['en' => 'Name'], $this->model->getTranslations('name')); } /* -----------------------------------------------------------------