We have a product which is being slightly customized for each client. The exact customization is unpredictable - we assume that any point in the code can become needing change. However, we want to keep one code base, as 90+% of the code will be identical, so we don't have to merge every update or new feature to each client separately.

How can this be done?

The project is written in PHP with the Yii framework.

Basically, we would like something like this: Every client will have a folder with a 'mirror' of the code. That 'mirror' will include only those classes customized for the client. Than, at runtime, the clients identity will be known, and every mention of classes name will be resolved to the generic version of the class - if no client specific version exists for this client, or to the client customized version of that class - if such a version does exist.

I'll appreciate comments about the general design question.
Any comments on the above solution.
Are there other ways to achieve what I want to achieve?
Maybe some code generation tool for generating the client specific version from the current main code?

And also there is the implementation question. How can this be implemented in PHP and Yii?

I thought first to use PHPs __autoload. However, it will anyway choose only one version of the class. And this is a problem, because we'll need to choose the client specific version every time except of one: when defining the client specific version of the class, we will extend the general purpose version of that class. So classes version can not be resolved at the loading time, both need to be loaded, and the client specific will be used every time except of one.

Thank you

Recommended Answers

All 2 Replies

In such a situation I'd define my classes/methods for my generic functionality. For every class I'd sub-class it to a client class. The default client sub-class will contain nothing new, and all calls will go through the client class.

class FileAccess {}
class ClientFileAccess extends FileAccess {} // <-- Always use this one, change as needed

In such a situation I'd define my classes/methods for my generic functionality. For every class I'd sub-class it to a client class. The default client sub-class will contain nothing new, and all calls will go through the client class.

class FileAccess {}
class ClientFileAccess extends FileAccess {} // <-- Always use this one, change as needed

Thank you, an interesting idea. We're going to have multiple clients, but it can be used combined with __autoload to select the correct client class from current clients directory.

However, currently, it will demand a huge refactoring, as we already have lot of code, and adding the multi-client support now.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.