Completed
Pull Request — develop (#27)
by Chris
13:09
created

AbstractMetadatas::generateMetadata()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
3
namespace Chrisyue\PhpM3u8\Model\Mapping;
4
5
abstract class AbstractMetadatas implements \IteratorAggregate
6
{
7
    protected $annotationReader;
8
    protected $metadatas = [];
9
10
    public function get($key)
11
    {
12
        if (isset($this->metadatas[$key])) {
13
            return $this->metadatas[$key];
14
        }
15
    }
16
17
    public function getByPropertyName($name)
18
    {
19
        foreach ($this->metadatas as $metadata) {
20
            if ($name === $metadata->getProperty()->getName()) {
21
                return $metadata;
22
            }
23
        }
24
    }
25
26
    public function getIterator()
27
    {
28
        return new \ArrayIterator($this->metadatas);
29
    }
30
31
    protected function load($class)
32
    {
33
        $refClass = new \ReflectionClass($class);
34
35
        foreach ($refClass->getProperties() as $refProp) {
36
            foreach ($this->annotationReader->getPropertyAnnotations($refProp) as $annot) {
37
                $this->generateMetadata($refProp, $annot);
38
            }
39
        }
40
    }
41
42
    abstract protected function generateMetadata(\ReflectionProperty $refProp, $annot);
43
}
44