Skip to content

Commit

Permalink
Make enum code unconditional
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Sep 5, 2024
1 parent 7c3a06f commit 488bc9c
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 12 deletions.
4 changes: 0 additions & 4 deletions src/phongo_bson.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
#include "bson/bson.h"

#include <php.h>
#if PHP_VERSION_ID >= 80100
#include <Zend/zend_enum.h>
#endif
#include <Zend/zend_interfaces.h>
#include <Zend/zend_portability.h>

Expand Down Expand Up @@ -67,11 +65,9 @@ static inline bool phongo_is_class_instantiatable(const zend_class_entry* ce)
return false;
}

#if PHP_VERSION_ID >= 80100
if (ce->ce_flags & ZEND_ACC_ENUM) {
return false;
}
#endif /* PHP_VERSION_ID < 80100 */

return true;
}
Expand Down
6 changes: 0 additions & 6 deletions src/phongo_bson_encode.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
#include "bson/bson.h"

#include <php.h>
#if PHP_VERSION_ID >= 80100
#include <Zend/zend_enum.h>
#endif
#include <Zend/zend_interfaces.h>

#include "php_phongo.h"
Expand Down Expand Up @@ -293,7 +291,6 @@ static void php_phongo_bson_append_object(bson_t* bson, php_phongo_field_path* f
return;
}

#if PHP_VERSION_ID >= 80100
if (Z_TYPE_P(object) == IS_OBJECT && Z_OBJCE_P(object)->ce_flags & ZEND_ACC_ENUM) {
if (Z_OBJCE_P(object)->enum_backing_type == IS_UNDEF) {
char* path_string = php_phongo_field_path_as_string(field_path);
Expand All @@ -305,7 +302,6 @@ static void php_phongo_bson_append_object(bson_t* bson, php_phongo_field_path* f
php_phongo_bson_append(bson, field_path, flags, key, key_len, zend_enum_fetch_case_value(Z_OBJ_P(object)));
return;
}
#endif /* PHP_VERSION_ID >= 80100 */

{
bson_t child;
Expand Down Expand Up @@ -520,12 +516,10 @@ static void php_phongo_zval_to_bson_internal(zval* data, php_phongo_field_path*
/* For the error handling that follows, we can safely assume that we
* are at the root level, since php_phongo_bson_append_object would
* have already been called for a non-root level. */
#if PHP_VERSION_ID >= 80100
if (Z_OBJCE_P(data)->ce_flags & ZEND_ACC_ENUM) {
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "Enum %s cannot be serialized as a root element", ZSTR_VAL(Z_OBJCE_P(data)->name));
return;
}
#endif /* PHP_VERSION_ID >= 80100 */

if (instanceof_function(Z_OBJCE_P(data), php_phongo_type_ce)) {
phongo_throw_exception(PHONGO_ERROR_UNEXPECTED_VALUE, "%s instance %s cannot be serialized as a root element", ZSTR_VAL(php_phongo_type_ce->name), ZSTR_VAL(Z_OBJCE_P(data)->name));
Expand Down
2 changes: 0 additions & 2 deletions src/phongo_compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,9 @@ const char* zend_get_object_type_case(const zend_class_entry* ce, zend_bool uppe
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
return upper_case ? "Interface" : "interface";
}
#if PHP_VERSION_ID >= 80100
if (ce->ce_flags & ZEND_ACC_ENUM) {
return upper_case ? "Enum" : "enum";
}
#endif /* PHP_VERSION_ID > 80100 */
return upper_case ? "Class" : "class";
}
#endif /* PHP_VERSION_ID < 80200 */

0 comments on commit 488bc9c

Please sign in to comment.