Controller.class.php 915 Bytes
Newer Older
Zohten's avatar
Zohten committed
1 2 3 4 5 6 7 8 9 10 11 12 13
<?php

/*
* A Controller is dedicated to process a request
* its responsabilities are:
* - analyses the action to be done
* - analyses the parameters
* - act on the model objects to perform the action
* - process the data
* - call the view and passes it the data
* - return the response
*/

Zohten's avatar
Zohten committed
14 15
abstract class Controller
{
Zohten's avatar
Zohten committed
16 17 18
    protected $name;
    protected $request;

Zohten's avatar
Zohten committed
19 20
    public function __construct($name, $request)
    {
Zohten's avatar
Zohten committed
21 22 23 24
        $this->request = $request;
        $this->name = $name;
    }

Zohten's avatar
Zohten committed
25
    abstract public function processRequest();
Zohten's avatar
Zohten committed
26

Zohten's avatar
Zohten committed
27 28
    public function execute()
    {
Zohten's avatar
Zohten committed
29
        $response = $this->processRequest();
Zohten's avatar
Zohten committed
30
        if (empty($response)) {
Zohten's avatar
Zohten committed
31 32 33 34 35
            // $response = Response::serverErrorResponse("error processing request in ". self::class); // Oh my PHP!
            $response = Response::serverErrorResponse("error processing request in ". static::class);
        }
        return $response;
    }
Zohten's avatar
Zohten committed
36
}