Search code examples
phpcomposer-phpautoloadpsr-4

Using Composer Autoloader with PSR-4


I'm looking at examples, and I cannot get my code to work.

Directory Structure

app
    src
        company
            FileExport
                FileExport.php
                FileExportInterface.php
            Validator
    vendor
        ...

My composer.json

"require": {
    "monolog/monolog": "1.9.1",
    "ilya/belt": "2.1.1"
},
"autoload": {
    "psr-4": {"Company\\": "src"}
}

Namespace is Company\FileExport.

Classes in vendor work fine, but not mine. I've run composer update as well.


Solution

  • Your autoload should look like so

       "autoload": {
            "psr-4": {"Company\\": "src/company/"}
        }