Completed
Push — master ( c1ad5e...1443d8 )
by Peter
08:22
created

RawArray::fromModel()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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\Transformers;
15
16
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
17
use Maslosoft\Mangan\AspectManager;
18
use Maslosoft\Mangan\Interfaces\Transformators\TransformatorInterface;
19
20
/**
21
 * This transformer is by default configured to store document in database.
22
 * 
23
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
24
 */
25
class RawArray extends Transformer implements TransformatorInterface
26
{
27
	const AspectRawArrayFromModel = 'AspectRawArrayFromModel';
28
	const AspectRawArrayToModel = 'AspectRawArrayToModel';
29
30 128
	public static function fromModel(AnnotatedInterface $model, $fields = [])
31
	{
32 128
		AspectManager::addAspect($model, self::AspectRawArrayFromModel);
33 128
		$data = parent::fromModel($model, $fields);
34 127
		AspectManager::removeAspect($model, self::AspectRawArrayFromModel);
35 127
		return $data;
36
	}
37
38 91
	public static function toModel($data, $className = null, AnnotatedInterface $instance = null, AnnotatedInterface $parent = null, $parentField = '')
39
	{
40 91
		AspectManager::addAspect($instance, self::AspectRawArrayToModel);
41 91
		$model = parent::toModel($data, $className, $instance, $parent, $parentField);
42 91
		AspectManager::removeAspect($instance, self::AspectRawArrayToModel);
43 91
		AspectManager::removeAspect($model, self::AspectRawArrayToModel);
44 91
		return $model;
45
	}
46
}
47