Download - Diaporama du sfPot Lillois du 20 mars 2014
![Page 1: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/1.jpg)
Réaliser des applications innovantes avec Symfony2Symfony2, API REST et Javascript
![Page 2: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/2.jpg)
Qui sommes-nous ?Alexandre Salomé
Consultant
@alexandresalome
Kévin DunglasCo-fondateur
@dunglas
![Page 3: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/3.jpg)
Architecture
![Page 4: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/4.jpg)
API REST
- Exposer les données de l’application- HTTP + JSON/XML- Plus léger que SOAP (adapté pour le mobile)- RESTful
curl -X POST http://example.com/api/user
--data '{"username": "alice", "fullname": "Alice"}'
![Page 5: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/5.jpg)
SPA (Single Page Application)
- Application JavaScript- S’exécute côté client- Récupère et modifie les données via l’API REST- Seules les données utiles transitent
![Page 6: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/6.jpg)
Application
apps mobiles
site webresponsive
autres applications et sites
(ERP, logistique, partenaires…)
applicationFacebook
API REST
Internet
![Page 7: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/7.jpg)
Stockage de données
Application Serveur Web
Internet
Applications tierces
Fichiers
![Page 8: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/8.jpg)
Ecosystème
![Page 9: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/9.jpg)
- PHP 5.3, 5.4, 5.5 (namespaces, traits)- Composer- Frameworks / CMS / PSR (PHP-FIG)- PHPUnit / phpspec / Behat
PHP-FIG : http://www.php-fig.orgAwesome PHP : https://github.com/ziadoz/awesome-php
PHP
![Page 10: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/10.jpg)
- Framework “full stack”- Découplé en composants- Axé fiabilité (tests), sécurité et performance- Design moderne (POO, MVC, DIC, Events…)- Intègre des bibliothèques tierces reconnues : Twig, Swiftmailer, Doctrinehttp://symfony.com / http://github.com/symfony/symfony
Symfony2
![Page 11: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/11.jpg)
AngularJS
- Framework JavaScript MVC complet- Maintenu par Google- Communauté importante- S’intègre parfaitement avec Symfony
http://angularjs.org/
![Page 12: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/12.jpg)
Backbone.js
- Bibliothèque JavaScript- Synchronise la couche modèle de l’application cliente avec une API REST- S’intègre facilement dans du code JS existant- S’intègre parfaitement avec Symfony
http://backbonejs.org/
![Page 13: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/13.jpg)
Alternatives
- Ember.js :http://emberjs.com/
- Chaplin.js :http://chaplinjs.org/
Et bien d’autres.
![Page 14: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/14.jpg)
Implémentation
![Page 15: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/15.jpg)
Modèle relationnel objet
- Doctrine : http://www.doctrine-project.org/ (ORM + ODM + O*M)- Propel : http://propelorm.org/- PHPCR : http://phpcr.github.io/- ElasticSearch : http://www.elasticsearch.org/guide/en/elasticsearch/client/php-api/current/
Voir aussi https://github.com/ziadoz/awesome-php#orm-and-datamapping
![Page 16: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/16.jpg)
Sérialisation des objetsreturn new JsonResponse($object->toArray());
Composant Serializerhttp://symfony.com/fr/doc/current/components/serializer.html
JMSSerializerBundlehttps://github.com/schmittjoh/JMSSerializerBundle
![Page 17: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/17.jpg)
Exposer une API REST- FOSRestBundle : https://github.com/FriendsOfSymfony/FOSRestBundle
- NelmioApiDocBundle :https://github.com/nelmio/NelmioApiDocBundle
- JMSSerializerBundle :http://jmsyst.com/bundles/JMSSerializerBundle
![Page 18: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/18.jpg)
Envoyer des données
- “Désérialisation” du JSON ou du XML :JMSSerializerBundle
- Validation des données et mise à jour des objets :Symfony Form framework
![Page 19: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/19.jpg)
Gestion des assets
- Less, SASS- Minify, Uglify, YUI Compressor, …- Bower
Avec Symfony : AsseticSans Symfony : Grunt + Yeoman
![Page 20: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/20.jpg)
Show me the code
![Page 21: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/21.jpg)
Exemple KISS /**
* @Route(path="/user/{id}", name="user_show")
*/
public function showAction($id)
{
$user = $this
->getDoctrine()
->getRepository('AcmeDemoBundle:User')
->find($id)
;
if (!$user) {
throw $this->createNotFoundException(sprintf('User %s not found.', $id));
}
return new JsonResponse($user->toArray());
}
![Page 22: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/22.jpg)
Exemple (encore plus court) /**
* @Route(path="/user/{id}", name="user_show")
*/
public function showAction(User $user)
{
return new JsonResponse($user->toArray());
}
![Page 23: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/23.jpg)
Behat-LauncherCôté serveur (80%)- Silex- Composant Serializer
Côté client (20%)- Twitter Bootstrap- AngularJS- Internationalisation- Grunthttp://github.com/alexandresalome/behat-launcher
![Page 24: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/24.jpg)
DunglasTodoMVCBundle
Côté serveur (50%)- Symfony- FOSRest / JMSSerializer
Côté client (50%)- Backbone.js et Chaplin.js- CoffeeScript
http://github.com/dunglas/DunglasTodoMVCBundle
![Page 25: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/25.jpg)
Aller plus loin
![Page 26: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/26.jpg)
Référencement
- Google ne sait pas exécuter le JavaScript- Les SPA ne sont pas référencées par défaut
Solution : Prerender.io (snapshots)http://prerender.iohttps://github.com/rjanot/YuccaPrerenderBundle
![Page 27: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/27.jpg)
Sécurité
- Protection CSRF d’une SPAhttps://github.com/dunglas/DunglasAngularCsrfBundle
- Utilisation de l’objet JsonResponseJSON Vulnerability
![Page 28: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/28.jpg)
Hypermedia API
Découverte dynamique des serveurs par les clients :
- HATEOAS (HAL+JSON)http://hateoas-php.org/- Hydra / JSON-LD http://www.markus-lanthaler.com/hydra/
![Page 29: Diaporama du sfPot Lillois du 20 mars 2014](https://reader033.vdocuments.us/reader033/viewer/2022052905/5584b1e8d8b42a85768b46aa/html5/thumbnails/29.jpg)
Des questions ?Une bière !