473,387 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Version number and Build # generator for PHP

dlite922
1,584 Expert 1GB
Hey guys,

I've built applications and I've always wanted my own version and build number that's more like bigger applications.

Requirements:
1. The version should be manual (besides obviously there is no way for the app itself to know if it got a new feature vs a fix, I'd like to be the one starting new versions or sub-versions)

2. Build number should be automatic based on the most recently modified file.

My Idea:

1. Get all the project files and find the most recent file update time stamp

2. Calculate the build number based on given version number to get a value that's from hundreds to thousands long (I don't want to reach tens of thousands preferably)

I'm having trouble with the math for 2. Primarily how I can make the build look like it was reset when I change version number, say when I change the version value from 2.0.1 to 2.0.2 or 2.1.0

Maybe I should just store the date the version was changed when change the version value itself and calculate the number of hours from that TS (time stamp) and the last modified file TS.

I'm open to any other ideas.


Peace out,


Dan
Nov 5 '09 #1
5 5653
dlite922
1,584 Expert 1GB
current test code I'm playing around with:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. <?php
  4.  
  5.  
  6.  
  7. /**
  8. * Gets entire file system recursively or non-recursivly in a given directory
  9. * @param mixed $directory
  10. * @param mixed $recursive
  11. * @return array
  12. */
  13. function getAllFiles($directory, $recursive = true) 
  14. {
  15.     $result = array();
  16.  
  17.     if(is_dir($directory))
  18.     {
  19.          $handle =  opendir($directory);
  20.          while ($datei = readdir($handle))
  21.          {
  22.               if (($datei != '.') && ($datei != '..')) {
  23.                    $file = $directory.$datei;
  24.                    if (is_dir($file)) {
  25.                         if ($recursive) {
  26.                              $result = array_merge($result, getAllFiles($file.'/'));
  27.                         }
  28.                    } 
  29.                    else {
  30.                         $result[] = $file;
  31.                    }
  32.               }
  33.          }
  34.          closedir($handle);
  35.     }
  36.  
  37.     return $result;
  38. }
  39.  
  40. /**
  41. * Gets the most recent file TS in a directory
  42. * @uses getAllFiles()
  43. * @param mixed $directory
  44. * @param mixed $recursive
  45. * @return integer
  46. */
  47. function getHighestFileTimestamp($directory, $recursive = true) 
  48. {
  49.      $allFiles = getAllFiles($directory, $recursive);
  50.  
  51.      $highestKnown = 0;
  52.      foreach ($allFiles as $val) 
  53.      {
  54.           $currentValue = filemtime($val);
  55.           if ($currentValue > $highestKnown) $highestKnown = $currentValue;
  56.      }
  57.  
  58.      return $highestKnown;
  59. }
  60.  
  61.  
  62. /**
  63. * Makes a build number based on newest file in the project and project version
  64. * @uses getHighestFileTimestamp()
  65. * @return integer
  66. */
  67. function makeBuildNumber($version,$dir)
  68. {
  69.     $newestFileTS = getHighestFileTimestamp($dir,true);
  70.  
  71.     // TS is too large, subtract and version number + padding in thousands to get a build number
  72.     $verMx = intval(preg_replace('/[^0-9]/','',$version)) + 1257455304 * 1000;
  73.  
  74.     return ($newestFileTS - $verMx); 
  75. }
  76.  
  77. echo makeBuildNumber("2.0.1","/path/to/project/");
  78.  
  79.  
see if you can get a better formula to work for line number 74 above.




Dan
Nov 5 '09 #2
dlite922
1,584 Expert 1GB
My best idea so far:

Build number is based on the 3rd version value. So when you change from 2.0.1 to 2.0.5 the build number grows as well. But will seem to have reset when you change to 2.0.1

psuedocode:

Expand|Select|Wrap|Line Numbers
  1.  
  2. $version = "2.0.2"; 
  3. $multiplier = end(explode(".",$version)) * $othervalues; 
  4.  
  5.  
ya? no? got a better idea?



Dan
Nov 5 '09 #3
Dormilich
8,658 Expert Mod 8TB
@dlite922
I’d use the subversion (or whatever you use) revision number as build number.
Nov 5 '09 #4
dlite922
1,584 Expert 1GB
@Dormilich
How would I display that on the main page of the app though? Every time I check anything into SVN i'd have to change the version number by hand, which is daily at the beginning phases of the project.

It would be cool if SVN would update a text file everytime you checked something in and I could read the file content.



Dan
Nov 6 '09 #5
Dormilich
8,658 Expert Mod 8TB
the latest revision number should be somewhere in .svn.
Nov 7 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Whitney Kew | last post by:
Hi, Is there a programmatic way to get the "general" or "overall" version of a currently running instance of the Visual Studio .NET compiler? What I mean by "general" or "overall" version is, I...
10
by: Sonoman | last post by:
Hi all: I am trying to write a simple program that simulates asking several persons their birth day and it counts how many persons are asked until two have the same birth day. The problem that I...
4
by: Wahoo | last post by:
Another question,my teacher gave me a code for generate a random number from 1 - range, but I can't made it work, where is the problem? Thanks!!
3
by: Joe | last post by:
Hi, I have been working on some code that requires a high use of random numbers within. Mostly I either have to either: 1) flip a coin i.e. 0 or 1, or 2) generate a double between 0 and 1. I...
1
by: Djakobsson | last post by:
Hi, I have a SQL server DB for a document handeling system. For the new version of the system the database have been updated with some new tables, new stored procedures and updated stored...
5
by: mekim | last post by:
Hello....I am trying to System.Reflection.Assembly.GetExecutingAssembly ().GetName ().Version.ToString () ; to display the version of the app...but it remains static and therefore does not...
8
by: John | last post by:
Hi How can I change the product version number that is returned by Application.ProductVersion? Thanks Regards
6
by: Gavin Sullivan | last post by:
I've been using the date (in YMMDD) format for the build number in the AssemblyVersion attribute. However, it appears that numbers 65534 are invalid!! Bit of a bummer for 2007!!! Is there a...
1
by: ewingate | last post by:
I cannot seem to get the version number of my VB app to increment properly in VS2005. When I build the app each day the "build" number increments with no problem as does the version number but if I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.