Symfony2 Building on Alpha / Beta technology

1,541 views
1,395 views

Published on

Presentation i gave at londonweb august on building a site on what turned out to be 12 preview, 5 beta, 6 RC and a final release of Symfony 2.

Published in: Technology, Design
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,541
On SlideShare
0
From Embeds
0
Number of Embeds
23
Actions
Shares
0
Downloads
11
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Symfony2 Building on Alpha / Beta technology

    1. 1. Symfony 2Building on Alpha / Beta Technologies Daniel Knell
    2. 2. WHY?
    3. 3. PHP5.3
    4. 4. Closures$count = 0;$add = function($value) use ($count) { $count += $value;}$add(5);echo $count; // outputs 5
    5. 5. Namespaces$worker = new Artisan_SomeModule_Foo_Bar();// vsuse ArtisanSomeModuleFooBar;// ...$bar = new Bar();
    6. 6. Invokeclass Slug { private $regexp; public function __construct($regexp) { $this->regexp = $regexp; } public function __invoke($value) { return strtolower(preg_replace($this->regexp, "-", $value)); }}$filter = new Slug("#^[^A-Z0-9]$#i");echo $filter("Hello World"); // outputs hello-world
    7. 7. Late Static Binding abstract class Singleton{ protected static $instance; protected function __construct() { } final public static function getInstance() { if (null === static::$instance) { static::$instance = new static(); } return static::$instance; } final private function __clone() { }}
    8. 8. Shiny
    9. 9. Best Frameworks Limited to 5.2
    10. 10. Existing 5.3Frameworks?
    11. 11. Symfony 2
    12. 12. From Good Stock
    13. 13. BUT!No stable release
    14. 14. Crunch Time
    15. 15. WHAT?
    16. 16. Bundles
    17. 17. Reusability
    18. 18. symfony2bundles.org
    19. 19. Twig
    20. 20. Django Inspired
    21. 21. Simple<html><body>{% if name is defined %} <p>Hello {{ name }}!</p>{% else %} <p>Hello World!</p>{% endif %}</html></body>
    22. 22. Cool Stuff{% extends "layout.html" %}{% block content %} <ul id="navigation"> {% for item in navigation %} <li><a href="{{ item.href }}">{{ item.caption }}</a></li> {% endfor %} </ul> <h1>My Webpage</h1> {{ a_variable }}{% endblock %}
    23. 23. Twignamespace ArtisanFooBundleTwigExtension;class TextExtension extends Twig_Extension{ public function getFilters() { return array( upper => new Twig_Filter_Method($this, upper), ); } public function upper($value) { return strtoupper($value); } public function getName() { return text; }}
    24. 24. Doctrine2
    25. 25. Standard Classes class Widget{ protected $id; protected $name;}
    26. 26. Give Me My Constructor Backclass Widget{ protected $id; protected $name; public function __construct($id, $name) { $this->id = $id; $this->name = $name; }}
    27. 27. YAMLArtisanWidgetBundleEntityWidget: type: entity table: widget id: id: type: integer fields: name: type: string length: 100
    28. 28. XML<doctrine-mapping xmlns="http://doctrine-project.org/schemas/orm/doctrine-mapping" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://doctrine-project.org/schemas/orm/doctrine-mapping http://doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> <entity name="ArtisanWidgetBundleEntityWidget" table="product"> <id name="id" type="integer" column="id" /> <field name="name" column="name" type="string" length="100" /> </entity></doctrine-mapping>
    29. 29. Annotations/** * @ORMEntity * @ORMTable(name="widget") */class Widget{ /** * @ORMId * @ORMColumn(type="integer") */ protected $id; /** * @ORMColumn(type="string", length=100) */ protected $name;}
    30. 30. Controllersnamespace ArtisanHelloBundleController;use SymfonyComponentHttpFoundationResponse;class HelloController{ public function indexAction($name) { return new Response(<html><body>Hello .$name.!</body></html>); }}
    31. 31. Controllersnamespace ArtisanHelloBundleController;use SymfonyBundleFrameworkBundleControllerController;class HelloController extends Controller{ public function indexAction($name) { return $this->render(array(“name” => $name)); }}
    32. 32. Render Helpernamespace ArtisanHelloBundleController;use SymfonyBundleFrameworkBundleControllerController;class HelloController extends Controller{ public function indexAction($name) { return $this->render(HelloBundle:hello:index.html.twig, array( name => $name )); }}
    33. 33. Framework Extrasnamespace ArtisanHelloBundleController;use SymfonyComponentHttpFoundationResponse;class HelloController{ /** * @Route("/{name}") * @Template */ public function indexAction($name) { return array(name => $name); }}
    34. 34. Template Annotationnamespace ArtisanHelloBundleController;use SymfonyComponentHttpFoundationResponse;class HelloController{ /** * @Route("/{name}") * @Template */ public function indexAction($name) { return array(name => $name); }}
    35. 35. Console Interface
    36. 36. Console Extensionnamespace ArtisanHelloBundleCommand;class HelloCommand extends ContainerAwareCommand{ protected function configure() { $this->addArgument(name, InputArgument::OPTIONAL, Who?) ->setName(demo:greet) ->setDescription(Greet someone); } protected function execute(InputInterface $input, OutputInterface $output) { $name = $input->getArgument(name); if (null === $name) { $name = World; } $output->writeln(Hello . $text . !); }}
    37. 37. Validation
    38. 38. Validation namespace ArtisanWidgetBundleController;use SymfonyBundleFrameworkBundleControllerController;class WidgetController extends Controller{ public function indexAction($name) { $widget = new Widget(); // do something with the widget... $errors = $this->get("validator")->validate($widget); return $this->render(HelloBundle:hello:index.html.twig, array( "errors" => $errors )); }}
    39. 39. YAMLArtisanWidgetBundleEntityWidget: properties: id: - Type: { type: integer } name: - NotBlank: ~ - Type: { type: string } - MaxLength: 100
    40. 40. XML <class name="ArtisanWidgetBundleEntityWidget"> <property name="id"> <constraint name="Type"> <option name="type">integer</option> </constraint> <constraint name="MinLength">3</constraint> </property> <property name="id"> <constraint name="NotBlank" /> <constraint name="Type"> <option name="type">string</option> </constraint> <constraint name="MinLength">100</constraint> </property></class>
    41. 41. Annotationsclass Widget{ /** * @AssertType(type="integer") */ protected $id; /** * @AssertNotBlank() * @AssertType(type="string") * @AssertMaxLength(100) */ protected $name;}
    42. 42. Forms
    43. 43. Forms public function newAction(){ $widget = new Widget(); $form = $this->createFormBuilder($widget) ->add(name, text) ->getForm(); if ($request->getMethod() == POST) { $form->bindRequest($request); if ($form->isValid()) { // do something to save widget... return $this->redirect($this->generateUrl(widget_success)); } } return $this->render(WidgetBundle:widget:new.html.twig, array( "errors" => $errors ));}
    44. 44. Twig Intergration <form action="{{ path(widget_new) }}" method="post" {{ form_enctype(form) }}> {{ form_widget(form) }} <input type="submit" /></form>
    45. 45. Security
    46. 46. Debugging
    47. 47. Web Profiler
    48. 48. Service Containerparameters: widget_manager.class: ArtisanWidgetBundleWidgetWidgetManagerservices: widget_factory: # ... widget_manager: class: %widget_manager.class% arguments: [@widget_factory]
    49. 49. HOW?
    50. 50. Two Strategies
    51. 51. Snapshot
    52. 52. One Off
    53. 53. Update Often
    54. 54. Every Morning
    55. 55. Difficulty Increases Exponentially With Time
    56. 56. Wait
    57. 57. Downside
    58. 58. All Things In Time
    59. 59. Thats All Folksemail: contact@danielknell.co.uktwitter: @danielknellwebsite: http://danielknell.co.uk/Any Questions?

    ×