1 <?php
2
3 4 5 6 7 8
9
10 namespace nk2580\wordsmith\Environment;
11
12 use Philo\Blade\Blade as Blade;
13
14 class Instance {
15
16 protected static $_instances = array();
17 private $dir;
18 private $uri;
19 public $APP_DIR;
20 public $EXTENSIONS_DIR;
21 public $CONTROLLER_DIR;
22 public $VIEW_DIR;
23 public $CACHE_DIR;
24 public $BOWER_URI;
25 public $ASSET_DIR;
26
27 public function __construct($dir, $uri) {
28 self::$_instances[] = $this;
29 $this->dir = $dir;
30 $this->uri = $uri;
31 $config = include $this->dir . "/wordsmith.php";
32 $this->APP_DIR = $this->dir . $config["APP_DIR"];
33 $this->CONTROLLER_DIR = $this->dir . $config["CONTROLLER_DIR"];
34 $this->EXTENSIONS_DIR = $this->dir . $config["EXTENSIONS_DIR"];
35 $this->VIEW_DIR = $this->dir . $config["VIEW_DIR"];
36 $this->CACHE_DIR = $this->dir . $config["CACHE_DIR"];
37 $this->BOWER_URI = $this->uri . $config["BOWER_URI"];
38 $this->ASSET_DIR = $this->uri . $config["ASSET_DIR"];
39 $this->boot();
40 }
41
42 public function boot() {
43 self::loadDir($this->EXTENSIONS_DIR);
44 self::loadDir($this->APP_DIR);
45 self::loadDir($this->CONTROLLER_DIR);
46 }
47
48 private static function loadDir($dir) {
49 $ffs = scandir($dir);
50 $i = 0;
51 foreach ($ffs as $ff) {
52 if ($ff != '.' && $ff != '..') {
53 if (strlen($ff) >= 5) {
54 if (substr($ff, -4) == '.php') {
55 include $dir . '/' . $ff;
56 }
57 }
58 if (is_dir($dir . '/' . $ff))
59 self::loadDir($dir . '/' . $ff);
60 }
61 }
62 }
63
64 public function View() {
65 $blade = new Blade($this->VIEW_DIR, $this->CACHE_DIR);
66 return $blade;
67 }
68
69 }
70