<?php
namespace Moto\System\Traits; use Moto; use Zend; trait ChannelEventsTrait { public static function listen($eventName, $listener) { $channel = get_class(); $eventName = '#' . $channel . '.' . $eventName; try { Moto\System::getEventDispatcher()->listen($eventName, $listener); return true; } catch (\Exception $e) { if (Moto\System::isDevelopmentStage()) { Moto\System\Log::error(static::class . ':' . __FUNCTION__, array('channel' => $channel, 'event' => $eventName, 'code' => $e->getCode(), 'message' => $e->getMessage())); } } return false; } public function _fireEvent($eventName, $value = null) { $channel = get_class(); try { $eventName = '#' . $channel . '.' . $eventName; $args = func_get_args(); $args = array_slice($args, 1); array_unshift($args, $this); Moto\System::getEventDispatcher()->fire($eventName, $args); return true; } catch (\Exception $e) { if (Moto\System::isDevelopmentStage()) { Moto\System\Log::error(static::class . ':' . __FUNCTION__, array('channel' => $channel, 'event' => $eventName, 'code' => $e->getCode(), 'message' => $e->getMessage())); } } return false; } } 