6
Zend Framework Basic Request Workflow Chart public/index.php application/ bootstrap.php End User’s Browser Request for a page Requires application/ bootstrap.php Configure include paths URL Register Custom Plugin Initializer that runs $this->initDb(); $this->initHelpers(); $this->initView(); $this->initPlugins(); $this->initRoutes(); $this->initControllers(); Prepares Front Controller Pass in Environment (development/staging/...) Pass in Optional Custom Request & Response Object Runs Front Controller Dispatch V 1.01, Created by Polley Wong

Zend Framework Dispatch Workflow (v1.01)

Embed Size (px)

DESCRIPTION

I've been researching Zend Framework lately and was curious about what's actually happening behind the scene of the whole dispatch process. I found a wonderful diagram created by Thorsten Ruf (http://nethands.de/download/zenddispatch_en.pdf) Inspired by it's clear and beautifully presented workflow, I decided to go a step deeper and crawl Zend Framework's code. I came up with my own version of the flexible yet complicated workflow. The Zend Framework version is 1.7, noting that things might have changed a bit in the latest 1.8 version that was released a weeks ago.

Citation preview

Page 1: Zend Framework Dispatch Workflow (v1.01)

Zend Framework Basic Request Workflow Chartpu

blic

/inde

x.ph

pap

plic

atio

n/bo

otst

rap.

php

End

Use

r’s

Bro

wse

r

Request for a page

Requires

application/bootstrap.php

Configure include paths

URL

Register Custom Plugin Initializer that runs $this->initDb(); $this->initHelpers(); $this->initView(); $this->initPlugins(); $this->initRoutes(); $this->initControllers();

Prepares Front Controller

Pass inEnvironment

(development/staging/...)

Pass in Optional CustomRequest & Response

Object

Runs

Front Controller Dispatch

V 1.01, Created by Polley Wong

Page 2: Zend Framework Dispatch Workflow (v1.01)

Front Controller Dispatch Workflow Chart

Rou

ter

Plu

gin

Bro

ker

Fron

t Con

trolle

r

Register Request Object

and Response Object

with Plugin Broker

Instantiate Default

Response Objectif none provided

Instantiate Default Request Object if none

provided

Notify Plugin Broker

of Router Startup

Run Plugin’s routeStartup()

More Plugins with routeStartup() method? Yes

No

Start Routing

Find a matching route to the

current PATH_INFO

Inject returning values to the

Request Object

Notify Plugin Broker

of Router Completion

YesMore Plugins with routeShutdown()

method?

Run Plugin’s routeShutdown()

Extract Module, Controller, Action and Parameters

Runs

Front Controller Dispatch

No

V 1.01, Created by Polley Wong

Page 3: Zend Framework Dispatch Workflow (v1.01)

Front Controller Dispatch Workflow Chart

Rou

ter

Plu

gin

Bro

ker

Fron

t Con

trolle

r

Yes

No

Yes

Runs

Front Controller Dispatch

Run Plugin’s routeShutdown()

Inject returning values to the

Request Object

Run Plugin’s routeStartup()

Notify Plugin Broker

of Router Startup

More Plugins with routeShutdown()

method?

Notify Plugin Broker

of Router Completion

Instantiate Default

Response Objectif none provided

Start Routing

Extract Module, Controller, Action and Parameters

More Plugins with routeStartup() method?

Find a matching route to the

current PATH_INFO

Instantiate Default Request Object if none

provided

Register Request Object

and Response Object

with Plugin Broker

No

cont.

V 1.01, Created by Polley Wong

Routing Process

Page 4: Zend Framework Dispatch Workflow (v1.01)

Front Controller Dispatch Workflow ChartP

lugi

n B

roke

rFr

ont C

ontro

ller

RequestObject

Yes

No

Yes

RequestObject

No

Request ObjectNo: and

Response Object

Yes

RequestObject No

Yes

Yes

Replace current Action Skip current action

More Plugins with postDispatch()

method?

Run Plugin’s preDispatch()

Run Plugin’s dispatchLoopStartup()

More Plugins with dispatchLoopStartup()

method?

Set Request Object'’s

“isDispatched Flag”to

TRUE

Notify Plugin Broker

of Dispatch

Completion

More Plugins with preDispatch()

method?

Did anypreDispatch() reset “isDispatched Flag”

to FALSE?

Run Plugin’s postDispatch()

Notify Plugin Broker

of Dispatch Loop

Startup

Notify Plugin Broker

of Dispatch Startup

Did anypostDispatch() reset “isDispatched Flag”

to FALSE?

Action Controller Dispatch Process

Replace current Action OR

Skip current action

cont.

cont.

postDispatch ProcesspreDispatch Process

V 1.01, Created by Polley Wong

Page 5: Zend Framework Dispatch Workflow (v1.01)

Front Controller Dispatch Workflow ChartA

ctio

n H

elpe

r B

roke

rA

ctio

n C

ontro

ller

Con

trolle

r Dis

patc

her

Plug

in B

roke

rFr

ont C

ontro

ller

RequestObject

Yes

No

Yes

RequestObject

No

Request ObjectNo: and

Response Object

Yes

RequestObject No

Yes

Yes

Replace current Action Skip current action

TRUE

FALSE

TRUE

FALSE

Yes

No

Yes

NoNo

Yes

Run Plugin’s postDispatch()

Notify Plugin Broker

of Dispatch Loop

Startup

Run init() method

in helper

More helper in stack?

More Plugins with postDispatch()

method?

Initialize Action Helper Broker

RretrieveAction Method

Name from Request Object

Run setActionController()

method in helper

Notify Plugin Broker

of Dispatch Startup cont.

Notify Helper Broker

of Dispatch Completion

More Helpers with preDispatch()

method?

Load Controllerclass file

Set Request Object'’s

“isDispatched Flag”to

TRUE

Run Action Controller’s

postDispatch()

More Helpers with postDispatch()

method?

Did anypreDispatch() reset “isDispatched Flag”

to FALSE?

Is parameter disableOutputBuffering

TRUE (default)or FALSE?

Run Plugin’s dispatchLoopStartup()

Run Action Controller’s

preDispatch()

Is“isDispatched

Flag” ==TRUE?

Append buffered content into

Response Object’s body

Notify Plugin Broker

of Dispatch

Completion

Call of theAction Method

Run Plugin’s preDispatch()

Register Action Controller

with Helper Broker

Action Controller Dispatch Process

Call Action Controller’s dispatch() method

(Passes the Name of Actionto the method) Destroy Action

Controller Object

Set Request Object'’s

“isDispatched Flag”to

TRUE

Is parameter disableOutputBuffering

TRUE (default)or FALSE?

Run Helper’s preDispatch()

output buffer start

Replace current Action OR

Skip current action

Did anypostDispatch() reset “isDispatched Flag”

to FALSE?

Run Helper’s postDispatch()

Notify Helper Broker

of Dispatch Startup

More Plugins with dispatchLoopStartup()

method?

More Plugins with preDispatch()

method?

postDispatch ProcesspreDispatch Process

cont.

V 1.01, Created by Polley Wong

Page 6: Zend Framework Dispatch Workflow (v1.01)

Front Controller Dispatch Workflow Chart

End

Use

r’s

Bro

wse

rR

espo

nse

Obj

ect

Plu

gin

Bro

ker

Fron

t Con

trolle

r

RequestObject

Yes

No

More Plugins with dispatchLoopShutdown()

method?

Return the Response Object

Run Plugin’s dispatchLoopShutdown()

Notify Plugin Broker

of Dispatch Loop

Completion

Is “returnResponse” Flag set to TRUE?

Yes

sendResponse()

Send Headers Output Body(echo $content)

Waiting for User Input

cont.

postDispatch Process (cont.)

V 1.01, Created by Polley Wong