6. APIJokes (I)
GET /api/list
Get the jokes list in JSON
POST /api/add
Add a new joke
POST /api/edit
Edit an existing joke
GET /
Public website with the joke list in HTML
7. APIJokes (II)
Special cases
Every time a joke is added or edited,
an email is sent to the administrator.
We don’t allow jokes about Java.
34. A change in the data or
configuration should’t
require changing the code
35. public function load(ObjectManager $manager)
{
$jokes = array(
'There’s no place like 127.0.0.1',
'If at first you don’t succeed; call it version 1.0',
'Beware of programmers that carry screwdrivers',
'What color do you want that database?'
);
foreach ($jokes as $item) {
$joke = new Joke();
$joke->setContent($item);
$manager->persist($joke);
}
$manager->flush();
}
36. # fixtures/joke.yml
jokes:
- 'I would love to change the world, but they won’t...'
- 'There’s no place like 127.0.0.1'
- 'If at first you don’t succeed; call it version 1.0'
- 'You know it’s love when you memorize her IP...'
- 'Beware of programmers that carry screwdrivers'
- 'Best file compression around: “rm *.*” = 100...'
- 'The truth is out there…anybody got the URL?'
- 'What color do you want that database?'
37. public function load(ObjectManager $manager)
{
$jokes = Yaml::parse(__DIR__ . '/fixtures/joke.yml');
foreach ($jokes['jokes'] as $item) {
$joke = new Joke();
$joke->setContent($item);
$manager->persist($joke);
}
$manager->flush();
}