-1

Restler is refusing to instantiate any of my API classes. It's just always saying it fails on Route, but doesn't bother to provide any other useful information. I installed Restler via composer via "restler/framework" : "3.0.0-RC6" and then created an index.php that looks like this:

<?php

require __DIR__.'/../vendor/autoload.php';

use Luracast\Restler\Restler;

$r = new Restler();
$r->addAPIClass('Explorer');
$r->addAPIClass('Play');

$r->handle();

In the exact same directory as the index.php I've created a file called Play.php that looks like so:

<?php

public class Play
{
    public function __construct() {
        error_log("I called the constructor!\n", 3, '/tmp/scott');
    }

    public function index() {
        error_log("I called the index\n", 3, '/tmp/scott');
    }

When I call http://.../api/play I never see the /tmp/scott file created, and I just get the generic failure response from Restler:

{
    "error": {
        "code": 404,
        "message": "Not Found"
    },
    "debug": {
        "source": "Routes.php:438 at route stage",
        "stages": {
            "success": [
                "get"
            ],
            "failure": [
                "route",
                "negotiate",
                "message"
            ]
        }
    }
}
Software Engineer
  • 15,457
  • 7
  • 74
  • 102
Gargoyle
  • 9,590
  • 16
  • 80
  • 145
  • Looks like some how class `Play` is not autoloaded. Try var_dump(class_exists('Play')); in your index.php to confirm – Arul Kumaran Apr 07 '15 at 06:46
  • And how do I see that output? – Gargoyle Apr 07 '15 at 06:59
  • OK, I used error_log to check the value and it definitely says it does not exist. – Gargoyle Apr 07 '15 at 07:02
  • If I explicitly add a require of Play.php to index.php it works. Not sure if that helps you figure out anything though. – Gargoyle Apr 07 '15 at 07:09
  • You have to edit your composer.json to add the folders it has to look for source files. Read about it in https://getcomposer.org/doc/01-basic-usage.md#autoloading You may read the cheat-sheet at http://composer.json.jolicode.com/ and roll over the autload section in composer.json – Arul Kumaran Apr 07 '15 at 09:57

1 Answers1

1

As Luracast noted in the comments, I had to edit the composer.json to add this stanza:

"autoload": {
    "psr-0": {
        "": "api"
    }
}

and then run composer dump-autoload

Gargoyle
  • 9,590
  • 16
  • 80
  • 145