File indexing completed on 2025-03-02 05:29:42

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Reflection
0017  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0018  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0019  * @version    $Id$
0020  */
0021 
0022 /** Zend_Loader */
0023 // require_once 'Zend/Loader.php';
0024 
0025 /**
0026  * @category   Zend
0027  * @package    Zend_Reflection
0028  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0029  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0030  */
0031 class Zend_Reflection_Docblock_Tag implements Reflector
0032 {
0033     /**
0034      * @var array Array of Class names
0035      */
0036     protected static $_tagClasses = array(
0037         'param'  => 'Zend_Reflection_Docblock_Tag_Param',
0038         'return' => 'Zend_Reflection_Docblock_Tag_Return',
0039         );
0040 
0041     /**
0042      * @var string
0043      */
0044     protected $_name = null;
0045 
0046     /**
0047      * @var string
0048      */
0049     protected $_description = null;
0050 
0051     /**
0052      * Factory: Create the appropriate annotation tag object
0053      *
0054      * @param  string $tagDocblockLine
0055      * @return Zend_Reflection_Docblock_Tag
0056      */
0057     public static function factory($tagDocblockLine)
0058     {
0059         $matches = array();
0060 
0061         if (!preg_match('#^@(\w+)(\s|$)#', $tagDocblockLine, $matches)) {
0062             // require_once 'Zend/Reflection/Exception.php';
0063             throw new Zend_Reflection_Exception('No valid tag name found within provided docblock line.');
0064         }
0065 
0066         $tagName = $matches[1];
0067         if (array_key_exists($tagName, self::$_tagClasses)) {
0068             $tagClass = self::$_tagClasses[$tagName];
0069             if (!class_exists($tagClass)) {
0070                 Zend_Loader::loadClass($tagClass);
0071             }
0072             return new $tagClass($tagDocblockLine);
0073         }
0074         return new self($tagDocblockLine);
0075     }
0076 
0077     /**
0078      * Export reflection
0079      *
0080      * Required by Reflector
0081      *
0082      * @todo   What should this do?
0083      * @return void
0084      */
0085     public static function export()
0086     {
0087     }
0088 
0089     /**
0090      * Serialize to string
0091      *
0092      * Required by Reflector
0093      *
0094      * @todo   What should this do?
0095      * @return string
0096      */
0097     public function __toString()
0098     {
0099         $str = "Docblock Tag [ * @".$this->_name." ]".PHP_EOL;
0100 
0101         return $str;
0102     }
0103 
0104     /**
0105      * Constructor
0106      *
0107      * @param  string $tagDocblockLine
0108      * @return void
0109      */
0110     public function __construct($tagDocblockLine)
0111     {
0112         $matches = array();
0113 
0114         // find the line
0115         if (!preg_match('#^@(\w+)(?:\s+([^\s].*)|$)?#', $tagDocblockLine, $matches)) {
0116             // require_once 'Zend/Reflection/Exception.php';
0117             throw new Zend_Reflection_Exception('Provided docblock line does not contain a valid tag');
0118         }
0119 
0120         $this->_name = $matches[1];
0121         if (isset($matches[2]) && $matches[2]) {
0122             $this->_description = $matches[2];
0123         }
0124     }
0125 
0126     /**
0127      * Get annotation tag name
0128      *
0129      * @return string
0130      */
0131     public function getName()
0132     {
0133         return $this->_name;
0134     }
0135 
0136     /**
0137      * Get annotation tag description
0138      *
0139      * @return string
0140      */
0141     public function getDescription()
0142     {
0143         return $this->_description;
0144     }
0145 }