-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.php
More file actions
153 lines (138 loc) · 3.58 KB
/
code.php
File metadata and controls
153 lines (138 loc) · 3.58 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
<?php
/**
* @package Joomla.Component.Builder
*
* @created 4th September, 2022
* @author Llewellyn van der Merwe <https://dev.vdm.io>
* @git Joomla Component Builder <https://git.vdm.dev/joomla/Component-Builder>
* @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
namespace VDM\Joomla\Componentbuilder\Server\Model;
use Joomla\Registry\Registry;
use VDM\Joomla\Componentbuilder\Compiler\Factory;
use VDM\Joomla\Componentbuilder\Crypt;
use VDM\Joomla\Componentbuilder\Table;
use VDM\Joomla\Utilities\StringHelper;
use VDM\Joomla\Utilities\JsonHelper;
use VDM\Joomla\Interfaces\ModelInterface;
use VDM\Joomla\Abstraction\Model;
/**
* Server Model Load Class
*
* @since 3.2.0
*/
class Load extends Model implements ModelInterface
{
/**
* Decryption Class
*
* @var Crypt
* @since 3.2.0
*/
protected Crypt $crypt;
/**
* Constructor
*
* @param Crypt|null $crypt The core crypt object.
* @param Table|null $table The search table object.
*
* @since 3.2.0
*/
public function __construct(?Crypt $crypt = null, ?Table $table = null)
{
parent::__construct($table ?? Factory::_('Table'));
$this->crypt = $crypt ?: Factory::_('Crypt');
}
/**
* Model the value
* Example: $this->value(value, 'value_key', 'table_name');
*
* @param mixed $value The value to model
* @param string $field The field key
* @param string|null $table The table
*
* @return mixed
* @since 3.2.0
*/
public function value($value, string $field, ?string $table = null)
{
// load the table
if (empty($table))
{
$table = $this->getTable();
}
// check if this is a valid table
if (StringHelper::check($value) && ($store = $this->table->get($table, $field, 'store')) !== null)
{
// open the value based on the store method
switch($store)
{
case 'basic_encryption':
$value = $this->crypt->decrypt($value, 'basic');
break;
case 'medium_encryption':
$value = $this->crypt->decrypt($value, 'medium');
break;
case 'base64':
$value = base64_decode((string) $value);
break;
case 'json':
// check if there is a json string
if (JsonHelper::check($value))
{
$registry = new Registry;
$registry->loadString($value);
$value = $registry->toArray();
}
break;
default:
if ($this->crypt->exist($store))
{
$value = $this->crypt->decrypt($value, $store);
}
break;
}
}
return $value;
}
/**
* Validate before the value is modelled
*
* @param mixed $value The field value
* @param string|null $field The field key
* @param string|null $table The table
*
* @return bool
* @since 3.2.0
*/
protected function validateBefore(&$value, ?string $field = null, ?string $table = null): bool
{
// remove none
return true;
}
/**
* Validate after the value is modelled
*
* @param mixed $value The field value
* @param string|null $field The field key
* @param string|null $table The table
*
* @return bool
* @since 3.2.0
*/
protected function validateAfter(&$value, ?string $field = null, ?string $table = null): bool
{
return true;
}
/**
* Get the current active table
*
* @return string
* @since 3.2.0
*/
protected function getTable(): string
{
return 'server';
}
}