Chapters
26 Chapters
|
2:18:26
|
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!
14.
GET Your (One) Battle On
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
"jms/serializer": "~0.16", // 0.16.0
"willdurand/hateoas": "~2.3" // v2.3.0
},
"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
}
}
7 Comments
Hi, is there a way to implement the same %battles.last.id% in Symfony? I mean, since "id" is usually a protected or private variable, the only way I found is to use %battles.last.getId()%, which is not as elegant as yours... Any suggestion?
Hey Pietrino!
Ah, so you got all the hard stuff working then with the entity manager, etc - nice work! For this last piece, use the PropertyAccess component: http://symfony.com/doc/curr.... This is used internally by Symfony's form system, which is how you're able to say "name" in your form and it calls getName().
Let me know if that works!
Hi Ryan, I managed for it to work in behat features, with something like creating a wrapper class, that implements the __get method and returns a PropertyAccessor. It works, but leaves me with two similar problems:
1. it works only on the first level, so it doesn't let me access "protected properties" for something like %item.children[0].id%
2. it happens to be a very similar problem with Expression Language formulas used in Hateoas\Relations (such as "expr(object.id)"
Any ideas?
Maybe I can extend Expression Language?
Hey Pietrino!
Hmm, yes, I see the issue. I'm sure it's possible to get this working, but I might stick with the %battles.last.getId()% instead - trying to get this working just like %battles.last.id%` with the expression language might not be worth it (but might be fun to try!). The easiest way I can see to do this would be to NOT use the expression language, and instead parse the string manually - exploding on the first "." and using the pieces separately. If you give "children[0].id" to the PropertyAccessor, it'll *love* that.
Good question and good luck :)
Yup, might be interesting to dive into Expression Language and extend it beyond providers and registered functions... I'll give it a try! Thanks!
Hi guys,
i just want to mention that on the script at the last two code that you re describing the first says
"$url = $this->generateUrl('api_battle_show', array('id' => $battle->id));"
and the second says
"$controllers->get('/api/battles/{id}', array($this, 'showAction'))->bind('api_battles_show');"
so there is a tiny difference that "api_battles_show" at first is in singular and at second is plural. Just to mention this "s" on script.
You re doing a perfect work,
Argy
Hey Argy,
Wow, it was difficult to spot, well done! In the video we use singular form, i.e. "api_battle_show" in both places. And thanks for this report, I'll fix it.
Cheers!
"Houston: no signs of life"
Start the conversation!