From f3dbc898b71844db8f7f28d1595b4c5d788f399f Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Tue, 20 Feb 2018 14:49:54 +0000 Subject: [PATCH] Update phpseclib, fix composer.json, PHP 5 fixes, update travis CI script. --- .gitignore | 4 +- composer.json | 5 +- makephar.php | 62 +++---------------- src/BigIntegor.php | 2 +- .../MTProtoTools/PeerHandler.php | 3 +- tests/makephar.sh | 31 +++++++++- 6 files changed, 45 insertions(+), 62 deletions(-) diff --git a/.gitignore b/.gitignore index 973315302..69c3a6a07 100644 --- a/.gitignore +++ b/.gitignore @@ -105,6 +105,6 @@ tests/500mb *.save *.save.1 *.save.* -composer -phar +phar7 +phar5 madeline.phar diff --git a/composer.json b/composer.json index 1afa746f1..ea2c5361e 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ "php": ">=5.6.0", "danog/primemodule": "dev-master", "danog/magicalserializer": "dev-master", - "phpseclib/phpseclib": "dev-master#0d9dc46", + "phpseclib/phpseclib": "dev-master#27370df", "vlucas/phpdotenv": "^2.4", "erusev/parsedown": "^1.6", "rollbar/rollbar": "dev-master", @@ -21,12 +21,11 @@ "ext-xml": "*" }, "require-dev": { - "spatie/7to5": "^1.2", "phpdocumentor/reflection-docblock": "^3.1" }, "suggest": { "ext-libtgvoip": "Install the php-libtgvoip extension to make phone calls (https:/github.com/danog/php-libtgvoip)", - "ext-socket": "Install the socket extension to speed up MadelineProto" + "ext-sockets": "Install the socket extension to speed up MadelineProto" }, "authors": [ { diff --git a/makephar.php b/makephar.php index e2c889adf..182cc8343 100755 --- a/makephar.php +++ b/makephar.php @@ -11,61 +11,15 @@ You should have received a copy of the GNU General Public License along with Mad If not, see . */ -require 'vendor/autoload.php'; -use Spatie\Php7to5\DirectoryConverter; - -if (!isset($argv[1])) { - die('This script requires a parameter with the commit number to turn into a phar'); +if (!isset($argv[3])) { + echo('Usage: '.$argv[0].' inputDir output.phar ref'.PHP_EOL); + die(1); } -function rimraf($dir) -{ - if (is_dir($dir)) { - $objects = scandir($dir); - foreach ($objects as $object) { - if ($object != '.' && $object != '..') { - if (is_dir($dir.'/'.$object)) { - rimraf($dir.'/'.$object); - } else { - unlink($dir.'/'.$object); - } - } - } - rmdir($dir); - } -} +@unlink($argv[2]); -@unlink('madeline.phar'); -rimraf('phar'); -rimraf('composer'); -mkdir('phar'); -mkdir('composer'); -chdir('composer'); -file_put_contents('composer.json', '{ - "name": "danog/madelineprototests", - "minimum-stability":"dev", - "require": { - "danog/madelineproto": "dev-master#'.$argv[1].'" - }, - "repositories": [ - { - "type": "git", - "url": "https://github.com/danog/phpseclib" - } - ], - "authors": [ - { - "name": "Daniil Gentili", - "email": "daniil@daniil.it" - } - ] -}'); -shell_exec('composer update'); +$p = new Phar(__DIR__.'/'.$argv[2], 0, $argv[2]); +$p->buildFromDirectory(realpath($argv[1]), '/^((?!tests).)*(\.php|\.py|\.tl|\.json)$/i'); +$p->addFromString('.git/refs/heads/master', $argv[3]); -(new DirectoryConverter(__DIR__.'/composer', ['.php']))->alsoCopyNonPhpFiles()->savePhp5FilesTo(__DIR__.'/phar'); - -$p = new Phar(__DIR__.'/madeline.phar', 0, 'madeline.phar'); -$p->buildFromDirectory(__DIR__.'/phar', '/^((?!tests).)*(\.php|\.py|\.tl|\.json)$/i'); -$p->addFromString('.git/refs/heads/master', file_get_contents(__DIR__.'/.git/refs/heads/master')); - -$p->setStub(''); +$p->setStub(''); diff --git a/src/BigIntegor.php b/src/BigIntegor.php index fd0640900..f539af6b8 100644 --- a/src/BigIntegor.php +++ b/src/BigIntegor.php @@ -3,7 +3,7 @@ namespace phpseclib\Math; if (PHP_MAJOR_VERSION < 7 && !(class_exists('\Phar') && \Phar::running())) { - throw new Exception('MadelineProto requires php 7 to run'); + throw new \Exception('MadelineProto requires php 7 to run'); } class BigIntegor diff --git a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php index bc8616459..bfa5b8fe2 100644 --- a/src/danog/MadelineProto/MTProtoTools/PeerHandler.php +++ b/src/danog/MadelineProto/MTProtoTools/PeerHandler.php @@ -535,7 +535,8 @@ trait PeerHandler public function store_db($res, $force = false) { - if (!isset($this->settings['pwr']) || $this->settings['pwr']['pwr'] === false || (isset($this->settings['connection_settings'][$this->datacenter->curdc]) ? $this->settings['connection_settings'][$this->datacenter->curdc] : $this->settings['connection_settings']['all'])['test_mode']) { + $settings = isset($this->settings['connection_settings'][$this->datacenter->curdc]) ? $this->settings['connection_settings'][$this->datacenter->curdc] : $this->settings['connection_settings']['all']; + if (!isset($this->settings['pwr']) || $this->settings['pwr']['pwr'] === false || $settings['test_mode']) { /* try { if (isset($res['username'])) { diff --git a/tests/makephar.sh b/tests/makephar.sh index 24b36d068..bf67ba309 100755 --- a/tests/makephar.sh +++ b/tests/makephar.sh @@ -1,6 +1,35 @@ #!/bin/sh -e +composer global require spatie/7to5 + +rm -rf phar7 phar5 + +mkdir phar7 +cd phar7 +echo '{ + "name": "danog/madelineprototests", + "minimum-stability":"dev", + "require": { + "danog/madelineproto": "dev-master#'$TRAVIS_COMMIT'" + }, + "repositories": [ + { + "type": "git", + "url": "https://github.com/danog/phpseclib" + } + ], + "authors": [ + { + "name": "Daniil Gentili", + "email": "daniil@daniil.it" + } + ] +}' > composer.json composer update -php makephar.php $TRAVIS_COMMIT +cd .. + +$HOME/.composer/vendor/bin/php7to5 convert --copy-all phar7 phar5 + +php makephar.php phar5 madeline.phar $TRAVIS_COMMIT [ -d JSON.sh ] || git clone https://github.com/dominictarr/JSON.sh