상속: extends Exceptio\Exception
예제 #1
0
 /**
  * @param string $className
  * @param ClassMetadata|\Doctrine\Search\Mapping\ClassMetadata $metadata
  *
  * @throws \ReflectionException
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata)
 {
     $class = $metadata->getReflectionClass();
     if (!$class) {
         $class = new \ReflectionClass((string) $className);
     }
     $classAnnotations = $this->reader->getClassAnnotations($class);
     $classMapping = array();
     $validMapping = false;
     foreach ($classAnnotations as $annotation) {
         switch (get_class($annotation)) {
             case 'Doctrine\\Search\\Mapping\\Annotations\\ElasticSearchable':
                 $classMapping = (array) $annotation;
                 $classMapping['class'] = 'ElasticSearchable';
                 $validMapping = true;
                 break;
             case 'Doctrine\\Search\\Mapping\\Annotations\\Searchable':
                 $classMapping = (array) $annotation;
                 $classMapping['class'] = 'Searchable';
                 $validMapping = true;
                 break;
             case 'Doctrine\\Search\\Mapping\\Annotations\\ElasticRoot':
                 $rootMapping = (array) $annotation;
                 $metadata->mapRoot($this->rootToArray($rootMapping));
                 break;
         }
     }
     if (!$validMapping) {
         throw MappingException::classIsNotAValidDocument($className);
     }
     $this->annotateClassMetadata($classMapping, $metadata);
     $properties = $class->getProperties();
     foreach ($properties as $property) {
         $propertyAnnotations = $this->reader->getPropertyAnnotations($property);
         foreach ($propertyAnnotations as $annotation) {
             switch (get_class($annotation)) {
                 case 'Doctrine\\Search\\Mapping\\Annotations\\Id':
                     $metadata->identifier = $property->getName();
                     break;
                 case 'Doctrine\\Search\\Mapping\\Annotations\\Parameter':
                     $mapping = $this->parameterToArray($property->getName(), (array) $annotation);
                     $metadata->mapParameter($mapping);
                     break;
                 case 'Doctrine\\Search\\Mapping\\Annotations\\Field':
                 case 'Doctrine\\Search\\Mapping\\Annotations\\ElasticField':
                 case 'Doctrine\\Search\\Mapping\\Annotations\\SolrField':
                     $mapping = $this->fieldToArray($property->getName(), (array) $annotation);
                     $metadata->mapField($mapping);
                     break;
             }
         }
     }
 }
예제 #2
0
 /**
  * Adds a mapped parameter to the class.
  *
  * @param array $mapping The parameter mapping.
  * @throws MappingException
  * @return void
  */
 public function mapParameter(array $mapping)
 {
     if (isset($this->fieldMappings[$mapping['parameterName']])) {
         throw MappingException::duplicateParameterMapping($this->className, $mapping['parameterName']);
     }
     $this->parameters[$mapping['parameterName']] = $mapping;
 }
예제 #3
0
 private function annotateClassMetadata($classMapping, $metadata)
 {
     $className = $classMapping['class'];
     switch ($className) {
         case 'ElasticSearchable':
             if (isset($classMapping['numberOfShards'])) {
                 $metadata->numberOfShards = $classMapping['numberOfShards'];
             }
             if (isset($classMapping['numberOfReplicas'])) {
                 $metadata->numberOfReplicas = $classMapping['numberOfReplicas'];
             }
             if (isset($classMapping['parent'])) {
                 $metadata->parent = $classMapping['parent'];
             }
             if (isset($classMapping['timeToLive'])) {
                 $metadata->timeToLive = $classMapping['timeToLive'];
             }
             if (isset($classMapping['boost'])) {
                 $metadata->boost = $classMapping['boost'];
             }
             if (isset($classMapping['source'])) {
                 $metadata->source = $classMapping['source'];
             }
             // no break
         // no break
         case 'Searchable':
             if (isset($classMapping['index'])) {
                 $metadata->index = $classMapping['index'];
             }
             if (isset($classMapping['type'])) {
                 $metadata->type = $classMapping['type'];
             }
             break;
         default:
             throw MappingException::classIsNotAValidDocument($className);
     }
 }