7

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 :(

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Alias
  • 2,983
  • 7
  • 39
  • 62

2 Answers2

11

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"]
    }
}
Koraktor
  • 41,357
  • 10
  • 69
  • 99
  • Koraktor it's working! Thanks very much for taking the time to look into it. – Alias Jun 19 '13 at 16:02
  • Actually, `classmap` might be a better solution. `files` simply forces the file to be loaded, even if you do not use the classes in there. `classmap` on the other hand enables the autoloader to find the classes and only load them on demand. – Nils Werner Jun 19 '13 at 18:51
  • Hm, looking at it it seems like `files` is indeed the right choice. The file you're loading not just loads the classes but contains some data needed by them as well. – Nils Werner Jun 19 '13 at 18:57
1

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"]
}
DAG
  • 6,710
  • 4
  • 39
  • 63
  • 1
    Thanks (there is a typo in that though). I'm confused though, other packages I've been using (such as HybridAuth) literally worked out of the box, didn't have to add anything, but with this I did? It does load the files. However I get the error "Use of undefined constant STEAM_CONDENSER_PATH - assumed 'STEAM_CONDENSER_PATH' - I guess that's because it isn't loading a file which is defining that. – Alias Jun 19 '13 at 15:41
  • Have a look into the code and see where this define happens and figure out if it is getting loaded. – DAG Jun 19 '13 at 15:44
  • Happens in the "steam-condenser.php" file: define('STEAM_CONDENSER_PATH', dirname(__FILE__) . '/'); So I assume not... but it is within the /lib/ directory which is odd! – Alias Jun 19 '13 at 15:46