📜 ⬆️ ⬇️

C # -like events for PHP. Reflection, closures ...

The task is to make PHP events a la C # arbitrary object can generate events. Other objects can subscribe to these events directly at the instance of the generating object.

The main difference from what I saw earlier is a strict check of the hook being hung. It checks for the presence of a method, the number of its arguments, etc ...

<?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  1. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  2. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  3. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  4. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  5. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  6. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  7. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  8. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  9. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  10. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  11. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  12. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  13. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  14. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  15. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  16. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  17. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  18. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  19. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  20. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  21. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  22. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  23. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  24. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  25. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  26. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  27. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  28. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  29. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  30. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  31. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  32. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  33. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  34. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  35. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  36. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  37. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  38. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  39. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  40. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  41. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  42. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  43. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  44. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  45. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  46. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  47. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  48. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  49. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  50. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  51. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  52. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  53. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  54. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  55. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  56. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  57. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  58. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  59. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  60. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  61. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  62. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  63. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  64. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  65. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  66. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  67. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  68. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  69. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  70. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  71. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  72. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  73. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  74. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  75. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  76. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  77. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  78. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  79. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  80. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  81. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  82. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  83. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  84. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  85. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  86. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  87. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  88. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  89. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  90. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  91. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  92. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  93. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  94. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  95. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  96. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  97. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  98. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  99. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  100. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  101. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  102. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  103. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  104. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  105. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  106. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
  107. <?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .
<?php abstract class EventClass { /** * * * @var array */ protected $eventRecievers = array(); /** * - * * @var array */ protected $myEvents = array(); /** * * * @param string $prop * @param callback $val */ function __set($prop, $val) { if (in_array($prop, $ this ->myEvents)) $ this ->attachEvent($prop, $val); else throw new Exception( "Property {$prop} is not found or read only" ); } /** * Caller overloader * * @param string $name * @param array $args */ function __call($name, $args) { if (in_array($name, $ this ->myEvents)) $ this ->fireEvent($name, $args); else throw new Exception( "No such event or bad arguments given" ); } /** * * * @param srting $event * @param callback $callback */ protected function attachEvent($ event , $callback) { if (in_array($ event , $ this ->myEvents)) { if (is_array($callback) && is_object($callback[0]) && is_string($callback[1])) { $reflection = new ReflectionClass(get_class($callback[0])); try { $method = $reflection->getMethod($callback[1]); if ($method->getNumberOfParameters() == 1) $ this ->eventRecievers[$ event ][]=$callback; else throw new Exception(get_class($callback[0]). "::{$callback[1]} have more than 1 arguments" ); } catch (Exception $e) { throw new Exception( "Class " .get_class($callback[0]). " doesn't have method {$callback[1]}" ); } } else throw new Exception( "Wrong callback format" ); } else throw new Exception(__CLASS__. " has no event {$event}" ); } /** * "" * * @param string $event * @param EventArgument $argument */ protected function fireEvent($ event , $argument) { if (in_array($ event , $ this ->myEvents)) { if (is_array($ this ->eventRecievers[$ event ]) && count($ this ->eventRecievers[$ event ])) foreach ($ this ->eventRecievers[$ event ] as $callback) call_user_func_array($callback, array( new EventArgument($ this , $argument))); } else throw new Exception(__CLASS__. " have no event {$event}" ); } } class CanGenerateEvents extends EventClass { protected $myEvents = array( 'onSomething' , 'onSomethingElse' ); // Code goes here function makeSomething() { // Doing something useful... $ this ->onSomething( "someText" ); } } class WantSomething { function recieveHere(EventArgument $arg) { echo $arg->argument; } } $w = new WantSomething(); $g = new CanGenerateEvents(); $g->onSomething = array($w, 'recieveHere' ); ?> * This source code was highlighted with Source Code Highlighter .

When the ReflectionMethod :: getClosure () method appears in PHP (which, apparently, will not go into 5.3 although it was previously present in the documentation), you can stop using call_user_func_array and use closures, replacing line 63 with the following code
$ this ->eventRecievers[$ event ][]=$method->getClosure();

* This source code was highlighted with Source Code Highlighter .

And the line in the fireEvent function to the following ...
$callback( new EventArgument($ this , $argument));

* This source code was highlighted with Source Code Highlighter .


UPD : Forgotten EventArgument Class
class EventArgument {

public $caller = null ;

public $argument = null ;

function __construct($caller, $argument = null )
{
$ this ->caller = $caller;
$ this ->argument = $argument;
}

}


* This source code was highlighted with Source Code Highlighter .


')

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


All Articles