コード例 #1
0
 public function testExtendLoadMetadataForClass()
 {
     $doctrineClassMetadata = $this->em->getClassMetadata('Oro\\Bundle\\DataAuditBundle\\Tests\\Unit\\Fixture\\LoggableClass');
     $nameProperty = new PropertyMetadata('Oro\\Bundle\\DataAuditBundle\\Tests\\Unit\\Fixture\\LoggableClass', 'name');
     $nameProperty->method = '__toString';
     $collectionProperty = new PropertyMetadata('Oro\\Bundle\\DataAuditBundle\\Tests\\Unit\\Fixture\\LoggableClass', 'collection');
     $collectionProperty->method = '__toString';
     $collectionProperty->isCollection = true;
     $collectionWithMethodNameProperty = new PropertyMetadata('Oro\\Bundle\\DataAuditBundle\\Tests\\Unit\\Fixture\\LoggableClass', 'collectionWithMethodName');
     $collectionWithMethodNameProperty->isCollection = true;
     $collectionWithMethodNameProperty->method = 'getName';
     $metadata = new BaseClassMetadata('Oro\\Bundle\\DataAuditBundle\\Tests\\Unit\\Fixture\\LoggableClass');
     $metadata->addPropertyMetadata($nameProperty);
     $metadata->addPropertyMetadata($collectionProperty);
     $metadata->addPropertyMetadata($collectionWithMethodNameProperty);
     $annotationDriver = new AnnotationDriver(new AnnotationReader());
     $resultMetadata = $annotationDriver->extendLoadMetadataForClass($doctrineClassMetadata);
     $metadata->createdAt = $resultMetadata->createdAt;
     $this->assertEquals($metadata, $resultMetadata);
 }
コード例 #2
0
ファイル: AnnotationDriver.php プロジェクト: Maksold/platform
 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass(\ReflectionClass $class)
 {
     $classMetadata = new ClassMetadata($class->getName());
     /** @var Loggable $loggable */
     $loggable = $this->reader->getClassAnnotation($class, self::LOGGABLE);
     foreach ($class->getProperties() as $reflectionProperty) {
         /** @var Versioned $versioned */
         if ($versioned = $this->reader->getPropertyAnnotation($reflectionProperty, self::VERSIONED)) {
             $propertyMetadata = new PropertyMetadata($class->getName(), $reflectionProperty->getName());
             $propertyMetadata->method = $versioned->method ? $versioned->method : '__toString';
             $classMetadata->addPropertyMetadata($propertyMetadata);
         }
     }
     if (count($classMetadata->propertyMetadata) && (!$loggable && !$class->getParentClass())) {
         throw new \InvalidArgumentException(sprintf("Class must be annoted with Loggable annotation in order to track versioned fields in class - %s", $classMetadata->name));
     }
     if (count($classMetadata->propertyMetadata)) {
         return $classMetadata;
     } else {
         return null;
     }
 }
コード例 #3
0
ファイル: LoggableManager.php プロジェクト: xamin123/platform
 protected function checkAuditable($entityClassName)
 {
     if ($this->auditConfigProvider->hasConfig($entityClassName) && $this->auditConfigProvider->getConfig($entityClassName)->is('auditable')) {
         $reflection = new \ReflectionClass($entityClassName);
         $classMetadata = new ClassMetadata($reflection->getName());
         foreach ($reflection->getProperties() as $reflectionProperty) {
             $fieldName = $reflectionProperty->getName();
             if ($this->auditConfigProvider->hasConfig($entityClassName, $fieldName) && ($fieldConfig = $this->auditConfigProvider->getConfig($entityClassName, $fieldName)) && $fieldConfig->is('auditable')) {
                 $propertyMetadata = new PropertyMetadata($entityClassName, $reflectionProperty->getName());
                 $propertyMetadata->method = '__toString';
                 $classMetadata->addPropertyMetadata($propertyMetadata);
             }
         }
         if (count($classMetadata->propertyMetadata)) {
             $this->addConfig($classMetadata);
             return true;
         }
     }
     return false;
 }