From edae4165edbf542bd798f7e4c2df1da086f2ce53 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Sun, 14 May 2017 15:43:31 +0200 Subject: [PATCH 01/54] Fixed ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO macro The macro was expanding to a wrong macro and thus leads to compile errors upon usage. Changed it to expand to the correct macro, and added Doxygen documentation to help new users. --- Zend/zend_API.h | 65 +++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/Zend/zend_API.h b/Zend/zend_API.h index b8a6ecfcb77d8..59d7c29747bde 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -1,4 +1,4 @@ -/* +ο»Ώ/* +----------------------------------------------------------------------+ | Zend Engine | +----------------------------------------------------------------------+ @@ -107,12 +107,67 @@ typedef struct _zend_fcall_info_cache { #define ZEND_ARG_VARIADIC_TYPE_INFO(pass_by_ref, name, type_hint, allow_null) { #name, ZEND_TYPE_ENCODE(type_hint, allow_null), pass_by_ref, 1 }, #define ZEND_ARG_VARIADIC_OBJ_INFO(pass_by_ref, name, classname, allow_null) { #name, ZEND_TYPE_ENCODE_CLASS_CONST(#classname, allow_null), pass_by_ref, 1 }, - -#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, classname, allow_null) \ +/** + * Start extended argument information block with an object return type + * declaration. + * + * ## Examples + * ```c + * ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arg_info_f, 0, 0, T, 0) + * ZEND_END_ARG_INFO() + * ``` + * + * Above example argument information applied to a function _f_ would result in + * the following PHP function signature: + * + * ```php + * function f(): T {} + * ``` + * + * @param[in] name + * of the variable where the argument information should be assigned to. + * @param[in] return_reference + * whether the routine returns by reference (`1`) or not (`0`). + * @param[in] required_num_args + * total amount of required (non-optional) arguments of the routine. + * @param[in] class_name + * of the object that this routine must return. + * @param[in] allow_null + * whether the routine's return type is nullable (`1`) or not (`0`). + * @see ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO + * for routines that do not take any arguments. + */ +#define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, return_reference, required_num_args, class_name, allow_null) \ static const zend_internal_arg_info name[] = { \ - { (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_ENCODE_CLASS_CONST(#classname, allow_null), return_reference, 0 }, + { (const char*)(zend_uintptr_t)(required_num_args), ZEND_TYPE_ENCODE_CLASS_CONST(#class_name, allow_null), return_reference, 0 }, + +/** + * Start argument information block with return object return type declaration. + * + * ## Examples + * ```c + * ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(arg_info_f, T, 0) + * ZEND_END_ARG_INFO() + * ``` + * + * Above example argument information applied to a function _f_ would result + * in the following PHP function signature: + * + * ```php + * function f(): T {} + * ``` + * + * @param[in] name + * of the variable where the argument information should be assigned to. + * @param[in] class_name + * of the object that this routine must return. + * @param[in] allow_null + * whether the routine's return type is nullable (`1`) or not (`0`). + * @see ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX + * which allows the specification of the total amount of required arguments. + */ #define ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(name, class_name, allow_null) \ - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, 0, -1, class_name, allow_null) + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(name, 0, -1, class_name, allow_null) #define ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(name, return_reference, required_num_args, type, allow_null) \ static const zend_internal_arg_info name[] = { \ From 76e1a206224905c592ba20b1f05d80d7ad848c01 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Tue, 23 May 2017 18:02:49 +0200 Subject: [PATCH 02/54] Test cases for UUIDParsingException --- .../__construct/definition-001.phpt | 22 +++++++++++++++ .../__construct/definition-002.phpt | 24 ++++++++++++++++ .../__construct/definition-003.phpt | 24 ++++++++++++++++ .../__construct/definition-004.phpt | 25 +++++++++++++++++ .../__construct/definition-005.phpt | 25 +++++++++++++++++ .../__construct/error-001.phpt | 17 +++++++++++ .../__construct/error-002.phpt | 17 +++++++++++ .../__construct/variation-001.phpt | 20 +++++++++++++ .../__construct/variation-002.phpt | 20 +++++++++++++ .../__construct/variation-003.phpt | 25 +++++++++++++++++ .../uuid/UUIDParsingException/basic.phpt | 28 +++++++++++++++++++ .../UUIDParsingException/definition-001.phpt | 24 ++++++++++++++++ .../UUIDParsingException/definition-002.phpt | 15 ++++++++++ .../UUIDParsingException/definition-003.phpt | 15 ++++++++++ .../UUIDParsingException/getInput/basic.phpt | 12 ++++++++ .../getInput/definition.phpt | 26 +++++++++++++++++ .../getPosition/basic.phpt | 12 ++++++++ .../getPosition/definition.phpt | 26 +++++++++++++++++ .../getPosition/variation.phpt | 12 ++++++++ .../UUIDParsingException/variation-001.phpt | 28 +++++++++++++++++++ .../UUIDParsingException/variation-002.phpt | 28 +++++++++++++++++++ .../UUIDParsingException/variation-003.phpt | 28 +++++++++++++++++++ 22 files changed, 473 insertions(+) create mode 100644 ext/standard/tests/uuid/UUIDParsingException/__construct/definition-001.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/__construct/definition-002.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/__construct/definition-003.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/__construct/definition-004.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/__construct/definition-005.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/__construct/error-001.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/__construct/error-002.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/__construct/variation-001.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/__construct/variation-002.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/__construct/variation-003.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/basic.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/definition-001.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/definition-002.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/definition-003.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/getInput/basic.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/getInput/definition.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/getPosition/basic.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/getPosition/definition.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/getPosition/variation.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/variation-001.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/variation-002.phpt create mode 100644 ext/standard/tests/uuid/UUIDParsingException/variation-003.phpt diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-001.phpt b/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-001.phpt new file mode 100644 index 0000000000000..bf369e0c3c304 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-001.phpt @@ -0,0 +1,22 @@ +--TEST-- +UUIDParsingException::__construct method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + $m->hasReturnType(), + $m->isPublic() +); + +?> +--EXPECT-- +int(4) +int(2) +bool(false) +bool(true) diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-002.phpt b/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-002.phpt new file mode 100644 index 0000000000000..bdc69d96fe4c4 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-002.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUIDParsingException::__construct 1. parameter definition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getParameters()[0]; + +var_dump( + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference() +); + +?> +--EXPECT-- +string(6) "reason" +bool(false) +string(6) "string" +bool(false) +bool(false) diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-003.phpt b/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-003.phpt new file mode 100644 index 0000000000000..130d60a4be99f --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-003.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUIDParsingException::__construct 2. parameter definition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getParameters()[1]; + +var_dump( + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference() +); + +?> +--EXPECT-- +string(5) "input" +bool(false) +string(6) "string" +bool(false) +bool(false) diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-004.phpt b/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-004.phpt new file mode 100644 index 0000000000000..e86e4e9e44b49 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-004.phpt @@ -0,0 +1,25 @@ +--TEST-- +UUIDParsingException::__construct 3. parameter definition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getParameters()[2]; + +var_dump( + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + //$p->getDefaultValue(), + $p->isPassedByReference() +); + +?> +--EXPECT-- +string(8) "position" +bool(false) +string(3) "int" +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-005.phpt b/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-005.phpt new file mode 100644 index 0000000000000..f02fdace419bc --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-005.phpt @@ -0,0 +1,25 @@ +--TEST-- +UUIDParsingException::__construct 4. parameter definition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getParameters()[3]; + +var_dump( + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + //$p->getDefaultValue(), + $p->isPassedByReference() +); + +?> +--EXPECT-- +string(8) "previous" +bool(true) +string(9) "Throwable" +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/error-001.phpt b/ext/standard/tests/uuid/UUIDParsingException/__construct/error-001.phpt new file mode 100644 index 0000000000000..7902d908b4401 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/__construct/error-001.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUIDParsingException::__construct ArgumentCountError with 0 arguments +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage(); +} + +?> +--EXPECT-- +Too few arguments to method UUIDParsingException::__construct(), 0 passed and at least 2 expected diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/error-002.phpt b/ext/standard/tests/uuid/UUIDParsingException/__construct/error-002.phpt new file mode 100644 index 0000000000000..d250c38baaf04 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/__construct/error-002.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUIDParsingException::__construct ArgumentCountError with 1 argument +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage(); +} + +?> +--EXPECT-- +Too few arguments to method UUIDParsingException::__construct(), 1 passed and at least 2 expected diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-001.phpt b/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-001.phpt new file mode 100644 index 0000000000000..007a62ee75b32 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-001.phpt @@ -0,0 +1,20 @@ +--TEST-- +UUIDParsingException::__construct with 2 arguments +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +setAccessible(true); + var_dump($p->getValue($e)); +} + +?> +--EXPECT-- +string(20) "variation-001-reason" +string(19) "variation-001-input" +int(0) diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-002.phpt b/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-002.phpt new file mode 100644 index 0000000000000..f0277d2bf2657 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-002.phpt @@ -0,0 +1,20 @@ +--TEST-- +UUIDParsingException::__construct with 3 arguments +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +setAccessible(true); + var_dump($p->getValue($e)); +} + +?> +--EXPECT-- +string(20) "variation-002-reason" +string(19) "variation-002-input" +int(42) diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-003.phpt b/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-003.phpt new file mode 100644 index 0000000000000..7374001656d39 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-003.phpt @@ -0,0 +1,25 @@ +--TEST-- +UUIDParsingException::__construct with 4 arguments +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +setAccessible(true); + var_dump($p->getValue($e)); +} + +$p = new ReflectionProperty(Exception::class, 'previous'); +$p->setAccessible(true); +var_dump($p->getValue($e) === $previous); + +?> +--EXPECT-- +string(20) "variation-003-reason" +string(19) "variation-003-input" +int(84) +bool(true) diff --git a/ext/standard/tests/uuid/UUIDParsingException/basic.phpt b/ext/standard/tests/uuid/UUIDParsingException/basic.phpt new file mode 100644 index 0000000000000..48683f2a3048c --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/basic.phpt @@ -0,0 +1,28 @@ +--TEST-- +UUIDParsingException construction +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getCode(), + $e->getFile() === __FILE__, + $e->getInput(), + $e->getLine(), + $e->getMessage(), + $e->getPosition(), + $e->getPrevious() +); + +?> +--EXPECT-- +int(0) +bool(true) +string(11) "basic-input" +int(3) +string(12) "basic-reason" +int(0) +NULL diff --git a/ext/standard/tests/uuid/UUIDParsingException/definition-001.phpt b/ext/standard/tests/uuid/UUIDParsingException/definition-001.phpt new file mode 100644 index 0000000000000..36f7ef57af501 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/definition-001.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUIDParsingException class definition. +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +isAbstract(), + $c->isFinal(), + $c->isInstantiable(), + $c->isInternal(), + $c->isSubclassOf(Exception::class) +); + +?> +--EXPECT-- +bool(false) +bool(true) +bool(true) +bool(true) +bool(true) diff --git a/ext/standard/tests/uuid/UUIDParsingException/definition-002.phpt b/ext/standard/tests/uuid/UUIDParsingException/definition-002.phpt new file mode 100644 index 0000000000000..32355b7d1f9e9 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/definition-002.phpt @@ -0,0 +1,15 @@ +--TEST-- +UUIDParsingException input property definition. +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +isPrivate(), $p->isStatic()); + +?> +--EXPECT-- +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUIDParsingException/definition-003.phpt b/ext/standard/tests/uuid/UUIDParsingException/definition-003.phpt new file mode 100644 index 0000000000000..9ab53628391dc --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/definition-003.phpt @@ -0,0 +1,15 @@ +--TEST-- +UUIDParsingException position property definition. +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +isPrivate(), $p->isStatic()); + +?> +--EXPECT-- +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUIDParsingException/getInput/basic.phpt b/ext/standard/tests/uuid/UUIDParsingException/getInput/basic.phpt new file mode 100644 index 0000000000000..6f0343c8adc75 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/getInput/basic.phpt @@ -0,0 +1,12 @@ +--TEST-- +UUIDParsingException::getInput +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getInput()); + +?> +--EXPECT-- +string(10) "input-test" diff --git a/ext/standard/tests/uuid/UUIDParsingException/getInput/definition.phpt b/ext/standard/tests/uuid/UUIDParsingException/getInput/definition.phpt new file mode 100644 index 0000000000000..0cc63279870b0 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/getInput/definition.phpt @@ -0,0 +1,26 @@ +--TEST-- +UUIDParsingException::getInput method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isAbstract(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(6) "string" +bool(false) +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUIDParsingException/getPosition/basic.phpt b/ext/standard/tests/uuid/UUIDParsingException/getPosition/basic.phpt new file mode 100644 index 0000000000000..fabcfc37a7a9e --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/getPosition/basic.phpt @@ -0,0 +1,12 @@ +--TEST-- +UUIDParsingException::getPosition default value +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getPosition()); + +?> +--EXPECT-- +int(0) diff --git a/ext/standard/tests/uuid/UUIDParsingException/getPosition/definition.phpt b/ext/standard/tests/uuid/UUIDParsingException/getPosition/definition.phpt new file mode 100644 index 0000000000000..d78a7d08b48a3 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/getPosition/definition.phpt @@ -0,0 +1,26 @@ +--TEST-- +UUIDParsingException::getPosition method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isAbstract(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(3) "int" +bool(false) +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUIDParsingException/getPosition/variation.phpt b/ext/standard/tests/uuid/UUIDParsingException/getPosition/variation.phpt new file mode 100644 index 0000000000000..9fcfe859bf793 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/getPosition/variation.phpt @@ -0,0 +1,12 @@ +--TEST-- +UUIDParsingException::getPosition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getPosition()); + +?> +--EXPECT-- +int(42) diff --git a/ext/standard/tests/uuid/UUIDParsingException/variation-001.phpt b/ext/standard/tests/uuid/UUIDParsingException/variation-001.phpt new file mode 100644 index 0000000000000..997ae97796d6f --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/variation-001.phpt @@ -0,0 +1,28 @@ +--TEST-- +UUIDParsingException construction with custom position +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getCode(), + $e->getFile() === __FILE__, + $e->getInput(), + $e->getLine(), + $e->getMessage(), + $e->getPosition(), + $e->getPrevious() +); + +?> +--EXPECT-- +int(0) +bool(true) +string(19) "variation-001-input" +int(3) +string(20) "variation-001-reason" +int(1) +NULL diff --git a/ext/standard/tests/uuid/UUIDParsingException/variation-002.phpt b/ext/standard/tests/uuid/UUIDParsingException/variation-002.phpt new file mode 100644 index 0000000000000..6b298122ddfef --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/variation-002.phpt @@ -0,0 +1,28 @@ +--TEST-- +UUIDParsingException construction with custom position and previous error +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getCode(), + $e->getFile() === __FILE__, + $e->getInput(), + $e->getLine(), + $e->getMessage(), + $e->getPosition(), + $e->getPrevious() === $previous +); + +?> +--EXPECT-- +int(0) +bool(true) +string(19) "variation-002-input" +int(3) +string(20) "variation-002-reason" +int(2) +bool(true) diff --git a/ext/standard/tests/uuid/UUIDParsingException/variation-003.phpt b/ext/standard/tests/uuid/UUIDParsingException/variation-003.phpt new file mode 100644 index 0000000000000..5c6c49cc3e75e --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParsingException/variation-003.phpt @@ -0,0 +1,28 @@ +--TEST-- +UUIDParsingException construction with custom position and previous exception +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getCode(), + $e->getFile() === __FILE__, + $e->getInput(), + $e->getLine(), + $e->getMessage(), + $e->getPosition(), + $e->getPrevious() === $previous +); + +?> +--EXPECT-- +int(0) +bool(true) +string(19) "variation-003-input" +int(3) +string(20) "variation-003-reason" +int(3) +bool(true) From 7e13b7ffa1b4f5d666d666ef853f30d32c08ad9a Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Tue, 23 May 2017 22:33:24 +0200 Subject: [PATCH 03/54] Test cases for UUID --- .../tests/uuid/UUID/NamespaceDNS/basic.phpt | 24 ++++++++++++ .../uuid/UUID/NamespaceDNS/definition.phpt | 24 ++++++++++++ .../tests/uuid/UUID/NamespaceOID/basic.phpt | 24 ++++++++++++ .../uuid/UUID/NamespaceOID/definition.phpt | 24 ++++++++++++ .../tests/uuid/UUID/NamespaceURL/basic.phpt | 24 ++++++++++++ .../uuid/UUID/NamespaceURL/definition.phpt | 24 ++++++++++++ .../tests/uuid/UUID/NamespaceX500/basic.phpt | 24 ++++++++++++ .../uuid/UUID/NamespaceX500/definition.phpt | 24 ++++++++++++ ext/standard/tests/uuid/UUID/Nil/basic.phpt | 24 ++++++++++++ .../tests/uuid/UUID/Nil/definition.phpt | 24 ++++++++++++ .../tests/uuid/UUID/__clone/definition.phpt | 24 ++++++++++++ .../tests/uuid/UUID/__clone/error.phpt | 20 ++++++++++ .../uuid/UUID/__construct/definition.phpt | 24 ++++++++++++ .../tests/uuid/UUID/__set/definition.phpt | 24 ++++++++++++ ext/standard/tests/uuid/UUID/__set/error.phpt | 17 +++++++++ .../tests/uuid/UUID/__wakeup/basic.phpt | 15 ++++++++ .../tests/uuid/UUID/__wakeup/definition.phpt | 24 ++++++++++++ .../tests/uuid/UUID/__wakeup/error.phpt | 24 ++++++++++++ .../tests/uuid/UUID/comparison-001.phpt | 18 +++++++++ .../tests/uuid/UUID/comparison-002.phpt | 21 ++++++++++ .../tests/uuid/UUID/comparison-003.phpt | 22 +++++++++++ .../tests/uuid/UUID/comparison-004.phpt | 36 ++++++++++++++++++ .../tests/uuid/UUID/definition-001.phpt | 38 +++++++++++++++++++ .../tests/uuid/UUID/definition-002.phpt | 20 ++++++++++ .../tests/uuid/UUID/definition-003.phpt | 22 +++++++++++ .../tests/uuid/UUID/definition-004.phpt | 15 ++++++++ .../tests/uuid/UUID/fromBinary/basic.phpt | 17 +++++++++ .../uuid/UUID/fromBinary/definition-001.phpt | 24 ++++++++++++ .../uuid/UUID/fromBinary/definition-002.phpt | 26 +++++++++++++ .../tests/uuid/UUID/fromBinary/error-001.phpt | 17 +++++++++ .../tests/uuid/UUID/fromBinary/error-002.phpt | 23 +++++++++++ .../tests/uuid/UUID/getVariant/basic.phpt | 20 ++++++++++ .../uuid/UUID/getVariant/definition.phpt | 24 ++++++++++++ .../uuid/UUID/getVariant/variation-001.phpt | 20 ++++++++++ .../uuid/UUID/getVariant/variation-002.phpt | 16 ++++++++ .../tests/uuid/UUID/getVersion/basic.phpt | 29 ++++++++++++++ .../uuid/UUID/getVersion/definition.phpt | 24 ++++++++++++ .../tests/uuid/UUID/parse/basic-001.phpt | 16 ++++++++ .../tests/uuid/UUID/parse/basic-002.phpt | 16 ++++++++ .../tests/uuid/UUID/parse/basic-003.phpt | 16 ++++++++ .../tests/uuid/UUID/parse/basic-004.phpt | 16 ++++++++ .../tests/uuid/UUID/parse/definition-001.phpt | 24 ++++++++++++ .../tests/uuid/UUID/parse/definition-002.phpt | 26 +++++++++++++ .../tests/uuid/UUID/parse/error-001.phpt | 17 +++++++++ .../tests/uuid/UUID/parse/error-002.phpt | 29 ++++++++++++++ .../tests/uuid/UUID/parse/error-003.phpt | 17 +++++++++ .../tests/uuid/UUID/parse/error-004.phpt | 17 +++++++++ .../tests/uuid/UUID/parse/variation-001.phpt | 16 ++++++++ .../tests/uuid/UUID/parse/variation-002.phpt | 16 ++++++++ .../tests/uuid/UUID/parse/variation-003.phpt | 16 ++++++++ .../tests/uuid/UUID/parse/variation-004.phpt | 16 ++++++++ .../tests/uuid/UUID/toBinary/basic.phpt | 12 ++++++ .../tests/uuid/UUID/toBinary/definition.phpt | 24 ++++++++++++ ext/standard/tests/uuid/UUID/toHex/basic.phpt | 12 ++++++ .../tests/uuid/UUID/toHex/definition.phpt | 24 ++++++++++++ .../tests/uuid/UUID/toString/basic.phpt | 12 ++++++ .../tests/uuid/UUID/toString/definition.phpt | 24 ++++++++++++ ext/standard/tests/uuid/UUID/v3/basic.phpt | 12 ++++++ .../tests/uuid/UUID/v3/definition-001.phpt | 24 ++++++++++++ .../tests/uuid/UUID/v3/definition-002.phpt | 26 +++++++++++++ .../tests/uuid/UUID/v3/definition-003.phpt | 26 +++++++++++++ .../tests/uuid/UUID/v3/error-001.phpt | 17 +++++++++ .../tests/uuid/UUID/v3/error-002.phpt | 17 +++++++++ ext/standard/tests/uuid/UUID/v4/basic.phpt | 12 ++++++ .../tests/uuid/UUID/v4/definition.phpt | 24 ++++++++++++ ext/standard/tests/uuid/UUID/v5/basic.phpt | 12 ++++++ .../tests/uuid/UUID/v5/definition-001.phpt | 24 ++++++++++++ .../tests/uuid/UUID/v5/definition-002.phpt | 26 +++++++++++++ .../tests/uuid/UUID/v5/definition-003.phpt | 26 +++++++++++++ .../tests/uuid/UUID/v5/error-001.phpt | 17 +++++++++ .../tests/uuid/UUID/v5/error-002.phpt | 17 +++++++++ 71 files changed, 1490 insertions(+) create mode 100644 ext/standard/tests/uuid/UUID/NamespaceDNS/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/NamespaceDNS/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/NamespaceOID/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/NamespaceOID/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/NamespaceURL/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/NamespaceURL/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/NamespaceX500/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/NamespaceX500/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/Nil/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/Nil/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/__clone/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/__clone/error.phpt create mode 100644 ext/standard/tests/uuid/UUID/__construct/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/__set/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/__set/error.phpt create mode 100644 ext/standard/tests/uuid/UUID/__wakeup/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/__wakeup/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/__wakeup/error.phpt create mode 100644 ext/standard/tests/uuid/UUID/comparison-001.phpt create mode 100644 ext/standard/tests/uuid/UUID/comparison-002.phpt create mode 100644 ext/standard/tests/uuid/UUID/comparison-003.phpt create mode 100644 ext/standard/tests/uuid/UUID/comparison-004.phpt create mode 100644 ext/standard/tests/uuid/UUID/definition-001.phpt create mode 100644 ext/standard/tests/uuid/UUID/definition-002.phpt create mode 100644 ext/standard/tests/uuid/UUID/definition-003.phpt create mode 100644 ext/standard/tests/uuid/UUID/definition-004.phpt create mode 100644 ext/standard/tests/uuid/UUID/fromBinary/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/fromBinary/definition-001.phpt create mode 100644 ext/standard/tests/uuid/UUID/fromBinary/definition-002.phpt create mode 100644 ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt create mode 100644 ext/standard/tests/uuid/UUID/fromBinary/error-002.phpt create mode 100644 ext/standard/tests/uuid/UUID/getVariant/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/getVariant/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/getVariant/variation-001.phpt create mode 100644 ext/standard/tests/uuid/UUID/getVariant/variation-002.phpt create mode 100644 ext/standard/tests/uuid/UUID/getVersion/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/getVersion/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/parse/basic-001.phpt create mode 100644 ext/standard/tests/uuid/UUID/parse/basic-002.phpt create mode 100644 ext/standard/tests/uuid/UUID/parse/basic-003.phpt create mode 100644 ext/standard/tests/uuid/UUID/parse/basic-004.phpt create mode 100644 ext/standard/tests/uuid/UUID/parse/definition-001.phpt create mode 100644 ext/standard/tests/uuid/UUID/parse/definition-002.phpt create mode 100644 ext/standard/tests/uuid/UUID/parse/error-001.phpt create mode 100644 ext/standard/tests/uuid/UUID/parse/error-002.phpt create mode 100644 ext/standard/tests/uuid/UUID/parse/error-003.phpt create mode 100644 ext/standard/tests/uuid/UUID/parse/error-004.phpt create mode 100644 ext/standard/tests/uuid/UUID/parse/variation-001.phpt create mode 100644 ext/standard/tests/uuid/UUID/parse/variation-002.phpt create mode 100644 ext/standard/tests/uuid/UUID/parse/variation-003.phpt create mode 100644 ext/standard/tests/uuid/UUID/parse/variation-004.phpt create mode 100644 ext/standard/tests/uuid/UUID/toBinary/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/toBinary/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/toHex/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/toHex/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/toString/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/toString/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/v3/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/v3/definition-001.phpt create mode 100644 ext/standard/tests/uuid/UUID/v3/definition-002.phpt create mode 100644 ext/standard/tests/uuid/UUID/v3/definition-003.phpt create mode 100644 ext/standard/tests/uuid/UUID/v3/error-001.phpt create mode 100644 ext/standard/tests/uuid/UUID/v3/error-002.phpt create mode 100644 ext/standard/tests/uuid/UUID/v4/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/v4/definition.phpt create mode 100644 ext/standard/tests/uuid/UUID/v5/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/v5/definition-001.phpt create mode 100644 ext/standard/tests/uuid/UUID/v5/definition-002.phpt create mode 100644 ext/standard/tests/uuid/UUID/v5/definition-003.phpt create mode 100644 ext/standard/tests/uuid/UUID/v5/error-001.phpt create mode 100644 ext/standard/tests/uuid/UUID/v5/error-002.phpt diff --git a/ext/standard/tests/uuid/UUID/NamespaceDNS/basic.phpt b/ext/standard/tests/uuid/UUID/NamespaceDNS/basic.phpt new file mode 100644 index 0000000000000..94cf41403f759 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/NamespaceDNS/basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::NamespaceDNS +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getVariant() === UUID::VARIANT_RFC4122, + $uuid->getVersion() === UUID::VERSION_1_TIME_BASED, + $uuid->toBinary() === "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8", + $uuid->toHex(), + $uuid->toString() +); + +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +string(32) "6ba7b8109dad11d180b400c04fd430c8" +string(36) "6ba7b810-9dad-11d1-80b4-00c04fd430c8" diff --git a/ext/standard/tests/uuid/UUID/NamespaceDNS/definition.phpt b/ext/standard/tests/uuid/UUID/NamespaceDNS/definition.phpt new file mode 100644 index 0000000000000..c3930e093f854 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/NamespaceDNS/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::NamespaceDNS method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(4) "UUID" +bool(true) +bool(true) diff --git a/ext/standard/tests/uuid/UUID/NamespaceOID/basic.phpt b/ext/standard/tests/uuid/UUID/NamespaceOID/basic.phpt new file mode 100644 index 0000000000000..f124ef7c79e70 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/NamespaceOID/basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::NamespaceOID +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getVariant() === UUID::VARIANT_RFC4122, + $uuid->getVersion() === UUID::VERSION_1_TIME_BASED, + $uuid->toBinary() === "\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8", + $uuid->toHex(), + $uuid->toString() +); + +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +string(32) "6ba7b8129dad11d180b400c04fd430c8" +string(36) "6ba7b812-9dad-11d1-80b4-00c04fd430c8" diff --git a/ext/standard/tests/uuid/UUID/NamespaceOID/definition.phpt b/ext/standard/tests/uuid/UUID/NamespaceOID/definition.phpt new file mode 100644 index 0000000000000..85903d4427048 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/NamespaceOID/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::NamespaceOID method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(4) "UUID" +bool(true) +bool(true) diff --git a/ext/standard/tests/uuid/UUID/NamespaceURL/basic.phpt b/ext/standard/tests/uuid/UUID/NamespaceURL/basic.phpt new file mode 100644 index 0000000000000..b4eac752774cc --- /dev/null +++ b/ext/standard/tests/uuid/UUID/NamespaceURL/basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::NamespaceURL +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getVariant() === UUID::VARIANT_RFC4122, + $uuid->getVersion() === UUID::VERSION_1_TIME_BASED, + $uuid->toBinary() === "\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8", + $uuid->toHex(), + $uuid->toString() +); + +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +string(32) "6ba7b8119dad11d180b400c04fd430c8" +string(36) "6ba7b811-9dad-11d1-80b4-00c04fd430c8" diff --git a/ext/standard/tests/uuid/UUID/NamespaceURL/definition.phpt b/ext/standard/tests/uuid/UUID/NamespaceURL/definition.phpt new file mode 100644 index 0000000000000..4f8bc7c1bad7e --- /dev/null +++ b/ext/standard/tests/uuid/UUID/NamespaceURL/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::NamespaceURL method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(4) "UUID" +bool(true) +bool(true) diff --git a/ext/standard/tests/uuid/UUID/NamespaceX500/basic.phpt b/ext/standard/tests/uuid/UUID/NamespaceX500/basic.phpt new file mode 100644 index 0000000000000..7c88b51b8b650 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/NamespaceX500/basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::NamespaceX500 +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getVariant() === UUID::VARIANT_RFC4122, + $uuid->getVersion() === UUID::VERSION_1_TIME_BASED, + $uuid->toBinary() === "\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8", + $uuid->toHex(), + $uuid->toString() +); + +?> +--EXPECT-- +bool(true) +bool(true) +bool(true) +string(32) "6ba7b8149dad11d180b400c04fd430c8" +string(36) "6ba7b814-9dad-11d1-80b4-00c04fd430c8" diff --git a/ext/standard/tests/uuid/UUID/NamespaceX500/definition.phpt b/ext/standard/tests/uuid/UUID/NamespaceX500/definition.phpt new file mode 100644 index 0000000000000..91d599c5df7f5 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/NamespaceX500/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::NamespaceX500 method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(4) "UUID" +bool(true) +bool(true) diff --git a/ext/standard/tests/uuid/UUID/Nil/basic.phpt b/ext/standard/tests/uuid/UUID/Nil/basic.phpt new file mode 100644 index 0000000000000..7603c832b4cd8 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/Nil/basic.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::Nil +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getVariant(), + $uuid->getVersion(), + $uuid->toBinary() === "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", + $uuid->toHex(), + $uuid->toString() +); + +?> +--EXPECT-- +int(0) +int(0) +bool(true) +string(32) "00000000000000000000000000000000" +string(36) "00000000-0000-0000-0000-000000000000" diff --git a/ext/standard/tests/uuid/UUID/Nil/definition.phpt b/ext/standard/tests/uuid/UUID/Nil/definition.phpt new file mode 100644 index 0000000000000..0557b5636b8ba --- /dev/null +++ b/ext/standard/tests/uuid/UUID/Nil/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::Nil method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(4) "UUID" +bool(true) +bool(true) diff --git a/ext/standard/tests/uuid/UUID/__clone/definition.phpt b/ext/standard/tests/uuid/UUID/__clone/definition.phpt new file mode 100644 index 0000000000000..a8f2998ec485e --- /dev/null +++ b/ext/standard/tests/uuid/UUID/__clone/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::__clone method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + $m->hasReturnType(), + $m->isPrivate(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +bool(false) +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/__clone/error.phpt b/ext/standard/tests/uuid/UUID/__clone/error.phpt new file mode 100644 index 0000000000000..8a2bd868065af --- /dev/null +++ b/ext/standard/tests/uuid/UUID/__clone/error.phpt @@ -0,0 +1,20 @@ +--TEST-- +UUID::__clone invocation leads to Error +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +setAccessible(true); + +try { + $m->invoke(UUID::Nil()); +} +catch (Error $e) { + echo $e->getMessage(); +} + +?> +--EXPECT-- +Cannot clone immutable UUID object diff --git a/ext/standard/tests/uuid/UUID/__construct/definition.phpt b/ext/standard/tests/uuid/UUID/__construct/definition.phpt new file mode 100644 index 0000000000000..06d0c0529bd3a --- /dev/null +++ b/ext/standard/tests/uuid/UUID/__construct/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::__construct method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + $m->hasReturnType(), + $m->isPrivate(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +bool(false) +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/__set/definition.phpt b/ext/standard/tests/uuid/UUID/__set/definition.phpt new file mode 100644 index 0000000000000..e25b133869071 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/__set/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::__set method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(2) +int(2) +string(4) "void" +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/__set/error.phpt b/ext/standard/tests/uuid/UUID/__set/error.phpt new file mode 100644 index 0000000000000..4fd47beab1b61 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/__set/error.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUID::__set invocation leads to Error +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +dynamic_property = 'value'; +} +catch (Error $e) { + echo $e->getMessage(); +} + +?> +--EXPECT-- +Cannot set dynamic properties on immutable UUID object diff --git a/ext/standard/tests/uuid/UUID/__wakeup/basic.phpt b/ext/standard/tests/uuid/UUID/__wakeup/basic.phpt new file mode 100644 index 0000000000000..6b28de395c41b --- /dev/null +++ b/ext/standard/tests/uuid/UUID/__wakeup/basic.phpt @@ -0,0 +1,15 @@ +--TEST-- +UUID::__wakeup +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- + +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/uuid/UUID/__wakeup/definition.phpt b/ext/standard/tests/uuid/UUID/__wakeup/definition.phpt new file mode 100644 index 0000000000000..bca95d7c7dba0 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/__wakeup/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::__wakeup method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(4) "void" +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/__wakeup/error.phpt b/ext/standard/tests/uuid/UUID/__wakeup/error.phpt new file mode 100644 index 0000000000000..32de0515336a8 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/__wakeup/error.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::__wakeup throws UnexpectedValueException if binary string is not exactly 16 bytes long after deserialization +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage() , "\n"; + } +} + +?> +--EXPECTF-- +Expected exactly 16 bytes, but found 0 +Expected exactly 16 bytes, but found 1 +Expected exactly 16 bytes, but found 15 +Expected exactly 16 bytes, but found 17 +Expected exactly 16 bytes, but found %d diff --git a/ext/standard/tests/uuid/UUID/comparison-001.phpt b/ext/standard/tests/uuid/UUID/comparison-001.phpt new file mode 100644 index 0000000000000..499a2a8b82830 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/comparison-001.phpt @@ -0,0 +1,18 @@ +--TEST-- +UUID comparison reflexivity +--DESCRIPTION-- +π‘Ž β‰Ό π‘Ž + +https://en.wikipedia.org/wiki/Reflexive_relation +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- + +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/uuid/UUID/comparison-002.phpt b/ext/standard/tests/uuid/UUID/comparison-002.phpt new file mode 100644 index 0000000000000..31e136222dbfc --- /dev/null +++ b/ext/standard/tests/uuid/UUID/comparison-002.phpt @@ -0,0 +1,21 @@ +--TEST-- +UUID comparison antisymmetry +--DESCRIPTION-- +if π‘Ž β‰Ό 𝑏 and 𝑏 β‰Ό π‘Ž, then π‘Ž = 𝑏 + +https://en.wikipedia.org/wiki/Antisymmetric_relation +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- + +--EXPECT-- +bool(true) +bool(true) +bool(true) diff --git a/ext/standard/tests/uuid/UUID/comparison-003.phpt b/ext/standard/tests/uuid/UUID/comparison-003.phpt new file mode 100644 index 0000000000000..7e425b28db187 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/comparison-003.phpt @@ -0,0 +1,22 @@ +--TEST-- +UUID comparison transitivity +--DESCRIPTION-- +if π‘Ž β‰Ό 𝑏 and 𝑏 β‰Ό 𝑐, then π‘Ž β‰Ό 𝑐 + +https://en.wikipedia.org/wiki/Transitive_relation +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- + +--EXPECT-- +bool(true) +bool(true) +bool(true) diff --git a/ext/standard/tests/uuid/UUID/comparison-004.phpt b/ext/standard/tests/uuid/UUID/comparison-004.phpt new file mode 100644 index 0000000000000..05eadc9f4237c --- /dev/null +++ b/ext/standard/tests/uuid/UUID/comparison-004.phpt @@ -0,0 +1,36 @@ +--TEST-- +UUID comparison toset +--DESCRIPTION-- +only one of π‘Ž β‰Ί 𝑏, π‘Ž = 𝑏, or π‘Ž ≻ 𝑏 is true + +https://en.wikipedia.org/wiki/Toset +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- + $b) , "\n"; + +$a = UUID::fromBinary("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1"); +$b = UUID::fromBinary("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1"); +echo var_dump($a < $b, $a == $b, $a > $b) , "\n"; + +$a = UUID::fromBinary("\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2"); +$b = UUID::fromBinary("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1"); +echo var_dump($a < $b, $a == $b, $a > $b) , "\n"; + +?> +--EXPECT-- +bool(true) +bool(false) +bool(false) + +bool(false) +bool(true) +bool(false) + +bool(false) +bool(false) +bool(true) diff --git a/ext/standard/tests/uuid/UUID/definition-001.phpt b/ext/standard/tests/uuid/UUID/definition-001.phpt new file mode 100644 index 0000000000000..65a4c9bad2fcc --- /dev/null +++ b/ext/standard/tests/uuid/UUID/definition-001.phpt @@ -0,0 +1,38 @@ +--TEST-- +UUID class definition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getInterfaces() === [], + $c->getParentClass(), + $c->isAbstract(), + $c->isCloneable(), + $c->isFinal(), + $c->isInstantiable(), + $c->isInterface(), + $c->isInternal(), + $c->isIterateable(), + $c->isTrait(), + count($c->getConstants()), + count($c->getProperties()) +); + +?> +--EXPECT-- +bool(true) +bool(false) +bool(false) +bool(false) +bool(true) +bool(false) +bool(false) +bool(true) +bool(false) +bool(false) +int(9) +int(1) diff --git a/ext/standard/tests/uuid/UUID/definition-002.phpt b/ext/standard/tests/uuid/UUID/definition-002.phpt new file mode 100644 index 0000000000000..81545dfa8a0b2 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/definition-002.phpt @@ -0,0 +1,20 @@ +--TEST-- +UUID::VARIANT_* constant definition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- + +--EXPECT-- +int(0) +int(1) +int(2) +int(3) diff --git a/ext/standard/tests/uuid/UUID/definition-003.phpt b/ext/standard/tests/uuid/UUID/definition-003.phpt new file mode 100644 index 0000000000000..f480800bc1958 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/definition-003.phpt @@ -0,0 +1,22 @@ +--TEST-- +UUID::VERSION_* constant definition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- + +--EXPECT-- +int(1) +int(2) +int(3) +int(4) +int(5) diff --git a/ext/standard/tests/uuid/UUID/definition-004.phpt b/ext/standard/tests/uuid/UUID/definition-004.phpt new file mode 100644 index 0000000000000..8ad081d5e9380 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/definition-004.phpt @@ -0,0 +1,15 @@ +--TEST-- +UUID::$binary property definition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +isPrivate(), $p->isStatic()); + +?> +--EXPECT-- +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/fromBinary/basic.phpt b/ext/standard/tests/uuid/UUID/fromBinary/basic.phpt new file mode 100644 index 0000000000000..cf5569364a5e3 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/fromBinary/basic.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUID::fromBinary random data +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +setAccessible(true); +var_dump($p->getValue($uuid) === $bytes); + +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/uuid/UUID/fromBinary/definition-001.phpt b/ext/standard/tests/uuid/UUID/fromBinary/definition-001.phpt new file mode 100644 index 0000000000000..a950e3a9da0a5 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/fromBinary/definition-001.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::fromBinary method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(1) +int(1) +string(4) "UUID" +bool(true) +bool(true) diff --git a/ext/standard/tests/uuid/UUID/fromBinary/definition-002.phpt b/ext/standard/tests/uuid/UUID/fromBinary/definition-002.phpt new file mode 100644 index 0000000000000..1a6cd95ff2eb8 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/fromBinary/definition-002.phpt @@ -0,0 +1,26 @@ +--TEST-- +UUID::fromBinary 1. parameter definition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getParameters()[0]; + +var_dump( + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference(), + $p->isVariadic() +); + +?> +--EXPECT-- +string(5) "input" +bool(false) +string(6) "string" +bool(false) +bool(false) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt b/ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt new file mode 100644 index 0000000000000..ddff22d9923f8 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUID::fromBinary throws ArgumentCountError if no arguments are passed +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage(); +} + +?> +--EXPECT-- +Too few arguments to method UUID::fromBinary(), 0 passed and exactly 1 expected diff --git a/ext/standard/tests/uuid/UUID/fromBinary/error-002.phpt b/ext/standard/tests/uuid/UUID/fromBinary/error-002.phpt new file mode 100644 index 0000000000000..b32b7bd8199a5 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/fromBinary/error-002.phpt @@ -0,0 +1,23 @@ +--TEST-- +UUID::fromBinary boundaries +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage() , "\n"; + } +} + +?> +--EXPECTF-- +Expected exactly 16 bytes, but got 0 +Expected exactly 16 bytes, but got 1 +Expected exactly 16 bytes, but got 15 +Expected exactly 16 bytes, but got 17 +Expected exactly 16 bytes, but got %d diff --git a/ext/standard/tests/uuid/UUID/getVariant/basic.phpt b/ext/standard/tests/uuid/UUID/getVariant/basic.phpt new file mode 100644 index 0000000000000..6749d6bfd1653 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/getVariant/basic.phpt @@ -0,0 +1,20 @@ +--TEST-- +UUID::getVariant +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getVariant(), + UUID::fromBinary("\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00")->getVariant(), + UUID::fromBinary("\x00\x00\x00\x00\x00\x00\x00\x00\xC0\x00\x00\x00\x00\x00\x00\x00")->getVariant(), + UUID::fromBinary("\x00\x00\x00\x00\x00\x00\x00\x00\xE0\x00\x00\x00\x00\x00\x00\x00")->getVariant() +); + +?> +--EXPECT-- +int(0) +int(1) +int(2) +int(3) diff --git a/ext/standard/tests/uuid/UUID/getVariant/definition.phpt b/ext/standard/tests/uuid/UUID/getVariant/definition.phpt new file mode 100644 index 0000000000000..ad311a99098b3 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/getVariant/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::getVariant method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(3) "int" +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/getVariant/variation-001.phpt b/ext/standard/tests/uuid/UUID/getVariant/variation-001.phpt new file mode 100644 index 0000000000000..a5d6497aaa705 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/getVariant/variation-001.phpt @@ -0,0 +1,20 @@ +--TEST-- +UUID::getVariant ignores Msb1 and Msb2 of octet 8 if Msb0 is 0 +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getVariant(), + UUID::fromBinary("\x00\x00\x00\x00\x00\x00\x00\x00\x40\x00\x00\x00\x00\x00\x00\x00")->getVariant(), + UUID::fromBinary("\x00\x00\x00\x00\x00\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00")->getVariant(), + UUID::fromBinary("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")->getVariant() +); + +?> +--EXPECT-- +int(0) +int(0) +int(0) +int(0) diff --git a/ext/standard/tests/uuid/UUID/getVariant/variation-002.phpt b/ext/standard/tests/uuid/UUID/getVariant/variation-002.phpt new file mode 100644 index 0000000000000..57f4a76427c6f --- /dev/null +++ b/ext/standard/tests/uuid/UUID/getVariant/variation-002.phpt @@ -0,0 +1,16 @@ +--TEST-- +UUID::getVariant ignores Msb2 of octet 8 if Msb0 is 1 and Msb1 is 0 +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getVariant(), + UUID::fromBinary("\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00")->getVariant() +); + +?> +--EXPECT-- +int(1) +int(1) diff --git a/ext/standard/tests/uuid/UUID/getVersion/basic.phpt b/ext/standard/tests/uuid/UUID/getVersion/basic.phpt new file mode 100644 index 0000000000000..a20845f5c0d61 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/getVersion/basic.phpt @@ -0,0 +1,29 @@ +--TEST-- +UUID::getVersion +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getVersion()); +} + +?> +--EXPECT-- +int(0) +int(1) +int(2) +int(3) +int(4) +int(5) +int(6) +int(7) +int(8) +int(9) +int(10) +int(11) +int(12) +int(13) +int(14) +int(15) diff --git a/ext/standard/tests/uuid/UUID/getVersion/definition.phpt b/ext/standard/tests/uuid/UUID/getVersion/definition.phpt new file mode 100644 index 0000000000000..209e2be8d35b6 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/getVersion/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::getVersion method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(3) "int" +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/parse/basic-001.phpt b/ext/standard/tests/uuid/UUID/parse/basic-001.phpt new file mode 100644 index 0000000000000..b98450ad0991a --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/basic-001.phpt @@ -0,0 +1,16 @@ +--TEST-- +UUID::parse hexadecimal representation +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +setAccessible(true); +var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); + +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/uuid/UUID/parse/basic-002.phpt b/ext/standard/tests/uuid/UUID/parse/basic-002.phpt new file mode 100644 index 0000000000000..847f87022d128 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/basic-002.phpt @@ -0,0 +1,16 @@ +--TEST-- +UUID::parse string representation +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +setAccessible(true); +var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); + +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/uuid/UUID/parse/basic-003.phpt b/ext/standard/tests/uuid/UUID/parse/basic-003.phpt new file mode 100644 index 0000000000000..3d608aa426623 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/basic-003.phpt @@ -0,0 +1,16 @@ +--TEST-- +UUID::parse URN +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +setAccessible(true); +var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); + +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/uuid/UUID/parse/basic-004.phpt b/ext/standard/tests/uuid/UUID/parse/basic-004.phpt new file mode 100644 index 0000000000000..3b0fd042738ce --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/basic-004.phpt @@ -0,0 +1,16 @@ +--TEST-- +UUID::parse Microsoft +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +setAccessible(true); +var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); + +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/uuid/UUID/parse/definition-001.phpt b/ext/standard/tests/uuid/UUID/parse/definition-001.phpt new file mode 100644 index 0000000000000..91c98db7efec5 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/definition-001.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::parse method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(1) +int(1) +string(4) "UUID" +bool(true) +bool(true) diff --git a/ext/standard/tests/uuid/UUID/parse/definition-002.phpt b/ext/standard/tests/uuid/UUID/parse/definition-002.phpt new file mode 100644 index 0000000000000..0f48d13c630ec --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/definition-002.phpt @@ -0,0 +1,26 @@ +--TEST-- +UUID::parse 1. parameter definition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getParameters()[0]; + +var_dump( + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference(), + $p->isVariadic() +); + +?> +--EXPECT-- +string(5) "input" +bool(false) +string(6) "string" +bool(false) +bool(false) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/parse/error-001.phpt b/ext/standard/tests/uuid/UUID/parse/error-001.phpt new file mode 100644 index 0000000000000..fb93488873b1c --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/error-001.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUID::parse throws ArgumentCountError if no arguments are passed +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage(); +} + +?> +--EXPECT-- +Too few arguments to method UUID::parse(), 0 passed and exactly 1 expected diff --git a/ext/standard/tests/uuid/UUID/parse/error-002.phpt b/ext/standard/tests/uuid/UUID/parse/error-002.phpt new file mode 100644 index 0000000000000..26459970b1596 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/error-002.phpt @@ -0,0 +1,29 @@ +--TEST-- +UUID::parse throws UUIDParsingException if there are less than 32 chars +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage() , "\n"; + } +} + +?> +--EXPECT-- +Expected at least 32 hexadecimal digits, but got 0 +Expected at least 32 hexadecimal digits, but got 1 +Expected at least 32 hexadecimal digits, but got 31 +Expected at least 32 hexadecimal digits, but got 30 +Expected at least 32 hexadecimal digits, but got 30 diff --git a/ext/standard/tests/uuid/UUID/parse/error-003.phpt b/ext/standard/tests/uuid/UUID/parse/error-003.phpt new file mode 100644 index 0000000000000..55bdb339f6751 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/error-003.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUID::parse throws UUIDParsingException for non-hexadecimal characters +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage() , "\n"; +} + +?> +--EXPECT-- +Expected hexadecimal digit, but found 'P' (0x50) diff --git a/ext/standard/tests/uuid/UUID/parse/error-004.phpt b/ext/standard/tests/uuid/UUID/parse/error-004.phpt new file mode 100644 index 0000000000000..0eec3b8e2305a --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/error-004.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUID::parse throws UUIDParsingException if too many hexadecimal digits are found +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage() , "\n"; +} + +?> +--EXPECT-- +Expected no more than 32 hexadecimal digits diff --git a/ext/standard/tests/uuid/UUID/parse/variation-001.phpt b/ext/standard/tests/uuid/UUID/parse/variation-001.phpt new file mode 100644 index 0000000000000..96e53aa485f47 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/variation-001.phpt @@ -0,0 +1,16 @@ +--TEST-- +UUID::parse is case-insensitive +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +setAccessible(true); +var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); + +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/uuid/UUID/parse/variation-002.phpt b/ext/standard/tests/uuid/UUID/parse/variation-002.phpt new file mode 100644 index 0000000000000..3811c97ed0f44 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/variation-002.phpt @@ -0,0 +1,16 @@ +--TEST-- +UUID::parse ignores leading spaces ( ), tabs (\t), and opening braces ({) +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +setAccessible(true); +var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); + +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/uuid/UUID/parse/variation-003.phpt b/ext/standard/tests/uuid/UUID/parse/variation-003.phpt new file mode 100644 index 0000000000000..69fcffbb06d11 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/variation-003.phpt @@ -0,0 +1,16 @@ +--TEST-- +UUID::parse ignores trailing spaces ( ), tabs (\t), and closing braces (}) +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +setAccessible(true); +var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); + +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/uuid/UUID/parse/variation-004.phpt b/ext/standard/tests/uuid/UUID/parse/variation-004.phpt new file mode 100644 index 0000000000000..2e10eaf9f6d25 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/variation-004.phpt @@ -0,0 +1,16 @@ +--TEST-- +UUID::parse ignores hyphens (-) +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +setAccessible(true); +var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); + +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/uuid/UUID/toBinary/basic.phpt b/ext/standard/tests/uuid/UUID/toBinary/basic.phpt new file mode 100644 index 0000000000000..a30d3afc35dce --- /dev/null +++ b/ext/standard/tests/uuid/UUID/toBinary/basic.phpt @@ -0,0 +1,12 @@ +--TEST-- +UUID::toBinary +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +toBinary() === "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F"); + +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/uuid/UUID/toBinary/definition.phpt b/ext/standard/tests/uuid/UUID/toBinary/definition.phpt new file mode 100644 index 0000000000000..22b8841d1dde5 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/toBinary/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::toBinary method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(6) "string" +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/toHex/basic.phpt b/ext/standard/tests/uuid/UUID/toHex/basic.phpt new file mode 100644 index 0000000000000..776468aa6486c --- /dev/null +++ b/ext/standard/tests/uuid/UUID/toHex/basic.phpt @@ -0,0 +1,12 @@ +--TEST-- +UUID::toHex +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +toHex()); + +?> +--EXPECT-- +string(32) "000102030405060708090a0b0c0d0e0f" diff --git a/ext/standard/tests/uuid/UUID/toHex/definition.phpt b/ext/standard/tests/uuid/UUID/toHex/definition.phpt new file mode 100644 index 0000000000000..64fb84407561b --- /dev/null +++ b/ext/standard/tests/uuid/UUID/toHex/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::toHex method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(6) "string" +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/toString/basic.phpt b/ext/standard/tests/uuid/UUID/toString/basic.phpt new file mode 100644 index 0000000000000..186c2c96bf097 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/toString/basic.phpt @@ -0,0 +1,12 @@ +--TEST-- +UUID::toString +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +toString()); + +?> +--EXPECT-- +string(36) "00010203-0405-0607-0809-0a0b0c0d0e0f" diff --git a/ext/standard/tests/uuid/UUID/toString/definition.phpt b/ext/standard/tests/uuid/UUID/toString/definition.phpt new file mode 100644 index 0000000000000..64fb84407561b --- /dev/null +++ b/ext/standard/tests/uuid/UUID/toString/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::toHex method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(6) "string" +bool(true) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/v3/basic.phpt b/ext/standard/tests/uuid/UUID/v3/basic.phpt new file mode 100644 index 0000000000000..5c7a61ce7dacc --- /dev/null +++ b/ext/standard/tests/uuid/UUID/v3/basic.phpt @@ -0,0 +1,12 @@ +--TEST-- +UUID::v3 +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +toString()); + +?> +--EXPECT-- +string(36) "11a38b9a-b3da-360f-9353-a5a725514269" diff --git a/ext/standard/tests/uuid/UUID/v3/definition-001.phpt b/ext/standard/tests/uuid/UUID/v3/definition-001.phpt new file mode 100644 index 0000000000000..62f2a48f0da08 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/v3/definition-001.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::v3 method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(2) +int(2) +string(4) "UUID" +bool(true) +bool(true) diff --git a/ext/standard/tests/uuid/UUID/v3/definition-002.phpt b/ext/standard/tests/uuid/UUID/v3/definition-002.phpt new file mode 100644 index 0000000000000..3886334cb1e7c --- /dev/null +++ b/ext/standard/tests/uuid/UUID/v3/definition-002.phpt @@ -0,0 +1,26 @@ +--TEST-- +UUID::v3 1. parameter definition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getParameters()[0]; + +var_dump( + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference(), + $p->isVariadic() +); + +?> +--EXPECT-- +string(9) "namespace" +bool(false) +string(4) "UUID" +bool(false) +bool(false) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/v3/definition-003.phpt b/ext/standard/tests/uuid/UUID/v3/definition-003.phpt new file mode 100644 index 0000000000000..b62f9fcb87b1a --- /dev/null +++ b/ext/standard/tests/uuid/UUID/v3/definition-003.phpt @@ -0,0 +1,26 @@ +--TEST-- +UUID::v3 2. parameter definition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getParameters()[1]; + +var_dump( + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference(), + $p->isVariadic() +); + +?> +--EXPECT-- +string(4) "name" +bool(false) +string(6) "string" +bool(false) +bool(false) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/v3/error-001.phpt b/ext/standard/tests/uuid/UUID/v3/error-001.phpt new file mode 100644 index 0000000000000..4d78ee9b3c9d2 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/v3/error-001.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUID::v3 throws ArgumentCountError if no arguments are passed +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage(); +} + +?> +--EXPECT-- +Too few arguments to method UUID::v3(), 0 passed and exactly 2 expected diff --git a/ext/standard/tests/uuid/UUID/v3/error-002.phpt b/ext/standard/tests/uuid/UUID/v3/error-002.phpt new file mode 100644 index 0000000000000..c6921cd1e72c9 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/v3/error-002.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUID::v3 throws ArgumentCountError if only one argument is passed +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage(); +} + +?> +--EXPECT-- +Too few arguments to method UUID::v3(), 1 passed and exactly 2 expected diff --git a/ext/standard/tests/uuid/UUID/v4/basic.phpt b/ext/standard/tests/uuid/UUID/v4/basic.phpt new file mode 100644 index 0000000000000..b458e4eca1eb3 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/v4/basic.phpt @@ -0,0 +1,12 @@ +--TEST-- +UUID::v4 +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- + +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/uuid/UUID/v4/definition.phpt b/ext/standard/tests/uuid/UUID/v4/definition.phpt new file mode 100644 index 0000000000000..f9af6e6c54440 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/v4/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::v4 method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(4) "UUID" +bool(true) +bool(true) diff --git a/ext/standard/tests/uuid/UUID/v5/basic.phpt b/ext/standard/tests/uuid/UUID/v5/basic.phpt new file mode 100644 index 0000000000000..10aab673137ca --- /dev/null +++ b/ext/standard/tests/uuid/UUID/v5/basic.phpt @@ -0,0 +1,12 @@ +--TEST-- +UUID::v5 +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +toString()); + +?> +--EXPECT-- +string(36) "c4a760a8-dbcf-5254-a0d9-6a4474bd1b62" diff --git a/ext/standard/tests/uuid/UUID/v5/definition-001.phpt b/ext/standard/tests/uuid/UUID/v5/definition-001.phpt new file mode 100644 index 0000000000000..3d82aaf956ab3 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/v5/definition-001.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::v5 method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(2) +int(2) +string(4) "UUID" +bool(true) +bool(true) diff --git a/ext/standard/tests/uuid/UUID/v5/definition-002.phpt b/ext/standard/tests/uuid/UUID/v5/definition-002.phpt new file mode 100644 index 0000000000000..a64bb54f828be --- /dev/null +++ b/ext/standard/tests/uuid/UUID/v5/definition-002.phpt @@ -0,0 +1,26 @@ +--TEST-- +UUID::v5 1. parameter definition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getParameters()[0]; + +var_dump( + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference(), + $p->isVariadic() +); + +?> +--EXPECT-- +string(9) "namespace" +bool(false) +string(4) "UUID" +bool(false) +bool(false) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/v5/definition-003.phpt b/ext/standard/tests/uuid/UUID/v5/definition-003.phpt new file mode 100644 index 0000000000000..fd843ae0edd47 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/v5/definition-003.phpt @@ -0,0 +1,26 @@ +--TEST-- +UUID::v5 2. parameter definition +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getParameters()[1]; + +var_dump( + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference(), + $p->isVariadic() +); + +?> +--EXPECT-- +string(4) "name" +bool(false) +string(6) "string" +bool(false) +bool(false) +bool(false) diff --git a/ext/standard/tests/uuid/UUID/v5/error-001.phpt b/ext/standard/tests/uuid/UUID/v5/error-001.phpt new file mode 100644 index 0000000000000..167927083e25d --- /dev/null +++ b/ext/standard/tests/uuid/UUID/v5/error-001.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUID::v5 throws ArgumentCountError if no arguments are passed +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage(); +} + +?> +--EXPECT-- +Too few arguments to method UUID::v5(), 0 passed and exactly 2 expected diff --git a/ext/standard/tests/uuid/UUID/v5/error-002.phpt b/ext/standard/tests/uuid/UUID/v5/error-002.phpt new file mode 100644 index 0000000000000..d21b86a32de76 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/v5/error-002.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUID::v5 throws ArgumentCountError if only one argument is passed +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage(); +} + +?> +--EXPECT-- +Too few arguments to method UUID::v5(), 1 passed and exactly 2 expected From 9e0e146b508274ecbe128e59fb6b85c32171d36f Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Tue, 23 May 2017 22:39:27 +0200 Subject: [PATCH 04/54] Added UUIDParsingException stub --- ext/standard/stubs/UUIDParsingException.php | 79 +++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 ext/standard/stubs/UUIDParsingException.php diff --git a/ext/standard/stubs/UUIDParsingException.php b/ext/standard/stubs/UUIDParsingException.php new file mode 100644 index 0000000000000..078ec35801987 --- /dev/null +++ b/ext/standard/stubs/UUIDParsingException.php @@ -0,0 +1,79 @@ +getMessage(); // Expected at least 32 characters, but got 3 characters + * echo $e->getInput(); // php + * echo $e->getPosition(); // 0 + * } + * + * try { + * UUID::parse('12345678-1234-1234-1234-123456789php'); + * } + * catch (UUIDParsingException $e) { + * echo $e->getMessage(); // Expected hexadecimal digit, but found 'p' (0x70) + * echo $e->getInput(); // 12345678-1234-1234-1234-123456789php + * echo $e->getPosition(); // 33 + * } + * + * try { + * UUID::parse('12345678-1234-1234-1234-123456789abcdef'); + * } + * catch (UUIDParsingException $e) { + * echo $e->getMessage(); // Expected no more than 32 hexadecimal digits + * echo $e->getInput(); // 12345678-1234-1234-1234-123456789abcdef + * echo $e->getPosition(); // 37 + * } + * + * ?> + * ``` + * + * @see \UUID::parse() + */ +final class UUIDParsingException extends Exception { + /** @var string */ + private $input; + + /** @var int */ + private $position; + + /** + * Construct new UUID parsing exception instance. + * + * @param string $reason why parsing the UUID string failed. + * @param string $input that should be parsed. + * @param int $position at which parsing failed. + * @param Throwable|null $previous error/exception that lead to this + * failure, if any. + */ + public function __construct(string $reason, string $input, int $position = 0, ?Throwable $previous = null) { } + + /** + * Get the original input string that should have been parsed as a UUID. + * + * @return string + */ + public function getInput(): string { } + + /** + * Get the position in the input string where the parsing failure occurred. + * + * @return int + */ + public function getPosition(): int { } +} From 1fde9141be823ca826b746b3a7939f75071c71c4 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Tue, 23 May 2017 23:44:17 +0200 Subject: [PATCH 05/54] Added extended garbage test case --- .../tests/uuid/UUID/parse/variation-005.phpt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 ext/standard/tests/uuid/UUID/parse/variation-005.phpt diff --git a/ext/standard/tests/uuid/UUID/parse/variation-005.phpt b/ext/standard/tests/uuid/UUID/parse/variation-005.phpt new file mode 100644 index 0000000000000..7596bbf9793bc --- /dev/null +++ b/ext/standard/tests/uuid/UUID/parse/variation-005.phpt @@ -0,0 +1,16 @@ +--TEST-- +UUID::parse accepts URN even with leading and trailing whitespace/braces and extraneous hyphens everywhere +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +setAccessible(true); +var_dump($p->getValue($uuid) === "\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef"); + +?> +--EXPECT-- +bool(true) From 9c416eb2f342a07dcdd2f9cab4d843256f9aab0e Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 24 May 2017 00:31:48 +0200 Subject: [PATCH 06/54] Added sorting test case --- ext/standard/tests/uuid/UUID/sorting.phpt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 ext/standard/tests/uuid/UUID/sorting.phpt diff --git a/ext/standard/tests/uuid/UUID/sorting.phpt b/ext/standard/tests/uuid/UUID/sorting.phpt new file mode 100644 index 0000000000000..5c692c2ae6637 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/sorting.phpt @@ -0,0 +1,18 @@ +--TEST-- +UUID sorting +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- + +--EXPECT-- +bool(true) From 72dc6f8ed94295e8b78faf41b27cb3d11ceafb35 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 24 May 2017 01:21:39 +0200 Subject: [PATCH 07/54] Added UUID stub --- ext/standard/stubs/UUID.php | 668 ++++++++++++++++++++++++++++++++++++ 1 file changed, 668 insertions(+) create mode 100644 ext/standard/stubs/UUID.php diff --git a/ext/standard/stubs/UUID.php b/ext/standard/stubs/UUID.php new file mode 100644 index 0000000000000..ac9e859a75ca4 --- /dev/null +++ b/ext/standard/stubs/UUID.php @@ -0,0 +1,668 @@ +isNil()); + * assert($uuid->getVariant() === 0); + * assert($uuid->getVersion() === 0); + * + * $uuid = UUID::v3(UUID::NamespaceDNS(), 'php.net'); + * assert($uuid->isNil() === false); + * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); + * assert($uuid->getVersion() === UUID::VERSION_3_NAME_BASED_MD5); + * + * $uuid = UUID::v4(); + * assert($uuid->isNil() === false); + * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); + * assert($uuid->getVersion() === UUID::VERSION_4_RANDOM); + * + * $uuid = UUID::v5(UUID::NamespaceDNS(), 'php.net'); + * assert($uuid->isNil() === false); + * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); + * assert($uuid->getVersion() === UUID::VERSION_5_NAME_BASED_SHA1); + * + * $uuid = UUID::parse('urn:uuid:123E4567-E89B-12D3-A456-426655440000'); + * assert($uuid->isNil() === false); + * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); + * assert($uuid->getVersion() === UUID::VERSION_1_TIME_BASED); + * + * assert($uuid->toBinary() === "\x12\x3E\x45\x67\xE8\x9B\x12\xD3\xA4\x56\x42\x66\x55\x44\x00\x00"); + * assert($uuid->toHex() === '123e4567e89b12d3a456426655440000'); + * assert($uuid->toString() === '123e4567-e89b-12d3-a456-426655440000'); + * + * ?> + * ``` + * + * Comparison of UUIDs is possible with the default comparison operators of + * PHP. + * + * ``` + * + * ``` + * + * @since 7.2 + * @see https://php.net/uuid + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier + * @see https://tools.ietf.org/html/rfc4122 + */ +final class UUID { + /** + * Code for the (reserved) NCS variant of UUIDs. + * + * @since 7.2 + * @see https://tools.ietf.org/html/rfc4122#section-4.1.1 + */ + public const VARIANT_NCS = 0; + + /** + * Code for the RFC 4122 variant of UUIDs. + * + * This implementation generates UUIDs of this variant only. + * + * @since 7.2 + * @see https://tools.ietf.org/html/rfc4122#section-4.1.1 + */ + public const VARIANT_RFC4122 = 1; + + /** + * Code for the (reserved) Microsoft variant of UUIDs, the GUIDs. + * + * @since 7.2 + * @see https://tools.ietf.org/html/rfc4122#section-4.1.1 + */ + public const VARIANT_MICROSOFT = 2; + + /** + * Version code for the future reserved variant of UUIDs. + * + * @since 7.2 + * @see https://tools.ietf.org/html/rfc4122#section-4.1.1 + */ + public const VARIANT_FUTURE_RESERVED = 4; + + /** + * Version code for date-time and IEEE 802 MAC address UUIDs. + * + * Generation of this version is not supported by this implementation due + * to security concerns. Version 4 UUIDs are a good replacement for version + * 1 UUIDs without the privacy/security concerns (see Wikipedia). + * + * @since 7.2 + * @see https://tools.ietf.org/html/rfc4122#section-4.2 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_.28date-time_and_MAC_address.29 + */ + public const VERSION_1_TIME_BASED = 1; + + /** + * Version code for date-time and IEEE 802 MAC address UUIDs (DCE security + * algorithm). + * + * Generation of this version is not supported by this implementation due + * to security concerns, and uniqueness limitations for applications with + * high allocations. Version 4 UUIDs are a good replacement for version 2 + * UUIDs without the privacy/security concerns (see Wikipedia), and they + * support high allocations. + * + * @since 7.2 + * @see https://tools.ietf.org/html/rfc4122#section-4.2 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_2_.28date-time_and_MAC_Address.2C_DCE_security_version.29 + */ + public const VERSION_2_DCE_SECURITY = 2; + + /** + * Version code for namespace/name-based MD5 hashed UUIDs. + * + * @since 7.2 + * @see v3 + * @see https://tools.ietf.org/html/rfc4122#section-4.3 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 + */ + public const VERSION_3_NAME_BASED_MD5 = 3; + + /** + * Version code for random UUIDs. + * + * @since 7.2 + * @see v4 + * @see https://tools.ietf.org/html/rfc4122#section-4.4 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 + */ + public const VERSION_4_RANDOM = 4; + + /** + * Version code for namespace/name-based SHA1 hashed UUIDs. + * + * @since 7.2 + * @see v5 + * @see https://tools.ietf.org/html/rfc4122#section-4.3 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 + */ + public const VERSION_5_NAME_BASED_SHA1 = 5; + + /** + * This UUID's 128 bit integer value as 16 byte binary string. + * + * @since 7.2 + * @see toBinary + * @var string + */ + private $binary; + + /** + * Use {@see fromBinary} or {@see parse} to construct a new instance. + */ + private function __construct() { } + + /** + * Construct new UUID instance from binary string of exactly 16 bytes. + * + * Any string of 16 bytes is accepted by this named constructor. This + * enables the construction of UUIDs of any variant and version, regardless + * of the {@see parse} implementation. + * + * ## Examples + * ``` + * getVariant() === UUID::VARIANT_FUTURE_RESERVED); + * + * ?> + * ``` + * + * @since 7.2 + * @see https://php.net/uuid.fromBinary + * @see toBinary + * @param string $input string of exactly 16 bytes to construct the + * instance from. + * @return UUID instance constructed from the input. + * @throws \InvalidArgumentException if the input is not exactly 16 bytes + * long. + */ + public static function fromBinary(string $input): UUID { } + + /** + * Parse the given string as UUID. + * + * The following UUID representations are parsable: + * + * - hexadecimal representations (`aaaaaaaabbbbccccddddeeeeeeeeeeeee`), + * - string representations (`aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), + * - URNs (`urn:uuid:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), and + * - Microsoft representations (`{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee}`). + * + * Leading and trailing whitespace, namely spaces (` `) and tabs (`\t`), is + * ignored, so are leading opening braces (`{`) and trailing closing braces + * (`}`). Hyphens (`-`) are ignored everywhere. The parsing algorithm + * follows the [robustness + * principle](https://en.wikipedia.org/wiki/Robustness_principle) and is + * not meant for validation. + * + * ## Examples + * ``` + * getMessage() === 'Expected hexadecimal digit, but found + * '{' (0x7b)'); + * } + * + * ?> + * ``` + * + * @since 7.2 + * @see https://php.net/uuid.parse + * @see toHex + * @see toString + * @param string $input to parse as UUID and construct the instance from. + * @return UUID constructed from the parsed input. + * @throws UUIDParsingException if parsing of the input fails. + */ + public static function parse(string $input): UUID { } + + /** + * Construct new version 3 UUID. + * + * > RFC 4122 recommends {@see v5} over this one and states that version 3 + * > UUIDs should be used if backwards compatibility is required only. This + * > is because MD5 has a higher collision probability compared to SHA1, + * > which is used by version 5; regardless of the truncation! + * + * Version 3 UUIDs are generated by MD5 hashing the concatenated + * namespace's byte representation and the given name. The namespace itself + * must be another UUID. This can be any UUID, or one of the predefined + * ones: + * + * - {@see NamespaceDNS} + * - {@see NamespaceOID} + * - {@see NamespaceURL} + * - {@see NamespaceX500} + * + * A particular name within the same namespace always results in the same + * version 3 UUID, across all RFC 4122 compliant UUID implementations. + * However, the namespace and name cannot be determined from the UUID + * alone. + * + * ## Examples + * ``` + * isNil() === false); + * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); + * assert($uuid->getVersion() === UUID::VERSION_3_NAME_BASED_MD5); + * assert($uuid->toString() === '11a38b9a-b3da-360f-9353-a5a725514269'); + * assert($uuid == UUID::v3(UUID::NamespaceDNS(), 'php.net')); + * + * ?> + * ``` + * + * @since 7.2 + * @see https://php.net/uuid.v3 + * @see https://tools.ietf.org/html/rfc4122#section-4.3 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 + * @param UUID $namespace to construct the UUID in. + * @param string $name to construct the UUID from. + * @return UUID + */ + public static function v3(UUID $namespace, string $name): UUID { } + + /** + * Construct new version 4 UUID. + * + * Version 4 UUIDs are randomly generated from the best available random + * source. The selection of that source is determined by PHP's + * {@see random_bytes} implementation. Some systems may be bad at + * generating sufficient entropy, e.g. virtual machines. This might lead to + * collisions faster than desired. If this is the case, the {@see v5} + * version should be used. + * + * ## Examples + * ``` + * isNil() === false); + * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); + * assert($uuid->getVersion() === UUID::VERSION_4_RANDOM); + * assert($uuid != UUID::v4()); + * + * ?> + * ``` + * + * @since 7.2 + * @see https://php.net/uuid.v4 + * @see https://tools.ietf.org/html/rfc4122#section-4.4 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 + * @return UUID + * @throws Exception if it was not possible to gather sufficient entropy. + */ + public static function v4(): UUID { } + + /** + * Construct new version 5 UUID. + * + * Version 5 UUIDs are generated by MD5 hashing the concatenated + * namespace's byte representation and the given name. The namespace itself + * must be another UUID. This can be any UUID, or one of the predefined + * ones: + * + * - {@see NamespaceDNS} + * - {@see NamespaceOID} + * - {@see NamespaceURL} + * - {@see NamespaceX500} + * + * A particular name within the same namespace always results in the same + * version 5 UUID, across all RFC 4122 compliant UUID implementations. + * However, the namespace and name cannot be determined from the UUID + * alone. + * + * ## Examples + * ``` + * isNil() === false); + * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); + * assert($uuid->getVersion() === UUID::VERSION_5_NAME_BASED_SHA1); + * assert($uuid->toString() === 'c4a760a8-dbcf-5254-a0d9-6a4474bd1b62'); + * assert($uuid == UUID::v5(UUID::NamespaceDNS(), 'php.net')); + * + * ?> + * ``` + * + * @since 7.2 + * @see https://php.net/uuid.v5 + * @see @see https://tools.ietf.org/html/rfc4122#section-4.3 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 + * @param UUID $namespace to construct the UUID in. + * @param string $name to construct the UUID from. + * @return UUID + */ + public static function v5(UUID $namespace, string $name): UUID { } + + /** + * Construct new Domain Name System (DNS) namespace UUID instance. + * + * @since 7.2 + * @see https://php.net/uuid.NamespaceDNS + * @see https://tools.ietf.org/html/rfc4122#appendix-C + * @see https://en.wikipedia.org/wiki/Domain_Name_System + * @return UUID + */ + public static function NamespaceDNS(): UUID { } + + /** + * Construct new Object Identifier (OID) namespace UUID instance. + * + * @since 7.2 + * @see https://php.net/uuid.NamespaceOID + * @see https://tools.ietf.org/html/rfc4122#appendix-C + * @see https://en.wikipedia.org/wiki/Object_identifier + * @return UUID + */ + public static function NamespaceOID(): UUID { } + + /** + * Construct new Uniform Resource Locator (URL) namespace UUID instance. + * + * @since 7.2 + * @see https://php.net/uuid.NamespaceURL + * @see https://tools.ietf.org/html/rfc4122#appendix-C + * @see https://en.wikipedia.org/wiki/URL + * @return UUID + */ + public static function NamespaceURL(): UUID { } + + /** + * Construct new X.500 Distinguished Names (X.500 DN) namespace UUID + * instance. The names that are to be hashed in this namespace can be in + * DER or a text output format. + * + * @since 7.2 + * @see https://php.net/uuid.NamespaceX500 + * @see https://tools.ietf.org/html/rfc4122#appendix-C + * @see https://en.wikipedia.org/wiki/X.500 + * @see https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol + * @return UUID + */ + public static function NamespaceX500(): UUID { } + + /** + * Construct special nil UUID that has all 128 bits set to zero. + * + * @since 7.2 + * @see https://php.net/uuid.Nil + * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID + * @return UUID + */ + public static function Nil(): UUID { } + + /** + * Callback for dynamic adding of properties which throws an {@see Error} + * upon every invocation, direct or indirect. This is necessary to protect + * the promised immutability of this object. Not doing so could lead to + * problems with the comparison operators, since PHP always compares all + * properties. + * + * @since 7.2 + * @see https://php.net/uuid.__set + * @param mixed $_ + * @param mixed $__ + * @return void + * @throws Error upon every invocation, direct or indirect. + */ + public function __set($_, $__): void { } + + /** + * Deserialization callback. + * + * @since 7.2 + * @see https://php.net/uuid.__wakeup + * @see unserialize() + * @return void + * @throws \UnexpectedValueException if the binary string is not exactly 16 + * bytes long. + */ + public function __wakeup(): void { } + + /** + * Get the variant associated with this UUID. + * + * The variant specifies the internal data layout of a UUID. This + * implementation generates {@see UUID::VARIANT_RFC4122} UUIDs only, + * however, parsing and construction of other variants is supported. + * + * @since 7.2 + * @see https://php.net/uuid.getVariant + * @see https://tools.ietf.org/html/rfc4122#section-4.1.1 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Variants + * @see UUID::VARIANT_NCS + * @see UUID::VARIANT_RFC4122 + * @see UUID::VARIANT_MICROSOFT + * @see UUID::VARIANT_FUTURE_RESERVED + * @returns int An integer in [0, 3] where each value corresponds to one of + * the `UUID::VARIANT_*` class constants. + */ + public function getVariant(): int { } + + /** + * Get the version associated with this UUID. + * + * The version specifies which algorithm was used to generate the UUID. + * Note that the version might not be meaningful if another variant than + * the {@see UUID::VARIANT_RFC4122} was used to generate the UUID. This + * implementation generates {@see UUID::VARIANT_RFC4122} UUIDs only, but + * allows parsing and construction of other variants. + * + * @since 7.2 + * @see https://php.net/uuid.getVersion + * @see https://tools.ietf.org/html/rfc4122#section-4.1.3 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions + * @see UUID::VERSION_1_TIME_BASED + * @see UUID::VERSION_2_DCE_SECURITY + * @see UUID::VERSION_3_NAME_BASED_MD5 + * @see UUID::VERSION_4_RANDOM + * @see UUID::VERSION_5_NAME_BASED_SHA1 + * @return int An integer in [0, 15], the values [1, 5] correspond to one + * of the `UUID::VERSION_*` class constants. The others are not defined + * in RFC 4122. + */ + public function getVersion(): int { } + + /** + * Check if this UUID is the special nil UUID that has all 128 bits set to + * zero. + * + * @since 7.2 + * @see https://php.net/uuid.isNil + * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID + * @see Nil + * @return bool **TRUE** if this is the special nil UUID; **FALSE** + * otherwise. + */ + public function isNil(): bool { } + + /** + * Convert the UUID to its binary representation. + * + * The binary representation of a UUID is a string of exactly 16 bytes. It + * is the format that is used internally. It is also the format that should + * be used to store UUIDs in a database (e.g. in MySQL as `BINARY(16)` + * column). The resulting string, if generated by this implementation, is + * always in network byte order. + * + * ## Examples + * ``` + * toBinary() === "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"); + * + * ?> + * ``` + * + * @since 7.2 + * @see https://php.net/uuid.toBinary + * @return string + */ + public function toBinary(): string { } + + /** + * Convert the UUID to its hexadecimal representation. + * + * The hexadecimal representation of a UUID are 32 hexadecimal digits. The + * hexadecimal digits `a` through `f` are always formatted as lower case + * characters, in accordance with RFC 4122. + * + * ## Examples + * ``` + * toHex() === '6ba7b8109dad11d180b400c04fd430c8'); + * + * ?> + * ``` + * + * @since 7.2 + * @see https://php.net/uuid.toHex + * @return string + */ + public function toHex(): string { } + + /** + * Convert the UUID to its string representation. + * + * The string representation of a UUID are 32 hexadecimal digits separated + * by a hyphen into five groups of 8, 4, 4, 4, and 12 digits. The + * hexadecimal digits `a` through `f` are always formatted as lower case + * characters, in accordance with RFC 4122. + * + * ## Examples + * ``` + * toString() === '6ba7b810-9dad-11d1-80b4-00c04fd430c8'); + * + * ?> + * ``` + * + * @since 7.2 + * @see https://php.net/uuid.toString + * @see https://tools.ietf.org/html/rfc4122#page-4 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Format + * @return string + */ + public function toString(): string { } + + /** + * Callback for cloning of objects. This method is private and effectively + * disables cloning of this object, since it makes no sense to clone + * immutable objects. + * + * @return void + */ + private function __clone() { } +} From 7743aa0202f7e4a9e02ebbef5e35d4ac6d8f06d7 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 24 May 2017 01:24:03 +0200 Subject: [PATCH 08/54] Implemented UUID and UUIDParsingException --- ext/standard/basic_functions.c | 5 +- ext/standard/config.m4 | 2 +- ext/standard/config.w32 | 2 +- ext/standard/php_standard.h | 3 +- ext/standard/php_uuid.h | 598 ++++++++++++++++++++++++++++++ ext/standard/uuid.c | 646 +++++++++++++++++++++++++++++++++ 6 files changed, 1251 insertions(+), 5 deletions(-) create mode 100644 ext/standard/php_uuid.h create mode 100644 ext/standard/uuid.c diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 56131e72ea4df..f86e1fae966bc 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1,4 +1,4 @@ -/* +ο»Ώ/* +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ @@ -3707,6 +3707,7 @@ PHP_MINIT_FUNCTION(basic) /* {{{ */ #endif BASIC_MINIT_SUBMODULE(random) + BASIC_MINIT_SUBMODULE(uuid) return SUCCESS; } @@ -4040,7 +4041,7 @@ PHP_FUNCTION(long2ip) ********************/ /* {{{ proto string getenv(string varname[, bool local_only] - Get the value of an environment variable or every available environment variable + Get the value of an environment variable or every available environment variable if no varname is present */ PHP_FUNCTION(getenv) { diff --git a/ext/standard/config.m4 b/ext/standard/config.m4 index 284e74e967ea7..b60f1a2b8ccaa 100644 --- a/ext/standard/config.m4 +++ b/ext/standard/config.m4 @@ -455,7 +455,7 @@ PHP_NEW_EXTENSION(standard, array.c base64.c basic_functions.c browscap.c crc32. http_fopen_wrapper.c php_fopen_wrapper.c credits.c css.c \ var_unserializer.c ftok.c sha1.c user_filters.c uuencode.c \ filters.c proc_open.c streamsfuncs.c http.c password.c \ - random.c,,, + random.c uuid.c,,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1) PHP_ADD_MAKEFILE_FRAGMENT diff --git a/ext/standard/config.w32 b/ext/standard/config.w32 index 00b2166abe876..11d6941a1f478 100644 --- a/ext/standard/config.w32 +++ b/ext/standard/config.w32 @@ -31,7 +31,7 @@ EXTENSION("standard", "array.c base64.c basic_functions.c browscap.c \ url_scanner_ex.c ftp_fopen_wrapper.c http_fopen_wrapper.c \ php_fopen_wrapper.c credits.c css.c var_unserializer.c ftok.c sha1.c \ user_filters.c uuencode.c filters.c proc_open.c password.c \ - streamsfuncs.c http.c flock_compat.c random.c", false /* never shared */, + streamsfuncs.c http.c flock_compat.c random.c uuid.c", false /* never shared */, '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'); PHP_INSTALL_HEADERS("", "ext/standard"); if (PHP_MBREGEX != "no") { diff --git a/ext/standard/php_standard.h b/ext/standard/php_standard.h index 5b0111f143c31..06f63e1dfc8ef 100644 --- a/ext/standard/php_standard.h +++ b/ext/standard/php_standard.h @@ -1,4 +1,4 @@ -/* +ο»Ώ/* +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ @@ -60,6 +60,7 @@ #include "php_type.h" #include "php_password.h" #include "php_random.h" +#include "php_uuid.h" #include "php_version.h" #define PHP_STANDARD_VERSION PHP_VERSION diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h new file mode 100644 index 0000000000000..252c9480a752f --- /dev/null +++ b/ext/standard/php_uuid.h @@ -0,0 +1,598 @@ +ο»Ώ/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2017 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Richard Fussenegger | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +/** + * Generate and parse RFC 4122/DCE 1.1 Universally Unique Identifiers (UUIDs). + * + * This standard submodule provides generation and parsing capabilities for + * Universally Unique Identifiers (UUIDs, also known as Globally Unique + * Identifiers [GUIDs]) as specified in RFC 4122. + * + * UUIDs are 128 bit integers that guarantee uniqueness across space and time. + * They are mainly used to assign identifiers to entities without requiring a + * central authority. They are thus particularly useful in distributed systems. + * They also allow very high allocation rates; up to 10 million per second per + * machine, if necessary. + * + * There are different types of UUIDs, known as variants. This implementation + * generates UUIDs according to the Leach-Salz variant; the one specified in + * RFC 4122 as variant 1. Textual parsing supports both variant 1 (RFC 4122) + * and variant 2 (Microsoft), and construction supports any kind of UUID. + * However, note that the provided functions are **not** guaranteed to provide + * meaningful results if any other variants than the Leach-Salz one is used. + * + * There are also different UUID generation algorithms, known as versions. This + * implementation provides functions to generate version 3, 4, and 5 UUIDs. + * + * Versions 3 and 5 are meant for generating UUIDs from "names" that are drawn + * from, and unique within, some "namespace". They generate the same UUID for + * the same name in the same namespace across all RFC 4122 compliant + * implementations. + * + * Version 4 UUIDs are random and result in a new UUID upon every generation. + * The randomness is provided by PHP's random bytes implementation, and thus + * uses the best available random source of the operating system. + * + * Versions 1 and 2 are not supported due to privacy/security concerns. Refer + * to the Wikipedia article for more information. + * + * This implementation is inspired by many other implementations: + * - [RFC 4122 Sample Implementation](https://tools.ietf.org/html/rfc4122#appendix-A) + * - [Rust UUID](https://github.com/rust-lang-nursery/uuid) + * - [util-linux LibUUID](https://github.com/karelzak/util-linux) + * - [boost Uuid](http://www.boost.org/doc/libs/1_64_0/libs/uuid/) + * - [D std.uuid](https://dlang.org/library/std/uuid.html) + * + * ## Examples + * ``` + * php_uuid uuid; + * + * // A random UUID with more randomness than the version 4 implementation. + * // This should NOT be used in real-world applications! + * php_random_bytes_silent(&uuid, PHP_UUID_LEN); + * php_uuid_set_variant(&uuid, PHP_UUID_VARIANT_FUTURE_RESERVED); + * + * php_uuid_create_v3(&uuid, &PHP_UUID_NAMESPACE_DNS, "php.net", sizeof("php.net") - 1); + * assert(php_uuid_is_nil(uuid) == FALSE); + * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); + * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_3_NAME_BASED_MD5); + * + * php_uuid_create_v4_silent(&uuid); + * assert(php_uuid_is_nil(uuid) == FALSE); + * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); + * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_4_RANDOM); + * + * php_uuid_create_v5(&uuid, &PHP_UUID_NAMESPACE_DNS, "php.net", sizeof("php.net") - 1); + * assert(php_uuid_is_nil(uuid) == FALSE); + * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); + * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_5_NAME_BASED_SHA1); + * + * php_uuid_parse_silent(&uuid, "urn:uuid:123E4567-E89B-12D3-A456-426655440000", sizeof("urn:uuid:123E4567-E89b-12D3-A456-426655440000") - 1); + * assert(php_uuid_is_nil(uuid) == FALSE); + * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); + * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_1_TIME_BASED); + * + * assert(memcmp(&uuid, "\x12\x3E\x45\x67\xE8\x9B\x12\xD3\xA4\x56\x42\x66\x55\x44\x00\x00", PHP_UUID_LEN) == 0); + * + * php_uuid_hex hex; + * php_uuid_to_hex(&hex, uuid); + * assert(memcmp(&hex, "123e4567e89b12d3a456426655440000", PHP_UUID_HEX_LEN) == 0); + * + * php_uuid_string str; + * php_uuid_to_string(&str, uuid); + * assert(memcmp(&str, "123e4567-e89b-12d3-a456-426655440000", PHP_UUID_STRING_LEN) == 0); + * ``` + * + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier + * @see https://tools.ietf.org/html/rfc4122 + */ + +#ifndef PHP_UUID_H +#define PHP_UUID_H + +#include "zend_types.h" +#include "php.h" + +/** UUID class entry for usage by other modules. */ +PHPAPI extern zend_class_entry *php_ce_UUID; + +/** UUIDParsingException class entry for usage by other modules. */ +PHPAPI extern zend_class_entry *php_ce_UUIDParsingException; + +/** UUID binary representation to store the 128 bit number in 16 bytes. */ +PHPAPI typedef uint8_t php_uuid[16]; + +/** UUID hexadecimal representation: `000000001111222233334444444444444444\0` */ +PHPAPI typedef char php_uuid_hex[33]; + +/** UUID string representation: `00000000-1111-2222-3333-4444444444444444\0` */ +PHPAPI typedef char php_uuid_string[37]; + +/** UUID representation lengths (without terminating NUL character). */ +PHPAPI extern const uint8_t PHP_UUID_LEN; +PHPAPI extern const uint8_t PHP_UUID_HEX_LEN; +PHPAPI extern const uint8_t PHP_UUID_STRING_LEN; + +/** + * Domain Name System (DNS) namespace UUID. + * + * @see https://tools.ietf.org/html/rfc4122#appendix-C + * @see https://en.wikipedia.org/wiki/Domain_Name_System + */ +PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_DNS; + +/** +* Object Identifier (OID) namespace UUID. +* + * @see https://tools.ietf.org/html/rfc4122#appendix-C + * @see https://en.wikipedia.org/wiki/Object_identifier + */ +PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_OID; + +/** + * Uniform Resource Locator (URL) namespace UUID. + * + * @see https://tools.ietf.org/html/rfc4122#appendix-C + * @see https://en.wikipedia.org/wiki/URL + */ +PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_URL; + +/** + * X.500 Distinguished Names (X.500 DN) namespace UUID. The names that are to + * be hashed in this namespace can be in DER or a text output format. + * + * @see https://tools.ietf.org/html/rfc4122#appendix-C + * @see https://en.wikipedia.org/wiki/X.500 + * @see https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol + */ +PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_X500; + +/** + * Special nil UUID that has all 128 bits set to zero. + * + * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID + */ +PHPAPI extern const php_uuid PHP_UUID_NIL; + +/** + * UUID variants as defined in RFC 4122. + * + * @see https://tools.ietf.org/html/rfc4122#section-4.1.1 + */ +PHPAPI typedef enum php_uuid_variant { + PHP_UUID_VARIANT_NCS = 0, /* 0b0xx */ + PHP_UUID_VARIANT_RFC4122 = 1, /* 0b10x */ + PHP_UUID_VARIANT_MICROSOFT = 2, /* 0b110 */ + PHP_UUID_VARIANT_FUTURE_RESERVED = 3, /* 0b111 */ +} php_uuid_variant; + +/** + * Version code for date-time and IEEE 802 MAC address UUIDs. + * + * Generation of this version is not supported by this implementation due + * to security concerns. Version 4 UUIDs are a good replacement for version + * 1 UUIDs without the privacy/security concerns (see Wikipedia). + * + * @see https://tools.ietf.org/html/rfc4122#section-4.2 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_.28date-time_and_MAC_address.29 + */ +PHPAPI extern const uint8_t PHP_UUID_VERSION_1_TIME_BASED; + +/** + * Version code for date-time and IEEE 802 MAC address UUIDs (DCE security + * algorithm). + * + * Generation of this version is not supported by this implementation due + * to security concerns, and uniqueness limitations for applications with + * high allocations. Version 4 UUIDs are a good replacement for version 2 + * UUIDs without the privacy/security concerns (see Wikipedia), and they + * support high allocations. + * + * @see https://tools.ietf.org/html/rfc4122#section-4.2 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_2_.28date-time_and_MAC_Address.2C_DCE_security_version.29 + */ +PHPAPI extern const uint8_t PHP_UUID_VERSION_2_DCE_SECURITY; + +/** + * Version code for namespace/name-based MD5 hashed UUIDs. + * + * @see php_uuid_create_v3 + * @see https://tools.ietf.org/html/rfc4122#section-4.3 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 + */ +PHPAPI extern const uint8_t PHP_UUID_VERSION_3_NAME_BASED_MD5; + +/** + * Version code for random UUIDs. + * + * @see php_uuid_create_v4 + * @see https://tools.ietf.org/html/rfc4122#section-4.4 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 + */ +PHPAPI extern const uint8_t PHP_UUID_VERSION_4_RANDOM; + +/** + * Version code for namespace/name-based SHA1 hashed UUIDs. + * + * @see php_uuid_create_v5 + * @see https://tools.ietf.org/html/rfc4122#section-4.3 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 + */ +PHPAPI extern const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1; + +/** + * Parse the given string as UUID. + * + * The following UUID representations are parsable: + * + * - hexadecimal representations (`aaaaaaaabbbbccccddddeeeeeeeeeeeee`), + * - string representations (`aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), + * - URNs (`urn:uuid:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), and + * - Microsoft representations (`{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee}`). + * + * Leading and trailing whitespace, namely spaces (` `) and tabs (`\t`), is + * ignored, so are leading opening braces (`{`) and trailing closing braces + * (`}`). Hyphens (`-`) are ignored everywhere. The parsing algorithm + * follows the [robustness + * principle](https://en.wikipedia.org/wiki/Robustness_principle) and is + * not meant for validation. + * + * ## Examples + * ``` + * php_uuid uuid; + * + * // Parsing of canonical representations. + * php_uuid_parse_silent(&uuid, "0123456789abcdef0123456789abcdef", sizeof("0123456789abcdef0123456789abcdef") - 1); + * php_uuid_parse_silent(&uuid, "01234567-89ab-cdef-0123-456789abcdef", sizeof("01234567-89ab-cdef-0123-456789abcdef") - 1); + * php_uuid_parse_silent(&uuid, "urn:uuid:01234567-89ab-cdef-0123-456789abcdef", sizeof("urn:uuid:01234567-89ab-cdef-0123-456789abcdef") - 1); + * php_uuid_parse_silent(&uuid, "{01234567-89ab-cdef-0123-456789abcdef}", sizeof("{01234567-89ab-cdef-0123-456789abcdef}") - 1); + * + * // Leading and trailing gargabe is ignored, so are extraneous hyphens. + * php_uuid_parse_silent(&uuid, " \t ---- { urn:uuid:----0123-4567-89ab-cdef-0123-4567-89ab-cdef---- } ---- \t ", sizeof(" \t ---- { urn:uuid:----0123-4567-89ab-cdef-0123-4567-89ab-cdef---- } ---- \t ") - 1); + * + * // However, note that there cannot be whitespace or braces between the URN + * // scheme and the UUID itself. + * assert(php_uuid_parse_silent( + * &uuid, + * "urn:uuid:{01234567-89ab-cdef-0123-456789abcdef", + * sizeof("urn:uuid:{01234567-89ab-cdef-0123-456789abcdef") - 1 + * ) == FAILURE); + * ``` + * + * @see php_uuid_parse_silent + * @see php_uuid_parse_throw + * @param[out] uuid to store the result in. + * @param[in] input to parse as UUID. + * @param[in] input_len + * @param[in] throw whether to throw PHP exceptions (`TRUE`), or not (`FALSE`). + * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. + */ +PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_len, const zend_bool throw); + +/** + * Silently parse the string as UUID. + * + * @see php_uuid_parse + * @param[out] uuid to store the result in. + * @param[in] input to parse as UUID. + * @param[in] input_len + * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. + */ +#define php_uuid_parse_silent(uuid, input, input_len) php_uuid_parse(uuid, input, input_len, FALSE) + +/** + * Parse the string as UUID and throw PHP exceptions on failures. + * + * @see php_uuid_parse + * @param[out] uuid to store the result in. + * @param[in] input to parse as UUID. + * @param[in] input_len + * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. + */ +#define php_uuid_parse_throw(uuid, input, input_len) php_uuid_parse(uuid, input, input_len, TRUE) + +/** + * Create version 3 UUID. + * + * > RFC 4122 recommends {@see v5} over this one and states that version 3 + * > UUIDs should be used if backwards compatibility is required only. This + * > is because MD5 has a higher collision probability compared to SHA1, + * > which is used by version 5; regardless of the truncation! + * + * Version 3 UUIDs are generated by MD5 hashing the concatenated namespace's + * byte representation and the given name. The namespace itself must be + * another UUID. This can be any UUID, or one of the predefined ones: + * + * - {@see PHP_UUID_NAMESPACE_DNS} + * - {@see PHP_UUID_NAMESPACE_OID} + * - {@see PHP_UUID_NAMESPACE_URL} + * - {@see PHP_UUID_NAMESPACE_X500} + * + * A particular name within the same namespace always results in the same + * version 3 UUID, across all RFC 4122 compliant UUID implementations. + * However, the namespace and name cannot be determined from the UUID alone. + * + * ## Examples + * ``` + * php_uuid uuid; + * + * php_uuid_create_v3(&uuid, PHP_UUID_NAMESPACE_DNS, "php.net", sizeof("php.net") - 1); + * + * assert(php_uuid_is_nil(uuid) == FALSE); + * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); + * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_3_NAME_BASED_MD5); + * + * php_uuid_string str; + * php_uuid_to_string(&str, uuid); + * assert(memcmp(&str, "11a38b9a-b3da-360f-9353-a5a725514269", PHP_UUID_STRING_LEN) == 0); + * + * php_uuid tmp; + * php_uuid_create_v3(&tmp, PHP_UUID_NAMESPACE_DNS, "php.net", sizeof("php.net") - 1); + * assert(memcmp(&tmp, &uuid, PHP_UUID_LEN) == 0); + * ``` + * + * @see https://tools.ietf.org/html/rfc4122#section-4.3 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 + * @param[out] uuid to store the result in. + * @param[in] namespace to create the UUID in. + * @param[in] name to create the UUID from. + * @param[in] name_len + */ +PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len); + +/** + * Create version 4 UUID. + * + * Version 4 UUIDs are randomly generated from the best available random source. + * The selection of that source is determined by PHP's random implementation. + * Some systems may be bad at generating sufficient entropy, e.g. virtual + * machines. This might lead to collisions faster than desired. If this is the + * case, the {@see php_uuid_create_v5} version should be used. + * + * ## Examples + * ``` + * php_uuid uuid; + * + * php_uuid_create_v4_silent(&uuid); + * + * assert(php_uuid_is_nil(uuid) == FALSE); + * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); + * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_4_RANDOM); + * + * php_uuid tmp; + * php_uuid_create_v4_silent(&uuid); + * assert(memcmp(&tmp, &uuid, PHP_UUID_LEN) == 0); + * ``` + * + * @see https://tools.ietf.org/html/rfc4122#section-4.4 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 + * @see php_uuid_create_v4_silent + * @see php_uuid_create_v4_throw + * @param[out] uuid to store the result. + * @param[in] throw whether to throw a PHP exception (`TRUE`) if it was not + * possible to gather sufficient entropy, or not (`FALSE`). + * @return `SUCCESS` if the generation succeeded, `FAILURE` if it was not + * possible to gather sufficient entropy. + */ +PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); + +/** + * Silently create version 4 UUID. + * + * @see php_uuid_create_v4 + * @param[out] uuid to store the result. + * @return `SUCCESS` if the generation succeeded, `FAILURE` if it was not + * possible to gather sufficient entropy. + */ +#define php_uuid_create_v4_silent(uuid) php_uuid_create_v4(uuid, FALSE) + +/** + * Create version 4 UUID and throw PHP exception if it is not possible to + * gather sufficient entropy. + * + * @see php_uuid_create_v4 + * @param[out] uuid to store the result. + * @return `SUCCESS` if the generation succeeded, `FAILURE` if it was not + * possible to gather sufficient entropy. + */ +#define php_uuid_create_v4_throw(uuid) php_uuid_create_v4(uuid, TRUE) + +/** + * Create version 5 UUID. + * + * Version 5 UUIDs are generated by MD5 hashing the concatenated namespace's + * byte representation and the given name. The namespace itself must be + * another UUID. This can be any UUID, or one of the predefined ones: + * + * - {@see PHP_UUID_NAMESPACE_DNS} + * - {@see PHP_UUID_NAMESPACE_OID} + * - {@see PHP_UUID_NAMESPACE_URL} + * - {@see PHP_UUID_NAMESPACE_X500} + * + * A particular name within the same namespace always results in the same + * version 5 UUID, across all RFC 4122 compliant UUID implementations. + * However, the namespace and name cannot be determined from the UUID alone. + * + * ## Examples + * ``` + * php_uuid uuid; + * + * php_uuid_create_v5(&uuid, PHP_UUID_NAMESPACE_DNS, "php.net", sizeof("php.net") - 1); + * + * assert(php_uuid_is_nil(uuid) == FALSE); + * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); + * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_5_NAME_BASED_SHA1); + * + * php_uuid_string str; + * php_uuid_to_string(&str, uuid); + * assert(memcmp(&str, "c4a760a8-dbcf-5254-a0d9-6a4474bd1b62", PHP_UUID_STRING_LEN) == 0); + * + * php_uuid tmp; + * php_uuid_create_v5(&tmp, PHP_UUID_NAMESPACE_DNS, "php.net", sizeof("php.net") - 1); + * assert(memcmp(&tmp, &uuid, PHP_UUID_LEN) == 0); + * ``` + * + * @see https://tools.ietf.org/html/rfc4122#section-4.3 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 + * @param[out] uuid to store the result in. + * @param[in] namespace to create the UUID in. + * @param[in] name to create the UUID from. + * @param[in] name_len + */ +PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len); + +/** + * Get the variant associated with this UUID. + * + * The variant specifies the internal data layout of a UUID. This + * implementation generates {@see UUID::VARIANT_RFC4122} UUIDs only, + * however, parsing and construction of other variants is supported. + * + * @see http://tools.ietf.org/html/rfc4122#section-4.1.1 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Variants + * @see PHP_UUID_VARIANT_NCS + * @see PHP_UUID_VARIANT_RFC4122 + * @see PHP_UUID_VARIANT_MICROSOFT + * @see PHP_UUID_VARIANT_FUTURE_RESERVED + * @param[in] uuid to get the variant from. + * @return The variant of the given UUID. + */ +PHPAPI zend_always_inline const php_uuid_variant php_uuid_get_variant(const php_uuid uuid); + +/** + * Get the version associated with this UUID. + * + * The version specifies which algorithm was used to generate the UUID. Note + * that the version might not be meaningful if another variant than the + * {@see PHP_UUID_VARIANT_RFC4122} was used to generate the UUID. This + * implementation generates {@see PHP_UUID_VARIANT_RFC4122} UUIDs only, but + * allows parsing and construction of other variants. + * + * @see http://tools.ietf.org/html/rfc4122#section-4.1.3 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions + * @see PHP_UUID_VERSION_1_TIME_BASED + * @see PHP_UUID_VERSION_2_DCE_SECURITY + * @see PHP_UUID_VERSION_3_NAME_BASED_MD5 + * @see PHP_UUID_VERSION_4_RANDOM + * @see PHP_UUID_VERSION_5_NAME_BASED_SHA1 + * @param[in] uuid to get the version from. + * @return The version of the given UUID, which is an integer in [0, 15], the + * values [1, 5] correspond to one of the `PHP_UUID_VERSION_*` constants. + * The others are not defined in RFC 4122. + */ +PHPAPI zend_always_inline const uint8_t php_uuid_get_version(const php_uuid uuid); + +/** + * Check if the given UUID is the special nil UUID that has all 128 bits set + * to zero. + * + * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID + * @param[in] uuid to check. + * @return TRUE if the UUID contains the special nil UUID; FALSE otherwise. + */ +PHPAPI zend_always_inline const int php_uuid_is_nil(const php_uuid uuid); + +/** + * Convert the UUID to its hexadecimal representation. + * + * The hexadecimal representation of a UUID are 32 hexadecimal digits. The + * hexadecimal digits `a` through `f` are always formatted as lower case + * characters, in accordance with RFC 4122. + * + * ## Examples + * ``` + * php_uuid_hex hex; + * + * php_uuid_to_hex(&hex, PHP_UUID_NAMESPACE_DNS); + * assert(memcmp(&hex, "6ba7b8109dad11d180b400c04fd430c8", PHP_UUID_HEX_LEN) == 0); + * ``` + * + * @param[out] buffer to store the hexadecimal representation in. + * @param[in] uuid to convert. + */ +PHPAPI zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_uuid uuid); + +/** + * Convert the UUID to its string representation. + * + * The string representation of a UUID are 32 hexadecimal digits separated + * by a hyphen into five groups of 8, 4, 4, 4, and 12 digits. The + * hexadecimal digits `a` through `f` are always formatted as lower case + * characters, in accordance with RFC 4122. + * + * ## Examples + * ``` + * php_uuid_string str; + * + * php_uuid_to_hex(&str, PHP_UUID_NAMESPACE_DNS); + * assert(memcmp(&str, "6ba7b810-9dad-11d1-80b4-00c04fd430c8", PHP_UUID_STRING_LEN) == 0); + * ``` + * + * @param[out] buffer to store the string representation in. + * @param[in] uuid to convert. + */ +PHPAPI zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const php_uuid uuid); + +/** + * Initialization function of the standard UUID submodule. + * + * @see ext/standard/basic_functions.c + * @see ext/standard/php_standard.h + */ +PHP_MINIT_FUNCTION(uuid); + +/** + * Final UUID class methods. + * + * @see ext/standard/stubs/UUID.php + */ +PHP_METHOD(UUID, __construct); +PHP_METHOD(UUID, fromBinary); +PHP_METHOD(UUID, parse); +PHP_METHOD(UUID, v3); +PHP_METHOD(UUID, v4); +PHP_METHOD(UUID, v5); +PHP_METHOD(UUID, NamespaceDNS); +PHP_METHOD(UUID, NamespaceOID); +PHP_METHOD(UUID, NamespaceURL); +PHP_METHOD(UUID, NamespaceX500); +PHP_METHOD(UUID, Nil); +PHP_METHOD(UUID, __clone); +PHP_METHOD(UUID, __set); +PHP_METHOD(UUID, __wakeup); +PHP_METHOD(UUID, getVariant); +PHP_METHOD(UUID, getVersion); +PHP_METHOD(UUID, isNil); +PHP_METHOD(UUID, toBinary); +PHP_METHOD(UUID, toHex); +PHP_METHOD(UUID, toString); + +/** + * Final UUIDParsingException class methods (extends Exception). + * + * @see ext/standard/stubs/UUIDParsingException.php + */ +PHP_METHOD(UUIDParsingException, __construct); +PHP_METHOD(UUIDParsingException, getInput); +PHP_METHOD(UUIDParsingException, getPosition); + +#endif /* PHP_UUID_H */ diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c new file mode 100644 index 0000000000000..7649b5110bc97 --- /dev/null +++ b/ext/standard/uuid.c @@ -0,0 +1,646 @@ +ο»Ώ/* + +----------------------------------------------------------------------+ + | PHP Version 7 | + +----------------------------------------------------------------------+ + | Copyright (c) 1997-2017 The PHP Group | + +----------------------------------------------------------------------+ + | This source file is subject to version 3.01 of the PHP license, | + | that is bundled with this package in the file LICENSE, and is | + | available through the world-wide-web at the following url: | + | http://www.php.net/license/3_01.txt | + | If you did not receive a copy of the PHP license and are unable to | + | obtain it through the world-wide-web, please send a note to | + | license@php.net so we can mail you a copy immediately. | + +----------------------------------------------------------------------+ + | Author: Richard Fussenegger | + +----------------------------------------------------------------------+ +*/ + +/* $Id$ */ + +#include "php_uuid.h" + +#include "zend_exceptions.h" +#include "md5.h" +#include "php_random.h" +#include "sha1.h" + +#ifdef HAVE_SPL +# include "ext/spl/spl_exceptions.h" +#endif + +PHPAPI zend_class_entry *php_ce_UUID; +PHPAPI zend_class_entry *php_ce_UUIDParsingException; + +PHPAPI const php_uuid PHP_UUID_NAMESPACE_DNS = "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"; +PHPAPI const php_uuid PHP_UUID_NAMESPACE_OID = "\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"; +PHPAPI const php_uuid PHP_UUID_NAMESPACE_URL = "\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"; +PHPAPI const php_uuid PHP_UUID_NAMESPACE_X500 = "\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"; +PHPAPI const php_uuid PHP_UUID_NIL = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; + +static const uint8_t PHP_UUID_VERSION_MIN = 0; +PHPAPI const uint8_t PHP_UUID_VERSION_1_TIME_BASED = 1; +PHPAPI const uint8_t PHP_UUID_VERSION_2_DCE_SECURITY = 2; +PHPAPI const uint8_t PHP_UUID_VERSION_3_NAME_BASED_MD5 = 3; +PHPAPI const uint8_t PHP_UUID_VERSION_4_RANDOM = 4; +PHPAPI const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1 = 5; +static const uint8_t PHP_UUID_VERSION_MAX = 15; + +PHPAPI const uint8_t PHP_UUID_LEN = sizeof(php_uuid); +PHPAPI const uint8_t PHP_UUID_HEX_LEN = sizeof(php_uuid_hex) - 1; +PHPAPI const uint8_t PHP_UUID_STRING_LEN = sizeof(php_uuid_string) - 1; + +static const char UUID_BINARY_PROP[] = "binary"; +static const uint8_t UUID_BINARY_PROP_LEN = sizeof(UUID_BINARY_PROP) - 1; + +static const char UUID_EX_INPUT_PROP[] = "input"; +static const uint8_t UUID_EX_INPUT_PROP_LEN = sizeof(UUID_EX_INPUT_PROP) - 1; +static const char UUID_EX_POSITION_PROP[] = "position"; +static const uint8_t UUID_EX_POSITON_PROP_LEN = sizeof(UUID_EX_POSITION_PROP) - 1; + +static const char URN_PREFIX[] = "urn:uuid:"; +static const uint8_t URN_PREFIX_LEN = sizeof(URN_PREFIX) - 1; + +static zend_always_inline void set_variant_rfc4122(php_uuid *uuid) +{ + (*uuid)[8] = ((*uuid)[8] & 0x3F) | 0x80; +} + +static zend_always_inline void php_uuid_set_version(php_uuid *uuid, const uint8_t version) +{ + assert(PHP_UUID_VERSION_MIN <= version && version <= PHP_UUID_VERSION_MAX); + + (*uuid)[6] = ((*uuid)[6] & 0x0F) | (version << 4); +} + +static ZEND_COLD zend_object *throw_uuid_parsing_exception(const char *input, const size_t input_len, const size_t position, const char *reason, ...) +{ + va_list format_args; + char *formatted_reason; + zend_object *object; + zval exception; + + va_start(format_args, reason); + zend_vspprintf(&formatted_reason, 0, reason, format_args); + va_end(format_args); + object = zend_throw_exception(php_ce_UUIDParsingException, formatted_reason, 0); + efree(formatted_reason); + + ZVAL_OBJ(&exception, object); + zend_update_property_stringl(php_ce_UUIDParsingException, &exception, UUID_EX_INPUT_PROP, UUID_EX_INPUT_PROP_LEN, input, input_len); + zend_update_property_long(php_ce_UUIDParsingException, &exception, UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, position); + + return object; +} + +static zend_always_inline zend_object *throw_uuid_parsing_exception_invalid_len(const char *input, const size_t input_len, const size_t position, const size_t actual) +{ + return throw_uuid_parsing_exception( + input, + input_len, + position, + "Expected at least %u hexadecimal digits, but got %u", + PHP_UUID_HEX_LEN, + actual + ); +} + +static zend_always_inline zend_object *throw_uuid_parsing_exception_invalid_char(const char *input, const size_t input_len, const size_t position) +{ + return throw_uuid_parsing_exception( + input, + input_len, + position, + "Expected hexadecimal digit, but found '%c' (0x%02x)", + input[position], + input[position] + ); +} + +PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_len, const zend_bool throw) +{ + char chr; + size_t position = 0; + size_t digit = 0; + size_t limit = input_len - 1; + uint8_t byte = 0; + + while (input[position] == '-' || input[position] == ' ' || input[position] == '\t' || input[position] == '{') { + ++position; + } + + if (memcmp(input + position, URN_PREFIX, URN_PREFIX_LEN) == 0) { + position += URN_PREFIX_LEN; + } + + while (input[limit] == '-' || input[limit] == ' ' || input[limit] == '\t' || input[limit] == '}') { + --limit; + } + + if ((limit - position + 1) < PHP_UUID_HEX_LEN) { + if (throw == TRUE) { + throw_uuid_parsing_exception_invalid_len(input, input_len, position, limit - position + 1); + } + return FAILURE; + } + + for (; position <= limit; ++position) { + chr = input[position]; + + /* First digit of the byte. */ + if (digit % 2 == 0) { + if ('0' <= chr && chr <= '9') { + byte = chr - '0'; + } + else if ('a' <= chr && chr <= 'f') { + byte = chr - 'a' + 10; + } + else if ('A' <= chr && chr <= 'F') { + byte = chr - 'A' + 10; + } + else if (chr == '-') { + continue; + } + else { + if (throw == TRUE) { + throw_uuid_parsing_exception_invalid_char(input, input_len, position); + } + return FAILURE; + } + } + /* Second digit of the byte. */ + else { + /* Shift upper half. */ + byte *= 16; + + if ('0' <= chr && chr <= '9') { + byte += chr - '0'; + } + else if ('a' <= chr && chr <= 'f') { + byte += chr - 'a' + 10; + } + else if ('A' <= chr && chr <= 'F') { + byte += chr - 'A' + 10; + } + else if (chr == '-') { + continue; + } + else { + if (throw == TRUE) { + throw_uuid_parsing_exception_invalid_char(input, input_len, position); + } + return FAILURE; + } + + if (digit > PHP_UUID_HEX_LEN) { + if (throw == TRUE) { + throw_uuid_parsing_exception( + input, + input_len, + position, + "Expected no more than %u hexadecimal digits", + PHP_UUID_HEX_LEN + ); + } + return FAILURE; + } + + (*uuid)[digit / 2] = byte; + } + + ++digit; + } + + if (digit < PHP_UUID_HEX_LEN) { + if (throw == TRUE) { + throw_uuid_parsing_exception_invalid_len(input, input_len, position, digit); + } + return FAILURE; + } + + return SUCCESS; +} + +PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) +{ + PHP_MD5_CTX context; + + PHP_MD5Init(&context); + PHP_MD5Update(&context, (char *) namespace, PHP_UUID_LEN); + PHP_MD5Update(&context, name, name_len); + PHP_MD5Final((char *)uuid, &context); + set_variant_rfc4122(uuid); + php_uuid_set_version(uuid, PHP_UUID_VERSION_3_NAME_BASED_MD5); +} + +PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw) +{ + int result = php_random_bytes(uuid, PHP_UUID_LEN, throw); + + if (result == SUCCESS) { + set_variant_rfc4122(uuid); + php_uuid_set_version(uuid, PHP_UUID_VERSION_4_RANDOM); + } + + return result; +} + +PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) +{ + PHP_SHA1_CTX context; + char digest[20]; + + PHP_SHA1Init(&context); + PHP_SHA1Update(&context, (char *) namespace, PHP_UUID_LEN); + PHP_SHA1Update(&context, name, name_len); + PHP_SHA1Final(digest, &context); + memcpy(uuid, digest, PHP_UUID_LEN); + set_variant_rfc4122(uuid); + php_uuid_set_version(uuid, PHP_UUID_VERSION_5_NAME_BASED_SHA1); +} + +PHPAPI zend_always_inline const php_uuid_variant php_uuid_get_variant(const php_uuid uuid) +{ + if ((uuid[8] & 0xC0) == 0x80) return PHP_UUID_VARIANT_RFC4122; + if ((uuid[8] & 0xE0) == 0xC0) return PHP_UUID_VARIANT_MICROSOFT; + if ((uuid[8] & 0x80) == 0x00) return PHP_UUID_VARIANT_NCS; + return PHP_UUID_VARIANT_FUTURE_RESERVED; +} + +PHPAPI zend_always_inline const uint8_t php_uuid_get_version(const php_uuid uuid) +{ + return uuid[6] >> 4; +} + +PHPAPI zend_always_inline const int php_uuid_is_nil(const php_uuid uuid) +{ + return memcmp(uuid, PHP_UUID_NIL, PHP_UUID_LEN) == 0; +} + +PHPAPI zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_uuid uuid) +{ + sprintf( + (char *) buffer, + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + uuid[0], uuid[1], uuid[2], uuid[3], + uuid[4], uuid[5], + uuid[6], uuid[7], + uuid[8], uuid[9], + uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15] + ); +} + +PHPAPI zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const php_uuid uuid) +{ + sprintf( + (char *) buffer, + "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + uuid[0], uuid[1], uuid[2], uuid[3], + uuid[4], uuid[5], + uuid[6], uuid[7], + uuid[8], uuid[9], + uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15] + ); +} + +PHP_MINIT_FUNCTION(uuid) +{ + zend_class_entry ce; + + ZEND_BEGIN_ARG_INFO(UUID___construct_args, NULL) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_fromBinary_args, 0, 1, UUID, 0) + ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, UUID, 0) + ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, UUID, 0) + ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_v4_args, UUID, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, UUID, 0) + ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, UUID, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, UUID, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, UUID, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, UUID, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, UUID, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_INFO(UUID___clone_args, NULL) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___set_args, IS_VOID, 0) + ZEND_ARG_INFO(0, _) + ZEND_ARG_INFO(0, __) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___wakeup_args, IS_VOID, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toHex_args, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toString_args, IS_STRING, 0) + ZEND_END_ARG_INFO(); + + static const zend_function_entry uuid_methods[] = { + PHP_ME(UUID, __construct, UUID___construct_args, ZEND_ACC_PRIVATE) + PHP_ME(UUID, fromBinary, UUID_fromBinary_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, parse, UUID_parse_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, v3, UUID_v3_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, v4, UUID_v4_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, v5, UUID_v5_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, NamespaceDNS, UUID_NamespaceDNS_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, NamespaceOID, UUID_NamespaceOID_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, NamespaceURL, UUID_NamespaceURL_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, NamespaceX500, UUID_NamespaceX500_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, Nil, UUID_Nil_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, __clone, UUID___clone_args, ZEND_ACC_PRIVATE) + PHP_ME(UUID, __set, UUID___set_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, __wakeup, UUID___wakeup_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, getVariant, UUID_getVariant_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, getVersion, UUID_getVersion_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, isNil, UUID_isNil_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, toBinary, UUID_toBinary_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, toHex, UUID_toHex_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, toString, UUID_toString_args, ZEND_ACC_PUBLIC) + PHP_FE_END + }; + + INIT_CLASS_ENTRY(ce, "UUID", uuid_methods); + php_ce_UUID = zend_register_internal_class(&ce); + php_ce_UUID->ce_flags |= ZEND_ACC_FINAL; + + zend_declare_class_constant_long(php_ce_UUID, "VARIANT_NCS", sizeof("VARIANT_NCS") - 1, PHP_UUID_VARIANT_NCS); + zend_declare_class_constant_long(php_ce_UUID, "VARIANT_RFC4122", sizeof("VARIANT_RFC4122") - 1, PHP_UUID_VARIANT_RFC4122); + zend_declare_class_constant_long(php_ce_UUID, "VARIANT_MICROSOFT", sizeof("VARIANT_MICROSOFT") - 1, PHP_UUID_VARIANT_MICROSOFT); + zend_declare_class_constant_long(php_ce_UUID, "VARIANT_FUTURE_RESERVED", sizeof("VARIANT_FUTURE_RESERVED") - 1, PHP_UUID_VARIANT_FUTURE_RESERVED); + + zend_declare_class_constant_long(php_ce_UUID, "VERSION_1_TIME_BASED", sizeof("VERSION_1_TIME_BASED") - 1, PHP_UUID_VERSION_1_TIME_BASED); + zend_declare_class_constant_long(php_ce_UUID, "VERSION_2_DCE_SECURITY", sizeof("VERSION_2_DCE_SECURITY") - 1, PHP_UUID_VERSION_2_DCE_SECURITY); + zend_declare_class_constant_long(php_ce_UUID, "VERSION_3_NAME_BASED_MD5", sizeof("VERSION_3_NAME_BASED_MD5") - 1, PHP_UUID_VERSION_3_NAME_BASED_MD5); + zend_declare_class_constant_long(php_ce_UUID, "VERSION_4_RANDOM", sizeof("VERSION_4_RANDOM") - 1, PHP_UUID_VERSION_4_RANDOM); + zend_declare_class_constant_long(php_ce_UUID, "VERSION_5_NAME_BASED_SHA1", sizeof("VERSION_5_NAME_BASED_SHA1") - 1, PHP_UUID_VERSION_5_NAME_BASED_SHA1); + + zend_declare_property_null(php_ce_UUID, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, ZEND_ACC_PRIVATE); + + ZEND_BEGIN_ARG_INFO_EX(UUIDParsingException___construct_args, NULL, 0, 2) + ZEND_ARG_TYPE_INFO(0, reason, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, position, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, previous, Throwable, 1) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParsingException_getInput_args, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParsingException_getPosition_args, IS_LONG, 0) + ZEND_END_ARG_INFO(); + + static const zend_function_entry uuid_parsing_exception_methods[] = { + PHP_ME(UUIDParsingException, __construct, UUIDParsingException___construct_args, ZEND_ACC_PUBLIC) + PHP_ME(UUIDParsingException, getInput, UUIDParsingException_getInput_args, ZEND_ACC_PUBLIC) + PHP_ME(UUIDParsingException, getPosition, UUIDParsingException_getPosition_args, ZEND_ACC_PUBLIC) + PHP_FE_END + }; + + INIT_CLASS_ENTRY(ce, "UUIDParsingException", uuid_parsing_exception_methods); + php_ce_UUIDParsingException = zend_register_internal_class_ex(&ce, zend_ce_exception); + php_ce_UUIDParsingException->ce_flags |= ZEND_ACC_FINAL; + php_ce_UUIDParsingException->create_object = zend_ce_exception->create_object; + + zend_declare_property_null(php_ce_UUIDParsingException, UUID_EX_INPUT_PROP, UUID_EX_INPUT_PROP_LEN, ZEND_ACC_PRIVATE); + zend_declare_property_null(php_ce_UUIDParsingException, UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, ZEND_ACC_PRIVATE); + + return SUCCESS; +} + +static zend_always_inline php_uuid *get_bytes(zval *object) +{ + return (php_uuid *) Z_STRVAL_P(zend_read_property(php_ce_UUID, object, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, TRUE, NULL)); +} + +static zend_always_inline void new_uuid(zval *object, const php_uuid uuid) +{ + object_init_ex(object, php_ce_UUID); + zend_update_property_stringl(php_ce_UUID, object, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, uuid, PHP_UUID_LEN); +} + +static zend_always_inline zend_object *throw_argument_count_error(const char *method, const size_t passed, const size_t expected) +{ + return zend_throw_exception_ex( + zend_ce_argument_count_error, + 0, + "Too few arguments to method UUID::%s(), %u passed and exactly %u expected", + method, + passed, + expected + ); +} + +PHP_METHOD(UUID, __construct) { /* NOOP */ } + +PHP_METHOD(UUID, fromBinary) +{ + char *input = NULL; + size_t input_len; + + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, MIN(1, ZEND_NUM_ARGS()), "s", &input, &input_len) == FAILURE) { + throw_argument_count_error("fromBinary", ZEND_NUM_ARGS(), 1); + return; + } + + if (input_len != PHP_UUID_LEN) { + zend_throw_exception_ex( + spl_ce_InvalidArgumentException, + 0, + "Expected exactly %u bytes, but got %u", + PHP_UUID_LEN, + input_len + ); + return; + } + + new_uuid(return_value, input); +} + +PHP_METHOD(UUID, parse) +{ + char *input = NULL; + size_t input_len; + php_uuid uuid; + + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, MIN(ZEND_NUM_ARGS(), 1), "s", &input, &input_len) == FAILURE) { + throw_argument_count_error("parse", ZEND_NUM_ARGS(), 1); + return; + } + + php_uuid_parse_throw(&uuid, input, input_len); + new_uuid(return_value, uuid); +} + +PHP_METHOD(UUID, v3) +{ + zval *namespace = NULL; + char *name = NULL; + size_t name_len; + php_uuid uuid; + + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, MIN(ZEND_NUM_ARGS(), 2), "zs", &namespace, &name, &name_len) == FAILURE) { + throw_argument_count_error("v3", ZEND_NUM_ARGS(), 2); + return; + } + + php_uuid_create_v3(&uuid, get_bytes(namespace), name, name_len); + new_uuid(return_value, uuid); +} + +PHP_METHOD(UUID, v4) +{ + php_uuid uuid; + if (php_uuid_create_v4_throw(&uuid) == SUCCESS) { + new_uuid(return_value, uuid); + } +} + +PHP_METHOD(UUID, v5) +{ + zval *namespace = NULL; + char *name = NULL; + size_t name_len; + php_uuid uuid; + + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, MIN(ZEND_NUM_ARGS(), 2), "zs", &namespace, &name, &name_len) == FAILURE) { + throw_argument_count_error("v5", ZEND_NUM_ARGS(), 2); + return; + } + + php_uuid_create_v5(&uuid, get_bytes(namespace), name, name_len); + new_uuid(return_value, uuid); +} + +PHP_METHOD(UUID, NamespaceDNS) { new_uuid(return_value, PHP_UUID_NAMESPACE_DNS); } +PHP_METHOD(UUID, NamespaceOID) { new_uuid(return_value, PHP_UUID_NAMESPACE_OID); } +PHP_METHOD(UUID, NamespaceURL) { new_uuid(return_value, PHP_UUID_NAMESPACE_URL); } +PHP_METHOD(UUID, NamespaceX500) { new_uuid(return_value, PHP_UUID_NAMESPACE_X500); } +PHP_METHOD(UUID, Nil) { new_uuid(return_value, PHP_UUID_NIL); } + +PHP_METHOD(UUID, __clone) { zend_throw_error(zend_ce_error, "Cannot clone immutable UUID object"); } +PHP_METHOD(UUID, __set) { zend_throw_error(zend_ce_error, "Cannot set dynamic properties on immutable UUID object"); } + +PHP_METHOD(UUID, __wakeup) +{ + size_t len = Z_STRLEN_P(zend_read_property(php_ce_UUID, &EX(This), UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, TRUE, NULL)); + + if (len != PHP_UUID_LEN) { + zend_throw_exception_ex( + spl_ce_UnexpectedValueException, + 0, + "Expected exactly %u bytes, but found %u", + PHP_UUID_LEN, + len + ); + } +} + +PHP_METHOD(UUID, getVariant) +{ + RETURN_LONG(php_uuid_get_variant(*get_bytes(&EX(This)))); +} + +PHP_METHOD(UUID, getVersion) +{ + RETURN_LONG(php_uuid_get_version(*get_bytes(&EX(This)))); +} + +PHP_METHOD(UUID, isNil) +{ + RETURN_BOOL(php_uuid_is_nil(*get_bytes(&EX(This)))); +} + +PHP_METHOD(UUID, toBinary) +{ + RETURN_STRINGL(*get_bytes(&EX(This)), PHP_UUID_LEN); +} + +PHP_METHOD(UUID, toHex) +{ + php_uuid_hex buffer; + php_uuid_to_hex(&buffer, *get_bytes(&EX(This))); + RETURN_STRINGL(buffer, PHP_UUID_HEX_LEN); +} + +PHP_METHOD(UUID, toString) +{ + php_uuid_string buffer; + php_uuid_to_string(&buffer, *get_bytes(&EX(This))); + RETURN_STRINGL(buffer, PHP_UUID_STRING_LEN); +} + +PHP_METHOD(UUIDParsingException, __construct) +{ + zval *reason = NULL; + zval *input = NULL; + zval *position = NULL; + zval *previous = NULL; + + if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, MIN(ZEND_NUM_ARGS(), 4), "zz|zz!", &reason, &input, &position, &previous) == FAILURE) { + zend_throw_exception_ex( + zend_ce_argument_count_error, + 0, + "Too few arguments to method UUIDParsingException::__construct(), %u passed and at least 2 expected", + ZEND_NUM_ARGS() + ); + return; + } + + zend_update_property_ex(zend_ce_exception, &EX(This), ZSTR_KNOWN(ZEND_STR_MESSAGE), reason); + zend_update_property(php_ce_UUIDParsingException, &EX(This), UUID_EX_INPUT_PROP, UUID_EX_INPUT_PROP_LEN, input); + + if (position != NULL) { + zend_update_property(php_ce_UUIDParsingException, &EX(This), UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, position); + } + else { + zend_update_property_long(php_ce_UUIDParsingException, &EX(This), UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, 0); + } + + if (previous != NULL) { + zend_update_property_ex(zend_ce_exception, &EX(This), ZSTR_KNOWN(ZEND_STR_PREVIOUS), previous); + } +} + +PHP_METHOD(UUIDParsingException, getInput) +{ + RETURN_ZVAL(zend_read_property( + php_ce_UUIDParsingException, + &EX(This), + UUID_EX_INPUT_PROP, + UUID_EX_INPUT_PROP_LEN, + TRUE, + NULL + ), 1, 0); +} + +/* */ +PHP_METHOD(UUIDParsingException, getPosition) +{ + RETURN_ZVAL(zend_read_property( + php_ce_UUIDParsingException, + &EX(This), + UUID_EX_POSITION_PROP, + UUID_EX_POSITON_PROP_LEN, + TRUE, + NULL + ), 1, 0); +} From 8f85dff8457c3b0cbc66fc63a6b45243320110ba Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 24 May 2017 01:38:30 +0200 Subject: [PATCH 09/54] Fixed encoding and line endings Thanks Visual Studio ;( --- ext/standard/basic_functions.c | 2 +- ext/standard/php_standard.h | 2 +- ext/standard/php_uuid.h | 250 ++++++++++++++++----------------- ext/standard/uuid.c | 2 +- 4 files changed, 128 insertions(+), 128 deletions(-) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index f86e1fae966bc..33b263e19f354 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -1,4 +1,4 @@ -ο»Ώ/* +/* +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ diff --git a/ext/standard/php_standard.h b/ext/standard/php_standard.h index 06f63e1dfc8ef..3bd5d2d73c2a3 100644 --- a/ext/standard/php_standard.h +++ b/ext/standard/php_standard.h @@ -1,4 +1,4 @@ -ο»Ώ/* +/* +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index 252c9480a752f..a8eb765eb4693 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -131,43 +131,43 @@ PHPAPI extern const uint8_t PHP_UUID_HEX_LEN; PHPAPI extern const uint8_t PHP_UUID_STRING_LEN; /** - * Domain Name System (DNS) namespace UUID. - * - * @see https://tools.ietf.org/html/rfc4122#appendix-C + * Domain Name System (DNS) namespace UUID. + * + * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/Domain_Name_System */ PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_DNS; -/** -* Object Identifier (OID) namespace UUID. -* - * @see https://tools.ietf.org/html/rfc4122#appendix-C - * @see https://en.wikipedia.org/wiki/Object_identifier +/** +* Object Identifier (OID) namespace UUID. +* + * @see https://tools.ietf.org/html/rfc4122#appendix-C + * @see https://en.wikipedia.org/wiki/Object_identifier */ PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_OID; /** - * Uniform Resource Locator (URL) namespace UUID. - * - * @see https://tools.ietf.org/html/rfc4122#appendix-C + * Uniform Resource Locator (URL) namespace UUID. + * + * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/URL */ PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_URL; /** * X.500 Distinguished Names (X.500 DN) namespace UUID. The names that are to - * be hashed in this namespace can be in DER or a text output format. - * - * @see https://tools.ietf.org/html/rfc4122#appendix-C - * @see https://en.wikipedia.org/wiki/X.500 + * be hashed in this namespace can be in DER or a text output format. + * + * @see https://tools.ietf.org/html/rfc4122#appendix-C + * @see https://en.wikipedia.org/wiki/X.500 * @see https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol */ PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_X500; /** * Special nil UUID that has all 128 bits set to zero. - * - * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 + * + * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID */ PHPAPI extern const php_uuid PHP_UUID_NIL; @@ -184,75 +184,75 @@ PHPAPI typedef enum php_uuid_variant { PHP_UUID_VARIANT_FUTURE_RESERVED = 3, /* 0b111 */ } php_uuid_variant; -/** - * Version code for date-time and IEEE 802 MAC address UUIDs. - * - * Generation of this version is not supported by this implementation due - * to security concerns. Version 4 UUIDs are a good replacement for version - * 1 UUIDs without the privacy/security concerns (see Wikipedia). - * - * @see https://tools.ietf.org/html/rfc4122#section-4.2 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_.28date-time_and_MAC_address.29 +/** + * Version code for date-time and IEEE 802 MAC address UUIDs. + * + * Generation of this version is not supported by this implementation due + * to security concerns. Version 4 UUIDs are a good replacement for version + * 1 UUIDs without the privacy/security concerns (see Wikipedia). + * + * @see https://tools.ietf.org/html/rfc4122#section-4.2 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_.28date-time_and_MAC_address.29 */ PHPAPI extern const uint8_t PHP_UUID_VERSION_1_TIME_BASED; -/** - * Version code for date-time and IEEE 802 MAC address UUIDs (DCE security - * algorithm). - * - * Generation of this version is not supported by this implementation due - * to security concerns, and uniqueness limitations for applications with - * high allocations. Version 4 UUIDs are a good replacement for version 2 - * UUIDs without the privacy/security concerns (see Wikipedia), and they - * support high allocations. - * - * @see https://tools.ietf.org/html/rfc4122#section-4.2 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_2_.28date-time_and_MAC_Address.2C_DCE_security_version.29 +/** + * Version code for date-time and IEEE 802 MAC address UUIDs (DCE security + * algorithm). + * + * Generation of this version is not supported by this implementation due + * to security concerns, and uniqueness limitations for applications with + * high allocations. Version 4 UUIDs are a good replacement for version 2 + * UUIDs without the privacy/security concerns (see Wikipedia), and they + * support high allocations. + * + * @see https://tools.ietf.org/html/rfc4122#section-4.2 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_2_.28date-time_and_MAC_Address.2C_DCE_security_version.29 */ PHPAPI extern const uint8_t PHP_UUID_VERSION_2_DCE_SECURITY; -/** - * Version code for namespace/name-based MD5 hashed UUIDs. - * - * @see php_uuid_create_v3 - * @see https://tools.ietf.org/html/rfc4122#section-4.3 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 +/** + * Version code for namespace/name-based MD5 hashed UUIDs. + * + * @see php_uuid_create_v3 + * @see https://tools.ietf.org/html/rfc4122#section-4.3 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 */ PHPAPI extern const uint8_t PHP_UUID_VERSION_3_NAME_BASED_MD5; -/** - * Version code for random UUIDs. - * - * @see php_uuid_create_v4 - * @see https://tools.ietf.org/html/rfc4122#section-4.4 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 +/** + * Version code for random UUIDs. + * + * @see php_uuid_create_v4 + * @see https://tools.ietf.org/html/rfc4122#section-4.4 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 */ PHPAPI extern const uint8_t PHP_UUID_VERSION_4_RANDOM; - -/** - * Version code for namespace/name-based SHA1 hashed UUIDs. - * - * @see php_uuid_create_v5 - * @see https://tools.ietf.org/html/rfc4122#section-4.3 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 + +/** + * Version code for namespace/name-based SHA1 hashed UUIDs. + * + * @see php_uuid_create_v5 + * @see https://tools.ietf.org/html/rfc4122#section-4.3 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 */ PHPAPI extern const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1; /** - * Parse the given string as UUID. - * - * The following UUID representations are parsable: - * - * - hexadecimal representations (`aaaaaaaabbbbccccddddeeeeeeeeeeeee`), - * - string representations (`aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), - * - URNs (`urn:uuid:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), and - * - Microsoft representations (`{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee}`). - * - * Leading and trailing whitespace, namely spaces (` `) and tabs (`\t`), is - * ignored, so are leading opening braces (`{`) and trailing closing braces - * (`}`). Hyphens (`-`) are ignored everywhere. The parsing algorithm - * follows the [robustness - * principle](https://en.wikipedia.org/wiki/Robustness_principle) and is + * Parse the given string as UUID. + * + * The following UUID representations are parsable: + * + * - hexadecimal representations (`aaaaaaaabbbbccccddddeeeeeeeeeeeee`), + * - string representations (`aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), + * - URNs (`urn:uuid:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), and + * - Microsoft representations (`{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee}`). + * + * Leading and trailing whitespace, namely spaces (` `) and tabs (`\t`), is + * ignored, so are leading opening braces (`{`) and trailing closing braces + * (`}`). Hyphens (`-`) are ignored everywhere. The parsing algorithm + * follows the [robustness + * principle](https://en.wikipedia.org/wiki/Robustness_principle) and is * not meant for validation. * * ## Examples @@ -265,7 +265,7 @@ PHPAPI extern const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1; * php_uuid_parse_silent(&uuid, "urn:uuid:01234567-89ab-cdef-0123-456789abcdef", sizeof("urn:uuid:01234567-89ab-cdef-0123-456789abcdef") - 1); * php_uuid_parse_silent(&uuid, "{01234567-89ab-cdef-0123-456789abcdef}", sizeof("{01234567-89ab-cdef-0123-456789abcdef}") - 1); * - * // Leading and trailing gargabe is ignored, so are extraneous hyphens. + * // Leading and trailing garbage is ignored, so are extraneous hyphens. * php_uuid_parse_silent(&uuid, " \t ---- { urn:uuid:----0123-4567-89ab-cdef-0123-4567-89ab-cdef---- } ---- \t ", sizeof(" \t ---- { urn:uuid:----0123-4567-89ab-cdef-0123-4567-89ab-cdef---- } ---- \t ") - 1); * * // However, note that there cannot be whitespace or braces between the URN @@ -275,7 +275,7 @@ PHPAPI extern const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1; * "urn:uuid:{01234567-89ab-cdef-0123-456789abcdef", * sizeof("urn:uuid:{01234567-89ab-cdef-0123-456789abcdef") - 1 * ) == FAILURE); - * ``` + * ``` * * @see php_uuid_parse_silent * @see php_uuid_parse_throw @@ -312,22 +312,22 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ /** * Create version 3 UUID. * - * > RFC 4122 recommends {@see v5} over this one and states that version 3 - * > UUIDs should be used if backwards compatibility is required only. This - * > is because MD5 has a higher collision probability compared to SHA1, - * > which is used by version 5; regardless of the truncation! - * - * Version 3 UUIDs are generated by MD5 hashing the concatenated namespace's - * byte representation and the given name. The namespace itself must be - * another UUID. This can be any UUID, or one of the predefined ones: - * - * - {@see PHP_UUID_NAMESPACE_DNS} - * - {@see PHP_UUID_NAMESPACE_OID} - * - {@see PHP_UUID_NAMESPACE_URL} - * - {@see PHP_UUID_NAMESPACE_X500} - * - * A particular name within the same namespace always results in the same - * version 3 UUID, across all RFC 4122 compliant UUID implementations. + * > RFC 4122 recommends {@see v5} over this one and states that version 3 + * > UUIDs should be used if backwards compatibility is required only. This + * > is because MD5 has a higher collision probability compared to SHA1, + * > which is used by version 5; regardless of the truncation! + * + * Version 3 UUIDs are generated by MD5 hashing the concatenated namespace's + * byte representation and the given name. The namespace itself must be + * another UUID. This can be any UUID, or one of the predefined ones: + * + * - {@see PHP_UUID_NAMESPACE_DNS} + * - {@see PHP_UUID_NAMESPACE_OID} + * - {@see PHP_UUID_NAMESPACE_URL} + * - {@see PHP_UUID_NAMESPACE_X500} + * + * A particular name within the same namespace always results in the same + * version 3 UUID, across all RFC 4122 compliant UUID implementations. * However, the namespace and name cannot be determined from the UUID alone. * * ## Examples @@ -418,17 +418,17 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); /** * Create version 5 UUID. * - * Version 5 UUIDs are generated by MD5 hashing the concatenated namespace's - * byte representation and the given name. The namespace itself must be - * another UUID. This can be any UUID, or one of the predefined ones: - * - * - {@see PHP_UUID_NAMESPACE_DNS} - * - {@see PHP_UUID_NAMESPACE_OID} - * - {@see PHP_UUID_NAMESPACE_URL} - * - {@see PHP_UUID_NAMESPACE_X500} - * - * A particular name within the same namespace always results in the same - * version 5 UUID, across all RFC 4122 compliant UUID implementations. + * Version 5 UUIDs are generated by MD5 hashing the concatenated namespace's + * byte representation and the given name. The namespace itself must be + * another UUID. This can be any UUID, or one of the predefined ones: + * + * - {@see PHP_UUID_NAMESPACE_DNS} + * - {@see PHP_UUID_NAMESPACE_OID} + * - {@see PHP_UUID_NAMESPACE_URL} + * - {@see PHP_UUID_NAMESPACE_X500} + * + * A particular name within the same namespace always results in the same + * version 5 UUID, across all RFC 4122 compliant UUID implementations. * However, the namespace and name cannot be determined from the UUID alone. * * ## Examples @@ -462,8 +462,8 @@ PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const /** * Get the variant associated with this UUID. * - * The variant specifies the internal data layout of a UUID. This - * implementation generates {@see UUID::VARIANT_RFC4122} UUIDs only, + * The variant specifies the internal data layout of a UUID. This + * implementation generates {@see UUID::VARIANT_RFC4122} UUIDs only, * however, parsing and construction of other variants is supported. * * @see http://tools.ietf.org/html/rfc4122#section-4.1.1 @@ -486,7 +486,7 @@ PHPAPI zend_always_inline const php_uuid_variant php_uuid_get_variant(const php_ * implementation generates {@see PHP_UUID_VARIANT_RFC4122} UUIDs only, but * allows parsing and construction of other variants. * - * @see http://tools.ietf.org/html/rfc4122#section-4.1.3 + * @see http://tools.ietf.org/html/rfc4122#section-4.1.3 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions * @see PHP_UUID_VERSION_1_TIME_BASED * @see PHP_UUID_VERSION_2_DCE_SECURITY @@ -503,8 +503,8 @@ PHPAPI zend_always_inline const uint8_t php_uuid_get_version(const php_uuid uuid /** * Check if the given UUID is the special nil UUID that has all 128 bits set * to zero. - * - * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 + * + * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID * @param[in] uuid to check. * @return TRUE if the UUID contains the special nil UUID; FALSE otherwise. @@ -512,18 +512,18 @@ PHPAPI zend_always_inline const uint8_t php_uuid_get_version(const php_uuid uuid PHPAPI zend_always_inline const int php_uuid_is_nil(const php_uuid uuid); /** - * Convert the UUID to its hexadecimal representation. - * - * The hexadecimal representation of a UUID are 32 hexadecimal digits. The - * hexadecimal digits `a` through `f` are always formatted as lower case - * characters, in accordance with RFC 4122. - * - * ## Examples - * ``` + * Convert the UUID to its hexadecimal representation. + * + * The hexadecimal representation of a UUID are 32 hexadecimal digits. The + * hexadecimal digits `a` through `f` are always formatted as lower case + * characters, in accordance with RFC 4122. + * + * ## Examples + * ``` * php_uuid_hex hex; * * php_uuid_to_hex(&hex, PHP_UUID_NAMESPACE_DNS); - * assert(memcmp(&hex, "6ba7b8109dad11d180b400c04fd430c8", PHP_UUID_HEX_LEN) == 0); + * assert(memcmp(&hex, "6ba7b8109dad11d180b400c04fd430c8", PHP_UUID_HEX_LEN) == 0); * ``` * * @param[out] buffer to store the hexadecimal representation in. @@ -532,20 +532,20 @@ PHPAPI zend_always_inline const int php_uuid_is_nil(const php_uuid uuid); PHPAPI zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_uuid uuid); /** - * Convert the UUID to its string representation. - * - * The string representation of a UUID are 32 hexadecimal digits separated - * by a hyphen into five groups of 8, 4, 4, 4, and 12 digits. The - * hexadecimal digits `a` through `f` are always formatted as lower case - * characters, in accordance with RFC 4122. - * - * ## Examples - * ``` + * Convert the UUID to its string representation. + * + * The string representation of a UUID are 32 hexadecimal digits separated + * by a hyphen into five groups of 8, 4, 4, 4, and 12 digits. The + * hexadecimal digits `a` through `f` are always formatted as lower case + * characters, in accordance with RFC 4122. + * + * ## Examples + * ``` * php_uuid_string str; * * php_uuid_to_hex(&str, PHP_UUID_NAMESPACE_DNS); - * assert(memcmp(&str, "6ba7b810-9dad-11d1-80b4-00c04fd430c8", PHP_UUID_STRING_LEN) == 0); - * ``` + * assert(memcmp(&str, "6ba7b810-9dad-11d1-80b4-00c04fd430c8", PHP_UUID_STRING_LEN) == 0); + * ``` * * @param[out] buffer to store the string representation in. * @param[in] uuid to convert. diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 7649b5110bc97..0db7e66cec3b7 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -1,4 +1,4 @@ -ο»Ώ/* +/* +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ From 6e8707d4a3026675b27267104ce0c1bf9c273670 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 24 May 2017 01:50:21 +0200 Subject: [PATCH 10/54] Removed TRUE and FALSE usages --- ext/standard/php_uuid.h | 10 +++++----- ext/standard/uuid.c | 18 +++++++++--------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index a8eb765eb4693..bc462fa3fd1eb 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -1,4 +1,4 @@ -ο»Ώ/* +/* +----------------------------------------------------------------------+ | PHP Version 7 | +----------------------------------------------------------------------+ @@ -296,7 +296,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ * @param[in] input_len * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. */ -#define php_uuid_parse_silent(uuid, input, input_len) php_uuid_parse(uuid, input, input_len, FALSE) +#define php_uuid_parse_silent(uuid, input, input_len) php_uuid_parse(uuid, input, input_len, 0) /** * Parse the string as UUID and throw PHP exceptions on failures. @@ -307,7 +307,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ * @param[in] input_len * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. */ -#define php_uuid_parse_throw(uuid, input, input_len) php_uuid_parse(uuid, input, input_len, TRUE) +#define php_uuid_parse_throw(uuid, input, input_len) php_uuid_parse(uuid, input, input_len, 1) /** * Create version 3 UUID. @@ -402,7 +402,7 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); * @return `SUCCESS` if the generation succeeded, `FAILURE` if it was not * possible to gather sufficient entropy. */ -#define php_uuid_create_v4_silent(uuid) php_uuid_create_v4(uuid, FALSE) +#define php_uuid_create_v4_silent(uuid) php_uuid_create_v4(uuid, 0) /** * Create version 4 UUID and throw PHP exception if it is not possible to @@ -413,7 +413,7 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); * @return `SUCCESS` if the generation succeeded, `FAILURE` if it was not * possible to gather sufficient entropy. */ -#define php_uuid_create_v4_throw(uuid) php_uuid_create_v4(uuid, TRUE) +#define php_uuid_create_v4_throw(uuid) php_uuid_create_v4(uuid, 1) /** * Create version 5 UUID. diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 0db7e66cec3b7..949158100f4b4 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -138,7 +138,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ } if ((limit - position + 1) < PHP_UUID_HEX_LEN) { - if (throw == TRUE) { + if (throw) { throw_uuid_parsing_exception_invalid_len(input, input_len, position, limit - position + 1); } return FAILURE; @@ -162,7 +162,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ continue; } else { - if (throw == TRUE) { + if (throw) { throw_uuid_parsing_exception_invalid_char(input, input_len, position); } return FAILURE; @@ -186,14 +186,14 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ continue; } else { - if (throw == TRUE) { + if (throw) { throw_uuid_parsing_exception_invalid_char(input, input_len, position); } return FAILURE; } if (digit > PHP_UUID_HEX_LEN) { - if (throw == TRUE) { + if (throw) { throw_uuid_parsing_exception( input, input_len, @@ -212,7 +212,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ } if (digit < PHP_UUID_HEX_LEN) { - if (throw == TRUE) { + if (throw) { throw_uuid_parsing_exception_invalid_len(input, input_len, position, digit); } return FAILURE; @@ -428,7 +428,7 @@ PHP_MINIT_FUNCTION(uuid) static zend_always_inline php_uuid *get_bytes(zval *object) { - return (php_uuid *) Z_STRVAL_P(zend_read_property(php_ce_UUID, object, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, TRUE, NULL)); + return (php_uuid *) Z_STRVAL_P(zend_read_property(php_ce_UUID, object, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, 1, NULL)); } static zend_always_inline void new_uuid(zval *object, const php_uuid uuid) @@ -541,7 +541,7 @@ PHP_METHOD(UUID, __set) { zend_throw_error(zend_ce_error, "Cannot set dynamic PHP_METHOD(UUID, __wakeup) { - size_t len = Z_STRLEN_P(zend_read_property(php_ce_UUID, &EX(This), UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, TRUE, NULL)); + size_t len = Z_STRLEN_P(zend_read_property(php_ce_UUID, &EX(This), UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, 1, NULL)); if (len != PHP_UUID_LEN) { zend_throw_exception_ex( @@ -627,7 +627,7 @@ PHP_METHOD(UUIDParsingException, getInput) &EX(This), UUID_EX_INPUT_PROP, UUID_EX_INPUT_PROP_LEN, - TRUE, + 1, NULL ), 1, 0); } @@ -640,7 +640,7 @@ PHP_METHOD(UUIDParsingException, getPosition) &EX(This), UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, - TRUE, + 1, NULL ), 1, 0); } From d6dc0f9ebff207e584278e973459467dbff047aa Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 24 May 2017 01:52:22 +0200 Subject: [PATCH 11/54] Reverted whitespace change --- ext/standard/basic_functions.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c index 33b263e19f354..9343bde5de624 100644 --- a/ext/standard/basic_functions.c +++ b/ext/standard/basic_functions.c @@ -4041,7 +4041,7 @@ PHP_FUNCTION(long2ip) ********************/ /* {{{ proto string getenv(string varname[, bool local_only] - Get the value of an environment variable or every available environment variable + Get the value of an environment variable or every available environment variable if no varname is present */ PHP_FUNCTION(getenv) { From 92f0ce613d6c427492afeeeae6b4b9372ba958b7 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 24 May 2017 01:53:43 +0200 Subject: [PATCH 12/54] Changed encoding back to ANSI Thanks Visual Studio ;( --- Zend/zend_API.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zend/zend_API.h b/Zend/zend_API.h index 59d7c29747bde..7fb398565fade 100644 --- a/Zend/zend_API.h +++ b/Zend/zend_API.h @@ -1,4 +1,4 @@ -ο»Ώ/* +/* +----------------------------------------------------------------------+ | Zend Engine | +----------------------------------------------------------------------+ From a6b1ceb1cce43b7c81932e57e66e8d9ccc8ea55f Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 24 May 2017 12:43:05 +0200 Subject: [PATCH 13/54] C89 compatibility: moved decls to top --- ext/standard/uuid.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 949158100f4b4..48ee877a4f7b2 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -380,6 +380,24 @@ PHP_MINIT_FUNCTION(uuid) PHP_FE_END }; + ZEND_BEGIN_ARG_INFO_EX(UUIDParsingException___construct_args, NULL, 0, 2) + ZEND_ARG_TYPE_INFO(0, reason, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, position, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, previous, Throwable, 1) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParsingException_getInput_args, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParsingException_getPosition_args, IS_LONG, 0) + ZEND_END_ARG_INFO(); + + static const zend_function_entry uuid_parsing_exception_methods[] = { + PHP_ME(UUIDParsingException, __construct, UUIDParsingException___construct_args, ZEND_ACC_PUBLIC) + PHP_ME(UUIDParsingException, getInput, UUIDParsingException_getInput_args, ZEND_ACC_PUBLIC) + PHP_ME(UUIDParsingException, getPosition, UUIDParsingException_getPosition_args, ZEND_ACC_PUBLIC) + PHP_FE_END + }; + INIT_CLASS_ENTRY(ce, "UUID", uuid_methods); php_ce_UUID = zend_register_internal_class(&ce); php_ce_UUID->ce_flags |= ZEND_ACC_FINAL; @@ -397,24 +415,6 @@ PHP_MINIT_FUNCTION(uuid) zend_declare_property_null(php_ce_UUID, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, ZEND_ACC_PRIVATE); - ZEND_BEGIN_ARG_INFO_EX(UUIDParsingException___construct_args, NULL, 0, 2) - ZEND_ARG_TYPE_INFO(0, reason, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, position, IS_LONG, 0) - ZEND_ARG_OBJ_INFO(0, previous, Throwable, 1) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParsingException_getInput_args, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParsingException_getPosition_args, IS_LONG, 0) - ZEND_END_ARG_INFO(); - - static const zend_function_entry uuid_parsing_exception_methods[] = { - PHP_ME(UUIDParsingException, __construct, UUIDParsingException___construct_args, ZEND_ACC_PUBLIC) - PHP_ME(UUIDParsingException, getInput, UUIDParsingException_getInput_args, ZEND_ACC_PUBLIC) - PHP_ME(UUIDParsingException, getPosition, UUIDParsingException_getPosition_args, ZEND_ACC_PUBLIC) - PHP_FE_END - }; - INIT_CLASS_ENTRY(ce, "UUIDParsingException", uuid_parsing_exception_methods); php_ce_UUIDParsingException = zend_register_internal_class_ex(&ce, zend_ce_exception); php_ce_UUIDParsingException->ce_flags |= ZEND_ACC_FINAL; From 18bf284aa9455c52e90d9efe13034386d3aac85d Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 24 May 2017 13:42:37 +0200 Subject: [PATCH 14/54] Renamed UUIDParsingException to UUIDParseException --- ext/standard/php_uuid.h | 14 ++-- ext/standard/stubs/UUID.php | 4 +- ...ngException.php => UUIDParseException.php} | 12 ++-- .../tests/uuid/UUID/parse/error-002.phpt | 4 +- .../tests/uuid/UUID/parse/error-003.phpt | 4 +- .../tests/uuid/UUID/parse/error-004.phpt | 4 +- .../__construct/definition-001.phpt | 4 +- .../__construct/definition-002.phpt | 4 +- .../__construct/definition-003.phpt | 4 +- .../__construct/definition-004.phpt | 4 +- .../__construct/definition-005.phpt | 4 +- .../__construct/error-001.phpt | 17 +++++ .../__construct/error-002.phpt | 17 +++++ .../__construct/variation-001.phpt | 6 +- .../__construct/variation-002.phpt | 6 +- .../__construct/variation-003.phpt | 6 +- .../basic.phpt | 4 +- .../definition-001.phpt | 4 +- .../definition-002.phpt | 4 +- .../definition-003.phpt | 4 +- .../getInput/basic.phpt | 4 +- .../getInput/definition.phpt | 4 +- .../UUIDParseException/getPosition/basic.phpt | 12 ++++ .../getPosition/definition.phpt | 4 +- .../getPosition/variation.phpt | 4 +- .../variation-001.phpt | 4 +- .../variation-002.phpt | 4 +- .../variation-003.phpt | 4 +- .../__construct/error-001.phpt | 17 ----- .../__construct/error-002.phpt | 17 ----- .../getPosition/basic.phpt | 12 ---- ext/standard/uuid.c | 72 +++++++++---------- 32 files changed, 144 insertions(+), 144 deletions(-) rename ext/standard/stubs/{UUIDParsingException.php => UUIDParseException.php} (85%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/__construct/definition-001.phpt (68%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/__construct/definition-002.phpt (66%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/__construct/definition-003.phpt (66%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/__construct/definition-004.phpt (68%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/__construct/definition-005.phpt (68%) create mode 100644 ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt create mode 100644 ext/standard/tests/uuid/UUIDParseException/__construct/error-002.phpt rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/__construct/variation-001.phpt (59%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/__construct/variation-002.phpt (58%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/__construct/variation-003.phpt (65%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/basic.phpt (78%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/definition-001.phpt (75%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/definition-002.phpt (58%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/definition-003.phpt (56%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/getInput/basic.phpt (54%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/getInput/definition.phpt (74%) create mode 100644 ext/standard/tests/uuid/UUIDParseException/getPosition/basic.phpt rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/getPosition/definition.phpt (72%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/getPosition/variation.phpt (50%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/variation-001.phpt (71%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/variation-002.phpt (67%) rename ext/standard/tests/uuid/{UUIDParsingException => UUIDParseException}/variation-003.phpt (66%) delete mode 100644 ext/standard/tests/uuid/UUIDParsingException/__construct/error-001.phpt delete mode 100644 ext/standard/tests/uuid/UUIDParsingException/__construct/error-002.phpt delete mode 100644 ext/standard/tests/uuid/UUIDParsingException/getPosition/basic.phpt diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index bc462fa3fd1eb..1740ea2fe3cdf 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -113,8 +113,8 @@ /** UUID class entry for usage by other modules. */ PHPAPI extern zend_class_entry *php_ce_UUID; -/** UUIDParsingException class entry for usage by other modules. */ -PHPAPI extern zend_class_entry *php_ce_UUIDParsingException; +/** UUIDParseException class entry for usage by other modules. */ +PHPAPI extern zend_class_entry *php_ce_UUIDParseException; /** UUID binary representation to store the 128 bit number in 16 bytes. */ PHPAPI typedef uint8_t php_uuid[16]; @@ -587,12 +587,12 @@ PHP_METHOD(UUID, toHex); PHP_METHOD(UUID, toString); /** - * Final UUIDParsingException class methods (extends Exception). + * Final UUIDParseException class methods (extends Exception). * - * @see ext/standard/stubs/UUIDParsingException.php + * @see ext/standard/stubs/UUIDParseException.php */ -PHP_METHOD(UUIDParsingException, __construct); -PHP_METHOD(UUIDParsingException, getInput); -PHP_METHOD(UUIDParsingException, getPosition); +PHP_METHOD(UUIDParseException, __construct); +PHP_METHOD(UUIDParseException, getInput); +PHP_METHOD(UUIDParseException, getPosition); #endif /* PHP_UUID_H */ diff --git a/ext/standard/stubs/UUID.php b/ext/standard/stubs/UUID.php index ac9e859a75ca4..4b4c146972512 100644 --- a/ext/standard/stubs/UUID.php +++ b/ext/standard/stubs/UUID.php @@ -297,7 +297,7 @@ public static function fromBinary(string $input): UUID { } * try { * UUID::parse('urn:uuid:{01234567-89ab-cdef-0123-456789abcdef'); * } - * catch (UUIDParsingException $e) { + * catch (UUIDParseException $e) { * assert($e->getMessage() === 'Expected hexadecimal digit, but found * '{' (0x7b)'); * } @@ -311,7 +311,7 @@ public static function fromBinary(string $input): UUID { } * @see toString * @param string $input to parse as UUID and construct the instance from. * @return UUID constructed from the parsed input. - * @throws UUIDParsingException if parsing of the input fails. + * @throws UUIDParseException if parsing of the input fails. */ public static function parse(string $input): UUID { } diff --git a/ext/standard/stubs/UUIDParsingException.php b/ext/standard/stubs/UUIDParseException.php similarity index 85% rename from ext/standard/stubs/UUIDParsingException.php rename to ext/standard/stubs/UUIDParseException.php index 078ec35801987..ecdb9b3fcabb4 100644 --- a/ext/standard/stubs/UUIDParsingException.php +++ b/ext/standard/stubs/UUIDParseException.php @@ -1,6 +1,6 @@ getMessage(); // Expected at least 32 characters, but got 3 characters * echo $e->getInput(); // php * echo $e->getPosition(); // 0 @@ -25,7 +25,7 @@ * try { * UUID::parse('12345678-1234-1234-1234-123456789php'); * } - * catch (UUIDParsingException $e) { + * catch (UUIDParseException $e) { * echo $e->getMessage(); // Expected hexadecimal digit, but found 'p' (0x70) * echo $e->getInput(); // 12345678-1234-1234-1234-123456789php * echo $e->getPosition(); // 33 @@ -34,7 +34,7 @@ * try { * UUID::parse('12345678-1234-1234-1234-123456789abcdef'); * } - * catch (UUIDParsingException $e) { + * catch (UUIDParseException $e) { * echo $e->getMessage(); // Expected no more than 32 hexadecimal digits * echo $e->getInput(); // 12345678-1234-1234-1234-123456789abcdef * echo $e->getPosition(); // 37 @@ -45,7 +45,7 @@ * * @see \UUID::parse() */ -final class UUIDParsingException extends Exception { +final class UUIDParseException extends Exception { /** @var string */ private $input; @@ -53,7 +53,7 @@ final class UUIDParsingException extends Exception { private $position; /** - * Construct new UUID parsing exception instance. + * Construct new UUID parse exception instance. * * @param string $reason why parsing the UUID string failed. * @param string $input that should be parsed. diff --git a/ext/standard/tests/uuid/UUID/parse/error-002.phpt b/ext/standard/tests/uuid/UUID/parse/error-002.phpt index 26459970b1596..8c2059cb9d74a 100644 --- a/ext/standard/tests/uuid/UUID/parse/error-002.phpt +++ b/ext/standard/tests/uuid/UUID/parse/error-002.phpt @@ -1,5 +1,5 @@ --TEST-- -UUID::parse throws UUIDParsingException if there are less than 32 chars +UUID::parse throws UUIDParseException if there are less than 32 chars --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- @@ -15,7 +15,7 @@ foreach ([ try { UUID::parse($date); } - catch (UUIDParsingException $e) { + catch (UUIDParseException $e) { echo $e->getMessage() , "\n"; } } diff --git a/ext/standard/tests/uuid/UUID/parse/error-003.phpt b/ext/standard/tests/uuid/UUID/parse/error-003.phpt index 55bdb339f6751..4c462761fbba6 100644 --- a/ext/standard/tests/uuid/UUID/parse/error-003.phpt +++ b/ext/standard/tests/uuid/UUID/parse/error-003.phpt @@ -1,5 +1,5 @@ --TEST-- -UUID::parse throws UUIDParsingException for non-hexadecimal characters +UUID::parse throws UUIDParseException for non-hexadecimal characters --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- @@ -8,7 +8,7 @@ Richard Fussenegger php@fleshgrinder.com try { UUID::parse('01234567-89ab-cdef-0123-456789abcPHP'); } -catch (UUIDParsingException $e) { +catch (UUIDParseException $e) { echo $e->getMessage() , "\n"; } diff --git a/ext/standard/tests/uuid/UUID/parse/error-004.phpt b/ext/standard/tests/uuid/UUID/parse/error-004.phpt index 0eec3b8e2305a..3bdfc4150cb26 100644 --- a/ext/standard/tests/uuid/UUID/parse/error-004.phpt +++ b/ext/standard/tests/uuid/UUID/parse/error-004.phpt @@ -1,5 +1,5 @@ --TEST-- -UUID::parse throws UUIDParsingException if too many hexadecimal digits are found +UUID::parse throws UUIDParseException if too many hexadecimal digits are found --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- @@ -8,7 +8,7 @@ Richard Fussenegger php@fleshgrinder.com try { UUID::parse('12345678-1234-1234-1234-123456789abcdef'); } -catch (UUIDParsingException $e) { +catch (UUIDParseException $e) { echo $e->getMessage() , "\n"; } diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-001.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-001.phpt similarity index 68% rename from ext/standard/tests/uuid/UUIDParsingException/__construct/definition-001.phpt rename to ext/standard/tests/uuid/UUIDParseException/__construct/definition-001.phpt index bf369e0c3c304..884a02ec9207c 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-001.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-001.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException::__construct method signature +UUIDParseException::__construct method signature --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getNumberOfParameters(), diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-002.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-002.phpt similarity index 66% rename from ext/standard/tests/uuid/UUIDParsingException/__construct/definition-002.phpt rename to ext/standard/tests/uuid/UUIDParseException/__construct/definition-002.phpt index bdc69d96fe4c4..b6b3c6dddd956 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-002.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-002.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException::__construct 1. parameter definition +UUIDParseException::__construct 1. parameter definition --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getParameters()[0]; +$p = (new ReflectionMethod(UUIDParseException::class, '__construct'))->getParameters()[0]; var_dump( $p->getName(), diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-003.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-003.phpt similarity index 66% rename from ext/standard/tests/uuid/UUIDParsingException/__construct/definition-003.phpt rename to ext/standard/tests/uuid/UUIDParseException/__construct/definition-003.phpt index 130d60a4be99f..04d7f1e4a0939 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-003.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-003.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException::__construct 2. parameter definition +UUIDParseException::__construct 2. parameter definition --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getParameters()[1]; +$p = (new ReflectionMethod(UUIDParseException::class, '__construct'))->getParameters()[1]; var_dump( $p->getName(), diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-004.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-004.phpt similarity index 68% rename from ext/standard/tests/uuid/UUIDParsingException/__construct/definition-004.phpt rename to ext/standard/tests/uuid/UUIDParseException/__construct/definition-004.phpt index e86e4e9e44b49..411cca79668ef 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-004.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-004.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException::__construct 3. parameter definition +UUIDParseException::__construct 3. parameter definition --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getParameters()[2]; +$p = (new ReflectionMethod(UUIDParseException::class, '__construct'))->getParameters()[2]; var_dump( $p->getName(), diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-005.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-005.phpt similarity index 68% rename from ext/standard/tests/uuid/UUIDParsingException/__construct/definition-005.phpt rename to ext/standard/tests/uuid/UUIDParseException/__construct/definition-005.phpt index f02fdace419bc..17fa814f654c7 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/__construct/definition-005.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-005.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException::__construct 4. parameter definition +UUIDParseException::__construct 4. parameter definition --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getParameters()[3]; +$p = (new ReflectionMethod(UUIDParseException::class, '__construct'))->getParameters()[3]; var_dump( $p->getName(), diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt new file mode 100644 index 0000000000000..942d4dfc2dadf --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUIDParseException::__construct ArgumentCountError with 0 arguments +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage(); +} + +?> +--EXPECT-- +Too few arguments to method UUIDParseException::__construct(), 0 passed and at least 2 expected diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/error-002.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/error-002.phpt new file mode 100644 index 0000000000000..8c703575c589c --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/error-002.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUIDParseException::__construct ArgumentCountError with 1 argument +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage(); +} + +?> +--EXPECT-- +Too few arguments to method UUIDParseException::__construct(), 1 passed and at least 2 expected diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-001.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/variation-001.phpt similarity index 59% rename from ext/standard/tests/uuid/UUIDParsingException/__construct/variation-001.phpt rename to ext/standard/tests/uuid/UUIDParseException/__construct/variation-001.phpt index 007a62ee75b32..87477ecd05cb8 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-001.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/variation-001.phpt @@ -1,14 +1,14 @@ --TEST-- -UUIDParsingException::__construct with 2 arguments +UUIDParseException::__construct with 2 arguments --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- setAccessible(true); var_dump($p->getValue($e)); } diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-002.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/variation-002.phpt similarity index 58% rename from ext/standard/tests/uuid/UUIDParsingException/__construct/variation-002.phpt rename to ext/standard/tests/uuid/UUIDParseException/__construct/variation-002.phpt index f0277d2bf2657..ad292c6f6ccfa 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-002.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/variation-002.phpt @@ -1,14 +1,14 @@ --TEST-- -UUIDParsingException::__construct with 3 arguments +UUIDParseException::__construct with 3 arguments --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- setAccessible(true); var_dump($p->getValue($e)); } diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-003.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/variation-003.phpt similarity index 65% rename from ext/standard/tests/uuid/UUIDParsingException/__construct/variation-003.phpt rename to ext/standard/tests/uuid/UUIDParseException/__construct/variation-003.phpt index 7374001656d39..b34f8da595304 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/__construct/variation-003.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/variation-003.phpt @@ -1,14 +1,14 @@ --TEST-- -UUIDParsingException::__construct with 4 arguments +UUIDParseException::__construct with 4 arguments --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- setAccessible(true); var_dump($p->getValue($e)); } diff --git a/ext/standard/tests/uuid/UUIDParsingException/basic.phpt b/ext/standard/tests/uuid/UUIDParseException/basic.phpt similarity index 78% rename from ext/standard/tests/uuid/UUIDParsingException/basic.phpt rename to ext/standard/tests/uuid/UUIDParseException/basic.phpt index 48683f2a3048c..a2f629f3f7581 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/basic.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/basic.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException construction +UUIDParseException construction --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getCode(), diff --git a/ext/standard/tests/uuid/UUIDParsingException/definition-001.phpt b/ext/standard/tests/uuid/UUIDParseException/definition-001.phpt similarity index 75% rename from ext/standard/tests/uuid/UUIDParsingException/definition-001.phpt rename to ext/standard/tests/uuid/UUIDParseException/definition-001.phpt index 36f7ef57af501..8d1d40084b9aa 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/definition-001.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/definition-001.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException class definition. +UUIDParseException class definition. --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- isAbstract(), diff --git a/ext/standard/tests/uuid/UUIDParsingException/definition-002.phpt b/ext/standard/tests/uuid/UUIDParseException/definition-002.phpt similarity index 58% rename from ext/standard/tests/uuid/UUIDParsingException/definition-002.phpt rename to ext/standard/tests/uuid/UUIDParseException/definition-002.phpt index 32355b7d1f9e9..42a68160b82e2 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/definition-002.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/definition-002.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException input property definition. +UUIDParseException input property definition. --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- isPrivate(), $p->isStatic()); diff --git a/ext/standard/tests/uuid/UUIDParsingException/definition-003.phpt b/ext/standard/tests/uuid/UUIDParseException/definition-003.phpt similarity index 56% rename from ext/standard/tests/uuid/UUIDParsingException/definition-003.phpt rename to ext/standard/tests/uuid/UUIDParseException/definition-003.phpt index 9ab53628391dc..7f55019bb2030 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/definition-003.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/definition-003.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException position property definition. +UUIDParseException position property definition. --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- isPrivate(), $p->isStatic()); diff --git a/ext/standard/tests/uuid/UUIDParsingException/getInput/basic.phpt b/ext/standard/tests/uuid/UUIDParseException/getInput/basic.phpt similarity index 54% rename from ext/standard/tests/uuid/UUIDParsingException/getInput/basic.phpt rename to ext/standard/tests/uuid/UUIDParseException/getInput/basic.phpt index 6f0343c8adc75..c16dc8579db77 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/getInput/basic.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/getInput/basic.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException::getInput +UUIDParseException::getInput --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getInput()); +var_dump((new UUIDParseException('', 'input-test'))->getInput()); ?> --EXPECT-- diff --git a/ext/standard/tests/uuid/UUIDParsingException/getInput/definition.phpt b/ext/standard/tests/uuid/UUIDParseException/getInput/definition.phpt similarity index 74% rename from ext/standard/tests/uuid/UUIDParsingException/getInput/definition.phpt rename to ext/standard/tests/uuid/UUIDParseException/getInput/definition.phpt index 0cc63279870b0..c640f6fba66b4 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/getInput/definition.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/getInput/definition.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException::getInput method signature +UUIDParseException::getInput method signature --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getNumberOfParameters(), diff --git a/ext/standard/tests/uuid/UUIDParseException/getPosition/basic.phpt b/ext/standard/tests/uuid/UUIDParseException/getPosition/basic.phpt new file mode 100644 index 0000000000000..674bf8262a383 --- /dev/null +++ b/ext/standard/tests/uuid/UUIDParseException/getPosition/basic.phpt @@ -0,0 +1,12 @@ +--TEST-- +UUIDParseException::getPosition default value +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getPosition()); + +?> +--EXPECT-- +int(0) diff --git a/ext/standard/tests/uuid/UUIDParsingException/getPosition/definition.phpt b/ext/standard/tests/uuid/UUIDParseException/getPosition/definition.phpt similarity index 72% rename from ext/standard/tests/uuid/UUIDParsingException/getPosition/definition.phpt rename to ext/standard/tests/uuid/UUIDParseException/getPosition/definition.phpt index d78a7d08b48a3..e74c8e7bcf77f 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/getPosition/definition.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/getPosition/definition.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException::getPosition method signature +UUIDParseException::getPosition method signature --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getNumberOfParameters(), diff --git a/ext/standard/tests/uuid/UUIDParsingException/getPosition/variation.phpt b/ext/standard/tests/uuid/UUIDParseException/getPosition/variation.phpt similarity index 50% rename from ext/standard/tests/uuid/UUIDParsingException/getPosition/variation.phpt rename to ext/standard/tests/uuid/UUIDParseException/getPosition/variation.phpt index 9fcfe859bf793..ef598fa8ed1b7 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/getPosition/variation.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/getPosition/variation.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException::getPosition +UUIDParseException::getPosition --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getPosition()); +var_dump((new UUIDParseException('', '', 42))->getPosition()); ?> --EXPECT-- diff --git a/ext/standard/tests/uuid/UUIDParsingException/variation-001.phpt b/ext/standard/tests/uuid/UUIDParseException/variation-001.phpt similarity index 71% rename from ext/standard/tests/uuid/UUIDParsingException/variation-001.phpt rename to ext/standard/tests/uuid/UUIDParseException/variation-001.phpt index 997ae97796d6f..78a5a125b7a46 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/variation-001.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/variation-001.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException construction with custom position +UUIDParseException construction with custom position --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getCode(), diff --git a/ext/standard/tests/uuid/UUIDParsingException/variation-002.phpt b/ext/standard/tests/uuid/UUIDParseException/variation-002.phpt similarity index 67% rename from ext/standard/tests/uuid/UUIDParsingException/variation-002.phpt rename to ext/standard/tests/uuid/UUIDParseException/variation-002.phpt index 6b298122ddfef..93356613fec77 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/variation-002.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/variation-002.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException construction with custom position and previous error +UUIDParseException construction with custom position and previous error --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getCode(), diff --git a/ext/standard/tests/uuid/UUIDParsingException/variation-003.phpt b/ext/standard/tests/uuid/UUIDParseException/variation-003.phpt similarity index 66% rename from ext/standard/tests/uuid/UUIDParsingException/variation-003.phpt rename to ext/standard/tests/uuid/UUIDParseException/variation-003.phpt index 5c6c49cc3e75e..0f2ca7360ca00 100644 --- a/ext/standard/tests/uuid/UUIDParsingException/variation-003.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/variation-003.phpt @@ -1,11 +1,11 @@ --TEST-- -UUIDParsingException construction with custom position and previous exception +UUIDParseException construction with custom position and previous exception --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getCode(), diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/error-001.phpt b/ext/standard/tests/uuid/UUIDParsingException/__construct/error-001.phpt deleted file mode 100644 index 7902d908b4401..0000000000000 --- a/ext/standard/tests/uuid/UUIDParsingException/__construct/error-001.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -UUIDParsingException::__construct ArgumentCountError with 0 arguments ---CREDITS-- -Richard Fussenegger php@fleshgrinder.com ---FILE-- -getMessage(); -} - -?> ---EXPECT-- -Too few arguments to method UUIDParsingException::__construct(), 0 passed and at least 2 expected diff --git a/ext/standard/tests/uuid/UUIDParsingException/__construct/error-002.phpt b/ext/standard/tests/uuid/UUIDParsingException/__construct/error-002.phpt deleted file mode 100644 index d250c38baaf04..0000000000000 --- a/ext/standard/tests/uuid/UUIDParsingException/__construct/error-002.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -UUIDParsingException::__construct ArgumentCountError with 1 argument ---CREDITS-- -Richard Fussenegger php@fleshgrinder.com ---FILE-- -getMessage(); -} - -?> ---EXPECT-- -Too few arguments to method UUIDParsingException::__construct(), 1 passed and at least 2 expected diff --git a/ext/standard/tests/uuid/UUIDParsingException/getPosition/basic.phpt b/ext/standard/tests/uuid/UUIDParsingException/getPosition/basic.phpt deleted file mode 100644 index fabcfc37a7a9e..0000000000000 --- a/ext/standard/tests/uuid/UUIDParsingException/getPosition/basic.phpt +++ /dev/null @@ -1,12 +0,0 @@ ---TEST-- -UUIDParsingException::getPosition default value ---CREDITS-- -Richard Fussenegger php@fleshgrinder.com ---FILE-- -getPosition()); - -?> ---EXPECT-- -int(0) diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 48ee877a4f7b2..08f1c14bafe0f 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -30,7 +30,7 @@ #endif PHPAPI zend_class_entry *php_ce_UUID; -PHPAPI zend_class_entry *php_ce_UUIDParsingException; +PHPAPI zend_class_entry *php_ce_UUIDParseException; PHPAPI const php_uuid PHP_UUID_NAMESPACE_DNS = "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"; PHPAPI const php_uuid PHP_UUID_NAMESPACE_OID = "\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"; @@ -73,7 +73,7 @@ static zend_always_inline void php_uuid_set_version(php_uuid *uuid, const uint8_ (*uuid)[6] = ((*uuid)[6] & 0x0F) | (version << 4); } -static ZEND_COLD zend_object *throw_uuid_parsing_exception(const char *input, const size_t input_len, const size_t position, const char *reason, ...) +static ZEND_COLD zend_object *throw_uuid_parse_exception(const char *input, const size_t input_len, const size_t position, const char *reason, ...) { va_list format_args; char *formatted_reason; @@ -83,19 +83,19 @@ static ZEND_COLD zend_object *throw_uuid_parsing_exception(const char *input, co va_start(format_args, reason); zend_vspprintf(&formatted_reason, 0, reason, format_args); va_end(format_args); - object = zend_throw_exception(php_ce_UUIDParsingException, formatted_reason, 0); + object = zend_throw_exception(php_ce_UUIDParseException, formatted_reason, 0); efree(formatted_reason); ZVAL_OBJ(&exception, object); - zend_update_property_stringl(php_ce_UUIDParsingException, &exception, UUID_EX_INPUT_PROP, UUID_EX_INPUT_PROP_LEN, input, input_len); - zend_update_property_long(php_ce_UUIDParsingException, &exception, UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, position); + zend_update_property_stringl(php_ce_UUIDParseException, &exception, UUID_EX_INPUT_PROP, UUID_EX_INPUT_PROP_LEN, input, input_len); + zend_update_property_long(php_ce_UUIDParseException, &exception, UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, position); return object; } -static zend_always_inline zend_object *throw_uuid_parsing_exception_invalid_len(const char *input, const size_t input_len, const size_t position, const size_t actual) +static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_len(const char *input, const size_t input_len, const size_t position, const size_t actual) { - return throw_uuid_parsing_exception( + return throw_uuid_parse_exception( input, input_len, position, @@ -105,9 +105,9 @@ static zend_always_inline zend_object *throw_uuid_parsing_exception_invalid_len( ); } -static zend_always_inline zend_object *throw_uuid_parsing_exception_invalid_char(const char *input, const size_t input_len, const size_t position) +static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_char(const char *input, const size_t input_len, const size_t position) { - return throw_uuid_parsing_exception( + return throw_uuid_parse_exception( input, input_len, position, @@ -139,7 +139,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ if ((limit - position + 1) < PHP_UUID_HEX_LEN) { if (throw) { - throw_uuid_parsing_exception_invalid_len(input, input_len, position, limit - position + 1); + throw_uuid_parse_exception_invalid_len(input, input_len, position, limit - position + 1); } return FAILURE; } @@ -163,7 +163,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ } else { if (throw) { - throw_uuid_parsing_exception_invalid_char(input, input_len, position); + throw_uuid_parse_exception_invalid_char(input, input_len, position); } return FAILURE; } @@ -187,14 +187,14 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ } else { if (throw) { - throw_uuid_parsing_exception_invalid_char(input, input_len, position); + throw_uuid_parse_exception_invalid_char(input, input_len, position); } return FAILURE; } if (digit > PHP_UUID_HEX_LEN) { if (throw) { - throw_uuid_parsing_exception( + throw_uuid_parse_exception( input, input_len, position, @@ -213,7 +213,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ if (digit < PHP_UUID_HEX_LEN) { if (throw) { - throw_uuid_parsing_exception_invalid_len(input, input_len, position, digit); + throw_uuid_parse_exception_invalid_len(input, input_len, position, digit); } return FAILURE; } @@ -380,21 +380,21 @@ PHP_MINIT_FUNCTION(uuid) PHP_FE_END }; - ZEND_BEGIN_ARG_INFO_EX(UUIDParsingException___construct_args, NULL, 0, 2) + ZEND_BEGIN_ARG_INFO_EX(UUIDParseException___construct_args, NULL, 0, 2) ZEND_ARG_TYPE_INFO(0, reason, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) ZEND_ARG_TYPE_INFO(0, position, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, previous, Throwable, 1) ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParsingException_getInput_args, IS_STRING, 0) + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getInput_args, IS_STRING, 0) ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParsingException_getPosition_args, IS_LONG, 0) + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getPosition_args, IS_LONG, 0) ZEND_END_ARG_INFO(); - static const zend_function_entry uuid_parsing_exception_methods[] = { - PHP_ME(UUIDParsingException, __construct, UUIDParsingException___construct_args, ZEND_ACC_PUBLIC) - PHP_ME(UUIDParsingException, getInput, UUIDParsingException_getInput_args, ZEND_ACC_PUBLIC) - PHP_ME(UUIDParsingException, getPosition, UUIDParsingException_getPosition_args, ZEND_ACC_PUBLIC) + static const zend_function_entry uuid_parse_exception_methods[] = { + PHP_ME(UUIDParseException, __construct, UUIDParseException___construct_args, ZEND_ACC_PUBLIC) + PHP_ME(UUIDParseException, getInput, UUIDParseException_getInput_args, ZEND_ACC_PUBLIC) + PHP_ME(UUIDParseException, getPosition, UUIDParseException_getPosition_args, ZEND_ACC_PUBLIC) PHP_FE_END }; @@ -415,13 +415,13 @@ PHP_MINIT_FUNCTION(uuid) zend_declare_property_null(php_ce_UUID, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, ZEND_ACC_PRIVATE); - INIT_CLASS_ENTRY(ce, "UUIDParsingException", uuid_parsing_exception_methods); - php_ce_UUIDParsingException = zend_register_internal_class_ex(&ce, zend_ce_exception); - php_ce_UUIDParsingException->ce_flags |= ZEND_ACC_FINAL; - php_ce_UUIDParsingException->create_object = zend_ce_exception->create_object; + INIT_CLASS_ENTRY(ce, "UUIDParseException", uuid_parse_exception_methods); + php_ce_UUIDParseException = zend_register_internal_class_ex(&ce, zend_ce_exception); + php_ce_UUIDParseException->ce_flags |= ZEND_ACC_FINAL; + php_ce_UUIDParseException->create_object = zend_ce_exception->create_object; - zend_declare_property_null(php_ce_UUIDParsingException, UUID_EX_INPUT_PROP, UUID_EX_INPUT_PROP_LEN, ZEND_ACC_PRIVATE); - zend_declare_property_null(php_ce_UUIDParsingException, UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, ZEND_ACC_PRIVATE); + zend_declare_property_null(php_ce_UUIDParseException, UUID_EX_INPUT_PROP, UUID_EX_INPUT_PROP_LEN, ZEND_ACC_PRIVATE); + zend_declare_property_null(php_ce_UUIDParseException, UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, ZEND_ACC_PRIVATE); return SUCCESS; } @@ -588,7 +588,7 @@ PHP_METHOD(UUID, toString) RETURN_STRINGL(buffer, PHP_UUID_STRING_LEN); } -PHP_METHOD(UUIDParsingException, __construct) +PHP_METHOD(UUIDParseException, __construct) { zval *reason = NULL; zval *input = NULL; @@ -599,20 +599,20 @@ PHP_METHOD(UUIDParsingException, __construct) zend_throw_exception_ex( zend_ce_argument_count_error, 0, - "Too few arguments to method UUIDParsingException::__construct(), %u passed and at least 2 expected", + "Too few arguments to method UUIDParseException::__construct(), %u passed and at least 2 expected", ZEND_NUM_ARGS() ); return; } zend_update_property_ex(zend_ce_exception, &EX(This), ZSTR_KNOWN(ZEND_STR_MESSAGE), reason); - zend_update_property(php_ce_UUIDParsingException, &EX(This), UUID_EX_INPUT_PROP, UUID_EX_INPUT_PROP_LEN, input); + zend_update_property(php_ce_UUIDParseException, &EX(This), UUID_EX_INPUT_PROP, UUID_EX_INPUT_PROP_LEN, input); if (position != NULL) { - zend_update_property(php_ce_UUIDParsingException, &EX(This), UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, position); + zend_update_property(php_ce_UUIDParseException, &EX(This), UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, position); } else { - zend_update_property_long(php_ce_UUIDParsingException, &EX(This), UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, 0); + zend_update_property_long(php_ce_UUIDParseException, &EX(This), UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, 0); } if (previous != NULL) { @@ -620,10 +620,10 @@ PHP_METHOD(UUIDParsingException, __construct) } } -PHP_METHOD(UUIDParsingException, getInput) +PHP_METHOD(UUIDParseException, getInput) { RETURN_ZVAL(zend_read_property( - php_ce_UUIDParsingException, + php_ce_UUIDParseException, &EX(This), UUID_EX_INPUT_PROP, UUID_EX_INPUT_PROP_LEN, @@ -633,10 +633,10 @@ PHP_METHOD(UUIDParsingException, getInput) } /* */ -PHP_METHOD(UUIDParsingException, getPosition) +PHP_METHOD(UUIDParseException, getPosition) { RETURN_ZVAL(zend_read_property( - php_ce_UUIDParsingException, + php_ce_UUIDParseException, &EX(This), UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, From edf2bd3aef306a0dcdf295ef8817a8b782ae287a Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 24 May 2017 20:46:32 +0200 Subject: [PATCH 15/54] Removed PHP_METHODs from header file This I did due to a comment by nikic about having them in the header is actually uselus. It required that I move the MINIT function to the bottom of the c file, otherwise the routines are undefined because the compiler cannot find them anymore. --- ext/standard/php_uuid.h | 35 ------ ext/standard/uuid.c | 246 ++++++++++++++++++++-------------------- 2 files changed, 123 insertions(+), 158 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index 1740ea2fe3cdf..5804cb3ed7682 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -560,39 +560,4 @@ PHPAPI zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const */ PHP_MINIT_FUNCTION(uuid); -/** - * Final UUID class methods. - * - * @see ext/standard/stubs/UUID.php - */ -PHP_METHOD(UUID, __construct); -PHP_METHOD(UUID, fromBinary); -PHP_METHOD(UUID, parse); -PHP_METHOD(UUID, v3); -PHP_METHOD(UUID, v4); -PHP_METHOD(UUID, v5); -PHP_METHOD(UUID, NamespaceDNS); -PHP_METHOD(UUID, NamespaceOID); -PHP_METHOD(UUID, NamespaceURL); -PHP_METHOD(UUID, NamespaceX500); -PHP_METHOD(UUID, Nil); -PHP_METHOD(UUID, __clone); -PHP_METHOD(UUID, __set); -PHP_METHOD(UUID, __wakeup); -PHP_METHOD(UUID, getVariant); -PHP_METHOD(UUID, getVersion); -PHP_METHOD(UUID, isNil); -PHP_METHOD(UUID, toBinary); -PHP_METHOD(UUID, toHex); -PHP_METHOD(UUID, toString); - -/** - * Final UUIDParseException class methods (extends Exception). - * - * @see ext/standard/stubs/UUIDParseException.php - */ -PHP_METHOD(UUIDParseException, __construct); -PHP_METHOD(UUIDParseException, getInput); -PHP_METHOD(UUIDParseException, getPosition); - #endif /* PHP_UUID_H */ diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 08f1c14bafe0f..df9f1ade17522 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -303,129 +303,6 @@ PHPAPI zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const ); } -PHP_MINIT_FUNCTION(uuid) -{ - zend_class_entry ce; - - ZEND_BEGIN_ARG_INFO(UUID___construct_args, NULL) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_fromBinary_args, 0, 1, UUID, 0) - ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, UUID, 0) - ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, UUID, 0) - ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) - ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_v4_args, UUID, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, UUID, 0) - ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) - ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, UUID, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, UUID, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, UUID, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, UUID, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, UUID, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_INFO(UUID___clone_args, NULL) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___set_args, IS_VOID, 0) - ZEND_ARG_INFO(0, _) - ZEND_ARG_INFO(0, __) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___wakeup_args, IS_VOID, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toHex_args, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toString_args, IS_STRING, 0) - ZEND_END_ARG_INFO(); - - static const zend_function_entry uuid_methods[] = { - PHP_ME(UUID, __construct, UUID___construct_args, ZEND_ACC_PRIVATE) - PHP_ME(UUID, fromBinary, UUID_fromBinary_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, parse, UUID_parse_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, v3, UUID_v3_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, v4, UUID_v4_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, v5, UUID_v5_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, NamespaceDNS, UUID_NamespaceDNS_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, NamespaceOID, UUID_NamespaceOID_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, NamespaceURL, UUID_NamespaceURL_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, NamespaceX500, UUID_NamespaceX500_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, Nil, UUID_Nil_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, __clone, UUID___clone_args, ZEND_ACC_PRIVATE) - PHP_ME(UUID, __set, UUID___set_args, ZEND_ACC_PUBLIC) - PHP_ME(UUID, __wakeup, UUID___wakeup_args, ZEND_ACC_PUBLIC) - PHP_ME(UUID, getVariant, UUID_getVariant_args, ZEND_ACC_PUBLIC) - PHP_ME(UUID, getVersion, UUID_getVersion_args, ZEND_ACC_PUBLIC) - PHP_ME(UUID, isNil, UUID_isNil_args, ZEND_ACC_PUBLIC) - PHP_ME(UUID, toBinary, UUID_toBinary_args, ZEND_ACC_PUBLIC) - PHP_ME(UUID, toHex, UUID_toHex_args, ZEND_ACC_PUBLIC) - PHP_ME(UUID, toString, UUID_toString_args, ZEND_ACC_PUBLIC) - PHP_FE_END - }; - - ZEND_BEGIN_ARG_INFO_EX(UUIDParseException___construct_args, NULL, 0, 2) - ZEND_ARG_TYPE_INFO(0, reason, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, position, IS_LONG, 0) - ZEND_ARG_OBJ_INFO(0, previous, Throwable, 1) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getInput_args, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getPosition_args, IS_LONG, 0) - ZEND_END_ARG_INFO(); - - static const zend_function_entry uuid_parse_exception_methods[] = { - PHP_ME(UUIDParseException, __construct, UUIDParseException___construct_args, ZEND_ACC_PUBLIC) - PHP_ME(UUIDParseException, getInput, UUIDParseException_getInput_args, ZEND_ACC_PUBLIC) - PHP_ME(UUIDParseException, getPosition, UUIDParseException_getPosition_args, ZEND_ACC_PUBLIC) - PHP_FE_END - }; - - INIT_CLASS_ENTRY(ce, "UUID", uuid_methods); - php_ce_UUID = zend_register_internal_class(&ce); - php_ce_UUID->ce_flags |= ZEND_ACC_FINAL; - - zend_declare_class_constant_long(php_ce_UUID, "VARIANT_NCS", sizeof("VARIANT_NCS") - 1, PHP_UUID_VARIANT_NCS); - zend_declare_class_constant_long(php_ce_UUID, "VARIANT_RFC4122", sizeof("VARIANT_RFC4122") - 1, PHP_UUID_VARIANT_RFC4122); - zend_declare_class_constant_long(php_ce_UUID, "VARIANT_MICROSOFT", sizeof("VARIANT_MICROSOFT") - 1, PHP_UUID_VARIANT_MICROSOFT); - zend_declare_class_constant_long(php_ce_UUID, "VARIANT_FUTURE_RESERVED", sizeof("VARIANT_FUTURE_RESERVED") - 1, PHP_UUID_VARIANT_FUTURE_RESERVED); - - zend_declare_class_constant_long(php_ce_UUID, "VERSION_1_TIME_BASED", sizeof("VERSION_1_TIME_BASED") - 1, PHP_UUID_VERSION_1_TIME_BASED); - zend_declare_class_constant_long(php_ce_UUID, "VERSION_2_DCE_SECURITY", sizeof("VERSION_2_DCE_SECURITY") - 1, PHP_UUID_VERSION_2_DCE_SECURITY); - zend_declare_class_constant_long(php_ce_UUID, "VERSION_3_NAME_BASED_MD5", sizeof("VERSION_3_NAME_BASED_MD5") - 1, PHP_UUID_VERSION_3_NAME_BASED_MD5); - zend_declare_class_constant_long(php_ce_UUID, "VERSION_4_RANDOM", sizeof("VERSION_4_RANDOM") - 1, PHP_UUID_VERSION_4_RANDOM); - zend_declare_class_constant_long(php_ce_UUID, "VERSION_5_NAME_BASED_SHA1", sizeof("VERSION_5_NAME_BASED_SHA1") - 1, PHP_UUID_VERSION_5_NAME_BASED_SHA1); - - zend_declare_property_null(php_ce_UUID, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, ZEND_ACC_PRIVATE); - - INIT_CLASS_ENTRY(ce, "UUIDParseException", uuid_parse_exception_methods); - php_ce_UUIDParseException = zend_register_internal_class_ex(&ce, zend_ce_exception); - php_ce_UUIDParseException->ce_flags |= ZEND_ACC_FINAL; - php_ce_UUIDParseException->create_object = zend_ce_exception->create_object; - - zend_declare_property_null(php_ce_UUIDParseException, UUID_EX_INPUT_PROP, UUID_EX_INPUT_PROP_LEN, ZEND_ACC_PRIVATE); - zend_declare_property_null(php_ce_UUIDParseException, UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, ZEND_ACC_PRIVATE); - - return SUCCESS; -} - static zend_always_inline php_uuid *get_bytes(zval *object) { return (php_uuid *) Z_STRVAL_P(zend_read_property(php_ce_UUID, object, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, 1, NULL)); @@ -644,3 +521,126 @@ PHP_METHOD(UUIDParseException, getPosition) NULL ), 1, 0); } + +PHP_MINIT_FUNCTION(uuid) +{ + zend_class_entry ce; + + ZEND_BEGIN_ARG_INFO(UUID___construct_args, NULL) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_fromBinary_args, 0, 1, UUID, 0) + ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, UUID, 0) + ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, UUID, 0) + ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_v4_args, UUID, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, UUID, 0) + ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, UUID, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, UUID, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, UUID, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, UUID, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, UUID, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_INFO(UUID___clone_args, NULL) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___set_args, IS_VOID, 0) + ZEND_ARG_INFO(0, _) + ZEND_ARG_INFO(0, __) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___wakeup_args, IS_VOID, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toHex_args, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toString_args, IS_STRING, 0) + ZEND_END_ARG_INFO(); + + static const zend_function_entry uuid_methods[] = { + PHP_ME(UUID, __construct, UUID___construct_args, ZEND_ACC_PRIVATE) + PHP_ME(UUID, fromBinary, UUID_fromBinary_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, parse, UUID_parse_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, v3, UUID_v3_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, v4, UUID_v4_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, v5, UUID_v5_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, NamespaceDNS, UUID_NamespaceDNS_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, NamespaceOID, UUID_NamespaceOID_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, NamespaceURL, UUID_NamespaceURL_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, NamespaceX500, UUID_NamespaceX500_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, Nil, UUID_Nil_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, __clone, UUID___clone_args, ZEND_ACC_PRIVATE) + PHP_ME(UUID, __set, UUID___set_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, __wakeup, UUID___wakeup_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, getVariant, UUID_getVariant_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, getVersion, UUID_getVersion_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, isNil, UUID_isNil_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, toBinary, UUID_toBinary_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, toHex, UUID_toHex_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, toString, UUID_toString_args, ZEND_ACC_PUBLIC) + PHP_FE_END + }; + + ZEND_BEGIN_ARG_INFO_EX(UUIDParseException___construct_args, NULL, 0, 2) + ZEND_ARG_TYPE_INFO(0, reason, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, position, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, previous, Throwable, 1) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getInput_args, IS_STRING, 0) + ZEND_END_ARG_INFO(); + ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getPosition_args, IS_LONG, 0) + ZEND_END_ARG_INFO(); + + static const zend_function_entry uuid_parse_exception_methods[] = { + PHP_ME(UUIDParseException, __construct, UUIDParseException___construct_args, ZEND_ACC_PUBLIC) + PHP_ME(UUIDParseException, getInput, UUIDParseException_getInput_args, ZEND_ACC_PUBLIC) + PHP_ME(UUIDParseException, getPosition, UUIDParseException_getPosition_args, ZEND_ACC_PUBLIC) + PHP_FE_END + }; + + INIT_CLASS_ENTRY(ce, "UUID", uuid_methods); + php_ce_UUID = zend_register_internal_class(&ce); + php_ce_UUID->ce_flags |= ZEND_ACC_FINAL; + + zend_declare_class_constant_long(php_ce_UUID, "VARIANT_NCS", sizeof("VARIANT_NCS") - 1, PHP_UUID_VARIANT_NCS); + zend_declare_class_constant_long(php_ce_UUID, "VARIANT_RFC4122", sizeof("VARIANT_RFC4122") - 1, PHP_UUID_VARIANT_RFC4122); + zend_declare_class_constant_long(php_ce_UUID, "VARIANT_MICROSOFT", sizeof("VARIANT_MICROSOFT") - 1, PHP_UUID_VARIANT_MICROSOFT); + zend_declare_class_constant_long(php_ce_UUID, "VARIANT_FUTURE_RESERVED", sizeof("VARIANT_FUTURE_RESERVED") - 1, PHP_UUID_VARIANT_FUTURE_RESERVED); + + zend_declare_class_constant_long(php_ce_UUID, "VERSION_1_TIME_BASED", sizeof("VERSION_1_TIME_BASED") - 1, PHP_UUID_VERSION_1_TIME_BASED); + zend_declare_class_constant_long(php_ce_UUID, "VERSION_2_DCE_SECURITY", sizeof("VERSION_2_DCE_SECURITY") - 1, PHP_UUID_VERSION_2_DCE_SECURITY); + zend_declare_class_constant_long(php_ce_UUID, "VERSION_3_NAME_BASED_MD5", sizeof("VERSION_3_NAME_BASED_MD5") - 1, PHP_UUID_VERSION_3_NAME_BASED_MD5); + zend_declare_class_constant_long(php_ce_UUID, "VERSION_4_RANDOM", sizeof("VERSION_4_RANDOM") - 1, PHP_UUID_VERSION_4_RANDOM); + zend_declare_class_constant_long(php_ce_UUID, "VERSION_5_NAME_BASED_SHA1", sizeof("VERSION_5_NAME_BASED_SHA1") - 1, PHP_UUID_VERSION_5_NAME_BASED_SHA1); + + zend_declare_property_null(php_ce_UUID, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, ZEND_ACC_PRIVATE); + + INIT_CLASS_ENTRY(ce, "UUIDParseException", uuid_parse_exception_methods); + php_ce_UUIDParseException = zend_register_internal_class_ex(&ce, zend_ce_exception); + php_ce_UUIDParseException->ce_flags |= ZEND_ACC_FINAL; + php_ce_UUIDParseException->create_object = zend_ce_exception->create_object; + + zend_declare_property_null(php_ce_UUIDParseException, UUID_EX_INPUT_PROP, UUID_EX_INPUT_PROP_LEN, ZEND_ACC_PRIVATE); + zend_declare_property_null(php_ce_UUIDParseException, UUID_EX_POSITION_PROP, UUID_EX_POSITON_PROP_LEN, ZEND_ACC_PRIVATE); + + return SUCCESS; +} From d2e56414f2dad2b2a42e440bc71f5808179d01d6 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 24 May 2017 20:59:57 +0200 Subject: [PATCH 16/54] Moved argument and function decls out of MINIT --- ext/standard/uuid.c | 182 ++++++++++++++++++++++---------------------- 1 file changed, 91 insertions(+), 91 deletions(-) diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index df9f1ade17522..171fcdcef1e5f 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -465,6 +465,79 @@ PHP_METHOD(UUID, toString) RETURN_STRINGL(buffer, PHP_UUID_STRING_LEN); } +ZEND_BEGIN_ARG_INFO(UUID___construct_args, NULL) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_fromBinary_args, 0, 1, UUID, 0) + ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, UUID, 0) + ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, UUID, 0) + ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_v4_args, UUID, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, UUID, 0) + ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, UUID, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, UUID, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, UUID, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, UUID, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, UUID, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO(UUID___clone_args, NULL) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___set_args, IS_VOID, 0) + ZEND_ARG_INFO(0, _) + ZEND_ARG_INFO(0, __) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___wakeup_args, IS_VOID, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toHex_args, IS_STRING, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toString_args, IS_STRING, 0) +ZEND_END_ARG_INFO() + +static const zend_function_entry uuid_methods[] = { + PHP_ME(UUID, __construct, UUID___construct_args, ZEND_ACC_PRIVATE) + PHP_ME(UUID, fromBinary, UUID_fromBinary_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, parse, UUID_parse_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, v3, UUID_v3_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, v4, UUID_v4_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, v5, UUID_v5_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, NamespaceDNS, UUID_NamespaceDNS_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, NamespaceOID, UUID_NamespaceOID_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, NamespaceURL, UUID_NamespaceURL_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, NamespaceX500, UUID_NamespaceX500_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, Nil, UUID_Nil_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) + PHP_ME(UUID, __clone, UUID___clone_args, ZEND_ACC_PRIVATE) + PHP_ME(UUID, __set, UUID___set_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, __wakeup, UUID___wakeup_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, getVariant, UUID_getVariant_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, getVersion, UUID_getVersion_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, isNil, UUID_isNil_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, toBinary, UUID_toBinary_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, toHex, UUID_toHex_args, ZEND_ACC_PUBLIC) + PHP_ME(UUID, toString, UUID_toString_args, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + PHP_METHOD(UUIDParseException, __construct) { zval *reason = NULL; @@ -522,101 +595,28 @@ PHP_METHOD(UUIDParseException, getPosition) ), 1, 0); } +ZEND_BEGIN_ARG_INFO_EX(UUIDParseException___construct_args, NULL, 0, 2) + ZEND_ARG_TYPE_INFO(0, reason, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, position, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, previous, Throwable, 1) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getInput_args, IS_STRING, 0) +ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getPosition_args, IS_LONG, 0) +ZEND_END_ARG_INFO() + +static const zend_function_entry uuid_parse_exception_methods[] = { + PHP_ME(UUIDParseException, __construct, UUIDParseException___construct_args, ZEND_ACC_PUBLIC) + PHP_ME(UUIDParseException, getInput, UUIDParseException_getInput_args, ZEND_ACC_PUBLIC) + PHP_ME(UUIDParseException, getPosition, UUIDParseException_getPosition_args, ZEND_ACC_PUBLIC) + PHP_FE_END +}; + PHP_MINIT_FUNCTION(uuid) { zend_class_entry ce; - ZEND_BEGIN_ARG_INFO(UUID___construct_args, NULL) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_fromBinary_args, 0, 1, UUID, 0) - ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, UUID, 0) - ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, UUID, 0) - ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) - ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_v4_args, UUID, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, UUID, 0) - ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) - ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, UUID, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, UUID, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, UUID, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, UUID, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, UUID, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_INFO(UUID___clone_args, NULL) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___set_args, IS_VOID, 0) - ZEND_ARG_INFO(0, _) - ZEND_ARG_INFO(0, __) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___wakeup_args, IS_VOID, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toHex_args, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toString_args, IS_STRING, 0) - ZEND_END_ARG_INFO(); - - static const zend_function_entry uuid_methods[] = { - PHP_ME(UUID, __construct, UUID___construct_args, ZEND_ACC_PRIVATE) - PHP_ME(UUID, fromBinary, UUID_fromBinary_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, parse, UUID_parse_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, v3, UUID_v3_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, v4, UUID_v4_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, v5, UUID_v5_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, NamespaceDNS, UUID_NamespaceDNS_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, NamespaceOID, UUID_NamespaceOID_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, NamespaceURL, UUID_NamespaceURL_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, NamespaceX500, UUID_NamespaceX500_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, Nil, UUID_Nil_args, ZEND_ACC_PUBLIC | ZEND_ACC_STATIC) - PHP_ME(UUID, __clone, UUID___clone_args, ZEND_ACC_PRIVATE) - PHP_ME(UUID, __set, UUID___set_args, ZEND_ACC_PUBLIC) - PHP_ME(UUID, __wakeup, UUID___wakeup_args, ZEND_ACC_PUBLIC) - PHP_ME(UUID, getVariant, UUID_getVariant_args, ZEND_ACC_PUBLIC) - PHP_ME(UUID, getVersion, UUID_getVersion_args, ZEND_ACC_PUBLIC) - PHP_ME(UUID, isNil, UUID_isNil_args, ZEND_ACC_PUBLIC) - PHP_ME(UUID, toBinary, UUID_toBinary_args, ZEND_ACC_PUBLIC) - PHP_ME(UUID, toHex, UUID_toHex_args, ZEND_ACC_PUBLIC) - PHP_ME(UUID, toString, UUID_toString_args, ZEND_ACC_PUBLIC) - PHP_FE_END - }; - - ZEND_BEGIN_ARG_INFO_EX(UUIDParseException___construct_args, NULL, 0, 2) - ZEND_ARG_TYPE_INFO(0, reason, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, position, IS_LONG, 0) - ZEND_ARG_OBJ_INFO(0, previous, Throwable, 1) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getInput_args, IS_STRING, 0) - ZEND_END_ARG_INFO(); - ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getPosition_args, IS_LONG, 0) - ZEND_END_ARG_INFO(); - - static const zend_function_entry uuid_parse_exception_methods[] = { - PHP_ME(UUIDParseException, __construct, UUIDParseException___construct_args, ZEND_ACC_PUBLIC) - PHP_ME(UUIDParseException, getInput, UUIDParseException_getInput_args, ZEND_ACC_PUBLIC) - PHP_ME(UUIDParseException, getPosition, UUIDParseException_getPosition_args, ZEND_ACC_PUBLIC) - PHP_FE_END - }; - INIT_CLASS_ENTRY(ce, "UUID", uuid_methods); php_ce_UUID = zend_register_internal_class(&ce); php_ce_UUID->ce_flags |= ZEND_ACC_FINAL; From aa5530c89feb581a23f2dcc9d13121c9ec28a4dc Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 24 May 2017 21:11:29 +0200 Subject: [PATCH 17/54] Removed custom ArgumentCountErrors There already is the `zend_parse_parameters_throw` function which does exactly the same thing in a consistent and standard way. This is much, much better. Many thanks to @nikic for pointing that out. --- .../tests/uuid/UUID/fromBinary/error-001.phpt | 2 +- .../tests/uuid/UUID/parse/error-001.phpt | 2 +- .../tests/uuid/UUID/v3/error-001.phpt | 2 +- .../tests/uuid/UUID/v3/error-002.phpt | 2 +- .../tests/uuid/UUID/v5/error-001.phpt | 2 +- .../tests/uuid/UUID/v5/error-002.phpt | 2 +- .../__construct/error-001.phpt | 2 +- .../__construct/error-002.phpt | 2 +- ext/standard/uuid.c | 32 +++---------------- 9 files changed, 13 insertions(+), 35 deletions(-) diff --git a/ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt b/ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt index ddff22d9923f8..340f2420609e6 100644 --- a/ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt +++ b/ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt @@ -14,4 +14,4 @@ catch (ArgumentCountError $e) { ?> --EXPECT-- -Too few arguments to method UUID::fromBinary(), 0 passed and exactly 1 expected +UUID::fromBinary() expects exactly 1 parameter, 0 given diff --git a/ext/standard/tests/uuid/UUID/parse/error-001.phpt b/ext/standard/tests/uuid/UUID/parse/error-001.phpt index fb93488873b1c..0e01875f80bd8 100644 --- a/ext/standard/tests/uuid/UUID/parse/error-001.phpt +++ b/ext/standard/tests/uuid/UUID/parse/error-001.phpt @@ -14,4 +14,4 @@ catch (ArgumentCountError $e) { ?> --EXPECT-- -Too few arguments to method UUID::parse(), 0 passed and exactly 1 expected +UUID::parse() expects exactly 1 parameter, 0 given diff --git a/ext/standard/tests/uuid/UUID/v3/error-001.phpt b/ext/standard/tests/uuid/UUID/v3/error-001.phpt index 4d78ee9b3c9d2..b600b320a9efe 100644 --- a/ext/standard/tests/uuid/UUID/v3/error-001.phpt +++ b/ext/standard/tests/uuid/UUID/v3/error-001.phpt @@ -14,4 +14,4 @@ catch (ArgumentCountError $e) { ?> --EXPECT-- -Too few arguments to method UUID::v3(), 0 passed and exactly 2 expected +UUID::v3() expects exactly 2 parameters, 0 given diff --git a/ext/standard/tests/uuid/UUID/v3/error-002.phpt b/ext/standard/tests/uuid/UUID/v3/error-002.phpt index c6921cd1e72c9..cee24e3f9506d 100644 --- a/ext/standard/tests/uuid/UUID/v3/error-002.phpt +++ b/ext/standard/tests/uuid/UUID/v3/error-002.phpt @@ -14,4 +14,4 @@ catch (ArgumentCountError $e) { ?> --EXPECT-- -Too few arguments to method UUID::v3(), 1 passed and exactly 2 expected +UUID::v3() expects exactly 2 parameters, 1 given diff --git a/ext/standard/tests/uuid/UUID/v5/error-001.phpt b/ext/standard/tests/uuid/UUID/v5/error-001.phpt index 167927083e25d..9646a7036df7e 100644 --- a/ext/standard/tests/uuid/UUID/v5/error-001.phpt +++ b/ext/standard/tests/uuid/UUID/v5/error-001.phpt @@ -14,4 +14,4 @@ catch (ArgumentCountError $e) { ?> --EXPECT-- -Too few arguments to method UUID::v5(), 0 passed and exactly 2 expected +UUID::v5() expects exactly 2 parameters, 0 given diff --git a/ext/standard/tests/uuid/UUID/v5/error-002.phpt b/ext/standard/tests/uuid/UUID/v5/error-002.phpt index d21b86a32de76..6b1fee467eac6 100644 --- a/ext/standard/tests/uuid/UUID/v5/error-002.phpt +++ b/ext/standard/tests/uuid/UUID/v5/error-002.phpt @@ -14,4 +14,4 @@ catch (ArgumentCountError $e) { ?> --EXPECT-- -Too few arguments to method UUID::v5(), 1 passed and exactly 2 expected +UUID::v5() expects exactly 2 parameters, 1 given diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt index 942d4dfc2dadf..455be21bba3e6 100644 --- a/ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt @@ -14,4 +14,4 @@ catch (ArgumentCountError $e) { ?> --EXPECT-- -Too few arguments to method UUIDParseException::__construct(), 0 passed and at least 2 expected +UUIDParseException::__construct() expects at least 2 parameters, 0 given diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/error-002.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/error-002.phpt index 8c703575c589c..7f0d0f4aa598f 100644 --- a/ext/standard/tests/uuid/UUIDParseException/__construct/error-002.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/error-002.phpt @@ -14,4 +14,4 @@ catch (ArgumentCountError $e) { ?> --EXPECT-- -Too few arguments to method UUIDParseException::__construct(), 1 passed and at least 2 expected +UUIDParseException::__construct() expects at least 2 parameters, 1 given diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 171fcdcef1e5f..75f63d463ceb1 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -314,18 +314,6 @@ static zend_always_inline void new_uuid(zval *object, const php_uuid uuid) zend_update_property_stringl(php_ce_UUID, object, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, uuid, PHP_UUID_LEN); } -static zend_always_inline zend_object *throw_argument_count_error(const char *method, const size_t passed, const size_t expected) -{ - return zend_throw_exception_ex( - zend_ce_argument_count_error, - 0, - "Too few arguments to method UUID::%s(), %u passed and exactly %u expected", - method, - passed, - expected - ); -} - PHP_METHOD(UUID, __construct) { /* NOOP */ } PHP_METHOD(UUID, fromBinary) @@ -333,8 +321,7 @@ PHP_METHOD(UUID, fromBinary) char *input = NULL; size_t input_len; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, MIN(1, ZEND_NUM_ARGS()), "s", &input, &input_len) == FAILURE) { - throw_argument_count_error("fromBinary", ZEND_NUM_ARGS(), 1); + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &input, &input_len) == FAILURE) { return; } @@ -358,8 +345,7 @@ PHP_METHOD(UUID, parse) size_t input_len; php_uuid uuid; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, MIN(ZEND_NUM_ARGS(), 1), "s", &input, &input_len) == FAILURE) { - throw_argument_count_error("parse", ZEND_NUM_ARGS(), 1); + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &input, &input_len) == FAILURE) { return; } @@ -374,8 +360,7 @@ PHP_METHOD(UUID, v3) size_t name_len; php_uuid uuid; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, MIN(ZEND_NUM_ARGS(), 2), "zs", &namespace, &name, &name_len) == FAILURE) { - throw_argument_count_error("v3", ZEND_NUM_ARGS(), 2); + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zs", &namespace, &name, &name_len) == FAILURE) { return; } @@ -398,8 +383,7 @@ PHP_METHOD(UUID, v5) size_t name_len; php_uuid uuid; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, MIN(ZEND_NUM_ARGS(), 2), "zs", &namespace, &name, &name_len) == FAILURE) { - throw_argument_count_error("v5", ZEND_NUM_ARGS(), 2); + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zs", &namespace, &name, &name_len) == FAILURE) { return; } @@ -545,13 +529,7 @@ PHP_METHOD(UUIDParseException, __construct) zval *position = NULL; zval *previous = NULL; - if (zend_parse_parameters_ex(ZEND_PARSE_PARAMS_QUIET, MIN(ZEND_NUM_ARGS(), 4), "zz|zz!", &reason, &input, &position, &previous) == FAILURE) { - zend_throw_exception_ex( - zend_ce_argument_count_error, - 0, - "Too few arguments to method UUIDParseException::__construct(), %u passed and at least 2 expected", - ZEND_NUM_ARGS() - ); + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zz|zz!", &reason, &input, &position, &previous) == FAILURE) { return; } From dce8a1cb36f53d63362056b53c73287873559a9d Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Thu, 25 May 2017 12:56:28 +0200 Subject: [PATCH 18/54] Moved arg info to their methods --- ext/standard/uuid.c | 156 ++++++++++++++++++++++++++------------------ 1 file changed, 91 insertions(+), 65 deletions(-) diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 75f63d463ceb1..b9e3390aead9f 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -314,7 +314,12 @@ static zend_always_inline void new_uuid(zval *object, const php_uuid uuid) zend_update_property_stringl(php_ce_UUID, object, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, uuid, PHP_UUID_LEN); } -PHP_METHOD(UUID, __construct) { /* NOOP */ } +PHP_METHOD(UUID, __construct) +{ + /* NOOP */ +} +ZEND_BEGIN_ARG_INFO(UUID___construct_args, NULL) +ZEND_END_ARG_INFO() PHP_METHOD(UUID, fromBinary) { @@ -338,6 +343,9 @@ PHP_METHOD(UUID, fromBinary) new_uuid(return_value, input); } +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_fromBinary_args, 0, 1, UUID, 0) + ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) +ZEND_END_ARG_INFO() PHP_METHOD(UUID, parse) { @@ -352,6 +360,9 @@ PHP_METHOD(UUID, parse) php_uuid_parse_throw(&uuid, input, input_len); new_uuid(return_value, uuid); } +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, UUID, 0) + ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) +ZEND_END_ARG_INFO() PHP_METHOD(UUID, v3) { @@ -367,6 +378,10 @@ PHP_METHOD(UUID, v3) php_uuid_create_v3(&uuid, get_bytes(namespace), name, name_len); new_uuid(return_value, uuid); } +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, UUID, 0) + ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) +ZEND_END_ARG_INFO() PHP_METHOD(UUID, v4) { @@ -375,6 +390,8 @@ PHP_METHOD(UUID, v4) new_uuid(return_value, uuid); } } +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_v4_args, UUID, 0) +ZEND_END_ARG_INFO() PHP_METHOD(UUID, v5) { @@ -390,15 +407,61 @@ PHP_METHOD(UUID, v5) php_uuid_create_v5(&uuid, get_bytes(namespace), name, name_len); new_uuid(return_value, uuid); } +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, UUID, 0) + ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) + ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) +ZEND_END_ARG_INFO() + +PHP_METHOD(UUID, NamespaceDNS) +{ + new_uuid(return_value, PHP_UUID_NAMESPACE_DNS); +} +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, UUID, 0) +ZEND_END_ARG_INFO() + +PHP_METHOD(UUID, NamespaceOID) +{ + new_uuid(return_value, PHP_UUID_NAMESPACE_OID); +} +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, UUID, 0) +ZEND_END_ARG_INFO() + +PHP_METHOD(UUID, NamespaceURL) +{ + new_uuid(return_value, PHP_UUID_NAMESPACE_URL); +} +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, UUID, 0) +ZEND_END_ARG_INFO() -PHP_METHOD(UUID, NamespaceDNS) { new_uuid(return_value, PHP_UUID_NAMESPACE_DNS); } -PHP_METHOD(UUID, NamespaceOID) { new_uuid(return_value, PHP_UUID_NAMESPACE_OID); } -PHP_METHOD(UUID, NamespaceURL) { new_uuid(return_value, PHP_UUID_NAMESPACE_URL); } -PHP_METHOD(UUID, NamespaceX500) { new_uuid(return_value, PHP_UUID_NAMESPACE_X500); } -PHP_METHOD(UUID, Nil) { new_uuid(return_value, PHP_UUID_NIL); } +PHP_METHOD(UUID, NamespaceX500) +{ + new_uuid(return_value, PHP_UUID_NAMESPACE_X500); +} +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, UUID, 0) +ZEND_END_ARG_INFO() -PHP_METHOD(UUID, __clone) { zend_throw_error(zend_ce_error, "Cannot clone immutable UUID object"); } -PHP_METHOD(UUID, __set) { zend_throw_error(zend_ce_error, "Cannot set dynamic properties on immutable UUID object"); } +PHP_METHOD(UUID, Nil) +{ + new_uuid(return_value, PHP_UUID_NIL); +} +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, UUID, 0) +ZEND_END_ARG_INFO() + +PHP_METHOD(UUID, __clone) +{ + zend_throw_error(zend_ce_error, "Cannot clone immutable UUID object"); +} +ZEND_BEGIN_ARG_INFO(UUID___clone_args, NULL) +ZEND_END_ARG_INFO() + +PHP_METHOD(UUID, __set) +{ + zend_throw_error(zend_ce_error, "Cannot set dynamic properties on immutable UUID object"); +} +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___set_args, IS_VOID, 0) + ZEND_ARG_INFO(0, _) + ZEND_ARG_INFO(0, __) +ZEND_END_ARG_INFO() PHP_METHOD(UUID, __wakeup) { @@ -414,26 +477,36 @@ PHP_METHOD(UUID, __wakeup) ); } } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___wakeup_args, IS_VOID, 0) +ZEND_END_ARG_INFO() PHP_METHOD(UUID, getVariant) { RETURN_LONG(php_uuid_get_variant(*get_bytes(&EX(This)))); } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) +ZEND_END_ARG_INFO() PHP_METHOD(UUID, getVersion) { RETURN_LONG(php_uuid_get_version(*get_bytes(&EX(This)))); } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) +ZEND_END_ARG_INFO() PHP_METHOD(UUID, isNil) { RETURN_BOOL(php_uuid_is_nil(*get_bytes(&EX(This)))); } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) +ZEND_END_ARG_INFO() PHP_METHOD(UUID, toBinary) { RETURN_STRINGL(*get_bytes(&EX(This)), PHP_UUID_LEN); } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) +ZEND_END_ARG_INFO() PHP_METHOD(UUID, toHex) { @@ -441,6 +514,8 @@ PHP_METHOD(UUID, toHex) php_uuid_to_hex(&buffer, *get_bytes(&EX(This))); RETURN_STRINGL(buffer, PHP_UUID_HEX_LEN); } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toHex_args, IS_STRING, 0) +ZEND_END_ARG_INFO() PHP_METHOD(UUID, toString) { @@ -448,53 +523,6 @@ PHP_METHOD(UUID, toString) php_uuid_to_string(&buffer, *get_bytes(&EX(This))); RETURN_STRINGL(buffer, PHP_UUID_STRING_LEN); } - -ZEND_BEGIN_ARG_INFO(UUID___construct_args, NULL) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_fromBinary_args, 0, 1, UUID, 0) - ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, UUID, 0) - ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, UUID, 0) - ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) - ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_v4_args, UUID, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, UUID, 0) - ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) - ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, UUID, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, UUID, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, UUID, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, UUID, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, UUID, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO(UUID___clone_args, NULL) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___set_args, IS_VOID, 0) - ZEND_ARG_INFO(0, _) - ZEND_ARG_INFO(0, __) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___wakeup_args, IS_VOID, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toHex_args, IS_STRING, 0) -ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toString_args, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -547,6 +575,12 @@ PHP_METHOD(UUIDParseException, __construct) zend_update_property_ex(zend_ce_exception, &EX(This), ZSTR_KNOWN(ZEND_STR_PREVIOUS), previous); } } +ZEND_BEGIN_ARG_INFO_EX(UUIDParseException___construct_args, NULL, 0, 2) + ZEND_ARG_TYPE_INFO(0, reason, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) + ZEND_ARG_TYPE_INFO(0, position, IS_LONG, 0) + ZEND_ARG_OBJ_INFO(0, previous, Throwable, 1) +ZEND_END_ARG_INFO() PHP_METHOD(UUIDParseException, getInput) { @@ -559,8 +593,9 @@ PHP_METHOD(UUIDParseException, getInput) NULL ), 1, 0); } +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getInput_args, IS_STRING, 0) +ZEND_END_ARG_INFO() -/* */ PHP_METHOD(UUIDParseException, getPosition) { RETURN_ZVAL(zend_read_property( @@ -572,15 +607,6 @@ PHP_METHOD(UUIDParseException, getPosition) NULL ), 1, 0); } - -ZEND_BEGIN_ARG_INFO_EX(UUIDParseException___construct_args, NULL, 0, 2) - ZEND_ARG_TYPE_INFO(0, reason, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) - ZEND_ARG_TYPE_INFO(0, position, IS_LONG, 0) - ZEND_ARG_OBJ_INFO(0, previous, Throwable, 1) -ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getInput_args, IS_STRING, 0) -ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getPosition_args, IS_LONG, 0) ZEND_END_ARG_INFO() From 49aed4fd75e9560444f63593b67fc4ed18e233c9 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Thu, 25 May 2017 13:43:07 +0200 Subject: [PATCH 19/54] Added zend_parse_parameters_none --- ext/standard/uuid.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index b9e3390aead9f..a948ec70eb481 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -303,7 +303,7 @@ PHPAPI zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const ); } -static zend_always_inline php_uuid *get_bytes(zval *object) +static zend_always_inline php_uuid *get_bytes(/*const*/ zval *object) { return (php_uuid *) Z_STRVAL_P(zend_read_property(php_ce_UUID, object, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, 1, NULL)); } @@ -386,6 +386,9 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, v4) { php_uuid uuid; + + zend_parse_parameters_none(); + if (php_uuid_create_v4_throw(&uuid) == SUCCESS) { new_uuid(return_value, uuid); } @@ -414,6 +417,8 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, NamespaceDNS) { + zend_parse_parameters_none(); + new_uuid(return_value, PHP_UUID_NAMESPACE_DNS); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, UUID, 0) @@ -421,6 +426,8 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, NamespaceOID) { + zend_parse_parameters_none(); + new_uuid(return_value, PHP_UUID_NAMESPACE_OID); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, UUID, 0) @@ -428,6 +435,8 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, NamespaceURL) { + zend_parse_parameters_none(); + new_uuid(return_value, PHP_UUID_NAMESPACE_URL); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, UUID, 0) @@ -435,6 +444,8 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, NamespaceX500) { + zend_parse_parameters_none(); + new_uuid(return_value, PHP_UUID_NAMESPACE_X500); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, UUID, 0) @@ -442,6 +453,8 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, Nil) { + zend_parse_parameters_none(); + new_uuid(return_value, PHP_UUID_NIL); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, UUID, 0) @@ -467,6 +480,9 @@ PHP_METHOD(UUID, __wakeup) { size_t len = Z_STRLEN_P(zend_read_property(php_ce_UUID, &EX(This), UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, 1, NULL)); + zend_parse_parameters_none(); + + if (len != PHP_UUID_LEN) { zend_throw_exception_ex( spl_ce_UnexpectedValueException, @@ -482,6 +498,8 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, getVariant) { + zend_parse_parameters_none(); + RETURN_LONG(php_uuid_get_variant(*get_bytes(&EX(This)))); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) @@ -489,6 +507,8 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, getVersion) { + zend_parse_parameters_none(); + RETURN_LONG(php_uuid_get_version(*get_bytes(&EX(This)))); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) @@ -496,6 +516,8 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, isNil) { + zend_parse_parameters_none(); + RETURN_BOOL(php_uuid_is_nil(*get_bytes(&EX(This)))); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) @@ -503,6 +525,8 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, toBinary) { + zend_parse_parameters_none(); + RETURN_STRINGL(*get_bytes(&EX(This)), PHP_UUID_LEN); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) @@ -511,6 +535,9 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, toHex) { php_uuid_hex buffer; + + zend_parse_parameters_none(); + php_uuid_to_hex(&buffer, *get_bytes(&EX(This))); RETURN_STRINGL(buffer, PHP_UUID_HEX_LEN); } @@ -520,6 +547,9 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, toString) { php_uuid_string buffer; + + zend_parse_parameters_none(); + php_uuid_to_string(&buffer, *get_bytes(&EX(This))); RETURN_STRINGL(buffer, PHP_UUID_STRING_LEN); } @@ -584,6 +614,8 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUIDParseException, getInput) { + zend_parse_parameters_none(); + RETURN_ZVAL(zend_read_property( php_ce_UUIDParseException, &EX(This), @@ -598,6 +630,8 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUIDParseException, getPosition) { + zend_parse_parameters_none(); + RETURN_ZVAL(zend_read_property( php_ce_UUIDParseException, &EX(This), From 5b69abe6f59c4b4c4c279606c7d5b628f817c4d6 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Thu, 25 May 2017 13:51:43 +0200 Subject: [PATCH 20/54] Extended documentation --- ext/standard/uuid.c | 97 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index a948ec70eb481..66077a8ce1614 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -61,11 +61,27 @@ static const uint8_t UUID_EX_POSITON_PROP_LEN = sizeof(UUID_EX_POSITIO static const char URN_PREFIX[] = "urn:uuid:"; static const uint8_t URN_PREFIX_LEN = sizeof(URN_PREFIX) - 1; +/** + * Set UUID variant to RFC 4122, the only supported variant. + * + * @param[out] uuid to set the variant. + */ static zend_always_inline void set_variant_rfc4122(php_uuid *uuid) { (*uuid)[8] = ((*uuid)[8] & 0x3F) | 0x80; } +/** + * Set UUID version. + * + * @see PHP_UUID_VERSION_1_TIME_BASED + * @see PHP_UUID_VERSION_2_DCE_SECURITY + * @see PHP_UUID_VERSION_3_NAME_BASED_MD5 + * @see PHP_UUID_VERSION_4_RANDOM + * @see PHP_UUID_VERSION_5_NAME_BASED_SHA1 + * @param[out] uuid to set the version. + * @param[in] version to set. + */ static zend_always_inline void php_uuid_set_version(php_uuid *uuid, const uint8_t version) { assert(PHP_UUID_VERSION_MIN <= version && version <= PHP_UUID_VERSION_MAX); @@ -73,6 +89,15 @@ static zend_always_inline void php_uuid_set_version(php_uuid *uuid, const uint8_ (*uuid)[6] = ((*uuid)[6] & 0x0F) | (version << 4); } +/** + * Throw UUIDParseException. + * + * @param[in] input that could not be parsed. + * @param[in] input_len + * @param[in] position at which parsing failed. + * @param[in] reason why parsing failed. + * @param[in] ... arguments to format the reason. + */ static ZEND_COLD zend_object *throw_uuid_parse_exception(const char *input, const size_t input_len, const size_t position, const char *reason, ...) { va_list format_args; @@ -93,6 +118,14 @@ static ZEND_COLD zend_object *throw_uuid_parse_exception(const char *input, cons return object; } +/** + * Throw UUIDParseException because of insufficient input. + * + * @param[in] input that could not be parsed. + * @param[in] input_len + * @param[in] position at which parsing failed. + * @param[in] actual amount of characters that were found. + */ static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_len(const char *input, const size_t input_len, const size_t position, const size_t actual) { return throw_uuid_parse_exception( @@ -105,6 +138,13 @@ static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_len(co ); } +/** + * Throw UUIDParseException because of an invalid character. + * + * @param[in] input that could not be parsed. + * @param[in] input_len + * @param[in] position at which parsing failed. + */ static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_char(const char *input, const size_t input_len, const size_t position) { return throw_uuid_parse_exception( @@ -303,24 +343,38 @@ PHPAPI zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const ); } +/** + * Get the UUID's bytes from the private property. + * + * @param[in] object to get the bytes from. + */ static zend_always_inline php_uuid *get_bytes(/*const*/ zval *object) { return (php_uuid *) Z_STRVAL_P(zend_read_property(php_ce_UUID, object, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, 1, NULL)); } +/** + * Construct new UUID instance. + * + * @param[out] object to store the UUID instance int. + * @param[in] uuid to construct the instance from. + */ static zend_always_inline void new_uuid(zval *object, const php_uuid uuid) { object_init_ex(object, php_ce_UUID); zend_update_property_stringl(php_ce_UUID, object, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, uuid, PHP_UUID_LEN); } +/* private function __construct() {{{ */ PHP_METHOD(UUID, __construct) { /* NOOP */ } ZEND_BEGIN_ARG_INFO(UUID___construct_args, NULL) ZEND_END_ARG_INFO() +/* }}} */ +/* public static function fromBinary(string $input): UUID {{{ */ PHP_METHOD(UUID, fromBinary) { char *input = NULL; @@ -346,7 +400,9 @@ PHP_METHOD(UUID, fromBinary) ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_fromBinary_args, 0, 1, UUID, 0) ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public static function parse(string $input): UUID {{{ */ PHP_METHOD(UUID, parse) { char *input = NULL; @@ -363,7 +419,9 @@ PHP_METHOD(UUID, parse) ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, UUID, 0) ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public static function v3(UUID $namespace, string $name): UUID {{{ */ PHP_METHOD(UUID, v3) { zval *namespace = NULL; @@ -382,7 +440,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, UUID, 0) ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public static function v4(): UUID {{{ */ PHP_METHOD(UUID, v4) { php_uuid uuid; @@ -395,7 +455,9 @@ PHP_METHOD(UUID, v4) } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_v4_args, UUID, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public static function v5(UUID $namespace, string $name): UUID {{{ */ PHP_METHOD(UUID, v5) { zval *namespace = NULL; @@ -414,7 +476,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, UUID, 0) ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public static function NamespaceDNS(): UUID {{{ */ PHP_METHOD(UUID, NamespaceDNS) { zend_parse_parameters_none(); @@ -423,7 +487,9 @@ PHP_METHOD(UUID, NamespaceDNS) } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, UUID, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public static function NamespaceOID(): UUID {{{ */ PHP_METHOD(UUID, NamespaceOID) { zend_parse_parameters_none(); @@ -432,7 +498,9 @@ PHP_METHOD(UUID, NamespaceOID) } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, UUID, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public static function NamespaceURL(): UUID {{{ */ PHP_METHOD(UUID, NamespaceURL) { zend_parse_parameters_none(); @@ -441,7 +509,9 @@ PHP_METHOD(UUID, NamespaceURL) } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, UUID, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public static function NamespaceX500(): UUID {{{ */ PHP_METHOD(UUID, NamespaceX500) { zend_parse_parameters_none(); @@ -450,7 +520,9 @@ PHP_METHOD(UUID, NamespaceX500) } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, UUID, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public static function Nil(): UUID {{{ */ PHP_METHOD(UUID, Nil) { zend_parse_parameters_none(); @@ -459,14 +531,18 @@ PHP_METHOD(UUID, Nil) } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, UUID, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* private function __clone() {{{ */ PHP_METHOD(UUID, __clone) { zend_throw_error(zend_ce_error, "Cannot clone immutable UUID object"); } ZEND_BEGIN_ARG_INFO(UUID___clone_args, NULL) ZEND_END_ARG_INFO() +/* }}} */ +/* public function __set($_, $__): void {{{ */ PHP_METHOD(UUID, __set) { zend_throw_error(zend_ce_error, "Cannot set dynamic properties on immutable UUID object"); @@ -475,7 +551,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___set_args, IS_VOID, 0) ZEND_ARG_INFO(0, _) ZEND_ARG_INFO(0, __) ZEND_END_ARG_INFO() +/* }}} */ +/* public function __wakeup(): void {{{ */ PHP_METHOD(UUID, __wakeup) { size_t len = Z_STRLEN_P(zend_read_property(php_ce_UUID, &EX(This), UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, 1, NULL)); @@ -495,7 +573,9 @@ PHP_METHOD(UUID, __wakeup) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___wakeup_args, IS_VOID, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public function getVaraitn(): int {{{ */ PHP_METHOD(UUID, getVariant) { zend_parse_parameters_none(); @@ -504,7 +584,9 @@ PHP_METHOD(UUID, getVariant) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public function getVersion(): int {{{ */ PHP_METHOD(UUID, getVersion) { zend_parse_parameters_none(); @@ -513,7 +595,9 @@ PHP_METHOD(UUID, getVersion) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public function isNil(): bool {{{ */ PHP_METHOD(UUID, isNil) { zend_parse_parameters_none(); @@ -522,7 +606,9 @@ PHP_METHOD(UUID, isNil) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public function toBinary(): string {{{ */ PHP_METHOD(UUID, toBinary) { zend_parse_parameters_none(); @@ -531,7 +617,9 @@ PHP_METHOD(UUID, toBinary) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public function toHex(): string {{{ */ PHP_METHOD(UUID, toHex) { php_uuid_hex buffer; @@ -543,7 +631,9 @@ PHP_METHOD(UUID, toHex) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toHex_args, IS_STRING, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public function toString(): string {{{ */ PHP_METHOD(UUID, toString) { php_uuid_string buffer; @@ -555,6 +645,7 @@ PHP_METHOD(UUID, toString) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toString_args, IS_STRING, 0) ZEND_END_ARG_INFO() +/* }}} */ static const zend_function_entry uuid_methods[] = { PHP_ME(UUID, __construct, UUID___construct_args, ZEND_ACC_PRIVATE) @@ -580,6 +671,7 @@ static const zend_function_entry uuid_methods[] = { PHP_FE_END }; +/* public function __construct(string $reason, string $input, int $position = 0, ?Throwable $previous = null) {{{ */ PHP_METHOD(UUIDParseException, __construct) { zval *reason = NULL; @@ -611,7 +703,9 @@ ZEND_BEGIN_ARG_INFO_EX(UUIDParseException___construct_args, NULL, 0, 2) ZEND_ARG_TYPE_INFO(0, position, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, previous, Throwable, 1) ZEND_END_ARG_INFO() +/* }}} */ +/* public function getInput(): string {{{ */ PHP_METHOD(UUIDParseException, getInput) { zend_parse_parameters_none(); @@ -627,7 +721,9 @@ PHP_METHOD(UUIDParseException, getInput) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getInput_args, IS_STRING, 0) ZEND_END_ARG_INFO() +/* }}} */ +/* public function getPosition(): int {{{ */ PHP_METHOD(UUIDParseException, getPosition) { zend_parse_parameters_none(); @@ -643,6 +739,7 @@ PHP_METHOD(UUIDParseException, getPosition) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getPosition_args, IS_LONG, 0) ZEND_END_ARG_INFO() +/* }}} */ static const zend_function_entry uuid_parse_exception_methods[] = { PHP_ME(UUIDParseException, __construct, UUIDParseException___construct_args, ZEND_ACC_PUBLIC) From 02fa17b04511e828f3d55089ad8ba89653a52dc0 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Thu, 25 May 2017 13:56:02 +0200 Subject: [PATCH 21/54] Removed SPL check (always there) --- ext/standard/uuid.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 66077a8ce1614..a41e7ce4dea67 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -21,14 +21,11 @@ #include "php_uuid.h" #include "zend_exceptions.h" +#include "ext/spl/spl_exceptions.h" #include "md5.h" #include "php_random.h" #include "sha1.h" -#ifdef HAVE_SPL -# include "ext/spl/spl_exceptions.h" -#endif - PHPAPI zend_class_entry *php_ce_UUID; PHPAPI zend_class_entry *php_ce_UUIDParseException; From 23bc8223f21dc9d7875b403d2cfc26aa02c1ecc8 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Thu, 25 May 2017 17:51:38 +0200 Subject: [PATCH 22/54] Removed leading backslashes --- ext/standard/stubs/UUID.php | 4 ++-- ext/standard/stubs/UUIDParseException.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/standard/stubs/UUID.php b/ext/standard/stubs/UUID.php index 4b4c146972512..f28a38e438628 100644 --- a/ext/standard/stubs/UUID.php +++ b/ext/standard/stubs/UUID.php @@ -256,7 +256,7 @@ private function __construct() { } * @param string $input string of exactly 16 bytes to construct the * instance from. * @return UUID instance constructed from the input. - * @throws \InvalidArgumentException if the input is not exactly 16 bytes + * @throws InvalidArgumentException if the input is not exactly 16 bytes * long. */ public static function fromBinary(string $input): UUID { } @@ -520,7 +520,7 @@ public function __set($_, $__): void { } * @see https://php.net/uuid.__wakeup * @see unserialize() * @return void - * @throws \UnexpectedValueException if the binary string is not exactly 16 + * @throws UnexpectedValueException if the binary string is not exactly 16 * bytes long. */ public function __wakeup(): void { } diff --git a/ext/standard/stubs/UUIDParseException.php b/ext/standard/stubs/UUIDParseException.php index ecdb9b3fcabb4..a90cfd2749738 100644 --- a/ext/standard/stubs/UUIDParseException.php +++ b/ext/standard/stubs/UUIDParseException.php @@ -43,7 +43,7 @@ * ?> * ``` * - * @see \UUID::parse() + * @see UUID::parse() */ final class UUIDParseException extends Exception { /** @var string */ From 44f71c8c1582e65840358c871b547b6badc37f14 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Thu, 25 May 2017 18:58:06 +0200 Subject: [PATCH 23/54] Use static value in test --- ext/standard/tests/uuid/UUID/__wakeup/basic.phpt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/standard/tests/uuid/UUID/__wakeup/basic.phpt b/ext/standard/tests/uuid/UUID/__wakeup/basic.phpt index 6b28de395c41b..9137f7804ab99 100644 --- a/ext/standard/tests/uuid/UUID/__wakeup/basic.phpt +++ b/ext/standard/tests/uuid/UUID/__wakeup/basic.phpt @@ -5,10 +5,9 @@ Richard Fussenegger php@fleshgrinder.com --FILE-- --EXPECT-- From ecd18ccc305b8418880ae74fe80b52af2c9f29ba Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Thu, 25 May 2017 19:14:32 +0200 Subject: [PATCH 24/54] Fixed formatting --- .../tests/uuid/UUID/NamespaceDNS/basic.phpt | 10 +++---- .../uuid/UUID/NamespaceDNS/definition.phpt | 10 +++---- .../tests/uuid/UUID/NamespaceOID/basic.phpt | 10 +++---- .../uuid/UUID/NamespaceOID/definition.phpt | 10 +++---- .../tests/uuid/UUID/NamespaceURL/basic.phpt | 10 +++---- .../uuid/UUID/NamespaceURL/definition.phpt | 10 +++---- .../tests/uuid/UUID/NamespaceX500/basic.phpt | 10 +++---- .../uuid/UUID/NamespaceX500/definition.phpt | 10 +++---- ext/standard/tests/uuid/UUID/Nil/basic.phpt | 10 +++---- .../tests/uuid/UUID/Nil/definition.phpt | 10 +++---- .../tests/uuid/UUID/__clone/definition.phpt | 10 +++---- .../tests/uuid/UUID/__clone/error.phpt | 2 +- .../uuid/UUID/__construct/definition.phpt | 8 +++--- .../tests/uuid/UUID/__set/definition.phpt | 8 +++--- ext/standard/tests/uuid/UUID/__set/error.phpt | 2 +- .../tests/uuid/UUID/__wakeup/definition.phpt | 8 +++--- .../tests/uuid/UUID/__wakeup/error.phpt | 4 +-- .../tests/uuid/UUID/comparison-004.phpt | 6 ++-- .../tests/uuid/UUID/definition-001.phpt | 24 ++++++++-------- .../tests/uuid/UUID/definition-002.phpt | 8 +++--- .../tests/uuid/UUID/definition-003.phpt | 10 +++---- .../uuid/UUID/fromBinary/definition-001.phpt | 6 ++-- .../uuid/UUID/fromBinary/definition-002.phpt | 12 ++++---- .../tests/uuid/UUID/fromBinary/error-001.phpt | 4 +-- .../tests/uuid/UUID/fromBinary/error-002.phpt | 12 ++++---- .../tests/uuid/UUID/getVariant/basic.phpt | 4 +-- .../uuid/UUID/getVariant/definition.phpt | 8 +++--- .../tests/uuid/UUID/getVersion/basic.phpt | 2 +- .../uuid/UUID/getVersion/definition.phpt | 8 +++--- .../tests/uuid/UUID/parse/definition-001.phpt | 6 ++-- .../tests/uuid/UUID/parse/definition-002.phpt | 12 ++++---- .../tests/uuid/UUID/parse/error-001.phpt | 4 +-- .../tests/uuid/UUID/parse/error-002.phpt | 28 ++++++++++--------- .../tests/uuid/UUID/parse/error-003.phpt | 4 +-- .../tests/uuid/UUID/parse/error-004.phpt | 4 +-- .../tests/uuid/UUID/toBinary/definition.phpt | 8 +++--- .../tests/uuid/UUID/toHex/definition.phpt | 8 +++--- .../tests/uuid/UUID/toString/definition.phpt | 8 +++--- .../tests/uuid/UUID/v3/definition-001.phpt | 8 +++--- .../tests/uuid/UUID/v3/definition-002.phpt | 12 ++++---- .../tests/uuid/UUID/v3/definition-003.phpt | 12 ++++---- .../tests/uuid/UUID/v3/error-001.phpt | 4 +-- .../tests/uuid/UUID/v3/error-002.phpt | 4 +-- .../tests/uuid/UUID/v4/definition.phpt | 8 +++--- .../tests/uuid/UUID/v5/definition-001.phpt | 8 +++--- .../tests/uuid/UUID/v5/definition-002.phpt | 12 ++++---- .../tests/uuid/UUID/v5/definition-003.phpt | 12 ++++---- .../tests/uuid/UUID/v5/error-001.phpt | 4 +-- .../tests/uuid/UUID/v5/error-002.phpt | 4 +-- .../__construct/definition-001.phpt | 8 +++--- .../__construct/definition-002.phpt | 8 +++--- .../__construct/definition-003.phpt | 6 ++-- .../__construct/definition-004.phpt | 8 +++--- .../__construct/definition-005.phpt | 8 +++--- .../__construct/error-001.phpt | 4 +-- .../__construct/variation-001.phpt | 6 ++-- .../__construct/variation-002.phpt | 6 ++-- .../__construct/variation-003.phpt | 6 ++-- .../tests/uuid/UUIDParseException/basic.phpt | 14 +++++----- .../UUIDParseException/definition-001.phpt | 10 +++---- .../getInput/definition.phpt | 12 ++++---- 61 files changed, 257 insertions(+), 255 deletions(-) diff --git a/ext/standard/tests/uuid/UUID/NamespaceDNS/basic.phpt b/ext/standard/tests/uuid/UUID/NamespaceDNS/basic.phpt index 94cf41403f759..4077641712421 100644 --- a/ext/standard/tests/uuid/UUID/NamespaceDNS/basic.phpt +++ b/ext/standard/tests/uuid/UUID/NamespaceDNS/basic.phpt @@ -8,11 +8,11 @@ Richard Fussenegger php@fleshgrinder.com $uuid = UUID::NamespaceDNS(); var_dump( - $uuid->getVariant() === UUID::VARIANT_RFC4122, - $uuid->getVersion() === UUID::VERSION_1_TIME_BASED, - $uuid->toBinary() === "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8", - $uuid->toHex(), - $uuid->toString() + $uuid->getVariant() === UUID::VARIANT_RFC4122, + $uuid->getVersion() === UUID::VERSION_1_TIME_BASED, + $uuid->toBinary() === "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8", + $uuid->toHex(), + $uuid->toString() ); ?> diff --git a/ext/standard/tests/uuid/UUID/NamespaceDNS/definition.phpt b/ext/standard/tests/uuid/UUID/NamespaceDNS/definition.phpt index c3930e093f854..c3cd0e8825fd6 100644 --- a/ext/standard/tests/uuid/UUID/NamespaceDNS/definition.phpt +++ b/ext/standard/tests/uuid/UUID/NamespaceDNS/definition.phpt @@ -8,11 +8,11 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'NamespaceDNS'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), - $m->isStatic() + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() ); ?> diff --git a/ext/standard/tests/uuid/UUID/NamespaceOID/basic.phpt b/ext/standard/tests/uuid/UUID/NamespaceOID/basic.phpt index f124ef7c79e70..b68da54e583e2 100644 --- a/ext/standard/tests/uuid/UUID/NamespaceOID/basic.phpt +++ b/ext/standard/tests/uuid/UUID/NamespaceOID/basic.phpt @@ -8,11 +8,11 @@ Richard Fussenegger php@fleshgrinder.com $uuid = UUID::NamespaceOID(); var_dump( - $uuid->getVariant() === UUID::VARIANT_RFC4122, - $uuid->getVersion() === UUID::VERSION_1_TIME_BASED, - $uuid->toBinary() === "\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8", - $uuid->toHex(), - $uuid->toString() + $uuid->getVariant() === UUID::VARIANT_RFC4122, + $uuid->getVersion() === UUID::VERSION_1_TIME_BASED, + $uuid->toBinary() === "\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8", + $uuid->toHex(), + $uuid->toString() ); ?> diff --git a/ext/standard/tests/uuid/UUID/NamespaceOID/definition.phpt b/ext/standard/tests/uuid/UUID/NamespaceOID/definition.phpt index 85903d4427048..3886b7fdbed98 100644 --- a/ext/standard/tests/uuid/UUID/NamespaceOID/definition.phpt +++ b/ext/standard/tests/uuid/UUID/NamespaceOID/definition.phpt @@ -8,11 +8,11 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'NamespaceOID'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), - $m->isStatic() + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() ); ?> diff --git a/ext/standard/tests/uuid/UUID/NamespaceURL/basic.phpt b/ext/standard/tests/uuid/UUID/NamespaceURL/basic.phpt index b4eac752774cc..ae0fe9af8aee1 100644 --- a/ext/standard/tests/uuid/UUID/NamespaceURL/basic.phpt +++ b/ext/standard/tests/uuid/UUID/NamespaceURL/basic.phpt @@ -8,11 +8,11 @@ Richard Fussenegger php@fleshgrinder.com $uuid = UUID::NamespaceURL(); var_dump( - $uuid->getVariant() === UUID::VARIANT_RFC4122, - $uuid->getVersion() === UUID::VERSION_1_TIME_BASED, - $uuid->toBinary() === "\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8", - $uuid->toHex(), - $uuid->toString() + $uuid->getVariant() === UUID::VARIANT_RFC4122, + $uuid->getVersion() === UUID::VERSION_1_TIME_BASED, + $uuid->toBinary() === "\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8", + $uuid->toHex(), + $uuid->toString() ); ?> diff --git a/ext/standard/tests/uuid/UUID/NamespaceURL/definition.phpt b/ext/standard/tests/uuid/UUID/NamespaceURL/definition.phpt index 4f8bc7c1bad7e..3b40b8bff62f2 100644 --- a/ext/standard/tests/uuid/UUID/NamespaceURL/definition.phpt +++ b/ext/standard/tests/uuid/UUID/NamespaceURL/definition.phpt @@ -8,11 +8,11 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'NamespaceURL'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), - $m->isStatic() + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() ); ?> diff --git a/ext/standard/tests/uuid/UUID/NamespaceX500/basic.phpt b/ext/standard/tests/uuid/UUID/NamespaceX500/basic.phpt index 7c88b51b8b650..74b9efd43ac36 100644 --- a/ext/standard/tests/uuid/UUID/NamespaceX500/basic.phpt +++ b/ext/standard/tests/uuid/UUID/NamespaceX500/basic.phpt @@ -8,11 +8,11 @@ Richard Fussenegger php@fleshgrinder.com $uuid = UUID::NamespaceX500(); var_dump( - $uuid->getVariant() === UUID::VARIANT_RFC4122, - $uuid->getVersion() === UUID::VERSION_1_TIME_BASED, - $uuid->toBinary() === "\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8", - $uuid->toHex(), - $uuid->toString() + $uuid->getVariant() === UUID::VARIANT_RFC4122, + $uuid->getVersion() === UUID::VERSION_1_TIME_BASED, + $uuid->toBinary() === "\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8", + $uuid->toHex(), + $uuid->toString() ); ?> diff --git a/ext/standard/tests/uuid/UUID/NamespaceX500/definition.phpt b/ext/standard/tests/uuid/UUID/NamespaceX500/definition.phpt index 91d599c5df7f5..a871d1689687b 100644 --- a/ext/standard/tests/uuid/UUID/NamespaceX500/definition.phpt +++ b/ext/standard/tests/uuid/UUID/NamespaceX500/definition.phpt @@ -8,11 +8,11 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'NamespaceX500'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), - $m->isStatic() + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() ); ?> diff --git a/ext/standard/tests/uuid/UUID/Nil/basic.phpt b/ext/standard/tests/uuid/UUID/Nil/basic.phpt index 7603c832b4cd8..a1edf8108509a 100644 --- a/ext/standard/tests/uuid/UUID/Nil/basic.phpt +++ b/ext/standard/tests/uuid/UUID/Nil/basic.phpt @@ -8,11 +8,11 @@ Richard Fussenegger php@fleshgrinder.com $uuid = UUID::Nil(); var_dump( - $uuid->getVariant(), - $uuid->getVersion(), - $uuid->toBinary() === "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", - $uuid->toHex(), - $uuid->toString() + $uuid->getVariant(), + $uuid->getVersion(), + $uuid->toBinary() === "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0", + $uuid->toHex(), + $uuid->toString() ); ?> diff --git a/ext/standard/tests/uuid/UUID/Nil/definition.phpt b/ext/standard/tests/uuid/UUID/Nil/definition.phpt index 0557b5636b8ba..157530b596aaa 100644 --- a/ext/standard/tests/uuid/UUID/Nil/definition.phpt +++ b/ext/standard/tests/uuid/UUID/Nil/definition.phpt @@ -8,11 +8,11 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'Nil'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), - $m->isStatic() + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() ); ?> diff --git a/ext/standard/tests/uuid/UUID/__clone/definition.phpt b/ext/standard/tests/uuid/UUID/__clone/definition.phpt index a8f2998ec485e..42cf485afaab6 100644 --- a/ext/standard/tests/uuid/UUID/__clone/definition.phpt +++ b/ext/standard/tests/uuid/UUID/__clone/definition.phpt @@ -8,11 +8,11 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, '__clone'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - $m->hasReturnType(), - $m->isPrivate(), - $m->isStatic() + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + $m->hasReturnType(), + $m->isPrivate(), + $m->isStatic() ); ?> diff --git a/ext/standard/tests/uuid/UUID/__clone/error.phpt b/ext/standard/tests/uuid/UUID/__clone/error.phpt index 8a2bd868065af..cd6452e171ba1 100644 --- a/ext/standard/tests/uuid/UUID/__clone/error.phpt +++ b/ext/standard/tests/uuid/UUID/__clone/error.phpt @@ -12,7 +12,7 @@ try { $m->invoke(UUID::Nil()); } catch (Error $e) { - echo $e->getMessage(); + echo $e->getMessage(); } ?> diff --git a/ext/standard/tests/uuid/UUID/__construct/definition.phpt b/ext/standard/tests/uuid/UUID/__construct/definition.phpt index 06d0c0529bd3a..443b2045d4ccd 100644 --- a/ext/standard/tests/uuid/UUID/__construct/definition.phpt +++ b/ext/standard/tests/uuid/UUID/__construct/definition.phpt @@ -8,10 +8,10 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, '__construct'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - $m->hasReturnType(), - $m->isPrivate(), + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + $m->hasReturnType(), + $m->isPrivate(), $m->isStatic() ); diff --git a/ext/standard/tests/uuid/UUID/__set/definition.phpt b/ext/standard/tests/uuid/UUID/__set/definition.phpt index e25b133869071..23ebdf488eb8d 100644 --- a/ext/standard/tests/uuid/UUID/__set/definition.phpt +++ b/ext/standard/tests/uuid/UUID/__set/definition.phpt @@ -8,10 +8,10 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, '__set'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), $m->isStatic() ); diff --git a/ext/standard/tests/uuid/UUID/__set/error.phpt b/ext/standard/tests/uuid/UUID/__set/error.phpt index 4fd47beab1b61..ba549ee8ea0ef 100644 --- a/ext/standard/tests/uuid/UUID/__set/error.phpt +++ b/ext/standard/tests/uuid/UUID/__set/error.phpt @@ -9,7 +9,7 @@ try { UUID::Nil()->dynamic_property = 'value'; } catch (Error $e) { - echo $e->getMessage(); + echo $e->getMessage(); } ?> diff --git a/ext/standard/tests/uuid/UUID/__wakeup/definition.phpt b/ext/standard/tests/uuid/UUID/__wakeup/definition.phpt index bca95d7c7dba0..7b1a0cc2b34ae 100644 --- a/ext/standard/tests/uuid/UUID/__wakeup/definition.phpt +++ b/ext/standard/tests/uuid/UUID/__wakeup/definition.phpt @@ -8,10 +8,10 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, '__wakeup'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), $m->isStatic() ); diff --git a/ext/standard/tests/uuid/UUID/__wakeup/error.phpt b/ext/standard/tests/uuid/UUID/__wakeup/error.phpt index 32de0515336a8..1e3f5f486937f 100644 --- a/ext/standard/tests/uuid/UUID/__wakeup/error.phpt +++ b/ext/standard/tests/uuid/UUID/__wakeup/error.phpt @@ -7,11 +7,11 @@ Richard Fussenegger php@fleshgrinder.com foreach ([0, 1, 15, 17, random_int(18, 256)] as $i) { try { - $bytes = $i === 0 ? '' : random_bytes($i); + $bytes = $i === 0 ? '' : random_bytes($i); unserialize("O:4:\"UUID\":1:{s:12:\"\0UUID\0binary\";s:{$i}:\"{$bytes}\";}"); } catch (UnexpectedValueException $e) { - echo $e->getMessage() , "\n"; + echo $e->getMessage(), "\n"; } } diff --git a/ext/standard/tests/uuid/UUID/comparison-004.phpt b/ext/standard/tests/uuid/UUID/comparison-004.phpt index 05eadc9f4237c..60a8c6cb2b1a4 100644 --- a/ext/standard/tests/uuid/UUID/comparison-004.phpt +++ b/ext/standard/tests/uuid/UUID/comparison-004.phpt @@ -11,15 +11,15 @@ Richard Fussenegger php@fleshgrinder.com $a = UUID::fromBinary("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1"); $b = UUID::fromBinary("\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2"); -echo var_dump($a < $b, $a == $b, $a > $b) , "\n"; +echo var_dump($a < $b, $a == $b, $a > $b), "\n"; $a = UUID::fromBinary("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1"); $b = UUID::fromBinary("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1"); -echo var_dump($a < $b, $a == $b, $a > $b) , "\n"; +echo var_dump($a < $b, $a == $b, $a > $b), "\n"; $a = UUID::fromBinary("\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2\2"); $b = UUID::fromBinary("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1"); -echo var_dump($a < $b, $a == $b, $a > $b) , "\n"; +echo var_dump($a < $b, $a == $b, $a > $b), "\n"; ?> --EXPECT-- diff --git a/ext/standard/tests/uuid/UUID/definition-001.phpt b/ext/standard/tests/uuid/UUID/definition-001.phpt index 65a4c9bad2fcc..52b4b7b46ded6 100644 --- a/ext/standard/tests/uuid/UUID/definition-001.phpt +++ b/ext/standard/tests/uuid/UUID/definition-001.phpt @@ -8,18 +8,18 @@ Richard Fussenegger php@fleshgrinder.com $c = new ReflectionClass(UUID::class); var_dump( - $c->getInterfaces() === [], - $c->getParentClass(), - $c->isAbstract(), - $c->isCloneable(), - $c->isFinal(), - $c->isInstantiable(), - $c->isInterface(), - $c->isInternal(), - $c->isIterateable(), - $c->isTrait(), - count($c->getConstants()), - count($c->getProperties()) + $c->getInterfaces() === [], + $c->getParentClass(), + $c->isAbstract(), + $c->isCloneable(), + $c->isFinal(), + $c->isInstantiable(), + $c->isInterface(), + $c->isInternal(), + $c->isIterateable(), + $c->isTrait(), + count($c->getConstants()), + count($c->getProperties()) ); ?> diff --git a/ext/standard/tests/uuid/UUID/definition-002.phpt b/ext/standard/tests/uuid/UUID/definition-002.phpt index 81545dfa8a0b2..ab9250e84f2e3 100644 --- a/ext/standard/tests/uuid/UUID/definition-002.phpt +++ b/ext/standard/tests/uuid/UUID/definition-002.phpt @@ -6,10 +6,10 @@ Richard Fussenegger php@fleshgrinder.com diff --git a/ext/standard/tests/uuid/UUID/definition-003.phpt b/ext/standard/tests/uuid/UUID/definition-003.phpt index f480800bc1958..8786047acfc25 100644 --- a/ext/standard/tests/uuid/UUID/definition-003.phpt +++ b/ext/standard/tests/uuid/UUID/definition-003.phpt @@ -6,11 +6,11 @@ Richard Fussenegger php@fleshgrinder.com diff --git a/ext/standard/tests/uuid/UUID/fromBinary/definition-001.phpt b/ext/standard/tests/uuid/UUID/fromBinary/definition-001.phpt index a950e3a9da0a5..fac604fabde0b 100644 --- a/ext/standard/tests/uuid/UUID/fromBinary/definition-001.phpt +++ b/ext/standard/tests/uuid/UUID/fromBinary/definition-001.phpt @@ -8,9 +8,9 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'fromBinary'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), $m->isPublic(), $m->isStatic() ); diff --git a/ext/standard/tests/uuid/UUID/fromBinary/definition-002.phpt b/ext/standard/tests/uuid/UUID/fromBinary/definition-002.phpt index 1a6cd95ff2eb8..5a80e2c0b8fdd 100644 --- a/ext/standard/tests/uuid/UUID/fromBinary/definition-002.phpt +++ b/ext/standard/tests/uuid/UUID/fromBinary/definition-002.phpt @@ -8,12 +8,12 @@ Richard Fussenegger php@fleshgrinder.com $p = (new ReflectionMethod(UUID::class, 'fromBinary'))->getParameters()[0]; var_dump( - $p->getName(), - $p->allowsNull(), - (string) $p->getType(), - $p->isOptional(), - $p->isPassedByReference(), - $p->isVariadic() + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference(), + $p->isVariadic() ); ?> diff --git a/ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt b/ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt index 340f2420609e6..271a4105f3f45 100644 --- a/ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt +++ b/ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt @@ -6,10 +6,10 @@ Richard Fussenegger php@fleshgrinder.com getMessage(); + echo $e->getMessage(); } ?> diff --git a/ext/standard/tests/uuid/UUID/fromBinary/error-002.phpt b/ext/standard/tests/uuid/UUID/fromBinary/error-002.phpt index b32b7bd8199a5..bca341ce9f8a5 100644 --- a/ext/standard/tests/uuid/UUID/fromBinary/error-002.phpt +++ b/ext/standard/tests/uuid/UUID/fromBinary/error-002.phpt @@ -6,12 +6,12 @@ Richard Fussenegger php@fleshgrinder.com getMessage() , "\n"; - } + try { + UUID::fromBinary($i === 0 ? '' : random_bytes($i)); + } + catch (InvalidArgumentException $e) { + echo $e->getMessage(), "\n"; + } } ?> diff --git a/ext/standard/tests/uuid/UUID/getVariant/basic.phpt b/ext/standard/tests/uuid/UUID/getVariant/basic.phpt index 6749d6bfd1653..c57e5791c7d9e 100644 --- a/ext/standard/tests/uuid/UUID/getVariant/basic.phpt +++ b/ext/standard/tests/uuid/UUID/getVariant/basic.phpt @@ -6,10 +6,10 @@ Richard Fussenegger php@fleshgrinder.com getVariant(), + UUID::fromBinary("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")->getVariant(), UUID::fromBinary("\x00\x00\x00\x00\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00")->getVariant(), UUID::fromBinary("\x00\x00\x00\x00\x00\x00\x00\x00\xC0\x00\x00\x00\x00\x00\x00\x00")->getVariant(), - UUID::fromBinary("\x00\x00\x00\x00\x00\x00\x00\x00\xE0\x00\x00\x00\x00\x00\x00\x00")->getVariant() + UUID::fromBinary("\x00\x00\x00\x00\x00\x00\x00\x00\xE0\x00\x00\x00\x00\x00\x00\x00")->getVariant() ); ?> diff --git a/ext/standard/tests/uuid/UUID/getVariant/definition.phpt b/ext/standard/tests/uuid/UUID/getVariant/definition.phpt index ad311a99098b3..ca54340f54414 100644 --- a/ext/standard/tests/uuid/UUID/getVariant/definition.phpt +++ b/ext/standard/tests/uuid/UUID/getVariant/definition.phpt @@ -8,10 +8,10 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'getVariant'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), $m->isStatic() ); diff --git a/ext/standard/tests/uuid/UUID/getVersion/basic.phpt b/ext/standard/tests/uuid/UUID/getVersion/basic.phpt index a20845f5c0d61..b8609747c1b03 100644 --- a/ext/standard/tests/uuid/UUID/getVersion/basic.phpt +++ b/ext/standard/tests/uuid/UUID/getVersion/basic.phpt @@ -6,7 +6,7 @@ Richard Fussenegger php@fleshgrinder.com getVersion()); + var_dump(UUID::fromBinary(sprintf("\x00\x00\x00\x00\x00\x00%s\x00\x00\x00\x00\x00\x00\x00\x00\x00", chr($i << 4)))->getVersion()); } ?> diff --git a/ext/standard/tests/uuid/UUID/getVersion/definition.phpt b/ext/standard/tests/uuid/UUID/getVersion/definition.phpt index 209e2be8d35b6..1c41b8461b16e 100644 --- a/ext/standard/tests/uuid/UUID/getVersion/definition.phpt +++ b/ext/standard/tests/uuid/UUID/getVersion/definition.phpt @@ -8,10 +8,10 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'getVersion'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), $m->isStatic() ); diff --git a/ext/standard/tests/uuid/UUID/parse/definition-001.phpt b/ext/standard/tests/uuid/UUID/parse/definition-001.phpt index 91c98db7efec5..b3820d1eb4048 100644 --- a/ext/standard/tests/uuid/UUID/parse/definition-001.phpt +++ b/ext/standard/tests/uuid/UUID/parse/definition-001.phpt @@ -8,9 +8,9 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'parse'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), $m->isPublic(), $m->isStatic() ); diff --git a/ext/standard/tests/uuid/UUID/parse/definition-002.phpt b/ext/standard/tests/uuid/UUID/parse/definition-002.phpt index 0f48d13c630ec..9a13a815ba864 100644 --- a/ext/standard/tests/uuid/UUID/parse/definition-002.phpt +++ b/ext/standard/tests/uuid/UUID/parse/definition-002.phpt @@ -8,12 +8,12 @@ Richard Fussenegger php@fleshgrinder.com $p = (new ReflectionMethod(UUID::class, 'parse'))->getParameters()[0]; var_dump( - $p->getName(), - $p->allowsNull(), - (string) $p->getType(), - $p->isOptional(), - $p->isPassedByReference(), - $p->isVariadic() + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference(), + $p->isVariadic() ); ?> diff --git a/ext/standard/tests/uuid/UUID/parse/error-001.phpt b/ext/standard/tests/uuid/UUID/parse/error-001.phpt index 0e01875f80bd8..4e766a2194675 100644 --- a/ext/standard/tests/uuid/UUID/parse/error-001.phpt +++ b/ext/standard/tests/uuid/UUID/parse/error-001.phpt @@ -6,10 +6,10 @@ Richard Fussenegger php@fleshgrinder.com getMessage(); + echo $e->getMessage(); } ?> diff --git a/ext/standard/tests/uuid/UUID/parse/error-002.phpt b/ext/standard/tests/uuid/UUID/parse/error-002.phpt index 8c2059cb9d74a..53757504f8836 100644 --- a/ext/standard/tests/uuid/UUID/parse/error-002.phpt +++ b/ext/standard/tests/uuid/UUID/parse/error-002.phpt @@ -5,19 +5,21 @@ Richard Fussenegger php@fleshgrinder.com --FILE-- getMessage() , "\n"; - } +foreach ( + [ + '', + '0', + str_repeat('0', 31), + '0123456789-0123456789-0123456789', + " \t{012345678901234567890123456789}\t ", + ] as $date +) { + try { + UUID::parse($date); + } + catch (UUIDParseException $e) { + echo $e->getMessage(), "\n"; + } } ?> diff --git a/ext/standard/tests/uuid/UUID/parse/error-003.phpt b/ext/standard/tests/uuid/UUID/parse/error-003.phpt index 4c462761fbba6..e9dd06e014b3c 100644 --- a/ext/standard/tests/uuid/UUID/parse/error-003.phpt +++ b/ext/standard/tests/uuid/UUID/parse/error-003.phpt @@ -6,10 +6,10 @@ Richard Fussenegger php@fleshgrinder.com getMessage() , "\n"; + echo $e->getMessage(), "\n"; } ?> diff --git a/ext/standard/tests/uuid/UUID/parse/error-004.phpt b/ext/standard/tests/uuid/UUID/parse/error-004.phpt index 3bdfc4150cb26..aa2db047cca1d 100644 --- a/ext/standard/tests/uuid/UUID/parse/error-004.phpt +++ b/ext/standard/tests/uuid/UUID/parse/error-004.phpt @@ -6,10 +6,10 @@ Richard Fussenegger php@fleshgrinder.com getMessage() , "\n"; + echo $e->getMessage(), "\n"; } ?> diff --git a/ext/standard/tests/uuid/UUID/toBinary/definition.phpt b/ext/standard/tests/uuid/UUID/toBinary/definition.phpt index 22b8841d1dde5..ba74d613619e6 100644 --- a/ext/standard/tests/uuid/UUID/toBinary/definition.phpt +++ b/ext/standard/tests/uuid/UUID/toBinary/definition.phpt @@ -8,10 +8,10 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'toBinary'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), $m->isStatic() ); diff --git a/ext/standard/tests/uuid/UUID/toHex/definition.phpt b/ext/standard/tests/uuid/UUID/toHex/definition.phpt index 64fb84407561b..cb39e14a5c3ce 100644 --- a/ext/standard/tests/uuid/UUID/toHex/definition.phpt +++ b/ext/standard/tests/uuid/UUID/toHex/definition.phpt @@ -8,10 +8,10 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'toHex'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), $m->isStatic() ); diff --git a/ext/standard/tests/uuid/UUID/toString/definition.phpt b/ext/standard/tests/uuid/UUID/toString/definition.phpt index 64fb84407561b..cb39e14a5c3ce 100644 --- a/ext/standard/tests/uuid/UUID/toString/definition.phpt +++ b/ext/standard/tests/uuid/UUID/toString/definition.phpt @@ -8,10 +8,10 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'toHex'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), $m->isStatic() ); diff --git a/ext/standard/tests/uuid/UUID/v3/definition-001.phpt b/ext/standard/tests/uuid/UUID/v3/definition-001.phpt index 62f2a48f0da08..88ef6924d2c5d 100644 --- a/ext/standard/tests/uuid/UUID/v3/definition-001.phpt +++ b/ext/standard/tests/uuid/UUID/v3/definition-001.phpt @@ -8,10 +8,10 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'v3'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), $m->isStatic() ); diff --git a/ext/standard/tests/uuid/UUID/v3/definition-002.phpt b/ext/standard/tests/uuid/UUID/v3/definition-002.phpt index 3886334cb1e7c..007aae37551ca 100644 --- a/ext/standard/tests/uuid/UUID/v3/definition-002.phpt +++ b/ext/standard/tests/uuid/UUID/v3/definition-002.phpt @@ -8,12 +8,12 @@ Richard Fussenegger php@fleshgrinder.com $p = (new ReflectionMethod(UUID::class, 'v3'))->getParameters()[0]; var_dump( - $p->getName(), - $p->allowsNull(), - (string) $p->getType(), - $p->isOptional(), - $p->isPassedByReference(), - $p->isVariadic() + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference(), + $p->isVariadic() ); ?> diff --git a/ext/standard/tests/uuid/UUID/v3/definition-003.phpt b/ext/standard/tests/uuid/UUID/v3/definition-003.phpt index b62f9fcb87b1a..166246d5cdf5b 100644 --- a/ext/standard/tests/uuid/UUID/v3/definition-003.phpt +++ b/ext/standard/tests/uuid/UUID/v3/definition-003.phpt @@ -8,12 +8,12 @@ Richard Fussenegger php@fleshgrinder.com $p = (new ReflectionMethod(UUID::class, 'v3'))->getParameters()[1]; var_dump( - $p->getName(), - $p->allowsNull(), - (string) $p->getType(), - $p->isOptional(), - $p->isPassedByReference(), - $p->isVariadic() + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference(), + $p->isVariadic() ); ?> diff --git a/ext/standard/tests/uuid/UUID/v3/error-001.phpt b/ext/standard/tests/uuid/UUID/v3/error-001.phpt index b600b320a9efe..b6cbb3929735f 100644 --- a/ext/standard/tests/uuid/UUID/v3/error-001.phpt +++ b/ext/standard/tests/uuid/UUID/v3/error-001.phpt @@ -6,10 +6,10 @@ Richard Fussenegger php@fleshgrinder.com getMessage(); + echo $e->getMessage(); } ?> diff --git a/ext/standard/tests/uuid/UUID/v3/error-002.phpt b/ext/standard/tests/uuid/UUID/v3/error-002.phpt index cee24e3f9506d..81e3e599dd44d 100644 --- a/ext/standard/tests/uuid/UUID/v3/error-002.phpt +++ b/ext/standard/tests/uuid/UUID/v3/error-002.phpt @@ -6,10 +6,10 @@ Richard Fussenegger php@fleshgrinder.com getMessage(); + echo $e->getMessage(); } ?> diff --git a/ext/standard/tests/uuid/UUID/v4/definition.phpt b/ext/standard/tests/uuid/UUID/v4/definition.phpt index f9af6e6c54440..a0d93595c4932 100644 --- a/ext/standard/tests/uuid/UUID/v4/definition.phpt +++ b/ext/standard/tests/uuid/UUID/v4/definition.phpt @@ -8,10 +8,10 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'v4'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), $m->isStatic() ); diff --git a/ext/standard/tests/uuid/UUID/v5/definition-001.phpt b/ext/standard/tests/uuid/UUID/v5/definition-001.phpt index 3d82aaf956ab3..bd3355b62a368 100644 --- a/ext/standard/tests/uuid/UUID/v5/definition-001.phpt +++ b/ext/standard/tests/uuid/UUID/v5/definition-001.phpt @@ -8,10 +8,10 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUID::class, 'v5'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isPublic(), + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), $m->isStatic() ); diff --git a/ext/standard/tests/uuid/UUID/v5/definition-002.phpt b/ext/standard/tests/uuid/UUID/v5/definition-002.phpt index a64bb54f828be..fd91d55fbf3d0 100644 --- a/ext/standard/tests/uuid/UUID/v5/definition-002.phpt +++ b/ext/standard/tests/uuid/UUID/v5/definition-002.phpt @@ -8,12 +8,12 @@ Richard Fussenegger php@fleshgrinder.com $p = (new ReflectionMethod(UUID::class, 'v5'))->getParameters()[0]; var_dump( - $p->getName(), - $p->allowsNull(), - (string) $p->getType(), - $p->isOptional(), - $p->isPassedByReference(), - $p->isVariadic() + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference(), + $p->isVariadic() ); ?> diff --git a/ext/standard/tests/uuid/UUID/v5/definition-003.phpt b/ext/standard/tests/uuid/UUID/v5/definition-003.phpt index fd843ae0edd47..a6c70f8b65bd3 100644 --- a/ext/standard/tests/uuid/UUID/v5/definition-003.phpt +++ b/ext/standard/tests/uuid/UUID/v5/definition-003.phpt @@ -8,12 +8,12 @@ Richard Fussenegger php@fleshgrinder.com $p = (new ReflectionMethod(UUID::class, 'v5'))->getParameters()[1]; var_dump( - $p->getName(), - $p->allowsNull(), - (string) $p->getType(), - $p->isOptional(), - $p->isPassedByReference(), - $p->isVariadic() + $p->getName(), + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference(), + $p->isVariadic() ); ?> diff --git a/ext/standard/tests/uuid/UUID/v5/error-001.phpt b/ext/standard/tests/uuid/UUID/v5/error-001.phpt index 9646a7036df7e..7fbd47fa68892 100644 --- a/ext/standard/tests/uuid/UUID/v5/error-001.phpt +++ b/ext/standard/tests/uuid/UUID/v5/error-001.phpt @@ -6,10 +6,10 @@ Richard Fussenegger php@fleshgrinder.com getMessage(); + echo $e->getMessage(); } ?> diff --git a/ext/standard/tests/uuid/UUID/v5/error-002.phpt b/ext/standard/tests/uuid/UUID/v5/error-002.phpt index 6b1fee467eac6..9de5eded8d614 100644 --- a/ext/standard/tests/uuid/UUID/v5/error-002.phpt +++ b/ext/standard/tests/uuid/UUID/v5/error-002.phpt @@ -6,10 +6,10 @@ Richard Fussenegger php@fleshgrinder.com getMessage(); + echo $e->getMessage(); } ?> diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/definition-001.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-001.phpt index 884a02ec9207c..3d2f4a6f4bac5 100644 --- a/ext/standard/tests/uuid/UUIDParseException/__construct/definition-001.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-001.phpt @@ -8,10 +8,10 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUIDParseException::class, '__construct'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - $m->hasReturnType(), - $m->isPublic() + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + $m->hasReturnType(), + $m->isPublic() ); ?> diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/definition-002.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-002.phpt index b6b3c6dddd956..2da8a68e9c0bc 100644 --- a/ext/standard/tests/uuid/UUIDParseException/__construct/definition-002.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-002.phpt @@ -9,10 +9,10 @@ $p = (new ReflectionMethod(UUIDParseException::class, '__construct'))->getParame var_dump( $p->getName(), - $p->allowsNull(), - (string) $p->getType(), - $p->isOptional(), - $p->isPassedByReference() + $p->allowsNull(), + (string) $p->getType(), + $p->isOptional(), + $p->isPassedByReference() ); ?> diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/definition-003.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-003.phpt index 04d7f1e4a0939..736cbe6b4534f 100644 --- a/ext/standard/tests/uuid/UUIDParseException/__construct/definition-003.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-003.phpt @@ -9,10 +9,10 @@ $p = (new ReflectionMethod(UUIDParseException::class, '__construct'))->getParame var_dump( $p->getName(), - $p->allowsNull(), + $p->allowsNull(), (string) $p->getType(), - $p->isOptional(), - $p->isPassedByReference() + $p->isOptional(), + $p->isPassedByReference() ); ?> diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/definition-004.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-004.phpt index 411cca79668ef..fedaeefae28d1 100644 --- a/ext/standard/tests/uuid/UUIDParseException/__construct/definition-004.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-004.phpt @@ -9,11 +9,11 @@ $p = (new ReflectionMethod(UUIDParseException::class, '__construct'))->getParame var_dump( $p->getName(), - $p->allowsNull(), + $p->allowsNull(), (string) $p->getType(), - $p->isOptional(), - //$p->getDefaultValue(), - $p->isPassedByReference() + $p->isOptional(), + //$p->getDefaultValue(), + $p->isPassedByReference() ); ?> diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/definition-005.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-005.phpt index 17fa814f654c7..a5eca83ec6683 100644 --- a/ext/standard/tests/uuid/UUIDParseException/__construct/definition-005.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/definition-005.phpt @@ -9,11 +9,11 @@ $p = (new ReflectionMethod(UUIDParseException::class, '__construct'))->getParame var_dump( $p->getName(), - $p->allowsNull(), + $p->allowsNull(), (string) $p->getType(), - $p->isOptional(), - //$p->getDefaultValue(), - $p->isPassedByReference() + $p->isOptional(), + //$p->getDefaultValue(), + $p->isPassedByReference() ); ?> diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt index 455be21bba3e6..a71618c1d7cce 100644 --- a/ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt @@ -6,10 +6,10 @@ Richard Fussenegger php@fleshgrinder.com getMessage(); + echo $e->getMessage(); } ?> diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/variation-001.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/variation-001.phpt index 87477ecd05cb8..ab56532e60c3c 100644 --- a/ext/standard/tests/uuid/UUIDParseException/__construct/variation-001.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/variation-001.phpt @@ -8,9 +8,9 @@ Richard Fussenegger php@fleshgrinder.com $e = new UUIDParseException('variation-001-reason', 'variation-001-input'); foreach (['message', 'input', 'position'] as $p) { - $p = new ReflectionProperty(UUIDParseException::class, $p); - $p->setAccessible(true); - var_dump($p->getValue($e)); + $p = new ReflectionProperty(UUIDParseException::class, $p); + $p->setAccessible(true); + var_dump($p->getValue($e)); } ?> diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/variation-002.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/variation-002.phpt index ad292c6f6ccfa..382195ea0d7be 100644 --- a/ext/standard/tests/uuid/UUIDParseException/__construct/variation-002.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/variation-002.phpt @@ -8,9 +8,9 @@ Richard Fussenegger php@fleshgrinder.com $e = new UUIDParseException('variation-002-reason', 'variation-002-input', 42); foreach (['message', 'input', 'position'] as $p) { - $p = new ReflectionProperty(UUIDParseException::class, $p); - $p->setAccessible(true); - var_dump($p->getValue($e)); + $p = new ReflectionProperty(UUIDParseException::class, $p); + $p->setAccessible(true); + var_dump($p->getValue($e)); } ?> diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/variation-003.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/variation-003.phpt index b34f8da595304..5a3984d5bc87f 100644 --- a/ext/standard/tests/uuid/UUIDParseException/__construct/variation-003.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/__construct/variation-003.phpt @@ -8,9 +8,9 @@ Richard Fussenegger php@fleshgrinder.com $e = new UUIDParseException('variation-003-reason', 'variation-003-input', 84, $previous = new Exception); foreach (['message', 'input', 'position'] as $p) { - $p = new ReflectionProperty(UUIDParseException::class, $p); - $p->setAccessible(true); - var_dump($p->getValue($e)); + $p = new ReflectionProperty(UUIDParseException::class, $p); + $p->setAccessible(true); + var_dump($p->getValue($e)); } $p = new ReflectionProperty(Exception::class, 'previous'); diff --git a/ext/standard/tests/uuid/UUIDParseException/basic.phpt b/ext/standard/tests/uuid/UUIDParseException/basic.phpt index a2f629f3f7581..85c6fe2f364ee 100644 --- a/ext/standard/tests/uuid/UUIDParseException/basic.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/basic.phpt @@ -8,13 +8,13 @@ Richard Fussenegger php@fleshgrinder.com $e = new UUIDParseException('basic-reason', 'basic-input'); var_dump( - $e->getCode(), - $e->getFile() === __FILE__, - $e->getInput(), - $e->getLine(), - $e->getMessage(), - $e->getPosition(), - $e->getPrevious() + $e->getCode(), + $e->getFile() === __FILE__, + $e->getInput(), + $e->getLine(), + $e->getMessage(), + $e->getPosition(), + $e->getPrevious() ); ?> diff --git a/ext/standard/tests/uuid/UUIDParseException/definition-001.phpt b/ext/standard/tests/uuid/UUIDParseException/definition-001.phpt index 8d1d40084b9aa..9daa46edca808 100644 --- a/ext/standard/tests/uuid/UUIDParseException/definition-001.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/definition-001.phpt @@ -8,11 +8,11 @@ Richard Fussenegger php@fleshgrinder.com $c = new ReflectionClass(UUIDParseException::class); var_dump( - $c->isAbstract(), - $c->isFinal(), - $c->isInstantiable(), - $c->isInternal(), - $c->isSubclassOf(Exception::class) + $c->isAbstract(), + $c->isFinal(), + $c->isInstantiable(), + $c->isInternal(), + $c->isSubclassOf(Exception::class) ); ?> diff --git a/ext/standard/tests/uuid/UUIDParseException/getInput/definition.phpt b/ext/standard/tests/uuid/UUIDParseException/getInput/definition.phpt index c640f6fba66b4..73b620120d87e 100644 --- a/ext/standard/tests/uuid/UUIDParseException/getInput/definition.phpt +++ b/ext/standard/tests/uuid/UUIDParseException/getInput/definition.phpt @@ -8,12 +8,12 @@ Richard Fussenegger php@fleshgrinder.com $m = new ReflectionMethod(UUIDParseException::class, 'getInput'); var_dump( - $m->getNumberOfParameters(), - $m->getNumberOfRequiredParameters(), - (string) $m->getReturnType(), - $m->isAbstract(), - $m->isPublic(), - $m->isStatic() + $m->getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isAbstract(), + $m->isPublic(), + $m->isStatic() ); ?> From b4b900844512e1c886da0a389dbbcffd18f247cd Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Thu, 25 May 2017 19:16:48 +0200 Subject: [PATCH 25/54] Use static value for test --- ext/standard/tests/uuid/UUID/fromBinary/basic.phpt | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ext/standard/tests/uuid/UUID/fromBinary/basic.phpt b/ext/standard/tests/uuid/UUID/fromBinary/basic.phpt index cf5569364a5e3..469d3f4986b93 100644 --- a/ext/standard/tests/uuid/UUID/fromBinary/basic.phpt +++ b/ext/standard/tests/uuid/UUID/fromBinary/basic.phpt @@ -5,12 +5,10 @@ Richard Fussenegger php@fleshgrinder.com --FILE-- setAccessible(true); -var_dump($p->getValue($uuid) === $bytes); +var_dump($p->getValue($uuid) === ' '); ?> --EXPECT-- From 9ceae1d234835636c793789d3436a80dca563641 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Thu, 25 May 2017 19:19:09 +0200 Subject: [PATCH 26/54] Removed ArgumentCountError test cases This is now handled by the default PHP implementation. No custom logic means that this is covered by other tests. --- .../tests/uuid/UUID/fromBinary/error-001.phpt | 17 ----------- .../fromBinary/{error-002.phpt => error.phpt} | 0 .../tests/uuid/UUID/parse/error-001.phpt | 28 ++++++++++++++----- .../tests/uuid/UUID/parse/error-002.phpt | 28 +++++-------------- .../tests/uuid/UUID/parse/error-003.phpt | 6 ++-- .../tests/uuid/UUID/parse/error-004.phpt | 17 ----------- .../tests/uuid/UUID/v3/error-001.phpt | 17 ----------- .../tests/uuid/UUID/v3/error-002.phpt | 17 ----------- .../tests/uuid/UUID/v5/error-001.phpt | 17 ----------- .../tests/uuid/UUID/v5/error-002.phpt | 17 ----------- .../__construct/error-001.phpt | 17 ----------- .../__construct/error-002.phpt | 17 ----------- 12 files changed, 31 insertions(+), 167 deletions(-) delete mode 100644 ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt rename ext/standard/tests/uuid/UUID/fromBinary/{error-002.phpt => error.phpt} (100%) delete mode 100644 ext/standard/tests/uuid/UUID/parse/error-004.phpt delete mode 100644 ext/standard/tests/uuid/UUID/v3/error-001.phpt delete mode 100644 ext/standard/tests/uuid/UUID/v3/error-002.phpt delete mode 100644 ext/standard/tests/uuid/UUID/v5/error-001.phpt delete mode 100644 ext/standard/tests/uuid/UUID/v5/error-002.phpt delete mode 100644 ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt delete mode 100644 ext/standard/tests/uuid/UUIDParseException/__construct/error-002.phpt diff --git a/ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt b/ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt deleted file mode 100644 index 271a4105f3f45..0000000000000 --- a/ext/standard/tests/uuid/UUID/fromBinary/error-001.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -UUID::fromBinary throws ArgumentCountError if no arguments are passed ---CREDITS-- -Richard Fussenegger php@fleshgrinder.com ---FILE-- -getMessage(); -} - -?> ---EXPECT-- -UUID::fromBinary() expects exactly 1 parameter, 0 given diff --git a/ext/standard/tests/uuid/UUID/fromBinary/error-002.phpt b/ext/standard/tests/uuid/UUID/fromBinary/error.phpt similarity index 100% rename from ext/standard/tests/uuid/UUID/fromBinary/error-002.phpt rename to ext/standard/tests/uuid/UUID/fromBinary/error.phpt diff --git a/ext/standard/tests/uuid/UUID/parse/error-001.phpt b/ext/standard/tests/uuid/UUID/parse/error-001.phpt index 4e766a2194675..53757504f8836 100644 --- a/ext/standard/tests/uuid/UUID/parse/error-001.phpt +++ b/ext/standard/tests/uuid/UUID/parse/error-001.phpt @@ -1,17 +1,31 @@ --TEST-- -UUID::parse throws ArgumentCountError if no arguments are passed +UUID::parse throws UUIDParseException if there are less than 32 chars --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getMessage(); +foreach ( + [ + '', + '0', + str_repeat('0', 31), + '0123456789-0123456789-0123456789', + " \t{012345678901234567890123456789}\t ", + ] as $date +) { + try { + UUID::parse($date); + } + catch (UUIDParseException $e) { + echo $e->getMessage(), "\n"; + } } ?> --EXPECT-- -UUID::parse() expects exactly 1 parameter, 0 given +Expected at least 32 hexadecimal digits, but got 0 +Expected at least 32 hexadecimal digits, but got 1 +Expected at least 32 hexadecimal digits, but got 31 +Expected at least 32 hexadecimal digits, but got 30 +Expected at least 32 hexadecimal digits, but got 30 diff --git a/ext/standard/tests/uuid/UUID/parse/error-002.phpt b/ext/standard/tests/uuid/UUID/parse/error-002.phpt index 53757504f8836..e9dd06e014b3c 100644 --- a/ext/standard/tests/uuid/UUID/parse/error-002.phpt +++ b/ext/standard/tests/uuid/UUID/parse/error-002.phpt @@ -1,31 +1,17 @@ --TEST-- -UUID::parse throws UUIDParseException if there are less than 32 chars +UUID::parse throws UUIDParseException for non-hexadecimal characters --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getMessage(), "\n"; - } +try { + UUID::parse('01234567-89ab-cdef-0123-456789abcPHP'); +} +catch (UUIDParseException $e) { + echo $e->getMessage(), "\n"; } ?> --EXPECT-- -Expected at least 32 hexadecimal digits, but got 0 -Expected at least 32 hexadecimal digits, but got 1 -Expected at least 32 hexadecimal digits, but got 31 -Expected at least 32 hexadecimal digits, but got 30 -Expected at least 32 hexadecimal digits, but got 30 +Expected hexadecimal digit, but found 'P' (0x50) diff --git a/ext/standard/tests/uuid/UUID/parse/error-003.phpt b/ext/standard/tests/uuid/UUID/parse/error-003.phpt index e9dd06e014b3c..aa2db047cca1d 100644 --- a/ext/standard/tests/uuid/UUID/parse/error-003.phpt +++ b/ext/standard/tests/uuid/UUID/parse/error-003.phpt @@ -1,12 +1,12 @@ --TEST-- -UUID::parse throws UUIDParseException for non-hexadecimal characters +UUID::parse throws UUIDParseException if too many hexadecimal digits are found --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getMessage(), "\n"; @@ -14,4 +14,4 @@ catch (UUIDParseException $e) { ?> --EXPECT-- -Expected hexadecimal digit, but found 'P' (0x50) +Expected no more than 32 hexadecimal digits diff --git a/ext/standard/tests/uuid/UUID/parse/error-004.phpt b/ext/standard/tests/uuid/UUID/parse/error-004.phpt deleted file mode 100644 index aa2db047cca1d..0000000000000 --- a/ext/standard/tests/uuid/UUID/parse/error-004.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -UUID::parse throws UUIDParseException if too many hexadecimal digits are found ---CREDITS-- -Richard Fussenegger php@fleshgrinder.com ---FILE-- -getMessage(), "\n"; -} - -?> ---EXPECT-- -Expected no more than 32 hexadecimal digits diff --git a/ext/standard/tests/uuid/UUID/v3/error-001.phpt b/ext/standard/tests/uuid/UUID/v3/error-001.phpt deleted file mode 100644 index b6cbb3929735f..0000000000000 --- a/ext/standard/tests/uuid/UUID/v3/error-001.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -UUID::v3 throws ArgumentCountError if no arguments are passed ---CREDITS-- -Richard Fussenegger php@fleshgrinder.com ---FILE-- -getMessage(); -} - -?> ---EXPECT-- -UUID::v3() expects exactly 2 parameters, 0 given diff --git a/ext/standard/tests/uuid/UUID/v3/error-002.phpt b/ext/standard/tests/uuid/UUID/v3/error-002.phpt deleted file mode 100644 index 81e3e599dd44d..0000000000000 --- a/ext/standard/tests/uuid/UUID/v3/error-002.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -UUID::v3 throws ArgumentCountError if only one argument is passed ---CREDITS-- -Richard Fussenegger php@fleshgrinder.com ---FILE-- -getMessage(); -} - -?> ---EXPECT-- -UUID::v3() expects exactly 2 parameters, 1 given diff --git a/ext/standard/tests/uuid/UUID/v5/error-001.phpt b/ext/standard/tests/uuid/UUID/v5/error-001.phpt deleted file mode 100644 index 7fbd47fa68892..0000000000000 --- a/ext/standard/tests/uuid/UUID/v5/error-001.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -UUID::v5 throws ArgumentCountError if no arguments are passed ---CREDITS-- -Richard Fussenegger php@fleshgrinder.com ---FILE-- -getMessage(); -} - -?> ---EXPECT-- -UUID::v5() expects exactly 2 parameters, 0 given diff --git a/ext/standard/tests/uuid/UUID/v5/error-002.phpt b/ext/standard/tests/uuid/UUID/v5/error-002.phpt deleted file mode 100644 index 9de5eded8d614..0000000000000 --- a/ext/standard/tests/uuid/UUID/v5/error-002.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -UUID::v5 throws ArgumentCountError if only one argument is passed ---CREDITS-- -Richard Fussenegger php@fleshgrinder.com ---FILE-- -getMessage(); -} - -?> ---EXPECT-- -UUID::v5() expects exactly 2 parameters, 1 given diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt deleted file mode 100644 index a71618c1d7cce..0000000000000 --- a/ext/standard/tests/uuid/UUIDParseException/__construct/error-001.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -UUIDParseException::__construct ArgumentCountError with 0 arguments ---CREDITS-- -Richard Fussenegger php@fleshgrinder.com ---FILE-- -getMessage(); -} - -?> ---EXPECT-- -UUIDParseException::__construct() expects at least 2 parameters, 0 given diff --git a/ext/standard/tests/uuid/UUIDParseException/__construct/error-002.phpt b/ext/standard/tests/uuid/UUIDParseException/__construct/error-002.phpt deleted file mode 100644 index 7f0d0f4aa598f..0000000000000 --- a/ext/standard/tests/uuid/UUIDParseException/__construct/error-002.phpt +++ /dev/null @@ -1,17 +0,0 @@ ---TEST-- -UUIDParseException::__construct ArgumentCountError with 1 argument ---CREDITS-- -Richard Fussenegger php@fleshgrinder.com ---FILE-- -getMessage(); -} - -?> ---EXPECT-- -UUIDParseException::__construct() expects at least 2 parameters, 1 given From 5fdfe2d7ad255de09aee6f9c3ca2ad875d0a63cc Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Thu, 25 May 2017 19:56:41 +0200 Subject: [PATCH 27/54] Added isNil test cases --- ext/standard/tests/uuid/UUID/isNil/basic.phpt | 12 ++++++++++ .../tests/uuid/UUID/isNil/definition.phpt | 24 +++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 ext/standard/tests/uuid/UUID/isNil/basic.phpt create mode 100644 ext/standard/tests/uuid/UUID/isNil/definition.phpt diff --git a/ext/standard/tests/uuid/UUID/isNil/basic.phpt b/ext/standard/tests/uuid/UUID/isNil/basic.phpt new file mode 100644 index 0000000000000..ad7fb7d3014d1 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/isNil/basic.phpt @@ -0,0 +1,12 @@ +--TEST-- +UUID::isNil +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +isNil()); + +?> +--EXPECT-- +bool(true) diff --git a/ext/standard/tests/uuid/UUID/isNil/definition.phpt b/ext/standard/tests/uuid/UUID/isNil/definition.phpt new file mode 100644 index 0000000000000..a452da05bce6e --- /dev/null +++ b/ext/standard/tests/uuid/UUID/isNil/definition.phpt @@ -0,0 +1,24 @@ +--TEST-- +UUID::isNil method signature +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getNumberOfParameters(), + $m->getNumberOfRequiredParameters(), + (string) $m->getReturnType(), + $m->isPublic(), + $m->isStatic() +); + +?> +--EXPECT-- +int(0) +int(0) +string(4) "bool" +bool(true) +bool(false) From 9b240c75bb9d93569dec73c6a75bea1f656b03ea Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Fri, 26 May 2017 11:21:33 +0200 Subject: [PATCH 28/54] Changed parameter parsing to throw --- ext/standard/uuid.c | 48 +++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index a41e7ce4dea67..1a5d4b5521d48 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -26,6 +26,13 @@ #include "php_random.h" #include "sha1.h" +#define PHP_UUID_PARSE_PARAMETERS_NONE() \ + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "") == FAILURE) return; + +#define PHP_UUID_NAMED_CONSTRUCTOR(uuid) \ + PHP_UUID_PARSE_PARAMETERS_NONE(); \ + new_uuid(return_value, uuid); + PHPAPI zend_class_entry *php_ce_UUID; PHPAPI zend_class_entry *php_ce_UUIDParseException; @@ -444,7 +451,7 @@ PHP_METHOD(UUID, v4) { php_uuid uuid; - zend_parse_parameters_none(); + PHP_UUID_PARSE_PARAMETERS_NONE(); if (php_uuid_create_v4_throw(&uuid) == SUCCESS) { new_uuid(return_value, uuid); @@ -478,9 +485,7 @@ ZEND_END_ARG_INFO() /* public static function NamespaceDNS(): UUID {{{ */ PHP_METHOD(UUID, NamespaceDNS) { - zend_parse_parameters_none(); - - new_uuid(return_value, PHP_UUID_NAMESPACE_DNS); + PHP_UUID_NAMED_CONSTRUCTOR(PHP_UUID_NAMESPACE_DNS); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, UUID, 0) ZEND_END_ARG_INFO() @@ -489,9 +494,7 @@ ZEND_END_ARG_INFO() /* public static function NamespaceOID(): UUID {{{ */ PHP_METHOD(UUID, NamespaceOID) { - zend_parse_parameters_none(); - - new_uuid(return_value, PHP_UUID_NAMESPACE_OID); + PHP_UUID_NAMED_CONSTRUCTOR(PHP_UUID_NAMESPACE_OID); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, UUID, 0) ZEND_END_ARG_INFO() @@ -500,9 +503,7 @@ ZEND_END_ARG_INFO() /* public static function NamespaceURL(): UUID {{{ */ PHP_METHOD(UUID, NamespaceURL) { - zend_parse_parameters_none(); - - new_uuid(return_value, PHP_UUID_NAMESPACE_URL); + PHP_UUID_NAMED_CONSTRUCTOR(PHP_UUID_NAMESPACE_URL); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, UUID, 0) ZEND_END_ARG_INFO() @@ -511,9 +512,7 @@ ZEND_END_ARG_INFO() /* public static function NamespaceX500(): UUID {{{ */ PHP_METHOD(UUID, NamespaceX500) { - zend_parse_parameters_none(); - - new_uuid(return_value, PHP_UUID_NAMESPACE_X500); + PHP_UUID_NAMED_CONSTRUCTOR(PHP_UUID_NAMESPACE_X500); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, UUID, 0) ZEND_END_ARG_INFO() @@ -522,9 +521,7 @@ ZEND_END_ARG_INFO() /* public static function Nil(): UUID {{{ */ PHP_METHOD(UUID, Nil) { - zend_parse_parameters_none(); - - new_uuid(return_value, PHP_UUID_NIL); + PHP_UUID_NAMED_CONSTRUCTOR(PHP_UUID_NIL); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, UUID, 0) ZEND_END_ARG_INFO() @@ -555,8 +552,7 @@ PHP_METHOD(UUID, __wakeup) { size_t len = Z_STRLEN_P(zend_read_property(php_ce_UUID, &EX(This), UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, 1, NULL)); - zend_parse_parameters_none(); - + PHP_UUID_PARSE_PARAMETERS_NONE(); if (len != PHP_UUID_LEN) { zend_throw_exception_ex( @@ -575,7 +571,7 @@ ZEND_END_ARG_INFO() /* public function getVaraitn(): int {{{ */ PHP_METHOD(UUID, getVariant) { - zend_parse_parameters_none(); + PHP_UUID_PARSE_PARAMETERS_NONE(); RETURN_LONG(php_uuid_get_variant(*get_bytes(&EX(This)))); } @@ -586,7 +582,7 @@ ZEND_END_ARG_INFO() /* public function getVersion(): int {{{ */ PHP_METHOD(UUID, getVersion) { - zend_parse_parameters_none(); + PHP_UUID_PARSE_PARAMETERS_NONE(); RETURN_LONG(php_uuid_get_version(*get_bytes(&EX(This)))); } @@ -597,7 +593,7 @@ ZEND_END_ARG_INFO() /* public function isNil(): bool {{{ */ PHP_METHOD(UUID, isNil) { - zend_parse_parameters_none(); + PHP_UUID_PARSE_PARAMETERS_NONE(); RETURN_BOOL(php_uuid_is_nil(*get_bytes(&EX(This)))); } @@ -608,7 +604,7 @@ ZEND_END_ARG_INFO() /* public function toBinary(): string {{{ */ PHP_METHOD(UUID, toBinary) { - zend_parse_parameters_none(); + PHP_UUID_PARSE_PARAMETERS_NONE(); RETURN_STRINGL(*get_bytes(&EX(This)), PHP_UUID_LEN); } @@ -621,7 +617,7 @@ PHP_METHOD(UUID, toHex) { php_uuid_hex buffer; - zend_parse_parameters_none(); + PHP_UUID_PARSE_PARAMETERS_NONE(); php_uuid_to_hex(&buffer, *get_bytes(&EX(This))); RETURN_STRINGL(buffer, PHP_UUID_HEX_LEN); @@ -635,7 +631,7 @@ PHP_METHOD(UUID, toString) { php_uuid_string buffer; - zend_parse_parameters_none(); + PHP_UUID_PARSE_PARAMETERS_NONE(); php_uuid_to_string(&buffer, *get_bytes(&EX(This))); RETURN_STRINGL(buffer, PHP_UUID_STRING_LEN); @@ -705,7 +701,7 @@ ZEND_END_ARG_INFO() /* public function getInput(): string {{{ */ PHP_METHOD(UUIDParseException, getInput) { - zend_parse_parameters_none(); + PHP_UUID_PARSE_PARAMETERS_NONE(); RETURN_ZVAL(zend_read_property( php_ce_UUIDParseException, @@ -723,7 +719,7 @@ ZEND_END_ARG_INFO() /* public function getPosition(): int {{{ */ PHP_METHOD(UUIDParseException, getPosition) { - zend_parse_parameters_none(); + PHP_UUID_PARSE_PARAMETERS_NONE(); RETURN_ZVAL(zend_read_property( php_ce_UUIDParseException, From ea59cfac73005984a9e603cef7eed7292adccd4a Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Fri, 26 May 2017 11:55:50 +0200 Subject: [PATCH 29/54] Added ArgumentCountError throw annotations to stubs --- ext/standard/stubs/UUID.php | 35 +++++++++++++++++------ ext/standard/stubs/UUIDParseException.php | 4 +++ 2 files changed, 31 insertions(+), 8 deletions(-) diff --git a/ext/standard/stubs/UUID.php b/ext/standard/stubs/UUID.php index f28a38e438628..19c204ee8495d 100644 --- a/ext/standard/stubs/UUID.php +++ b/ext/standard/stubs/UUID.php @@ -77,7 +77,8 @@ * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); * assert($uuid->getVersion() === UUID::VERSION_1_TIME_BASED); * - * assert($uuid->toBinary() === "\x12\x3E\x45\x67\xE8\x9B\x12\xD3\xA4\x56\x42\x66\x55\x44\x00\x00"); + * assert($uuid->toBinary() === + * "\x12\x3E\x45\x67\xE8\x9B\x12\xD3\xA4\x56\x42\x66\x55\x44\x00\x00"); * assert($uuid->toHex() === '123e4567e89b12d3a456426655440000'); * assert($uuid->toString() === '123e4567-e89b-12d3-a456-426655440000'); * @@ -256,6 +257,7 @@ private function __construct() { } * @param string $input string of exactly 16 bytes to construct the * instance from. * @return UUID instance constructed from the input. + * @throws ArgumentCountError if less or more than one argument is passed. * @throws InvalidArgumentException if the input is not exactly 16 bytes * long. */ @@ -289,8 +291,7 @@ public static function fromBinary(string $input): UUID { } * UUID::parse('{01234567-89ab-cdef-0123-456789abcdef}'); * * // Leading and trailing garbage is ignored, so are extraneous hyphens. - * UUID::parse(" \t ---- { - * urn:uuid:----0123-4567-89ab-cdef-0123-4567-89ab-cdef---- } ---- \t "); + * UUID::parse(" \t ---- { urn:uuid:----0123-4567-89ab-cdef-0123-4567-89ab-cdef---- } ---- \t "); * * // However, note that there cannot be whitespace or braces between the * // URN scheme and the UUID itUUID. @@ -298,8 +299,7 @@ public static function fromBinary(string $input): UUID { } * UUID::parse('urn:uuid:{01234567-89ab-cdef-0123-456789abcdef'); * } * catch (UUIDParseException $e) { - * assert($e->getMessage() === 'Expected hexadecimal digit, but found - * '{' (0x7b)'); + * assert($e->getMessage() === 'Expected hexadecimal digit, but found '{' (0x7b)'); * } * * ?> @@ -311,6 +311,7 @@ public static function fromBinary(string $input): UUID { } * @see toString * @param string $input to parse as UUID and construct the instance from. * @return UUID constructed from the parsed input. + * @throws ArgumentCountError if less or more than one argument is passed. * @throws UUIDParseException if parsing of the input fails. */ public static function parse(string $input): UUID { } @@ -348,7 +349,8 @@ public static function parse(string $input): UUID { } * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); * assert($uuid->getVersion() === UUID::VERSION_3_NAME_BASED_MD5); * assert($uuid->toString() === '11a38b9a-b3da-360f-9353-a5a725514269'); - * assert($uuid == UUID::v3(UUID::NamespaceDNS(), 'php.net')); + * assert($uuid == UUID::v3(UUID::NamespaceDNS(), + * 'php.net')); * * ?> * ``` @@ -360,6 +362,7 @@ public static function parse(string $input): UUID { } * @param UUID $namespace to construct the UUID in. * @param string $name to construct the UUID from. * @return UUID + * @throws ArgumentCountError if less or more than two arguments are passed. */ public static function v3(UUID $namespace, string $name): UUID { } @@ -393,6 +396,7 @@ public static function v3(UUID $namespace, string $name): UUID { } * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 * @return UUID * @throws Exception if it was not possible to gather sufficient entropy. + * @throws ArgumentCountError if arguments are passed. */ public static function v4(): UUID { } @@ -424,7 +428,8 @@ public static function v4(): UUID { } * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); * assert($uuid->getVersion() === UUID::VERSION_5_NAME_BASED_SHA1); * assert($uuid->toString() === 'c4a760a8-dbcf-5254-a0d9-6a4474bd1b62'); - * assert($uuid == UUID::v5(UUID::NamespaceDNS(), 'php.net')); + * assert($uuid == UUID::v5(UUID::NamespaceDNS(), + * 'php.net')); * * ?> * ``` @@ -436,6 +441,7 @@ public static function v4(): UUID { } * @param UUID $namespace to construct the UUID in. * @param string $name to construct the UUID from. * @return UUID + * @throws ArgumentCountError if less or more than two arguments are passed. */ public static function v5(UUID $namespace, string $name): UUID { } @@ -447,6 +453,7 @@ public static function v5(UUID $namespace, string $name): UUID { } * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/Domain_Name_System * @return UUID + * @throws ArgumentCountError if arguments are passed. */ public static function NamespaceDNS(): UUID { } @@ -458,6 +465,7 @@ public static function NamespaceDNS(): UUID { } * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/Object_identifier * @return UUID + * @throws ArgumentCountError if arguments are passed. */ public static function NamespaceOID(): UUID { } @@ -469,6 +477,7 @@ public static function NamespaceOID(): UUID { } * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/URL * @return UUID + * @throws ArgumentCountError if arguments are passed. */ public static function NamespaceURL(): UUID { } @@ -483,6 +492,7 @@ public static function NamespaceURL(): UUID { } * @see https://en.wikipedia.org/wiki/X.500 * @see https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol * @return UUID + * @throws ArgumentCountError if arguments are passed. */ public static function NamespaceX500(): UUID { } @@ -494,6 +504,7 @@ public static function NamespaceX500(): UUID { } * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID * @return UUID + * @throws ArgumentCountError if arguments are passed. */ public static function Nil(): UUID { } @@ -520,6 +531,7 @@ public function __set($_, $__): void { } * @see https://php.net/uuid.__wakeup * @see unserialize() * @return void + * @throws ArgumentCountError if arguments are passed. * @throws UnexpectedValueException if the binary string is not exactly 16 * bytes long. */ @@ -542,6 +554,7 @@ public function __wakeup(): void { } * @see UUID::VARIANT_FUTURE_RESERVED * @returns int An integer in [0, 3] where each value corresponds to one of * the `UUID::VARIANT_*` class constants. + * @throws ArgumentCountError if arguments are passed. */ public function getVariant(): int { } @@ -566,6 +579,7 @@ public function getVariant(): int { } * @return int An integer in [0, 15], the values [1, 5] correspond to one * of the `UUID::VERSION_*` class constants. The others are not defined * in RFC 4122. + * @throws ArgumentCountError if arguments are passed. */ public function getVersion(): int { } @@ -580,6 +594,7 @@ public function getVersion(): int { } * @see Nil * @return bool **TRUE** if this is the special nil UUID; **FALSE** * otherwise. + * @throws ArgumentCountError if arguments are passed. */ public function isNil(): bool { } @@ -597,7 +612,8 @@ public function isNil(): bool { } * toBinary() === "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"); + * assert($uuid->toBinary() === + * "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"); * * ?> * ``` @@ -605,6 +621,7 @@ public function isNil(): bool { } * @since 7.2 * @see https://php.net/uuid.toBinary * @return string + * @throws ArgumentCountError if arguments are passed. */ public function toBinary(): string { } @@ -628,6 +645,7 @@ public function toBinary(): string { } * @since 7.2 * @see https://php.net/uuid.toHex * @return string + * @throws ArgumentCountError if arguments are passed. */ public function toHex(): string { } @@ -654,6 +672,7 @@ public function toHex(): string { } * @see https://tools.ietf.org/html/rfc4122#page-4 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Format * @return string + * @throws ArgumentCountError if arguments are passed. */ public function toString(): string { } diff --git a/ext/standard/stubs/UUIDParseException.php b/ext/standard/stubs/UUIDParseException.php index a90cfd2749738..80b89499e1ec2 100644 --- a/ext/standard/stubs/UUIDParseException.php +++ b/ext/standard/stubs/UUIDParseException.php @@ -60,6 +60,8 @@ final class UUIDParseException extends Exception { * @param int $position at which parsing failed. * @param Throwable|null $previous error/exception that lead to this * failure, if any. + * @throws ArgumentCountError if less than two or more than four arguments + * are passed. */ public function __construct(string $reason, string $input, int $position = 0, ?Throwable $previous = null) { } @@ -67,6 +69,7 @@ public function __construct(string $reason, string $input, int $position = 0, ?T * Get the original input string that should have been parsed as a UUID. * * @return string + * @throws ArgumentCountError if arguments are passed. */ public function getInput(): string { } @@ -74,6 +77,7 @@ public function getInput(): string { } * Get the position in the input string where the parsing failure occurred. * * @return int + * @throws ArgumentCountError if arguments are passed. */ public function getPosition(): int { } } From d72e2aebadc130ac9b352dacb0fbad77d9e6f808 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Fri, 26 May 2017 15:00:28 +0200 Subject: [PATCH 30/54] Formatting of PhpDoc --- ext/standard/stubs/UUID.php | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/ext/standard/stubs/UUID.php b/ext/standard/stubs/UUID.php index 19c204ee8495d..78624ba800771 100644 --- a/ext/standard/stubs/UUID.php +++ b/ext/standard/stubs/UUID.php @@ -77,8 +77,7 @@ * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); * assert($uuid->getVersion() === UUID::VERSION_1_TIME_BASED); * - * assert($uuid->toBinary() === - * "\x12\x3E\x45\x67\xE8\x9B\x12\xD3\xA4\x56\x42\x66\x55\x44\x00\x00"); + * assert($uuid->toBinary() === "\x12\x3E\x45\x67\xE8\x9B\x12\xD3\xA4\x56\x42\x66\x55\x44\x00\x00"); * assert($uuid->toHex() === '123e4567e89b12d3a456426655440000'); * assert($uuid->toString() === '123e4567-e89b-12d3-a456-426655440000'); * @@ -268,17 +267,15 @@ public static function fromBinary(string $input): UUID { } * * The following UUID representations are parsable: * - * - hexadecimal representations (`aaaaaaaabbbbccccddddeeeeeeeeeeeee`), - * - string representations (`aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), + * - hexadecimal (`aaaaaaaabbbbccccddddeeeeeeeeeeeee`), + * - string (`aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), * - URNs (`urn:uuid:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), and - * - Microsoft representations (`{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee}`). + * - Microsoft (`{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee}`). * * Leading and trailing whitespace, namely spaces (` `) and tabs (`\t`), is * ignored, so are leading opening braces (`{`) and trailing closing braces * (`}`). Hyphens (`-`) are ignored everywhere. The parsing algorithm - * follows the [robustness - * principle](https://en.wikipedia.org/wiki/Robustness_principle) and is - * not meant for validation. + * follows the [robustness principle][wrp] and is not meant for validation. * * ## Examples * ``` @@ -305,6 +302,7 @@ public static function fromBinary(string $input): UUID { } * ?> * ``` * + * [wrp]: https://en.wikipedia.org/wiki/Robustness_principle * @since 7.2 * @see https://php.net/uuid.parse * @see toHex @@ -349,8 +347,7 @@ public static function parse(string $input): UUID { } * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); * assert($uuid->getVersion() === UUID::VERSION_3_NAME_BASED_MD5); * assert($uuid->toString() === '11a38b9a-b3da-360f-9353-a5a725514269'); - * assert($uuid == UUID::v3(UUID::NamespaceDNS(), - * 'php.net')); + * assert($uuid == UUID::v3(UUID::NamespaceDNS(), 'php.net')); * * ?> * ``` @@ -385,7 +382,7 @@ public static function v3(UUID $namespace, string $name): UUID { } * assert($uuid->isNil() === false); * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); * assert($uuid->getVersion() === UUID::VERSION_4_RANDOM); - * assert($uuid != UUID::v4()); + * assert($uuid != UUID::v4()); * * ?> * ``` @@ -428,8 +425,7 @@ public static function v4(): UUID { } * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); * assert($uuid->getVersion() === UUID::VERSION_5_NAME_BASED_SHA1); * assert($uuid->toString() === 'c4a760a8-dbcf-5254-a0d9-6a4474bd1b62'); - * assert($uuid == UUID::v5(UUID::NamespaceDNS(), - * 'php.net')); + * assert($uuid == UUID::v5(UUID::NamespaceDNS(), 'php.net')); * * ?> * ``` @@ -611,9 +607,7 @@ public function isNil(): bool { } * ``` * toBinary() === - * "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"); + * assert(UUID::NamespaceDNS()->toBinary() === "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"); * * ?> * ``` @@ -636,8 +630,7 @@ public function toBinary(): string { } * ``` * toHex() === '6ba7b8109dad11d180b400c04fd430c8'); + * assert(UUID::NamespaceDNS()->toHex() === '6ba7b8109dad11d180b400c04fd430c8'); * * ?> * ``` @@ -661,8 +654,7 @@ public function toHex(): string { } * ``` * toString() === '6ba7b810-9dad-11d1-80b4-00c04fd430c8'); + * assert(UUID::NamespaceDNS()->toString() === '6ba7b810-9dad-11d1-80b4-00c04fd430c8'); * * ?> * ``` @@ -682,6 +674,7 @@ public function toString(): string { } * immutable objects. * * @return void + * @throws Error upon every invocation. */ private function __clone() { } } From 1efeba34761a6e3bbf33be8cd71e74db1872481e Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Sat, 27 May 2017 10:41:56 +0200 Subject: [PATCH 31/54] Removed custom macros Exchanged custom macros with the new zent_parse_parameters_none_throw macro and inlined everything directly into their respective methods again. --- ext/standard/uuid.c | 82 ++++++++++++++++++++++++++++++++------------- 1 file changed, 58 insertions(+), 24 deletions(-) diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 1a5d4b5521d48..a7fad0c993955 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -26,13 +26,6 @@ #include "php_random.h" #include "sha1.h" -#define PHP_UUID_PARSE_PARAMETERS_NONE() \ - if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "") == FAILURE) return; - -#define PHP_UUID_NAMED_CONSTRUCTOR(uuid) \ - PHP_UUID_PARSE_PARAMETERS_NONE(); \ - new_uuid(return_value, uuid); - PHPAPI zend_class_entry *php_ce_UUID; PHPAPI zend_class_entry *php_ce_UUIDParseException; @@ -417,8 +410,9 @@ PHP_METHOD(UUID, parse) return; } - php_uuid_parse_throw(&uuid, input, input_len); - new_uuid(return_value, uuid); + if (php_uuid_parse_throw(&uuid, input, input_len) == SUCCESS) { + new_uuid(return_value, uuid); + } } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, UUID, 0) ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) @@ -451,7 +445,9 @@ PHP_METHOD(UUID, v4) { php_uuid uuid; - PHP_UUID_PARSE_PARAMETERS_NONE(); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } if (php_uuid_create_v4_throw(&uuid) == SUCCESS) { new_uuid(return_value, uuid); @@ -485,7 +481,11 @@ ZEND_END_ARG_INFO() /* public static function NamespaceDNS(): UUID {{{ */ PHP_METHOD(UUID, NamespaceDNS) { - PHP_UUID_NAMED_CONSTRUCTOR(PHP_UUID_NAMESPACE_DNS); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } + + new_uuid(return_value, PHP_UUID_NAMESPACE_DNS); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, UUID, 0) ZEND_END_ARG_INFO() @@ -494,7 +494,11 @@ ZEND_END_ARG_INFO() /* public static function NamespaceOID(): UUID {{{ */ PHP_METHOD(UUID, NamespaceOID) { - PHP_UUID_NAMED_CONSTRUCTOR(PHP_UUID_NAMESPACE_OID); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } + + new_uuid(return_value, PHP_UUID_NAMESPACE_OID); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, UUID, 0) ZEND_END_ARG_INFO() @@ -503,7 +507,11 @@ ZEND_END_ARG_INFO() /* public static function NamespaceURL(): UUID {{{ */ PHP_METHOD(UUID, NamespaceURL) { - PHP_UUID_NAMED_CONSTRUCTOR(PHP_UUID_NAMESPACE_URL); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } + + new_uuid(return_value, PHP_UUID_NAMESPACE_URL); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, UUID, 0) ZEND_END_ARG_INFO() @@ -512,7 +520,11 @@ ZEND_END_ARG_INFO() /* public static function NamespaceX500(): UUID {{{ */ PHP_METHOD(UUID, NamespaceX500) { - PHP_UUID_NAMED_CONSTRUCTOR(PHP_UUID_NAMESPACE_X500); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } + + new_uuid(return_value, PHP_UUID_NAMESPACE_X500); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, UUID, 0) ZEND_END_ARG_INFO() @@ -521,7 +533,11 @@ ZEND_END_ARG_INFO() /* public static function Nil(): UUID {{{ */ PHP_METHOD(UUID, Nil) { - PHP_UUID_NAMED_CONSTRUCTOR(PHP_UUID_NIL); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } + + new_uuid(return_value, PHP_UUID_NIL); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, UUID, 0) ZEND_END_ARG_INFO() @@ -552,7 +568,9 @@ PHP_METHOD(UUID, __wakeup) { size_t len = Z_STRLEN_P(zend_read_property(php_ce_UUID, &EX(This), UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, 1, NULL)); - PHP_UUID_PARSE_PARAMETERS_NONE(); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } if (len != PHP_UUID_LEN) { zend_throw_exception_ex( @@ -571,7 +589,9 @@ ZEND_END_ARG_INFO() /* public function getVaraitn(): int {{{ */ PHP_METHOD(UUID, getVariant) { - PHP_UUID_PARSE_PARAMETERS_NONE(); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } RETURN_LONG(php_uuid_get_variant(*get_bytes(&EX(This)))); } @@ -582,7 +602,9 @@ ZEND_END_ARG_INFO() /* public function getVersion(): int {{{ */ PHP_METHOD(UUID, getVersion) { - PHP_UUID_PARSE_PARAMETERS_NONE(); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } RETURN_LONG(php_uuid_get_version(*get_bytes(&EX(This)))); } @@ -593,7 +615,9 @@ ZEND_END_ARG_INFO() /* public function isNil(): bool {{{ */ PHP_METHOD(UUID, isNil) { - PHP_UUID_PARSE_PARAMETERS_NONE(); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } RETURN_BOOL(php_uuid_is_nil(*get_bytes(&EX(This)))); } @@ -604,7 +628,9 @@ ZEND_END_ARG_INFO() /* public function toBinary(): string {{{ */ PHP_METHOD(UUID, toBinary) { - PHP_UUID_PARSE_PARAMETERS_NONE(); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } RETURN_STRINGL(*get_bytes(&EX(This)), PHP_UUID_LEN); } @@ -617,7 +643,9 @@ PHP_METHOD(UUID, toHex) { php_uuid_hex buffer; - PHP_UUID_PARSE_PARAMETERS_NONE(); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } php_uuid_to_hex(&buffer, *get_bytes(&EX(This))); RETURN_STRINGL(buffer, PHP_UUID_HEX_LEN); @@ -631,7 +659,9 @@ PHP_METHOD(UUID, toString) { php_uuid_string buffer; - PHP_UUID_PARSE_PARAMETERS_NONE(); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } php_uuid_to_string(&buffer, *get_bytes(&EX(This))); RETURN_STRINGL(buffer, PHP_UUID_STRING_LEN); @@ -701,7 +731,9 @@ ZEND_END_ARG_INFO() /* public function getInput(): string {{{ */ PHP_METHOD(UUIDParseException, getInput) { - PHP_UUID_PARSE_PARAMETERS_NONE(); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } RETURN_ZVAL(zend_read_property( php_ce_UUIDParseException, @@ -719,7 +751,9 @@ ZEND_END_ARG_INFO() /* public function getPosition(): int {{{ */ PHP_METHOD(UUIDParseException, getPosition) { - PHP_UUID_PARSE_PARAMETERS_NONE(); + if (zend_parse_parameters_none_throw() == FAILURE) { + return; + } RETURN_ZVAL(zend_read_property( php_ce_UUIDParseException, From d281e24dcb5dac6e9c70d2c318963b0ed8ee5350 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Sun, 28 May 2017 11:51:17 +0200 Subject: [PATCH 32/54] Use self instead of UUID Using UUID directly is not as future compatible as using self, e.g. if we want to introduce namespaces. --- ext/standard/stubs/UUID.php | 20 ++++----- .../uuid/UUID/NamespaceDNS/definition.phpt | 2 +- .../uuid/UUID/NamespaceOID/definition.phpt | 2 +- .../uuid/UUID/NamespaceURL/definition.phpt | 2 +- .../uuid/UUID/NamespaceX500/definition.phpt | 2 +- .../tests/uuid/UUID/Nil/definition.phpt | 2 +- .../uuid/UUID/fromBinary/definition-001.phpt | 2 +- .../tests/uuid/UUID/parse/definition-001.phpt | 2 +- .../tests/uuid/UUID/v3/definition-001.phpt | 2 +- .../tests/uuid/UUID/v3/definition-002.phpt | 2 +- .../tests/uuid/UUID/v4/definition.phpt | 2 +- .../tests/uuid/UUID/v5/definition-001.phpt | 2 +- .../tests/uuid/UUID/v5/definition-002.phpt | 2 +- ext/standard/uuid.c | 44 +++++++++---------- 14 files changed, 44 insertions(+), 44 deletions(-) diff --git a/ext/standard/stubs/UUID.php b/ext/standard/stubs/UUID.php index 78624ba800771..961f97bf51de9 100644 --- a/ext/standard/stubs/UUID.php +++ b/ext/standard/stubs/UUID.php @@ -260,7 +260,7 @@ private function __construct() { } * @throws InvalidArgumentException if the input is not exactly 16 bytes * long. */ - public static function fromBinary(string $input): UUID { } + public static function fromBinary(string $input): self { } /** * Parse the given string as UUID. @@ -312,7 +312,7 @@ public static function fromBinary(string $input): UUID { } * @throws ArgumentCountError if less or more than one argument is passed. * @throws UUIDParseException if parsing of the input fails. */ - public static function parse(string $input): UUID { } + public static function parse(string $input): self { } /** * Construct new version 3 UUID. @@ -361,7 +361,7 @@ public static function parse(string $input): UUID { } * @return UUID * @throws ArgumentCountError if less or more than two arguments are passed. */ - public static function v3(UUID $namespace, string $name): UUID { } + public static function v3(self $namespace, string $name): self { } /** * Construct new version 4 UUID. @@ -395,7 +395,7 @@ public static function v3(UUID $namespace, string $name): UUID { } * @throws Exception if it was not possible to gather sufficient entropy. * @throws ArgumentCountError if arguments are passed. */ - public static function v4(): UUID { } + public static function v4(): self { } /** * Construct new version 5 UUID. @@ -439,7 +439,7 @@ public static function v4(): UUID { } * @return UUID * @throws ArgumentCountError if less or more than two arguments are passed. */ - public static function v5(UUID $namespace, string $name): UUID { } + public static function v5(self $namespace, string $name): self { } /** * Construct new Domain Name System (DNS) namespace UUID instance. @@ -451,7 +451,7 @@ public static function v5(UUID $namespace, string $name): UUID { } * @return UUID * @throws ArgumentCountError if arguments are passed. */ - public static function NamespaceDNS(): UUID { } + public static function NamespaceDNS(): self { } /** * Construct new Object Identifier (OID) namespace UUID instance. @@ -463,7 +463,7 @@ public static function NamespaceDNS(): UUID { } * @return UUID * @throws ArgumentCountError if arguments are passed. */ - public static function NamespaceOID(): UUID { } + public static function NamespaceOID(): self { } /** * Construct new Uniform Resource Locator (URL) namespace UUID instance. @@ -475,7 +475,7 @@ public static function NamespaceOID(): UUID { } * @return UUID * @throws ArgumentCountError if arguments are passed. */ - public static function NamespaceURL(): UUID { } + public static function NamespaceURL(): self { } /** * Construct new X.500 Distinguished Names (X.500 DN) namespace UUID @@ -490,7 +490,7 @@ public static function NamespaceURL(): UUID { } * @return UUID * @throws ArgumentCountError if arguments are passed. */ - public static function NamespaceX500(): UUID { } + public static function NamespaceX500(): self { } /** * Construct special nil UUID that has all 128 bits set to zero. @@ -502,7 +502,7 @@ public static function NamespaceX500(): UUID { } * @return UUID * @throws ArgumentCountError if arguments are passed. */ - public static function Nil(): UUID { } + public static function Nil(): self { } /** * Callback for dynamic adding of properties which throws an {@see Error} diff --git a/ext/standard/tests/uuid/UUID/NamespaceDNS/definition.phpt b/ext/standard/tests/uuid/UUID/NamespaceDNS/definition.phpt index c3cd0e8825fd6..5f2a5e7606679 100644 --- a/ext/standard/tests/uuid/UUID/NamespaceDNS/definition.phpt +++ b/ext/standard/tests/uuid/UUID/NamespaceDNS/definition.phpt @@ -19,6 +19,6 @@ var_dump( --EXPECT-- int(0) int(0) -string(4) "UUID" +string(4) "self" bool(true) bool(true) diff --git a/ext/standard/tests/uuid/UUID/NamespaceOID/definition.phpt b/ext/standard/tests/uuid/UUID/NamespaceOID/definition.phpt index 3886b7fdbed98..cd2eea5fd9761 100644 --- a/ext/standard/tests/uuid/UUID/NamespaceOID/definition.phpt +++ b/ext/standard/tests/uuid/UUID/NamespaceOID/definition.phpt @@ -19,6 +19,6 @@ var_dump( --EXPECT-- int(0) int(0) -string(4) "UUID" +string(4) "self" bool(true) bool(true) diff --git a/ext/standard/tests/uuid/UUID/NamespaceURL/definition.phpt b/ext/standard/tests/uuid/UUID/NamespaceURL/definition.phpt index 3b40b8bff62f2..a2785133fd8c0 100644 --- a/ext/standard/tests/uuid/UUID/NamespaceURL/definition.phpt +++ b/ext/standard/tests/uuid/UUID/NamespaceURL/definition.phpt @@ -19,6 +19,6 @@ var_dump( --EXPECT-- int(0) int(0) -string(4) "UUID" +string(4) "self" bool(true) bool(true) diff --git a/ext/standard/tests/uuid/UUID/NamespaceX500/definition.phpt b/ext/standard/tests/uuid/UUID/NamespaceX500/definition.phpt index a871d1689687b..6832b095918fb 100644 --- a/ext/standard/tests/uuid/UUID/NamespaceX500/definition.phpt +++ b/ext/standard/tests/uuid/UUID/NamespaceX500/definition.phpt @@ -19,6 +19,6 @@ var_dump( --EXPECT-- int(0) int(0) -string(4) "UUID" +string(4) "self" bool(true) bool(true) diff --git a/ext/standard/tests/uuid/UUID/Nil/definition.phpt b/ext/standard/tests/uuid/UUID/Nil/definition.phpt index 157530b596aaa..f0062254bba50 100644 --- a/ext/standard/tests/uuid/UUID/Nil/definition.phpt +++ b/ext/standard/tests/uuid/UUID/Nil/definition.phpt @@ -19,6 +19,6 @@ var_dump( --EXPECT-- int(0) int(0) -string(4) "UUID" +string(4) "self" bool(true) bool(true) diff --git a/ext/standard/tests/uuid/UUID/fromBinary/definition-001.phpt b/ext/standard/tests/uuid/UUID/fromBinary/definition-001.phpt index fac604fabde0b..c3160678dc162 100644 --- a/ext/standard/tests/uuid/UUID/fromBinary/definition-001.phpt +++ b/ext/standard/tests/uuid/UUID/fromBinary/definition-001.phpt @@ -19,6 +19,6 @@ var_dump( --EXPECT-- int(1) int(1) -string(4) "UUID" +string(4) "self" bool(true) bool(true) diff --git a/ext/standard/tests/uuid/UUID/parse/definition-001.phpt b/ext/standard/tests/uuid/UUID/parse/definition-001.phpt index b3820d1eb4048..7d025f93c1322 100644 --- a/ext/standard/tests/uuid/UUID/parse/definition-001.phpt +++ b/ext/standard/tests/uuid/UUID/parse/definition-001.phpt @@ -19,6 +19,6 @@ var_dump( --EXPECT-- int(1) int(1) -string(4) "UUID" +string(4) "self" bool(true) bool(true) diff --git a/ext/standard/tests/uuid/UUID/v3/definition-001.phpt b/ext/standard/tests/uuid/UUID/v3/definition-001.phpt index 88ef6924d2c5d..03a8b092cdd00 100644 --- a/ext/standard/tests/uuid/UUID/v3/definition-001.phpt +++ b/ext/standard/tests/uuid/UUID/v3/definition-001.phpt @@ -19,6 +19,6 @@ var_dump( --EXPECT-- int(2) int(2) -string(4) "UUID" +string(4) "self" bool(true) bool(true) diff --git a/ext/standard/tests/uuid/UUID/v3/definition-002.phpt b/ext/standard/tests/uuid/UUID/v3/definition-002.phpt index 007aae37551ca..7b43dc3b1edc6 100644 --- a/ext/standard/tests/uuid/UUID/v3/definition-002.phpt +++ b/ext/standard/tests/uuid/UUID/v3/definition-002.phpt @@ -20,7 +20,7 @@ var_dump( --EXPECT-- string(9) "namespace" bool(false) -string(4) "UUID" +string(4) "self" bool(false) bool(false) bool(false) diff --git a/ext/standard/tests/uuid/UUID/v4/definition.phpt b/ext/standard/tests/uuid/UUID/v4/definition.phpt index a0d93595c4932..5d269c86a95b3 100644 --- a/ext/standard/tests/uuid/UUID/v4/definition.phpt +++ b/ext/standard/tests/uuid/UUID/v4/definition.phpt @@ -19,6 +19,6 @@ var_dump( --EXPECT-- int(0) int(0) -string(4) "UUID" +string(4) "self" bool(true) bool(true) diff --git a/ext/standard/tests/uuid/UUID/v5/definition-001.phpt b/ext/standard/tests/uuid/UUID/v5/definition-001.phpt index bd3355b62a368..563a4cae7b240 100644 --- a/ext/standard/tests/uuid/UUID/v5/definition-001.phpt +++ b/ext/standard/tests/uuid/UUID/v5/definition-001.phpt @@ -19,6 +19,6 @@ var_dump( --EXPECT-- int(2) int(2) -string(4) "UUID" +string(4) "self" bool(true) bool(true) diff --git a/ext/standard/tests/uuid/UUID/v5/definition-002.phpt b/ext/standard/tests/uuid/UUID/v5/definition-002.phpt index fd91d55fbf3d0..2b49120517741 100644 --- a/ext/standard/tests/uuid/UUID/v5/definition-002.phpt +++ b/ext/standard/tests/uuid/UUID/v5/definition-002.phpt @@ -20,7 +20,7 @@ var_dump( --EXPECT-- string(9) "namespace" bool(false) -string(4) "UUID" +string(4) "self" bool(false) bool(false) bool(false) diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index a7fad0c993955..fcf1bc6508966 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -371,7 +371,7 @@ ZEND_BEGIN_ARG_INFO(UUID___construct_args, NULL) ZEND_END_ARG_INFO() /* }}} */ -/* public static function fromBinary(string $input): UUID {{{ */ +/* public static function fromBinary(string $input): self {{{ */ PHP_METHOD(UUID, fromBinary) { char *input = NULL; @@ -394,12 +394,12 @@ PHP_METHOD(UUID, fromBinary) new_uuid(return_value, input); } -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_fromBinary_args, 0, 1, UUID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_fromBinary_args, 0, 1, self, 0) ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) ZEND_END_ARG_INFO() /* }}} */ -/* public static function parse(string $input): UUID {{{ */ +/* public static function parse(string $input): self {{{ */ PHP_METHOD(UUID, parse) { char *input = NULL; @@ -414,12 +414,12 @@ PHP_METHOD(UUID, parse) new_uuid(return_value, uuid); } } -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, UUID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, self, 0) ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) ZEND_END_ARG_INFO() /* }}} */ -/* public static function v3(UUID $namespace, string $name): UUID {{{ */ +/* public static function v3(self $namespace, string $name): self {{{ */ PHP_METHOD(UUID, v3) { zval *namespace = NULL; @@ -434,13 +434,13 @@ PHP_METHOD(UUID, v3) php_uuid_create_v3(&uuid, get_bytes(namespace), name, name_len); new_uuid(return_value, uuid); } -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, UUID, 0) - ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, self, 0) + ZEND_ARG_OBJ_INFO(0, namespace, self, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_END_ARG_INFO() /* }}} */ -/* public static function v4(): UUID {{{ */ +/* public static function v4(): self {{{ */ PHP_METHOD(UUID, v4) { php_uuid uuid; @@ -453,11 +453,11 @@ PHP_METHOD(UUID, v4) new_uuid(return_value, uuid); } } -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_v4_args, UUID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_v4_args, self, 0) ZEND_END_ARG_INFO() /* }}} */ -/* public static function v5(UUID $namespace, string $name): UUID {{{ */ +/* public static function v5(self $namespace, string $name): self {{{ */ PHP_METHOD(UUID, v5) { zval *namespace = NULL; @@ -472,13 +472,13 @@ PHP_METHOD(UUID, v5) php_uuid_create_v5(&uuid, get_bytes(namespace), name, name_len); new_uuid(return_value, uuid); } -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, UUID, 0) - ZEND_ARG_OBJ_INFO(0, namespace, UUID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, self, 0) + ZEND_ARG_OBJ_INFO(0, namespace, self, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_END_ARG_INFO() /* }}} */ -/* public static function NamespaceDNS(): UUID {{{ */ +/* public static function NamespaceDNS(): self {{{ */ PHP_METHOD(UUID, NamespaceDNS) { if (zend_parse_parameters_none_throw() == FAILURE) { @@ -487,11 +487,11 @@ PHP_METHOD(UUID, NamespaceDNS) new_uuid(return_value, PHP_UUID_NAMESPACE_DNS); } -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, UUID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, self, 0) ZEND_END_ARG_INFO() /* }}} */ -/* public static function NamespaceOID(): UUID {{{ */ +/* public static function NamespaceOID(): self {{{ */ PHP_METHOD(UUID, NamespaceOID) { if (zend_parse_parameters_none_throw() == FAILURE) { @@ -500,11 +500,11 @@ PHP_METHOD(UUID, NamespaceOID) new_uuid(return_value, PHP_UUID_NAMESPACE_OID); } -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, UUID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, self, 0) ZEND_END_ARG_INFO() /* }}} */ -/* public static function NamespaceURL(): UUID {{{ */ +/* public static function NamespaceURL(): self {{{ */ PHP_METHOD(UUID, NamespaceURL) { if (zend_parse_parameters_none_throw() == FAILURE) { @@ -513,11 +513,11 @@ PHP_METHOD(UUID, NamespaceURL) new_uuid(return_value, PHP_UUID_NAMESPACE_URL); } -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, UUID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, self, 0) ZEND_END_ARG_INFO() /* }}} */ -/* public static function NamespaceX500(): UUID {{{ */ +/* public static function NamespaceX500(): self {{{ */ PHP_METHOD(UUID, NamespaceX500) { if (zend_parse_parameters_none_throw() == FAILURE) { @@ -526,11 +526,11 @@ PHP_METHOD(UUID, NamespaceX500) new_uuid(return_value, PHP_UUID_NAMESPACE_X500); } -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, UUID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, self, 0) ZEND_END_ARG_INFO() /* }}} */ -/* public static function Nil(): UUID {{{ */ +/* public static function Nil(): self {{{ */ PHP_METHOD(UUID, Nil) { if (zend_parse_parameters_none_throw() == FAILURE) { @@ -539,7 +539,7 @@ PHP_METHOD(UUID, Nil) new_uuid(return_value, PHP_UUID_NIL); } -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, UUID, 0) +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, self, 0) ZEND_END_ARG_INFO() /* }}} */ From 0e31760d6726b70c914fe4fbc31f0c5df5633777 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Sun, 28 May 2017 11:54:13 +0200 Subject: [PATCH 33/54] Removed hard coded class name Using the hard coded class name requires that these particular parts have to be updated in case we want to introduce namespaces. These paths are cold anyways, hence, there is no performance loss or anything. --- ext/standard/uuid.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index fcf1bc6508966..ec498975955b1 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -546,7 +546,7 @@ ZEND_END_ARG_INFO() /* private function __clone() {{{ */ PHP_METHOD(UUID, __clone) { - zend_throw_error(zend_ce_error, "Cannot clone immutable UUID object"); + zend_throw_error(zend_ce_error, "Cannot clone immutable %s object", ZSTR_VAL(php_ce_UUID->name)); } ZEND_BEGIN_ARG_INFO(UUID___clone_args, NULL) ZEND_END_ARG_INFO() @@ -555,7 +555,7 @@ ZEND_END_ARG_INFO() /* public function __set($_, $__): void {{{ */ PHP_METHOD(UUID, __set) { - zend_throw_error(zend_ce_error, "Cannot set dynamic properties on immutable UUID object"); + zend_throw_error(zend_ce_error, "Cannot set dynamic properties on immutable %s object", ZSTR_VAL(php_ce_UUID->name)); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___set_args, IS_VOID, 0) ZEND_ARG_INFO(0, _) From c0d46350b5e0d7ca4a595b507be1336d02e1d024 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Sun, 28 May 2017 12:36:59 +0200 Subject: [PATCH 34/54] Verify type after deserialization The assumption that the property contains a value of type string must be ensured, since there is no guarantee. --- ext/standard/stubs/UUID.php | 4 ++-- .../tests/uuid/UUID/__wakeup/error-001.phpt | 17 +++++++++++++++++ .../__wakeup/{error.phpt => error-002.phpt} | 0 ext/standard/uuid.c | 19 ++++++++++++++++--- 4 files changed, 35 insertions(+), 5 deletions(-) create mode 100644 ext/standard/tests/uuid/UUID/__wakeup/error-001.phpt rename ext/standard/tests/uuid/UUID/__wakeup/{error.phpt => error-002.phpt} (100%) diff --git a/ext/standard/stubs/UUID.php b/ext/standard/stubs/UUID.php index 961f97bf51de9..54c6fe73e0ce3 100644 --- a/ext/standard/stubs/UUID.php +++ b/ext/standard/stubs/UUID.php @@ -528,8 +528,8 @@ public function __set($_, $__): void { } * @see unserialize() * @return void * @throws ArgumentCountError if arguments are passed. - * @throws UnexpectedValueException if the binary string is not exactly 16 - * bytes long. + * @throws UnexpectedValueException if the value of the {@see binary} + * property is not of type string, or not exactly 16 bytes long. */ public function __wakeup(): void { } diff --git a/ext/standard/tests/uuid/UUID/__wakeup/error-001.phpt b/ext/standard/tests/uuid/UUID/__wakeup/error-001.phpt new file mode 100644 index 0000000000000..20cf5f58cef74 --- /dev/null +++ b/ext/standard/tests/uuid/UUID/__wakeup/error-001.phpt @@ -0,0 +1,17 @@ +--TEST-- +UUID::__wakeup throws UnexpectedValueException if binary property value is not of type string +--CREDITS-- +Richard Fussenegger php@fleshgrinder.com +--FILE-- +getMessage(), "\n"; +} + +?> +--EXPECTF-- +Expected value of type string, but found null diff --git a/ext/standard/tests/uuid/UUID/__wakeup/error.phpt b/ext/standard/tests/uuid/UUID/__wakeup/error-002.phpt similarity index 100% rename from ext/standard/tests/uuid/UUID/__wakeup/error.phpt rename to ext/standard/tests/uuid/UUID/__wakeup/error-002.phpt diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index ec498975955b1..611d99dcaef39 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -566,19 +566,32 @@ ZEND_END_ARG_INFO() /* public function __wakeup(): void {{{ */ PHP_METHOD(UUID, __wakeup) { - size_t len = Z_STRLEN_P(zend_read_property(php_ce_UUID, &EX(This), UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, 1, NULL)); + zval *binary = NULL; if (zend_parse_parameters_none_throw() == FAILURE) { return; } - if (len != PHP_UUID_LEN) { + binary = zend_read_property(php_ce_UUID, &EX(This), UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, 1, NULL); + + if (Z_TYPE_P(binary) != IS_STRING) { + zend_throw_exception_ex( + spl_ce_UnexpectedValueException, + 0, + "Expected value of type %s, but found %s", + zend_get_type_by_const(IS_STRING), + zend_zval_type_name(binary) + ); + return; + } + + if (Z_STRLEN_P(binary) != PHP_UUID_LEN) { zend_throw_exception_ex( spl_ce_UnexpectedValueException, 0, "Expected exactly %u bytes, but found %u", PHP_UUID_LEN, - len + Z_STRLEN_P(binary) ); } } From d1dc0c5cc36287a6f7a7909bd6a27417bd1a5357 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Sun, 28 May 2017 13:46:45 +0200 Subject: [PATCH 35/54] Moved inlinable declaration to header The functions, as they were, would not have been inlined correctly. This changes ensures that the functions are type-safe (compared to a macro), and always inlined. --- ext/standard/php_uuid.h | 44 ++++++++++++++++++++++++++++++++++++----- ext/standard/uuid.c | 44 ----------------------------------------- 2 files changed, 39 insertions(+), 49 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index 5804cb3ed7682..1a9d0c49ac330 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -475,7 +475,13 @@ PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const * @param[in] uuid to get the variant from. * @return The variant of the given UUID. */ -PHPAPI zend_always_inline const php_uuid_variant php_uuid_get_variant(const php_uuid uuid); +static zend_always_inline const php_uuid_variant php_uuid_get_variant(const php_uuid uuid) +{ + if ((uuid[8] & 0xC0) == 0x80) return PHP_UUID_VARIANT_RFC4122; + if ((uuid[8] & 0xE0) == 0xC0) return PHP_UUID_VARIANT_MICROSOFT; + if ((uuid[8] & 0x80) == 0x00) return PHP_UUID_VARIANT_NCS; + return PHP_UUID_VARIANT_FUTURE_RESERVED; +} /** * Get the version associated with this UUID. @@ -498,7 +504,10 @@ PHPAPI zend_always_inline const php_uuid_variant php_uuid_get_variant(const php_ * values [1, 5] correspond to one of the `PHP_UUID_VERSION_*` constants. * The others are not defined in RFC 4122. */ -PHPAPI zend_always_inline const uint8_t php_uuid_get_version(const php_uuid uuid); +static zend_always_inline const uint8_t php_uuid_get_version(const php_uuid uuid) +{ + return uuid[6] >> 4; +} /** * Check if the given UUID is the special nil UUID that has all 128 bits set @@ -509,7 +518,10 @@ PHPAPI zend_always_inline const uint8_t php_uuid_get_version(const php_uuid uuid * @param[in] uuid to check. * @return TRUE if the UUID contains the special nil UUID; FALSE otherwise. */ -PHPAPI zend_always_inline const int php_uuid_is_nil(const php_uuid uuid); +static zend_always_inline const int php_uuid_is_nil(const php_uuid uuid) +{ + return memcmp(uuid, PHP_UUID_NIL, PHP_UUID_LEN) == 0; +} /** * Convert the UUID to its hexadecimal representation. @@ -529,7 +541,18 @@ PHPAPI zend_always_inline const int php_uuid_is_nil(const php_uuid uuid); * @param[out] buffer to store the hexadecimal representation in. * @param[in] uuid to convert. */ -PHPAPI zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_uuid uuid); +static zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_uuid uuid) +{ + sprintf( + (char *) buffer, + "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", + uuid[0], uuid[1], uuid[2], uuid[3], + uuid[4], uuid[5], + uuid[6], uuid[7], + uuid[8], uuid[9], + uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15] + ); +} /** * Convert the UUID to its string representation. @@ -550,7 +573,18 @@ PHPAPI zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_u * @param[out] buffer to store the string representation in. * @param[in] uuid to convert. */ -PHPAPI zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const php_uuid uuid); +static zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const php_uuid uuid) +{ + sprintf( + (char *) buffer, + "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", + uuid[0], uuid[1], uuid[2], uuid[3], + uuid[4], uuid[5], + uuid[6], uuid[7], + uuid[8], uuid[9], + uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15] + ); +} /** * Initialization function of the standard UUID submodule. diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 611d99dcaef39..571c5bb639e0f 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -296,50 +296,6 @@ PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const php_uuid_set_version(uuid, PHP_UUID_VERSION_5_NAME_BASED_SHA1); } -PHPAPI zend_always_inline const php_uuid_variant php_uuid_get_variant(const php_uuid uuid) -{ - if ((uuid[8] & 0xC0) == 0x80) return PHP_UUID_VARIANT_RFC4122; - if ((uuid[8] & 0xE0) == 0xC0) return PHP_UUID_VARIANT_MICROSOFT; - if ((uuid[8] & 0x80) == 0x00) return PHP_UUID_VARIANT_NCS; - return PHP_UUID_VARIANT_FUTURE_RESERVED; -} - -PHPAPI zend_always_inline const uint8_t php_uuid_get_version(const php_uuid uuid) -{ - return uuid[6] >> 4; -} - -PHPAPI zend_always_inline const int php_uuid_is_nil(const php_uuid uuid) -{ - return memcmp(uuid, PHP_UUID_NIL, PHP_UUID_LEN) == 0; -} - -PHPAPI zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_uuid uuid) -{ - sprintf( - (char *) buffer, - "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - uuid[0], uuid[1], uuid[2], uuid[3], - uuid[4], uuid[5], - uuid[6], uuid[7], - uuid[8], uuid[9], - uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15] - ); -} - -PHPAPI zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const php_uuid uuid) -{ - sprintf( - (char *) buffer, - "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", - uuid[0], uuid[1], uuid[2], uuid[3], - uuid[4], uuid[5], - uuid[6], uuid[7], - uuid[8], uuid[9], - uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15] - ); -} - /** * Get the UUID's bytes from the private property. * From 0cff5f1a2b5ae3c360c754dacce3adc9b477d097 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Sun, 28 May 2017 16:37:01 +0200 Subject: [PATCH 36/54] Use struct wrappers around arrays Also renamed the property from "binary" to "bytes" to be aligned with the C struct. --- ext/standard/php_uuid.h | 54 +++++++------ ext/standard/stubs/UUID.php | 2 +- .../tests/uuid/UUID/__wakeup/error-001.phpt | 4 +- .../tests/uuid/UUID/__wakeup/error-002.phpt | 2 +- .../tests/uuid/UUID/definition-004.phpt | 4 +- .../tests/uuid/UUID/fromBinary/basic.phpt | 2 +- .../tests/uuid/UUID/parse/basic-001.phpt | 2 +- .../tests/uuid/UUID/parse/basic-002.phpt | 2 +- .../tests/uuid/UUID/parse/basic-003.phpt | 2 +- .../tests/uuid/UUID/parse/basic-004.phpt | 2 +- .../tests/uuid/UUID/parse/variation-001.phpt | 2 +- .../tests/uuid/UUID/parse/variation-002.phpt | 2 +- .../tests/uuid/UUID/parse/variation-003.phpt | 2 +- .../tests/uuid/UUID/parse/variation-004.phpt | 2 +- .../tests/uuid/UUID/parse/variation-005.phpt | 2 +- ext/standard/uuid.c | 78 ++++++++++--------- 16 files changed, 85 insertions(+), 79 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index 1a9d0c49ac330..f2c30a46f1074 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -116,19 +116,23 @@ PHPAPI extern zend_class_entry *php_ce_UUID; /** UUIDParseException class entry for usage by other modules. */ PHPAPI extern zend_class_entry *php_ce_UUIDParseException; +/** UUID binary representation length without terminating NUL. */ +#define PHP_UUID_LEN 16 + /** UUID binary representation to store the 128 bit number in 16 bytes. */ -PHPAPI typedef uint8_t php_uuid[16]; +PHPAPI typedef struct php_uuid { + uint8_t bytes[PHP_UUID_LEN]; +} php_uuid; /** UUID hexadecimal representation: `000000001111222233334444444444444444\0` */ -PHPAPI typedef char php_uuid_hex[33]; +PHPAPI typedef struct php_uuid_hex { + char str[33]; +} php_uuid_hex; /** UUID string representation: `00000000-1111-2222-3333-4444444444444444\0` */ -PHPAPI typedef char php_uuid_string[37]; - -/** UUID representation lengths (without terminating NUL character). */ -PHPAPI extern const uint8_t PHP_UUID_LEN; -PHPAPI extern const uint8_t PHP_UUID_HEX_LEN; -PHPAPI extern const uint8_t PHP_UUID_STRING_LEN; +PHPAPI typedef struct php_uuid_string { + char str[37]; +} php_uuid_string; /** * Domain Name System (DNS) namespace UUID. @@ -477,9 +481,9 @@ PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const */ static zend_always_inline const php_uuid_variant php_uuid_get_variant(const php_uuid uuid) { - if ((uuid[8] & 0xC0) == 0x80) return PHP_UUID_VARIANT_RFC4122; - if ((uuid[8] & 0xE0) == 0xC0) return PHP_UUID_VARIANT_MICROSOFT; - if ((uuid[8] & 0x80) == 0x00) return PHP_UUID_VARIANT_NCS; + if ((uuid.bytes[8] & 0xC0) == 0x80) return PHP_UUID_VARIANT_RFC4122; + if ((uuid.bytes[8] & 0xE0) == 0xC0) return PHP_UUID_VARIANT_MICROSOFT; + if ((uuid.bytes[8] & 0x80) == 0x00) return PHP_UUID_VARIANT_NCS; return PHP_UUID_VARIANT_FUTURE_RESERVED; } @@ -506,7 +510,7 @@ static zend_always_inline const php_uuid_variant php_uuid_get_variant(const php_ */ static zend_always_inline const uint8_t php_uuid_get_version(const php_uuid uuid) { - return uuid[6] >> 4; + return uuid.bytes[6] >> 4; } /** @@ -520,7 +524,7 @@ static zend_always_inline const uint8_t php_uuid_get_version(const php_uuid uuid */ static zend_always_inline const int php_uuid_is_nil(const php_uuid uuid) { - return memcmp(uuid, PHP_UUID_NIL, PHP_UUID_LEN) == 0; + return memcmp(uuid.bytes, "", PHP_UUID_LEN) == 0; } /** @@ -544,13 +548,13 @@ static zend_always_inline const int php_uuid_is_nil(const php_uuid uuid) static zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_uuid uuid) { sprintf( - (char *) buffer, + buffer->str, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - uuid[0], uuid[1], uuid[2], uuid[3], - uuid[4], uuid[5], - uuid[6], uuid[7], - uuid[8], uuid[9], - uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15] + uuid.bytes[0], uuid.bytes[1], uuid.bytes[2], uuid.bytes[3], + uuid.bytes[4], uuid.bytes[5], + uuid.bytes[6], uuid.bytes[7], + uuid.bytes[8], uuid.bytes[9], + uuid.bytes[10], uuid.bytes[11], uuid.bytes[12], uuid.bytes[13], uuid.bytes[14], uuid.bytes[15] ); } @@ -576,13 +580,13 @@ static zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_u static zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const php_uuid uuid) { sprintf( - (char *) buffer, + buffer->str, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", - uuid[0], uuid[1], uuid[2], uuid[3], - uuid[4], uuid[5], - uuid[6], uuid[7], - uuid[8], uuid[9], - uuid[10], uuid[11], uuid[12], uuid[13], uuid[14], uuid[15] + uuid.bytes[0], uuid.bytes[1], uuid.bytes[2], uuid.bytes[3], + uuid.bytes[4], uuid.bytes[5], + uuid.bytes[6], uuid.bytes[7], + uuid.bytes[8], uuid.bytes[9], + uuid.bytes[10], uuid.bytes[11], uuid.bytes[12], uuid.bytes[13], uuid.bytes[14], uuid.bytes[15] ); } diff --git a/ext/standard/stubs/UUID.php b/ext/standard/stubs/UUID.php index 54c6fe73e0ce3..9c2d1bcbc792e 100644 --- a/ext/standard/stubs/UUID.php +++ b/ext/standard/stubs/UUID.php @@ -222,7 +222,7 @@ final class UUID { * @see toBinary * @var string */ - private $binary; + private $bytes; /** * Use {@see fromBinary} or {@see parse} to construct a new instance. diff --git a/ext/standard/tests/uuid/UUID/__wakeup/error-001.phpt b/ext/standard/tests/uuid/UUID/__wakeup/error-001.phpt index 20cf5f58cef74..c556f56e057ad 100644 --- a/ext/standard/tests/uuid/UUID/__wakeup/error-001.phpt +++ b/ext/standard/tests/uuid/UUID/__wakeup/error-001.phpt @@ -1,12 +1,12 @@ --TEST-- -UUID::__wakeup throws UnexpectedValueException if binary property value is not of type string +UUID::__wakeup throws UnexpectedValueException if property value is not of type string --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- getMessage(), "\n"; diff --git a/ext/standard/tests/uuid/UUID/__wakeup/error-002.phpt b/ext/standard/tests/uuid/UUID/__wakeup/error-002.phpt index 1e3f5f486937f..45fcdf3fee2dd 100644 --- a/ext/standard/tests/uuid/UUID/__wakeup/error-002.phpt +++ b/ext/standard/tests/uuid/UUID/__wakeup/error-002.phpt @@ -8,7 +8,7 @@ Richard Fussenegger php@fleshgrinder.com foreach ([0, 1, 15, 17, random_int(18, 256)] as $i) { try { $bytes = $i === 0 ? '' : random_bytes($i); - unserialize("O:4:\"UUID\":1:{s:12:\"\0UUID\0binary\";s:{$i}:\"{$bytes}\";}"); + unserialize("O:4:\"UUID\":1:{s:11:\"\0UUID\0bytes\";s:{$i}:\"{$bytes}\";}"); } catch (UnexpectedValueException $e) { echo $e->getMessage(), "\n"; diff --git a/ext/standard/tests/uuid/UUID/definition-004.phpt b/ext/standard/tests/uuid/UUID/definition-004.phpt index 8ad081d5e9380..d16da6f02aa46 100644 --- a/ext/standard/tests/uuid/UUID/definition-004.phpt +++ b/ext/standard/tests/uuid/UUID/definition-004.phpt @@ -1,11 +1,11 @@ --TEST-- -UUID::$binary property definition +UUID::$bytes property definition --CREDITS-- Richard Fussenegger php@fleshgrinder.com --FILE-- isPrivate(), $p->isStatic()); diff --git a/ext/standard/tests/uuid/UUID/fromBinary/basic.phpt b/ext/standard/tests/uuid/UUID/fromBinary/basic.phpt index 469d3f4986b93..ca2d2b65310a4 100644 --- a/ext/standard/tests/uuid/UUID/fromBinary/basic.phpt +++ b/ext/standard/tests/uuid/UUID/fromBinary/basic.phpt @@ -6,7 +6,7 @@ Richard Fussenegger php@fleshgrinder.com setAccessible(true); var_dump($p->getValue($uuid) === ' '); diff --git a/ext/standard/tests/uuid/UUID/parse/basic-001.phpt b/ext/standard/tests/uuid/UUID/parse/basic-001.phpt index b98450ad0991a..7930967897eee 100644 --- a/ext/standard/tests/uuid/UUID/parse/basic-001.phpt +++ b/ext/standard/tests/uuid/UUID/parse/basic-001.phpt @@ -7,7 +7,7 @@ Richard Fussenegger php@fleshgrinder.com $uuid = UUID::parse('123e4567e89b12d3a456426655440000'); -$p = new ReflectionProperty($uuid, 'binary'); +$p = new ReflectionProperty($uuid, 'bytes'); $p->setAccessible(true); var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); diff --git a/ext/standard/tests/uuid/UUID/parse/basic-002.phpt b/ext/standard/tests/uuid/UUID/parse/basic-002.phpt index 847f87022d128..105c0f74005bc 100644 --- a/ext/standard/tests/uuid/UUID/parse/basic-002.phpt +++ b/ext/standard/tests/uuid/UUID/parse/basic-002.phpt @@ -7,7 +7,7 @@ Richard Fussenegger php@fleshgrinder.com $uuid = UUID::parse('123e4567-e89b-12d3-a456-426655440000'); -$p = new ReflectionProperty($uuid, 'binary'); +$p = new ReflectionProperty($uuid, 'bytes'); $p->setAccessible(true); var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); diff --git a/ext/standard/tests/uuid/UUID/parse/basic-003.phpt b/ext/standard/tests/uuid/UUID/parse/basic-003.phpt index 3d608aa426623..6f37149e8cd01 100644 --- a/ext/standard/tests/uuid/UUID/parse/basic-003.phpt +++ b/ext/standard/tests/uuid/UUID/parse/basic-003.phpt @@ -7,7 +7,7 @@ Richard Fussenegger php@fleshgrinder.com $uuid = UUID::parse('urn:uuid:123e4567-e89b-12d3-a456-426655440000'); -$p = new ReflectionProperty($uuid, 'binary'); +$p = new ReflectionProperty($uuid, 'bytes'); $p->setAccessible(true); var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); diff --git a/ext/standard/tests/uuid/UUID/parse/basic-004.phpt b/ext/standard/tests/uuid/UUID/parse/basic-004.phpt index 3b0fd042738ce..8ece658d1f74d 100644 --- a/ext/standard/tests/uuid/UUID/parse/basic-004.phpt +++ b/ext/standard/tests/uuid/UUID/parse/basic-004.phpt @@ -7,7 +7,7 @@ Richard Fussenegger php@fleshgrinder.com $uuid = UUID::parse('{123e4567-e89b-12d3-a456-426655440000}'); -$p = new ReflectionProperty($uuid, 'binary'); +$p = new ReflectionProperty($uuid, 'bytes'); $p->setAccessible(true); var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); diff --git a/ext/standard/tests/uuid/UUID/parse/variation-001.phpt b/ext/standard/tests/uuid/UUID/parse/variation-001.phpt index 96e53aa485f47..d779734e5aa3e 100644 --- a/ext/standard/tests/uuid/UUID/parse/variation-001.phpt +++ b/ext/standard/tests/uuid/UUID/parse/variation-001.phpt @@ -7,7 +7,7 @@ Richard Fussenegger php@fleshgrinder.com $uuid = UUID::parse('123E4567E89B12D3A456426655440000'); -$p = new ReflectionProperty($uuid, 'binary'); +$p = new ReflectionProperty($uuid, 'bytes'); $p->setAccessible(true); var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); diff --git a/ext/standard/tests/uuid/UUID/parse/variation-002.phpt b/ext/standard/tests/uuid/UUID/parse/variation-002.phpt index 3811c97ed0f44..c5d1240bfefb4 100644 --- a/ext/standard/tests/uuid/UUID/parse/variation-002.phpt +++ b/ext/standard/tests/uuid/UUID/parse/variation-002.phpt @@ -7,7 +7,7 @@ Richard Fussenegger php@fleshgrinder.com $uuid = UUID::parse(" \t{\t{ { \t123e4567e89b12d3a456426655440000"); -$p = new ReflectionProperty($uuid, 'binary'); +$p = new ReflectionProperty($uuid, 'bytes'); $p->setAccessible(true); var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); diff --git a/ext/standard/tests/uuid/UUID/parse/variation-003.phpt b/ext/standard/tests/uuid/UUID/parse/variation-003.phpt index 69fcffbb06d11..98a7a4fe923cd 100644 --- a/ext/standard/tests/uuid/UUID/parse/variation-003.phpt +++ b/ext/standard/tests/uuid/UUID/parse/variation-003.phpt @@ -7,7 +7,7 @@ Richard Fussenegger php@fleshgrinder.com $uuid = UUID::parse("123e4567e89b12d3a456426655440000 \t}\t} } \t"); -$p = new ReflectionProperty($uuid, 'binary'); +$p = new ReflectionProperty($uuid, 'bytes'); $p->setAccessible(true); var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); diff --git a/ext/standard/tests/uuid/UUID/parse/variation-004.phpt b/ext/standard/tests/uuid/UUID/parse/variation-004.phpt index 2e10eaf9f6d25..744fb74eb008c 100644 --- a/ext/standard/tests/uuid/UUID/parse/variation-004.phpt +++ b/ext/standard/tests/uuid/UUID/parse/variation-004.phpt @@ -7,7 +7,7 @@ Richard Fussenegger php@fleshgrinder.com $uuid = UUID::parse('----123e-4567-e89b-12d3-a456-4266-5544-0000----'); -$p = new ReflectionProperty($uuid, 'binary'); +$p = new ReflectionProperty($uuid, 'bytes'); $p->setAccessible(true); var_dump($p->getValue($uuid) === "\x12\x3e\x45\x67\xe8\x9b\x12\xd3\xa4\x56\x42\x66\x55\x44\x00\x00"); diff --git a/ext/standard/tests/uuid/UUID/parse/variation-005.phpt b/ext/standard/tests/uuid/UUID/parse/variation-005.phpt index 7596bbf9793bc..bda87c038e22d 100644 --- a/ext/standard/tests/uuid/UUID/parse/variation-005.phpt +++ b/ext/standard/tests/uuid/UUID/parse/variation-005.phpt @@ -7,7 +7,7 @@ Richard Fussenegger php@fleshgrinder.com $uuid = UUID::parse(" \t ---- { urn:uuid:----0123-4567-89ab-cdef-0123-4567-89ab-cdef---- } ---- \t "); -$p = new ReflectionProperty($uuid, 'binary'); +$p = new ReflectionProperty($uuid, 'bytes'); $p->setAccessible(true); var_dump($p->getValue($uuid) === "\x01\x23\x45\x67\x89\xab\xcd\xef\x01\x23\x45\x67\x89\xab\xcd\xef"); diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 571c5bb639e0f..424e36348ab70 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -29,11 +29,11 @@ PHPAPI zend_class_entry *php_ce_UUID; PHPAPI zend_class_entry *php_ce_UUIDParseException; -PHPAPI const php_uuid PHP_UUID_NAMESPACE_DNS = "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"; -PHPAPI const php_uuid PHP_UUID_NAMESPACE_OID = "\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"; -PHPAPI const php_uuid PHP_UUID_NAMESPACE_URL = "\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"; -PHPAPI const php_uuid PHP_UUID_NAMESPACE_X500 = "\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"; -PHPAPI const php_uuid PHP_UUID_NIL = "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"; +PHPAPI const php_uuid PHP_UUID_NAMESPACE_DNS = { "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; +PHPAPI const php_uuid PHP_UUID_NAMESPACE_OID = { "\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; +PHPAPI const php_uuid PHP_UUID_NAMESPACE_URL = { "\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; +PHPAPI const php_uuid PHP_UUID_NAMESPACE_X500 = { "\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; +PHPAPI const php_uuid PHP_UUID_NIL = { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }; static const uint8_t PHP_UUID_VERSION_MIN = 0; PHPAPI const uint8_t PHP_UUID_VERSION_1_TIME_BASED = 1; @@ -43,12 +43,11 @@ PHPAPI const uint8_t PHP_UUID_VERSION_4_RANDOM = 4; PHPAPI const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1 = 5; static const uint8_t PHP_UUID_VERSION_MAX = 15; -PHPAPI const uint8_t PHP_UUID_LEN = sizeof(php_uuid); PHPAPI const uint8_t PHP_UUID_HEX_LEN = sizeof(php_uuid_hex) - 1; PHPAPI const uint8_t PHP_UUID_STRING_LEN = sizeof(php_uuid_string) - 1; -static const char UUID_BINARY_PROP[] = "binary"; -static const uint8_t UUID_BINARY_PROP_LEN = sizeof(UUID_BINARY_PROP) - 1; +static const char UUID_PROP_NAME[] = "bytes"; +static const uint8_t UUID_PROP_NAME_LEN = sizeof(UUID_PROP_NAME) - 1; static const char UUID_EX_INPUT_PROP[] = "input"; static const uint8_t UUID_EX_INPUT_PROP_LEN = sizeof(UUID_EX_INPUT_PROP) - 1; @@ -65,7 +64,7 @@ static const uint8_t URN_PREFIX_LEN = sizeof(URN_PREFIX) - 1 */ static zend_always_inline void set_variant_rfc4122(php_uuid *uuid) { - (*uuid)[8] = ((*uuid)[8] & 0x3F) | 0x80; + uuid->bytes[8] = (uuid->bytes[8] & 0x3F) | 0x80; } /** @@ -83,7 +82,7 @@ static zend_always_inline void php_uuid_set_version(php_uuid *uuid, const uint8_ { assert(PHP_UUID_VERSION_MIN <= version && version <= PHP_UUID_VERSION_MAX); - (*uuid)[6] = ((*uuid)[6] & 0x0F) | (version << 4); + uuid->bytes[6] = (uuid->bytes[6] & 0x0F) | (version << 4); } /** @@ -156,7 +155,6 @@ static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_char(c PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_len, const zend_bool throw) { - char chr; size_t position = 0; size_t digit = 0; size_t limit = input_len - 1; @@ -182,7 +180,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ } for (; position <= limit; ++position) { - chr = input[position]; + const char chr = input[position]; /* First digit of the byte. */ if (digit % 2 == 0) { @@ -242,7 +240,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ return FAILURE; } - (*uuid)[digit / 2] = byte; + uuid->bytes[digit / 2] = byte; } ++digit; @@ -303,7 +301,7 @@ PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const */ static zend_always_inline php_uuid *get_bytes(/*const*/ zval *object) { - return (php_uuid *) Z_STRVAL_P(zend_read_property(php_ce_UUID, object, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, 1, NULL)); + return (php_uuid *) Z_STRVAL_P(zend_read_property(php_ce_UUID, object, UUID_PROP_NAME, UUID_PROP_NAME_LEN, 1, NULL)); } /** @@ -315,7 +313,7 @@ static zend_always_inline php_uuid *get_bytes(/*const*/ zval *object) static zend_always_inline void new_uuid(zval *object, const php_uuid uuid) { object_init_ex(object, php_ce_UUID); - zend_update_property_stringl(php_ce_UUID, object, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, uuid, PHP_UUID_LEN); + zend_update_property_stringl(php_ce_UUID, object, UUID_PROP_NAME, UUID_PROP_NAME_LEN, uuid.bytes, PHP_UUID_LEN); } /* private function __construct() {{{ */ @@ -330,25 +328,25 @@ ZEND_END_ARG_INFO() /* public static function fromBinary(string $input): self {{{ */ PHP_METHOD(UUID, fromBinary) { - char *input = NULL; - size_t input_len; + zval *input = NULL; - if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &input, &input_len) == FAILURE) { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "z", &input) == FAILURE) { return; } - if (input_len != PHP_UUID_LEN) { + if (Z_STRLEN_P(input) != PHP_UUID_LEN) { zend_throw_exception_ex( spl_ce_InvalidArgumentException, 0, "Expected exactly %u bytes, but got %u", PHP_UUID_LEN, - input_len + Z_STRLEN_P(input) ); return; } - new_uuid(return_value, input); + object_init_ex(return_value, php_ce_UUID); + zend_update_property(php_ce_UUID, return_value, UUID_PROP_NAME, UUID_PROP_NAME_LEN, input); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_fromBinary_args, 0, 1, self, 0) ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) @@ -358,15 +356,14 @@ ZEND_END_ARG_INFO() /* public static function parse(string $input): self {{{ */ PHP_METHOD(UUID, parse) { - char *input = NULL; - size_t input_len; + zval *input = NULL; php_uuid uuid; - if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "s", &input, &input_len) == FAILURE) { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "z", &input) == FAILURE) { return; } - if (php_uuid_parse_throw(&uuid, input, input_len) == SUCCESS) { + if (php_uuid_parse_throw(&uuid, Z_STRVAL_P(input), Z_STRLEN_P(input)) == SUCCESS) { new_uuid(return_value, uuid); } } @@ -379,15 +376,14 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, v3) { zval *namespace = NULL; - char *name = NULL; - size_t name_len; + zval *name = NULL; php_uuid uuid; - if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zs", &namespace, &name, &name_len) == FAILURE) { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zz", &namespace, &name) == FAILURE) { return; } - php_uuid_create_v3(&uuid, get_bytes(namespace), name, name_len); + php_uuid_create_v3(&uuid, get_bytes(namespace), Z_STRVAL_P(name), Z_STRLEN_P(name)); new_uuid(return_value, uuid); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, self, 0) @@ -417,15 +413,14 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, v5) { zval *namespace = NULL; - char *name = NULL; - size_t name_len; + zval *name = NULL; php_uuid uuid; - if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zs", &namespace, &name, &name_len) == FAILURE) { + if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zz", &namespace, &name) == FAILURE) { return; } - php_uuid_create_v5(&uuid, get_bytes(namespace), name, name_len); + php_uuid_create_v5(&uuid, get_bytes(namespace), Z_STRVAL_P(name), Z_STRLEN_P(name)); new_uuid(return_value, uuid); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, self, 0) @@ -528,7 +523,7 @@ PHP_METHOD(UUID, __wakeup) return; } - binary = zend_read_property(php_ce_UUID, &EX(This), UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, 1, NULL); + binary = zend_read_property(php_ce_UUID, &EX(This), UUID_PROP_NAME, UUID_PROP_NAME_LEN, 1, NULL); if (Z_TYPE_P(binary) != IS_STRING) { zend_throw_exception_ex( @@ -601,7 +596,14 @@ PHP_METHOD(UUID, toBinary) return; } - RETURN_STRINGL(*get_bytes(&EX(This)), PHP_UUID_LEN); + RETURN_ZVAL(zend_read_property( + php_ce_UUID, + &EX(This), + UUID_PROP_NAME, + UUID_PROP_NAME_LEN, + 1, + NULL + ), 1, 0); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -617,7 +619,7 @@ PHP_METHOD(UUID, toHex) } php_uuid_to_hex(&buffer, *get_bytes(&EX(This))); - RETURN_STRINGL(buffer, PHP_UUID_HEX_LEN); + RETURN_STRINGL(buffer.str, PHP_UUID_HEX_LEN); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toHex_args, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -633,7 +635,7 @@ PHP_METHOD(UUID, toString) } php_uuid_to_string(&buffer, *get_bytes(&EX(This))); - RETURN_STRINGL(buffer, PHP_UUID_STRING_LEN); + RETURN_STRINGL(buffer.str, PHP_UUID_STRING_LEN); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toString_args, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -763,7 +765,7 @@ PHP_MINIT_FUNCTION(uuid) zend_declare_class_constant_long(php_ce_UUID, "VERSION_4_RANDOM", sizeof("VERSION_4_RANDOM") - 1, PHP_UUID_VERSION_4_RANDOM); zend_declare_class_constant_long(php_ce_UUID, "VERSION_5_NAME_BASED_SHA1", sizeof("VERSION_5_NAME_BASED_SHA1") - 1, PHP_UUID_VERSION_5_NAME_BASED_SHA1); - zend_declare_property_null(php_ce_UUID, UUID_BINARY_PROP, UUID_BINARY_PROP_LEN, ZEND_ACC_PRIVATE); + zend_declare_property_null(php_ce_UUID, UUID_PROP_NAME, UUID_PROP_NAME_LEN, ZEND_ACC_PRIVATE); INIT_CLASS_ENTRY(ce, "UUIDParseException", uuid_parse_exception_methods); php_ce_UUIDParseException = zend_register_internal_class_ex(&ce, zend_ce_exception); From a36bd49b49cd5818c15891ab8ad1c26068ceee6f Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Sun, 28 May 2017 16:52:43 +0200 Subject: [PATCH 37/54] Numbers are easier to read --- ext/standard/php_uuid.h | 8 ++++---- ext/standard/stubs/UUID.php | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index f2c30a46f1074..6935eb6e8774f 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -247,10 +247,10 @@ PHPAPI extern const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1; * * The following UUID representations are parsable: * - * - hexadecimal representations (`aaaaaaaabbbbccccddddeeeeeeeeeeeee`), - * - string representations (`aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), - * - URNs (`urn:uuid:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), and - * - Microsoft representations (`{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee}`). + * - hexadecimal (`00000000111122223333444444444444`), + * - string (`00000000-1111-2222-3333-444444444444`), + * - URNs (`urn:uuid:00000000-1111-2222-3333-444444444444`), and + * - Microsoft (`{00000000-1111-2222-3333-444444444444}`). * * Leading and trailing whitespace, namely spaces (` `) and tabs (`\t`), is * ignored, so are leading opening braces (`{`) and trailing closing braces diff --git a/ext/standard/stubs/UUID.php b/ext/standard/stubs/UUID.php index 9c2d1bcbc792e..9468fbc67bb4f 100644 --- a/ext/standard/stubs/UUID.php +++ b/ext/standard/stubs/UUID.php @@ -267,10 +267,10 @@ public static function fromBinary(string $input): self { } * * The following UUID representations are parsable: * - * - hexadecimal (`aaaaaaaabbbbccccddddeeeeeeeeeeeee`), - * - string (`aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), - * - URNs (`urn:uuid:aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee`), and - * - Microsoft (`{aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeeee}`). + * - hexadecimal (`00000000111122223333444444444444`), + * - string (`00000000-1111-2222-3333-444444444444`), + * - URNs (`urn:uuid:00000000-1111-2222-3333-444444444444`), and + * - Microsoft (`{00000000-1111-2222-3333-444444444444}`). * * Leading and trailing whitespace, namely spaces (` `) and tabs (`\t`), is * ignored, so are leading opening braces (`{`) and trailing closing braces From 942d117b8190690e8bcd975585e5baa66430a9dc Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Sun, 28 May 2017 19:30:35 +0200 Subject: [PATCH 38/54] Verify property value upon access --- ext/standard/php_uuid.h | 15 +- ext/standard/stubs/UUID.php | 132 +++++++------- .../tests/uuid/UUID/__wakeup/error-001.phpt | 2 +- .../tests/uuid/UUID/__wakeup/error-002.phpt | 10 +- ext/standard/uuid.c | 164 ++++++++++++++---- 5 files changed, 211 insertions(+), 112 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index 6935eb6e8774f..427bbc3f5edc8 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -286,8 +286,9 @@ PHPAPI extern const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1; * @param[out] uuid to store the result in. * @param[in] input to parse as UUID. * @param[in] input_len - * @param[in] throw whether to throw PHP exceptions (`TRUE`), or not (`FALSE`). + * @param[in] throw whether to throw PHP exceptions (`1`), or not (`0`). * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. + * @throws UUIDParseException if throw is enabled and parsing fails. */ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_len, const zend_bool throw); @@ -310,6 +311,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ * @param[in] input to parse as UUID. * @param[in] input_len * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. + * @throws UUIDParseException if throw is enabled and parsing fails. */ #define php_uuid_parse_throw(uuid, input, input_len) php_uuid_parse(uuid, input, input_len, 1) @@ -360,7 +362,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ * @param[in] name to create the UUID from. * @param[in] name_len */ -PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len); +PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid namespace, const char *name, const size_t name_len); /** * Create version 4 UUID. @@ -391,10 +393,11 @@ PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const * @see php_uuid_create_v4_silent * @see php_uuid_create_v4_throw * @param[out] uuid to store the result. - * @param[in] throw whether to throw a PHP exception (`TRUE`) if it was not - * possible to gather sufficient entropy, or not (`FALSE`). + * @param[in] throw whether to throw a PHP exception (`1`), or not (`0`). * @return `SUCCESS` if the generation succeeded, `FAILURE` if it was not * possible to gather sufficient entropy. + * @throws Exception if throw is enabled and it was not possible to gather + * sufficient entropy for generating random bytes. */ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); @@ -416,6 +419,8 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); * @param[out] uuid to store the result. * @return `SUCCESS` if the generation succeeded, `FAILURE` if it was not * possible to gather sufficient entropy. + * @throws Exception if throw is enabled and it was not possible to gather + * sufficient entropy for generating random bytes. */ #define php_uuid_create_v4_throw(uuid) php_uuid_create_v4(uuid, 1) @@ -461,7 +466,7 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); * @param[in] name to create the UUID from. * @param[in] name_len */ -PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len); +PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid namespace, const char *name, const size_t name_len); /** * Get the variant associated with this UUID. diff --git a/ext/standard/stubs/UUID.php b/ext/standard/stubs/UUID.php index 9468fbc67bb4f..794da9acbaa60 100644 --- a/ext/standard/stubs/UUID.php +++ b/ext/standard/stubs/UUID.php @@ -11,8 +11,7 @@ * * This class provides generation and parsing capabilities for Universally * Unique Identifiers (UUIDs, also known as Globally Unique Identifiers - * [GUIDs]) - * as specified in RFC 4122. + * [GUIDs]) as specified in [RFC 4122][rfc]. * * UUIDs are 128 bit integers that guarantee uniqueness across space and time. * They are mainly used to assign identifiers to entities without requiring a @@ -22,7 +21,7 @@ * * There are different types of UUIDs, known as variants. This implementation * generates UUIDs according to the Leach-Salz variant; the one specified in - * RFC 4122 as variant 1. Textual parsing supports both variant 1 and 2 + * [RFC 4122][rfc] as variant 1. Textual parsing supports both variant 1 and 2 * (Microsoft), and construction supports any kind of UUID. However, note that * the provided methods are **not** guaranteed to provide meaningful results if * any other variant than the Leach-Salz one is used. @@ -40,7 +39,7 @@ * and thus uses the best available random source of the operating system. * * Versions 1 and 2 are not supported due to privacy/security concerns. Refer - * to the Wikipedia article for more information. + * to the [Wikipedia article][wiki] for more information. * * ## Examples * ``` @@ -116,10 +115,10 @@ * ?> * ``` * + * [rfc]: https://tools.ietf.org/html/rfc4122 + * [wiki]: https://en.wikipedia.org/wiki/Universally_unique_identifier * @since 7.2 * @see https://php.net/uuid - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier - * @see https://tools.ietf.org/html/rfc4122 */ final class UUID { /** @@ -161,8 +160,9 @@ final class UUID { * * Generation of this version is not supported by this implementation due * to security concerns. Version 4 UUIDs are a good replacement for version - * 1 UUIDs without the privacy/security concerns (see Wikipedia). + * 1 UUIDs without the privacy/security concerns (see [Wikipedia][wiki]). * + * [wiki]: https://en.wikipedia.org/wiki/Universally_unique_identifier * @since 7.2 * @see https://tools.ietf.org/html/rfc4122#section-4.2 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_.28date-time_and_MAC_address.29 @@ -176,9 +176,10 @@ final class UUID { * Generation of this version is not supported by this implementation due * to security concerns, and uniqueness limitations for applications with * high allocations. Version 4 UUIDs are a good replacement for version 2 - * UUIDs without the privacy/security concerns (see Wikipedia), and they - * support high allocations. + * UUIDs without the privacy/security concerns (see [Wikipedia][wiki]), and + * they support high allocations. * + * [wiki]: https://en.wikipedia.org/wiki/Universally_unique_identifier * @since 7.2 * @see https://tools.ietf.org/html/rfc4122#section-4.2 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_2_.28date-time_and_MAC_Address.2C_DCE_security_version.29 @@ -253,12 +254,10 @@ private function __construct() { } * @since 7.2 * @see https://php.net/uuid.fromBinary * @see toBinary - * @param string $input string of exactly 16 bytes to construct the - * instance from. - * @return UUID instance constructed from the input. - * @throws ArgumentCountError if less or more than one argument is passed. - * @throws InvalidArgumentException if the input is not exactly 16 bytes - * long. + * @param $input string of exactly 16 bytes to construct the instance from. + * @returns UUID constructed from the binary input. + * @throws \ArgumentCountError if less or more than one argument is passed. + * @throws \InvalidArgumentException if the input is not 16 bytes long. */ public static function fromBinary(string $input): self { } @@ -307,10 +306,10 @@ public static function fromBinary(string $input): self { } * @see https://php.net/uuid.parse * @see toHex * @see toString - * @param string $input to parse as UUID and construct the instance from. - * @return UUID constructed from the parsed input. - * @throws ArgumentCountError if less or more than one argument is passed. - * @throws UUIDParseException if parsing of the input fails. + * @param $input to parse as UUID and construct the instance from. + * @returns UUID constructed from the parsed input. + * @throws \ArgumentCountError if less or more than one argument is passed. + * @throws \UUIDParseException if parsing of the input fails. */ public static function parse(string $input): self { } @@ -356,10 +355,11 @@ public static function parse(string $input): self { } * @see https://php.net/uuid.v3 * @see https://tools.ietf.org/html/rfc4122#section-4.3 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 - * @param UUID $namespace to construct the UUID in. - * @param string $name to construct the UUID from. - * @return UUID - * @throws ArgumentCountError if less or more than two arguments are passed. + * @param $namespace to construct the UUID in. + * @param $name to construct the UUID from. + * @returns UUID constructed from the name in the namespace. + * @throws \ArgumentCountError if less or more than two arguments are passed. + * @throws \Error if the namespace does not encapsulate a valid UUID. */ public static function v3(self $namespace, string $name): self { } @@ -391,9 +391,9 @@ public static function v3(self $namespace, string $name): self { } * @see https://php.net/uuid.v4 * @see https://tools.ietf.org/html/rfc4122#section-4.4 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 - * @return UUID - * @throws Exception if it was not possible to gather sufficient entropy. - * @throws ArgumentCountError if arguments are passed. + * @returns UUID constructed from random data. + * @throws \Exception if it was not possible to gather sufficient entropy. + * @throws \ArgumentCountError if arguments are passed. */ public static function v4(): self { } @@ -434,10 +434,11 @@ public static function v4(): self { } * @see https://php.net/uuid.v5 * @see @see https://tools.ietf.org/html/rfc4122#section-4.3 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 - * @param UUID $namespace to construct the UUID in. - * @param string $name to construct the UUID from. - * @return UUID - * @throws ArgumentCountError if less or more than two arguments are passed. + * @param $namespace to construct the UUID in. + * @param $name to construct the UUID from. + * @returns UUID constructed from the name in the namespace. + * @throws \ArgumentCountError if less or more than two arguments are passed. + * @throws \Error if the namespace does not encapsulate a valid UUID. */ public static function v5(self $namespace, string $name): self { } @@ -448,8 +449,8 @@ public static function v5(self $namespace, string $name): self { } * @see https://php.net/uuid.NamespaceDNS * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/Domain_Name_System - * @return UUID - * @throws ArgumentCountError if arguments are passed. + * @returns Predefined DNS namespace UUID. + * @throws \ArgumentCountError if arguments are passed. */ public static function NamespaceDNS(): self { } @@ -460,8 +461,8 @@ public static function NamespaceDNS(): self { } * @see https://php.net/uuid.NamespaceOID * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/Object_identifier - * @return UUID - * @throws ArgumentCountError if arguments are passed. + * @returns Predefined OID namespace UUID. + * @throws \ArgumentCountError if arguments are passed. */ public static function NamespaceOID(): self { } @@ -472,8 +473,8 @@ public static function NamespaceOID(): self { } * @see https://php.net/uuid.NamespaceURL * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/URL - * @return UUID - * @throws ArgumentCountError if arguments are passed. + * @returns Predefined URL namespace UUID. + * @throws \ArgumentCountError if arguments are passed. */ public static function NamespaceURL(): self { } @@ -487,8 +488,8 @@ public static function NamespaceURL(): self { } * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/X.500 * @see https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol - * @return UUID - * @throws ArgumentCountError if arguments are passed. + * @returns Predefined X.500 namespace UUID instance. + * @throws \ArgumentCountError if arguments are passed. */ public static function NamespaceX500(): self { } @@ -499,8 +500,8 @@ public static function NamespaceX500(): self { } * @see https://php.net/uuid.Nil * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID - * @return UUID - * @throws ArgumentCountError if arguments are passed. + * @returns Predefined special nil UUID. + * @throws \ArgumentCountError if arguments are passed. */ public static function Nil(): self { } @@ -515,8 +516,8 @@ public static function Nil(): self { } * @see https://php.net/uuid.__set * @param mixed $_ * @param mixed $__ - * @return void - * @throws Error upon every invocation, direct or indirect. + * @returns void + * @throws \Error upon every invocation, direct or indirect. */ public function __set($_, $__): void { } @@ -526,9 +527,9 @@ public function __set($_, $__): void { } * @since 7.2 * @see https://php.net/uuid.__wakeup * @see unserialize() - * @return void - * @throws ArgumentCountError if arguments are passed. - * @throws UnexpectedValueException if the value of the {@see binary} + * @returns void + * @throws \ArgumentCountError if arguments are passed. + * @throws \UnexpectedValueException if the value of the {@see bytes} * property is not of type string, or not exactly 16 bytes long. */ public function __wakeup(): void { } @@ -548,9 +549,10 @@ public function __wakeup(): void { } * @see UUID::VARIANT_RFC4122 * @see UUID::VARIANT_MICROSOFT * @see UUID::VARIANT_FUTURE_RESERVED - * @returns int An integer in [0, 3] where each value corresponds to one of - * the `UUID::VARIANT_*` class constants. - * @throws ArgumentCountError if arguments are passed. + * @returns An integer in [0, 3] where each value corresponds to one of the + * `UUID::VARIANT_*` class constants. + * @throws \ArgumentCountError if arguments are passed. + * @throws \Error if this instance does not encapsulate a valid UUID. */ public function getVariant(): int { } @@ -572,10 +574,11 @@ public function getVariant(): int { } * @see UUID::VERSION_3_NAME_BASED_MD5 * @see UUID::VERSION_4_RANDOM * @see UUID::VERSION_5_NAME_BASED_SHA1 - * @return int An integer in [0, 15], the values [1, 5] correspond to one - * of the `UUID::VERSION_*` class constants. The others are not defined - * in RFC 4122. - * @throws ArgumentCountError if arguments are passed. + * @returns An integer in [0, 15], the values [1, 5] correspond to one of the + * `UUID::VERSION_*` class constants. The others are not defined in + * RFC 4122. + * @throws \ArgumentCountError if arguments are passed. + * @throws \Error if this instance does not encapsulate a valid UUID. */ public function getVersion(): int { } @@ -588,9 +591,9 @@ public function getVersion(): int { } * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID * @see Nil - * @return bool **TRUE** if this is the special nil UUID; **FALSE** - * otherwise. - * @throws ArgumentCountError if arguments are passed. + * @returns **TRUE** if this is the special nil UUID; **FALSE** otherwise. + * @throws \ArgumentCountError if arguments are passed. + * @throws \Error if this instance does not encapsulate a valid UUID. */ public function isNil(): bool { } @@ -614,8 +617,9 @@ public function isNil(): bool { } * * @since 7.2 * @see https://php.net/uuid.toBinary - * @return string - * @throws ArgumentCountError if arguments are passed. + * @returns Binary representation of the UUID. + * @throws \ArgumentCountError if arguments are passed. + * @throws \Error if this instance does not encapsulate a valid UUID. */ public function toBinary(): string { } @@ -637,8 +641,9 @@ public function toBinary(): string { } * * @since 7.2 * @see https://php.net/uuid.toHex - * @return string - * @throws ArgumentCountError if arguments are passed. + * @returns Hexadecimal representation of the UUID. + * @throws \ArgumentCountError if arguments are passed. + * @throws \Error if this instance does not encapsulate a valid UUID. */ public function toHex(): string { } @@ -663,8 +668,9 @@ public function toHex(): string { } * @see https://php.net/uuid.toString * @see https://tools.ietf.org/html/rfc4122#page-4 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Format - * @return string - * @throws ArgumentCountError if arguments are passed. + * @returns String representation of the UUID. + * @throws \ArgumentCountError if arguments are passed. + * @throws \Error if this instance does not encapsulate a valid UUID. */ public function toString(): string { } @@ -673,8 +679,8 @@ public function toString(): string { } * disables cloning of this object, since it makes no sense to clone * immutable objects. * - * @return void - * @throws Error upon every invocation. + * @returns void + * @throws \Error upon every invocation. */ private function __clone() { } } diff --git a/ext/standard/tests/uuid/UUID/__wakeup/error-001.phpt b/ext/standard/tests/uuid/UUID/__wakeup/error-001.phpt index c556f56e057ad..d2004e46a937f 100644 --- a/ext/standard/tests/uuid/UUID/__wakeup/error-001.phpt +++ b/ext/standard/tests/uuid/UUID/__wakeup/error-001.phpt @@ -14,4 +14,4 @@ catch (UnexpectedValueException $e) { ?> --EXPECTF-- -Expected value of type string, but found null +Expected UUID::$bytes value to be of type string, but found null diff --git a/ext/standard/tests/uuid/UUID/__wakeup/error-002.phpt b/ext/standard/tests/uuid/UUID/__wakeup/error-002.phpt index 45fcdf3fee2dd..2e7e9b2094e2a 100644 --- a/ext/standard/tests/uuid/UUID/__wakeup/error-002.phpt +++ b/ext/standard/tests/uuid/UUID/__wakeup/error-002.phpt @@ -17,8 +17,8 @@ foreach ([0, 1, 15, 17, random_int(18, 256)] as $i) { ?> --EXPECTF-- -Expected exactly 16 bytes, but found 0 -Expected exactly 16 bytes, but found 1 -Expected exactly 16 bytes, but found 15 -Expected exactly 16 bytes, but found 17 -Expected exactly 16 bytes, but found %d +Expected UUID::$bytes value to be exactly 16 bytes long, but found 0 +Expected UUID::$bytes value to be exactly 16 bytes long, but found 1 +Expected UUID::$bytes value to be exactly 16 bytes long, but found 15 +Expected UUID::$bytes value to be exactly 16 bytes long, but found 17 +Expected UUID::$bytes value to be exactly 16 bytes long, but found %d diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 424e36348ab70..ab89baf4435ae 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -256,14 +256,14 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ return SUCCESS; } -PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) +PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid namespace, const char *name, const size_t name_len) { PHP_MD5_CTX context; PHP_MD5Init(&context); - PHP_MD5Update(&context, (char *) namespace, PHP_UUID_LEN); + PHP_MD5Update(&context, namespace.bytes, PHP_UUID_LEN); PHP_MD5Update(&context, name, name_len); - PHP_MD5Final((char *)uuid, &context); + PHP_MD5Final(uuid->bytes, &context); set_variant_rfc4122(uuid); php_uuid_set_version(uuid, PHP_UUID_VERSION_3_NAME_BASED_MD5); } @@ -280,28 +280,62 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw) return result; } -PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) +PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid namespace, const char *name, const size_t name_len) { PHP_SHA1_CTX context; char digest[20]; PHP_SHA1Init(&context); - PHP_SHA1Update(&context, (char *) namespace, PHP_UUID_LEN); + PHP_SHA1Update(&context, namespace.bytes, PHP_UUID_LEN); PHP_SHA1Update(&context, name, name_len); PHP_SHA1Final(digest, &context); - memcpy(uuid, digest, PHP_UUID_LEN); + memcpy(uuid->bytes, digest, PHP_UUID_LEN); set_variant_rfc4122(uuid); php_uuid_set_version(uuid, PHP_UUID_VERSION_5_NAME_BASED_SHA1); } /** - * Get the UUID's bytes from the private property. + * Get the UUID from the given UUID object. * - * @param[in] object to get the bytes from. + * We are required to check the type and length of the encapsulated value upon + * every access because users can change the value through various ways (e.g. + * reflection, closures, ...) and there is nothing that prevents them from + * doing so. + * + * @param[in] uuid_object to get the UUID from. + * @return SUCCESS if the UUID could be read from the object, FAILURE otherwise. + * @throws TypeError if the value is not of type string. + * @throws Error if the string value is not exactly 16 bytes long. */ -static zend_always_inline php_uuid *get_bytes(/*const*/ zval *object) +static zend_always_inline php_uuid *get_uuid(/*const*/ zval uuid_object) { - return (php_uuid *) Z_STRVAL_P(zend_read_property(php_ce_UUID, object, UUID_PROP_NAME, UUID_PROP_NAME_LEN, 1, NULL)); + zval *bytes = zend_read_property(php_ce_UUID, &uuid_object, UUID_PROP_NAME, UUID_PROP_NAME_LEN, 1, NULL); + + if (Z_TYPE_P(bytes) != IS_STRING) { + zend_throw_error( + zend_ce_type_error, + "Expected %s::$%s value to be of type %s, but found %s", + ZSTR_VAL(php_ce_UUID->name), + UUID_PROP_NAME, + zend_get_type_by_const(IS_STRING), + zend_zval_type_name(bytes) + ); + return NULL; + } + + if (Z_STRLEN_P(bytes) != PHP_UUID_LEN) { + zend_throw_error( + zend_ce_error, + "Expected %s::$%s value to be exactly %u bytes long, but found %u", + ZSTR_VAL(php_ce_UUID->name), + UUID_PROP_NAME, + PHP_UUID_LEN, + Z_STRLEN_P(bytes) + ); + return NULL; + } + + return (php_uuid *) Z_STRVAL_P(bytes); } /** @@ -363,9 +397,11 @@ PHP_METHOD(UUID, parse) return; } - if (php_uuid_parse_throw(&uuid, Z_STRVAL_P(input), Z_STRLEN_P(input)) == SUCCESS) { - new_uuid(return_value, uuid); + if (php_uuid_parse_throw(&uuid, Z_STRVAL_P(input), Z_STRLEN_P(input)) == FAILURE) { + return; } + + new_uuid(return_value, uuid); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, self, 0) ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) @@ -377,13 +413,19 @@ PHP_METHOD(UUID, v3) { zval *namespace = NULL; zval *name = NULL; + php_uuid *nsid = NULL; php_uuid uuid; if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zz", &namespace, &name) == FAILURE) { return; } - php_uuid_create_v3(&uuid, get_bytes(namespace), Z_STRVAL_P(name), Z_STRLEN_P(name)); + nsid = get_uuid(*namespace); + if (nsid == NULL) { + return; + } + + php_uuid_create_v3(&uuid, *nsid, Z_STRVAL_P(name), Z_STRLEN_P(name)); new_uuid(return_value, uuid); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, self, 0) @@ -401,9 +443,11 @@ PHP_METHOD(UUID, v4) return; } - if (php_uuid_create_v4_throw(&uuid) == SUCCESS) { - new_uuid(return_value, uuid); + if (php_uuid_create_v4_throw(&uuid) == FAILURE) { + return; } + + new_uuid(return_value, uuid); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_v4_args, self, 0) ZEND_END_ARG_INFO() @@ -414,13 +458,19 @@ PHP_METHOD(UUID, v5) { zval *namespace = NULL; zval *name = NULL; + php_uuid *nsid = NULL; php_uuid uuid; if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "zz", &namespace, &name) == FAILURE) { return; } - php_uuid_create_v5(&uuid, get_bytes(namespace), Z_STRVAL_P(name), Z_STRLEN_P(name)); + nsid = get_uuid(*namespace); + if (nsid == NULL) { + return; + } + + php_uuid_create_v5(&uuid, *nsid, Z_STRVAL_P(name), Z_STRLEN_P(name)); new_uuid(return_value, uuid); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, self, 0) @@ -517,33 +567,36 @@ ZEND_END_ARG_INFO() /* public function __wakeup(): void {{{ */ PHP_METHOD(UUID, __wakeup) { - zval *binary = NULL; + zval *bytes = zend_read_property(php_ce_UUID, &EX(This), UUID_PROP_NAME, UUID_PROP_NAME_LEN, 1, NULL); if (zend_parse_parameters_none_throw() == FAILURE) { return; } - binary = zend_read_property(php_ce_UUID, &EX(This), UUID_PROP_NAME, UUID_PROP_NAME_LEN, 1, NULL); - - if (Z_TYPE_P(binary) != IS_STRING) { + if (Z_TYPE_P(bytes) != IS_STRING) { zend_throw_exception_ex( spl_ce_UnexpectedValueException, 0, - "Expected value of type %s, but found %s", + "Expected %s::$%s value to be of type %s, but found %s", + ZSTR_VAL(php_ce_UUID->name), + UUID_PROP_NAME, zend_get_type_by_const(IS_STRING), - zend_zval_type_name(binary) + zend_zval_type_name(bytes) ); return; } - if (Z_STRLEN_P(binary) != PHP_UUID_LEN) { + if (Z_STRLEN_P(bytes) != PHP_UUID_LEN) { zend_throw_exception_ex( spl_ce_UnexpectedValueException, 0, - "Expected exactly %u bytes, but found %u", + "Expected %s::$%s value to be exactly %u bytes long, but found %u", + ZSTR_VAL(php_ce_UUID->name), + UUID_PROP_NAME, PHP_UUID_LEN, - Z_STRLEN_P(binary) + Z_STRLEN_P(bytes) ); + return; } } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___wakeup_args, IS_VOID, 0) @@ -553,11 +606,18 @@ ZEND_END_ARG_INFO() /* public function getVaraitn(): int {{{ */ PHP_METHOD(UUID, getVariant) { + php_uuid *uuid = NULL; + if (zend_parse_parameters_none_throw() == FAILURE) { return; } - RETURN_LONG(php_uuid_get_variant(*get_bytes(&EX(This)))); + uuid = get_uuid(EX(This)); + if (uuid == NULL) { + return; + } + + RETURN_LONG(php_uuid_get_variant(*uuid)); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -566,11 +626,18 @@ ZEND_END_ARG_INFO() /* public function getVersion(): int {{{ */ PHP_METHOD(UUID, getVersion) { + php_uuid *uuid = NULL; + if (zend_parse_parameters_none_throw() == FAILURE) { return; } - RETURN_LONG(php_uuid_get_version(*get_bytes(&EX(This)))); + uuid = get_uuid(EX(This)); + if (uuid == NULL) { + return; + } + + RETURN_LONG(php_uuid_get_version(*uuid)); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -579,11 +646,18 @@ ZEND_END_ARG_INFO() /* public function isNil(): bool {{{ */ PHP_METHOD(UUID, isNil) { + php_uuid *uuid = NULL; + if (zend_parse_parameters_none_throw() == FAILURE) { return; } - RETURN_BOOL(php_uuid_is_nil(*get_bytes(&EX(This)))); + uuid = get_uuid(EX(This)); + if (uuid == NULL) { + return; + } + + RETURN_BOOL(php_uuid_is_nil(*uuid)); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) ZEND_END_ARG_INFO() @@ -592,18 +666,18 @@ ZEND_END_ARG_INFO() /* public function toBinary(): string {{{ */ PHP_METHOD(UUID, toBinary) { + php_uuid *uuid = NULL; + if (zend_parse_parameters_none_throw() == FAILURE) { return; } - RETURN_ZVAL(zend_read_property( - php_ce_UUID, - &EX(This), - UUID_PROP_NAME, - UUID_PROP_NAME_LEN, - 1, - NULL - ), 1, 0); + uuid = get_uuid(EX(This)); + if (uuid == NULL) { + return; + } + + RETURN_STRINGL(uuid->bytes, PHP_UUID_LEN); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -612,13 +686,20 @@ ZEND_END_ARG_INFO() /* public function toHex(): string {{{ */ PHP_METHOD(UUID, toHex) { + php_uuid *uuid = NULL; php_uuid_hex buffer; if (zend_parse_parameters_none_throw() == FAILURE) { return; } - php_uuid_to_hex(&buffer, *get_bytes(&EX(This))); + uuid = get_uuid(EX(This)); + if (uuid == NULL) { + return; + } + + php_uuid_to_hex(&buffer, *uuid); + RETURN_STRINGL(buffer.str, PHP_UUID_HEX_LEN); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toHex_args, IS_STRING, 0) @@ -628,13 +709,20 @@ ZEND_END_ARG_INFO() /* public function toString(): string {{{ */ PHP_METHOD(UUID, toString) { + php_uuid *uuid = NULL; php_uuid_string buffer; if (zend_parse_parameters_none_throw() == FAILURE) { return; } - php_uuid_to_string(&buffer, *get_bytes(&EX(This))); + uuid = get_uuid(EX(This)); + if (uuid == NULL) { + return; + } + + php_uuid_to_string(&buffer, *uuid); + RETURN_STRINGL(buffer.str, PHP_UUID_STRING_LEN); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toString_args, IS_STRING, 0) From a0158ee2fe7cbdc1880b4fa9880a7fc748b75bcd Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Sun, 28 May 2017 20:39:12 +0200 Subject: [PATCH 39/54] Avoid copy of arguments --- ext/standard/php_uuid.h | 44 +++++++++++++-------------- ext/standard/uuid.c | 66 ++++++++++++++++++++--------------------- 2 files changed, 55 insertions(+), 55 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index 427bbc3f5edc8..f976630926b85 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -362,7 +362,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ * @param[in] name to create the UUID from. * @param[in] name_len */ -PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid namespace, const char *name, const size_t name_len); +PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len); /** * Create version 4 UUID. @@ -466,7 +466,7 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); * @param[in] name to create the UUID from. * @param[in] name_len */ -PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid namespace, const char *name, const size_t name_len); +PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len); /** * Get the variant associated with this UUID. @@ -484,11 +484,11 @@ PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid namespace, const c * @param[in] uuid to get the variant from. * @return The variant of the given UUID. */ -static zend_always_inline const php_uuid_variant php_uuid_get_variant(const php_uuid uuid) +static zend_always_inline const php_uuid_variant php_uuid_get_variant(const php_uuid *uuid) { - if ((uuid.bytes[8] & 0xC0) == 0x80) return PHP_UUID_VARIANT_RFC4122; - if ((uuid.bytes[8] & 0xE0) == 0xC0) return PHP_UUID_VARIANT_MICROSOFT; - if ((uuid.bytes[8] & 0x80) == 0x00) return PHP_UUID_VARIANT_NCS; + if ((uuid->bytes[8] & 0xC0) == 0x80) return PHP_UUID_VARIANT_RFC4122; + if ((uuid->bytes[8] & 0xE0) == 0xC0) return PHP_UUID_VARIANT_MICROSOFT; + if ((uuid->bytes[8] & 0x80) == 0x00) return PHP_UUID_VARIANT_NCS; return PHP_UUID_VARIANT_FUTURE_RESERVED; } @@ -513,9 +513,9 @@ static zend_always_inline const php_uuid_variant php_uuid_get_variant(const php_ * values [1, 5] correspond to one of the `PHP_UUID_VERSION_*` constants. * The others are not defined in RFC 4122. */ -static zend_always_inline const uint8_t php_uuid_get_version(const php_uuid uuid) +static zend_always_inline const uint8_t php_uuid_get_version(const php_uuid *uuid) { - return uuid.bytes[6] >> 4; + return uuid->bytes[6] >> 4; } /** @@ -527,9 +527,9 @@ static zend_always_inline const uint8_t php_uuid_get_version(const php_uuid uuid * @param[in] uuid to check. * @return TRUE if the UUID contains the special nil UUID; FALSE otherwise. */ -static zend_always_inline const int php_uuid_is_nil(const php_uuid uuid) +static zend_always_inline const int php_uuid_is_nil(const php_uuid *uuid) { - return memcmp(uuid.bytes, "", PHP_UUID_LEN) == 0; + return memcmp(uuid->bytes, "", PHP_UUID_LEN) == 0; } /** @@ -550,16 +550,16 @@ static zend_always_inline const int php_uuid_is_nil(const php_uuid uuid) * @param[out] buffer to store the hexadecimal representation in. * @param[in] uuid to convert. */ -static zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_uuid uuid) +static zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_uuid *uuid) { sprintf( buffer->str, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", - uuid.bytes[0], uuid.bytes[1], uuid.bytes[2], uuid.bytes[3], - uuid.bytes[4], uuid.bytes[5], - uuid.bytes[6], uuid.bytes[7], - uuid.bytes[8], uuid.bytes[9], - uuid.bytes[10], uuid.bytes[11], uuid.bytes[12], uuid.bytes[13], uuid.bytes[14], uuid.bytes[15] + uuid->bytes[0], uuid->bytes[1], uuid->bytes[2], uuid->bytes[3], + uuid->bytes[4], uuid->bytes[5], + uuid->bytes[6], uuid->bytes[7], + uuid->bytes[8], uuid->bytes[9], + uuid->bytes[10], uuid->bytes[11], uuid->bytes[12], uuid->bytes[13], uuid->bytes[14], uuid->bytes[15] ); } @@ -582,16 +582,16 @@ static zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_u * @param[out] buffer to store the string representation in. * @param[in] uuid to convert. */ -static zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const php_uuid uuid) +static zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const php_uuid *uuid) { sprintf( buffer->str, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", - uuid.bytes[0], uuid.bytes[1], uuid.bytes[2], uuid.bytes[3], - uuid.bytes[4], uuid.bytes[5], - uuid.bytes[6], uuid.bytes[7], - uuid.bytes[8], uuid.bytes[9], - uuid.bytes[10], uuid.bytes[11], uuid.bytes[12], uuid.bytes[13], uuid.bytes[14], uuid.bytes[15] + uuid->bytes[0], uuid->bytes[1], uuid->bytes[2], uuid->bytes[3], + uuid->bytes[4], uuid->bytes[5], + uuid->bytes[6], uuid->bytes[7], + uuid->bytes[8], uuid->bytes[9], + uuid->bytes[10], uuid->bytes[11], uuid->bytes[12], uuid->bytes[13], uuid->bytes[14], uuid->bytes[15] ); } diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index ab89baf4435ae..eef762f6e19b9 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -256,12 +256,12 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ return SUCCESS; } -PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid namespace, const char *name, const size_t name_len) +PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) { PHP_MD5_CTX context; PHP_MD5Init(&context); - PHP_MD5Update(&context, namespace.bytes, PHP_UUID_LEN); + PHP_MD5Update(&context, namespace->bytes, PHP_UUID_LEN); PHP_MD5Update(&context, name, name_len); PHP_MD5Final(uuid->bytes, &context); set_variant_rfc4122(uuid); @@ -280,13 +280,13 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw) return result; } -PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid namespace, const char *name, const size_t name_len) +PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) { PHP_SHA1_CTX context; char digest[20]; PHP_SHA1Init(&context); - PHP_SHA1Update(&context, namespace.bytes, PHP_UUID_LEN); + PHP_SHA1Update(&context, namespace->bytes, PHP_UUID_LEN); PHP_SHA1Update(&context, name, name_len); PHP_SHA1Final(digest, &context); memcpy(uuid->bytes, digest, PHP_UUID_LEN); @@ -307,9 +307,9 @@ PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid namespace, const c * @throws TypeError if the value is not of type string. * @throws Error if the string value is not exactly 16 bytes long. */ -static zend_always_inline php_uuid *get_uuid(/*const*/ zval uuid_object) +static zend_always_inline php_uuid *get_uuid(/*const*/ zval *uuid_object) { - zval *bytes = zend_read_property(php_ce_UUID, &uuid_object, UUID_PROP_NAME, UUID_PROP_NAME_LEN, 1, NULL); + zval *bytes = zend_read_property(php_ce_UUID, uuid_object, UUID_PROP_NAME, UUID_PROP_NAME_LEN, 1, NULL); if (Z_TYPE_P(bytes) != IS_STRING) { zend_throw_error( @@ -344,10 +344,10 @@ static zend_always_inline php_uuid *get_uuid(/*const*/ zval uuid_object) * @param[out] object to store the UUID instance int. * @param[in] uuid to construct the instance from. */ -static zend_always_inline void new_uuid(zval *object, const php_uuid uuid) +static zend_always_inline void new_uuid(zval *object, const php_uuid *uuid) { object_init_ex(object, php_ce_UUID); - zend_update_property_stringl(php_ce_UUID, object, UUID_PROP_NAME, UUID_PROP_NAME_LEN, uuid.bytes, PHP_UUID_LEN); + zend_update_property_stringl(php_ce_UUID, object, UUID_PROP_NAME, UUID_PROP_NAME_LEN, uuid->bytes, PHP_UUID_LEN); } /* private function __construct() {{{ */ @@ -390,7 +390,7 @@ ZEND_END_ARG_INFO() /* public static function parse(string $input): self {{{ */ PHP_METHOD(UUID, parse) { - zval *input = NULL; + zval *input = NULL; php_uuid uuid; if (zend_parse_parameters_throw(ZEND_NUM_ARGS(), "z", &input) == FAILURE) { @@ -401,7 +401,7 @@ PHP_METHOD(UUID, parse) return; } - new_uuid(return_value, uuid); + new_uuid(return_value, &uuid); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, self, 0) ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) @@ -420,13 +420,13 @@ PHP_METHOD(UUID, v3) return; } - nsid = get_uuid(*namespace); + nsid = get_uuid(namespace); if (nsid == NULL) { return; } - php_uuid_create_v3(&uuid, *nsid, Z_STRVAL_P(name), Z_STRLEN_P(name)); - new_uuid(return_value, uuid); + php_uuid_create_v3(&uuid, nsid, Z_STRVAL_P(name), Z_STRLEN_P(name)); + new_uuid(return_value, &uuid); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, self, 0) ZEND_ARG_OBJ_INFO(0, namespace, self, 0) @@ -447,7 +447,7 @@ PHP_METHOD(UUID, v4) return; } - new_uuid(return_value, uuid); + new_uuid(return_value, &uuid); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_v4_args, self, 0) ZEND_END_ARG_INFO() @@ -465,13 +465,13 @@ PHP_METHOD(UUID, v5) return; } - nsid = get_uuid(*namespace); + nsid = get_uuid(namespace); if (nsid == NULL) { return; } - php_uuid_create_v5(&uuid, *nsid, Z_STRVAL_P(name), Z_STRLEN_P(name)); - new_uuid(return_value, uuid); + php_uuid_create_v5(&uuid, nsid, Z_STRVAL_P(name), Z_STRLEN_P(name)); + new_uuid(return_value, &uuid); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, self, 0) ZEND_ARG_OBJ_INFO(0, namespace, self, 0) @@ -486,7 +486,7 @@ PHP_METHOD(UUID, NamespaceDNS) return; } - new_uuid(return_value, PHP_UUID_NAMESPACE_DNS); + new_uuid(return_value, &PHP_UUID_NAMESPACE_DNS); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, self, 0) ZEND_END_ARG_INFO() @@ -499,7 +499,7 @@ PHP_METHOD(UUID, NamespaceOID) return; } - new_uuid(return_value, PHP_UUID_NAMESPACE_OID); + new_uuid(return_value, &PHP_UUID_NAMESPACE_OID); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, self, 0) ZEND_END_ARG_INFO() @@ -512,7 +512,7 @@ PHP_METHOD(UUID, NamespaceURL) return; } - new_uuid(return_value, PHP_UUID_NAMESPACE_URL); + new_uuid(return_value, &PHP_UUID_NAMESPACE_URL); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, self, 0) ZEND_END_ARG_INFO() @@ -525,7 +525,7 @@ PHP_METHOD(UUID, NamespaceX500) return; } - new_uuid(return_value, PHP_UUID_NAMESPACE_X500); + new_uuid(return_value, &PHP_UUID_NAMESPACE_X500); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, self, 0) ZEND_END_ARG_INFO() @@ -538,7 +538,7 @@ PHP_METHOD(UUID, Nil) return; } - new_uuid(return_value, PHP_UUID_NIL); + new_uuid(return_value, &PHP_UUID_NIL); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, self, 0) ZEND_END_ARG_INFO() @@ -612,12 +612,12 @@ PHP_METHOD(UUID, getVariant) return; } - uuid = get_uuid(EX(This)); + uuid = get_uuid(&EX(This)); if (uuid == NULL) { return; } - RETURN_LONG(php_uuid_get_variant(*uuid)); + RETURN_LONG(php_uuid_get_variant(uuid)); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -632,12 +632,12 @@ PHP_METHOD(UUID, getVersion) return; } - uuid = get_uuid(EX(This)); + uuid = get_uuid(&EX(This)); if (uuid == NULL) { return; } - RETURN_LONG(php_uuid_get_version(*uuid)); + RETURN_LONG(php_uuid_get_version(uuid)); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) ZEND_END_ARG_INFO() @@ -652,12 +652,12 @@ PHP_METHOD(UUID, isNil) return; } - uuid = get_uuid(EX(This)); + uuid = get_uuid(&EX(This)); if (uuid == NULL) { return; } - RETURN_BOOL(php_uuid_is_nil(*uuid)); + RETURN_BOOL(php_uuid_is_nil(uuid)); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) ZEND_END_ARG_INFO() @@ -672,7 +672,7 @@ PHP_METHOD(UUID, toBinary) return; } - uuid = get_uuid(EX(This)); + uuid = get_uuid(&EX(This)); if (uuid == NULL) { return; } @@ -693,12 +693,12 @@ PHP_METHOD(UUID, toHex) return; } - uuid = get_uuid(EX(This)); + uuid = get_uuid(&EX(This)); if (uuid == NULL) { return; } - php_uuid_to_hex(&buffer, *uuid); + php_uuid_to_hex(&buffer, uuid); RETURN_STRINGL(buffer.str, PHP_UUID_HEX_LEN); } @@ -716,12 +716,12 @@ PHP_METHOD(UUID, toString) return; } - uuid = get_uuid(EX(This)); + uuid = get_uuid(&EX(This)); if (uuid == NULL) { return; } - php_uuid_to_string(&buffer, *uuid); + php_uuid_to_string(&buffer, uuid); RETURN_STRINGL(buffer.str, PHP_UUID_STRING_LEN); } From 6b97a187775df14f06244ff53c7710cd6ba05085 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Sun, 28 May 2017 20:46:27 +0200 Subject: [PATCH 40/54] Duplicated everything again Duplicated all type information to ensure compatibility among different PHPDoc implementations. Also reverted `@returns` back to `@return` (this was a typo in an earlier search-replace). --- ext/standard/stubs/UUID.php | 57 +++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/ext/standard/stubs/UUID.php b/ext/standard/stubs/UUID.php index 794da9acbaa60..260c72eda5b7c 100644 --- a/ext/standard/stubs/UUID.php +++ b/ext/standard/stubs/UUID.php @@ -254,8 +254,8 @@ private function __construct() { } * @since 7.2 * @see https://php.net/uuid.fromBinary * @see toBinary - * @param $input string of exactly 16 bytes to construct the instance from. - * @returns UUID constructed from the binary input. + * @param string $input string of exactly 16 bytes to construct the instance from. + * @return \UUID UUID constructed from the binary input. * @throws \ArgumentCountError if less or more than one argument is passed. * @throws \InvalidArgumentException if the input is not 16 bytes long. */ @@ -306,8 +306,8 @@ public static function fromBinary(string $input): self { } * @see https://php.net/uuid.parse * @see toHex * @see toString - * @param $input to parse as UUID and construct the instance from. - * @returns UUID constructed from the parsed input. + * @param string $input to parse as UUID and construct the instance from. + * @return \UUID UUID constructed from the parsed input. * @throws \ArgumentCountError if less or more than one argument is passed. * @throws \UUIDParseException if parsing of the input fails. */ @@ -355,9 +355,9 @@ public static function parse(string $input): self { } * @see https://php.net/uuid.v3 * @see https://tools.ietf.org/html/rfc4122#section-4.3 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 - * @param $namespace to construct the UUID in. - * @param $name to construct the UUID from. - * @returns UUID constructed from the name in the namespace. + * @param \UUID $namespace to construct the UUID in. + * @param string $name to construct the UUID from. + * @return \UUID UUID constructed from the name in the namespace. * @throws \ArgumentCountError if less or more than two arguments are passed. * @throws \Error if the namespace does not encapsulate a valid UUID. */ @@ -391,7 +391,7 @@ public static function v3(self $namespace, string $name): self { } * @see https://php.net/uuid.v4 * @see https://tools.ietf.org/html/rfc4122#section-4.4 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 - * @returns UUID constructed from random data. + * @return \UUID UUID constructed from random data. * @throws \Exception if it was not possible to gather sufficient entropy. * @throws \ArgumentCountError if arguments are passed. */ @@ -434,9 +434,9 @@ public static function v4(): self { } * @see https://php.net/uuid.v5 * @see @see https://tools.ietf.org/html/rfc4122#section-4.3 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 - * @param $namespace to construct the UUID in. - * @param $name to construct the UUID from. - * @returns UUID constructed from the name in the namespace. + * @param \UUID $namespace to construct the UUID in. + * @param string $name to construct the UUID from. + * @return \UUID UUID constructed from the name in the namespace. * @throws \ArgumentCountError if less or more than two arguments are passed. * @throws \Error if the namespace does not encapsulate a valid UUID. */ @@ -449,7 +449,7 @@ public static function v5(self $namespace, string $name): self { } * @see https://php.net/uuid.NamespaceDNS * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/Domain_Name_System - * @returns Predefined DNS namespace UUID. + * @return \UUID Predefined DNS namespace UUID. * @throws \ArgumentCountError if arguments are passed. */ public static function NamespaceDNS(): self { } @@ -461,7 +461,7 @@ public static function NamespaceDNS(): self { } * @see https://php.net/uuid.NamespaceOID * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/Object_identifier - * @returns Predefined OID namespace UUID. + * @return \UUID Predefined OID namespace UUID. * @throws \ArgumentCountError if arguments are passed. */ public static function NamespaceOID(): self { } @@ -473,7 +473,7 @@ public static function NamespaceOID(): self { } * @see https://php.net/uuid.NamespaceURL * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/URL - * @returns Predefined URL namespace UUID. + * @return \UUID Predefined URL namespace UUID. * @throws \ArgumentCountError if arguments are passed. */ public static function NamespaceURL(): self { } @@ -488,7 +488,7 @@ public static function NamespaceURL(): self { } * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/X.500 * @see https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol - * @returns Predefined X.500 namespace UUID instance. + * @return \UUID Predefined X.500 namespace UUID instance. * @throws \ArgumentCountError if arguments are passed. */ public static function NamespaceX500(): self { } @@ -500,7 +500,7 @@ public static function NamespaceX500(): self { } * @see https://php.net/uuid.Nil * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID - * @returns Predefined special nil UUID. + * @return \UUID Predefined special nil UUID. * @throws \ArgumentCountError if arguments are passed. */ public static function Nil(): self { } @@ -516,7 +516,7 @@ public static function Nil(): self { } * @see https://php.net/uuid.__set * @param mixed $_ * @param mixed $__ - * @returns void + * @return void * @throws \Error upon every invocation, direct or indirect. */ public function __set($_, $__): void { } @@ -527,7 +527,7 @@ public function __set($_, $__): void { } * @since 7.2 * @see https://php.net/uuid.__wakeup * @see unserialize() - * @returns void + * @return void * @throws \ArgumentCountError if arguments are passed. * @throws \UnexpectedValueException if the value of the {@see bytes} * property is not of type string, or not exactly 16 bytes long. @@ -549,8 +549,8 @@ public function __wakeup(): void { } * @see UUID::VARIANT_RFC4122 * @see UUID::VARIANT_MICROSOFT * @see UUID::VARIANT_FUTURE_RESERVED - * @returns An integer in [0, 3] where each value corresponds to one of the - * `UUID::VARIANT_*` class constants. + * @return int An integer in [0, 3] where each value corresponds to one of + * the `UUID::VARIANT_*` class constants. * @throws \ArgumentCountError if arguments are passed. * @throws \Error if this instance does not encapsulate a valid UUID. */ @@ -574,9 +574,9 @@ public function getVariant(): int { } * @see UUID::VERSION_3_NAME_BASED_MD5 * @see UUID::VERSION_4_RANDOM * @see UUID::VERSION_5_NAME_BASED_SHA1 - * @returns An integer in [0, 15], the values [1, 5] correspond to one of the - * `UUID::VERSION_*` class constants. The others are not defined in - * RFC 4122. + * @return int An integer in [0, 15], the values [1, 5] correspond to one + * of the `UUID::VERSION_*` class constants. The others are not defined + * in RFC 4122. * @throws \ArgumentCountError if arguments are passed. * @throws \Error if this instance does not encapsulate a valid UUID. */ @@ -591,7 +591,8 @@ public function getVersion(): int { } * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID * @see Nil - * @returns **TRUE** if this is the special nil UUID; **FALSE** otherwise. + * @return bool **TRUE** if this is the special nil UUID; **FALSE** + * otherwise. * @throws \ArgumentCountError if arguments are passed. * @throws \Error if this instance does not encapsulate a valid UUID. */ @@ -617,7 +618,7 @@ public function isNil(): bool { } * * @since 7.2 * @see https://php.net/uuid.toBinary - * @returns Binary representation of the UUID. + * @return string Binary representation of the UUID. * @throws \ArgumentCountError if arguments are passed. * @throws \Error if this instance does not encapsulate a valid UUID. */ @@ -641,7 +642,7 @@ public function toBinary(): string { } * * @since 7.2 * @see https://php.net/uuid.toHex - * @returns Hexadecimal representation of the UUID. + * @return string Hexadecimal representation of the UUID. * @throws \ArgumentCountError if arguments are passed. * @throws \Error if this instance does not encapsulate a valid UUID. */ @@ -668,7 +669,7 @@ public function toHex(): string { } * @see https://php.net/uuid.toString * @see https://tools.ietf.org/html/rfc4122#page-4 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Format - * @returns String representation of the UUID. + * @return string String representation of the UUID. * @throws \ArgumentCountError if arguments are passed. * @throws \Error if this instance does not encapsulate a valid UUID. */ @@ -679,7 +680,7 @@ public function toString(): string { } * disables cloning of this object, since it makes no sense to clone * immutable objects. * - * @returns void + * @return void * @throws \Error upon every invocation. */ private function __clone() { } From 7e94490212c60726611467a0da8c44394db24f5a Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Sun, 28 May 2017 21:12:36 +0200 Subject: [PATCH 41/54] Changed const values to be static External linking does not seem to make much sense for constant values. --- ext/standard/php_uuid.h | 32 ++++++++++------- ext/standard/uuid.c | 78 ++++++++++++++++++----------------------- 2 files changed, 53 insertions(+), 57 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index f976630926b85..88d80b58d53d8 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -124,14 +124,20 @@ PHPAPI typedef struct php_uuid { uint8_t bytes[PHP_UUID_LEN]; } php_uuid; +/** UUID hexadecimal representation length with terminating NUL. */ +#define PHP_UUID_HEX_LEN 33 + /** UUID hexadecimal representation: `000000001111222233334444444444444444\0` */ PHPAPI typedef struct php_uuid_hex { - char str[33]; + char str[PHP_UUID_HEX_LEN]; } php_uuid_hex; +/** UUID string representation length with terminating NUL. */ +#define PHP_UUID_STRING_LEN 37 + /** UUID string representation: `00000000-1111-2222-3333-4444444444444444\0` */ PHPAPI typedef struct php_uuid_string { - char str[37]; + char str[PHP_UUID_STRING_LEN]; } php_uuid_string; /** @@ -140,7 +146,7 @@ PHPAPI typedef struct php_uuid_string { * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/Domain_Name_System */ -PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_DNS; +static const php_uuid PHP_UUID_NAMESPACE_DNS = { "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; /** * Object Identifier (OID) namespace UUID. @@ -148,7 +154,7 @@ PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_DNS; * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/Object_identifier */ -PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_OID; +static const php_uuid PHP_UUID_NAMESPACE_OID = { "\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; /** * Uniform Resource Locator (URL) namespace UUID. @@ -156,7 +162,7 @@ PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_OID; * @see https://tools.ietf.org/html/rfc4122#appendix-C * @see https://en.wikipedia.org/wiki/URL */ -PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_URL; +static const php_uuid PHP_UUID_NAMESPACE_URL = { "\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; /** * X.500 Distinguished Names (X.500 DN) namespace UUID. The names that are to @@ -166,7 +172,7 @@ PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_URL; * @see https://en.wikipedia.org/wiki/X.500 * @see https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol */ -PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_X500; +static const php_uuid PHP_UUID_NAMESPACE_X500 = { "\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; /** * Special nil UUID that has all 128 bits set to zero. @@ -174,7 +180,7 @@ PHPAPI extern const php_uuid PHP_UUID_NAMESPACE_X500; * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID */ -PHPAPI extern const php_uuid PHP_UUID_NIL; +static const php_uuid PHP_UUID_NIL = { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }; /** * UUID variants as defined in RFC 4122. @@ -198,7 +204,7 @@ PHPAPI typedef enum php_uuid_variant { * @see https://tools.ietf.org/html/rfc4122#section-4.2 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_.28date-time_and_MAC_address.29 */ -PHPAPI extern const uint8_t PHP_UUID_VERSION_1_TIME_BASED; +static const uint8_t PHP_UUID_VERSION_1_TIME_BASED = 1; /** * Version code for date-time and IEEE 802 MAC address UUIDs (DCE security @@ -213,7 +219,7 @@ PHPAPI extern const uint8_t PHP_UUID_VERSION_1_TIME_BASED; * @see https://tools.ietf.org/html/rfc4122#section-4.2 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_2_.28date-time_and_MAC_Address.2C_DCE_security_version.29 */ -PHPAPI extern const uint8_t PHP_UUID_VERSION_2_DCE_SECURITY; +static const uint8_t PHP_UUID_VERSION_2_DCE_SECURITY = 2; /** * Version code for namespace/name-based MD5 hashed UUIDs. @@ -222,7 +228,7 @@ PHPAPI extern const uint8_t PHP_UUID_VERSION_2_DCE_SECURITY; * @see https://tools.ietf.org/html/rfc4122#section-4.3 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 */ -PHPAPI extern const uint8_t PHP_UUID_VERSION_3_NAME_BASED_MD5; +static const uint8_t PHP_UUID_VERSION_3_NAME_BASED_MD5 = 3; /** * Version code for random UUIDs. @@ -231,7 +237,7 @@ PHPAPI extern const uint8_t PHP_UUID_VERSION_3_NAME_BASED_MD5; * @see https://tools.ietf.org/html/rfc4122#section-4.4 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 */ -PHPAPI extern const uint8_t PHP_UUID_VERSION_4_RANDOM; +static const uint8_t PHP_UUID_VERSION_4_RANDOM = 4; /** * Version code for namespace/name-based SHA1 hashed UUIDs. @@ -240,7 +246,7 @@ PHPAPI extern const uint8_t PHP_UUID_VERSION_4_RANDOM; * @see https://tools.ietf.org/html/rfc4122#section-4.3 * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 */ -PHPAPI extern const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1; +static const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1 = 5; /** * Parse the given string as UUID. @@ -529,7 +535,7 @@ static zend_always_inline const uint8_t php_uuid_get_version(const php_uuid *uui */ static zend_always_inline const int php_uuid_is_nil(const php_uuid *uuid) { - return memcmp(uuid->bytes, "", PHP_UUID_LEN) == 0; + return memcmp(uuid->bytes, &PHP_UUID_NIL, PHP_UUID_LEN) == 0; } /** diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index eef762f6e19b9..4db031a2d57c8 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -29,33 +29,23 @@ PHPAPI zend_class_entry *php_ce_UUID; PHPAPI zend_class_entry *php_ce_UUIDParseException; -PHPAPI const php_uuid PHP_UUID_NAMESPACE_DNS = { "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; -PHPAPI const php_uuid PHP_UUID_NAMESPACE_OID = { "\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; -PHPAPI const php_uuid PHP_UUID_NAMESPACE_URL = { "\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; -PHPAPI const php_uuid PHP_UUID_NAMESPACE_X500 = { "\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; -PHPAPI const php_uuid PHP_UUID_NIL = { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }; - -static const uint8_t PHP_UUID_VERSION_MIN = 0; -PHPAPI const uint8_t PHP_UUID_VERSION_1_TIME_BASED = 1; -PHPAPI const uint8_t PHP_UUID_VERSION_2_DCE_SECURITY = 2; -PHPAPI const uint8_t PHP_UUID_VERSION_3_NAME_BASED_MD5 = 3; -PHPAPI const uint8_t PHP_UUID_VERSION_4_RANDOM = 4; -PHPAPI const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1 = 5; -static const uint8_t PHP_UUID_VERSION_MAX = 15; - -PHPAPI const uint8_t PHP_UUID_HEX_LEN = sizeof(php_uuid_hex) - 1; -PHPAPI const uint8_t PHP_UUID_STRING_LEN = sizeof(php_uuid_string) - 1; - -static const char UUID_PROP_NAME[] = "bytes"; -static const uint8_t UUID_PROP_NAME_LEN = sizeof(UUID_PROP_NAME) - 1; - -static const char UUID_EX_INPUT_PROP[] = "input"; -static const uint8_t UUID_EX_INPUT_PROP_LEN = sizeof(UUID_EX_INPUT_PROP) - 1; -static const char UUID_EX_POSITION_PROP[] = "position"; -static const uint8_t UUID_EX_POSITON_PROP_LEN = sizeof(UUID_EX_POSITION_PROP) - 1; - -static const char URN_PREFIX[] = "urn:uuid:"; -static const uint8_t URN_PREFIX_LEN = sizeof(URN_PREFIX) - 1; +static const uint8_t UUID_VERSION_MIN = 0; +static const uint8_t UUID_VERSION_MAX = 15; + +static const uint8_t UUID_HEX_LEN = sizeof(php_uuid_hex) - 1; +static const uint8_t UUID_STRING_LEN = sizeof(php_uuid_string) - 1; + +static const char UUID_BYTES_PROP[] = "bytes"; +static const uint8_t UUID_BYTES_PROP_LEN = sizeof(UUID_BYTES_PROP) - 1; + +static const char UUID_EX_INPUT_PROP[] = "input"; +static const uint8_t UUID_EX_INPUT_PROP_LEN = sizeof(UUID_EX_INPUT_PROP) - 1; + +static const char UUID_EX_POSITION_PROP[] = "position"; +static const uint8_t UUID_EX_POSITON_PROP_LEN = sizeof(UUID_EX_POSITION_PROP) - 1; + +static const char URN_PREFIX[] = "urn:uuid:"; +static const uint8_t URN_PREFIX_LEN = sizeof(URN_PREFIX) - 1; /** * Set UUID variant to RFC 4122, the only supported variant. @@ -80,7 +70,7 @@ static zend_always_inline void set_variant_rfc4122(php_uuid *uuid) */ static zend_always_inline void php_uuid_set_version(php_uuid *uuid, const uint8_t version) { - assert(PHP_UUID_VERSION_MIN <= version && version <= PHP_UUID_VERSION_MAX); + assert(UUID_VERSION_MIN <= version && version <= UUID_VERSION_MAX); uuid->bytes[6] = (uuid->bytes[6] & 0x0F) | (version << 4); } @@ -129,7 +119,7 @@ static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_len(co input_len, position, "Expected at least %u hexadecimal digits, but got %u", - PHP_UUID_HEX_LEN, + UUID_HEX_LEN, actual ); } @@ -172,7 +162,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ --limit; } - if ((limit - position + 1) < PHP_UUID_HEX_LEN) { + if ((limit - position + 1) < UUID_HEX_LEN) { if (throw) { throw_uuid_parse_exception_invalid_len(input, input_len, position, limit - position + 1); } @@ -227,14 +217,14 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ return FAILURE; } - if (digit > PHP_UUID_HEX_LEN) { + if (digit > UUID_HEX_LEN) { if (throw) { throw_uuid_parse_exception( input, input_len, position, "Expected no more than %u hexadecimal digits", - PHP_UUID_HEX_LEN + UUID_HEX_LEN ); } return FAILURE; @@ -246,7 +236,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ ++digit; } - if (digit < PHP_UUID_HEX_LEN) { + if (digit < UUID_HEX_LEN) { if (throw) { throw_uuid_parse_exception_invalid_len(input, input_len, position, digit); } @@ -309,14 +299,14 @@ PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const */ static zend_always_inline php_uuid *get_uuid(/*const*/ zval *uuid_object) { - zval *bytes = zend_read_property(php_ce_UUID, uuid_object, UUID_PROP_NAME, UUID_PROP_NAME_LEN, 1, NULL); + zval *bytes = zend_read_property(php_ce_UUID, uuid_object, UUID_BYTES_PROP, UUID_BYTES_PROP_LEN, 1, NULL); if (Z_TYPE_P(bytes) != IS_STRING) { zend_throw_error( zend_ce_type_error, "Expected %s::$%s value to be of type %s, but found %s", ZSTR_VAL(php_ce_UUID->name), - UUID_PROP_NAME, + UUID_BYTES_PROP, zend_get_type_by_const(IS_STRING), zend_zval_type_name(bytes) ); @@ -328,7 +318,7 @@ static zend_always_inline php_uuid *get_uuid(/*const*/ zval *uuid_object) zend_ce_error, "Expected %s::$%s value to be exactly %u bytes long, but found %u", ZSTR_VAL(php_ce_UUID->name), - UUID_PROP_NAME, + UUID_BYTES_PROP, PHP_UUID_LEN, Z_STRLEN_P(bytes) ); @@ -347,7 +337,7 @@ static zend_always_inline php_uuid *get_uuid(/*const*/ zval *uuid_object) static zend_always_inline void new_uuid(zval *object, const php_uuid *uuid) { object_init_ex(object, php_ce_UUID); - zend_update_property_stringl(php_ce_UUID, object, UUID_PROP_NAME, UUID_PROP_NAME_LEN, uuid->bytes, PHP_UUID_LEN); + zend_update_property_stringl(php_ce_UUID, object, UUID_BYTES_PROP, UUID_BYTES_PROP_LEN, uuid->bytes, PHP_UUID_LEN); } /* private function __construct() {{{ */ @@ -380,7 +370,7 @@ PHP_METHOD(UUID, fromBinary) } object_init_ex(return_value, php_ce_UUID); - zend_update_property(php_ce_UUID, return_value, UUID_PROP_NAME, UUID_PROP_NAME_LEN, input); + zend_update_property(php_ce_UUID, return_value, UUID_BYTES_PROP, UUID_BYTES_PROP_LEN, input); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_fromBinary_args, 0, 1, self, 0) ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) @@ -567,7 +557,7 @@ ZEND_END_ARG_INFO() /* public function __wakeup(): void {{{ */ PHP_METHOD(UUID, __wakeup) { - zval *bytes = zend_read_property(php_ce_UUID, &EX(This), UUID_PROP_NAME, UUID_PROP_NAME_LEN, 1, NULL); + zval *bytes = zend_read_property(php_ce_UUID, &EX(This), UUID_BYTES_PROP, UUID_BYTES_PROP_LEN, 1, NULL); if (zend_parse_parameters_none_throw() == FAILURE) { return; @@ -579,7 +569,7 @@ PHP_METHOD(UUID, __wakeup) 0, "Expected %s::$%s value to be of type %s, but found %s", ZSTR_VAL(php_ce_UUID->name), - UUID_PROP_NAME, + UUID_BYTES_PROP, zend_get_type_by_const(IS_STRING), zend_zval_type_name(bytes) ); @@ -592,7 +582,7 @@ PHP_METHOD(UUID, __wakeup) 0, "Expected %s::$%s value to be exactly %u bytes long, but found %u", ZSTR_VAL(php_ce_UUID->name), - UUID_PROP_NAME, + UUID_BYTES_PROP, PHP_UUID_LEN, Z_STRLEN_P(bytes) ); @@ -700,7 +690,7 @@ PHP_METHOD(UUID, toHex) php_uuid_to_hex(&buffer, uuid); - RETURN_STRINGL(buffer.str, PHP_UUID_HEX_LEN); + RETURN_STRINGL(buffer.str, UUID_HEX_LEN); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toHex_args, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -723,7 +713,7 @@ PHP_METHOD(UUID, toString) php_uuid_to_string(&buffer, uuid); - RETURN_STRINGL(buffer.str, PHP_UUID_STRING_LEN); + RETURN_STRINGL(buffer.str, UUID_STRING_LEN); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toString_args, IS_STRING, 0) ZEND_END_ARG_INFO() @@ -853,7 +843,7 @@ PHP_MINIT_FUNCTION(uuid) zend_declare_class_constant_long(php_ce_UUID, "VERSION_4_RANDOM", sizeof("VERSION_4_RANDOM") - 1, PHP_UUID_VERSION_4_RANDOM); zend_declare_class_constant_long(php_ce_UUID, "VERSION_5_NAME_BASED_SHA1", sizeof("VERSION_5_NAME_BASED_SHA1") - 1, PHP_UUID_VERSION_5_NAME_BASED_SHA1); - zend_declare_property_null(php_ce_UUID, UUID_PROP_NAME, UUID_PROP_NAME_LEN, ZEND_ACC_PRIVATE); + zend_declare_property_null(php_ce_UUID, UUID_BYTES_PROP, UUID_BYTES_PROP_LEN, ZEND_ACC_PRIVATE); INIT_CLASS_ENTRY(ce, "UUIDParseException", uuid_parse_exception_methods); php_ce_UUIDParseException = zend_register_internal_class_ex(&ce, zend_ce_exception); From 2fe21333ce753d50979836af42421c60c814b95d Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Mon, 29 May 2017 08:49:58 +0200 Subject: [PATCH 42/54] Made namespaces & nil into functions There is not need to allocate the namespace and nil for the complete duration of the program, they are used occassionaly only. Also created macros for the named constructors and getting of the current UUID. This makes the code less readable, but much easier to change. --- ext/standard/php_uuid.h | 139 +++++++++++++++++++--------------- ext/standard/uuid.c | 162 ++++++++-------------------------------- 2 files changed, 111 insertions(+), 190 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index 88d80b58d53d8..bcc3f95c92bf7 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -69,7 +69,7 @@ * php_random_bytes_silent(&uuid, PHP_UUID_LEN); * php_uuid_set_variant(&uuid, PHP_UUID_VARIANT_FUTURE_RESERVED); * - * php_uuid_create_v3(&uuid, &PHP_UUID_NAMESPACE_DNS, "php.net", sizeof("php.net") - 1); + * php_uuid_create_v3(&uuid, php_uuid_namespace_dns(), "php.net", sizeof("php.net") - 1); * assert(php_uuid_is_nil(uuid) == FALSE); * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_3_NAME_BASED_MD5); @@ -79,7 +79,7 @@ * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_4_RANDOM); * - * php_uuid_create_v5(&uuid, &PHP_UUID_NAMESPACE_DNS, "php.net", sizeof("php.net") - 1); + * php_uuid_create_v5(&uuid, php_uuid_namespace_dns(), "php.net", sizeof("php.net") - 1); * assert(php_uuid_is_nil(uuid) == FALSE); * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_5_NAME_BASED_SHA1); @@ -140,48 +140,6 @@ PHPAPI typedef struct php_uuid_string { char str[PHP_UUID_STRING_LEN]; } php_uuid_string; -/** - * Domain Name System (DNS) namespace UUID. - * - * @see https://tools.ietf.org/html/rfc4122#appendix-C - * @see https://en.wikipedia.org/wiki/Domain_Name_System - */ -static const php_uuid PHP_UUID_NAMESPACE_DNS = { "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; - -/** -* Object Identifier (OID) namespace UUID. -* - * @see https://tools.ietf.org/html/rfc4122#appendix-C - * @see https://en.wikipedia.org/wiki/Object_identifier - */ -static const php_uuid PHP_UUID_NAMESPACE_OID = { "\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; - -/** - * Uniform Resource Locator (URL) namespace UUID. - * - * @see https://tools.ietf.org/html/rfc4122#appendix-C - * @see https://en.wikipedia.org/wiki/URL - */ -static const php_uuid PHP_UUID_NAMESPACE_URL = { "\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; - -/** - * X.500 Distinguished Names (X.500 DN) namespace UUID. The names that are to - * be hashed in this namespace can be in DER or a text output format. - * - * @see https://tools.ietf.org/html/rfc4122#appendix-C - * @see https://en.wikipedia.org/wiki/X.500 - * @see https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol - */ -static const php_uuid PHP_UUID_NAMESPACE_X500 = { "\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; - -/** - * Special nil UUID that has all 128 bits set to zero. - * - * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID - */ -static const php_uuid PHP_UUID_NIL = { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }; - /** * UUID variants as defined in RFC 4122. * @@ -248,6 +206,63 @@ static const uint8_t PHP_UUID_VERSION_4_RANDOM = 4; */ static const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1 = 5; +/** + * Domain Name System (DNS) namespace UUID. + * + * @see https://tools.ietf.org/html/rfc4122#appendix-C + * @see https://en.wikipedia.org/wiki/Domain_Name_System + */ +static const zend_always_inline php_uuid php_uuid_namespace_dns() +{ + return (php_uuid) { "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; +} + +/** +* Object Identifier (OID) namespace UUID. +* + * @see https://tools.ietf.org/html/rfc4122#appendix-C + * @see https://en.wikipedia.org/wiki/Object_identifier + */ +static const zend_always_inline php_uuid php_uuid_namespace_oid() +{ + return (php_uuid) { "\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; +} + +/** + * Uniform Resource Locator (URL) namespace UUID. + * + * @see https://tools.ietf.org/html/rfc4122#appendix-C + * @see https://en.wikipedia.org/wiki/URL + */ +static const zend_always_inline php_uuid php_uuid_namespace_url() +{ + return (php_uuid) { "\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; +} + +/** + * X.500 Distinguished Names (X.500 DN) namespace UUID. The names that are to + * be hashed in this namespace can be in DER or a text output format. + * + * @see https://tools.ietf.org/html/rfc4122#appendix-C + * @see https://en.wikipedia.org/wiki/X.500 + * @see https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol + */ +static const zend_always_inline php_uuid php_uuid_namespace_x500() +{ + return (php_uuid) { "\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; +} + +/** + * Special nil UUID that has all 128 bits set to zero. + * + * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 + * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID + */ +static const zend_always_inline php_uuid php_uuid_nil() +{ + return (php_uuid) { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }; +} + /** * Parse the given string as UUID. * @@ -333,10 +348,10 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ * byte representation and the given name. The namespace itself must be * another UUID. This can be any UUID, or one of the predefined ones: * - * - {@see PHP_UUID_NAMESPACE_DNS} - * - {@see PHP_UUID_NAMESPACE_OID} - * - {@see PHP_UUID_NAMESPACE_URL} - * - {@see PHP_UUID_NAMESPACE_X500} + * - {@see php_uuid_namespace_dns} + * - {@see php_uuid_namespace_oid} + * - {@see php_uuid_namespace_url} + * - {@see php_uuid_namespace_x500} * * A particular name within the same namespace always results in the same * version 3 UUID, across all RFC 4122 compliant UUID implementations. @@ -344,9 +359,10 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ * * ## Examples * ``` + * const php_uuid nsid = php_uuid_namespace_dns(); * php_uuid uuid; * - * php_uuid_create_v3(&uuid, PHP_UUID_NAMESPACE_DNS, "php.net", sizeof("php.net") - 1); + * php_uuid_create_v3(&uuid, &nsid, "php.net", sizeof("php.net") - 1); * * assert(php_uuid_is_nil(uuid) == FALSE); * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); @@ -357,7 +373,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ * assert(memcmp(&str, "11a38b9a-b3da-360f-9353-a5a725514269", PHP_UUID_STRING_LEN) == 0); * * php_uuid tmp; - * php_uuid_create_v3(&tmp, PHP_UUID_NAMESPACE_DNS, "php.net", sizeof("php.net") - 1); + * php_uuid_create_v3(&tmp, &nsid, "php.net", sizeof("php.net") - 1); * assert(memcmp(&tmp, &uuid, PHP_UUID_LEN) == 0); * ``` * @@ -437,10 +453,10 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); * byte representation and the given name. The namespace itself must be * another UUID. This can be any UUID, or one of the predefined ones: * - * - {@see PHP_UUID_NAMESPACE_DNS} - * - {@see PHP_UUID_NAMESPACE_OID} - * - {@see PHP_UUID_NAMESPACE_URL} - * - {@see PHP_UUID_NAMESPACE_X500} + * - {@see php_uuid_namespace_dns} + * - {@see php_uuid_namespace_oid} + * - {@see php_uuid_namespace_url} + * - {@see php_uuid_namespace_x500} * * A particular name within the same namespace always results in the same * version 5 UUID, across all RFC 4122 compliant UUID implementations. @@ -448,9 +464,10 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); * * ## Examples * ``` + * const php_uuid nsid = php_uuid_namespace_dns(); * php_uuid uuid; * - * php_uuid_create_v5(&uuid, PHP_UUID_NAMESPACE_DNS, "php.net", sizeof("php.net") - 1); + * php_uuid_create_v5(&uuid, &nsid, "php.net", sizeof("php.net") - 1); * * assert(php_uuid_is_nil(uuid) == FALSE); * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); @@ -461,7 +478,7 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); * assert(memcmp(&str, "c4a760a8-dbcf-5254-a0d9-6a4474bd1b62", PHP_UUID_STRING_LEN) == 0); * * php_uuid tmp; - * php_uuid_create_v5(&tmp, PHP_UUID_NAMESPACE_DNS, "php.net", sizeof("php.net") - 1); + * php_uuid_create_v5(&tmp, &nsid, "php.net", sizeof("php.net") - 1); * assert(memcmp(&tmp, &uuid, PHP_UUID_LEN) == 0); * ``` * @@ -535,7 +552,9 @@ static zend_always_inline const uint8_t php_uuid_get_version(const php_uuid *uui */ static zend_always_inline const int php_uuid_is_nil(const php_uuid *uuid) { - return memcmp(uuid->bytes, &PHP_UUID_NIL, PHP_UUID_LEN) == 0; + const php_uuid nil = php_uuid_nil(); + + return memcmp(uuid->bytes, &nil, PHP_UUID_LEN) == 0; } /** @@ -547,9 +566,10 @@ static zend_always_inline const int php_uuid_is_nil(const php_uuid *uuid) * * ## Examples * ``` + * const php_uuid nsid = php_uuid_namespace_dns(); * php_uuid_hex hex; * - * php_uuid_to_hex(&hex, PHP_UUID_NAMESPACE_DNS); + * php_uuid_to_hex(&hex, &nsid); * assert(memcmp(&hex, "6ba7b8109dad11d180b400c04fd430c8", PHP_UUID_HEX_LEN) == 0); * ``` * @@ -579,9 +599,10 @@ static zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_u * * ## Examples * ``` + * const php_uuid nsid = php_uuid_namespace_dns(); * php_uuid_string str; * - * php_uuid_to_hex(&str, PHP_UUID_NAMESPACE_DNS); + * php_uuid_to_hex(&str, &nsid); * assert(memcmp(&str, "6ba7b810-9dad-11d1-80b4-00c04fd430c8", PHP_UUID_STRING_LEN) == 0); * ``` * diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 4db031a2d57c8..e6245cb303968 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -469,69 +469,26 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, self, 0) ZEND_END_ARG_INFO() /* }}} */ -/* public static function NamespaceDNS(): self {{{ */ -PHP_METHOD(UUID, NamespaceDNS) -{ - if (zend_parse_parameters_none_throw() == FAILURE) { - return; - } - - new_uuid(return_value, &PHP_UUID_NAMESPACE_DNS); -} -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceDNS_args, self, 0) -ZEND_END_ARG_INFO() -/* }}} */ - -/* public static function NamespaceOID(): self {{{ */ -PHP_METHOD(UUID, NamespaceOID) -{ - if (zend_parse_parameters_none_throw() == FAILURE) { - return; - } - - new_uuid(return_value, &PHP_UUID_NAMESPACE_OID); -} -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceOID_args, self, 0) -ZEND_END_ARG_INFO() -/* }}} */ - -/* public static function NamespaceURL(): self {{{ */ -PHP_METHOD(UUID, NamespaceURL) -{ - if (zend_parse_parameters_none_throw() == FAILURE) { - return; - } - - new_uuid(return_value, &PHP_UUID_NAMESPACE_URL); -} -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceURL_args, self, 0) -ZEND_END_ARG_INFO() -/* }}} */ - -/* public static function NamespaceX500(): self {{{ */ -PHP_METHOD(UUID, NamespaceX500) -{ - if (zend_parse_parameters_none_throw() == FAILURE) { - return; - } - - new_uuid(return_value, &PHP_UUID_NAMESPACE_X500); -} -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_NamespaceX500_args, self, 0) -ZEND_END_ARG_INFO() -/* }}} */ - -/* public static function Nil(): self {{{ */ -PHP_METHOD(UUID, Nil) -{ - if (zend_parse_parameters_none_throw() == FAILURE) { - return; - } - - new_uuid(return_value, &PHP_UUID_NIL); -} -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_Nil_args, self, 0) -ZEND_END_ARG_INFO() +/* public static function ##method_name##(): self {{{ */ +#define PHP_UUID_NAMED_CONSTRUCTOR(method_name, name) \ + PHP_METHOD(UUID, method_name) \ + { \ + const php_uuid name = php_uuid_##name##(); \ + \ + if (zend_parse_parameters_none_throw() == FAILURE) { \ + return; \ + } \ + \ + new_uuid(return_value, &##name##); \ + } \ + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_##method_name##_args, self, 0) \ + ZEND_END_ARG_INFO() + +PHP_UUID_NAMED_CONSTRUCTOR(NamespaceDNS, namespace_dns) +PHP_UUID_NAMED_CONSTRUCTOR(NamespaceOID, namespace_oid) +PHP_UUID_NAMED_CONSTRUCTOR(NamespaceURL, namespace_url) +PHP_UUID_NAMED_CONSTRUCTOR(NamespaceX500, namespace_x500) +PHP_UUID_NAMED_CONSTRUCTOR(Nil, nil) /* }}} */ /* private function __clone() {{{ */ @@ -593,20 +550,15 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___wakeup_args, IS_VOID, 0) ZEND_END_ARG_INFO() /* }}} */ +#define PHP_UUID_GET_THIS_UUID() \ + php_uuid *uuid = NULL; \ + if (zend_parse_parameters_none_throw() == FAILURE) return; \ + if ((uuid = get_uuid(&EX(This))) == NULL) return; + /* public function getVaraitn(): int {{{ */ PHP_METHOD(UUID, getVariant) { - php_uuid *uuid = NULL; - - if (zend_parse_parameters_none_throw() == FAILURE) { - return; - } - - uuid = get_uuid(&EX(This)); - if (uuid == NULL) { - return; - } - + PHP_UUID_GET_THIS_UUID(); RETURN_LONG(php_uuid_get_variant(uuid)); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) @@ -616,17 +568,7 @@ ZEND_END_ARG_INFO() /* public function getVersion(): int {{{ */ PHP_METHOD(UUID, getVersion) { - php_uuid *uuid = NULL; - - if (zend_parse_parameters_none_throw() == FAILURE) { - return; - } - - uuid = get_uuid(&EX(This)); - if (uuid == NULL) { - return; - } - + PHP_UUID_GET_THIS_UUID(); RETURN_LONG(php_uuid_get_version(uuid)); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) @@ -636,17 +578,7 @@ ZEND_END_ARG_INFO() /* public function isNil(): bool {{{ */ PHP_METHOD(UUID, isNil) { - php_uuid *uuid = NULL; - - if (zend_parse_parameters_none_throw() == FAILURE) { - return; - } - - uuid = get_uuid(&EX(This)); - if (uuid == NULL) { - return; - } - + PHP_UUID_GET_THIS_UUID(); RETURN_BOOL(php_uuid_is_nil(uuid)); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) @@ -656,17 +588,7 @@ ZEND_END_ARG_INFO() /* public function toBinary(): string {{{ */ PHP_METHOD(UUID, toBinary) { - php_uuid *uuid = NULL; - - if (zend_parse_parameters_none_throw() == FAILURE) { - return; - } - - uuid = get_uuid(&EX(This)); - if (uuid == NULL) { - return; - } - + PHP_UUID_GET_THIS_UUID(); RETURN_STRINGL(uuid->bytes, PHP_UUID_LEN); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) @@ -676,20 +598,9 @@ ZEND_END_ARG_INFO() /* public function toHex(): string {{{ */ PHP_METHOD(UUID, toHex) { - php_uuid *uuid = NULL; php_uuid_hex buffer; - - if (zend_parse_parameters_none_throw() == FAILURE) { - return; - } - - uuid = get_uuid(&EX(This)); - if (uuid == NULL) { - return; - } - + PHP_UUID_GET_THIS_UUID(); php_uuid_to_hex(&buffer, uuid); - RETURN_STRINGL(buffer.str, UUID_HEX_LEN); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toHex_args, IS_STRING, 0) @@ -699,20 +610,9 @@ ZEND_END_ARG_INFO() /* public function toString(): string {{{ */ PHP_METHOD(UUID, toString) { - php_uuid *uuid = NULL; php_uuid_string buffer; - - if (zend_parse_parameters_none_throw() == FAILURE) { - return; - } - - uuid = get_uuid(&EX(This)); - if (uuid == NULL) { - return; - } - + PHP_UUID_GET_THIS_UUID(); php_uuid_to_string(&buffer, uuid); - RETURN_STRINGL(buffer.str, UUID_STRING_LEN); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toString_args, IS_STRING, 0) From 441dfb0d943087203fc4f627ee6d3caf5de839d9 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Mon, 29 May 2017 19:13:27 +0200 Subject: [PATCH 43/54] Added C++ compatibility Also removed the macros again and exchanged them with proper functions. They are simply better in every way, and should be properly inlined by the compiler as well anyways. --- ext/standard/php_uuid.h | 30 +++++++++++++++++++++++------- ext/standard/uuid.c | 14 +++++++------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index bcc3f95c92bf7..290eef915d580 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -206,6 +206,8 @@ static const uint8_t PHP_UUID_VERSION_4_RANDOM = 4; */ static const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1 = 5; +BEGIN_EXTERN_C() + /** * Domain Name System (DNS) namespace UUID. * @@ -322,7 +324,10 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ * @param[in] input_len * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. */ -#define php_uuid_parse_silent(uuid, input, input_len) php_uuid_parse(uuid, input, input_len, 0) +static zend_always_inline int php_uuid_parse_silent(php_uuid *uuid, const char *input, const size_t input_len) +{ + return php_uuid_parse(uuid, input, input_len, 0); +} /** * Parse the string as UUID and throw PHP exceptions on failures. @@ -334,7 +339,10 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. * @throws UUIDParseException if throw is enabled and parsing fails. */ -#define php_uuid_parse_throw(uuid, input, input_len) php_uuid_parse(uuid, input, input_len, 1) +static zend_always_inline int php_uuid_parse_throw(php_uuid *uuid, const char *input, const size_t input_len) +{ + return php_uuid_parse(uuid, input, input_len, 1); +} /** * Create version 3 UUID. @@ -431,7 +439,10 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); * @return `SUCCESS` if the generation succeeded, `FAILURE` if it was not * possible to gather sufficient entropy. */ -#define php_uuid_create_v4_silent(uuid) php_uuid_create_v4(uuid, 0) +static zend_always_inline int php_uuid_create_v4_silent(php_uuid *uuid) +{ + return php_uuid_create_v4(uuid, 0); +} /** * Create version 4 UUID and throw PHP exception if it is not possible to @@ -444,7 +455,10 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); * @throws Exception if throw is enabled and it was not possible to gather * sufficient entropy for generating random bytes. */ -#define php_uuid_create_v4_throw(uuid) php_uuid_create_v4(uuid, 1) +static zend_always_inline int php_uuid_create_v4_throw(php_uuid *uuid) +{ + return php_uuid_create_v4(uuid, 1); +} /** * Create version 5 UUID. @@ -507,7 +521,7 @@ PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const * @param[in] uuid to get the variant from. * @return The variant of the given UUID. */ -static zend_always_inline const php_uuid_variant php_uuid_get_variant(const php_uuid *uuid) +static const zend_always_inline php_uuid_variant php_uuid_get_variant(const php_uuid *uuid) { if ((uuid->bytes[8] & 0xC0) == 0x80) return PHP_UUID_VARIANT_RFC4122; if ((uuid->bytes[8] & 0xE0) == 0xC0) return PHP_UUID_VARIANT_MICROSOFT; @@ -536,7 +550,7 @@ static zend_always_inline const php_uuid_variant php_uuid_get_variant(const php_ * values [1, 5] correspond to one of the `PHP_UUID_VERSION_*` constants. * The others are not defined in RFC 4122. */ -static zend_always_inline const uint8_t php_uuid_get_version(const php_uuid *uuid) +static const zend_always_inline uint8_t php_uuid_get_version(const php_uuid *uuid) { return uuid->bytes[6] >> 4; } @@ -550,7 +564,7 @@ static zend_always_inline const uint8_t php_uuid_get_version(const php_uuid *uui * @param[in] uuid to check. * @return TRUE if the UUID contains the special nil UUID; FALSE otherwise. */ -static zend_always_inline const int php_uuid_is_nil(const php_uuid *uuid) +static const zend_always_inline int php_uuid_is_nil(const php_uuid *uuid) { const php_uuid nil = php_uuid_nil(); @@ -622,6 +636,8 @@ static zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const ); } +END_EXTERN_C() + /** * Initialization function of the standard UUID submodule. * diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index e6245cb303968..d31e38838a744 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -550,7 +550,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___wakeup_args, IS_VOID, 0) ZEND_END_ARG_INFO() /* }}} */ -#define PHP_UUID_GET_THIS_UUID() \ +#define PHP_UUID_ACCESSOR \ php_uuid *uuid = NULL; \ if (zend_parse_parameters_none_throw() == FAILURE) return; \ if ((uuid = get_uuid(&EX(This))) == NULL) return; @@ -558,7 +558,7 @@ ZEND_END_ARG_INFO() /* public function getVaraitn(): int {{{ */ PHP_METHOD(UUID, getVariant) { - PHP_UUID_GET_THIS_UUID(); + PHP_UUID_ACCESSOR; RETURN_LONG(php_uuid_get_variant(uuid)); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) @@ -568,7 +568,7 @@ ZEND_END_ARG_INFO() /* public function getVersion(): int {{{ */ PHP_METHOD(UUID, getVersion) { - PHP_UUID_GET_THIS_UUID(); + PHP_UUID_ACCESSOR; RETURN_LONG(php_uuid_get_version(uuid)); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) @@ -578,7 +578,7 @@ ZEND_END_ARG_INFO() /* public function isNil(): bool {{{ */ PHP_METHOD(UUID, isNil) { - PHP_UUID_GET_THIS_UUID(); + PHP_UUID_ACCESSOR; RETURN_BOOL(php_uuid_is_nil(uuid)); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) @@ -588,7 +588,7 @@ ZEND_END_ARG_INFO() /* public function toBinary(): string {{{ */ PHP_METHOD(UUID, toBinary) { - PHP_UUID_GET_THIS_UUID(); + PHP_UUID_ACCESSOR; RETURN_STRINGL(uuid->bytes, PHP_UUID_LEN); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) @@ -599,7 +599,7 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, toHex) { php_uuid_hex buffer; - PHP_UUID_GET_THIS_UUID(); + PHP_UUID_ACCESSOR; php_uuid_to_hex(&buffer, uuid); RETURN_STRINGL(buffer.str, UUID_HEX_LEN); } @@ -611,7 +611,7 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, toString) { php_uuid_string buffer; - PHP_UUID_GET_THIS_UUID(); + PHP_UUID_ACCESSOR; php_uuid_to_string(&buffer, uuid); RETURN_STRINGL(buffer.str, UUID_STRING_LEN); } From cf9429348acbb3dc1cc5cf7cd133d97f4ca1d288 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Mon, 29 May 2017 19:28:33 +0200 Subject: [PATCH 44/54] Made all references absolute --- ext/standard/stubs/UUIDParseException.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/standard/stubs/UUIDParseException.php b/ext/standard/stubs/UUIDParseException.php index 80b89499e1ec2..82a95406f3e78 100644 --- a/ext/standard/stubs/UUIDParseException.php +++ b/ext/standard/stubs/UUIDParseException.php @@ -45,7 +45,7 @@ * * @see UUID::parse() */ -final class UUIDParseException extends Exception { +final class UUIDParseException extends \Exception { /** @var string */ private $input; @@ -58,18 +58,18 @@ final class UUIDParseException extends Exception { * @param string $reason why parsing the UUID string failed. * @param string $input that should be parsed. * @param int $position at which parsing failed. - * @param Throwable|null $previous error/exception that lead to this + * @param \Throwable|null $previous error/exception that lead to this * failure, if any. - * @throws ArgumentCountError if less than two or more than four arguments + * @throws \ArgumentCountError if less than two or more than four arguments * are passed. */ - public function __construct(string $reason, string $input, int $position = 0, ?Throwable $previous = null) { } + public function __construct(string $reason, string $input, int $position = 0, ?\Throwable $previous = null) { } /** * Get the original input string that should have been parsed as a UUID. * * @return string - * @throws ArgumentCountError if arguments are passed. + * @throws \ArgumentCountError if arguments are passed. */ public function getInput(): string { } @@ -77,7 +77,7 @@ public function getInput(): string { } * Get the position in the input string where the parsing failure occurred. * * @return int - * @throws ArgumentCountError if arguments are passed. + * @throws \ArgumentCountError if arguments are passed. */ public function getPosition(): int { } } From 4fcb326072a8593eda751ba17f3fc494f43d7ca0 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Mon, 29 May 2017 22:49:50 +0200 Subject: [PATCH 45/54] Fixed gcc errors + warnings --- ext/standard/php_uuid.h | 8 ++++---- ext/standard/uuid.c | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index 290eef915d580..8642d2ffa09bd 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -120,7 +120,7 @@ PHPAPI extern zend_class_entry *php_ce_UUIDParseException; #define PHP_UUID_LEN 16 /** UUID binary representation to store the 128 bit number in 16 bytes. */ -PHPAPI typedef struct php_uuid { +typedef struct php_uuid { uint8_t bytes[PHP_UUID_LEN]; } php_uuid; @@ -128,7 +128,7 @@ PHPAPI typedef struct php_uuid { #define PHP_UUID_HEX_LEN 33 /** UUID hexadecimal representation: `000000001111222233334444444444444444\0` */ -PHPAPI typedef struct php_uuid_hex { +typedef struct php_uuid_hex { char str[PHP_UUID_HEX_LEN]; } php_uuid_hex; @@ -136,7 +136,7 @@ PHPAPI typedef struct php_uuid_hex { #define PHP_UUID_STRING_LEN 37 /** UUID string representation: `00000000-1111-2222-3333-4444444444444444\0` */ -PHPAPI typedef struct php_uuid_string { +typedef struct php_uuid_string { char str[PHP_UUID_STRING_LEN]; } php_uuid_string; @@ -145,7 +145,7 @@ PHPAPI typedef struct php_uuid_string { * * @see https://tools.ietf.org/html/rfc4122#section-4.1.1 */ -PHPAPI typedef enum php_uuid_variant { +typedef enum php_uuid_variant { PHP_UUID_VARIANT_NCS = 0, /* 0b0xx */ PHP_UUID_VARIANT_RFC4122 = 1, /* 0b10x */ PHP_UUID_VARIANT_MICROSOFT = 2, /* 0b110 */ diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index d31e38838a744..bd119898359cd 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -473,13 +473,13 @@ ZEND_END_ARG_INFO() #define PHP_UUID_NAMED_CONSTRUCTOR(method_name, name) \ PHP_METHOD(UUID, method_name) \ { \ - const php_uuid name = php_uuid_##name##(); \ + const php_uuid name = php_uuid_##name(); \ \ if (zend_parse_parameters_none_throw() == FAILURE) { \ return; \ } \ \ - new_uuid(return_value, &##name##); \ + new_uuid(return_value, &name); \ } \ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_##method_name##_args, self, 0) \ ZEND_END_ARG_INFO() From b1ac4dea1c05ae3c2e125f3a2d77cb44308f36d6 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Mon, 29 May 2017 23:56:26 +0200 Subject: [PATCH 46/54] Consistenly use unsigned char everywhere --- ext/standard/php_uuid.h | 14 +++++++------- ext/standard/uuid.c | 38 +++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index 8642d2ffa09bd..aab10fb3a59db 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -129,7 +129,7 @@ typedef struct php_uuid { /** UUID hexadecimal representation: `000000001111222233334444444444444444\0` */ typedef struct php_uuid_hex { - char str[PHP_UUID_HEX_LEN]; + unsigned char str[PHP_UUID_HEX_LEN]; } php_uuid_hex; /** UUID string representation length with terminating NUL. */ @@ -137,7 +137,7 @@ typedef struct php_uuid_hex { /** UUID string representation: `00000000-1111-2222-3333-4444444444444444\0` */ typedef struct php_uuid_string { - char str[PHP_UUID_STRING_LEN]; + unsigned char str[PHP_UUID_STRING_LEN]; } php_uuid_string; /** @@ -313,7 +313,7 @@ static const zend_always_inline php_uuid php_uuid_nil() * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. * @throws UUIDParseException if throw is enabled and parsing fails. */ -PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_len, const zend_bool throw); +PHPAPI int php_uuid_parse(php_uuid *uuid, const unsigned char *input, const size_t input_len, const zend_bool throw); /** * Silently parse the string as UUID. @@ -324,7 +324,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ * @param[in] input_len * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. */ -static zend_always_inline int php_uuid_parse_silent(php_uuid *uuid, const char *input, const size_t input_len) +static zend_always_inline int php_uuid_parse_silent(php_uuid *uuid, const unsigned char *input, const size_t input_len) { return php_uuid_parse(uuid, input, input_len, 0); } @@ -339,7 +339,7 @@ static zend_always_inline int php_uuid_parse_silent(php_uuid *uuid, const char * * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. * @throws UUIDParseException if throw is enabled and parsing fails. */ -static zend_always_inline int php_uuid_parse_throw(php_uuid *uuid, const char *input, const size_t input_len) +static zend_always_inline int php_uuid_parse_throw(php_uuid *uuid, const unsigned char *input, const size_t input_len) { return php_uuid_parse(uuid, input, input_len, 1); } @@ -392,7 +392,7 @@ static zend_always_inline int php_uuid_parse_throw(php_uuid *uuid, const char *i * @param[in] name to create the UUID from. * @param[in] name_len */ -PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len); +PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const unsigned char *name, const size_t name_len); /** * Create version 4 UUID. @@ -503,7 +503,7 @@ static zend_always_inline int php_uuid_create_v4_throw(php_uuid *uuid) * @param[in] name to create the UUID from. * @param[in] name_len */ -PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len); +PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const unsigned char *name, const size_t name_len); /** * Get the variant associated with this UUID. diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index bd119898359cd..2139a0a7262e9 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -29,23 +29,23 @@ PHPAPI zend_class_entry *php_ce_UUID; PHPAPI zend_class_entry *php_ce_UUIDParseException; -static const uint8_t UUID_VERSION_MIN = 0; -static const uint8_t UUID_VERSION_MAX = 15; +static const uint8_t UUID_VERSION_MIN = 0; +static const uint8_t UUID_VERSION_MAX = 15; -static const uint8_t UUID_HEX_LEN = sizeof(php_uuid_hex) - 1; -static const uint8_t UUID_STRING_LEN = sizeof(php_uuid_string) - 1; +static const uint8_t UUID_HEX_LEN = sizeof(php_uuid_hex) - 1; +static const uint8_t UUID_STRING_LEN = sizeof(php_uuid_string) - 1; -static const char UUID_BYTES_PROP[] = "bytes"; -static const uint8_t UUID_BYTES_PROP_LEN = sizeof(UUID_BYTES_PROP) - 1; +static const unsigned char UUID_BYTES_PROP[] = "bytes"; +static const uint8_t UUID_BYTES_PROP_LEN = sizeof(UUID_BYTES_PROP) - 1; -static const char UUID_EX_INPUT_PROP[] = "input"; -static const uint8_t UUID_EX_INPUT_PROP_LEN = sizeof(UUID_EX_INPUT_PROP) - 1; +static const unsigned char UUID_EX_INPUT_PROP[] = "input"; +static const uint8_t UUID_EX_INPUT_PROP_LEN = sizeof(UUID_EX_INPUT_PROP) - 1; -static const char UUID_EX_POSITION_PROP[] = "position"; -static const uint8_t UUID_EX_POSITON_PROP_LEN = sizeof(UUID_EX_POSITION_PROP) - 1; +static const unsigned char UUID_EX_POSITION_PROP[] = "position"; +static const uint8_t UUID_EX_POSITON_PROP_LEN = sizeof(UUID_EX_POSITION_PROP) - 1; -static const char URN_PREFIX[] = "urn:uuid:"; -static const uint8_t URN_PREFIX_LEN = sizeof(URN_PREFIX) - 1; +static const unsigned char URN_PREFIX[] = "urn:uuid:"; +static const uint8_t URN_PREFIX_LEN = sizeof(URN_PREFIX) - 1; /** * Set UUID variant to RFC 4122, the only supported variant. @@ -84,7 +84,7 @@ static zend_always_inline void php_uuid_set_version(php_uuid *uuid, const uint8_ * @param[in] reason why parsing failed. * @param[in] ... arguments to format the reason. */ -static ZEND_COLD zend_object *throw_uuid_parse_exception(const char *input, const size_t input_len, const size_t position, const char *reason, ...) +static ZEND_COLD zend_object *throw_uuid_parse_exception(const unsigned char *input, const size_t input_len, const size_t position, const unsigned char *reason, ...) { va_list format_args; char *formatted_reason; @@ -112,7 +112,7 @@ static ZEND_COLD zend_object *throw_uuid_parse_exception(const char *input, cons * @param[in] position at which parsing failed. * @param[in] actual amount of characters that were found. */ -static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_len(const char *input, const size_t input_len, const size_t position, const size_t actual) +static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_len(const unsigned char *input, const size_t input_len, const size_t position, const size_t actual) { return throw_uuid_parse_exception( input, @@ -131,7 +131,7 @@ static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_len(co * @param[in] input_len * @param[in] position at which parsing failed. */ -static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_char(const char *input, const size_t input_len, const size_t position) +static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_char(const unsigned char *input, const size_t input_len, const size_t position) { return throw_uuid_parse_exception( input, @@ -143,7 +143,7 @@ static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_char(c ); } -PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_len, const zend_bool throw) +PHPAPI int php_uuid_parse(php_uuid *uuid, const unsigned char *input, const size_t input_len, const zend_bool throw) { size_t position = 0; size_t digit = 0; @@ -170,7 +170,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ } for (; position <= limit; ++position) { - const char chr = input[position]; + const unsigned char chr = input[position]; /* First digit of the byte. */ if (digit % 2 == 0) { @@ -246,7 +246,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ return SUCCESS; } -PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) +PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const unsigned char *name, const size_t name_len) { PHP_MD5_CTX context; @@ -270,7 +270,7 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw) return result; } -PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) +PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const unsigned char *name, const size_t name_len) { PHP_SHA1_CTX context; char digest[20]; From 2ab7c5af502cf06451a2c5d0312acefa2f30c984 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Tue, 30 May 2017 00:04:06 +0200 Subject: [PATCH 47/54] Use char instead of uchar for sprintf --- ext/standard/php_uuid.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index aab10fb3a59db..6d5f4ce373201 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -129,7 +129,7 @@ typedef struct php_uuid { /** UUID hexadecimal representation: `000000001111222233334444444444444444\0` */ typedef struct php_uuid_hex { - unsigned char str[PHP_UUID_HEX_LEN]; + char str[PHP_UUID_HEX_LEN]; } php_uuid_hex; /** UUID string representation length with terminating NUL. */ @@ -137,7 +137,7 @@ typedef struct php_uuid_hex { /** UUID string representation: `00000000-1111-2222-3333-4444444444444444\0` */ typedef struct php_uuid_string { - unsigned char str[PHP_UUID_STRING_LEN]; + char str[PHP_UUID_STRING_LEN]; } php_uuid_string; /** From 92e0a28c1df42db5e99e8cbf41efee435d2ac89a Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Tue, 30 May 2017 00:22:38 +0200 Subject: [PATCH 48/54] More signes changes according to gcc --- ext/standard/php_uuid.h | 6 +++--- ext/standard/uuid.c | 8 ++++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index 6d5f4ce373201..a53608355afc8 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -313,7 +313,7 @@ static const zend_always_inline php_uuid php_uuid_nil() * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. * @throws UUIDParseException if throw is enabled and parsing fails. */ -PHPAPI int php_uuid_parse(php_uuid *uuid, const unsigned char *input, const size_t input_len, const zend_bool throw); +PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_len, const zend_bool throw); /** * Silently parse the string as UUID. @@ -324,7 +324,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const unsigned char *input, const size * @param[in] input_len * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. */ -static zend_always_inline int php_uuid_parse_silent(php_uuid *uuid, const unsigned char *input, const size_t input_len) +static zend_always_inline int php_uuid_parse_silent(php_uuid *uuid, const char *input, const size_t input_len) { return php_uuid_parse(uuid, input, input_len, 0); } @@ -339,7 +339,7 @@ static zend_always_inline int php_uuid_parse_silent(php_uuid *uuid, const unsign * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. * @throws UUIDParseException if throw is enabled and parsing fails. */ -static zend_always_inline int php_uuid_parse_throw(php_uuid *uuid, const unsigned char *input, const size_t input_len) +static zend_always_inline int php_uuid_parse_throw(php_uuid *uuid, const char *input, const size_t input_len) { return php_uuid_parse(uuid, input, input_len, 1); } diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 2139a0a7262e9..297b18c0f5d13 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -84,7 +84,7 @@ static zend_always_inline void php_uuid_set_version(php_uuid *uuid, const uint8_ * @param[in] reason why parsing failed. * @param[in] ... arguments to format the reason. */ -static ZEND_COLD zend_object *throw_uuid_parse_exception(const unsigned char *input, const size_t input_len, const size_t position, const unsigned char *reason, ...) +static ZEND_COLD zend_object *throw_uuid_parse_exception(const char *input, const size_t input_len, const size_t position, const char *reason, ...) { va_list format_args; char *formatted_reason; @@ -112,7 +112,7 @@ static ZEND_COLD zend_object *throw_uuid_parse_exception(const unsigned char *in * @param[in] position at which parsing failed. * @param[in] actual amount of characters that were found. */ -static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_len(const unsigned char *input, const size_t input_len, const size_t position, const size_t actual) +static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_len(const char *input, const size_t input_len, const size_t position, const size_t actual) { return throw_uuid_parse_exception( input, @@ -131,7 +131,7 @@ static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_len(co * @param[in] input_len * @param[in] position at which parsing failed. */ -static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_char(const unsigned char *input, const size_t input_len, const size_t position) +static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_char(const char *input, const size_t input_len, const size_t position) { return throw_uuid_parse_exception( input, @@ -143,7 +143,7 @@ static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_char(c ); } -PHPAPI int php_uuid_parse(php_uuid *uuid, const unsigned char *input, const size_t input_len, const zend_bool throw) +PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_len, const zend_bool throw) { size_t position = 0; size_t digit = 0; From ee74c598e237dbd37db7f83a8136a81534806c9c Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Tue, 30 May 2017 00:35:57 +0200 Subject: [PATCH 49/54] More sign changes according to gcc --- ext/standard/php_uuid.h | 4 ++-- ext/standard/uuid.c | 34 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index a53608355afc8..8642d2ffa09bd 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -392,7 +392,7 @@ static zend_always_inline int php_uuid_parse_throw(php_uuid *uuid, const char *i * @param[in] name to create the UUID from. * @param[in] name_len */ -PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const unsigned char *name, const size_t name_len); +PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len); /** * Create version 4 UUID. @@ -503,7 +503,7 @@ static zend_always_inline int php_uuid_create_v4_throw(php_uuid *uuid) * @param[in] name to create the UUID from. * @param[in] name_len */ -PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const unsigned char *name, const size_t name_len); +PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len); /** * Get the variant associated with this UUID. diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 297b18c0f5d13..4ad4eac425153 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -29,23 +29,23 @@ PHPAPI zend_class_entry *php_ce_UUID; PHPAPI zend_class_entry *php_ce_UUIDParseException; -static const uint8_t UUID_VERSION_MIN = 0; -static const uint8_t UUID_VERSION_MAX = 15; +static const uint8_t UUID_VERSION_MIN = 0; +static const uint8_t UUID_VERSION_MAX = 15; -static const uint8_t UUID_HEX_LEN = sizeof(php_uuid_hex) - 1; -static const uint8_t UUID_STRING_LEN = sizeof(php_uuid_string) - 1; +static const uint8_t UUID_HEX_LEN = sizeof(php_uuid_hex) - 1; +static const uint8_t UUID_STRING_LEN = sizeof(php_uuid_string) - 1; -static const unsigned char UUID_BYTES_PROP[] = "bytes"; -static const uint8_t UUID_BYTES_PROP_LEN = sizeof(UUID_BYTES_PROP) - 1; +static const char UUID_BYTES_PROP[] = "bytes"; +static const uint8_t UUID_BYTES_PROP_LEN = sizeof(UUID_BYTES_PROP) - 1; -static const unsigned char UUID_EX_INPUT_PROP[] = "input"; -static const uint8_t UUID_EX_INPUT_PROP_LEN = sizeof(UUID_EX_INPUT_PROP) - 1; +static const char UUID_EX_INPUT_PROP[] = "input"; +static const uint8_t UUID_EX_INPUT_PROP_LEN = sizeof(UUID_EX_INPUT_PROP) - 1; -static const unsigned char UUID_EX_POSITION_PROP[] = "position"; -static const uint8_t UUID_EX_POSITON_PROP_LEN = sizeof(UUID_EX_POSITION_PROP) - 1; +static const char UUID_EX_POSITION_PROP[] = "position"; +static const uint8_t UUID_EX_POSITON_PROP_LEN = sizeof(UUID_EX_POSITION_PROP) - 1; -static const unsigned char URN_PREFIX[] = "urn:uuid:"; -static const uint8_t URN_PREFIX_LEN = sizeof(URN_PREFIX) - 1; +static const char URN_PREFIX[] = "urn:uuid:"; +static const uint8_t URN_PREFIX_LEN = sizeof(URN_PREFIX) - 1; /** * Set UUID variant to RFC 4122, the only supported variant. @@ -170,7 +170,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ } for (; position <= limit; ++position) { - const unsigned char chr = input[position]; + const char chr = input[position]; /* First digit of the byte. */ if (digit % 2 == 0) { @@ -246,7 +246,7 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ return SUCCESS; } -PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const unsigned char *name, const size_t name_len) +PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) { PHP_MD5_CTX context; @@ -270,14 +270,14 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw) return result; } -PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const unsigned char *name, const size_t name_len) +PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) { PHP_SHA1_CTX context; - char digest[20]; + unsigned char digest[20]; PHP_SHA1Init(&context); PHP_SHA1Update(&context, namespace->bytes, PHP_UUID_LEN); - PHP_SHA1Update(&context, name, name_len); + PHP_SHA1Update(&context, (const unsigned char *) name, name_len); PHP_SHA1Final(digest, &context); memcpy(uuid->bytes, digest, PHP_UUID_LEN); set_variant_rfc4122(uuid); From 7e2d8c835a53df43f1b3c5dca683e9daac71a2ef Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Tue, 30 May 2017 00:45:54 +0200 Subject: [PATCH 50/54] More sign warnings from gcc --- ext/standard/php_uuid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index 8642d2ffa09bd..0ade1b3ec0044 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -121,7 +121,7 @@ PHPAPI extern zend_class_entry *php_ce_UUIDParseException; /** UUID binary representation to store the 128 bit number in 16 bytes. */ typedef struct php_uuid { - uint8_t bytes[PHP_UUID_LEN]; + char bytes[PHP_UUID_LEN]; } php_uuid; /** UUID hexadecimal representation length with terminating NUL. */ From 03c162794930dca2de860317609f4561d4978183 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Wed, 31 May 2017 21:46:14 +0200 Subject: [PATCH 51/54] Fixed all remaining errors + warnings --- ...flectionExtension_getClassNames_basic.phpt | 19 +++++++++++-------- ext/standard/php_uuid.h | 2 +- ext/standard/uuid.c | 10 ++++++---- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt b/ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt index 3fea08c43f115..a333acc26bba3 100644 --- a/ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt +++ b/ext/reflection/tests/ReflectionExtension_getClassNames_basic.phpt @@ -2,21 +2,24 @@ ReflectionExtension::getClassNames() method on an extension which actually returns some information --CREDITS-- Felix De Vliegher +Richard Fussenegger --FILE-- getClassNames()); ?> -==DONE== ---EXPECTF-- -array(4) { +--EXPECT-- +array(6) { [0]=> - %s(22) "__PHP_Incomplete_Class" + string(22) "__PHP_Incomplete_Class" [1]=> - %s(15) "php_user_filter" + string(15) "php_user_filter" [2]=> - %s(9) "Directory" + string(9) "Directory" [3]=> - %s(14) "AssertionError" + string(14) "AssertionError" + [4]=> + string(4) "UUID" + [5]=> + string(18) "UUIDParseException" } -==DONE== diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index 0ade1b3ec0044..8642d2ffa09bd 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -121,7 +121,7 @@ PHPAPI extern zend_class_entry *php_ce_UUIDParseException; /** UUID binary representation to store the 128 bit number in 16 bytes. */ typedef struct php_uuid { - char bytes[PHP_UUID_LEN]; + uint8_t bytes[PHP_UUID_LEN]; } php_uuid; /** UUID hexadecimal representation length with terminating NUL. */ diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 4ad4eac425153..3b7515ae51887 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -249,11 +249,13 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) { PHP_MD5_CTX context; + unsigned char digest[16]; PHP_MD5Init(&context); PHP_MD5Update(&context, namespace->bytes, PHP_UUID_LEN); PHP_MD5Update(&context, name, name_len); - PHP_MD5Final(uuid->bytes, &context); + PHP_MD5Final(digest, &context); + memcpy(uuid->bytes, digest, PHP_UUID_LEN); set_variant_rfc4122(uuid); php_uuid_set_version(uuid, PHP_UUID_VERSION_3_NAME_BASED_MD5); } @@ -276,7 +278,7 @@ PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const unsigned char digest[20]; PHP_SHA1Init(&context); - PHP_SHA1Update(&context, namespace->bytes, PHP_UUID_LEN); + PHP_SHA1Update(&context, (const unsigned char *) namespace->bytes, PHP_UUID_LEN); PHP_SHA1Update(&context, (const unsigned char *) name, name_len); PHP_SHA1Final(digest, &context); memcpy(uuid->bytes, digest, PHP_UUID_LEN); @@ -337,7 +339,7 @@ static zend_always_inline php_uuid *get_uuid(/*const*/ zval *uuid_object) static zend_always_inline void new_uuid(zval *object, const php_uuid *uuid) { object_init_ex(object, php_ce_UUID); - zend_update_property_stringl(php_ce_UUID, object, UUID_BYTES_PROP, UUID_BYTES_PROP_LEN, uuid->bytes, PHP_UUID_LEN); + zend_update_property_stringl(php_ce_UUID, object, UUID_BYTES_PROP, UUID_BYTES_PROP_LEN, (const char *) uuid->bytes, PHP_UUID_LEN); } /* private function __construct() {{{ */ @@ -589,7 +591,7 @@ ZEND_END_ARG_INFO() PHP_METHOD(UUID, toBinary) { PHP_UUID_ACCESSOR; - RETURN_STRINGL(uuid->bytes, PHP_UUID_LEN); + RETURN_STRINGL((const char *) uuid->bytes, PHP_UUID_LEN); } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) ZEND_END_ARG_INFO() From c1067c9256959f9246daa7658a94fea0d612295e Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Thu, 1 Jun 2017 20:06:16 +0200 Subject: [PATCH 52/54] Extended documentation Actually generated the documentation to verify that it is in a format that adheres to the rules of Doxygen, and not PhpDoc. --- ext/standard/php_uuid.h | 497 +++++++++++++++++++++------------------- ext/standard/uuid.c | 253 +++++++++++--------- 2 files changed, 406 insertions(+), 344 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index 8642d2ffa09bd..7e07609882a9c 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -18,12 +18,13 @@ /* $Id$ */ -/** +/** @file ext/standard/php_uuid.h + * * Generate and parse RFC 4122/DCE 1.1 Universally Unique Identifiers (UUIDs). * * This standard submodule provides generation and parsing capabilities for * Universally Unique Identifiers (UUIDs, also known as Globally Unique - * Identifiers [GUIDs]) as specified in RFC 4122. + * Identifiers [GUIDs]) as specified in [RFC 4122]. * * UUIDs are 128 bit integers that guarantee uniqueness across space and time. * They are mainly used to assign identifiers to entities without requiring a @@ -33,7 +34,7 @@ * * There are different types of UUIDs, known as variants. This implementation * generates UUIDs according to the Leach-Salz variant; the one specified in - * RFC 4122 as variant 1. Textual parsing supports both variant 1 (RFC 4122) + * [RFC 4122] as variant 1. Textual parsing supports both variant 1 ([RFC 4122]) * and variant 2 (Microsoft), and construction supports any kind of UUID. * However, note that the provided functions are **not** guaranteed to provide * meaningful results if any other variants than the Leach-Salz one is used. @@ -43,7 +44,7 @@ * * Versions 3 and 5 are meant for generating UUIDs from "names" that are drawn * from, and unique within, some "namespace". They generate the same UUID for - * the same name in the same namespace across all RFC 4122 compliant + * the same name in the same namespace across all [RFC 4122] compliant * implementations. * * Version 4 UUIDs are random and result in a new UUID upon every generation. @@ -51,7 +52,7 @@ * uses the best available random source of the operating system. * * Versions 1 and 2 are not supported due to privacy/security concerns. Refer - * to the Wikipedia article for more information. + * to the [Wikipedia] article for more information. * * This implementation is inspired by many other implementations: * - [RFC 4122 Sample Implementation](https://tools.ietf.org/html/rfc4122#appendix-A) @@ -60,14 +61,18 @@ * - [boost Uuid](http://www.boost.org/doc/libs/1_64_0/libs/uuid/) * - [D std.uuid](https://dlang.org/library/std/uuid.html) * - * ## Examples - * ``` + * ### Examples + * + * ```c * php_uuid uuid; * * // A random UUID with more randomness than the version 4 implementation. - * // This should NOT be used in real-world applications! + * // Do NOT be used in real-world applications! * php_random_bytes_silent(&uuid, PHP_UUID_LEN); - * php_uuid_set_variant(&uuid, PHP_UUID_VARIANT_FUTURE_RESERVED); + * + * // Set version to future reserved, because we are using a custom UUID. + * // Once more, do NOT use this in real-world applications! + * uuid.bytes = (uuid.bytes[8] & 0x1F) | 0xE0; * * php_uuid_create_v3(&uuid, php_uuid_namespace_dns(), "php.net", sizeof("php.net") - 1); * assert(php_uuid_is_nil(uuid) == FALSE); @@ -100,8 +105,12 @@ * assert(memcmp(&str, "123e4567-e89b-12d3-a456-426655440000", PHP_UUID_STRING_LEN) == 0); * ``` * - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier - * @see https://tools.ietf.org/html/rfc4122 + * @author [Richard Fussenegger](mailto:php@fleshgrinder.com) + * @see [Wikipedia: Universally unique identifier][Wikipedia] + * @see [RFC 4122] + * + * [RFC 4122]: https://tools.ietf.org/html/rfc4122 + * [Wikipedia]: https://en.wikipedia.org/wiki/Universally_unique_identifier */ #ifndef PHP_UUID_H @@ -110,10 +119,10 @@ #include "zend_types.h" #include "php.h" -/** UUID class entry for usage by other modules. */ +/** `UUID` class entry for usage by other modules. */ PHPAPI extern zend_class_entry *php_ce_UUID; -/** UUIDParseException class entry for usage by other modules. */ +/** `UUIDParseException` class entry for usage by other modules. */ PHPAPI extern zend_class_entry *php_ce_UUIDParseException; /** UUID binary representation length without terminating NUL. */ @@ -141,26 +150,33 @@ typedef struct php_uuid_string { } php_uuid_string; /** - * UUID variants as defined in RFC 4122. - * - * @see https://tools.ietf.org/html/rfc4122#section-4.1.1 + * UUID variants as defined in [RFC 4122](https://tools.ietf.org/html/rfc4122#section-4.1.1). */ typedef enum php_uuid_variant { - PHP_UUID_VARIANT_NCS = 0, /* 0b0xx */ - PHP_UUID_VARIANT_RFC4122 = 1, /* 0b10x */ - PHP_UUID_VARIANT_MICROSOFT = 2, /* 0b110 */ - PHP_UUID_VARIANT_FUTURE_RESERVED = 3, /* 0b111 */ + /** Reserved, NCS backward compatibility: `0b0xx` */ + PHP_UUID_VARIANT_NCS = 0, + + /** The variant of this implementation and specified in RFC 4122: `0b10x` */ + PHP_UUID_VARIANT_RFC4122 = 1, + + /** Reserved, Microsoft Corporation backward compatibility: `0b110` */ + PHP_UUID_VARIANT_MICROSOFT = 2, + + /** Reserved for future definition: `0b111` */ + PHP_UUID_VARIANT_FUTURE_RESERVED = 3, } php_uuid_variant; /** * Version code for date-time and IEEE 802 MAC address UUIDs. * + * @warning * Generation of this version is not supported by this implementation due * to security concerns. Version 4 UUIDs are a good replacement for version - * 1 UUIDs without the privacy/security concerns (see Wikipedia). + * 1 UUIDs without the privacy/security concerns (see [Wikipedia]). * - * @see https://tools.ietf.org/html/rfc4122#section-4.2 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_.28date-time_and_MAC_address.29 + * @see [RFC 4122: Section 4.2](https://tools.ietf.org/html/rfc4122#section-4.2) + * @see [Wikipedia: Universally unique identifier (Version 1)][Wikipedia] + * [Wikipedia]: https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_.28date-time_and_MAC_address.29 */ static const uint8_t PHP_UUID_VERSION_1_TIME_BASED = 1; @@ -168,211 +184,80 @@ static const uint8_t PHP_UUID_VERSION_1_TIME_BASED = 1; * Version code for date-time and IEEE 802 MAC address UUIDs (DCE security * algorithm). * + * @warning * Generation of this version is not supported by this implementation due * to security concerns, and uniqueness limitations for applications with * high allocations. Version 4 UUIDs are a good replacement for version 2 - * UUIDs without the privacy/security concerns (see Wikipedia), and they + * UUIDs without the privacy/security concerns (see [Wikipedia]), and they * support high allocations. * - * @see https://tools.ietf.org/html/rfc4122#section-4.2 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_2_.28date-time_and_MAC_Address.2C_DCE_security_version.29 + * @see [RFC 4122: Section 4.2](https://tools.ietf.org/html/rfc4122#section-4.2) + * @see [Wikipedia: Universally unique identifier (Version 2)][Wikipedia] + * [Wikipedia]: https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_2_.28date-time_and_MAC_Address.2C_DCE_security_version.29 */ static const uint8_t PHP_UUID_VERSION_2_DCE_SECURITY = 2; /** * Version code for namespace/name-based MD5 hashed UUIDs. * - * @see php_uuid_create_v3 - * @see https://tools.ietf.org/html/rfc4122#section-4.3 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 + * @see php_uuid_create_v3() + * @see [RFC 4122: Section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3) + * @see [Wikipedia: Universally unique identifiers (versions 3 and 5)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29) */ static const uint8_t PHP_UUID_VERSION_3_NAME_BASED_MD5 = 3; /** * Version code for random UUIDs. * - * @see php_uuid_create_v4 - * @see https://tools.ietf.org/html/rfc4122#section-4.4 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 + * @see php_uuid_create_v4() + * @see [RFC 4122: Section 4.4](https://tools.ietf.org/html/rfc4122#section-4.4) + * @see [Wikipedia: Universally unique identifiers (version 4)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29) */ static const uint8_t PHP_UUID_VERSION_4_RANDOM = 4; /** * Version code for namespace/name-based SHA1 hashed UUIDs. * - * @see php_uuid_create_v5 - * @see https://tools.ietf.org/html/rfc4122#section-4.3 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 + * @see php_uuid_create_v5() + * @see [RFC 4122: Section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3) + * @see [Wikipedia: Universally unique identifiers (versions 3 and 5)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29) */ static const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1 = 5; BEGIN_EXTERN_C() -/** - * Domain Name System (DNS) namespace UUID. - * - * @see https://tools.ietf.org/html/rfc4122#appendix-C - * @see https://en.wikipedia.org/wiki/Domain_Name_System - */ -static const zend_always_inline php_uuid php_uuid_namespace_dns() -{ - return (php_uuid) { "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; -} - -/** -* Object Identifier (OID) namespace UUID. -* - * @see https://tools.ietf.org/html/rfc4122#appendix-C - * @see https://en.wikipedia.org/wiki/Object_identifier - */ -static const zend_always_inline php_uuid php_uuid_namespace_oid() -{ - return (php_uuid) { "\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; -} - -/** - * Uniform Resource Locator (URL) namespace UUID. - * - * @see https://tools.ietf.org/html/rfc4122#appendix-C - * @see https://en.wikipedia.org/wiki/URL - */ -static const zend_always_inline php_uuid php_uuid_namespace_url() -{ - return (php_uuid) { "\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; -} - -/** - * X.500 Distinguished Names (X.500 DN) namespace UUID. The names that are to - * be hashed in this namespace can be in DER or a text output format. - * - * @see https://tools.ietf.org/html/rfc4122#appendix-C - * @see https://en.wikipedia.org/wiki/X.500 - * @see https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol - */ -static const zend_always_inline php_uuid php_uuid_namespace_x500() -{ - return (php_uuid) { "\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; -} - -/** - * Special nil UUID that has all 128 bits set to zero. - * - * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID - */ -static const zend_always_inline php_uuid php_uuid_nil() -{ - return (php_uuid) { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }; -} - -/** - * Parse the given string as UUID. - * - * The following UUID representations are parsable: - * - * - hexadecimal (`00000000111122223333444444444444`), - * - string (`00000000-1111-2222-3333-444444444444`), - * - URNs (`urn:uuid:00000000-1111-2222-3333-444444444444`), and - * - Microsoft (`{00000000-1111-2222-3333-444444444444}`). - * - * Leading and trailing whitespace, namely spaces (` `) and tabs (`\t`), is - * ignored, so are leading opening braces (`{`) and trailing closing braces - * (`}`). Hyphens (`-`) are ignored everywhere. The parsing algorithm - * follows the [robustness - * principle](https://en.wikipedia.org/wiki/Robustness_principle) and is - * not meant for validation. - * - * ## Examples - * ``` - * php_uuid uuid; - * - * // Parsing of canonical representations. - * php_uuid_parse_silent(&uuid, "0123456789abcdef0123456789abcdef", sizeof("0123456789abcdef0123456789abcdef") - 1); - * php_uuid_parse_silent(&uuid, "01234567-89ab-cdef-0123-456789abcdef", sizeof("01234567-89ab-cdef-0123-456789abcdef") - 1); - * php_uuid_parse_silent(&uuid, "urn:uuid:01234567-89ab-cdef-0123-456789abcdef", sizeof("urn:uuid:01234567-89ab-cdef-0123-456789abcdef") - 1); - * php_uuid_parse_silent(&uuid, "{01234567-89ab-cdef-0123-456789abcdef}", sizeof("{01234567-89ab-cdef-0123-456789abcdef}") - 1); - * - * // Leading and trailing garbage is ignored, so are extraneous hyphens. - * php_uuid_parse_silent(&uuid, " \t ---- { urn:uuid:----0123-4567-89ab-cdef-0123-4567-89ab-cdef---- } ---- \t ", sizeof(" \t ---- { urn:uuid:----0123-4567-89ab-cdef-0123-4567-89ab-cdef---- } ---- \t ") - 1); - * - * // However, note that there cannot be whitespace or braces between the URN - * // scheme and the UUID itself. - * assert(php_uuid_parse_silent( - * &uuid, - * "urn:uuid:{01234567-89ab-cdef-0123-456789abcdef", - * sizeof("urn:uuid:{01234567-89ab-cdef-0123-456789abcdef") - 1 - * ) == FAILURE); - * ``` - * - * @see php_uuid_parse_silent - * @see php_uuid_parse_throw - * @param[out] uuid to store the result in. - * @param[in] input to parse as UUID. - * @param[in] input_len - * @param[in] throw whether to throw PHP exceptions (`1`), or not (`0`). - * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. - * @throws UUIDParseException if throw is enabled and parsing fails. - */ -PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_len, const zend_bool throw); - -/** - * Silently parse the string as UUID. - * - * @see php_uuid_parse - * @param[out] uuid to store the result in. - * @param[in] input to parse as UUID. - * @param[in] input_len - * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. - */ -static zend_always_inline int php_uuid_parse_silent(php_uuid *uuid, const char *input, const size_t input_len) -{ - return php_uuid_parse(uuid, input, input_len, 0); -} - -/** - * Parse the string as UUID and throw PHP exceptions on failures. - * - * @see php_uuid_parse - * @param[out] uuid to store the result in. - * @param[in] input to parse as UUID. - * @param[in] input_len - * @return `SUCCESS` if the string was parsed as UUID, `FAILURE` otherwise. - * @throws UUIDParseException if throw is enabled and parsing fails. - */ -static zend_always_inline int php_uuid_parse_throw(php_uuid *uuid, const char *input, const size_t input_len) -{ - return php_uuid_parse(uuid, input, input_len, 1); -} - /** * Create version 3 UUID. * - * > RFC 4122 recommends {@see v5} over this one and states that version 3 - * > UUIDs should be used if backwards compatibility is required only. This - * > is because MD5 has a higher collision probability compared to SHA1, - * > which is used by version 5; regardless of the truncation! + * @warning + * [RFC 4122] recommends [v5](@ref php_uuid_create_v5()) over this one and + * states that version 3 UUIDs should be used if backwards compatibility is + * required only. This is because MD5 has a higher collision probability + * compared to SHA1, which is used by version 5; regardless of the truncation! * - * Version 3 UUIDs are generated by MD5 hashing the concatenated namespace's - * byte representation and the given name. The namespace itself must be - * another UUID. This can be any UUID, or one of the predefined ones: + * Version 3 UUIDs are generated by [MD5](https://en.wikipedia.org/wiki/MD5) + * hashing the concatenated namespace's byte representation and the given name. + * The namespace itself must be another UUID. This can be any UUID, or one of + * the predefined ones: * - * - {@see php_uuid_namespace_dns} - * - {@see php_uuid_namespace_oid} - * - {@see php_uuid_namespace_url} - * - {@see php_uuid_namespace_x500} + * - php_uuid_namespace_dns() + * - php_uuid_namespace_oid() + * - php_uuid_namespace_url() + * - php_uuid_namespace_x500() * * A particular name within the same namespace always results in the same - * version 3 UUID, across all RFC 4122 compliant UUID implementations. + * version 3 UUID, across all [RFC 4122] compliant UUID implementations. * However, the namespace and name cannot be determined from the UUID alone. * - * ## Examples - * ``` + * ### Examples + * + * ```c * const php_uuid nsid = php_uuid_namespace_dns(); * php_uuid uuid; * * php_uuid_create_v3(&uuid, &nsid, "php.net", sizeof("php.net") - 1); * - * assert(php_uuid_is_nil(uuid) == FALSE); + * assert(php_uuid_is_nil(uuid) == 0); * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_3_NAME_BASED_MD5); * @@ -385,8 +270,9 @@ static zend_always_inline int php_uuid_parse_throw(php_uuid *uuid, const char *i * assert(memcmp(&tmp, &uuid, PHP_UUID_LEN) == 0); * ``` * - * @see https://tools.ietf.org/html/rfc4122#section-4.3 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 + * [RFC 4122]: https://tools.ietf.org/html/rfc4122 + * @see [RFC 4122: Section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3) + * @see [Wikipedia: Universally unique identifier (Versions 3 and 5)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29) * @param[out] uuid to store the result in. * @param[in] namespace to create the UUID in. * @param[in] name to create the UUID from. @@ -401,15 +287,16 @@ PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const * The selection of that source is determined by PHP's random implementation. * Some systems may be bad at generating sufficient entropy, e.g. virtual * machines. This might lead to collisions faster than desired. If this is the - * case, the {@see php_uuid_create_v5} version should be used. + * case, the php_uuid_create_v5() implementation should be used. * - * ## Examples - * ``` + * ### Examples + * + * ```c * php_uuid uuid; * * php_uuid_create_v4_silent(&uuid); * - * assert(php_uuid_is_nil(uuid) == FALSE); + * assert(php_uuid_is_nil(uuid) == 0); * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_4_RANDOM); * @@ -418,15 +305,15 @@ PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const * assert(memcmp(&tmp, &uuid, PHP_UUID_LEN) == 0); * ``` * - * @see https://tools.ietf.org/html/rfc4122#section-4.4 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 - * @see php_uuid_create_v4_silent - * @see php_uuid_create_v4_throw + * @see [RFC 4122: Section 4.4](https://tools.ietf.org/html/rfc4122#section-4.4) + * @see [Wikipedia: Universally unique identifier (Version 4)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29) + * @see php_uuid_create_v4_silent() + * @see php_uuid_create_v4_throw() * @param[out] uuid to store the result. * @param[in] throw whether to throw a PHP exception (`1`), or not (`0`). - * @return `SUCCESS` if the generation succeeded, `FAILURE` if it was not + * @return #SUCCESS() if the generation succeeded, #FAILURE() if it was not * possible to gather sufficient entropy. - * @throws Exception if throw is enabled and it was not possible to gather + * @throws Exception if `throw` is set to true and it was not possible to gather * sufficient entropy for generating random bytes. */ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); @@ -434,9 +321,9 @@ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); /** * Silently create version 4 UUID. * - * @see php_uuid_create_v4 + * @see php_uuid_create_v4() * @param[out] uuid to store the result. - * @return `SUCCESS` if the generation succeeded, `FAILURE` if it was not + * @return #SUCCESS() if the generation succeeded, #FAILURE() if it was not * possible to gather sufficient entropy. */ static zend_always_inline int php_uuid_create_v4_silent(php_uuid *uuid) @@ -448,11 +335,11 @@ static zend_always_inline int php_uuid_create_v4_silent(php_uuid *uuid) * Create version 4 UUID and throw PHP exception if it is not possible to * gather sufficient entropy. * - * @see php_uuid_create_v4 + * @see php_uuid_create_v4() * @param[out] uuid to store the result. - * @return `SUCCESS` if the generation succeeded, `FAILURE` if it was not + * @return #SUCCESS() if the generation succeeded, #FAILURE() if it was not * possible to gather sufficient entropy. - * @throws Exception if throw is enabled and it was not possible to gather + * @throws Exception if `throw` is enabled and it was not possible to gather * sufficient entropy for generating random bytes. */ static zend_always_inline int php_uuid_create_v4_throw(php_uuid *uuid) @@ -463,27 +350,29 @@ static zend_always_inline int php_uuid_create_v4_throw(php_uuid *uuid) /** * Create version 5 UUID. * - * Version 5 UUIDs are generated by MD5 hashing the concatenated namespace's - * byte representation and the given name. The namespace itself must be - * another UUID. This can be any UUID, or one of the predefined ones: + * Version 5 UUIDs are generated by [SHA-1](https://en.wikipedia.org/wiki/SHA-1) + * hashing the concatenated namespace's byte representation and the given name. + * The namespace itself must be another UUID. This can be any UUID, or one of + * the predefined ones: * - * - {@see php_uuid_namespace_dns} - * - {@see php_uuid_namespace_oid} - * - {@see php_uuid_namespace_url} - * - {@see php_uuid_namespace_x500} + * - php_uuid_namespace_dns() + * - php_uuid_namespace_oid() + * - php_uuid_namespace_url() + * - php_uuid_namespace_x500() * * A particular name within the same namespace always results in the same - * version 5 UUID, across all RFC 4122 compliant UUID implementations. + * version 5 UUID, across all [RFC 4122] compliant UUID implementations. * However, the namespace and name cannot be determined from the UUID alone. * - * ## Examples - * ``` + * ### Examples + * + * ```c * const php_uuid nsid = php_uuid_namespace_dns(); * php_uuid uuid; * * php_uuid_create_v5(&uuid, &nsid, "php.net", sizeof("php.net") - 1); * - * assert(php_uuid_is_nil(uuid) == FALSE); + * assert(php_uuid_is_nil(uuid) == 0); * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_5_NAME_BASED_SHA1); * @@ -496,8 +385,9 @@ static zend_always_inline int php_uuid_create_v4_throw(php_uuid *uuid) * assert(memcmp(&tmp, &uuid, PHP_UUID_LEN) == 0); * ``` * - * @see https://tools.ietf.org/html/rfc4122#section-4.3 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 + * [RFC 4122]: https://tools.ietf.org/html/rfc4122 + * @see [RFC 4122: Section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3) + * @see [Wikipedia: Universally unique identifier (Versions 3 and 5)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29) * @param[out] uuid to store the result in. * @param[in] namespace to create the UUID in. * @param[in] name to create the UUID from. @@ -509,11 +399,11 @@ PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const * Get the variant associated with this UUID. * * The variant specifies the internal data layout of a UUID. This - * implementation generates {@see UUID::VARIANT_RFC4122} UUIDs only, - * however, parsing and construction of other variants is supported. + * implementation generates #PHP_UUID_VARIANT_RFC4122 UUIDs only, however, + * parsing and construction of other variants is supported. * - * @see http://tools.ietf.org/html/rfc4122#section-4.1.1 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Variants + * @see [RFC 4122: Section 4.1.1](http://tools.ietf.org/html/rfc4122#section-4.1.1) + * @see [Wikipedia: Universally unique identifier (Variants)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Variants) * @see PHP_UUID_VARIANT_NCS * @see PHP_UUID_VARIANT_RFC4122 * @see PHP_UUID_VARIANT_MICROSOFT @@ -534,12 +424,12 @@ static const zend_always_inline php_uuid_variant php_uuid_get_variant(const php_ * * The version specifies which algorithm was used to generate the UUID. Note * that the version might not be meaningful if another variant than the - * {@see PHP_UUID_VARIANT_RFC4122} was used to generate the UUID. This - * implementation generates {@see PHP_UUID_VARIANT_RFC4122} UUIDs only, but - * allows parsing and construction of other variants. + * #PHP_UUID_VARIANT_RFC4122 was used to generate the UUID. This implementation + * generates #PHP_UUID_VARIANT_RFC4122 UUIDs only, but allows parsing and + * construction of other variants. * - * @see http://tools.ietf.org/html/rfc4122#section-4.1.3 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions + * @see [RFC 4122: Section 4.1.3](http://tools.ietf.org/html/rfc4122#section-4.1.3) + * @see [Wikipedia: Universally unique identifier (Versions)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions) * @see PHP_UUID_VERSION_1_TIME_BASED * @see PHP_UUID_VERSION_2_DCE_SECURITY * @see PHP_UUID_VERSION_3_NAME_BASED_MD5 @@ -547,22 +437,79 @@ static const zend_always_inline php_uuid_variant php_uuid_get_variant(const php_ * @see PHP_UUID_VERSION_5_NAME_BASED_SHA1 * @param[in] uuid to get the version from. * @return The version of the given UUID, which is an integer in [0, 15], the - * values [1, 5] correspond to one of the `PHP_UUID_VERSION_*` constants. - * The others are not defined in RFC 4122. + * values [1, 5] correspond to one of the version constants. The others are + * not defined in RFC 4122. */ static const zend_always_inline uint8_t php_uuid_get_version(const php_uuid *uuid) { return uuid->bytes[6] >> 4; } +/** + * Domain Name System (DNS) namespace UUID. + * + * @see [RFC 4122: Appendix C](https://tools.ietf.org/html/rfc4122#appendix-C) + * @see [Wikipedia: Domain Name System](https://en.wikipedia.org/wiki/Domain_Name_System) + */ +static const zend_always_inline php_uuid php_uuid_namespace_dns() +{ + return (php_uuid) { "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; +} + +/** +* Object Identifier (OID) namespace UUID. +* + * @see [RFC 4122: Appendix C](https://tools.ietf.org/html/rfc4122#appendix-C) + * @see [Wikipedia: Object identifier](https://en.wikipedia.org/wiki/Object_identifier) + */ +static const zend_always_inline php_uuid php_uuid_namespace_oid() +{ + return (php_uuid) { "\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; +} + +/** + * Uniform Resource Locator (URL) namespace UUID. + * + * @see [RFC 4122: Appendix C](https://tools.ietf.org/html/rfc4122#appendix-C) + * @see [Wikipedia: URL](https://en.wikipedia.org/wiki/URL) + */ +static const zend_always_inline php_uuid php_uuid_namespace_url() +{ + return (php_uuid) { "\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; +} + +/** + * X.500 Distinguished Names (X.500 DN) namespace UUID. The names that are to + * be hashed in this namespace can be in DER or a text output format. + * + * @see [RFC 4122: Appendix C](https://tools.ietf.org/html/rfc4122#appendix-C) + * @see [Wikipedia: X.500](https://en.wikipedia.org/wiki/X.500) + * @see [Wikipedia: Lightweight Directory Access Protocol](https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol) + */ +static const zend_always_inline php_uuid php_uuid_namespace_x500() +{ + return (php_uuid) { "\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; +} + +/** + * Special nil UUID that has all 128 bits set to zero. + * + * @see [RFC 4122: Section 4.1.7](https://tools.ietf.org/html/rfc4122#section-4.1.7) + * @see [Wikipedia: Universally unique identifier (Nil UUID)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID) + */ +static const zend_always_inline php_uuid php_uuid_nil() +{ + return (php_uuid) { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }; +} + /** * Check if the given UUID is the special nil UUID that has all 128 bits set * to zero. * - * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID + * @see [RFC 4122: Section 4.1.7](https://tools.ietf.org/html/rfc4122#section-4.1.7) + * @see [Wikipedia: Universally unique identifier (Nil UUID)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID) * @param[in] uuid to check. - * @return TRUE if the UUID contains the special nil UUID; FALSE otherwise. + * @return `1` if the UUID contains the special nil UUID; `0` otherwise. */ static const zend_always_inline int php_uuid_is_nil(const php_uuid *uuid) { @@ -571,6 +518,86 @@ static const zend_always_inline int php_uuid_is_nil(const php_uuid *uuid) return memcmp(uuid->bytes, &nil, PHP_UUID_LEN) == 0; } +/** + * Parse the given string as UUID. + * + * The following UUID representations are parsable: + * + * - hexadecimal (`00000000111122223333444444444444`), + * - string (`00000000-1111-2222-3333-444444444444`), + * - URNs (`urn:uuid:00000000-1111-2222-3333-444444444444`), and + * - Microsoft (`{00000000-1111-2222-3333-444444444444}`). + * + * Leading and trailing whitespace, namely spaces (` `) and tabs (`\t`), is + * ignored, so are leading opening braces (`{`) and trailing closing braces + * (`}`). Hyphens (`-`) are ignored everywhere. The parsing algorithm + * follows the [robustness + * principle](https://en.wikipedia.org/wiki/Robustness_principle) and is + * not meant for validation. + * + * ### Examples + * + * ```c + * php_uuid uuid; + * + * // Parsing of canonical representations. + * php_uuid_parse_silent(&uuid, "0123456789abcdef0123456789abcdef", sizeof("0123456789abcdef0123456789abcdef") - 1); + * php_uuid_parse_silent(&uuid, "01234567-89ab-cdef-0123-456789abcdef", sizeof("01234567-89ab-cdef-0123-456789abcdef") - 1); + * php_uuid_parse_silent(&uuid, "urn:uuid:01234567-89ab-cdef-0123-456789abcdef", sizeof("urn:uuid:01234567-89ab-cdef-0123-456789abcdef") - 1); + * php_uuid_parse_silent(&uuid, "{01234567-89ab-cdef-0123-456789abcdef}", sizeof("{01234567-89ab-cdef-0123-456789abcdef}") - 1); + * + * // Leading and trailing garbage is ignored, so are extraneous hyphens. + * php_uuid_parse_silent(&uuid, " \t ---- { urn:uuid:----0123-4567-89ab-cdef-0123-4567-89ab-cdef---- } ---- \t ", sizeof(" \t ---- { urn:uuid:----0123-4567-89ab-cdef-0123-4567-89ab-cdef---- } ---- \t ") - 1); + * + * // However, note that there cannot be whitespace or braces between the URN + * // scheme and the UUID itself. + * assert(php_uuid_parse_silent( + * &uuid, + * "urn:uuid:{01234567-89ab-cdef-0123-456789abcdef", + * sizeof("urn:uuid:{01234567-89ab-cdef-0123-456789abcdef") - 1 + * ) == FAILURE); + * ``` + * + * @see php_uuid_parse_silent + * @see php_uuid_parse_throw + * @param[out] uuid to store the result in. + * @param[in] input to parse as UUID. + * @param[in] input_len + * @param[in] throw whether to throw PHP exceptions (`1`), or not (`0`). + * @return #SUCCESS() if the string was parsed as UUID; #FAILURE() otherwise. + * @throws UUIDParseException if `throw` is enabled and parsing fails. + */ +PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_len, const zend_bool throw); + +/** + * Silently parse the string as UUID. + * + * @see php_uuid_parse + * @param[out] uuid to store the result in. + * @param[in] input to parse as UUID. + * @param[in] input_len + * @return #SUCCESS() if the string was parsed as UUID; #FAILURE() otherwise. + */ +static zend_always_inline int php_uuid_parse_silent(php_uuid *uuid, const char *input, const size_t input_len) +{ + return php_uuid_parse(uuid, input, input_len, 0); +} + +/** + * Parse the string as UUID and throw PHP exceptions on failures. + * + * @see php_uuid_parse + * @param[out] uuid to store the result in. + * @param[in] input to parse as UUID. + * @param[in] input_len + * @return #SUCCESS() if the string was parsed as UUID; #FAILURE() otherwise. + * @throws UUIDParseException if parsing fails. + */ +static zend_always_inline int php_uuid_parse_throw(php_uuid *uuid, const char *input, const size_t input_len) +{ + return php_uuid_parse(uuid, input, input_len, 1); +} + /** * Convert the UUID to its hexadecimal representation. * @@ -578,8 +605,9 @@ static const zend_always_inline int php_uuid_is_nil(const php_uuid *uuid) * hexadecimal digits `a` through `f` are always formatted as lower case * characters, in accordance with RFC 4122. * - * ## Examples - * ``` + * ### Examples + * + * ```c * const php_uuid nsid = php_uuid_namespace_dns(); * php_uuid_hex hex; * @@ -611,8 +639,9 @@ static zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_u * hexadecimal digits `a` through `f` are always formatted as lower case * characters, in accordance with RFC 4122. * - * ## Examples - * ``` + * ### Examples + * + * ```c * const php_uuid nsid = php_uuid_namespace_dns(); * php_uuid_string str; * diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 3b7515ae51887..6414cffde668a 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -29,23 +29,56 @@ PHPAPI zend_class_entry *php_ce_UUID; PHPAPI zend_class_entry *php_ce_UUIDParseException; -static const uint8_t UUID_VERSION_MIN = 0; -static const uint8_t UUID_VERSION_MAX = 15; +/** Minimum legal UUID version value. */ +static const uint8_t UUID_VERSION_MIN = 0; -static const uint8_t UUID_HEX_LEN = sizeof(php_uuid_hex) - 1; -static const uint8_t UUID_STRING_LEN = sizeof(php_uuid_string) - 1; +/** Maximum legal UUID version value. */ +static const uint8_t UUID_VERSION_MAX = 15; -static const char UUID_BYTES_PROP[] = "bytes"; -static const uint8_t UUID_BYTES_PROP_LEN = sizeof(UUID_BYTES_PROP) - 1; +/** UUID hexadecimal representation length without terminating NUL. */ +static const uint8_t UUID_HEX_LEN = sizeof(php_uuid_hex) - 1; -static const char UUID_EX_INPUT_PROP[] = "input"; -static const uint8_t UUID_EX_INPUT_PROP_LEN = sizeof(UUID_EX_INPUT_PROP) - 1; +/** UUID string representation length without terminating NUL. */ +static const uint8_t UUID_STRING_LEN = sizeof(php_uuid_string) - 1; -static const char UUID_EX_POSITION_PROP[] = "position"; +/** + * Name of the private property of the `UUID` class where the binary + * representation of the UUID is stored in. + */ +static const char UUID_BYTES_PROP[] = "bytes"; + +/** Length of the `UUID::$bytes` property name without terminating NUL. */ +static const uint8_t UUID_BYTES_PROP_LEN = sizeof(UUID_BYTES_PROP) - 1; + +/** + * Name of the private property of the `UUIDParseException` class where the + * original input is stored in that should have been parsed, but failed. + */ +static const char UUID_EX_INPUT_PROP[] = "input"; + +/** + * Length of the `UUIDParseException::$input` property name without terminating + * NUL. + */ +static const uint8_t UUID_EX_INPUT_PROP_LEN = sizeof(UUID_EX_INPUT_PROP) - 1; + +/** + * Name of the private property of the `UUIDParseException` class where the + * position is stored at which the parsing of the UUID failed. + */ +static const char UUID_EX_POSITION_PROP[] = "position"; + +/** + * Length of the `UUIDParseException::$position` property name without + * terminating NUL. + */ static const uint8_t UUID_EX_POSITON_PROP_LEN = sizeof(UUID_EX_POSITION_PROP) - 1; -static const char URN_PREFIX[] = "urn:uuid:"; -static const uint8_t URN_PREFIX_LEN = sizeof(URN_PREFIX) - 1; +/** URN prefix of a UUID's string representation. */ +static const char URN_PREFIX[] = "urn:uuid:"; + +/** Length of the URN prefix of a UUID without terminating NUL. */ +static const uint8_t URN_PREFIX_LEN = sizeof(URN_PREFIX) - 1; /** * Set UUID variant to RFC 4122, the only supported variant. @@ -75,8 +108,48 @@ static zend_always_inline void php_uuid_set_version(php_uuid *uuid, const uint8_ uuid->bytes[6] = (uuid->bytes[6] & 0x0F) | (version << 4); } +PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) +{ + PHP_MD5_CTX context; + unsigned char digest[16]; + + PHP_MD5Init(&context); + PHP_MD5Update(&context, namespace->bytes, PHP_UUID_LEN); + PHP_MD5Update(&context, name, name_len); + PHP_MD5Final(digest, &context); + memcpy(uuid->bytes, digest, PHP_UUID_LEN); + set_variant_rfc4122(uuid); + php_uuid_set_version(uuid, PHP_UUID_VERSION_3_NAME_BASED_MD5); +} + +PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw) +{ + int result = php_random_bytes(uuid, PHP_UUID_LEN, throw); + + if (result == SUCCESS) { + set_variant_rfc4122(uuid); + php_uuid_set_version(uuid, PHP_UUID_VERSION_4_RANDOM); + } + + return result; +} + +PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) +{ + PHP_SHA1_CTX context; + unsigned char digest[20]; + + PHP_SHA1Init(&context); + PHP_SHA1Update(&context, (const unsigned char *) namespace->bytes, PHP_UUID_LEN); + PHP_SHA1Update(&context, (const unsigned char *)name, name_len); + PHP_SHA1Final(digest, &context); + memcpy(uuid->bytes, digest, PHP_UUID_LEN); + set_variant_rfc4122(uuid); + php_uuid_set_version(uuid, PHP_UUID_VERSION_5_NAME_BASED_SHA1); +} + /** - * Throw UUIDParseException. + * Throw `UUIDParseException`. * * @param[in] input that could not be parsed. * @param[in] input_len @@ -105,7 +178,7 @@ static ZEND_COLD zend_object *throw_uuid_parse_exception(const char *input, cons } /** - * Throw UUIDParseException because of insufficient input. + * Throw `UUIDParseException` because of insufficient input. * * @param[in] input that could not be parsed. * @param[in] input_len @@ -125,7 +198,7 @@ static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_len(co } /** - * Throw UUIDParseException because of an invalid character. + * Throw `UUIDParseException` because of an invalid character. * * @param[in] input that could not be parsed. * @param[in] input_len @@ -246,56 +319,18 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ return SUCCESS; } -PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) -{ - PHP_MD5_CTX context; - unsigned char digest[16]; - - PHP_MD5Init(&context); - PHP_MD5Update(&context, namespace->bytes, PHP_UUID_LEN); - PHP_MD5Update(&context, name, name_len); - PHP_MD5Final(digest, &context); - memcpy(uuid->bytes, digest, PHP_UUID_LEN); - set_variant_rfc4122(uuid); - php_uuid_set_version(uuid, PHP_UUID_VERSION_3_NAME_BASED_MD5); -} - -PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw) -{ - int result = php_random_bytes(uuid, PHP_UUID_LEN, throw); - - if (result == SUCCESS) { - set_variant_rfc4122(uuid); - php_uuid_set_version(uuid, PHP_UUID_VERSION_4_RANDOM); - } - - return result; -} - -PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len) -{ - PHP_SHA1_CTX context; - unsigned char digest[20]; - - PHP_SHA1Init(&context); - PHP_SHA1Update(&context, (const unsigned char *) namespace->bytes, PHP_UUID_LEN); - PHP_SHA1Update(&context, (const unsigned char *) name, name_len); - PHP_SHA1Final(digest, &context); - memcpy(uuid->bytes, digest, PHP_UUID_LEN); - set_variant_rfc4122(uuid); - php_uuid_set_version(uuid, PHP_UUID_VERSION_5_NAME_BASED_SHA1); -} - /** * Get the UUID from the given UUID object. * + * @attention * We are required to check the type and length of the encapsulated value upon * every access because users can change the value through various ways (e.g. * reflection, closures, ...) and there is nothing that prevents them from * doing so. * * @param[in] uuid_object to get the UUID from. - * @return SUCCESS if the UUID could be read from the object, FAILURE otherwise. + * @return #SUCCESS() if the UUID could be read from the object; #FAILURE() + * otherwise. * @throws TypeError if the value is not of type string. * @throws Error if the string value is not exactly 16 bytes long. */ @@ -342,16 +377,15 @@ static zend_always_inline void new_uuid(zval *object, const php_uuid *uuid) zend_update_property_stringl(php_ce_UUID, object, UUID_BYTES_PROP, UUID_BYTES_PROP_LEN, (const char *) uuid->bytes, PHP_UUID_LEN); } -/* private function __construct() {{{ */ +/** `private function UUID::__construct()` */ PHP_METHOD(UUID, __construct) { /* NOOP */ } ZEND_BEGIN_ARG_INFO(UUID___construct_args, NULL) ZEND_END_ARG_INFO() -/* }}} */ -/* public static function fromBinary(string $input): self {{{ */ +/** `public static function UUID::fromBinary(string $input): self` */ PHP_METHOD(UUID, fromBinary) { zval *input = NULL; @@ -377,9 +411,8 @@ PHP_METHOD(UUID, fromBinary) ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_fromBinary_args, 0, 1, self, 0) ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) ZEND_END_ARG_INFO() -/* }}} */ -/* public static function parse(string $input): self {{{ */ +/** `public static function UUID::parse(string $input): self` */ PHP_METHOD(UUID, parse) { zval *input = NULL; @@ -398,9 +431,8 @@ PHP_METHOD(UUID, parse) ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, self, 0) ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) ZEND_END_ARG_INFO() -/* }}} */ -/* public static function v3(self $namespace, string $name): self {{{ */ +/** `public static function UUID::v3(self $namespace, string $name): self` */ PHP_METHOD(UUID, v3) { zval *namespace = NULL; @@ -424,9 +456,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, self, 0) ZEND_ARG_OBJ_INFO(0, namespace, self, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_END_ARG_INFO() -/* }}} */ -/* public static function v4(): self {{{ */ +/** `public static function UUID::v4(): self` */ PHP_METHOD(UUID, v4) { php_uuid uuid; @@ -443,9 +474,8 @@ PHP_METHOD(UUID, v4) } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_v4_args, self, 0) ZEND_END_ARG_INFO() -/* }}} */ -/* public static function v5(self $namespace, string $name): self {{{ */ +/** `public static function UUID::v5(self $namespace, string $name): self` */ PHP_METHOD(UUID, v5) { zval *namespace = NULL; @@ -466,43 +496,52 @@ PHP_METHOD(UUID, v5) new_uuid(return_value, &uuid); } ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v5_args, 0, 2, self, 0) - ZEND_ARG_OBJ_INFO(0, namespace, self, 0) - ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) +ZEND_ARG_OBJ_INFO(0, namespace, self, 0) +ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_END_ARG_INFO() -/* }}} */ - -/* public static function ##method_name##(): self {{{ */ -#define PHP_UUID_NAMED_CONSTRUCTOR(method_name, name) \ - PHP_METHOD(UUID, method_name) \ - { \ - const php_uuid name = php_uuid_##name(); \ - \ - if (zend_parse_parameters_none_throw() == FAILURE) { \ - return; \ - } \ - \ - new_uuid(return_value, &name); \ - } \ - ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_##method_name##_args, self, 0) \ - ZEND_END_ARG_INFO() + +/** + * Macro for consistent creation of named UUID class constructors from C + * functions. The output of the macro is as follows: + * + * ```php + * final class UUID { + * public static function php_method_name(): self {} + * } + * ``` + * + * @param[in] php_method_name + * @param[in] c_function_name without the `php_uuid_` prefix. + */ +#define PHP_UUID_NAMED_CONSTRUCTOR(php_method_name, c_function_name) \ + PHP_METHOD(UUID, php_method_name) \ + { \ + const php_uuid c_function_name = php_uuid_##c_function_name(); \ + \ + if (zend_parse_parameters_none_throw() == FAILURE) { \ + return; \ + } \ + \ + new_uuid(return_value, &c_function_name); \ + } \ + ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_##php_method_name##_args, self, 0) \ + ZEND_END_ARG_INFO(); PHP_UUID_NAMED_CONSTRUCTOR(NamespaceDNS, namespace_dns) PHP_UUID_NAMED_CONSTRUCTOR(NamespaceOID, namespace_oid) PHP_UUID_NAMED_CONSTRUCTOR(NamespaceURL, namespace_url) PHP_UUID_NAMED_CONSTRUCTOR(NamespaceX500, namespace_x500) PHP_UUID_NAMED_CONSTRUCTOR(Nil, nil) -/* }}} */ -/* private function __clone() {{{ */ +/** `private function UUID::__clone()` */ PHP_METHOD(UUID, __clone) { zend_throw_error(zend_ce_error, "Cannot clone immutable %s object", ZSTR_VAL(php_ce_UUID->name)); } ZEND_BEGIN_ARG_INFO(UUID___clone_args, NULL) ZEND_END_ARG_INFO() -/* }}} */ -/* public function __set($_, $__): void {{{ */ +/** `public function UUID::__set($_, $__): void` */ PHP_METHOD(UUID, __set) { zend_throw_error(zend_ce_error, "Cannot set dynamic properties on immutable %s object", ZSTR_VAL(php_ce_UUID->name)); @@ -511,9 +550,8 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___set_args, IS_VOID, 0) ZEND_ARG_INFO(0, _) ZEND_ARG_INFO(0, __) ZEND_END_ARG_INFO() -/* }}} */ -/* public function __wakeup(): void {{{ */ +/** `public function UUID::__wakeup(): void` */ PHP_METHOD(UUID, __wakeup) { zval *bytes = zend_read_property(php_ce_UUID, &EX(This), UUID_BYTES_PROP, UUID_BYTES_PROP_LEN, 1, NULL); @@ -550,14 +588,18 @@ PHP_METHOD(UUID, __wakeup) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___wakeup_args, IS_VOID, 0) ZEND_END_ARG_INFO() -/* }}} */ +/** + * Macro for consistent checking that there were no parameters passed to the + * PHP method, and to fetch the content of the private property that contains + * the byte representation of the UUID into a local variable called `uuid`. + */ #define PHP_UUID_ACCESSOR \ - php_uuid *uuid = NULL; \ + const php_uuid *uuid = NULL; \ if (zend_parse_parameters_none_throw() == FAILURE) return; \ if ((uuid = get_uuid(&EX(This))) == NULL) return; -/* public function getVaraitn(): int {{{ */ +/** `public function UUID::getVariant(): int` */ PHP_METHOD(UUID, getVariant) { PHP_UUID_ACCESSOR; @@ -565,9 +607,8 @@ PHP_METHOD(UUID, getVariant) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) ZEND_END_ARG_INFO() -/* }}} */ -/* public function getVersion(): int {{{ */ +/** `public function UUID::getVersion(): int` */ PHP_METHOD(UUID, getVersion) { PHP_UUID_ACCESSOR; @@ -575,9 +616,8 @@ PHP_METHOD(UUID, getVersion) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) ZEND_END_ARG_INFO() -/* }}} */ -/* public function isNil(): bool {{{ */ +/** `public function UUID::isNil(): bool` */ PHP_METHOD(UUID, isNil) { PHP_UUID_ACCESSOR; @@ -585,9 +625,8 @@ PHP_METHOD(UUID, isNil) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) ZEND_END_ARG_INFO() -/* }}} */ -/* public function toBinary(): string {{{ */ +/** `public function UUID::toBinary(): string` */ PHP_METHOD(UUID, toBinary) { PHP_UUID_ACCESSOR; @@ -595,9 +634,8 @@ PHP_METHOD(UUID, toBinary) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) ZEND_END_ARG_INFO() -/* }}} */ -/* public function toHex(): string {{{ */ +/** `public function UUID::toHex(): string` */ PHP_METHOD(UUID, toHex) { php_uuid_hex buffer; @@ -607,9 +645,8 @@ PHP_METHOD(UUID, toHex) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toHex_args, IS_STRING, 0) ZEND_END_ARG_INFO() -/* }}} */ -/* public function toString(): string {{{ */ +/** `public function UUID::toString(): string` */ PHP_METHOD(UUID, toString) { php_uuid_string buffer; @@ -619,7 +656,6 @@ PHP_METHOD(UUID, toString) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toString_args, IS_STRING, 0) ZEND_END_ARG_INFO() -/* }}} */ static const zend_function_entry uuid_methods[] = { PHP_ME(UUID, __construct, UUID___construct_args, ZEND_ACC_PRIVATE) @@ -645,7 +681,7 @@ static const zend_function_entry uuid_methods[] = { PHP_FE_END }; -/* public function __construct(string $reason, string $input, int $position = 0, ?Throwable $previous = null) {{{ */ +/** `public function UUIDParseException::__construct(string $reason, string $input, int $position = 0, ?Throwable $previous = null)` */ PHP_METHOD(UUIDParseException, __construct) { zval *reason = NULL; @@ -677,9 +713,8 @@ ZEND_BEGIN_ARG_INFO_EX(UUIDParseException___construct_args, NULL, 0, 2) ZEND_ARG_TYPE_INFO(0, position, IS_LONG, 0) ZEND_ARG_OBJ_INFO(0, previous, Throwable, 1) ZEND_END_ARG_INFO() -/* }}} */ -/* public function getInput(): string {{{ */ +/** `public function UUIDParseException::getInput(): string` */ PHP_METHOD(UUIDParseException, getInput) { if (zend_parse_parameters_none_throw() == FAILURE) { @@ -697,9 +732,8 @@ PHP_METHOD(UUIDParseException, getInput) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getInput_args, IS_STRING, 0) ZEND_END_ARG_INFO() -/* }}} */ -/* public function getPosition(): int {{{ */ +/** `public function UUIDParseException::getPosition(): int` */ PHP_METHOD(UUIDParseException, getPosition) { if (zend_parse_parameters_none_throw() == FAILURE) { @@ -717,7 +751,6 @@ PHP_METHOD(UUIDParseException, getPosition) } ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getPosition_args, IS_LONG, 0) ZEND_END_ARG_INFO() -/* }}} */ static const zend_function_entry uuid_parse_exception_methods[] = { PHP_ME(UUIDParseException, __construct, UUIDParseException___construct_args, ZEND_ACC_PUBLIC) From e3ea162f7d2023055e620bb0439a015e1a02e98c Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Sat, 1 Jul 2017 20:02:05 +0200 Subject: [PATCH 53/54] Removed Comments from C Files --- ext/standard/php_uuid.h | 529 +--------------------------------------- ext/standard/uuid.c | 130 ---------- 2 files changed, 7 insertions(+), 652 deletions(-) diff --git a/ext/standard/php_uuid.h b/ext/standard/php_uuid.h index 7e07609882a9c..9d44e7c6aaf7a 100644 --- a/ext/standard/php_uuid.h +++ b/ext/standard/php_uuid.h @@ -18,399 +18,61 @@ /* $Id$ */ -/** @file ext/standard/php_uuid.h - * - * Generate and parse RFC 4122/DCE 1.1 Universally Unique Identifiers (UUIDs). - * - * This standard submodule provides generation and parsing capabilities for - * Universally Unique Identifiers (UUIDs, also known as Globally Unique - * Identifiers [GUIDs]) as specified in [RFC 4122]. - * - * UUIDs are 128 bit integers that guarantee uniqueness across space and time. - * They are mainly used to assign identifiers to entities without requiring a - * central authority. They are thus particularly useful in distributed systems. - * They also allow very high allocation rates; up to 10 million per second per - * machine, if necessary. - * - * There are different types of UUIDs, known as variants. This implementation - * generates UUIDs according to the Leach-Salz variant; the one specified in - * [RFC 4122] as variant 1. Textual parsing supports both variant 1 ([RFC 4122]) - * and variant 2 (Microsoft), and construction supports any kind of UUID. - * However, note that the provided functions are **not** guaranteed to provide - * meaningful results if any other variants than the Leach-Salz one is used. - * - * There are also different UUID generation algorithms, known as versions. This - * implementation provides functions to generate version 3, 4, and 5 UUIDs. - * - * Versions 3 and 5 are meant for generating UUIDs from "names" that are drawn - * from, and unique within, some "namespace". They generate the same UUID for - * the same name in the same namespace across all [RFC 4122] compliant - * implementations. - * - * Version 4 UUIDs are random and result in a new UUID upon every generation. - * The randomness is provided by PHP's random bytes implementation, and thus - * uses the best available random source of the operating system. - * - * Versions 1 and 2 are not supported due to privacy/security concerns. Refer - * to the [Wikipedia] article for more information. - * - * This implementation is inspired by many other implementations: - * - [RFC 4122 Sample Implementation](https://tools.ietf.org/html/rfc4122#appendix-A) - * - [Rust UUID](https://github.com/rust-lang-nursery/uuid) - * - [util-linux LibUUID](https://github.com/karelzak/util-linux) - * - [boost Uuid](http://www.boost.org/doc/libs/1_64_0/libs/uuid/) - * - [D std.uuid](https://dlang.org/library/std/uuid.html) - * - * ### Examples - * - * ```c - * php_uuid uuid; - * - * // A random UUID with more randomness than the version 4 implementation. - * // Do NOT be used in real-world applications! - * php_random_bytes_silent(&uuid, PHP_UUID_LEN); - * - * // Set version to future reserved, because we are using a custom UUID. - * // Once more, do NOT use this in real-world applications! - * uuid.bytes = (uuid.bytes[8] & 0x1F) | 0xE0; - * - * php_uuid_create_v3(&uuid, php_uuid_namespace_dns(), "php.net", sizeof("php.net") - 1); - * assert(php_uuid_is_nil(uuid) == FALSE); - * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); - * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_3_NAME_BASED_MD5); - * - * php_uuid_create_v4_silent(&uuid); - * assert(php_uuid_is_nil(uuid) == FALSE); - * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); - * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_4_RANDOM); - * - * php_uuid_create_v5(&uuid, php_uuid_namespace_dns(), "php.net", sizeof("php.net") - 1); - * assert(php_uuid_is_nil(uuid) == FALSE); - * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); - * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_5_NAME_BASED_SHA1); - * - * php_uuid_parse_silent(&uuid, "urn:uuid:123E4567-E89B-12D3-A456-426655440000", sizeof("urn:uuid:123E4567-E89b-12D3-A456-426655440000") - 1); - * assert(php_uuid_is_nil(uuid) == FALSE); - * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); - * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_1_TIME_BASED); - * - * assert(memcmp(&uuid, "\x12\x3E\x45\x67\xE8\x9B\x12\xD3\xA4\x56\x42\x66\x55\x44\x00\x00", PHP_UUID_LEN) == 0); - * - * php_uuid_hex hex; - * php_uuid_to_hex(&hex, uuid); - * assert(memcmp(&hex, "123e4567e89b12d3a456426655440000", PHP_UUID_HEX_LEN) == 0); - * - * php_uuid_string str; - * php_uuid_to_string(&str, uuid); - * assert(memcmp(&str, "123e4567-e89b-12d3-a456-426655440000", PHP_UUID_STRING_LEN) == 0); - * ``` - * - * @author [Richard Fussenegger](mailto:php@fleshgrinder.com) - * @see [Wikipedia: Universally unique identifier][Wikipedia] - * @see [RFC 4122] - * - * [RFC 4122]: https://tools.ietf.org/html/rfc4122 - * [Wikipedia]: https://en.wikipedia.org/wiki/Universally_unique_identifier - */ - #ifndef PHP_UUID_H #define PHP_UUID_H #include "zend_types.h" #include "php.h" -/** `UUID` class entry for usage by other modules. */ PHPAPI extern zend_class_entry *php_ce_UUID; - -/** `UUIDParseException` class entry for usage by other modules. */ PHPAPI extern zend_class_entry *php_ce_UUIDParseException; -/** UUID binary representation length without terminating NUL. */ #define PHP_UUID_LEN 16 - -/** UUID binary representation to store the 128 bit number in 16 bytes. */ typedef struct php_uuid { uint8_t bytes[PHP_UUID_LEN]; } php_uuid; -/** UUID hexadecimal representation length with terminating NUL. */ #define PHP_UUID_HEX_LEN 33 - -/** UUID hexadecimal representation: `000000001111222233334444444444444444\0` */ typedef struct php_uuid_hex { char str[PHP_UUID_HEX_LEN]; } php_uuid_hex; -/** UUID string representation length with terminating NUL. */ #define PHP_UUID_STRING_LEN 37 - -/** UUID string representation: `00000000-1111-2222-3333-4444444444444444\0` */ typedef struct php_uuid_string { char str[PHP_UUID_STRING_LEN]; } php_uuid_string; -/** - * UUID variants as defined in [RFC 4122](https://tools.ietf.org/html/rfc4122#section-4.1.1). - */ typedef enum php_uuid_variant { - /** Reserved, NCS backward compatibility: `0b0xx` */ - PHP_UUID_VARIANT_NCS = 0, - - /** The variant of this implementation and specified in RFC 4122: `0b10x` */ - PHP_UUID_VARIANT_RFC4122 = 1, - - /** Reserved, Microsoft Corporation backward compatibility: `0b110` */ - PHP_UUID_VARIANT_MICROSOFT = 2, - - /** Reserved for future definition: `0b111` */ + PHP_UUID_VARIANT_NCS = 0, + PHP_UUID_VARIANT_RFC4122 = 1, + PHP_UUID_VARIANT_MICROSOFT = 2, PHP_UUID_VARIANT_FUTURE_RESERVED = 3, } php_uuid_variant; -/** - * Version code for date-time and IEEE 802 MAC address UUIDs. - * - * @warning - * Generation of this version is not supported by this implementation due - * to security concerns. Version 4 UUIDs are a good replacement for version - * 1 UUIDs without the privacy/security concerns (see [Wikipedia]). - * - * @see [RFC 4122: Section 4.2](https://tools.ietf.org/html/rfc4122#section-4.2) - * @see [Wikipedia: Universally unique identifier (Version 1)][Wikipedia] - * [Wikipedia]: https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_.28date-time_and_MAC_address.29 - */ -static const uint8_t PHP_UUID_VERSION_1_TIME_BASED = 1; - -/** - * Version code for date-time and IEEE 802 MAC address UUIDs (DCE security - * algorithm). - * - * @warning - * Generation of this version is not supported by this implementation due - * to security concerns, and uniqueness limitations for applications with - * high allocations. Version 4 UUIDs are a good replacement for version 2 - * UUIDs without the privacy/security concerns (see [Wikipedia]), and they - * support high allocations. - * - * @see [RFC 4122: Section 4.2](https://tools.ietf.org/html/rfc4122#section-4.2) - * @see [Wikipedia: Universally unique identifier (Version 2)][Wikipedia] - * [Wikipedia]: https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_2_.28date-time_and_MAC_Address.2C_DCE_security_version.29 - */ -static const uint8_t PHP_UUID_VERSION_2_DCE_SECURITY = 2; - -/** - * Version code for namespace/name-based MD5 hashed UUIDs. - * - * @see php_uuid_create_v3() - * @see [RFC 4122: Section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3) - * @see [Wikipedia: Universally unique identifiers (versions 3 and 5)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29) - */ -static const uint8_t PHP_UUID_VERSION_3_NAME_BASED_MD5 = 3; - -/** - * Version code for random UUIDs. - * - * @see php_uuid_create_v4() - * @see [RFC 4122: Section 4.4](https://tools.ietf.org/html/rfc4122#section-4.4) - * @see [Wikipedia: Universally unique identifiers (version 4)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29) - */ -static const uint8_t PHP_UUID_VERSION_4_RANDOM = 4; - -/** - * Version code for namespace/name-based SHA1 hashed UUIDs. - * - * @see php_uuid_create_v5() - * @see [RFC 4122: Section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3) - * @see [Wikipedia: Universally unique identifiers (versions 3 and 5)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29) - */ +static const uint8_t PHP_UUID_VERSION_1_TIME_BASED = 1; +static const uint8_t PHP_UUID_VERSION_2_DCE_SECURITY = 2; +static const uint8_t PHP_UUID_VERSION_3_NAME_BASED_MD5 = 3; +static const uint8_t PHP_UUID_VERSION_4_RANDOM = 4; static const uint8_t PHP_UUID_VERSION_5_NAME_BASED_SHA1 = 5; BEGIN_EXTERN_C() -/** - * Create version 3 UUID. - * - * @warning - * [RFC 4122] recommends [v5](@ref php_uuid_create_v5()) over this one and - * states that version 3 UUIDs should be used if backwards compatibility is - * required only. This is because MD5 has a higher collision probability - * compared to SHA1, which is used by version 5; regardless of the truncation! - * - * Version 3 UUIDs are generated by [MD5](https://en.wikipedia.org/wiki/MD5) - * hashing the concatenated namespace's byte representation and the given name. - * The namespace itself must be another UUID. This can be any UUID, or one of - * the predefined ones: - * - * - php_uuid_namespace_dns() - * - php_uuid_namespace_oid() - * - php_uuid_namespace_url() - * - php_uuid_namespace_x500() - * - * A particular name within the same namespace always results in the same - * version 3 UUID, across all [RFC 4122] compliant UUID implementations. - * However, the namespace and name cannot be determined from the UUID alone. - * - * ### Examples - * - * ```c - * const php_uuid nsid = php_uuid_namespace_dns(); - * php_uuid uuid; - * - * php_uuid_create_v3(&uuid, &nsid, "php.net", sizeof("php.net") - 1); - * - * assert(php_uuid_is_nil(uuid) == 0); - * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); - * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_3_NAME_BASED_MD5); - * - * php_uuid_string str; - * php_uuid_to_string(&str, uuid); - * assert(memcmp(&str, "11a38b9a-b3da-360f-9353-a5a725514269", PHP_UUID_STRING_LEN) == 0); - * - * php_uuid tmp; - * php_uuid_create_v3(&tmp, &nsid, "php.net", sizeof("php.net") - 1); - * assert(memcmp(&tmp, &uuid, PHP_UUID_LEN) == 0); - * ``` - * - * [RFC 4122]: https://tools.ietf.org/html/rfc4122 - * @see [RFC 4122: Section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3) - * @see [Wikipedia: Universally unique identifier (Versions 3 and 5)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29) - * @param[out] uuid to store the result in. - * @param[in] namespace to create the UUID in. - * @param[in] name to create the UUID from. - * @param[in] name_len - */ PHPAPI void php_uuid_create_v3(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len); -/** - * Create version 4 UUID. - * - * Version 4 UUIDs are randomly generated from the best available random source. - * The selection of that source is determined by PHP's random implementation. - * Some systems may be bad at generating sufficient entropy, e.g. virtual - * machines. This might lead to collisions faster than desired. If this is the - * case, the php_uuid_create_v5() implementation should be used. - * - * ### Examples - * - * ```c - * php_uuid uuid; - * - * php_uuid_create_v4_silent(&uuid); - * - * assert(php_uuid_is_nil(uuid) == 0); - * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); - * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_4_RANDOM); - * - * php_uuid tmp; - * php_uuid_create_v4_silent(&uuid); - * assert(memcmp(&tmp, &uuid, PHP_UUID_LEN) == 0); - * ``` - * - * @see [RFC 4122: Section 4.4](https://tools.ietf.org/html/rfc4122#section-4.4) - * @see [Wikipedia: Universally unique identifier (Version 4)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29) - * @see php_uuid_create_v4_silent() - * @see php_uuid_create_v4_throw() - * @param[out] uuid to store the result. - * @param[in] throw whether to throw a PHP exception (`1`), or not (`0`). - * @return #SUCCESS() if the generation succeeded, #FAILURE() if it was not - * possible to gather sufficient entropy. - * @throws Exception if `throw` is set to true and it was not possible to gather - * sufficient entropy for generating random bytes. - */ PHPAPI int php_uuid_create_v4(php_uuid *uuid, const zend_bool throw); -/** - * Silently create version 4 UUID. - * - * @see php_uuid_create_v4() - * @param[out] uuid to store the result. - * @return #SUCCESS() if the generation succeeded, #FAILURE() if it was not - * possible to gather sufficient entropy. - */ static zend_always_inline int php_uuid_create_v4_silent(php_uuid *uuid) { return php_uuid_create_v4(uuid, 0); } -/** - * Create version 4 UUID and throw PHP exception if it is not possible to - * gather sufficient entropy. - * - * @see php_uuid_create_v4() - * @param[out] uuid to store the result. - * @return #SUCCESS() if the generation succeeded, #FAILURE() if it was not - * possible to gather sufficient entropy. - * @throws Exception if `throw` is enabled and it was not possible to gather - * sufficient entropy for generating random bytes. - */ static zend_always_inline int php_uuid_create_v4_throw(php_uuid *uuid) { return php_uuid_create_v4(uuid, 1); } -/** - * Create version 5 UUID. - * - * Version 5 UUIDs are generated by [SHA-1](https://en.wikipedia.org/wiki/SHA-1) - * hashing the concatenated namespace's byte representation and the given name. - * The namespace itself must be another UUID. This can be any UUID, or one of - * the predefined ones: - * - * - php_uuid_namespace_dns() - * - php_uuid_namespace_oid() - * - php_uuid_namespace_url() - * - php_uuid_namespace_x500() - * - * A particular name within the same namespace always results in the same - * version 5 UUID, across all [RFC 4122] compliant UUID implementations. - * However, the namespace and name cannot be determined from the UUID alone. - * - * ### Examples - * - * ```c - * const php_uuid nsid = php_uuid_namespace_dns(); - * php_uuid uuid; - * - * php_uuid_create_v5(&uuid, &nsid, "php.net", sizeof("php.net") - 1); - * - * assert(php_uuid_is_nil(uuid) == 0); - * assert(php_uuid_get_variant(uuid) == PHP_UUID_VARIANT_RFC4122); - * assert(php_uuid_get_version(uuid) == PHP_UUID_VERSION_5_NAME_BASED_SHA1); - * - * php_uuid_string str; - * php_uuid_to_string(&str, uuid); - * assert(memcmp(&str, "c4a760a8-dbcf-5254-a0d9-6a4474bd1b62", PHP_UUID_STRING_LEN) == 0); - * - * php_uuid tmp; - * php_uuid_create_v5(&tmp, &nsid, "php.net", sizeof("php.net") - 1); - * assert(memcmp(&tmp, &uuid, PHP_UUID_LEN) == 0); - * ``` - * - * [RFC 4122]: https://tools.ietf.org/html/rfc4122 - * @see [RFC 4122: Section 4.3](https://tools.ietf.org/html/rfc4122#section-4.3) - * @see [Wikipedia: Universally unique identifier (Versions 3 and 5)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29) - * @param[out] uuid to store the result in. - * @param[in] namespace to create the UUID in. - * @param[in] name to create the UUID from. - * @param[in] name_len - */ PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const char *name, const size_t name_len); -/** - * Get the variant associated with this UUID. - * - * The variant specifies the internal data layout of a UUID. This - * implementation generates #PHP_UUID_VARIANT_RFC4122 UUIDs only, however, - * parsing and construction of other variants is supported. - * - * @see [RFC 4122: Section 4.1.1](http://tools.ietf.org/html/rfc4122#section-4.1.1) - * @see [Wikipedia: Universally unique identifier (Variants)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Variants) - * @see PHP_UUID_VARIANT_NCS - * @see PHP_UUID_VARIANT_RFC4122 - * @see PHP_UUID_VARIANT_MICROSOFT - * @see PHP_UUID_VARIANT_FUTURE_RESERVED - * @param[in] uuid to get the variant from. - * @return The variant of the given UUID. - */ static const zend_always_inline php_uuid_variant php_uuid_get_variant(const php_uuid *uuid) { if ((uuid->bytes[8] & 0xC0) == 0x80) return PHP_UUID_VARIANT_RFC4122; @@ -419,98 +81,36 @@ static const zend_always_inline php_uuid_variant php_uuid_get_variant(const php_ return PHP_UUID_VARIANT_FUTURE_RESERVED; } -/** - * Get the version associated with this UUID. - * - * The version specifies which algorithm was used to generate the UUID. Note - * that the version might not be meaningful if another variant than the - * #PHP_UUID_VARIANT_RFC4122 was used to generate the UUID. This implementation - * generates #PHP_UUID_VARIANT_RFC4122 UUIDs only, but allows parsing and - * construction of other variants. - * - * @see [RFC 4122: Section 4.1.3](http://tools.ietf.org/html/rfc4122#section-4.1.3) - * @see [Wikipedia: Universally unique identifier (Versions)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions) - * @see PHP_UUID_VERSION_1_TIME_BASED - * @see PHP_UUID_VERSION_2_DCE_SECURITY - * @see PHP_UUID_VERSION_3_NAME_BASED_MD5 - * @see PHP_UUID_VERSION_4_RANDOM - * @see PHP_UUID_VERSION_5_NAME_BASED_SHA1 - * @param[in] uuid to get the version from. - * @return The version of the given UUID, which is an integer in [0, 15], the - * values [1, 5] correspond to one of the version constants. The others are - * not defined in RFC 4122. - */ static const zend_always_inline uint8_t php_uuid_get_version(const php_uuid *uuid) { return uuid->bytes[6] >> 4; } -/** - * Domain Name System (DNS) namespace UUID. - * - * @see [RFC 4122: Appendix C](https://tools.ietf.org/html/rfc4122#appendix-C) - * @see [Wikipedia: Domain Name System](https://en.wikipedia.org/wiki/Domain_Name_System) - */ static const zend_always_inline php_uuid php_uuid_namespace_dns() { return (php_uuid) { "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; } -/** -* Object Identifier (OID) namespace UUID. -* - * @see [RFC 4122: Appendix C](https://tools.ietf.org/html/rfc4122#appendix-C) - * @see [Wikipedia: Object identifier](https://en.wikipedia.org/wiki/Object_identifier) - */ static const zend_always_inline php_uuid php_uuid_namespace_oid() { return (php_uuid) { "\x6b\xa7\xb8\x12\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; } -/** - * Uniform Resource Locator (URL) namespace UUID. - * - * @see [RFC 4122: Appendix C](https://tools.ietf.org/html/rfc4122#appendix-C) - * @see [Wikipedia: URL](https://en.wikipedia.org/wiki/URL) - */ static const zend_always_inline php_uuid php_uuid_namespace_url() { return (php_uuid) { "\x6b\xa7\xb8\x11\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; } -/** - * X.500 Distinguished Names (X.500 DN) namespace UUID. The names that are to - * be hashed in this namespace can be in DER or a text output format. - * - * @see [RFC 4122: Appendix C](https://tools.ietf.org/html/rfc4122#appendix-C) - * @see [Wikipedia: X.500](https://en.wikipedia.org/wiki/X.500) - * @see [Wikipedia: Lightweight Directory Access Protocol](https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol) - */ static const zend_always_inline php_uuid php_uuid_namespace_x500() { return (php_uuid) { "\x6b\xa7\xb8\x14\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8" }; } -/** - * Special nil UUID that has all 128 bits set to zero. - * - * @see [RFC 4122: Section 4.1.7](https://tools.ietf.org/html/rfc4122#section-4.1.7) - * @see [Wikipedia: Universally unique identifier (Nil UUID)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID) - */ static const zend_always_inline php_uuid php_uuid_nil() { return (php_uuid) { "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" }; } -/** - * Check if the given UUID is the special nil UUID that has all 128 bits set - * to zero. - * - * @see [RFC 4122: Section 4.1.7](https://tools.ietf.org/html/rfc4122#section-4.1.7) - * @see [Wikipedia: Universally unique identifier (Nil UUID)](https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID) - * @param[in] uuid to check. - * @return `1` if the UUID contains the special nil UUID; `0` otherwise. - */ static const zend_always_inline int php_uuid_is_nil(const php_uuid *uuid) { const php_uuid nil = php_uuid_nil(); @@ -518,106 +118,18 @@ static const zend_always_inline int php_uuid_is_nil(const php_uuid *uuid) return memcmp(uuid->bytes, &nil, PHP_UUID_LEN) == 0; } -/** - * Parse the given string as UUID. - * - * The following UUID representations are parsable: - * - * - hexadecimal (`00000000111122223333444444444444`), - * - string (`00000000-1111-2222-3333-444444444444`), - * - URNs (`urn:uuid:00000000-1111-2222-3333-444444444444`), and - * - Microsoft (`{00000000-1111-2222-3333-444444444444}`). - * - * Leading and trailing whitespace, namely spaces (` `) and tabs (`\t`), is - * ignored, so are leading opening braces (`{`) and trailing closing braces - * (`}`). Hyphens (`-`) are ignored everywhere. The parsing algorithm - * follows the [robustness - * principle](https://en.wikipedia.org/wiki/Robustness_principle) and is - * not meant for validation. - * - * ### Examples - * - * ```c - * php_uuid uuid; - * - * // Parsing of canonical representations. - * php_uuid_parse_silent(&uuid, "0123456789abcdef0123456789abcdef", sizeof("0123456789abcdef0123456789abcdef") - 1); - * php_uuid_parse_silent(&uuid, "01234567-89ab-cdef-0123-456789abcdef", sizeof("01234567-89ab-cdef-0123-456789abcdef") - 1); - * php_uuid_parse_silent(&uuid, "urn:uuid:01234567-89ab-cdef-0123-456789abcdef", sizeof("urn:uuid:01234567-89ab-cdef-0123-456789abcdef") - 1); - * php_uuid_parse_silent(&uuid, "{01234567-89ab-cdef-0123-456789abcdef}", sizeof("{01234567-89ab-cdef-0123-456789abcdef}") - 1); - * - * // Leading and trailing garbage is ignored, so are extraneous hyphens. - * php_uuid_parse_silent(&uuid, " \t ---- { urn:uuid:----0123-4567-89ab-cdef-0123-4567-89ab-cdef---- } ---- \t ", sizeof(" \t ---- { urn:uuid:----0123-4567-89ab-cdef-0123-4567-89ab-cdef---- } ---- \t ") - 1); - * - * // However, note that there cannot be whitespace or braces between the URN - * // scheme and the UUID itself. - * assert(php_uuid_parse_silent( - * &uuid, - * "urn:uuid:{01234567-89ab-cdef-0123-456789abcdef", - * sizeof("urn:uuid:{01234567-89ab-cdef-0123-456789abcdef") - 1 - * ) == FAILURE); - * ``` - * - * @see php_uuid_parse_silent - * @see php_uuid_parse_throw - * @param[out] uuid to store the result in. - * @param[in] input to parse as UUID. - * @param[in] input_len - * @param[in] throw whether to throw PHP exceptions (`1`), or not (`0`). - * @return #SUCCESS() if the string was parsed as UUID; #FAILURE() otherwise. - * @throws UUIDParseException if `throw` is enabled and parsing fails. - */ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_len, const zend_bool throw); -/** - * Silently parse the string as UUID. - * - * @see php_uuid_parse - * @param[out] uuid to store the result in. - * @param[in] input to parse as UUID. - * @param[in] input_len - * @return #SUCCESS() if the string was parsed as UUID; #FAILURE() otherwise. - */ static zend_always_inline int php_uuid_parse_silent(php_uuid *uuid, const char *input, const size_t input_len) { return php_uuid_parse(uuid, input, input_len, 0); } -/** - * Parse the string as UUID and throw PHP exceptions on failures. - * - * @see php_uuid_parse - * @param[out] uuid to store the result in. - * @param[in] input to parse as UUID. - * @param[in] input_len - * @return #SUCCESS() if the string was parsed as UUID; #FAILURE() otherwise. - * @throws UUIDParseException if parsing fails. - */ static zend_always_inline int php_uuid_parse_throw(php_uuid *uuid, const char *input, const size_t input_len) { return php_uuid_parse(uuid, input, input_len, 1); } -/** - * Convert the UUID to its hexadecimal representation. - * - * The hexadecimal representation of a UUID are 32 hexadecimal digits. The - * hexadecimal digits `a` through `f` are always formatted as lower case - * characters, in accordance with RFC 4122. - * - * ### Examples - * - * ```c - * const php_uuid nsid = php_uuid_namespace_dns(); - * php_uuid_hex hex; - * - * php_uuid_to_hex(&hex, &nsid); - * assert(memcmp(&hex, "6ba7b8109dad11d180b400c04fd430c8", PHP_UUID_HEX_LEN) == 0); - * ``` - * - * @param[out] buffer to store the hexadecimal representation in. - * @param[in] uuid to convert. - */ static zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_uuid *uuid) { sprintf( @@ -631,27 +143,6 @@ static zend_always_inline void php_uuid_to_hex(php_uuid_hex *buffer, const php_u ); } -/** - * Convert the UUID to its string representation. - * - * The string representation of a UUID are 32 hexadecimal digits separated - * by a hyphen into five groups of 8, 4, 4, 4, and 12 digits. The - * hexadecimal digits `a` through `f` are always formatted as lower case - * characters, in accordance with RFC 4122. - * - * ### Examples - * - * ```c - * const php_uuid nsid = php_uuid_namespace_dns(); - * php_uuid_string str; - * - * php_uuid_to_hex(&str, &nsid); - * assert(memcmp(&str, "6ba7b810-9dad-11d1-80b4-00c04fd430c8", PHP_UUID_STRING_LEN) == 0); - * ``` - * - * @param[out] buffer to store the string representation in. - * @param[in] uuid to convert. - */ static zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const php_uuid *uuid) { sprintf( @@ -667,12 +158,6 @@ static zend_always_inline void php_uuid_to_string(php_uuid_string *buffer, const END_EXTERN_C() -/** - * Initialization function of the standard UUID submodule. - * - * @see ext/standard/basic_functions.c - * @see ext/standard/php_standard.h - */ PHP_MINIT_FUNCTION(uuid); #endif /* PHP_UUID_H */ diff --git a/ext/standard/uuid.c b/ext/standard/uuid.c index 6414cffde668a..7e87ea2e9ab9f 100644 --- a/ext/standard/uuid.c +++ b/ext/standard/uuid.c @@ -29,78 +29,29 @@ PHPAPI zend_class_entry *php_ce_UUID; PHPAPI zend_class_entry *php_ce_UUIDParseException; -/** Minimum legal UUID version value. */ static const uint8_t UUID_VERSION_MIN = 0; - -/** Maximum legal UUID version value. */ static const uint8_t UUID_VERSION_MAX = 15; -/** UUID hexadecimal representation length without terminating NUL. */ static const uint8_t UUID_HEX_LEN = sizeof(php_uuid_hex) - 1; - -/** UUID string representation length without terminating NUL. */ static const uint8_t UUID_STRING_LEN = sizeof(php_uuid_string) - 1; -/** - * Name of the private property of the `UUID` class where the binary - * representation of the UUID is stored in. - */ static const char UUID_BYTES_PROP[] = "bytes"; - -/** Length of the `UUID::$bytes` property name without terminating NUL. */ static const uint8_t UUID_BYTES_PROP_LEN = sizeof(UUID_BYTES_PROP) - 1; -/** - * Name of the private property of the `UUIDParseException` class where the - * original input is stored in that should have been parsed, but failed. - */ static const char UUID_EX_INPUT_PROP[] = "input"; - -/** - * Length of the `UUIDParseException::$input` property name without terminating - * NUL. - */ static const uint8_t UUID_EX_INPUT_PROP_LEN = sizeof(UUID_EX_INPUT_PROP) - 1; -/** - * Name of the private property of the `UUIDParseException` class where the - * position is stored at which the parsing of the UUID failed. - */ static const char UUID_EX_POSITION_PROP[] = "position"; - -/** - * Length of the `UUIDParseException::$position` property name without - * terminating NUL. - */ static const uint8_t UUID_EX_POSITON_PROP_LEN = sizeof(UUID_EX_POSITION_PROP) - 1; -/** URN prefix of a UUID's string representation. */ static const char URN_PREFIX[] = "urn:uuid:"; - -/** Length of the URN prefix of a UUID without terminating NUL. */ static const uint8_t URN_PREFIX_LEN = sizeof(URN_PREFIX) - 1; -/** - * Set UUID variant to RFC 4122, the only supported variant. - * - * @param[out] uuid to set the variant. - */ static zend_always_inline void set_variant_rfc4122(php_uuid *uuid) { uuid->bytes[8] = (uuid->bytes[8] & 0x3F) | 0x80; } -/** - * Set UUID version. - * - * @see PHP_UUID_VERSION_1_TIME_BASED - * @see PHP_UUID_VERSION_2_DCE_SECURITY - * @see PHP_UUID_VERSION_3_NAME_BASED_MD5 - * @see PHP_UUID_VERSION_4_RANDOM - * @see PHP_UUID_VERSION_5_NAME_BASED_SHA1 - * @param[out] uuid to set the version. - * @param[in] version to set. - */ static zend_always_inline void php_uuid_set_version(php_uuid *uuid, const uint8_t version) { assert(UUID_VERSION_MIN <= version && version <= UUID_VERSION_MAX); @@ -148,15 +99,6 @@ PHPAPI void php_uuid_create_v5(php_uuid *uuid, const php_uuid *namespace, const php_uuid_set_version(uuid, PHP_UUID_VERSION_5_NAME_BASED_SHA1); } -/** - * Throw `UUIDParseException`. - * - * @param[in] input that could not be parsed. - * @param[in] input_len - * @param[in] position at which parsing failed. - * @param[in] reason why parsing failed. - * @param[in] ... arguments to format the reason. - */ static ZEND_COLD zend_object *throw_uuid_parse_exception(const char *input, const size_t input_len, const size_t position, const char *reason, ...) { va_list format_args; @@ -177,14 +119,6 @@ static ZEND_COLD zend_object *throw_uuid_parse_exception(const char *input, cons return object; } -/** - * Throw `UUIDParseException` because of insufficient input. - * - * @param[in] input that could not be parsed. - * @param[in] input_len - * @param[in] position at which parsing failed. - * @param[in] actual amount of characters that were found. - */ static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_len(const char *input, const size_t input_len, const size_t position, const size_t actual) { return throw_uuid_parse_exception( @@ -197,13 +131,6 @@ static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_len(co ); } -/** - * Throw `UUIDParseException` because of an invalid character. - * - * @param[in] input that could not be parsed. - * @param[in] input_len - * @param[in] position at which parsing failed. - */ static zend_always_inline zend_object *throw_uuid_parse_exception_invalid_char(const char *input, const size_t input_len, const size_t position) { return throw_uuid_parse_exception( @@ -319,21 +246,6 @@ PHPAPI int php_uuid_parse(php_uuid *uuid, const char *input, const size_t input_ return SUCCESS; } -/** - * Get the UUID from the given UUID object. - * - * @attention - * We are required to check the type and length of the encapsulated value upon - * every access because users can change the value through various ways (e.g. - * reflection, closures, ...) and there is nothing that prevents them from - * doing so. - * - * @param[in] uuid_object to get the UUID from. - * @return #SUCCESS() if the UUID could be read from the object; #FAILURE() - * otherwise. - * @throws TypeError if the value is not of type string. - * @throws Error if the string value is not exactly 16 bytes long. - */ static zend_always_inline php_uuid *get_uuid(/*const*/ zval *uuid_object) { zval *bytes = zend_read_property(php_ce_UUID, uuid_object, UUID_BYTES_PROP, UUID_BYTES_PROP_LEN, 1, NULL); @@ -365,19 +277,12 @@ static zend_always_inline php_uuid *get_uuid(/*const*/ zval *uuid_object) return (php_uuid *) Z_STRVAL_P(bytes); } -/** - * Construct new UUID instance. - * - * @param[out] object to store the UUID instance int. - * @param[in] uuid to construct the instance from. - */ static zend_always_inline void new_uuid(zval *object, const php_uuid *uuid) { object_init_ex(object, php_ce_UUID); zend_update_property_stringl(php_ce_UUID, object, UUID_BYTES_PROP, UUID_BYTES_PROP_LEN, (const char *) uuid->bytes, PHP_UUID_LEN); } -/** `private function UUID::__construct()` */ PHP_METHOD(UUID, __construct) { /* NOOP */ @@ -385,7 +290,6 @@ PHP_METHOD(UUID, __construct) ZEND_BEGIN_ARG_INFO(UUID___construct_args, NULL) ZEND_END_ARG_INFO() -/** `public static function UUID::fromBinary(string $input): self` */ PHP_METHOD(UUID, fromBinary) { zval *input = NULL; @@ -412,7 +316,6 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_fromBinary_args, 0, 1, self, 0) ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) ZEND_END_ARG_INFO() -/** `public static function UUID::parse(string $input): self` */ PHP_METHOD(UUID, parse) { zval *input = NULL; @@ -432,7 +335,6 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_parse_args, 0, 1, self, 0) ZEND_ARG_TYPE_INFO(0, input, IS_STRING, 0) ZEND_END_ARG_INFO() -/** `public static function UUID::v3(self $namespace, string $name): self` */ PHP_METHOD(UUID, v3) { zval *namespace = NULL; @@ -457,7 +359,6 @@ ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(UUID_v3_args, 0, 2, self, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_END_ARG_INFO() -/** `public static function UUID::v4(): self` */ PHP_METHOD(UUID, v4) { php_uuid uuid; @@ -475,7 +376,6 @@ PHP_METHOD(UUID, v4) ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO(UUID_v4_args, self, 0) ZEND_END_ARG_INFO() -/** `public static function UUID::v5(self $namespace, string $name): self` */ PHP_METHOD(UUID, v5) { zval *namespace = NULL; @@ -500,19 +400,6 @@ ZEND_ARG_OBJ_INFO(0, namespace, self, 0) ZEND_ARG_TYPE_INFO(0, name, IS_STRING, 0) ZEND_END_ARG_INFO() -/** - * Macro for consistent creation of named UUID class constructors from C - * functions. The output of the macro is as follows: - * - * ```php - * final class UUID { - * public static function php_method_name(): self {} - * } - * ``` - * - * @param[in] php_method_name - * @param[in] c_function_name without the `php_uuid_` prefix. - */ #define PHP_UUID_NAMED_CONSTRUCTOR(php_method_name, c_function_name) \ PHP_METHOD(UUID, php_method_name) \ { \ @@ -533,7 +420,6 @@ PHP_UUID_NAMED_CONSTRUCTOR(NamespaceURL, namespace_url) PHP_UUID_NAMED_CONSTRUCTOR(NamespaceX500, namespace_x500) PHP_UUID_NAMED_CONSTRUCTOR(Nil, nil) -/** `private function UUID::__clone()` */ PHP_METHOD(UUID, __clone) { zend_throw_error(zend_ce_error, "Cannot clone immutable %s object", ZSTR_VAL(php_ce_UUID->name)); @@ -541,7 +427,6 @@ PHP_METHOD(UUID, __clone) ZEND_BEGIN_ARG_INFO(UUID___clone_args, NULL) ZEND_END_ARG_INFO() -/** `public function UUID::__set($_, $__): void` */ PHP_METHOD(UUID, __set) { zend_throw_error(zend_ce_error, "Cannot set dynamic properties on immutable %s object", ZSTR_VAL(php_ce_UUID->name)); @@ -551,7 +436,6 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___set_args, IS_VOID, 0) ZEND_ARG_INFO(0, __) ZEND_END_ARG_INFO() -/** `public function UUID::__wakeup(): void` */ PHP_METHOD(UUID, __wakeup) { zval *bytes = zend_read_property(php_ce_UUID, &EX(This), UUID_BYTES_PROP, UUID_BYTES_PROP_LEN, 1, NULL); @@ -589,17 +473,11 @@ PHP_METHOD(UUID, __wakeup) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID___wakeup_args, IS_VOID, 0) ZEND_END_ARG_INFO() -/** - * Macro for consistent checking that there were no parameters passed to the - * PHP method, and to fetch the content of the private property that contains - * the byte representation of the UUID into a local variable called `uuid`. - */ #define PHP_UUID_ACCESSOR \ const php_uuid *uuid = NULL; \ if (zend_parse_parameters_none_throw() == FAILURE) return; \ if ((uuid = get_uuid(&EX(This))) == NULL) return; -/** `public function UUID::getVariant(): int` */ PHP_METHOD(UUID, getVariant) { PHP_UUID_ACCESSOR; @@ -608,7 +486,6 @@ PHP_METHOD(UUID, getVariant) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVariant_args, IS_LONG, 0) ZEND_END_ARG_INFO() -/** `public function UUID::getVersion(): int` */ PHP_METHOD(UUID, getVersion) { PHP_UUID_ACCESSOR; @@ -617,7 +494,6 @@ PHP_METHOD(UUID, getVersion) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_getVersion_args, IS_LONG, 0) ZEND_END_ARG_INFO() -/** `public function UUID::isNil(): bool` */ PHP_METHOD(UUID, isNil) { PHP_UUID_ACCESSOR; @@ -626,7 +502,6 @@ PHP_METHOD(UUID, isNil) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_isNil_args, _IS_BOOL, 0) ZEND_END_ARG_INFO() -/** `public function UUID::toBinary(): string` */ PHP_METHOD(UUID, toBinary) { PHP_UUID_ACCESSOR; @@ -635,7 +510,6 @@ PHP_METHOD(UUID, toBinary) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toBinary_args, IS_STRING, 0) ZEND_END_ARG_INFO() -/** `public function UUID::toHex(): string` */ PHP_METHOD(UUID, toHex) { php_uuid_hex buffer; @@ -646,7 +520,6 @@ PHP_METHOD(UUID, toHex) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUID_toHex_args, IS_STRING, 0) ZEND_END_ARG_INFO() -/** `public function UUID::toString(): string` */ PHP_METHOD(UUID, toString) { php_uuid_string buffer; @@ -681,7 +554,6 @@ static const zend_function_entry uuid_methods[] = { PHP_FE_END }; -/** `public function UUIDParseException::__construct(string $reason, string $input, int $position = 0, ?Throwable $previous = null)` */ PHP_METHOD(UUIDParseException, __construct) { zval *reason = NULL; @@ -714,7 +586,6 @@ ZEND_BEGIN_ARG_INFO_EX(UUIDParseException___construct_args, NULL, 0, 2) ZEND_ARG_OBJ_INFO(0, previous, Throwable, 1) ZEND_END_ARG_INFO() -/** `public function UUIDParseException::getInput(): string` */ PHP_METHOD(UUIDParseException, getInput) { if (zend_parse_parameters_none_throw() == FAILURE) { @@ -733,7 +604,6 @@ PHP_METHOD(UUIDParseException, getInput) ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO(UUIDParseException_getInput_args, IS_STRING, 0) ZEND_END_ARG_INFO() -/** `public function UUIDParseException::getPosition(): int` */ PHP_METHOD(UUIDParseException, getPosition) { if (zend_parse_parameters_none_throw() == FAILURE) { From 3dc104e0dc13257ec78e51ce4637e737002da7d3 Mon Sep 17 00:00:00 2001 From: Richard Fussenegger Date: Sat, 1 Jul 2017 20:02:29 +0200 Subject: [PATCH 54/54] Removed PHP Stub Files --- ext/standard/stubs/UUID.php | 687 ---------------------- ext/standard/stubs/UUIDParseException.php | 83 --- 2 files changed, 770 deletions(-) delete mode 100644 ext/standard/stubs/UUID.php delete mode 100644 ext/standard/stubs/UUIDParseException.php diff --git a/ext/standard/stubs/UUID.php b/ext/standard/stubs/UUID.php deleted file mode 100644 index 260c72eda5b7c..0000000000000 --- a/ext/standard/stubs/UUID.php +++ /dev/null @@ -1,687 +0,0 @@ -isNil()); - * assert($uuid->getVariant() === 0); - * assert($uuid->getVersion() === 0); - * - * $uuid = UUID::v3(UUID::NamespaceDNS(), 'php.net'); - * assert($uuid->isNil() === false); - * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); - * assert($uuid->getVersion() === UUID::VERSION_3_NAME_BASED_MD5); - * - * $uuid = UUID::v4(); - * assert($uuid->isNil() === false); - * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); - * assert($uuid->getVersion() === UUID::VERSION_4_RANDOM); - * - * $uuid = UUID::v5(UUID::NamespaceDNS(), 'php.net'); - * assert($uuid->isNil() === false); - * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); - * assert($uuid->getVersion() === UUID::VERSION_5_NAME_BASED_SHA1); - * - * $uuid = UUID::parse('urn:uuid:123E4567-E89B-12D3-A456-426655440000'); - * assert($uuid->isNil() === false); - * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); - * assert($uuid->getVersion() === UUID::VERSION_1_TIME_BASED); - * - * assert($uuid->toBinary() === "\x12\x3E\x45\x67\xE8\x9B\x12\xD3\xA4\x56\x42\x66\x55\x44\x00\x00"); - * assert($uuid->toHex() === '123e4567e89b12d3a456426655440000'); - * assert($uuid->toString() === '123e4567-e89b-12d3-a456-426655440000'); - * - * ?> - * ``` - * - * Comparison of UUIDs is possible with the default comparison operators of - * PHP. - * - * ``` - * - * ``` - * - * [rfc]: https://tools.ietf.org/html/rfc4122 - * [wiki]: https://en.wikipedia.org/wiki/Universally_unique_identifier - * @since 7.2 - * @see https://php.net/uuid - */ -final class UUID { - /** - * Code for the (reserved) NCS variant of UUIDs. - * - * @since 7.2 - * @see https://tools.ietf.org/html/rfc4122#section-4.1.1 - */ - public const VARIANT_NCS = 0; - - /** - * Code for the RFC 4122 variant of UUIDs. - * - * This implementation generates UUIDs of this variant only. - * - * @since 7.2 - * @see https://tools.ietf.org/html/rfc4122#section-4.1.1 - */ - public const VARIANT_RFC4122 = 1; - - /** - * Code for the (reserved) Microsoft variant of UUIDs, the GUIDs. - * - * @since 7.2 - * @see https://tools.ietf.org/html/rfc4122#section-4.1.1 - */ - public const VARIANT_MICROSOFT = 2; - - /** - * Version code for the future reserved variant of UUIDs. - * - * @since 7.2 - * @see https://tools.ietf.org/html/rfc4122#section-4.1.1 - */ - public const VARIANT_FUTURE_RESERVED = 4; - - /** - * Version code for date-time and IEEE 802 MAC address UUIDs. - * - * Generation of this version is not supported by this implementation due - * to security concerns. Version 4 UUIDs are a good replacement for version - * 1 UUIDs without the privacy/security concerns (see [Wikipedia][wiki]). - * - * [wiki]: https://en.wikipedia.org/wiki/Universally_unique_identifier - * @since 7.2 - * @see https://tools.ietf.org/html/rfc4122#section-4.2 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_1_.28date-time_and_MAC_address.29 - */ - public const VERSION_1_TIME_BASED = 1; - - /** - * Version code for date-time and IEEE 802 MAC address UUIDs (DCE security - * algorithm). - * - * Generation of this version is not supported by this implementation due - * to security concerns, and uniqueness limitations for applications with - * high allocations. Version 4 UUIDs are a good replacement for version 2 - * UUIDs without the privacy/security concerns (see [Wikipedia][wiki]), and - * they support high allocations. - * - * [wiki]: https://en.wikipedia.org/wiki/Universally_unique_identifier - * @since 7.2 - * @see https://tools.ietf.org/html/rfc4122#section-4.2 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_2_.28date-time_and_MAC_Address.2C_DCE_security_version.29 - */ - public const VERSION_2_DCE_SECURITY = 2; - - /** - * Version code for namespace/name-based MD5 hashed UUIDs. - * - * @since 7.2 - * @see v3 - * @see https://tools.ietf.org/html/rfc4122#section-4.3 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 - */ - public const VERSION_3_NAME_BASED_MD5 = 3; - - /** - * Version code for random UUIDs. - * - * @since 7.2 - * @see v4 - * @see https://tools.ietf.org/html/rfc4122#section-4.4 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 - */ - public const VERSION_4_RANDOM = 4; - - /** - * Version code for namespace/name-based SHA1 hashed UUIDs. - * - * @since 7.2 - * @see v5 - * @see https://tools.ietf.org/html/rfc4122#section-4.3 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 - */ - public const VERSION_5_NAME_BASED_SHA1 = 5; - - /** - * This UUID's 128 bit integer value as 16 byte binary string. - * - * @since 7.2 - * @see toBinary - * @var string - */ - private $bytes; - - /** - * Use {@see fromBinary} or {@see parse} to construct a new instance. - */ - private function __construct() { } - - /** - * Construct new UUID instance from binary string of exactly 16 bytes. - * - * Any string of 16 bytes is accepted by this named constructor. This - * enables the construction of UUIDs of any variant and version, regardless - * of the {@see parse} implementation. - * - * ## Examples - * ``` - * getVariant() === UUID::VARIANT_FUTURE_RESERVED); - * - * ?> - * ``` - * - * @since 7.2 - * @see https://php.net/uuid.fromBinary - * @see toBinary - * @param string $input string of exactly 16 bytes to construct the instance from. - * @return \UUID UUID constructed from the binary input. - * @throws \ArgumentCountError if less or more than one argument is passed. - * @throws \InvalidArgumentException if the input is not 16 bytes long. - */ - public static function fromBinary(string $input): self { } - - /** - * Parse the given string as UUID. - * - * The following UUID representations are parsable: - * - * - hexadecimal (`00000000111122223333444444444444`), - * - string (`00000000-1111-2222-3333-444444444444`), - * - URNs (`urn:uuid:00000000-1111-2222-3333-444444444444`), and - * - Microsoft (`{00000000-1111-2222-3333-444444444444}`). - * - * Leading and trailing whitespace, namely spaces (` `) and tabs (`\t`), is - * ignored, so are leading opening braces (`{`) and trailing closing braces - * (`}`). Hyphens (`-`) are ignored everywhere. The parsing algorithm - * follows the [robustness principle][wrp] and is not meant for validation. - * - * ## Examples - * ``` - * getMessage() === 'Expected hexadecimal digit, but found '{' (0x7b)'); - * } - * - * ?> - * ``` - * - * [wrp]: https://en.wikipedia.org/wiki/Robustness_principle - * @since 7.2 - * @see https://php.net/uuid.parse - * @see toHex - * @see toString - * @param string $input to parse as UUID and construct the instance from. - * @return \UUID UUID constructed from the parsed input. - * @throws \ArgumentCountError if less or more than one argument is passed. - * @throws \UUIDParseException if parsing of the input fails. - */ - public static function parse(string $input): self { } - - /** - * Construct new version 3 UUID. - * - * > RFC 4122 recommends {@see v5} over this one and states that version 3 - * > UUIDs should be used if backwards compatibility is required only. This - * > is because MD5 has a higher collision probability compared to SHA1, - * > which is used by version 5; regardless of the truncation! - * - * Version 3 UUIDs are generated by MD5 hashing the concatenated - * namespace's byte representation and the given name. The namespace itself - * must be another UUID. This can be any UUID, or one of the predefined - * ones: - * - * - {@see NamespaceDNS} - * - {@see NamespaceOID} - * - {@see NamespaceURL} - * - {@see NamespaceX500} - * - * A particular name within the same namespace always results in the same - * version 3 UUID, across all RFC 4122 compliant UUID implementations. - * However, the namespace and name cannot be determined from the UUID - * alone. - * - * ## Examples - * ``` - * isNil() === false); - * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); - * assert($uuid->getVersion() === UUID::VERSION_3_NAME_BASED_MD5); - * assert($uuid->toString() === '11a38b9a-b3da-360f-9353-a5a725514269'); - * assert($uuid == UUID::v3(UUID::NamespaceDNS(), 'php.net')); - * - * ?> - * ``` - * - * @since 7.2 - * @see https://php.net/uuid.v3 - * @see https://tools.ietf.org/html/rfc4122#section-4.3 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 - * @param \UUID $namespace to construct the UUID in. - * @param string $name to construct the UUID from. - * @return \UUID UUID constructed from the name in the namespace. - * @throws \ArgumentCountError if less or more than two arguments are passed. - * @throws \Error if the namespace does not encapsulate a valid UUID. - */ - public static function v3(self $namespace, string $name): self { } - - /** - * Construct new version 4 UUID. - * - * Version 4 UUIDs are randomly generated from the best available random - * source. The selection of that source is determined by PHP's - * {@see random_bytes} implementation. Some systems may be bad at - * generating sufficient entropy, e.g. virtual machines. This might lead to - * collisions faster than desired. If this is the case, the {@see v5} - * version should be used. - * - * ## Examples - * ``` - * isNil() === false); - * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); - * assert($uuid->getVersion() === UUID::VERSION_4_RANDOM); - * assert($uuid != UUID::v4()); - * - * ?> - * ``` - * - * @since 7.2 - * @see https://php.net/uuid.v4 - * @see https://tools.ietf.org/html/rfc4122#section-4.4 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Version_4_.28random.29 - * @return \UUID UUID constructed from random data. - * @throws \Exception if it was not possible to gather sufficient entropy. - * @throws \ArgumentCountError if arguments are passed. - */ - public static function v4(): self { } - - /** - * Construct new version 5 UUID. - * - * Version 5 UUIDs are generated by MD5 hashing the concatenated - * namespace's byte representation and the given name. The namespace itself - * must be another UUID. This can be any UUID, or one of the predefined - * ones: - * - * - {@see NamespaceDNS} - * - {@see NamespaceOID} - * - {@see NamespaceURL} - * - {@see NamespaceX500} - * - * A particular name within the same namespace always results in the same - * version 5 UUID, across all RFC 4122 compliant UUID implementations. - * However, the namespace and name cannot be determined from the UUID - * alone. - * - * ## Examples - * ``` - * isNil() === false); - * assert($uuid->getVariant() === UUID::VARIANT_RFC4122); - * assert($uuid->getVersion() === UUID::VERSION_5_NAME_BASED_SHA1); - * assert($uuid->toString() === 'c4a760a8-dbcf-5254-a0d9-6a4474bd1b62'); - * assert($uuid == UUID::v5(UUID::NamespaceDNS(), 'php.net')); - * - * ?> - * ``` - * - * @since 7.2 - * @see https://php.net/uuid.v5 - * @see @see https://tools.ietf.org/html/rfc4122#section-4.3 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions_3_and_5_.28namespace_name-based.29 - * @param \UUID $namespace to construct the UUID in. - * @param string $name to construct the UUID from. - * @return \UUID UUID constructed from the name in the namespace. - * @throws \ArgumentCountError if less or more than two arguments are passed. - * @throws \Error if the namespace does not encapsulate a valid UUID. - */ - public static function v5(self $namespace, string $name): self { } - - /** - * Construct new Domain Name System (DNS) namespace UUID instance. - * - * @since 7.2 - * @see https://php.net/uuid.NamespaceDNS - * @see https://tools.ietf.org/html/rfc4122#appendix-C - * @see https://en.wikipedia.org/wiki/Domain_Name_System - * @return \UUID Predefined DNS namespace UUID. - * @throws \ArgumentCountError if arguments are passed. - */ - public static function NamespaceDNS(): self { } - - /** - * Construct new Object Identifier (OID) namespace UUID instance. - * - * @since 7.2 - * @see https://php.net/uuid.NamespaceOID - * @see https://tools.ietf.org/html/rfc4122#appendix-C - * @see https://en.wikipedia.org/wiki/Object_identifier - * @return \UUID Predefined OID namespace UUID. - * @throws \ArgumentCountError if arguments are passed. - */ - public static function NamespaceOID(): self { } - - /** - * Construct new Uniform Resource Locator (URL) namespace UUID instance. - * - * @since 7.2 - * @see https://php.net/uuid.NamespaceURL - * @see https://tools.ietf.org/html/rfc4122#appendix-C - * @see https://en.wikipedia.org/wiki/URL - * @return \UUID Predefined URL namespace UUID. - * @throws \ArgumentCountError if arguments are passed. - */ - public static function NamespaceURL(): self { } - - /** - * Construct new X.500 Distinguished Names (X.500 DN) namespace UUID - * instance. The names that are to be hashed in this namespace can be in - * DER or a text output format. - * - * @since 7.2 - * @see https://php.net/uuid.NamespaceX500 - * @see https://tools.ietf.org/html/rfc4122#appendix-C - * @see https://en.wikipedia.org/wiki/X.500 - * @see https://en.wikipedia.org/wiki/Lightweight_Directory_Access_Protocol - * @return \UUID Predefined X.500 namespace UUID instance. - * @throws \ArgumentCountError if arguments are passed. - */ - public static function NamespaceX500(): self { } - - /** - * Construct special nil UUID that has all 128 bits set to zero. - * - * @since 7.2 - * @see https://php.net/uuid.Nil - * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID - * @return \UUID Predefined special nil UUID. - * @throws \ArgumentCountError if arguments are passed. - */ - public static function Nil(): self { } - - /** - * Callback for dynamic adding of properties which throws an {@see Error} - * upon every invocation, direct or indirect. This is necessary to protect - * the promised immutability of this object. Not doing so could lead to - * problems with the comparison operators, since PHP always compares all - * properties. - * - * @since 7.2 - * @see https://php.net/uuid.__set - * @param mixed $_ - * @param mixed $__ - * @return void - * @throws \Error upon every invocation, direct or indirect. - */ - public function __set($_, $__): void { } - - /** - * Deserialization callback. - * - * @since 7.2 - * @see https://php.net/uuid.__wakeup - * @see unserialize() - * @return void - * @throws \ArgumentCountError if arguments are passed. - * @throws \UnexpectedValueException if the value of the {@see bytes} - * property is not of type string, or not exactly 16 bytes long. - */ - public function __wakeup(): void { } - - /** - * Get the variant associated with this UUID. - * - * The variant specifies the internal data layout of a UUID. This - * implementation generates {@see UUID::VARIANT_RFC4122} UUIDs only, - * however, parsing and construction of other variants is supported. - * - * @since 7.2 - * @see https://php.net/uuid.getVariant - * @see https://tools.ietf.org/html/rfc4122#section-4.1.1 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Variants - * @see UUID::VARIANT_NCS - * @see UUID::VARIANT_RFC4122 - * @see UUID::VARIANT_MICROSOFT - * @see UUID::VARIANT_FUTURE_RESERVED - * @return int An integer in [0, 3] where each value corresponds to one of - * the `UUID::VARIANT_*` class constants. - * @throws \ArgumentCountError if arguments are passed. - * @throws \Error if this instance does not encapsulate a valid UUID. - */ - public function getVariant(): int { } - - /** - * Get the version associated with this UUID. - * - * The version specifies which algorithm was used to generate the UUID. - * Note that the version might not be meaningful if another variant than - * the {@see UUID::VARIANT_RFC4122} was used to generate the UUID. This - * implementation generates {@see UUID::VARIANT_RFC4122} UUIDs only, but - * allows parsing and construction of other variants. - * - * @since 7.2 - * @see https://php.net/uuid.getVersion - * @see https://tools.ietf.org/html/rfc4122#section-4.1.3 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions - * @see UUID::VERSION_1_TIME_BASED - * @see UUID::VERSION_2_DCE_SECURITY - * @see UUID::VERSION_3_NAME_BASED_MD5 - * @see UUID::VERSION_4_RANDOM - * @see UUID::VERSION_5_NAME_BASED_SHA1 - * @return int An integer in [0, 15], the values [1, 5] correspond to one - * of the `UUID::VERSION_*` class constants. The others are not defined - * in RFC 4122. - * @throws \ArgumentCountError if arguments are passed. - * @throws \Error if this instance does not encapsulate a valid UUID. - */ - public function getVersion(): int { } - - /** - * Check if this UUID is the special nil UUID that has all 128 bits set to - * zero. - * - * @since 7.2 - * @see https://php.net/uuid.isNil - * @see https://tools.ietf.org/html/rfc4122#section-4.1.7 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Nil_UUID - * @see Nil - * @return bool **TRUE** if this is the special nil UUID; **FALSE** - * otherwise. - * @throws \ArgumentCountError if arguments are passed. - * @throws \Error if this instance does not encapsulate a valid UUID. - */ - public function isNil(): bool { } - - /** - * Convert the UUID to its binary representation. - * - * The binary representation of a UUID is a string of exactly 16 bytes. It - * is the format that is used internally. It is also the format that should - * be used to store UUIDs in a database (e.g. in MySQL as `BINARY(16)` - * column). The resulting string, if generated by this implementation, is - * always in network byte order. - * - * ## Examples - * ``` - * toBinary() === "\x6b\xa7\xb8\x10\x9d\xad\x11\xd1\x80\xb4\x00\xc0\x4f\xd4\x30\xc8"); - * - * ?> - * ``` - * - * @since 7.2 - * @see https://php.net/uuid.toBinary - * @return string Binary representation of the UUID. - * @throws \ArgumentCountError if arguments are passed. - * @throws \Error if this instance does not encapsulate a valid UUID. - */ - public function toBinary(): string { } - - /** - * Convert the UUID to its hexadecimal representation. - * - * The hexadecimal representation of a UUID are 32 hexadecimal digits. The - * hexadecimal digits `a` through `f` are always formatted as lower case - * characters, in accordance with RFC 4122. - * - * ## Examples - * ``` - * toHex() === '6ba7b8109dad11d180b400c04fd430c8'); - * - * ?> - * ``` - * - * @since 7.2 - * @see https://php.net/uuid.toHex - * @return string Hexadecimal representation of the UUID. - * @throws \ArgumentCountError if arguments are passed. - * @throws \Error if this instance does not encapsulate a valid UUID. - */ - public function toHex(): string { } - - /** - * Convert the UUID to its string representation. - * - * The string representation of a UUID are 32 hexadecimal digits separated - * by a hyphen into five groups of 8, 4, 4, 4, and 12 digits. The - * hexadecimal digits `a` through `f` are always formatted as lower case - * characters, in accordance with RFC 4122. - * - * ## Examples - * ``` - * toString() === '6ba7b810-9dad-11d1-80b4-00c04fd430c8'); - * - * ?> - * ``` - * - * @since 7.2 - * @see https://php.net/uuid.toString - * @see https://tools.ietf.org/html/rfc4122#page-4 - * @see https://en.wikipedia.org/wiki/Universally_unique_identifier#Format - * @return string String representation of the UUID. - * @throws \ArgumentCountError if arguments are passed. - * @throws \Error if this instance does not encapsulate a valid UUID. - */ - public function toString(): string { } - - /** - * Callback for cloning of objects. This method is private and effectively - * disables cloning of this object, since it makes no sense to clone - * immutable objects. - * - * @return void - * @throws \Error upon every invocation. - */ - private function __clone() { } -} diff --git a/ext/standard/stubs/UUIDParseException.php b/ext/standard/stubs/UUIDParseException.php deleted file mode 100644 index 82a95406f3e78..0000000000000 --- a/ext/standard/stubs/UUIDParseException.php +++ /dev/null @@ -1,83 +0,0 @@ -getMessage(); // Expected at least 32 characters, but got 3 characters - * echo $e->getInput(); // php - * echo $e->getPosition(); // 0 - * } - * - * try { - * UUID::parse('12345678-1234-1234-1234-123456789php'); - * } - * catch (UUIDParseException $e) { - * echo $e->getMessage(); // Expected hexadecimal digit, but found 'p' (0x70) - * echo $e->getInput(); // 12345678-1234-1234-1234-123456789php - * echo $e->getPosition(); // 33 - * } - * - * try { - * UUID::parse('12345678-1234-1234-1234-123456789abcdef'); - * } - * catch (UUIDParseException $e) { - * echo $e->getMessage(); // Expected no more than 32 hexadecimal digits - * echo $e->getInput(); // 12345678-1234-1234-1234-123456789abcdef - * echo $e->getPosition(); // 37 - * } - * - * ?> - * ``` - * - * @see UUID::parse() - */ -final class UUIDParseException extends \Exception { - /** @var string */ - private $input; - - /** @var int */ - private $position; - - /** - * Construct new UUID parse exception instance. - * - * @param string $reason why parsing the UUID string failed. - * @param string $input that should be parsed. - * @param int $position at which parsing failed. - * @param \Throwable|null $previous error/exception that lead to this - * failure, if any. - * @throws \ArgumentCountError if less than two or more than four arguments - * are passed. - */ - public function __construct(string $reason, string $input, int $position = 0, ?\Throwable $previous = null) { } - - /** - * Get the original input string that should have been parsed as a UUID. - * - * @return string - * @throws \ArgumentCountError if arguments are passed. - */ - public function getInput(): string { } - - /** - * Get the position in the input string where the parsing failure occurred. - * - * @return int - * @throws \ArgumentCountError if arguments are passed. - */ - public function getPosition(): int { } -}