How to make your own springloops in PHP

Springloops is a nice code management service recently came into focus. It helps you to manage the code base of your application, monitor the commit and deploy the final version easily to another server. So if you are wondering how to build such a system and how it actually works, this article is for you.

Please note that I am neither way affiliated with Springloops nor any of it’s contacts. This article expresses completely my own opinion.

The primary obstacles of making such a service are
1. Managing the subversion repositories and users
2. Interaction with subversion repositories (Not same as option 1)
3. Payment gateways
4. Code browser
5. User friendliness
6. Scaling

Among these options, 4 and 6 are out of the scope of this article. There are thousands of article explaining those topics to you. So I am not going to talk about them. There are excellent libraries available to manage many popular payment gateways. Just google it and you are done. And about user friendliness and design, you can hire a consultant who’s specializing on this subject and get it done.

1. Managing the subversion repositories and users
In springloops or any other subversion hosting service, you need to do some basic shell scripting which is required for adding the subversion repositories dynamically and to add users in it. There are some excellent articles how you can do it with apache2. To avoid any traffic related issue, best practice will be hosting these repositories in another server, and using htaccess – just point your user’s svn URL to the exact url. Check out the following urls to find out how to host subversion repositories with apache. Linux should be the first choice, heh heh.

Reference:
1. Setting up subversion with apache in Ubuntu gutsy gibon
2. Setting up subversion with apache2
3. Setting up subversion with apache2 and DAV in debian
4. Host your open source projects in ubuntu in 3 easy steps

All you have to do is writing shell script to automate these steps and restart the apache2 demon once an user register his/her project with your service. You are done

2. Interaction with subversion repositories (Not same as option 1)
Now this is quite a challenging part and many of you are lost how to achieve this kind of functionality for such services. For PHP developers, you know there are an excellent repository of extensions named PECL and also repository of libraries name PEAR. In PECL there is an excellent extension which is cent percent appropriate for this work. Yup, I am talking about “SVN” extension. You have to install this extension to use it with your PHP code. Once you are done with installing it, now you got the complete power to interact with the subversion repositories hosted by your users. This extension is very rich and provides all the functionalities you need to interact. For details please point your browser to the appropriate section in PHP manual.

Reference
1. Installing PECL SVN extension for PHP in Ubuntu Gutsy Gibon
2. PECL svn package
3. SVN extension documentation

4. Code Browser
Another challenging part of the total setup. If you cannot provide excellent code browser which will clearly demonstrate the changes in code from different revisions, figure out the log and the notes made during each commit and finally, make note on it to show to your fellow team members.

Using svn_diff, svn_ls and svn_log you can clearly find out the difference of a file in two different revisions, the file and directory structure of the repository and the log of each commit. So basically once you got the file and directory structure of your repository for a revision, you can just traverse through it and display as a nice report using your PHP code. And when user will ask you to display the difference, you will find the difference using svn_diff which returns the difference as standard diff format. Now using regular expression (or whatever way) you will mark the lines which was changed and just display them highlighting using different colors to your user, as a nice report. And You can also browse the log of any revision using svn_log and show it to your user.

And last but not the least, you can create tags, branch and whatever addition by maintaining a local shadow working copy of your repository. Only the thing that you cannot do (or still I am thinking how-to) is merging, heh heh.

And when it comes about deploy the latest code base to your server, you can do it using svn_update where the path is the working directory in your server.

Reference
1. Standard Diff Format
2. svn_diff
3. svn_log
4. svn_ls
5. svn_add
6. svn_update
7. svn_checkout

Basically this is how a service like Springloops is built. I hope, you’ve enjoyed this article as much as I did to write it, heh heh.