oop - PHP runtime class modification -
So I want to be able to add / remove class management at runtime. Before you tell me that there is a terrible practice in OOP, maybe, but I really do not care. The reason for this is that I want to be able to do this because I want to consider the application as very modular, so some plugins can expand some base classes and add the main app without any way.
For example, say I have the following category:
class user {secure $ id; Protected $ name; Protected $ password; Secure $ PostPaperPage; }
And say, some plugin adds the possibility of changing your visibility settings to users, adding $ visual assets to orbit in the class. The square will be created:
class user {secure $ id; Protected $ name; Protected $ password; Secure $ PostPaperPage; Protected $ visible; }
This can be achieved by __get and __set, but the most common implementation runtime is to obtain and set the generated properties, and it is for each of the pseudo gates and the setters The problem of code will be added to the property, as well as to use __set in my opinion is not a no-no.
The other thing I thought was to store user settings separately, as in another array of $ UserVisiblitySettings [userid] things are not in the form of oh, as I want.
The next idea was to create a helper class, something like this:
class UserHelper {public function SetVisiblity ($ user_object, value); }
Then, I can use __get and __set to implement "friends" methods / classes, but it seems that it is a lot of laughter. If I want to go that way, just overload __Col, __Jat and __set I'm not even sure that this is a good OOP practice, and it also looks ugly.
Last thought I had some work so that I can use the Evil (Dynamically) classes in sequence (this is the only legitimate use of Evil that I can come together). In fact, get a definition of a class from a file, find a few simple brackets to find the class opening and closing the bracket and sending it to the eval.
The use of the Runkit is out of the question because it is outdated and I should not force the user to install some detail.
When I look at my thoughts, the simplest and less CPU looks intensive _call overload and a way to register methods
Please do not consider any such " "It is appreciated.
extension can do this ( runkit_method_add ()
, etc.) P>
However this is an experimental extension and you are already targeting on your feet ... <
You have other options:
- New areas and
__ get ()
and__ call ()
- Use sub-clinging and factory patterns (
class plugin base implementation Expands on
and factory institutePlugin
ins tidBase Implementation
). The Zend plugin loader does something like that.
This is the solution with at least overhead, but it is limited to a cloud to a plugin. - Add hooks and use delegation (strategy pattern) (
$ this-> Plugin-> onFoo ()
). .
Comments
Post a Comment