From 2c53ef2f80d663d24459c5075b24d306b9cff9a9 Mon Sep 17 00:00:00 2001 From: jedrzejchalubek Date: Wed, 14 Aug 2019 16:48:14 +0200 Subject: [PATCH 1/2] feat(): Introduce own PSR-4 autoloader Using own autoloader simplifies usage of package as WordPress plugin. That way it's not required to install composer in a plugin itself.It is ready for working right away --- tonik-gin.php | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tonik-gin.php b/tonik-gin.php index 543419c..ae8dfc4 100644 --- a/tonik-gin.php +++ b/tonik-gin.php @@ -4,7 +4,7 @@ Plugin Name: tonik/gin Plugin URI: http://tonik.pl Description: Foundation of the Tonik WordPress Starter Theme. Provides all custom functionalities which it offers. -Version: 3.0.0-dev +Version: 3.1.0-dev Author: Tonik Author URI: http://tonik.pl License: GPL-2.0+ @@ -13,7 +13,30 @@ Text Domain: tonik.gin */ -if (file_exists($composer = __DIR__ . '/vendor/autoload.php')) { - require $composer; -} +spl_autoload_register(function ($class) { + // Namespace prefix + $prefix = 'Tonik\\'; + // Base directory for the namespace prefix + $base_dir = __DIR__ . '/src/'; + + // Does the class use the namespace prefix? + $len = strlen($prefix); + if (strncmp($prefix, $class, $len) !== 0) { + // No, move to the next registered autoloader + return; + } + + // Get the relative class name + $relative_class = substr($class, $len); + + // Replace the namespace prefix with the base + // directory, replace namespace separators with directory + // separators in the relative class name, append with .php + $file = $base_dir . str_replace('\\', '/', $relative_class) . '.php'; + + // If the file exists, require it + if (file_exists($file)) { + require $file; + } +}); From 535e81c893b5e5c2589b3e2ab8e38528becabb97 Mon Sep 17 00:00:00 2001 From: jedrzejchalubek Date: Wed, 14 Aug 2019 16:50:43 +0200 Subject: [PATCH 2/2] chore(): Bump v3.1.0 --- tonik-gin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tonik-gin.php b/tonik-gin.php index ae8dfc4..685f1c1 100644 --- a/tonik-gin.php +++ b/tonik-gin.php @@ -4,7 +4,7 @@ Plugin Name: tonik/gin Plugin URI: http://tonik.pl Description: Foundation of the Tonik WordPress Starter Theme. Provides all custom functionalities which it offers. -Version: 3.1.0-dev +Version: 3.1.0 Author: Tonik Author URI: http://tonik.pl License: GPL-2.0+