PageRenderTime 53ms CodeModel.GetById 19ms RepoModel.GetById 0ms app.codeStats 0ms

/application/protected/extensions/yiiext/components/phpDoc/EPhpDoc.php

https://bitbucket.org/dinhtrung/yiicorecms/
PHP | 94 lines | 38 code | 0 blank | 56 comment | 7 complexity | d611905ffd1c1cbd9863face4a8aa9c7 MD5 | raw file
Possible License(s): GPL-3.0, BSD-3-Clause, CC0-1.0, BSD-2-Clause, GPL-2.0, LGPL-2.1, LGPL-3.0
  1. <?php
  2. /**
  3. * EPhpDoc class file.
  4. *
  5. * @author Veaceslav Medvedev <slavcopost@gmail.com>
  6. * @link http://code.google.com/p/yiiext/
  7. * @license http://www.opensource.org/licenses/bsd-license.php
  8. */
  9. /**
  10. * PhpDoc Reader
  11. *
  12. * The map of phpDoc documentation.
  13. *
  14. * @author Veaceslav Medvedev <slavcopost@gmail.com>
  15. * @version 0.1
  16. * @package yiiext.components.phpDoc
  17. * @link http://phpdoc.org/
  18. *
  19. * @var string $title the documentation title.
  20. * @var string $description the documentation description.
  21. * @var boolean $abstract
  22. * @var string $access the access, public or private.
  23. * @var string $author the author. Example: 'author name <author@email>'.
  24. * @var string $copyright
  25. * @var string $deprecated
  26. * @var string $deprec alias for deprecated.
  27. * @var string $example the path to example.
  28. * @var string $exception Javadoc-compatible, use as needed.
  29. * @var string $global the data for a global variable. Format: 'type $globalvarname' or 'type description'.
  30. * @var boolean $ignore
  31. * @var string $internal the private information for advanced developers only.
  32. * @var string $param the data for a function or method param. Format: 'type [$varname] description'.
  33. * @var string $return the data for a function or method returns. Format: 'type description'.
  34. * @var string $link the URL.
  35. * @var string $name
  36. * @var string $magic phpdoc.de compatibility.
  37. * @var string $package the package name.
  38. * @var string $see the name of another element that can be documented, produces a link to it in the documentation.
  39. * @var string $since the version or a date.
  40. * @var boolean $static
  41. * @var string $staticvar the data for a static variable. Format: 'type description'.
  42. * @var string $subpackage the sub package name, groupings inside of a project.
  43. * @var string $throws Javadoc-compatible, use as needed.
  44. * @var string $todo phpdoc.de compatibility.
  45. * @var string $var the data for a class variable. Format: 'type description'.
  46. * @var string $version the version.
  47. */
  48. class EPhpDoc extends CMap
  49. {
  50. /**
  51. * @param Reflector $class
  52. * @return CMap
  53. */
  54. public function __construct($class)
  55. {
  56. $data=array('title'=>NULL,'description'=>NULL);
  57. if($class instanceof Reflector&&method_exists($class,'getDocComment'))
  58. {
  59. // Get the comment.
  60. if(preg_match('#^/\*\*(.*)\*/#s',$class->getDocComment(),$lines)!==false)
  61. {
  62. $lines=trim($lines[1]);
  63. // Get all the lines and strip the * from the first character.
  64. if(preg_match_all('#^\s*\*(.*)#m',$lines,$lines)!==false)
  65. {
  66. $description=array();
  67. foreach($lines[1] as $line)
  68. {
  69. // Parse the line.
  70. $line=trim($line);
  71. if(!empty($line)&&strpos($line,'@')===0)
  72. {
  73. // Get the parameter name and value.
  74. $param=explode(' ',substr($line,1),2);
  75. $data[$param[0]]=isset($param[1])?$param[1]:true;
  76. }
  77. else if(count($data)<=2)
  78. {
  79. $description[]=$line;
  80. // Store the first line in the title.
  81. if(!empty($line)&&empty($data['title']))
  82. {
  83. $data['title']=$line;
  84. }
  85. }
  86. // Store the line before params in the description.
  87. $data['description']=trim(implode(PHP_EOL,$description));
  88. }
  89. }
  90. }
  91. }
  92. parent::__construct($data,true);
  93. }
  94. }