Phing for power usersStephan Hochdörfer, bitExpert AG
Phing for power usersAbout me Stephan Hochdörfer Head of IT at bitExpert AG, Germany enjoying PHP since 1999 S.Hochdoe...
How to install Phing?Phing for power users
$> pear channel­discover pear.phing.info$> pear install phing/phingHow to install Phing? The PEAR way...Phing for power us...
$> phing ­vPhing 2.5.0$> pear channel­discover pear.phing.info$> pear install phing/phingHow to install Phing? The PEAR wa...
How to install Phing?Phing for power usersInstalling Phing globally? WTF?!?
How to install Phing?Phing for power usersRemember: Phing is „just another“dependency for your project.
How to install Phing? The Composer way...Phing for power users
{"require": {"phing/phing": "2.5.0"}}How to install Phing? The Composer way...Phing for power userscomposer.json:
{"require": {"phing/phing": "2.5.0"}}$> php composer.phar installLoading composer repositories with package informationIns...
How to install Phing? The Composer way...Phing for power users/home/shochdoerfer/myproject   |­vendor   |­­­bin   |­­­­­@p...
How to install Phing? The Composer way...Phing for power users/home/shochdoerfer/myproject   |­vendor   |­­­bin   |­­­­­@p...
Properties FilePhing for power users
<?xml version="1.0"?><project name="myproject" default="hello"><target name="hello" description="Says whatever you want to...
<?xml version="1.0"?><project name="myproject" default="hello"><target name="hello" description="Says whatever you want to...
$> phingBuildfile: /home/shochdoerfer/build.xmlmyproject > hello: [property] Loading /home/shochdoerfer/build.properties  ...
Properties File - Improved versionPhing for power users
Properties File - Improved versionPhing for power usersRequirement: Externalize the propertiesbut offer customization capa...
<?xml version="1.0"?><project name="myproject" default="hello"><target name="hello" depends="init"><echo msg="${Hello}" />...
<target name="local-prop"if="local-prop.exists"depends="local-prop-check"><echo message="Loading custom properties!"/><pro...
Enforce Internal TargetsPhing for power users
Enforce Internal TargetsPhing for power usersUser can call both targets from command line.We do not want that.<?xml versio...
<?xml version="1.0"?><project name="myproject" default="hello"><target name="-init"description="Property initialization"><...
$> ./vendor/bin/phing -lBuildfile: /home/shochdoerfer/myproject/build.xmlDefault target:----------------------------------...
Enforce Internal Targets (Improved Version)Phing for power users<?xml version="1.0"?><project name="myproject" default="he...
$> ./vendor/bin/phing -lBuildfile: /home/shochdoerfer/myproject/build.xmlDefault target:----------------------------------...
Custom TasksPhing for power users
Custom TasksPhing for power usersRemember: Phing can do waymore than simple exec calls!
Custom Task (Adhoc definition)Phing for power users<?xml version="1.0"?><project name="myproject" default="hello"><target ...
<?phprequire_once phing/Task.php;class MyTask extends Task {/*** (non-PHPdoc)* @see Task::main()*/public function main() {...
<?xml version="1.0"?><project name="myproject" default="hello"><target name="init"><taskdefname="mytask"classpath="${proje...
<?phprequire_once phing/Task.php;class MyTask extends Task {protected $file;/*** @param string $file*/public function setF...
<?xml version="1.0"?><project name="myproject" default="hello"><target name="init"><taskdefname="mytask"classpath="${proje...
<?xml version="1.0"?><project name="myproject" default="app:run"><!--The following target namespaces exist:db:* - Database...
Import Targets: Composer packagesPhing for power users
<?xml version="1.0"?><project name="myproject" default="app:run"><!--The following target namespaces exist:lib1:* - Target...
Import Targets: Path handlingPhing for power usersBe aware that imports behavelike include in PHP!
<?xml version="1.0"?><project name="myproject" default="lib1:run"><!--The following target namespaces exist:lib1:* - Targe...
<?xml version="1.0"?><project name="lib1" default="lib1:run"><target name="lib1:run"><echo msg="Local dir: ${phing.dir.lib...
$> ./vendor/bin/phingBuildfile: /tmp/myproject/build.xmlmyproject > lib1:run:[echo] Local dir: /tmp/myproject/vendor/lib1/...
Import Targets: Path handlingPhing for power usersBe aware to always(!) use theprojects name in lowercase format!
Import Targets: Path handlingPhing for power usersIt`s ${ping.dir.myproject} not${phing.dir.MyProject}!
Distinct Target NamingPhing for power users
Distinct Target NamingPhing for power users<?xml version="1.0"?><project name="myproject" default="ci:run-tests"><target n...
Prompt user for inputPhing for power users<?xml version="1.0"?><project name="myproject" default="run"><target name="run">...
Calling PHP functions from PhingPhing for power users
Calling PHP functions from PhingPhing for power users<?xml version="1.0"?><project name="myproject" default="run"><target ...
Accessing application configurationPhing for power users
Accessing application configurationPhing for power users<?phprequire_once phing/Task.php;class ConfigMapperTask extends Ta...
Phing + JenkinsPhing for power users
Phing + JenkinsPhing for power usersInstall the Jenkins Phing plugin
Phing for power users
Phing for power users
Phing for power users
Phing + Composer + JenkinsPhing for power users
Phing + Composer + JenkinsPhing for power usersInstall the Jenkins EnvInject plugin
Phing for power users
Phing for power users
Phing for power users
Phing for power users
Follow conventionsA Phing fairy tale
Follow conventionsA Phing fairy talePhing expects your build file to be calledbuild.xml and the build’s properties filebui...
Follow conventionsA Phing fairy talePick meaningful, human-readablenames for targets and properties.
Follow conventionsA Phing fairy taleMake build files self-contained.
Thank you!
http://joind.in/8766
Upcoming SlideShare
Loading in...5
×

Phing for power users - dpc_uncon13

991

Published on

Published in: Technology, Business
0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
991
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
5
Embeds 0
No embeds

No notes for slide

Phing for power users - dpc_uncon13

  1. 1. Phing for power usersStephan Hochdörfer, bitExpert AG
  2. 2. Phing for power usersAbout me Stephan Hochdörfer Head of IT at bitExpert AG, Germany enjoying PHP since 1999 S.Hochdoerfer@bitExpert.de @shochdoerfer
  3. 3. How to install Phing?Phing for power users
  4. 4. $> pear channel­discover pear.phing.info$> pear install phing/phingHow to install Phing? The PEAR way...Phing for power usersInstalling Phing
  5. 5. $> phing ­vPhing 2.5.0$> pear channel­discover pear.phing.info$> pear install phing/phingHow to install Phing? The PEAR way...Phing for power usersInstalling PhingRunning Phing:
  6. 6. How to install Phing?Phing for power usersInstalling Phing globally? WTF?!?
  7. 7. How to install Phing?Phing for power usersRemember: Phing is „just another“dependency for your project.
  8. 8. How to install Phing? The Composer way...Phing for power users
  9. 9. {"require": {"phing/phing": "2.5.0"}}How to install Phing? The Composer way...Phing for power userscomposer.json:
  10. 10. {"require": {"phing/phing": "2.5.0"}}$> php composer.phar installLoading composer repositories with package informationInstalling dependencies  ­ Installing phing/phing (2.5.0)    Downloading: 100%         Writing lock fileGenerating autoload filesHow to install Phing? The Composer way...Phing for power userscomposer.json:Running Composer:
  11. 11. How to install Phing? The Composer way...Phing for power users/home/shochdoerfer/myproject   |­vendor   |­­­bin   |­­­­­@phing   |­­­composer   |­­­phing   |­­­­­phing   |­­­­­­­bin   |­­­­­­­­­phing   |­­­­­­­build   |­­­­­­­classes   |­­­­­­­docs   |­­­­­­­etc   |­­­­­­­test
  12. 12. How to install Phing? The Composer way...Phing for power users/home/shochdoerfer/myproject   |­vendor   |­­­bin   |­­­­­@phing   |­­­composer   |­­­phing   |­­­­­phing   |­­­­­­­bin   |­­­­­­­­­phing   |­­­­­­­build   |­­­­­­­classes   |­­­­­­­docs   |­­­­­­­etc   |­­­­­­­test$> ./vendor/bin/phing ­vPhing 2.5.0Running Phing:
  13. 13. Properties FilePhing for power users
  14. 14. <?xml version="1.0"?><project name="myproject" default="hello"><target name="hello" description="Says whatever you want to say"><propertyfile="./build.properties" /> <echo msg="${Hello}" /></target></project>Properties FilePhing for power users
  15. 15. <?xml version="1.0"?><project name="myproject" default="hello"><target name="hello" description="Says whatever you want to say"><propertyfile="./build.properties" /> <echo msg="${Hello}" /></target></project>Properties FilePhing for power usersHello=Hello, world!build.properties:
  16. 16. $> phingBuildfile: /home/shochdoerfer/build.xmlmyproject > hello: [property] Loading /home/shochdoerfer/build.properties     [echo] Hello, world!BUILD FINISHEDTotal time: 0.0601 secondsProperties FilePhing for power users
  17. 17. Properties File - Improved versionPhing for power users
  18. 18. Properties File - Improved versionPhing for power usersRequirement: Externalize the propertiesbut offer customization capabilities!
  19. 19. <?xml version="1.0"?><project name="myproject" default="hello"><target name="hello" depends="init"><echo msg="${Hello}" /></target><target name="init" depends="prop, local-prop"><!-- some more init logic --></target><target name="prop"><echo message="Load default build.properties"/><propertyfile="./build.properties" /></target>Properties File - Improved versionPhing for power users
  20. 20. <target name="local-prop"if="local-prop.exists"depends="local-prop-check"><echo message="Loading custom properties!"/><propertyfile="${project.basedir}/local.properties"override="true"/></target><target name="local-prop-check"><availablefile="${project.basedir}/local.properties"property="local-prop.exists" /></target></project>Properties File - Improved versionPhing for power users
  21. 21. Enforce Internal TargetsPhing for power users
  22. 22. Enforce Internal TargetsPhing for power usersUser can call both targets from command line.We do not want that.<?xml version="1.0"?><project name="myproject" default="hello"><target name="init"description="Property initialization"><property name="Hello" value="Hello, world!" /></target><target name="hello"depends="init"><echo msg="${Hello}" /></target></project>
  23. 23. <?xml version="1.0"?><project name="myproject" default="hello"><target name="-init"description="Property initialization"><property name="Hello" value="Hello, world!" /></target><target name="hello"depends="-init"><echo msg="${Hello}" /></target></project>Enforce Internal TargetsPhing for power usersPrefixing a targets with a „-“ prevents the targetfrom being called from the command line.
  24. 24. $> ./vendor/bin/phing -lBuildfile: /home/shochdoerfer/myproject/build.xmlDefault target:---------------------------------------------------------helloMain targets:----------------------------------------------------------init Property initializationSubtargets:---------------------------------------------------------helloEnforce Internal TargetsPhing for power users
  25. 25. Enforce Internal Targets (Improved Version)Phing for power users<?xml version="1.0"?><project name="myproject" default="hello"><target name="-init"hidden="true"description="Property initialization"><property name="Hello" value="Hello, world!" /></target><target name="hello"depends="-init"><echo msg="${Hello}" /></target></project>
  26. 26. $> ./vendor/bin/phing -lBuildfile: /home/shochdoerfer/myproject/build.xmlDefault target:---------------------------------------------------------helloSubtargets:---------------------------------------------------------helloEnforce Internal Targets (Improved Version)Phing for power users
  27. 27. Custom TasksPhing for power users
  28. 28. Custom TasksPhing for power usersRemember: Phing can do waymore than simple exec calls!
  29. 29. Custom Task (Adhoc definition)Phing for power users<?xml version="1.0"?><project name="myproject" default="hello"><target name="init"><adhoc-task name="mytask"><![CDATA[class MyTask extends Task {/*** (non-PHPdoc)* @see Task::main()*/public function main() {// Custom code here...}}]]></adhoc-task></target><target name="hello"depends="init"><mytask /></target></project>
  30. 30. <?phprequire_once phing/Task.php;class MyTask extends Task {/*** (non-PHPdoc)* @see Task::main()*/public function main() {// Custom code here...}}Custom Task (External file)Phing for power users
  31. 31. <?xml version="1.0"?><project name="myproject" default="hello"><target name="init"><taskdefname="mytask"classpath="${project.basedir}"classname="MyApp.Common.Phing.MyTask" /></target><target name="hello"depends="init"><mytask /></target></project>Custom Task (External file)Phing for power users
  32. 32. <?phprequire_once phing/Task.php;class MyTask extends Task {protected $file;/*** @param string $file*/public function setFile($file) {$this->file = $file;}/*** @see Task::main()*/public function main() {// Custom code here...}}Custom Task with ParametersPhing for power users
  33. 33. <?xml version="1.0"?><project name="myproject" default="hello"><target name="init"><taskdefname="mytask"classpath="${project.basedir}"classname="MyApp.Common.Phing.MyTask" /></target><target name="hello"depends="init"><mytask file="myfile.txt" /></target></project>Custom Task with ParametersPhing for power users
  34. 34. <?xml version="1.0"?><project name="myproject" default="app:run"><!--The following target namespaces exist:db:* - Database specific targetsapp:* - Application specific tasksci:* - CI server specific tasks--><import file="build/build.db.xml" /><import file="build/build.app.xml" /><import file="build/build.ci.xml" /></project>Imports for Targets can help structuringPhing for power users
  35. 35. Import Targets: Composer packagesPhing for power users
  36. 36. <?xml version="1.0"?><project name="myproject" default="app:run"><!--The following target namespaces exist:lib1:* - Targets imported from lib1lib2:* - Targets imported from lib2app:* - Local application targets--><import file="vendor/lib1/build/build.xml" /><import file="vendor/lib2/build/build.xml" /><import file="build/build.app.xml" /></project>Import Targets: Composer packagesPhing for power users
  37. 37. Import Targets: Path handlingPhing for power usersBe aware that imports behavelike include in PHP!
  38. 38. <?xml version="1.0"?><project name="myproject" default="lib1:run"><!--The following target namespaces exist:lib1:* - Targets imported from lib1--><import file="vendor/lib1/build/build.xml" /></project>Import Targets: Path handlingPhing for power usersbuild.xml
  39. 39. <?xml version="1.0"?><project name="lib1" default="lib1:run"><target name="lib1:run"><echo msg="Local dir: ${phing.dir.lib1}" /><echo msg="Global dir: ${phing.dir}" /></target></project><?xml version="1.0"?><project name="myproject" default="lib1:run"><!--The following target namespaces exist:lib1:* - Targets imported from lib1--><import file="vendor/lib1/build/build.xml" /></project>Import Targets: Path handlingPhing for power usersbuild.xmlvendor/lib1/build/build.xml
  40. 40. $> ./vendor/bin/phingBuildfile: /tmp/myproject/build.xmlmyproject > lib1:run:[echo] Local dir: /tmp/myproject/vendor/lib1/build[echo] Global dir: /tmp/myprojectBUILD FINISHEDTotal time: 0.0411 secondsImport Targets: Path handlingPhing for power users
  41. 41. Import Targets: Path handlingPhing for power usersBe aware to always(!) use theprojects name in lowercase format!
  42. 42. Import Targets: Path handlingPhing for power usersIt`s ${ping.dir.myproject} not${phing.dir.MyProject}!
  43. 43. Distinct Target NamingPhing for power users
  44. 44. Distinct Target NamingPhing for power users<?xml version="1.0"?><project name="myproject" default="ci:run-tests"><target name="app:clean-cache"></target><target name="app:create-cache"></target><target name="db:migrate"></target><target name="js:minifiy"></target><target name="ci:lint"></target><target name="ci:run-tests"></target></project>
  45. 45. Prompt user for inputPhing for power users<?xml version="1.0"?><project name="myproject" default="run"><target name="run"><!-- tag the database --><inputpropertyname="tag"defaultValue="mytag">Tag to create?</input><liquibase-tagtag="${tag}"jar="/opt/liquibase/liquibase.jar"classpathref="/opt/liquibase/lib/mysql.jar"changelogFile="${project.basedir}/diff.xml"username="liquibase"password="liquibase"url="jdbc:mysql://localhost/myproject"/></target></project>
  46. 46. Calling PHP functions from PhingPhing for power users
  47. 47. Calling PHP functions from PhingPhing for power users<?xml version="1.0"?><project name="myproject" default="run"><target name="run"><!--Returns canonicalized absolute pathname--><php function="realpath"returnProperty="app.dir"><param value="${app.dir}"/></php></target></project>
  48. 48. Accessing application configurationPhing for power users
  49. 49. Accessing application configurationPhing for power users<?phprequire_once phing/Task.php;class ConfigMapperTask extends Task {/*** @see Task::main()*/public function main() {// will import $APP_CONF in local contextrequire_once(src/bootstrap.php);$project = $this->project;$project->setProperty(db.host, $APP_CONF[db_host]);$project->setProperty(db.database, $APP_CONF[db_database]);$project->setProperty(db.user, $APP_CONF[db_user]);$project->setProperty(db.password, $APP_CONF[db_passwd]);}}
  50. 50. Phing + JenkinsPhing for power users
  51. 51. Phing + JenkinsPhing for power usersInstall the Jenkins Phing plugin
  52. 52. Phing for power users
  53. 53. Phing for power users
  54. 54. Phing for power users
  55. 55. Phing + Composer + JenkinsPhing for power users
  56. 56. Phing + Composer + JenkinsPhing for power usersInstall the Jenkins EnvInject plugin
  57. 57. Phing for power users
  58. 58. Phing for power users
  59. 59. Phing for power users
  60. 60. Phing for power users
  61. 61. Follow conventionsA Phing fairy tale
  62. 62. Follow conventionsA Phing fairy talePhing expects your build file to be calledbuild.xml and the build’s properties filebuild.properties
  63. 63. Follow conventionsA Phing fairy talePick meaningful, human-readablenames for targets and properties.
  64. 64. Follow conventionsA Phing fairy taleMake build files self-contained.
  65. 65. Thank you!
  66. 66. http://joind.in/8766

×