SlideShare ist ein Scribd-Unternehmen logo
1 von 63
Downloaden Sie, um offline zu lesen
Symfony is not scary
Valeriy Tuz
Inuits
Is it scary?..
Is it scary?.. No! Let me try it!!!
- Interior
- Driving
- Engine
- Assembly
- Service
- etc
Symfony is not scary → Why I love Symfony2
Just try it!
$ curl -s http://getcomposer.org/installer | php
$ php composer.phar create-project
symfony/framework-standard-edition
/var/www/symfony/
$ cd /var/www/symfony/
$ php app/check.php (PHP >= 5.3.2, etc)
Get Symfony using Composer
Composer — dependency manager
for PHP
Composer.json{
'autoload': {
'psr-0': {}
}
'name': 'My Project'
'description': 'Very cool one'
'require': {
'php': '>=5.3.3',
'symfony/class-loader': '2.2.*',
}
}
Composer: run your PHP script
Time to look what we've got
Some demo included
Symfony is both:

Full-stack framework

Set of decoupled and standalone components
What are the Symfony components?
Symfony components are:
– Set of independent components
– Each can be used separately
– High quality coded, tested and documented
Symfony components are just bricks but you're
completely responsible to glue them
The list of Symfony2 components
Class loader
Config
Console
CssSelector
Dependency Injection
Form
Event Dispatcher
Http Foundation
Http Kernel
Routing
Security
Yaml
What is bundle
Bundle — set of files which implement single
feature
Generate bundle skeleton
$ php app/console generate:bundle
--namespace=BundleFolder/NameBundle
--format=annotation
What is bundle
Templates go there
Database mappers
Request → Response
Controller: all together
Controller: route
URL and name of route
Controller: template
Look for template in:
./Resources/views/Account/index.html.twig
Controller: get data from DB
Fetch Doctrine
data manager
Get data from repository
Twig
Syntax is very simple:
{{ something }} - «Print something»
{% something %} - «Do something»
Twig
Print var:
{{ var }}
«var» can be even an object. With __toString() method
public function __toString()
{
return $this->name;
}
Twig
Concise:
<?php echo $var ?> → {{ var }}
<?php echo htmlspecialchars($var, ENT_QUOTES, 'UTF-8' ?>
{{ var |e }}
Twig: base template example
Twig: inheritance
Twig: documentation
Need smth Twig doesn't provide?
Just do it!
Symfony and inspiration
How to rescue your PHP project with Symfony2
components
http://habrahabr.ru/post/146521/
http://www.slideshare.net/xavierlacot/symfony2-
components-to-the-rescue-of-your-php-
projects
Create your own framework on top
of Symfony components
Recipe from Fabien Potencier
http://fabien.potencier.org/article/50/create-your-
own-framework-on-top-of-the-symfony2-
components-part-1
Symfony2 components: Console
Some examples of usage
$ php app/console doctrine:generate:entities
Name/MyBundle/Entity/SomeEntity
- generates getters and setters for SomeEntity
$ php app/console container:debug
list of all available services
Symfony2 components: Console
Http Foundation
Request Response
Http Foundation: Request
Http Foundation: Response
Routing component
Services: Dependency Injection
Benefits:
Only one instance of Mailer which can be used
in entire application
Centralized configuration of Mailer
It can be replaced by another service
Services container (DIC)
Step 1: Create class
Step 2: Register it as service by adding to the
service container
Step 3 ... n: Use it
Create class
Register as service
Let's make example more complicated
Step 1: Create one more class
Step 2: Inject service to it
Step 3: Register it as service as well
Create class and inject service
Register new class as service
Use it
Let's improve it. Load services from file
Service.yml become a config file
Http Kernel
Request → Response flow
Events and listeners
Event 1 in HttpKernel->handle(): kernel.request
I.e. Security listener can throw Response object
with 403 Access denied response
Symfony2 is very kind:
For visitors
For developers
Symfony2 is very fast
Response class to manage HTTP cache:
$response = new Response();
$response->setMaxAge(600);
$date = new DateTime();
$date->modify('+600 seconds');
$response->setExpires($date);
Symfony2 dev mode
Symfony2 dev mode
Symfony2 dev mode
Symfony2 follows standards...
Autoloading standard: PSR-0
Basic coding style: PSR-1
Coding style: PSR-2
http://www.php-fig.org/
… which means:
It heavily uses namespaces, OOP, SOA, design
patterns, etc
http://php.net/manual/en/language.namespaces.php
http://en.wikipedia.org/wiki/Software_design_pattern
http://en.wikipedia.org/wiki/Service-
oriented_architecture
I'm almost finished
Yellow: development
Blue: stable
Green: maintenance
Since 3 June 2013 –
long time support
for v. 2.3
Symfony2 bundles
Try Symfony2
But be careful — it can become
addictive from the very first
encounter :)
Questions
valery@inuits.eu
valeriy.tuz@gmail.com
+380 67 505 42 76

Weitere ähnliche Inhalte

Was ist angesagt?

Windows Containers - Microsoft Ignite The Tour
Windows Containers - Microsoft Ignite The TourWindows Containers - Microsoft Ignite The Tour
Windows Containers - Microsoft Ignite The TourEran Stiller
 
Nice performance using Sf2 cache wrapping Sf1 application
Nice performance using Sf2 cache wrapping Sf1 applicationNice performance using Sf2 cache wrapping Sf1 application
Nice performance using Sf2 cache wrapping Sf1 applicationMarc Weistroff
 
Introduction to symfony2
Introduction to symfony2Introduction to symfony2
Introduction to symfony2Pablo Godel
 
Grape Presentation
Grape PresentationGrape Presentation
Grape Presentationchrishein
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Eugene Kurko
 
Symfony 4.0 + - Track Technique eZ Roadshow 2019 - PARIS
Symfony 4.0 + - Track Technique eZ Roadshow 2019 - PARISSymfony 4.0 + - Track Technique eZ Roadshow 2019 - PARIS
Symfony 4.0 + - Track Technique eZ Roadshow 2019 - PARISeZ Systems
 
Python interfaces
Python interfacesPython interfaces
Python interfacespythonchile
 
Hot Code is Faster Code - Addressing JVM Warm-up
Hot Code is Faster Code - Addressing JVM Warm-upHot Code is Faster Code - Addressing JVM Warm-up
Hot Code is Faster Code - Addressing JVM Warm-upMark Price
 
CYB 130 Education Specialist |tutorialrank.com
CYB 130 Education Specialist |tutorialrank.comCYB 130 Education Specialist |tutorialrank.com
CYB 130 Education Specialist |tutorialrank.comladworkspaces
 
Rest api titouan benoit
Rest api   titouan benoitRest api   titouan benoit
Rest api titouan benoitTitouan BENOIT
 
Symfony 4.4 Dependency Injection Improvements
Symfony 4.4 Dependency Injection ImprovementsSymfony 4.4 Dependency Injection Improvements
Symfony 4.4 Dependency Injection ImprovementsIllia Antypenko
 
Droidcon Nigeria 2021 - Still Sleeping on KMM?
Droidcon Nigeria 2021 - Still Sleeping on KMM? Droidcon Nigeria 2021 - Still Sleeping on KMM?
Droidcon Nigeria 2021 - Still Sleeping on KMM? Emmanuel Kehinde
 
Manage appium dependencies with -appium-home in appium 2.0
Manage appium dependencies with  -appium-home in appium 2.0Manage appium dependencies with  -appium-home in appium 2.0
Manage appium dependencies with -appium-home in appium 2.0Kazuaki Matsuo
 
Add new commands in appium 2.0
Add new commands in appium 2.0Add new commands in appium 2.0
Add new commands in appium 2.0Kazuaki Matsuo
 
Symfony Nano Framework
Symfony Nano FrameworkSymfony Nano Framework
Symfony Nano FrameworkLoïc Faugeron
 
From Ruby to Node.js
From Ruby to Node.jsFrom Ruby to Node.js
From Ruby to Node.jsjubilem
 

Was ist angesagt? (20)

Windows Containers - Microsoft Ignite The Tour
Windows Containers - Microsoft Ignite The TourWindows Containers - Microsoft Ignite The Tour
Windows Containers - Microsoft Ignite The Tour
 
Nice performance using Sf2 cache wrapping Sf1 application
Nice performance using Sf2 cache wrapping Sf1 applicationNice performance using Sf2 cache wrapping Sf1 application
Nice performance using Sf2 cache wrapping Sf1 application
 
Introduction to symfony2
Introduction to symfony2Introduction to symfony2
Introduction to symfony2
 
Grape Presentation
Grape PresentationGrape Presentation
Grape Presentation
 
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
Multiplatform shared codebase with Kotlin/Native - UA Mobile 2019
 
Symfony 4.0 + - Track Technique eZ Roadshow 2019 - PARIS
Symfony 4.0 + - Track Technique eZ Roadshow 2019 - PARISSymfony 4.0 + - Track Technique eZ Roadshow 2019 - PARIS
Symfony 4.0 + - Track Technique eZ Roadshow 2019 - PARIS
 
Python interfaces
Python interfacesPython interfaces
Python interfaces
 
Hot Code is Faster Code - Addressing JVM Warm-up
Hot Code is Faster Code - Addressing JVM Warm-upHot Code is Faster Code - Addressing JVM Warm-up
Hot Code is Faster Code - Addressing JVM Warm-up
 
Magento Meetup New Delhi- Console
Magento Meetup New Delhi- ConsoleMagento Meetup New Delhi- Console
Magento Meetup New Delhi- Console
 
Basics of Akka
Basics of AkkaBasics of Akka
Basics of Akka
 
CYB 130 Education Specialist |tutorialrank.com
CYB 130 Education Specialist |tutorialrank.comCYB 130 Education Specialist |tutorialrank.com
CYB 130 Education Specialist |tutorialrank.com
 
Rest api titouan benoit
Rest api   titouan benoitRest api   titouan benoit
Rest api titouan benoit
 
Symfony 4.4 Dependency Injection Improvements
Symfony 4.4 Dependency Injection ImprovementsSymfony 4.4 Dependency Injection Improvements
Symfony 4.4 Dependency Injection Improvements
 
Droidcon Nigeria 2021 - Still Sleeping on KMM?
Droidcon Nigeria 2021 - Still Sleeping on KMM? Droidcon Nigeria 2021 - Still Sleeping on KMM?
Droidcon Nigeria 2021 - Still Sleeping on KMM?
 
Manage appium dependencies with -appium-home in appium 2.0
Manage appium dependencies with  -appium-home in appium 2.0Manage appium dependencies with  -appium-home in appium 2.0
Manage appium dependencies with -appium-home in appium 2.0
 
Add new commands in appium 2.0
Add new commands in appium 2.0Add new commands in appium 2.0
Add new commands in appium 2.0
 
Spring Boot Update
Spring Boot UpdateSpring Boot Update
Spring Boot Update
 
Symfony Nano Framework
Symfony Nano FrameworkSymfony Nano Framework
Symfony Nano Framework
 
Composer
ComposerComposer
Composer
 
From Ruby to Node.js
From Ruby to Node.jsFrom Ruby to Node.js
From Ruby to Node.js
 

Ähnlich wie Why Symfony is not scary and how to start using it

Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"Fwdays
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Componentsguest0de7c2
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Componentsguest0de7c2
 
Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Fabien Potencier
 
Symfony Live 09 Symfony 2
Symfony Live 09 Symfony 2Symfony Live 09 Symfony 2
Symfony Live 09 Symfony 2narkoza
 
Symfony: A Brief Introduction
Symfony: A Brief IntroductionSymfony: A Brief Introduction
Symfony: A Brief IntroductionCraig Willis
 
Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3Fabien Potencier
 
Integrating symfony and Zend Framework (PHPNW09)
Integrating symfony and Zend Framework (PHPNW09)Integrating symfony and Zend Framework (PHPNW09)
Integrating symfony and Zend Framework (PHPNW09)Stefan Koopmanschap
 
Integrating symfony and Zend Framework
Integrating symfony and Zend FrameworkIntegrating symfony and Zend Framework
Integrating symfony and Zend FrameworkStefan Koopmanschap
 
Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19Antonio Peric-Mazar
 
Symfony2 for Midgard Developers
Symfony2 for Midgard DevelopersSymfony2 for Midgard Developers
Symfony2 for Midgard DevelopersHenri Bergius
 
Symfony 4: A new way to develop applications #phpsrb
 Symfony 4: A new way to develop applications #phpsrb Symfony 4: A new way to develop applications #phpsrb
Symfony 4: A new way to develop applications #phpsrbAntonio Peric-Mazar
 
Create Your Own Framework by Fabien Potencier
Create Your Own Framework by Fabien PotencierCreate Your Own Framework by Fabien Potencier
Create Your Own Framework by Fabien PotencierHimel Nag Rana
 
Hands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkHands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkRyan Weaver
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsDeepak Chandani
 
Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with ComposerJason Grimes
 
An introduction to Symfony 2 for symfony 1 developers
An introduction to Symfony 2 for symfony 1 developersAn introduction to Symfony 2 for symfony 1 developers
An introduction to Symfony 2 for symfony 1 developersGiorgio Cefaro
 

Ähnlich wie Why Symfony is not scary and how to start using it (20)

Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"Fabien Potencier "Symfony 4 in action"
Fabien Potencier "Symfony 4 in action"
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Components
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Components
 
Symfony Components
Symfony ComponentsSymfony Components
Symfony Components
 
Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3Symfony 2.0 on PHP 5.3
Symfony 2.0 on PHP 5.3
 
Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009Symfony2 San Francisco Meetup 2009
Symfony2 San Francisco Meetup 2009
 
Symfony Live 09 Symfony 2
Symfony Live 09 Symfony 2Symfony Live 09 Symfony 2
Symfony Live 09 Symfony 2
 
Symfony: A Brief Introduction
Symfony: A Brief IntroductionSymfony: A Brief Introduction
Symfony: A Brief Introduction
 
Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3Symfony Components 2.0 on PHP 5.3
Symfony Components 2.0 on PHP 5.3
 
Running Symfony
Running SymfonyRunning Symfony
Running Symfony
 
Integrating symfony and Zend Framework (PHPNW09)
Integrating symfony and Zend Framework (PHPNW09)Integrating symfony and Zend Framework (PHPNW09)
Integrating symfony and Zend Framework (PHPNW09)
 
Integrating symfony and Zend Framework
Integrating symfony and Zend FrameworkIntegrating symfony and Zend Framework
Integrating symfony and Zend Framework
 
Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19Symfony 4: A new way to develop applications #ipc19
Symfony 4: A new way to develop applications #ipc19
 
Symfony2 for Midgard Developers
Symfony2 for Midgard DevelopersSymfony2 for Midgard Developers
Symfony2 for Midgard Developers
 
Symfony 4: A new way to develop applications #phpsrb
 Symfony 4: A new way to develop applications #phpsrb Symfony 4: A new way to develop applications #phpsrb
Symfony 4: A new way to develop applications #phpsrb
 
Create Your Own Framework by Fabien Potencier
Create Your Own Framework by Fabien PotencierCreate Your Own Framework by Fabien Potencier
Create Your Own Framework by Fabien Potencier
 
Hands-on with the Symfony2 Framework
Hands-on with the Symfony2 FrameworkHands-on with the Symfony2 Framework
Hands-on with the Symfony2 Framework
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 Components
 
Dependency management with Composer
Dependency management with ComposerDependency management with Composer
Dependency management with Composer
 
An introduction to Symfony 2 for symfony 1 developers
An introduction to Symfony 2 for symfony 1 developersAn introduction to Symfony 2 for symfony 1 developers
An introduction to Symfony 2 for symfony 1 developers
 

Why Symfony is not scary and how to start using it