public function start()
 {
     $this->initController();
     View::$controllerName = $this->controllerName;
     View::$actionName = $this->actionName;
     call_user_func_array([$this->controller, $this->actionName], $this->requestParams);
 }
 private function callControllerAction($params)
 {
     View::$controllerName = $this->controllerName;
     View::$actionName = $this->actionName;
     $actionName = $this->actionName;
     $this->controller->{$actionName}($params);
 }
 public function start()
 {
     \Softuni\Router::readAllRoutes();
     $uri = Router::make_uri();
     $params = Router::match_uri($uri);
     //var_dump($params);
     if ($params) {
         $controller = ucwords($params['controller']);
         $this->actionName = $params['action'];
         unset($params['controller'], $params['action']);
         $this->controllerName = $controller;
         $classes = get_declared_classes();
         $pattern = '/.*\\\\' . $this->controllerName . '$/';
         //var_dump($pattern);
         $filteredClasses = array_filter($classes, function ($class) use($pattern) {
             if (preg_match($pattern, $class, $match)) {
                 return $class;
             }
         });
         //var_dump($filteredClasses);
         if ($filteredClasses) {
             foreach ($filteredClasses as $filteredClass) {
                 //var_dump($filteredClass);
                 if (method_exists($filteredClass, $this->actionName)) {
                     if (preg_match('/Areas\\\\(.*?)\\\\/', $filteredClass, $match)) {
                         View::$area = $match[1];
                     }
                     $this->controller = new $filteredClass();
                     View::$controllerName = $this->controllerName;
                     View::$actionName = $this->actionName;
                     call_user_func_array(array($this->controller, $this->actionName), $params);
                 } else {
                     throw new \Exception("Method not found");
                 }
             }
         } else {
             throw new \Exception("Controller not found");
         }
     } else {
         throw new \Exception("Route not found");
     }
 }
Exemple #4
0
}
if (!isset($controller)) {
    $requestUri = explode("/", $uri);
    $controller = array_shift($requestUri);
    $action = array_shift($requestUri);
    $controllerNamespace = '\\Framework\\Controllers\\';
}
$controllerName = $controllerNamespace . ucfirst($controller) . 'Controller';
spl_autoload_register(function ($class) {
    $splitted = explode("\\", $class);
    array_shift($splitted);
    $fullClassName = implode(DIRECTORY_SEPARATOR, $splitted);
    require_once $fullClassName . '.php';
});
View::$controllerName = $controller;
View::$actionName = $action;
Token::tokenValidationCheck();
$refc = new \ReflectionClass($controllerName);
$method = $refc->getMethod($action);
if (count($method->getParameters()) > 0 && is_object($method->getParameters()[0])) {
    $propertyObject = $method->getParameters()[0]->getClass();
    if (is_object($propertyObject)) {
        $properties = $propertyObject->getProperties();
        foreach ($properties as $property) {
            if (!isset($_POST[$property->getName()])) {
                throw new \Exception("Invalid properties for binding model");
            }
        }
        $bindingModelName = $propertyObject->getName();
        $bindingModelObject = new $bindingModelName();
        foreach ($properties as $property) {