| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
namespace phpDocumentor\Reflection; |
| 15 |
|
| 16 |
use InvalidArgumentException; |
| 17 |
use function assert; |
| 18 |
use function end; |
| 19 |
use function explode; |
| 20 |
use function is_string; |
| 21 |
use function preg_match; |
| 22 |
use function sprintf; |
| 23 |
use function trim; |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
final class Fqsen |
| 33 |
{ |
| 34 |
|
| 35 |
private $fqsen; |
| 36 |
|
| 37 |
|
| 38 |
private $name; |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public function __construct(string $fqsen) |
| 46 |
{ |
| 47 |
$matches = []; |
| 48 |
|
| 49 |
$result = preg_match( |
| 50 |
|
| 51 |
'/^\\\\([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff\\\\]*)?(?:[:]{2}\\$?([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*))?(?:\\(\\))?$/', |
| 52 |
$fqsen, |
| 53 |
$matches |
| 54 |
); |
| 55 |
|
| 56 |
if ($result === 0) { |
| 57 |
throw new InvalidArgumentException( |
| 58 |
sprintf('"%s" is not a valid Fqsen.', $fqsen) |
| 59 |
); |
| 60 |
} |
| 61 |
|
| 62 |
$this->fqsen = $fqsen; |
| 63 |
|
| 64 |
if (isset($matches[2])) { |
| 65 |
$this->name = $matches[2]; |
| 66 |
} else { |
| 67 |
$matches = explode('\\', $fqsen); |
| 68 |
$name = end($matches); |
| 69 |
assert(is_string($name)); |
| 70 |
$this->name = trim($name, '()'); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
public function __toString() : string |
| 78 |
{ |
| 79 |
return $this->fqsen; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
public function getName() : string |
| 86 |
{ |
| 87 |
return $this->name; |
| 88 |
} |
| 89 |
} |