-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
799 lines (798 loc) · 25.7 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
<html>
<head>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/<?php print $_GET['theme'] ? $_GET['theme'] : 'moon';?>.css">
<link rel="stylesheet" href="css/custom.css">
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1>Symfony in Drupal 8:</h1>
How much and what does Drupal inherit from Symfony?
<br>
<br>
<br>
<h3>Dipak Yadav</h3>( @dipakmdhrm )
</section>
<section>
<h2>Who am I?</h2>
<br>
<div style="text-align: left">
<ul>
<li>Dipak Yadav <strong>( @dipakmdhrm )</strong></li>
<li>From Pune, India</li>
<li>Sr Software Developer (Vidushi Infotech)</li>
<li>Consultant (Rotary International)</li>
<li>
<a href="https://twitter.com/dipakmdhrm">Twitter</a> |
<a href="https://www.drupal.org/u/dipakmdhrm">Drupal.org</a> |
<a href="https://github.com/dipakmdhrm">Github</a>
</li>
<li><a href="http://www.dipakyadav.com" target="_blank">http://www.dipakyadav.com</a></li>
</ul>
</div>
</section>
<section>
<h1>Symfony in Drupal 8:</h1>
How much and what does Drupal inherit from Symfony?
<br>
<br>
<br>
<h3>Dipak Yadav</h3>( @dipakmdhrm )
</section>
<section>
<h2>Who are you?</h2>
<ul>
<li>Drupal 7 developer</li>
<li>Drupal 8 beginner</li>
<li>Symfony Enthusiast</li>
<li>Understand OOP Basics:
<ul>
<li>Classes, Objects, Interfaces, Namespaces etc.</li>
</ul>
</li>
</ul>
</section>
<section>
<h2>Overview</h2>
<br>
<div style="text-align: left">
<ul>
<li>Drupal development before Drupal 8</li>
<li>Introduction to Symfony</li>
<li>Symfony Components in Drupal 8</li>
<li>Personal thoughts</li>
</ul>
</div>
</section>
<section>
<section>
<h2>Drupal development before Drupal 8</h2>
</section>
<section>
<h3>Drupal developer trying Symfony</h3>
<img data-src="images/Frustated.jpg">
</section>
<section>
<h3>Symfony developer trying Drupal</h3>
<img data-src="images/hooks-hooks-everywhere.jpg">
</section>
<section>
<h3>The Drupal way</h3>
<img data-src="images/different.jpg">
</section>
<section>
<h3>Drupal & OOP PHP</h3>
<img data-src="images/php-oop.png">
</section>
<section>
<h3>"Not Invented Here" & "Drupal Island"</h3>
<img data-src="images/nie.jpg">
</section>
<section>
<h3>Drupal 8 and "Proudly Invented Elsewhere"</h3>
<img data-src="images/pfe-projects-in-drupal.png">
</section>
</section>
<section>
<section>
<h2>Symfony</h2>
</section>
<section>
<h3>Symfony</h3>
<img data-src="images/symfony-def.png">
</section>
<section>
<h3>Symfony Components</h3>
<ul>
<li>Component : PHP Library</li>
<li>Independent or Loosely coupled</li>
<li>Reusable: can be used in any PHP application
<ul>
<li>
Even Drupal 7
</li>
</ul>
</li>
<li>Eg.
<ul>
<li>Config, Form, HttpFoundation</li>
</ul>
</li>
<li>Drupal 8 uses many Symfony components</li>
</ul>
</section>
<section>
<h3>Symfony Framework</h3>
<ul>
<li>Web Application Framework built using 35 Symfony components</li>
<ul>
<li>Plus a few other PHP libraries like Twig, Swiftmailer etc</li>
</ul>
<li>Fully functional Application.
<ul>
<li>Meant to be starting point for a web application.</li>
</ul>
</li>
</ul>
</section>
<section>
<h3>Drupal vs Symfony Framework</h3>
<ul>
<li>Drupal:
<ul>
<li>Full-fledged CMS with lots of ready-made, built-in features</li>
</ul>
</li>
<li>Symfony Framework:
<ul>
<li>Meant to be customized and extended from ground-up.</li>
</ul>
</li>
</ul>
</section>
</section>
<section>
<section>
<h2>Symfony Community</h2>
</section>
<section>
<h3>Symfony Community</h3>
<img data-src="images/symfony-community.png">
</section>
<section>
<h3>Symfony Events</h3>
<img data-src="images/symfony-events.png">
</section>
<section>
<h3>Drupal inherits Symfony Community</h3>
<ul>
<li>Dedicated Symfony Track in DrupalCon</li>
<li>Prominent members from Symfony Community
<ul>
<li>Ryan Weaver, KnpUniversity</li>
<li>Nicolas Grekas, Blackfir.io (previously Sensiolabs)</li>
<li>Michelle Sanver, Liip</li>
</ul>
</li>
</ul>
</section>
</section>
<section>
<section>
<h1>Symfony Components in <br>Drupal 8</h1>
</section>
<section>
<h3>Symfony Components in Drupal</h3>
<ul>
<li>HttpFoundation</li>
<li>Routing</li>
<li>EventDispatcher</li>
<li>DependencyInjection</li>
<li>HttpKernel</li>
-------------------
<li>Serializer</li>
<li>Validator</li>
<li>Yaml</li>
<li>Console</li>
</ul>
</section>
</section>
<section>
<section>
<h2>HttpFoundation</h2>
</section>
<section>
<h3>HTTP</h3>
<img data-src="images/http-protocol-flow.jpg">
</section>
<section>
<h3>Front Controller</h3>
<img data-src="images/front-controller.jpg">
</section>
<section>
<h3>Drupal 7 index.php</h3>
<img data-src="images/drupal-7-index-php.png">
</section>
<section>
<h3>Drupal 7 index.php</h3>
<img data-src="images/drupal-7-index-php-request-response.png">
</section>
<section>
<h3>Drupal 8 index.php</h3>
<img data-src="images/drupal-8-index-php.png">
</section>
<section>
<h3>Drupal 8 index.php</h3>
<img data-src="images/drupal-8-index-php-request-response.png">
</section>
<section>
<h3>Drupal 8 Front Controller</h3>
<img data-src="images/drupal-8-front-controller.jpg">
</section>
<section>
<h3>HttpFoundation</h3>
<ul>
<li><code>HttpFoundation\Request</code></li>
<li><code>HttpFoundation\Response</code></li>
</ul>
</section>
<section>
<h3>HttpFoundation\Request</h3>
<ul>
<li><code>$request = Request::createFromGlobals();</code></li>
<li>Gathers request data from PHP globals
<ul>
<li><code>$request->query ($_GET)</code></li>
<li><code>$request->request ($_POST)</code></li>
<li><code>$request->server ($_SERVER)</code></li>
</ul>
</li>
</ul>
</section>
<section>
<h3>HttpFoundation\Response</h3>
<ul>
<li><code>$response = new Response();</code>
<ul>
<li>$content</li>
<li>$status_code</li>
<li>$response_headers</li>
</ul>
</li>
<li><code>$response->send();</code></li>
</ul>
</section>
<section>
<h3>API support</h3>
<ul>
<li>Drupal 7: No support for creating RESTful APIs</li>
<ul>
<li>Almost always GET requests.</li>
<li>Poor support for handling other methods like:
<ul>
<li>POST, PUT, DELETE etc.</li>
</ul>
</li>
</ul>
<li>Drupal 8: API first</li>
</ul>
</section>
</section>
<section>
<section>
<h2>Routing</h2>
</section>
<section>
<h3>Routing</h3>
<em>"Routing is a process to match a request path to a function, or a controller that then processes that request"</em>
<br>
<br>
<ul><li>Route:
<ul><li>"The map from the path to the controller"</li></ul>
</li></ul>
</section>
<section>
<h3>Route in Drupal 7</h3>
<img data-src="images/hook-menu.png">
</section>
<section>
<h3>Routing in Drupal 7</h3>
<img data-src="images/drupal-7-index-php-routing.png">
</section>
<section>
<h3>Routing in Drupal 7</h3>
<img data-src="images/drupal-7-route-finder.png">
</section>
<section>
<h3>Route in Drupal 8</h3>
<img data-src="images/routing-yml.png">
</section>
<section>
<h3>Routing in Drupal 8</h3>
<img data-src="images/drupal-8-index-php-routing.png">
</section>
<section>
<h3>Basics of Routing</h3>
<img data-src="images/routing-overview.jpg">
</section>
<section>
<h3>Basics of Routing Component</h3>
<img data-src="images/routing-component-basics.jpg">
</section>
</section>
<section>
<section>
<h2>EventDispatcher</h2>
</section>
<section>
<h3>Communication between sub-systems</h3>
<img data-src="images/sub-system-communication.jpg">
</section>
<section>
<h3>Drupal 7 hooks</h3>
<code>hook_node_delete()</code>
<img data-src="images/hook-communication.jpg">
</section>
<section>
<h3>Drupal 7 hooks behind the scenes</h3>
<img data-src="images/hooks-behind-the-scenes.png">
</section>
<section>
<h3>EventDispatcher in Drupal 8</h3>
<ul>
<li>Facilitates communication between objects</li>
<li>Events:
<ul>
<li><em>"An Event is any action that an object needs to communicate to other objects"</em></li>
<li>Eg. Node deletion</li>
</ul>
</li>
</ul>
<br>
</section>
<section>
<h3>EventDispatcher: adding listeners</h3>
<img data-src="images/bruh-listeners.jpg">
</section>
<section>
<h3>EventDispatcher: adding listeners: code</h3>
<img data-src="images/event-dispatcher-add-listener-code.png">
</section>
<section>
<h3>EventDispatcher: event</h3>
<img data-src="images/bruh-event.jpg">
</section>
<section>
<h3>EventDispatcher: dispatching event</h3>
<img data-src="images/bruh-dispatching.jpg">
</section>
<section>
<h3>EventDispatcher: dispatching event: code</h3>
<img data-src="images/event-dispatcher-dispatch-event-code.png">
</section>
<section>
<h3>Event Dispatcher Overview</h3>
<img data-src="images/events-dispatcher-overview.jpg">
</section>
<section>
<h3>Events Examples</h3>
<ul>
<li>Migrate
<ul>
<li><code>migrate.pre_import</code></li>
<li><code>migrate.post_import</code></li>
</ul>
</li>
<li>Config
<ul>
<li><code>config.save</code></li>
<li><code>config.delete</code></li>
</ul>
</li>
<li>Entity
<ul>
<li><code>entity_type.definition.create</code></li>
<li><code>entity_type.definition.delete</code></li>
</ul>
</li>
</ul>
</section>
<section>
<h3>Drupal 8: Events and Hooks</h3>
<ul>
<li>Hooks</li>
<li>Events</li>
<li>Best of both world... but is it??</li>
</ul>
</section>
</section>
<section>
<section>
<h2>DependencyInjection</h2>
</section>
<section>
<ul>
<li>Services</li>
<li>Service container</li>
<li>Dependency Injection</li>
</ul>
</section>
<section>
<h3>Services</h3>
<ul>
<li>Useful Objects</li>
<img data-src="images/services-yml.png">
</ul>
</section>
<section>
<h3>Drupal services examples</h3>
<ul>
<li><code>FormBuilder</code>
<ul>
<li><code>getForm()</code></li>
<li><code>buildForm()</code></li>
</ul>
</li>
<li><code>UserAuth</code>
<ul>
<li><code>authenticate()</code></li>
</ul>
</li>
<li><code>DBLog</code>
<ul>
<li><code>log()</code></li>
</ul>
</li>
<li><code>current_user</code></li>
</ul>
</section>
<section>
<h3>Service Container</h3>
<ul>
<li>Provides a way to fetch services
<ul>
<li><code>$container->get('service.name')</code></li>
</ul>
</li>
<li>Gathers info about services from all <code>services.yml</code> files</li>
<li>Uses this info to create services</li>
</ul>
</section>
<section>
<h3>Dependency Injection</h3>
<ul>
<li>Everything (almost) is object</li>
<li>Objects use objects</li>
<li>Objects are dependent on objects</li>
</ul>
</section>
<section>
<h3>Objects should not create dependencies</h3>
<img data-src="images/object-creating-dependency.png">
</section>
<section>
<h3>Dependencies should be passed</h3>
<img data-src="images/object-injecting-dependency.png">
</section>
<section>
<h3>Why Dependency Injection?</h3>
<ul>
<li>Facilitates encapsulation</li>
<li>Helps Unit Testing</li>
</ul>
</section>
<section>
<h3>Service container does DI</h3>
<ul>
<li>Takes care of:
<ul>
<li>Creating services</li>
<li>Injecting them as dependencies in objects</li>
</ul>
</li>
<li>Also called as Dependency Injection Container</li>
</ul>
</section>
<section>
<h3>Drupal 8: Two Containers</h3>
<ul>
<li>Dependency Injection container: preferred & recommended</li>
<li>Legacy container: for non-OO parts</li>
</ul>
</section>
<section>
<h3>Using Drupal 8 legacy container</h3>
<ul>
<li><code>\Drupal::service('service.name')</code></li>
<li>Hooks and other procedural code</li>
<li>Should be avoided if possible</li>
</ul>
</section>
</section>
<section>
<section>
<h2>HTTPKernel</h2>
</section>
<section>
<h3>DrupalKernel</h3>
<ul>
<li>Core of Drupal</li>
<li>Puts everything together</li>
<li>Extended from <code>HTTPKernelInterface</code></li>
</ul>
</section>
<section>
<h3>Drupal 8 index.php</h3>
<img data-src="images/drupal-8-index-php-kernel.png">
</section>
<section>
<h3>DrupalKernel creates service container</h3>
<img data-src="images/kernel-initialize-container.png">
</section>
<section>
<h3>DrupalKernel adds services to container</h3>
<img data-src="images/kernel-add-service.png">
</section>
<section>
<h3>DrupalKernel passes control to request handler</h3>
<img data-src="images/kernel-handle-request.png">
</section>
</section>
<section>
<section>
<h2>Serializer</h2>
</section>
<section>
<h3>Serialization</h3>
<ul>
<li>Process of translating data structures to a format that can be easily stored and transmitted.
<ul>
<li>And vice versa</li>
</ul>
</li>
<li>
In Drupal, mostly used for serialization of objects and arrays.
</li>
</ul>
</section>
<section>
<h3>Serialization component in Drupal 8</h3>
<ul>
<li>Heavily used in Drupal 8 APIs</li>
<li>Drupal web services modules
<ul>
<li>Serialization, RESTful Web Services</li>
</ul>
</li>
<li>Serializer component for encoding objects to JSON/XML
<ul>
<li>And vice versa</li>
</ul>
</li>
</ul>
</section>
</section>
<section>
<section>
<h2>Validator</h2>
</section>
<section>
<h3>Validator component</h3>
<ul>
<li>Used to validate values based on rules</li>
<li>Generally used for form validation</li>
<li>Allows to create:
<ul>
<li>Constraints: Rules
<ul>
<li>Eg. length, email, link</li>
</ul>
</li>
<li>
Validators: Objects
<ul>
<li>Can act on basis of values following/violating constraints.</li>
</ul>
</li>
</ul>
</li>
</ul>
</section>
<section>
<h3>Validator in Drupal 8</h3>
<li>Used to create constraints for form fields of various types
</section>
</section>
<section>
<section>
<h2>Yaml</h2>
</section>
<section>
<h3>YAML</h3>
<ul>
<li>YAML: YAML Ain't Markup Language</li>
<li>Human readable serialization language</li>
<li>Commonly used to store configuration</li>
</ul>
</section>
<section>
<h3>Yaml Component</h3>
<ul>
<li>Allows parsing and dumping YAML files</li>
</ul>
</section>
<section>
<h3>Yaml in Drupal 8</h3>
<ul>
<li>{module}/{theme}.info.yml</li>
<li>routing.yml</li>
<li>services.yml</li>
<li>Configuration (eg. views are now configuration)</li>
</ul>
</section>
</section>
<section>
<section>
<h2>Console</h2>
</section>
<section>
<h3>Drupal Console</h3>
<ul>
<li>Console optimized for Drupal</li>
<li>Used for debugging & generating skeleton code</li>
<li>Installed using composer</li>
</ul>
</section>
<section>
<h3>Drupal Console commands</h3>
<ul>
<li><code>generate:module</code></li>
<li><code>generate:controller</code></li>
<li><code>generate:form</code></li>
<li><code>debug:container</code></li>
<li><code>debug:permission</code></li>
<li><code>debug:update</code></li>
</ul>
</section>
</section>
<section>
<h1>Personal Thoughts</h1>
<h2>Symfony's Philosophies in Drupal that I love</h2>
</section>
<section>
<section>
<h2>Easier Upgrades</h2>
</section>
<section>
<h3>Drupal upgrades in past</h3>
<ul>
<li>Challenging upgrade between major versions
<ul>
<li>Steep learning curve</li>
<li>Difficult upgrade path</li>
</ul>
</li>
<li>Complete rebuild of application</li>
</ul>
</section>
<section>
<h3>Drupal 8 upgrades</h3>
<ul>
<li>Two kind of upgrades
<ul>
<li>Minor</li>
<li>Major</li>
</ul>
</li>
</ul>
</section>
<section>
<h3>Drupal 8 minor upgrades</h3>
<ul>
<li>8.1 -> 8.2, 8.2 -> 8.3</li>
<li>Every 6 months</li>
<li>New Features</li>
<li>Backward Compatible changes</li>
<li>Deprecate old stuff</li>
</ul>
</section>
<section>
<h3>Drupal 8 major upgrades</h3>
<ul>
<li>No new features</li>
<li>Backward compatibility break
<ul>
<li>Remove deprecated stuff</li>
</ul>
</li>
</ul>
</section>
<section>
<h3>Upgrade policy advantages</h3>
<ul>
<li>Periodic addition of new features
<ul><li>Instead of years of wait</li></ul>
</li>
<li>Enough time to shed deprecates stuff for major release
<ul><li>No surprises by major release</li></ul>
</li>
</ul>
</section>
</section>
<section>
<section>
<h2>Standard Compliance</h2>
</section>
<section>
<ul>
<li>PHP-FIG
<ul>
<li>PHP - Framework Interoperability Group</li>
</ul>
</li>
<li>
PSRs
<ul>
<li>PHP Standards Recommendations</li>
</ul>
</li>
</ul>
</section>
<section>
<h3>Adoption of PSRs</h3>
<ul>
<li>PSR 4</li>
<li>PSR 3</li>
</ul>
</section>
</section>
<section>
<h1>Personal Thoughts</h1>
<h2>Symfony's Philosophies that I want in Drupal</h2>
</section>
<section>
<h3>Symfony's philosophy of loosely coupled independent parts</h3>
<ul>
<li>Drupal sub-systems as loosely coupled libraries
<ul><li>Available for use in other PHP projects</li></ul>
</li>
</ul>
</section>
<section>
<h3>More standard compliance</h3>
<ul>
<li>Eg. PSR-1 & PSR-2</li>
</ul>
</section>
<section>
<h2>Takeaways</h2>
<ul>
<li>Drupal uses Symfony components, not Symfony framework</li>
<li>HttpFoundation, Routing help Drupal 8 become API-first</li>
<li>HttpFoundation, Routing, EventDispatcher, DependencyInjection & DrupalKernal form the core of Drupal 8</li>
</ul>
</section>
<section>
<h1>Thank You!</h1>
<h3>Questions || Discussions?</h3>
</section>
<section>
<h1>Rate the session</h1>
<h3><a href="https://events.drupal.org/vienna2017/sessions/symfony-drupal-8-how-much-and-what-does-drupal-inherits-symfony">Link to session</a></h3>
</section>
</div>
</div>
<script src="js/reveal.js"></script>
<script>
Reveal.initialize({
width: "80%",
height: "100%",
margin: 0,
minScale: 1,
maxScale: 1
});
</script>
</body>
</html>