Skip to content

Latest commit

 

History

History
75 lines (51 loc) · 2.74 KB

01.without-composer.md

File metadata and controls

75 lines (51 loc) · 2.74 KB

Getting Started Without Composer

There are some situations when using Composer for dependency management isn't a viable option. In such cases, it is possible to get by with cloning two git repositories and setting up a simple PSR-4 autoloader.

This is of course the "advanced path" for getting started, so if you are not comfortable with git, it is recommended that you get Composer up and running.

Create Your Vendor Directory

The conventional path for third-party dependencies is vendor/ in the root of your project. However, any path will do, as long as it is read-accessible to PHP.

Create this directory, and if it's something other than vendor/, simply substitute it accordingly in the following explanation.

Next, you will need to clone a few dependencies. The first is the FireText SDK, the next few are the Laminas Hydrator component and it's dependencies, these power certain operations in the SDK.

Clone the SDK

In your vendor directory, run git clone https://github.com/FireText/FireText-PHP-SDK.git

Clone The Dependencies

Now to clone the dependencies, run git clone https://github.com/laminas/laminas-hydrator.git Laminas/Hydrator then run git clone https://github.com/laminas/laminas-stdlib.git Laminas/StdLib.

Finally, run git clone https://github.com/webmozarts/assert.git Webmozart/Assert.

Create SplClassLoader

SplClassLoader is a PSR-4 autoloader, recommended as the standard implementation by the PSR working group. The implementation is available at https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md#class-example

Create a file called SplClassLoader.php in your vendor/ directory, and place the SplClassLoader code there.

autoload.php

Lastly, create your autoload file for these dependencies. In a file called autoload.php, in your vendor directory, place the following code:

<?php
require(__DIR__.'/SplClassLoader.php');

$loader = new Example\Psr4AutoloaderClass;
$loader->register();

$loader->addNamespace('FireText', __DIR__.'/FireText-PHP-SDK/src/FireText');
$loader->addNamespace('Laminas\Hydrator', __DIR__.'/Laminas/Hydrator/src');
$loader->addNamespace('Laminas\StdLib', __DIR__.'/Laminas/StdLib/src');
$loader->addNamespace('Webmozart\Assert', __DIR__.'/Webmozart/Assert/src');

Include the autoloader

Depending upon the framework - or lack thereof - that you're utilizing for your project, you will need to place an include or require statement that references the autoload.php file that you created above.

An example would be:

<?php
require_once(__DIR__.'/vendor/autoload.php');

Once the autoloader is included in your project, you will be able to continue as indicated in the remainder of the documentation.