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 NO_CONSTRUCTOR: bool = false;
    const DOC_COMMENTS: DocComments = _;

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

    // Provided methods
    fn method_properties() -> &'static [PropertyDescriptor<Self>] { ... }
    fn static_properties(    ) -> &'static [(&'static str, PropertyFlags, Option<&'static (dyn IntoZvalDyn + Sync)>, DocComments)] { ... }
    fn interface_implementations() -> Vec<ClassEntryInfo> { ... }
    fn interface_method_implementations(    ) -> Vec<(FunctionBuilder<'static>, MethodFlags)> { ... }
    fn default_init() -> Option<Self> { ... }
    fn clone_fn() -> Option<fn(&Self) -> Self> { ... }
    fn gc_trace(&self, _roots: &mut GcRoots) { ... }
}
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 NO_CONSTRUCTOR: bool = false

Whether the class declares no constructor when it has none of its own, set by #[php(no_constructor)]: new then creates an object initialized with Default::default(), as for a PHP class without a constructor. Otherwise a class without a constructor gets one that throws.

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, handlers, and property descriptors.

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

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, ConstantFlags)]

Returns the constants provided by the class.

Provided Methods§

Source

fn method_properties() -> &'static [PropertyDescriptor<Self>]

Returns method properties (from #[php(getter)]/#[php(setter)]). Resolved via autoref specialization in the macro-generated code.

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 interface_implementations() -> Vec<ClassEntryInfo>

Returns interfaces from #[php_impl_interface] trait implementations.

This method is generated by the #[php_class] macro and uses the inventory crate to collect interface registrations across crate boundaries at link time.

The default implementation returns an empty vector. The macro overrides this to iterate over InterfaceRegistration entries matching this type.

Source

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

Returns methods from #[php_impl_interface] trait implementations.

This method is generated by the #[php_class] macro and uses the inventory crate to collect method registrations across crate boundaries at link time.

The default implementation returns an empty vector. The macro overrides this to iterate over MethodRegistration entries matching this type.

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.

Source

fn clone_fn() -> Option<fn(&Self) -> Self>

The function that copies the Rust value for PHP’s clone operator.

The #[php_class] macro returns Some(<Self as Clone>::clone) for types that implement Clone. When it is None, the class has no clone handler, like the uncloneable classes of PHP: clone throws an Error and ReflectionClass::isCloneable() returns false.

Source

fn gc_trace(&self, _roots: &mut GcRoots)

Reports the PHP values held in the Rust fields of this object to the cycle collector.

The crate::php_class macro generates it: it calls GcTrace::gc_trace one time for each field whose type implements GcTrace. The default reports nothing.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl RegisteredClass for Closure

Available on crate feature closure only.