1
|
|
|
<?php |
2
|
|
|
//[PHPCOMPRESSOR(remove,start)] |
3
|
|
|
/** |
4
|
|
|
* Created by Vitaly Iegorov <[email protected]>. |
5
|
|
|
* on 23.03.16 at 11:45 |
6
|
|
|
*/ |
7
|
|
|
namespace samsoncms\api\generator\analyzer; |
8
|
|
|
|
9
|
|
|
use samsoncms\api\Field; |
10
|
|
|
use samsoncms\api\generator\exception\ParentEntityNotFound; |
11
|
|
|
use samsoncms\api\Navigation; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Generic entities metadata analyzer. |
15
|
|
|
* |
16
|
|
|
* @package samsoncms\api\analyzer |
17
|
|
|
*/ |
18
|
|
|
class Gallery extends Virtual |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* Analyze virtual entities and gather their metadata. |
22
|
|
|
* |
23
|
|
|
* @return \samsoncms\api\generator\metadata\Virtual[] |
24
|
|
|
* @throws ParentEntityNotFound |
25
|
|
|
*/ |
26
|
|
|
public function analyze() |
27
|
|
|
{ |
28
|
|
|
$metadataCollection = []; |
29
|
|
|
|
30
|
|
|
// Iterate all structures, parents first |
31
|
|
|
foreach ($this->getVirtualEntities() as $structureRow) { |
32
|
|
|
// Fill in entity metadata |
33
|
|
|
$metadata = new \samsoncms\api\generator\metadata\Gallery(); |
34
|
|
|
$navigationID = $structureRow[Navigation::F_PRIMARY]; |
35
|
|
|
|
36
|
|
|
// Iterate entity fields |
37
|
|
|
foreach ($this->getEntityFields($navigationID) as $fieldID => $fieldRow) { |
38
|
|
|
// We need only gallery fields |
39
|
|
|
if ((int)$fieldRow[Field::F_TYPE] === Field::TYPE_GALLERY) { |
40
|
|
|
$metadata->parentClassName = $this->entityName($structureRow[Navigation::F_NAME]); |
|
|
|
|
41
|
|
|
// Avoid GalleryGallery |
42
|
|
|
$metadata->entity = ucfirst($this->fieldName($fieldRow[Field::F_IDENTIFIER])); |
43
|
|
|
// Avoid GalleryGallery |
44
|
|
|
$metadata->entity = $metadata->entity !== 'Gallery' ? $metadata->entity . 'Gallery' : $metadata->entity; |
45
|
|
|
// Prepend Entity name |
46
|
|
|
$metadata->entity = $metadata->parentClassName.$metadata->entity; |
47
|
|
|
$metadata->entityClassName = $this->fullEntityName($metadata->entity); |
48
|
|
|
$metadata->realName = $fieldRow[Field::F_IDENTIFIER]; |
49
|
|
|
$metadata->fieldID = $fieldID; |
|
|
|
|
50
|
|
|
$metadata->parentID = $navigationID; |
51
|
|
|
|
52
|
|
|
// Store metadata by entity identifier |
53
|
|
|
$metadataCollection[$navigationID] = $metadata; |
54
|
|
|
|
55
|
|
|
// Store global collection |
56
|
|
|
self::$metadata[$navigationID] = $metadata; |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $metadataCollection; |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
//[PHPCOMPRESSOR(remove,end)] |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.