Search code examples
laravelautoloadercomposer-php

Composer autoloader cannot find class


I have an issue with the class loading of classes.

After installing my package it does not find the class, here is its error message:

   Illuminate\Contracts\Container\BindingResolutionException  : Target class [SundayIT\ChatbotAdmin\Commands\DBM_RealtimeStats] does not exist.

Here is first few lines of the class that is missed by the autoloader:

<?php
    namespace SundayIT\ChatbotAdmin\Commands;

    use Illuminate\Console\Command;
    use Illuminate\Support\Facades\DB;
    use Symfony\Component\Console\Input\InputInterface;
    use Symfony\Component\Console\Output\OutputInterface;

    class DBM_RealtimeStats extends Command

Here is the relevant part of the package's composer.json file

    "autoload": {
        "psr-4": {
            "SundayIT\\ChatbotAdmin\\": "src/"
        }
    },

And here is the file structure: Directory screenshot

What am I missing? I have tried checking the other questions here, but I have not found a solution. Thank you


Solution

  • According to the PSR-4 standard class names should not contain underscores.

    Underscores have no special meaning in any portion of the fully qualified class name.

    That's why renaming the class to DbmRealtimeStats and the file to DbmRealtimeStats.php worked (as mentioned here).