Skip to content

Commit

Permalink
Merge pull request #77 from ARCANEDEV/update-laravel_5_4
Browse files Browse the repository at this point in the history
Updating the package to Support Laravel 5.4
  • Loading branch information
arcanedev-maroc authored Jan 27, 2017
2 parents 11d1cc2 + f5f675b commit 790a658
Show file tree
Hide file tree
Showing 24 changed files with 251 additions and 194 deletions.
16 changes: 10 additions & 6 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
* text=auto

/.github export-ignore
/_docs export-ignore
/tests export-ignore
/.editorconfig export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore
/phpunit.xml export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.scrutinizer.yml export-ignore
.travis.yml export-ignore
phpunit.xml export-ignore
CONTRIBUTING.md export-ignore
7 changes: 7 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- Localization Version: #.#.#
- Laravel Version: #.#.#
- PHP Version: #.#.#

### Description:

### Steps To Reproduce:
4 changes: 2 additions & 2 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ checks:

tools:
external_code_coverage:
timeout: 1800
runs: 8
timeout: 600
runs: 3
php_code_sniffer:
enabled: true
config:
Expand Down
7 changes: 2 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,11 @@ matrix:
- php: nightly

env:
- TESTBENCH_VERSION=3.0.*
- TESTBENCH_VERSION=3.1.*
- TESTBENCH_VERSION=3.2.*
- TESTBENCH_VERSION=3.3.*
- TESTBENCH_VERSION=3.4.*

before_script:
- travis_retry composer self-update
- travis_retry composer require --prefer-source --no-interaction --dev "orchestra/testbench:${TESTBENCH_VERSION}"
- travis_retry composer require --prefer-source --no-interaction --dev "orchestra/testbench-browser-kit:${TESTBENCH_VERSION}" "orchestra/database:${TESTBENCH_VERSION}"

script:
- composer validate
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-2016 | ARCANEDEV <[email protected]> - Localization
Copyright (c) 2015-2017 | 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
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` are supported.
* Laravel `5.0 | 5.1 | 5.2 | 5.3 | 5.4` are supported.
* SEO-Friendly (Search engine optimization).
* New extended Router to manage your localized routes.
* Locales selector menu (Publishable & Customizable).
Expand Down
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"type": "library",
"license": "MIT",
"require": {
"php" : ">=5.6.4",
"php": ">=5.6.4",
"arcanedev/support": "~3.20"
},
"require-dev": {
Expand All @@ -33,7 +33,7 @@
}
},
"scripts": {
"testbench": "composer require --dev \"orchestra/testbench=~3.0\""
"testbench": "composer require --dev \"orchestra/testbench-browser-kit=~3.4\" \"orchestra/database=~3.4\""
},
"suggest": {
"ext-intl": "Use Intl extension for 'Locale' class (an identifier used to get language)."
Expand All @@ -42,5 +42,7 @@
"branch-alias": {
"dev-master": "1.0.x-dev"
}
}
},
"minimum-stability": "dev",
"prefer-stable" : true
}
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
<directory suffix=".php">./src/</directory>
</whitelist>
</filter>
<php>
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
</php>
<logging>
<log type="coverage-clover" target="build/logs/clover.xml"/>
<log type="coverage-text" target="build/logs/coverage.txt"/>
Expand Down
31 changes: 31 additions & 0 deletions src/Bases/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
*/
abstract class Middleware extends BaseMiddleware
{
/* ------------------------------------------------------------------------------------------------
| Properties
| ------------------------------------------------------------------------------------------------
*/
/**
* The URIs that should not be localized.
*
* @var array
*/
protected $except = [];

/* ------------------------------------------------------------------------------------------------
| Getters & Setters
| ------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -75,6 +86,26 @@ protected function isDefaultLocaleHidden($locale)
return $this->getDefaultLocale() === $locale && $this->hideDefaultLocaleInURL();
}

/**
* Determine if the request has a URI that should not be localized.
*
* @param \Illuminate\Http\Request $request
*
* @return bool
*/
protected function shouldIgnore($request)
{
foreach ($this->except as $except) {
if ($except !== '/')
$except = trim($except, '/');

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

return false;
}

/* ------------------------------------------------------------------------------------------------
| Other Functions
| ------------------------------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions src/Middleware/LocaleCookieRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class LocaleCookieRedirect extends Middleware
*/
public function handle(Request $request, Closure $next)
{
// If the request URL is ignored from localization.
if ($this->shouldIgnore($request))
return $next($request);

$segment = $request->segment(1, null);
$locale = $request->cookie('locale', null);

Expand Down
4 changes: 4 additions & 0 deletions src/Middleware/LocaleSessionRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class LocaleSessionRedirect extends Middleware
*/
public function handle(Request $request, Closure $next)
{
// If the request URL is ignored from localization.
if ($this->shouldIgnore($request))
return $next($request);

$segment = $request->segment(1, null);
$locale = session('locale', null);

Expand Down
4 changes: 4 additions & 0 deletions src/Middleware/LocalizationRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class LocalizationRedirect extends Middleware
*/
public function handle(Request $request, Closure $next)
{
// If the request URL is ignored from localization.
if ($this->shouldIgnore($request))
return $next($request);

if ($redirectUrl = $this->getRedirectionUrl($request)) {
// Save any flashed data for redirect
session()->reflash();
Expand Down
4 changes: 4 additions & 0 deletions src/Middleware/LocalizationRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ class LocalizationRoutes extends Middleware
*/
public function handle(Request $request, Closure $next)
{
// If the request URL is ignored from localization.
if ($this->shouldIgnore($request))
return $next($request);

localization()->setRouteNameFromRequest($request);

return $next($request);
Expand Down
4 changes: 4 additions & 0 deletions src/Middleware/TranslationRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ class TranslationRedirect extends Middleware
*/
public function handle(Request $request, Closure $next)
{
// If the request URL is ignored from localization.
if ($this->shouldIgnore($request))
return $next($request);

$translatedUrl = $this->getTranslatedUrl($request);

if ( ! is_null($translatedUrl)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Providers/RoutingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private function registerMiddlewares()
*/
private function registerMiddleware(Router $router, $name, $class)
{
$router->middleware($name, $class);
$router->aliasMiddleware($name, $class);

if ($this->getMiddleware($name)) {
$this->middleware[] = $name;
Expand Down
37 changes: 0 additions & 37 deletions src/Routing/ResourceRegistrar.php

This file was deleted.

16 changes: 0 additions & 16 deletions src/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ protected function getActiveMiddlewares()
));
}

/* ------------------------------------------------------------------------------------------------
| Basic Route Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Route a resource to a controller.
*
* @param string $name
* @param string $controller
* @param array $options
*/
public function resource($name, $controller, array $options = [])
{
(new ResourceRegistrar($this))->register($name, $controller, $options);
}

/* ------------------------------------------------------------------------------------------------
| Route Functions
| ------------------------------------------------------------------------------------------------
Expand Down
7 changes: 7 additions & 0 deletions src/Utilities/Negotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,13 @@ private function inSupportedLocales(array $matches)
foreach (array_keys($matches) as $locale) {
if ($this->isSupported($locale))
return $locale;

// Search for acceptable locale by 'regional' => 'fr_FR' match.
foreach ($this->supportedLocales as $key => $entity) {
/** @var \Arcanedev\Localization\Entities\Locale $entity */
if ($entity->regional() == $locale)
return $key;
}
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/RouteTranslator.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ private function translate($key, $locale = null)
$locale = $this->translator->getLocale();
}

$translation = $this->translator->trans($key, [], '', $locale);
$translation = $this->translator->trans($key, [], $locale);

// @codeCoverageIgnoreStart
if ( ! is_string($translation)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Utilities/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ private static function extractAttributesFromRoutes($url, $routes)
continue;
}

$match = self::hasAttributesFromUriPath($url, $route->getUri(), $attributes);
$match = self::hasAttributesFromUriPath($url, $route->uri(), $attributes);

if ($match)
break;
Expand Down
15 changes: 15 additions & 0 deletions tests/Stubs/Http/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,21 @@ class Kernel extends HttpKernel
| Properties
| ------------------------------------------------------------------------------------------------
*/
/**
* The application's route middleware groups.
*
* @var array
*/
protected $middlewareGroups = [
'web' => [
Middleware\EncryptCookies::class,
\Illuminate\Session\Middleware\StartSession::class,
\Illuminate\View\Middleware\ShareErrorsFromSession::class,
\Orchestra\Testbench\Http\Middleware\VerifyCsrfToken::class,
\Illuminate\Routing\Middleware\SubstituteBindings::class,
],
];

/**
* The application's route middleware.
*
Expand Down
21 changes: 21 additions & 0 deletions tests/Stubs/Http/Middleware/EncryptCookies.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php namespace Arcanedev\Localization\Tests\Stubs\Http\Middleware;

use Illuminate\Cookie\Middleware\EncryptCookies as BaseEncrypter;

/**
* Class EncryptCookies
*
* @package Arcanedev\Localization\Tests\Stubs\Http\Middleware
* @author ARCANEDEV <[email protected]>
*/
class EncryptCookies extends BaseEncrypter
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected $except = [
'locale'
];
}
Loading

0 comments on commit 790a658

Please sign in to comment.