Method of loading third party class library in Laravel
- 2021-09-16 06:33:44
- OfStack
Laravel Version: 5.5
There are many third-party libraries that do not make Composer, but are loaded as require. For this class library, we can use it with only small-grained modifications. I take extreme geetest and mail service SendCloud as examples.
Establish the SDK directory for the third party in the Laravel framework
mkdir app/Libraries
SDK with geetest and SendCloud
After officially downloading the relevant SDK, move to the app/Libraries directory:
app/Libraries/sendcloud-php-sdk
app/Libraries/gt3-php-sdk
Pay attention to whether the. git directory exists under the respective SDK directory. If so, remember to recursively delete the. git directory. It is the. git directory under the SDK directory, so don't delete the error.
Modify the composer. json file
...
"autoload": {
"classmap": [
"database/seeds",
"database/factories",
"app/Libraries/sendcloud-php-sdk/lib",
"app/Libraries/gt3-php-sdk"
],
"psr-4": {
"App\\": "app/"
}
},
...
In autoload- > Under classmap, app/Libraries/sendcloud-php-sdk/lib and app/Libraries/gt3-php-sdk are added.
Execute the composer command
In the Laravel project:
composer dump-autoload
That's it.
About using
For example, it is used in Laravel controller
$objSendCloud = new \SendCloud(API_USER, API_KEY[, VERSION]);
$objGeetestLib = new \GeetestLib(CAPTCHA_ID, PRIVATE_KEY);