diff --git a/src/Plugin/HookableCollection.php b/src/Plugin/HookableCollection.php index 74bc337f42f33813106444e74a9cb0b767037be1..def6ec9d2bd5d3df16b7325f2ef5307ef55ef6e9 100644 --- a/src/Plugin/HookableCollection.php +++ b/src/Plugin/HookableCollection.php @@ -11,5 +11,14 @@ interface HookableCollection extends Hookable { */ 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 ); + } diff --git a/src/Plugin/HookableParent.php b/src/Plugin/HookableParent.php index 937ff77efe5ba9c3528e69c3fd78586369e9db34..5aca3784d46ede75c9938c0248f5fd0c8c9b605f 100644 --- a/src/Plugin/HookableParent.php +++ b/src/Plugin/HookableParent.php @@ -23,6 +23,22 @@ trait HookableParent { $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. */