From 1f094e400623918cc53c6ceb5fe38a9938b841c6 Mon Sep 17 00:00:00 2001 From: Grzegorz Rola <grola@seostudio.pl> Date: Fri, 20 Jul 2018 11:15:10 +0200 Subject: [PATCH] Hookable --- src/Plugin/AbstractPlugin.php | 19 ++++++------------- src/Plugin/Hookable.php | 23 ----------------------- src/Plugin/HookableCollection.php | 23 +++++++++++++++++++++++ src/Plugin/HookablePuginDependant.php | 24 ++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 36 deletions(-) create mode 100644 src/Plugin/HookableCollection.php create mode 100644 src/Plugin/HookablePuginDependant.php diff --git a/src/Plugin/AbstractPlugin.php b/src/Plugin/AbstractPlugin.php index 66d6f1f..6e9d4c1 100644 --- a/src/Plugin/AbstractPlugin.php +++ b/src/Plugin/AbstractPlugin.php @@ -8,7 +8,7 @@ namespace WPDesk\PluginBuilder\Plugin; * @author Grzegorz * */ -abstract class AbstractPlugin implements \WPDesk_Translable, Hookable { +abstract class AbstractPlugin implements \WPDesk_Translable, HookableCollection, Hookable { /** @var \WPDesk_Plugin_Info */ protected $plugin_info; @@ -53,23 +53,16 @@ abstract class AbstractPlugin implements \WPDesk_Translable, Hookable { /** * Add hookable object. + * + * @param Hookable|HookablePluginDependant $hookable_object Hookable object. */ public function add_hookable( $hookable_object ) { - $hookable_object->set_plugin( $this ); + if ( $hookable_object instanceof HookablePluginDependant ) { + $hookable_object->set_plugin( $this ); + } $this->hookable_objects[] = $hookable_object; } - /** - * Set plugin - currently do nothing. - * - * @param AbstractPlugin $plugin Plugin. - * - * @return null - */ - public function set_plugin( $plugin ) { - return; - } - /** * @return void */ diff --git a/src/Plugin/Hookable.php b/src/Plugin/Hookable.php index 1506c1d..6028682 100644 --- a/src/Plugin/Hookable.php +++ b/src/Plugin/Hookable.php @@ -4,29 +4,6 @@ namespace WPDesk\PluginBuilder\Plugin; interface Hookable { - /** - * Add hookable object. - * - * @param Hookable $hookable_object Hookable object to add. - */ - public function add_hookable( $hookable_object ); - - /** - * Set Plugin. - * - * @param AbstractPlugin $plugin Plugin. - * - * @return null - */ - public function set_plugin( $plugin ); - - /** - * Get plugin. - * - * @return AbstractPlugin. - */ - public function get_plugin(); - /** * Init hooks (actions and filters). * diff --git a/src/Plugin/HookableCollection.php b/src/Plugin/HookableCollection.php new file mode 100644 index 0000000..9d251bf --- /dev/null +++ b/src/Plugin/HookableCollection.php @@ -0,0 +1,23 @@ +<?php + +namespace WPDesk\PluginBuilder\Plugin; + +interface HookableCollection { + + /** + * Add hookable object. + * + * @param Hookable $hookable_object Hookable object to add. + */ + public function add_hookable( $hookable_object ); + + + /** + * Init hooks (actions and filters). + * + * @return null + */ + public function hooks(); + +} + diff --git a/src/Plugin/HookablePuginDependant.php b/src/Plugin/HookablePuginDependant.php new file mode 100644 index 0000000..9f2da43 --- /dev/null +++ b/src/Plugin/HookablePuginDependant.php @@ -0,0 +1,24 @@ +<?php + +namespace WPDesk\PluginBuilder\Plugin; + +interface HookablePluginDependant extends Hookable { + + /** + * Set Plugin. + * + * @param AbstractPlugin $plugin Plugin. + * + * @return null + */ + public function set_plugin( $plugin ); + + /** + * Get plugin. + * + * @return AbstractPlugin. + */ + public function get_plugin(); + +} + -- GitLab