1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81:
<?php
namespace LeanMapper\Reflection;
use LeanMapper\Exception\UtilityClassException;
class AnnotationsParser
{
public function __construct()
{
throw new UtilityClassException('Cannot instantiate utility class ' . get_called_class() . '.');
}
public static function parseSimpleAnnotationValue($annotation, $docComment)
{
$matches = [];
preg_match("#@$annotation\\s+([^\\s]+)#", $docComment, $matches);
return !empty($matches) ? $matches[1] : null;
}
public static function parseAnnotationValues($annotation, $docComment)
{
$matches = [];
preg_match_all("#@$annotation\\s+([^@\\n\\r]*)#", $docComment, $matches);
return $matches[1];
}
public static function parseMultiLineAnnotationValues($annotation, $docComment)
{
$matches = [];
preg_match_all("#@$annotation\\h+([^\n\r@]+(?:\\s*\*\\h{2,}+[^\n\r@]+)*)#", $docComment, $matches);
return $matches[1];
}
}