/** * {@inheritdoc} */ protected function processFunction($function, \Mibew\API\ExecutionContext &$context) { // Check if a function can be called. Operators can call anythig, thus // we should continue validation only for users. if (!$this->getAuthenticationManager()->getOperator()) { // A function is called by a user. We need to check that the thread // is related with the user. $arguments = $context->getArgumentsList($function); $thread_id = $arguments['threadId']; // As defined in Mibew\API\Interaction\ChatInteraction "threadid" // argument is mandatory, but some function allows it to be null. In // such cases there is no thread and there is nothing to check. if (!is_null($thread_id)) { $is_own_thread = isset($_SESSION[SESSION_PREFIX . 'own_threads']) && in_array($thread_id, $_SESSION[SESSION_PREFIX . 'own_threads']); if (!$is_own_thread) { throw new AccessDeniedException(); } } } // The function can be called. Process it. parent::processFunction($function, $context); }
/** * Process function * * @param array $function 'Function' array. See Mibew API for details * @param \Mibew\API\ExecutionContext &$context Execution context * @return boolean False if function returns errorCode and errorCode isn't 0 * and true otherwise. */ protected function processFunction($function, \Mibew\API\ExecutionContext &$context) { // Get function arguments with replaced references $arguments = $context->getArgumentsList($function); $call_vars = array('function' => $function['function'], 'arguments' => $arguments, 'results' => array()); // Call processor function $this->processorCall($call_vars); // Trigger FunctionCall event $call_vars['request_processor'] = $this; $dispatcher = EventDispatcher::getInstance(); $dispatcher->triggerEvent($this->eventPrefix . 'FunctionCall', $call_vars); // Get results $results = $call_vars['results']; // Add function results to execution context $context->storeFunctionResults($function, $results); // Check errorCode return empty($results['errorCode']); }