Phing – A PHP Build Tool An Introduction Michiel Rook DPC 2011 - Uncon
About me Michiel Rook <ul><li>Freelance PHP/Java consultant
Phing project lead
http://nl.linkedin.com/in/michieltcs
@michieltcs </li></ul>
About Phing <ul><li>“PHing Is Not GNU make; it's a PHP project build system or build tool based on  Apache Ant.”
Originally developed by Binarycloud
Ported to PHP5 by Hans Lellelid
I joined in 2005 </li></ul>
Features <ul><li>Scripting using XML build files
Mostly cross platform
Interface to various popular (PHP) tools </li></ul>
Features
Installation <ul><li>PEAR installation $ pear channel-discover pear.phing.info $ pear install [--alldeps] phing/phing
Optionally install the documentation $ pear install phing/phingdocs </li></ul>
Why A Build Tool?
Why A Build Tool <ul><li>Repetitive tasks </li><ul><li>Version control
(Unit) Testing
Configuring
Packaging
Uploading
DB changes
... </li></ul></ul>
Why A Build Tool <ul><li>For developers and deployments
Automate! </li><ul><li>Easier handover to new team members
Improves quality
Reduces errors
Saves time </li></ul></ul>
Upcoming SlideShare
Loading in...5
×

Phing - A PHP Build Tool (An Introduction)

10,685
-1

Published on

PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.

These are slides from my talk during the Unconference at the Dutch PHP 2011 Conference (Amsterdam). During this talk I gave an overview of the features and how to use, adapt and extend Phing.

Published in: Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
10,685
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
157
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Phing - A PHP Build Tool (An Introduction)

  1. 1. Phing – A PHP Build Tool An Introduction Michiel Rook DPC 2011 - Uncon
  2. 2. About me Michiel Rook <ul><li>Freelance PHP/Java consultant
  3. 3. Phing project lead
  4. 4. http://nl.linkedin.com/in/michieltcs
  5. 5. @michieltcs </li></ul>
  6. 6. About Phing <ul><li>“PHing Is Not GNU make; it's a PHP project build system or build tool based on Apache Ant.”
  7. 7. Originally developed by Binarycloud
  8. 8. Ported to PHP5 by Hans Lellelid
  9. 9. I joined in 2005 </li></ul>
  10. 10. Features <ul><li>Scripting using XML build files
  11. 11. Mostly cross platform
  12. 12. Interface to various popular (PHP) tools </li></ul>
  13. 13. Features
  14. 14. Installation <ul><li>PEAR installation $ pear channel-discover pear.phing.info $ pear install [--alldeps] phing/phing
  15. 15. Optionally install the documentation $ pear install phing/phingdocs </li></ul>
  16. 16. Why A Build Tool?
  17. 17. Why A Build Tool <ul><li>Repetitive tasks </li><ul><li>Version control
  18. 18. (Unit) Testing
  19. 19. Configuring
  20. 20. Packaging
  21. 21. Uploading
  22. 22. DB changes
  23. 23. ... </li></ul></ul>
  24. 24. Why A Build Tool <ul><li>For developers and deployments
  25. 25. Automate! </li><ul><li>Easier handover to new team members
  26. 26. Improves quality
  27. 27. Reduces errors
  28. 28. Saves time </li></ul></ul>
  29. 29. Why Phing <ul><li>Rich set of tasks
  30. 30. Integration with PHP specific tools
  31. 31. Allows you to stay in the PHP infrastructure
  32. 32. Easy to extend
  33. 33. Embed PHP code directly in the build file </li></ul>
  34. 34. Why Phing <ul><li>Rich set of tasks
  35. 35. Integration with PHP specific tools
  36. 36. Allows you to stay in the PHP infrastructure
  37. 37. Easy to extend
  38. 38. Embed PHP code directly in the build file
  39. 39. … in the end, the choice is yours </li></ul>
  40. 40. The Basics <ul><li>Phing uses XML build files
  41. 41. Standard elements </li><ul><li>Task : code that performs a specific function (svn checkout, mkdir, etc.)
  42. 42. Target : groups of tasks, can optionally depend on other targets
  43. 43. Project : root node, contains multiple targets </li></ul></ul>
  44. 44. Example Build File < project name = &quot;Example&quot; default = &quot;world&quot; > < target name = &quot;hello&quot; > < echo > Hello </ echo > </ target > < target name = &quot;world&quot; depends = &quot;hello&quot; > < echo > World! </ echo > </ target > </ project >
  45. 45. Properties < project name = &quot;Example&quot; default = &quot;default&quot; > < property file = &quot;build.properties&quot; / > < target name = &quot;default&quot; > < echo > ${version} </ echo > </ target > </ project > ## build.properties version=1.0
  46. 46. FileSet <ul><li>Constructs a group of files to process
  47. 47. Supported by most tasks </li></ul>< fileset dir = &quot;./application&quot; > <include name = &quot;**/*.php&quot; / > <exclude name = &quot;**/*.php&quot; / > </ fileset > < fileset dir = &quot;./application&quot; includes = &quot;**&quot; / > < fileset dir = &quot;./application&quot; id = &quot;files&quot; > <include name = &quot;**/*.php&quot; / > <exclude name = &quot;**/*Test.php&quot; / > </ fileset > < fileset refid = &quot;files&quot; / >
  48. 48. FileSet <ul><li>Selectors allow fine-grained matching on certain attributes </li></ul>< fileset dir = &quot;${dist}&quot; > <and> <filename name = &quot;**&quot; /> <date datetime = &quot;01/01/2011&quot; when = &quot;before&quot; /> </and> </ fileset >
  49. 49. Mappers & Filters <ul><li>Transform files during copy/move/...
  50. 50. Mappers </li><ul><li>Change filename </li></ul><li>Filters </li><ul><li>Strip comments
  51. 51. Replace values
  52. 52. Perform XSLT transformation
  53. 53. Translation (i18n) </li></ul></ul>
  54. 54. Mappers & Filters < copy todir = &quot;${build}&quot; > <fileset refid = &quot;files&quot; / > <mapper type = &quot;glob&quot; from = &quot;*.txt&quot; type = &quot;*.new.txt&quot; / > <filterchain> <replaceregexp> <regexp pattern = &quot;rn&quot; replace = &quot;n&quot; /> </replaceregexp> </filterchain> </ copy >
  55. 55. Testing <ul><li>Built-in support for PHPUnit / SimpleTest / Xdebug
  56. 56. Various output formats </li></ul>
  57. 57. Testing < target name = &quot;test&quot; > < coverage-setup database = &quot;reports/coverage.db&quot; > < fileset dir = &quot;src&quot; > < include name = &quot;**/*.php&quot; /> < exclude name = &quot;**/*Test.php&quot; /> </ fileset > </ coverage-setup > < phpunit codecoverage = &quot;true&quot; > < formatter type = &quot;xml&quot; todir = &quot;reports&quot; /> < formatter type = &quot;clover&quot; todir = &quot;.&quot; /> < batchtest > < fileset dir = &quot;src&quot; > < include name = &quot;**/*Test.php&quot; /> </ fileset > </ batchtest > </ phpunit >
  58. 58. Testing < phpunitreport infile = &quot;reports/testsuites.xml&quot; format = &quot;frames&quot; todir = &quot;reports/tests&quot; styledir = &quot;../../etc&quot; /> < coverage-report outfile = &quot;reports/coverage.xml&quot; > < report todir = &quot;reports/coverage&quot; styledir = &quot;../../etc&quot; title = &quot;Demo&quot; /> </ coverage-report > </ target >
  59. 59. Extending Phing <ul><li>Numerous possibilities </li><ul><li>Tasks
  60. 60. Types
  61. 61. Selectors
  62. 62. Filters
  63. 63. Mappers
  64. 64. Loggers
  65. 65. ... </li></ul></ul>
  66. 66. Sample Task class SampleTask extends Task { private $var ; public function setVar($v) { $this-> var = $v; } public function main() { $this->log( &quot;value: &quot; . $this-> var ); } }
  67. 67. Sample Task < project name = &quot;Example&quot; default = &quot;default&quot; > < taskdef name = &quot;sample&quot; classname = &quot;phing.tasks.my.SampleTask&quot; /> < target name = &quot;default&quot; > < sample var = &quot;Hello World&quot; /> </ target > </ project >
  68. 68. Ad Hoc Extension < target name = &quot;main&quot; > <adhoc-task name = &quot;foo&quot; > <![CDATA[ class FooTest extends Task { private $bar; function setBar($bar) { $this->bar = $bar; } function main() { $this->log(&quot;In FooTest: &quot; . $this->bar); } } ]]> </ adhoc-task > <foo bar = &quot;TEST&quot; / > </ target >
  69. 69. More Uses For Phing <ul><li>Installation
  70. 70. Bootstrap dev. environments
  71. 71. DB migrations
  72. 72. Analyze code
  73. 73. Run (unit) tests
  74. 74. Upgrade server </li></ul>
  75. 75. What's Next For Phing <ul><li>Improvements </li><ul><li>More tasks (DocBlox), bug fixes
  76. 76. Test coverage
  77. 77. Cross-platform compatibility
  78. 78. Pain-free installation of dependencies
  79. 79. IDE support </li></ul><li>We would love more contributions! </li></ul>
  80. 80. Questions? http://www.phing.info http://joind.in/3475 #phing (freenode) @phingofficial
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×