OptionsPropertyGroup.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Superclass for the Property Group classes.
  5. *
  6. * @package PhpMyAdmin
  7. */
  8. namespace PhpMyAdmin\Properties\Options;
  9. /**
  10. * Parents group property items and provides methods to manage groups of
  11. * properties.
  12. *
  13. * @todo modify descriptions if needed, when the options are integrated
  14. * @package PhpMyAdmin
  15. */
  16. abstract class OptionsPropertyGroup extends OptionsPropertyItem implements \Countable
  17. {
  18. /**
  19. * Holds a group of properties (PhpMyAdmin\Properties\Options\OptionsPropertyItem instances)
  20. *
  21. * @var array
  22. */
  23. private $_properties;
  24. /**
  25. * Adds a property to the group of properties
  26. *
  27. * @param OptionsPropertyItem $property the property instance to be added
  28. * to the group
  29. *
  30. * @return void
  31. */
  32. public function addProperty($property)
  33. {
  34. if (!$this->getProperties() == null
  35. && in_array($property, $this->getProperties(), true)
  36. ) {
  37. return;
  38. }
  39. $this->_properties [] = $property;
  40. }
  41. /**
  42. * Removes a property from the group of properties
  43. *
  44. * @param OptionsPropertyItem $property the property instance to be removed
  45. * from the group
  46. *
  47. * @return void
  48. */
  49. public function removeProperty($property)
  50. {
  51. $this->_properties = array_diff(
  52. $this->getProperties(),
  53. array($property)
  54. );
  55. }
  56. /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
  57. /**
  58. * Gets the instance of the class
  59. *
  60. * @return array
  61. */
  62. public function getGroup()
  63. {
  64. return $this;
  65. }
  66. /**
  67. * Gets the group of properties
  68. *
  69. * @return array
  70. */
  71. public function getProperties()
  72. {
  73. return $this->_properties;
  74. }
  75. /**
  76. * Gets the number of properties
  77. *
  78. * @return int
  79. */
  80. public function getNrOfProperties()
  81. {
  82. if (is_null($this->_properties)) {
  83. return 0;
  84. }
  85. return count($this->_properties);
  86. }
  87. /**
  88. * Countable interface implementation.
  89. *
  90. * @return int
  91. */
  92. public function count() {
  93. return $this->getNrOfProperties();
  94. }
  95. }