1 | <?php |
||
2 | |||
3 | declare(strict_types=1); |
||
4 | |||
5 | namespace WsdlToPhp\PackageGenerator\File; |
||
6 | |||
7 | use WsdlToPhp\PackageGenerator\Generator\Utils as GeneratorUtils; |
||
8 | use WsdlToPhp\PackageGenerator\Model\AbstractModel; |
||
9 | use WsdlToPhp\PhpGenerator\Element\PhpAnnotation; |
||
10 | use WsdlToPhp\PhpGenerator\Element\PhpAnnotationBlock; |
||
11 | |||
12 | final class Utils |
||
13 | { |
||
14 | 166 | public static function defineModelAnnotationsFromWsdl(PhpAnnotationBlock $block, AbstractModel $model, array $ignoreMeta = []): void |
|
15 | { |
||
16 | 166 | $validMeta = self::getValidMetaValues($model, $ignoreMeta); |
|
17 | 166 | if (!empty($validMeta)) { |
|
18 | // First line is the "The {propertyName}" |
||
19 | 126 | if (1 === count($block->getChildren())) { |
|
20 | 124 | $block->addChild('Meta information extracted from the WSDL'); |
|
21 | } |
||
22 | |||
23 | 126 | foreach ($validMeta as $meta) { |
|
24 | 126 | $block->addChild(new PhpAnnotation(PhpAnnotation::NO_NAME, $meta, AbstractModelFile::ANNOTATION_META_LENGTH)); |
|
25 | } |
||
26 | } |
||
27 | } |
||
28 | |||
29 | 166 | public static function getValidMetaValues(AbstractModel $model, array $ignoreMeta = []): array |
|
30 | { |
||
31 | 166 | $meta = $model->getMeta(); |
|
32 | 166 | $validMeta = []; |
|
33 | 166 | foreach ($meta as $metaName => $metaValue) { |
|
34 | 136 | if (in_array($metaName, $ignoreMeta, true)) { |
|
35 | 12 | continue; |
|
36 | } |
||
37 | |||
38 | 126 | $finalMeta = self::getMetaValueAnnotation($metaName, $metaValue); |
|
39 | 126 | if (is_scalar($finalMeta)) { |
|
40 | 126 | $validMeta[] = $finalMeta; |
|
41 | } |
||
42 | } |
||
43 | |||
44 | 166 | return $validMeta; |
|
45 | } |
||
46 | |||
47 | 126 | public static function getMetaValueAnnotation(string $metaName, $metaValue): ?string |
|
48 | { |
||
49 | 126 | $meta = null; |
|
50 | 126 | if (is_array($metaValue)) { |
|
51 | 66 | $metaValue = implode(' | ', array_unique($metaValue)); |
|
52 | } |
||
53 | |||
54 | 126 | $metaValue = GeneratorUtils::cleanComment($metaValue, ', ', false === mb_stripos($metaName, 'SOAPHeader')); |
|
55 | 126 | if (is_scalar($metaValue)) { |
|
0 ignored issues
–
show
introduced
by
![]() |
|||
56 | 126 | $meta = sprintf("\t- %s: %s", $metaName, $metaValue); |
|
57 | } |
||
58 | |||
59 | 126 | return $meta; |
|
60 | } |
||
61 | } |
||
62 |