|
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 http://maslosoft.com/mangan/ |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Maslosoft\Mangan\Transformers; |
|
15
|
|
|
|
|
16
|
|
|
use Maslosoft\Addendum\Interfaces\AnnotatedInterface; |
|
17
|
|
|
use Maslosoft\Mangan\Exceptions\TransformatorException; |
|
18
|
|
|
use Maslosoft\Mangan\Interfaces\Transformators\TransformatorInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Datamatrix |
|
22
|
|
|
* |
|
23
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
|
24
|
|
|
*/ |
|
25
|
|
|
class Datamatrix implements TransformatorInterface |
|
26
|
|
|
{ |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Returns the given object as an associative array |
|
30
|
|
|
* @param AnnotatedInterface|object $model |
|
31
|
|
|
* @param string[] $fields Fields to transform |
|
32
|
|
|
* @return array an associative array of the contents of this object |
|
33
|
|
|
*/ |
|
34
|
2 |
|
public static function fromModel(AnnotatedInterface $model, $fields = []) |
|
35
|
|
|
{ |
|
36
|
2 |
|
$data = YamlString::fromModel($model, $fields, 1, 1); |
|
37
|
2 |
|
return (new \Dmtx\Writer())->encode($data)->dump(); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* Create document from array |
|
42
|
|
|
* |
|
43
|
|
|
* @param mixed[] $data |
|
44
|
|
|
* @param string|object $className |
|
45
|
|
|
* @param AnnotatedInterface $instance |
|
46
|
|
|
* @return AnnotatedInterface |
|
47
|
|
|
* @throws TransformatorException |
|
48
|
|
|
*/ |
|
49
|
|
|
public static function toModel($data, $className = null, AnnotatedInterface $instance = null) |
|
50
|
|
|
{ |
|
51
|
|
|
$data = (new \Dmtx\Reader())->decode($data); |
|
52
|
|
|
return YamlString::toModel($data, $className, $instance); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
} |
|
56
|
|
|
|