示例#1
0
 /**
  * @covers ::create
  * @covers Nora\Core\Event\EventObserverClosure::__construct
  * @covers Nora\Core\Event\EventObserverClosure::notify
  */
 public function testEventObserverClosure()
 {
     $observer = EventObserver::create(function (EventIF $event) {
         $this->assertTrue($event->match('test'));
         $this->assertTrue($event->match('test1'));
     });
     $ev = Event::create('test');
     $ev->addTag('test1');
     $observer->notify($ev);
 }
 function __construct()
 {
     parent::__construct();
 }
示例#3
0
 /**
  * Return observer configuration for farm
  *
  * @param string $farmid
  * @param EventObserver $observer
  * @return DataForm
  */
 private static function GetFarmNotificationsConfig($farmid, $observer)
 {
     $DB = Core::GetDBInstance(NULL, true);
     // Reconfigure farm settings if changes made
     $farms = $DB->GetAll("SELECT farms.id as fid FROM farms INNER JOIN client_settings ON client_settings.clientid = farms.clientid WHERE client_settings.`key` = 'reconfigure_event_daemon' AND client_settings.`value` = '1'");
     if (count($farms) > 0) {
         Logger::getLogger(__CLASS__)->debug("Found " . count($farms) . " with new settings. Cleaning cache.");
         foreach ($farms as $cfarmid) {
             Logger::getLogger(__CLASS__)->info("Cache for farm {$cfarmid["fid"]} cleaned.");
             self::$ConfigsCache[$cfarmid["fid"]] = false;
         }
     }
     // Update reconfig flag
     $DB->Execute("UPDATE client_settings SET `value`='0' WHERE `key`='reconfigure_event_daemon'");
     // Check config in cache
     if (!self::$ConfigsCache[$farmid] || !self::$ConfigsCache[$farmid][$observer->ObserverName]) {
         Logger::getLogger(__CLASS__)->debug("There is no cached config for this farm or config updated. Loading config...");
         // Get configuration form
         self::$ConfigsCache[$farmid][$observer->ObserverName] = $observer->GetConfigurationForm();
         // Get farm observer id
         $farm_observer_id = $DB->GetOne("SELECT * FROM farm_event_observers \r\n\t\t\t\t\tWHERE farmid=? AND event_observer_name=?", array($farmid, get_class($observer)));
         // Get Configuration values
         if ($farm_observer_id) {
             Logger::getLogger(__CLASS__)->info("Farm observer id: {$farm_observer_id}");
             $config_opts = $DB->Execute("SELECT * FROM farm_event_observers_config \r\n\t\t\t\t\t\tWHERE observerid=?", array($farm_observer_id));
             // Set value for each config option
             while ($config_opt = $config_opts->FetchRow()) {
                 $field =& self::$ConfigsCache[$farmid][$observer->ObserverName]->GetFieldByName($config_opt['key']);
                 if ($field) {
                     $field->Value = $config_opt['value'];
                 }
             }
         } else {
             return false;
         }
     }
     return self::$ConfigsCache[$farmid][$observer->ObserverName];
 }