Skip to content

Commit

Permalink
Refactoring Localization
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Sep 24, 2015
1 parent 9872026 commit 034809c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 35 deletions.
29 changes: 4 additions & 25 deletions src/Bases/Middleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

use Arcanedev\Localization\Entities\LocaleCollection;
use Arcanedev\Localization\Exceptions\UndefinedSupportedLocalesException;
use Arcanedev\Localization\Localization;
use Arcanedev\Support\Bases\Middleware as BaseMiddleware;
use Illuminate\Http\RedirectResponse;

Expand All @@ -14,26 +13,6 @@
*/
abstract class Middleware extends BaseMiddleware
{
/* ------------------------------------------------------------------------------------------------
| Properties
| ------------------------------------------------------------------------------------------------
*/
/**
* The localization instance.
*
* @var Localization
*/
protected $localization;

/* ------------------------------------------------------------------------------------------------
| Constructor
| ------------------------------------------------------------------------------------------------
*/
public function __construct()
{
$this->localization = localization();
}

/* ------------------------------------------------------------------------------------------------
| Getters & Setters
| ------------------------------------------------------------------------------------------------
Expand All @@ -45,7 +24,7 @@ public function __construct()
*/
public function getDefaultLocale()
{
return $this->localization->getDefaultLocale();
return localization()->getDefaultLocale();
}

/**
Expand All @@ -55,7 +34,7 @@ public function getDefaultLocale()
*/
public function getCurrentLocale()
{
return $this->localization->getCurrentLocale();
return localization()->getCurrentLocale();
}

/**
Expand All @@ -67,7 +46,7 @@ public function getCurrentLocale()
*/
public function getSupportedLocales()
{
return $this->localization->getSupportedLocales();
return localization()->getSupportedLocales();
}

/**
Expand All @@ -77,7 +56,7 @@ public function getSupportedLocales()
*/
protected function hideDefaultLocaleInURL()
{
return $this->localization->isDefaultLocaleHiddenInUrl();
return localization()->isDefaultLocaleHiddenInUrl();
}

/* ------------------------------------------------------------------------------------------------
Expand Down
8 changes: 5 additions & 3 deletions src/Contracts/LocalizationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,13 @@ public function setLocale($locale = null);
public function setBaseUrl($url);

/**
* Set current route name.
* Set route name from path.
*
* @param false|string $routeName
* @param string $uri
*
* @return self
*/
public function setRouteName($routeName);
public function setRouteNameFromCurrentUri($uri);

/* ------------------------------------------------------------------------------------------------
| Main Functions
Expand Down
10 changes: 7 additions & 3 deletions src/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,16 @@ public function setBaseUrl($url)
}

/**
* Set current route name.
* Set route name from path.
*
* @param false|string $routeName
* @param string $uri
*
* @return self
*/
public function setRouteName($routeName)
public function setRouteNameFromCurrentUri($uri)
{
$routeName = $this->getRouteNameFromPath($uri);

$this->routeTranslator->setCurrentRoute($routeName);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/LocaleSessionRedirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function handle(Request $request, Closure $next)
{
$locale = $request->segment(1, null);

if ($this->localization->isLocaleSupported($locale)) {
if (localization()->isLocaleSupported($locale)) {
session()->put(compact('locale'));

return $next($request);
Expand Down
5 changes: 2 additions & 3 deletions src/Middleware/LocalizationRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,9 @@ class LocalizationRoutes extends Middleware
*/
public function handle(Request $request, Closure $next)
{
$localization = localization();
$routeName = $localization->getRouteNameFromPath($request->getUri());
$currentUri = $request->getUri();

$localization->setRouteName($routeName);
localization()->setRouteNameFromCurrentUri($currentUri);

return $next($request);
}
Expand Down

0 comments on commit 034809c

Please sign in to comment.