46
Introduction to Symfony components and helper components in Drupal 8 Ankit Babbar Drupal Developer at Valuebound Volunteer at SPIC MACAY twitter: ankitbabbar

Introduction to Symfony Components and helper components in Drupal 8

Embed Size (px)

Citation preview

Introduction to Symfony components and helper components in Drupal 8

Ankit Babbar Drupal Developer at ValueboundVolunteer at SPIC MACAYtwitter: ankitbabbar

History of PHP

Functional vs OOPs ProgrammingFrameworks

3rd Party LibrariesNamespace

PHP-FIGYAML

Composer

Awesome Drupal CMS + Symfony2 Framework

+ Best PHP Practices from Community

https://cipix.nl/understanding-drupal-8-part-1-general-structure-framework

HTTP Foundation

Request -> Response

HTTP request looks like:

GET /foo.html HTTP/1.1Host: example.comAccept: text/htmlUser-Agent: Mozialla/5.0 (Macintosh)

GET Retrieve the resource from the server

POSTCreate a resource on the server

PUT Update the resource on the server

DELETE Delete the resource from the server

Request

HTTP response looks like:HTTP/1.1 200 OKDate: Sat, 25 Jul 2015 10:30:00 ISTServer: apache2/2.xxContent-Type: text/html

<html>

Response

Routing

YAML: YAML Ain’t Markup LanguageSample Router

hello_world.content: path: ‘/hello-world' defaults: _controller: '\Drupal\hello\Controller\HelloController::content' _title: 'Hello World' requirements: _permission: 'access content'

Controllers

Sample Hello World Controllerclass HelloController extends ControllerBase { public function content() { return array( '#type' => 'markup', '#markup' => t('Hello, World!'), ); }}

Application Flow

Event Dispatcher

HTTP Kernel

Dependency Injection

class Notifier { private $mailer; public function __construct() { $this->mailer = new Mailer(); } public function notify() { … $this->mailer->send($from, $to, $msg); … }}

class Notifier { private $mailer; public function __construct(MailInterface $m) { $this->mailer = $m; } public function notify() { …. $this->mailer->send($from, $to, $msg); … }}

$mailer = new SpecialMailer();$notifier = new Notifier($mailer);

Composer

Sample composer.json for hello_world module{ "name": “drupal/hello_world", "require": { "mailchimp/mailchimp": "2.0.6" }}

Namespace +

Autoloading

Full Controller File Look like:<?php/** * @file * Contains \Drupal\hello\Controller\HelloController. */

namespace Drupal\hello\Controller;

use Drupal\Core\Controller\ControllerBase;class HelloController extends ControllerBase { public function content() { return array( '#type' => 'markup', '#markup' => t('Hello, World!'), ); }}?>

Serializer

Array

Serialization

FormatObject

DeSerialization

Validator

1. Symfony Documentation2. DrupalCon Denver 2012: DRUPAL 8 MEETS SYMFONY2

https://www.youtube.com/watch?v=Gr71z_WoejM3. UNDERSTANDING DRUPAL 8: https://cipix.nl/understanding-drupal-8-part-1-

general-structure-framework4. DrupalCon Portland 2013: DEPENDENCY INJECTION IN DRUPAL 8

https://www.youtube.com/watch?v=kocJ6pn9kEc5. DrupalCon Denver 2012: DRUPAL 8 MEETS SYMFONY2

https://www.youtube.com/watch?v=Gr71z_WoejM6. Symfony en Drupal 8

http://symfony.com/doc/current/components/event_dispatcher/introduction.html#introduction

7. Unravelling the Drupal 8 Plugin System https://drupalize.me/blog/201409/unravelling-drupal-8-plugin-system

8. Drupal 8 Plugin System https://www.youtube.com/watch?v=2o5uY-iOoMo9. PSR-4 http://www.php-fig.org/psr/psr-4/10. Namespaces http://php.net/manual/en/language.namespaces.php

References and Resources

Thank You!

Questions?