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
|
|
|
* DocumentArray |
22
|
|
|
* |
23
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
24
|
|
|
*/ |
25
|
|
|
class DocumentArray extends Transformer implements TransformatorInterface |
26
|
|
|
{ |
27
|
|
|
const AspectDocumentArrayFromModel = 'AspectDocumentArrayFromModel'; |
28
|
|
|
const AspectDocumentArrayToModel = 'AspectDocumentArrayToModel'; |
29
|
|
|
|
30
|
1 |
|
public static function fromModel(AnnotatedInterface $model, $fields = []) |
31
|
|
|
{ |
32
|
1 |
|
AspectManager::addAspect($model, self::AspectDocumentArrayFromModel); |
33
|
1 |
|
$data = parent::fromModel($model, $fields); |
34
|
1 |
|
AspectManager::removeAspect($model, self::AspectDocumentArrayFromModel); |
35
|
1 |
|
return $data; |
36
|
|
|
} |
37
|
|
|
|
38
|
4 |
|
public static function toModel($data, $className = null, AnnotatedInterface $instance = null, AnnotatedInterface $parent = null, $parentField = '') |
39
|
|
|
{ |
40
|
4 |
|
AspectManager::addAspect($instance, self::AspectDocumentArrayToModel); |
41
|
4 |
|
$model = parent::toModel($data, $className, $instance, $parent, $parentField); |
42
|
4 |
|
AspectManager::removeAspect($instance, self::AspectDocumentArrayToModel); |
43
|
4 |
|
AspectManager::removeAspect($model, self::AspectDocumentArrayToModel); |
44
|
4 |
|
return $model; |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|