An other Slim\Exception\ HttpNotFoundException error

Hello,

I tried to take over an old project, the updates broke everything so I tried to make a clean installation from scratch and integrate my old code in it.

But there is something that doesn’t work, I have this error all the time:

[Sat Jul 23 14:11:41 2022] [::1]:57598 [200]: OPTIONS /tokens
[Sat Jul 23 14:11:41 2022] [::1]:57598 Closing
[Sat Jul 23 14:11:41 2022] [::1]:57600 Accepted
[Sat Jul 23 14:11:41 2022] 404 Not Found
Type: Slim\Exception\HttpNotFoundException
Code: 404
Message: Not found.
File: /home/baudouin/Documents/DEV/pvappcore-test/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php
Line: 91
Trace: #0 /home/baudouin/Documents/DEV/pvappcore-test/vendor/slim/slim/Slim/Middleware/RoutingMiddleware.php(58): Slim\Middleware\RoutingMiddleware->performRouting()
#1 /home/baudouin/Documents/DEV/pvappcore-test/vendor/slim/slim/Slim/MiddlewareDispatcher.php(147): Slim\Middleware\RoutingMiddleware->process()
#2 /home/baudouin/Documents/DEV/pvappcore-test/vendor/selective/basepath/src/BasePathMiddleware.php(52): Psr\Http\Server\RequestHandlerInterface@anonymous->handle()
#3 /home/baudouin/Documents/DEV/pvappcore-test/vendor/slim/slim/Slim/MiddlewareDispatcher.php(209): Selective\BasePath\BasePathMiddleware->process()
#4 /home/baudouin/Documents/DEV/pvappcore-test/vendor/slim/slim/Slim/Middleware/ErrorMiddleware.php(107): Psr\Http\Server\RequestHandlerInterface@anonymous->handle()
#5 /home/baudouin/Documents/DEV/pvappcore-test/vendor/slim/slim/Slim/MiddlewareDispatcher.php(147): Slim\Middleware\ErrorMiddleware->process()
#6 /home/baudouin/Documents/DEV/pvappcore-test/src/Middleware/LoginMiddleware.php(21): Psr\Http\Server\RequestHandlerInterface@anonymous->handle()
#7 /home/baudouin/Documents/DEV/pvappcore-test/vendor/slim/slim/Slim/MiddlewareDispatcher.php(313): App\Middleware\LoginMiddleware->__invoke()
#8 /home/baudouin/Documents/DEV/pvappcore-test/vendor/slim/slim/Slim/MiddlewareDispatcher.php(81): Psr\Http\Server\RequestHandlerInterface@anonymous->handle()
#9 /home/baudouin/Documents/DEV/pvappcore-test/vendor/slim/slim/Slim/App.php(215): Slim\MiddlewareDispatcher->handle()
#10 /home/baudouin/Documents/DEV/pvappcore-test/vendor/slim/slim/Slim/App.php(199): Slim\App->handle()
#11 /home/baudouin/Documents/DEV/pvappcore-test/public/index.php(3): Slim\App->run()
#12 {main}
[Sat Jul 23 14:11:41 2022] [::1]:57600 [404]: POST /tokens
[Sat Jul 23 14:11:41 2022] [::1]:57600 Closing

I tried a lot of things but it doesn’t work.

I have to know that during the installation I had a conflict between PHP-DI and psr/container that I had to downgrade with -W flag.

Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires php-di/php-di ^6.4 -> satisfiable by php-di/php-di[6.4.0].
    - php-di/php-di 6.4.0 requires psr/container ^1.0 -> found psr/container[1.0.0, 1.1.0, 1.1.1, 1.1.2] but the package is fixed to 2.0.2 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.

Yo can see the code here : https://gitlab.com/LaBaude32/pvappcore-test

I’m interested in any advice you may have!

Thx

In this case the real “issue” refers to PHP-DI as dependency. The error message is not related to the Slim router or basePath etc. as the title implies.

php-di/php-di 6.4.0 requires psr/container ^1.0

This is a known issue with PHP-DI 6.x, see here:

To solve this you can force composer to “downgrade” to psr/container v1 with:

composer require php-di/php-di --with-all-dependencies

This would still work with Slim since the interface is not that different.

PHP-DI 7.0 provides support for psr/container 2.0 interfaces.

See here: https://github.com/PHP-DI/PHP-DI/pull/726

Thanks for your quick answer ! That’s what it seemed to me too.

But I already did that :

And my psr is already in version 1.1.2

But it does not solve my issue and i don’t know why.

I have downloaded your example project, and it works with this command. Just an idea. Maybe try to delete the vendor/ directory and the composer.lock file and run composer update again.

Unfortunately it doesn’t change anything.
Is it possible that the problem comes from the fact that I’m using php 8.1 ? because I saw that PHP-DI 7 seems to bring php 8 support

Edit :

There is only one route that works: home ( localhost:8000/).
But all the others don’t work.
You can try for example localhost:8000/adduser which is the only unprotected one.

{
"email": "",
"firstName": "",
"lastName": "",
"organism": "",
"password": "",
"phone": "",
"user_function": "",
"userGroup": ""
}

I guess not, because I use PHP 8.1 on my local dev machine, and it works with your example repository.

PS: According to the routing issue.

localhost:8000/adduser

This will not work, because there is no route like this in your project.
But there is a route like: localhost:8000/api/v1/addNewUser
Have you tried this url?

Question: Why do you use RPC-ish URL-paths?

Damn, I’m really stupid. I don’t work on it since 2 years.
Indeed with the right road it works better!
I made some fixes but I still have a problem with the tokens.

Message: Call to undefined method Lcobucci\JWT\Builder::issuedBy()
File: /home/baudouin/Documents/DEV/pvappcore-test/src/Auth/JwtAuth.php
Line: 88

Hum I’m really do that ? :see_no_evil: :joy: . For me this is RESTfull but maybe I’m not doing it right. But i have followed you tutorial. So I probably miss something

It looks like your JwtAuth class is referring to an older version of the lcobucci/jwt package. Do you have the latest version of the eBook? You can also read the latest article online. Please send me a private message and I can check your email address.

For me this is RESTfull but maybe I’m not doing it right. But i have followed you tutorial. So I probably miss something

I never said that :slight_smile: Can you show me where I recommend to build RPC-ish URI path?

The truth is, I don’t know what an RPC-ish URI path is.
I followed the old tutorial in 2019 when it was longer and before you created the eBook. So, since we can’t access the full version anymore, I can’t check. But as I say, this is probably me making a mistake. :wink:

Witch one ?

Yes, I am trying to reproduce the same thing I got with version 3. Actually the real repository is the one I’m trying to fix: https://github.com/LaBaude32/PvApp_Core

No I haven’t bought it yet, but I think I will soon but until now I was a student so I had little money.

Ok, no problem. Let me explain what I mean with “RPC-ish”. RPC means “Remote Procedure Call”, where you have method names in an API like “addNewUser” or “getUser” etc… When you use a URI path like /addNewUser or /getUser then this is looking very “RPC-ish” to me. :slight_smile:

In practice, this style is not the way how to name RESTful API endpoints. Instead you would combine the HTTP method and the URI path to represent the resource you are trying to fetch, change or delete.

So instead of POST /addNewUser you would use POST /users,
and instead of GET getUser you would use GET /users.

Witch one ?

This article is only available if you buy the eBook.

I got with version 3

Yeah, this might be the point. The tutorial uses lcobucci/jwt v4.
This upgrading guide exlains how to upgrade lcobucci/jwt from version 3 to version 4. I hope it helps.