-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
executable file
·535 lines (437 loc) · 19 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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Composer - Dependency Management for PHP</title>
<meta name="author" content="John Kelly">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/default.css" id="theme">
<!-- Code syntax highlighting -->
<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>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<!-- Any section element inside of this container is displayed as a slide -->
<div class="slides">
<section>
<h1><img src="images/composer.png" /></h1>
<h3>Dependency Management for PHP</h3>
<p>
<small>Presented by <a href="mailto:john.m.kelly@cdk.com">John Kelly</a></small>
</p>
</section>
<section class="present">
<h2>John Kelly</h2>
<ul>
<li>Software Engineering Lead at CDK Global</li>
<li>Zend Certified Engineer - PHP 5.3</li>
<li>Software engineering for 12 years</li>
</ul>
<p><img src="images/cdk_logo.png" width="161" style="padding: 15px;background-color: white;" /></p>
</section>
<section>
<h2>What is Composer?</h2>
<ul>
<li>Dependency manager for PHP</li>
<li>Manages per-project dependencies</li>
<li>Comes with built in autoloading and basic task-runner</li>
</ul>
</section>
<section>
<section>
<h2>What's wrong with PEAR?</h2>
<ul>
<li>Manages system-wide dependencies</li>
<li>Application doesn't manage dependencies</li>
<li>No autoloading provided</li>
</ul>
</section>
</section>
<section>
<h2>Installing Composer</h2>
<h3>http://getcomposer.org</h3>
<dl>
<dt>OSX/Linux/Unix</dt>
<dd>Download composer.phar and move to /usr/local/bin/composer</dd>
<dt>Windows</dt>
<dd>Download Installed</dd>
</dl>
</section>
<section>
<h2>Using Composer - Basics</h2>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
# composer.json
{
"require": {
"silex/silex": "~1.1"
}
}
</code></pre>
<pre class="fragment"><code>$ composer install</code></pre>
</section>
<section>
<h2>Using the package</h2>
<p>Include the autoloader</p>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px">
require __DIR__ . '/vendor/autoload.php';
</code></pre>
</section>
<section>
<h2><img src="images/packagist.png" style="background-color: #ffffff;" /></h2>
</section>
<section>
<section>
<h2>Semantic Versioning</h2>
<p><a href="http://semver.org/">http://semver.org/</a></p>
<p><img src="images/versioning.gif" /></p>
</section>
<section>
<h3>Definitions</h3>
<dl>
<div class="fragment">
<dt>MAJOR</dt>
<dd>When you make incompatible API changes</dd>
</div>
<div class="fragment">
<dt>MINOR</dt>
<dd>When you add functionality in a backwards-compatible manner</dd>
</div>
<div class="fragment">
<dt>PATCH</dt>
<dd>When you make backwards compatible bug fixes</dd>
</div>
</dl>
</section>
</section>
<section>
<section>
<h2>Version Syntax</h2>
<div class="fragment">
<h3>Exact version</h3>
<p><strong>1.0.2</strong></p>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
# composer.json
{
"require": {
"silex/silex": "1.0.2"
}
}
</code></pre>
<aside class="notes">
This will tell Composer to install this version and this version only. If other dependencies require a different version, the solver will ultimately fail and abort any install or update procedures.
</aside>
</div>
</section>
<section>
<h3>Range</h3>
<ul>
<li>>=1.0</li>
<li>>=1.0,<2.0</li>
<li>>=1.0,<1.1 | >=1.2</li>
<li>1.0 - 2.0 (hyphen)</li>
</ul>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
# composer.json
{
"require": {
"silex/silex": ">=1.0,<1.1 || >=1.2"
}
}
</code></pre>
<aside class="notes">
By using comparison operators you can specify ranges of valid versions. Valid operators are >, >=, <, <=, !=.
You can define multiple ranges. Ranges separated by a space ( ) or comma (,) will be treated as a logical AND. A double pipe (||) will be treated as a logical OR. AND has higher precedence than OR.
</aside>
</section>
<section>
<h3>Wildcard</h3>
<ul>
<li>1.0.*</li>
<li>1.*</li>
</ul>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
# composer.json
{
"require": {
"silex/silex": "1.0.*"
}
}
</code></pre>
</section>
<section>
<h3>Tilde Operator</h3>
<p></p>
<ul>
<li>~1.2</li>
<li>~1.2.1</li>
</ul>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
# composer.json
{
"require": {
"silex/silex": "~1.2"
}
}
</code></pre>
<aside class="notes">
Next significant release. Specifies a minimum version, but allows the last digit specified to go up.
</aside>
</section>
<section>
<h3>Caret Operator</h3>
<p></p>
<ul>
<li>^1.2.3</li>
<li>^1.2.0</li>
<li>^1.2</li>
</ul>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
# composer.json
{
"require": {
"silex/silex": "^1.2.3"
}
}
</code></pre>
<aside class="notes">
Next significant release. For pre-1.0 versions it also acts with safety in mind and treats ^0.3 as >=0.3.0 <0.4.0.
This is the recommended operator for maximum interoperability when writing library code.
</aside>
</section>
<section>
<h3>Test version constraints</h3>
<p>http://semver.mwl.be/</p>
</section>
</section>
<section>
<h2>Aliases</h2>
<p>Used to alias a branch to a specific version.</p>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
# composer.json
{
"require": {
"silex/silex": "dev-master as 1.2.9"
}
}
</code></pre>
</section>
<section>
<section>
<h2>Lock file</h2>
<h3>composer.lock</h3>
<p>After installing the dependencies, Composer writes the list of the exact versions it installed into a <strong>composer.lock</strong> file. This locks the project to those specific versions.</p>
</section>
<section>
<h3>Should I commit the lock file to VCS?</h3>
<h4 class="fragment">Depends...</h4>
<aside class="notes">
This can help your team to always test against the same dependency versions. However, this lock file will not have any effect on other projects that depend on it. It only has an effect on the main project.
</aside>
</section>
</section>
<section>
<section>
<h2>Custom Installers</h2>
<p>Allows for a package maintainer to customize the installation of their package.</p>
<h3>PhpDocumentor Example</h3>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
{
"name": "phpdocumentor/template-responsive",
"type": "phpdocumentor-template",
"require": {
"phpdocumentor/template-installer-plugin": "*"
}
}</code></pre>
<aside class="notes">
such as installing packages outside of the default vendor library.
In these cases you could consider creating a Custom Installer to handle your specific logic.
phpDocumentor features Templates that need to be installed outside of the default /vendor folder structure. As such they have chosen to adopt the phpdocumentor-template type and create a plugin providing the Custom Installer to send these templates to the correct folder.
</aside>
</section>
<section>
<h2>Custom Installers</h2>
<h3>PhpDocumentor Custom Installer Example</h3>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
{
"name": "phpdocumentor/template-installer-plugin",
"type": "composer-plugin",
"license": "MIT",
"autoload": {
"psr-0": {"phpDocumentor\\Composer": "src/"}
},
"extra": {
"class": "phpDocumentor\\Composer\\TemplateInstallerPlugin"
},
"require": {
"composer-plugin-api": "1.0.0"
}
}</code></pre>
<aside class="notes">
</aside>
</section>
<section>
<h2>Custom Installers</h2>
<h3>PhpDocumentor Custom Installer Example</h3>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
namespace phpDocumentor\Composer;
use Composer\Composer;
use Composer\IO\IOInterface;
use Composer\Plugin\PluginInterface;
class TemplateInstallerPlugin implements PluginInterface
{
public function activate(Composer $composer, IOInterface $io)
{
$installer = new TemplateInstaller($io, $composer);
$composer->getInstallationManager()->addInstaller($installer);
}
}</code></pre>
<aside class="notes">
alter or expand Composer's functionality with your own
</aside>
</section>
<section>
<h2>Custom Installers</h2>
<h3>PhpDocumentor Custom Installer Example</h3>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
namespace phpDocumentor\Composer;
use Composer\Package\PackageInterface;
use Composer\Installer\LibraryInstaller;
class TemplateInstaller extends LibraryInstaller
{
/**
* {@inheritDoc}
*/
public function getPackageBasePath(PackageInterface $package)
{
$prefix = substr($package->getPrettyName(), 0, 23);
if ('phpdocumentor/template-' !== $prefix) {
throw new \InvalidArgumentException(
'Unable to install template, phpdocumentor templates '
. 'should always start their package name with '
. '"phpdocumentor/template-"'
);
}
return 'data/templates/'.substr($package->getPrettyName(), 23);
}
/**
* {@inheritDoc}
*/
public function supports($packageType)
{
return 'phpdocumentor-template' === $packageType;
}
}</code></pre>
<aside class="notes">
</aside>
</section>
</section>
<section>
<section>
<h2>Scripts</h2>
<p>Execute custom code or package-specific commands during the composer execution process.</p>
<aside class="notes">
This is just the task-runner side of Composer. Like Gradle, Maven, Grunt, Gulp.
</aside>
</section>
</section>
<section>
<section>
<h2>Private Packages</h2>
<h3>with Satis</h3>
<p>Host your own composer repository.</p>
<p><a href="https://github.com/composer/satis">https://github.com/composer/satis</a></p>
<aside class="notes">
For example let's assume you have a few packages you want to reuse across your company but don't really want to open-source. You would first define a Satis configuration: a json file with an arbitrary name that lists your curated repositories.
</aside>
</section>
<section>
<img src="images/satis.png" />
</section>
</section>
<section>
<h2>Vendor binaries</h2>
<p>Any command line script that a Composer package would like to pass along to a user who installs the package should be listed as a vendor binary.</p>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
# composer.json
{
"bin": [
"bin/my-script",
"bin/my-other-script"
]
}
</code></pre>
<aside class="notes">
Creates a .BAT and Bash file for you, in a known location.
</aside>
</section>
<section>
<section>
<h2>DMS Considerations</h2>
<h3>Multiple PHP versions</h3>
<pre><code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
# composer.json
{
"config": {
"platform": {
"php": "5.3.3"
}
}
}
</code></pre>
<p>Lets you fake platform packages (PHP and extensions) so that you can emulate a production env or define your target platform in the config</p>
</section>
<section>
<h3>Build before deploy</h3>
<code data-trim contenteditable style="font-size: 18px; margin-top: 20px;">
$ composer install --no-dev --prefer-dist --optimize-autoloader --no-interaction
</code></pre>
</section>
</section>
<section>
<h1>THANK YOU</h1>
<h2>QUESTIONS?</h2>
<p><img src="images/cdk_logo.png" width="161" style="padding: 20px;background-color: white;" /></p>
<h3>BY John Kelly / john.m.kelly@cdk.com</h3>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.js"></script>
<script>
// Full list of configuration options available at:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
transition: 'slide', // none/fade/slide/convex/concave/zoom
// Optional reveal.js plugins
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/highlight/highlight.js', async: true, condition: function() { return !!document.querySelector( 'pre code' ); }, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true },
{ src: 'plugin/notes/notes.js', async: true },
{ src: 'socket.io/socket.io.js', async: true },
{ src: 'plugin/notes-server/client.js', async: true }
]
});
</script>
</body>
</html>