Putting "Phings" together - how to automate your life
Upcoming SlideShare
Loading in...5

Putting "Phings" together - how to automate your life






Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
Post Comment
Edit your comment
  • (PH)ing (I)s (N)ot (G)NU make; it's a PHP project build system or build tool based on Apache Ant. You can do anything with it that you could do with a traditional build system like GNU make, and its use of simple XML build files and extensible PHP "task" classes make it an easy-to-use and highly flexible build framework.Phing is a PHP tool that allows us to automate processes -- typically, it's used for building and deploying software. It's similar in functionality to the Apache Ant project and uses XML files to execute tasks that are defined as PHP classes. Best of all, it has a tonne of cool tasks already baked in! These include tasty things such as unit testing, file system operations, code sniffer integration, SQL execution, shell commands, 3rd party services and version control integration.Have you heard about Phing before?Is there java developers?
  • If you find yourself writing custom scripts to handle the packaging, deploying, or testing of your applications, then we suggest looking at Phing. Phing comes packaged with numerous out-of-the-box operation modules (tasks), and an easy-to-use OO model to extend or add your own custom tasks.
  • Phing uses XML buildfiles that contain a description of the things to do. The buildfile is structured into targets that contain the actual commands to perform (e.g. commands to copy a file, delete a directory, perform a DB query, etc.). So, to use Phing, you would first write your buildfile and then you would run phing, specifying the target in your buildfile that you want to execute. % phing -f mybuildfile.xml mytarget By default Phing will look for a buildfile named build.xml (so you don't have to specify the buildfile name unless it is not build.xml) and if no target is specified Phing will try to execute the default target, as specified in the tag.
  • Project – Root node of a build file containing one or more targets.Target – A group of tasks that run as an entity.Task – Custom piece of code to perform a specific function.Properties – Properties (Variables) help to customize execution.Built-In Properties – e.g. host.os, line.separator, phing.version, php.version, …
  • All Phing really needs at the project level is a build file.  Normally, you will want to name this file  build.xml .  This is the default file name that Phing will look for, so in most cases, this is your best bet.  I am kind of psychotic about what files are in the project root, so normally I but the file in a directory called build, but you can absolutely keep it in the root if you wish. From there it is all about customizing the content of the build file to work with your project.
  • The outermost tag is the project tag and all of the other tags like targets will be contained within it.  I set my project tags up with a name and description, mostly so I can remember better what I am working on later and to be able to see what the project is supposed to do when I run phing -l.  The other property in this tag are “default” and “basedir”.  Default is the name of the target (which I will explain shortly) that phing will run if none is provided, and basedir is the base directory of the project, relative to the location of the build file.  Since my build file is in the “build” directory, my basedir is one level up.
  • Target is a group of tasks that run as an entity.
  • Task is a custom piece of code to perform a specific function.We will cover some of the latter.
  • Properties (Variables) help to customize execution.
  • Mappers are applied to the filenames. Type - Type of the mapper.From - The pattern the filename is to be matched to. The exact meaning is dependent on the implementation of the mapper.To - The pattern according to which the filename is to be changed to. Here, the usage is dependent on the implementation of the mapper, too.
  • The FlattenMapper removes the directories from a filename and solely returns the filename. This code will copy all files in the fileset to /tmp. All files will be in the target directory.
  • The GlobMapper works like the copy command in DOSThis will change the extension of all files matching the pattern *.php to .php.bak.
  • The RegexpMapper changes filenames according to a pattern defined by a regular expression. This is the most powerful mapper and you should be able to use it for every possible application.
  • Filters are a subset of Phing data types which provide for the transformation of file contents during the operation of another task. For example, a filter might replace tokens in a file as part of a copy task. Filters have to be defined within a context to work.
  • The TidyFilter allows you to use the PHP tidy extension to clean up and repair HTML documents.
  • The ExpandProperties simply replaces property names with their property values.what we dofirst we define paths to the template file, the new file and the file containing the propertiesthen we copy the template to the new file and say phing to replace all properties with their valueTemplate fileA template file can be anything and all properties will be replaced by their value
  • Phing was designed to be flexible and easily extensible. Phing's existing core and optional tasks do provide a great deal of flexibility in processing files, performing database actions, and even getting user feedback during a build process. In some cases, however, the existing tasks just won't suffice and because of Phing's open, modular architecture adding exactly the functionality you need is often quite trivial.

Putting "Phings" together - how to automate your life Putting "Phings" together - how to automate your life Presentation Transcript

  • Putting "Phings" together - how to automate your life
  • Table of contents • • • • • • • • About me Introduction to Phing Basics What Phing can do for you Phing and Drupal How Phing is helping us/Demo Conclusions Q/A
  • About me • Boyan Borisov • Team Leader @ Propeople • boyanb@propeople.dk • @boyan_borisov • Skype: boian.borisov • http://linkedin.com/in/ boyanborisov
  • What is Phing? • (PH)ing (I)s (N)ot (G)NU make • Project build tool • Platform-independent: works on UNIX, Windows, Mac OSX • Based on Apache Ant • Provides a simple OO model for extending • Uses XML build files • No required external dependencies • Open source – written on PHP5
  • Why? • Improves work quality • Eliminates repeatable tasks • Minimises errors • Saves time and money • More code, less configuration • Forces universal way of automation • Tons of built-in tasks and features
  • Let’s install it • Pear install $> pear channel-discover pear.phing.info $> pear install [--alldeps] phing/phing • Non pear install $> apt-get install pear $> pear channel-discover pear.phing.info $> pear install [--alldeps] phing/phing
  • Using Phing • • • • • • • • phing -v phing -f mybuildfile.xml phing -f mybuildfile.xml mytarget phing phing mytarget phing -l phing -debug phing -Dproperty.name=value
  • Basics • • • • • • Build.xml Project Target Task Properties Built-In Properties
  • Build.xml <project name="example" default="hello"> <target name="hello" > <echo>Hello world!</echo> </target> <target name= "bye"> <echo>Bye!</echo> </target> </project>
  • Project <project name="example" default="world” description="Phing example"> <target name="world" description="Say world" depends="hello"> <echo>world!</echo> </target> <target name="hello" description="Say hello"> <echo>Hello</echo> </target> </project>
  • Target <project name="example" default="world” description="Phing example"> <target name="world" description="Say world" depends="hello"> <echo>world!</echo> </target> <target name="hello" description="Say hello"> <echo>Hello</echo> </target> </project>
  • Task <project name="example" default="world” description="Phing example"> <target name="world" description="Say world" depends="hello"> <echo>world!</echo> </target> <target name="hello" description="Say hello"> <echo>Hello</echo> </target> </project>
  • Properties • Built-in properties • Custom properties • Declaration – Inline – External file – Input
  • Properties <project name="Example" default="default"> <property name="var1" value="value1"/> <property file="build.properties"/> <input propertyName="var3">Enter var3</input> <target name="default"> <echo>Variables: ${var1}, ${var2} and ${var3}</echo> </target> </project>
  • Build properties file Drupal.site_name = “Test site” Drupal.profile = “standard” #comment Project.env = “dev” Project.git.url = “httpp://…”
  • Tasks • Core: – Copy, Delete, Echo, Exec, Move, Foreach, PhpEvalTask and more • Optional: – FtpDeploy, GitPush, PDOSQL Exec, Scp, Zip, and more
  • FileSet <fileset dir="./application" includes="**" /> <fileset dir="./application" id="files"> <include name="**/*.php"/> <exclude name="**/*Test.php"/> </fileset> <fileset refid="files" />
  • FileSet selectors <fileset dir="${dist}"> <and> <filename name="**/*.log"/> <date datetime="01/01/2013" when="before"/> </and> </fileset>
  • Mappers • Mappers are like filters for files and directories – Flatten – Glob – RegExp <mapper type="mappername" from="frompattern" to="topattern" />
  • FlattenMapper <copy todir="/tmp"> <mapper type="flatten" /> <fileset refid="someid" /> </copy>
  • GlobMapper <copy todir="/tmp"> <mapper type="glob" from="*.php" to="*.php.bak"/> <fileset refid="someid"/> </copy>
  • RegexpMapper <mapper type="regexp" from="^(.*).conf.xml" to="1.php"/>
  • Filters • Filters Transform data/file contents within a task – Tidy – ExpandProperty – StripPhpComments – ReplaceRegexp – StripWhitespace
  • TidyFilter <filterchain> <tidyfilter encoding="utf8"> <config name="indent" value="true" /> <config name="output-xhtml" value="true" /> </tidyfilter> </filterchain>
  • ExpandProperty <target name="config"> <property name="config.template" value="config.php-dist" /> <property name="config.file" value="config.php" /> <property file="config.properties" override="true" /> <copy file="${config.template}" tofile="${config.file}"> <filterchain> <expandproperties /> </filterchain> </copy> </target>
  • Extending Phing • • • • • • Tasks Types Selectors Filters Mappers Loggers ...
  • Sample task SampleTask extends Task { private $var; public function setVar($v) { $this->var = $v; } public function main() { print('value: ' . $this->var); } }
  • Hey, is this a DrupalCamp or what?!
  • Phing Drush Task https://drupal.org/project/phingdrushtask drush site-install --yes --locale=uk --site-name =${sitename} expert <drush command="site-install" assume="yes""> <option name="locale">uk</option> <option name="site-name" value="${sitename}"/> <param>expert</param> </drush>
  • How Phing is helping us • Company is growing – from 30 to 75+ people in about a year • Bigger projects – from 300 to 2000+ hours • Bigger teams – from 2 to 10+ team members • Many new employees • Many developers, many ways to manage a project
  • Thank you, Phing!
  • What’s next • http://phing.info • Adopt Phing for your needs • Create new tasks • Contribute • Jenkins • https://github.com/relo ad/phing-drupaltemplate
  • Questions?