Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge branch 'feature/21' into develop
Browse files Browse the repository at this point in the history
Close #21
Close #22
  • Loading branch information
weierophinney committed Feb 10, 2016
2 parents 34f9d25 + f73c76e commit dc4d11a
Show file tree
Hide file tree
Showing 25 changed files with 400 additions and 92 deletions.
22 changes: 21 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,28 @@ matrix:
- php: 5.5
env:
- EXECUTE_CS_CHECK=true
- php: 5.5
env:
- SERVICE_MANAGER_VERSION="^2.7.5"
- EVENT_MANAGER_VERSION="^2.6.2"
- php: 5.6
env:
- EXECUTE_TEST_COVERALLS=true
- php: 5.6
env:
- SERVICE_MANAGER_VERSION="^2.7.5"
- EVENT_MANAGER_VERSION="^2.6.2"
- php: 7
- php: 7
env:
- SERVICE_MANAGER_VERSION="^2.7.5"
- EVENT_MANAGER_VERSION="^2.6.2"
- php: hhvm
- php: hhvm
env:
- SERVICE_MANAGER_VERSION="^2.7.5"
- EVENT_MANAGER_VERSION="^2.6.2"
allow_failures:
- php: 7
- php: hhvm

notifications:
Expand All @@ -34,6 +49,11 @@ before_install:
- if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi
- composer self-update
- if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi
- if [[ $SERVICE_MANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION" ; fi
- if [[ $SERVICE_MANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0.3" ; fi
- if [[ $SERVICE_MANAGER_VERSION == '' ]]; then composer remove --dev --no-update zendframework/zend-cache zendframework/zend-validator zendframework/zend-view ; fi
- if [[ $EVENT_MANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-eventmanager:$EVENT_MANAGER_VERSION" ; fi
- if [[ $EVENT_MANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-eventmanager:^3.0" ; fi

install:
- travis_retry composer install --no-interaction --ignore-platform-reqs
Expand Down
11 changes: 6 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 3.0.0 - TBD
## 2.6.0 - TBD

### Added

Expand All @@ -18,7 +18,8 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- [#12](https://github.com/zendframework/zend-i18n/pull/12) updates the
component to the v3 version of zend-servicemanager.
- [#12](https://github.com/zendframework/zend-i18n/pull/12) updates the
component to the v3 version of zend-eventmanager.
- [#12](https://github.com/zendframework/zend-i18n/pull/12),
[#21](https://github.com/zendframework/zend-i18n/pull/21), and
[#22](https://github.com/zendframework/zend-i18n/pull/22) update the
component to be forwards compatible with the v3 versions of zend-stdlib,
zend-servicemanager, and zend-eventmanager.
34 changes: 16 additions & 18 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,24 @@
"i18n"
],
"homepage": "https://github.com/zendframework/zend-i18n",
"autoload": {
"psr-4": {
"Zend\\I18n\\": "src/"
"extra": {
"branch-alias": {
"dev-master": "2.5-dev",
"dev-develop": "2.6-dev"
}
},
"require": {
"php": ">=5.5",
"zendframework/zend-stdlib": "~2.5"
"php": "^5.5 || ^7.0",
"zendframework/zend-stdlib": "^2.7 || ^3.0"
},
"require-dev": {
"zendframework/zend-cache": "dev-develop as 2.6.0",
"zendframework/zend-config": "~2.5",
"zendframework/zend-eventmanager": "dev-develop as 2.7.0",
"zendframework/zend-filter": "~2.5",
"zendframework/zend-servicemanager": "dev-develop as 2.7.0",
"zendframework/zend-validator": "~2.5",
"zendframework/zend-view": "dev-develop as 2.6.0",
"zendframework/zend-cache": "^2.5",
"zendframework/zend-config": "^2.6",
"zendframework/zend-eventmanager": "^2.6.2 || ^3.0",
"zendframework/zend-filter": "^2.6.1",
"zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3",
"zendframework/zend-validator": "^2.5",
"zendframework/zend-view": "^2.5",
"fabpot/php-cs-fixer": "1.7.*",
"phpunit/PHPUnit": "~4.0"
},
Expand All @@ -38,12 +39,9 @@
"zendframework/zend-view": "You should install this package to use the provided view helpers",
"zendframework/zend-i18n-resources": "Translation resources"
},
"minimum-stability": "dev",
"prefer-stable": true,
"extra": {
"branch-alias": {
"dev-master": "2.5-dev",
"dev-develop": "3.0-dev"
"autoload": {
"psr-4": {
"Zend\\I18n\\": "src/"
}
},
"autoload-dev": {
Expand Down
36 changes: 33 additions & 3 deletions src/Translator/LoaderPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

use Zend\I18n\Exception;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Exception\InvalidServiceException;
use Zend\ServiceManager\Factory\InvokableFactory;

/**
Expand Down Expand Up @@ -64,7 +65,13 @@ class LoaderPluginManager extends AbstractPluginManager
protected $factories = [
Loader\Gettext::class => InvokableFactory::class,
Loader\Ini::class => InvokableFactory::class,
Loader\PhpArray::class => InvokableFactory::class
Loader\PhpArray::class => InvokableFactory::class,
// Legacy (v2) due to alias resolution; canonical form of resolved
// alias is used to look up the factory, while the non-normalized
// resolved alias is used as the requested name passed to the factory.
'zendi18ntranslatorloadergettext' => InvokableFactory::class,
'zendi18ntranslatorloaderini' => InvokableFactory::class,
'zendi18ntranslatorloaderphparray' => InvokableFactory::class
];

/**
Expand All @@ -77,17 +84,40 @@ class LoaderPluginManager extends AbstractPluginManager
* @return void
* @throws Exception\RuntimeException if invalid
*/
public function validatePlugin($plugin)
public function validate($plugin)
{
if ($plugin instanceof Loader\FileLoaderInterface || $plugin instanceof Loader\RemoteLoaderInterface) {
// we're okay
return;
}

throw new Exception\RuntimeException(sprintf(
throw new InvalidServiceException(sprintf(
'Plugin of type %s is invalid; must implement %s\Loader\FileLoaderInterface or %s\Loader\RemoteLoaderInterface',
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
__NAMESPACE__,
__NAMESPACE__
));
}

/**
* Validate the plugin is of the expected type (v2).
*
* Proxies to `validate()`.
*
* @param mixed $plugin
* @throws Exception\RuntimeException
*/
public function validatePlugin($plugin)
{
try {
$this->validate($plugin);
} catch (InvalidServiceException $e) {
throw new Exception\RuntimeException(sprintf(
'Plugin of type %s is invalid; must implement %s\Loader\FileLoaderInterface or %s\Loader\RemoteLoaderInterface',
(is_object($plugin) ? get_class($plugin) : gettype($plugin)),
__NAMESPACE__,
__NAMESPACE__
));
}
}
}
37 changes: 18 additions & 19 deletions src/Translator/Translator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Traversable;
use Zend\Cache;
use Zend\Cache\Storage\StorageInterface as CacheStorage;
use Zend\EventManager\Event;
use Zend\EventManager\EventManager;
use Zend\EventManager\EventManagerInterface;
use Zend\I18n\Exception;
Expand Down Expand Up @@ -449,16 +450,15 @@ protected function getTranslatedMessage(
$until = function ($r) {
return is_string($r);
};
$results = $this->getEventManager()->triggerUntil(
$until,
self::EVENT_MISSING_TRANSLATION,
$this,
[
'message' => $message,
'locale' => $locale,
'text_domain' => $textDomain,
]
);

$event = new Event(self::EVENT_MISSING_TRANSLATION, $this, [
'message' => $message,
'locale' => $locale,
'text_domain' => $textDomain,
]);

$results = $this->getEventManager()->triggerEventUntil($until, $event);

$last = $results->last();
if (is_string($last)) {
return $last;
Expand Down Expand Up @@ -579,15 +579,14 @@ protected function loadMessages($textDomain, $locale)
$until = function ($r) {
return ($r instanceof TextDomain);
};
$results = $this->getEventManager()->triggerUntil(
$until,
self::EVENT_NO_MESSAGES_LOADED,
$this,
[
'locale' => $locale,
'text_domain' => $textDomain,
]
);

$event = new Event(self::EVENT_NO_MESSAGES_LOADED, $this, [
'locale' => $locale,
'text_domain' => $textDomain,
]);

$results = $this->getEventManager()->triggerEventUntil($until, $event);

$last = $results->last();
if ($last instanceof TextDomain) {
$discoveredTextDomain = $last;
Expand Down
33 changes: 22 additions & 11 deletions src/Translator/TranslatorServiceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,42 @@

namespace Zend\I18n\Translator;

use Zend\ServiceManager\Factory\FactoryInterface;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

/**
* Translator.
*/
class TranslatorServiceFactory implements FactoryInterface
{
/*
public function createService(ServiceLocatorInterface $serviceLocator)
/**
* Create a Translator instance.
*
* @param ContainerInterface $container
* @param string $requestedName
* @param null|array $options
* @return Translator
*/
public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
{
// Configure the translator
$config = $serviceLocator->get('Config');
$config = $container->get('config');
$trConfig = isset($config['translator']) ? $config['translator'] : [];
$translator = Translator::factory($trConfig);
return $translator;
}
*/

public function __invoke(ContainerInterface $container, $requestedName, array $options = null)
/**
* zend-servicemanager v2 factory for creating Translator instance.
*
* Proxies to `__invoke()`.
*
* @param ServiceLocatorInterface $serviceLocator
* @returns Translator
*/
public function createService(ServiceLocatorInterface $serviceLocator)
{
// Configure the translator
$config = $container->get('Config');
$trConfig = isset($config['translator']) ? $config['translator'] : [];
$translator = Translator::factory($trConfig);
return $translator;
return $this($serviceLocator, Translator::class);
}
}
75 changes: 63 additions & 12 deletions src/View/HelperConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Zend\I18n\View;

use Zend\ServiceManager\ConfigInterface;
use Zend\ServiceManager\Factory\InvokableFactory;
use Zend\ServiceManager\ServiceManager;

/**
Expand All @@ -18,17 +19,48 @@
class HelperConfig implements ConfigInterface
{
/**
* Pre-aliased view helpers
*
* Common aliases for helpers
* @var array
*/
protected $invokables = [
'currencyformat' => 'Zend\I18n\View\Helper\CurrencyFormat',
'dateformat' => 'Zend\I18n\View\Helper\DateFormat',
'numberformat' => 'Zend\I18n\View\Helper\NumberFormat',
'plural' => 'Zend\I18n\View\Helper\Plural',
'translate' => 'Zend\I18n\View\Helper\Translate',
'translateplural' => 'Zend\I18n\View\Helper\TranslatePlural',
protected $aliases = [
'currencyformat' => Helper\CurrencyFormat::class,
'currencyFormat' => Helper\CurrencyFormat::class,
'CurrencyFormat' => Helper\CurrencyFormat::class,
'dateformat' => Helper\DateFormat::class,
'dateFormat' => Helper\DateFormat::class,
'DateFormat' => Helper\DateFormat::class,
'numberformat' => Helper\NumberFormat::class,
'numberFormat' => Helper\NumberFormat::class,
'NumberFormat' => Helper\NumberFormat::class,
'plural' => Helper\Plural::class,
'Plural' => Helper\Plural::class,
'translate' => Helper\Translate::class,
'Translate' => Helper\Translate::class,
'translateplural' => Helper\TranslatePlural::class,
'translatePlural' => Helper\TranslatePlural::class,
'TranslatePlural' => Helper\TranslatePlural::class,
];

/**
* Factories for included helpers.
* @var array
*/
protected $factories = [
Helper\CurrencyFormat::class => InvokableFactory::class,
Helper\DateFormat::class => InvokableFactory::class,
Helper\NumberFormat::class => InvokableFactory::class,
Helper\Plural::class => InvokableFactory::class,
Helper\Translate::class => InvokableFactory::class,
Helper\TranslatePlural::class => InvokableFactory::class,
// Legacy (v2) due to alias resolution; canonical form of resolved
// alias is used to look up the factory, while the non-normalized
// resolved alias is used as the requested name passed to the factory.
'zendi18nviewhelpercurrencyformat' => InvokableFactory::class,
'zendi18nviewhelperdateformat' => InvokableFactory::class,
'zendi18nviewhelpernumberformat' => InvokableFactory::class,
'zendi18nviewhelperplural' => InvokableFactory::class,
'zendi18nviewhelpertranslate' => InvokableFactory::class,
'zendi18nviewhelpertranslateplural' => InvokableFactory::class,
];

/**
Expand All @@ -40,8 +72,27 @@ class HelperConfig implements ConfigInterface
*/
public function configureServiceManager(ServiceManager $serviceManager)
{
return $serviceManager->withConfig(
[ 'invokables' => $this->invokables ]
);
foreach ($this->factories as $name => $factory) {
$serviceManager->setFactory($name, $factory);
}
foreach ($this->aliases as $alias => $target) {
$serviceManager->setAlias($alias, $target);
}
return $serviceManager;
}

/**
* Cast configuration to an array.
*
* Provided for v3 compatibility
*
* @return array
*/
public function toArray()
{
return [
'aliases' => $this->aliases,
'factories' => $this->factories,
];
}
}
Loading

0 comments on commit dc4d11a

Please sign in to comment.