SlideShare a Scribd company logo
1 of 30
Download to read offline
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

More Related Content

What's hot

Getting started with Catalyst and extjs
Getting started with Catalyst and extjsGetting started with Catalyst and extjs
Getting started with Catalyst and extjs
Peter Edwards
 
03 form-data
03 form-data03 form-data
03 form-data
snopteck
 
Introduction to Web Programming with Perl
Introduction to Web Programming with PerlIntroduction to Web Programming with Perl
Introduction to Web Programming with Perl
Dave Cross
 

What's hot (20)

Automated Deployment With Phing
Automated Deployment With PhingAutomated Deployment With Phing
Automated Deployment With Phing
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Practical catalyst
Practical catalystPractical catalyst
Practical catalyst
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
 
Getting started with Catalyst and extjs
Getting started with Catalyst and extjsGetting started with Catalyst and extjs
Getting started with Catalyst and extjs
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
 
03 form-data
03 form-data03 form-data
03 form-data
 
PHP - Introduction to PHP Date and Time Functions
PHP -  Introduction to  PHP Date and Time FunctionsPHP -  Introduction to  PHP Date and Time Functions
PHP - Introduction to PHP Date and Time Functions
 
Modern Web Development with Perl
Modern Web Development with PerlModern Web Development with Perl
Modern Web Development with Perl
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
Perl in the Internet of Things
Perl in the Internet of ThingsPerl in the Internet of Things
Perl in the Internet of Things
 
Os Furlong
Os FurlongOs Furlong
Os Furlong
 
Mastering Namespaces in PHP
Mastering Namespaces in PHPMastering Namespaces in PHP
Mastering Namespaces in PHP
 
Introduction to PHP
Introduction to PHPIntroduction to PHP
Introduction to PHP
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
 
Os Pruett
Os PruettOs Pruett
Os Pruett
 
New Features in PHP 5.3
New Features in PHP 5.3New Features in PHP 5.3
New Features in PHP 5.3
 
Introduction to Web Programming with Perl
Introduction to Web Programming with PerlIntroduction to Web Programming with Perl
Introduction to Web Programming with Perl
 
Web Development in Perl
Web Development in PerlWeb Development in Perl
Web Development in Perl
 
Os Bunce
Os BunceOs Bunce
Os Bunce
 

Similar to Propel Your PHP Applications

Big data processing using HPCC Systems Above and Beyond Hadoop
Big data processing using HPCC Systems Above and Beyond HadoopBig data processing using HPCC Systems Above and Beyond Hadoop
Big data processing using HPCC Systems Above and Beyond Hadoop
HPCC Systems
 
Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016
Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016
Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016
MLconf
 
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
LEDC 2016
 
Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0
Quang Ngoc
 
Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)
Stefan Koopmanschap
 

Similar to Propel Your PHP Applications (20)

Basics PHP
Basics PHPBasics PHP
Basics PHP
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex
 
PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019
PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019
PHP, The X DevAPI, and the MySQL Document Store -- Benelux PHP Confernece 2019
 
PHP, The X DevAPI, and the MySQL Document Store Presented January 23rd, 20...
PHP,  The X DevAPI,  and the  MySQL Document Store Presented January 23rd, 20...PHP,  The X DevAPI,  and the  MySQL Document Store Presented January 23rd, 20...
PHP, The X DevAPI, and the MySQL Document Store Presented January 23rd, 20...
 
Enterprise Perl
Enterprise PerlEnterprise Perl
Enterprise Perl
 
Big data processing using HPCC Systems Above and Beyond Hadoop
Big data processing using HPCC Systems Above and Beyond HadoopBig data processing using HPCC Systems Above and Beyond Hadoop
Big data processing using HPCC Systems Above and Beyond Hadoop
 
Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016
Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016
Arun Rathinasabapathy, Senior Software Engineer, LexisNexis at MLconf ATL 2016
 
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
Артем Сыльчук - Хранение полей в Drupal. От CCK к FieldableEntityStorageContr...
 
Intro to drupal_7_architecture
Intro to drupal_7_architectureIntro to drupal_7_architecture
Intro to drupal_7_architecture
 
PHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iPHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM i
 
Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0Open Source RAD with OpenERP 7.0
Open Source RAD with OpenERP 7.0
 
wamp.ppt
wamp.pptwamp.ppt
wamp.ppt
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Enhancing Domain Specific Language Implementations Through Ontology
Enhancing Domain Specific Language Implementations Through OntologyEnhancing Domain Specific Language Implementations Through Ontology
Enhancing Domain Specific Language Implementations Through Ontology
 
Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)
 
PHP ITCS 323
PHP ITCS 323PHP ITCS 323
PHP ITCS 323
 
Sql php-vibrant course-mumbai(1)
Sql php-vibrant course-mumbai(1)Sql php-vibrant course-mumbai(1)
Sql php-vibrant course-mumbai(1)
 
Php Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi MensahPhp Applications with Oracle by Kuassi Mensah
Php Applications with Oracle by Kuassi Mensah
 
Current state-of-php
Current state-of-phpCurrent state-of-php
Current state-of-php
 
Introduction to php
Introduction to phpIntroduction to php
Introduction to php
 

Recently uploaded

Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
dlhescort
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
amitlee9823
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
daisycvs
 
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
dlhescort
 
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Anamikakaur10
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
dollysharma2066
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Sheetaleventcompany
 

Recently uploaded (20)

SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 MonthsSEO Case Study: How I Increased SEO Traffic & Ranking by 50-60%  in 6 Months
SEO Case Study: How I Increased SEO Traffic & Ranking by 50-60% in 6 Months
 
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service NoidaCall Girls In Noida 959961⊹3876 Independent Escort Service Noida
Call Girls In Noida 959961⊹3876 Independent Escort Service Noida
 
PHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation FinalPHX May 2024 Corporate Presentation Final
PHX May 2024 Corporate Presentation Final
 
Uneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration PresentationUneak White's Personal Brand Exploration Presentation
Uneak White's Personal Brand Exploration Presentation
 
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort ServiceEluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
Eluru Call Girls Service ☎ ️93326-06886 ❤️‍🔥 Enjoy 24/7 Escort Service
 
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
The Path to Product Excellence: Avoiding Common Pitfalls and Enhancing Commun...
 
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
Call Girls Electronic City Just Call 👗 7737669865 👗 Top Class Call Girl Servi...
 
Falcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in indiaFalcon Invoice Discounting platform in india
Falcon Invoice Discounting platform in india
 
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai KuwaitThe Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
The Abortion pills for sale in Qatar@Doha [+27737758557] []Deira Dubai Kuwait
 
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
Call Girls in Delhi, Escort Service Available 24x7 in Delhi 959961-/-3876
 
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
Cheap Rate Call Girls In Noida Sector 62 Metro 959961乂3876
 
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
👉Chandigarh Call Girls 👉9878799926👉Just Call👉Chandigarh Call Girl In Chandiga...
 
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdfDr. Admir Softic_ presentation_Green Club_ENG.pdf
Dr. Admir Softic_ presentation_Green Club_ENG.pdf
 
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
Call Now ☎️🔝 9332606886🔝 Call Girls ❤ Service In Bhilwara Female Escorts Serv...
 
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
FULL ENJOY Call Girls In Mahipalpur Delhi Contact Us 8377877756
 
Value Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and painsValue Proposition canvas- Customer needs and pains
Value Proposition canvas- Customer needs and pains
 
Falcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business GrowthFalcon Invoice Discounting: Empowering Your Business Growth
Falcon Invoice Discounting: Empowering Your Business Growth
 
How to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League CityHow to Get Started in Social Media for Art League City
How to Get Started in Social Media for Art League City
 
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
Call Girls Zirakpur👧 Book Now📱7837612180 📞👉Call Girl Service In Zirakpur No A...
 
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
Chandigarh Escorts Service 📞8868886958📞 Just📲 Call Nihal Chandigarh Call Girl...
 

Propel Your PHP Applications

  • 1. Propel Your PHP Applications Hans Lellelid International PHP Conference 2007-11-06
  • 2. 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
  • 3. 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
  • 4. Pre-Flight Check Going over the basics. Hans Lellelid: Propel Your PHP Applications 4
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. 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
  • 9. 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
  • 10. 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
  • 11. Flight Plan A Typical Propel Work Cycle Hans Lellelid: Propel Your PHP Applications 11
  • 12. 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
  • 13. 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
  • 14. 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
  • 15. 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
  • 16. 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
  • 17. 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
  • 18. 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
  • 19. Cruising Altitude Getting comfortable with Propel. Hans Lellelid: Propel Your PHP Applications 19
  • 20. 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
  • 21. 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
  • 22. 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
  • 23. 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
  • 24. Over-Drive Wait ... I thought we were using airplane metaphors. Hans Lellelid: Propel Your PHP Applications 24
  • 25. 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
  • 26. 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
  • 27. 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
  • 28. 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
  • 29. 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
  • 30. On Behalf of the Flight Crew ... Thanks for listening. :) Hans Lellelid: Propel Your PHP Applications 30