-
Notifications
You must be signed in to change notification settings - Fork 18
/
Framework.php
127 lines (104 loc) · 3.22 KB
/
Framework.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<?php
/*
* Created on Tue Dec 10 2019 by DaRock
*
* Aweb Design
* https://www.awebdesign.ro
*
*/
namespace OpenCore;
define('LARAVEL_START', microtime(true));
/*
|--------------------------------------------------------------------------
| Register The Auto Loader
|--------------------------------------------------------------------------
|
| Composer provides a convenient, automatically generated class loader for
| our application. We just need to utilize it! We'll simply require it
| into the script here so that we don't have to worry about manual
| loading any of our classes later on. It feels great to relax.
|
*/
require __DIR__ . '/vendor/autoload.php';
class Framework
{
public static $instance;
private $app;
private $response;
private $request = null;
private $kernel;
private $registry;
public $route;
public $output;
public function __construct()
{
$this->app = require __DIR__ . '/bootstrap/app.php';
$this->kernel = $this->app->make(\Illuminate\Contracts\Http\Kernel::class);
$this->app->singleton('OcLoader', function () {
$OcLoader = new \OpenCore\Support\OcLoader();
/**
* set loaded true in order to know the request was done through OpenCart
*/
$OcLoader->set('loaded', true);
return $OcLoader;
});
}
/**
* Bootstrap Instance
*/
public static function getInstance()
{
if (!(self::$instance instanceof self)) {
$app = new self();
self::$instance = $app;
}
return self::$instance;
}
/**
* Retrieve Response
*/
public function getResponse()
{
$this->response->sendHeaders();
$content = $this->response;
$this->kernel->terminate($this->request, $this->response);
return $content;
}
public function getRegistry($type = null)
{
if ($type) {
return $this->registry->get($type);
}
return $this->registry;
}
/**
* Handle Framework Response
*/
public function handle($registry, $route, &$output)
{
$this->registry = $registry;
$this->route = $route;
$this->output = $output;
$this->request = \Illuminate\Http\Request::capture();
/**
* force admin route in case the request comes from admin side
*/
$appBaseName = basename(DIR_APPLICATION) . '/';
if (defined('HTTPS_CATALOG')) {
$serverName = $this->request->server->get('SCRIPT_NAME');
$this->request->server->set('SCRIPT_NAME', str_replace($appBaseName, '', $serverName));
}
/**
* Change URI for partial loaded controllers like common/header, common/footer etc...
* in order to be able to override them
*/
if ($this->output !== false) {
$this->request->server->set('REQUEST_URI', $this->route);
}
$this->response = $this->kernel->handle($this->request);
if ($this->response instanceof \Symfony\Component\HttpFoundation\BinaryFileResponse) {
$this->response->send();
}
$this->kernel->terminate($this->request, $this->response);
}
}