Example #1
0
 public function execute()
 {
     $suffix = "Controller";
     Router::parseUri();
     try {
         $_cc = ucfirst(Router::getController()) . $suffix;
         Loader::autoload($_cc);
         if (!class_exists($_cc, false) && !interface_exists($_cc, false)) {
             throw new Exception('Class ' . $_cc . ' does not exist');
         }
         $class = new ReflectionClass($_cc);
         if ($class->isAbstract()) {
             throw new Exception('Cannot create instances of abstract ' . $_cc . '');
         }
         // Create a new instance of the controller
         $controller = $class->newInstance();
         // Execute the "before action" method
         //$class->getMethod('before')->invoke($controller);
         // Execute the main action with the parameters
         $class->getMethod(Router::getAction() . 'Action')->invokeArgs($controller, Router::getParams());
         // Execute the "after action" method
         //$class->getMethod('after')->invoke($controller);
     } catch (Exception $e) {
         throw $e;
     }
     return $this;
 }
include "bindingModels" . DS . "LoginBindingModel.php";
include "bindingModels" . DS . "RegisterBindingModel.php";
include "bindingModels" . DS . "ManageUserBindingModel.php";
include "bindingModels" . DS . "AddProductBindingModel.php";
include "bindingModels" . DS . "AddCategoryBindingModel.php";
include "bindingModels" . DS . "DeleteCategoryBindingModel.php";
include "bindingModels" . DS . "MoveToCategoryBindingModel.php";
include "bindingModels" . DS . "QuantityChangedBindingModel.php";
include "viewModels" . DS . "ListProductsViewModel.php";
include "viewModels" . DS . "CheckoutViewModel.php";
include "viewModels" . DS . "chooseProductsToSellViewModel.php";
include "viewModels" . DS . "ChooseProductToMoveToCategoryViewModel.php";
include "viewModels" . DS . "MoveProductToCategoryViewModel.php";
// get route data
$routeConfig = (include "config" . DS . "routes.php");
$route = Router::parseUri($_SERVER['REQUEST_URI']);
// determine which controller should be invoked based on the URL and Route configuration
$controllersDir = isset($route['area']) ? "areas" . DS . $route['area'] . DS . "controllers" . DS : "controllers" . DS;
$controllerFilePath = $controllersDir . $route['controller'] . ".php";
if (file_exists($controllerFilePath)) {
    include $controllerFilePath;
} else {
    die("<h2>No such controller found: <i>" . $controllerFilePath . "</i></h2>");
}
$controllerInstance = new $route['controller']();
// bind Post model
if ($_SERVER['REQUEST_METHOD'] === "POST") {
    $reflection = new ReflectionMethod($controllerInstance, $route['method']);
    if (isset($reflection->getParameters()[0])) {
        $param = $reflection->getParameters()[0];
    } else {