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()); } }
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; } } }
public static function getAnnotations() { $controllersFilePaths = CommonFunction::getDirContents($_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'Controllers'); $annotations = []; $annotations['byType'] = []; $annotations['byController'] = []; foreach ($controllersFilePaths as $controllersFilePath) { //var_dump($controllersFilePath); //var_dump($annotations); if (preg_match('/Controllers\\' . DIRECTORY_SEPARATOR . '(.*?).php/', $controllersFilePath, $match)) { $className = $match[1]; $fileName = $className . '.php'; require_once 'Controllers' . DIRECTORY_SEPARATOR . $fileName; //echo "class:".$className; // Get Class Annotations if (class_exists('SoftUni\\Controllers\\' . $className)) { $classAnnotations = []; $reflectionClass = new \ReflectionClass('SoftUni\\Controllers\\' . $className); $doc = $reflectionClass->getDocComment(); if ($doc) { $classAnnotations = self::extractAnnotations($doc, $classAnnotations); //echo "<br/><br/>".json_encode($classAnnotations, JSON_PRETTY_PRINT)."<br/>"; } // Get Method Annotations $methods = $reflectionClass->getMethods(); foreach ($methods as $method) { $methodName = $method->getName(); $methodDoc = $method->getDocComment(); if ($methodDoc != null) { $methodAnnotations = self::extractAnnotations($methodDoc, $classAnnotations); //echo $methodName.": ".json_encode($methodAnnotations, JSON_PRETTY_PRINT)."<br/>"; } else { $methodAnnotations = []; foreach ($classAnnotations as $annotationType => $value) { if ($annotationType != 'Route') { $methodAnnotations[$annotationType] = $value; } } } // Add extracted annotaions to all Annotations foreach ($methodAnnotations as $methodAnnotationType => $methodAnnotationProperty) { $annotations['byType'][$methodAnnotationType][] = array("property" => $methodAnnotationProperty, "controller" => $className, "action" => $methodName); $annotations['byController'][$className][$methodName][$methodAnnotationType] = $methodAnnotationProperty; } // Add GET annotation if no Get, Post, Put or Delete annotation is available if (isset($annotations['byController'][$className][$methodName])) { //var_dump($annotations['byController'][$className][$methodName]); $httpRequestAnnotation = array_filter(array_keys($annotations['byController'][$className][$methodName]), function ($annotationType) { //var_dump($annotationType); if (preg_match('#(Get|Post|Delete|Put)#i', $annotationType)) { return true; } return false; }); } else { $httpRequestAnnotation = []; } if (count($httpRequestAnnotation) == 0) { $getAnnotation = new GetAnnotation(); $getAnnotationProperty = $getAnnotation->onInitialize('GET'); $annotations['byController'][$className][$methodName]['GET'] = $getAnnotationProperty; } } } } } self::$allAnnotations = $annotations; }