+ All Categories
Home > Internet > ZF3 introduction

ZF3 introduction

Date post: 02-Dec-2014
Category:
Upload: vincent-blanchon
View: 333 times
Download: 1 times
Share this document with a friend
Description:
 
27
Zend Framework 3 jeudi 16 janvier 14
Transcript
Page 1: ZF3 introduction

Zend Framework 3

jeudi 16 janvier 14

Page 2: ZF3 introduction

Why a new version ?* PHP5.4 (performance, traits, callable type, etc.)

* Improve the documentation

* Improve performance

* Improve maintainability and code design

* Because the contributors are being bored

jeudi 16 janvier 14

Page 3: ZF3 introduction

When ?* Nobody knows

* But a lot of PR in progress !

* A lot of ideas proposed

* Don’t repeat the same mess with the second version ...

jeudi 16 janvier 14

Page 4: ZF3 introduction

Booooooo

jeudi 16 janvier 14

Page 5: ZF3 introduction

What about components ?* New service locator implementation : lighter, maybe a compiled version ? Removal of the peering and abstract factories (I hope ...)

* New event manager implementation : lighter and faster

* New validators and input filter : stateless and faster

jeudi 16 janvier 14

Page 6: ZF3 introduction

What else ?* Hydrator with their own namespace

* Improve the code generation with the console

* Components with few activities will move

* Better normalization ...

jeudi 16 janvier 14

Page 7: ZF3 introduction

Better normalization ...

Zend Framework services name :

array(    'my_factory'  =>  'My\Factory',    'my.factory'  =>  'My\Factory',    'My\Factory'  =>  'My\Factory',);

ZF3 will use probably FQCN (Fully Qualified Class Name)

* Each interfaces should be finished by ‘Interface’* Each module should be finished by ‘Module’* Each config key should use underscores

jeudi 16 janvier 14

Page 8: ZF3 introduction

Other ideas* Routing by annotation

* Composer autoloader usage

* Doctrine instead of Zend\Db

* Modularize ZF2 (Symfony style)

* Get route parameters inside actions controllers

jeudi 16 janvier 14

Page 9: ZF3 introduction

* Get route parameters inside actions controllers

Currently :

$this-­‐>getEvent()-­‐>getRouteMatch()-­‐>getParam('id');$this-­‐>params()-­‐>fromRoute('id');$this-­‐>params('id');

With parameters inside :

public  function  editUser($id)

Or with transformers :

public  function  editUser(User  $user)

jeudi 16 janvier 14

Page 10: ZF3 introduction

Is it awesome ?YES ! otherwise I won’t be there ... AND :

* Less code and more developer friendly

* More good practice (less magical), with your controllers and your modules !

jeudi 16 janvier 14

Page 11: ZF3 introduction

Forget :

class  Module{        public  function  getConfig()        {                return  include  __DIR__  .  ‘/config/module.config.php’;        }}

Use this :

class  Module  implements  ConfigProviderInterface{        public  function  getConfig()        {                return  include  __DIR__  .  ‘/config/module.config.php’;        }}

* And maybe some components written in Zephir !

jeudi 16 janvier 14

Page 12: ZF3 introduction

Zephir ?Zephir can be seen as a hybrid language that allows to write code that looks like PHP, but is compiled to native C code, which allows to create an extension from it, and having a very efficient code.

http://www.michaelgallego.fr/blog/2013/08/28/a-quick-introduction-to-zephir-language/

public function trigger(string event) { var callable, listeners; let listeners = this->listeners;

if array_key_exists(event, listeners) { let callable = listeners[event]; return call_user_func(callable); } }

jeudi 16 janvier 14

Page 13: ZF3 introduction

Zephir ?* Write your code* Compile your code* Execute your code

http://www.michaelgallego.fr/blog/2013/08/28/a-quick-introduction-to-zephir-language/

$eventManager = new Test\EventManager();$eventManager->attach('myEvent', function() { echo 'Okey!';});

$eventManager->trigger('myEvent'); // outputs "Okey!"

PHP_METHOD(Test_EventManager, trigger) {

zval *event_param = NULL, *callable, *listeners, _0 = zval_used_for_init, *_1; zephir_str *event = NULL; ZEPHIR_MM_GROW(); zephir_fetch_params(1, 1, 0, &event_param); [...]

jeudi 16 janvier 14

Page 14: ZF3 introduction

The great debatesMigration :

* Easier than ZF1 -> ZF2 : concept will be close, the major changes will concern the internal code

* Maybe a gateway to migrate easily

* But there will be some code to re-written

jeudi 16 janvier 14

Page 15: ZF3 introduction

The great debatesDon’t do anything with the service locator ...

In a perfect world, you will never use your service locator in a controller or in a library ...

Maybe ZF2 will remove ServiceLocatorAwareInterface and set all your dependences !

jeudi 16 janvier 14

Page 16: ZF3 introduction

The great debatesBut, what about memory ?

My controller has 5 actions which use more than 8 resources ... Why I need to set up 6 or 7 resources for nothing ?

Help me please !

jeudi 16 janvier 14

Page 17: ZF3 introduction

The great debatesNo worries, you are in Australia !

ProxyManager is here for you ! Change nothing !

* Define your getter and setter in your controller* Don’t use the Service Locator in your controller !* Define your controller factory* Use the ProxyManager to have lazy loading

jeudi 16 janvier 14

Page 18: ZF3 introduction

class  MemberController  extends  AbstractActionController{        protected  $loginForm;          public  function  loginAction()        {                $form  =  $this-­‐>getLoginForm();                //  ...  your  action  here        }          public  function  setLoginForm(LoginForm$loginForm)        {                $this-­‐>loginForm  =  $loginForm;        }          public  function  getLoginForm()        {                if  (null  ===  $this-­‐>loginForm)  {                        throw  new  LogicException('Login  form  must  be  defined');                }                return  $this-­‐>loginForm;        }}

jeudi 16 janvier 14

Page 19: ZF3 introduction

class  MemberControllerFactory  implements  FactoryInterface{        public  function  createService(ServiceLocatorInterface  $sm)        {                $factory  =  new  LazyLoadingGhostFactory();                $proxy  =  $factory-­‐>createProxy(                        'MemberManager\Controller\MemberController',                        function($proxy,  $method,  $parameters,  &$initializer)  use  ($sm)                        {                                if  ($method  ==  'getLoginForm')  {                                        $proxy-­‐>setLoginForm(                                                $sm-­‐>get('MemberManager\Form\Login')                                        );                                }                        }                );                  return  $proxy;        }}

Lazy loading with the proxy manager :

jeudi 16 janvier 14

Page 20: ZF3 introduction

The great debatesWhat are the advantages ?

Your application is more decoupled and ...

* It’s Really REALLY easier to write your tests !

* No dependence with a service locator !

jeudi 16 janvier 14

Page 21: ZF3 introduction

jeudi 16 janvier 14

Page 22: ZF3 introduction

New validators

$validator  =  new  Boolean();if  (!$validator-­‐>isValid(true))  {      $error  =  $validator-­‐>getErrorMessages();}

$validator  =  new  Boolean();$validationResult  =  $validator-­‐>validate($value);

if  ($validationResult-­‐>isValid())  {        $error  =  $validationResult-­‐>getErrorMessages();}

Currently :

Make the validator stateless :

jeudi 16 janvier 14

Page 23: ZF3 introduction

New routerarray(        'path'  =>  '/foo',        'action'  =>  'bar',        'controller'  =>  'FooController',        'methods'  =>  array('get',  'post'));

No route type, 5x faster :

Easily configurable :array(        'path'  =>  '/foo',        'action'  =>  'bar',        'controller'  =>  'FooController',        'hostname'  =>  'login.example.com'],        'secure'  =>  true);

jeudi 16 janvier 14

Page 24: ZF3 introduction

EventManager proposals* 3 proposals :

1/ use callable type hinting, faster

2/ Listener and EventManager are merged

3/ a simple rewrite, 6x faster

jeudi 16 janvier 14

Page 25: ZF3 introduction

So, is ZF the good choice ?YES, but ...

ALWAYS keep an eye on native C framework, like Phalcon, or more structured and code oriented company and framework like Symfony !

And don’t forget, ZF has awesome contributors (Marco Pivetta, Evan Coury, O'Phinney, M. Gallego, etc) and still probably the faster (and the biggest) MVC framework !

jeudi 16 janvier 14

Page 26: ZF3 introduction

Best plan for 4mation ?* Get the ZF2 certification

* Read every week some PR on the zend framework repository -- best way to stay tuned

* Add your modules on Github and contribute to most popular modules -- best way to become popular among the ZF developer and improve the company skills

jeudi 16 janvier 14

Page 27: ZF3 introduction

Questions ?

jeudi 16 janvier 14


Recommended