Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 8, 2020. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 16 additions & 67 deletions library/Zend/Code/Generator/DocBlock/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,94 +9,43 @@

namespace Zend\Code\Generator\DocBlock;

use ReflectionClass;
use ReflectionMethod;
use Zend\Code\Generator\AbstractGenerator;
use Zend\Code\Reflection\DocBlock\Tag\TagInterface as ReflectionDocBlockTag;
use Zend\Code\Generator\DocBlock\Tag\GenericTag;
use Zend\Code\Reflection\DocBlock\Tag\TagInterface as ReflectionTagInterface;

class Tag extends AbstractGenerator
/**
* @deprecated Deprecated in 2.3. Use GenericTag instead
*/
class Tag extends GenericTag
{
/**
* @var string
*/
protected $name = null;

/**
* @var string
*/
protected $description = null;

/**
* Build a Tag generator object from a reflection object
*
* @param ReflectionDocBlockTag $reflectionTag
* @param ReflectionTagInterface $reflectionTag
* @return Tag
* @deprecated Deprecated in 2.3. Use TagManager::createTagFromReflection() instead
*/
public static function fromReflection(ReflectionDocBlockTag $reflectionTag)
public static function fromReflection(ReflectionTagInterface $reflectionTag)
{
$tagName = $reflectionTag->getName();

$codeGenDocBlockTag = new static();
$codeGenDocBlockTag->setName($tagName);

// transport any properties via accessors and mutators from reflection to codegen object
$reflectionClass = new ReflectionClass($reflectionTag);
foreach ($reflectionClass->getMethods(ReflectionMethod::IS_PUBLIC) as $method) {
if (substr($method->getName(), 0, 3) == 'get') {
$propertyName = substr($method->getName(), 3);
if (method_exists($codeGenDocBlockTag, 'set' . $propertyName)) {
$codeGenDocBlockTag->{'set' . $propertyName}($reflectionTag->{'get' . $propertyName}());
}
}
}

return $codeGenDocBlockTag;
}

/**
* @param string $name
* @return Tag
*/
public function setName($name)
{
$this->name = ltrim($name, '@');
return $this;
}

/**
* @return string
*/
public function getName()
{
return $this->name;
$tagManager = new TagManager();
$tagManager->initializeDefaultTags();
return $tagManager->createTagFromReflection($reflectionTag);
}

/**
* @param string $description
* @return Tag
* @deprecated Deprecated in 2.3. Use GenericTag::setContent() instead
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
return $this->setContent($description);
}

/**
* @return string
* @deprecated Deprecated in 2.3. Use GenericTag::getContent() instead
*/
public function getDescription()
{
return $this->description;
}

/**
* @return string
*/
public function generate()
{
$output = '@' . $this->name
. (($this->description != null) ? ' ' . $this->description : '');

return $output;
return $this->getContent();
}
}
96 changes: 96 additions & 0 deletions library/Zend/Code/Generator/DocBlock/Tag/AbstractTypeableTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace Zend\Code\Generator\DocBlock\Tag;

use Zend\Code\Generator\AbstractGenerator;

/**
* This abstract class can be used as parent for all tags
* that use a type part in their content.
* @see http://www.phpdoc.org/docs/latest/for-users/phpdoc/types.html
*/
abstract class AbstractTypeableTag extends AbstractGenerator
{
/**
* @var string
*/
protected $description = null;

/**
* @var array
*/
protected $types = array();

/**
* @param array $types
* @param string $description
*/
public function __construct($types = array(), $description = null)
{
if (!empty($types)) {
$this->setTypes($types);
}

if (!empty($description)) {
$this->setDescription($description);
}
}

/**
* @param string $description
* @return ReturnTag
*/
public function setDescription($description)
{
$this->description = $description;
return $this;
}

/**
* @return string
*/
public function getDescription()
{
return $this->description;
}

/**
* Array of types or string with types delimited by pipe (|)
* e.g. array('int', 'null') or "int|null"
*
* @param array|string $types
* @return ReturnTag
*/
public function setTypes($types)
{
if (is_string($types)) {
$types = explode('|', $types);
}
$this->types = $types;
return $this;
}

/**
* @return array
*/
public function getTypes()
{
return $this->types;
}

/**
* @param string $delimiter
* @return string
*/
public function getTypesAsString($delimiter = '|')
{
return implode($delimiter, $this->types);
}
}
77 changes: 48 additions & 29 deletions library/Zend/Code/Generator/DocBlock/Tag/AuthorTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,82 +9,101 @@

namespace Zend\Code\Generator\DocBlock\Tag;

use Zend\Code\Generator\DocBlock\Tag;
use Zend\Code\Reflection\DocBlock\Tag\TagInterface as ReflectionDocBlockTag;
use Zend\Code\Generator\AbstractGenerator;
use Zend\Code\Generator\DocBlock\TagManager;
use Zend\Code\Reflection\DocBlock\Tag\TagInterface as ReflectionTagInterface;

class AuthorTag extends Tag
class AuthorTag extends AbstractGenerator implements TagInterface
{
/**
* @var string
*/
protected $datatype = null;
protected $authorName = null;

/**
* @var string
*/
protected $paramName = null;
protected $authorEmail = null;

/**
* @param ReflectionDocBlockTag $reflectionTagParam
* @return AuthorTag
* @param string $authorName
* @param string $authorEmail
*/
public function __construct($authorName = null, $authorEmail = null)
{
if (!empty($authorName)) {
$this->setAuthorName($authorName);
}

if (!empty($authorEmail)) {
$this->setAuthorEmail($authorEmail);
}
}

/**
* @param ReflectionTagInterface $reflectionTag
* @return ReturnTag
* @deprecated Deprecated in 2.3. Use TagManager::createTagFromReflection() instead
*/
public static function fromReflection(ReflectionDocBlockTag $reflectionTagParam)
public static function fromReflection(ReflectionTagInterface $reflectionTag)
{
$authorTag = new self();
$authorTag
->setName('author')
->setAuthorName($reflectionTagParam->getType()) // @todo rename
->setAuthorEmail($reflectionTagParam->getVariableName())
->setDescription($reflectionTagParam->getDescription());
$tagManager = new TagManager();
$tagManager->initializeDefaultTags();
return $tagManager->createTagFromReflection($reflectionTag);
}

return $authorTag;
/**
* @return string
*/
public function getName()
{
return 'author';
}

/**
* @param string $datatype
* @param string $authorEmail
* @return AuthorTag
*/
public function setDatatype($datatype)
public function setAuthorEmail($authorEmail)
{
$this->datatype = (string) $datatype;
$this->authorEmail = $authorEmail;
return $this;
}

/**
* @return string
*/
public function getDatatype()
public function getAuthorEmail()
{
return $this->datatype;
return $this->authorEmail;
}

/**
* @param string $paramName
* @param string $authorName
* @return AuthorTag
*/
public function setParamName($paramName)
public function setAuthorName($authorName)
{
$this->paramName = (string) $paramName;
$this->authorName = $authorName;
return $this;
}

/**
* @return string
*/
public function getParamName()
public function getAuthorName()
{
return $this->paramName;
return $this->authorName;
}

/**
* @return string
*/
public function generate()
{
$output = '@param '
. (($this->datatype != null) ? $this->datatype : 'unknown')
. (($this->paramName != null) ? ' $' . $this->paramName : '')
. (($this->description != null) ? ' ' . $this->description : '');
$output = '@author'
. ((!empty($this->authorName)) ? ' ' . $this->authorName : '')
. ((!empty($this->authorEmail)) ? ' <' . $this->authorEmail . '>' : '');

return $output;
}
Expand Down
Loading