Param.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Class method parameter documentation generator.
  4. *
  5. * @package Kohana/Userguide
  6. * @category Base
  7. * @author Kohana Team
  8. * @copyright (c) Kohana Team
  9. * @license https://koseven.ga/LICENSE.md
  10. */
  11. class Kohana_Kodoc_Method_Param extends Kodoc {
  12. /**
  13. * @var object ReflectionParameter for this property
  14. */
  15. public $param;
  16. /**
  17. * @var string name of this var
  18. */
  19. public $name;
  20. /**
  21. * @var string variable type, retrieved from the comment
  22. */
  23. public $type;
  24. /**
  25. * @var string default value of this param
  26. */
  27. public $default;
  28. /**
  29. * @var string description of this parameter
  30. */
  31. public $description;
  32. /**
  33. * @var boolean is the parameter passed by reference?
  34. */
  35. public $reference = FALSE;
  36. /**
  37. * @var boolean is the parameter optional?
  38. */
  39. public $optional = FALSE;
  40. public function __construct($method, $param)
  41. {
  42. $this->param = new ReflectionParameter($method, $param);
  43. $this->name = $this->param->name;
  44. if ($this->param->isDefaultValueAvailable())
  45. {
  46. $this->default = Debug::dump($this->param->getDefaultValue());
  47. }
  48. if ($this->param->isPassedByReference())
  49. {
  50. $this->reference = TRUE;
  51. }
  52. if ($this->param->isOptional())
  53. {
  54. $this->optional = TRUE;
  55. }
  56. }
  57. public function __toString()
  58. {
  59. $display = '';
  60. if ($this->type)
  61. {
  62. $display .= '<small>'.$this->type.'</small> ';
  63. }
  64. if ($this->reference)
  65. {
  66. $display .= '<small><abbr title="passed by reference">&</abbr></small> ';
  67. }
  68. if ($this->description)
  69. {
  70. $display .= '<span class="param" title="'.preg_replace('/\s+/', ' ', $this->description).'">$'.$this->name.'</span> ';
  71. }
  72. else
  73. {
  74. $display .= '$'.$this->name.' ';
  75. }
  76. if ($this->default)
  77. {
  78. $display .= '<small>= '.$this->default.'</small> ';
  79. }
  80. return $display;
  81. }
  82. } // End Kodoc_Method_Param