/
index.html
618 lines (467 loc) · 20.7 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
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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Using Phing for Fun and Profit</title>
<meta name="description" content="Using Phing for Fun and Profit">
<meta name="author" content="Nic Jansma">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/nicj.css" id="theme">
<!-- For syntax highlighting -->
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', use the PDF print sheet -->
<script>
document.write( '<link rel="stylesheet" href="css/print/' + ( window.location.search.match( /print-pdf/gi ) ? 'pdf' : 'paper' ) + '.css" type="text/css" media="print">' );
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h1>Using Phing for Fun and Profit</h1>
<h3>Phing: A PHP build system</h3>
<p>
<small><a href="http://nicj.net">Nic Jansma</a></small>
</p>
<p>
<small><a href="http://nicj.net">nicj.net</a></small>
</p>
<p>
<small><a href="http://twitter.com/nicj">@NicJ</a></small>
</p>
</section>
<section>
<h2>Phing</h2>
<p>
<a href="http://www.phing.info">Phing</a> is a cross-platform PHP build tool</a>, similar to
<a href="http://ant.apache.org/">Apache Ant</a>.
</p>
</section>
<section>
<section>
<h2>What is a build tool?</h2>
<p>A build tool helps you automate repetitive tasks.</p>
</section>
<section>
<h2>A Build Tool Helps You...</h2>
<ul>
<li>Build resources (CSS, JavaScript, templates, etc)</li>
<li>Validate code (lint, sniff, etc)</li>
<li>Run unit tests</li>
<li>Build documentation</li>
<li>Create packages</li>
<li>Deploy code</li>
<li>Execute system commands</li>
<li>... and anything else you do repetitively ...</li>
</ul>
</section>
<section>
<h2>Why Use a Build Tool?</h2>
<p class="fragment">Otherwise you will f*** up.</p>
<p class="fragment">You should automate <b>everything</b> you can.</p>
<p class="fragment">Automating your processes will save you time.</p>
<p class="fragment">Automating your processes will save you from your future self.</p>
<p class="fragment">Maybe not today, maybe not tomorrow, but at some point you will make
a mistake if it's not automated.</p>
</section>
<section>
<h2>Why Use Phing?</h2>
<p>It's written in PHP, so if the rest of your project is PHP, you can run Phing.</p>
<p>Besides PHP, no other external dependencies are needed (such as Ruby or Java).</p>
<p>Great community support, with hundreds of different tasks.</p>
</section>
</section>
<section>
<section>
<h2>Installation - Github</h2>
<p><a href="https://github.com/phingofficial/phing">github.com/phingofficial/phing</a></p>
<pre><code>
$> git clone https://github.com/phingofficial/phing.git
$> php phing\bin\phing
</code></pre>
</section>
<section>
<h2>Installation - PHAR Package</h2>
<p><a href="http://www.phing.info/trac/wiki/Users/Download">www.phing.info/trac/wiki/Users/Download</a></p>
<pre><code>
$> wget http://www.phing.info/get/phing-latest.phar -O phing.phar
$> php phing.phar
</code></pre>
</section>
<section>
<h2>Installation - PEAR</h2>
<pre><code>
$> pear channel-discover pear.phing.info
$> pear install phing/phing
$> phing
</code></pre>
</section>
<section>
<h2>Installation - Composer</h2>
<p>composer.json:</p>
<pre><code>
{
"require": {
"phing/phing": "2.6.1"
}
}
</code></pre>
<pre><code>
$> php composer.phar install
Loading composer repositories with package information
Installing dependencies (including require-dev)
- Installing phing/phing (2.6.1)
Downloading: 100%
Writing lock file
Generating autoload files
$> php vendor\phing\phing\bin\phing
</code></pre>
</section>
</section>
<section>
<section>
<h2>Phing Overview</h2>
<p>Phing is driven by XML files that define your projects, build targets, and individual tasks.</p>
<p>The XML format is very similar to <a href="http://ant.apache.org/">Apache Ant</a>.</p>
</section>
<section>
<h2>Phing - Projects</h2>
<p>A project is the root element of your XML.</p>
<p>The <code><project></code> defines of all of your build targets and the tasks that will execute for the targets.</p>
<p>Only the <code>default</code> attribut is required, which specifies the default target to run.</p>
<pre><code>
<?xml version="1.0" encoding="UTF-8"?>
<project name="my-project" default="build">
<!-- targets and tasks -->
<!-- ... -->
</project>
</code></pre>
</section>
<section>
<h2>Phing - Targets</h2>
<p>A <code><target></code> is a logical set of actions you want to take.</p>
<p>A <code><target></code> can have tasks.</p>
<p>A <code><target></code> can also have a list of other targets it depends on.</p>
<pre><code>
<?xml version="1.0" encoding="UTF-8"?>
<project name="my-project" default="build">
<target name="build" depends="clean,lint,minify" />
<target name="clean">
<echo msg="I'm cleaning your build" />
</target>
<!-- ... -->
</project>
</code></pre>
</section>
<section>
<h2>Phing - Tasks</h2>
<p>A task will take an action.</p>
<p>Tasks can be a <a href="http://www.phing.info/docs/stable/hlhtml/index.html#app.coretasks">core task</a>
that Phing ships with,
or an external <a href="http://www.phing.info/docs/stable/hlhtml/index.html#ch.extending">plug-in</a>
that you write.</a>
<pre><code>
<?xml version="1.0" encoding="UTF-8"?>
<project name="my-project" default="build">
<target name="clean">
<echo msg="I'm cleaning your build" />
<delete dir="build" />
</target>
</project>
</code></pre>
</section>
<section>
<h2>Phing - Core Tasks</h2>
<p><a href="http://www.phing.info/docs/stable/hlhtml/index.html#app.coretasks">123 built-in tasks</a>.</p>
<p>Some of the most useful:</p>
<ul>
<li>File operations: <code>append</code>, <code>copy</code>, <code>delete</code>, <code>mkdir</code></li>
<li>Conditional logic: <code>condition</code>, <code>foreach</code>, <code>if</code>, <code>fail</code></li>
<li>Input / output: <code>echo</code>, <code>input</code></li>
<li>System: <code>exec</code>, <code>tstamp</code>, <code>taskdef</code></li>
<li>Source control: <code>git*</code>, <code>svn*</code>, <code>cvs*</code></li>
<li>Network: <code>ftpdeploy</code>, <code>httpget</code>, <code>mail</code>, <code>s3put</code>, <code>scp</code>, <code>ssh</code></li>
<li>External Libraries: <code>phpcodesniffer</code>, <code>phpunit</code>, <code>phpdocumentor</code>, <code>jslint</code>, <code>phpmd</code></li>
</ul>
</section>
<section>
<h2>Phing - Properties</h2>
<p>A property is a variable.</p>
<p>Properties can come from built-in properties (Phing environment variables),
a <code>build.properties</code> file, or created at runtime in your XML file via the <code><property></code> element.</p>
<p>Use properties via the <code>${propertyname}</code> syntax.</p>
<pre><code>
<?xml version="1.0" encoding="UTF-8"?>
<project name="my-project" default="clean">
<property name="builddir" value="./build" />
<target name="clean">
<echo msg="I'm cleaning ${builddir}" />
<delete dir="${builddir}" />
</target>
</project>
</code></pre>
</section>
<section>
<h2>Phing - Built-in Properties</h2>
<p>There are many <a href="http://www.phing.info/docs/stable/hlhtml/index.html#app.factsheet">built-in</a> properties:</p>
<p><code>application.startdir, env.*, host.arch, host.domain, host.fstype, host.name, host.os, host.os.release,
host.os.version, line.separator, os.name, phing.file, phing.dir, phing.home, phing.version, phing.project.name,
php.classpath, php.version, project.basedir, user.home</code></p>
</section>
<section>
<h2>Phing - .properties Files</h2>
<p>Simple <code>key=value</code> format</p>
<pre><code>
# This is a comment in the .properties file
key=value
builddir=build
myapp.name=foo
myapp.url=http://foo.com
</code></pre>
<pre><code>
<?xml version="1.0" encoding="UTF-8"?>
<project name="my-project" default="clean">
<property file="./build.properties" />
<target name="clean">
<echo msg="I'm cleaning ${builddir} for ${myapp.name}" />
<delete dir="${builddir}" />
</target>
</project>
</code></pre>
</section>
<section>
<h2>Phing - <code><property></code></h2>
<p>Define new properties in your XML.</p>
<pre><code>
<?xml version="1.0" encoding="UTF-8"?>
<project name="my-project" default="build">
<property name="builddir" value="./build" />
<property name="cssdir" value="${build}/css" />
<property name="jsdir" value="${build}/js" />
<target name="clean">
<delete dir="${cssdir}" />
<delete dir="${jsdir}" />
</target>
</project>
</code></pre>
</section>
</section>
<section>
<section>
<h2>Examples</h2>
</section>
<section>
<h2>Simple</h2>
<pre><code>
<?xml version="1.0" encoding="UTF-8"?>
<project name="my-project" default="echo">
<target name="echo">
<echo msg="Hello" />
</target>
</project>
</code></pre>
<pre><code>
>$ phing echo
Buildfile: .\build.xml
my-project > echo:
[echo] Hello
BUILD FINISHED
Total time: 0.1780 seconds
</code></pre>
</section>
<section>
<h2>Two Tasks</h2>
<pre><code>
<?xml version="1.0" encoding="UTF-8"?>
<project name="my-project" default="first">
<target name="first" depends="second" />
<target name="second">
<fail message="You messed up" />
</target>
</project>
</code></pre>
<pre><code>
>$ phing first
Buildfile: .\build.xml
my-project > second:
Execution of target "second" failed for the following reason:
.\build.xml:16:22: You messed up
BUILD FAILED
.\build.xml:16:22: You messed up
Total time: 0.1800 seconds
</code></pre>
</section>
<section>
<h2>Shell Commands</h2>
<pre><code>
<?xml version="1.0" encoding="UTF-8"?>
<project name="my-project" default="deploy">
<property name="deploy.hostname" value="foo.com" />
<target name="deploy">
<exec
command="rsynz -avz ./ ${deploy.hostname}/"
dir="${project.basedir}"
checkreturn="true" />
</target>
</project>
</code></pre>
</section>
<section>
<h2>External PHP</h2>
<pre><code>
<?xml version="1.0" encoding="UTF-8"?>
<project name="my-project" default="externaltask">
<target name="externaltask">
<taskdef
name="myprojecttask"
classpath="${project.basedir}"
classname="MyTask" /> <!-- ./MyTask.php -->
<myprojecttask message='hi' />
</target>
</project>
</code></pre>
<pre><code>
<?php
require_once 'phing/Task.php';
class MyTask extends Task {
protected $message;
// set from the task's attribute in the XML
public function setMessage($message) {
$this->message = $message;
}
// executed when task is called
public function main() {
echo $this->message;
}
}
</code></pre>
</section>
<section>
<h2>External PHP - Output</h2>
<pre><code>
$>phing externaltask
Buildfile: .\build.xml
[property] Loading .\build.properties
my-project > externaltask:
hi
BUILD FINISHED
Total time: 0.2930 seconds
</code></pre>
</section>
<section>
<h2>Continuous Integration / Build Server</h2>
<pre><code>
<?xml version="1.0" encoding="UTF-8"?>
<project name="big-project" default="build">
<!-- main targets -->
<target name="build" depends="clean,checkout,lint,
sniff,phpmd,test,doc,package" />
<target name="deploy" depends="build,pre-deploy,rsync,release" />
<target name="clean">
<!-- clean the build -->
</target>
<target name="checkout">
<!-- checkout / pull latest from source control -->
</target>
<target name="lint" depends="phplint,jslint,csslint" />
<target name="phplint">
<!-- php lint all *.php files -->
</target>
<target name="jslint">
<!-- jslint / jshint -->
</target>
<target name="csslint">
<!-- csslint -->
</target>
<target name="sniff">
<!-- PHP_CodeSniffer -->
</target>
<target name="phpmd">
<!-- PHPMD -->
</target>
<target name="test">
<!-- phpUnit -->
</target>
<target name="doc">
<!-- phpDocumentor -->
</target>
<target name="package">
<!-- save all build artifacts -->
</target>
<target name="pre-deploy">
<!-- any internal pre-deploy tasks -->
</target>
<target name="rsync">
<!-- rsync or ssh+rsync -->
</target>
<target name="release">
<!-- release new code on servers -->
</target>
</project>
</code></pre>
</section>
</section>
<section>
<h2>Downsitdes</h2>
<ul>
<li>Learning curve if you're not familiar with Ant.</li>
<li>Asynchronous operation, so large builds/deploys may be slow.</li>
<li>Not everything is available on all OSs.</li>
</ul>
</section>
<section>
<section>
<h2>Conclusion</h2>
<ol>
<li>Use Phing</li>
<li>???</li>
<li>Profit!</li>
</ol>
</section>
<section>
<h2>Conclusion</h2>
<p>Phing is a great way to automate repetitive tasks.</p>
<p>Phing can be as simple or complex (and powerful) as you make it.</p>
<p>Phing can save time and reduce human error.</p>
<p>More Info:</p>
<ul>
<li><a href="http://www.phing.info/">phing.info</a></li>
<li><a href="https://wiki.jenkins-ci.org/display/JENKINS/Phing+Plugin">Jenkins integration</a></li>
<li><a href="http://www.jetbrains.com/phpstorm/webhelp/using-phing.html">Jetbrains PhpStorm integration</a></li>
<li><a href="https://code.google.com/a/eclipselabs.org/p/phingle/">Eclipse integration</a></li>
</ul>
<p style='margin-top: 20px'><small>Thanks - Nic Jansma - <a href="http://nicj.net">nicj.net</a> - <a href="https://twitter.com/NicJ">@NicJ</a></small></p>
</section>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
// Full list of configuration options available here:
// https://github.com/hakimel/reveal.js#configuration
Reveal.initialize({
controls: true,
progress: true,
history: true,
center: true,
theme: Reveal.getQueryHash().theme, // available themes are in /css/theme
transition: Reveal.getQueryHash().transition || 'default', // default/cube/page/concave/zoom/linear/fade/none
// Optional libraries used to extend on reveal.js
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, callback: function() { hljs.initHighlightingOnLoad(); } },
{ src: 'plugin/zoom-js/zoom.js', async: true, condition: function() { return !!document.body.classList; } },
{ src: 'plugin/notes/notes.js', async: true, condition: function() { return !!document.body.classList; } }
]
});
</script>
</body>
</html>