annotate vendor/phpdocumentor/reflection-common/src/Fqsen.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 7a779792577d
children
rev   line source
Chris@12 1 <?php
Chris@12 2 /**
Chris@12 3 * phpDocumentor
Chris@12 4 *
Chris@12 5 * PHP Version 5.5
Chris@12 6 *
Chris@12 7 * @copyright 2010-2015 Mike van Riel / Naenius (http://www.naenius.com)
Chris@12 8 * @license http://www.opensource.org/licenses/mit-license.php MIT
Chris@12 9 * @link http://phpdoc.org
Chris@12 10 */
Chris@12 11
Chris@12 12 namespace phpDocumentor\Reflection;
Chris@12 13
Chris@12 14 /**
Chris@12 15 * Value Object for Fqsen.
Chris@12 16 *
Chris@12 17 * @link https://github.com/phpDocumentor/fig-standards/blob/master/proposed/phpdoc-meta.md
Chris@12 18 */
Chris@12 19 final class Fqsen
Chris@12 20 {
Chris@12 21 /**
Chris@12 22 * @var string full quallified class name
Chris@12 23 */
Chris@12 24 private $fqsen;
Chris@12 25
Chris@12 26 /**
Chris@12 27 * @var string name of the element without path.
Chris@12 28 */
Chris@12 29 private $name;
Chris@12 30
Chris@12 31 /**
Chris@12 32 * Initializes the object.
Chris@12 33 *
Chris@12 34 * @param string $fqsen
Chris@12 35 *
Chris@12 36 * @throws \InvalidArgumentException when $fqsen is not matching the format.
Chris@12 37 */
Chris@12 38 public function __construct($fqsen)
Chris@12 39 {
Chris@12 40 $matches = array();
Chris@12 41 $result = preg_match(
Chris@12 42 '/^\\\\([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff\\\\]*)?(?:[:]{2}\\$?([a-zA-Z_\\x7f-\\xff][a-zA-Z0-9_\\x7f-\\xff]*))?(?:\\(\\))?$/',
Chris@12 43 $fqsen,
Chris@12 44 $matches
Chris@12 45 );
Chris@12 46
Chris@12 47 if ($result === 0) {
Chris@12 48 throw new \InvalidArgumentException(
Chris@12 49 sprintf('"%s" is not a valid Fqsen.', $fqsen)
Chris@12 50 );
Chris@12 51 }
Chris@12 52
Chris@12 53 $this->fqsen = $fqsen;
Chris@12 54
Chris@12 55 if (isset($matches[2])) {
Chris@12 56 $this->name = $matches[2];
Chris@12 57 } else {
Chris@12 58 $matches = explode('\\', $fqsen);
Chris@12 59 $this->name = trim(end($matches), '()');
Chris@12 60 }
Chris@12 61 }
Chris@12 62
Chris@12 63 /**
Chris@12 64 * converts this class to string.
Chris@12 65 *
Chris@12 66 * @return string
Chris@12 67 */
Chris@12 68 public function __toString()
Chris@12 69 {
Chris@12 70 return $this->fqsen;
Chris@12 71 }
Chris@12 72
Chris@12 73 /**
Chris@12 74 * Returns the name of the element without path.
Chris@12 75 *
Chris@12 76 * @return string
Chris@12 77 */
Chris@12 78 public function getName()
Chris@12 79 {
Chris@12 80 return $this->name;
Chris@12 81 }
Chris@12 82 }