From d974bde2c470ece25f62b587c553d9c79a2b25d2 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Tue, 14 May 2024 11:59:42 -0700 Subject: [PATCH] Add a PSR-4 loading script to allow Smarty to be used without Composer Fix a directory path --- src/Smarty.class.php | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/Smarty.class.php diff --git a/src/Smarty.class.php b/src/Smarty.class.php new file mode 100644 index 00000000..ff6e7579 --- /dev/null +++ b/src/Smarty.class.php @@ -0,0 +1,46 @@ +testInstall(); // +///////////////////////////////////////////////////////////////////// + +define('__SMARTY_DIR', __DIR__ . '/'); + +// Global function declarations +require_once(__SMARTY_DIR . "/functions.php"); + +spl_autoload_register(function ($class) { + // Class prefix + $prefix = 'Smarty\\'; + + // Does the class use the namespace prefix? + $len = strlen($prefix); + if (strncmp($prefix, $class, $len) !== 0) { + // If not, move to the next registered autoloader + return; + } + + // Hack off the prefix part + $relative_class = substr($class, $len); + + // Build a path to the include file + $file = __SMARTY_DIR . str_replace('\\', '/', $relative_class) . '.php'; + + // If the file exists, require it + if (file_exists($file)) { + //print "
Class $class maps to $file
\n"; + + require_once($file); + } +}); + +// vim: tabstop=4 shiftwidth=4 noexpandtab autoindent softtabstop=4