Skip to content

Commit

Permalink
Merge pull request #57 from ARCANEDEV/feature-laravel_53
Browse files Browse the repository at this point in the history
Adding Laravel 5.3 Support
  • Loading branch information
arcanedev-maroc authored Aug 28, 2016
2 parents 1f1d163 + 5db93d1 commit bb58d09
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 72 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
/.gitignore export-ignore
/.scrutinizer.yml export-ignore
/.travis.yml export-ignore
/CONTRIBUTING.md export-ignore
/phpunit.xml export-ignore
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
/.idea/
/_arcanedev/
/build/
/vendor/
/composer.phar
Expand Down
2 changes: 1 addition & 1 deletion .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ checks:
tools:
external_code_coverage:
timeout: 1800
runs: 12
runs: 8
php_code_sniffer:
enabled: true
config:
Expand Down
9 changes: 4 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ language: php
sudo: false

php:
- 5.5.9
- 5.5
- 5.6
- 7.0
- 7.1
- nightly
- hhvm

matrix:
allow_failures:
Expand All @@ -18,6 +16,7 @@ env:
- TESTBENCH_VERSION=3.0.*
- TESTBENCH_VERSION=3.1.*
- TESTBENCH_VERSION=3.2.*
- TESTBENCH_VERSION=3.3.*

before_script:
- travis_retry composer self-update
Expand All @@ -29,5 +28,5 @@ script:
- vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover

after_script:
- if [ "$TRAVIS_PHP_VERSION" != "nightly" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "nightly" ] && [ "$TRAVIS_PHP_VERSION" != "hhvm" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
- if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then wget https://scrutinizer-ci.com/ocular.phar; fi
- if [ "$TRAVIS_PHP_VERSION" != "nightly" ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# Localization [![Packagist License][badge_license]](LICENSE.md) [![For Laravel 5][badge_laravel]][link-github-repo]

[![Travis Status][badge_build]][link-travis]
[![HHVM Status][badge_hhvm]][link-hhvm]
[![Coverage Status][badge_coverage]][link-scrutinizer]
[![Scrutinizer Code Quality][badge_quality]][link-scrutinizer]
[![SensioLabs Insight][badge_insight]][link-insight]
Expand All @@ -22,6 +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.
* SEO-Friendly (Search engine optimization).
* New extended Router to manage your localized routes.
* Locales selector menu (Publishable & Customizable).
Expand All @@ -37,17 +37,9 @@ Feel free to check out the [releases](https://github.com/ARCANEDEV/Localization/
5. [Extras](_docs/5-Extras.md)
6. [FAQ](_docs/6-FAQ.md)

### DONE

- [x] Laravel 5.2 supported.
- [x] Laravel 5.1 supported.
- [x] Laravel 5.0 supported.
- [x] Adding language selector view.

### TODOS

- [ ] 100% Code coverage + Maximum code quality.
- [ ] Laravel 5.3 support.
- [ ] Complete the documentation.
- [ ] Adding more regionals for locales.

Expand All @@ -68,7 +60,6 @@ If you discover any security related issues, please email arcanedev.maroc@gmail.
[badge_license]: http://img.shields.io/packagist/l/arcanedev/localization.svg?style=flat-square
[badge_laravel]: https://img.shields.io/badge/For-Laravel%205-orange.svg?style=flat-square
[badge_build]: http://img.shields.io/travis/ARCANEDEV/Localization.svg?style=flat-square
[badge_hhvm]: https://img.shields.io/hhvm/arcanedev/localization.svg?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
[badge_insight]: https://img.shields.io/sensiolabs/i/30a231b2-295e-466a-8733-fe95cf2bc48d.svg?style=flat-square
Expand All @@ -83,6 +74,5 @@ If you discover any security related issues, please email arcanedev.maroc@gmail.
[link-contributors]: https://github.com/ARCANEDEV/Localization/graphs/contributors
[link-packagist]: https://packagist.org/packages/arcanedev/localization
[link-travis]: https://travis-ci.org/ARCANEDEV/Localization
[link-hhvm]: http://hhvm.h4cc.de/package/arcanedev/localization
[link-scrutinizer]: https://scrutinizer-ci.com/g/ARCANEDEV/Localization/?branch=master
[link-insight]: https://insight.sensiolabs.com/projects/30a231b2-295e-466a-8733-fe95cf2bc48d
1 change: 1 addition & 0 deletions _docs/0-Home.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,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.
* SEO-Friendly (Search engine optimization).
* New extended Router to manage your localized routes.
* Locales selector menu (Publishable & Customizable).
Expand Down
2 changes: 1 addition & 1 deletion _docs/1-Requirements.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

The Localization package has a few system requirements:

- PHP >= 5.5.9
- PHP >= 5.6

##### Optional

Expand Down
2 changes: 1 addition & 1 deletion _docs/2-Installation-and-Setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Or by adding the package to your `composer.json`.
```json
{
"require": {
"arcanedev/localization": "0.7.*"
"arcanedev/localization": "0.8.*"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion 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.5.9",
"php" : ">=5.6",
"arcanedev/support": "~3.6"
},
"require-dev": {
Expand Down
63 changes: 17 additions & 46 deletions src/Localization.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use Arcanedev\Localization\Contracts\LocalesManagerInterface;
use Arcanedev\Localization\Contracts\LocalizationInterface;
use Arcanedev\Localization\Contracts\RouteTranslatorInterface;
use Arcanedev\Localization\Exceptions\UndefinedSupportedLocalesException;
use Arcanedev\Localization\Exceptions\UnsupportedLocaleException;
use Arcanedev\Localization\Utilities\Url;
use Illuminate\Foundation\Application;
Expand All @@ -22,30 +21,30 @@ class Localization implements LocalizationInterface
| ------------------------------------------------------------------------------------------------
*/
/**
* Laravel application instance.
* Base url.
*
* @var Application
* @var string
*/
private $app;
protected $baseUrl;

/**
* Base url.
* Laravel application instance.
*
* @var string
* @var \Illuminate\Foundation\Application
*/
protected $baseUrl;
private $app;

/**
* The RouteTranslator instance.
*
* @var RouteTranslatorInterface
* @var \Arcanedev\Localization\Contracts\RouteTranslatorInterface
*/
protected $routeTranslator;

/**
* The LocalesManager instance.
*
* @var LocalesManagerInterface
* @var \Arcanedev\Localization\Contracts\LocalesManagerInterface
*/
private $localesManager;

Expand All @@ -56,12 +55,9 @@ class Localization implements LocalizationInterface
/**
* Creates new instance.
*
* @param Application $app
* @param RouteTranslatorInterface $routeTranslator
* @param LocalesManagerInterface $localesManager
*
* @throws UndefinedSupportedLocalesException
* @throws UnsupportedLocaleException
* @param \Illuminate\Foundation\Application $app
* @param \Arcanedev\Localization\Contracts\RouteTranslatorInterface $routeTranslator
* @param \Arcanedev\Localization\Contracts\LocalesManagerInterface $localesManager
*/
public function __construct(
Application $app,
Expand All @@ -84,7 +80,7 @@ public function __construct(
/**
* Get Request instance.
*
* @return Request
* @return \Illuminate\Http\Request
*/
private function request()
{
Expand All @@ -105,8 +101,6 @@ public function getDefaultLocale()
* Return an array of all supported Locales.
*
* @return \Arcanedev\Localization\Entities\LocaleCollection
*
* @throws UndefinedSupportedLocalesException
*/
public function getSupportedLocales()
{
Expand All @@ -131,8 +125,6 @@ public function setSupportedLocales(array $supportedLocales)
* Get supported locales keys.
*
* @return array
*
* @throws UndefinedSupportedLocalesException
*/
public function getSupportedLocalesKeys()
{
Expand Down Expand Up @@ -240,9 +232,7 @@ public function setLocale($locale = null)
*/
public function setBaseUrl($url)
{
if (substr($url, -1) !== '/') {
$url .= '/';
}
if (substr($url, -1) !== '/') $url .= '/';

$this->baseUrl = $url;

Expand Down Expand Up @@ -271,8 +261,6 @@ public function transRoute($routeName)
* @param string|null $url
* @param string|null $locale
*
* @throws UnsupportedLocaleException
*
* @return string
*/
public function localizeURL($url = null, $locale = null)
Expand Down Expand Up @@ -302,9 +290,6 @@ public function getNonLocalizedURL($url = null)
* @param array $attributes
*
* @return string|false
*
* @throws UndefinedSupportedLocalesException
* @throws UnsupportedLocaleException
*/
public function getLocalizedURL($locale = null, $url = null, $attributes = [])
{
Expand Down Expand Up @@ -386,11 +371,7 @@ public function createUrlFromUri($uri)
{
$uri = ltrim($uri, '/');

if (empty($this->baseUrl)) {
return app('url')->to($uri);
}

return $this->baseUrl . $uri;
return empty($this->baseUrl) ? app('url')->to($uri) : $this->baseUrl.$uri;
}

/**
Expand All @@ -417,9 +398,6 @@ public function localesNavbar()
* @param string $locale
*
* @return string|false
*
* @throws UndefinedSupportedLocalesException
* @throws UnsupportedLocaleException
*/
private function findTranslatedRouteByUrl($url, $attributes, $locale)
{
Expand All @@ -445,9 +423,6 @@ private function findTranslatedRouteByUrl($url, $attributes, $locale)
* @param array $attributes
*
* @return string|false
*
* @throws UndefinedSupportedLocalesException
* @throws UnsupportedLocaleException
*/
public function getUrlFromRouteName($locale, $transKey, $attributes = [])
{
Expand All @@ -470,7 +445,7 @@ public function getUrlFromRouteName($locale, $transKey, $attributes = [])
/**
* Set route name from request.
*
* @param Request $request
* @param \Illuminate\Http\Request $request
*/
public function setRouteNameFromRequest(Request $request)
{
Expand Down Expand Up @@ -500,23 +475,19 @@ public function isDefaultLocaleHiddenInUrl()
*
* @param string|bool $locale
*
* @throws UndefinedSupportedLocalesException
*
* @return bool
*/
public function isLocaleSupported($locale)
{
return (
$locale !== false && ! $this->localesManager->isSupportedLocale($locale)
) ? false : true;
return ! ($locale !== false && ! $this->localesManager->isSupportedLocale($locale));
}

/**
* Check if the locale is supported or fail if not.
*
* @param string $locale
*
* @throws UnsupportedLocaleException
* @throws \Arcanedev\Localization\Exceptions\UnsupportedLocaleException
*/
private function isLocaleSupportedOrFail($locale)
{
Expand Down
4 changes: 1 addition & 3 deletions src/Utilities/Url.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,7 @@ private static function hasAttributesFromUriPath($url, $path, &$attributes)
}
}

if (isset($url[$i + 1])) {
$match = false;
}
if (isset($url[$i + 1])) $match = false;

return $match;
}
Expand Down

0 comments on commit bb58d09

Please sign in to comment.