Phing is a PHP build tool, similar to Apache's Ant. Phing can be used for everything from validating your build, running tests, combining/minifying resources to deploying.
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Using Phing for Fun and Profit
1. USING PHING
FOR FUN AND
PROFIT
PHING: A PHP BUILD SYSTEM
Nic Jansma
nicj.net
@NicJ
2. PHING
Phing is a cross-platform PHP build tool, similar to Apache
Ant.
3. WHAT IS A BUILD TOOL?
A build tool helps you automate repetitive tasks.
4. A BUILD TOOL HELPS
YOU...
Build resources (CSS, JavaScript, templates, etc)
Validate code (lint, sniff, etc)
Run unit tests
Build documentation
Create packages
Deploy code
Execute system commands
... and anything else you do repetitively ...
5. WHY USE A BUILD TOOL?
Otherwise you will f*** up.
You should automate everything you can.
Automating your processes will save you time.
Automating your processes will save you from your future
self.
Maybe not today, maybe not tomorrow, but at some point
you will make a mistake if it's not automated.
6. WHY USE PHING?
It's written in PHP, so if the rest of your project is PHP, you
can run Phing.
Besides PHP, no other external dependencies are needed
(such as Ruby or Java).
Great community support, with hundreds of different tasks.
9. INSTALLATION - PEAR
$ pa c an ld s oe p a. hn .n o
> e r hn e- ic vr e rp i gi f
$ pa i sa lp i gp ig
> e r nt l hn /h n
$ pi g
> hn
10. INSTALLATION COMPOSER
composer.json:
{
" eu r" {
r q ie :
"hn /h n " " . ."
pi gp ig : 26 1
}
}
$ pp c mo e. hr is a l
> h o ps rp a n tl
L ai gc mo e rp st r e w t pc ae i fr ai n
o dn op sr e oi oi s ih a kg n om t o
I sa ln d pn ec e (n ld n rq ie d v
n tl i g e ed n is i cu ig e ur -e )
-I sa ln p ig pi g (. .)
n t li g h n/h n 26 1
D wl ai g 10
o n od n: 0 %
W ii gl c fl
r tn ok ie
G nr tn a tl a fl s
e ea i g u oo d ie
$ pp v no h n hn i hn
> h e dr pi g pi g b np i g
11. PHING OVERVIEW
Phing is driven by XML files that define your projects, build
targets, and individual tasks.
The XML format is very similar to Apache Ant.
12. PHING - PROJECTS
A project is the root element of your XML.
The < r j c >defines of all of your build targets and the
poet
tasks that will execute for the targets.
Only the d f u tattribut is required, which specifies the
eal
default target to run.
< xl vr in ". " ec dn =U F 8?
? m e so =1 0 no i g" T- ">
< rj c nm =m -r jc " df ut "u l"
p oe t ae "y p oe t ea l =b id >
< - tr es ad ts s ->
! - ag t n a k < - .. ->
!- . <po et
/rj c >
13. PHING - TARGETS
A < a g t is a logical set of actions you want to take.
tre>
A < a g t can have tasks.
tre>
A < a g t can also have a list of other targets it depends
tre>
on.
< xl vr in ". " ec dn =U F 8?
? m e so =1 0 no i g" T- ">
< rj c nm =m -r jc " df ut "u l"
p oe t ae "y p oe t ea l =b id >
< ag tn m=b id d pn s" la ,i t mn f"/
t r e ae"u l" e ed = ce nl n, ii y >
< ag tn m=c en >
t r e ae"l a"
<co mg " ' c e nn y u b id /
eh s =I m la ig o r ul " >
<tr e >
/a gt
< - .. ->
!- . <po et
/rj c >
14. PHING - TASKS
A task will take an action.
Tasks can be a core task that Phing ships with, or an external
plug-in that you write.
< xl vr in ". " ec dn =U F 8?
? m e so =1 0 no i g" T- ">
< rj c nm =m -r jc " df ut "u l"
p oe t ae "y p oe t ea l =b id >
< ag tn m=c en >
t r e ae"l a"
<co mg " ' c e nn y u b id /
eh s =I m la ig o r ul " >
<ee e d r"u l" /
dl t i=bi d >
<tr e >
/a gt
<po et
/rj c >
15. PHING - CORE TASKS
123 built-in tasks.
Some of the most useful:
File operations: a p n , c p , d l t , m d r
ped oy eee ki
Conditional logic: c n i i n f r a h i , f i
odto, oec, f al
Input / output: e h , i p t
co nu
System: e e , t t m , t s d f
xc sap ake
Source control: g t , s n , c s
i* v* v*
Network: f p e l y h t g t m i , s p t s p s h
tdpo, tpe, al 3u, c, s
External Libraries: p p o e n f e , p p n t
hcdsifr hui,
p p o u e t rj l n , p p d
hdcmno, sit hm
16. PHING - PROPERTIES
A property is a variable.
Properties can come from built-in properties (Phing
environment variables), a b i d p o e t e file, or
ul.rpris
created at runtime in your XML file via the < r p r y
poet>
element.
Use properties via the $ p o e t n m }syntax.
{rpryae
< xl vr in ". " ec dn =U F 8?
? m e so =1 0 no i g" T- ">
< rj c nm =m -r jc " df ut "l a"
p oe t ae "y p oe t ea l =c en >
< rp ry nm = bi di "v l e" /u l" /
p o et a e" ul d r au=. bi d >
< ag tn m=c en >
t r e ae"l a"
<co mg " ' c e nn $ bi di } /
eh s =I m la ig { ul dr " >
<ee e d r"{ ul dr " /
dl t i=$b i di } >
<tr e >
/a gt
<po et
/rj c >
18. PHING - .PROPERTIES
FILES
Simple k y v l eformat
e=au
#Ti i ac me t i t e .r pr is fl
hs s
om n n h po e te i e
k yv le
e =a u
b id i= ul
u ld r bi d
m ap nm =o
y p. a ef o
m ap ul ht :/ o .o
y p. r =t p/ fo cm
< xl vr in ". " ec dn =U F 8?
? m e so =1 0 no i g" T- ">
< rj c nm =m -r jc " df ut "l a"
p o e t a e " y p o e t e a l =c e n >
< rp ry fl = .b id po e te "/
p o et i e" /u l .r pr is >
< ag tn m= c en >
t r e ae "l a"
< co mg " ' c e nn $ bi di }f r$ m ap nm } /
eh s =I m la ig { ul dr o {y p. a e" >
<ee e d r"{ ul dr " /
dl t i= $b i di } >
< tr e>
/ a gt
< po et
/ rj c>
19. PHING - < R P R Y
POET>
Define new properties in your XML.
< xl vr in ". " ec dn =U F 8?
? m e so =1 0 no i g" T- ">
< rj c nm =m -r jc " df ut "u l"
p o e t a e " y p o e t e a l =b i d >
< rp ry nm = bi di "v l e" /u l" /
p o et a e" ul d r au =. bi d >
< rp ry nm = cs i"vl e "{ ul }c s /
p o et a e" sd r a u= $b id / s" >
< rp ry nm = jd r vl e"{u l} j "/
p o et a e" si " au =$b id /s >
< ag tn m= c en >
t r e ae "l a"
<ee e d r"{ sd r"/
dl t i= $c s i} >
<ee e d r"{ si } /
dl t i= $j d r" >
< tr e>
/ a gt
< po et
/ rj c>
21. SIMPLE
< xl vr in ". " ec dn =U F 8?
? m e so =1 0 no i g" T- ">
< rj c nm =m -r jc " df ut "c o >
p oe t ae "y p oe t ea l =e h"
< ag tn m=e h"
t r e ae"c o >
<co mg " el "/
eh s =H lo >
<tr e >
/a gt
<po et
/rj c >
> pi geh
$ h n co
B id ie . bi dx l
u lf l : ul . m
m -r jc > eh :
y po e t
co
[ c o H lo
eh ] el
B ID FN SE
U L I IH D
T tl tm :0 18 s cn s
o a i e .7 0 eo d
22. TWO TASKS
< xl vr in ". " ec dn =U F 8?
? m e so =1 0 no i g" T- ">
< rj c nm =m -r jc " df ut "i s"
p oe t ae "y p oe t ea l =f rt >
< ag tn m=f rt d pn s" eo d /
t r e ae"i s" e ed = sc n" >
< ag tn m=s cn "
t r e ae"e od >
<al ms a e" o ms e u" /
fi e sg =Y u es d p >
<tr e >
/a gt
<po et
/rj c >
> pi g fr t
$ h n is
B id ie . bi dx l
u lf l: ul . m
m -r jc > sc n :
y po e t
eo d
E eu in o tr e "e od f ie f rt ef lo i gr ao :
x ct o f ag t sc n " a l d o h ol wn e s n
. bi dx l1: 2 Y u ms e u
u l. m: 62 : o es d p
B ID FI E
U L A LD
. bi dx l1:2 Y um s e u
ul . m: 62 : o es d p
T tl tm :0 10 s cn s
o a i e .8 0 eo d
23. SHELL COMMANDS
< xl vr in ". " ec dn =U F 8?
? m e so =1 0 no i g" T- ">
< rj c nm =m -r jc " df ut "e ly >
p oe t ae "y p oe t ea l =d po "
< rp rynm = dp o. ot a e v le " o. o"/
p o et a e" el y hs nm " au=f oc m >
< ag tn m=d po "
t r e ae"e ly >
<xc
ee
c ma d"s n -v . $d po . ot ae /
om n=ry z az / { el yh sn m }"
d r" { rj c. ae i }
i= $p oe t bs dr "
c ek e un"r e /
hc rt r=t u" >
<tr e >
/a gt
<po et
/rj c >
24. EXTERNAL PHP
< xl vr in ". " ec dn =U F 8?
? m e so =1 0 no i g" T- ">
< rj c nm =m -r jc " df ut "x en l ak >
p oe t ae "y p oe t ea l =e tr at s"
< ag tn m=e tr at s"
t r e ae"x en l ak >
<ak e
ts df
n m=m po et ak
ae"y rj c ts "
c as a h" {r jc . ae i}
ls pt=$ p oe tb sd r"
c as a e" ya k / <- .M T s. h ->
ls nm=M T s" > !- / ya kp p <yr jc t s m s ae'i /
mp oe ta k es g=h ' >
<tr e >
/a gt
<po et
/rj c >
< pp
?h
r qi eo c 'h n/ ak p p;
e ur _ ne pi g Ts .h '
c as MT s et ns Ts {
l s y ak xe d a k
p oe td $e s g;
r t ce m sa e
/ s tf o t e ts ' at iu ei t eX L
/ e r m h ak s tr b t n h M
p bi f nt o st es g (m sa e {
u l c u ci n eM s ae $e sg )
$ hs>e s g = $ es g;
ti-m sa e
m sa e
}
/ e eu e w e ts i c le
/ x ct d hn a k s a l d
p bi f nt o mi ( {
u l c u ci n an )
e h $h s> es g ;
co ti - ms ae
}
25. EXTERNAL PHP - OUTPUT
$ pi ge tr at s
> hn xe nl ak
B id ie . bi d x l
u lf l : ul . m
[ rp r y L ai g .b id po e te
po et ] od n u l .r pr is
m -r jc > et ra ts :
y po e t
xe n la k
h
i
B ID FN SE
U L I IH D
T tl tm :0 23 s cn s
o a i e .9 0 eo d
26. CONTINUOUS
INTEGRATION / BUILD
SERVER
< xl vr in ". " ec dn =U F 8?
? m e so =1 0 no i g" T- ">
< rj c nm =b gp oe t df u t" ul "
p oe t ae "i - rj c" e al =b id >
< - mi tr e s- >
! - an a gt < ag tn m=b id d pn s" la ,h c ot ln ,
t r e ae"u l" e ed = ce nc ek u, i t
s if pp d ts ,o ,a k g" /
nf ,h m, et d cp ca e >
< ag tn m=d po "d pn s"u l, r- el y ry cr la e /
t r e ae"e ly ee d=bi dp e dp o, sn , ee s" >
< ag tn m=c en >
t r e ae"l a"
< - ce nt eb i d- >
!- la h ul <tr e >
/a gt
< ag tn m=c ek u"
t r e ae"h co t >
< - ce ku / pl l ts f o s u c c n rl ->
!- hc o t
u l a e t r m or e ot o <tr e >
/a gt
< ag tn m=l n" dp ns " hl n, si tc s it /
t r e ae"i t e ed =p pi tj l n, sl n" >
< ag tn m=p pi t>
t r e ae"h ln "
< - pp ln a l* pp f ls ->
!- h i t l .h i e <tr e >
/a gt
< ag tn m=j ln "
t r e ae"s it >
27. DOWNSITDES
Learning curve if you're not familiar with Ant.
Asynchronous operation, so large builds/deploys may be
slow.
Not everything is available on all OSs.
29. CONCLUSION
Phing is a great way to automate repetitive tasks.
Phing can be as simple or complex (and powerful) as you
make it.
Phing can save time and reduce human error.
More Info:
phing.info
Jenkins integration
Jetbrains PhpStorm integration
Eclipse integration
Thanks - Nic Jansma - nicj.net - @NicJ