Using PHP Packages without Composer

Composer is a “Dependency Manager for PHP”.

If you do not have Apache command line access, like most people using a shared hosting account, instructions for installing a PHP package with Composer won’t work (at least not using the instructions given):

The preferred method of installation is [composer]( In your project root (not web root), create a minimum [composer.json]( file:
"require": {
"VerticalTab/Pillow": "x.x.x"
Replace "x.x.x" above with the tag number you want to use.

Next, get composer and use it to install (again, in your project root)
$ wget
$ php composer.phar install
This will put the library into your vendors directory.

Then you would use this line of code in your program to access the package:
require 'vendor/autoload.php';

Well, you don’t need Composer to install this package, you can insert some standard PHP code that works, into your program. (But you won’t have all the version checking that Composer does.)

This PHP code replaces the autoload.php:
function __autoload($class_name) {

The package I am using as an example is a Zillow API package, in the VerticalTab folder, inside the current folder, and contains these files:

List all the package’s .PHP files using a special syntax. Convert the names like below. The backslashes are required; forward slashes are incorrect syntax. Drop the .php extension

use VerticalTab\Pillow\Chart;
use VerticalTab\Pillow\Comps;
use VerticalTab\Pillow\Date;
use VerticalTab\Pillow\HttpClient;
use VerticalTab\Pillow\Links;
use VerticalTab\Pillow\Property;
use VerticalTab\Pillow\Proxy;
use VerticalTab\Pillow\Range;
use VerticalTab\Pillow\ResultSet;
use VerticalTab\Pillow\SearchResults;
use VerticalTab\Pillow\Service;
use VerticalTab\Pillow\Xml;
use VerticalTab\Pillow\Zestimate;

Now all the package code is accessible to your program.

Inside the package are namespace commands, e.g. VerticalTab/Pillow/SearchResults.php has namespace VerticalTab\Pillow;





Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.