1<?php 2/** 3 * This file is part of phpDocumentor. 4 * 5 * For the full copyright and license information, please view the LICENSE 6 * file that was distributed with this source code. 7 * 8 * @copyright 2010-2015 Mike van Riel<mike@phpdoc.org> 9 * @license http://www.opensource.org/licenses/mit-license.php MIT 10 * @link http://phpdoc.org 11 */ 12 13namespace phpDocumentor\Reflection\DocBlock\Tags; 14 15use phpDocumentor\Reflection\DocBlock\Description; 16use phpDocumentor\Reflection\DocBlock\DescriptionFactory; 17use phpDocumentor\Reflection\DocBlock\Tags\Reference\Fqsen as FqsenRef; 18use phpDocumentor\Reflection\DocBlock\Tags\Reference\Reference; 19use phpDocumentor\Reflection\DocBlock\Tags\Reference\Url; 20use phpDocumentor\Reflection\FqsenResolver; 21use phpDocumentor\Reflection\Types\Context as TypeContext; 22use Webmozart\Assert\Assert; 23 24/** 25 * Reflection class for an {@}see tag in a Docblock. 26 */ 27class See extends BaseTag implements Factory\StaticMethod 28{ 29 protected $name = 'see'; 30 31 /** @var Reference */ 32 protected $refers = null; 33 34 /** 35 * Initializes this tag. 36 * 37 * @param Reference $refers 38 * @param Description $description 39 */ 40 public function __construct(Reference $refers, Description $description = null) 41 { 42 $this->refers = $refers; 43 $this->description = $description; 44 } 45 46 /** 47 * {@inheritdoc} 48 */ 49 public static function create( 50 $body, 51 FqsenResolver $resolver = null, 52 DescriptionFactory $descriptionFactory = null, 53 TypeContext $context = null 54 ) { 55 Assert::string($body); 56 Assert::allNotNull([$resolver, $descriptionFactory]); 57 58 $parts = preg_split('/\s+/Su', $body, 2); 59 $description = isset($parts[1]) ? $descriptionFactory->create($parts[1], $context) : null; 60 61 // https://tools.ietf.org/html/rfc2396#section-3 62 if (preg_match('/\w:\/\/\w/i', $parts[0])) { 63 return new static(new Url($parts[0]), $description); 64 } 65 66 return new static(new FqsenRef($resolver->resolve($parts[0], $context)), $description); 67 } 68 69 /** 70 * Returns the ref of this tag. 71 * 72 * @return Reference 73 */ 74 public function getReference() 75 { 76 return $this->refers; 77 } 78 79 /** 80 * Returns a string representation of this tag. 81 * 82 * @return string 83 */ 84 public function __toString() 85 { 86 return $this->refers . ($this->description ? ' ' . $this->description->render() : ''); 87 } 88} 89