I know that behaviors can be customized by overriding the behaviors method, which will return an array with the configurations of each attached behavior. I want to have, besides this method, another, suppose, behaviors2, the format of which was indentive, which would do exactly the same thing - keep the data on the behaviors.
The challenge is this: collect behavioral information from both methods.
Investigating the component code, I realized that the collection of information from the behaviors method is responsible for ensuring Behaviors, which in turn is launched almost at the beginning of every other method that is somehow related to behaviors. The first thought is to redefine it:
public function ensureBehaviors() { parent::ensureBehaviors(); $this->ensureBehaviors2();//для красоты можно использовать static:: }
Where am I to ensureBehaviors2 just attach all other behaviors.
Difficulty: the method that is responsible for attaching the behavior to the component, attachBehaviorInternal is private, and the attachBehavior method calls to ensureBehaviors. Total: recursion.
Output: add property to class:
private $_ensureBehaviorsLock = false;
And write like this:
public function ensureBehaviors() { if ($this->_ensureBehaviorsLock) { return; } $this->_ensureBehaviorsLock = true; parent::ensureBehaviors(); $this->ensureBehaviors2(); }
And then I wondered .. It seems to be working, but it seems like a big and heavy crutch. But it works. I would like to know your opinion and possible solutions to this problem.
Here is my sketch to make it clear what I want: http://pastebin.com/1pVaVvmq
A few reservations:
The functionality of the behaviors method should remain the same. I know that it would be possible to use behaviors2 and behaviors3, and in behaviors just to merge the results of these methods. Or in behaviors to add functionality which took an array which in it, and with others. But then it would be impossible to use inheritance.
Ps who have the privilege to edit questions, format, please, humanly. I am writing from the phone, there is no such possibility.
Задача такова: собирать информацию о поведениях из обоих методов.
It is possible in more detail, why such distortions? Do you need to keep the state of behavior before a certain action and after? - romeo