designing solution to dynamically load class

Posted by dot on Programmers See other posts from Programmers or by dot
Published on 2013-11-12T21:02:09Z Indexed on 2013/11/12 22:02 UTC
Read the original article Hit count: 170

Filed under:
|

Background Information

I have a web app that allows end users to connect to ssh-enabled devices and manipulate them. Right now, i only support one version of firmware. The logic is something like this:

  1. user clicks on a button to run some command on device.
  2. web application looks up the class name containing the correct ssh interface for the device, using the device's model name. (because the number of hardware models is so small, i have a list that's hardcoded in my web app)
  3. web app creates a new ssh object using the class loaded in step 2.
  4. ssh command is run and session closed.
  5. command results displayed on web page.

This all works fine. Now the end user wants me to be able to support multiple versions of firmware. But the catch is, they don't want to have to document the firmware version anywhere becuase the amount of overhead this will create in maintaining the system database. In other words, I can't look up the firmware version based on the device.

The good news is that it sounds like at most, I'll have to support two different versions of firmware per device.

One option is to name the the classes like this:

deviceX.1.php
deviceX.2.php
deviceY.1.php
deviceY.2.php

where "X" and "Y" represent the model names, and 1 and 2 represent the firmware versions. When a user runs a command, I will first try it with one of the class files, if it fails, i can try with the second. I think always try the newer version of firmware first... so let's say in the above example, I would load deviceX.2.php before deviceX.1.php.

This will work, but it's not very efficient. But I can't think of another way around this.

Any suggestions?

© Programmers or respective owner

Related posts about php

Related posts about class