mirror of
https://github.com/php/php-src.git
synced 2025-08-16 05:58:45 +02:00
Convert fileinfo functions arginfo to php stubs
We also allow the context for finfo to be null.
This commit is contained in:
parent
38c2230d07
commit
4836660b90
3 changed files with 112 additions and 56 deletions
|
@ -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) {
|
||||
|
|
54
ext/fileinfo/fileinfo.stub.php
Normal file
54
ext/fileinfo/fileinfo.stub.php
Normal file
|
@ -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) {}
|
51
ext/fileinfo/fileinfo_arginfo.h
Normal file
51
ext/fileinfo/fileinfo_arginfo.h
Normal file
|
@ -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()
|
Loading…
Add table
Add a link
Reference in a new issue