Property.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. class PHPParser_Builder_Property extends PHPParser_BuilderAbstract
  3. {
  4. protected $name;
  5. protected $type;
  6. protected $default;
  7. /**
  8. * Creates a property builder.
  9. *
  10. * @param string $name Name of the property
  11. */
  12. public function __construct($name) {
  13. $this->name = $name;
  14. $this->type = 0;
  15. $this->default = null;
  16. }
  17. /**
  18. * Makes the property public.
  19. *
  20. * @return PHPParser_Builder_Property The builder instance (for fluid interface)
  21. */
  22. public function makePublic() {
  23. $this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_PUBLIC);
  24. return $this;
  25. }
  26. /**
  27. * Makes the property protected.
  28. *
  29. * @return PHPParser_Builder_Property The builder instance (for fluid interface)
  30. */
  31. public function makeProtected() {
  32. $this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_PROTECTED);
  33. return $this;
  34. }
  35. /**
  36. * Makes the property private.
  37. *
  38. * @return PHPParser_Builder_Property The builder instance (for fluid interface)
  39. */
  40. public function makePrivate() {
  41. $this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_PRIVATE);
  42. return $this;
  43. }
  44. /**
  45. * Makes the property static.
  46. *
  47. * @return PHPParser_Builder_Property The builder instance (for fluid interface)
  48. */
  49. public function makeStatic() {
  50. $this->setModifier(PHPParser_Node_Stmt_Class::MODIFIER_STATIC);
  51. return $this;
  52. }
  53. /**
  54. * Sets default value for the property.
  55. *
  56. * @param mixed $value Default value to use
  57. *
  58. * @return PHPParser_Builder_Property The builder instance (for fluid interface)
  59. */
  60. public function setDefault($value) {
  61. $this->default = $this->normalizeValue($value);
  62. return $this;
  63. }
  64. /**
  65. * Returns the built class node.
  66. *
  67. * @return PHPParser_Node_Stmt_Property The built property node
  68. */
  69. public function getNode() {
  70. return new PHPParser_Node_Stmt_Property(
  71. $this->type !== 0 ? $this->type : PHPParser_Node_Stmt_Class::MODIFIER_PUBLIC,
  72. array(
  73. new PHPParser_Node_Stmt_PropertyProperty($this->name, $this->default)
  74. )
  75. );
  76. }
  77. }