How to enable composite package in simple php?

Good afternoon, I will start by saying that I never included a composer's project in my projects, unless it was a composer package for the Laravel framework. Where you “require” it and add it to an array of providers and aliases, if necessary.

Now the problem. I have a composer package that I'm trying to play with https://github.com/WHAnonymous/Chat-API , the problem is that I don’t know how to include it in myu project, since it’s not actually done "for" laravel. Therefore, I am trying to use simple php without a framework, but I have no idea how to “download” the package, I tried Google search and only found information about creating the package.

To clarify: I can install the package in order, its php-part of the “download” package in my index.php file, which I am trying to deal with, is pretending that the index.php file is empty.

Can anyone help me out?

+8
source share
2 answers

After installing the package using composer, composer generated an autoloader, which you can include in:

require_once 'vendor/autoload.php'; 

Then you can use the package classes without additional inclusions. In your example, this could be:

 // Create an instance of WhatsProt. $w = new WhatsProt($username, $nickname, $debug); 

(taken from https://github.com/WHAnonymous/Chat-API/blob/master/examples/exampleRegister.php )

Note that this line from the example is optional when you use the composer autoloader:

 require_once('../src/whatsprot.class.php'); 
+16
source

Assuming you have a composer installed, and grasped the basics in a link posted by Paul.

You will run the following

 ~/composer install (same directory your composer.json file resides in). 

The contents of the composer.json file will be:

 { "require" : { "whatsapp/chat-api" : "2.5.4" } } 
0
source

All Articles