1: | <?php
|
2: | |
3: | |
4: | |
5: | |
6: | |
7: | |
8: | |
9: | |
10: |
|
11: | namespace Opencart\System\Engine;
|
12: | |
13: | |
14: |
|
15: | class Factory {
|
16: | |
17: | |
18: |
|
19: | protected \Opencart\System\Engine\Registry $registry;
|
20: |
|
21: | |
22: | |
23: | |
24: | |
25: |
|
26: | public function __construct(\Opencart\System\Engine\Registry $registry) {
|
27: | $this->registry = $registry;
|
28: | }
|
29: |
|
30: | |
31: | |
32: | |
33: | |
34: | |
35: | |
36: |
|
37: | public function controller(string $route): object {
|
38: |
|
39: | $route = preg_replace('/[^a-zA-Z0-9_\/]/', '', $route);
|
40: |
|
41: |
|
42: | $class = 'Opencart\\' . $this->registry->get('config')->get('application') . '\Controller\\' . str_replace(['_', '/'], ['', '\\'], ucwords($route, '_/'));
|
43: |
|
44: | if (class_exists($class)) {
|
45: | return new $class($this->registry);
|
46: | } else {
|
47: | return new \Exception('Error: Could not load controller ' . $route . '!');
|
48: | }
|
49: | }
|
50: |
|
51: | |
52: | |
53: | |
54: | |
55: | |
56: | |
57: |
|
58: | public function model(string $route): object {
|
59: |
|
60: | $route = preg_replace('/[^a-zA-Z0-9_\/]/', '', $route);
|
61: |
|
62: |
|
63: | $class = 'Opencart\\' . $this->registry->get('config')->get('application') . '\Model\\' . str_replace(['_', '/'], ['', '\\'], ucwords($route, '_/'));
|
64: |
|
65: |
|
66: | if (class_exists($class)) {
|
67: | return new $class($this->registry);
|
68: | } else {
|
69: | throw new \Exception('Error: Could not load model ' . $route . '!');
|
70: | }
|
71: | }
|
72: |
|
73: | |
74: | |
75: | |
76: | |
77: | |
78: | |
79: | |
80: |
|
81: | public function library(string $route, array $args): object {
|
82: |
|
83: | $route = preg_replace('/[^a-zA-Z0-9_\/]/', '', $route);
|
84: |
|
85: |
|
86: | $class = 'Opencart\System\Library\\' . str_replace(['_', '/'], ['', '\\'], ucwords($route, '_/'));
|
87: |
|
88: |
|
89: | if (class_exists($class)) {
|
90: | return new $class(...$args);
|
91: | } else {
|
92: | throw new \Exception('Error: Could not load library ' . $route . '!');
|
93: | }
|
94: | }
|
95: | }
|
96: | |