Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 10
RestfullController
0.00% covered (danger)
0.00%
0 / 1
33.33% covered (danger)
33.33%
1 / 3
30
0.00% covered (danger)
0.00%
0 / 10
 __construct
0.00% covered (danger)
0.00%
0 / 1
12
0.00% covered (danger)
0.00%
0 / 7
 start
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 run
100.00% covered (success)
100.00%
1 / 1
1  
 
<?php
namespace Tools;
/**
 * Abstract Controller
**/
abstract class RestfullController extends AController
{
    private $encode_fnc;
    public function __construct($context, $params, $encode_fnc = null)
    {
        if (!\Entity\Config::getConfig(null, "restfullEnabled", false))
            throw new \Exception\Error404();
        parent::__construct($context, $params);
        if ($encode_fnc === null)
            $encode_fnc = array("method" => json_encode, "mime" => "application/json");
        $this->encode_fnc = $encode_fnc;
    }
    public function start()
    {
        //TODO call some hooks
        header("Content-Type: {$this->encode_fnc["mime"]}");
        echo $this->encode_fnc["method"]($this->run());
        //TODO call some hooks
    }
    abstract public function run();
}