-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUtil.php
More file actions
97 lines (78 loc) · 2.83 KB
/
Util.php
File metadata and controls
97 lines (78 loc) · 2.83 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
<?php
require __DIR__ . '/vendor/autoload.php';
use Lacuna\Amplia\AmpliaClient;
use Lacuna\Cloudhub\CloudhubClient;
use Lacuna\RestPki\RestPkiOptions;
use Lacuna\RestPki\RestPkiCoreClient;
use Lacuna\RestPki\RestPkiClient;
use Lacuna\RestPki\StandardSecurityContexts;
use Lacuna\PkiExpress\TimestampAuthority;
class Util {
//region REST PKI
public static function getRestPkiClient()
{
// Get configuration.
$config = getConfig();
// Get your token value from REST PKI configuration.
$accessToken = $config['restPki']['accessToken'];
// Throw exception if token is not set (this check is here just for the sake of newcomers, you
// can remove it).
if (empty($accessToken) || strpos($accessToken, ' ACCESS TOKEN ') !== false) {
throw new \Exception('The REST PKI access token was not set! Hint: to run this ' .
'sample you must generate an API access token on the REST PKI website and paste it ' .
'on the file config.php');
}
$endpoint = $config['restPki']['endpoint'];
return new RestPkiClient($endpoint, $accessToken);
}
public static function getCloudhubClient()
{
$config = getConfig();
$apiKey = $config['cloudHub']['apiKey'];
if (empty($apiKey) || strpos($apiKey, ' API KEY ') !== false) {
throw new \Exception('The Cloudhub API Key was not set!');
}
$endpoint = $config['cloudHub']['endpoint'];
return new CloudhubClient($endpoint, $apiKey);
}
public static function getSecurityContextId()
{
// Get configuration.
$config = getConfig();
if ($config['trustLacunaTestRoot']) {
return StandardSecurityContexts::LACUNA_TEST;
}
// In production, accept only certificates from ICP-Brasil.
return StandardSecurityContexts::PKI_BRAZIL;
}
//endregion
public static function setExpiredPage()
{
header('Expires: ' . gmdate('D, d M Y H:i:s', time() - 3600) . ' GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header('Cache-Control: private, no-store, max-age=0, no-cache, must-revalidate, post-check=0, pre-check=0');
header('Pragma: no-cache');
}
public static function getDateYearsFromNow($years)
{
return date('Y-m-d', strtotime("+{$years} years"));
}
public static function joinStringsPt($strings)
{
$text = '';
$count = count($strings);
$index = 0;
foreach ($strings as $s) {
if ($index > 0) {
if ($index < $count - 1) {
$text .= ', ';
} else {
$text .= ' e ';
}
}
$text .= $s;
++$index;
}
return $text;
}
}