@@ -72,6 +72,10 @@ class Config
7272 * @var array
7373 */
7474 private static $ custom ;
75+ /**
76+ * @var int
77+ */
78+ private static $ heartbeatPeriod ;
7579
7680 /**
7781 * Config constructor.
@@ -91,6 +95,7 @@ class Config
9195 * @param array $databasesOnly
9296 * @param int $tableCacheSize
9397 * @param array $custom
98+ * @param int $heartbeatPeriod
9499 */
95100 public function __construct (
96101 $ user ,
@@ -108,7 +113,8 @@ public function __construct(
108113 array $ tablesOnly ,
109114 array $ databasesOnly ,
110115 $ tableCacheSize ,
111- array $ custom
116+ array $ custom ,
117+ $ heartbeatPeriod
112118 ) {
113119 self ::$ user = $ user ;
114120 self ::$ host = $ host ;
@@ -126,73 +132,82 @@ public function __construct(
126132 self ::$ mariaDbGtid = $ mariaGtid ;
127133 self ::$ tableCacheSize = $ tableCacheSize ;
128134 self ::$ custom = $ custom ;
135+ self ::$ heartbeatPeriod = $ heartbeatPeriod ;
129136 }
130137
131138 /**
132139 * @throws ConfigException
133140 */
134141 public static function validate ()
135142 {
136- if (!empty (self ::$ user ) && false === is_string (self ::$ user )) {
143+ if (!empty (self ::$ user ) && ! is_string (self ::$ user )) {
137144 throw new ConfigException (ConfigException::USER_ERROR_MESSAGE , ConfigException::USER_ERROR_CODE );
138145 }
139146 if (!empty (self ::$ host )) {
140147 $ ip = gethostbyname (self ::$ host );
141- if (false === filter_var ($ ip , FILTER_VALIDATE_IP )) {
148+ if (! filter_var ($ ip , FILTER_VALIDATE_IP )) {
142149 throw new ConfigException (ConfigException::IP_ERROR_MESSAGE , ConfigException::IP_ERROR_CODE );
143150 }
144151 }
145- if (!empty (self ::$ port ) && false === filter_var (
152+ if (!empty (self ::$ port ) && ! filter_var (
146153 self ::$ port , FILTER_VALIDATE_INT , ['options ' => ['min_range ' => 0 ]]
147154 )
148155 ) {
149156 throw new ConfigException (ConfigException::PORT_ERROR_MESSAGE , ConfigException::PORT_ERROR_CODE );
150157 }
151- if (!empty (self ::$ password ) && false === is_string (self ::$ password ) && false === is_numeric (self ::$ password )) {
158+ if (!empty (self ::$ password ) && ! is_string (self ::$ password ) && ! is_numeric (self ::$ password )) {
152159 throw new ConfigException (ConfigException::PASSWORD_ERROR_MESSAGE , ConfigException::PASSWORD_ERROR_CODE );
153160 }
154- if (!empty (self ::$ charset ) && false === is_string (self ::$ charset )) {
161+ if (!empty (self ::$ charset ) && ! is_string (self ::$ charset )) {
155162 throw new ConfigException (ConfigException::CHARSET_ERROR_MESSAGE , ConfigException::CHARSET_ERROR_CODE );
156163 }
157- if (!empty (self ::$ gtid ) && false === is_string (self ::$ gtid )) {
164+ if (!empty (self ::$ gtid ) && ! is_string (self ::$ gtid )) {
158165 foreach (explode (', ' , self ::$ gtid ) as $ gtid ) {
159- if (false === (bool )preg_match (
160- '/^([0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12})((?::[0-9-]+)+)$/ ' , $ gtid , $ matches
161- )
166+ if (! (bool )preg_match (
167+ '/^([0-9a-fA-F]{8}(?:-[0-9a-fA-F]{4}){3}-[0-9a-fA-F]{12})((?::[0-9-]+)+)$/ ' , $ gtid , $ matches
168+ )
162169 ) {
163170 throw new ConfigException (ConfigException::GTID_ERROR_MESSAGE , ConfigException::GTID_ERROR_CODE );
164171 }
165172 }
166173 }
167- if (!empty (self ::$ slaveId ) && false === filter_var (
174+ if (!empty (self ::$ slaveId ) && ! filter_var (
168175 self ::$ slaveId , FILTER_VALIDATE_INT , ['options ' => ['min_range ' => 0 ]]
169176 )
170177 ) {
171178 throw new ConfigException (ConfigException::SLAVE_ID_ERROR_MESSAGE , ConfigException::SLAVE_ID_ERROR_CODE );
172179 }
173- if (!empty (self ::$ binLogFileName ) && false === is_string (self ::$ binLogFileName )) {
180+ if (!empty (self ::$ binLogFileName ) && ! is_string (self ::$ binLogFileName )) {
174181 throw new ConfigException (
175182 ConfigException::BIN_LOG_FILE_NAME_ERROR_MESSAGE , ConfigException::BIN_LOG_FILE_NAME_ERROR_CODE
176183 );
177184 }
178- if (!empty (self ::$ binLogPosition ) && false === filter_var (
185+ if (!empty (self ::$ binLogPosition ) && ! filter_var (
179186 self ::$ binLogPosition , FILTER_VALIDATE_INT , ['options ' => ['min_range ' => 0 ]]
180187 )
181188 ) {
182189 throw new ConfigException (
183190 ConfigException::BIN_LOG_FILE_POSITION_ERROR_MESSAGE , ConfigException::BIN_LOG_FILE_POSITION_ERROR_CODE
184191 );
185192 }
186- if (!empty (self ::$ mariaDbGtid ) && false === is_string (self ::$ mariaDbGtid )) {
193+ if (!empty (self ::$ mariaDbGtid ) && ! is_string (self ::$ mariaDbGtid )) {
187194 throw new ConfigException (
188195 ConfigException::MARIADBGTID_ERROR_MESSAGE , ConfigException::MARIADBGTID_ERROR_CODE
189196 );
190197 }
191- if (false === filter_var (self ::$ tableCacheSize , FILTER_VALIDATE_INT , ['options ' => ['min_range ' => 0 ]])) {
198+ if (! filter_var (self ::$ tableCacheSize , FILTER_VALIDATE_INT , ['options ' => ['min_range ' => 0 ]])) {
192199 throw new ConfigException (
193200 ConfigException::TABLE_CACHE_SIZE_ERROR_MESSAGE , ConfigException::TABLE_CACHE_SIZE_ERROR_CODE
194201 );
195202 }
203+ if (0 !== self ::$ heartbeatPeriod && !filter_var (
204+ self ::$ heartbeatPeriod , FILTER_VALIDATE_INT , ['options ' => ['min_range ' => 1 , 'max_range ' => 4294967 ]]
205+ )
206+ ) {
207+ throw new ConfigException (
208+ ConfigException::HEARTBEAT_PERIOD_ERROR_MESSAGE , ConfigException::HEARTBEAT_PERIOD_ERROR_CODE
209+ );
210+ }
196211 }
197212
198213 /**
@@ -357,4 +372,12 @@ public static function checkEvent($type)
357372
358373 return true ;
359374 }
375+
376+ /**
377+ * @return int
378+ */
379+ public static function getHeartbeatPeriod ()
380+ {
381+ return self ::$ heartbeatPeriod ;
382+ }
360383}
0 commit comments