Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Phing - An Introduction (phpDublin June 2015)

Phing - An Introduction (phpDublin June 2015)

Slides for a 30 minute talk by @kenguest on phing - the multi-platform, ant based, PHP build tool. Given at @phpDublin's June 2015 meeting.

Ken Guest

June 23, 2015
Tweet

Other Decks in Programming

Transcript

  1. @phpdublin Who am I? Ken Guest <[email protected]> https://about.me/kenguest Twitter @kenguest

    Web Developer at the Irish Times PEAR guy Services_OpenStreetMap 15 years of developing projects in PHP.
  2. And what is Phing? PHing Is Not Gnu make https://www.phing.info/

    A cross platform build tool written in PHP. Automation. Gear yourself for efficiency. DRY v WET. @phpdublin
  3. And what can Phing do? Lint your code (php, javascript,

    xml) Run unit tests: phpunit, simpletest, behat Codesniffer Copy and Mess detectors Optimise images Minify javascript/css Transfer files (rsync, ftp, scp) Database migrations (dbdeploy, pdosqlexec) Modify ini files natively Git, SVN tasks Etc And it's in PHP? Yes. You can create custom tasks. @phpdublin
  4. What projects use it? joind.in OpenDAM (Digital Asset Management -

    https://github.com/martin-wikipixel/openDAM) Semantic Scuttle (social bookmarking) And many others https://github.com/reload/phing-drupal-template How to use it? From phpStorm, TextMate or NetBeans 8.1 From command line From Continuous Integration: Jenkins, Travis etc @phpdublin
  5. Obligatory Hello World example: <?xml version=”1.0” encoding=”UTF-8”?> <project name=”HelloWorld” default=”main”>

    <target name=”main”> <echo>Hello</echo> <echo msg=”World”/> </target> </project> @phpdublin
  6. @phpdublin Example with Dependencies: <?xml version=”1.0” encoding=”UTF-8”?> <project name=”HelloWorld” default=”main”>

    <target name=”main” depends=”banner,hello”/> <target name=”banner”> <echo>Banner</echo> </target> <target name=”hello”> <echo>Hello</echo> <echo msg=”World”/> </target> </project> $ phing banner $ phing hello $ phing
  7. @phpdublin Native Tasks <?xml version="1.0" encoding="UTF-8"?> <project name="HelloWorld" default="main"> <target

    name="main"> <input propertyname="name">Hello..?</input> <echo>Hello</echo> <echo msg="${name}"/> </target> </project>
  8. @phpdublin Something more meaty: <?xml version="1.0" encoding="UTF-8"?> <project name="HelloWorld" default="main">

    <property file=”buildproperties.ini”/> <import file=”build.common.xml”/> <fileset dir=”application” id=”app” includes=”**/*php”/> <fileset dir=”library” id=”library” includes=”**/*php”/> <fileset dir=”logs” id=”logs” includes=”**.log”/> <target name="main" depends=”clean,docs”/> <target name=”clean”> <delete verbose=”no”> <fileset ref=”logs”/> </delete> </target> <target name=”docs” description=”Build documentation”> <mkdir dir="${builddir}/docs" /> <phpdoc2 title="${docsTitle}" destdir="${builddir}/docs"> <fileset refid="application"/> <fileset refid="library"/> </phpdoc2> </target> </project>
  9. @phpdublin Native Tasks v 'Exec' <exec passthru="true" command="rsync -avx -e

    ssh --exclude-from=rsync_excludes . ${server}${www}" /> Compared to <FileSync sourcedir=”.” destinationdir=” ${server}${www}” verbose=”true”> Tonnes others: <scp/> <symfonyconsole/> <gitpull/> <gitpush/> <gittag/> <gitcommit/> <phpunit/> <phpdoc2/> <phpmd/> <phpcpd/> <phplint/> <phplint/> <jslint/> <xmllint/> <inifile/> <rst/> <xmllint/> <zendguardencode/> <ioncubeencoder/> <wikipublish/> https://www.phing.info/docs/guide/trunk/
  10. @phpdublin Adhoc Tasks <adhoc-task name="createusers"><![CDATA[ class CreateusersTask extends Task {

    private $filename; function setFile($filename) { $this->filename = $filename; } function main() { $this->log("Createusers: " . $this->filename); $serialised = file_get_contents($this->filename); $users = unserialize($serialised); foreach($users as $userRow) { // Do something useful... $this->log(implode($output)); } } } ]]></adhoc-task> <target name="..."> <createusers file="users.data"/> </target>
  11. @phpdublin Custom Tasks Different to AdHoc in that they reside

    outside of XML file. <taskdef name="notifysend" classname="tasks.NotifySendTask"/> <taskdef name="inifile" classname="tasks.inifile.IniFileTask"/> tasks/inifile/IniFileSet.php tasks/inifile/IniFileTask.php tasks/inifile/IniFileConfig.php tasks/inifile/IniFileRemove.php tasks/NotifySendTask.php <inifile dest="${rootdir}/application/configs/application.ini" haltonerror="no"> <set section="production" property="scriptversion" value="${DSTAMP}${TSTAMP}"/> <set section="staging : production" property="scriptversion" operation="+"/> </inifile> <target name="notify_done"> <notifysend title='Phing' msg='Phing has finished.' /> </target>