Skip to content
Snippets Groups Projects
Commit 6c970f95 authored by Dyszczo's avatar Dyszczo
Browse files

Merge branch 'feature/get-hookable' into 'master'

added method: get_hookable_instance_by_class_name

See merge request !15
parents 1d98f903 06214b90
No related branches found
No related tags found
1 merge request!15added method: get_hookable_instance_by_class_name
Pipeline #7635 failed with stages
in 2 minutes and 36 seconds
...@@ -11,5 +11,14 @@ interface HookableCollection extends Hookable { ...@@ -11,5 +11,14 @@ interface HookableCollection extends Hookable {
*/ */
public function add_hookable( Hookable $hookable_object ); public function add_hookable( Hookable $hookable_object );
/**
* Get hookable instance.
*
* @param string $class_name Class name.
*
* @return false|Hookable
*/
public function get_hookable_instance_by_class_name( $class_name );
} }
...@@ -23,6 +23,22 @@ trait HookableParent { ...@@ -23,6 +23,22 @@ trait HookableParent {
$this->hookable_objects[] = $hookable_object; $this->hookable_objects[] = $hookable_object;
} }
/**
* Get hookable instance.
*
* @param string $class_name Class name.
*
* @return false|Hookable
*/
public function get_hookable_instance_by_class_name( $class_name ) {
foreach ( $this->hookable_objects as $hookable_object ) {
if ( $hookable_object instanceof $class_name ) {
return $hookable_object;
}
}
return false;
}
/** /**
* Run hooks method on all hookable objects. * Run hooks method on all hookable objects.
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment