About me
» PHPBenelux
» PFZ
» PHPAmersfoort/PHP.FRL
» Ingewikkeld
» phpBB, Zend Framework, Symfony and many more
Slide 3
Slide 3 text
Once upon a time...
Slide 4
Slide 4 text
No content
Slide 5
Slide 5 text
Dependency Injection
Slide 6
Slide 6 text
Dependency Injection
» No hardcoded dependencies
» Easily manage and update specific classes
» Program to contracts, not implementations
» Minimize bootstrap code
» More testable code
Slide 7
Slide 7 text
Dependency Injection
class Foo
{
public function bar()
{
$coffee = new Coffee();
$coffee->init();
return $coffee->drink();
}
}
Slide 8
Slide 8 text
Dependency Injection
$coffee = new Coffee();
Slide 9
Slide 9 text
Dependency Injection
$coffee->init();
Slide 10
Slide 10 text
Dependency Injection
class Coffee implements Roastable {}
class Foo
{
private $coffee;
public function __construct(Roastable $coffee)
{
$this->coffee = $coffee;
}
}
Slide 11
Slide 11 text
Dependency Injection
public function bar()
{
return $this->coffee->drink();
}
Dependency Injection
class DefaultController
{
public function fooAction()
{
$foo = $this->container->get('foo');
$foo->bar();
}
}
Slide 14
Slide 14 text
Dependency Injection
class DefaultController
{
private $foo;
public function __construct(Foo $foo)
{
$this->foo = $foo;
}
public function fooAction()
{
$this->foo->bar();
}
}
Slide 15
Slide 15 text
Service layer
Or: How Symfony
is only
implementation
Slide 16
Slide 16 text
Service layer
» Seperation of concerns
» Business logic should not be bound to the
application
» Service layer can be accessed through the service
container
Slide 17
Slide 17 text
Service layer
public function showAction($productId)
{
$product = $this->getDoctrine()
->getRepository('AppBundle:Product')
->find($productId);
if (!$product) {
throw $this->createNotFoundException(
'No product found for id '.$productId
);
}
// ... do something, like pass the $product object into a template
}
Slide 18
Slide 18 text
No content
Slide 19
Slide 19 text
No content
Slide 20
Slide 20 text
Service Layer
Hexagonal architecture
» http://php-and-symfony.matthiasnoback.nl/tags/
hexagonal%20architecture/
» http://protalk.me/the-framework-as-an-
implementation-detail
Slide 21
Slide 21 text
No content
Slide 22
Slide 22 text
Documentation
Slide 23
Slide 23 text
Documentation
» The best starting point for your search
» Not the ultimate source for information
Slide 24
Slide 24 text
Documentation
» Google
» Stack Overflow
» Blogs
» IRC
Slide 25
Slide 25 text
Documentation
» Something missing? Add it yourself!
» https://github.com/symfony/symfony-docs
Slide 26
Slide 26 text
Documentation
» Symfony Rainbow Series by Joshua Thijssen
» https://leanpub.com/b/symfonyrainbowseries
Slide 27
Slide 27 text
Project
Configuration
Slide 28
Slide 28 text
Project Configuration
Everything in its right place
» config*.yml
» routing*.yml
» security.yml
» parameters.yml
Slide 29
Slide 29 text
No content
Slide 30
Slide 30 text
Project Configuration
XML vs yaml
» http://gowat.ch/xmlyml
» http://converter.rosstuck.com/
Slide 31
Slide 31 text
Choose and
Standardize
Slide 32
Slide 32 text
Choose
» You can do things in multiple ways
» THIS IS GREAT!
» Clarity, readability, maintainability
Slide 33
Slide 33 text
Standardize
» Configuration: yml, xml, annotations
» Controller extends or not?
» Naming of services, parameters, bundles
Slide 34
Slide 34 text
Ready for
action?
Slide 35
Slide 35 text
Ready for action?
» Use bundles correctly
» Maximize external library usage
» Avoid |raw
» .gitignore your parameters.yml
» Translate!
» Log all the things!
» Stay up-to-date
Slide 36
Slide 36 text
Up-to-date
» 2.7 - support until 05/2018, EOL 05/2019
» 2.8 - support until 11/2018, EOL 11/2019
» 3.0 - support until 07/2016, EOL 01/2017
» Next LTS: 3.4: support until 11/2020, EOL 11/2021
Slide 37
Slide 37 text
Questions?
Slide 38
Slide 38 text
I Salute You
Slide 39
Slide 39 text
I Salute You
@skoop
leftontheweb.com
php.ingewikkeld.net