/** * Parses a documentation comment. * * @param string $commentString * @param $target * * @return Comment */ public function parse($commentString, $target) { // Extract the description part of the comment block $commentString = $this->stripCommentDecoration($commentString); $parts = preg_split('/^\\s*(?=@[a-zA-Z]+)/m', $commentString, 2); $comment = new Comment(trim($parts[0])); if (!isset($parts[1])) { return $comment; } $trimmed = trim($parts[1]); if (empty($trimmed)) { return $comment; } $pattern = '/(\'(?:\\\\.|[^\'\\\\])*\'|"(?:\\\\.|[^"\\\\])*"|[@(),={}]|\\s+|(?<![:])[:](?![:]))/'; $flags = PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY; $this->parts = preg_split($pattern, $parts[1], -1, $flags); $this->position = -1; while (isset($this->parts[++$this->position])) { if ($this->parts[$this->position] === '@') { list($name, $parameters, $isClass) = $this->parseTag(); if ($isClass) { $className = $this->getFullyQualifiedName($name); $this->saveState(); $comment->addAnnotation($className, $this->container->readClass($className, $parameters, $target)); $this->restoreState(); } else { $comment->add($name, $parameters); } } } return $comment; }
/** * @param Comment $comment * @param AnnotationMetadata $metadata */ private function collectDefaultAttributeMetadata(Comment $comment, AnnotationMetadata $metadata) { //@DefaultAttribute if ($comment->has('DefaultAttribute')) { $metadata->defaultAttribute = $comment->get('DefaultAttribute'); } }
/** * @param Comment $comment * @param $property * @param Entity $entity */ private function processRelation(Comment $comment, $property, Entity $entity) { /** @var \ORMiny\Annotations\Relation $relationAnnotation */ $relationAnnotation = current($comment->getAnnotationType(RelationAnnotation::class)); $relation = Relation::create($entity, $this->manager->get($relationAnnotation->target), $relationAnnotation, $this->createSetter($entity, $property, $relationAnnotation), $this->createGetter($entity, $property, $relationAnnotation)); $entity->addRelation($relationAnnotation->name, $relationAnnotation->foreignKey, $relation); }
/** * @expectedException \OutOfBoundsException */ public function testClassAnnotationInterfaceException() { $comment = new Comment(''); $comment->getAnnotationType('someclass'); }