SlideShare a Scribd company logo
Putting Phing to Work for You
                          Hans Lellelid
          International PHP Conference
                            2007-11-05
Introduction
• My name is Hans Lellelid
• Developer & Manager at Applied Security,
  Inc. (near Washington DC).
• PHP developer and OO evangelist.
• I ported Phing to PHP5 in 2004.
• I now manage the Phing project with
  Michiel Rook.




Hans Lellelid: Putting Phing to Work for You    2
What is it?
•   PHing Is Not Gnumake
•   It is a project build tool.
•   Original PHP4 version by Andreas Aderhold
•   Written for PHP5
•   Based on Apache Ant
•   Cross-platform (i.e. Windows too)
•   http://phing.info/



Hans Lellelid: Putting Phing to Work for You      3
Workshop Topics: Fundamentals
•   Phing basics
•   Creating a first build file
•   Transforming directories and files
•   Performing PDO tasks
•   Gathering user input
•   Building phpdoc
•   Running unit tests
•   Integrating with CI tools


Hans Lellelid: Putting Phing to Work for You   4
Workshop Topics: Extension
•   Using PHP code in a build file
•   Building a simple Task
•   Writing more complex Task
•   Creating a shared Type
•   Custom filters
•   Custom selectors
•   Custom logger/listener
•   Custom input handlers


Hans Lellelid: Putting Phing to Work for You   5
Getting Started




Hans Lellelid: Putting Phing to Work for You   6
Install Phing
• Install via PEAR
      – pear channel-discover pear.phing.info
      – pear install phing/phing
• Install “traditional” package
      – Available on Download page
• Install from SVN
      – svn co http://svn.phing.info/trunk phing




Hans Lellelid: Putting Phing to Work for You       7
Following Along
• Install via PEAR
      – pear install phing/phing
      – Install “traditional” package
• Available on Download page
      – Install from SVN
• svn co http://svn.phing.info/trunk phing




Hans Lellelid: Putting Phing to Work for You   8
The phing script
• A wrapper shell script for phing.php script.
• Sets default logger to use (dependent on
  system)
• Typical usage: phing [target]
• Other useful options:
      – Help (-h)
      – Specify properties (-Dpropname=value)
      – List targets (-l)
      – Get more output (-verbose or -debug)

Hans Lellelid: Putting Phing to Work for You    9
Buildfiles
• Build files are XML
• Build files are composed of:
      – Tasks: a “build-in” piece of code that a
        specific function. E.g. <mkdir>
      – Types: data structures that are used
        commonly by tasks. E.g. <path>
      – Targets: grouping of Tasks that perform a
        more general function. E.g. Copy files to a
        new directory.
      – A Project: the root node for the build file.

Hans Lellelid: Putting Phing to Work for You       10
A simple build file
     <project name=quot;samplequot; default=quot;mainquot;>
        <property name=quot;verquot; value=quot;1.0.1quot;/>
        <property file=quot;build.propertiesquot;/>

          <target name=quot;mainquot;>
            <mkdir dir=quot;./build/${ver}quot;>
            <copy todir=quot;./build/${ver}quot;>
               <fileset dir=quot;.quot;
                  includes=quot;*.txtquot; />
            </copy>
          </target>

     </project>
Hans Lellelid: Putting Phing to Work for You   11
Javaisms
• Properties
      – Properties are variables for build scripts.
      – Like php.ini, but more flexible:
            • tgz = ${pkg}-${ver}.tgz
      – Can be set in build script or imported from
        files.
• Dot-path notation for class names:
      – path.to.Class = path/to/Class.php
      – Represents directory and class name in a
        single string.
Hans Lellelid: Putting Phing to Work for You          12
Control Structures
• depends, if, and unless attributes provide
  control over target execution condition and
  sequence.
• <if> task provides a more familiar (to
  developers) control structure that can be
  used within a target.




Hans Lellelid: Putting Phing to Work for You   13
Reorganize, Transform




Hans Lellelid: Putting Phing to Work for You   14
Match a bunch of files
• The <fileset> type represents an
  extremely powerful way to select a
  group of files for processing
• Many built-in tasks support <fileset>




Hans Lellelid: Putting Phing to Work for You   15
Fileset Examples
    <fileset dir=quot;./webappquot;
     includes=quot;**/*.htmlquot;
     excludes=quot;**/test-*quot;/>

    <fileset dir=quot;./webappquot;>
     <include name=quot;img/${theme}/*.jpgquot;/>
     <include name=quot;tpl/${lang}/*.phtmlquot;/>
     <exclude name=quot;**/*.bakquot;/>
     <exclude name=quot;**/test/**quot;/>
    </fileset>




Hans Lellelid: Putting Phing to Work for You   16
Fine-tuned Selection
• Selectors provide entirely new dimensions
  for <fileset> file matching criteria.
• Some examples of selectors:
      – Created before/after certain date
      – Greater/less than specified size
      – Type ('file' or 'dir')
      – At specific depth in dir structure
      – Having corresponding file in another dir.



Hans Lellelid: Putting Phing to Work for You        17
Selector examples
 <fileset dir=quot;${htdocs.dir}quot;>
    <includes name=”**/*.html”/>
    <containsregexp
      expression=quot;/prodd+.phpquot;/>
 </fileset>

 <fileset dir=quot;${dist}quot; includes=quot;**quot;>
     <or>
          <present targetdir=quot;${htdocs}quot;/>
          <date datetime=quot;01/01/2007quot;
        when=quot;beforequot;/>
     </or>
 </fileset>

Hans Lellelid: Putting Phing to Work for You   18
Filesystem Transformations
• The <mapper> element adds filesystem
  transformation capabilities to supporting
  tasks (e.g. <copy>, <move>).
• For example:
      – Change all “.php” files to “.html”
      – Remove dirs from filename
      – Change all files to the same filename
• Custom mappers can be defined.


Hans Lellelid: Putting Phing to Work for You    19
Mapper examples
 <copy todir=quot;/tmpquot;>
    <mapper type=quot;globquot; from=quot;*.phpquot;
      to=quot;*.php.bakquot; />
    <fileset dir=quot;./appquot;
      includes=quot;**/*.phpquot; />
 </copy>

 <copy todir=quot;${deploy.dir}quot;>
    <mapper type=quot;regexpquot;
      from=quot;^(.*)-(.*).conf.xmlquot;
      to=quot;1.2.phpquot;/>
    <fileset dir=quot;${config.src.dir}quot;
      includes=quot;**/*.conf.xmlquot; />
 </copy>
Hans Lellelid: Putting Phing to Work for You   20
Data Transformation
• The <filterchain> type adds data
  filtering/transforming capabilities to
  supporting tasks.
• Tasks that support <filterchain> include
  <copy>, <move>, <append> + more
• For example:
      – Strip comments from files
      – Replace values in files (+ regexp)
      – Perform XSLT transformation
• Easily add your own.
Hans Lellelid: Putting Phing to Work for You   21
Filtering examples
    <copy todir=quot;${build}/htdocsquot;>
       <fileset includes=quot;*.htmlquot;/>
       <filterchain>
         <replaceregexp>
            <regexp pattern=quot;rnquot;
              replace=quot;nquot;/>
         </replaceregexp>
         <tidyfilter encoding=quot;utf8quot;>
            <config name=quot;indentquot;
              value=quot;truequot;/>
         </tidyfilter>
       </filterchain>
    </copy>

Hans Lellelid: Putting Phing to Work for You   22
Other Tasks




Hans Lellelid: Putting Phing to Work for You   23
PDO Task
• <pdo> task allows you to execute SQL
  statements from
      – The buildfile itself
      – One or more files
• Transactions can be explicitly demarcated.
• Output can be formatted with a provided or
  custom formatter.




Hans Lellelid: Putting Phing to Work for You     24
User Input
• The <propertyprompt> task provides an
  basic, easy way to set a value from user
  input.
• The <input> task provides a more feature
  rich version.
      – Special handling of yes/no, multiple choice
      – Support for input validation




Hans Lellelid: Putting Phing to Work for You      25
Build API Docs
• The <phpdoc> task provides a wrapper for
  the PhpDocumentor application.
• A few advantages over standalone phpdoc:
      – Use properties from build script
      – Use Phing features like filesets




Hans Lellelid: Putting Phing to Work for You   26
Unit Testing
• Phing has extensive support for PHPUnit
  and SimpleTest unit testing frameworks
• PHPUnit tasks provide support for
      – Batch testing using <fileset> to select all
        the tests you wish to run.
      – Output in XML (Junit-compatible) and Plain
        text.
      – Report generator creates XHTML reports
        using XSLT
      – Code coverage reports (requires Xdebug)

Hans Lellelid: Putting Phing to Work for You      27
Continuous Integration
• Code -> Commit -> Build -> Test ->
  Report
• CI tools watch the repository and provide
  automated building, testing, reporting.
• CruiseControl is probably the most well-
  known.
• Xinc provides CI tool functionality written in
  PHP.
• Xinc is built to use Phing
• CruiseControl also supports Phing
Hans Lellelid: Putting Phing to Work for You   28
Extending Phing




Hans Lellelid: Putting Phing to Work for You   29
Paths for Extension
• Embedding PHP in build file.
• Write your own class to provide any of the
  functionality we have seen:
      – Task
      – Type
      – Selector
      – Filter
      – Mapper
      – Listener (logger)
      – Input Handler
Hans Lellelid: Putting Phing to Work for You   30
Embedding PHP
• The <php> task allows you to evaluate a
  PHP expression, function call, etc. and store
  result in a property.
• The <adhoc> task allows you to embed
  PHP directly. Useful for including setup
  files.
    <adhoc><![CDATA[
         require_once 'propel/Propel.php';
         Propel::init('bookstore-conf.php');

    ]]></adhoc>
Hans Lellelid: Putting Phing to Work for You   31
Writing a Task
• Extend Task
• Add setter methods for any params your
  task accepts.
• Implement public function main()
• Abstract subclasses exist to make life
  easier (e.g. MatchingTask)




Hans Lellelid: Putting Phing to Work for You   32
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);
          }
    }


Hans Lellelid: Putting Phing to Work for You    33
More Complex Task
• Adding support for CDATA text.
• Adding support for Fileset, Filelist,
  Filterchain child elements.
• Supporting nested arbitrary classes ...




Hans Lellelid: Putting Phing to Work for You   34
Data Types
• Classes that can be shared by different
  tasks.
• Extend DataType
• Add setter methods for any params your
  data type accepts/expects.




Hans Lellelid: Putting Phing to Work for You    35
Filters
• Extend BaseFilterReader or
  BaseParamFilterReader and implement
  ChainableReader.
• Implement read() and chain() methods.
      – Read stream and return -1 when stream is
        exhausted.
• If using params, you must initialize them
  locally.
• Use <filterreader classname=”YourClass”>
  in your build file.
Hans Lellelid: Putting Phing to Work for You        36
Selectors
• Extend BaseExtendSelector
• Implement isSelected()
• Use <custom> tag in your build file.




Hans Lellelid: Putting Phing to Work for You      37
Mappers
• Implement FileNameMapper
• Implement main(filename), setFrom(str),
  setTo(str)
• Use <mapper classname=”...”> in your
  build file.




Hans Lellelid: Putting Phing to Work for You     38
Build Listeners
• Implement BuildListener (or
  BuildLogger which expects streams)
• Register on the commandline using
  -listener (or -logger) option.




Hans Lellelid: Putting Phing to Work for You   39
Input Handlers
• Implement InputHandler interface
      – Implement the handleInput(InputRequest)
        method.
• Register on the commandline using
  -listener (or -inputhandler) option.




Hans Lellelid: Putting Phing to Work for You   40
Where next?
• Visit http://phing.info for downloads,
  documentation, and issue tracking.
• Ask questions on the mailing lists.
      – users@phing.tigris.org
      – dev@phing.tigris.org




Hans Lellelid: Putting Phing to Work for You   41

More Related Content

What's hot

Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP Applications
Pavan Kumar N
 
Building and deploying PHP applications with Phing
Building and deploying PHP applications with PhingBuilding and deploying PHP applications with Phing
Building and deploying PHP applications with Phing
Michiel Rook
 
Propel Your PHP Applications
Propel Your PHP ApplicationsPropel Your PHP Applications
Propel Your PHP Applications
hozn
 
Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application Deployment
Shahar Evron
 
Practical PHP Deployment with Jenkins
Practical PHP Deployment with JenkinsPractical PHP Deployment with Jenkins
Practical PHP Deployment with Jenkins
Adam Culp
 
Zend Framework 1.8 workshop
Zend Framework 1.8 workshopZend Framework 1.8 workshop
Zend Framework 1.8 workshop
Nick Belhomme
 
PHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBeneluxPHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBenelux
Nick Belhomme
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016
Clark Everetts
 
Vagrant move over, here is Docker
Vagrant move over, here is DockerVagrant move over, here is Docker
Vagrant move over, here is Docker
Nick Belhomme
 
Zend con 2016 bdd with behat for beginners
Zend con 2016   bdd with behat for beginnersZend con 2016   bdd with behat for beginners
Zend con 2016 bdd with behat for beginners
Adam Englander
 
Modern Perl for the Unfrozen Paleolithic Perl Programmer
Modern Perl for the Unfrozen Paleolithic  Perl ProgrammerModern Perl for the Unfrozen Paleolithic  Perl Programmer
Modern Perl for the Unfrozen Paleolithic Perl Programmer
John Anderson
 
Laravel 4 package development
Laravel 4 package developmentLaravel 4 package development
Laravel 4 package development
Tihomir Opačić
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
之宇 趙
 
New EEA Plone Add-ons
New EEA Plone Add-onsNew EEA Plone Add-ons
New EEA Plone Add-ons
Alin Voinea
 
11 tools for your PHP devops stack
11 tools for your PHP devops stack11 tools for your PHP devops stack
11 tools for your PHP devops stack
Kris Buytaert
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
Nathan Eror
 
Virtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 MayVirtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 May
Puppet
 
Ansible project-deploy (NomadPHP lightning talk)
Ansible project-deploy (NomadPHP lightning talk)Ansible project-deploy (NomadPHP lightning talk)
Ansible project-deploy (NomadPHP lightning talk)
Ramon de la Fuente
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
Haiqi Chen
 
Web Development in Perl
Web Development in PerlWeb Development in Perl
Web Development in Perl
Naveen Gupta
 

What's hot (20)

Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP Applications
 
Building and deploying PHP applications with Phing
Building and deploying PHP applications with PhingBuilding and deploying PHP applications with Phing
Building and deploying PHP applications with Phing
 
Propel Your PHP Applications
Propel Your PHP ApplicationsPropel Your PHP Applications
Propel Your PHP Applications
 
Best Practices in PHP Application Deployment
Best Practices in PHP Application DeploymentBest Practices in PHP Application Deployment
Best Practices in PHP Application Deployment
 
Practical PHP Deployment with Jenkins
Practical PHP Deployment with JenkinsPractical PHP Deployment with Jenkins
Practical PHP Deployment with Jenkins
 
Zend Framework 1.8 workshop
Zend Framework 1.8 workshopZend Framework 1.8 workshop
Zend Framework 1.8 workshop
 
PHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBeneluxPHP Quality Assurance Workshop PHPBenelux
PHP Quality Assurance Workshop PHPBenelux
 
Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016Php Dependency Management with Composer ZendCon 2016
Php Dependency Management with Composer ZendCon 2016
 
Vagrant move over, here is Docker
Vagrant move over, here is DockerVagrant move over, here is Docker
Vagrant move over, here is Docker
 
Zend con 2016 bdd with behat for beginners
Zend con 2016   bdd with behat for beginnersZend con 2016   bdd with behat for beginners
Zend con 2016 bdd with behat for beginners
 
Modern Perl for the Unfrozen Paleolithic Perl Programmer
Modern Perl for the Unfrozen Paleolithic  Perl ProgrammerModern Perl for the Unfrozen Paleolithic  Perl Programmer
Modern Perl for the Unfrozen Paleolithic Perl Programmer
 
Laravel 4 package development
Laravel 4 package developmentLaravel 4 package development
Laravel 4 package development
 
Django Introduction & Tutorial
Django Introduction & TutorialDjango Introduction & Tutorial
Django Introduction & Tutorial
 
New EEA Plone Add-ons
New EEA Plone Add-onsNew EEA Plone Add-ons
New EEA Plone Add-ons
 
11 tools for your PHP devops stack
11 tools for your PHP devops stack11 tools for your PHP devops stack
11 tools for your PHP devops stack
 
Building a Dynamic Website Using Django
Building a Dynamic Website Using DjangoBuilding a Dynamic Website Using Django
Building a Dynamic Website Using Django
 
Virtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 MayVirtual Bolt Workshop - 6 May
Virtual Bolt Workshop - 6 May
 
Ansible project-deploy (NomadPHP lightning talk)
Ansible project-deploy (NomadPHP lightning talk)Ansible project-deploy (NomadPHP lightning talk)
Ansible project-deploy (NomadPHP lightning talk)
 
Django Architecture Introduction
Django Architecture IntroductionDjango Architecture Introduction
Django Architecture Introduction
 
Web Development in Perl
Web Development in PerlWeb Development in Perl
Web Development in Perl
 

Similar to Putting Phing to Work for You

Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projects
Mpho Mphego
 
Development Workflow Tools for Open-Source PHP Libraries
Development Workflow Tools for Open-Source PHP LibrariesDevelopment Workflow Tools for Open-Source PHP Libraries
Development Workflow Tools for Open-Source PHP Libraries
Pantheon
 
Power shell training
Power shell trainingPower shell training
Power shell training
David Brabant
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Bastian Feder
 
PHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iPHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM i
Alan Seiden
 
Installing Hortonworks Hadoop for Windows
Installing Hortonworks Hadoop for WindowsInstalling Hortonworks Hadoop for Windows
Installing Hortonworks Hadoop for Windows
Jonathan Bloom
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-way
Robert Lujo
 
InSpec For DevOpsDays Amsterdam 2017
InSpec For DevOpsDays Amsterdam 2017InSpec For DevOpsDays Amsterdam 2017
InSpec For DevOpsDays Amsterdam 2017
Mandi Walls
 
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Pantheon
 
Ansible new paradigms for orchestration
Ansible new paradigms for orchestrationAnsible new paradigms for orchestration
Ansible new paradigms for orchestration
Paolo Tonin
 
2019 11-bgphp
2019 11-bgphp2019 11-bgphp
2019 11-bgphp
dantleech
 
Basics PHP
Basics PHPBasics PHP
24HOP Introduction to Linux for SQL Server DBAs
24HOP Introduction to Linux for SQL Server DBAs24HOP Introduction to Linux for SQL Server DBAs
24HOP Introduction to Linux for SQL Server DBAs
Kellyn Pot'Vin-Gorman
 
Assignment 1 MapReduce With Hadoop
Assignment 1  MapReduce With HadoopAssignment 1  MapReduce With Hadoop
Assignment 1 MapReduce With Hadoop
Allison Thompson
 
Presentation laravel 5 4
Presentation laravel 5 4Presentation laravel 5 4
Presentation laravel 5 4
Christen Gjølbye Christensen
 
Holy PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood editionHoly PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood edition
Dave Diehl
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
biicode
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
Alan Pinstein
 
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
I Just Want to Run My Code: Waypoint, Nomad, and Other ThingsI Just Want to Run My Code: Waypoint, Nomad, and Other Things
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
Michael Lange
 
Current state-of-php
Current state-of-phpCurrent state-of-php
Current state-of-php
Richard McIntyre
 

Similar to Putting Phing to Work for You (20)

Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projects
 
Development Workflow Tools for Open-Source PHP Libraries
Development Workflow Tools for Open-Source PHP LibrariesDevelopment Workflow Tools for Open-Source PHP Libraries
Development Workflow Tools for Open-Source PHP Libraries
 
Power shell training
Power shell trainingPower shell training
Power shell training
 
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
Advanced Eclipse Workshop (held at IPC2010 -spring edition-)
 
PHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM iPHP Toolkit from Zend and IBM: Open Source on IBM i
PHP Toolkit from Zend and IBM: Open Source on IBM i
 
Installing Hortonworks Hadoop for Windows
Installing Hortonworks Hadoop for WindowsInstalling Hortonworks Hadoop for Windows
Installing Hortonworks Hadoop for Windows
 
Django dev-env-my-way
Django dev-env-my-wayDjango dev-env-my-way
Django dev-env-my-way
 
InSpec For DevOpsDays Amsterdam 2017
InSpec For DevOpsDays Amsterdam 2017InSpec For DevOpsDays Amsterdam 2017
InSpec For DevOpsDays Amsterdam 2017
 
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
Creating a Smooth Development Workflow for High-Quality Modular Open-Source P...
 
Ansible new paradigms for orchestration
Ansible new paradigms for orchestrationAnsible new paradigms for orchestration
Ansible new paradigms for orchestration
 
2019 11-bgphp
2019 11-bgphp2019 11-bgphp
2019 11-bgphp
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
24HOP Introduction to Linux for SQL Server DBAs
24HOP Introduction to Linux for SQL Server DBAs24HOP Introduction to Linux for SQL Server DBAs
24HOP Introduction to Linux for SQL Server DBAs
 
Assignment 1 MapReduce With Hadoop
Assignment 1  MapReduce With HadoopAssignment 1  MapReduce With Hadoop
Assignment 1 MapReduce With Hadoop
 
Presentation laravel 5 4
Presentation laravel 5 4Presentation laravel 5 4
Presentation laravel 5 4
 
Holy PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood editionHoly PowerShell, BATman! - dogfood edition
Holy PowerShell, BATman! - dogfood edition
 
Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014Dependencies Managers in C/C++. Using stdcpp 2014
Dependencies Managers in C/C++. Using stdcpp 2014
 
Lean Php Presentation
Lean Php PresentationLean Php Presentation
Lean Php Presentation
 
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
I Just Want to Run My Code: Waypoint, Nomad, and Other ThingsI Just Want to Run My Code: Waypoint, Nomad, and Other Things
I Just Want to Run My Code: Waypoint, Nomad, and Other Things
 
Current state-of-php
Current state-of-phpCurrent state-of-php
Current state-of-php
 

Recently uploaded

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 

Recently uploaded (20)

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 

Putting Phing to Work for You

  • 1. Putting Phing to Work for You Hans Lellelid International PHP Conference 2007-11-05
  • 2. Introduction • My name is Hans Lellelid • Developer & Manager at Applied Security, Inc. (near Washington DC). • PHP developer and OO evangelist. • I ported Phing to PHP5 in 2004. • I now manage the Phing project with Michiel Rook. Hans Lellelid: Putting Phing to Work for You 2
  • 3. What is it? • PHing Is Not Gnumake • It is a project build tool. • Original PHP4 version by Andreas Aderhold • Written for PHP5 • Based on Apache Ant • Cross-platform (i.e. Windows too) • http://phing.info/ Hans Lellelid: Putting Phing to Work for You 3
  • 4. Workshop Topics: Fundamentals • Phing basics • Creating a first build file • Transforming directories and files • Performing PDO tasks • Gathering user input • Building phpdoc • Running unit tests • Integrating with CI tools Hans Lellelid: Putting Phing to Work for You 4
  • 5. Workshop Topics: Extension • Using PHP code in a build file • Building a simple Task • Writing more complex Task • Creating a shared Type • Custom filters • Custom selectors • Custom logger/listener • Custom input handlers Hans Lellelid: Putting Phing to Work for You 5
  • 6. Getting Started Hans Lellelid: Putting Phing to Work for You 6
  • 7. Install Phing • Install via PEAR – pear channel-discover pear.phing.info – pear install phing/phing • Install “traditional” package – Available on Download page • Install from SVN – svn co http://svn.phing.info/trunk phing Hans Lellelid: Putting Phing to Work for You 7
  • 8. Following Along • Install via PEAR – pear install phing/phing – Install “traditional” package • Available on Download page – Install from SVN • svn co http://svn.phing.info/trunk phing Hans Lellelid: Putting Phing to Work for You 8
  • 9. The phing script • A wrapper shell script for phing.php script. • Sets default logger to use (dependent on system) • Typical usage: phing [target] • Other useful options: – Help (-h) – Specify properties (-Dpropname=value) – List targets (-l) – Get more output (-verbose or -debug) Hans Lellelid: Putting Phing to Work for You 9
  • 10. Buildfiles • Build files are XML • Build files are composed of: – Tasks: a “build-in” piece of code that a specific function. E.g. <mkdir> – Types: data structures that are used commonly by tasks. E.g. <path> – Targets: grouping of Tasks that perform a more general function. E.g. Copy files to a new directory. – A Project: the root node for the build file. Hans Lellelid: Putting Phing to Work for You 10
  • 11. A simple build file <project name=quot;samplequot; default=quot;mainquot;> <property name=quot;verquot; value=quot;1.0.1quot;/> <property file=quot;build.propertiesquot;/> <target name=quot;mainquot;> <mkdir dir=quot;./build/${ver}quot;> <copy todir=quot;./build/${ver}quot;> <fileset dir=quot;.quot; includes=quot;*.txtquot; /> </copy> </target> </project> Hans Lellelid: Putting Phing to Work for You 11
  • 12. Javaisms • Properties – Properties are variables for build scripts. – Like php.ini, but more flexible: • tgz = ${pkg}-${ver}.tgz – Can be set in build script or imported from files. • Dot-path notation for class names: – path.to.Class = path/to/Class.php – Represents directory and class name in a single string. Hans Lellelid: Putting Phing to Work for You 12
  • 13. Control Structures • depends, if, and unless attributes provide control over target execution condition and sequence. • <if> task provides a more familiar (to developers) control structure that can be used within a target. Hans Lellelid: Putting Phing to Work for You 13
  • 14. Reorganize, Transform Hans Lellelid: Putting Phing to Work for You 14
  • 15. Match a bunch of files • The <fileset> type represents an extremely powerful way to select a group of files for processing • Many built-in tasks support <fileset> Hans Lellelid: Putting Phing to Work for You 15
  • 16. Fileset Examples <fileset dir=quot;./webappquot; includes=quot;**/*.htmlquot; excludes=quot;**/test-*quot;/> <fileset dir=quot;./webappquot;> <include name=quot;img/${theme}/*.jpgquot;/> <include name=quot;tpl/${lang}/*.phtmlquot;/> <exclude name=quot;**/*.bakquot;/> <exclude name=quot;**/test/**quot;/> </fileset> Hans Lellelid: Putting Phing to Work for You 16
  • 17. Fine-tuned Selection • Selectors provide entirely new dimensions for <fileset> file matching criteria. • Some examples of selectors: – Created before/after certain date – Greater/less than specified size – Type ('file' or 'dir') – At specific depth in dir structure – Having corresponding file in another dir. Hans Lellelid: Putting Phing to Work for You 17
  • 18. Selector examples <fileset dir=quot;${htdocs.dir}quot;> <includes name=”**/*.html”/> <containsregexp expression=quot;/prodd+.phpquot;/> </fileset> <fileset dir=quot;${dist}quot; includes=quot;**quot;> <or> <present targetdir=quot;${htdocs}quot;/> <date datetime=quot;01/01/2007quot; when=quot;beforequot;/> </or> </fileset> Hans Lellelid: Putting Phing to Work for You 18
  • 19. Filesystem Transformations • The <mapper> element adds filesystem transformation capabilities to supporting tasks (e.g. <copy>, <move>). • For example: – Change all “.php” files to “.html” – Remove dirs from filename – Change all files to the same filename • Custom mappers can be defined. Hans Lellelid: Putting Phing to Work for You 19
  • 20. Mapper examples <copy todir=quot;/tmpquot;> <mapper type=quot;globquot; from=quot;*.phpquot; to=quot;*.php.bakquot; /> <fileset dir=quot;./appquot; includes=quot;**/*.phpquot; /> </copy> <copy todir=quot;${deploy.dir}quot;> <mapper type=quot;regexpquot; from=quot;^(.*)-(.*).conf.xmlquot; to=quot;1.2.phpquot;/> <fileset dir=quot;${config.src.dir}quot; includes=quot;**/*.conf.xmlquot; /> </copy> Hans Lellelid: Putting Phing to Work for You 20
  • 21. Data Transformation • The <filterchain> type adds data filtering/transforming capabilities to supporting tasks. • Tasks that support <filterchain> include <copy>, <move>, <append> + more • For example: – Strip comments from files – Replace values in files (+ regexp) – Perform XSLT transformation • Easily add your own. Hans Lellelid: Putting Phing to Work for You 21
  • 22. Filtering examples <copy todir=quot;${build}/htdocsquot;> <fileset includes=quot;*.htmlquot;/> <filterchain> <replaceregexp> <regexp pattern=quot;rnquot; replace=quot;nquot;/> </replaceregexp> <tidyfilter encoding=quot;utf8quot;> <config name=quot;indentquot; value=quot;truequot;/> </tidyfilter> </filterchain> </copy> Hans Lellelid: Putting Phing to Work for You 22
  • 23. Other Tasks Hans Lellelid: Putting Phing to Work for You 23
  • 24. PDO Task • <pdo> task allows you to execute SQL statements from – The buildfile itself – One or more files • Transactions can be explicitly demarcated. • Output can be formatted with a provided or custom formatter. Hans Lellelid: Putting Phing to Work for You 24
  • 25. User Input • The <propertyprompt> task provides an basic, easy way to set a value from user input. • The <input> task provides a more feature rich version. – Special handling of yes/no, multiple choice – Support for input validation Hans Lellelid: Putting Phing to Work for You 25
  • 26. Build API Docs • The <phpdoc> task provides a wrapper for the PhpDocumentor application. • A few advantages over standalone phpdoc: – Use properties from build script – Use Phing features like filesets Hans Lellelid: Putting Phing to Work for You 26
  • 27. Unit Testing • Phing has extensive support for PHPUnit and SimpleTest unit testing frameworks • PHPUnit tasks provide support for – Batch testing using <fileset> to select all the tests you wish to run. – Output in XML (Junit-compatible) and Plain text. – Report generator creates XHTML reports using XSLT – Code coverage reports (requires Xdebug) Hans Lellelid: Putting Phing to Work for You 27
  • 28. Continuous Integration • Code -> Commit -> Build -> Test -> Report • CI tools watch the repository and provide automated building, testing, reporting. • CruiseControl is probably the most well- known. • Xinc provides CI tool functionality written in PHP. • Xinc is built to use Phing • CruiseControl also supports Phing Hans Lellelid: Putting Phing to Work for You 28
  • 29. Extending Phing Hans Lellelid: Putting Phing to Work for You 29
  • 30. Paths for Extension • Embedding PHP in build file. • Write your own class to provide any of the functionality we have seen: – Task – Type – Selector – Filter – Mapper – Listener (logger) – Input Handler Hans Lellelid: Putting Phing to Work for You 30
  • 31. Embedding PHP • The <php> task allows you to evaluate a PHP expression, function call, etc. and store result in a property. • The <adhoc> task allows you to embed PHP directly. Useful for including setup files. <adhoc><![CDATA[ require_once 'propel/Propel.php'; Propel::init('bookstore-conf.php'); ]]></adhoc> Hans Lellelid: Putting Phing to Work for You 31
  • 32. Writing a Task • Extend Task • Add setter methods for any params your task accepts. • Implement public function main() • Abstract subclasses exist to make life easier (e.g. MatchingTask) Hans Lellelid: Putting Phing to Work for You 32
  • 33. 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); } } Hans Lellelid: Putting Phing to Work for You 33
  • 34. More Complex Task • Adding support for CDATA text. • Adding support for Fileset, Filelist, Filterchain child elements. • Supporting nested arbitrary classes ... Hans Lellelid: Putting Phing to Work for You 34
  • 35. Data Types • Classes that can be shared by different tasks. • Extend DataType • Add setter methods for any params your data type accepts/expects. Hans Lellelid: Putting Phing to Work for You 35
  • 36. Filters • Extend BaseFilterReader or BaseParamFilterReader and implement ChainableReader. • Implement read() and chain() methods. – Read stream and return -1 when stream is exhausted. • If using params, you must initialize them locally. • Use <filterreader classname=”YourClass”> in your build file. Hans Lellelid: Putting Phing to Work for You 36
  • 37. Selectors • Extend BaseExtendSelector • Implement isSelected() • Use <custom> tag in your build file. Hans Lellelid: Putting Phing to Work for You 37
  • 38. Mappers • Implement FileNameMapper • Implement main(filename), setFrom(str), setTo(str) • Use <mapper classname=”...”> in your build file. Hans Lellelid: Putting Phing to Work for You 38
  • 39. Build Listeners • Implement BuildListener (or BuildLogger which expects streams) • Register on the commandline using -listener (or -logger) option. Hans Lellelid: Putting Phing to Work for You 39
  • 40. Input Handlers • Implement InputHandler interface – Implement the handleInput(InputRequest) method. • Register on the commandline using -listener (or -inputhandler) option. Hans Lellelid: Putting Phing to Work for You 40
  • 41. Where next? • Visit http://phing.info for downloads, documentation, and issue tracking. • Ask questions on the mailing lists. – users@phing.tigris.org – dev@phing.tigris.org Hans Lellelid: Putting Phing to Work for You 41