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

Like this? Share it with your network

Share

Putting "Phings" together - how to automate your life

on

  • 264 views

 

Statistics

Views

Total Views
264
Views on SlideShare
264
Embed Views
0

Actions

Likes
0
Downloads
1
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

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.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
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 Presentation Transcript

  • 1. Putting "Phings" together - how to automate your life
  • 2. 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
  • 3. About me • Boyan Borisov • Team Leader @ Propeople • boyanb@propeople.dk • @boyan_borisov • Skype: boian.borisov • http://linkedin.com/in/ boyanborisov
  • 4. 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
  • 5. 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
  • 6. 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
  • 7. Using Phing • • • • • • • • phing -v phing -f mybuildfile.xml phing -f mybuildfile.xml mytarget phing phing mytarget phing -l phing -debug phing -Dproperty.name=value
  • 8. Basics • • • • • • Build.xml Project Target Task Properties Built-In Properties
  • 9. Build.xml <project name="example" default="hello"> <target name="hello" > <echo>Hello world!</echo> </target> <target name= "bye"> <echo>Bye!</echo> </target> </project>
  • 10. 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>
  • 11. 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>
  • 12. 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>
  • 13. Properties • Built-in properties • Custom properties • Declaration – Inline – External file – Input
  • 14. 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>
  • 15. Build properties file Drupal.site_name = “Test site” Drupal.profile = “standard” #comment Project.env = “dev” Project.git.url = “httpp://…”
  • 16. Tasks • Core: – Copy, Delete, Echo, Exec, Move, Foreach, PhpEvalTask and more • Optional: – FtpDeploy, GitPush, PDOSQL Exec, Scp, Zip, and more
  • 17. FileSet <fileset dir="./application" includes="**" /> <fileset dir="./application" id="files"> <include name="**/*.php"/> <exclude name="**/*Test.php"/> </fileset> <fileset refid="files" />
  • 18. FileSet selectors <fileset dir="${dist}"> <and> <filename name="**/*.log"/> <date datetime="01/01/2013" when="before"/> </and> </fileset>
  • 19. Mappers • Mappers are like filters for files and directories – Flatten – Glob – RegExp <mapper type="mappername" from="frompattern" to="topattern" />
  • 20. FlattenMapper <copy todir="/tmp"> <mapper type="flatten" /> <fileset refid="someid" /> </copy>
  • 21. GlobMapper <copy todir="/tmp"> <mapper type="glob" from="*.php" to="*.php.bak"/> <fileset refid="someid"/> </copy>
  • 22. RegexpMapper <mapper type="regexp" from="^(.*).conf.xml" to="1.php"/>
  • 23. Filters • Filters Transform data/file contents within a task – Tidy – ExpandProperty – StripPhpComments – ReplaceRegexp – StripWhitespace
  • 24. TidyFilter <filterchain> <tidyfilter encoding="utf8"> <config name="indent" value="true" /> <config name="output-xhtml" value="true" /> </tidyfilter> </filterchain>
  • 25. 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>
  • 26. Extending Phing • • • • • • Tasks Types Selectors Filters Mappers Loggers ...
  • 27. Sample task SampleTask extends Task { private $var; public function setVar($v) { $this->var = $v; } public function main() { print('value: ' . $this->var); } }
  • 28. Hey, is this a DrupalCamp or what?!
  • 29. 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>
  • 30. 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
  • 31. Thank you, Phing!
  • 32. What’s next • http://phing.info • Adopt Phing for your needs • Create new tasks • Contribute • Jenkins • https://github.com/relo ad/phing-drupaltemplate
  • 33. Questions?