Example #1
0
 /**
  * __construct
  * @param array $config optional
  **/
 public function __construct($config = array())
 {
     self::$instance = $this;
     //** Config
     $this->config = new Config();
     if (is_array($config) && count($config)) {
         while (list($key, $value) = each($config)) {
             $this->config->set($key, $value);
         }
     }
     //-- End Config
     if ($this->config->get('path.basepath') == '') {
         $this->config->set('path.basepath', getcwd() . '/');
     }
     self::$header[] = $_SERVER["SERVER_PROTOCOL"] . ' ' . Route::$HTTP_RESPONSE[200];
     $this->route = new Route();
     Route::init();
     Route::$BASEPATH = $this->config->get('path.basepath');
     $this->url = new Url(Route::$PROTOCOL, Route::$BASEURL, Route::$BASEPATH);
     $this->assets = new Assets($this->url);
     $this->request = new Request();
     //** ID: Memasukan Libary/Pustaka berdasarkan config | EN: Load Dynamic Libraries from config
     $libraries = $this->config->get('libraries');
     if (is_array($libraries) && count($libraries) > 0) {
         while (list($library, $params) = each($libraries)) {
             $clsLibrary = 'Kecik\\' . $library;
             if (class_exists($clsLibrary)) {
                 if (isset($params['enable']) && $params['enable'] === TRUE) {
                     $library = strtolower($library);
                     //** ID: Untuk Library/Pustaka tanpa parameter
                     //** EN: For Library without parameter
                     if (!isset($params['config']) && !isset($params['params'])) {
                         //** ID: Untuk Library/Pustaka DIC | EN: For DIC Library
                         if ($library == 'dic') {
                             $this->container = new DIC();
                         } elseif ($library == 'mvc') {
                             if (isset($this->db)) {
                                 MVC::setDB($this->db);
                             }
                         } else {
                             // ID: Untuk Library/Pustaka lain | EN: Other Library
                             $this->{$library} = new $clsLibrary();
                         }
                         //** ID: Untuk Library/Pustaka dengan parameter Kelas Kecik
                         //** EN: For Library with parameter of Kecik CLass
                     } elseif (isset($params['config'])) {
                         //** ID: Buat variabel config
                         //** EN: Create config variable
                         while (list($key, $value) = each($params['config'])) {
                             $this->config->set($library . '.' . $key, $value);
                         }
                         //** ID: untuk Library/Pustaka Database | EN: For Database Library
                         if ($library == 'database') {
                             $this->db = new Database();
                             if (class_exists('MVC')) {
                                 MVC::setDB($this->db);
                             }
                         } else {
                             //** ID: untuk Library/Pustaka lain | EN: For Other library
                             $this->{$library} = new $clsLibrary();
                         }
                         //** ID: Untuk Library/Pustaka tanpa parameter Kelas Kecik
                         //** EN: For Library without parameter of Kecik CLass
                     } elseif (isset($params['params'])) {
                         $this->{$library} = new $clsLibrary($params['params']);
                     }
                 }
             }
         }
     }
     //-- ID: Akhir untuk memasukan library/pustaka secara dinamis
     //-- EN: End Load Dynamic Library
     spl_autoload_register(array($this, 'autoload'), true, true);
 }