📜 ⬆️ ⬇️

Learn PHP Communicate

About communication.


All people are independent (or almost)! All people communicate!
Everyone knows the rite of communication between people, its causes. To get the information we need about her, you can ask, and not necessarily a specific person. To ask, so to speak, in the air, if someone knows the answer, he will answer.

About JavaScript and Qt.


I love javascript. I like his flexibility. I like his event system.
Although I do not consider myself a C ++ programmer, I like Qt. His (her?) Signal / slot system.

Why did I remember the language and the library? Because they can communicate, it makes them stand out.

About the idea.


All modules are independent (or almost)! All modules communicate!
Somehow I thought: why would teach another one of my favorite language? PHP
I imagined a system where all its components are independent of each other, moreover, they do not know about each other.
They communicate.
- Does anyone have the value of the variable xxx?
- Yes, of course, hold.
- Can someone give me the last 10 comments?
- No problem.

')

On the implementation.


Looking for some information on this issue, I found an attempt to implement Qt in PHP - QPHP, but this is not what I wanted. There is also the implementation of signals / slots in the ezComponents framework, but this is also not the case. That's why I started designing the core of the future library.
In my imagination, she looked like this:
image
As can be seen on the scheme, all components of the system depend only on the kernel, since all messages / events go through it.
What I decided to include in the kernel:
In my opinion this is quite enough.

Implementation code wait soon.

About use


In typical usage, I see something like the following:
  1. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  2. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  3. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  4. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  5. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  6. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  7. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  8. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  9. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  10. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  11. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  12. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  13. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  14. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  15. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  16. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  17. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  18. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  19. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  20. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  21. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  22. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  23. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  24. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  25. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  26. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;
  27. <?php class module_test_1 extends module { public function __construct ( ) { // , , $this -> emit ( new signal ( 'config.getvar' , array ( 'var' => 'varname' , 'callback' => array ( $this , 'write' ) ) ) ; $this -> emit ( new signal ( 'module_test_1.run' ) ) ; } public function write ( $val ) { echo "varname = $val " ; } } class module_test_2 extends module { public function __construct ( ) { $this -> connect ( new slot ( 'module_test_1.run' , array ( $this , 'write' ) ) ) ; } public function write ( ) { echo "module_test_1 -> run" ; } } $test_2 = new module_test_2 ( ) ; $test_1 = new module_test_1 ( ) ;


______________________
The text was prepared in the Habr Editor from © SoftCoder.ru

Source: https://habr.com/ru/post/61692/


All Articles