SlideShare a Scribd company logo
1 of 22
Klaus Großmann
   Dshini UG
Was Propel Ist
                  PDO
                   PDO

                  MySQL
                   MySQL


• ORM für PHP 5
                  PostgreSQL
                   PostgreSQL
                  SQLite
                   SQLite
                  MSSQL
                   MSSQL
                  Oracle
                   Oracle


• 2005 gestartet
• basiert auf Konzepten Apache Torque
 • Aufteilung in Generator und Runtime
 • Schema
• MIT-Lizenz
Generator
<?xml version="1.0" encoding="UTF-8"?>
<database name="bookstore" defaultIdMethod="native">
    <table name="book" phpName="Book">
        <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
        <column name="title" type="varchar" size="255" required="true" />
        <column name="isbn" type="varchar" size="24" required="true" phpName="ISBN"/>
        <column name="publisher_id" type="integer" required="true"/>
        <column name="author_id" type="integer" required="true"/>
        <foreign-key foreignTable="publisher" phpName="Publisher" refPhpName="Book">
             <reference local="publisher_id" foreign="id"/>
        </foreign-key>
        <foreign-key foreignTable="author">
             <reference local="author_id" foreign="id"/>
        </foreign-key>
    </table>
    <table name="author" phpName="Author">
        <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/>
        <column name="first_name" type="varchar" size="128" required="true"/>
        <column name="last_name" type="varchar" size="128" required="true"/>
    </table>
    <table name="publisher" phpName="Publisher">
        <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" />
        <column name="name" type="varchar" size="128" required="true" />
    </table>
</database>
Generator

• Code-Generation aus XML-Schema
 • schnell
 • IDE freundlich
 • leicht zu lernen und verstehen
Killerfeatures

• Inheritance
 • Single Table Inheritance
 • Class Table Inheritance
 • Concrete Table Inheritance
Single Table
                                Inheritance
• semantische Unterscheidung von Objekten
  <table name="book" abstract="true">
      <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true"/>
      <column name="title" type="VARCHAR" size="100"/>
      <column name="class_key" type="INTEGER" inheritance="single">
          <inheritance key="1" class="Book"/>
          <inheritance key="2" class="Essay" extends="Book"/>
          <inheritance key="3" class="Comic" extends="Book"/>
      </column>
  </table>

  <?php

  $book = new Book();
  $book->setTitle('War And Peace');
  $book->save();

  $essay = new Essay();
  $essay->setTitle('On the Duty of Civil Disobedience');
  $essay->save();

  $comic = new Comic();
  $comic->setTitle('Little Nemo In Slumberland');
  $comic->save();
Class Table
                                        Inheritance
<table name="player">
    <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" />
    <column name="first_name" type="VARCHAR" size="100" />
    <column name="last_name" type="VARCHAR" size="100" />
</table>
<table name="footballer">
    <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
    <column name="goals_scored" type="INTEGER" />
    <column name="fouls_committed" type="INTEGER" />
    <column name="player_id" type="INTEGER" />
    <foreign-key foreignTable="player">
        <reference local="player_id" foreign="id" />
    </foreign-key>
    <behavior name="delegate">
        <parameter name="to" value="player" />
    </behavior>
</table>
<table name="basketballer">
    <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
    <column name="points" type="INTEGER" />
    <column name="field_goals" type="INTEGER" />
    <column name="three_points_field_goals" type="INTEGER" />
    <column name="player_id" type="INTEGER" />
    <foreign-key foreignTable="player">
        <reference local="player_id" foreign="id" />
    </foreign-key>
    <behavior name="delegate">
        <parameter name="to" value="player" />
    </behavior>
</table>
Class Table
                                      Inheritance
•   Struktur analog zu Vererbung in Klassen
•   Realisierung via Delegation
•   ermöglicht „Mehrfachvererbung“
    <?php

    $basketballer = new Basketballer();
    $basketballer->setPoints(101);
    $basketballer->setFieldGoals(47);
    $basketballer->setThreePointsFieldGoals(7);
    // set player identity via delegation
    $basketballer->setFirstName('Michael');
    $basketballer->setLastName('Giordano');
    // same as
    $player = new Player();
    $player->setFirstName('Michael');
    $player->setLastName('Giordano');
    $basketballer->setPlayer($player);

    // save basketballer and player
    $basketballer->save();

    // retrieve delegated data directly from the main object
    echo $basketballer->getFirstName(); // Michael
Concrete Table
                                 Inheritance
<table name="content">
    <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" />
    <column name="title" type="VARCHAR" size="100" />
    <column name="category_id" required="false" type="INTEGER" />
    <foreign-key foreignTable="category" onDelete="cascade">
        <reference local="category_id" foreign="id" />
    </foreign-key>
</table>
<table name="category">
    <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" />
    <column name="name" type="VARCHAR" size="100" primaryString="true" />
</table>
<table name="article">
    <behavior name="concrete_inheritance">
        <parameter name="extends" value="content" />
    </behavior>
    <column name="body" type="VARCHAR" size="100" />
</table>
<table name="video">
    <behavior name="concrete_inheritance">
        <parameter name="extends" value="content" />
    </behavior>
    <column name="resource_link" type="VARCHAR" size="100" />
</table>
Concrete Table
                               Inheritance
•   hält gemeinsame Informationen doppelt vor
•   übernimmt Fremdschlüssel, Indexes und Validatoren
•   stellt via Transaktion Integrität zwischen Super- und Subclass sicher
       <?php
       // create a new Category
       $cat = new Category();
       $cat->setName('Movie');
       $cat->save();
       // create a new Article
       $art = new Article();
       $art->setTitle('Avatar Makes Best Opening Weekend in the History');
       $art->setCategory($cat);
       $art->setContent('With $232.2 million worldwide total, Avatar had one of the
       best-opening weekends in the history of cinema.');
       $art->save();
       // create a new Video
       $vid = new Video();
       $vid->setTitle('Avatar Trailer');
       $vid->setCategory($cat);
       $vid->setResourceLink('http://www.avatarmovie.com/index.html')
       $vid->save();
Concrete Table
                      Inheritance
•   OO Arbeiten mit den Modellen
    •   Denormalisierung für optimale Performance
    •   Propel kümmert sich um das Mapping
•   PHP arbeitet…
    •   …mit der Vererbungshirachie
    •   …auf den Objekten, nicht auf Datensätzen
    •   …auf Collections, nicht auf Arrays
    •   …auf Beziehungen, nicht auf Fremdschlüsseln
Runtime

• nutzt generierte Klassen zur…
 • …Repräsentation (BaseObject)
 • …Datenabfrage (ModelCriteria)
• minimaler Gluecode
BaseObject

• Vererbungsbaum der ObjectModels
 • BaseObject > BaseClass > Class
• BaseObject implementiert
  Standardverhalten eines OM
BaseClass

• BaseClass implementiert transparent…
 • …DB-Abstraktion (save, delete, …)
 • …Validation Properties (getter/setter)
 • …Fremdschlüssel-Accessoren
 • …Behaviors
BaseClass
                • Validation Properties (getter/setter)
/**
 * Sets the value of [created_at] column to a normalized version of the date/time value specified.
 *
 * @param mixed $v string, integer (timestamp), or DateTime value.
 *               Empty strings are treated as null.
 * @return Category The current object (for fluent API support)
 */
 public function setCreatedAt($v)
 {
    $dt = PropelDateTime::newInstance($v, null, 'DateTime');
    if ($this->created_at !== null || $dt !== null) {
        $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') :
null;
        $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null;
        if ($currentDateAsString !== $newDateAsString) {
            $this->created_at = $newDateAsString;
            $this->modifiedColumns[] = CategoryPeer::CREATED_AT;
        }
    } // if either are not null


    return $this;
} // setCreatedAt()
Class

• Klasse wird tatsächlich verwendet
• überschreibt standardmäßig leer die Basis
• custom Getter/Setter
• Raum für DB-ferne, zusätzliche Funktionen
Class
$category = new Category();           $con = Propel::getConnection();
$category->setName('Propel');
                                      $con->beginTransaction();
$article = new Article();
$article                              try {
    ->setTitle('Propel is Awesome')       $category = new Category();
    ->setBody('You know why')             $category->setName('Propel');
    ->setCategory($category)
    ->save();                             $article = new Article();
                                          $article
                                              ->setTitle('Propel is Awesome')
                                              ->setBody('You know why')
                                              ->setCategory($category)
                                              ->save($con);

                                          $another_article = new Article();
                                          $another_article
                                              ->setTitle('Doctrine not so much')
                                              ->setBody('You know why')
                                              ->setCategory($category)
                                              ->save($con);

                                          $con->commit();
                                      }
                                      catch (Exception $e) {
                                          $con->rollBack();
                                      }
ModelCriteria
• Vererbungsbaum der Query-Klassen
 • ModelCriteria > BaseClassQuery > ClassQuery
• ModelCriteria implementiert eine abstrakte,
  formale Definition einer SQL-Datenbankabfrage
 • kann überführt werden in konkrete Abfragen
    für MySQL, MSSQL, etc
BaseClassQuery
•   BaseClassQuery implementiert…
    •   …fluent API für ModelCriteria
        •   einfaches Filtern – filterByXXX()
        •   einfaches Abfragen – findByXXX()
        •   paginate, delete, update, …
    •   …Class spezifische Methoden (für joins, etc)
    •   …@method-Definitionen für IDEs für MagicMethods
ClassQuery

• Klasse wird tatsächlich verwendet
• überschreibt standardmäßig leer die Basis
• Ort für eigene filterBy Methoden
ClassQuery

// Kurzform
ArticleQuery::create()->findOneByTitle('%Awesome', ArticleQuery::LIKE);
// Langform
ArticleQuery::create()
    ->filterByTitle('%Awesome', ArticleQuery::LIKE)
    ->findOne();
http://www.slideshare.net/francoisz/symfony2-meets-propel-15-4

More Related Content

What's hot

Your code sucks, let's fix it (CakeFest2012)
Your code sucks, let's fix it (CakeFest2012)Your code sucks, let's fix it (CakeFest2012)
Your code sucks, let's fix it (CakeFest2012)Rafael Dohms
 
HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created itPaul Bearne
 
jQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformancejQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformanceJonas De Smet
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB jhchabran
 
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Balázs Tatár
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress sitereferences
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)Jeff Eaton
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Thinqloud
 
Drupal is Stupid (But I Love It Anyway)
Drupal is Stupid (But I Love It Anyway)Drupal is Stupid (But I Love It Anyway)
Drupal is Stupid (But I Love It Anyway)brockboland
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
 
Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019Balázs Tatár
 

What's hot (20)

Your code sucks, let's fix it (CakeFest2012)
Your code sucks, let's fix it (CakeFest2012)Your code sucks, let's fix it (CakeFest2012)
Your code sucks, let's fix it (CakeFest2012)
 
HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created it
 
jQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and PerformancejQuery: Tips, tricks and hints for better development and Performance
jQuery: Tips, tricks and hints for better development and Performance
 
Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB Introduction à CoffeeScript pour ParisRB
Introduction à CoffeeScript pour ParisRB
 
Daily notes
Daily notesDaily notes
Daily notes
 
php plus mysql
php plus mysqlphp plus mysql
php plus mysql
 
My shell
My shellMy shell
My shell
 
Php
PhpPhp
Php
 
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018Let's write secure Drupal code! - DrupalCamp Oslo, 2018
Let's write secure Drupal code! - DrupalCamp Oslo, 2018
 
Separation of concerns - DPC12
Separation of concerns - DPC12Separation of concerns - DPC12
Separation of concerns - DPC12
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
 
Drupal Development (Part 2)
Drupal Development (Part 2)Drupal Development (Part 2)
Drupal Development (Part 2)
 
Build your own entity with Drupal
Build your own entity with DrupalBuild your own entity with Drupal
Build your own entity with Drupal
 
Your Entity, Your Code
Your Entity, Your CodeYour Entity, Your Code
Your Entity, Your Code
 
Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...Learning jQuery made exciting in an interactive session by one of our team me...
Learning jQuery made exciting in an interactive session by one of our team me...
 
Drupal is Stupid (But I Love It Anyway)
Drupal is Stupid (But I Love It Anyway)Drupal is Stupid (But I Love It Anyway)
Drupal is Stupid (But I Love It Anyway)
 
Quality code by design
Quality code by designQuality code by design
Quality code by design
 
Jquery-overview
Jquery-overviewJquery-overview
Jquery-overview
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019Let's write secure Drupal code! - Drupal Camp Poland 2019
Let's write secure Drupal code! - Drupal Camp Poland 2019
 

Viewers also liked

Divisio diferencies
Divisio diferenciesDivisio diferencies
Divisio diferenciescalaix2ie
 
Cross Cultural Sensitivity
Cross Cultural SensitivityCross Cultural Sensitivity
Cross Cultural SensitivitySrinimf-Slides
 
Présentation2
Présentation2Présentation2
Présentation2nassr1996
 
The importance of Historical Conscience for a creative return to the future (...
The importance of Historical Conscience for a creative return to the future (...The importance of Historical Conscience for a creative return to the future (...
The importance of Historical Conscience for a creative return to the future (...CISRE Venice
 
Didactica enfoques psicopedagogicos
Didactica enfoques psicopedagogicos Didactica enfoques psicopedagogicos
Didactica enfoques psicopedagogicos Liseth Encalada
 
Charles Perkins.
Charles Perkins.Charles Perkins.
Charles Perkins.ccaarrlaa
 
Resume- Nishant Verma (JEE Consultant with 10+ years ) (1)
Resume- Nishant Verma (JEE Consultant with 10+ years ) (1)Resume- Nishant Verma (JEE Consultant with 10+ years ) (1)
Resume- Nishant Verma (JEE Consultant with 10+ years ) (1)Nishant Verma
 
псалом 150 книжка раскраска для детей - Psalm 150 coloring book
псалом 150 книжка раскраска для детей - Psalm 150 coloring bookпсалом 150 книжка раскраска для детей - Psalm 150 coloring book
псалом 150 книжка раскраска для детей - Psalm 150 coloring bookFreekidstories
 
Enfoques, campos formativos y ámbitos
Enfoques, campos formativos y ámbitosEnfoques, campos formativos y ámbitos
Enfoques, campos formativos y ámbitosFernanda Serrano Reyna
 
Psaumes 150 cahier de coloriage - Psalm 150 coloring book
Psaumes 150 cahier de coloriage - Psalm 150 coloring bookPsaumes 150 cahier de coloriage - Psalm 150 coloring book
Psaumes 150 cahier de coloriage - Psalm 150 coloring bookFreekidstories
 
Psalmen 150 malbuch für kinder - Psalm 150 coloring book
Psalmen 150 malbuch für kinder - Psalm 150 coloring bookPsalmen 150 malbuch für kinder - Psalm 150 coloring book
Psalmen 150 malbuch für kinder - Psalm 150 coloring bookFreekidstories
 
компютърна система Ibm
компютърна система Ibmкомпютърна система Ibm
компютърна система Ibmdermendjieva
 
Pakistan NFC Horizontal Distribution
Pakistan NFC Horizontal DistributionPakistan NFC Horizontal Distribution
Pakistan NFC Horizontal DistributionSanawarsi2013
 

Viewers also liked (20)

Divisio diferencies
Divisio diferenciesDivisio diferencies
Divisio diferencies
 
Cross Cultural Sensitivity
Cross Cultural SensitivityCross Cultural Sensitivity
Cross Cultural Sensitivity
 
Kirim email
Kirim emailKirim email
Kirim email
 
Hands
HandsHands
Hands
 
Présentation2
Présentation2Présentation2
Présentation2
 
Editing
EditingEditing
Editing
 
Herramienta outlook
Herramienta outlookHerramienta outlook
Herramienta outlook
 
The importance of Historical Conscience for a creative return to the future (...
The importance of Historical Conscience for a creative return to the future (...The importance of Historical Conscience for a creative return to the future (...
The importance of Historical Conscience for a creative return to the future (...
 
Didactica enfoques psicopedagogicos
Didactica enfoques psicopedagogicos Didactica enfoques psicopedagogicos
Didactica enfoques psicopedagogicos
 
ELOY ALFARO
ELOY ALFAROELOY ALFARO
ELOY ALFARO
 
Charles Perkins.
Charles Perkins.Charles Perkins.
Charles Perkins.
 
Resume- Nishant Verma (JEE Consultant with 10+ years ) (1)
Resume- Nishant Verma (JEE Consultant with 10+ years ) (1)Resume- Nishant Verma (JEE Consultant with 10+ years ) (1)
Resume- Nishant Verma (JEE Consultant with 10+ years ) (1)
 
псалом 150 книжка раскраска для детей - Psalm 150 coloring book
псалом 150 книжка раскраска для детей - Psalm 150 coloring bookпсалом 150 книжка раскраска для детей - Psalm 150 coloring book
псалом 150 книжка раскраска для детей - Psalm 150 coloring book
 
Enfoques, campos formativos y ámbitos
Enfoques, campos formativos y ámbitosEnfoques, campos formativos y ámbitos
Enfoques, campos formativos y ámbitos
 
Psaumes 150 cahier de coloriage - Psalm 150 coloring book
Psaumes 150 cahier de coloriage - Psalm 150 coloring bookPsaumes 150 cahier de coloriage - Psalm 150 coloring book
Psaumes 150 cahier de coloriage - Psalm 150 coloring book
 
Xgboost
XgboostXgboost
Xgboost
 
Psalmen 150 malbuch für kinder - Psalm 150 coloring book
Psalmen 150 malbuch für kinder - Psalm 150 coloring bookPsalmen 150 malbuch für kinder - Psalm 150 coloring book
Psalmen 150 malbuch für kinder - Psalm 150 coloring book
 
компютърна система Ibm
компютърна система Ibmкомпютърна система Ibm
компютърна система Ibm
 
Evaluation
EvaluationEvaluation
Evaluation
 
Pakistan NFC Horizontal Distribution
Pakistan NFC Horizontal DistributionPakistan NFC Horizontal Distribution
Pakistan NFC Horizontal Distribution
 

Similar to Propel sfugmd

Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodJeremy Kendall
 
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011camp_drupal_ua
 
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011Alessandro Nadalin
 
laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutesBarang CK
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesLuis Curo Salvatierra
 
Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片cfc
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11Michelangelo van Dam
 
You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix itRafael Dohms
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxMichelangelo van Dam
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntityBasuke Suzuki
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix itRafael Dohms
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Leonardo Proietti
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix itRafael Dohms
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejsNick Lee
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7chuvainc
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntityBasuke Suzuki
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsJarod Ferguson
 
WordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressWordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressAlena Holligan
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Knowgirish82
 

Similar to Propel sfugmd (20)

Php 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the GoodPhp 102: Out with the Bad, In with the Good
Php 102: Out with the Bad, In with the Good
 
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
Nickolay Shmalenuk.Render api eng.DrupalCamp Kyiv 2011
 
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011 Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
Be lazy, be ESI: HTTP caching and Symfony2 @ PHPDay 2011 05-13-2011
 
laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutes
 
Desarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móvilesDesarrollo de módulos en Drupal e integración con dispositivos móviles
Desarrollo de módulos en Drupal e integración con dispositivos móviles
 
Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片Contagion的Ruby/Rails投影片
Contagion的Ruby/Rails投影片
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
You code sucks, let's fix it
You code sucks, let's fix itYou code sucks, let's fix it
You code sucks, let's fix it
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntity
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
 
Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5Rich domain model with symfony 2.5 and doctrine 2.5
Rich domain model with symfony 2.5 and doctrine 2.5
 
Your code sucks, let's fix it
Your code sucks, let's fix itYour code sucks, let's fix it
Your code sucks, let's fix it
 
Understanding backbonejs
Understanding backbonejsUnderstanding backbonejs
Understanding backbonejs
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
 
Introducing CakeEntity
Introducing CakeEntityIntroducing CakeEntity
Introducing CakeEntity
 
Hooks WCSD12
Hooks WCSD12Hooks WCSD12
Hooks WCSD12
 
Taming that client side mess with Backbone.js
Taming that client side mess with Backbone.jsTaming that client side mess with Backbone.js
Taming that client side mess with Backbone.js
 
WordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPressWordCamp Portland 2018: PHP for WordPress
WordCamp Portland 2018: PHP for WordPress
 
jQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't KnowjQuery - 10 Time-Savers You (Maybe) Don't Know
jQuery - 10 Time-Savers You (Maybe) Don't Know
 

Propel sfugmd

  • 1. Klaus Großmann Dshini UG
  • 2. Was Propel Ist PDO PDO MySQL MySQL • ORM für PHP 5 PostgreSQL PostgreSQL SQLite SQLite MSSQL MSSQL Oracle Oracle • 2005 gestartet • basiert auf Konzepten Apache Torque • Aufteilung in Generator und Runtime • Schema • MIT-Lizenz
  • 3. Generator <?xml version="1.0" encoding="UTF-8"?> <database name="bookstore" defaultIdMethod="native"> <table name="book" phpName="Book"> <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/> <column name="title" type="varchar" size="255" required="true" /> <column name="isbn" type="varchar" size="24" required="true" phpName="ISBN"/> <column name="publisher_id" type="integer" required="true"/> <column name="author_id" type="integer" required="true"/> <foreign-key foreignTable="publisher" phpName="Publisher" refPhpName="Book"> <reference local="publisher_id" foreign="id"/> </foreign-key> <foreign-key foreignTable="author"> <reference local="author_id" foreign="id"/> </foreign-key> </table> <table name="author" phpName="Author"> <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true"/> <column name="first_name" type="varchar" size="128" required="true"/> <column name="last_name" type="varchar" size="128" required="true"/> </table> <table name="publisher" phpName="Publisher"> <column name="id" type="integer" required="true" primaryKey="true" autoIncrement="true" /> <column name="name" type="varchar" size="128" required="true" /> </table> </database>
  • 4. Generator • Code-Generation aus XML-Schema • schnell • IDE freundlich • leicht zu lernen und verstehen
  • 5. Killerfeatures • Inheritance • Single Table Inheritance • Class Table Inheritance • Concrete Table Inheritance
  • 6. Single Table Inheritance • semantische Unterscheidung von Objekten <table name="book" abstract="true"> <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true"/> <column name="title" type="VARCHAR" size="100"/> <column name="class_key" type="INTEGER" inheritance="single"> <inheritance key="1" class="Book"/> <inheritance key="2" class="Essay" extends="Book"/> <inheritance key="3" class="Comic" extends="Book"/> </column> </table> <?php $book = new Book(); $book->setTitle('War And Peace'); $book->save(); $essay = new Essay(); $essay->setTitle('On the Duty of Civil Disobedience'); $essay->save(); $comic = new Comic(); $comic->setTitle('Little Nemo In Slumberland'); $comic->save();
  • 7. Class Table Inheritance <table name="player"> <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" /> <column name="first_name" type="VARCHAR" size="100" /> <column name="last_name" type="VARCHAR" size="100" /> </table> <table name="footballer"> <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" /> <column name="goals_scored" type="INTEGER" /> <column name="fouls_committed" type="INTEGER" /> <column name="player_id" type="INTEGER" /> <foreign-key foreignTable="player"> <reference local="player_id" foreign="id" /> </foreign-key> <behavior name="delegate"> <parameter name="to" value="player" /> </behavior> </table> <table name="basketballer"> <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" /> <column name="points" type="INTEGER" /> <column name="field_goals" type="INTEGER" /> <column name="three_points_field_goals" type="INTEGER" /> <column name="player_id" type="INTEGER" /> <foreign-key foreignTable="player"> <reference local="player_id" foreign="id" /> </foreign-key> <behavior name="delegate"> <parameter name="to" value="player" /> </behavior> </table>
  • 8. Class Table Inheritance • Struktur analog zu Vererbung in Klassen • Realisierung via Delegation • ermöglicht „Mehrfachvererbung“ <?php $basketballer = new Basketballer(); $basketballer->setPoints(101); $basketballer->setFieldGoals(47); $basketballer->setThreePointsFieldGoals(7); // set player identity via delegation $basketballer->setFirstName('Michael'); $basketballer->setLastName('Giordano'); // same as $player = new Player(); $player->setFirstName('Michael'); $player->setLastName('Giordano'); $basketballer->setPlayer($player); // save basketballer and player $basketballer->save(); // retrieve delegated data directly from the main object echo $basketballer->getFirstName(); // Michael
  • 9. Concrete Table Inheritance <table name="content"> <column name="id" type="INTEGER" primaryKey="true" autoIncrement="true" /> <column name="title" type="VARCHAR" size="100" /> <column name="category_id" required="false" type="INTEGER" /> <foreign-key foreignTable="category" onDelete="cascade"> <reference local="category_id" foreign="id" /> </foreign-key> </table> <table name="category"> <column name="id" required="true" primaryKey="true" autoIncrement="true" type="INTEGER" /> <column name="name" type="VARCHAR" size="100" primaryString="true" /> </table> <table name="article"> <behavior name="concrete_inheritance"> <parameter name="extends" value="content" /> </behavior> <column name="body" type="VARCHAR" size="100" /> </table> <table name="video"> <behavior name="concrete_inheritance"> <parameter name="extends" value="content" /> </behavior> <column name="resource_link" type="VARCHAR" size="100" /> </table>
  • 10. Concrete Table Inheritance • hält gemeinsame Informationen doppelt vor • übernimmt Fremdschlüssel, Indexes und Validatoren • stellt via Transaktion Integrität zwischen Super- und Subclass sicher <?php // create a new Category $cat = new Category(); $cat->setName('Movie'); $cat->save(); // create a new Article $art = new Article(); $art->setTitle('Avatar Makes Best Opening Weekend in the History'); $art->setCategory($cat); $art->setContent('With $232.2 million worldwide total, Avatar had one of the best-opening weekends in the history of cinema.'); $art->save(); // create a new Video $vid = new Video(); $vid->setTitle('Avatar Trailer'); $vid->setCategory($cat); $vid->setResourceLink('http://www.avatarmovie.com/index.html') $vid->save();
  • 11. Concrete Table Inheritance • OO Arbeiten mit den Modellen • Denormalisierung für optimale Performance • Propel kümmert sich um das Mapping • PHP arbeitet… • …mit der Vererbungshirachie • …auf den Objekten, nicht auf Datensätzen • …auf Collections, nicht auf Arrays • …auf Beziehungen, nicht auf Fremdschlüsseln
  • 12. Runtime • nutzt generierte Klassen zur… • …Repräsentation (BaseObject) • …Datenabfrage (ModelCriteria) • minimaler Gluecode
  • 13. BaseObject • Vererbungsbaum der ObjectModels • BaseObject > BaseClass > Class • BaseObject implementiert Standardverhalten eines OM
  • 14. BaseClass • BaseClass implementiert transparent… • …DB-Abstraktion (save, delete, …) • …Validation Properties (getter/setter) • …Fremdschlüssel-Accessoren • …Behaviors
  • 15. BaseClass • Validation Properties (getter/setter) /** * Sets the value of [created_at] column to a normalized version of the date/time value specified. * * @param mixed $v string, integer (timestamp), or DateTime value. * Empty strings are treated as null. * @return Category The current object (for fluent API support) */ public function setCreatedAt($v) { $dt = PropelDateTime::newInstance($v, null, 'DateTime'); if ($this->created_at !== null || $dt !== null) { $currentDateAsString = ($this->created_at !== null && $tmpDt = new DateTime($this->created_at)) ? $tmpDt->format('Y-m-d H:i:s') : null; $newDateAsString = $dt ? $dt->format('Y-m-d H:i:s') : null; if ($currentDateAsString !== $newDateAsString) { $this->created_at = $newDateAsString; $this->modifiedColumns[] = CategoryPeer::CREATED_AT; } } // if either are not null return $this; } // setCreatedAt()
  • 16. Class • Klasse wird tatsächlich verwendet • überschreibt standardmäßig leer die Basis • custom Getter/Setter • Raum für DB-ferne, zusätzliche Funktionen
  • 17. Class $category = new Category(); $con = Propel::getConnection(); $category->setName('Propel'); $con->beginTransaction(); $article = new Article(); $article try { ->setTitle('Propel is Awesome') $category = new Category(); ->setBody('You know why') $category->setName('Propel'); ->setCategory($category) ->save(); $article = new Article(); $article ->setTitle('Propel is Awesome') ->setBody('You know why') ->setCategory($category) ->save($con); $another_article = new Article(); $another_article ->setTitle('Doctrine not so much') ->setBody('You know why') ->setCategory($category) ->save($con); $con->commit(); } catch (Exception $e) { $con->rollBack(); }
  • 18. ModelCriteria • Vererbungsbaum der Query-Klassen • ModelCriteria > BaseClassQuery > ClassQuery • ModelCriteria implementiert eine abstrakte, formale Definition einer SQL-Datenbankabfrage • kann überführt werden in konkrete Abfragen für MySQL, MSSQL, etc
  • 19. BaseClassQuery • BaseClassQuery implementiert… • …fluent API für ModelCriteria • einfaches Filtern – filterByXXX() • einfaches Abfragen – findByXXX() • paginate, delete, update, … • …Class spezifische Methoden (für joins, etc) • …@method-Definitionen für IDEs für MagicMethods
  • 20. ClassQuery • Klasse wird tatsächlich verwendet • überschreibt standardmäßig leer die Basis • Ort für eigene filterBy Methoden
  • 21. ClassQuery // Kurzform ArticleQuery::create()->findOneByTitle('%Awesome', ArticleQuery::LIKE); // Langform ArticleQuery::create() ->filterByTitle('%Awesome', ArticleQuery::LIKE) ->findOne();