2. 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
3. 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
5. 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
6. 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
7. Better normalization ...
Zend Framework services name :
array(
'my_factory'
=>
'MyFactory',
'my.factory'
=>
'MyFactory',
'MyFactory'
=>
'MyFactory',
);
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
8. Other ideas
* Routing by annotation
* Composer autoloader usage
* Doctrine instead of ZendDb
* Modularize ZF2 (Symfony style)
* Get route parameters inside actions controllers
jeudi 16 janvier 14
9. * 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
10. 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
11. 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
12. 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.
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);
}
}
http://www.michaelgallego.fr/blog/2013/08/28/a-quick-introduction-to-zephir-language/
jeudi 16 janvier 14
14. The great debates
Migration :
* 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
15. The great debates
Don’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
16. The great debates
But, 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
17. The great debates
No 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
18. 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
19. class
MemberControllerFactory
implements
FactoryInterface
{
public
function
createService(ServiceLocatorInterface
$sm)
{
$factory
=
new
LazyLoadingGhostFactory();
$proxy
=
$factory-‐>createProxy(
'MemberManagerControllerMemberController',
function($proxy,
$method,
$parameters,
&$initializer)
use
($sm)
{
if
($method
==
'getLoginForm')
{
$proxy-‐>setLoginForm(
$sm-‐>get('MemberManagerFormLogin')
);
}
}
);
return
$proxy;
}
}
Lazy loading with the proxy manager :
jeudi 16 janvier 14
20. The great debates
What 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
22. New validators
Currently :
$validator
=
new
Boolean();
if
(!$validator-‐>isValid(true))
{
$error
=
$validator-‐>getErrorMessages();
}
Make the validator stateless :
$validator
=
new
Boolean();
$validationResult
=
$validator-‐>validate($value);
if
($validationResult-‐>isValid())
{
$error
=
$validationResult-‐>getErrorMessages();
}
jeudi 16 janvier 14
24. 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
25. 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
26. 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