check behavior method in WebSocketServer.php
Closed this issue · 7 comments
I think you should write
if ($command && $this->hasMethod('command'.ucfirst($command))) {
instead of
if ($command && method_exists($this, 'command' . ucfirst($command))) {
in WebSocketServer.php:200 because it does not check behaviors
Server component is some kind of controller.
Adding commands handlers in behaviors makes its logic not so clear.
Do you really need behaviors for processing users commands? What behavior can be reused?
Also
You can use traits, if you want make reusable command handlers.
Or extend my component and override methods as you wish)
Thanks for your proposal!
I'm just going to split web socket server via several parts. Each of them stores commands and event handlers. For example, i want to add periodic timers with different ticks. I cant (or dont know how) to attach events through traits, but without events traits are good choice. I have no idea how to do it beatiful without behaviors.
So i would create separate parts as behaviors and attach them to web socket server.
Each behavior stores commands and event handlers.
why don't you want to use inheritance?
So you will have one parent Server class that extends base WebSocketServer and realize your common commands handlers.
Maybe it should be abstract for your issue.
I really can't understand your trouble with architecture without behavior. Can you send an example of your classes via email with description what do you want to exclude into behaviors?
Maybe I'll be able to help you if you want.
Also you can override my method onMessage and use hasMethod() instead of method_exists() in your own class.
I really don't have an opportunity to update this repository now. Earliest at weekend.
I have overriden your method. Don't be angry. Just suggestion :)
I'm not angry:) Sorry if my comments looks so! I always glad to help someone.