|
| 1 | +#[macro_use] |
| 2 | +extern crate ext_php_rs_derive; |
| 3 | +/// Doc comments for MyInterface. |
| 4 | +/// This is a basic interface example. |
| 5 | +trait MyInterface { |
| 6 | + /// Doc comments for my_method. |
| 7 | + /// This method does something. |
| 8 | + fn my_method(&self, arg: i32) -> String; |
| 9 | +} |
| 10 | +pub struct PhpInterfaceMyInterface; |
| 11 | +impl ::ext_php_rs::class::RegisteredClass for PhpInterfaceMyInterface { |
| 12 | + const CLASS_NAME: &'static str = "MyInterface"; |
| 13 | + const BUILDER_MODIFIER: Option< |
| 14 | + fn(::ext_php_rs::builders::ClassBuilder) -> ::ext_php_rs::builders::ClassBuilder, |
| 15 | + > = None; |
| 16 | + const EXTENDS: Option<::ext_php_rs::class::ClassEntryInfo> = None; |
| 17 | + const FLAGS: ::ext_php_rs::flags::ClassFlags = ::ext_php_rs::flags::ClassFlags::Interface; |
| 18 | + const IMPLEMENTS: &'static [::ext_php_rs::class::ClassEntryInfo] = &[]; |
| 19 | + const DOC_COMMENTS: &'static [String] = &[ |
| 20 | + " Doc comments for MyInterface.", |
| 21 | + " This is a basic interface example.", |
| 22 | + ]; |
| 23 | + fn get_metadata() -> &'static ::ext_php_rs::class::ClassMetadata<Self> { |
| 24 | + static METADATA: ::ext_php_rs::class::ClassMetadata<PhpInterfaceMyInterface> = ::ext_php_rs::class::ClassMetadata::new(); |
| 25 | + &METADATA |
| 26 | + } |
| 27 | + fn method_builders() -> Vec< |
| 28 | + ( |
| 29 | + ::ext_php_rs::builders::FunctionBuilder<'static>, |
| 30 | + ::ext_php_rs::flags::MethodFlags, |
| 31 | + ), |
| 32 | + > { |
| 33 | + <[_]>::into_vec( |
| 34 | + ::alloc::boxed::box_new([ |
| 35 | + ( |
| 36 | + ::ext_php_rs::builders::FunctionBuilder::new_abstract("myMethod") |
| 37 | + .arg( |
| 38 | + ::ext_php_rs::args::Arg::new( |
| 39 | + "arg", |
| 40 | + <i32 as ::ext_php_rs::convert::FromZvalMut>::TYPE, |
| 41 | + ), |
| 42 | + ) |
| 43 | + .not_required() |
| 44 | + .returns( |
| 45 | + <String as ::ext_php_rs::convert::IntoZval>::TYPE, |
| 46 | + false, |
| 47 | + <String as ::ext_php_rs::convert::IntoZval>::NULLABLE, |
| 48 | + ) |
| 49 | + .docs( |
| 50 | + &[ |
| 51 | + " Doc comments for my_method.", |
| 52 | + " This method does something.", |
| 53 | + ], |
| 54 | + ), |
| 55 | + ::ext_php_rs::flags::MethodFlags::Public |
| 56 | + | ::ext_php_rs::flags::MethodFlags::Abstract, |
| 57 | + ), |
| 58 | + ]), |
| 59 | + ) |
| 60 | + } |
| 61 | + fn constructor() -> Option<::ext_php_rs::class::ConstructorMeta<Self>> { |
| 62 | + None |
| 63 | + } |
| 64 | + fn constants() -> &'static [( |
| 65 | + &'static str, |
| 66 | + &'static dyn ext_php_rs::convert::IntoZvalDyn, |
| 67 | + ext_php_rs::describe::DocComments, |
| 68 | + )] { |
| 69 | + &[] |
| 70 | + } |
| 71 | + fn get_properties<'a>() -> ::std::collections::HashMap< |
| 72 | + &'static str, |
| 73 | + ::ext_php_rs::internal::property::PropertyInfo<'a, Self>, |
| 74 | + > { |
| 75 | + { |
| 76 | + ::core::panicking::panic_fmt(format_args!("Not supported for Interface")); |
| 77 | + }; |
| 78 | + } |
| 79 | +} |
| 80 | +impl<'a> ::ext_php_rs::convert::FromZendObject<'a> for &'a PhpInterfaceMyInterface { |
| 81 | + #[inline] |
| 82 | + fn from_zend_object( |
| 83 | + obj: &'a ::ext_php_rs::types::ZendObject, |
| 84 | + ) -> ::ext_php_rs::error::Result<Self> { |
| 85 | + let obj = ::ext_php_rs::types::ZendClassObject::< |
| 86 | + PhpInterfaceMyInterface, |
| 87 | + >::from_zend_obj(obj) |
| 88 | + .ok_or(::ext_php_rs::error::Error::InvalidScope)?; |
| 89 | + Ok(&**obj) |
| 90 | + } |
| 91 | +} |
| 92 | +impl<'a> ::ext_php_rs::convert::FromZendObjectMut<'a> |
| 93 | +for &'a mut PhpInterfaceMyInterface { |
| 94 | + #[inline] |
| 95 | + fn from_zend_object_mut( |
| 96 | + obj: &'a mut ::ext_php_rs::types::ZendObject, |
| 97 | + ) -> ::ext_php_rs::error::Result<Self> { |
| 98 | + let obj = ::ext_php_rs::types::ZendClassObject::< |
| 99 | + PhpInterfaceMyInterface, |
| 100 | + >::from_zend_obj_mut(obj) |
| 101 | + .ok_or(::ext_php_rs::error::Error::InvalidScope)?; |
| 102 | + Ok(&mut **obj) |
| 103 | + } |
| 104 | +} |
| 105 | +impl<'a> ::ext_php_rs::convert::FromZval<'a> for &'a PhpInterfaceMyInterface { |
| 106 | + const TYPE: ::ext_php_rs::flags::DataType = ::ext_php_rs::flags::DataType::Object( |
| 107 | + Some( |
| 108 | + <PhpInterfaceMyInterface as ::ext_php_rs::class::RegisteredClass>::CLASS_NAME, |
| 109 | + ), |
| 110 | + ); |
| 111 | + #[inline] |
| 112 | + fn from_zval(zval: &'a ::ext_php_rs::types::Zval) -> ::std::option::Option<Self> { |
| 113 | + <Self as ::ext_php_rs::convert::FromZendObject>::from_zend_object(zval.object()?) |
| 114 | + .ok() |
| 115 | + } |
| 116 | +} |
| 117 | +impl<'a> ::ext_php_rs::convert::FromZvalMut<'a> for &'a mut PhpInterfaceMyInterface { |
| 118 | + const TYPE: ::ext_php_rs::flags::DataType = ::ext_php_rs::flags::DataType::Object( |
| 119 | + Some( |
| 120 | + <PhpInterfaceMyInterface as ::ext_php_rs::class::RegisteredClass>::CLASS_NAME, |
| 121 | + ), |
| 122 | + ); |
| 123 | + #[inline] |
| 124 | + fn from_zval_mut( |
| 125 | + zval: &'a mut ::ext_php_rs::types::Zval, |
| 126 | + ) -> ::std::option::Option<Self> { |
| 127 | + <Self as ::ext_php_rs::convert::FromZendObjectMut>::from_zend_object_mut( |
| 128 | + zval.object_mut()?, |
| 129 | + ) |
| 130 | + .ok() |
| 131 | + } |
| 132 | +} |
| 133 | +impl ::ext_php_rs::convert::IntoZendObject for PhpInterfaceMyInterface { |
| 134 | + #[inline] |
| 135 | + fn into_zend_object( |
| 136 | + self, |
| 137 | + ) -> ::ext_php_rs::error::Result< |
| 138 | + ::ext_php_rs::boxed::ZBox<::ext_php_rs::types::ZendObject>, |
| 139 | + > { |
| 140 | + Ok(::ext_php_rs::types::ZendClassObject::new(self).into()) |
| 141 | + } |
| 142 | +} |
| 143 | +impl ::ext_php_rs::convert::IntoZval for PhpInterfaceMyInterface { |
| 144 | + const TYPE: ::ext_php_rs::flags::DataType = ::ext_php_rs::flags::DataType::Object( |
| 145 | + Some( |
| 146 | + <PhpInterfaceMyInterface as ::ext_php_rs::class::RegisteredClass>::CLASS_NAME, |
| 147 | + ), |
| 148 | + ); |
| 149 | + const NULLABLE: bool = false; |
| 150 | + #[inline] |
| 151 | + fn set_zval( |
| 152 | + self, |
| 153 | + zv: &mut ::ext_php_rs::types::Zval, |
| 154 | + persistent: bool, |
| 155 | + ) -> ::ext_php_rs::error::Result<()> { |
| 156 | + use ::ext_php_rs::convert::IntoZendObject; |
| 157 | + self.into_zend_object()?.set_zval(zv, persistent) |
| 158 | + } |
| 159 | +} |
0 commit comments