Saumini Navaratnam
Saumini Navaratnam

Reputation: 8850

How do I include external library phar file in Laravel

I have couple of library phar files, where do I include those in laravel 5 application?

So far what I tried is created a folder under vendor directory and added the phar files I needed and finally included them in the vendor/autoload.php file as below.

// Include internal library
include(__DIR__.'/internal/composer/vendor/autoload.php');
require('phar://'.__DIR__.'/internal/Common.phar/index.php');
require('phar://'.__DIR__.'/internal/client.phar/index.php');

This is working, but the issue is when ever you do composer update, the autoload.php file get override.

Is there a better way to do this ?

Upvotes: 1

Views: 1368

Answers (1)

Saumini Navaratnam
Saumini Navaratnam

Reputation: 8850

Added a folder outside vendor and copied the phar files there and finally edited the composer.json file as following to include the phar files.

"autoload": {
        "classmap": ...,
        "psr-4": ...,
        "files" : [
            "extension/internal/client.phar",
            "extension/internal/Common.phar",
            "extension/internal/composer/vendor/autoload.php"]
    }

Upvotes: 2

Related Questions