mirror of
https://github.com/smarty-php/smarty.git
synced 2025-08-02 17:34:26 +02:00
Add a PSR-4 loading script to allow Smarty to be used without Composer
Fix a directory path
This commit is contained in:
46
src/Smarty.class.php
Normal file
46
src/Smarty.class.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////
|
||||||
|
// This is a stub PSR-4 loading script that gets all the pieces of //
|
||||||
|
// Smarty 5.x loaded without requiring the use of composer. It's //
|
||||||
|
// not really a 'class' file, but the name is used so we're //
|
||||||
|
// backwards compatible with previous versions of Smarty. //
|
||||||
|
// //
|
||||||
|
// Example: //
|
||||||
|
// require_once("/path/to/smarty/Smarty.class.php"); //
|
||||||
|
// //
|
||||||
|
// $smarty = new Smarty\Smarty; //
|
||||||
|
// $smarty->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 "<div>Class <b>$class</b> maps to <code>$file</code></div>\n";
|
||||||
|
|
||||||
|
require_once($file);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// vim: tabstop=4 shiftwidth=4 noexpandtab autoindent softtabstop=4
|
Reference in New Issue
Block a user