Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Composer not auto-loading package

I'm currently working on Laravel 4. I have added the following to my composer.json, and ran the update:

    "require": {
        ...
        "koraktor/steam-condenser": "*"

The package: https://packagist.org/packages/koraktor/steam-condenser

The issue I'm having is that if I call one of the classes it uses, for example:

$steamUser = new SteamId('000000000000000000');
echo "Welcome, " . $steamUser->getNickname() . "<br />";

I get the error Class 'SteamId' not found

If I manually require the file needed, then it works perfectly:

require_once('/home/path-to-laravel/laravel/vendor/koraktor/steam-condenser/lib/steam-condenser.php');

I've ran composer dump-autoload and still doesn't work. Does anyone know why this is? It's really frustrating me :(

like image 424
Alias Avatar asked Jun 19 '13 15:06

Alias


2 Answers

Steam Condenser is not (yet) compliant to PSR-0, so you have to use a different autoloading approach (see http://getcomposer.org/doc/04-schema.md#autoload).

Using the files method should be best suited here:

{
    "autoload": {
        "files": ["vendor/koraktor/steam-condenser/lib/steam-condenser.php"]
    }
}
like image 192
Koraktor Avatar answered Oct 09 '22 06:10

Koraktor


Just requiring a package, does not force composer to autoload the package.

Have a look into autoloading with composer, but something like these should get you started:

autoload: {
    "classmap": ["vendor/koraktor/steam-condenso/lib"]
}
like image 21
ChrisG Avatar answered Oct 09 '22 04:10

ChrisG