Complete interface impl
Description
Description
Need impl 2 interface features:
Rust struct declared as php_class and impl trait declared as php_interface
#[php_interface]
#[php(name = "ExtPhpRs\\Interface\\HelloInterface")]
trait HelloTrait {
fn say_hello(): String;
}
#[php_class]
#[php(name = "ExtPhpRs\\Test")]
struct Test;
impl HelloTrait for Test {
fn say_hello(): String {
String::from("Hello")
}
}
<?php
assert(class_exists('ExtPhpRs\Test'), 'Class not exist');
assert(interface_exists('ExtPhpRs\Interface\HelloInterface'), 'Interface not exist');
assert(is_a('ExtPhpRs\Test', ExtPhpRs\Interface\HelloInterface', true));
Convert supertrait to interface extending
#[php_interface]
#[php(name = "ExtPhpRs\\Interface\\BaseInterface")]
trait BaseTrait {}
#[php_interface]
#[php(name = "ExtPhpRs\\Interface\\ChildInterface")]
trait ChildTrait: BaseTrait { }
<?php
assert(interface_exists('ExtPhpRs\Interface\BaseInterface'), 'Interface not exist');
assert(interface_exists('ExtPhpRs\Interface\ChildInterface'), 'Interface not exist');
assert(is_a('ExtPhpRs\Interface\ChildInterface', 'ExtPhpRs\Interface\BaseInterface', true), 'Interface could extend ExtPhpRs\Interface\BaseInterface');
Additional Context
- [x] I can try implementing this feature myself (please assign me to this issue)
- would probably need a macro on the impl block, but looks good.
If you do this make this into separate MRs pls.
@Xenira i think about, how reuse attribute
#[php(implements(ce = ce_fn, stub = "InterfaceName"))]
But there is one problem, i don't know how to solve, It's how get &'static ClassEntry before module will build.
Cause in any case, we need get ClassEntry.
Don't think we have a way to do that yet.
This would be great. As an ad-hoc solution I declare my interfaces in PHP code and then link Rust-defined classes with PHP-defined interfaces using a simple technique described in https://github.com/extphprs/ext-php-rs/issues/528.
Ye, we need to do some stuff on module load for this, but should be possible.