From 869ce50f3163834cf3dbf330798aecc5460e1343 Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Tue, 4 Mar 2014 13:41:58 +0000 Subject: [PATCH] Add \Mibew\Plugin\AbstractPlugin class --- .../classes/Mibew/Plugin/AbstractPlugin.php | 172 ++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 src/mibew/libs/classes/Mibew/Plugin/AbstractPlugin.php diff --git a/src/mibew/libs/classes/Mibew/Plugin/AbstractPlugin.php b/src/mibew/libs/classes/Mibew/Plugin/AbstractPlugin.php new file mode 100644 index 00000000..25aa9f89 --- /dev/null +++ b/src/mibew/libs/classes/Mibew/Plugin/AbstractPlugin.php @@ -0,0 +1,172 @@ +weight = $config['weight']; + } + + // Save configurations + $this->config = $config; + } + + /** + * Implementation of {@link \Mibew\Plugin\PluginInterface::getFilesPath()}. + * + * Determine file path based on path to the file which contains a class of + * concrete plugin. + * + * @return string + */ + public function getFilesPath() + { + static $path = false; + + if ($path === false) { + // Get full name of the file with the current plugin class + $reflection = new \ReflectionClass($this); + $file_path = $reflection->getFileName(); + + // Remove FS root from the path + if (strpos($file_path, MIBEW_FS_ROOT) === 0) { + $file_path = substr($file_path, strlen(MIBEW_FS_ROOT)); + } + + // Remove file name + $path_parts = explode( + DIRECTORY_SEPARATOR, + trim($file_path, DIRECTORY_SEPARATOR) + ); + array_pop($path_parts); + $path = implode(DIRECTORY_SEPARATOR, $path_parts); + } + + return $path; + } + + /** + * Implementation of {@link \Mibew\Plugin\PluginInterface::getWeight()}. + * + * Returns value of the AbstractPlugin::$weight property. Thus the + * property can be used to change weight of the plugin. + * + * @return int + */ + public function getWeight() + { + return $this->weight; + } + + /** + * Implementation of {@link \Mibew\Plugin\PluginInterface::initialized()}. + * + * Returns value of the AbstractPlugin::$initialized property. Thus the + * property can be used to change initialization status. + * + * @return boolean + */ + public function initialized() + { + return $this->initialized; + } + + /** + * Implementation of + * {@link \Mibew\Plugin\PluginInterface::getDependencies()}. + * + * Returns an empty array to tell the Plugin Manager that the plugin has + * no dependencies. + * + * @return array + */ + public static function getDependencies() + { + return array(); + } + + /** + * Implementation of {@link \Mibew\Plugin\PluginInterface::getInfo()}. + * + * Returns an empty array. + * + * @return array + */ + public static function getInfo() + { + return array(); + } + + /** + * Implementation of {@link \Mibew\Plugin\PluginInterface::install()}. + * + * The method does not perform any actions just returns boolean true. + * + * @return boolean + */ + public static function install() + { + return true; + } + + /** + * Implementation of {@link \Mibew\Plugin\PluginInterface::uninstall()}. + * + * The method does not perform any actions just returns boolean true. + * + * @return boolean + */ + public static function uninstall() + { + return true; + } +}