I have several classes handling data validation and API requests preparation for every external API function. An example of those:
class PostProductFunction($user_params)
{
validate()
{
//...
}
invoke($user_params)
{
$this->validate();
//doing request...
}
}
I have an APIAccount class to represent one of several API accounts. It handles auth and it has a method
function invokeFunction($functionClassName, $user_params)
{
// check if the class $functionClassName exists and creates an instance of it
// ... $obj = new $functionClassName();
$obj->invoke($user_params);
}
So, the function class doesn't know about auth stuff and the APIAccount class doesn't know about user data structure.
The question is how to handle this $functionClassName inside the APIAccount class. Do I need to store all names of function classes somewhere? Do I need some kind of enum class? I don't want to simply take a string and then check whether the class with this name exists because the programmer passing this string can easily mistype, and in general he needs documentation to know the proper function name. I want that he somehow see all available options with something like enum. Do you have any ideas how to better implement it?
Aucun commentaire:
Enregistrer un commentaire