From d974bde2c470ece25f62b587c553d9c79a2b25d2 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Tue, 14 May 2024 11:59:42 -0700 Subject: [PATCH 1/7] 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 000000000..ff6e75797 --- /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 From 11cc46c9420fc1b48806cd918592899eb540f6f5 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Tue, 14 May 2024 12:23:52 -0700 Subject: [PATCH 2/7] Add standalone instantiation documentation --- docs/getting-started.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/docs/getting-started.md b/docs/getting-started.md index 5b49fffdb..b9a6c4cfc 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -25,9 +25,17 @@ Here's how you create an instance of Smarty in your PHP scripts: ```php Date: Tue, 14 May 2024 12:28:56 -0700 Subject: [PATCH 3/7] Correct a path in the example --- src/Smarty.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Smarty.class.php b/src/Smarty.class.php index ff6e75797..aa5ecf201 100644 --- a/src/Smarty.class.php +++ b/src/Smarty.class.php @@ -7,7 +7,7 @@ // backwards compatible with previous versions of Smarty. // // // // Example: // -// require_once("/path/to/smarty/Smarty.class.php"); // +// require_once("/path/to/smarty/src/Smarty.class.php"); // // // // $smarty = new Smarty\Smarty; // // $smarty->testInstall(); // From d0270fb8ea334bb8422d36216b02cd3b4284b2cb Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Wed, 15 May 2024 08:11:01 -0700 Subject: [PATCH 4/7] Move to /libs/ --- {src => libs}/Smarty.class.php | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {src => libs}/Smarty.class.php (100%) diff --git a/src/Smarty.class.php b/libs/Smarty.class.php similarity index 100% rename from src/Smarty.class.php rename to libs/Smarty.class.php From 2042979701c7f975bfcc94b0484430df8fa07b4e Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Wed, 15 May 2024 08:11:50 -0700 Subject: [PATCH 5/7] Update example docs to point at libs/ --- docs/getting-started.md | 2 +- libs/Smarty.class.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/getting-started.md b/docs/getting-started.md index b9a6c4cfc..3628fd203 100644 --- a/docs/getting-started.md +++ b/docs/getting-started.md @@ -33,7 +33,7 @@ $smarty = new Smarty(); // or ... // Instantiated directly -require("/path/to/smarty/src/Smarty.class.php"); +require("/path/to/smarty/libs/Smarty.class.php"); use Smarty\Smarty; $smarty = new Smarty(); ``` diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index aa5ecf201..c5d9caa16 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -7,13 +7,13 @@ // backwards compatible with previous versions of Smarty. // // // // Example: // -// require_once("/path/to/smarty/src/Smarty.class.php"); // +// require_once("/path/to/smarty/libs/Smarty.class.php"); // // // // $smarty = new Smarty\Smarty; // // $smarty->testInstall(); // ///////////////////////////////////////////////////////////////////// -define('__SMARTY_DIR', __DIR__ . '/'); +define('__SMARTY_DIR', __DIR__ . '/../src/'); // Global function declarations require_once(__SMARTY_DIR . "/functions.php"); From 32c8339492d58c12160c5e1bbdf2a5e5c6c74187 Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Wed, 15 May 2024 08:45:01 -0700 Subject: [PATCH 6/7] Some fixes per Wisskid in the PR --- libs/Smarty.class.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libs/Smarty.class.php b/libs/Smarty.class.php index c5d9caa16..459fe2cfb 100644 --- a/libs/Smarty.class.php +++ b/libs/Smarty.class.php @@ -37,10 +37,6 @@ // 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 From 5de6092a5634b69878d03c49c6caae7b655f4b0a Mon Sep 17 00:00:00 2001 From: Simon Wisselink Date: Fri, 24 May 2024 00:15:02 +0200 Subject: [PATCH 7/7] added changelog --- changelog/1017.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/1017.md diff --git a/changelog/1017.md b/changelog/1017.md new file mode 100644 index 000000000..cb9dd5552 --- /dev/null +++ b/changelog/1017.md @@ -0,0 +1 @@ +- Added a PSR-4 loading script to allow Smarty to be used without Composer [#1017](https://github.com/smarty-php/smarty/pull/1017)