/** * Processes the interaction service request. All the specific requests will be processed and optional responses will be returned * @param \System\Collection\Map The serviceResult to output * @param \System\Db\Database The database to work with. */ public static final function interact(\System\Collection\Map $serviceResult, \System\Db\Database $defaultDb) { self::validateHandles(); $val = self::$post->request; if (!empty($val)) { //decodes the given content in the request post var $decoded = \System\System\Interaction\Interaction::decode($val); if ($decoded) { $reply = new \System\Collection\Vector(); foreach ($decoded as $message) { $event = new \System\System\Interaction\Event\OnInteractionEvent(); $event->setMessage($message); $event->setDatabase($defaultDb); $event->raise(); $event->addResponse(new \System\System\Interaction\Response($message, 'OK')); foreach ($event->getResponses() as $response) { $reply[] = $response; } } $serviceResult->reply = $reply; return true; } } return false; }
/** * Handles the transferring of the request to the service. */ public final function interact() { $reply = new \System\Collection\Vector(); if ($this->hasServiceResult('\\System\\System\\Interaction\\Service\\InteractionRcv::interact')) { $serviceResult = $this->getServiceResult('\\System\\System\\Interaction\\Service\\InteractionRcv::interact'); $reply = $serviceResult->reply; } $renderer = new \System\Output\Renderer\DataRenderer(); $renderer->render(\System\System\Interaction\Interaction::encode($reply)); $renderSurface = \System\Output\RenderSurface::getSurface('\\System\\Output\\GZIPBufferSurface'); $renderSurface->setRenderer($renderer); $this->setRenderSurface($renderSurface); }