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

Post on 10-May-2015

3.756 views 2 download

Tags:

Transcript of 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

Juozas Kaziukėnas, Lithuanian

You can call me Joe

Talk to me at @juokaz

More info http://juokaz.com

Thursday, November 29, 12

WhiskyWeb.co.uk

Thursday, November 29, 12

A CLASSIC PHP FRAMEWORK

Thursday, November 29, 12

WHAT A FRAMEWORK SHOULD DO?

Thursday, November 29, 12

WHAT A FRAMEWORK SHOULD DO?

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

Thursday, November 29, 12

WHAT IT SHOULD DO, VER 2

Thursday, November 29, 12

NO PHP FRAMEWORK TO DO IT RIGHT

Thursday, November 29, 12

WRONG ATTEMPTS

• Hugely coupled

• Hard to override core behavior

•Overcomplicated

• Low quality

• Slow

•million other reasons

Thursday, November 29, 12

FALSE PROMISES

Thursday, November 29, 12

WHAT IS SYMFONY2?

Thursday, November 29, 12

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

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

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

WHAT SYMFONY2 DOES WELL?

Thursday, November 29, 12

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

STARTING WITH SYMFONY2

Thursday, November 29, 12

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

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

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

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

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('ryan@foobar.net', ...); }}

Thursday, November 29, 12

COMMUNITY

Thursday, November 29, 12

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

QUESTIONS?

Thursday, November 29, 12

THANKS!

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

Thursday, November 29, 12