Implement Countable interface in OptionsPropertyGroup
[phpmyadmin.git] / libraries / properties / options / OptionsPropertyGroup.php
blob1ac67395d4c45934b417dc7b6c910682c919b1b6
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Superclass for the Property Group classes.
6 * @package PhpMyAdmin
7 */
8 namespace PMA\libraries\properties\options;
10 /**
11 * Parents group property items and provides methods to manage groups of
12 * properties.
14 * @todo modify descriptions if needed, when the options are integrated
15 * @package PhpMyAdmin
17 abstract class OptionsPropertyGroup extends OptionsPropertyItem implements \Countable
19 /**
20 * Holds a group of properties (PMA\libraries\properties\options\OptionsPropertyItem instances)
22 * @var array
24 private $_properties;
26 /**
27 * Adds a property to the group of properties
29 * @param OptionsPropertyItem $property the property instance to be added
30 * to the group
32 * @return void
34 public function addProperty($property)
36 if (!$this->getProperties() == null
37 && in_array($property, $this->getProperties(), true)
38 ) {
39 return;
41 $this->_properties [] = $property;
44 /**
45 * Removes a property from the group of properties
47 * @param OptionsPropertyItem $property the property instance to be removed
48 * from the group
50 * @return void
52 public function removeProperty($property)
54 $this->_properties = array_diff(
55 $this->getProperties(),
56 array($property)
61 /* ~~~~~~~~~~~~~~~~~~~~ Getters and Setters ~~~~~~~~~~~~~~~~~~~~ */
63 /**
64 * Gets the instance of the class
66 * @return array
68 public function getGroup()
70 return $this;
73 /**
74 * Gets the group of properties
76 * @return array
78 public function getProperties()
80 return $this->_properties;
83 /**
84 * Gets the number of properties
86 * @return int
88 public function getNrOfProperties()
90 if (is_null($this->_properties)) {
91 return 0;
93 return count($this->_properties);
96 /**
97 * Countable interface implementation.
99 * @return int
101 public function count() {
102 return $this->getNrOfProperties();