Skip to content

Commit

Permalink
Adding a translator router
Browse files Browse the repository at this point in the history
  • Loading branch information
arcanedev-maroc committed Sep 15, 2015
1 parent fb4444f commit 89c38a9
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Facades/TransRoute.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php namespace Arcanedev\Localization\Facades;

use Illuminate\Support\Facades\Facade;

/**
* Class TransRoute
*
* @package Arcanedev\Localization\Facades
* @author ARCANEDEV <arcanedev.maroc@gmail.com>
*/
class TransRoute extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*
* @throws \RuntimeException
*/
protected static function getFacadeAccessor() {
return 'arcanedev.localization.router';
}
}
13 changes: 13 additions & 0 deletions src/LocalizationServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function register()
{
$this->registerConfig();
$this->registerLocalization();
$this->registerRouter();
}

/**
Expand Down Expand Up @@ -95,4 +96,16 @@ private function registerLocalization()
Facades\Localization::class
);
}

/**
* Register the router
*/
private function registerRouter()
{
$this->app->singleton('arcanedev.localization.router', function ($app) {
return new Routing\TransRouter($app['events'], $app);
});

$this->addFacade('TransRoute', Facades\TransRoute::class);
}
}
107 changes: 107 additions & 0 deletions src/Routing/TransRouter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php namespace Arcanedev\Localization\Routing;

use Illuminate\Routing\Router;

/**
* Class TransRouter
*
* @package Arcanedev\Localization\Routing
* @author ARCANEDEV <arcanedev.maroc@gmail.com>
*/
class TransRouter extends Router
{
/* ------------------------------------------------------------------------------------------------
| Main Functions
| ------------------------------------------------------------------------------------------------
*/
/**
* Create a localized route group with shared attributes.
*
* @param \Closure $callback
*/
public function trans(\Closure $callback)
{
$attributes = [
'prefix' => localization()->setLocale(),
'middleware' => [
'localeSessionRedirect',
'localizationRedirect'
],
];

$this->group($attributes, $callback);
}

/**
* Register a new GET route with the router.
*
* @param string $uri
* @param \Closure|array|string $action
* @return \Illuminate\Routing\Route
*/
// public function get($uri, $action);

/**
* Register a new POST route with the router.
*
* @param string $uri
* @param \Closure|array|string $action
* @return \Illuminate\Routing\Route
*/
// public function post($uri, $action);

/**
* Register a new PUT route with the router.
*
* @param string $uri
* @param \Closure|array|string $action
* @return \Illuminate\Routing\Route
*/
// public function put($uri, $action);

/**
* Register a new PATCH route with the router.
*
* @param string $uri
* @param \Closure|array|string $action
* @return \Illuminate\Routing\Route
*/
// public function patch($uri, $action);

/**
* Register a new DELETE route with the router.
*
* @param string $uri
* @param \Closure|array|string $action
* @return \Illuminate\Routing\Route
*/
// public function delete($uri, $action);

/**
* Register a new OPTIONS route with the router.
*
* @param string $uri
* @param \Closure|array|string $action
* @return \Illuminate\Routing\Route
*/
// public function options($uri, $action);

/**
* Register a new route responding to all verbs.
*
* @param string $uri
* @param \Closure|array|string $action
* @return \Illuminate\Routing\Route
*/
// public function any($uri, $action);

/**
* Register a new route with the given verbs.
*
* @param array|string $methods
* @param string $uri
* @param \Closure|array|string $action
* @return \Illuminate\Routing\Route
*/
// public function match($methods, $uri, $action);
}

0 comments on commit 89c38a9

Please sign in to comment.