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
|
|
|
|