PageRenderTime 43ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/upload/system/engine/loader.php

https://github.com/opencartlite/opencart
PHP | 95 lines | 76 code | 19 blank | 0 comment | 12 complexity | 8c588dc3ede2bc20f0b7899e5a66f48a MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-3.0
  1. <?php
  2. final class Loader {
  3. protected $registry;
  4. public function __construct($registry) {
  5. $this->registry = $registry;
  6. }
  7. public function library($library) {
  8. $file = DIR_SYSTEM . 'library/' . $library . '.php';
  9. if (file_exists($file)) {
  10. include_once($file);
  11. } else {
  12. trigger_error('Error: Could not load library ' . $library . '!');
  13. exit();
  14. }
  15. }
  16. public function model($model) {
  17. $file = DIR_APPLICATION . 'model/' . $model . '.php';
  18. $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model);
  19. if (file_exists($file)) {
  20. include_once($file);
  21. $this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry));
  22. } else {
  23. trigger_error('Error: Could not load model ' . $model . '!');
  24. exit();
  25. }
  26. }
  27. public function view($model) {
  28. $file = DIR_APPLICATION . 'model/' . $model . '.php';
  29. $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model);
  30. if (file_exists($file)) {
  31. include_once($file);
  32. $this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry));
  33. } else {
  34. trigger_error('Error: Could not load model ' . $model . '!');
  35. exit();
  36. }
  37. }
  38. public function controller($model) {
  39. $file = DIR_APPLICATION . 'model/' . $model . '.php';
  40. $class = 'Model' . preg_replace('/[^a-zA-Z0-9]/', '', $model);
  41. if (file_exists($file)) {
  42. include_once($file);
  43. $this->registry->set('model_' . str_replace('/', '_', $model), new $class($this->registry));
  44. } else {
  45. trigger_error('Error: Could not load model ' . $model . '!');
  46. exit();
  47. }
  48. }
  49. public function helper($helper) {
  50. $file = DIR_SYSTEM . 'helper/' . $helper . '.php';
  51. if (file_exists($file)) {
  52. include_once($file);
  53. } else {
  54. trigger_error('Error: Could not load helper ' . $helper . '!');
  55. exit();
  56. }
  57. }
  58. public function database($driver, $hostname, $username, $password, $database) {
  59. $file = DIR_SYSTEM . 'database/' . $driver . '.php';
  60. $class = 'Database' . preg_replace('/[^a-zA-Z0-9]/', '', $driver);
  61. if (file_exists($file)) {
  62. include_once($file);
  63. $this->registry->set(str_replace('/', '_', $driver), new $class($hostname, $username, $password, $database));
  64. } else {
  65. trigger_error('Error: Could not load database ' . $driver . '!');
  66. exit();
  67. }
  68. }
  69. public function config($config) {
  70. $this->config->load($config);
  71. }
  72. public function language($language) {
  73. return $this->language->load($language);
  74. }
  75. }
  76. ?>