Chapters
28 Chapters
|
1:45:06
|
This course is archived!
This tutorial uses a deprecated micro-framework called Silex. The fundamentals of REST are still valid, but the code we use can't be used in a real application.
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
23.
Enforcing Consistency with ApiProblem
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial uses a deprecated micro-framework called Silex. The fundamentals of REST are still valid, but the code we use can't be used in a real application.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"silex/silex": "~1.0", // v1.3.2
"symfony/twig-bridge": "~2.1", // v2.7.3
"symfony/security": "~2.4", // v2.7.3
"doctrine/dbal": "^2.5.4", // v2.5.4
"monolog/monolog": "~1.7.0", // 1.7.0
"symfony/validator": "~2.4", // v2.7.3
"symfony/expression-language": "~2.4" // v2.7.3
},
"require-dev": {
"behat/mink": "~1.5", // v1.5.0
"behat/mink-goutte-driver": "~1.0.9", // v1.0.9
"behat/mink-selenium2-driver": "~1.1.1", // v1.1.1
"behat/behat": "~2.5", // v2.5.5
"behat/mink-extension": "~1.2.0", // v1.2.0
"phpunit/phpunit": "~5.7.0", // 5.7.27
"guzzle/guzzle": "~3.7" // v3.9.3
}
}
5 Comments
Hello! Maybe more of an OOP question but, why did you set the errors separately rather than through the constructor, if they're all available at the same time?
Hey BL,
Well, it's not too much important, you really can pass those errors in the constructor. I think the reason behind of it is that doing it as a setter gives you a bit more flexibility. Except errors, you also may pass some other extra data if there're any, so this was just a "universal" way of working with extra data. I don't remember for sure, but probably later in this course or next courses it will be more explicit why this is done this way. But once again, you can do whatever you want, if it's more convenient for you to pass those errors in the constructor - why not? Especially if you *always* going to pass some errors :)
Cheers!
We also could to implement `JsonSerializable` interface by `ApiProblem` and then we could not call `toArray` method manually. All that we will be need is to just pass `$apiProblem` object to the `JsonResponse`
Yea, great idea! I haven't tried it, but you could in theory get even fancier by using some annotations to try to run the ApiProblem through the Json serializer. Might be overkill, but a cool thought :).
Sounds great! :) So far I have enough to use `JsonSerializable` interface, but now I want to deep into the `JMSSerializer` to discover more features with it, thanks.
"Houston: no signs of life"
Start the conversation!