Apigility reloaded

1.092 Aufrufe

Veröffentlicht am

Ein frischer Blick auf Apigility 1.1 und den Einsatz von Doctrine mit Apigility

Veröffentlicht in: Technologie
0 Kommentare
2 Gefällt mir
Statistik
Notizen
  • Als Erste(r) kommentieren

Keine Downloads
Aufrufe
Aufrufe insgesamt
1.092
Auf SlideShare
0
Aus Einbettungen
0
Anzahl an Einbettungen
2
Aktionen
Geteilt
0
Downloads
10
Kommentare
0
Gefällt mir
2
Einbettungen 0
Keine Einbettungen

Keine Notizen für die Folie

Apigility reloaded

  1. 1. APIGILITY ReloadedAPIGILITY Reloaded Ein frischer Blick auf Apigility 1.1  Repository: https://github.com/RalfEggert/ipc2015-apigility 1 / 44
  2. 2. Über michÜber mich 2 / 44www.RalfEggert.dewww.RalfEggert.de
  3. 3. Fragen ans PublikumFragen ans Publikum 3 / 44 [b01][b01]
  4. 4. [B00][B00] Apigility 1.0Apigility 1.0 4 / 44
  5. 5. Performance LastigPerformance Lastig 5 / 44 [b02][b02]
  6. 6. Bug lastigBug lastig 6 / 44 [b03]
  7. 7. KonfigurationsLastigKonfigurationsLastig 7 / 44 [b00]
  8. 8. Code lastigCode lastig 8 / 44 [b00]
  9. 9. [B04] 9 / 44 Apigility 1.0Apigility 1.0 War mir zuWar mir zu AufwändigAufwändig
  10. 10. [B05] 10 / 44 Dann schau dirDann schau dir Apigility 1.1 an!Apigility 1.1 an!
  11. 11. [B06] Apigility 1.1Apigility 1.1 In a NutshellIn a Nutshell 11 / 44
  12. 12. Restful Web ServicesRestful Web Services 12 / 44 CLIENT WebBrowser PHP Javascript RUBY PYTHON REST SERVER /api/user/123 /api/user /api/user /api/user/123 /api/user/123 USER DOMAIN getUserEntity() getUserCollection() addUserEntity() updateUserEntity() deleteUserEntity() GET Request JSON Response GET Request JSON Response POST Request JSON Response PUT Request JSON Response DELETE Request JSON Response Integer UserEntity void UserCollection Array Boolean Integer, Array Boolean Integer Boolean
  13. 13. RPC Web ServicesRPC Web Services 13 / 44 Local CLIENT javascript RPC Client JSON Method:getUser Params:id USER DOMAIN getUserEntity() GET Request JSON Result Integer UserEntity RPC Server /json-rpc.php Remote Call JSON Result javascript JSON Method:addUser Params:name addUserEntity() POST Request JSON Result Array Boolean /json-rpc.php Remote Call JSON Result javascript XML Method:getUser Params:id getUserEntity() GET Request XML Result Integer UserEntity /xml-rpc.php Remote Call XML Result javascript XML Method:addUser Params:name addUserEntity() POST Request XML Result Array Boolean /xml-rpc.php Remote Call XML Result
  14. 14. VersionierungVersionierung 14 / 44 default Version per URLdefault Version per URL Version 1 per URLVersion 1 per URL Version 2 per URLVersion 2 per URL default Version per Content Negotiationdefault Version per Content Negotiation Version 1 per Content NegotiationVersion 1 per Content Negotiation Version 2 per Content NegotiationVersion 2 per Content Negotiation
  15. 15. JSON / HAL / ProblemJSON / HAL / Problem 15 / 44
  16. 16. WEITERE FEATURESWEITERE FEATURES Datenbank-basiertDatenbank-basiert Code-basiertCode-basiert AuthentifizierungAuthentifizierung API DokumentationAPI Dokumentation DatenvalidierungDatenvalidierung DeploymentDeployment 16 / 44 [B09] [B08][B08][B07] [B12][B12][B11][B10]
  17. 17. [b07] DB-ConnectedDB-Connected ServiceService 17 / 44
  18. 18. DatenbankmodellDatenbankmodell 18 / 44
  19. 19. InstallationInstallation 19 / 44 // Konsole // Projekt anlegen $ cd /home/devhost/ $ composer create-project --dev zfcampus/zf-apigility-skeleton apigility.local $ cd apigility.local/ // ggf. Schreibrechte setzen $ sudo chmod 777 -R /home/devhost/apigility.local/ // Development Modus $ php public/index.php development enable // Composer besorgen (falls benötigt) $ curl -s https://getcomposer.org/installer | php -- // Passwort Datei erstellen $ htpasswd -cs data/users.htpasswd ipc2015
  20. 20. UI: DB-connectedUI: DB-connected Auth AdapterAuth Adapter Datenbank AdapterDatenbank Adapter Neue User APINeue User API AuthentifizierungAuthentifizierung Profile ServiceProfile Service User ServiceUser Service #step1 20 / 44
  21. 21. Testen mit POSTMANTesten mit POSTMAN 2121 // 4444 [b13][b13]
  22. 22. [B00] Doctrine-Doctrine- ConnectedConnected ServiceService 22 / 44
  23. 23. DatenbankmodellDatenbankmodell 23 / 44
  24. 24. UI: DOCTRINE-connectedUI: DOCTRINE-connected Neue User APINeue User API AuthentifizierungAuthentifizierung 24 / 44
  25. 25. Doctrine InstallationDoctrine Installation 25 / 44 // Konsole // Apigility Modul für Doctrine installieren $ php composer.phar require zfcampus/zf-apigility-doctrine "~0.3" // DoctrineORMModule installieren (falls noch nicht installiert) $ php composer.phar require doctrine/doctrine-orm-module "~0.8"
  26. 26. Module aktivierenModule aktivieren 26 / 44 // Datei /config/application.config.php return array( 'modules' => array( [...] 'DoctrineModule', 'DoctrineORMModule', 'PhproDoctrineHydrationModule', 'ZFApigilityDoctrineServer', ), ); // Datei /config/development.config.php return array( 'modules' => array( [...] 'ZFApigilityDoctrineAdmin', ), );
  27. 27. Doctrine ConnectionDoctrine Connection 27 / 44 // Datei /config/autoload/user.global.php return array( 'doctrine' => array( 'connection' => array( 'orm_default' => array( 'driverClass' => 'DoctrineDBALDriverPDOMySqlDriver', 'params' => array( 'host' => 'localhost', 'user' => 'ipc2015', 'password' => 'ipc2015', 'dbname' => 'ipc2015.shop', 'charset' => 'utf8', ), ), ), ), );
  28. 28. Doctrine DriverDoctrine Driver 28 / 44 // Datei /module/Shop/config/module.config.php return array( 'doctrine' => array( 'driver' => array( 'shop_driver' => array( 'class' => 'DoctrineORMMappingDriverAnnotationDriver', 'cache' => 'array', 'paths' => array( 0 => __DIR__ . '/../src/Shop/V1/Entity', ), ), 'orm_default' => array( 'drivers' => array( 'ShopV1Entity' => 'shop_driver', ), ), ), ), );
  29. 29. ENUM Doctrine TYPEENUM Doctrine TYPE 29 / 44 // Datei /module/Application/Module.php [...] use DoctrineORMEntityManager; class Module { public function onBootstrap(MvcEvent $e) { [...] $serviceManager = $e->getApplication()->getServiceManager(); $entityManager = $serviceManager->get('DoctrineORMEntityManager'); $platform = $entityManager->getConnection()->getDatabasePlatform(); try { $result = $platform->getDoctrineTypeMapping('enum'); } catch (DBALException $e) { $platform->registerDoctrineTypeMapping('enum', 'string'); } } }
  30. 30. Entities erstellenEntities erstellen 30 / 44 // Entities aus Datenbank generieren $ php public/index.php orm:convert-mapping --namespace="ShopV1Entity" --force --from-database annotation ./module/Shop/src Processing entity "ShopV1EntityAddress" Processing entity "ShopV1EntityBooking" Processing entity "ShopV1EntityBookingposition" Processing entity "ShopV1EntityCustomer" Processing entity "ShopV1EntityProduct" Exporting "annotation" mapping information to "/home/devhost/apigility.local/module/Shop/src" // Setter und Getter für Entities generieren $ php public/index.php orm:generate-entities ./module/Shop/src --generate-annotations=true Processing entity "ShopV1EntityBookingposition" Processing entity "ShopV1EntityBooking" Processing entity "ShopV1EntityAddress" Processing entity "ShopV1EntityProduct" Processing entity "ShopV1EntityCustomer" Entity classes generated to "/home/devhost/apigility.local/module/Shop/src"
  31. 31. UI: Doctrine-connectedUI: Doctrine-connected Address ServiceAddress Service Customer ServiceCustomer Service Product ServiceProduct Service Booking ServiceBooking Service Bookingpos. ServiceBookingpos. Service #step2 31 / 44
  32. 32. Testen mit POSTMANTesten mit POSTMAN 3232 // 4444 [b13][b13]
  33. 33. Speichern (cascade)Speichern (cascade) // Datei /module/Shop/src/Shop/V1/Entity/Customer.php /** * @var ShopV1EntityAddress * * @ORMManyToOne(targetEntity="ShopV1EntityAddress", cascade={"persist"}) * @ORMJoinColumns({ * @ORMJoinColumn(name="invoice_address", referencedColumnName="id") * }) */ private $invoiceAddress; /** * @var ShopV1EntityAddress * * @ORMManyToOne(targetEntity="ShopV1EntityAddress", cascade={"persist"}) * @ORMJoinColumns({ * @ORMJoinColumn(name="delivery_address", referencedColumnName="id") * }) */ private $deliveryAddress; #step3 33 / 44
  34. 34. [B14] Many-to-ManyMany-to-Many 34 / 44
  35. 35. Testen mit POSTMANTesten mit POSTMAN 3535 // 4444 [b13][b13]
  36. 36. Positionen für BookingPositionen für Booking 36 / 44 // Datei /module/Shop/src/Shop/V1/Entity/Booking.php /** * @var ArrayCollection * * @ORMManyToMany(targetEntity="Bookingposition") * @ORMJoinTable(name="bookingposition", * joinColumns={@ORMJoinColumn(name="booking", referencedColumnName="id")}, * inverseJoinColumns={@ORMJoinColumn(name="product", referencedColumnName="id")} * ) **/ private $positions;
  37. 37. BookingHydratorBookingHydrator 37 / 44 // Datei /module/Shop/config/module.config.php return array( 'doctrine-hydrator' => array( [...] 'ShopV1RestBookingBookingHydrator' => array( [...] 'strategies' => array( 'positions' => 'ZFApigilityDoctrineServer HydratorStrategyCollectionExtract', ), [...] ), [...] ), );
  38. 38. Max_Depth setzenMax_Depth setzen 38 / 44 // Datei /module/Shop/config/module.config.php return array( 'zf-hal' => array( 'metadata_map' => array( 'ShopV1EntityBooking' => array( [...] 'max_depth' => 3, ), [...] 'ShopV1EntityBookingposition' => array( [...] 'max_depth' => 2, ), ), ), );
  39. 39. Entities aktualisierenEntities aktualisieren 39 / 44 // Setter und Getter für Entities aktualisieren $ php public/index.php orm:generate-entities ./module/Shop/src --generate-annotations=true Processing entity "ShopV1EntityBookingposition" Processing entity "ShopV1EntityBooking" Processing entity "ShopV1EntityAddress" Processing entity "ShopV1EntityProduct" Processing entity "ShopV1EntityCustomer" Entity classes generated to "/home/devhost/apigility.local/module/Shop/src" // Schreibrechte für module/ Verzeichnis neu setzen $ sudo chmod 777 -R /home/devhost/apigility.local/
  40. 40. Testen mit POSTMANTesten mit POSTMAN 4040 // 4444 [b13][b13]
  41. 41. [B15] 41 / 44 Fazit:Fazit: Apigility 1.1Apigility 1.1 ist (fast)ist (fast) kinderleichtkinderleicht
  42. 42. Fragen vom Publikum?Fragen vom Publikum? 42 / 44 [b16]
  43. 43. DANKEDANKE Für Ihre / Eure Aufmerksamkeit!  Repository: https://github.com/RalfEggert/ipc2015-apigility 43 / 44
  44. 44. BildnachweisBildnachweis [B00] Fotos von Ralf Eggert [B01] Frontiers 2011 - Day 2 https://www.flickr.com/photos/frontiersofinteraction/5866676276/ von Frontiersofinteraction - CC-BY https://creativecommons.org/licenses/by/2.0/ [B02] Slow poke - bush gardens https://www.flickr.com/photos/hyku/421609299 von Josh Hallett - CC-BY https://creativecommons.org/licenses/by/2.0/ [B03] Thirsty lady bugs https://www.flickr.com/photos/snowpeak/5897430351/ von John Fowler - CC-BY https://creativecommons.org/licenses/by/2.0/ [B04] Still here https://www.flickr.com/photos/thenovys/3784261365 von Abe Novy - CC-BY https://creativecommons.org/licenses/by/2.0/ [B05] Young student https://www.flickr.com/photos/audiolucistore/14159712431/ von www.audio-luci-store.it - CC-BY https://creativecommons.org/licenses/by/2.0/ [B06] My nuts https://www.flickr.com/photos/lucasincas/6517703315/ von Lucas Incas - CC-BY https://creativecommons.org/licenses/by/2.0/ [B07] Fixing the database https://www.flickr.com/photos/dahlstroms/4140461901 von Håkan Dahlström - CC-BY https://creativecommons.org/licenses/by/2.0/ [B08] Monaco 14pt https://www.flickr.com/photos/polarity/3138680190 von Robert Agthe - CC-BY https://creativecommons.org/licenses/by/2.0/ [B09] RSA Securid Token - Credit Card Style https://www.flickr.com/photos/purpleslog/265657780 von Purple Slog - CC-BY https://creativecommons.org/licenses/by/2.0/ [B10] Shelf of Used Books https://www.flickr.com/photos/thedarkthing/5363586197 von William Ross - CC-BY https://creativecommons.org/licenses/by/2.0/ [B11] Ticket validator at Nice train station https://www.flickr.com/photos/traveleden/3797157077 von Simon - CC-BY https://creativecommons.org/licenses/by/2.0/ [B12] Test Lab - Supermicro Storage https://www.flickr.com/photos/jemimus/8533890844 von Robert - CC-BY https://creativecommons.org/licenses/by/2.0/ [B13] Busy Postmen https://www.flickr.com/photos/wheatfields/4253690499 von Christian Guthier - CC-BY https://creativecommons.org/licenses/by/2.0/ [B14] Network switch and cables https://www.flickr.com/photos/nayukim/3827776580 von Nayu Kim - CC-BY https://creativecommons.org/licenses/by/2.0/ [B15] We are all fan of laptops. https://www.flickr.com/photos/scottvanderchijs/4493248747 von Scott & Elaine van der Chijs - CC-BY https://creativecommons.org/licenses/by/2.0/ [B16] Etech05: Audience https://www.flickr.com/photos/oreilly/6648470 von James Duncan Davidson - CC-BY https://creativecommons.org/licenses/by/2.0/ Alle weiteren Screenshots wurden von Ralf Eggert erstellt. 44 / 44

×