Skip to content

Commit

Permalink
Merge branch 'release-0.5.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
svycka committed Sep 9, 2020
2 parents ddc7f55 + b27674f commit 7357acd
Show file tree
Hide file tree
Showing 30 changed files with 513 additions and 170 deletions.
15 changes: 8 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,28 @@ cache:

matrix:
include:
- php: 5.6
- php: 7.2
env:
- DEPENDENCIES="--prefer-stable"
- php: 5.6
- php: 7.2
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"
- php: 7.0

- php: 7.3
env:
- DEPENDENCIES="--prefer-stable"
- php: 7.0
- php: 7.3
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"
- php: 7.1

- php: 7.4
env:
- DEPENDENCIES="--prefer-stable"
- TEST_COVERAGE=true
- php: 7.1
- php: 7.4
env:
- DEPENDENCIES="--prefer-lowest --prefer-stable"


before_script:
- phpenv config-rm xdebug.ini
- composer self-update
Expand Down
10 changes: 9 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Changelog
v1.0.0 - TBD
---

v0.5.0 - 2020-09-09
---
* [#104](https://github.com/basz/SlmLocale/pull/104) Run tests for php 7.2 and 7.3
* [#106](https://github.com/basz/SlmLocale/pull/106) Added a view-helper to get the primary-language
* [#105](https://github.com/basz/SlmLocale/pull/105) Fixed locale url change, from default locale to other locale
* [#107](https://github.com/basz/SlmLocale/pull/107) Added Laminas support
* [#108](https://github.com/basz/SlmLocale/pull/108) Added tests for php74

v0.4.1
---
* [#99](https://github.com/basz/SlmLocale/pull/99) fixed #26 unit testing applications using SlmLocale
Expand Down Expand Up @@ -34,4 +42,4 @@ First public stable release
* Rewrite of internal detector events
* Update of all available strategies
* Compliant with coding standards
* All covered with unit tests
* All covered with unit tests
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Created by Jurian Sluiman

Introduction
------------
SlmLocale is a Zend Framework module to automatically detect a locale for your
SlmLocale is a Laminas module to automatically detect a locale for your
application. It uses a variety of pluggable strategies to search for a valid
locale. SlmLocale features a default locale, a set of supported locales and
locale aliases.
Expand Down Expand Up @@ -96,7 +96,7 @@ is important! You usually want the `acceptlanguage` as last for a fallback:

At this moment, the locale should be detected. The locale is stored inside php's
`Locale` object. Retrieve the locale with `Locale::getDefault()`. This is also
automated inside Zend Framework translator objects and i18n view helpers (so
automated inside Laminas translator objects and i18n view helpers (so
you do not need to set the locale yourself there).

### Set the locale's language in html
Expand All @@ -110,7 +110,7 @@ in the `html` tag:
Inject the detected language here with the following code:

```
<html lang="<?= Locale::getPrimaryLanguage(Locale::getDefault())?>">
<html lang="<?= $this->primaryLanguage()?>">
```

### Disable UriPathStrategy in PHPUNIT
Expand Down
33 changes: 17 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
{
"name": "slm/locale",
"description": "Automatic detection of locales for Zend Framework",
"description": "Automatic detection of locales for Laminas",
"type": "library",
"license": "BSD-3-Clause",
"keywords": [
"laminas",
"zf",
"zend framework",
"i18n",
Expand All @@ -18,26 +19,26 @@
}
],
"require": {
"php": "^5.6 || ^7.0",
"php": "^7.2",
"ext-intl": "*",
"zendframework/zend-eventmanager": "^3.1",
"zendframework/zend-http": "^2.7",
"zendframework/zend-modulemanager": "^2.8.2",
"zendframework/zend-router": "^3.0",
"zendframework/zend-servicemanager": "^3.2",
"zendframework/zend-stdlib": "^3.1",
"zendframework/zend-view": "^2.9.0"
"laminas/laminas-eventmanager": "^3.1",
"laminas/laminas-http": "^2.7",
"laminas/laminas-modulemanager": "^2.8.2",
"laminas/laminas-router": "^3.0",
"laminas/laminas-servicemanager": "^3.2",
"laminas/laminas-stdlib": "^3.2.1",
"laminas/laminas-view": "^2.9.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.8.1",
"phpunit/phpunit": "^4.8.36",
"satooshi/php-coveralls": "^1.0.2",
"zendframework/zend-console": "^2.6",
"zendframework/zend-mvc": "^3.1",
"zendframework/zend-mvc-console": "^1.1.9"
"friendsofphp/php-cs-fixer": "^2.16.1",
"phpunit/phpunit": "^8.5.1",
"satooshi/php-coveralls": "^1.1.0",
"laminas/laminas-console": "^2.6",
"laminas/laminas-mvc": "^3.1",
"laminas/laminas-mvc-console": "^1.1.9"
},
"suggest": {
"zendframework/zend-mvc": "For using the router in the UriPath strategy"
"laminas/laminas-mvc": "For using the router in the UriPath strategy"
},
"autoload": {
"psr-4": {
Expand Down
19 changes: 9 additions & 10 deletions config/module.config.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<?php

use SlmLocale\Locale\Detector;
use SlmLocale\Service\DetectorFactory;
use SlmLocale\Service\LocaleMenuViewHelperFactory;
use SlmLocale\Service\LocaleUrlViewHelperFactory;
use SlmLocale\Service;
use SlmLocale\Strategy\Factory\StrategyPluginManagerFactory;
use SlmLocale\Strategy\StrategyPluginManager;
use SlmLocale\View\Helper\LocaleMenu;
use SlmLocale\View\Helper\LocaleUrl;
use SlmLocale\View\Helper;

/**
* Copyright (c) 2012-2013 Jurian Sluiman.
Expand Down Expand Up @@ -56,18 +53,20 @@
'service_manager' => [
'factories' => [
StrategyPluginManager::class => StrategyPluginManagerFactory::class,
Detector::class => DetectorFactory::class,
Detector::class => Service\DetectorFactory::class,
],
],

'view_helpers' => [
'aliases' => [
'localeUrl' => LocaleUrl::class,
'localeMenu' => LocaleMenu::class,
'localeUrl' => Helper\LocaleUrl::class,
'localeMenu' => Helper\LocaleMenu::class,
'primaryLanguage' => Helper\PrimaryLanguage::class,
],
'factories' => [
LocaleUrl::class => LocaleUrlViewHelperFactory::class,
LocaleMenu::class => LocaleMenuViewHelperFactory::class,
Helper\LocaleUrl::class => Service\LocaleUrlViewHelperFactory::class,
Helper\LocaleMenu::class => Service\LocaleMenuViewHelperFactory::class,
Helper\PrimaryLanguage::class => Service\PrimaryLanguageHelperFactory::class,
],
],
];
2 changes: 1 addition & 1 deletion docs/1.Introduction.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Introduction
===
SlmLocale is a Zend Framework module to automatically detect a locale for your application. It uses a variety of pluggable strategies to search for a valid locale. SlmLocale features a default locale, a set of supported locales and locale aliases.
SlmLocale is a Laminas module to automatically detect a locale for your application. It uses a variety of pluggable strategies to search for a valid locale. SlmLocale features a default locale, a set of supported locales and locale aliases.

Strategies
---
Expand Down
2 changes: 1 addition & 1 deletion docs/2.Strategies.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Path segment of URI
---
The path segment uses the first part of the path which does not belong to the base path. This means if your site runs under http://example.com, then `/en-US/` selects the locale en-US. If your site runs under http://example.com/my-app/, then `/my-app/en-US/` selects the locale.

Furthermore, this strategy updates the router's base path with the locale appended. This means all links built with Zend\Navigation or with the `url()` view helper, will have the locale prepended automatically.
Furthermore, this strategy updates the router's base path with the locale appended. This means all links built with Laminas\Navigation or with the `url()` view helper, will have the locale prepended automatically.

The strategy supports aliases, so you can use `en` as an alias for en-US and `nl` for nl-NL. However, a few bugs are still present at this moment so it is not advised to use these aliases together with this strategy.

Expand Down
6 changes: 6 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,10 @@
<testsuite name="SlmLocale">
<directory>./tests</directory>
</testsuite>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</phpunit>
10 changes: 5 additions & 5 deletions src/SlmLocale/Locale/Detector.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@

namespace SlmLocale\Locale;

use Laminas\EventManager\EventManagerAwareInterface;
use Laminas\EventManager\EventManagerInterface;
use Laminas\Stdlib\RequestInterface;
use Laminas\Stdlib\ResponseInterface;
use Laminas\Uri\Uri;
use SlmLocale\LocaleEvent;
use SlmLocale\Strategy\StrategyInterface;
use Zend\EventManager\EventManagerAwareInterface;
use Zend\EventManager\EventManagerInterface;
use Zend\Stdlib\RequestInterface;
use Zend\Stdlib\ResponseInterface;
use Zend\Uri\Uri;

class Detector implements EventManagerAwareInterface
{
Expand Down
8 changes: 4 additions & 4 deletions src/SlmLocale/LocaleEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@

namespace SlmLocale;

use Zend\EventManager\Event;
use Zend\Stdlib\RequestInterface;
use Zend\Stdlib\ResponseInterface;
use Zend\Uri\Uri;
use Laminas\EventManager\Event;
use Laminas\Stdlib\RequestInterface;
use Laminas\Stdlib\ResponseInterface;
use Laminas\Uri\Uri;

class LocaleEvent extends Event
{
Expand Down
10 changes: 5 additions & 5 deletions src/SlmLocale/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@

namespace SlmLocale;

use Locale;
use Laminas\EventManager\EventInterface;

use Laminas\ModuleManager\Feature;
use Laminas\Mvc\MvcEvent;
use Laminas\Stdlib\ResponseInterface;
use Locale;
use SlmLocale\Locale\Detector;
use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature;
use Zend\Mvc\MvcEvent;
use Zend\Stdlib\ResponseInterface;

class Module implements
Feature\ConfigProviderInterface,
Expand Down
59 changes: 59 additions & 0 deletions src/SlmLocale/Service/PrimaryLanguageHelperFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/**
* Copyright (c) 2012-2019 Jurian Sluiman.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the names of the copyright holders nor the names of the
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* @author Jurian Sluiman <[email protected]>
* @copyright 2012-2013 Jurian Sluiman.
* @license http://www.opensource.org/licenses/bsd-license.php BSD License
* @link http://juriansluiman.nl
*/
namespace SlmLocale\Service;

use Interop\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Locale;
use SlmLocale\View\Helper\PrimaryLanguage;

final class PrimaryLanguageHelperFactory implements FactoryInterface
{
/**
* @param ContainerInterface $container
* @param string $requestedName
* @param array|null $options
* @return object|PrimaryLanguage
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
return new PrimaryLanguage(new Locale());
}
}
8 changes: 4 additions & 4 deletions src/SlmLocale/Strategy/AbstractStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@

namespace SlmLocale\Strategy;

use Laminas\EventManager\AbstractListenerAggregate;
use Laminas\EventManager\EventManagerInterface;
use Laminas\Http\Request as HttpRequest;
use Laminas\Stdlib\RequestInterface;
use SlmLocale\LocaleEvent;
use Zend\EventManager\AbstractListenerAggregate;
use Zend\EventManager\EventManagerInterface;
use Zend\Http\Request as HttpRequest;
use Zend\Stdlib\RequestInterface;

abstract class AbstractStrategy extends AbstractListenerAggregate implements StrategyInterface
{
Expand Down
4 changes: 2 additions & 2 deletions src/SlmLocale/Strategy/CookieStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@

namespace SlmLocale\Strategy;

use Laminas\Http\Header\Cookie;
use Laminas\Http\Header\SetCookie;
use SlmLocale\LocaleEvent;
use SlmLocale\Strategy\Exception\InvalidArgumentException;
use Zend\Http\Header\Cookie;
use Zend\Http\Header\SetCookie;

class CookieStrategy extends AbstractStrategy
{
Expand Down
2 changes: 1 addition & 1 deletion src/SlmLocale/Strategy/StrategyInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

namespace SlmLocale\Strategy;

use Zend\EventManager\ListenerAggregateInterface;
use Laminas\EventManager\ListenerAggregateInterface;

interface StrategyInterface extends ListenerAggregateInterface
{
Expand Down
4 changes: 2 additions & 2 deletions src/SlmLocale/Strategy/StrategyPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@

namespace SlmLocale\Strategy;

use Laminas\ServiceManager\AbstractPluginManager;
use Laminas\ServiceManager\Factory\InvokableFactory;
use SlmLocale\Strategy\Factory\UriPathStrategyFactory;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Factory\InvokableFactory;

class StrategyPluginManager extends AbstractPluginManager
{
Expand Down
Loading

0 comments on commit 7357acd

Please sign in to comment.