2
votes

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.

1
remove trailing slash after src. then try to run composer updateAri Djemana
No difference. According to the composer documentation it should contain the trailing slash it seems - getcomposer.org/doc/04-schema.md#psr-0Martyn
Oh, well I changed it to PSR-4 and it finds the class now :) PSR-4 or PSR-0 is fine, I just don't want to have to keep running composer dump-autoload as with classmap.Martyn

1 Answers

2
votes

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