diff --git a/src/Plugin/AbstractPlugin.php b/src/Plugin/AbstractPlugin.php index 66d6f1fb31cd8cea89d02cf8ef54a6192a7a49be..6e9d4c10412c36643f9eee8d48cf6eb8e611824b 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 1506c1dabac5bac628d2ec8930dfb3be833eb7fb..60286828a0d41844a3cf55bf19ba998db93b6f12 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 0000000000000000000000000000000000000000..9d251bf59e8962f902e8f080f21698d0a3593cc3 --- /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 0000000000000000000000000000000000000000..9f2da43096dd7f01e47bdbdc05b5d59f91227d55 --- /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(); + +} +