use std::{any::TypeId, collections::HashMap, marker::PhantomData};
use crate::{
builders::FunctionBuilder,
class::{ClassEntryInfo, ConstructorMeta, RegisteredClass},
convert::{IntoZval, IntoZvalDyn},
describe::DocComments,
flags::MethodFlags,
internal::property::PropertyInfo,
};
pub struct InterfaceRegistration {
pub class_type_id: TypeId,
pub interface_getter: fn() -> ClassEntryInfo,
}
inventory::collect!(InterfaceRegistration);
pub trait InterfaceMethodsProvider<T: RegisteredClass> {
fn get_interface_methods(self) -> Vec<(FunctionBuilder<'static>, MethodFlags)>;
}
impl<T: RegisteredClass> InterfaceMethodsProvider<T> for &'_ PhpClassImplCollector<T> {
#[inline]
fn get_interface_methods(self) -> Vec<(FunctionBuilder<'static>, MethodFlags)> {
Vec::new()
}
}
pub struct PhpClassImplCollector<T: RegisteredClass>(PhantomData<T>);
impl<T: RegisteredClass> Default for PhpClassImplCollector<T> {
#[inline]
fn default() -> Self {
Self(PhantomData)
}
}
pub trait PhpClassImpl<T: RegisteredClass> {
fn get_methods(self) -> Vec<(FunctionBuilder<'static>, MethodFlags)>;
fn get_method_props<'a>(self) -> HashMap<&'static str, PropertyInfo<'a, T>>;
fn get_constructor(self) -> Option<ConstructorMeta<T>>;
fn get_constants(self) -> &'static [(&'static str, &'static dyn IntoZvalDyn, DocComments)];
}
impl<T: RegisteredClass> PhpClassImpl<T> for &'_ PhpClassImplCollector<T> {
#[inline]
fn get_methods(self) -> Vec<(FunctionBuilder<'static>, MethodFlags)> {
Vec::default()
}
#[inline]
fn get_method_props<'a>(self) -> HashMap<&'static str, PropertyInfo<'a, T>> {
HashMap::default()
}
#[inline]
fn get_constructor(self) -> Option<ConstructorMeta<T>> {
Option::default()
}
#[inline]
fn get_constants(self) -> &'static [(&'static str, &'static dyn IntoZvalDyn, DocComments)] {
&[]
}
}
impl<T: RegisteredClass + IntoZval> IntoZval for PhpClassImplCollector<T> {
const TYPE: crate::flags::DataType = T::TYPE;
const NULLABLE: bool = T::NULLABLE;
#[inline]
fn set_zval(self, _: &mut crate::types::Zval, _: bool) -> crate::error::Result<()> {
unreachable!();
}
}