ecom
E-commerce cms
 All Data Structures Namespaces Files Functions Variables
ARestfullController.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Tools;
4 
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 
__construct($context, $params, $encode_fnc=null)