2019-07-17 20:16:19 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Zend Framework
|
|
|
|
*
|
|
|
|
* LICENSE
|
|
|
|
*
|
|
|
|
* This source file is subject to the new BSD license that is bundled
|
|
|
|
* with this package in the file LICENSE.txt.
|
|
|
|
* It is also available through the world-wide-web at this URL:
|
|
|
|
* http://framework.zend.com/license/new-bsd
|
|
|
|
* If you did not receive a copy of the license and are unable to
|
|
|
|
* obtain it through the world-wide-web, please send an email
|
|
|
|
* to license@zend.com so we can send you a copy immediately.
|
|
|
|
*
|
|
|
|
* @category Zend
|
|
|
|
* @package Zend_Reflection
|
|
|
|
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
|
|
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
2019-07-17 20:31:04 +00:00
|
|
|
* @version $Id: Docblock.php 18951 2009-11-12 16:26:19Z alexander $
|
2019-07-17 20:16:19 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @see Zend_Reflection_Docblock_Tag
|
|
|
|
*/
|
|
|
|
require_once 'Zend/Reflection/Docblock/Tag.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @category Zend
|
|
|
|
* @package Zend_Reflection
|
|
|
|
* @copyright Copyright (c) 2005-2009 Zend Technologies USA Inc. (http://www.zend.com)
|
|
|
|
* @license http://framework.zend.com/license/new-bsd New BSD License
|
|
|
|
*/
|
|
|
|
class Zend_Reflection_Docblock implements Reflector
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var Reflector
|
|
|
|
*/
|
|
|
|
protected $_reflector = null;
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**#@+
|
|
|
|
* @var int
|
|
|
|
*/
|
|
|
|
protected $_startLine = null;
|
|
|
|
protected $_endLine = null;
|
|
|
|
/**#@-*/
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $_docComment = null;
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $_cleanDocComment = null;
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $_longDescription = null;
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $_shortDescription = null;
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
protected $_tags = array();
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* Export reflection
|
|
|
|
*
|
|
|
|
* Reqired by the Reflector interface.
|
|
|
|
*
|
|
|
|
* @todo What should this do?
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public static function export()
|
|
|
|
{
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* Serialize to string
|
|
|
|
*
|
|
|
|
* Required by the Reflector interface
|
|
|
|
*
|
|
|
|
* @todo What should this return?
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function __toString()
|
|
|
|
{
|
2019-07-17 20:31:04 +00:00
|
|
|
$str = "Docblock [ /* Docblock */ ] {".PHP_EOL.PHP_EOL;
|
|
|
|
$str .= " - Tags [".count($this->_tags)."] {".PHP_EOL;
|
|
|
|
|
|
|
|
foreach($this->_tags AS $tag) {
|
|
|
|
$str .= " ".$tag;
|
|
|
|
}
|
|
|
|
|
|
|
|
$str .= " }".PHP_EOL;
|
|
|
|
$str .= "}".PHP_EOL;
|
|
|
|
|
|
|
|
return $str;
|
2019-07-17 20:16:19 +00:00
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*
|
|
|
|
* @param Reflector|string $commentOrReflector
|
|
|
|
*/
|
|
|
|
public function __construct($commentOrReflector)
|
|
|
|
{
|
|
|
|
if ($commentOrReflector instanceof Reflector) {
|
|
|
|
$this->_reflector = $commentOrReflector;
|
|
|
|
if (!method_exists($commentOrReflector, 'getDocComment')) {
|
|
|
|
require_once 'Zend/Reflection/Exception.php';
|
|
|
|
throw new Zend_Reflection_Exception('Reflector must contain method "getDocComment"');
|
|
|
|
}
|
|
|
|
$docComment = $commentOrReflector->getDocComment();
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
$lineCount = substr_count($docComment, "\n");
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
$this->_startLine = $this->_reflector->getStartLine() - $lineCount - 1;
|
|
|
|
$this->_endLine = $this->_reflector->getStartLine() - 1;
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
} elseif (is_string($commentOrReflector)) {
|
|
|
|
$docComment = $commentOrReflector;
|
|
|
|
} else {
|
|
|
|
require_once 'Zend/Reflection/Exception.php';
|
|
|
|
throw new Zend_Reflection_Exception(get_class($this) . ' must have a (string) DocComment or a Reflector in the constructor');
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
if ($docComment == '') {
|
|
|
|
require_once 'Zend/Reflection/Exception.php';
|
|
|
|
throw new Zend_Reflection_Exception('DocComment cannot be empty');
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
$this->_docComment = $docComment;
|
|
|
|
$this->_parse();
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* Retrieve contents of docblock
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getContents()
|
|
|
|
{
|
|
|
|
return $this->_cleanDocComment;
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* Get start line (position) of docblock
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getStartLine()
|
|
|
|
{
|
|
|
|
return $this->_startLine;
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* Get last line (position) of docblock
|
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getEndLine()
|
|
|
|
{
|
|
|
|
return $this->_endLine;
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* Get docblock short description
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getShortDescription()
|
|
|
|
{
|
|
|
|
return $this->_shortDescription;
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* Get docblock long description
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getLongDescription()
|
|
|
|
{
|
|
|
|
return $this->_longDescription;
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* Does the docblock contain the given annotation tag?
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return bool
|
|
|
|
*/
|
|
|
|
public function hasTag($name)
|
|
|
|
{
|
|
|
|
foreach ($this->_tags as $tag) {
|
|
|
|
if ($tag->getName() == $name) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* Retrieve the given docblock tag
|
|
|
|
*
|
|
|
|
* @param string $name
|
|
|
|
* @return Zend_Reflection_Docblock_Tag|false
|
|
|
|
*/
|
|
|
|
public function getTag($name)
|
|
|
|
{
|
|
|
|
foreach ($this->_tags as $tag) {
|
|
|
|
if ($tag->getName() == $name) {
|
|
|
|
return $tag;
|
|
|
|
}
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
return false;
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* Get all docblock annotation tags
|
|
|
|
*
|
|
|
|
* @param string $filter
|
|
|
|
* @return array Array of Zend_Reflection_Docblock_Tag
|
|
|
|
*/
|
|
|
|
public function getTags($filter = null)
|
|
|
|
{
|
|
|
|
if ($filter === null || !is_string($filter)) {
|
|
|
|
return $this->_tags;
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
$returnTags = array();
|
|
|
|
foreach ($this->_tags as $tag) {
|
|
|
|
if ($tag->getName() == $filter) {
|
|
|
|
$returnTags[] = $tag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $returnTags;
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
/**
|
|
|
|
* Parse the docblock
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
protected function _parse()
|
|
|
|
{
|
|
|
|
$docComment = $this->_docComment;
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
// First remove doc block line starters
|
|
|
|
$docComment = preg_replace('#[ \t]*(?:\/\*\*|\*\/|\*)?[ ]{0,1}(.*)?#', '$1', $docComment);
|
|
|
|
$docComment = ltrim($docComment, "\r\n"); // @todo should be changed to remove first and last empty line
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
$this->_cleanDocComment = $docComment;
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
// Next parse out the tags and descriptions
|
|
|
|
$parsedDocComment = $docComment;
|
|
|
|
$lineNumber = $firstBlandLineEncountered = 0;
|
|
|
|
while (($newlinePos = strpos($parsedDocComment, "\n")) !== false) {
|
|
|
|
$lineNumber++;
|
|
|
|
$line = substr($parsedDocComment, 0, $newlinePos);
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
$matches = array();
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
if ((strpos($line, '@') === 0) && (preg_match('#^(@\w+.*?)(\n)(?:@|\r?\n|$)#s', $parsedDocComment, $matches))) {
|
|
|
|
$this->_tags[] = Zend_Reflection_Docblock_Tag::factory($matches[1]);
|
|
|
|
$parsedDocComment = str_replace($matches[1] . $matches[2], '', $parsedDocComment);
|
|
|
|
} else {
|
|
|
|
if ($lineNumber < 3 && !$firstBlandLineEncountered) {
|
|
|
|
$this->_shortDescription .= $line . "\n";
|
|
|
|
} else {
|
|
|
|
$this->_longDescription .= $line . "\n";
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
if ($line == '') {
|
|
|
|
$firstBlandLineEncountered = true;
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
$parsedDocComment = substr($parsedDocComment, $newlinePos + 1);
|
|
|
|
}
|
2019-07-17 20:31:04 +00:00
|
|
|
|
2019-07-17 20:16:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->_shortDescription = rtrim($this->_shortDescription);
|
|
|
|
$this->_longDescription = rtrim($this->_longDescription);
|
|
|
|
}
|
|
|
|
}
|