Skip to main content

ClassMetadata

Struct ClassMetadata 

Source
pub struct ClassMetadata<T: 'static> { /* private fields */ }
Expand description

Stores the class entry, handlers, and property descriptors for a Rust type which has been exported to PHP. Usually allocated statically.

Implementations§

Source§

impl<T: 'static> ClassMetadata<T>

Source

pub const fn new(field_properties: &'static [PropertyDescriptor<T>]) -> Self

Creates a new class metadata instance with the given field properties.

Source§

impl<T: RegisteredClass> ClassMetadata<T>

Source

pub fn handlers(&self) -> &ZendObjectHandlers

Returns an immutable reference to the object handlers contained inside the class metadata.

Source

pub fn has_ce(&self) -> bool

Checks if the class entry has been stored, returning a boolean.

Source

pub fn ce(&self) -> &'static ClassEntry

Retrieves a reference to the stored class entry.

The class entry lives until the module shuts down. A SAPI that starts the module again in the same process (FrankenPHP worker restarts) registers a new one, so do not keep the reference across a restart: call this again instead.

§Panics

Panics if there is no class entry stored inside the class metadata.

Source

pub fn set_ce(&self, ce: &'static mut ClassEntry)

Stores a reference to a class entry inside the class metadata.

Called during MINIT, before any concurrent access. A SAPI can shut the module down and start it again in the same process (FrankenPHP does on a worker restart or opcache_reset()): MINIT then registers the class again, and the new entry replaces the one freed with the old module.

Source

pub fn set_arg_info(&self, arg_info: OwnedArgInfo)

Takes ownership of the argument info tables of this class’s methods.

zend_register_functions keeps zend_internal_function.arg_info pointing into these until the module shuts down, so they must outlive registration. Called from ClassBuilder::register, once per MINIT: when the SAPI starts the module again in the same process, the new tables replace those of the class freed with the old module.

Source

pub fn find_property(&self, name: &str) -> Option<&PropertyDescriptor<T>>

Finds a property descriptor by name.

Checks field properties first, then method properties. Linear scan is used since typical PHP classes have few properties and cache locality beats hashing at small N.

Source

pub fn field_properties(&self) -> &'static [PropertyDescriptor<T>]

Returns the field properties (from #[php(prop)] struct fields).

Source

pub fn method_properties(&self) -> &'static [PropertyDescriptor<T>]

Returns the method properties (from #[php(getter)]/#[php(setter)]). Lazily initialized on first access from RegisteredClass::method_properties().

Source

pub fn all_properties(&self) -> impl Iterator<Item = &PropertyDescriptor<T>>

Iterates over all properties (field + method).

Source

pub fn mangled_names(&self) -> &[Box<str>]

Returns the PHP-convention mangled names of every property, in all_properties order.

Private properties mangle to "\0Class\0name", protected ones to "\0*\0name", public ones keep their name. Computed once per class on first access, one allocation for the process lifetime.

Trait Implementations§

Source§

impl<T: 'static> Default for ClassMetadata<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> !Freeze for ClassMetadata<T>

§

impl<T> RefUnwindSafe for ClassMetadata<T>
where &'static [PropertyDescriptor<T>]: RefUnwindSafe, OnceCell<&'static [PropertyDescriptor<T>]>: RefUnwindSafe, PhantomData<Atomic<*mut T>>: RefUnwindSafe,

§

impl<T> Send for ClassMetadata<T>
where &'static [PropertyDescriptor<T>]: Send, OnceCell<&'static [PropertyDescriptor<T>]>: Send, PhantomData<Atomic<*mut T>>: Send,

§

impl<T> Sync for ClassMetadata<T>
where &'static [PropertyDescriptor<T>]: Sync, OnceCell<&'static [PropertyDescriptor<T>]>: Sync, PhantomData<Atomic<*mut T>>: Sync,

§

impl<T> Unpin for ClassMetadata<T>
where &'static [PropertyDescriptor<T>]: Unpin, OnceCell<&'static [PropertyDescriptor<T>]>: Unpin, PhantomData<Atomic<*mut T>>: Unpin,

§

impl<T> UnsafeUnpin for ClassMetadata<T>
where &'static [PropertyDescriptor<T>]: UnsafeUnpin, OnceCell<&'static [PropertyDescriptor<T>]>: UnsafeUnpin, PhantomData<Atomic<*mut T>>: UnsafeUnpin,

§

impl<T> UnwindSafe for ClassMetadata<T>
where &'static [PropertyDescriptor<T>]: UnwindSafe, OnceCell<&'static [PropertyDescriptor<T>]>: UnwindSafe, PhantomData<Atomic<*mut T>>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.