-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVastn3.php
125 lines (112 loc) · 3.83 KB
/
Vastn3.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
<?php
/* Generated by neoan3-cli */
namespace Neoan3\Frame;
use Neoan3\Apps\Db;
use Neoan3\Apps\DbException;
use Neoan3\Apps\Stateless;
use Neoan3\Core\Serve;
use PHPMailer\PHPMailer\PHPMailer;
class Vastn3 extends Serve
{
private $credentials = [];
private $loadedComponents = [];
function __construct()
{
parent::__construct();
if ($_SERVER['HTTP_HOST'] == 'localhost') {
$this->includeJs(base . 'node_modules/vue/dist/vue.js');
} else {
$this->includeJs(base . 'node_modules/vue/dist/vue.min.js');
}
try {
$this->credentials = getCredentials();
} catch (\Exception $e) {
print('SETUP: No credentials found. Please check README for instructions and/or change ' . __FILE__ . ' starting at line ' . (__LINE__ - 4) . ' ');
die();
}
// default header
$this->vueComponent('header');
$this->hook('header', 'header');
$this->setup();
}
function constants()
{
return [
'base' => [base],
'meta' => [
['name' => 'viewport', 'content' => 'width=device-width, initial-scale=1.0']
],
'stylesheet' => [base . 'frame/vastn3/style.css'],
'js' => [
['src' => path . '/node_modules/axios/dist/axios.min.js', 'data'=>['base' => base]],
['src' => 'https://cdn.jsdelivr.net/npm/lodash@latest/lodash.min.js'],
['src' => path . '/frame/vastn3/main.js', 'data' => ['base' => base]]
]
];
}
// vuejs integration
function output($params = [])
{
$this->js .= 'new Vue({el:"#root"});';
$this->main = '<div id="root" class="main">' . $this->header . $this->main . '</div>';
$this->header = '';
parent::output($params);
}
function vueComponents($components, $params = [])
{
foreach ($components as $component) {
$this->vueComponent($component, $params);
}
return $this;
}
function vueComponent($element, $params = [])
{
if(in_array($element,$this->loadedComponents)){
return $this;
}
$this->loadedComponents[] = $element;
$params['base'] = base;
$path = path . '/component/' . $element . '/' . $element . '.ce.';
if (file_exists($path . $this->viewExt)) {
$this->footer .= '<template id="' . $element . '">' . $this->fileContent($path . $this->viewExt, $params) .
'</template>';
}
if (file_exists($path . $this->styleExt)) {
$this->style .= $this->fileContent($path . $this->styleExt, $params);
}
if (file_exists($path . 'js')) {
$this->js .= $this->fileContent($path . 'js', $params);
}
// dependencies?
$phpCtrl = path . '/component/' . $element . '/' . ucfirst($element) . '.ctrl.php';
if (file_exists($phpCtrl)) {
$class = '\\Neoan3\\Components\\' . ucfirst($element);
if (method_exists($class, 'dependencies')) {
$dependencies = "$class::dependencies";
$this->vueComponents($dependencies(), $params);
}
}
return $this;
}
function newEmail()
{
$wrapper = new PHPMailer(true);
$wrapper->isSMTP();
$wrapper->isHTML(true);
foreach (getCredentials()['vastn3_mail'] as $property => $value){
$wrapper->$property = $value;
}
return $wrapper;
}
private function setup()
{
// stateless
Stateless::setSecret($this->credentials['salts']['vastn3']);
// db
try {
Db::setEnvironment($this->credentials['vastn3_db']);
} catch (DbException $e) {
print('database currently unavailable');
}
}
}