42
An App Inside An App Making your Zend Framework modules distributable (and how Doctrine can help!)

App Inside An App - Zend UnConn 2008

Embed Size (px)

Citation preview

Page 1: App Inside An App - Zend UnConn 2008

An App Inside An AppMaking your Zend Framework modules distributable

(and how Doctrine can help!)

Page 2: App Inside An App - Zend UnConn 2008

About Me:Jason Eisenmenger

Age 23

Louisville, KY

Saw the end of PHP3

This is my first talk!

Page 3: App Inside An App - Zend UnConn 2008

What this talk covers• Making the decision

• Problems

• Solutions

• Choosing your weapons

• Doctrine

• Demonstration

Page 4: App Inside An App - Zend UnConn 2008

Making the decisionSo you want to share your module, eh?

Page 5: App Inside An App - Zend UnConn 2008

First and foremost:

Feature creep comes really easy.

People don’t like creeps.

Focus only on your module’s intended purpose

Page 6: App Inside An App - Zend UnConn 2008

Problems

Page 7: App Inside An App - Zend UnConn 2008

Dependencies

• Libraries

• Helpers / Plugins

• Base Classes

• Externals

• Methodologies

• Resources

Page 8: App Inside An App - Zend UnConn 2008

Solution

• Include your own library

• Don’t depend on externals

• Use standard methodologies

• Allow as much configuration as possible

Page 9: App Inside An App - Zend UnConn 2008

Integration

• Modules are secluded

Page 10: App Inside An App - Zend UnConn 2008

Solution

• Provide an API

• Plugins

• Helpers

• View Actions

Page 11: App Inside An App - Zend UnConn 2008

Overabundance

• Doing more than some users need/want

• Taking too much control

• Overlap of existing application

Page 12: App Inside An App - Zend UnConn 2008

Solution

• Break it into pieces

• Allow them to be turned on / off

Page 13: App Inside An App - Zend UnConn 2008

Point of Entry

• Requiring as little change of existing code as possible

• The simpler the better

Page 14: App Inside An App - Zend UnConn 2008

Solution

• Bootstrap

• Controller plugin

• No entry

Page 15: App Inside An App - Zend UnConn 2008

Boostrap

• Pros:

• Specify Prerequisites

• Access to application before dispatch

• Cons:

• Exceptions won’t be caught

• Requires excessive coding

Page 16: App Inside An App - Zend UnConn 2008

Controller Plugin

• Pros:

• Access to application hooks

• __construct() setup same as bootstrap

• Simple: one line of code

• Cons:

• Using construct(), prerequisites depend on order of bootstrap

Page 17: App Inside An App - Zend UnConn 2008

Other things keep in mind:

• You can’t please everybody; abstracting everything creates overhead

• Checking turned on/off features creates overhead too

Page 18: App Inside An App - Zend UnConn 2008

Choosing your weapons

Page 19: App Inside An App - Zend UnConn 2008

In the future:

• Zend_Tool

• Bootstrap class

• Module bootstraps

Page 20: App Inside An App - Zend UnConn 2008

DoctrineAnd how it can help!

Before we get to the demo...

Page 21: App Inside An App - Zend UnConn 2008

What is Doctrine?

• Doctrine is an Object Relational Mapper built to work with PHP 5.2.3 or greater.

-Wikipedia

Page 22: App Inside An App - Zend UnConn 2008

Doctrine is organized just like Zend

Page 23: App Inside An App - Zend UnConn 2008

How do queries work?

Turns into:SELECT `p`.`id` AS `p__id`, `p`.`user_id` AS `p__user_id`, `p`.`title` AS `p__title`, `p`.`body` AS `p__body`, `p`.`created_at` AS `p__created_at`, `p`.`updated_at` AS `p__updated_at`, `p`.`slug` AS `p__slug`, `u`.`id` AS `u__id`, `u`.`username` AS `u__username`, `u`.`password` AS `u__password`, `u`.`firstname` AS `u__firstname`, `u`.`lastname` AS `u__lastname` FROM `post` `p` INNER JOIN `user` `u` ON `p`.`user_id` = `u`.`id` ORDER BY `p`.`created_at` DESC

Page 24: App Inside An App - Zend UnConn 2008

How are results returned?

As hydrated

arrays

Page 25: App Inside An App - Zend UnConn 2008

How are results returned?

As hydrated objects

Page 26: App Inside An App - Zend UnConn 2008
Page 27: App Inside An App - Zend UnConn 2008

Saving records:

OR

Page 28: App Inside An App - Zend UnConn 2008

Saving records with relations

Page 29: App Inside An App - Zend UnConn 2008

How is it so smart?

• Uses “schemas” for table / relation definitions

• Builds queries accordingly

Page 30: App Inside An App - Zend UnConn 2008

Doctrine::generateYamlFromDb()

Doctrine::generateModelsFromDb()

Doctrine::generateYamlFromModels()

Doctrine::generateModelsFromYaml()

Doctrine::generateTabelsFromModels()

Doctrine::generateSqlFromModels()

Page 31: App Inside An App - Zend UnConn 2008
Page 32: App Inside An App - Zend UnConn 2008

Migrations

• Tracking SQL changes manually is bad

• Migrations integrate with build processes

• Doctrine can manage them for you

Page 33: App Inside An App - Zend UnConn 2008
Page 34: App Inside An App - Zend UnConn 2008
Page 35: App Inside An App - Zend UnConn 2008
Page 36: App Inside An App - Zend UnConn 2008

Usage:

Page 37: App Inside An App - Zend UnConn 2008

Why I chose Doctrine

• Model Generation

• Migrations

• Code reduction

• Metadata

Page 38: App Inside An App - Zend UnConn 2008

Demo

Page 39: App Inside An App - Zend UnConn 2008

Remember:

It’s still alpha!

Page 40: App Inside An App - Zend UnConn 2008

The Security Module Future:

• Perhaps a full admin module

• More than just module/controller/action ACL

• Routes

• Objects / Relations

• Arbitrary user-specified

• Much more...

Page 41: App Inside An App - Zend UnConn 2008

The ZF Project future:

• Formalized bootstrap spec or class from Zend

• Automatic module hooks

Page 42: App Inside An App - Zend UnConn 2008

Questions:

[email protected]

• http://zfsecurity.googlecode.com

• http://framework.zend.com

• http://www.doctrine-project.org

Thank you!

Doctrine