1 | <?php |
||
45 | class MicroformatsFactory |
||
46 | { |
||
47 | /** |
||
48 | * Microformats 2 profile URI |
||
49 | * |
||
50 | * @var string |
||
51 | * @link http://microformats.org/wiki/microformats-2# |
||
52 | */ |
||
53 | const MF2_PROFILE_URI = 'http://microformats.org/profile/'; |
||
54 | |||
55 | /** |
||
56 | * Refine an item |
||
57 | * |
||
58 | * @param array $item Item |
||
59 | * @return \stdClass Refined item |
||
60 | */ |
||
61 | 3 | protected static function createItem(array $item) |
|
62 | { |
||
63 | 3 | $microformatItem = ['type' => self::createTypes($item['type'])]; |
|
64 | |||
65 | // Create the properties (if any) |
||
66 | 3 | if (isset($item['properties']) && is_array($item['properties'])) { |
|
67 | 3 | $microformatItem['properties'] = self::createProperties($item['properties']); |
|
68 | } |
||
69 | |||
70 | // Create the value (if any) |
||
71 | 3 | if (isset($item['value'])) { |
|
72 | 3 | $microformatItem['value'] = self::createValue($item['value']); |
|
73 | } |
||
74 | |||
75 | // Create the nested children (if any) |
||
76 | 3 | if (isset($item['children']) && is_array($item['children'])) { |
|
77 | 1 | $microformatItem['children'] = self::createFromParserResult($item['children']); |
|
78 | } |
||
79 | |||
80 | 3 | return (object)$microformatItem; |
|
81 | } |
||
82 | |||
83 | /** |
||
84 | * Refine the item types |
||
85 | * |
||
86 | * @param array $types Types |
||
87 | * @return array Refined types |
||
88 | */ |
||
89 | 3 | protected static function createTypes(array $types) |
|
97 | |||
98 | /** |
||
99 | * Refine the item properties |
||
100 | * |
||
101 | * @param array $properties Properties |
||
102 | * @return array Refined properties |
||
103 | */ |
||
104 | 3 | protected static function createProperties(array $properties) |
|
116 | |||
117 | /** |
||
118 | * Refine the item property values |
||
119 | * |
||
120 | * @param array $propertyValues Property values |
||
121 | * @return array Refined property values |
||
122 | */ |
||
123 | 3 | protected static function createProperty(array $propertyValues) |
|
134 | |||
135 | /** |
||
136 | * Refine the item value |
||
137 | * |
||
138 | * @param string $value Value |
||
139 | * @return string Refined value |
||
140 | */ |
||
141 | 3 | protected static function createValue($value) |
|
145 | |||
146 | /** |
||
147 | * Refine and convert the Microformats parser result |
||
148 | * |
||
149 | * @param array $items Items |
||
150 | * @return array Refined items |
||
151 | */ |
||
152 | 3 | public static function createFromParserResult(array $items) |
|
156 | } |
||
157 |