radarphp / Radar.Adr

The Action-Domain-Responder core for Radar.
MIT License
55 stars 7 forks source link

Adr::input() no longer returns $this #26

Closed cxj closed 8 years ago

cxj commented 8 years ago

Somewhere between whatever version Composer was picking up using "require": { "radar/adr": "~1.0" } and the 1.0.0-alpha7 version, this stopped working:

$boot = new Boot();
$adr  = $boot->adr();
$adr->post('270', '/270', '\Clx\X12ApiAction')
    ->input('\Clx\GenericPostInput')
    ->responder('\Clx\GenericTextResponder');

$adr goes null after the call to input(). I've had to change my code to read like this when using alpha7:

$boot = new Boot();
$adr  = $boot->adr();
$adr->post('270', '/270', '\Clx\X12ApiAction')
    ->input('\Clx\GenericPostInput');
$adr->responder('\Clx\GenericTextResponder');
cxj commented 8 years ago

Hmm, maybe I actually moved backward on the chain of commits. Sometimes Github's view is not the clearest. Reverting. I don't even remember why I updated it to begin with.

cxj commented 8 years ago

Baffling. My require statement in composer.json says "~1.0" but it keeps grabbing the 1.0.0-alpha7 release. Composer can be really frustrating sometimes.

pmjones commented 8 years ago

Hey @cxj is this still a problem?

cxj commented 8 years ago

I'm attempting to reverify it now. IIRC it seemed to be more a matter of Composer pulling code with the bug rather than the newer code actually being wrong.

cxj commented 8 years ago

Maybe I'm just ignorant when it comes to Composer, but the following seems to be what causes the problem of pulling outdated code (it also is pulling pipeline/pipeline, for example):

Your recommended install procedure, which seems to work correctly:

composer create-project -s dev radar/project example-project

My install procedure, which I use because radar/adr is part of my project, not a standalone thing:

composer install

However, the composer.json files are functionally identical where it counts. I've just added a couple of dependencies for local libraries and a psr-4 clause for my local code. In theory -- at least to my way of understanding -- Composer should install exactly the same versions of the packages it does grab from Github. But it doesn't.

Is it my misunderstanding, or is there some config/release anomaly somewhere in your packaging, or a bug in Composer?

cxj commented 8 years ago

Is this a valid test? Namely, I altered your example code which works to explicitly call input() and and responder() as I do in my project, but using your generic classes.

$adr->get('Hello', '/{name}?', function (array $input) {
        $payload = new Aura\Payload\Payload();
        return $payload
            ->setStatus(Aura\Payload_Interface\PayloadStatus::SUCCESS)
            ->setOutput([
                'phrase' => 'Hello ' . $input['name']
            ]);
    })
    ->input('\Radar\Adr\Input')
    ->responder('\Radar\Adr\Responder\Responder')
    ->defaults(['name' => 'world']);
cxj commented 8 years ago

Well, I'm baffled as to the why, but I found a way to fix it. I removed an extraneous require from my root composer.json, and now it grabs the correct version of radar/adr. With the correct version, the fluent interface works as expected.