Skip to main content

RegisteredClass

Trait RegisteredClass 

Source
pub trait RegisteredClass: Sized + 'static {
    const CLASS_NAME: &'static str;
    const BUILDER_MODIFIER: Option<fn(ClassBuilder) -> ClassBuilder>;
    const EXTENDS: Option<ClassEntryInfo>;
    const IMPLEMENTS: &'static [ClassEntryInfo];
    const FLAGS: ClassFlags = _;
    const DOC_COMMENTS: DocComments = _;

    // Required methods
    fn get_metadata() -> &'static ClassMetadata<Self>;
    fn get_properties<'a>() -> HashMap<&'static str, PropertyInfo<'a, Self>>;
    fn method_builders() -> Vec<(FunctionBuilder<'static>, MethodFlags)>;
    fn constructor() -> Option<ConstructorMeta<Self>>;
    fn constants(    ) -> &'static [(&'static str, &'static dyn IntoZvalDyn, DocComments)];

    // Provided methods
    fn static_properties(    ) -> &'static [(&'static str, PropertyFlags, Option<&'static (dyn IntoZvalDyn + Sync)>, DocComments)] { ... }
    fn default_init() -> Option<Self> { ... }
}
Expand description

Implemented on Rust types which are exported to PHP. Allows users to get and set PHP properties on the object.

Required Associated Constants§

Source

const CLASS_NAME: &'static str

PHP class name of the registered class.

Source

const BUILDER_MODIFIER: Option<fn(ClassBuilder) -> ClassBuilder>

Function to be called when building the class. Allows user to modify the class at runtime (add runtime constants etc).

Source

const EXTENDS: Option<ClassEntryInfo>

Parent class entry. Optional.

Source

const IMPLEMENTS: &'static [ClassEntryInfo]

Interfaces implemented by the class.

Provided Associated Constants§

Source

const FLAGS: ClassFlags = _

PHP flags applied to the class.

Source

const DOC_COMMENTS: DocComments = _

Doc comments for the class.

Required Methods§

Source

fn get_metadata() -> &'static ClassMetadata<Self>

Returns a reference to the class metadata, which stores the class entry and handlers.

This must be statically allocated, and is usually done through the macro@php_class macro.

Source

fn get_properties<'a>() -> HashMap<&'static str, PropertyInfo<'a, Self>>

Returns a hash table containing the properties of the class.

The key should be the name of the property and the value should be a reference to the property with reference to self. The value is a [PropertyInfo].

Instead of using this method directly, you should access the properties through the ClassMetadata::get_properties function, which builds the hashmap one and stores it in memory.

Source

fn method_builders() -> Vec<(FunctionBuilder<'static>, MethodFlags)>

Returns the method builders required to build the class.

Source

fn constructor() -> Option<ConstructorMeta<Self>>

Returns the class constructor (if any).

Source

fn constants() -> &'static [(&'static str, &'static dyn IntoZvalDyn, DocComments)]

Returns the constants provided by the class.

Provided Methods§

Source

fn static_properties() -> &'static [(&'static str, PropertyFlags, Option<&'static (dyn IntoZvalDyn + Sync)>, DocComments)]

Returns the static properties provided by the class.

Static properties are declared at the class level and managed by PHP, not by Rust handlers. Each tuple contains (name, flags, default, docs). The default value is optional - None means null default.

Source

fn default_init() -> Option<Self>

Returns a default instance of the class for immediate initialization.

This is used when PHP creates an object without calling the constructor, such as when throwing exceptions via zend_throw_exception_ex. For types that derive Default, this will return Some(Self::default()), allowing the object to be properly initialized even without a constructor call.

§Returns

Some(Self) if the type can be default-initialized, None otherwise.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl RegisteredClass for Closure

Available on crate feature closure only.