Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-ports-kde
Path: blob/main/databases/adminer/files/makephar.php
16461 views
1
<?php
2
/***********************************************************
3
*
4
* Merges adminer.php and it's plugins to a phar archive
5
*
6
***********************************************************/
7
8
$phar = new Phar(
9
$tmpFile = __DIR__ . '/adminer_' . bin2hex(random_bytes(8)) . '.phar',
10
0,
11
'adminer.phar'
12
);
13
14
$stub = <<<STUB
15
<?php
16
/******************************************************************************
17
*
18
* All Adminer plugins are now included in this
19
* FreeBSD ports edition, no need to download
20
* them separately.
21
* https://www.adminer.org/en/plugins/
22
*
23
* copyright Paavo-Einari Kaipila (FreeBSD ports edition)
24
* copyright Jakub Vrana (original Adminer)
25
*
26
* Licensed under the Apache License, Version 2.0 (the "License");
27
* you may not use this file except in compliance with the License.
28
* You may obtain a copy of the License at
29
*
30
* http://www.apache.org/licenses/LICENSE-2.0
31
*
32
* Unless required by applicable law or agreed to in writing, software
33
* distributed under the License is distributed on an "AS IS" BASIS,
34
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
35
* See the License for the specific language governing permissions and
36
* limitations under the License.
37
*
38
******************************************************************************/
39
if (file_exists(\$adminerObjectFile = __DIR__ . '/adminer-object.php'))
40
{
41
require \$adminerObjectFile;
42
}
43
Phar::mapPhar('adminer.phar');
44
define('ADMINER_PLUGIN_CLASSMAP', json_decode('%s', true));
45
require 'phar://adminer.phar/autoload.php';
46
__HALT_COMPILER();
47
STUB;
48
49
$classMap = [];
50
$plugins = [];
51
52
foreach(new DirectoryIterator(__DIR__ . '/plugins') as $file)
53
{
54
if ($file->isFile())
55
{
56
$contents = php_strip_whitespace($file->getRealPath());
57
$pharFile = 'adminer-plugins/' . $file->getFileName();
58
$plugins[$pharFile] = $contents;
59
if (preg_match('/class\s(A[a-zA-Z]+)\sextends\sAdminer/', $contents, $m))
60
{
61
$classMap[$m[1]] = $file->getFileName();
62
}
63
}
64
}
65
66
$phar->setStub(
67
sprintf(
68
$stub,
69
json_encode($classMap, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)
70
)
71
);
72
73
$autoLoader = <<<LOADER
74
<?php
75
spl_autoload_register(function(\$class)
76
{
77
if (isset(ADMINER_PLUGIN_CLASSMAP[\$class]))
78
{
79
require __DIR__ . '/adminer-plugins/' . ADMINER_PLUGIN_CLASSMAP[\$class];
80
return true;
81
}
82
});
83
require __DIR__ . '/adminer.php';
84
LOADER;
85
86
$phar->addFromString(
87
'autoload.php',
88
$autoLoader
89
);
90
91
foreach($plugins as $file => $contents)
92
{
93
$phar->addFromString(
94
$file,
95
$contents
96
);
97
}
98
99
$phar->addFromString(
100
'adminer.php',
101
php_strip_whitespace(__DIR__ . '/adminer.php'),
102
);
103
104
rename($tmpFile, __DIR__ . '/index.php');
105
106