Example #1
0
 /**
  * {@inheritdoc}
  */
 public function getMapping($reverse = false, $reload = false)
 {
     if (is_null($this->_mapping) || $reload) {
         $this->_mapping = array();
         $this->_primary_keys = array();
         $reflector = new \ReflectionClass($this);
         $reader = new AnnotationReader();
         foreach ($reflector->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
             $annotations = $reader->getPropertyAnnotations($property);
             if (isset($annotations->db_ref)) {
                 $db_ref = $annotations->db_ref;
                 $this->_mapping[$property->getName()] = (string) $db_ref;
                 if (isset($annotations->pk)) {
                     $key = (string) $db_ref;
                     $strategy = isset($annotations->strategy) ? (string) $annotations->strategy : 'auto';
                     if ($strategy != 'auto' && $strategy != 'manual') {
                         throw new InvalidStrategyException(sprintf('The primary key strategy must be auto or manual'));
                     }
                     $this->_primary_keys[] = array('key' => $key, 'strategy' => $strategy);
                 }
             }
         }
     }
     return $reverse ? array_flip($this->_mapping) : $this->_mapping;
 }
Example #2
0
 /**
  * @depends testInitialize
  * @param Reader $reader
  */
 public function testGetPropertyAnnotations($reader)
 {
     $reflector = new \ReflectionProperty('CustomTestClass', 'name');
     $this->assertNotNull($reader->getPropertyAnnotations($reflector));
 }