Adam McGurk
Adam McGurk

Reputation: 476

Composer not generating autoload files package made by me

I hate to add more to the noise of "autoload isn't working!!!!!", but I can't seem to get this problem figured out, and I figured getting some fresh eyes on it would get the problem in a lot less time. Here is my index.php file:

<?php
declare(strict_types=1);

require_once 'vendor/autoload.php';
require_once 'model/PageNav.php';

use ShinePHP\{Crud, CrudException, EasyHttp, EasyHttpException, HandleData, HandleDataException};

// ALWAYS serve over encrypted channels
try {
    EasyHttp::checkHttps();
} catch (EasyHttpException $ex) {
    echo $ex;
}


try {

    // check if it's a GET request, if it is, serve page, if not, do nothing
    if (EasyHttp::isRequestMethod('GET')) {
        $Page = new PageNav('Home', 'view/home.php');
        $Page->buildPage();
        exit;
    }

} 
catch (EasyHttpException $ex) {
    echo $ex;
}

So obviously I am using a package from composer called ShinePHP (it's one I've made, and I'm still working on the documentation, so I'm just using it for my own projects at the moment, composer just makes package management so easy!)
ANYWAYS...because I'm writing this question, I'm obviously getting the following error:

Fatal error: Uncaught Error: Class 'ShinePHP\EasyHttp' not found in /Applications/XAMPP/xamppfiles/htdocs/KRTY/src/index.php:11 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/KRTY/src/index.php on line 11

Now, I haven't manually touched the composer.json file, so here it is:

{
    "require": {
        "adammcgurk/shine-php": "~0.0.1"
    },

    "autoload": {
        "psr-4": {
            "ShinePHP\\": "src/"
        }
    }
}

I'm not getting any errors on requiring the vendor/autoload.php file (and I've tried changing the path to something that doesn't exist like vendor/alkdjfladksf/autoload.php and it throws an error how it should), I'm running PHP version 7.2.7 on XAMPP on Mac OS Mojave. Here is the directory structure, the highlighted index.php file is the one with the code above:
enter image description here

And here is the output of composer dump-autoload -o:

Generating optimized autoload files

And so...to add more to the fire of this question on Stack...How can I get composer to autoload my ShinePHP namespace with the classes as shown in the code?

Upvotes: 0

Views: 5702

Answers (1)

rob006
rob006

Reputation: 22174

This dependency does not have any autoloading rules, so Composer does not know where to find ShinePHP\EasyHttp class. You need to add autoloading configuration in composer.json of shine-php package:

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

Upvotes: 2

Related Questions