| 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 |  |  |

1 | <?php
2 |
3 | namespace Tools;
4 |
5 | /**
6 | * Abstract Controller
7 | **/
8 | abstract class RestfullController extends AController
9 | {
10 | private $encode_fnc;
11 |
12 | public function __construct($context, $params, $encode_fnc = null)
13 | {
14 | if (!\Entity\Config::getConfig(null, "restfullEnabled", false))
15 | throw new \Exception\Error404();
16 | parent::__construct($context, $params);
17 | if ($encode_fnc === null)
18 | $encode_fnc = array("method" => json_encode, "mime" => "application/json");
19 | $this->encode_fnc = $encode_fnc;
20 | }
21 |
22 | public function start()
23 | {
24 | //TODO call some hooks
25 | header("Content-Type: {$this->encode_fnc["mime"]}");
26 | echo $this->encode_fnc["method"]($this->run());
27 | //TODO call some hooks
28 | }
29 |
30 | abstract public function run();
31 | }
32 |