private static function viewAdjustment() { if (Helpers::endsWith(self::$actionName, "Pst") || Helpers::endsWith(self::$actionName, "Put") || Helpers::endsWith(self::$actionName, "Del")) { self::$actionName = substr(self::$actionName, 0, strlen(self::$actionName) - 3); } }
private function checkBindingModel() { $errors = []; $controller = AppConfig::CONTROLLERS_NAMESPACE . ucfirst($this->getControllerName()) . AppConfig::CONTROLLERS_SUFFIX; $reflector = new \ReflectionClass($controller); $method = $reflector->getMethod($this->action); if (!$method->getParameters()) { return; } $params = $method->getParameters(); $count = 0; foreach ($params as $param) { if ($param->getClass() !== null && class_exists($param->getClass()->getName(), false)) { $className = $param->getClass()->getName(); if (Helpers::endsWith($className, "BindingModel")) { $paramReflectorClass = new \ReflectionClass($param->getClass()->getName()); $bindingModelName = $paramReflectorClass->getName(); $bindingModel = new $bindingModelName(); $paramClassFields = $paramReflectorClass->getProperties(); foreach ($paramClassFields as $field) { $doc = $field->getDocComment(); $annotations = self::getBindingModelAnnotations($doc); $fieldName = $field->getName(); $setter = 'set' . $field->getName(); $displayName = array_key_exists("Display", $annotations) ? $annotations["Display"] : $fieldName; if (array_key_exists("Required", $annotations) && !isset($_POST[$fieldName]) || strlen($_POST[$fieldName]) === 0) { $errors[] = $displayName . " is required."; } else { if (array_key_exists("MinLength", $annotations) && isset($_POST[$fieldName]) && strlen($_POST[$fieldName]) < intval($annotations["MinLength"])) { $errors[] = "Min length for " . $displayName . " is " . $annotations["MinLength"]; } else { if (array_key_exists("MaxLength", $annotations) && isset($_POST[$fieldName]) && strlen($_POST[$fieldName]) > intval($annotations["MaxLength"])) { $errors[] = "Max length for " . $displayName . " is " . $annotations["MaxLength"]; } else { $bindingModel->{$setter}($_POST[$fieldName]); } } } } $this->params[] = $bindingModel; } } else { if (count($this->params) < $count + 1) { throw new \Exception("Different parameters count!"); } else { if (preg_match('/@param ([^\\s]+) \\$' . $param->getName() . "/", $method->getDocComment(), $parameterType)) { if ($parameterType[1] === "int") { $this->params[$count] = intval($this->params[$count]); } } } } $count++; } if (count($errors) > 0) { $redirect = $this->requestStr; if (HttpContext::getInstance()->getRequest()->getForm()->redirect !== "") { $redirect = HttpContext::getInstance()->getRequest()->getForm()->redirect; } $_SESSION["binding-errors"] = $errors; throw new ApplicationException("", $redirect); } }