ecom
E-commerce cms
 All Data Structures Namespaces Files Functions Variables
AHttpController.php
Go to the documentation of this file.
1 <?php
2 
3 namespace Tools;
4 
5 abstract class AHttpController extends AController
6 {
12  private $theme;
13 
18  private $output;
19 
20  public function __construct($context, $params)
21  {
22  parent::__construct($context, $params);
23  $this->output = new \Tools\Output($context);
24  $this->loadTheme();
25  }
26 
30  private function loadTheme()
31  {
32  $themeName = \Entity\Config::getConfig(null, "theme", "default");
33  $themeDir = $this->context->router->themesPath.$themeName.'/';
34  if (!is_dir($themeDir))
35  throw new \Exception\Error404();
36  $this->theme = $themeDir;
37  }
38 
42  public function start()
43  {
44  //TODO trigger hook GET, POST
45  //TODO call some hooks
46  $this->run();
47  //TODO calls some hooks
48  }
49 
55  protected function render($viewFile)
56  {
57  $themedir = opendir($this->theme);
58  $exists = false;
59  while ($dir = readdir($themedir))
60  {
61  if ($dir !== $viewFile || is_dir($this->theme.'/'.$dir))
62  continue;
63  $exists = $dir;
64  }
65  closedir($themedir);
66  if ($exists === false)
67  return false;
68  $this->output->renderFile($this->theme . $exists);
69  return true;
70  }
71 
72  public abstract function run();
73 
74  public function __get($key)
75  {
76  if ($key === "theme")
77  return $this->theme;
78  throw new \Exception("Cannot access attribute {$key}");
79  }
80 }
81 
static getConfig($lang=null, $key=null, $defaultValue=null)
Definition: Config.php:44
__construct($context, $params)