Property.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /**
  3. * Class property 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_Property extends Kodoc {
  12. /**
  13. * @var object ReflectionProperty
  14. */
  15. public $property;
  16. /**
  17. * @var string modifiers: public, private, static, etc
  18. */
  19. public $modifiers = 'public';
  20. /**
  21. * @var string variable type, retrieved from the comment
  22. */
  23. public $type;
  24. /**
  25. * @var string value of the property
  26. */
  27. public $value;
  28. /**
  29. * @var string default value of the property
  30. */
  31. public $default;
  32. public function __construct($class, $property, $default = NULL)
  33. {
  34. $property = new ReflectionProperty($class, $property);
  35. list($description, $tags) = Kodoc::parse($property->getDocComment());
  36. $this->description = $description;
  37. if ($modifiers = $property->getModifiers())
  38. {
  39. $this->modifiers = '<small>'.implode(' ', Reflection::getModifierNames($modifiers)).'</small> ';
  40. }
  41. if (isset($tags['var']))
  42. {
  43. if (preg_match('/^(\S*)(?:\s*(.+?))?$/s', $tags['var'][0], $matches))
  44. {
  45. $this->type = $matches[1];
  46. if (isset($matches[2]))
  47. {
  48. $this->description = Kodoc_Markdown::markdown($matches[2]);
  49. }
  50. }
  51. }
  52. $this->property = $property;
  53. // Show the value of static properties
  54. if ($property->isStatic())
  55. {
  56. // Force the property to be accessible
  57. $property->setAccessible(TRUE);
  58. // Don't debug the entire object, just say what kind of object it is
  59. if (is_object($property->getValue($class)))
  60. {
  61. $this->value = '<pre>object '.get_class($property->getValue($class)).'()</pre>';
  62. }
  63. else
  64. {
  65. $this->value = Debug::vars($property->getValue($class));
  66. }
  67. }
  68. // Store the defult property
  69. $this->default = Debug::vars($default);
  70. }
  71. } // End Kodoc_Property