• Like
  • Save
Propel Your PHP Applications
Upcoming SlideShare
Loading in...5
×
 

Propel Your PHP Applications

on

  • 26,716 views

"Propel Your PHP Applications" presentation at 2007 International PHP Conference in Frankfurt.

"Propel Your PHP Applications" presentation at 2007 International PHP Conference in Frankfurt.

Statistics

Views

Total Views
26,716
Views on SlideShare
25,459
Embed Views
1,257

Actions

Likes
11
Downloads
544
Comments
0

28 Embeds 1,257

http://jsanroman.net 572
http://www.jsanroman.net 284
http://casivaagustin.blogspot.com 131
http://casivaagustin.blogspot.com.ar 50
http://www.slideshare.net 50
http://www.nexen.net 35
http://casivaagustin.com.ar 33
http://casivaagustin.blogspot.com.es 19
http://partners.addada.com 18
http://www.casivaagustin.com.ar 17
http://www.longlinfeng.com 7
http://www.php.rk.edu.pl 7
http://casivaagustin.blogspot.mx 6
http://localhost 5
http://translate.googleusercontent.com 4
http://www.sfexception.com 3
http://www.casivaagustin.blogspot.ru 2
http://casivaagustin.blogspot.de 2
http://casivaagustin.blogspot.ru 2
http://casivaagustin.blogspot.com.br 2
http://casivaagustin.blogspot.com.au 1
http://casivaagustin.blogspot.ro 1
http://casivaagustin.blogspot.cz 1
http://casivaagustin.blogspot.it 1
http://10.150.200.57 1
http://cache.baidu.com 1
http://209.85.229.132 1
http://longlinfeng.blogspot.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Propel Your PHP Applications Propel Your PHP Applications Presentation Transcript

    • Propel Your PHP Applications Hans Lellelid International PHP Conference 2007-11-06
    • Introduction • My name is Hans Lellelid • Developer + manager at Applied Security, Inc. (near Washington DC). • I wrote/ported original Propel. • I currently manage the project with David Zülke – and an ever-growing team of developers. Hans Lellelid: Propel Your PHP Applications 2
    • This Talk • Overview of Propel • A typical work cycle • More in-depth usage • Advanced features • Slides available at http://propel.phpdb.org/presentations/ Hans Lellelid: Propel Your PHP Applications 3
    • Pre-Flight Check Going over the basics. Hans Lellelid: Propel Your PHP Applications 4
    • Fact Sheet • Propel is an ORM tool for PHP5. – It is also a code (and DDL) generator. • Based on Apache Torque. • Includes runtime and generator frameworks. • Uses PDO (v1.2 uses Creole) • Generator uses Phing tasks to create the PHP and SQL files. • Installs using PEAR installer. Hans Lellelid: Propel Your PHP Applications 5
    • ORM Patterns in PHP • The most common alternative ORM pattern in PHP is ActiveRecord. – (Thank you, Ruby on Rails!) • Propel is not an ActiveRecord implementation: it is a Row Data Gateway + Table Data Gateway implementation. • Key differences: – Clean division of labor between table operation objects and row instances. – RDG and TDG are inherently simpler, more transparent, models. Hans Lellelid: Propel Your PHP Applications 6
    • Motivations & Purpose • Created because nothing comparable existed for PHP at the time. • Designed to facilitate prototyping and RAD • Basic Philosophy: Database tasks should feel as simple as they actually are. • Designed for “enterprise” frameworks. Hans Lellelid: Propel Your PHP Applications 7
    • Requirements • PHP 5 – Version 1.3 requires PHP >= 5.2 – SPL, PDO (1.3), XML, XSLT • Phing • A supported database. Currently Propel supports: MySQL, PostgreSQL, MSSQL, Oracle, SQLite Hans Lellelid: Propel Your PHP Applications 8
    • Propel will ... • Generate classes to represent your database (model) in an OOP way. – “Object” classes for rows (RDG) – “Peer” classes for table operations (TDG) • Build SQL (DDL) to initialize your database. • Use unit-of-work pattern to wrap nested inserts in transactions. • Provide Exception-based error handling. • Allow you to avoid SQL (if you want). • Type-cast output and escape input. Hans Lellelid: Propel Your PHP Applications 9
    • But Propel won't ... • Build forms, reports, or other display stuff. – Several full frameworks are built around Propel to provide this (e.g Symfony, Agavi) • Help you design your database. • Prevent you from writing insecure code. • Replenish essential electrolytes after a hard workout. Hans Lellelid: Propel Your PHP Applications 10
    • Flight Plan A Typical Propel Work Cycle Hans Lellelid: Propel Your PHP Applications 11
    • A Typical Workflow • Design Database in XML (schema.xml) • Configure generator (build.properties) • Configure runtime (runtime-conf.xml) • Build SQL DDL and PHP classes. • (Maybe) initialize database. • Use newly-built objects in your application. Hans Lellelid: Propel Your PHP Applications 12
    • schema.xml • The schema.xml is the single authority for your data model. • Written in [quite intuitive] XML <?xml version=quot;1.0quot;?> <database name=quot;demoquot;> <table name=quot;sessionquot;> <column name=quot;idquot; type=quot;integerquot; primaryKey=quot;truequot; /> <column name=quot;namequot; type=quot;varcharquot; size=quot;255quot; /> <column name=quot;roomquot; type=quot;varcharquot; size=quot;16quot; /> <column name=quot;speakerquot; type=quot;varcharquot; size=quot;32quot; /> </table> </database> • Will be validated by build process (DTD and schema provided). Hans Lellelid: Propel Your PHP Applications 13
    • build.properties • Generator uses “properties” files (Phing) • Propel needs to know (at least) your RDBMS and project name. • It's often simplest to start with the provided “bookstore” example. • Example minimal build.properties: propel.project = myproj propel.database = mysql propel.database.url = mysql:dbname=test Hans Lellelid: Propel Your PHP Applications 14
    • runtime-conf.xml • Runtime config expressed in XML. • Configures connection and (optionally) PEAR logging facility. • Gets converted to PHP by build process. <config> <propel> <datasources default=quot;myprojquot;> <datasource id=quot;myprojquot;> <adapter>mysql</adapter> <connection> <dsn>mysql:dbname=test</dsn> </connection> </datasource> </datasources> </propel> </config> Hans Lellelid: Propel Your PHP Applications 15
    • Build! • Run propel-gen /path/to/projdir to build the SQL DDL and PHP classes. • Watch output for errors. (They're red.) Hans Lellelid: Propel Your PHP Applications 16
    • Initialize DB • Use propel-gen /path/to/projdir insert-sql to run the generated DDL statements against your configured database. • This will delete any existing data! Hans Lellelid: Propel Your PHP Applications 17
    • Start using new OM • Initialize Propel require_once 'propel/Propel.php'; Propel::init('/path/to/myproj-conf.php'); • Configure your include_path to include the output directory. – Propel 1.3 uses SPL autoload. • Begin reading and writing DB rows with your new object model. Hans Lellelid: Propel Your PHP Applications 18
    • Cruising Altitude Getting comfortable with Propel. Hans Lellelid: Propel Your PHP Applications 19
    • Column Types • Propel uses an abstract subset of SQL types. • SQL types are mapped to specific PHP types. • You can override the SQL type for a column. • Temporal values (DATE, TIME, TIMESTAMP) will use PHP DateTime objects. Hans Lellelid: Propel Your PHP Applications 20
    • Expressing Relationships • Relationships between tables are defined using foreign keys. – Even for systems that don't support true FK constraints. • Propel supports single or composite foreign keys. • Support for deletion cascading emulation. • The related objects can be get/set just like simple column values. Hans Lellelid: Propel Your PHP Applications 21
    • Selecting Rows • retrieveByPK() static method exists to select a single row. • Criteria provides an OO approach to building queries. • Smart handling of column types. • Multiple “Criterion” objects can be grouped together to form complex queries. • You can also use SQL, if you prefer. Hans Lellelid: Propel Your PHP Applications 22
    • Customization • Build properties customize code generation. • Override method and constant naming from the schema.xml • Empty stub object & peer classes for custom methods: – New methods or – Override parent (base) methods Hans Lellelid: Propel Your PHP Applications 23
    • Over-Drive Wait ... I thought we were using airplane metaphors. Hans Lellelid: Propel Your PHP Applications 24
    • Locator Objects (LOBs) • LOB columns returned as PHP streams. – This is the PDO design (though there are some exceptions). • Mutator methods support streams or (string) file contents. Hans Lellelid: Propel Your PHP Applications 25
    • Inheritance • Propel supports table-per-class-hierarchy inheritance. • Subclasses can be enumerated in the schema.xml (faster) or resolved at runtime (more flexible). • Plans in place for other inheritance models. Hans Lellelid: Propel Your PHP Applications 26
    • Other Features • Reverse engineer existing databases (requires Creole) • Import and export data as XML • Generate Graphviz ERD from schema.xml • Represent trees in SQL using nested set approach. Hans Lellelid: Propel Your PHP Applications 27
    • Extension Paths • Integrating with other Phing projects • Custom platform classes – Affects generation of SQL DDL • Custom builder classes – Determine how your classes are built. Hans Lellelid: Propel Your PHP Applications 28
    • The 2.0 Horizon • Criteria redesign • New inheritance models • Eagerly awaiting PHP6 (or 5.3) – Namespaces – Late static binding • Plugin-based builder framework. Hans Lellelid: Propel Your PHP Applications 29
    • On Behalf of the Flight Crew ... Thanks for listening. :) Hans Lellelid: Propel Your PHP Applications 30