Skip to content

Commit

Permalink
Fixed bug for IIS server.
Browse files Browse the repository at this point in the history
  • Loading branch information
grinry committed Nov 30, 2015
1 parent a7de4fa commit 76a34a3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 14 deletions.
2 changes: 2 additions & 0 deletions MultiLanguageServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
/**
* @author Rytis Grincevicius <[email protected]>
* @link http://www.github.com/kiberzauras/laravel.multilanguage
* @version 2.0.2
* @license MIT
*/
namespace Kiberzauras\MultiLanguage;
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
This package will help you to easy create multilanguage routes on top of your single language website. With this package
you will be able to access your website with these routes example.com, example.com/en, example.com/en/page and etc. and
there is no need to change your routes.php file!

!Note: will not work if you use microsoft IIS as your server. I will try to solve this issue soon.

### Installation

Expand Down
48 changes: 37 additions & 11 deletions Request.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
/**
* @author Rytis Grincevicius <[email protected]>
* @link http://www.github.com/kiberzauras/laravel.multilanguage
* @version 2.0.2
* @license MIT
*/
namespace Kiberzauras\MultiLanguage;
Expand All @@ -24,22 +26,46 @@ public static function capture()
$params = json_decode(file_get_contents($config_url));

if (!empty($params->enabled)) {
$uri = trim($_SERVER['REQUEST_URI'], '/');
$lang = strstr($uri, '/', true);
if (in_array($lang, $params->enabled)) {
// for accessing /en/page/page
$_SERVER['REQUEST_URI'] = strstr($uri, '/');
define('Language', $lang);
} elseif (in_array($uri, $params->enabled)) {
// for accessing /, /en, and /en/ pages
$_SERVER['REQUEST_URI'] = '/';
define('Language', $uri);
}

if (array_key_exists('HTTP_X_ORIGINAL_URL', $_SERVER))
self::parseServerVars('HTTP_X_ORIGINAL_URL', $params);

elseif (array_key_exists('HTTP_X_REWRITE_URL', $_SERVER))
self::parseServerVars('HTTP_X_REWRITE_URL', $params);

elseif ($_SERVER['UNENCODED_URL'] && $_SERVER['IIS_WasUrlRewritten'] == 1)
self::parseServerVars('UNENCODED_URL', $params);

elseif ($_SERVER['REQUEST_URI'])
self::parseServerVars('REQUEST_URI', $params);

elseif ($_SERVER['ORIG_PATH_INFO'])
self::parseServerVars('ORIG_PATH_INFO', $params);

}
defined('Language') || define('Language', !empty($params->default) ? $params->default : 'en');
}

static::enableHttpMethodParameterOverride();
return static::createFromBase(SymfonyRequest::createFromGlobals());
}

/**
* @param $var
* @param $params
*/
protected static function parseServerVars($var, $params)
{
$uri = trim($_SERVER[$var], '/');
$lang = strstr($uri, '/', true);
if (in_array($lang, $params->enabled)) {
// for accessing /en/page/page
$_SERVER[$var] = strstr($uri, '/');
define('Language', $lang);
} elseif (in_array($uri, $params->enabled)) {
// for accessing /, /en, and /en/ pages
$_SERVER[$var] = '/';
define('Language', $uri);
}
}
}
2 changes: 2 additions & 0 deletions UrlGenerator.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
/**
* @author Rytis Grincevicius <[email protected]>
* @link http://www.github.com/kiberzauras/laravel.multilanguage
* @version 2.0.2
* @license MIT
*/
namespace Kiberzauras\MultiLanguage;
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
"description": "Multilanguage support for Laravel 5.1 routes",
"keywords": ["laravel", "multilanguage", "kiberzauras"],
"license": "MIT",
"time": "2015-11-30",
"authors": [
{
"name": "Rytis Grincevicius",
"email": "[email protected]"
"email": "[email protected]",
"homepage": "http://www.github.com/kiberzauras/laravel.multilanguage"
}
],
"require": {
Expand Down

0 comments on commit 76a34a3

Please sign in to comment.