Documente Academic
Documente Profesional
Documente Cultură
by Enrico Zimuel (enrico@zend.com) Senior Software Engineer Zend Framework Core Team Zend Technologies Ltd
About me
Enrico Zimuel o!tware Engineer since "##$
%ssembly &'$( C)C**( +a,a( -erl( -.-
Zend Framework Team /nternational s0eaker on -.- and com0uter security to0ics 1esearcher 0rogrammer at /n!ormatics /nstitute o! 2ni,ersity o! %msterdam Co3!ounder o! -24 Torino (/taly)
ZF2 in a slide
5ew architecture
-er!ormance im0ro,ement (lazy loading) 1e9uirement: PHP 5.3.3 - 13; com0liant -ackaging system (0yrus( com0oser) ZF ;.<.= last stable
htt0:))!ramework.zend.com
A new core
The ZF way:
ingleton( 1egistry( and .ard3 Coded 8e0endencies %s0ect >riented 8esign and 8e0endency /n?ection
MVC
The central idea behind 67C is code reusability and se0aration o! concerns
.TTre9uest
bootstra$
route
dis$atch
.TTres0onse
Listeners
A common wor%flow
use Zend@ er,ice6anager@ er,ice6anagerA use Zend@6,c@%00licationA )B C B) Dser,ices E new er,ice6anager(Dser,icesCon!ig)A Da00 E new %00lication(Da00Con!ig( Dser,ices)A Da003Fbootstra0()A Dres0onse E Da003Frun()A Dres0onse3Fsend()A
&efault ser#ices
ZF2
'%eleton A$$lication
curl 3s htt0s:))getcom0oser.org)installer G 0h0 33 0h0 com0oser.0har create30ro?ect 33re0ository3 urlEHhtt0:))0ackages.zend!ramework.comH zend!ramework)skeleton3a00lication 0ath)to)install
com$oser.(son
I HnameH: Hzend!ramework)skeleton3a00licationH( Hdescri0tionH: H keleton %00lication !or ZF;H( HlicenseH: HJ 83=3ClauseH( HkeywordsH: K H!rameworkH( Hz!;H L( Hhome0ageH: Hhtt0:))!ramework.zend.com)H( Hre9uireH: I H0h0H: HFEM.=.=H( Hzend!ramework)zend!rameworkH: H;.BH N
8irectory tree
con!ig data module 0ublic ,endor
Con!ig !older
confi) autoload a00lication.con!ig.0h0 data module 0ublic ,endor
8ata !older
con!ig data cache module 0ublic ,endor
6odule !older
module
5ame o! the module %00lication con!ig module.con!ig.0h0 src %00lication Controller /nde&Controller.0h0 ,iew a00lication inde& inde&.0html error layout Module.$h$
-ublic !older
$ublic images ?s css .htaccess inde&.0h0
7endor !older
con!ig data module 0ublic #endor zend!ramework
confi)uration
*confi)*a$$lication.confi).$h$
return array( OmodulesO EF array( O%00licationO( )( OmodulePlistenerPo0tionsO EF array( Ocon!igPglobP0athsO EF array( Ocon!ig)autoload)I(B.NIglobal(localN.0h0O( )( OmoduleP0athsO EF array( O.)moduleO( O.),endorO( )( )( )A
All rights reserved. Zend Technologies, Inc.
$ublic folder
$ublic*.htaccess
RewriteEngine On RewriteCond %{REQUEST !I"E#A$E% &s 'OR( RewriteCond %{REQUEST !I"E#A$E% &l 'OR( RewriteCond %{REQUEST !I"E#A$E% &d RewriteR)le *.+, & '#C,"( RewriteR)le *.+, inde-..h. '#C,"(
Front controller +$ublic*inde,.$h$QR0h0 )BB B This makes our li!e easier when dealing with 0aths. E,erything is relati,e B to the a00lication root now. B) chdir(dirname(PP8/1PP))A )) etu0 autoloading include OinitPautoloader.0h0OA )) 1un the a00licationS Zend@6,c@%00lication::init(include Ocon!ig)a00lication.con!ig.0h0O)3Frun()3Fsend()A
Zend.'er#iceMana)er
The er,ice6anager is a 'er#ice /ocator im0lementation % er,ice Locator is a well3known ob?ect in which you may re)ister ob(ects (more in general ser,ices) and later retrie#e them 8ri,en by con!iguration
T0$es of 'er#ices
E&0licit (name EF ob?ect 0airs) /n,okables (name EF class to instantiate) Factories (name EF callable returning ob?ect) %liases (name EF some other name) %bstract Factories (unknown ser,ices) co0ed Containers (limit what can be created) hared (or notA you decide)
module
Modules b0 default
% module is all related code and assets that solve a specific problem. 6odules inform the MVC about ser,ices and e,ent listeners
The basic unit in a ZF; a00lication is a Module 6odules are 1Plu) and $la02 technology 6odules are sim0le:
&e#elo$ Modules
.module.A$$lication.Module.$h$
names0ace %00licationA use Zend@6,c@6odule1outeListenerA use Zend@6,c@6,cE,entA class 6odule I 0ublic !unction getCon!ig() I return include PP8/1PP . O)con!ig)module.con!ig.0h0OA N N
*module*A$$lication*confi)*module.confi).$h$ +routin) $artreturn array( OrouterO EF array( OroutesO EF array( OhomeO EF array( Oty0eO EF OZend@6,c@1outer@.tt0@LiteralO( Oo0tionsO EF array( OrouteO EF O)O( Ode!aultsO EF array( OcontrollerO EF O%00lication@Controller@/nde&O( OactionO EF Oinde&O( )( )( )( ...
*module*A$$lication*confi)*module.confi).$h$ +controller 3 translator $artC Oser,icePmanagerO EF array( O!actoriesO EF array( OtranslatorO EF OZend@/"'n@Translator@Translator er,iceFactoryO( )( )( OtranslatorO EF array( OlocaleO EF OenP2 O( OtranslationP!ileP0atternsO EF array( array( Oty0eO EF Ogette&tO( ObasePdirO EF PP8/1PP . O)..)languageO( O0atternO EF OTs.moO( )( )( )( OcontrollersO EF array( Oin,okablesO EF array( O%00lication@Controller@/nde&O EF O%00lication@Controller@/nde&ControllerO )( )( ...
*module*A$$lication*confi)*module.confi).$h$ +#iew... O,iewPmanagerO EF array( Odis0layPnotP!oundPreasonO EF true( Odis0layPe&ce0tionsO EF true( Odocty0eO EF O.T6LMO( OnotP!oundPtem0lateO EF Oerror)U<UO( Oe&ce0tionPtem0lateO EF Oerror)inde&O( Otem0latePma0O EF array( Olayout)layoutO EF PP8/1PP . O)..),iew)layout)layout.0htmlO( Oa00lication)inde&)inde&O EF PP8/1PP . O)..),iew)a00lication)inde&)inde&.0htmlO( Oerror)U<UO EF PP8/1PP . O)..),iew)error)U<U.0htmlO( Oerror)inde&O EF PP8/1PP . O)..),iew)error)inde&.0htmlO( )( Otem0lateP0athPstackO EF array( PP8/1PP . O)..),iewO( )( )( ...
*module*A$$lication*src*A$$lication* Controller*4nde,Controller.$h$
names0ace %00lication@ControllerA use Zend@6,c@Controller@%bstract%ctionControllerA use Zend@7iew@6odel@7iew6odelA class /nde&Controller e&tends %bstract%ctionController I 0ublic !unction inde&%ction() I return new 7iew6odel()A N N
Than% 0ou5
More information