From b5bb338726d5ee102dcd52b64dfc2081a2381827 Mon Sep 17 00:00:00 2001 From: Kharhamel Date: Tue, 6 Oct 2020 15:28:57 +0200 Subject: [PATCH 1/6] basic deprecate command --- composer.json | 1 + deprecated/functionsList.php | 5 ++ generator/safe.php | 2 + generator/src/DeprecateCommand.php | 103 +++++++++++++++++++++++ generator/tests/DeprecateCommandTest.php | 31 +++++++ 5 files changed, 142 insertions(+) create mode 100644 deprecated/functionsList.php create mode 100644 generator/src/DeprecateCommand.php create mode 100644 generator/tests/DeprecateCommandTest.php diff --git a/composer.json b/composer.json index f97b764d..eafed860 100644 --- a/composer.json +++ b/composer.json @@ -6,6 +6,7 @@ "psr-4": { "Safe\\": [ "lib/", + "deprecated/", "generated/" ] }, diff --git a/deprecated/functionsList.php b/deprecated/functionsList.php new file mode 100644 index 00000000..e45aa954 --- /dev/null +++ b/deprecated/functionsList.php @@ -0,0 +1,5 @@ +addCommands([new GenerateCommand()]); $application->addCommands([new ScanObjectsCommand()]); +$application->addCommands([new DeprecateCommand()]); $application->run(); diff --git a/generator/src/DeprecateCommand.php b/generator/src/DeprecateCommand.php new file mode 100644 index 00000000..d5ebdfb4 --- /dev/null +++ b/generator/src/DeprecateCommand.php @@ -0,0 +1,103 @@ +setName('deprecate') + ->setDescription('Flag a module as deprecated and save it into the deprecated directory') + ->addArgument('module', InputArgument::REQUIRED, 'the module to deprecate') + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $moduleName = $input->getArgument('module'); + + $moduleFilePath = self::GENERATE_DIRECTORY."$moduleName.php"; + if (!\file_exists($moduleFilePath)) { + throw new \RuntimeException("Module $moduleName is not maintained!"); + } + + $output->writeln("Move $moduleName.php to deprecated"); + $success = \rename($moduleFilePath, self::DEPRECATE_DIRECTORY."$moduleName.php"); + if (!$success) { + throw new \RuntimeException("Could not move the file."); + } + + $exceptionFilePath = self::GENERATE_DIRECTORY.$this->getExceptionFilePath($moduleName); + $moveException = false; + if (\file_exists($exceptionFilePath)) { + $moveException = true; + $output->writeln("Move exception file to deprecated"); + $success = \rename($exceptionFilePath, self::DEPRECATE_DIRECTORY.$this->getExceptionFilePath($moduleName)); + if (!$success) { + throw new \RuntimeException("Could not move the file."); + } + } + + $output->writeln('Editing composer.json'); + $this->editComposerFile($moduleName, $moveException); + + $generatedListFile = self::GENERATE_DIRECTORY.'functionsList.php'; + $deprecatedListFile = self::DEPRECATE_DIRECTORY.'functionsList.php'; + $output->writeln("Don't forget to edit $generatedListFile and $deprecatedListFile !"); + + return 0; + } + + public static function getExceptionFilePath(string $moduleName): string + { + return "Exceptions/".ucfirst($moduleName)."Exception.php"; + } + + + private function editComposerFile(string $moduleName, bool $moveException): void + { + + $composerContent = file_get_contents(__DIR__.'/../../composer.json'); + if ($composerContent === false) { + throw new \RuntimeException('Error while loading composer.json file for edition.'); + } + $composerJson = \json_decode($composerContent, true); + $composerJson['autoload']['files'] = self::editFileList($composerJson['autoload']['files'], $moduleName); + + $newContent = json_encode($composerJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES); + \file_put_contents(__DIR__.'/../../composer.json', $newContent); + } + + /** + * @param string[] $fileList + * @return string[] + */ + public static function editFileList(array $fileList, string $moduleName): array + { + $newList = []; + foreach ($fileList as $fileName) { + if ($fileName === "generated/$moduleName.php") { + $newList[] = "deprecated/$moduleName.php"; + //} else if($fileName === self::GENERATE_DIRECTORY.self::getExceptionFilePath($moduleName)) { + // $newList[] = self::DEPRECATE_DIRECTORY.self::getExceptionFilePath($moduleName); + } else { + $newList[] = $fileName; + } + } + + return $newList; + } + +} \ No newline at end of file diff --git a/generator/tests/DeprecateCommandTest.php b/generator/tests/DeprecateCommandTest.php new file mode 100644 index 00000000..2b977ab9 --- /dev/null +++ b/generator/tests/DeprecateCommandTest.php @@ -0,0 +1,31 @@ +assertEquals('Exceptions/ApcException.php', DeprecateCommand::getExceptionFilePath('apc')); + } + + public function testFileListEdition() + { + $oldList = [ + "generated/apache.php", + "generated/apc.php", + ]; + + $newList = DeprecateCommand::editFileList($oldList, 'apc'); + + $this->assertEquals([ + "generated/apache.php", + "deprecated/apc.php", + ], $newList); + } + +} \ No newline at end of file From 14d25175adc0e8a5ab3592262b354f66e51840fb Mon Sep 17 00:00:00 2001 From: Kharhamel Date: Tue, 6 Oct 2020 16:11:51 +0200 Subject: [PATCH 2/6] deprecated apc, libevent, mssql, stats --- composer.json | 8 +-- .../Exceptions/ApcException.php | 0 .../Exceptions/LibeventException.php | 0 .../Exceptions/MssqlException.php | 0 .../Exceptions/StatsException.php | 0 {generated => deprecated}/apc.php | 0 deprecated/functionsList.php | 53 ++++++++++++++++++- {generated => deprecated}/libevent.php | 0 {generated => deprecated}/mssql.php | 0 {generated => deprecated}/stats.php | 0 10 files changed, 56 insertions(+), 5 deletions(-) rename {generated => deprecated}/Exceptions/ApcException.php (100%) rename {generated => deprecated}/Exceptions/LibeventException.php (100%) rename {generated => deprecated}/Exceptions/MssqlException.php (100%) rename {generated => deprecated}/Exceptions/StatsException.php (100%) rename {generated => deprecated}/apc.php (100%) rename {generated => deprecated}/libevent.php (100%) rename {generated => deprecated}/mssql.php (100%) rename {generated => deprecated}/stats.php (100%) diff --git a/composer.json b/composer.json index eafed860..452b008b 100644 --- a/composer.json +++ b/composer.json @@ -12,7 +12,7 @@ }, "files": [ "generated/apache.php", - "generated/apc.php", + "deprecated/apc.php", "generated/apcu.php", "generated/array.php", "generated/bzip2.php", @@ -44,14 +44,14 @@ "generated/inotify.php", "generated/json.php", "generated/ldap.php", - "generated/libevent.php", + "deprecated/libevent.php", "generated/libxml.php", "generated/lzf.php", "generated/mailparse.php", "generated/mbstring.php", "generated/misc.php", "generated/msql.php", - "generated/mssql.php", + "deprecated/mssql.php", "generated/mysql.php", "generated/mysqli.php", "generated/mysqlndMs.php", @@ -83,7 +83,7 @@ "generated/sqlsrv.php", "generated/ssdeep.php", "generated/ssh2.php", - "generated/stats.php", + "deprecated/stats.php", "generated/stream.php", "generated/strings.php", "generated/swoole.php", diff --git a/generated/Exceptions/ApcException.php b/deprecated/Exceptions/ApcException.php similarity index 100% rename from generated/Exceptions/ApcException.php rename to deprecated/Exceptions/ApcException.php diff --git a/generated/Exceptions/LibeventException.php b/deprecated/Exceptions/LibeventException.php similarity index 100% rename from generated/Exceptions/LibeventException.php rename to deprecated/Exceptions/LibeventException.php diff --git a/generated/Exceptions/MssqlException.php b/deprecated/Exceptions/MssqlException.php similarity index 100% rename from generated/Exceptions/MssqlException.php rename to deprecated/Exceptions/MssqlException.php diff --git a/generated/Exceptions/StatsException.php b/deprecated/Exceptions/StatsException.php similarity index 100% rename from generated/Exceptions/StatsException.php rename to deprecated/Exceptions/StatsException.php diff --git a/generated/apc.php b/deprecated/apc.php similarity index 100% rename from generated/apc.php rename to deprecated/apc.php diff --git a/deprecated/functionsList.php b/deprecated/functionsList.php index e45aa954..e430cd3b 100644 --- a/deprecated/functionsList.php +++ b/deprecated/functionsList.php @@ -1,5 +1,56 @@ Date: Tue, 6 Oct 2020 16:17:44 +0200 Subject: [PATCH 3/6] fixed a broken test --- generator/tests/MethodTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/generator/tests/MethodTest.php b/generator/tests/MethodTest.php index 9ebc0da6..12a1681c 100644 --- a/generator/tests/MethodTest.php +++ b/generator/tests/MethodTest.php @@ -73,12 +73,13 @@ public function testGetTypeHintFromRessource() public function testGetInitializer() { - $docPage = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/apc/functions/apc-cache-info.xml'); + $docPage = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/apache/functions/apache-getenv.xml'); $xmlObject = $docPage->getMethodSynopsis(); $method = new Method($xmlObject[0], $docPage->loadAndResolveFile(), $docPage->getModule(), new PhpStanFunctionMapReader(), Method::FALSY_TYPE); $params = $method->getParams(); $this->assertEquals('', $params[0]->getDefaultValue()); + $this->assertEquals('false', $params[1]->getDefaultValue()); } public function testGetReturnDocBlock(): void From 9a163d9ebc744f644107c52decc7aba73cc6fc04 Mon Sep 17 00:00:00 2001 From: Kharhamel Date: Tue, 6 Oct 2020 17:10:55 +0200 Subject: [PATCH 4/6] edited the rule for mktime --- composer.json | 12 ++-- generator/src/ComposerJsonEditor.php | 68 +++++++++++++++++++--- generator/src/DeprecateCommand.php | 43 +------------- generator/src/DocPage.php | 5 +- generator/src/GenerateCommand.php | 2 +- generator/tests/ComposerJsonEditorTest.php | 48 +++++++++++++++ generator/tests/DeprecateCommandTest.php | 15 ----- generator/tests/DocPageTest.php | 2 + rector-migrate-0.7.php | 55 +---------------- 9 files changed, 125 insertions(+), 125 deletions(-) create mode 100644 generator/tests/ComposerJsonEditorTest.php diff --git a/composer.json b/composer.json index 452b008b..91e5e144 100644 --- a/composer.json +++ b/composer.json @@ -11,8 +11,12 @@ ] }, "files": [ - "generated/apache.php", "deprecated/apc.php", + "deprecated/libevent.php", + "deprecated/mssql.php", + "deprecated/stats.php", + "lib/special_cases.php", + "generated/apache.php", "generated/apcu.php", "generated/array.php", "generated/bzip2.php", @@ -44,14 +48,12 @@ "generated/inotify.php", "generated/json.php", "generated/ldap.php", - "deprecated/libevent.php", "generated/libxml.php", "generated/lzf.php", "generated/mailparse.php", "generated/mbstring.php", "generated/misc.php", "generated/msql.php", - "deprecated/mssql.php", "generated/mysql.php", "generated/mysqli.php", "generated/mysqlndMs.php", @@ -83,7 +85,6 @@ "generated/sqlsrv.php", "generated/ssdeep.php", "generated/ssh2.php", - "deprecated/stats.php", "generated/stream.php", "generated/strings.php", "generated/swoole.php", @@ -97,8 +98,7 @@ "generated/yaml.php", "generated/yaz.php", "generated/zip.php", - "generated/zlib.php", - "lib/special_cases.php" + "generated/zlib.php" ] }, "require": { diff --git a/generator/src/ComposerJsonEditor.php b/generator/src/ComposerJsonEditor.php index 24bd028e..d9902231 100644 --- a/generator/src/ComposerJsonEditor.php +++ b/generator/src/ComposerJsonEditor.php @@ -8,23 +8,73 @@ */ class ComposerJsonEditor { + private const COMPOSER_FILEPATH = __DIR__.'/../../composer.json'; + + public static function editComposerFileForDeprecation(string $moduleName): void + { + + $composerContent = file_get_contents(self::COMPOSER_FILEPATH); + if ($composerContent === false) { + throw new \RuntimeException('Error while loading composer.json file for edition.'); + } + $composerJson = \json_decode($composerContent, true); + $composerJson['autoload']['files'] = self::editFileListForDeprecation($composerJson['autoload']['files'], $moduleName); + + $newContent = \json_encode($composerJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES); + \file_put_contents(self::COMPOSER_FILEPATH, $newContent); + } + /** * @param string[] $modules A list of modules */ - public static function editFiles(array $modules): void + public static function editComposerFileForGeneration(array $modules): void { - $files = \array_map(function (string $module) { - return 'generated/'.lcfirst($module).'.php'; - }, $modules); - $files[] = 'lib/special_cases.php'; - $composerContent = file_get_contents(__DIR__.'/../../composer.json'); + + $composerContent = file_get_contents(self::COMPOSER_FILEPATH); if ($composerContent === false) { throw new \RuntimeException('Error while loading composer.json file for edition.'); } $composerJson = \json_decode($composerContent, true); - $composerJson['autoload']['files'] = $files; + $composerJson['autoload']['files'] = self::editFilesListForGeneration($composerJson['autoload']['files'], $modules); + + $newContent = \json_encode($composerJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES); + \file_put_contents(self::COMPOSER_FILEPATH, $newContent); + } + + + + + /** + * @param string[] $oldFiles + * @param string[] $modules A list of modules + * @return string[] + */ + public static function editFilesListForGeneration(array $oldFiles, array $modules): array + { + $files = array_values(array_filter($oldFiles, function ($file) { + return strpos($file, 'generated/') === false; + })); + foreach ($modules as $module) { + $files[] = 'generated/'.lcfirst($module).'.php'; + } + return $files; + } + + /** + * @param string[] $fileList + * @return string[] + */ + public static function editFileListForDeprecation(array $fileList, string $moduleName): array + { + $newList = []; + foreach ($fileList as $fileName) { + if ($fileName === "generated/$moduleName.php") { + $newList[] = "deprecated/$moduleName.php"; + } else { + $newList[] = $fileName; + } + } - $newContent = json_encode($composerJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES); - \file_put_contents(__DIR__.'/../../composer.json', $newContent); + return $newList; } } diff --git a/generator/src/DeprecateCommand.php b/generator/src/DeprecateCommand.php index d5ebdfb4..e49da6fe 100644 --- a/generator/src/DeprecateCommand.php +++ b/generator/src/DeprecateCommand.php @@ -39,19 +39,17 @@ protected function execute(InputInterface $input, OutputInterface $output) throw new \RuntimeException("Could not move the file."); } - $exceptionFilePath = self::GENERATE_DIRECTORY.$this->getExceptionFilePath($moduleName); - $moveException = false; + $exceptionFilePath = self::GENERATE_DIRECTORY.self::getExceptionFilePath($moduleName); if (\file_exists($exceptionFilePath)) { - $moveException = true; $output->writeln("Move exception file to deprecated"); - $success = \rename($exceptionFilePath, self::DEPRECATE_DIRECTORY.$this->getExceptionFilePath($moduleName)); + $success = \rename($exceptionFilePath, self::DEPRECATE_DIRECTORY.self::getExceptionFilePath($moduleName)); if (!$success) { throw new \RuntimeException("Could not move the file."); } } $output->writeln('Editing composer.json'); - $this->editComposerFile($moduleName, $moveException); + ComposerJsonEditor::editComposerFileForDeprecation($moduleName); $generatedListFile = self::GENERATE_DIRECTORY.'functionsList.php'; $deprecatedListFile = self::DEPRECATE_DIRECTORY.'functionsList.php'; @@ -65,39 +63,4 @@ public static function getExceptionFilePath(string $moduleName): string return "Exceptions/".ucfirst($moduleName)."Exception.php"; } - - private function editComposerFile(string $moduleName, bool $moveException): void - { - - $composerContent = file_get_contents(__DIR__.'/../../composer.json'); - if ($composerContent === false) { - throw new \RuntimeException('Error while loading composer.json file for edition.'); - } - $composerJson = \json_decode($composerContent, true); - $composerJson['autoload']['files'] = self::editFileList($composerJson['autoload']['files'], $moduleName); - - $newContent = json_encode($composerJson, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES); - \file_put_contents(__DIR__.'/../../composer.json', $newContent); - } - - /** - * @param string[] $fileList - * @return string[] - */ - public static function editFileList(array $fileList, string $moduleName): array - { - $newList = []; - foreach ($fileList as $fileName) { - if ($fileName === "generated/$moduleName.php") { - $newList[] = "deprecated/$moduleName.php"; - //} else if($fileName === self::GENERATE_DIRECTORY.self::getExceptionFilePath($moduleName)) { - // $newList[] = self::DEPRECATE_DIRECTORY.self::getExceptionFilePath($moduleName); - } else { - $newList[] = $fileName; - } - } - - return $newList; - } - } \ No newline at end of file diff --git a/generator/src/DocPage.php b/generator/src/DocPage.php index 644f2684..c086576b 100644 --- a/generator/src/DocPage.php +++ b/generator/src/DocPage.php @@ -106,12 +106,15 @@ public function detectFalsyFunction(): bool return true; } + if (preg_match('/&gd\.return\.identifier;/m', $file)) { + return true; + } if (preg_match('/&gd\.return\.identifier;/m', $file)) { return true; } //used to detect imagecreatefromstring - if (preg_match('/will be returned on success\. &false; is returned if/m', $file)) { + if (preg_match('/If the arguments are invalid, the function returns &false;/m', $file)) { return true; } diff --git a/generator/src/GenerateCommand.php b/generator/src/GenerateCommand.php index 8355924b..dd61fd39 100644 --- a/generator/src/GenerateCommand.php +++ b/generator/src/GenerateCommand.php @@ -74,7 +74,7 @@ protected function execute(InputInterface $input, OutputInterface $output) // Finally, let's edit the composer.json file $output->writeln('Editing composer.json'); - ComposerJsonEditor::editFiles(\array_values($modules)); + ComposerJsonEditor::editComposerFileForGeneration(\array_values($modules)); return 0; } diff --git a/generator/tests/ComposerJsonEditorTest.php b/generator/tests/ComposerJsonEditorTest.php new file mode 100644 index 00000000..dc8b9441 --- /dev/null +++ b/generator/tests/ComposerJsonEditorTest.php @@ -0,0 +1,48 @@ +assertEquals([ + "deprecated/apc.php", + "lib/special_cases.php", + "generated/apache.php", + "generated/mysql.php", + ], $newList); + } + + + public function testFileListEditionForDeprecation() + { + $oldList = [ + "generated/apache.php", + "generated/apc.php", + ]; + + $newList = ComposerJsonEditor::editFileListForDeprecation($oldList, 'apc'); + + $this->assertEquals([ + "generated/apache.php", + "deprecated/apc.php", + ], $newList); + } +} \ No newline at end of file diff --git a/generator/tests/DeprecateCommandTest.php b/generator/tests/DeprecateCommandTest.php index 2b977ab9..2caf2548 100644 --- a/generator/tests/DeprecateCommandTest.php +++ b/generator/tests/DeprecateCommandTest.php @@ -13,19 +13,4 @@ public function testExceptionName() $this->assertEquals('Exceptions/ApcException.php', DeprecateCommand::getExceptionFilePath('apc')); } - public function testFileListEdition() - { - $oldList = [ - "generated/apache.php", - "generated/apc.php", - ]; - - $newList = DeprecateCommand::editFileList($oldList, 'apc'); - - $this->assertEquals([ - "generated/apache.php", - "deprecated/apc.php", - ], $newList); - } - } \ No newline at end of file diff --git a/generator/tests/DocPageTest.php b/generator/tests/DocPageTest.php index ffee4109..0b8ed280 100644 --- a/generator/tests/DocPageTest.php +++ b/generator/tests/DocPageTest.php @@ -17,6 +17,7 @@ public function testDetectFalsyFunction() $mcryptDecrypt = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/mcrypt/functions/mcrypt-decrypt.xml'); $fsockopen = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/network/functions/fsockopen.xml'); $arrayReplace = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/array/functions/array-replace.xml'); + $mktime = new DocPage(__DIR__ . '/../doc/doc-en/en/reference/datetime/functions/mktime.xml'); $this->assertTrue($pregMatch->detectFalsyFunction()); $this->assertFalse($implode->detectFalsyFunction()); @@ -27,6 +28,7 @@ public function testDetectFalsyFunction() $this->assertTrue($mcryptDecrypt->detectFalsyFunction()); $this->assertTrue($fsockopen->detectFalsyFunction()); $this->assertFalse($arrayReplace->detectFalsyFunction()); + $this->assertTrue($mktime->detectFalsyFunction()); } public function testDetectNullsyFunction() diff --git a/rector-migrate-0.7.php b/rector-migrate-0.7.php index dbeb34e5..d0783bc2 100644 --- a/rector-migrate-0.7.php +++ b/rector-migrate-0.7.php @@ -23,17 +23,7 @@ 'apcu_fetch' => 'Safe\apcu_fetch', 'apcu_inc' => 'Safe\apcu_inc', 'apcu_sma_info' => 'Safe\apcu_sma_info', - 'apc_cache_info' => 'Safe\apc_cache_info', - 'apc_cas' => 'Safe\apc_cas', - 'apc_compile_file' => 'Safe\apc_compile_file', - 'apc_dec' => 'Safe\apc_dec', - 'apc_define_constants' => 'Safe\apc_define_constants', - 'apc_delete' => 'Safe\apc_delete', - 'apc_delete_file' => 'Safe\apc_delete_file', 'apc_fetch' => 'Safe\apc_fetch', - 'apc_inc' => 'Safe\apc_inc', - 'apc_load_constants' => 'Safe\apc_load_constants', - 'apc_sma_info' => 'Safe\apc_sma_info', 'array_combine' => 'Safe\array_combine', 'array_flip' => 'Safe\array_flip', 'array_replace' => 'Safe\array_replace', @@ -150,25 +140,6 @@ 'eio_utime' => 'Safe\eio_utime', 'eio_write' => 'Safe\eio_write', 'error_log' => 'Safe\error_log', - 'event_add' => 'Safe\event_add', - 'event_base_loopbreak' => 'Safe\event_base_loopbreak', - 'event_base_loopexit' => 'Safe\event_base_loopexit', - 'event_base_new' => 'Safe\event_base_new', - 'event_base_priority_init' => 'Safe\event_base_priority_init', - 'event_base_reinit' => 'Safe\event_base_reinit', - 'event_base_set' => 'Safe\event_base_set', - 'event_buffer_base_set' => 'Safe\event_buffer_base_set', - 'event_buffer_disable' => 'Safe\event_buffer_disable', - 'event_buffer_enable' => 'Safe\event_buffer_enable', - 'event_buffer_new' => 'Safe\event_buffer_new', - 'event_buffer_priority_set' => 'Safe\event_buffer_priority_set', - 'event_buffer_set_callback' => 'Safe\event_buffer_set_callback', - 'event_buffer_write' => 'Safe\event_buffer_write', - 'event_del' => 'Safe\event_del', - 'event_new' => 'Safe\event_new', - 'event_priority_set' => 'Safe\event_priority_set', - 'event_set' => 'Safe\event_set', - 'event_timer_set' => 'Safe\event_timer_set', 'fastcgi_finish_request' => 'Safe\fastcgi_finish_request', 'fbird_blob_cancel' => 'Safe\fbird_blob_cancel', 'fclose' => 'Safe\fclose', @@ -312,7 +283,6 @@ 'imagecreatefromgif' => 'Safe\imagecreatefromgif', 'imagecreatefromjpeg' => 'Safe\imagecreatefromjpeg', 'imagecreatefrompng' => 'Safe\imagecreatefrompng', - 'imagecreatefromstring' => 'Safe\imagecreatefromstring', 'imagecreatefromwbmp' => 'Safe\imagecreatefromwbmp', 'imagecreatefromwebp' => 'Safe\imagecreatefromwebp', 'imagecreatefromxbm' => 'Safe\imagecreatefromxbm', @@ -344,10 +314,6 @@ 'imageopenpolygon' => 'Safe\imageopenpolygon', 'imagepng' => 'Safe\imagepng', 'imagepolygon' => 'Safe\imagepolygon', - 'imagepsencodefont' => 'Safe\imagepsencodefont', - 'imagepsextendfont' => 'Safe\imagepsextendfont', - 'imagepsfreefont' => 'Safe\imagepsfreefont', - 'imagepsslantfont' => 'Safe\imagepsslantfont', 'imagerectangle' => 'Safe\imagerectangle', 'imagerotate' => 'Safe\imagerotate', 'imagesavealpha' => 'Safe\imagesavealpha', @@ -520,20 +486,6 @@ 'msql_pconnect' => 'Safe\msql_pconnect', 'msql_query' => 'Safe\msql_query', 'msql_select_db' => 'Safe\msql_select_db', - 'mssql_bind' => 'Safe\mssql_bind', - 'mssql_close' => 'Safe\mssql_close', - 'mssql_connect' => 'Safe\mssql_connect', - 'mssql_data_seek' => 'Safe\mssql_data_seek', - 'mssql_field_length' => 'Safe\mssql_field_length', - 'mssql_field_name' => 'Safe\mssql_field_name', - 'mssql_field_seek' => 'Safe\mssql_field_seek', - 'mssql_field_type' => 'Safe\mssql_field_type', - 'mssql_free_result' => 'Safe\mssql_free_result', - 'mssql_free_statement' => 'Safe\mssql_free_statement', - 'mssql_init' => 'Safe\mssql_init', - 'mssql_pconnect' => 'Safe\mssql_pconnect', - 'mssql_query' => 'Safe\mssql_query', - 'mssql_select_db' => 'Safe\mssql_select_db', 'mysqli_get_cache_stats' => 'Safe\mysqli_get_cache_stats', 'mysqli_get_client_stats' => 'Safe\mysqli_get_client_stats', 'mysqlnd_ms_dump_servers' => 'Safe\mysqlnd_ms_dump_servers', @@ -684,6 +636,7 @@ 'openssl_x509_read' => 'Safe\openssl_x509_read', 'output_add_rewrite_var' => 'Safe\output_add_rewrite_var', 'output_reset_rewrite_vars' => 'Safe\output_reset_rewrite_vars', + 'pack' => 'Safe\pack', 'parse_ini_file' => 'Safe\parse_ini_file', 'parse_ini_string' => 'Safe\parse_ini_string', 'parse_url' => 'Safe\parse_url', @@ -1044,11 +997,6 @@ 'ssh2_sftp_rmdir' => 'Safe\ssh2_sftp_rmdir', 'ssh2_sftp_symlink' => 'Safe\ssh2_sftp_symlink', 'ssh2_sftp_unlink' => 'Safe\ssh2_sftp_unlink', - 'stats_covariance' => 'Safe\stats_covariance', - 'stats_standard_deviation' => 'Safe\stats_standard_deviation', - 'stats_stat_correlation' => 'Safe\stats_stat_correlation', - 'stats_stat_innerproduct' => 'Safe\stats_stat_innerproduct', - 'stats_variance' => 'Safe\stats_variance', 'stream_context_set_params' => 'Safe\stream_context_set_params', 'stream_copy_to_stream' => 'Safe\stream_copy_to_stream', 'stream_filter_append' => 'Safe\stream_filter_append', @@ -1089,6 +1037,7 @@ 'uasort' => 'Safe\uasort', 'uksort' => 'Safe\uksort', 'unlink' => 'Safe\unlink', + 'unpack' => 'Safe\unpack', 'uopz_extend' => 'Safe\uopz_extend', 'uopz_implement' => 'Safe\uopz_implement', 'usort' => 'Safe\usort', From 47b77826b0e566edb24a89ca74837ba0e84bf32a Mon Sep 17 00:00:00 2001 From: Kharhamel Date: Tue, 6 Oct 2020 17:12:57 +0200 Subject: [PATCH 5/6] regenerated --- generated/apache.php | 8 +- generated/functionsList.php | 55 +--------- generated/image.php | 114 +-------------------- generated/misc.php | 198 ++++++++++++++++++++++++++++++++++++ generated/pcre.php | 4 +- generated/pgsql.php | 2 +- generated/uodbc.php | 39 +++---- 7 files changed, 232 insertions(+), 188 deletions(-) diff --git a/generated/apache.php b/generated/apache.php index dbec11ee..e71c32d7 100644 --- a/generated/apache.php +++ b/generated/apache.php @@ -46,7 +46,9 @@ function apache_getenv(string $variable, bool $walk_to_top = false): string /** - * Fetches all HTTP request headers from the current request. + * Fetches all HTTP request headers from the current request. Works in the + * Apache, FastCGI, CLI, FPM and NSAPI server module + * in Netscape/iPlanet/SunONE webservers. * * @return array An associative array of all the HTTP headers in the current request. * @throws ApacheException @@ -86,7 +88,9 @@ function apache_reset_timeout(): void /** - * Fetch all HTTP response headers. + * Fetch all HTTP response headers. Works in the + * Apache, FastCGI, CLI, FPM and NSAPI server module + * in Netscape/iPlanet/SunONE webservers. * * @return array An array of all Apache response headers on success. * @throws ApacheException diff --git a/generated/functionsList.php b/generated/functionsList.php index fd804f92..1c0e4737 100644 --- a/generated/functionsList.php +++ b/generated/functionsList.php @@ -13,17 +13,7 @@ 'apcu_fetch', 'apcu_inc', 'apcu_sma_info', - 'apc_cache_info', - 'apc_cas', - 'apc_compile_file', - 'apc_dec', - 'apc_define_constants', - 'apc_delete', - 'apc_delete_file', 'apc_fetch', - 'apc_inc', - 'apc_load_constants', - 'apc_sma_info', 'array_combine', 'array_flip', 'array_replace', @@ -140,25 +130,6 @@ 'eio_utime', 'eio_write', 'error_log', - 'event_add', - 'event_base_loopbreak', - 'event_base_loopexit', - 'event_base_new', - 'event_base_priority_init', - 'event_base_reinit', - 'event_base_set', - 'event_buffer_base_set', - 'event_buffer_disable', - 'event_buffer_enable', - 'event_buffer_new', - 'event_buffer_priority_set', - 'event_buffer_set_callback', - 'event_buffer_write', - 'event_del', - 'event_new', - 'event_priority_set', - 'event_set', - 'event_timer_set', 'fastcgi_finish_request', 'fbird_blob_cancel', 'fclose', @@ -302,7 +273,6 @@ 'imagecreatefromgif', 'imagecreatefromjpeg', 'imagecreatefrompng', - 'imagecreatefromstring', 'imagecreatefromwbmp', 'imagecreatefromwebp', 'imagecreatefromxbm', @@ -334,10 +304,6 @@ 'imageopenpolygon', 'imagepng', 'imagepolygon', - 'imagepsencodefont', - 'imagepsextendfont', - 'imagepsfreefont', - 'imagepsslantfont', 'imagerectangle', 'imagerotate', 'imagesavealpha', @@ -510,20 +476,6 @@ 'msql_pconnect', 'msql_query', 'msql_select_db', - 'mssql_bind', - 'mssql_close', - 'mssql_connect', - 'mssql_data_seek', - 'mssql_field_length', - 'mssql_field_name', - 'mssql_field_seek', - 'mssql_field_type', - 'mssql_free_result', - 'mssql_free_statement', - 'mssql_init', - 'mssql_pconnect', - 'mssql_query', - 'mssql_select_db', 'mysqli_get_cache_stats', 'mysqli_get_client_stats', 'mysqlnd_ms_dump_servers', @@ -674,6 +626,7 @@ 'openssl_x509_read', 'output_add_rewrite_var', 'output_reset_rewrite_vars', + 'pack', 'parse_ini_file', 'parse_ini_string', 'parse_url', @@ -1034,11 +987,6 @@ 'ssh2_sftp_rmdir', 'ssh2_sftp_symlink', 'ssh2_sftp_unlink', - 'stats_covariance', - 'stats_standard_deviation', - 'stats_stat_correlation', - 'stats_stat_innerproduct', - 'stats_variance', 'stream_context_set_params', 'stream_copy_to_stream', 'stream_filter_append', @@ -1079,6 +1027,7 @@ 'uasort', 'uksort', 'unlink', + 'unpack', 'uopz_extend', 'uopz_implement', 'usort', diff --git a/generated/image.php b/generated/image.php index 5de96e74..8e380b2e 100644 --- a/generated/image.php +++ b/generated/image.php @@ -809,30 +809,6 @@ function imagecreatefrompng(string $filename) } -/** - * imagecreatefromstring returns an image identifier - * representing the image obtained from the given image. - * These types will be automatically detected if your build of PHP supports - * them: JPEG, PNG, GIF, BMP, WBMP, and GD2. - * - * @param string $image A string containing the image data. - * @return resource An image resource will be returned on success. FALSE is returned if - * the image type is unsupported, the data is not in a recognised format, - * or the image is corrupt and cannot be loaded. - * @throws ImageException - * - */ -function imagecreatefromstring(string $image) -{ - error_clear_last(); - $result = \imagecreatefromstring($image); - if ($result === false) { - throw ImageException::createFromPhpError(); - } - return $result; -} - - /** * imagecreatefromwbmp returns an image identifier * representing the image obtained from the given filename. @@ -1891,92 +1867,6 @@ function imagepolygon($image, array $points, int $num_points, int $color): void } -/** - * Loads a character encoding vector from a file and changes the fonts - * encoding vector to it. As a PostScript fonts default vector lacks most of - * the character positions above 127, you'll definitely want to change this - * if you use a language other than English. - * - * If you find yourself using this function all the time, a much - * better way to define the encoding is to set ps.default_encoding in - * the configuration file - * to point to the right encoding file and all fonts you load will - * automatically have the right encoding. - * - * @param resource $font_index A font resource, returned by imagepsloadfont. - * @param string $encodingfile The exact format of this file is described in T1libs documentation. - * T1lib comes with two ready-to-use files, - * IsoLatin1.enc and - * IsoLatin2.enc. - * @throws ImageException - * - */ -function imagepsencodefont($font_index, string $encodingfile): void -{ - error_clear_last(); - $result = \imagepsencodefont($font_index, $encodingfile); - if ($result === false) { - throw ImageException::createFromPhpError(); - } -} - - -/** - * Extend or condense a font (font_index), if - * the value of the extend parameter is less - * than one you will be condensing the font. - * - * @param resource $font_index A font resource, returned by imagepsloadfont. - * @param float $extend Extension value, must be greater than 0. - * @throws ImageException - * - */ -function imagepsextendfont($font_index, float $extend): void -{ - error_clear_last(); - $result = \imagepsextendfont($font_index, $extend); - if ($result === false) { - throw ImageException::createFromPhpError(); - } -} - - -/** - * imagepsfreefont frees memory used by a PostScript - * Type 1 font. - * - * @param resource $font_index A font resource, returned by imagepsloadfont. - * @throws ImageException - * - */ -function imagepsfreefont($font_index): void -{ - error_clear_last(); - $result = \imagepsfreefont($font_index); - if ($result === false) { - throw ImageException::createFromPhpError(); - } -} - - -/** - * Slant a given font. - * - * @param resource $font_index A font resource, returned by imagepsloadfont. - * @param float $slant Slant level. - * @throws ImageException - * - */ -function imagepsslantfont($font_index, float $slant): void -{ - error_clear_last(); - $result = \imagepsslantfont($font_index, $slant); - if ($result === false) { - throw ImageException::createFromPhpError(); - } -} - - /** * imagerectangle creates a rectangle starting at * the specified coordinates. @@ -2705,7 +2595,7 @@ function imagewebp($image, $to = null, int $quality = 80): void * * @param resource $image An image resource, returned by one of the image creation functions, * such as imagecreatetruecolor. - * @param string|null $filename The path to save the file to. If not set or NULL, the raw image stream will be outputted directly. + * @param string|null $filename The path to save the file to, given as string. If NULL, the raw image stream will be output directly. * * The filename (without the .xbm extension) is also * used for the C identifiers of the XBM, whereby non @@ -2719,7 +2609,7 @@ function imagewebp($image, $to = null, int $quality = 80): void * @throws ImageException * */ -function imagexbm($image, ?string $filename = null, int $foreground = null): void +function imagexbm($image, ?string $filename, int $foreground = null): void { error_clear_last(); if ($foreground !== null) { diff --git a/generated/misc.php b/generated/misc.php index b704a0a9..ff636fd4 100644 --- a/generated/misc.php +++ b/generated/misc.php @@ -92,6 +92,175 @@ function highlight_string(string $str, bool $return = false) } +/** + * Pack given arguments into a binary string according to + * format. + * + * The idea for this function was taken from Perl and all formatting codes + * work the same as in Perl. However, there are some formatting codes that are + * missing such as Perl's "u" format code. + * + * Note that the distinction between signed and unsigned values only + * affects the function unpack, where as + * function pack gives the same result for + * signed and unsigned format codes. + * + * @param string $format The format string consists of format codes + * followed by an optional repeater argument. The repeater argument can + * be either an integer value or * for repeating to + * the end of the input data. For a, A, h, H the repeat count specifies + * how many characters of one data argument are taken, for @ it is the + * absolute position where to put the next data, for everything else the + * repeat count specifies how many data arguments are consumed and packed + * into the resulting binary string. + * + * Currently implemented formats are: + * + * pack format characters + * + * + * + * Code + * Description + * + * + * + * + * a + * NUL-padded string + * + * + * A + * SPACE-padded string + * + * h + * Hex string, low nibble first + * + * H + * Hex string, high nibble first + * csigned char + * + * C + * unsigned char + * + * s + * signed short (always 16 bit, machine byte order) + * + * + * S + * unsigned short (always 16 bit, machine byte order) + * + * + * n + * unsigned short (always 16 bit, big endian byte order) + * + * + * v + * unsigned short (always 16 bit, little endian byte order) + * + * + * i + * signed integer (machine dependent size and byte order) + * + * + * I + * unsigned integer (machine dependent size and byte order) + * + * + * l + * signed long (always 32 bit, machine byte order) + * + * + * L + * unsigned long (always 32 bit, machine byte order) + * + * + * N + * unsigned long (always 32 bit, big endian byte order) + * + * + * V + * unsigned long (always 32 bit, little endian byte order) + * + * + * q + * signed long long (always 64 bit, machine byte order) + * + * + * Q + * unsigned long long (always 64 bit, machine byte order) + * + * + * J + * unsigned long long (always 64 bit, big endian byte order) + * + * + * P + * unsigned long long (always 64 bit, little endian byte order) + * + * + * f + * float (machine dependent size and representation) + * + * + * g + * float (machine dependent size, little endian byte order) + * + * + * G + * float (machine dependent size, big endian byte order) + * + * + * d + * double (machine dependent size and representation) + * + * + * e + * double (machine dependent size, little endian byte order) + * + * + * E + * double (machine dependent size, big endian byte order) + * + * + * x + * NUL byte + * + * + * X + * Back up one byte + * + * + * Z + * NUL-padded string (new in PHP 5.5) + * + * + * @ + * NUL-fill to absolute position + * + * + * + * + * @param mixed $params + * @return string Returns a binary string containing data. + * @throws MiscException + * + */ +function pack(string $format, ...$params): string +{ + error_clear_last(); + if ($params !== []) { + $result = \pack($format, ...$params); + } else { + $result = \pack($format); + } + if ($result === false) { + throw MiscException::createFromPhpError(); + } + return $result; +} + + /** * Convert string from one codepage to another. * @@ -264,3 +433,32 @@ function time_sleep_until(float $timestamp): void throw MiscException::createFromPhpError(); } } + + +/** + * Unpacks from a binary string into an array according to the given + * format. + * + * The unpacked data is stored in an associative array. To + * accomplish this you have to name the different format codes and + * separate them by a slash /. If a repeater argument is present, + * then each of the array keys will have a sequence number behind + * the given name. + * + * @param string $format See pack for an explanation of the format codes. + * @param string $data The packed data. + * @param int $offset The offset to begin unpacking from. + * @return array Returns an associative array containing unpacked elements of binary + * string. + * @throws MiscException + * + */ +function unpack(string $format, string $data, int $offset = 0): array +{ + error_clear_last(); + $result = \unpack($format, $data, $offset); + if ($result === false) { + throw MiscException::createFromPhpError(); + } + return $result; +} diff --git a/generated/pcre.php b/generated/pcre.php index ceab9908..c40f14cc 100644 --- a/generated/pcre.php +++ b/generated/pcre.php @@ -97,7 +97,7 @@ * * * If this flag is passed, for every occurring match the appendant string - * offset will also be returned. Note that this changes the value of + * offset (in bytes) will also be returned. Note that this changes the value of * matches into an array of arrays where every element is an * array consisting of the matched string at offset 0 * and its string offset into subject at offset @@ -233,7 +233,7 @@ * The above example will output: * * If this flag is passed, for every occurring match the appendant string - * offset will also be returned. Note that this changes the value of + * offset (in bytes) will also be returned. Note that this changes the value of * matches into an array of arrays where every element is an * array consisting of the matched string at offset 0 * and its string offset into subject at offset diff --git a/generated/pgsql.php b/generated/pgsql.php index 8cb5f5e8..007faacb 100644 --- a/generated/pgsql.php +++ b/generated/pgsql.php @@ -1107,7 +1107,7 @@ function pg_options($connection = null): string * server_encoding, client_encoding, * is_superuser, session_authorization, * DateStyle, TimeZone, and - * integer_datetimes. + * integer_datetimes. Note that this value is case-sensitive. * @return string A string containing the value of the parameter, FALSE on failure or invalid * param_name. * @throws PgsqlException diff --git a/generated/uodbc.php b/generated/uodbc.php index 763f6c34..95fbc0c1 100644 --- a/generated/uodbc.php +++ b/generated/uodbc.php @@ -36,11 +36,13 @@ function odbc_autocommit($connection_id, bool $OnOff = false) /** - * Enables handling of binary column data. ODBC SQL types affected are + * Controls handling of binary column data. ODBC SQL types affected are * BINARY, VARBINARY, and * LONGVARBINARY. + * The default mode can be set using the + * uodbc.defaultbinmode php.ini directive. * - * When binary SQL data is converted to character C data, each byte + * When binary SQL data is converted to character C data (ODBC_BINMODE_CONVERT), each byte * (8 bits) of source data is represented as two ASCII characters. * These characters are the ASCII character representation of the * number in its hexadecimal form. For example, a binary @@ -48,6 +50,10 @@ function odbc_autocommit($connection_id, bool $OnOff = false) * "01" and a binary 11111111 * is converted to "FF". * + * While the handling of BINARY and VARBINARY + * columns only depend on the binmode, the handling of LONGVARBINARY + * columns also depends on the longreadlen as well: + * * LONGVARBINARY handling * * @@ -75,11 +81,6 @@ function odbc_autocommit($connection_id, bool $OnOff = false) * * * ODBC_BINMODE_PASSTHRU - * 0 - * passthru - * - * - * ODBC_BINMODE_PASSTHRU * >0 * passthru * @@ -99,19 +100,13 @@ function odbc_autocommit($connection_id, bool $OnOff = false) * * If odbc_fetch_into is used, passthru means that an * empty string is returned for these columns. + * If odbc_result is used, passthru means that the data are + * sent directly to the client (i.e. printed). * * @param int $result_id The result identifier. * * If result_id is 0, the * settings apply as default for new results. - * - * - * Default for longreadlen is 4096 and - * mode defaults to - * ODBC_BINMODE_RETURN. Handling of binary long - * columns is also affected by odbc_longreadlen. - * - * * @param int $mode Possible values for mode are: * * @@ -130,6 +125,12 @@ function odbc_autocommit($connection_id, bool $OnOff = false) * * * + * + * + * Handling of binary long + * columns is also affected by odbc_longreadlen. + * + * * @throws UodbcException * */ @@ -588,12 +589,14 @@ function odbc_gettypeinfo($connection_id, int $data_type = null) /** - * Enables handling of LONG and LONGVARBINARY columns. + * Controls handling of LONG, LONGVARCHAR and LONGVARBINARY columns. + * The default length can be set using the + * uodbc.defaultlrl php.ini directive. * * @param resource $result_id The result identifier. * @param int $length The number of bytes returned to PHP is controlled by the parameter - * length. If it is set to 0, Long column data is passed through to the - * client. + * length. If it is set to 0, long column data is passed through to the + * client (i.e. printed) when retrieved with odbc_result. * @throws UodbcException * */ From 0e15a41bd72dd82a55dee532d0584bc6840366c1 Mon Sep 17 00:00:00 2001 From: Kharhamel Date: Tue, 6 Oct 2020 17:20:05 +0200 Subject: [PATCH 6/6] fixes --- generated/uodbc.php | 4 ++++ generator/src/DeprecateCommand.php | 5 ++--- generator/src/DocPage.php | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/generated/uodbc.php b/generated/uodbc.php index 95fbc0c1..89775c82 100644 --- a/generated/uodbc.php +++ b/generated/uodbc.php @@ -676,6 +676,10 @@ function odbc_primarykeys($connection_id, string $catalog, string $schema, strin /** * Prints all rows from a result identifier produced by * odbc_exec. The result is printed in HTML table format. + * The data is not escaped. + * + * This function is not supposed to be used in production environments; it is + * merely meant for development purposes, to get a result set quickly rendered. * * @param resource $result_id The result identifier. * @param string $format Additional overall table formatting. diff --git a/generator/src/DeprecateCommand.php b/generator/src/DeprecateCommand.php index e49da6fe..3f4dd56d 100644 --- a/generator/src/DeprecateCommand.php +++ b/generator/src/DeprecateCommand.php @@ -3,7 +3,6 @@ namespace Safe; - use http\Exception\RuntimeException; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -26,6 +25,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output) { + /** @var string $moduleName */ $moduleName = $input->getArgument('module'); $moduleFilePath = self::GENERATE_DIRECTORY."$moduleName.php"; @@ -62,5 +62,4 @@ public static function getExceptionFilePath(string $moduleName): string { return "Exceptions/".ucfirst($moduleName)."Exception.php"; } - -} \ No newline at end of file +} diff --git a/generator/src/DocPage.php b/generator/src/DocPage.php index c086576b..27dd77a6 100644 --- a/generator/src/DocPage.php +++ b/generator/src/DocPage.php @@ -108,7 +108,7 @@ public function detectFalsyFunction(): bool if (preg_match('/&gd\.return\.identifier;/m', $file)) { return true; - } + } if (preg_match('/&gd\.return\.identifier;/m', $file)) { return true; }