Your SlideShare is downloading. ×
  • Like
  • Save
Phing for power users - dpc_uncon13
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Phing for power users - dpc_uncon13

  • 879 views
Published

 

Published in Technology , Business
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
879
On SlideShare
0
From Embeds
0
Number of Embeds
4

Actions

Shares
Downloads
0
Comments
0
Likes
5

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Phing for power usersStephan Hochdörfer, bitExpert AG
  • 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. How to install Phing?Phing for power users
  • 4. $> pear channel­discover pear.phing.info$> pear install phing/phingHow to install Phing? The PEAR way...Phing for power usersInstalling Phing
  • 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. How to install Phing?Phing for power usersInstalling Phing globally? WTF?!?
  • 7. How to install Phing?Phing for power usersRemember: Phing is „just another“dependency for your project.
  • 8. How to install Phing? The Composer way...Phing for power users
  • 9. {"require": {"phing/phing": "2.5.0"}}How to install Phing? The Composer way...Phing for power userscomposer.json:
  • 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. 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. 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. Properties FilePhing for power users
  • 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. <?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. $> 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. Properties File - Improved versionPhing for power users
  • 18. Properties File - Improved versionPhing for power usersRequirement: Externalize the propertiesbut offer customization capabilities!
  • 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. <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. Enforce Internal TargetsPhing for power users
  • 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. <?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. $> ./vendor/bin/phing -lBuildfile: /home/shochdoerfer/myproject/build.xmlDefault target:---------------------------------------------------------helloMain targets:----------------------------------------------------------init Property initializationSubtargets:---------------------------------------------------------helloEnforce Internal TargetsPhing for power users
  • 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. $> ./vendor/bin/phing -lBuildfile: /home/shochdoerfer/myproject/build.xmlDefault target:---------------------------------------------------------helloSubtargets:---------------------------------------------------------helloEnforce Internal Targets (Improved Version)Phing for power users
  • 27. Custom TasksPhing for power users
  • 28. Custom TasksPhing for power usersRemember: Phing can do waymore than simple exec calls!
  • 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. <?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. <?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. <?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. <?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. <?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. Import Targets: Composer packagesPhing for power users
  • 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. Import Targets: Path handlingPhing for power usersBe aware that imports behavelike include in PHP!
  • 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. <?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. $> ./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. Import Targets: Path handlingPhing for power usersBe aware to always(!) use theprojects name in lowercase format!
  • 42. Import Targets: Path handlingPhing for power usersIt`s ${ping.dir.myproject} not${phing.dir.MyProject}!
  • 43. Distinct Target NamingPhing for power users
  • 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. 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. Calling PHP functions from PhingPhing for power users
  • 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. Accessing application configurationPhing for power users
  • 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. Phing + JenkinsPhing for power users
  • 51. Phing + JenkinsPhing for power usersInstall the Jenkins Phing plugin
  • 52. Phing for power users
  • 53. Phing for power users
  • 54. Phing for power users
  • 55. Phing + Composer + JenkinsPhing for power users
  • 56. Phing + Composer + JenkinsPhing for power usersInstall the Jenkins EnvInject plugin
  • 57. Phing for power users
  • 58. Phing for power users
  • 59. Phing for power users
  • 60. Phing for power users
  • 61. Follow conventionsA Phing fairy tale
  • 62. Follow conventionsA Phing fairy talePhing expects your build file to be calledbuild.xml and the build’s properties filebuild.properties
  • 63. Follow conventionsA Phing fairy talePick meaningful, human-readablenames for targets and properties.
  • 64. Follow conventionsA Phing fairy taleMake build files self-contained.
  • 65. Thank you!
  • 66. http://joind.in/8766