-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRunScripts.php
86 lines (74 loc) · 2.19 KB
/
RunScripts.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
<?php
use NunoLopes\Database\DomainContacts\Factories\Services\MigrationsServiceFactory;
use NunoLopes\Database\DomainContacts\Factories\Services\SeedsServiceFactory;
use NunoLopes\DomainContacts\Utilities\Signatures\Sha256RsaSignature;
/**
* Class RunScripts.
*
* Utility class to help running migrations via composer script.
*
* @package NunoLopes\DomainContacts
*/
class RunScripts
{
/**
* Run the migrations.
*
* @return void
*/
public static function migrate(): void
{
// Fix this helper is not autoloaded.
require_once(__DIR__ . '/vendor/illuminate/support/helpers.php');
MigrationsServiceFactory::get()->runMigrations();
}
/**
* Seed the database.
*/
public static function seed(): void
{
// Fix this helper is not autoloaded.
require_once(__DIR__ . '/vendor/illuminate/support/helpers.php');
SeedsServiceFactory::get()->seedDatabase();
}
/**
* Rollback migrations.
*
* @return void
*/
public static function rollback(): void
{
// Fix this helper is not autoloaded.
require_once(__DIR__ . '/vendor/illuminate/support/helpers.php');
MigrationsServiceFactory::get()->rollbackMigrations();
}
/**
* Generates a new KeyPair in the storage folder.
*
* @return void
*/
public static function generateKeyPair(): void
{
$config = array(
"digest_alg" => "sha256",
"private_key_bits" => 2048,
"private_key_type" => OPENSSL_KEYTYPE_RSA,
);
// Create the private and public key
$res = openssl_pkey_new($config);
// Extract the private key from $res to $privKey
openssl_pkey_export($res, $privKey);
// Extract the public key from $res to $pubKey
$pubKey = openssl_pkey_get_details($res);
$pubKey = $pubKey["key"];
// Store the private and the public key in the filesystem.
\file_put_contents(
__DIR__ . '/storage/oauth-private.key',
$privKey
);
\file_put_contents(
__DIR__ . '/storage/oauth-public.key',
$pubKey
);
}
}