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 Dmtx\Reader; |
17
|
|
|
use Dmtx\Writer; |
18
|
|
|
use Maslosoft\Cli\Shared\Os; |
19
|
|
|
use Maslosoft\Addendum\Interfaces\AnnotatedInterface; |
20
|
|
|
use Maslosoft\Addendum\Utilities\ClassChecker; |
21
|
|
|
use Maslosoft\Mangan\Exceptions\ManganException; |
22
|
|
|
use Maslosoft\Mangan\Exceptions\TransformatorException; |
23
|
|
|
use Maslosoft\Mangan\Interfaces\Transformators\TransformatorInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Datamatrix |
27
|
|
|
* |
28
|
|
|
* @author Piotr Maselkowski <pmaselkowski at gmail.com> |
29
|
|
|
*/ |
30
|
|
|
class Datamatrix implements TransformatorInterface |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Returns the given object as an associative array |
35
|
|
|
* @param AnnotatedInterface|object $model |
36
|
|
|
* @param string[] $fields Fields to transform |
37
|
|
|
* @return array an associative array of the contents of this object |
38
|
|
|
*/ |
39
|
1 |
|
public static function fromModel(AnnotatedInterface $model, $fields = []) |
40
|
|
|
{ |
41
|
1 |
|
if(!ClassChecker::exists(Writer::class)) |
42
|
|
|
{ |
43
|
1 |
|
throw new ManganException('Missing php-dmtx library'); |
44
|
|
|
} |
45
|
|
|
assert(Os::commandExists('dmtxwrite')); |
|
|
|
|
46
|
|
|
$data = YamlString::fromModel($model, $fields, 1, 1); |
47
|
|
|
return (new Writer())->encode($data)->dump(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Create document from datamatrix code |
52
|
|
|
* |
53
|
|
|
* @param mixed[] $data |
54
|
|
|
* @param string|object $className |
55
|
|
|
* @param AnnotatedInterface $instance |
56
|
|
|
* @return AnnotatedInterface |
57
|
|
|
* @throws TransformatorException |
58
|
|
|
*/ |
59
|
|
|
public static function toModel($data, $className = null, AnnotatedInterface $instance = null) |
60
|
|
|
{ |
61
|
|
|
if(!ClassChecker::exists(Reader::class)) |
62
|
|
|
{ |
63
|
|
|
throw new ManganException('Missing php-dmtx library'); |
64
|
|
|
} |
65
|
|
|
assert(Os::commandExists('dmtxread')); |
|
|
|
|
66
|
|
|
$data = (new Reader())->decode($data); |
67
|
|
|
return YamlString::toModel($data, $className, $instance); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.