PageRenderTime 52ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/system/engine/loader.php

https://bitbucket.org/jjasko/opencart_serbian
PHP | 64 lines | 51 code | 13 blank | 0 comment | 6 complexity | d8b297ee2a7a9c312c6712f0ccc75d48 MD5 | raw file
  1. <?php
  2. final class Loader {
  3. protected $registry;
  4. public function __construct($registry) {
  5. $this->registry = $registry;
  6. }
  7. public function __get($key) {
  8. return $this->registry->get($key);
  9. }
  10. public function __set($key, $value) {
  11. $this->registry->set($key, $value);
  12. }
  13. public function library($library) {
  14. $file = DIR_SYSTEM . 'library/' . $library . '.php';
  15. if (file_exists($file)) {
  16. include_once($file);
  17. } else {
  18. trigger_error('Error: Could not load library ' . $library . '!');
  19. exit();
  20. }
  21. }
  22. public function model($model) {
  23. $file = DIR_APPLICATION . 'model/' . $model . '.php';
  24. $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model);
  25. if (file_exists($file)) {
  26. include_once($file);
  27. $this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry));
  28. } else {
  29. trigger_error('Error: Could not load model ' . $model . '!');
  30. exit();
  31. }
  32. }
  33. public function database($driver, $hostname, $username, $password, $database, $prefix = NULL, $charset = 'UTF8') {
  34. $file = DIR_SYSTEM . 'database/' . $driver . '.php';
  35. $class = 'Database' . preg_replace('/[^a-zA-Z0-9]/', '', $driver);
  36. if (file_exists($file)) {
  37. include_once($file);
  38. $this->registry->set(str_replace('/', '_', $driver), new $class());
  39. } else {
  40. trigger_error('Error: Could not load database ' . $driver . '!');
  41. exit();
  42. }
  43. }
  44. public function config($config) {
  45. $this->config->load($config);
  46. }
  47. public function language($language) {
  48. return $this->language->load($language);
  49. }
  50. }
  51. ?>