1
0
mirror of https://github.com/danog/MadelineProto.git synced 2025-01-12 00:38:16 +01:00
MadelineProto/src/polyfill.php

52 lines
1.4 KiB
PHP
Raw Normal View History

2022-12-30 21:54:44 +01:00
<?php
declare(strict_types=1);
2020-01-31 19:29:43 +01:00
if (defined('MADELINE_POLYFILLED')) {
return;
}
define('MADELINE_POLYFILLED', true);
2023-03-23 18:40:49 +01:00
if (PHP_VERSION_ID < 80204 || PHP_VERSION_ID < 80117) {
2023-03-17 11:10:06 +01:00
echo('MadelineProto requires PHP 8.2.4+ (recommended) or 8.1.17+.'.PHP_EOL);
die(1);
}
2023-02-04 22:33:52 +01:00
use Amp\Http\Client\Cookie\InMemoryCookieJar;
use Amp\Http\Client\Cookie\LocalCookieJar;
use Amp\Socket\EncryptableSocket;
use Amp\Socket\ResourceSocket;
$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); }";
}
2023-01-04 15:13:55 +01:00
$ampFilePolyfill .= '}';
eval($ampFilePolyfill);
unset($ampFilePolyfill);
class_alias(LocalCookieJar::class, InMemoryCookieJar::class);
class_alias(ResourceSocket::class, EncryptableSocket::class);