Make Phar $format and $compression arguments nullable

Rather than using Greg's birthday, use null to indicate that the
existing format/compression should be retained. For the format
simply using zero would be sufficient, but as the documentation
explicitly says that NULL is allowed here, we may as well make
that the truth.
This commit is contained in:
Nikita Popov 2020-10-08 13:12:22 +02:00
parent 9e32e1322e
commit 9719d6cade
4 changed files with 41 additions and 23 deletions

View file

@ -2336,10 +2336,10 @@ PHP_METHOD(Phar, convertToExecutable)
size_t ext_len = 0;
uint32_t flags;
zend_object *ret;
/* a number that is not 0, 1 or 2 (Which is also Greg's birthday, so there) */
zend_long format = 9021976, method = 9021976;
zend_long format, method;
zend_bool format_is_null = 1, method_is_null = 1;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lls!", &format, &method, &ext, &ext_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!l!s!", &format, &format_is_null, &method, &method_is_null, &ext, &ext_len) == FAILURE) {
RETURN_THROWS();
}
@ -2351,9 +2351,12 @@ PHP_METHOD(Phar, convertToExecutable)
RETURN_THROWS();
}
if (format_is_null) {
format = PHAR_FORMAT_SAME;
}
switch (format) {
case 9021976:
case PHAR_FORMAT_SAME: /* null is converted to 0 */
case 9021976: /* Retained for BC */
case PHAR_FORMAT_SAME:
/* by default, use the existing format */
if (phar_obj->archive->is_tar) {
format = PHAR_FORMAT_TAR;
@ -2373,8 +2376,11 @@ PHP_METHOD(Phar, convertToExecutable)
RETURN_THROWS();
}
switch (method) {
case 9021976:
if (method_is_null) {
flags = phar_obj->archive->flags & PHAR_FILE_COMPRESSION_MASK;
} else {
switch (method) {
case 9021976: /* Retained for BC */
flags = phar_obj->archive->flags & PHAR_FILE_COMPRESSION_MASK;
break;
case 0:
@ -2414,6 +2420,7 @@ PHP_METHOD(Phar, convertToExecutable)
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0,
"Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2");
RETURN_THROWS();
}
}
is_data = phar_obj->archive->is_data;
@ -2440,18 +2447,21 @@ PHP_METHOD(Phar, convertToData)
size_t ext_len = 0;
uint32_t flags;
zend_object *ret;
/* a number that is not 0, 1 or 2 (Which is also Greg's birthday so there) */
zend_long format = 9021976, method = 9021976;
zend_long format, method;
zend_bool format_is_null = 1, method_is_null = 1;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|lls!", &format, &method, &ext, &ext_len) == FAILURE) {
if (zend_parse_parameters(ZEND_NUM_ARGS(), "|l!l!s!", &format, &format_is_null, &method, &method_is_null, &ext, &ext_len) == FAILURE) {
RETURN_THROWS();
}
PHAR_ARCHIVE_OBJECT();
if (format_is_null) {
format = PHAR_FORMAT_SAME;
}
switch (format) {
case 9021976:
case PHAR_FORMAT_SAME: /* null is converted to 0 */
case 9021976: /* Retained for BC */
case PHAR_FORMAT_SAME:
/* by default, use the existing format */
if (phar_obj->archive->is_tar) {
format = PHAR_FORMAT_TAR;
@ -2476,8 +2486,11 @@ PHP_METHOD(Phar, convertToData)
RETURN_THROWS();
}
switch (method) {
case 9021976:
if (method_is_null) {
flags = phar_obj->archive->flags & PHAR_FILE_COMPRESSION_MASK;
} else {
switch (method) {
case 9021976: /* Retained for BC */
flags = phar_obj->archive->flags & PHAR_FILE_COMPRESSION_MASK;
break;
case 0:
@ -2517,6 +2530,7 @@ PHP_METHOD(Phar, convertToData)
zend_throw_exception_ex(spl_ce_BadMethodCallException, 0,
"Unknown compression specified, please pass one of Phar::GZ or Phar::BZ2");
RETURN_THROWS();
}
}
is_data = phar_obj->archive->is_data;

View file

@ -40,10 +40,10 @@ class Phar extends RecursiveDirectoryIterator implements Countable, ArrayAccess
public function decompress(?string $file_ext = null) {}
/** @return Phar|null */
public function convertToExecutable(int $format = 9021976, int $compression_type = 9021976, ?string $file_ext = null) {}
public function convertToExecutable(?int $format = null, ?int $compression_type = null, ?string $file_ext = null) {}
/** @return Phar|null */
public function convertToData(int $format = 9021976, int $compression_type = 9021976, ?string $file_ext = null) {}
public function convertToData(?int $format = null, ?int $compression_type = null, ?string $file_ext = null) {}
/** @return bool */
public function copy(string $newfile, string $oldfile) {}

View file

@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: e67cd4d59555843688a1bdd90ecd7d3924f1ee29 */
* Stub hash: 7c9fbbc6da2c4d7196583d82102fa857ce8eda6b */
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Phar___construct, 0, 0, 1)
ZEND_ARG_TYPE_INFO(0, filename, IS_STRING, 0)
@ -50,8 +50,8 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Phar_decompress, 0, 0, 0)
ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Phar_convertToExecutable, 0, 0, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, format, IS_LONG, 0, "9021976")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, compression_type, IS_LONG, 0, "9021976")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, format, IS_LONG, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, compression_type, IS_LONG, 1, "null")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file_ext, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()
@ -236,9 +236,13 @@ ZEND_END_ARG_INFO()
#define arginfo_class_PharData_decompress arginfo_class_Phar_decompress
#define arginfo_class_PharData_convertToExecutable arginfo_class_Phar_convertToExecutable
ZEND_BEGIN_ARG_INFO_EX(arginfo_class_PharData_convertToExecutable, 0, 0, 0)
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, format, IS_LONG, 0, "9021976")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, compression_type, IS_LONG, 0, "9021976")
ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, file_ext, IS_STRING, 1, "null")
ZEND_END_ARG_INFO()
#define arginfo_class_PharData_convertToData arginfo_class_Phar_convertToExecutable
#define arginfo_class_PharData_convertToData arginfo_class_PharData_convertToExecutable
#define arginfo_class_PharData_copy arginfo_class_Phar_copy

View file

@ -233,8 +233,8 @@ Phar::createDefaultStub(): Argument #1 ($index) must be of type ?string, array g
Phar::loadPhar(): Argument #1 ($filename) must be of type string, array given
Phar::canCompress(): Argument #1 ($method) must be of type int, string given
Phar::__construct(): Argument #1 ($filename) must be of type string, array given
Phar::convertToExecutable(): Argument #1 ($format) must be of type int, array given
Phar::convertToData(): Argument #1 ($format) must be of type int, array given
Phar::convertToExecutable(): Argument #1 ($format) must be of type ?int, array given
Phar::convertToData(): Argument #1 ($format) must be of type ?int, array given
PharData::delete(): Argument #1 ($entry) must be of type string, array given
Cannot write out phar archive, phar is read-only
Entry oops does not exist and cannot be deleted