How to Use Composer in Plain PHP
Currently, there are many good frameworks available to be installed using composer. But there's a time when I just want to quickly test a PHP package. How is this possible? I will share how I do this in the article below.
Assuming you know some basic composer commands and have installed composer on your system, here are what you need to do:
- Install the package with composer
composer require whatsapp/chat-api
- After installing the package with composer, composer has generated an autoloader that you can include on your main PHP file.
- Use the class(es) from the package without further includes.
$w = new WhatsProt($username, $nickname, $debug);
- That's it. Now you can try it with another package available on packagist.
I hope that you now know how to composer in plain PHP without any Framework. If you run into any issues or have any feedback feel free to drop a comment below.