From ccf82661007b885ce3ce03cf577fa94fefe5b082 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 10 Nov 2018 00:31:36 +0100 Subject: [PATCH 1/3] Implemented plugin system - added plugin autoloader - plugin interface (which plugins must implement from) - implemented class method checks - new defined configuration key - plugin error handling (non-breaking because a webhook not firing should not fatal throw and be silently logged) - added more success callback keys - added the discord plugin as a default example - fixed an issue with the recent change to `endScript()` where it would display the same message after `errorPage()` --- deploy-config.orig.php | 11 +++-- deploy.php | 70 +++++++++++++++++++++++++------- plugins/Discord.class.php | 84 +++++++++++++++++++++++++++++++++++++++ plugins/Plugin.class.php | 20 ++++++++++ 4 files changed, 167 insertions(+), 18 deletions(-) create mode 100644 plugins/Discord.class.php create mode 100644 plugins/Plugin.class.php diff --git a/deploy-config.orig.php b/deploy-config.orig.php index d17ddfd..89e4528 100644 --- a/deploy-config.orig.php +++ b/deploy-config.orig.php @@ -116,9 +116,14 @@ */ define('CLEANUP_WORK_TREE', false); -/* CALLBACK_FILE: - * Filename of a PHP script containing callback functions to +/* CALLBACK_CLASSES: + * Classnames containing callback functions to * be triggered at the end of the script on success or failure. * Useful to connect to your preferred notification system. + * Note: + * - Classes must implement Plugin Interface + * - Class names have to match their file-name (case-sensitive), e.g. "Discord.class.php" has class "Discord" + * - The array keys contain only the class name, e.g. array("Discord") */ -define('CALLBACK_FILE', ''); +define('CALLBACK_CLASSES', array( +)); \ No newline at end of file diff --git a/deploy.php b/deploy.php index 84e9823..e114867 100644 --- a/deploy.php +++ b/deploy.php @@ -8,6 +8,14 @@ // Measure execution time $time = -microtime(true); +// Autoloader for plugin classes +spl_autoload_register(function($className){ + $namespace=str_replace("\\","/",__NAMESPACE__); + $className=str_replace("\\","/",$className); + $class="plugins/".(empty($namespace)?"":$namespace."/")."{$className}.class.php"; + include_once($class); +}); + /* Functions */ // Output buffering handler @@ -29,36 +37,59 @@ function errorPage($msg) { } // Command to execute at the end of the script -function endScript($msg = "") { +function endScript($msg = "",$display = false) { // Remove lock file unlink(__DIR__ . '/deploy.lock'); + // Flush buffer and prepare output for log and email ob_end_flush(); global $output; + // Remove ,