/** * @param \Doctrine\ORM\Event\LoadClassMetadataEventArgs $eventArgs * @throws AnnotationException */ public function loadClassMetadata(LoadClassMetadataEventArgs $eventArgs) { $reader = new AnnotationReader(); $meta = $eventArgs->getClassMetadata(); foreach ($meta->getReflectionClass()->getProperties() as $property) { if ($meta->isMappedSuperclass && !$property->isPrivate() || $meta->isInheritedField($property->name) || isset($meta->associationMappings[$property->name]['inherited'])) { continue; } if ($annotation = $reader->getPropertyAnnotation($property, 'Leapt\\CoreBundle\\Doctrine\\Mapping\\File')) { $property->setAccessible(true); $field = $property->getName(); if (null === $annotation->mappedBy) { throw AnnotationException::requiredError('mappedBy', 'LeaptCore\\File', $meta->getReflectionClass()->getName(), 'another class property to map onto'); } if (null === $annotation->path && null === $annotation->pathCallback) { throw AnnotationException::syntaxError(sprintf('Annotation @%s declared on %s expects "path" or "pathCallback". One of them should not be null.', 'LeaptCore\\File', $meta->getReflectionClass()->getName())); } if (!$meta->hasField($annotation->mappedBy)) { throw AnnotationException::syntaxError(sprintf('The entity "%s" has no field named "%s", but it is documented in the annotation @%s', $meta->getReflectionClass()->getName(), $annotation->mappedBy, 'LeaptCore\\File')); } $this->config[$meta->getName()]['fields'][$field] = array('property' => $property, 'path' => $annotation->path, 'mappedBy' => $annotation->mappedBy, 'filename' => $annotation->filename, 'meta' => $meta, 'nameCallback' => $annotation->nameCallback, 'pathCallback' => $annotation->pathCallback); } } }
/** * Generates a new syntax error. * * @param string $expected Expected string. * @param array $token Optional token. * * @throws AnnotationException */ private function syntaxError($expected, $token = null) { if ($token === null) { $token = $this->lexer->lookahead; } $message = "Expected {$expected}, got "; if ($this->lexer->lookahead === null) { $message .= 'end of string'; } else { $message .= "'{$token['value']}' at position {$token['position']}"; } if (strlen($this->context)) { $message .= ' in ' . $this->context; } $message .= '.'; throw AnnotationException::syntaxError($message); }
/** * Generates a new syntax error. * * @param string $expected Expected string. * @param array|null $token Optional token. * * @return void * * @throws AnnotationException */ private function syntaxError($expected, $token = null) { if ($token === null) { $token = $this->lexer->lookahead; } $message = sprintf('Expected %s, got ', $expected); $message .= $this->lexer->lookahead === null ? 'end of string' : sprintf("'%s' at position %s", $token['value'], $token['position']); if (strlen($this->context)) { $message .= ' in ' . $this->context; } $message .= '.'; throw AnnotationException::syntaxError($message); }