NealVDV
NealVDV

Reputation: 2532

How to autoload with composer?

I am trying to get the composer autoloader to work for an hour now and I'm out of ideas. Looked at about 2 dozen stack overflow answers but still don't understand how it works:

I am trying to create a new ClientRepository() from this composer package.

See example of usage

My php file

<?php
require __DIR__ . '/../vendor/autoload.php';

$clientRepository = new ClientRepository();

I already tried the following:

Structure of composer folders

enter image description here

Upvotes: 1

Views: 172

Answers (1)

deminy
deminy

Reputation: 121

Class ClientRepository is not part of package league/oauth2-server although it's used in some sample code in package documentation. You will need to create it first (by implementing interface \League\OAuth2\Server\Repositories\ClientRepositoryInterface) then use it, which is too complicate for the question.

If you only want to see how Composer works for that package, following piece of code should work:

<?php
require __DIR__ . '/../vendor/autoload.php';

$request = new League\OAuth2\Server\RequestTypes\AuthorizationRequest();
?>

or

<?php
use League\OAuth2\Server\RequestTypes\AuthorizationRequest;

require __DIR__ . '/../vendor/autoload.php';

$request = new AuthorizationRequest();
?>

Upvotes: 3

Related Questions