OptionsPropertyGroup.php 2.3 KB

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