SlideShare une entreprise Scribd logo
1  sur  39
Télécharger pour lire hors ligne
Phing: Building in PHP
                   Hans Lellelid
   International PHP Conference
                     2007-11-06
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: Phing: Building in PHP           2
This Talk
•   Brief Overview & “Justification”
•   Basic Usage
•   Packaginig & Deployment
•   Development Cycle
•   Extending Phing
•   Slides available at
    http://phing.info/presentations/



Hans Lellelid: Phing: Building in PHP               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)
•   It seems to have caught on.
      – Propel, Prado, Symfony, Agavi, Xinc (to
        name a few)

Hans Lellelid: Phing: Building in PHP             4
Why do I need a build tool
                  for PHP?



Hans Lellelid: Phing: Building in PHP   5
Building != Compiling
• In this context, “building” is really any non-
  development task that supports your
  application.
• This could include
      – Configuring
      – Packaging
      – Uploading
      – Testing
      – Etc.

Hans Lellelid: Phing: Building in PHP        6
PHP apps > web pages
• PHP is no longer a simple web scripting
  language.
• We are using PHP to do all sorts of things
  on the CLI:
      – Run unit tests (PHPUnit, SimpleTest)
      – Build API docs (PhpDocumentor)
      – Install and Package (PEAR)




Hans Lellelid: Phing: Building in PHP          7
Web apps get deployed
• PHP web applications do eventually get
  deployed.
• Deployment has a whole lot of implications:
      – Permissions
      – Environment setup
      – App Configuration




Hans Lellelid: Phing: Building in PHP     8
Phing can help.
• Anything you can do with a shell script you
  can do with Phing.
• And a whole lot more ...
      – Transform directories and files.
      – Configure your application
      – Prepare files for deployment
      – Run unit tests
      – Do other useful stuff – like SVN commits or
        db initialization.

Hans Lellelid: Phing: Building in PHP            9
But why Phing specifically?
• Other choices do exist: Ant, Rake, NAnt
• With Phing you only need PHP.
• A PHP tool for PHP apps just makes a lot of
  sense:
      – Familiar territory, common environment
      – You can embed PHP directly in your build
        scripts.
      – You can integrate your own application code
        into Phing extensions.
      – Cross-pltform and small footprint.
Hans Lellelid: Phing: Building in PHP            10
How do I start using it?




Hans Lellelid: Phing: Building in PHP     11
The Basics
• Phing provides a simple shell script
  (“phing”) that launches the Phing PHP app.
• You create build files in XML
• Build file organization:
      – Tasks: a “build-in” piece of code that
        performs a specific function. E.g. <mkdir>
      – 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: Phing: Building in PHP              12
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: Phing: Building in PHP          13
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
      – Anwers question “How to represent both
        directory and class name in a single string?”
Hans Lellelid: Phing: Building in PHP                 14
Packaging and Deployment




Hans Lellelid: Phing: Building in PHP   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: Phing: Building in PHP      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: Phing: Building in PHP        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: Phing: Building in PHP               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: Phing: Building in PHP        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: Phing: Building in PHP           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: Phing: Building in PHP      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: Phing: Building in PHP        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: Phing: Building in PHP       23
Packaging Tools
• The <tar> and <zip> tasks allow you to
  bundle up your moved directories. (Of
  course, they support <fileset> too.)
• <pearpkg> (and <pearpkg2>) tasks
  allow you to create PEAR packages using
  Phing.




Hans Lellelid: Phing: Building in PHP        24
Deployment Tools
• Deployment means different things for
  different people.
• Phing includes some tasks to “put” stuff
  places:
      – <svn*> suite of tasks
      – <scp>
• Database statement execution provided by
  <pdo> and <creole> tasks.



Hans Lellelid: Phing: Building in PHP        25
Development Cycle




Hans Lellelid: Phing: Building in PHP    26
Building for Developers
• Not all build tasks are for deployment.
• Some build activities are specifically for
  developer consumption:
      – Checking validity or cleaning documents
      – Building API documentation
      – Running unit tests
• A more “traditional” build will likely also
  play a part in developer build functionality.


Hans Lellelid: Phing: Building in PHP             27
Validating
• Phing includes several contributed lint tasks
  for checking the validity of source code:
      – <jslint> uses external jsl utility.
      – <xmllint> uses built-in DOM support and
        validates with a schema file.
      – <phplint> users “php -l”
• The <tidy> task also provides ability to
  perform validation and cleanup on HTML
  documents.


Hans Lellelid: Phing: Building in PHP                28
PHP API Docs
• Phing includes support for
  PhpDocumentor using the <phpdoc>
  task.
 <phpdoc title=quot;API Documentationquot;
      destdir=quot;apidocsquot; sourcecode=quot;noquot;
      output=quot;HTML:Smarty:PHPquot;>
    <fileset dir=quot;./classesquot;>
      <include name=quot;**/*.phpquot; />
    </fileset>
 </phpdoc>



Hans Lellelid: Phing: Building in PHP          29
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: Phing: Building in PHP             30
PHPUnit Example
    <phpunit2 haltonerror=quot;truequot;
         haltonfailure=quot;falsequot;
         printsummary=quot;truequot;>
       <batchtest>
         <fileset dir=quot;${tests.dir}quot;>
            <include name=quot;**/*Test.phpquot;/>
         </fileset>
       </batchtest>
    </phpunit2>




Hans Lellelid: Phing: Building in PHP        31
Continuous Integration
• Code -> Commit -> Build -> Test ->
  Report
• CI tools watch the repository and provide
  automated building, testing, reporting.
• CruiseControl has a Phing builder.
• Xinc provides CI tool functionality written in
  PHP.
• Xinc is built to use Phing


Hans Lellelid: Phing: Building in PHP        32
Xinc Config Example
 <projects>
     <project name=quot;Project Namequot; interval=quot;10quot;>
         <modificationsets>
             <svn directory=quot;/var/projects/testquot;/>
         </modificationsets>
         <builder type=quot;phingquot;
             buildfile=quot;/var/projects/test/build.xmlquot;
             target=quot;buildquot;/>
         <publishers>
             <email to=quot;myemail@example.comquot;
                    publishonfailure=quot;truequot;/>
         </publishers>
     </project>
 </projects>


Hans Lellelid: Phing: Building in PHP              33
Extending Phing




Hans Lellelid: Phing: Building in PHP       34
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)
      – ... and more.
Hans Lellelid: Phing: Building in PHP       35
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: Phing: Building in PHP          36
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: Phing: Building in PHP           37
Phing IRL
• Phing is being used by many organizations
  and open-source projects.
• In the real world, Phing is used ...
      – as an interactive CLI application
        configuration or installation script,
      – to upgrade production webservers,
      – to manage product release builds,
      – as a quick way to reorganize a directory
        tree,
      – & much, much more.
Hans Lellelid: Phing: Building in PHP               38
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: Phing: Building in PHP         39

Contenu connexe

Tendances

200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드
200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드
200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드NAVER Engineering
 
객체지향 개념 (쫌 아는체 하기)
객체지향 개념 (쫌 아는체 하기)객체지향 개념 (쫌 아는체 하기)
객체지향 개념 (쫌 아는체 하기)Seung-June Lee
 
Kubernetes + Python = ❤ - Cloud Native Prague
Kubernetes + Python = ❤ - Cloud Native PragueKubernetes + Python = ❤ - Cloud Native Prague
Kubernetes + Python = ❤ - Cloud Native PragueHenning Jacobs
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate TutorialRam132
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golangBo-Yi Wu
 
NDC 2016 김태현 - 글로벌 동시 퀵 서버패치 이렇게 구축 했다
NDC 2016 김태현 - 글로벌 동시 퀵 서버패치 이렇게 구축 했다NDC 2016 김태현 - 글로벌 동시 퀵 서버패치 이렇게 구축 했다
NDC 2016 김태현 - 글로벌 동시 퀵 서버패치 이렇게 구축 했다Taehyun Kim
 
知らないと損するアプリ開発におけるStateMachineの活用法(15分版)
知らないと損するアプリ開発におけるStateMachineの活用法(15分版)知らないと損するアプリ開発におけるStateMachineの活用法(15分版)
知らないと損するアプリ開発におけるStateMachineの活用法(15分版)Ken Morishita
 
Windows 10 Nt Heap Exploitation (English version)
Windows 10 Nt Heap Exploitation (English version)Windows 10 Nt Heap Exploitation (English version)
Windows 10 Nt Heap Exploitation (English version)Angel Boy
 
Resource Handling in Spring MVC
Resource Handling in Spring MVCResource Handling in Spring MVC
Resource Handling in Spring MVCArawn Park
 
Why you should care about Go (Golang)
Why you should care about Go (Golang)Why you should care about Go (Golang)
Why you should care about Go (Golang)Aaron Schlesinger
 
Windows Internals: fuzzing, hijacking and weaponizing kernel objects
Windows Internals: fuzzing, hijacking and weaponizing kernel objectsWindows Internals: fuzzing, hijacking and weaponizing kernel objects
Windows Internals: fuzzing, hijacking and weaponizing kernel objectsNullbyte Security Conference
 
[개인 프로젝트] 쿠버네티스를 이용한 개발환경 자동화 구축시스템 - 프로토타입
[개인 프로젝트] 쿠버네티스를 이용한 개발환경 자동화 구축시스템 - 프로토타입[개인 프로젝트] 쿠버네티스를 이용한 개발환경 자동화 구축시스템 - 프로토타입
[개인 프로젝트] 쿠버네티스를 이용한 개발환경 자동화 구축시스템 - 프로토타입choi sungwook
 
HCL Commerce Developer V9.1.11 Installation
HCL Commerce Developer V9.1.11 InstallationHCL Commerce Developer V9.1.11 Installation
HCL Commerce Developer V9.1.11 InstallationFrancisBooth2
 
Docker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting TechniquesDocker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting TechniquesSreenivas Makam
 
Linux reversing study_basic_1
Linux reversing study_basic_1Linux reversing study_basic_1
Linux reversing study_basic_1Jinkyoung Kim
 
Drupal Development
Drupal DevelopmentDrupal Development
Drupal DevelopmentJeff Eaton
 
2018 종합선물세트 for 취준생
2018 종합선물세트 for 취준생2018 종합선물세트 for 취준생
2018 종합선물세트 for 취준생Yu Yongwoo
 

Tendances (20)

200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드
200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드
200819 NAVER TECH CONCERT 03_화려한 코루틴이 내 앱을 감싸네! 코루틴으로 작성해보는 깔끔한 비동기 코드
 
객체지향 개념 (쫌 아는체 하기)
객체지향 개념 (쫌 아는체 하기)객체지향 개념 (쫌 아는체 하기)
객체지향 개념 (쫌 아는체 하기)
 
Kubernetes + Python = ❤ - Cloud Native Prague
Kubernetes + Python = ❤ - Cloud Native PragueKubernetes + Python = ❤ - Cloud Native Prague
Kubernetes + Python = ❤ - Cloud Native Prague
 
Hibernate Tutorial
Hibernate TutorialHibernate Tutorial
Hibernate Tutorial
 
Write microservice in golang
Write microservice in golangWrite microservice in golang
Write microservice in golang
 
NDC 2016 김태현 - 글로벌 동시 퀵 서버패치 이렇게 구축 했다
NDC 2016 김태현 - 글로벌 동시 퀵 서버패치 이렇게 구축 했다NDC 2016 김태현 - 글로벌 동시 퀵 서버패치 이렇게 구축 했다
NDC 2016 김태현 - 글로벌 동시 퀵 서버패치 이렇게 구축 했다
 
知らないと損するアプリ開発におけるStateMachineの活用法(15分版)
知らないと損するアプリ開発におけるStateMachineの活用法(15分版)知らないと損するアプリ開発におけるStateMachineの活用法(15分版)
知らないと損するアプリ開発におけるStateMachineの活用法(15分版)
 
Windows 10 Nt Heap Exploitation (English version)
Windows 10 Nt Heap Exploitation (English version)Windows 10 Nt Heap Exploitation (English version)
Windows 10 Nt Heap Exploitation (English version)
 
Resource Handling in Spring MVC
Resource Handling in Spring MVCResource Handling in Spring MVC
Resource Handling in Spring MVC
 
Why you should care about Go (Golang)
Why you should care about Go (Golang)Why you should care about Go (Golang)
Why you should care about Go (Golang)
 
Concurrency With Go
Concurrency With GoConcurrency With Go
Concurrency With Go
 
Windows Internals: fuzzing, hijacking and weaponizing kernel objects
Windows Internals: fuzzing, hijacking and weaponizing kernel objectsWindows Internals: fuzzing, hijacking and weaponizing kernel objects
Windows Internals: fuzzing, hijacking and weaponizing kernel objects
 
Intro to Git and GitHub
Intro to Git and GitHubIntro to Git and GitHub
Intro to Git and GitHub
 
[개인 프로젝트] 쿠버네티스를 이용한 개발환경 자동화 구축시스템 - 프로토타입
[개인 프로젝트] 쿠버네티스를 이용한 개발환경 자동화 구축시스템 - 프로토타입[개인 프로젝트] 쿠버네티스를 이용한 개발환경 자동화 구축시스템 - 프로토타입
[개인 프로젝트] 쿠버네티스를 이용한 개발환경 자동화 구축시스템 - 프로토타입
 
HCL Commerce Developer V9.1.11 Installation
HCL Commerce Developer V9.1.11 InstallationHCL Commerce Developer V9.1.11 Installation
HCL Commerce Developer V9.1.11 Installation
 
Docker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting TechniquesDocker Networking - Common Issues and Troubleshooting Techniques
Docker Networking - Common Issues and Troubleshooting Techniques
 
Linux reversing study_basic_1
Linux reversing study_basic_1Linux reversing study_basic_1
Linux reversing study_basic_1
 
Drupal Development
Drupal DevelopmentDrupal Development
Drupal Development
 
2018 종합선물세트 for 취준생
2018 종합선물세트 for 취준생2018 종합선물세트 for 취준생
2018 종합선물세트 for 취준생
 
Final field semantics
Final field semanticsFinal field semantics
Final field semantics
 

Similaire à Phing: Building with PHP

Putting Phing to Work for You
Putting Phing to Work for YouPutting Phing to Work for You
Putting Phing to Work for Youhozn
 
Propel Your PHP Applications
Propel Your PHP ApplicationsPropel Your PHP Applications
Propel Your PHP Applicationshozn
 
Introduction to PHP (SDPHP)
Introduction to PHP   (SDPHP)Introduction to PHP   (SDPHP)
Introduction to PHP (SDPHP)Eric Johnson
 
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 LibrariesPantheon
 
2019 11-bgphp
2019 11-bgphp2019 11-bgphp
2019 11-bgphpdantleech
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP ApplicationsPavan Kumar N
 
Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)Stefan Koopmanschap
 
PHP and PDFLib
PHP and PDFLibPHP and PDFLib
PHP and PDFLibAdam Culp
 
Building and Deploying PHP apps with Phing
Building and Deploying PHP apps with PhingBuilding and Deploying PHP apps with Phing
Building and Deploying PHP apps with PhingMichiel Rook
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHPEric Johnson
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projectsMpho Mphego
 
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
 
Sanjip Shah: Internationalizing and Localizing WordPress Themes
Sanjip Shah: Internationalizing and Localizing  WordPress ThemesSanjip Shah: Internationalizing and Localizing  WordPress Themes
Sanjip Shah: Internationalizing and Localizing WordPress Themeswpnepal
 

Similaire à Phing: Building with PHP (20)

Putting Phing to Work for You
Putting Phing to Work for YouPutting Phing to Work for You
Putting Phing to Work for You
 
Propel Your PHP Applications
Propel Your PHP ApplicationsPropel Your PHP Applications
Propel Your PHP Applications
 
Current state-of-php
Current state-of-phpCurrent state-of-php
Current state-of-php
 
Introduction to PHP (SDPHP)
Introduction to PHP   (SDPHP)Introduction to PHP   (SDPHP)
Introduction to PHP (SDPHP)
 
Phing
PhingPhing
Phing
 
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
 
2019 11-bgphp
2019 11-bgphp2019 11-bgphp
2019 11-bgphp
 
Build Automation of PHP Applications
Build Automation of PHP ApplicationsBuild Automation of PHP Applications
Build Automation of PHP Applications
 
Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)Introduction into PHP5 (Jeroen van Sluijs)
Introduction into PHP5 (Jeroen van Sluijs)
 
PHP and PDFLib
PHP and PDFLibPHP and PDFLib
PHP and PDFLib
 
Building and Deploying PHP apps with Phing
Building and Deploying PHP apps with PhingBuilding and Deploying PHP apps with Phing
Building and Deploying PHP apps with Phing
 
Building Custom PHP Extensions
Building Custom PHP ExtensionsBuilding Custom PHP Extensions
Building Custom PHP Extensions
 
Introduction to PHP - SDPHP
Introduction to PHP - SDPHPIntroduction to PHP - SDPHP
Introduction to PHP - SDPHP
 
Makefile for python projects
Makefile for python projectsMakefile for python projects
Makefile for python projects
 
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-)
 
Improving qa on php projects
Improving qa on php projectsImproving qa on php projects
Improving qa on php projects
 
Basics PHP
Basics PHPBasics PHP
Basics PHP
 
php basics
php basicsphp basics
php basics
 
Sanjip Shah: Internationalizing and Localizing WordPress Themes
Sanjip Shah: Internationalizing and Localizing  WordPress ThemesSanjip Shah: Internationalizing and Localizing  WordPress Themes
Sanjip Shah: Internationalizing and Localizing WordPress Themes
 
Php ppt
Php pptPhp ppt
Php ppt
 

Dernier

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessPixlogix Infotech
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 

Dernier (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 

Phing: Building with PHP

  • 1. Phing: Building in PHP Hans Lellelid International PHP Conference 2007-11-06
  • 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: Phing: Building in PHP 2
  • 3. This Talk • Brief Overview & “Justification” • Basic Usage • Packaginig & Deployment • Development Cycle • Extending Phing • Slides available at http://phing.info/presentations/ Hans Lellelid: Phing: Building in PHP 3
  • 4. 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) • It seems to have caught on. – Propel, Prado, Symfony, Agavi, Xinc (to name a few) Hans Lellelid: Phing: Building in PHP 4
  • 5. Why do I need a build tool for PHP? Hans Lellelid: Phing: Building in PHP 5
  • 6. Building != Compiling • In this context, “building” is really any non- development task that supports your application. • This could include – Configuring – Packaging – Uploading – Testing – Etc. Hans Lellelid: Phing: Building in PHP 6
  • 7. PHP apps > web pages • PHP is no longer a simple web scripting language. • We are using PHP to do all sorts of things on the CLI: – Run unit tests (PHPUnit, SimpleTest) – Build API docs (PhpDocumentor) – Install and Package (PEAR) Hans Lellelid: Phing: Building in PHP 7
  • 8. Web apps get deployed • PHP web applications do eventually get deployed. • Deployment has a whole lot of implications: – Permissions – Environment setup – App Configuration Hans Lellelid: Phing: Building in PHP 8
  • 9. Phing can help. • Anything you can do with a shell script you can do with Phing. • And a whole lot more ... – Transform directories and files. – Configure your application – Prepare files for deployment – Run unit tests – Do other useful stuff – like SVN commits or db initialization. Hans Lellelid: Phing: Building in PHP 9
  • 10. But why Phing specifically? • Other choices do exist: Ant, Rake, NAnt • With Phing you only need PHP. • A PHP tool for PHP apps just makes a lot of sense: – Familiar territory, common environment – You can embed PHP directly in your build scripts. – You can integrate your own application code into Phing extensions. – Cross-pltform and small footprint. Hans Lellelid: Phing: Building in PHP 10
  • 11. How do I start using it? Hans Lellelid: Phing: Building in PHP 11
  • 12. The Basics • Phing provides a simple shell script (“phing”) that launches the Phing PHP app. • You create build files in XML • Build file organization: – Tasks: a “build-in” piece of code that performs a specific function. E.g. <mkdir> – 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: Phing: Building in PHP 12
  • 13. 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: Phing: Building in PHP 13
  • 14. 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 – Anwers question “How to represent both directory and class name in a single string?” Hans Lellelid: Phing: Building in PHP 14
  • 15. Packaging and Deployment Hans Lellelid: Phing: Building in PHP 15
  • 16. 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: Phing: Building in PHP 16
  • 17. 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: Phing: Building in PHP 17
  • 18. 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: Phing: Building in PHP 18
  • 19. 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: Phing: Building in PHP 19
  • 20. 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: Phing: Building in PHP 20
  • 21. 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: Phing: Building in PHP 21
  • 22. 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: Phing: Building in PHP 22
  • 23. 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: Phing: Building in PHP 23
  • 24. Packaging Tools • The <tar> and <zip> tasks allow you to bundle up your moved directories. (Of course, they support <fileset> too.) • <pearpkg> (and <pearpkg2>) tasks allow you to create PEAR packages using Phing. Hans Lellelid: Phing: Building in PHP 24
  • 25. Deployment Tools • Deployment means different things for different people. • Phing includes some tasks to “put” stuff places: – <svn*> suite of tasks – <scp> • Database statement execution provided by <pdo> and <creole> tasks. Hans Lellelid: Phing: Building in PHP 25
  • 26. Development Cycle Hans Lellelid: Phing: Building in PHP 26
  • 27. Building for Developers • Not all build tasks are for deployment. • Some build activities are specifically for developer consumption: – Checking validity or cleaning documents – Building API documentation – Running unit tests • A more “traditional” build will likely also play a part in developer build functionality. Hans Lellelid: Phing: Building in PHP 27
  • 28. Validating • Phing includes several contributed lint tasks for checking the validity of source code: – <jslint> uses external jsl utility. – <xmllint> uses built-in DOM support and validates with a schema file. – <phplint> users “php -l” • The <tidy> task also provides ability to perform validation and cleanup on HTML documents. Hans Lellelid: Phing: Building in PHP 28
  • 29. PHP API Docs • Phing includes support for PhpDocumentor using the <phpdoc> task. <phpdoc title=quot;API Documentationquot; destdir=quot;apidocsquot; sourcecode=quot;noquot; output=quot;HTML:Smarty:PHPquot;> <fileset dir=quot;./classesquot;> <include name=quot;**/*.phpquot; /> </fileset> </phpdoc> Hans Lellelid: Phing: Building in PHP 29
  • 30. 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: Phing: Building in PHP 30
  • 31. PHPUnit Example <phpunit2 haltonerror=quot;truequot; haltonfailure=quot;falsequot; printsummary=quot;truequot;> <batchtest> <fileset dir=quot;${tests.dir}quot;> <include name=quot;**/*Test.phpquot;/> </fileset> </batchtest> </phpunit2> Hans Lellelid: Phing: Building in PHP 31
  • 32. Continuous Integration • Code -> Commit -> Build -> Test -> Report • CI tools watch the repository and provide automated building, testing, reporting. • CruiseControl has a Phing builder. • Xinc provides CI tool functionality written in PHP. • Xinc is built to use Phing Hans Lellelid: Phing: Building in PHP 32
  • 33. Xinc Config Example <projects> <project name=quot;Project Namequot; interval=quot;10quot;> <modificationsets> <svn directory=quot;/var/projects/testquot;/> </modificationsets> <builder type=quot;phingquot; buildfile=quot;/var/projects/test/build.xmlquot; target=quot;buildquot;/> <publishers> <email to=quot;myemail@example.comquot; publishonfailure=quot;truequot;/> </publishers> </project> </projects> Hans Lellelid: Phing: Building in PHP 33
  • 34. Extending Phing Hans Lellelid: Phing: Building in PHP 34
  • 35. 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) – ... and more. Hans Lellelid: Phing: Building in PHP 35
  • 36. 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: Phing: Building in PHP 36
  • 37. 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: Phing: Building in PHP 37
  • 38. Phing IRL • Phing is being used by many organizations and open-source projects. • In the real world, Phing is used ... – as an interactive CLI application configuration or installation script, – to upgrade production webservers, – to manage product release builds, – as a quick way to reorganize a directory tree, – & much, much more. Hans Lellelid: Phing: Building in PHP 38
  • 39. 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: Phing: Building in PHP 39