SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
Let’s play with Symfony2
Noël GUILBERT
Symfony2 introduced a lot a new features,
             let’s discover some of them:

• Dependency Injection Container
• The form framework
• Doctrine2 integration
Dependency Injection Container

• Dependency Injection Container
  –a way to organize dependencies
  –Define services
       services:
        zend.translator:
         class: User
         arguments: [@user.storage]
        user.storage:
          class: SessionStorage
• How to use it in a Symfony2 project ?
• Create your own service
  –Symfony2 offer a simple and effective way to create
   services

  –It’s called an extension

  –An extension can receive some configuration parameter
   from the application config.yml file (i.e. databases
   connections, passwords, etc.)
• Create your own service
  –Define your services:
   # src/Bundle/TwitterBundle/Resources/config/user.yml
   parameters:
     twitter.username: ~
     twitter.password: ~

   services:
    twitter:
     class: Twitter
     arguments: [%twitter.username%, %twitter.password%]
• Create the extension class

     # src/Bundle/TwitterBundle/DependencyInjectionContainer/TwitterExtension.php
• Load your service

    # src/Bundle/TwitterBundle/DependencyInjectionContainer/TwitterExtension.php
• Enable the extension
  –Add these lines in the application config.yml file:

   # hello/config/config.yml
   twitter.twitter:
    username: noelguilbert
    password: mysecretpassword
• That’s all, the service is now available:
The Form Framework



• A brand new piece of code
• A layer on top of the domain models
• Allows you to easily create HTML forms
Your first form
Write a simple Request class
Let’s add some validators
And you are ready to use it!
Doctrine 2 integration

• Fully integrated:
  – DBAL
  – ORM
  – MongoDb mapper
  – Migrations
DBAL: configure your database connection
DBAL command lines

• Create configured database
$ php console doctrine:database:create

• Drop configured database
$ php console doctrine:database:drop

• Query the database
$ php console doctrine:sql:query ‘SELECT * FROM User’
ORM: persisting and retrieving entities
• An Entity is a regular
PHP class that has been
mapped to Doctrine 2
ORM: Defining entities
• Entities can be mapped with:

  • Regular PHP class
  • XML Definition schemas
  • YML Definition schemas
ORM: command lines
• Convert Doctrine1 schemas to Doctrine 2:
   $ php console doctrine:mapping:convert-d1-schema

• Generate entities:
   $ php console doctrine:generate:entities

• Create or update the database schema
   $ php console doctrine:schema:create
   $ php console doctrine:schema:update
• Load fixtures
   $ php console doctrine:schema:update
What’s next ?
Questions?
                         Noël GUILBERT
                    noel.guilbert@sensio.com

                           Sensio S.A.
                  92-98, boulevard Victor Hugo
                      92 115 Clichy Cedex
                            FRANCE
                     Tél. : +33 1 40 99 80 80

www.sensiolabs.com - www.symfony-project.org - www.noelguilbert.com

Mais conteúdo relacionado

Destaque

Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
Nerd Tzanetopoulos
 
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
Fabien Potencier
 

Destaque (10)

Dependency Injection Smells
Dependency Injection SmellsDependency Injection Smells
Dependency Injection Smells
 
Dependency injection with Symfony 2
Dependency injection with Symfony 2Dependency injection with Symfony 2
Dependency injection with Symfony 2
 
In The Future We All Use Symfony2
In The Future We All Use Symfony2In The Future We All Use Symfony2
In The Future We All Use Symfony2
 
The use of Symfony2 @ Overblog
The use of Symfony2 @ OverblogThe use of Symfony2 @ Overblog
The use of Symfony2 @ Overblog
 
Symfony2 Introduction Presentation
Symfony2 Introduction PresentationSymfony2 Introduction Presentation
Symfony2 Introduction Presentation
 
Presentation du framework symfony
Presentation du framework symfonyPresentation du framework symfony
Presentation du framework symfony
 
Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4Dependency injection in PHP 5.3/5.4
Dependency injection in PHP 5.3/5.4
 
Symfony 2 : chapitre 3 - Les modèles en Doctrine 2
Symfony 2 : chapitre 3 - Les modèles en Doctrine 2Symfony 2 : chapitre 3 - Les modèles en Doctrine 2
Symfony 2 : chapitre 3 - Les modèles en Doctrine 2
 
Symfony 2 : chapitre 4 - Les services et les formulaires
Symfony 2 : chapitre 4 - Les services et les formulairesSymfony 2 : chapitre 4 - Les services et les formulaires
Symfony 2 : chapitre 4 - Les services et les formulaires
 
Symfony 2 : chapitre 1 - Présentation Générale
Symfony 2 : chapitre 1 - Présentation GénéraleSymfony 2 : chapitre 1 - Présentation Générale
Symfony 2 : chapitre 1 - Présentation Générale
 

Semelhante a Lets play with Symfony2

Kubernetes @ meetic
Kubernetes @ meeticKubernetes @ meetic
Kubernetes @ meetic
Sébastien Le Gall
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
Jonathan Wage
 
Edp bootstrapping a-software_company
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_company
Ganesh Kulkarni
 

Semelhante a Lets play with Symfony2 (20)

CodeIgniter Lab
CodeIgniter LabCodeIgniter Lab
CodeIgniter Lab
 
Custom Tile Generation in PCF
Custom Tile Generation in PCFCustom Tile Generation in PCF
Custom Tile Generation in PCF
 
Custom Tile Generation in PCF
Custom Tile Generation in PCFCustom Tile Generation in PCF
Custom Tile Generation in PCF
 
Social Connections 13 - Troubleshooting Connections Pink
Social Connections 13 - Troubleshooting Connections PinkSocial Connections 13 - Troubleshooting Connections Pink
Social Connections 13 - Troubleshooting Connections Pink
 
Docker interview Questions-3.pdf
Docker interview Questions-3.pdfDocker interview Questions-3.pdf
Docker interview Questions-3.pdf
 
IBM Think 2018 - IBM Connections Troubleshooting
IBM Think 2018 -  IBM Connections TroubleshootingIBM Think 2018 -  IBM Connections Troubleshooting
IBM Think 2018 - IBM Connections Troubleshooting
 
Fiware cloud developers week brussels
Fiware cloud developers week brusselsFiware cloud developers week brussels
Fiware cloud developers week brussels
 
Kubernetes @ meetic
Kubernetes @ meeticKubernetes @ meetic
Kubernetes @ meetic
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
 
Docking, loading, running domino on docker v12
Docking, loading, running domino on docker v12Docking, loading, running domino on docker v12
Docking, loading, running domino on docker v12
 
Symfony2 for legacy app rejuvenation: the eZ Publish case study
Symfony2 for legacy app rejuvenation: the eZ Publish case studySymfony2 for legacy app rejuvenation: the eZ Publish case study
Symfony2 for legacy app rejuvenation: the eZ Publish case study
 
はじめてのSymfony2
はじめてのSymfony2はじめてのSymfony2
はじめてのSymfony2
 
Edp bootstrapping a-software_company
Edp bootstrapping a-software_companyEdp bootstrapping a-software_company
Edp bootstrapping a-software_company
 
Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)Drupal8 for Symfony Developers (PHP Day Verona 2017)
Drupal8 for Symfony Developers (PHP Day Verona 2017)
 
Php myadmin
Php myadminPhp myadmin
Php myadmin
 
AWS-CICD_MULESOFT
AWS-CICD_MULESOFTAWS-CICD_MULESOFT
AWS-CICD_MULESOFT
 
Caffe2
Caffe2Caffe2
Caffe2
 
VMworld 2015: Automating Everything VMware with PowerCLI- Deep Dive
VMworld 2015: Automating Everything VMware with PowerCLI- Deep DiveVMworld 2015: Automating Everything VMware with PowerCLI- Deep Dive
VMworld 2015: Automating Everything VMware with PowerCLI- Deep Dive
 
Chef arista devops days a'dam 2015
Chef arista devops days a'dam 2015Chef arista devops days a'dam 2015
Chef arista devops days a'dam 2015
 
C++ Windows Forms L01 - Intro
C++ Windows Forms L01 - IntroC++ Windows Forms L01 - Intro
C++ Windows Forms L01 - Intro
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 

Lets play with Symfony2

  • 1. Let’s play with Symfony2 Noël GUILBERT
  • 2. Symfony2 introduced a lot a new features, let’s discover some of them: • Dependency Injection Container • The form framework • Doctrine2 integration
  • 3. Dependency Injection Container • Dependency Injection Container –a way to organize dependencies –Define services services: zend.translator: class: User arguments: [@user.storage] user.storage: class: SessionStorage
  • 4. • How to use it in a Symfony2 project ?
  • 5. • Create your own service –Symfony2 offer a simple and effective way to create services –It’s called an extension –An extension can receive some configuration parameter from the application config.yml file (i.e. databases connections, passwords, etc.)
  • 6. • Create your own service –Define your services: # src/Bundle/TwitterBundle/Resources/config/user.yml parameters: twitter.username: ~ twitter.password: ~ services: twitter: class: Twitter arguments: [%twitter.username%, %twitter.password%]
  • 7. • Create the extension class # src/Bundle/TwitterBundle/DependencyInjectionContainer/TwitterExtension.php
  • 8. • Load your service # src/Bundle/TwitterBundle/DependencyInjectionContainer/TwitterExtension.php
  • 9. • Enable the extension –Add these lines in the application config.yml file: # hello/config/config.yml twitter.twitter: username: noelguilbert password: mysecretpassword
  • 10. • That’s all, the service is now available:
  • 11. The Form Framework • A brand new piece of code • A layer on top of the domain models • Allows you to easily create HTML forms
  • 13. Write a simple Request class
  • 14. Let’s add some validators
  • 15. And you are ready to use it!
  • 16. Doctrine 2 integration • Fully integrated: – DBAL – ORM – MongoDb mapper – Migrations
  • 17. DBAL: configure your database connection
  • 18. DBAL command lines • Create configured database $ php console doctrine:database:create • Drop configured database $ php console doctrine:database:drop • Query the database $ php console doctrine:sql:query ‘SELECT * FROM User’
  • 19. ORM: persisting and retrieving entities • An Entity is a regular PHP class that has been mapped to Doctrine 2
  • 20. ORM: Defining entities • Entities can be mapped with: • Regular PHP class • XML Definition schemas • YML Definition schemas
  • 21. ORM: command lines • Convert Doctrine1 schemas to Doctrine 2: $ php console doctrine:mapping:convert-d1-schema • Generate entities: $ php console doctrine:generate:entities • Create or update the database schema $ php console doctrine:schema:create $ php console doctrine:schema:update • Load fixtures $ php console doctrine:schema:update
  • 23. Questions? Noël GUILBERT noel.guilbert@sensio.com Sensio S.A. 92-98, boulevard Victor Hugo 92 115 Clichy Cedex FRANCE Tél. : +33 1 40 99 80 80 www.sensiolabs.com - www.symfony-project.org - www.noelguilbert.com