Reputation: 96
I would like to use following GitHub repo in my Laravel application:
https://github.com/khanamiryan/php-qrcode-detector-decoder
It doesn't have composer set up nor it can be found from Packagist. I tried to use regular php_require but it tells me "Class 'App\Http\Controllers\QrReader' not found".
Using php_require feels wrong anyways. What is the correct way to handle situation like this?
Upvotes: 1
Views: 403
Reputation: 3127
Because this github project does not have a composer.json file, I don't think you can use it with composer.
However, you could branch the repo, make your own copy, and add a composer file to it. Then you'd be able to add it to your main project's composer.json file:
{
"repositories": [
{
"type": "git",
"url": "https://github.com/your-git-account/php-qrcode-detector-decoder"
}
],
"require": {
"your-git-account/php-qrcode-detector-decoder": "dev-master"
}
Hope this helps!
(Source https://getcomposer.org/doc/05-repositories.md#loading-a-package-from-a-vcs-repository)
Upvotes: 0
Reputation: 87719
Create a new directory in your app root
mkdir third-party
cd third-party
Clone the repo
git clone https://github.com/khanamiryan/php-qrcode-detector-decoder
Edit your composer.json file and add it to the classmap:
"classmap": [
"database",
"third-party/php-qrcode-detector-decoder"
],
Update class maps:
composer dumpautoload
And you should see in your vendor/composer/autoload_classmap.php
'Zxing\\Binarizer' => $baseDir . '/third-party/php-qrcode-detector-decoder/lib/Binarizer.php',
'Zxing\\BinaryBitmap' => $baseDir . '/third-party/php-qrcode-detector-decoder/lib/BinaryBitmap.php',
...
Then you just have to use it:
use Zxing\Reader;
Upvotes: 2
Reputation: 4684
I think the major class is QrReader(). You can use this class as controller class but you need to extend the controller class and fix imports. You can import this class as third party class on your laravel controller too. Do you need to use QrReader() class? Then just put all the library files App\Libraries and the main class in App\classes. Or you can do in our own way too. But follow the following 1) Manage namespaces 2) import the class to your controller by using
use App\classes\QrReader
Finally, you will have access to all the methods defined in the imported class. But in you main class you need to correct the path and dependencies of libraries files.
You can try this tutorial too: How to use external classes
You can read the discussion here (Nice) Best way to import third party classes
Upvotes: 0