phpro / api-problem

RFC7807 Problem details implementation
MIT License
65 stars 8 forks source link

Missing dependencies #5

Closed judgej closed 5 years ago

judgej commented 5 years ago

I didn't realise this is very much just for Symfony until trying to use it, and realised it references a lot of Symfony interfaces and classes. None of these are listed in the composer dependencies.

Nice idea otherwise. A generic RFC-7807 payload construction package is sorely missing.

veewee commented 5 years ago

Hello @judgej,

Thanks for registering the issue.

This package does not require symfony. It contains base blocks that you can use to link to any framework you want.

We provide a bundle for symfony at https://github.com/phpro/api-problem-bundle It contains an exception listener that transforms any exception to an api problem json response. (See https://github.com/phpro/api-problem-bundle/blob/master/src/EventListener/JsonApiProblemExceptionListener.php)

You can use the same technique to link it to e.g. laravel. We just don't provide a package for that at this point. Feel free to poke me if you want to include this in another framework and still have questions on how to do this.

(This package also includes a ValidationApiProblem. This one requires the symfony/validator component which is suggested in composer.json and documented in the README file. That component can be used stand-alone and is completely opt-in for this package.)

judgej commented 5 years ago

It was dependencies like this:

https://github.com/phpro/api-problem/blob/master/src/Http/ValidationApiProblem.php#L7 (Symfony\Component\Validator\ConstraintViolationListInterface2)

I installed this package standalone, and it complained the Symfony packages were not installed. If the dependency was set in composer.json, then the Symfony packages would also be installed, and the PHP runtime would not complain.

I understand it should be standalone and you do have a Symfony Framework wrapper for it, which is great, but it does not look like that is entirely how it has turned out. Either there are some package interfaces that need to be taken out of this package, or there are some dependencies that need to be declared.

veewee commented 5 years ago

Thanks for the clarification.

Can you tell me what you refer to as it in the sentence "it complained the Symfony packages were not installed"?

As I mentioned in the first comment: that ValidationApiProblem class is opt-in. If you don't want to use it, you don't have to include symfony/validator. That dependency is added as a suggestion to composer.json which means it is not installed by default. The documentation also states that you have to manually add that dependency if you want to use it.

I don't feel like creating a new package (=maintenance overhead) for one class just to automatically include a dependency. But I do get your point :)

judgej commented 5 years ago

I was just trying out the package, creating a problem message with the example code in the README, and presented with the exception that the Symfony classes do not exist. I've removed all that now and using another package without dependencies like that, so can't give you the exact errors.

If you are happy that it does what you intend, and there is documentation that I didn't read properly (which certainly would not be the first time) then I guess everything is fine.