Unable to download Non-Laravel Composer package

The first time I try to download a Composer package that does not use a Laravel service provider or facade.

I am trying to install this package: https://github.com/mollie/mollie-api-php

I followed the steps to install the package using Composer.

At the top of my controller, I added:

require_once base_path('vendor/Mollie/API/Client.php'); 

I get the following error:

main (): Crash on opening '../vendor/Mollie/API/Client.php' (Include_path = ': /Applications/MAMP/ben/PHP/php7.0.0/Library/PHP')

It cannot find the file. Although the path in error is the path where the class is located. Are there a few more steps I should take?

Package Structure:

enter image description here

composer.json from the package:

 "autoload": { "psr-0": { "": "src/" } 

Update: My controller has this namespace

 namespace App\Http\Controllers; 

Therefore, when I just try to update my class, it obviously cannot find this class inside this namespace. So how do I ignore the namespace for class 1

Because this will not work inside this controller:

 $mollie = new Mollie_API_Client; 
+5
source share
1 answer

As noted in the comments, Composer handles autoload for you - manual re-request is not necessary and can cause problems.

my controller has a namespace, so it is trying to load this class from the namespace, how do I ignore it for class 1?

You can refer to the class with the leading \, ie new \Mollie_API_Client , which tells PHP to look in the root, and not in the controller namespace.

You can also put use Mollie_API_Client; to the top of the file to do a similar thing. For this reason, you will see use instructions at the top of a large number of Laravel files.

+5
source

Source: https://habr.com/ru/post/1247526/


All Articles