Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 76df592a6b
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 82 lines (64 sloc) 1.908 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
<?php

namespace DMS\Filter\Mapping\Loader;

use Doctrine\Common\Annotations\Reader,
    DMS\Filter\Rules;

/**
* Loader that reads filtering data from Annotations
*
* @package DMS
* @subpackage Filter
*/
class AnnotationLoader implements LoaderInterface
{
    /**
*
* @var Doctrine\Common\Annotations\Reader
*/
    protected $reader;
    
    /**
* Constructor
*
* @param Doctrine\Common\Annotations\Reader $reader
*/
    public function __construct(Reader $reader)
    {
        $this->reader = $reader;
    }
    
    /**
* Loads annotations data present in the class, using a Doctrine
* annotation reader
*
* @param ClassMetadata $metadata
*/
    public function loadClassMetadata(ClassMetadata $metadata)
    {
        
        $reflClass = $metadata->getReflectionClass();
        
        //Iterate over properties to get annotations
        foreach($reflClass->getProperties() as $property) {
            
            $this->readProperty($property, $metadata);
            
        }
        
    }
    
    /**
* Reads annotations for a selected property in the class
*
* @param ReflectionProperty $property
* @param ClassMetadata $metadata
*/
    private function readProperty($property, $metadata)
    {
        $reflClass = $metadata->getReflectionClass();
        
        // Skip if this property is not from this class
        if ($property->getDeclaringClass()->getName()
            != $reflClass->getClassName()
        ) {
            return;
        }

        //Iterate over all annotations
        foreach($this->reader->getPropertyAnnotations($property) as $rule) {

            //Skip is its not a rule
            if ( ! $rule instanceof Rules\Rule ) continue;
            
            //Add Rule
            $metadata->addPropertyRule($property->getName(), $rule);

        }

    }

}
Something went wrong with that request. Please try again.