예제 #1
0
 /**
  * @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;
 }
예제 #2
0
 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;
 }
예제 #3
0
파일: LeDb.php 프로젝트: guidamedia/leroy
 /**
  * @param LeDbData $dbData
  */
 public function buildConfigClass(LeDbData $dbData)
 {
     $this->initConfigClass($dbData);
     $jsonData = $this->getJsonDecodedData();
     $startPos = strrpos($this->getClassFileContents(), "}") - 1;
     $classContentTrimmed = substr($this->getClassFileContents(), 0, $startPos) . "\n";
     foreach ($jsonData as $accountId => $dsnData) {
         foreach ($dsnData as $dsn => $serverData) {
             $typeKeys = array_keys($serverData);
             if (in_array(LeDbTypeEnum::slave()->getValue(), $typeKeys)) {
                 foreach ($typeKeys as $type) {
                     if (LeDbTypeEnum::slave()->getValue() == $type) {
                         $data = $dbData->loadAll($serverData[$type]);
                     } else {
                         $data = $dbData->loadAll([$serverData[LeDbTypeEnum::master()->getValue()]]);
                     }
                     $this->buildMethods($data, $accountId, $dsn, $type, $classContentTrimmed);
                 }
             } else {
                 $type = current($typeKeys);
                 $datas = $dbData->loadAll($serverData);
                 $this->buildMethods($datas, $accountId, $dsn, $type, $classContentTrimmed);
             }
         }
     }
     $classContentTrimmed .= "}\n";
     $this->setClassFileContents($classContentTrimmed);
     $this->writeToClass();
 }
예제 #4
0
 public function isSlave()
 {
     return LeDbTypeEnum::slave()->doesLabelEq($this->getType());
 }