/** * @param string $input * @param bool|false $suppress * @return bool */ public function validateDbServerType($input, $suppress = false) { if (!($output = in_array(strtolower($input), [LeDbTypeEnum::master()->getValue(), LeDbTypeEnum::slave()->getValue()]))) { if (!$suppress) { throw new InvalidArgumentException("{$input} is not a valid Database server type"); } } return (bool) $output; }
public static function getFromValue($input) { if (LeDbTypeEnum::master()->getValue() == strtolower($input)) { $output = LeDbTypeEnum::master(); } elseif (LeDbTypeEnum::slave()->getValue() == strtolower($input)) { $output = LeDbTypeEnum::slave(); } else { throw new InvalidArgumentException("{$input} is not a valid DB Type Enum"); } return $output; }
/** * @param LeDbData $dto * @param LeDbTypeEnum $leDbEnum * @return string */ public function getMethodName(LeDbData $dto, LeDbTypeEnum $leDbEnum) { $dsn = ucfirst($dto->getDsn()); if (LeDbTypeEnum::master() == $leDbEnum) { $master = $leDbEnum->getLabel(); $output = "get{$master}ServerFor{$dsn}"; } else { $slave = $leDbEnum::slave()->getLabel(); $output = "get{$slave}{$dto->getServerNameAndZeroFillIfIp()}For{$dsn}"; } return $output; }
public function isMaster() { return LeDbTypeEnum::master()->doesLabelEq($this->getType()); }