Struct ClassBuilder

Source
pub struct ClassBuilder { /* private fields */ }
Expand description

Builder for registering a class in PHP.

Implementations§

Source§

impl ClassBuilder

Source

pub fn new<T: Into<String>>(name: T) -> Self

Creates a new class builder, used to build classes to be exported to PHP.

§Parameters
  • name - The name of the class.
Source

pub fn extends(self, parent: ClassEntryInfo) -> Self

Sets the class builder to extend another class.

§Parameters
  • parent - The parent class to extend.
Source

pub fn implements(self, interface: ClassEntryInfo) -> Self

Implements an interface on the class.

§Parameters
  • interface - Interface to implement on the class.
§Panics

Panics when the given class entry interface is not an interface.

Source

pub fn method(self, func: FunctionBuilder<'static>, flags: MethodFlags) -> Self

Adds a method to the class.

§Parameters
  • func - The function builder to add to the class.
  • flags - Flags relating to the function. See MethodFlags.
Source

pub fn property<T: Into<String>>( self, name: T, flags: PropertyFlags, docs: DocComments, ) -> Self

Adds a property to the class. The initial type of the property is given by the type of the given default. Note that the user can change the type.

§Parameters
  • name - The name of the property to add to the class.
  • default - The default value of the property.
  • flags - Flags relating to the property. See PropertyFlags.
  • docs - Documentation comments for the property.
§Panics

Function will panic if the given default cannot be converted into a Zval.

Source

pub fn constant<T: Into<String>>( self, name: T, value: impl IntoZval + 'static, docs: DocComments, ) -> Result<Self>

Adds a constant to the class. The type of the constant is defined by the type of the given default.

Returns a result containing the class builder if the constant was successfully added.

§Parameters
  • name - The name of the constant to add to the class.
  • value - The value of the constant.
  • docs - Documentation comments for the constant.
§Errors

TODO: Never?

Source

pub fn dyn_constant<T: Into<String>>( self, name: T, value: &'static dyn IntoZvalDyn, docs: DocComments, ) -> Result<Self>

Adds a constant to the class from a dyn object. The type of the constant is defined by the type of the value.

Returns a result containing the class builder if the constant was successfully added.

§Parameters
  • name - The name of the constant to add to the class.
  • value - The value of the constant.
  • docs - Documentation comments for the constant.
§Errors

TODO: Never?

Source

pub fn flags(self, flags: ClassFlags) -> Self

Sets the flags for the class.

§Parameters
  • flags - Flags relating to the class. See ClassFlags.
Source

pub fn object_override<T: RegisteredClass>(self) -> Self

Overrides the creation of the Zend object which will represent an instance of this class.

§Parameters
  • T - The type which will override the Zend object. Must implement RegisteredClass which can be derived using the php_class attribute macro.
§Panics

Panics if the class name associated with T is not the same as the class name specified when creating the builder.

Source

pub fn registration(self, register: fn(&'static mut ClassEntry)) -> Self

Function to register the class with PHP. This function is called after the class is built.

§Parameters
  • register - The function to call to register the class.
Source

pub fn docs(self, docs: DocComments) -> Self

Sets the documentation for the class.

§Parameters
  • docs - The documentation comments for the class.
Source

pub fn register(self) -> Result<()>

Builds and registers the class.

§Errors
§Panics

If no registration function was provided.

Trait Implementations§

Source§

impl From<ClassBuilder> for Class

Source§

fn from(val: ClassBuilder) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.