Preface: I am working in PHP (Abandon hope all ye who enter here).
Background: There exists a large set of global functions in PHP, a number of which are miscellaneous system calls, like sleep (and others). Now, I use
sleep (and others) in a bunch of different scripts I run in a bunch of different places, and I have found I need sleep to call
pcntl_signal_dispatch as soon as the
sleep finishes- but possibly not in all my scripts.
A Generalization: I need to make global function do more than it currently does, hopefully without disrupting my current ecosystem too much.
My Solution: I figure I could create a wrapper class that executes the correct
Singleton: I could make a singleton "System" class that wraps the global functions. Hell, I could even make the wrappers static methods. The downside is that there would be a lot of boilerplate checking to see which version I would need to execute, either a vanilla function call or one with extra stuff.
Global variable: I could make a generic "System" class that wraps the global functions. I could then extend the System class with different classes that override the wrapper functions. I create a global
System variable within each script, dependent upon how I need the functions to behave. All my scripts have access to that global variable. The downside is I would have to make sure the global variable is declared, is never overwritten, and uses the proper
Something else: I could create a
SysControl class with a static
System variable and static wrappers of the
System's wrappers of the functions, and then swap out which
SysControl class references. The downside is that I feel I am going overboard.
Are there any more options I should consider? Which of these methods is the best, and why? What pitfalls should I look for going forward?
EDIT: I ended up using the Something else solution.