So looking at the docs online and user comments here and there, Composer seems to be a great tool and I've used npm before so I can imagine it would be super convenient to use. There's only one problem, I cannot get packages I install with Composer to work no matter what I try.
I am trying to install the JWT package by Lcobucci. I had an existing project I wanted to add this to but the way the existing project is setup is I have a functions.php file in the root that is then included by all the other php scripts I have in my project. The functions file contains includes for DB plugins, DB connection, includes, etc.
I installed the package with Composer directly using
composer require lcobucci/jwt
I also tried installing it by creating the JSON file and running
composer install
like it says to do in the docs.
I then tried including the autoload.php file in my include using
require __DIR__. "/vendor/autoload.php";
I then added
use Lcobucci\JWT\Parser; //JWT Parser Class
but it kept complaining that the Class doesn't exist when I tried using it.
I then tried manually using require_once on all the actual PHP files in the src folder of the composer package. Still nothing. I tried switching things around.. trying to see what files PHP included using
get_included_files();
I also tried
composer dumpautoload
but all I got was
Generating autoload files
I seem to be missing something which is why I hesitated from posting this question but I've spent a couple hours on this now and this is getting frustrating. Is there anything I've missed?
If it helps, I'm on Windows 10 64 bit running WAMP server with PHP ver 5.6.25 and 1.6.5.
EDIT: I just realised it might help if I disclosed my file structure. ROOT |-functions.php |-register |-index.php |vendor |-autoload.php |-composer |-lcobucci |-src
I am trying to access the JWT library from the index.php file in the register folder which has an include to the functions.php file. functions works as described above.
So I fixed this issue by putting the use
statement in the index.php file (i.e. the one that included the functions.php file instead of in the functions.php file that was included)
Turns out the usage of a namespace/class doesn't carry over.. Or I'm not entirely sure but I'll update this answer if I get more info.