pub struct ClassBuilder { /* private fields */ }Expand description
Builder for registering a class in PHP.
Implementations§
Source§impl ClassBuilder
impl ClassBuilder
Sourcepub fn new<T: Into<String>>(name: T) -> Self
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.
Sourcepub fn extends(self, parent: ClassEntryInfo) -> Self
pub fn extends(self, parent: ClassEntryInfo) -> Self
Sourcepub fn implements(self, interface: ClassEntryInfo) -> Self
pub fn implements(self, interface: ClassEntryInfo) -> Self
Sourcepub fn method(self, func: FunctionBuilder<'static>, flags: MethodFlags) -> Self
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. SeeMethodFlags.
Sourcepub fn property(self, prop: ClassProperty) -> Self
pub fn property(self, prop: ClassProperty) -> Self
Sourcepub fn constant<T: Into<String>>(
self,
name: T,
value: impl IntoZval + 'static,
docs: DocComments,
flags: ConstantFlags,
) -> Result<Self>
pub fn constant<T: Into<String>>( self, name: T, value: impl IntoZval + 'static, docs: DocComments, flags: ConstantFlags, ) -> 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.flags- Visibility of the constant.
§Errors
Returns an error if value cannot be converted into a Zval.
Sourcepub fn dyn_constant<T: Into<String>>(
self,
name: T,
value: &'static dyn IntoZvalDyn,
docs: DocComments,
flags: ConstantFlags,
) -> Result<Self>
pub fn dyn_constant<T: Into<String>>( self, name: T, value: &'static dyn IntoZvalDyn, docs: DocComments, flags: ConstantFlags, ) -> 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.flags- Visibility of the constant.
§Errors
Returns an error if value cannot be converted into a Zval.
Sourcepub fn flags(self, flags: ClassFlags) -> Self
pub fn flags(self, flags: ClassFlags) -> Self
Sourcepub fn object_override<T: RegisteredClass>(self) -> Self
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 implementRegisteredClasswhich can be derived using thephp_classattribute macro.
§Panics
Panics if the class name associated with T is not the same as the
class name specified when creating the builder.
Sourcepub fn registration(
self,
register: fn(&'static mut ClassEntry, ArgInfoTables),
) -> Self
pub fn registration( self, register: fn(&'static mut ClassEntry, ArgInfoTables), ) -> Self
Function to register the class with PHP, called once the class is built.
It receives the registered class entry and the argument info tables of
the class’s methods. zend_register_functions borrows those tables for
the life of the process, so the function must park them somewhere that
lives that long — normally the class’s own
ClassMetadata static:
.registration(|ce, arg_info| {
META.set_ce(ce);
META.set_arg_info(arg_info);
})§Parameters
register- The function to call to register the class.
Sourcepub fn docs(self, docs: DocComments) -> Self
pub fn docs(self, docs: DocComments) -> Self
Sourcepub fn register(self) -> Result<()>
pub fn register(self) -> Result<()>
Builds and registers the class.
§Errors
Error::DuplicateProperty,Error::DuplicateMethodorError::DuplicateConstant- If two members share a PHP name.Error::DuplicateClass- If a class with this name, ignoring ASCII case, is already registered.Error::InvalidPointer- If the class could not be registered.Error::InvalidCString- If the class name is not a valid C string.Error::IntegerOverflow- If the property flags are not valid.- If a method or property could not be built.
§Panics
- If called outside a module startup (MINIT) function.
- If no registration function was provided.