Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add preliminary support for enums #201

Merged
merged 6 commits into from
Apr 6, 2025
Merged

Conversation

jmjoy
Copy link
Member

@jmjoy jmjoy commented Apr 5, 2025

This pull request introduces significant changes to the phper project, adding support for PHP enums, improving documentation, and making several internal adjustments to enhance functionality and maintainability.

Enum Support:

  • Added a new module phper::enums to provide Rust wrappers for PHP enum functionality, supporting pure enums, integer-backed enums, and string-backed enums.
  • Updated phper-build/src/lib.rs to include configuration for phper_enum_supported when PHP version is 8.1 or higher.
  • Included documentation on how to register enums in phper-doc/doc/_06_module/_08_register_enum/index.md.
  • Modified phper-doc/src/lib.rs to include the new enum registration documentation module.
  • Added necessary includes for enums in phper-sys/php_wrapper.c.

Documentation and Configuration:

  • Enhanced Cargo.toml to include the sealed crate and updated documentation configurations. [1] [2]
  • Enabled conditional compilation attributes for documentation in phper/src/lib.rs.

Internal Adjustments:

  • Made several internal structs and functions in phper/src/classes.rs public within the crate for broader usage. [1] [2] [3] [4] [5]
  • Included EnumEntity in the phper/src/modules.rs module imports.

@jmjoy
Copy link
Member Author

jmjoy commented Apr 6, 2025

Solve #161

@jmjoy jmjoy marked this pull request as ready for review April 6, 2025 00:19
@jmjoy jmjoy merged commit c66a28f into phper-framework:master Apr 6, 2025
22 checks passed
@jmjoy jmjoy deleted the feat branch April 6, 2025 00:19
@frederikbosch
Copy link

Fantastic, great work. Thank you.

@frederikbosch
Copy link

As I am directly implementing this in my ext-fs-notify library, I am wondering how to construct an enum from the Rust side. I'd like to return it from a method. I can add a docs-PR for that once I know how to do it.

@jmjoy
Copy link
Member Author

jmjoy commented Apr 6, 2025

As I am directly implementing this in my ext-fs-notify library, I am wondering how to construct an enum from the Rust side. I'd like to return it from a method. I can add a docs-PR for that once I know how to do it.

Your request requires further improvement of the enums API, using the PHP function zend_enum_get_case_cstr. I’ll add support for this later.

@frederikbosch
Copy link

That's great. I wish I could you with that, but I am afraid I can't. The knowledge gap I have to bridge is one I cannot make right now. Thanks again for your efforts.

@jmjoy
Copy link
Member Author

jmjoy commented Apr 7, 2025

That's great. I wish I could you with that, but I am afraid I can't. The knowledge gap I have to bridge is one I cannot make right now. Thanks again for your efforts.

Please refer to https://github.com/phper-framework/phper/blob/master/phper-doc/doc/_06_module/_08_register_enum/index.md#using-enumcase-for-direct-access

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants