-
Notifications
You must be signed in to change notification settings - Fork 715
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 |
I am happy with Composer., it makes my life much easier. Using Composer, put everything with PSR-4 together and thats it. Without composer, the day, someone in Smarty decides to load another library with composer you are done. So I am just curious, why you dont use it? |
@wblessen my application is very simple. I haven't needed the complexity of composer for any projects yet. Smarty used to be able to be loaded without composer. I'm just trying to keep things simple. |
I reworked some of the above and came up with the following define('SMARTY_DIR', "/home/username/html/include/smarty/src/");
spl_autoload_register(function ($class) {
// Class prefix
$prefix = 'Smarty\\';
// If we are not a member of above class skip
if (!str_starts_with($class, $prefix)) { return; }
// Hack off the prefix part
$relative_class = substr($class, strlen($prefix));
// 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)) { require_once($file); }
}); Then in another script I have require_once("load_smarty.php");
// Instantiate the class
$obj = new Smarty\Smarty(); I need to do some more testing, but this appears to work. |
Don't forget src/functions.php! |
Oh good call... I wrote up my implementation and submitted a PR to allow using Smarty without Composer. |
Thanks Scott, I was also looking for this when we try to migrate to v5 soon.
…On Tue, May 14, 2024 at 9:18 PM Scott Baker ***@***.***> wrote:
Oh good call... I wrote up my implementation and submitted a PR to allow
using Smarty without Composer.
—
Reply to this email directly, view it on GitHub
<#999 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAI7NGIG5SRQOW2JREA3XBTZCJPR5AVCNFSM6AAAAABGOAHDNCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCMJQHE3TQMBZG4>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
I haven't needed composer yet for my projects so I was looking for this. Thanks. |
It worked without composer. thank you. |
Is there any way for installation Smarty 5 without composer?
The text was updated successfully, but these errors were encountered: