Symfony2 for Beginners - Contao Ninja .• Dependency Injection ... Symfony2 for Beginners Julius

download Symfony2 for Beginners - Contao Ninja .• Dependency Injection ... Symfony2 for Beginners Julius

of 88

  • date post

    04-Jun-2018
  • Category

    Documents

  • view

    213
  • download

    0

Embed Size (px)

Transcript of Symfony2 for Beginners - Contao Ninja .• Dependency Injection ... Symfony2 for Beginners Julius

  • Symfony2 for Beginners

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Hi, my name is

    Julius Beckmannand i work at

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • and i do:

    PHP, Symfony2 Erlang, Elixir NodeJS DevOps + Continuous Everything!

    (github|twitter).com/h4cc

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Agenda

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Agenda 1/2

    What is Symfony?

    Howto Install Develop Deploy

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Agenda 1/2

    What is Symfony?

    Howto Install Develop Deploy

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Agenda 2/2

    Plain PHP to Symfony Starting Point Dispatching Routing Symfony HTTP Foundation Symfony HTTP Kernel Symfony Routing Symfony Controller

    Extending Symfony Kernel Kernel Events Request/Response Flow (Subrequests)

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Agenda 2/2

    Plain PHP to Symfony Starting Point Dispatching Routing Symfony HTTP Foundation Symfony HTTP Kernel Symfony Routing Symfony Controller

    Extending Symfony Kernel Kernel Events Request/Response Flow (Subrequests)

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • What is Symfony?

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • What is Symfony?

    Abstract: PHP Web Application Framework At least PHP 5.3.3 By Fabien Potencier (fabpot)

    Versions: v1 since 2005 (legacy) v2 since 2011 v3 in November 2015

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • What is Symfony?

    Abstract: PHP Web Application Framework At least PHP 5.3.3 By Fabien Potencier (fabpot)

    Versions: v1 since 2005 (legacy) v2 since 2011 v3 in November 2015

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Patterns: Framework Components Modular design (Bundles) Dependency Injection Event Dispatcher

    Used by: Drupal 8 eZPublish 5 Contao 4 phpBB 3

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Patterns: Framework Components Modular design (Bundles) Dependency Injection Event Dispatcher

    Used by: Drupal 8 eZPublish 5 Contao 4 phpBB 3

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Installing Symfony

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Symfony Installer

    A tool for bootstrapping new Symfony projects.

    .Installing the installer..

    ......

    curl -LsS http://symfony.com/installer -o symfony.phar

    chmod a+x symfony.phar

    .Using the installer..

    ......

    php symfony.phar new blog

    php symfony.phar new blog 2.3

    php symfony.phar new blog 2.5.2

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Symfony Installer

    A tool for bootstrapping new Symfony projects..Installing the installer..

    ......

    curl -LsS http://symfony.com/installer -o symfony.phar

    chmod a+x symfony.phar

    .Using the installer..

    ......

    php symfony.phar new blog

    php symfony.phar new blog 2.3

    php symfony.phar new blog 2.5.2

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Symfony Installer

    A tool for bootstrapping new Symfony projects..Installing the installer..

    ......

    curl -LsS http://symfony.com/installer -o symfony.phar

    chmod a+x symfony.phar

    .Using the installer..

    ......

    php symfony.phar new blog

    php symfony.phar new blog 2.3

    php symfony.phar new blog 2.5.2

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Composer

    Manual way of bootstrapping symfony projects.

    php composer.phar create-project \symfony/framework-standard-edition \blog "2.3.*"

    This will do:

    ..1 git clone https://github.com/symfony/symfony-standard blog

    ..2 cd blog

    ..3 git checkout v2.3.X

    ..4 rm -rf .git

    ..5 composer install

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Composer

    Manual way of bootstrapping symfony projects.

    php composer.phar create-project \symfony/framework-standard-edition \blog "2.3.*"

    This will do:

    ..1 git clone https://github.com/symfony/symfony-standard blog

    ..2 cd blog

    ..3 git checkout v2.3.X

    ..4 rm -rf .git

    ..5 composer install

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Development

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Development

    .Using the PHP >=5.4 internal Webserver..

    ......

    php app/console server:run# orphp -S 127.0.0.1:8080 -t web/

    .Frontend Tools..

    ......

    php app/console assets:install php app/console assetic:dump Grunt, Gulp, Brunch

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Development

    .Using the PHP >=5.4 internal Webserver..

    ......

    php app/console server:run# orphp -S 127.0.0.1:8080 -t web/

    .Frontend Tools..

    ......

    php app/console assets:install php app/console assetic:dump Grunt, Gulp, Brunch

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Deployment

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • DeploymentPoor-Man example:.Initial..

    ......

    git clone git@github.com:your/project.git /var/wwwcd /var/www# ensure correct permissions on app/cache and app/logs

    .Deploy..

    ......

    git pullrm -f web/app_*.phpcomposer installphp app/console cache:clear --env=prod# ... more needed commands like "doctrine"

    Tools: Capifony, Ansible, SaltStack, Puppet, Chef.Automation with: Jenkins.

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

    http://capifony.org/http://jenkins.org/

  • DeploymentPoor-Man example:.Initial..

    ......

    git clone git@github.com:your/project.git /var/wwwcd /var/www# ensure correct permissions on app/cache and app/logs

    .Deploy..

    ......

    git pullrm -f web/app_*.phpcomposer installphp app/console cache:clear --env=prod# ... more needed commands like "doctrine"

    Tools: Capifony, Ansible, SaltStack, Puppet, Chef.Automation with: Jenkins.

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

    http://capifony.org/http://jenkins.org/

  • From plain PHP to Symfony

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Starting point

    GET /post.php?id=1

  • Webserver Rewrites

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Using rewrites

    GET /post/1..htaccess Configuration..

    ......RewriteEngine onRewriteRule ^post/([0-9]+)$ post.php?id=$1

    .Problems..

    ......

    Depends on Webserver Static configuration Outside of Application

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Using rewrites

    GET /post/1..htaccess Configuration..

    ......RewriteEngine onRewriteRule ^post/([0-9]+)$ post.php?id=$1

    .Problems..

    ......

    Depends on Webserver Static configuration Outside of Application

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Dispatcher and Routing

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Using dispatcher..htaccess Configuration..

    ......RewriteEngine OnRewriteRule ^(.*)$ /index.php [QSA]

    .index.php with Routing..

    ......

  • Using dispatcher..htaccess Configuration..

    ......RewriteEngine OnRewriteRule ^(.*)$ /index.php [QSA].index.php with Routing..

    ......

  • Symfony HTTP Foundation

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Symfony HTTP Foundation

    ..1 Using HTTP as a Interface

    ..2 Hiding PHP-ServerAPI $_GET, $_POST, $_SERVER, echo(), header(), die()

    ..3 Providing Request/Response Objects

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Symfony HTTP Foundation

    ..1 Using HTTP as a Interface

    ..2 Hiding PHP-ServerAPI $_GET, $_POST, $_SERVER, echo(), header(), die()

    ..3 Providing Request/Response Objects

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Symfony HTTP Foundation

    ..1 Using HTTP as a Interface

    ..2 Hiding PHP-ServerAPI $_GET, $_POST, $_SERVER, echo(), header(), die()

    ..3 Providing Request/Response Objects

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Symfony Request Class

  • Symfony Response Class

  • Symfony Response Class

  • Benefits

    ..1 Reproducible Testable

    ..2 Common Interface Reuseable

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Benefits

    ..1 Reproducible Testable

    ..2 Common Interface Reuseable

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Symfony HTTP Kernel

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Http Kernel Interface

  • HTTP Kernel

  • Symfony Routing

    Symfony2 for Beginners Julius Beckmann - @h4cc Silpion IT-Solutions

  • Symfony Routing