2019-06-18 12:31:44 +02:00
|
|
|
<?php
|
2020-01-31 19:29:43 +01:00
|
|
|
|
2019-06-18 12:31:44 +02:00
|
|
|
// Polyfill for some PHP 5 functions
|
|
|
|
function callMe($allable, ...$args)
|
|
|
|
{
|
|
|
|
return $allable(...$args);
|
|
|
|
}
|
2019-09-02 17:08:36 +02:00
|
|
|
function returnMe($res)
|
|
|
|
{
|
2019-06-18 12:31:44 +02:00
|
|
|
return $res;
|
|
|
|
}
|
2019-12-26 20:26:27 +01:00
|
|
|
function __coalesce($ifNotNull, $then)
|
|
|
|
{
|
2019-12-28 20:28:29 +01:00
|
|
|
return $ifNotNull ?: $then;
|
2019-12-25 22:03:51 +01:00
|
|
|
}
|
2020-10-01 21:03:25 +02:00
|
|
|
function __destructure($list, $value): array
|
2019-12-26 20:26:27 +01:00
|
|
|
{
|
2019-12-25 22:03:51 +01:00
|
|
|
$res = [];
|
|
|
|
foreach ($list as $key) {
|
2019-12-26 20:26:27 +01:00
|
|
|
if (\is_string($key)) {
|
2020-01-31 19:29:43 +01:00
|
|
|
$res[] = $value[$key];
|
2019-12-25 22:03:51 +01:00
|
|
|
} else {
|
2019-12-26 20:26:27 +01:00
|
|
|
$res = \array_merge($res, __destructure($key, $value[$key]));
|
2019-12-25 22:03:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return $res;
|
|
|
|
}
|
2020-02-28 15:19:11 +01:00
|
|
|
|
2021-12-15 13:51:01 +01:00
|
|
|
$ampFilePolyfill = 'namespace Amp\\File {';
|
|
|
|
foreach ([
|
|
|
|
'open' => 'openFile',
|
|
|
|
'stat' => 'getStatus',
|
|
|
|
'lstat' => 'getLinkStatus',
|
|
|
|
'size' => 'getSize',
|
|
|
|
'isdir' => 'isDirectory',
|
|
|
|
'mtime' => 'getModificationTime',
|
|
|
|
'atime' => 'getAccessTime',
|
|
|
|
'ctime' => 'getCreationTime',
|
|
|
|
'symlink' => 'createSymlink',
|
|
|
|
'link' => 'createHardlink',
|
|
|
|
'readlink' => 'resolveSymlink',
|
|
|
|
'rename' => 'move',
|
|
|
|
'unlink' => 'deleteFile',
|
|
|
|
'rmdir' => 'deleteDirectory',
|
|
|
|
'scandir' => 'listFiles',
|
|
|
|
'chmod' => 'changePermissions',
|
|
|
|
'chown' => 'changeOwner',
|
|
|
|
'get' => 'read',
|
|
|
|
'put' => 'write',
|
|
|
|
'mkdir' => 'createDirectory',
|
|
|
|
] as $old => $new) {
|
|
|
|
$ampFilePolyfill .= "function $old(...\$args) { return $new(...\$args); }";
|
|
|
|
}
|
|
|
|
$ampFilePolyfill .= "}";
|
|
|
|
eval($ampFilePolyfill);
|
|
|
|
unset($ampFilePolyfill);
|