project lead introducing · 3 november 2010 matthew weier o'phinney project lead ralph...

58
3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Introducing Zend Framework 2.0 Zend Framework 2.0

Upload: others

Post on 14-Jul-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

3 November 2010

Matthew Weier O'PhinneyProject Lead

Ralph SchindlerSoftware Engineer IntroducingIntroducing

Zend Framework 2.0Zend Framework 2.0

Page 2: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

2

Some History

Summer 2005:Coding begins on Zend Framework, with a handful of cherry-picked partners.

Page 3: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

3

Some History

Fall 2005:First annual ZendConAndi and Zeev announce the PHP Community Process, which includes involvement in the Eclipse Foundation, a relaunch of Zend's Developer Zone, and Zend Framework.

Page 4: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

4

Some History

March 2006:Zend Framework 0.1.0 releasedProject opened up to the public for contributions; contributions require a Contributor License Agreement.

Page 5: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

5

Some History

July 2007:Zend Framework 1.0.0 releasedProject 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.

Page 6: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

6

Some History

March 2008:Zend Framework 1.5.0 releasedIncludes Zend_Form and Zend_Layout, and many Zend_View enhancements.

Page 7: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

7

Some History

September 2008:Zend Framework 1.6.0 releasedIncludes Dojo Toolkit integration, functional test utilities.

Page 8: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

8

Some History

November 2008:Zend Framework 1.7.0 releasedIncludes AMF support, performance improvements.

Page 9: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

9

Some History

April 2009:Zend Framework 1.8.0 releasedIncludes Zend_Application, Zend_Tool.First release widely seen as providing a full stack.

Page 10: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

10

Some History

July 2009:Zend Framework 1.9.0 releasedIncludes reworked feed component, Zend_Feed_Reader, and tons of community-driven enhancements.

Page 11: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

11

Some History

October 2009:First monthly community bug hunts launched.

Page 12: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

12

Some History

January 2010:Zend Framework 1.10.0 releasedIncludes Zend_Feed_Writer, re-organized documentation, and community-driven improvements.

Page 13: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

13

Some History

February 2010:Development on Zend Framework 2.0 begins

Page 14: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

14

Some History

June 2010:Formation of the Community Review Team

Page 15: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

15

Some History

November 2010:Zend Framework 1.11.0 releasedIncludes mobile support and SimpleCloud API.

Page 16: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

16

Some History

The future?

Page 17: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

Revolution?Revolution?

Page 18: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

Evolution.Evolution.

Page 19: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

19

Incremental Improvements

Autoload only (strip require_once calls)Conversion to PHP namespaces Refactor and standardize exceptions usageRefactor and consistently implement a single plugin loading strategyRefactor to use PHP 5.3-specific paradigms where they fit

Page 20: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

Rewrite only Rewrite only where it makes where it makes sensesense

Page 21: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

21

Zend_Db

Difficult to get the underlying connection and share it between instances or different classes.Difficult to get schema metadata in a consistent fashion.Difficult to extend.Difficult to add pre/post tasks.

Page 22: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

22

Zend_Session

Black-box design != testableNamespace storage incompatible with $_SESSION Many incompatibilities with ext/session

Page 23: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

23

use Zend\Session\SessionManager, Zend\Session\Container as SessionContainer;

$manager = new SessionManager(array( 'class' => 'My\Custom\SessionConfiguration', 'storage' => 'My\Custom\SessionStorage',));$container = new SessionContainer('Foo', $manager);$container['somekey'] = 'somevalue';$container->setExpirationHops(2);

use Zend\Session\SessionManager, Zend\Session\Container as SessionContainer;

$manager = new SessionManager(array( 'class' => 'My\Custom\SessionConfiguration', 'storage' => 'My\Custom\SessionStorage',));$container = new SessionContainer('Foo', $manager);$container['somekey'] = 'somevalue';$container->setExpirationHops(2);

Page 24: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

24

Filters and Validators

Static access and chain usage were mixed in the same objectDid not use common plugin loading methodology

Page 25: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

25

namespace Zend\Validator;

if (StaticValidator::execute($value, 'int')) { // passed validation}

$chain = new ValidatorChain();$chain->addValidator(new Int(), true) ->addValidator(new GreaterThan(10));

if ($chain->isValid($value)) { // passed validation}

namespace Zend\Validator;

if (StaticValidator::execute($value, 'int')) { // passed validation}

$chain = new ValidatorChain();$chain->addValidator(new Int(), true) ->addValidator(new GreaterThan(10));

if ($chain->isValid($value)) { // passed validation}

Page 26: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

Favor the ExplicitFavor the ExplicitOkay, not Okay, not thatthat kind of explicit kind of explicit……

Page 27: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

Magic is Magic is sometimessometimestoo arcanetoo arcane

Page 28: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

28

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...)) */

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...)) */

Page 29: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

(hidden) automation (hidden) automation makes learning hardmakes learning hard

Page 30: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

30

class FooController extends Zend_Controller_Action{ public function someAction() { $this->view->foo = 'bar'; }}

class FooController extends Zend_Controller_Action{ public function someAction() { $this->view->foo = 'bar'; }}

Where is this defined? When is

it rendered? What aboutlayouts?

Page 31: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

Explicit code isExplicit code is……easier to easier to understandunderstand

$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 */

$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 */

Page 32: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

Explicit code isExplicit code is……easier to easier to profileprofile

Page 33: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

Optimize for Optimize for performanceperformance

Page 34: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

34

Page 35: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

35

Profiling

Profile to determine where the pain points areLook for big gains primarilyFix them

Page 36: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

36

Autoloading: Problems

Class Maps are fastestBut they require maintenance

Using the include_path is slowNot using it requires maintenance

Using the include_path is most flexibleBut slower than alternatives

Page 37: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

37

Autoloading: Solutions

Ship a ClassMapAutoloader by defaultClass maps for full ZF library, and per-componentTools for generating class mapsUltimate in performance

StandardAutoloader requires namespace/path pairs

Flexibility and performance during development

StandardAutoloader can act as a fallback autoloader

Flexibility at the cost of performance

Page 38: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

38

// .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 = new Zend\Loader\ClassMapAutoloader( './.classmap.php');$loader->register();

$bar = new Foo\Model\Bar();

// .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 = new Zend\Loader\ClassMapAutoloader( './.classmap.php');$loader->register();

$bar = new Foo\Model\Bar();

Page 39: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

39

// StandardAutoloaderrequire_once 'Zend/Loader/StandardAutoloader.php';$loader = new Zend\Loader\StandardAutoloader(array( 'namespaces' => array( 'Foo' => __DIR__ . '/library/Foo'),));$loader->register();

$bar = new Foo\Model\Bar();

// StandardAutoloaderrequire_once 'Zend/Loader/StandardAutoloader.php';$loader = new Zend\Loader\StandardAutoloader(array( 'namespaces' => array( 'Foo' => __DIR__ . '/library/Foo'),));$loader->register();

$bar = new Foo\Model\Bar();

Page 40: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

40

Plugin Loading: Problems

Path stack-based autoloading is sloooowPrefix paths are hard to grasp

Particularly when coupled with stacksOverriding the paths without propagating paths is hardCase sensitivity becomes an issue

Page 41: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

41

Plugin Loading: Problems

Current solution only solves the class loading aspect of plugin loadingInstantiation happens differently per componentPersistence happens differently per component

Page 42: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

42

Plugin Loading: Solutions

Class alias based maps by defaultLoaders are coupled with brokers

Handle instantiation, including argumentsAct as registry

Allows attaching single broker to many objects

Page 43: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

43

/* class loader */namespace My\Component;use Zend\Loader\PluginClassLoader, Zend\Loader\PluginBroker;

class ComponentLoader extends PluginClassLoader{ protected $plugins = array( 'foo' => 'My\Component\Foo', 'foo_bar' => 'My\Component\FooBar', );}

/* class loader */namespace My\Component;use Zend\Loader\PluginClassLoader, Zend\Loader\PluginBroker;

class ComponentLoader extends PluginClassLoader{ protected $plugins = array( 'foo' => 'My\Component\Foo', 'foo_bar' => 'My\Component\FooBar', );}

Page 44: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

44

/* class broker */namespace My\Component;use Zend\Loader\PluginClassLoader, Zend\Loader\PluginBroker;

class ComponentBroker extends PluginBroker{ protected $defaultClassLoader = 'My\Component\PluginClassLoader';

protected function validatePlugin($plugin) { if (!$plugin instanceof Adapter) { throw new Exception\RuntimeException(); } return true; }}

/* class broker */namespace My\Component;use Zend\Loader\PluginClassLoader, Zend\Loader\PluginBroker;

class ComponentBroker extends PluginBroker{ protected $defaultClassLoader = 'My\Component\PluginClassLoader';

protected function validatePlugin($plugin) { if (!$plugin instanceof Adapter) { throw new Exception\RuntimeException(); } return true; }}

Page 45: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

45

/* factory */namespace My\Component;

class Factory{ /* Not shown: setBroker() and broker() methods */

public function get($adapter, array $options) { return $this->broker() ->load($adapter, $options); }}

/* factory */namespace My\Component;

class Factory{ /* Not shown: setBroker() and broker() methods */

public function get($adapter, array $options) { return $this->broker() ->load($adapter, $options); }}

Page 46: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

Ease the learning curveEase the learning curve

Page 47: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

47

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.

Page 48: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

48

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 to get ZF to use them.Some patterns are non-obvious in usage (Zend_Form decorators…).

Page 49: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

49

Proposed Solutions

Coding:Refactor where usage patterns differ from designReduce number of magic callsRefactor for consistencyRefactor unclear APIs

Page 50: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

50

Proposed Solutions

Documentation Standards:IntroductionQuick StartOptionsMethodsExamples

Page 51: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

The RoadmapThe Roadmap

Page 52: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

52

Completed Milestones

Migration to Git for ZF2 developmentStripping of require_once callsMigration to PHP 5.3 namespaces

Including SPL additions, Session rewrite, and addition of SignalSlot

Autoloading and plugin loading/brokeringIncluding View rewrite

ExceptionsIn fact, we've just released a new development milestone snapshot!

Page 53: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

53

Completed Milestones

Zend Framework 2.0.0dev2:http://bit.ly/zf2dev2

Page 54: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

54

Remaining Milestones

MVC Refactoring/RewriteInternationalization and LocalizationTestingDocumentationPackagingMigration tools

Page 55: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

How How YOU YOU can can helphelp

Page 56: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

56

Contribute to ZF2!

ZF2 wiki:http://bit.ly/zf2wikizf-contributors mailing list:[email protected]: #zftalk.dev on Freenode

Page 57: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

57

ZF2 Git

Git guide: http://bit.ly/zf2gitguideGitHub: http://github.com/zendframework/zf2Official repo: git://git.zendframework.com/zf.githttp://git.zendframework.com/You still need to sign a CLA!

Page 58: Project Lead Introducing · 3 November 2010 Matthew Weier O'Phinney Project Lead Ralph Schindler Software Engineer Introducing Zend Framework 2.0

Thank you!Thank you!http://framework.zend.comhttp://framework.zend.comFeedback: http:://joind.in/2287Feedback: http:://joind.in/2287Twitter:Twitter: weierophinney, weierophinney,

ralphschindlerralphschindler