Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: rename bind_* to bound_* #192

Merged
merged 1 commit into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions phper/src/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ fn find_global_class_entry_ptr(name: impl AsRef<str>) -> *mut zend_class_entry {

/// The [StateClass] holds [zend_class_entry] and inner state, created by
/// [Module::add_class](crate::modules::Module::add_class) or
/// [ClassEntity::bind_class].
/// [ClassEntity::bound_class].
///
/// When the class registered (module initialized), the [StateClass] will
/// be initialized, so you can use the [StateClass] to new stateful
Expand Down Expand Up @@ -436,7 +436,7 @@ pub struct ClassEntity<T: 'static> {
parent: Option<StateClass<()>>,
interfaces: Vec<Interface>,
constants: Vec<ConstantEntity>,
bind_class: StateClass<T>,
bound_class: StateClass<T>,
state_cloner: Option<Rc<StateCloner>>,
_p: PhantomData<(*mut (), T)>,
}
Expand Down Expand Up @@ -474,7 +474,7 @@ impl<T: 'static> ClassEntity<T> {
parent: None,
interfaces: Vec::new(),
constants: Vec::new(),
bind_class: StateClass::null(),
bound_class: StateClass::null(),
state_cloner: None,
_p: PhantomData,
}
Expand Down Expand Up @@ -673,7 +673,7 @@ impl<T: 'static> ClassEntity<T> {
parent.cast(),
);

self.bind_class.bind(class_ce);
self.bound_class.bind(class_ce);

for interface in &self.interfaces {
let interface_ce = interface.as_class_entry().as_ptr();
Expand Down Expand Up @@ -761,7 +761,7 @@ impl<T: 'static> ClassEntity<T> {
///
/// pub fn make_foo_class() -> ClassEntity<()> {
/// let mut class = ClassEntity::<()>::new_with_default_state_constructor("Foo");
/// let foo_class = class.bind_class();
/// let foo_class = class.bound_class();
/// class.add_static_method("newInstance", Visibility::Public, move |_| {
/// let mut object = foo_class.init_object()?;
/// Ok::<_, phper::Error>(object)
Expand All @@ -770,8 +770,8 @@ impl<T: 'static> ClassEntity<T> {
/// }
/// ```
#[inline]
pub fn bind_class(&self) -> StateClass<T> {
self.bind_class.clone()
pub fn bound_class(&self) -> StateClass<T> {
self.bound_class.clone()
}
}

Expand All @@ -794,7 +794,7 @@ pub struct InterfaceEntity {
method_entities: Vec<MethodEntity>,
constants: Vec<ConstantEntity>,
extends: Vec<Box<dyn Fn() -> &'static ClassEntry>>,
bind_interface: Interface,
bound_interface: Interface,
}

impl InterfaceEntity {
Expand All @@ -805,7 +805,7 @@ impl InterfaceEntity {
method_entities: Vec::new(),
constants: Vec::new(),
extends: Vec::new(),
bind_interface: Interface::null(),
bound_interface: Interface::null(),
}
}

Expand Down Expand Up @@ -858,7 +858,7 @@ impl InterfaceEntity {
null_mut(),
);

self.bind_interface.bind(class_ce);
self.bound_interface.bind(class_ce);

for interface in &self.extends {
let interface_ce = interface().as_ptr();
Expand Down Expand Up @@ -889,8 +889,8 @@ impl InterfaceEntity {

/// Get the bound interface.
#[inline]
pub fn bind_interface(&self) -> Interface {
self.bind_interface.clone()
pub fn bound_interface(&self) -> Interface {
self.bound_interface.clone()
}
}

Expand Down
8 changes: 4 additions & 4 deletions phper/src/modules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,17 +206,17 @@ impl Module {

/// Register class to module.
pub fn add_class<T>(&mut self, class: ClassEntity<T>) -> StateClass<T> {
let bind_class = class.bind_class();
let bound_class = class.bound_class();
self.class_entities
.push(unsafe { transmute::<ClassEntity<T>, ClassEntity<()>>(class) });
bind_class
bound_class
}

/// Register interface to module.
pub fn add_interface(&mut self, interface: InterfaceEntity) -> Interface {
let bind_interface = interface.bind_interface();
let bound_interface = interface.bound_interface();
self.interface_entities.push(interface);
bind_interface
bound_interface
}

/// Register constant to module.
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/src/classes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ pub fn integrate(module: &mut Module) {

fn integrate_a(module: &mut Module) {
let mut class = ClassEntity::new("IntegrationTest\\A");
let integrate_a_class = class.bind_class();
let integrate_a_class = class.bound_class();

class.add_property("name", Visibility::Private, "default");
class.add_property("number", Visibility::Private, 100);
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/tests/php/classes.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
$property_name = $reflection_class->getProperty("name");
assert_true($property_name->isPrivate());

// Test bind_class
// Test bound_class
$a_instance = IntegrationTest\A::newInstance();
assert_true($a_instance instanceof IntegrationTest\A);
assert_eq($a_instance->speak(), "name: default, number: 100");
Expand Down Expand Up @@ -104,4 +104,4 @@ class Foo2 extends IntegrationTest\Foo {}
// Test module class extends module class
$bar = new \IntegrationTest\BarExtendsFoo; //Bar should extend Foo
$reflection = new ReflectionClass($bar);
assert_true($reflection->isSubclassOf(IntegrationTest\Foo::class));
assert_true($reflection->isSubclassOf(IntegrationTest\Foo::class));
Loading