|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Blitz PHP framework. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2022 Dimitri Sitchet Tomkeu <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view |
|
9
|
|
|
* the LICENSE file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace BlitzPHP\Security\Encryption\Handlers; |
|
13
|
|
|
|
|
14
|
|
|
use BlitzPHP\Contracts\Security\EncrypterInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Classe de base pour les gestionnaires de chiffrement |
|
18
|
|
|
*/ |
|
19
|
|
|
abstract class BaseHandler implements EncrypterInterface |
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* Constructeur |
|
23
|
|
|
*/ |
|
24
|
|
|
public function __construct(?object $config = null) |
|
25
|
|
|
{ |
|
26
|
|
|
$config ??= (object) config('encryption'); |
|
27
|
|
|
|
|
28
|
|
|
// rendre les paramètres facilement accessibles |
|
29
|
|
|
foreach (get_object_vars($config) as $key => $value) { |
|
30
|
|
|
if (property_exists($this, $key)) { |
|
31
|
|
|
$this->{$key} = $value; |
|
32
|
|
|
} |
|
33
|
|
|
} |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Byte-safe substr() |
|
38
|
|
|
*/ |
|
39
|
|
|
protected static function substr(string $str, int $start, ?int $length = null): string |
|
40
|
|
|
{ |
|
41
|
|
|
return mb_substr($str, $start, $length, '8bit'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Fourni un accès en lecture seule à certaines de nos propriétés |
|
46
|
|
|
* |
|
47
|
|
|
* @param string $key Nom de la propriete |
|
48
|
|
|
* |
|
49
|
|
|
* @return array|bool|int|string|null |
|
50
|
|
|
*/ |
|
51
|
|
|
public function __get($key) |
|
52
|
|
|
{ |
|
53
|
|
|
if ($this->__isset($key)) { |
|
54
|
|
|
return $this->{$key}; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
return null; |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Assure la vérification de certaines de nos propriétés |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $key Nom de la propriete |
|
64
|
|
|
*/ |
|
65
|
|
|
public function __isset($key): bool |
|
66
|
|
|
{ |
|
67
|
|
|
return property_exists($this, $key); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|