New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Smarty5: installation without composer #999
Comments
With Smarty v4.x there definitely was a way. Checking the docs and the source for v5.x it's not as clear. I would very interested in not using composer as well. If this gets figured out we should update the docs with this info. |
This was discussed here |
That's pretty nebulous... I'd really like to see "official" documentation on how to do this. I'm not a huge fan of composer. |
Okay. Every (well, almost every, I guess) composer.json file has this section called "autoload". For Smarty it currently reads:
So, register a PSR-4 autoloader for the Smarty namespace that reads from the src folder and include src/functions.php once. That should do it. |
For Smarty 4.x my instantiation is:
I've been doing it that way for 8+ years on Smarty 3.x and 4.x. I'd like to do something similar with Smarty 5.x.
I get |
FWIW I'm 100% willing to write up some documentation and submit a PR for how load Smarty without composer once I get it working. Clearly there are other people that desire this functionality as well. It would be good to have it in the official documentation. |
I asked ChatGPT to write it, seems like this might work:
If not, just run composer require smarty/smarty && composer dump-autoload and see what's in vendor/autoload.php |
El código brindado por @wisskid funciona bien, lo acabo de comprobar <?php
define('SMARTY', __DIR__ . DIRECTORY_SEPARATOR . 'smarty' . DIRECTORY_SEPARATOR);
spl_autoload_register(function ($class) {
// Namespace prefix
$prefix = 'Smarty\\';
// Base directory for the namespace prefix
$baseDir = SMARTY;
// Does the class use the namespace prefix?
$len = strlen($prefix);
if (strncmp($prefix, $class, $len) !== 0) return;
// Get the relative class name
$relativeClass = substr($class, $len);
// Replace namespace prefix with base directory, replace namespace separators with directory separators, and append .php
$file = $baseDir . str_replace('\\', '/', $relativeClass) . '.php';
// If the file exists, require it
if (file_exists($file)) require $file;
}); Pero en donde vayan a utilizar use Smarty\Smarty;
$smarty = new Smarty(); ya que había intentado poner
PD: Ahora resulta que tengo que realizar cambios para adaptar los plugins que había realizado y la forma de agregar otra carpeta de plugins es otra, la verdad prefiero la versión Smarty 4.5.1, para mí, era más fácil y simple de usar... Esta versión tiene muchos cambios. |
Is there any way for installation Smarty 5 without composer?
The text was updated successfully, but these errors were encountered: