| 1234567891011121314151617181920212223242526272829303132 |
- <?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();
- }
|