2010_11_04_zf2talk_101104230157_phpapp01
TRANSCRIPT
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
1/61
3 November 2010
Matthew Weier O'Phinney
Project Lead
Ralph Schindler
Software Engineer IntroducingIntroducingZend Framework 2.0Zend Framework 2.0
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
2/61
2
Some History
Summer 2005:Coding begins on Zend Framework, with a
handful of cherry-picked partners.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
3/61
3
Some History
Fall 2005:First annualZendCon
Andi and Zeev announce the PHP Community
Process, which includes involvement in the
Eclipse Foundation, a relaunch of Zend's
Developer Zone, andZend Framework.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
4/61
4
Some History
March 2006:Zend Framework0.1.0released
Project opened up to the public for
contributions; contributions require a
Contributor License Agreement.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
5/61
5
Some History
July 2007:Zend Framework1.0.0released
Project includes MVC stack, Table and Row
Data Gateways, loads of Service APIs,
Authentication and Authorization layers, service
providers, and more.
Still largely deemed a work in progress.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
6/61
6
Some History
March 2008:Zend Framework1.5.0released
Includes Zend_Form and Zend_Layout, and
many Zend_View enhancements.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
7/61
7
Some History
September 2008:Zend Framework1.6.0released
Includes Dojo Toolkit integration, functional test
utilities.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
8/61
8
Some History
November 2008:Zend Framework1.7.0released
Includes AMF support, performance
improvements.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
9/61
9
Some History
April 2009:Zend Framework1.8.0released
Includes Zend_Application, Zend_Tool.
First release widely seen as providing a full
stack.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
10/61
10
Some History
July 2009:Zend Framework1.9.0released
Includes reworked feed component,
Zend_Feed_Reader, and tons of community-
driven enhancements.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
11/61
11
Some History
October 2009:First monthly community bug hunts launched.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
12/61
12
Some History
January 2010:Zend Framework1.10.0released
Includes Zend_Feed_Writer, re-organized
documentation, and community-driven
improvements.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
13/61
13
Some History
February 2010:Development on Zend Framework2.0begins
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
14/61
14
Some History
June 2010:Formation of the Community Review Team
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
15/61
15
Some History
November 2010:Zend Framework1.11.0released
Includesmobilesupport and
SimpleCloudAPI.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
16/61
16
Some History
The future?
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
17/61
Revolution?Revolution?
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
18/61
Evolution.Evolution.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
19/61
19
Incremental Improvements
Autoload only (strip require_once calls)
Conversion to PHP namespaces
Refactor and standardize exceptions usage
Refactor and consistently implement a
single plugin loading strategy
Refactor to use PHP 5.3-specific paradigms
where they fit
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
20/61
Rewrite onlyRewrite onlywhere it makeswhere it makes
sensesense
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
21/61
21
Zend_Db
Difficult to get the underlying connectionand share it between instances or different
classes.
Difficult to get schema metadata in aconsistent fashion.
Difficult to extend.
Difficult to add pre/post tasks.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
22/61
22
Zend_Session
Black-box design != testable
Namespace storage incompatible with
$_SESSION
Many incompatibilities with ext/session
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
23/61
23
useZend\Session\SessionManager,Zend\Session\ContainerasSessionContainer;
$manager =newSessionManager(array(
'class' =>'My\Custom\SessionConfiguration', 'storage'=>'My\Custom\SessionStorage',));$container =newSessionContainer('Foo', $manager);$container['somekey'] ='somevalue';
$container->setExpirationHops(2);
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
24/61
24
Filters and Validators
Static access and chain usage were mixedin the same object
Did not use common plugin loading
methodology
Paradigms required in Filter_Input and
Form were not supported
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
25/61
25
namespaceZend\Validator;
if(StaticValidator::execute($value,'int')) { // passed validation
}
$chain =newValidatorChain();$chain->addValidator(newInt(),true) ->addValidator(newGreaterThan(10));
if($chain->isValid($value)) { // passed validation}
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
26/61
AddAddfeatures favoringfeatures favoring
extensibilityextensibility
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
27/61
27
Examples
SignalSlotFilterChain
SPL extensions (SplStack, SplQueue)
PluginBroker
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
28/61
Favor the ExplicitFavor the Explicit
Okay, notOkay, not thatthatkind of explicitkind of explicit
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
29/61
Magic isMagic issometimessometimes
too arcanetoo arcane
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
30/61
30
echo $this->headLink()->appendStylesheet('foo.css');
/*** Hits Zend_View::__call()* Calls Zend_View::getHelper()* Calls Zend_View::_getPlugin()* Calls Zend_Loader_PluginLoader::load()
* Calls Zend_Loader::isReadable()* Calls call_user_func (hits autoloader...)* which calls Zend_Loader::loadClass* which calls Zend_Loader::loadFile* which calls include_once* Instantiates helper* Calls method on helper via call_user_func_array()* Returns helper instance* Call method on instance (hits __call...))*/
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
31/61
(hidden) automation(hidden) automation
makes learning hardmakes learning hard
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
32/61
32
classFooController
extendsZend_Controller_Action{ public functionsomeAction() {
$this->view->foo='bar';
}}
Where is
this defined? When isit rendered?
What about
layouts?
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
33/61
Explicit code isExplicit code is
easier toeasier tounderstandunderstand
$this->broker('head_link')->appendStylesheet('foo.css');
/*** Hits PhpRenderer::broker()* Calls HelperBroker::load()* Calls HelperLoader::load()* Hits autoloader* which simply does an include_once* Instantiates helper* Calls method on helper
*/
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
34/61
Explicit code isExplicit code is
easier toeasier toprofileprofile
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
35/61
Explicit code isExplicit code is
easier toeasier tomaintainmaintain
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
36/61
Optimize forOptimize for
performanceperformance
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
37/61
37
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
38/61
38
Profiling
Profile to determinewhere the pain
points are
Look for big gains
primarily
Fix them
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
39/61
39
Autoloading: Problems
Class Maps are fastestBut they require maintenance
Using the include_path is slow
Not using it requires maintenance
Using the include_path is most flexible
But slower than alternatives
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
40/61
40
Autoloading: Solutions
Ship a ClassMapAutoloader by defaultClass maps for full ZF library, and per-component
Tools for generating class maps
Ultimate in performance
StandardAutoloader requires
namespace/path pairs
Flexibility andperformance during development
StandardAutoloader can act as a fallback
autoloader
Flexibility at the cost of performance
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
41/61
41
// .classmap.phpreturn array( 'Foo\SomeController'=>__DIR__.
'/foo/controllers/SomeController.php', 'Foo\Model\Bar' =>__DIR__.'/foo/models/Bar.php',
);
// ClassMapAutoloaderrequire_once'Zend/Loader/ClassMapAutoloader.php';$loader =newZend\Loader\ClassMapAutoloader( './.classmap.php');
$loader->register();
$bar =newFoo\Model\Bar();
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
42/61
42
// StandardAutoloaderrequire_once'Zend/Loader/StandardAutoloader.php';$loader =newZend\Loader\StandardAutoloader(array( 'namespaces'=>array( 'Foo'=>__DIR__.'/library/Foo'),));$loader->register();
$bar =newFoo\Model\Bar();
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
43/61
43
Plugin Loading: Problems
Path stack-based autoloading is sloooowPrefix paths are hard to grasp
Particularly when coupled with stacks
Overriding the paths without propagating
paths is hard
Case sensitivity becomes an issue
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
44/61
44
Plugin Loading: Problems
Current solution only solves the classloading aspect of plugin loading
Instantiation happens differently per
component
Persistence happens differently per
component
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
45/61
45
Plugin Loading: Solutions
Class alias based maps by defaultLoaders are coupled with brokers
Handle instantiation, including arguments
Act as registry
Allows attaching single broker to many
objects
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
46/61
46
/* class loader */namespaceMy\Component;useZend\Loader\PluginClassLoader,
Zend\Loader\PluginBroker;
classComponentLoaderextendsPluginClassLoader{ protected $plugins =array( 'foo' =>'My\Component\Foo', 'foo_bar'=>'My\Component\FooBar',
);}
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
47/61
47
/* class broker */namespaceMy\Component;useZend\Loader\PluginClassLoader,
Zend\Loader\PluginBroker;
classComponentBrokerextendsPluginBroker{ protected $defaultClassLoader =
'My\Component\PluginClassLoader';
protected functionvalidatePlugin($plugin) { if(!$plugin instanceofAdapter) { throw newException\RuntimeException(); } returntrue; }}
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
48/61
48
/* factory */namespaceMy\Component;
classFactory{ /* Not shown: setBroker() and broker() methods */
public functionget($adapter,array $options) { return $this->broker()
->load($adapter, $options); }}
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
49/61
Ease the learning curveEase the learning curve
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
50/61
50
Common Documentation Complaints
Options are (often) not documented.Available functionality (typically, methods) is
not presented.
Inconsistent structure between
documentation of different components.
Examples do not show common use cases,
only using the component individually.
No examples showing complete application
development.
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
51/61
51
Common Learning Problems
Magic (__ methods) is hard to learn(just ask Harry Potter).
Uncertainty where and when to extend or
implement extension points and how toget ZF to use them.
Some patterns are non-obvious in usage
(Zend_Form decorators).
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
52/61
52
Proposed Solutions
Coding:Refactor where usage patterns differ
from design
Reduce number of magic calls
Refactor for consistency
Refactor unclear APIs
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
53/61
53
Proposed Solutions
Documentation Standards:Introduction
Quick Start
Options
Methods
Examples
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
54/61
The RoadmapThe Roadmap
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
55/61
55
Completed Milestones
Migration to Git for ZF2 developmentStripping of require_once calls
Migration to PHP 5.3 namespaces
Including SPL additions, Session rewrite, and
addition of SignalSlot
Autoloading and plugin loading/brokering
Including View rewrite
Exceptions
In fact, we've just released a new
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
56/61
56
Completed Milestones
Zend Framework 2.0.0dev2:http://bit.ly/zf2dev2
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
57/61
57
Remaining Milestones
MVC Refactoring/RewriteInternationalization and Localization
Testing
Documentation
Packaging
Migration tools
H
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
58/61
HowHow
YOUYOU
cancan
helphelp
C t ib t t ZF2!
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
59/61
59
Contribute to ZF2!
ZF2 wiki:http://bit.ly/zf2wiki
zf-contributors mailing list:
#zftalk.dev on Freenode
ZF2 Git
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
60/61
60
ZF2 Git
Git guide:http://bit.ly/zf2gitguide
GitHub:
http://github.com/zendframework/zf2
Official repo:
git://git.zendframework.com/zf.git
http://git.zendframework.com/
You still need to sign a CLA!
-
8/8/2019 2010_11_04_zf2talk_101104230157_phpapp01
61/61
Thank you!Thank you!http://framework.zend.comhttp://framework.zend.com
Feedback: http:://joind.in/2287Feedback: http:://joind.in/2287
Twitter:Twitter: weierophinney,weierophinney,
ralphschindlerralphschindler