473,804 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Version number and Build # generator for PHP

dlite922
1,584 Recognized Expert Top Contributor
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 5708
dlite922
1,584 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
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 Recognized Expert Moderator Expert
@dlite922
I’d use the subversion (or whatever you use) revision number as build number.
Nov 5 '09 #4
dlite922
1,584 Recognized Expert Top Contributor
@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 Recognized Expert Moderator Expert
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
8710
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 want to programmatically get the version string that I see in the registry underneath the HKLM\SOFTWARE\Microsoft\VisualStudio key, such as "7.0" or "7.1" (for .NET 2002 or .NET 2003, respectively). My registry contains both 7.0 and 7.1 keys,...
10
2912
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 have is that the first loop I get a sequence of random numbers untuil I get a match, BUT then on the following loops I get the SAME random(?) sequence. I am using rand(). I do not want to get too fancy with the random number generator, but is there...
4
2405
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
7383
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 have utilised the following random number source code http://www.agner.org/random/ What I have found is that there is a problem with seeding. The code generates a seed based on time(0). I have found that I need to increment
1
1308
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 procedures. There is no changes in the existing tables that contains data. What is the best way to update this DB? I had planned to use the SQL script generator. Is there a problem with this?
5
3606
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 increment...it's AssemblyInfo.vb looks like this
8
1802
by: John | last post by:
Hi How can I change the product version number that is returned by Application.ProductVersion? Thanks Regards
6
3693
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 reason for this? 65535 would make sense!? Is there a work around, patch, etc?? Regards
1
2195
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 make multiple changes to my code during the day and then build again that same day the version number will not change. I have the attribute set to "1.0.*" and the default .NET formula of versioning is fine if only it would update whenever I make...
0
9596
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10356
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10103
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7644
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5536
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4316
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.