Completed
Pull Request — master (#4)
by
unknown
02:12
created

Annotations::getAnnotation()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
cc 2
eloc 16
nc 2
nop 1
1
<?php
2
3
/**
4
 * Copyright (c) 2017. Este código foi feito por @marciioluucas, sob licença MIT
5
 */
6
namespace phiber\util;
7
8
/**
9
 * A classe Annotations é responsável por pegar por reflexão os comentários de mapeamento das classes.
10
 * 
11
 * @package util
12
 */
13
class Annotations 
14
{
15
    /**
16
     * Recupera os comentários de mapeamentos das classes de modelo.
17
     * 
18
     * @param $object
19
     * Retorna um array de atributos
20
     * @return array
21
     */
22
    final public static function getAnnotation($object)
23
    {
24
        $funReflec = new FuncoesReflections();
25
        
26
        $output = array();
27
        
28
        $pattern = '/@+_+[A-z]\w+=\w+/';
29
        
30
        $fullComments = $funReflec->retornaComentariosAtributos($object);
31
        $attribuites   = $funReflec->pegaAtributosDoObjeto($object);
32
        
33
        $annotationsList = [];
34
        
35
        $limit    = count($attribuites);
36
        $iterator = 0;
37
        for ($iterator; $iterator < $limit; $iterator++) {
38
            
39
            preg_match_all(
40
                $pattern,
41
                $fullComments[$attribuites[$iterator]],
42
                $output
43
            );
44
45
            $annotationsList[ $attribuites[$iterator] ] = $output[0];
46
        }
47
48
        return $annotationsList;
49
    }
50
}
51