laminas-api-tools / api-tools

Laminas API Tools module for Laminas
https://api-tools.getlaminas.org/documentation
BSD 3-Clause "New" or "Revised" License
37 stars 19 forks source link

LAB API-REST : laminas-api-tools/statuslib-example : Installation failed, reverting ./composer.json to its original content #78

Closed JYDARTHA closed 4 years ago

JYDARTHA commented 4 years ago

Bug Report

LAB API-REST doen't work, due to installation problems.

Q A
Version(s) x.y.z

Summary

Version api : 1.5.2p1 While starting the Lab "Creating a REST Service", we need to install laminas-api-tools/status-lib-example. Composer failed : Here's the command and standard output:

composer require laminas-api-tools/statuslib-example Using version ^1.2 for laminas-api-tools/statuslib-example ./composer.json has been updated Loading composer repositories with package information Updating dependencies (including require-dev) Package operations: 2 installs, 0 updates, 0 removals

require [--dev] [--prefer-source] [--prefer-dist] [--fixed] [--no-progress] [--no-suggest] [--no-update] [--no-scripts] [--update-no-dev] [--update-with-dependencies] [--update-with-all-dependencies] [--ignore-platform-reqs] [--prefer-stable] [--prefer-lowest] [--sort-packages] [-o|--optimize-autoloader] [-a|--classmap-authoritative] [--apcu-autoloader] [--] []...

Current behavior

So, The package is still installed when I check in the vendor directory and the composer.json. Well, let's goes on!

On the chapter "Defining The Resource", when editing the module/Status/src/V1/Rest/Status/StatusResourceFactory.php file, there is a warning on "return new StatusResource($services->get(Mapper::class));" . The message is: Type 'Mapper' not found

Just after, at the chapter "Testing it out", the server response to the GET /status HTTP/1.1 Accept: application/json is 500 Internal Server Error

Here is the CUrl Command : curl -X GET -i http://syrius-api:8081/status --data 'HTTP/1.1 Accept: application/json'

I tried the LAB, 3 times. I have already the same problem. It looks like something wrong on the StatusResourceFactory.php with the Mapper::class?

How to reproduce

Expected behavior

I would like to install correctly my first REST-api with Laminas.

Thanks

2020-06-23_21h58_00 2020-06-23_21h58_25

weierophinney commented 4 years ago

Before I attempt to reproduce, can you answer a few questions for me, please?

Another thing you can do for me: start over, and when you get to the composer require laminas-api-tools/statuslib-example command, add the flag -vvv when invoking it: composer require -vvv laminas-apitools/statuslib-example, and then provide the output in a comment.

Thanks!

weierophinney commented 4 years ago

I've gone through the getting started and REST tutorials at this time. There are some JavaScript errors in the UI that require refreshing after each save, but I was able to complete the steps up to the "Defining the resource" section.

I then did the work in that section, and started testing the API.

And had no issues.

Now, regarding the StatusLib\Mapper class referenced in the factory, this is what we've called in the past a "virtual service" - the class does not exist, but there is a mapping for the service StatusLib\Mapper in the container, and, if you follow the directions, it works, resolving to the ArrayMapper implementation in this case.

My guess is:

The first would mean there is no autoloader present for classes under the StatusLib namespace, and the second would mean that the application is not aware of the module, so it is not loading any service configuration for it. All of this stems from the failure when installing via Composer, and the fact that you kept going when that occurred.

I suggest re-trying the install of the laminas-api-tools/statuslib-example package. If you run into errors, run composer self-update to ensure you have the latest Composer version before trying again.

JYDARTHA commented 4 years ago

Hi. Thanks for your support. Here's my responses

When I launched, a second time, the composer require command, there wasn't the error message.

My composer version seems to be the latest one: composer --version Composer version 1.10.7 2020-06-03 10:03:56

Then, I cleaned my entire project and started it, a fourth time, from scratch :-) Here is the output in verbose mode of the composer require laminas-api-tools/statuslib-example command. 2020-06-24_07h40_44

There is an exception.

I ran the composer show command and the laminas-api-tools/statuslib-example seems to be present. 2020-06-24_07h48_31

But that's right, I don't have any StatusLib entry in my config/modules.config.php file. 2020-06-24_07h51_28

Finally, I launched the composer self-update command: composer self-update You are already using composer version 1.10.7 (stable channel).

Should I re-install composer ?

Thanks

JYDARTHA commented 4 years ago

I found this PHP bug report: Bug #78883 | fgets(STDIN) fails on Windows [https://bugs.php.net/bug.php?id=78883] Do you think it is related ?

JYDARTHA commented 4 years ago

Hi. Finally I upgraded my PHP from 7.4.0 to 7.4.7 and it solved my problem. It works fine now. Thank for your support.

weierophinney commented 4 years ago

Glad you were able to get it sorted!