-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
413 lines (349 loc) · 11.3 KB
/
index.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Liberte-se do framework</title>
<link rel="stylesheet" href="css/reveal.css">
<link rel="stylesheet" href="css/theme/black.css">
<!-- Theme used for syntax highlighting of code -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- Printing and PDF exports -->
<script>
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = window.location.search.match( /print-pdf/gi ) ? 'css/print/pdf.css' : 'css/print/paper.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
</script>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1>Liberte-se</h1>
<h2>do framework</h2>
</section>
<section>
<h2>Daniel Gimenes</h2>
<ul>
<li>Engenheiro de Software @ Maestrooo</li>
<li>Sistemas de Informação @ UNISAL</li>
<li>Open source contributor</li>
<li><span style="color:red">❤</span> blockchains, smart contracts, cryptoeconomics...</li>
</ul>
<p><a href="http://twitter.com/danizord">@Danizord</a></p>
<aside class="notes">
Avisar: Façam perguntas!
</aside>
</section>
<section>
<h2>Frameworks</h2>
<h1 class="fragment">They all suck</h1>
<p class="fragment">Rasmus Lerdorf</p>
<aside class="notes">
Perguntar: Quais frameworks vcs usam?
</aside>
</section>
<section>
<h2>Frameworks</h2>
<ul>
<li class="fragment">Vêm acompanhados de decisões prematuras</li>
<li class="fragment">Adicionam overhead desnecessário</li>
<li class="fragment">Ficam no seu caminho</li>
<li class="fragment">Limitam o ecossistema</li>
<li class="fragment">Aumentam a curva de aprendizado</li>
<li class="fragment">Dificultam a evolução</li>
</ul>
<aside class="notes">
Destrinchar essa parte
</aside>
</section>
<section data-background-image="img/hmm.gif">
<h1>Mhmm, e aí?</h1>
</section>
<section>
<h2>Frameworks fullstack?</h2>
<h5 class="fragment">nope</h5>
<aside class="notes">
A maioria dos frameworks não são realmente "modulares" e "desacoplados"
</aside>
</section>
<section>
<h2>Microframeworks?</h2>
<h5 class="fragment">é... Mas e a interoperabilidade?</h5>
<aside class="notes">
Lumen, Symfony, Zend Expressive... Mas e a interoperabilidade?
</aside>
</section>
<section>
<h2>Componentes padronizados?</h2>
<h5 class="fragment">Yep!</h5>
</section>
<section>
<h5>Falando em padrões...</h5>
<h2 class="fragment">HTTP</h2>
</section>
<section>
<h2>SAPI</h2>
<ul>
<li>$_GET</li>
<li>$_POST</li>
<li>$_SERVER</li>
<li>$_FILES</li>
<li>$_COOKIES</li>
<li>fopen('php://input');</li>
<li>header('HTTP/1.1 404 Not Found');</li>
<li>header('Content-type: text/html');</li>
<li>echo 'Not found';</li>
</ul>
</section>
<section>
<h2>PSR-7</h2>
<ul>
<li>ServerRequestInterface</li>
<li>ResponseInterface</li>
</ul>
</section>
<section>
<h3>Implementações PSR-7</h3>
<ul>
<li>guzzlehttp/psr7</li>
<li>symfony/psr-http-message-bridge</li>
<li>slim/slim</li>
<li>zendframework/zend-diactoros</li>
<li>...</li>
</ul>
</section>
<section>
<h3>SAPI <-> Zend\Diactoros</h3>
<pre><code class="php" data-trim>
use Zend\Diactoros\Response\JsonResponse;
use Zend\Diactoros\Response\SapiEmitter;
use Zend\Diactoros\ServerRequestFactory;
$request = ServerRequestFactory::fromGlobals();
$response = new JsonResponse([
'greeting' => 'Hello ' . $request->getQueryParams()['name']
]);
(new SapiEmitter())->emit($response);
</code></pre>
</section>
<section>
<h3>Business logic</h3>
<pre><code class="php" data-trim>
interface TodoServiceInterface
{
public function addTodo(int $id, string $title): void;
public function markTodoAsDone(int $id);
}
</code></pre>
</section>
<section>
<h3>PSR-15: Server request handler</h3>
<pre><code class="php" data-trim>
namespace Psr\Http\Server;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
interface RequestHandlerInterface
{
public function handle(
ServerRequestInterface $request
): ResponseInterface;
}
</code></pre>
</section>
<section>
<p>AddTodo</p>
<pre><code class="php" data-trim>
final class AddTodo implements RequestHandlerInterface
{
private $todoService;
public function __construct(TodoServiceInterface $service)
{
$this->todoService = $todoService;
}
public function handle(ServerRequestInterface $request)
{
$data = $request->getParsedBody();
$this->todoService->addTodo(
$data['id'],
$data['title']
);
return new JsonResponse(['message' => 'Todo added']);
}
}
</code></pre>
</section>
<section>
<p>MarkTodoAsDone</p>
<pre><code class="php" data-trim>
final class MarkTodoAsDone implements RequestHandlerInterface
{
// ... Dependency Injection ... //
public function handle(ServerRequestInterface $request)
{
$data = $request->getParsedBody();
$this->todoService->markTodoAsDone($data['id']);
return new JsonResponse(['message' => 'Todo done']);
}
}
</code></pre>
</section>
<section>
<h2>Injeção de dependência</h2>
<pre class="fragment"><code class="php" data-trim>
namespace Psr\Container;
interface ContainerInterface
{
public function get(string $id): mixed;
public function has(string $id): bool;
}
</code></pre>
<p class="fragment">$ composer require psr/container</p>
<aside class="notes">
Falar do Symfony 4 DependencyInjection
</aside>
</section>
<section>
<h2>Injeção de dependência</h2>
<ul>
<li>symfony/dependency-injection</li>
<li>bitexpert/disco</li>
<li>zendframework/zend-servicemanager</li>
<li>php-di/php-di</li>
<li>league/container</li>
<li>...</li>
</ul>
</section>
<section>
<h2>Configurando o container</h2>
<ul class="fragment">
<li>Symfony Flex</li>
<li>Zend Component Installer</li>
</ul>
<aside class="notes">
Essa parte ainda não é tão padronizada, mas isso não é problema!
</aside>
</section>
<section>
<h3>Refatorando</h3>
<pre><code class="php" data-trim>
$container = new Container();
$handler = $container->get(AddTodo::class);
$request = ServerRequestFactory::fromGlobals();
$response = $handler->handle($request);
(new SapiEmitter())->emit($response);
</code></pre>
</section>
<section>
<ul>
<li>Tratamento de erros</li>
<li>Roteamento</li>
<li>Autenticação</li>
<li>Controle de acesso</li>
<li>Prevenção contra ataques</li>
<li>Validação de entrada</li>
<li>Tratamento de saída</li>
<li>Controle de sessão</li>
<li>Cache HTTP</li>
<li>Log de acessos</li>
<li>Negociação de conteúdo</li>
<li>...</li>
</ul>
</section>
<section>
<h2>Middlewares</h2>
</section>
<section>
<h3>PSR-15: Middleware</h3>
<pre><code class="php" data-trim>
namespace Psr\Http\Server;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
interface MiddlewareInterface
{
public function process(
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface;
}
</code></pre>
</section>
<section data-background="white">
<img src="img/middleware.png" class="plain">
</section>
<section>
<h4>Implementações middleware pipeline</h4>
<ul>
<li>zendframework/zend-stratigility</li>
<li>slim/slim</li>
<li>mindplay/middleman</li>
<li>middleland/dispatcher</li>
<li>danizord/mid</li>
<li>...</li>
</ul>
</section>
<section>
<h3>Configurando rotas</h3>
<pre><code class="php" data-trim>
// Configure routes
$router = new Router($container);
$router->post('/todos', AddTodo::class);
$router->post('/todos/{id}/done', MarkTodoAsDone::class);
</code></pre>
</section>
<section>
<h3>Configurando pipeline</h3>
<pre><code class="php" data-trim>
// Configure middleware pipeline
$pipeline = new MiddlewarePipeline($container);
$pipeline->pipe(ErrorHandler::class);
$pipeline->pipe(Authentication::class);
$pipeline->pipe($router);
$pipeline->pipe(Authorization::class);
$pipeline->pipe(InputValidation::class);
$pipeline->pipe(RequestHandler::class);
</code></pre>
</section>
<section>
<h3>Refatorando</h3>
<pre><code class="php" data-trim>
$request = ServerRequestFactory::fromGlobals();
$response = $pipeline->handle($request);
(new SapiEmitter())->emit($response);
</code></pre>
</section>
<section>
<h2>Bonus points</h2>
<ul>
<li>Single Page App</li>
<li>Firebase</li>
<li>CQRS</li>
</ul>
</section>
<section>
<h2>Perguntas?!</h2>
</section>
<section>
<h3>Obrigado!</h3>
<p><a href="http://twitter.com/danizord">@Danizord</a></p>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// More info about config & dependencies:
// - https://github.com/hakimel/reveal.js#configuration
// - https://github.com/hakimel/reveal.js#dependencies
Reveal.initialize({
dependencies: [
{ src: 'plugin/markdown/marked.js' },
{ src: 'plugin/markdown/markdown.js' },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'plugin/highlight/highlight.js', async: true, callback: function() { hljs.initHighlightingOnLoad(); } }
]
});
</script>
</body>
</html>