コード例 #1
0
 public static function getUserProperties() : array
 {
     try {
         $userClassName = \SoftUni\Config\UserConfig::UserIdentityClassName;
         $identityUserProperties = \SoftUni\FrameworkCore\CommonFunction::getClassProperties('SoftUni\\Models\\IdentityUser');
         if ($userClassName != 'IdentityUser') {
             $customUserProperties = \SoftUni\FrameworkCore\CommonFunction::getClassProperties($userClassName);
             //var_dump($customUserProperties);
             $result = $identityUserProperties;
             foreach ($customUserProperties as $customUserProperty => $type) {
                 $result[$customUserProperty] = $type;
             }
             return $result;
         }
         return $identityUserProperties;
     } catch (\Exception $pe) {
         throw new \Exception('Could not get User Properties. ' . $pe->getMessage());
     }
 }
コード例 #2
0
 private static function createModelTable($className)
 {
     $db = self::getInstance('app');
     $modelProperties = CommonFunction::getClassProperties($className);
     if (preg_match_all("#\\\\(\\w+?)\$#", $className, $match)) {
         $table = $match[1][0] . 's';
         $table = strtolower($table);
         $propertySQL = [];
         foreach ($modelProperties as $property => $propertyType) {
             if (strpos(strtolower($property), 'datetime')) {
                 $dataType = 'DATETIME';
             } else {
                 switch ($propertyType) {
                     case 'string':
                         $dataType = 'VARCHAR(255)';
                         break;
                     case 'int':
                         $dataType = 'INT(6)';
                         break;
                     case 'float':
                         $dataType = 'FLOAT(28,8)';
                         break;
                     case 'bool':
                         $dataType = 'BIT';
                         break;
                     default:
                         $dataType = 'VARCHAR(255)';
                 }
                 if ($property == 'Id') {
                     $dataType .= ' UNSIGNED AUTO_INCREMENT PRIMARY KEY';
                 }
             }
             $property = strtolower($property);
             $propertySQL[] = "{$property} {$dataType}";
         }
         $propertyQuery = implode(', ', $propertySQL);
         $query = "CREATE TABLE if not EXISTS " . $table . " (" . $propertyQuery . ")";
         $result = $db->prepare($query);
         $result->execute([':propertyQuery' => $propertyQuery, ':table' => $table]);
         //
         //            echo "CREATE TABLE if not EXISTS ".$table."  (".$propertyQuery.")";
         //            die;
         if ($result->rowCount() > 0) {
             return true;
         }
     }
 }