G
G
Gleb Zhukov2020-02-07 12:25:40
PHP
Gleb Zhukov, 2020-02-07 12:25:40

What should I do to make composer load library files?

I'm trying to figure out the composer's autoloader. I re-read psr-4 psr-0 several times already, the file structure after installation (by composer) looks like this:

/vendor/machetero/PackageName/Client/Producer.php - this file contains the class \PackageName\Client\Producer
/vendor/ machetero/PackageName/Client/Consumer.php - this file contains the class \PackageName\Client\Consumer
and so on.

I connect /vendor/autoload.php

I try to create objects:
$producer = \PackageName\Client\Producer();
$consumer = \PackageName\Client\Consumer();

resulting in an error class not found.

What am I doing wrong ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Oleg Prilepa, 2020-02-07
@machetero

You need to have an autoload section in composer.json:

"autoload": {
    "psr-4": {
      "PackageName\\": ""
    }
  },

And then don't forget to run composer update to rebuild vendor/autoload.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question