class User
{
public function __construct()
{
$this->storage = new SessionStorage('SESSION_ID');
}
public function setLanguage($language)
{
$this->storage->set('language', $language);
}
}
$user = new User();
INJECTION DE DÉPENDANCE
mercredi 5 septembre 12
Slide 47
Slide 47 text
class User
{
public function __construct()
{
$this->storage = new SessionStorage('SESSION_ID');
}
public function setLanguage($language)
{
$this->storage->set('language', $language);
}
}
$user = new User();
INJECTION DE DÉPENDANCE
Dépendance
forte
mercredi 5 septembre 12
Slide 48
Slide 48 text
class User
{
private $storage;
public function __construct(StorageInterface $storage)
{
$this->storage = $storage;
}
}
$storage = new SessionStorage('SESSION_ID');
$user = new User($storage);
INJECTION DE DÉPENDANCE
Injection
mercredi 5 septembre 12
Slide 49
Slide 49 text
class User
{
private $storage;
public function __construct(StorageInterface $storage)
{
$this->storage = $storage;
}
}
$storage = new SessionStorage('my_session_name');
$user = new User($storage);
INJECTION DE DÉPENDANCE
mercredi 5 septembre 12
Slide 50
Slide 50 text
class User
{
private $storage;
public function __construct(StorageInterface $storage)
{
$this->storage = $storage;
}
}
$storage = new MemcacheStorage();
$user = new User($storage);
INJECTION DE DÉPENDANCE
mercredi 5 septembre 12
Slide 51
Slide 51 text
class User
{
private $storage;
public function __construct(StorageInterface $storage)
{
$this->storage = $storage;
}
}
$storage = new MemcacheStorage($memcacheClient);
$user = new User($storage);
INJECTION DE DÉPENDANCE
mercredi 5 septembre 12
Slide 52
Slide 52 text
http://www.slideshare.net/fabpot/dependency-injection-in-php-5354
Flexible
Configurable
Découplé
INJECTION DE DÉPENDANCE
mercredi 5 septembre 12
Slide 53
Slide 53 text
COMPOSANTS
mercredi 5 septembre 12
Slide 54
Slide 54 text
COMPOSANTS
ClassLoader
Config
Console
DependencyInjection
EventDispatcher
Finder
Form
HttpFoundation
Locale
Process
Routing
Security
Templating
Validation
YAML
...
mercredi 5 septembre 12
Slide 55
Slide 55 text
CLASSLOADER
mercredi 5 septembre 12
Slide 56
Slide 56 text
CLASSLOADER
“Autoloading” respectant le standard PSR-0
https://github.com/php-fig/fig-standards/blob/master/accepted/
PSR-0.md
COMPOSANTS
mercredi 5 septembre 12
CONFIG
Gestion avancée de configuration
COMPOSANTS
mercredi 5 septembre 12
Slide 62
Slide 62 text
CONFIG
Gestion avancée de configuration
Chargement de fichiers de configuration
COMPOSANTS
mercredi 5 septembre 12
Slide 63
Slide 63 text
CONFIG
Gestion avancée de configuration
Chargement de fichiers de configuration
Mise en cache de la configuration
COMPOSANTS
mercredi 5 septembre 12
Slide 64
Slide 64 text
CONFIG
Gestion avancée de configuration
Chargement de fichiers de configuration
Mise en cache de la configuration
Définition du format de configuration
COMPOSANTS
mercredi 5 septembre 12
Slide 65
Slide 65 text
CONFIG
Gestion avancée de configuration
Chargement de fichiers de configuration
Mise en cache de la configuration
Définition du format de configuration
Multi-source (fichiers, base de données)
COMPOSANTS
mercredi 5 septembre 12
Slide 66
Slide 66 text
CONFIG
Gestion avancée de configuration
Chargement de fichiers de configuration
Mise en cache de la configuration
Définition du format de configuration
Multi-source (fichiers, base de données)
Multi-format (YAML, XML, JSON)
COMPOSANTS
mercredi 5 septembre 12
Slide 67
Slide 67 text
CONSOLE
mercredi 5 septembre 12
Slide 68
Slide 68 text
CONSOLE
COMPOSANTS
mercredi 5 septembre 12
Slide 69
Slide 69 text
CONSOLE
COMPOSANTS
mercredi 5 septembre 12
Slide 70
Slide 70 text
CONSOLE
options
COMPOSANTS
mercredi 5 septembre 12
Slide 71
Slide 71 text
CONSOLE
options argument
COMPOSANTS
mercredi 5 septembre 12
Slide 72
Slide 72 text
CONSOLE
options argument
valeur par défaut
COMPOSANTS
mercredi 5 septembre 12
DEPENDENCYINJECTION
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__));
$loader->load('services.yml');
$manager = $container->get('newsletter_manager');
COMPOSANTS
mercredi 5 septembre 12
Slide 79
Slide 79 text
DEPENDENCYINJECTION
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
$container = new ContainerBuilder();
$loader = new YamlFileLoader($container, new FileLocator(__DIR__));
$loader->load('services.yml');
$manager = $container->get('newsletter_manager');
COMPOSANTS
mercredi 5 septembre 12
Slide 80
Slide 80 text
EVENTDISPATCHER
mercredi 5 septembre 12
Slide 81
Slide 81 text
EVENTDISPATCHER
Implémentation du design pattern “Observer”
COMPOSANTS
mercredi 5 septembre 12
Slide 82
Slide 82 text
EVENTDISPATCHER
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;
$dispatcher = new EventDispatcher();
$dispatcher->addListener('foo.action', function (Event $event) {
// will be executed when the foo.action event is dispatched
});
$dispatcher->dispatch('foo.action', new Event());
COMPOSANTS
mercredi 5 septembre 12
Slide 83
Slide 83 text
EVENTDISPATCHER
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;
$dispatcher = new EventDispatcher();
$dispatcher->addListener('foo.action', function (Event $event) {
// will be executed when the foo.action event is dispatched
});
$dispatcher->dispatch('foo.action', new Event());
COMPOSANTS
mercredi 5 septembre 12
Slide 84
Slide 84 text
EVENTDISPATCHER
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;
$dispatcher = new EventDispatcher();
$dispatcher->addListener('foo.action', function (Event $event) {
// will be executed when the foo.action event is dispatched
});
$dispatcher->dispatch('foo.action', new Event());
COMPOSANTS
Listener
mercredi 5 septembre 12
Slide 85
Slide 85 text
EVENTDISPATCHER
use Symfony\Component\EventDispatcher\EventDispatcher;
use Symfony\Component\EventDispatcher\Event;
$dispatcher = new EventDispatcher();
$dispatcher->addListener('foo.action', function (Event $event) {
// will be executed when the foo.action event is dispatched
});
$dispatcher->dispatch('foo.action', new Event());
COMPOSANTS
Événement
mercredi 5 septembre 12
Slide 86
Slide 86 text
FINDER
mercredi 5 septembre 12
Slide 87
Slide 87 text
FINDER
use Symfony\Component\Finder\Finder;
$finder = new Finder();
$finder->files()->in(__DIR__);
foreach ($finder as $file) {
// Print the absolute path
print $file->getRealpath()."\n";
// Print the relative path to the file, omitting the filename
print $file->getRelativePath()."\n";
// Print the relative path to the file
print $file->getRelativePathname()."\n";
}
COMPOSANTS
mercredi 5 septembre 12
Slide 88
Slide 88 text
FINDER
use Symfony\Component\Finder\Finder;
$finder = new Finder();
$finder->files()->in(__DIR__);
foreach ($finder as $file) {
// Print the absolute path
print $file->getRealpath()."\n";
// Print the relative path to the file, omitting the filename
print $file->getRelativePath()."\n";
// Print the relative path to the file
print $file->getRelativePathname()."\n";
}
SplFileInfo
COMPOSANTS
mercredi 5 septembre 12
Slide 89
Slide 89 text
FINDER
use Symfony\Component\Finder\Finder;
$finder = new Finder();
$finder->files()->in(__DIR__);
foreach ($finder as $file) {
// Print the absolute path
print $file->getRealpath()."\n";
// Print the relative path to the file, omitting the filename
print $file->getRelativePath()."\n";
// Print the relative path to the file
print $file->getRelativePathname()."\n";
}
COMPOSANTS
mercredi 5 septembre 12
Slide 90
Slide 90 text
FINDER
use Symfony\Component\Finder\Finder;
$finder = new Finder();
$finder->files()->in(__DIR__);
foreach ($finder as $file) {
// Print the absolute path
print $file->getRealpath()."\n";
// Print the relative path to the file, omitting the filename
print $file->getRelativePath()."\n";
// Print the relative path to the file
print $file->getRelativePathname()."\n";
}
COMPOSANTS
mercredi 5 septembre 12
Slide 91
Slide 91 text
FINDER
use Symfony\Component\Finder\Finder;
$finder = new Finder();
$finder->files()->in(__DIR__);
foreach ($finder as $file) {
// Print the absolute path
print $file->getRealpath()."\n";
// Print the relative path to the file, omitting the filename
print $file->getRelativePath()."\n";
// Print the relative path to the file
print $file->getRelativePathname()."\n";
}
COMPOSANTS
mercredi 5 septembre 12
Slide 92
Slide 92 text
FINDER
Recherche dans plusieurs répertoires
COMPOSANTS
mercredi 5 septembre 12
Slide 93
Slide 93 text
FINDER
Recherche dans plusieurs répertoires
Exclusion de répertoire
COMPOSANTS
mercredi 5 septembre 12
Slide 94
Slide 94 text
FINDER
Recherche dans plusieurs répertoires
Exclusion de répertoire
Recherche sur masques de fichiers
COMPOSANTS
mercredi 5 septembre 12
Slide 95
Slide 95 text
FINDER
Recherche dans plusieurs répertoires
Exclusion de répertoire
Recherche sur masques de fichiers
Recherche par taille
COMPOSANTS
mercredi 5 septembre 12
Slide 96
Slide 96 text
FINDER
Recherche dans plusieurs répertoires
Exclusion de répertoire
Recherche sur masques de fichiers
Recherche par taille
Recherche par date
COMPOSANTS
mercredi 5 septembre 12
Slide 97
Slide 97 text
FINDER
Recherche dans plusieurs répertoires
Exclusion de répertoire
Recherche sur masques de fichiers
Recherche par taille
Recherche par date
Tri standard (nom, type)
COMPOSANTS
mercredi 5 septembre 12
Slide 98
Slide 98 text
FINDER
Recherche dans plusieurs répertoires
Exclusion de répertoire
Recherche sur masques de fichiers
Recherche par taille
Recherche par date
Tri standard (nom, type)
Tri personnalisé (“callback”)
COMPOSANTS
mercredi 5 septembre 12
Slide 99
Slide 99 text
FINDER
Recherche dans plusieurs répertoires
Exclusion de répertoire
Recherche sur masques de fichiers
Recherche par taille
Recherche par date
Tri standard (nom, type)
Tri personnalisé (“callback”)
Compatible avec les “streams” PHP
COMPOSANTS
mercredi 5 septembre 12
Slide 100
Slide 100 text
FINDER
Recherche dans plusieurs répertoires
Exclusion de répertoire
Recherche sur masques de fichiers
Recherche par taille
Recherche par date
Tri standard (nom, type)
Tri personnalisé (“callback”)
Compatible avec les “streams” PHP
...
COMPOSANTS
mercredi 5 septembre 12
Slide 101
Slide 101 text
FORM
mercredi 5 septembre 12
Slide 102
Slide 102 text
FORM
Gestion de formulaires complexes
COMPOSANTS
mercredi 5 septembre 12
Slide 103
Slide 103 text
FORM
Gestion de formulaires complexes
Rendu personnalisable via Twig
COMPOSANTS
mercredi 5 septembre 12
Slide 104
Slide 104 text
FORM
Gestion de formulaires complexes
Rendu personnalisable via Twig
Validation des données
COMPOSANTS
mercredi 5 septembre 12
Slide 105
Slide 105 text
FORM
Gestion de formulaires complexes
Rendu personnalisable via Twig
Validation des données
Encore en beta (prévu pour la 2.1)
COMPOSANTS
mercredi 5 septembre 12
Slide 106
Slide 106 text
COMPOSANTS
ClassLoader
Config
Console
DependencyInjection
EventDispatcher
Finder
Form
HttpFoundation
Locale
Process
Routing
Security
Templating
Validation
YAML
...
mercredi 5 septembre 12
Slide 107
Slide 107 text
“Il y a un composant pour ça”
http://symfony.com/doc/current/components/index.html
COMPOSANTS
mercredi 5 septembre 12
Slide 108
Slide 108 text
BUNDLES
mercredi 5 septembre 12
Slide 109
Slide 109 text
BUNDLES
“Tout est Bundle !”
mercredi 5 septembre 12
Slide 110
Slide 110 text
BUNDLES
mercredi 5 septembre 12
Slide 111
Slide 111 text
BUNDLES
Bundle
mercredi 5 septembre 12
Slide 112
Slide 112 text
BUNDLES
Bundle
mercredi 5 septembre 12
Slide 113
Slide 113 text
BUNDLES
Bundle
mercredi 5 septembre 12
Slide 114
Slide 114 text
BUNDLES
Bundle
mercredi 5 septembre 12
Slide 115
Slide 115 text
Un Bundle peut contenir :
BUNDLES
mercredi 5 septembre 12
Slide 116
Slide 116 text
Un Bundle peut contenir :
Des extensions pour l’injection de dépendance
BUNDLES
mercredi 5 septembre 12
Slide 117
Slide 117 text
Un Bundle peut contenir :
Des extensions pour l’injection de dépendance
Des contrôleurs
BUNDLES
mercredi 5 septembre 12
Slide 118
Slide 118 text
Un Bundle peut contenir :
Des extensions pour l’injection de dépendance
Des contrôleurs
Des gabarits Twig
BUNDLES
mercredi 5 septembre 12
Slide 119
Slide 119 text
Un Bundle peut contenir :
Des extensions pour l’injection de dépendance
Des contrôleurs
Des gabarits Twig
La couche modèle
BUNDLES
mercredi 5 septembre 12
Slide 120
Slide 120 text
Un Bundle peut contenir :
Des extensions pour l’injection de dépendance
Des contrôleurs
Des gabarits Twig
La couche modèle
Tout le nécessaire pour votre application
BUNDLES
mercredi 5 septembre 12
Slide 121
Slide 121 text
Un moyen efficace de structurer du code
BUNDLES
mercredi 5 septembre 12
Slide 122
Slide 122 text
Un moyen efficace de partager du code
BUNDLES
mercredi 5 septembre 12
Slide 123
Slide 123 text
BUNDLES
mercredi 5 septembre 12
Slide 124
Slide 124 text
BUNDLES
1611 Bundles !
mercredi 5 septembre 12
Slide 125
Slide 125 text
AsseticBundle
BUNDLES
mercredi 5 septembre 12
Slide 126
Slide 126 text
AsseticBundle
AvalancheImagineBundle
BUNDLES
mercredi 5 septembre 12
Slide 127
Slide 127 text
AsseticBundle
AvalancheImagineBundle
FOSCommentBundle
BUNDLES
mercredi 5 septembre 12
Slide 128
Slide 128 text
AsseticBundle
AvalancheImagineBundle
FOSCommentBundle
FOSRestBundle
BUNDLES
mercredi 5 septembre 12
Slide 129
Slide 129 text
AsseticBundle
AvalancheImagineBundle
FOSCommentBundle
FOSRestBundle
FOSUserBundle
BUNDLES
mercredi 5 septembre 12
“Il y a un Bundle pour ça !”
http://knpbundles.com/
BUNDLES
mercredi 5 septembre 12
Slide 137
Slide 137 text
CONTRÔLE QUALITÉ
mercredi 5 septembre 12
Slide 138
Slide 138 text
CONTRÔLE QUALITÉ
mercredi 5 septembre 12
Slide 139
Slide 139 text
// src/Acme/DemoBundle/Tests/Utility/CalculatorTest.php
namespace Acme\DemoBundle\Tests\Utility;
use Acme\DemoBundle\Utility\Calculator;
class CalculatorTest extends \PHPUnit_Framework_TestCase
{
public function testAdd()
{
$calc = new Calculator();
$result = $calc->add(30, 12);
// assert that our calculator added the numbers correctly!
$this->assertEquals(42, $result);
}
}
CONTRÔLE QUALITÉ
mercredi 5 septembre 12
Slide 140
Slide 140 text
CONTRÔLE QUALITÉ
Barre verte !
mercredi 5 septembre 12
Slide 141
Slide 141 text
CONTRÔLE QUALITÉ
Seulement une partie des tests
mercredi 5 septembre 12
Slide 142
Slide 142 text
http://phpunit.de/
CONTRÔLE QUALITÉ
mercredi 5 septembre 12
Slide 143
Slide 143 text
Tests fonctionnels
CONTRÔLE QUALITÉ
mercredi 5 septembre 12
Slide 144
Slide 144 text
// src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php
namespace Acme\DemoBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DemoControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();
$crawler = $client->request('GET', '/demo/hello/Fabien');
$count = $crawler
->filter('html:contains("Hello Fabien")')
->count();
$this->assertGreaterThan(0, $count);
}
}
CONTRÔLE QUALITÉ
mercredi 5 septembre 12
Slide 145
Slide 145 text
// src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php
namespace Acme\DemoBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DemoControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();
$crawler = $client->request('GET', '/demo/hello/Fabien');
$count = $crawler
->filter('html:contains("Hello Fabien")')
->count();
$this->assertGreaterThan(0, $count);
}
}
CONTRÔLE QUALITÉ
Navigateur
mercredi 5 septembre 12
Slide 146
Slide 146 text
// src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php
namespace Acme\DemoBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DemoControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();
$crawler = $client->request('GET', '/demo/hello/Fabien');
$count = $crawler
->filter('html:contains("Hello Fabien")')
->count();
$this->assertGreaterThan(0, $count);
}
}
CONTRÔLE QUALITÉ
mercredi 5 septembre 12
Slide 147
Slide 147 text
// src/Acme/DemoBundle/Tests/Controller/DemoControllerTest.php
namespace Acme\DemoBundle\Tests\Controller;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
class DemoControllerTest extends WebTestCase
{
public function testIndex()
{
$client = static::createClient();
$crawler = $client->request('GET', '/demo/hello/Fabien');
$count = $crawler
->filter('html:contains("Hello Fabien")')
->count();
$this->assertGreaterThan(0, $count);
}
}
CONTRÔLE QUALITÉ
Assertion
mercredi 5 septembre 12
Slide 148
Slide 148 text
CONTRÔLE QUALITÉ
mercredi 5 septembre 12
Slide 149
Slide 149 text
“A PHP framework for testing your business expectations.”
CONTRÔLE QUALITÉ
mercredi 5 septembre 12
Slide 150
Slide 150 text
Feature: buy an article
In order to be happy
As a consumer
I want to be able to buy something
Scenario:
Given I am on the homepage
When I search for "fridge"
And I follow "Awesome Fridge"
And I add the article to my cart
And I follow "checkout"
# steps that describe the checkout process
Then I should see "Your order is complete!"
And I should be happy to have a new fridge
CONTRÔLE QUALITÉ
mercredi 5 septembre 12
Slide 151
Slide 151 text
Feature: buy an article
In order to be happy
As a consumer
I want to be able to buy something
Scenario:
Given I am on the homepage
When I search for "fridge"
And I follow "Awesome Fridge"
And I add the article to my cart
And I follow "checkout"
# steps that describe the checkout process
Then I should see "Your order is complete!"
And I should be happy to have a new fridge
CONTRÔLE QUALITÉ
Step
mercredi 5 septembre 12
Slide 152
Slide 152 text
CONTRÔLE QUALITÉ
/**
* @When /^I search for "(?P[^"]*)"$/
*/
public function iSearchFor($term)
{
$this->fillField('Search', $term);
$this->pressButton('Find');
}
mercredi 5 septembre 12
Slide 153
Slide 153 text
CONTRÔLE QUALITÉ
Extensible
mercredi 5 septembre 12
Slide 154
Slide 154 text
CONTRÔLE QUALITÉ
Extensible
Support de Selenium 1/2, ZombieJS, etc
mercredi 5 septembre 12
Slide 155
Slide 155 text
CONTRÔLE QUALITÉ
Extensible
Support de Selenium 1/2, ZombieJS, etc
Extension Symfony 2
mercredi 5 septembre 12
Slide 156
Slide 156 text
http://behat.org/
CONTRÔLE QUALITÉ
mercredi 5 septembre 12
Slide 157
Slide 157 text
RÉSUMÉ
mercredi 5 septembre 12
Slide 158
Slide 158 text
HTTP
mercredi 5 septembre 12
Slide 159
Slide 159 text
HTTP
Design Pattern MVC
mercredi 5 septembre 12
Slide 160
Slide 160 text
HTTP
Design Pattern MVC
Injection de dependance
mercredi 5 septembre 12
Slide 161
Slide 161 text
HTTP
Design Pattern MVC
Injection de dependance
Composants
mercredi 5 septembre 12
Slide 162
Slide 162 text
HTTP
Design Pattern MVC
Injection de dependance
Composants
Bundles
mercredi 5 septembre 12
Slide 163
Slide 163 text
HTTP
Design Pattern MVC
Injection de dependance
Composants
Bundles
Contrôle qualité
mercredi 5 septembre 12
Slide 164
Slide 164 text
Documentation complète
mercredi 5 septembre 12
Slide 165
Slide 165 text
Documentation complète
Sur le “framework”
mercredi 5 septembre 12
Slide 166
Slide 166 text
Documentation complète
Sur le “framework”
Par composant
mercredi 5 septembre 12
Slide 167
Slide 167 text
Documentation complète
Sur le “framework”
Par composant
“Cookbooks”
mercredi 5 septembre 12
Slide 168
Slide 168 text
plus de 100 contributeurs
mercredi 5 septembre 12
Slide 169
Slide 169 text
plus de 1600 bundles
mercredi 5 septembre 12
Slide 170
Slide 170 text
Drupal
mercredi 5 septembre 12
Slide 171
Slide 171 text
Drupal
PHPBB
mercredi 5 septembre 12
Slide 172
Slide 172 text
Drupal
PHPBB
Symfony-CMF / PHPCR
mercredi 5 septembre 12