]> granicus.if.org Git - php/commitdiff
Convert fileinfo functions arginfo to php stubs
authorCraig Duncan <git@duncanc.co.uk>
Mon, 26 Aug 2019 15:21:38 +0000 (17:21 +0200)
committerChristoph M. Becker <cmbecker69@gmx.de>
Mon, 26 Aug 2019 16:13:58 +0000 (18:13 +0200)
We also allow the context for finfo to be null.

ext/fileinfo/fileinfo.c
ext/fileinfo/fileinfo.stub.php [new file with mode: 0644]
ext/fileinfo/fileinfo_arginfo.h [new file with mode: 0644]

index 621e82c75a4a496a96f4572f7d41f728a27b6a61..2c5e4209c7f21f93ab131156ddc5d117d42a82bb 100644 (file)
@@ -34,6 +34,7 @@
 #include "ext/standard/info.h"
 #include "ext/standard/file.h" /* needed for context stuff */
 #include "php_fileinfo.h"
+#include "fileinfo_arginfo.h"
 #include "fopen_wrappers.h" /* needed for is_url */
 #include "Zend/zend_exceptions.h"
 
@@ -108,63 +109,13 @@ PHP_FILEINFO_API zend_object *finfo_objects_new(zend_class_entry *class_type)
 }
 /* }}} */
 
-/* {{{ arginfo */
-ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_open, 0, 0, 0)
-       ZEND_ARG_INFO(0, options)
-       ZEND_ARG_INFO(0, arg)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_close, 0, 0, 1)
-       ZEND_ARG_INFO(0, finfo)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_set_flags, 0, 0, 2)
-       ZEND_ARG_INFO(0, finfo)
-       ZEND_ARG_INFO(0, options)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_method_set_flags, 0, 0, 1)
-       ZEND_ARG_INFO(0, options)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_file, 0, 0, 2)
-       ZEND_ARG_INFO(0, finfo)
-       ZEND_ARG_INFO(0, filename)
-       ZEND_ARG_INFO(0, options)
-       ZEND_ARG_INFO(0, context)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_method_file, 0, 0, 1)
-       ZEND_ARG_INFO(0, filename)
-       ZEND_ARG_INFO(0, options)
-       ZEND_ARG_INFO(0, context)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_buffer, 0, 0, 2)
-       ZEND_ARG_INFO(0, finfo)
-       ZEND_ARG_INFO(0, string)
-       ZEND_ARG_INFO(0, options)
-       ZEND_ARG_INFO(0, context)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_method_buffer, 0, 0, 1)
-       ZEND_ARG_INFO(0, string)
-       ZEND_ARG_INFO(0, options)
-       ZEND_ARG_INFO(0, context)
-ZEND_END_ARG_INFO()
-
-ZEND_BEGIN_ARG_INFO_EX(arginfo_mime_content_type, 0, 0, 1)
-       ZEND_ARG_INFO(0, string)
-ZEND_END_ARG_INFO()
-/* }}} */
-
 /* {{{ finfo_class_functions
  */
 static const zend_function_entry finfo_class_functions[] = {
-       ZEND_ME_MAPPING(__construct,    finfo_open,     arginfo_finfo_open, ZEND_ACC_PUBLIC)
-       ZEND_ME_MAPPING(set_flags,      finfo_set_flags,arginfo_finfo_method_set_flags, ZEND_ACC_PUBLIC)
-       ZEND_ME_MAPPING(file,           finfo_file,     arginfo_finfo_method_file, ZEND_ACC_PUBLIC)
-       ZEND_ME_MAPPING(buffer,         finfo_buffer,   arginfo_finfo_method_buffer, ZEND_ACC_PUBLIC)
+       ZEND_ME_MAPPING(__construct,    finfo_open,     arginfo_class_finfo___construct, ZEND_ACC_PUBLIC)
+       ZEND_ME_MAPPING(set_flags,      finfo_set_flags,arginfo_class_finfo_set_flags, ZEND_ACC_PUBLIC)
+       ZEND_ME_MAPPING(file,           finfo_file,     arginfo_class_finfo_file, ZEND_ACC_PUBLIC)
+       ZEND_ME_MAPPING(buffer,         finfo_buffer,   arginfo_class_finfo_buffer, ZEND_ACC_PUBLIC)
        PHP_FE_END
 };
 /* }}} */
@@ -470,13 +421,13 @@ static void _php_finfo_get_type(INTERNAL_FUNCTION_PARAMETERS, int mode, int mime
                        goto common;
                }
        } else if (object) {
-               if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|lr", &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
+               if (zend_parse_parameters(ZEND_NUM_ARGS(), "s|lr!", &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
                        return;
                }
                FILEINFO_FROM_OBJECT(finfo, object);
                magic = finfo->magic;
        } else {
-               if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|lr", &zfinfo, &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
+               if (zend_parse_parameters(ZEND_NUM_ARGS(), "rs|lr!", &zfinfo, &buffer, &buffer_len, &options, &zcontext) == FAILURE) {
                        return;
                }
                if ((finfo = (php_fileinfo *)zend_fetch_resource(Z_RES_P(zfinfo), "file_info", le_fileinfo)) == NULL) {
diff --git a/ext/fileinfo/fileinfo.stub.php b/ext/fileinfo/fileinfo.stub.php
new file mode 100644 (file)
index 0000000..1b7a3b7
--- /dev/null
@@ -0,0 +1,54 @@
+<?php
+
+class finfo
+{
+    function __construct(int $options = FILEINFO_NONE, string $arg = "") {}
+
+    /**
+     * @param ?resource $context
+     * @return string|false
+     */
+    function file(string $file_name, int $options = FILEINFO_NONE, $context = null) {}
+
+    /**
+     * @param ?resource $context
+     * @return string|false
+     */
+    function buffer(string $string, int $options = FILEINFO_NONE, $context = null) {}
+
+    /** @return bool */
+    function set_flags(int $options) {}
+}
+
+/** @return resource|false */
+function finfo_open(int $options = FILEINFO_NONE, string $arg = "") {}
+
+/**
+ * @param resource $finfo
+ */
+function finfo_close($finfo): bool {}
+
+/**
+ * @param resource $finfo
+ */
+function finfo_set_flags($finfo, int $options): bool {}
+
+/**
+ * @param resource $finfo
+ * @param ?resource $context
+ * @return string|false
+ */
+function finfo_file($finfo, string $file_name, int $options = FILEINFO_NONE, $context = null) {}
+
+/**
+ * @param resource $finfo
+ * @param ?resource $context
+ * @return string|false
+ */
+function finfo_buffer($finfo, string $string, int $options = FILEINFO_NONE, $context = null) {}
+
+/**
+ * @param resource|string $filename
+ * @return string|false
+ */
+function mime_content_type($filename) {}
diff --git a/ext/fileinfo/fileinfo_arginfo.h b/ext/fileinfo/fileinfo_arginfo.h
new file mode 100644 (file)
index 0000000..b987d8a
--- /dev/null
@@ -0,0 +1,51 @@
+/* This is a generated file, edit the .stub.php file instead. */
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_class_finfo___construct, 0, 0, 0)
+       ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0)
+       ZEND_ARG_TYPE_INFO(0, arg, IS_STRING, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_class_finfo_file, 0, 0, 1)
+       ZEND_ARG_TYPE_INFO(0, file_name, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0)
+       ZEND_ARG_INFO(0, context)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_class_finfo_buffer, 0, 0, 1)
+       ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0)
+       ZEND_ARG_INFO(0, context)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_class_finfo_set_flags, 0, 0, 1)
+       ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0)
+ZEND_END_ARG_INFO()
+
+#define arginfo_finfo_open arginfo_class_finfo___construct
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_finfo_close, 0, 1, _IS_BOOL, 0)
+       ZEND_ARG_INFO(0, finfo)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_finfo_set_flags, 0, 2, _IS_BOOL, 0)
+       ZEND_ARG_INFO(0, finfo)
+       ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_file, 0, 0, 2)
+       ZEND_ARG_INFO(0, finfo)
+       ZEND_ARG_TYPE_INFO(0, file_name, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0)
+       ZEND_ARG_INFO(0, context)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_finfo_buffer, 0, 0, 2)
+       ZEND_ARG_INFO(0, finfo)
+       ZEND_ARG_TYPE_INFO(0, string, IS_STRING, 0)
+       ZEND_ARG_TYPE_INFO(0, options, IS_LONG, 0)
+       ZEND_ARG_INFO(0, context)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_mime_content_type, 0, 0, 1)
+       ZEND_ARG_INFO(0, filename)
+ZEND_END_ARG_INFO()