fruffl icon

understand signals

fruffl | 01/26/13 08:12:55 AM UTC | 0 ⭐ | 271 👁️ | Never ⏰ | []
PHP |

1.67 KB

|

None

|

0 👍

/

0 👎

    class bar extends \ILLI\Net\Message {}
    class foo extends \ILLI\Net\Message {}
    class bob extends \ILLI\Net\Message {}
    
    $bar = new bar;
    $foo = new foo;
    $bob = new bob;
 
/*
array(7) {
  ["scheme"]=>
  string(3) "tcp"
  ["host"]=>
  string(9) "localhost"
  ["port"]=>
  NULL
  ["username"]=>
  NULL
  ["password"]=>
  NULL
  ["path"]=>
  NULL
  ["body"]=>
  array(0) {
  }
}
*/
    
        $foo->registerSignal('username', bar::T_SIGNAL_EMIT_EVENT_INIT, 500, [$bar, 'propertySet']);    // foo::$username -> bar::$username
        $foo->registerSignal('propertySet', bar::T_SIGNAL_EMIT_EVENT_INIT, 500, [$bob, 'propertySet']); // foo::*-> bob::*
       
        $foo->propertySet('scheme', 'http');
        $foo->propertySet('host',   'localfrost');
        $foo->propertySet('username',   'fruffl');
        $foo->propertySet('password',   '12345');
    
    var_dump($foo->to('array'));
    var_dump($bar->to('array'));
    var_dump($bob->to('array'));
 
 
/*
array(7) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  string(10) "localfrost"
  ["port"]=>
  NULL
  ["username"]=>
  string(6) "fruffl"
  ["password"]=>
  string(5) "12345"
  ["path"]=>
  NULL
  ["body"]=>
  array(0) {
  }
}
array(7) {
  ["scheme"]=>
  string(3) "tcp"
  ["host"]=>
  string(9) "localhost"
  ["port"]=>
  NULL
  ["username"]=>
  string(6) "fruffl"
  ["password"]=>
  NULL
  ["path"]=>
  NULL
  ["body"]=>
  array(0) {
  }
}
array(7) {
  ["scheme"]=>
  string(4) "http"
  ["host"]=>
  string(10) "localfrost"
  ["port"]=>
  NULL
  ["username"]=>
  string(6) "fruffl"
  ["password"]=>
  string(5) "12345"
  ["path"]=>
  NULL
  ["body"]=>
  array(0) {
  }
}

Comments