The only php framework you'll need: Symfony2 - FOWA Prague

26
THE ONLY PHP FRAMEWORK YOU'LL NEED: SYMFONY2 Juozas Kaziukėnas // juokaz.com // @juokaz Thursday, November 29, 12

Transcript of The only php framework you'll need: Symfony2 - FOWA Prague

Page 1: The only php framework you'll need: Symfony2 - FOWA Prague

THE ONLY PHP FRAMEWORK YOU'LL NEED:

SYMFONY2Juozas Kaziukėnas // juokaz.com // @juokaz

Thursday, November 29, 12

Page 2: The only php framework you'll need: Symfony2 - FOWA Prague

Juozas Kaziukėnas, Lithuanian

You can call me Joe

Talk to me at @juokaz

More info http://juokaz.com

Thursday, November 29, 12

Page 3: The only php framework you'll need: Symfony2 - FOWA Prague

WhiskyWeb.co.uk

Thursday, November 29, 12

Page 4: The only php framework you'll need: Symfony2 - FOWA Prague

A CLASSIC PHP FRAMEWORK

Thursday, November 29, 12

Page 5: The only php framework you'll need: Symfony2 - FOWA Prague

WHAT A FRAMEWORK SHOULD DO?

Thursday, November 29, 12

Page 6: The only php framework you'll need: Symfony2 - FOWA Prague

WHAT A FRAMEWORK SHOULD DO?

•Out of the box functionality• Routing• Security• Best practices• Standardization•Decoupling• etc.

Thursday, November 29, 12

Page 7: The only php framework you'll need: Symfony2 - FOWA Prague

WHAT IT SHOULD DO, VER 2

Thursday, November 29, 12

Page 8: The only php framework you'll need: Symfony2 - FOWA Prague

NO PHP FRAMEWORK TO DO IT RIGHT

Thursday, November 29, 12

Page 9: The only php framework you'll need: Symfony2 - FOWA Prague

WRONG ATTEMPTS

• Hugely coupled

• Hard to override core behavior

•Overcomplicated

• Low quality

• Slow

•million other reasons

Thursday, November 29, 12

Page 10: The only php framework you'll need: Symfony2 - FOWA Prague

FALSE PROMISES

Thursday, November 29, 12

Page 11: The only php framework you'll need: Symfony2 - FOWA Prague

WHAT IS SYMFONY2?

Thursday, November 29, 12

Page 12: The only php framework you'll need: Symfony2 - FOWA Prague

WHAT IS SYMFONY2?

• A successor of symfony 1.X• Rewritten from scratch• Turns requests to responses, that’s it• Heavily utilizes PHP 5.3+ features• Component oriented architecture• Supported by Sensio Labs agency, run by Fabien Potencier

Thursday, November 29, 12

Page 13: The only php framework you'll need: Symfony2 - FOWA Prague

COMPONENTS

• Building blocks for the framework

• Like: HTTP kernel, Form, Validation, Security, Event dispatcher, Config, Console, etc.

• Independent self-contained components

• Can be used without using Symfony2 as a web framework

Thursday, November 29, 12

Page 14: The only php framework you'll need: Symfony2 - FOWA Prague

SILEX

require_once __DIR__.'/../vendor/autoload.php';

$app = new Silex\Application();

$app->get('/hello/{name}', function($name) use($app) { return 'Hello '.$app->escape($name); });

$app->run();

Thursday, November 29, 12

Page 15: The only php framework you'll need: Symfony2 - FOWA Prague

WHAT SYMFONY2 DOES WELL?

Thursday, November 29, 12

Page 16: The only php framework you'll need: Symfony2 - FOWA Prague

WHAT SYMFONY2 DOES WELL?

• Components• Inspired Composer to be created• Silex vs Symfony2 vs your own• Fully working standard distribution• Service container for dependencies

Thursday, November 29, 12

Page 17: The only php framework you'll need: Symfony2 - FOWA Prague

STARTING WITH SYMFONY2

Thursday, November 29, 12

Page 18: The only php framework you'll need: Symfony2 - FOWA Prague

STARTING WITH SYMFONY2

composer.phar create-project symfony/framework-standard-edition path/to/install 2.1.x-dev

php ./app/console server:run

Browse http://localhost:8000/app_dev.php

Thursday, November 29, 12

Page 19: The only php framework you'll need: Symfony2 - FOWA Prague

COMPOSER

• 3rd party dependency management

•Makes life so much easier

• Allows not to have 3rd party checked in into a master repo

• Project-specific dependencies vs PEAR-like system-wide

•One file composer.json to manage all expectations

• Became a de facto standard in PHP projects

Thursday, November 29, 12

Page 20: The only php framework you'll need: Symfony2 - FOWA Prague

BUNDLES

• “Modules” to separate application code

• Contains controllers, models, templates, etc.

• Symfony framework itself is a bundle called FrameworkBundle

• Repository of available bundles http://knpbundles.com/

• Can be extended to customize

Thursday, November 29, 12

Page 21: The only php framework you'll need: Symfony2 - FOWA Prague

BUNDLES

// src/Acme/DemoBundle/Controller/WelcomeController.php

namespace Acme\DemoBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class WelcomeController extends Controller{ public function indexAction() { return $this->render('AcmeDemoBundle:Welcome:index.html.twig'); }}

Thursday, November 29, 12

Page 22: The only php framework you'll need: Symfony2 - FOWA Prague

SERVICE CONTAINER

// app/config/config.ymlservices: my_mailer: class: Acme\HelloBundle\Mailer arguments: [sendmail]

class WelcomeController extends Controller{ public function sendEmailAction() { $mailer = $this->get('my_mailer'); $mailer->send('[email protected]', ...); }}

Thursday, November 29, 12

Page 23: The only php framework you'll need: Symfony2 - FOWA Prague

COMMUNITY

Thursday, November 29, 12

Page 24: The only php framework you'll need: Symfony2 - FOWA Prague

COMMUNITY

• Symfony2 on Twitter• Conferences, user groups• All of this?• Good market to be a developer• Less bugs, active GitHub•Drupal

Thursday, November 29, 12

Page 25: The only php framework you'll need: Symfony2 - FOWA Prague

QUESTIONS?

Thursday, November 29, 12

Page 26: The only php framework you'll need: Symfony2 - FOWA Prague

THANKS!

Juozas Kaziukėnashttp://juokaz.com/@juokaz

Thursday, November 29, 12