Slide 1

Slide 1 text

App Development with ZF2 Tired of Album examples? Let‘s try a real world problem example…

Slide 2

Slide 2 text

me Michael Scholl EasyBib / Wesrc / sch0ll twitter: @mischosch sch0ll.de / wesrc.com

Slide 3

Slide 3 text

hu? ZF2 MVC ZF2 Modules ZF2 EventManager ZF2 + Doctrine … no live coding! but a real world problem solution…

Slide 4

Slide 4 text

But first… Let us assume, we have a problem!

Slide 5

Slide 5 text

But first… Let us assume, we have a problem!

Slide 6

Slide 6 text

of course… YOU have no problem, because you always send credentials by FAX to your peers & customers! or YOU are the person who is having great fun, telling your customers credentials on the phone and using passwords like this: „B3y3^zA#](}7j6#tmJ=[r“

Slide 7

Slide 7 text

me don‘t like using phone at all! (FAX¿ - don‘t get me started about FAX PlugIns for my „digital workstation“)

Slide 8

Slide 8 text

so… we need an app for this! a key! (idea given from @lenada)

Slide 9

Slide 9 text

let‘s do that with ZF2 of course, we use Composer ! (and ZF community fortunately decided to do so, too) cd ~/Sites/zf2test git clone git://github.com/zendframework/ ZendSkeletonApplication.git cd ZendSkeletonApplication php composer.phar install or php composer.phar create-project --repository-url="http:// packages.zendframework.com" zendframework/skeleton- application ~/Sites/zf2test

Slide 10

Slide 10 text

WHAT WE SEE

Slide 11

Slide 11 text

WHAT WE GET

Slide 12

Slide 12 text

APPLICATION.CONFIG.PHP modules: a list of modules you want to use module_listener_options: where to find your modules & how to load other config files by pattern

Slide 13

Slide 13 text

MODULE FOLDER So, module folder contains your own „Modules“ „Application“ is the only Module right now

Slide 14

Slide 14 text

ZF2 Modules can be pretty anything ([more or less] code, assets, configs) there is no structure you have to follow but there is a structure, you could/should follow you need a Module.php in the module root Module.php needs its own Namespace

Slide 15

Slide 15 text

Module Folder Structure modules Namespace config language public css js images src Namespace Controller Form Service ... test view layout namespace

Slide 16

Slide 16 text

ZF2 ModuleManager „A flexible and powerful system for loading managing modules“ (Evan Coury) Loads all your modules and fires some listeners AutoloaderListener ConfigListener InitTrigger OnBootstrapListener LocatorRegistrationListener ServiceListener Makes use of ZF2 EventManager

Slide 17

Slide 17 text

ZF2 Modules more background info: http://www.zend.com/en/resources/webinars/framework?#ZF2ModMan (Webinar with Evan Coury) http://blog.evan.pro/introduction-to-modules-in-zend-framework-2-talk- at-zendcon-2012 http://evan.pro/slides/Introduction-to-Modules-in-Zend-Framework-2- ZendCon-2012.html#slide1 http://akrabat.com/zend-framework-2/modules-in-zf2/

Slide 18

Slide 18 text

ZF2 Modules of course: http://modules.zendframework.com

Slide 19

Slide 19 text

MODULE.PHP Listener Listener Listener Your Module definition

Slide 20

Slide 20 text

MODULE.CONFIG.PHP - ROUTER

Slide 21

Slide 21 text

MODULE.CONFIG.PHP - SERVICES/CONTROLLERS/VIEWS

Slide 22

Slide 22 text

ZF2 ServiceManager because we can write $sm then! because everybody right now uses a DIC your module.config.php will feed the ServiceManager and get you up and running I assume, you already understand the concepts behind DIC (Dependency Injection Container) and IoC (Inversion of Control), if not…

Slide 23

Slide 23 text

ZF2 ServiceManager Background Info: http://blog.astrumfutura.com/2011/10/zend-framework-2-0- dependency-injection-part-1/ - http://blog.astrumfutura.com/2011/10/ zend-framework-2-0-dependency-injection-part-2/ (must read!) http://www.maltblue.com/articles-2/zend-framework-2-core-concepts- understanding-dependency-injection http://www.maltblue.com/tutorial/zend-framework-2-servicemanager http://ralphschindler.com/2012/10/10/di-dic-service-locator-redux http://akrabat.com/zend-framework-2/zendservicemanager- configuration-keys/ (helpful doc article!) http://juriansluiman.nl/en/article/120/using-zend-framework-service- managers-in-your-application (great article!)

Slide 24

Slide 24 text

ZF2 EventManager ZF2 MVC makes heavy usage of EventManager Everything is bound to an event If you want to hook into any bootstrapping process, you will end in attaching to an event You can use the EventManager to integrate event based logic into your own app

Slide 25

Slide 25 text

ZF2 EventManager Background Info: http://www.mwop.net/blog/266-Using-the-ZF2-EventManager.html http://akrabat.com/zend-framework-2/a-list-of-zf2-events/ http://framework.zend.com/manual/2.1/en/modules/zend.event- manager.event-manager.html http://www.zend.com/en/resources/webinars/framework?#ZF2EM (Webinar with Matthew Weier O'Phinney) http://robertbasic.com/blog/azend-framework-2-eventmanager-use- case/

Slide 26

Slide 26 text

INDEXCONTROLLER

Slide 27

Slide 27 text

INDEX VIEW TEMPLATE

Slide 28

Slide 28 text

LAYOUT VIEW TEMPLATE

Slide 29

Slide 29 text

But we talked about „real world example“

Slide 30

Slide 30 text

may I introduce …

Slide 31

Slide 31 text

APP URL LICENSE HTTPS://GITHUB.COM/WESRC/SECRETARY MIT SECRETARY

Slide 32

Slide 32 text

Secretary application.config.php

Slide 33

Slide 33 text

APPLICATION.CONFIG.PHP QUITE MORE REAL WORLD EXAMPLE, ISN‘T IT?

Slide 34

Slide 34 text

APPLICATION.CONFIG.PHP / COMPOSER.JSON USE VERSION NUMBERS!

Slide 35

Slide 35 text

autoload/local.php

Slide 36

Slide 36 text

GLOBAL.PHP / LOCAL.PHP DB SETTINGS LANGUAGE SETTINGS

Slide 37

Slide 37 text

Secretary module.config.php

Slide 38

Slide 38 text

MODULE.CONFIG.PHP - DOCTRINE & NAVIGATION

Slide 39

Slide 39 text

MODULE.CONFIG.PHP - ROUTER & SERVICE MANAGER

Slide 40

Slide 40 text

MODULE.CONFIG.PHP - CONTROLLERS

Slide 41

Slide 41 text

MODULE.CONFIG.PHP - VIEW TO ENABLE JSON VIEW MODELS

Slide 42

Slide 42 text

Secretary Module.php

Slide 43

Slide 43 text

MODULE.PHP - INTERFACES & ONBOOTSTRAP INTERFACES TELL YOU, WHAT TO DO!

Slide 44

Slide 44 text

MODULE.PHP - INIT LOGGER

Slide 45

Slide 45 text

MODULE.PHP - INIT LOGGER ONLY GIVEN IDENTIFIER CAN TRIGGER EVENTS ! (USE * WILDCARD INSTEAD, IF NEEDED EVERYWHERE)

Slide 46

Slide 46 text

MODULE.PHP - GET CONFIG & AUTOLOADER

Slide 47

Slide 47 text

MODULE.PHP - VIEW CONFIG SET ACL FOR NAVIGATION VIEW PLUGIN ENABLE MARKDOWN VIEW PLUGIN will be callable by $this->SecretaryMarkdown($foo) in view

Slide 48

Slide 48 text

MODULE.PHP - FORM CONFIG THIS ONE IS LITTLE BIT CRAZY IF YOU WANT TO USE DoctrineORMModule\Form\Element\EntitySelect

Slide 49

Slide 49 text

so… we need that key!

Slide 50

Slide 50 text

KEYCONTROLLER.PHP

Slide 51

Slide 51 text

KEYCONTROLLER.PHP - SETTER & GETTER

Slide 52

Slide 52 text

KEYCONTROLLER.PHP - PRESDISPATCH & INDEX PREDISPATCH IS A OWN EVENT! (that is created in MvcController) add key-de_DE.mo and key-us_US.mo to translator Check, if key is already created. If not, create KeyForm. Return keyRecord and keyForm as ViewModel Attributes

Slide 53

Slide 53 text

KEYCONTROLLER.PHP - ADD ACTION redirect, if key already given Create KeyForm & ViewModel

Slide 54

Slide 54 text

KEYCONTROLLER.PHP - ADD ACTION If Request is POST Create new KeyRecord and get Input Filter out of it. Fill Form with POST data If form is valid Get passphrase out of form values Generate Private Key Save Public Key for User ($this->identity) Add Private Key to ViewModel Update User Role

Slide 55

Slide 55 text

KEY FORM

Slide 56

Slide 56 text

KEY ENTITY

Slide 57

Slide 57 text

KEY VIEW

Slide 58

Slide 58 text

WHAT YOU GET - INDEX

Slide 59

Slide 59 text

WHAT YOU GET - ADD

Slide 60

Slide 60 text

it‘s just that easy ;)

Slide 61

Slide 61 text

ZF2 - More Infos http://framework.zend.com/manual/2.1/en/index.html http://www.zend.com/en/resources/webinars/framework http://akrabat.com/ http://blog.astrumfutura.com/ http://blog.evan.pro http://www.mwop.net http://ralphschindler.com http://www.zimuel.it/en/ ZF MailingList: http://framework.zend.com/wiki/display/ZFDEV/Mailing+Lists GITHUB: https://github.com/zendframework/zf2 IRC: http://www.zftalk.com/channel/

Slide 62

Slide 62 text

Secretary proudly presented by wesrc.com HTTPS://GITHUB.COM/WESRC/SECRETARY

Slide 63

Slide 63 text

Thank you for listening