LeanMapper\Reflection\AnnotationsParser::parseSimpleAnnotationValue PHP Method

parseSimpleAnnotationValue() public static method

Parse value of requested simple annotation from given doc comment
public static parseSimpleAnnotationValue ( string $annotation, string $docComment ) : string | null
$annotation string
$docComment string
return string | null
    public static function parseSimpleAnnotationValue($annotation, $docComment)
    {
        $matches = [];
        preg_match("#@{$annotation}\\s+([^\\s]+)#", $docComment, $matches);
        return !empty($matches) ? $matches[1] : null;
    }

Usage Example

Example #1
0
 /**
  * Gets name of (main) database table related to entity that repository can handle
  *
  * @return string
  * @throws InvalidStateException
  */
 protected function getTable()
 {
     if ($this->table === null) {
         if (!$this->tableAnnotationChecked) {
             $this->tableAnnotationChecked = true;
             $table = AnnotationsParser::parseSimpleAnnotationValue('table', $this->getDocComment());
             if ($table !== null) {
                 return $this->table = $table;
             }
         }
         $this->table = $this->mapper->getTableByRepositoryClass(get_called_class());
     }
     return $this->table;
 }