• Save
Phing for power users - dpc_uncon13
Upcoming SlideShare
Loading in...5
×
 

Phing for power users - dpc_uncon13

on

  • 1,101 views

 

Statistics

Views

Total Views
1,101
Views on SlideShare
1,086
Embed Views
15

Actions

Likes
5
Downloads
0
Comments
0

4 Embeds 15

http://lanyrd.com 7
http://librosweb.es 5
https://twitter.com 2
http://getpocket.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Phing for power users - dpc_uncon13 Phing for power users - dpc_uncon13 Presentation Transcript

  • 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.Hochdoerfer@bitExpert.de @shochdoerfer
  • 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 usersInstalling Phing
  • $> 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:
  • 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 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:
  • 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
  • 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:
  • Properties FilePhing for power users
  • <?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
  • <?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:
  • $> 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
  • Properties File - Improved versionPhing for power users
  • Properties File - Improved versionPhing for power usersRequirement: Externalize the propertiesbut offer customization capabilities!
  • <?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
  • <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
  • 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 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>
  • <?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.
  • $> ./vendor/bin/phing -lBuildfile: /home/shochdoerfer/myproject/build.xmlDefault target:---------------------------------------------------------helloMain targets:----------------------------------------------------------init Property initializationSubtargets:---------------------------------------------------------helloEnforce Internal TargetsPhing for power users
  • 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>
  • $> ./vendor/bin/phing -lBuildfile: /home/shochdoerfer/myproject/build.xmlDefault target:---------------------------------------------------------helloSubtargets:---------------------------------------------------------helloEnforce Internal Targets (Improved Version)Phing for power users
  • 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 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>
  • <?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
  • <?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
  • <?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
  • <?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
  • <?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
  • Import Targets: Composer packagesPhing for power users
  • <?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
  • 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:* - Targets imported from lib1--><import file="vendor/lib1/build/build.xml" /></project>Import Targets: Path handlingPhing for power usersbuild.xml
  • <?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
  • $> ./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
  • 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 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>
  • 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>
  • 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 name="run"><!--Returns canonicalized absolute pathname--><php function="realpath"returnProperty="app.dir"><param value="${app.dir}"/></php></target></project>
  • Accessing application configurationPhing for power users
  • 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]);}}
  • 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 filebuild.properties
  • 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