Esempio n. 1
0
 /**
  * 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() != $metadata->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);
     }
 }
 public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
 {
     if (!in_array(SoftDeletable::class, $targetEntity->reflClass->getInterfaceNames())) {
         return '';
     }
     $class = $targetEntity->getReflectionClass();
     $reader = new AnnotationReader();
     $constraint = '';
     $isFirst = true;
     foreach ($class->getProperties() as $property) {
         if ($reader->getPropertyAnnotation($property, SoftDeletableMapping::class) !== null) {
             $constraint .= ($isFirst ? '' : ' AND ') . $targetTableAlias . '.' . $targetEntity->getColumnName($property->getName()) . ' IS NULL';
             $isFirst = false;
         }
     }
     return $constraint;
 }
 public function addFilterCriteria(ClassMetadata $targetDocument)
 {
     if (empty($this->reader)) {
         return '';
     }
     // The Doctrine filter is called for any query on any entity
     // Check if the current entity is "user aware" (marked with an annotation)
     $recordState = $this->reader->getClassAnnotation($targetDocument->getReflectionClass(), 'GreGosPhaTos\\DoctrineFiltersBundle\\Doctrine\\Annotation\\RecordState');
     if (!$recordState) {
         return '';
     }
     $stateFieldName = $recordState->stateFieldName;
     $activeValue = $recordState->activeValue;
     if (empty($stateFieldName) || empty($activeValue)) {
         return '';
     }
     return array($stateFieldName => $activeValue);
 }
 public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
 {
     if (empty($this->reader)) {
         return '';
     }
     // The Doctrine filter is called for any query on any entity
     // Check if the current entity is "active" (marked with an annotation)
     $recordState = $this->reader->getClassAnnotation($targetEntity->getReflectionClass(), 'GreGosPhaTos\\DoctrineFiltersBundle\\Doctrine\\Annotation\\RecordState');
     if (!$recordState) {
         return '';
     }
     $stateFieldName = $recordState->stateFieldName;
     $activeValue = $recordState->activeValue;
     if (empty($stateFieldName) || empty($activeValue)) {
         return '';
     }
     $query = sprintf('%s.%s = "%s"', $targetTableAlias, $stateFieldName, $activeValue);
     return $query;
 }
 /**
  * Gets the locale to use for translation. Loads object
  * defined locale first..
  *
  * @param object $object
  * @param ClassMetadata $meta
  * @throws RuntimeException - if language or locale property is not
  *         found in entity
  * @return string
  */
 public function getTranslatableLocale($object, $meta)
 {
     $locale = $this->locale;
     if (isset($this->configurations[$meta->name]['locale'])) {
         $class = $meta->getReflectionClass();
         $reflectionProperty = $class->getProperty($this->configurations[$meta->name]['locale']);
         if (!$reflectionProperty) {
             $column = $this->configurations[$meta->name]['locale'];
             throw new \Gedmo\Exception\RuntimeException("There is no locale or language property ({$column}) found on object: {$meta->name}");
         }
         $reflectionProperty->setAccessible(true);
         $value = $reflectionProperty->getValue($object);
         if (is_string($value) && strlen($value)) {
             $locale = $value;
         }
     }
     $this->validateLocale($locale);
     return strtolower($locale);
 }