Completed
Push — master ( 5ac736...e03d1c )
by Peter
05:20
created

I18NAnnotation::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 11
cts 11
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 10
nc 2
nop 0
crap 2
1
<?php
2
3
/**
4
 * This software package is licensed under AGPL or Commercial license.
5
 *
6
 * @package maslosoft/mangan
7
 * @licence AGPL or Commercial
8
 * @copyright Copyright (c) Piotr Masełkowski <[email protected]>
9
 * @copyright Copyright (c) Maslosoft
10
 * @copyright Copyright (c) Others as mentioned in code
11
 * @link https://maslosoft.com/mangan/
12
 */
13
14
namespace Maslosoft\Mangan\Annotations;
15
16
use InvalidArgumentException;
17
use Maslosoft\Addendum\Helpers\ParamsExpander;
18
use Maslosoft\Mangan\Decorators\Property\I18NDecorator;
19
use Maslosoft\Mangan\Meta\I18NMeta;
20
use Maslosoft\Mangan\Meta\ManganPropertyAnnotation;
21
use Maslosoft\ManganTest\Models\ModelWithI18NAllowAnyAndDefault;
22
23
/**
24
 * This annotation indicates internationalized fields
25
 * @template I18N
26
 * @Target('property')
27
 * @author Piotr
28
 */
29
class I18NAnnotation extends ManganPropertyAnnotation
30
{
31
32
	public $value = [];
33
34
	public $allowDefault = null;
35
36
	public $allowAny = null;
37
38 8
	public function init()
39
	{
40 8
		$data = ParamsExpander::expand($this, ['allowDefault', 'allowAny']);
41 8
		foreach ($data as $name => $value)
42
		{
43 2
			$this->$name = $value;
44
		}
45
46 8
		$i18n = new I18NMeta();
47 8
		$i18n->enabled = true;
48 8
		$i18n->allowDefault = (bool)$this->allowDefault;
49 8
		$i18n->allowAny = (bool)$this->allowAny;
50 8
		$this->getEntity()->i18n = $i18n;
51
52 8
		$this->getEntity()->decorators[] = I18NDecorator::class;
53 8
	}
54
55
}
56