/** * @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 array $datas * @param int $accountId * @param string $dsn * @param string $type * @param string $classContentTrimmed * @return string */ private function buildMethods($datas, $accountId, $dsn, $type, &$classContentTrimmed) { /** * @var LeDbData $data */ $tab = ' '; $tab2 = $tab . $tab; $tabs3 = $tab2 . $tab; $tabs4 = $tabs3 . $tab; $tabs5 = $tabs4 . $tab; $tabs6 = $tabs5 . $tab; foreach ($datas as $data) { $data->setAccountId($accountId); $data->setDsn($dsn); $methodName = $this->getMethodName($data, LeDbTypeEnum::getFromValue($type)); $classContentTrimmed .= "\n" . " /**\n" . " * @param int \$accountId\n" . " * @return LeDbConfig\n" . " */\n" . " public static function {$methodName}(\$accountId)\n" . " {\n" . " switch (\$accountId) {\n" . " case {$accountId}:\n" . " return new LeDbConfig(\n" . " new LeValidator(),\n" . " [\n" . " 'server' => '{$data->getServer()}',\n" . " 'dbName' => '{$data->getDbName()}',\n" . " 'userName' => '{$data->getUserName()}',\n" . " 'password' => '{$data->getPassword()}',\n" . " 'port' => '{$data->getPort()}',\n" . " 'type' => '{$type}',\n" . " ]\n" . " );\n" . " break;\n" . " }\n" . " }\n"; } return $classContentTrimmed; }
public function isSlave() { return LeDbTypeEnum::slave()->doesLabelEq($this->getType()); }