Skip to content

Commit

Permalink
Merge pull request #152 from ARCANEDEV/update-laravel_7.x_support
Browse files Browse the repository at this point in the history
Updating the package to support Laravel 7
  • Loading branch information
arcanedev-maroc authored Mar 5, 2020
2 parents d2c7dfe + 0cac4af commit 8d3b1ed
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 91 deletions.
10 changes: 5 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

root = true

[*]
end_of_line = lf
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2
7 changes: 3 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: run-tests

on: [push]
on: [push, pull_request]

jobs:
tests:
Expand All @@ -10,7 +10,6 @@ jobs:
fail-fast: true
matrix:
php: [7.2, 7.3, 7.4]
laravel: [6.*]
dependency-version: [prefer-lowest, prefer-stable]

name: PHP ${{ matrix.php }} - ${{ matrix.dependency-version }}
Expand All @@ -23,10 +22,10 @@ jobs:
uses: actions/cache@v1
with:
path: ~/.composer/cache/files
key: dependencies-laravel-${{ matrix.laravel }}-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}
key: dependencies-laravel-7.x-php-${{ matrix.php }}-composer-${{ hashFiles('composer.json') }}

- name: Setup PHP
uses: shivammathur/setup-php@v1
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: curl, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, iconv, intl
Expand Down
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2019 | ARCANEDEV <[email protected]> - Localization
Copyright (c) 2015-2020 | ARCANEDEV <[email protected]> - Localization

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
4 changes: 2 additions & 2 deletions 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.x | 6.x` are supported.
* Laravel `5.x | 6.x | 7.x` are supported.
* SEO-Friendly (Search engine optimization).
* New extended Router to manage your localized routes.
* Translated Eloquent Models.
Expand Down Expand Up @@ -52,7 +52,7 @@ If you discover any security related issues, please email arcanedev.maroc@gmail.
- [All Contributors][link-contributors]

[badge_license]: http://img.shields.io/packagist/l/arcanedev/localization.svg?style=flat-square
[badge_laravel]: https://img.shields.io/badge/Laravel-5.x%20|%206.x-orange.svg?style=flat-square
[badge_laravel]: https://img.shields.io/badge/Laravel-5.x|6.x|7.x-orange.svg?style=flat-square
[badge_build]: https://img.shields.io/github/workflow/status/ARCANEDEV/Localization/run-tests?style=flat-square
[badge_coverage]: https://img.shields.io/scrutinizer/coverage/g/ARCANEDEV/Localization.svg?style=flat-square
[badge_quality]: https://img.shields.io/scrutinizer/g/ARCANEDEV/Localization.svg?style=flat-square
Expand Down
61 changes: 28 additions & 33 deletions _docs/1-Installation-and-Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,40 @@
2. [Configuration](2-Configuration.md)
3. [Usage](3-Usage.md)
4. [FAQ](4-FAQ.md)

## Server Requirements

The Localization package has a few system requirements:

- PHP >= 7.0

##### Optional

PHP extensions:

* **ext_intl :** Needed to use the `Locale` class. (http://php.net/manual/en/class.locale.php)

## Version Compatibility

| Localization | Laravel |
|:---------------------------------------|:--------------------------------------------------------------------------------------------------------------------|
| ![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] |
| ![Localization v3.x][localization_3_x] | ![Laravel v5.6][laravel_5_6] |
| ![Localization v4.x][localization_4_x] | ![Laravel v5.7][laravel_5_7] |
| ![Localization v7.x][localization_7_x] | ![Laravel v7.*][laravel_7_x] |
| ![Localization v6.x][localization_6_x] | ![Laravel v6.*][laravel_6_x] |
| ![Localization v5.x][localization_5_x] | ![Laravel v5.8][laravel_5_8] |
| ![Localization v6.x][localization_6_x] | ![Laravel v6.0][laravel_6_0] |
| ![Localization v4.x][localization_4_x] | ![Laravel v5.7][laravel_5_7] |
| ![Localization v3.x][localization_3_x] | ![Laravel v5.6][laravel_5_6] |
| ![Localization v2.x][localization_2_x] | ![Laravel v5.5][laravel_5_5] |
| ![Localization v1.x][localization_1_x] | ![Laravel v5.4][laravel_5_4] |
| ![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] |

[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"
[laravel_5_6]: https://img.shields.io/badge/v5.6-supported-brightgreen.svg?style=flat-square "Laravel v5.6"
[laravel_5_7]: https://img.shields.io/badge/v5.7-supported-brightgreen.svg?style=flat-square "Laravel v5.7"
[laravel_7_x]: https://img.shields.io/badge/v7.x-supported-brightgreen.svg?style=flat-square "Laravel v7.*"
[laravel_6_x]: https://img.shields.io/badge/v6.x-supported-brightgreen.svg?style=flat-square "Laravel v6.*"
[laravel_5_8]: https://img.shields.io/badge/v5.8-supported-brightgreen.svg?style=flat-square "Laravel v5.8"
[laravel_6_0]: https://img.shields.io/badge/v6.0-supported-brightgreen.svg?style=flat-square "Laravel v6.0"
[laravel_5_7]: https://img.shields.io/badge/v5.7-supported-brightgreen.svg?style=flat-square "Laravel v5.7"
[laravel_5_6]: https://img.shields.io/badge/v5.6-supported-brightgreen.svg?style=flat-square "Laravel v5.6"
[laravel_5_5]: https://img.shields.io/badge/v5.5-supported-brightgreen.svg?style=flat-square "Laravel v5.5"
[laravel_5_4]: https://img.shields.io/badge/v5.4-supported-brightgreen.svg?style=flat-square "Laravel v5.4"
[laravel_5_3]: https://img.shields.io/badge/v5.3-supported-brightgreen.svg?style=flat-square "Laravel v5.3"
[laravel_5_2]: https://img.shields.io/badge/v5.2-supported-brightgreen.svg?style=flat-square "Laravel v5.2"
[laravel_5_1]: https://img.shields.io/badge/v5.1-supported-brightgreen.svg?style=flat-square "Laravel v5.1"
[laravel_5_0]: https://img.shields.io/badge/v5.0-supported-brightgreen.svg?style=flat-square "Laravel v5.0"

[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.*"
[localization_3_x]: https://img.shields.io/badge/version-3.*-blue.svg?style=flat-square "Localization v3.*"
[localization_4_x]: https://img.shields.io/badge/version-4.*-blue.svg?style=flat-square "Localization v4.*"
[localization_5_x]: https://img.shields.io/badge/version-5.*-blue.svg?style=flat-square "Localization v5.*"
[localization_7_x]: https://img.shields.io/badge/version-7.*-blue.svg?style=flat-square "Localization v7.*"
[localization_6_x]: https://img.shields.io/badge/version-6.*-blue.svg?style=flat-square "Localization v6.*"
[localization_5_x]: https://img.shields.io/badge/version-5.*-blue.svg?style=flat-square "Localization v5.*"
[localization_4_x]: https://img.shields.io/badge/version-4.*-blue.svg?style=flat-square "Localization v4.*"
[localization_3_x]: https://img.shields.io/badge/version-3.*-blue.svg?style=flat-square "Localization v3.*"
[localization_2_x]: https://img.shields.io/badge/version-2.*-blue.svg?style=flat-square "Localization v2.*"
[localization_1_x]: https://img.shields.io/badge/version-1.*-blue.svg?style=flat-square "Localization v1.*"
[localization_0_x]: https://img.shields.io/badge/version-0.*-blue.svg?style=flat-square "Localization v0.*"

## Composer

Expand All @@ -58,6 +49,10 @@ You can install this package via [Composer](http://getcomposer.org/) by running
composer require arcanedev/localization
```

PHP extensions:

* **ext_intl :** Needed to use the `Locale` class. (http://php.net/manual/en/class.locale.php)

## Laravel

### Setup
Expand Down
8 changes: 2 additions & 6 deletions _docs/2-Configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,10 @@ return [
| localized-routes | Allows to register all translatable routes. |
| translation-redirect | Allows to translate the route attributes by using the translation event. |

## Ignored URI / Route
## Ignored URI/Route from localization

```php
'ignored-uri' => [
//
],

'ignored-routes' => [
'ignored-redirection' => [
//
],
```
Expand Down
12 changes: 7 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
"type": "library",
"license": "MIT",
"require": {
"php": ">=7.2.0",
"php": "^7.2.5",
"ext-json": "*",
"arcanedev/support": "^5.1"
"arcanedev/support": "^7.0"
},
"require-dev": {
"ext-intl": "*",
"orchestra/testbench": "^4.0",
"orchestra/testbench": "^5.0",
"mockery/mockery": "^1.3.1",
"phpunit/phpunit": "^8.0"
"phpunit/phpunit": "^8.5|^9.0"
},
"autoload": {
"psr-4": {
Expand All @@ -45,5 +45,7 @@
},
"suggest": {
"ext-intl": "Use Intl extension for 'Locale' class (an identifier used to get language)."
}
},
"minimum-stability": "dev",
"prefer-stable": true
}
8 changes: 2 additions & 6 deletions config/localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,11 @@
],

/* -----------------------------------------------------------------
| Ignored URI/Routes from localization
| Ignored URI/Route from localization
| -----------------------------------------------------------------
*/

'ignored-uri' => [
//
],

'ignored-routes' => [
'ignored-redirection' => [
//
],

Expand Down
8 changes: 6 additions & 2 deletions src/LocalizationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,11 @@ public function register(): void
*/
public function boot(): void
{
$this->publishConfig();
$this->publishViews();
$this->loadViews();

if ($this->app->runningInConsole()) {
$this->publishConfig();
$this->publishViews();
}
}
}
32 changes: 16 additions & 16 deletions src/Middleware/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ protected function hideDefaultLocaleInURL()
return $this->localization->isDefaultLocaleHiddenInUrl();
}

/**
* Get the ignored URI/Route.
*
* @return array
*/
protected function getIgnoredRedirection(): array
{
return config('localization.ignored-redirection', []);
}

/* -----------------------------------------------------------------
| Check Methods
| -----------------------------------------------------------------
Expand Down Expand Up @@ -122,14 +132,17 @@ protected function isDefaultLocaleHidden($locale)
protected function shouldIgnore(Request $request): bool
{
foreach ($this->except as $except) {
if ($except !== '/')
if ($except !== '/') {
$except = trim($except, '/');
}

if ($request->is($except))
if ($request->is($except)) {
return true;
}

if ($request->routeIs($except))
if ($request->routeIs($except)) {
return true;
}
}

return false;
Expand Down Expand Up @@ -166,17 +179,4 @@ protected function makeRedirectResponse($url, $code = null)
{
return new RedirectResponse($url, $code ?? config('localization.redirection-code', 302), ['Vary' => 'Accept-Language']);
}

/**
* The URIs or route names that should not be redirected.
*
* @return array
*/
protected function getIgnoredRedirection(): array
{
return array_merge(
config('localization.ignored-uri', []),
config('localization.ignored-routes', [])
);
}
}
25 changes: 16 additions & 9 deletions src/Providers/RoutingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

namespace Arcanedev\Localization\Providers;

use Arcanedev\Localization\Middleware;
use Arcanedev\Support\Providers\RouteServiceProvider as ServiceProvider;
use Arcanedev\Localization\Middleware\{
LocaleCookieRedirect, LocaleSessionRedirect, LocalizationRedirect, LocalizationRoutes, TranslationRedirect
};
use Arcanedev\Localization\Routing\Router;
use Arcanedev\Support\Providers\RouteServiceProvider as ServiceProvider;

/**
* Class RoutingServiceProvider
Expand All @@ -29,11 +31,11 @@ class RoutingServiceProvider extends ServiceProvider
* @var array
*/
protected $routeMiddleware = [
'localization-session-redirect' => Middleware\LocaleSessionRedirect::class,
'localization-cookie-redirect' => Middleware\LocaleCookieRedirect::class,
'localization-redirect' => Middleware\LocalizationRedirect::class,
'localized-routes' => Middleware\LocalizationRoutes::class,
'translation-redirect' => Middleware\TranslationRedirect::class,
'localization-session-redirect' => LocaleSessionRedirect::class,
'localization-cookie-redirect' => LocaleCookieRedirect::class,
'localization-redirect' => LocalizationRedirect::class,
'localized-routes' => LocalizationRoutes::class,
'translation-redirect' => TranslationRedirect::class,
];

/* -----------------------------------------------------------------
Expand All @@ -46,8 +48,13 @@ class RoutingServiceProvider extends ServiceProvider
*/
public function register(): void
{
$this->app['router']->mixin(new Router);
/** @var \Illuminate\Routing\Router $router */
$router = $this->app['router'];

$router->mixin(new Router);

parent::register();
foreach ($this->routeMiddleware as $name => $class) {
$router->aliasMiddleware($name, $class);
}
}
}
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected function getEnvironmentSetUp($app): void

$translator->getLoader()->addNamespace(
'localization',
realpath(__DIR__).DS.'fixtures'.DS.'lang'
realpath(__DIR__).DIRECTORY_SEPARATOR.'fixtures'.DIRECTORY_SEPARATOR.'lang'
);

$translator->load('localization', 'routes', 'en');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class CreateTranslatableTable extends Migration
| Properties
| -----------------------------------------------------------------
*/

/**
* The table name.
*
Expand All @@ -31,7 +32,7 @@ class CreateTranslatableTable extends Migration
*/
public function up(): void
{
$this->createSchema(function (Blueprint $table) {
$this->createSchema(function (Blueprint $table): void {
$table->increments('id');
$table->string('name');
$table->string('slug')->nullable();
Expand Down
File renamed without changes.

0 comments on commit 8d3b1ed

Please sign in to comment.