SlideShare ist ein Scribd-Unternehmen logo
1 von 59
Symfony 2
Building on Alpha / Beta Technologies

              Daniel Knell
WHY?
PHP5.3
Closures
$count = 0;

$add = function($value) use ($count) {
    $count += $value;
}

$add(5);

echo $count; // outputs 5
Namespaces
$worker = new Artisan_SomeModule_Foo_Bar();

// vs

use ArtisanSomeModuleFooBar;

// ...

$bar = new Bar();
Invoke
class 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
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() { }
}
Shiny
Best Frameworks
 Limited to 5.2
Existing 5.3
Frameworks?
Symfony 2
From Good Stock
BUT!
No stable release
Crunch Time
WHAT?
Bundles
Reusability
symfony2bundles.org
Twig
Django Inspired
Simple
<html>
<body>
{% if name is defined %}
    <p>Hello {{ name }}!</p>
{% else %}
    <p>Hello World!</p>
{% endif %}
</html>
</body>
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 %}
Twig
namespace 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';
    }
}
Doctrine2
Standard Classes
    class Widget
{
    protected $id;

    protected $name;
}
Give Me My
    Constructor Back
class Widget
{
    protected $id;

    protected $name;

    public function __construct($id, $name)
    {
        $this->id = $id;
        $this->name = $name;
    }
}
YAML
ArtisanWidgetBundleEntityWidget:
 type: entity
 table: widget
 id:
     id:
              type: integer
 fields:
     name:
         type: string
         length: 100
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>
Annotations
/**
  * @ORMEntity
  * @ORMTable(name="widget")
  */
class Widget
{
     /**
      * @ORMId
      * @ORMColumn(type="integer")
      */
     protected $id;

    /**
     * @ORMColumn(type="string", length=100)
     */
    protected $name;
}
Controllers
namespace ArtisanHelloBundleController;
use SymfonyComponentHttpFoundationResponse;

class HelloController
{
    public function indexAction($name)
    {
      return new Response('<html><body>Hello '.$name.'!</body></html>');
    }
}
Controllers
namespace ArtisanHelloBundleController;
use SymfonyBundleFrameworkBundleControllerController;

class HelloController extends Controller
{
    public function indexAction($name)
    {
      return $this->render(array(“name” => $name));
    }
}
Render Helper
namespace ArtisanHelloBundleController;
use SymfonyBundleFrameworkBundleControllerController;

class HelloController extends Controller
{
    public function indexAction($name)
    {
        return $this->render('HelloBundle:hello:index.html.twig', array(
            'name' => $name
        ));
    }
}
Framework Extras
namespace ArtisanHelloBundleController;
use SymfonyComponentHttpFoundationResponse;

class HelloController
{
    /**
      * @Route("/{name}")
      * @Template
      */
    public function indexAction($name)
    {
       return array('name' => $name);
    }
}
Template
               Annotation
namespace ArtisanHelloBundleController;
use SymfonyComponentHttpFoundationResponse;

class HelloController
{
    /**
      * @Route("/{name}")
      * @Template
      */
    public function indexAction($name)
    {
       return array('name' => $name);
    }
}
Console Interface
Console Extension
namespace 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 . '!');
    }
}
Validation
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
        ));
    }
}
YAML
ArtisanWidgetBundleEntityWidget:
 properties:
     id:
         - Type: { type: integer }
     name:
         - NotBlank: ~
         - Type: { type: string }
         - MaxLength: 100
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>
Annotations
class Widget
{
    /**
     * @AssertType(type="integer")
     */
    protected $id;

    /**
     * @AssertNotBlank()
     * @AssertType(type="string")
     * @AssertMaxLength(100)
     */
    protected $name;
}
Forms
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
    ));
}
Twig Intergration
   <form action="{{ path('widget_new') }}"
      method="post" {{ form_enctype(form) }}>
    {{ form_widget(form) }}

    <input type="submit" />
</form>
Security
Debugging
Web Profiler
Service Container
parameters:
    widget_manager.class: ArtisanWidgetBundleWidgetWidgetManager

services:
    widget_factory:
        # ...
    widget_manager:
        class:      %widget_manager.class%
        arguments: [@widget_factory]
HOW?
Two Strategies
Snapshot
One Off
Update Often
Every Morning
Difficulty Increases
   Exponentially
    With Time
Wait
Downside
All Things In Time
Thats All Folks
email: contact@danielknell.co.uk
twitter: @danielknell
website: http://danielknell.co.uk/
Any Questions?

Weitere ähnliche Inhalte

Was ist angesagt?

How I started to love design patterns
How I started to love design patternsHow I started to love design patterns
How I started to love design patternsSamuel ROZE
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & RESTHugo Hamon
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteLeonardo Proietti
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleHugo Hamon
 
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICKonstantin Kudryashov
 
Design how your objects talk through mocking
Design how your objects talk through mockingDesign how your objects talk through mocking
Design how your objects talk through mockingKonstantin Kudryashov
 
Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015Konstantin Kudryashov
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 ViewsEyal Vardi
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsSam Hennessy
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveEugene Zharkov
 
購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介Jace Ju
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneRafael Felix da Silva
 
How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF Luc Bors
 
Decoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDDDecoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDDAleix Vergés
 

Was ist angesagt? (20)

How I started to love design patterns
How I started to love design patternsHow I started to love design patterns
How I started to love design patterns
 
Silex meets SOAP & REST
Silex meets SOAP & RESTSilex meets SOAP & REST
Silex meets SOAP & REST
 
Symfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il clienteSymfony2, creare bundle e valore per il cliente
Symfony2, creare bundle e valore per il cliente
 
Design Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et PimpleDesign Patterns avec PHP 5.3, Symfony et Pimple
Design Patterns avec PHP 5.3, Symfony et Pimple
 
Decoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DICDecoupling with Design Patterns and Symfony2 DIC
Decoupling with Design Patterns and Symfony2 DIC
 
Design how your objects talk through mocking
Design how your objects talk through mockingDesign how your objects talk through mocking
Design how your objects talk through mocking
 
Min-Maxing Software Costs
Min-Maxing Software CostsMin-Maxing Software Costs
Min-Maxing Software Costs
 
Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015Min-Maxing Software Costs - Laracon EU 2015
Min-Maxing Software Costs - Laracon EU 2015
 
Angular 2.0 Views
Angular 2.0 ViewsAngular 2.0 Views
Angular 2.0 Views
 
Adding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy ApplicationsAdding Dependency Injection to Legacy Applications
Adding Dependency Injection to Legacy Applications
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010Symfony2 - WebExpo 2010
Symfony2 - WebExpo 2010
 
Cycle.js: Functional and Reactive
Cycle.js: Functional and ReactiveCycle.js: Functional and Reactive
Cycle.js: Functional and Reactive
 
購物車程式架構簡介
購物車程式架構簡介購物車程式架構簡介
購物車程式架構簡介
 
How te bring common UI patterns to ADF
How te bring common UI patterns to ADFHow te bring common UI patterns to ADF
How te bring common UI patterns to ADF
 
Zero to SOLID
Zero to SOLIDZero to SOLID
Zero to SOLID
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com Backbone
 
Mocking Demystified
Mocking DemystifiedMocking Demystified
Mocking Demystified
 
How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF How to Bring Common UI Patterns to ADF
How to Bring Common UI Patterns to ADF
 
Decoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDDDecoupling the Ulabox.com monolith. From CRUD to DDD
Decoupling the Ulabox.com monolith. From CRUD to DDD
 

Ähnlich wie Symfony2 Building on Alpha / Beta technology

How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutesBarang CK
 
50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 MinutesAzim Kurt
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Tsuyoshi Yamamoto
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ EtsyNishan Subedi
 
ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperGary Hockin
 
PhpUnit - The most unknown Parts
PhpUnit - The most unknown PartsPhpUnit - The most unknown Parts
PhpUnit - The most unknown PartsBastian Feder
 
How kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonHow kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonKris Wallsmith
 
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnitinternational PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnitsmueller_sandsmedia
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languagesRafael Winterhalter
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection apiMatthieu Aubry
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownpartsBastian Feder
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksNate Abele
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf Conference
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxMichelangelo van Dam
 

Ähnlich wie Symfony2 Building on Alpha / Beta technology (20)

Migrare da symfony 1 a Symfony2
 Migrare da symfony 1 a Symfony2  Migrare da symfony 1 a Symfony2
Migrare da symfony 1 a Symfony2
 
Unittests für Dummies
Unittests für DummiesUnittests für Dummies
Unittests für Dummies
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutes
 
50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
 
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
Grails 1.2 探検隊 -新たな聖杯をもとめて・・・-
 
Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
ZF2 for the ZF1 Developer
ZF2 for the ZF1 DeveloperZF2 for the ZF1 Developer
ZF2 for the ZF1 Developer
 
PhpUnit - The most unknown Parts
PhpUnit - The most unknown PartsPhpUnit - The most unknown Parts
PhpUnit - The most unknown Parts
 
How kris-writes-symfony-apps-london
How kris-writes-symfony-apps-londonHow kris-writes-symfony-apps-london
How kris-writes-symfony-apps-london
 
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnitinternational PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
international PHP2011_Bastian Feder_The most unknown Parts of PHPUnit
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
Code generation for alternative languages
Code generation for alternative languagesCode generation for alternative languages
Code generation for alternative languages
 
Easy rest service using PHP reflection api
Easy rest service using PHP reflection apiEasy rest service using PHP reflection api
Easy rest service using PHP reflection api
 
Php unit the-mostunknownparts
Php unit the-mostunknownpartsPhp unit the-mostunknownparts
Php unit the-mostunknownparts
 
Lithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate FrameworksLithium: The Framework for People Who Hate Frameworks
Lithium: The Framework for People Who Hate Frameworks
 
Separation of concerns - DPC12
Separation of concerns - DPC12Separation of concerns - DPC12
Separation of concerns - DPC12
 
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
ZFConf 2010: Zend Framework & MVC, Model Implementation (Part 2, Dependency I...
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 

Kürzlich hochgeladen

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Symfony2 Building on Alpha / Beta technology

  • 1. Symfony 2 Building on Alpha / Beta Technologies Daniel Knell
  • 4. Closures $count = 0; $add = function($value) use ($count) { $count += $value; } $add(5); echo $count; // outputs 5
  • 5. Namespaces $worker = new Artisan_SomeModule_Foo_Bar(); // vs use ArtisanSomeModuleFooBar; // ... $bar = new Bar();
  • 6. Invoke class 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. 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() { } }
  • 15. WHAT?
  • 19. Twig
  • 21. Simple <html> <body> {% if name is defined %} <p>Hello {{ name }}!</p> {% else %} <p>Hello World!</p> {% endif %} </html> </body>
  • 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. Twig namespace 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'; } }
  • 25. Standard Classes class Widget { protected $id; protected $name; }
  • 26. Give Me My Constructor Back class Widget { protected $id; protected $name; public function __construct($id, $name) { $this->id = $id; $this->name = $name; } }
  • 27. YAML ArtisanWidgetBundleEntityWidget: type: entity table: widget id: id: type: integer fields: name: type: string length: 100
  • 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. Annotations /** * @ORMEntity * @ORMTable(name="widget") */ class Widget { /** * @ORMId * @ORMColumn(type="integer") */ protected $id; /** * @ORMColumn(type="string", length=100) */ protected $name; }
  • 30. Controllers namespace ArtisanHelloBundleController; use SymfonyComponentHttpFoundationResponse; class HelloController { public function indexAction($name) { return new Response('<html><body>Hello '.$name.'!</body></html>'); } }
  • 31. Controllers namespace ArtisanHelloBundleController; use SymfonyBundleFrameworkBundleControllerController; class HelloController extends Controller { public function indexAction($name) { return $this->render(array(“name” => $name)); } }
  • 32. Render Helper namespace ArtisanHelloBundleController; use SymfonyBundleFrameworkBundleControllerController; class HelloController extends Controller { public function indexAction($name) { return $this->render('HelloBundle:hello:index.html.twig', array( 'name' => $name )); } }
  • 33. Framework Extras namespace ArtisanHelloBundleController; use SymfonyComponentHttpFoundationResponse; class HelloController { /** * @Route("/{name}") * @Template */ public function indexAction($name) { return array('name' => $name); } }
  • 34. Template Annotation namespace ArtisanHelloBundleController; use SymfonyComponentHttpFoundationResponse; class HelloController { /** * @Route("/{name}") * @Template */ public function indexAction($name) { return array('name' => $name); } }
  • 36. Console Extension namespace 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 . '!'); } }
  • 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. YAML ArtisanWidgetBundleEntityWidget: properties: id: - Type: { type: integer } name: - NotBlank: ~ - Type: { type: string } - MaxLength: 100
  • 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. Annotations class Widget { /** * @AssertType(type="integer") */ protected $id; /** * @AssertNotBlank() * @AssertType(type="string") * @AssertMaxLength(100) */ protected $name; }
  • 42. Forms
  • 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. Twig Intergration <form action="{{ path('widget_new') }}" method="post" {{ form_enctype(form) }}> {{ form_widget(form) }} <input type="submit" /> </form>
  • 48. Service Container parameters: widget_manager.class: ArtisanWidgetBundleWidgetWidgetManager services: widget_factory: # ... widget_manager: class: %widget_manager.class% arguments: [@widget_factory]
  • 49. HOW?
  • 55. Difficulty Increases Exponentially With Time
  • 56. Wait
  • 59. Thats All Folks email: contact@danielknell.co.uk twitter: @danielknell website: http://danielknell.co.uk/ Any Questions?

Hinweis der Redaktion

  1. \n
  2. \n
  3. \n
  4. \n
  5. \n
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. \n
  19. \n
  20. \n
  21. \n
  22. \n
  23. \n
  24. \n
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n
  36. \n
  37. \n
  38. \n
  39. \n
  40. \n
  41. \n
  42. \n
  43. \n
  44. \n
  45. \n
  46. \n
  47. \n
  48. \n
  49. \n
  50. \n
  51. \n
  52. \n
  53. \n
  54. \n
  55. \n
  56. \n
  57. \n
  58. \n
  59. \n