Search code examples
phpcomposer-phppsr-0

Class not found with Composer autoload and PSR-0


I'm trying to use PSR-0 instead of classmap in composer but having some difficulty. It appears that my json file is correct yet the class I'm trying to access is not being picked up. Can someone please have a look and see if they can spot where I'm going wrong:

Here is what I have in composer.json:

"autoload": {
    "psr-0": {
        "MartynBiz\\Slim3Controller\\": "src/"
    }
},

Below is my folder structure:

$ tree .
.
|-- README.md
|-- composer.json
|-- composer.lock
|-- phpunit.xml
|-- src
|   |-- Controller.php
|   |-- Http
|   |   |-- Request.php
|   |   `-- Response.php
|   `-- Test
|       `-- PHPUnit
|           `-- TestCase.php
`-- tests
    |-- bootstrap.php
    `-- library
        `-- ControllerTest.php

Here is my Controller class:

<?php
namespace MartynBiz\Slim3Controller;

abstract class Controller
{

Also, I can confirm that composer autoload script has been included.


Solution

  • Use PSR-4 instead. PSR-0 requires the prefix to be included in the document tree (i.e. src/MartynBiz/Slim3Controller/Controller.php).