Beispiel #1
0
 /**
  * Save database credentials
  *
  * Credentials are initially stored as associative arrays which are replaced with instances Database upon
  * first call to getDb() method
  *
  * @param PlainObject $dbs
  * @throws KernelException
  */
 private function setDatabases(PlainObject $dbs)
 {
     $dbs = json_decode(json_encode($dbs), true);
     $requiredKeys = ["driver", "host", "username", "password", "name"];
     $this->databases = [];
     foreach ($dbs as $id => $credentials) {
         $id = is_string($id) ? $id : strval($id);
         if (!is_array($credentials)) {
             // Credentials must be in an associative array
             throw KernelException::badDbCredentials($id);
         }
         foreach ($requiredKeys as $required) {
             if (!array_key_exists($required, $credentials)) {
                 // A required key is missing
                 throw KernelException::badDbCredentials($id, $required);
             }
             // Convert NULL types to empty strings
             if (is_null($credentials[$required])) {
                 $credentials[$required] = "";
             }
         }
         // Save credentials for time being
         $this->databases[$id] = $credentials;
     }
 }