Completed
Push — master ( 67c4a6...e61cbc )
by Aimeos
01:50
created

src/Aimeos/Shop/Base/I18n.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/**
4
 * @license MIT, http://opensource.org/licenses/MIT
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package laravel
7
 * @subpackage Base
8
 */
9
10
namespace Aimeos\Shop\Base;
11
12
13
/**
14
 * Service providing the internationalization objects
15
 *
16
 * @package laravel
17
 * @subpackage Base
18
 */
19
class I18n
20
{
21
	/**
22
	 * @var \Aimeos\Shop\Base\Aimeos
23
	 */
24
	private $aimeos;
25
26
	/**
27
	 * @var \Illuminate\Contracts\Config\Repository
28
	 */
29
	private $config;
30
31
	/**
32
	 * @var array
33
	 */
34
	private $i18n = array();
35
36
37
	/**
38
	 * Initializes the object
39
	 *
40
	 * @param \Illuminate\Contracts\Config\Repository $config Configuration object
41
	 * @param \Aimeos\Shop\Base\Aimeos $aimeos Aimeos object
42
	 */
43
	public function __construct( \Illuminate\Contracts\Config\Repository $config, \Aimeos\Shop\Base\Aimeos $aimeos )
44
	{
45
		$this->aimeos = $aimeos;
46
		$this->config = $config;
47
	}
48
49
50
	/**
51
	 * Creates new translation objects.
52
	 *
53
	 * @param array $languageIds List of two letter ISO language IDs
54
	 * @return \Aimeos\MW\Translation\Iface[] List of translation objects
55
	 */
56
	public function get( array $languageIds )
57
	{
58
		$i18nPaths = $this->aimeos->get()->getI18nPaths();
59
60
		foreach( $languageIds as $langid )
61
		{
62
			if( !isset( $this->i18n[$langid] ) )
63
			{
64
				$i18n = new \Aimeos\MW\Translation\Gettext( $i18nPaths, $langid );
65
66 View Code Duplication
				if( $this->config->get( 'shop.apc_enabled', false ) == true ) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
					$i18n = new \Aimeos\MW\Translation\Decorator\APC( $i18n, $this->config->get( 'shop.apc_prefix', 'laravel:' ) );
68
				}
69
70
				if( $this->config->has( 'shop.i18n.' . $langid ) ) {
71
					$i18n = new \Aimeos\MW\Translation\Decorator\Memory( $i18n, $this->config->get( 'shop.i18n.' . $langid ) );
72
				}
73
74
				$this->i18n[$langid] = $i18n;
75
			}
76
		}
77
78
		return $this->i18n;
79
	}
80
}