Skip to content

Commit

Permalink
Merge pull request #105 from ARCANEDEV/laravel-5.5
Browse files Browse the repository at this point in the history
Updating the package for Laravel 5.5
  • Loading branch information
arcanedev-maroc authored Sep 4, 2017
2 parents b479127 + 44d37d4 commit 4eb3ae7
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ checks:
tools:
external_code_coverage:
timeout: 1200
runs: 3
runs: 2
php_code_sniffer:
enabled: true
config:
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ language: php
sudo: false

php:
- 5.6
- 7.0
- 7.1
- nightly
Expand All @@ -13,7 +12,7 @@ matrix:
- php: nightly

env:
- TESTBENCH_VERSION=3.4.*
- TESTBENCH_VERSION=3.5.*

before_script:
- travis_retry composer self-update
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion _docs/0-Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
7 changes: 6 additions & 1 deletion _docs/1-Installation-and-Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

The Localization package has a few system requirements:

- PHP >= 5.6
- PHP >= 7.0

##### Optional

Expand All @@ -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

Expand All @@ -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
Expand Down
27 changes: 15 additions & 12 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -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
}
}
2 changes: 1 addition & 1 deletion src/Entities/Locale.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? '');
}

/* -----------------------------------------------------------------
Expand Down
11 changes: 6 additions & 5 deletions src/Entities/LocaleCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
14 changes: 7 additions & 7 deletions src/Events/TranslationHasBeenSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TranslationHasBeenSet
| -----------------------------------------------------------------
*/

/** @var \Illuminate\Database\Eloquent\Model */
/** @var mixed */
public $model;

/** @var string */
Expand All @@ -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;
Expand Down
14 changes: 6 additions & 8 deletions src/Middleware/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
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
*
* @package Arcanedev\Localization\Bases
* @author ARCANEDEV <arcanedev.maroc@gmail.com>
*/
abstract class Middleware extends BaseMiddleware
abstract class Middleware
{
/* -----------------------------------------------------------------
| Properties
Expand Down Expand Up @@ -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 !== '/')
Expand All @@ -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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/HasTranslations.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions tests/TranslatableModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/* -----------------------------------------------------------------
Expand Down

0 comments on commit 4eb3ae7

Please sign in to comment.