AmbroseChapel
AmbroseChapel

Reputation: 12087

I have PHP code I need to use—how do I install it?

I'm trying to get some code set up to use an particular company's API.

I have experience with Perl and if I need a module installed, I type cpan ModuleName and most of the time it Just Works. How does that work with PHP code of similar complexity?

The company in question have a github repository with PHP Client system to access their API, which looks much the same as a perl Module.

I can git clone it, I can download it, but then what? Do I have to install it? There are no installation instructions. Or do I just start using it? There's a composer.json file in there. Do I need to run a composer command so it can figure out and install its dependencies like a CPAN module would? Will it install into system folders or just right there in whatever directory it happens to be in? I feel like there ought be some kind of official installation process because there's a /tests/ folder in the files I downloaded.

Their example code literally starts like this:

<?php

    /* @var $CompanyName \CompanyName_Api */
    $CompanyName = new \CompanyName_Api();
    /* do interesting stuff */

and that's it. Of course nothing works if I just do that because it doesn't know where the CompanyName_Api files are. It works if I add this:

<?php
    include('/full/path/to/downloaded/files/CompanyName/src/Api.php');

is that all I need to do?

Upvotes: 0

Views: 168

Answers (2)

Ashish Ranade
Ashish Ranade

Reputation: 605

First your need to install an PHP environment like PHP, Apache and all stuff, then you need to clone that file from the git repository or just download it, then navigate to the dir and fire the command composer install. It will install all of the dependencies required for that package. After that, run the code from the browser -- the package api code may have the auto loader file which you need to include in your current package and autoloader will do all the stuff for you. Add your folder structure and file structure so that you get a better answer on this.

Upvotes: 1

Cyclonecode
Cyclonecode

Reputation: 30001

In order to install all dependencies defined in composer.json you would run the following command inside the project directory:

composer install

This will find and download the dependencies into the vendor directory and it will also generate an optimized autoloader.

To autoload your own source files you'll need to add it to the autoload section in the composer.json file:

Upvotes: 3

Related Questions