Hi there!
Recently I had a problem with my services:
- I had 2 separate websites that use a kind of token authorization system
- I had a lot of code that was used in both web services
Of course the only smart thing to do when you have a sender and receiver on both ends is that its performed by the exactly same code as follows:
Sender service:
$token = new Token();
echo $token->generateToken();
Receiver service:
$token = new $token($_GET['token']);
echo $token->isValid();
So what we need to achieve here is pretty arbitrary to the point I'm making. Just a simple sending and receiving of some token that has to be validated on the other side.
The problem is that those two sites are entirely different projects that share some common logic. The mistake people make is to copy the common code between the services in the hope that no one will change it, or when changed, someone will change it on both ends. There is a lot of room for mistakes here.
Luckily we have svn:externals to help us with the whole process. What we want to achieve can be summarized in a few simple steps:
1) Isolate the common code in another repository to protect it from unwanted changes. Let's say we will name the repository CORE.
2) Remove the obsolete code from all code base in which i was present.
3) Add a external checkout to our library folder:
>svn propget svn:externals library
core https://svn.example.com/core
What this will do is when someone updates the library folder, svn will know to get the external items from the common code repository.
In this example you will have to commit your code to the external repository, but an easier way is that you create a directory for the code in one repository and add a directory externally to another repository that requires the code.
Hope you will take something from this simple example,
see you next time ;)
Peter
No comments:
Post a Comment