I18n::get()   B
last analyzed

Complexity

Conditions 7
Paths 18

Size

Total Lines 26
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 7
eloc 12
c 2
b 0
f 0
nc 18
nop 1
dl 0
loc 26
rs 8.8333
1
<?php
2
3
/**
4
 * @license LGPLv3, http://www.gnu.org/copyleft/lgpl.html
5
 * @copyright Aimeos (aimeos.org), 2015-2016
6
 * @package flow
7
 * @subpackage Base
8
 */
9
10
11
namespace Aimeos\Shop\Base;
12
13
use Neos\Flow\Annotations as Flow;
14
15
16
/**
17
 * Class providing the internationalization objects
18
 *
19
 * @package flow
20
 * @subpackage Base
21
 * @Flow\Scope("singleton")
22
 */
23
class I18n
24
{
25
	/**
26
	 * @var array
27
	 */
28
	private $settings;
29
30
	/**
31
	 * @var array List of \Aimeos\MW\Translation\Iface objects
32
	 */
33
	private $i18n = array();
34
35
	/**
36
	 * @var \Aimeos\Shop\Base\Aimeos
37
	 * @Flow\Inject
38
	 */
39
	protected $aimeos;
40
41
42
	/**
43
	 * Creates new translation objects.
44
	 *
45
	 * @param array $languageIds List of two letter ISO language IDs
46
	 * @return \Aimeos\MW\Translation\Iface[] List of translation objects
47
	 */
48
	public function get( array $languageIds )
49
	{
50
		$i18nPaths = $this->aimeos->get()->getI18nPaths();
51
52
		foreach( $languageIds as $langid )
53
		{
54
			if( !isset( $this->i18n[$langid] ) )
55
			{
56
				$i18n = new \Aimeos\MW\Translation\Gettext( $i18nPaths, $langid );
57
58
				$apc = (bool) ( isset( $this->settings['flow']['apc']['enable'] ) ? $this->settings['flow']['apc']['enable'] : false );
59
				$prefix = (string) ( isset( $this->settings['flow']['apc']['prefix'] ) ? $this->settings['flow']['apc']['prefix'] : 'flow:' );
60
61
				if( $apc === true ) {
62
					$i18n = new \Aimeos\MW\Translation\Decorator\APC( $i18n, $prefix );
63
				}
64
65
				if( isset( $this->settings['i18n'][$langid] ) ) {
66
					$i18n = new \Aimeos\MW\Translation\Decorator\Memory( $i18n, $this->settings['i18n'][$langid] );
67
				}
68
69
				$this->i18n[$langid] = $i18n;
70
			}
71
		}
72
73
		return $this->i18n;
74
	}
75
76
77
	/**
78
	 * Inject the settings
79
	 *
80
	 * @param array $settings
81
	 * @return void
82
	 */
83
	public function injectSettings( array $settings )
84
	{
85
		$this->settings = $settings;
86
	}
87
}
88