Invoke responder

@return mixed
@throws BaseException
551929
final public function invoker()
    {
        $beforeCallEvent = $this->dispatchEvent(
            self::EVENT_BEFORE_CALL_METHOD,
            $this,
            ['request' => $this->getRequest()]
        );

        if ($beforeCallEvent->getResult() instanceof Response) {
            return $beforeCallEvent->getResult();
        }

        $response = call_user_func_array($this, func_get_args());

        $this->dispatchEvent(
            self::EVENT_AFTER_CALL_METHOD,
            $this,
            ['request' => $this->getRequest(), 'response' => $response]
        );

        return $response;
    }
145815
public function activate(): void
    {
        if ($this->stopBuffering) {
            $this->buffering = false;
        }
        if (!$this->handler instanceof HandlerInterface) {
            $record = end($this->buffer) ?: null;

            $this->handler = call_user_func($this->handler, $record, $this);
            if (!$this->handler instanceof HandlerInterface) {
                throw new \RuntimeException("The factory callable should return a HandlerInterface");
            }
        }
        $this->handler->handleBatch($this->buffer);
        $this->buffer = [];
    }
821817
public function getResponse(\Phalcon\Http\Client\Response $response)
    {
        if ($response->body > 100) {
            $error = $this->config->statuses[$response->body];
            throw new BaseException((new \ReflectionClass($this->config))->getShortName(), $error);
        }
        return (($this->debug === true) ? [$response->header, $response] :
            (isset($this->config->statuses[$response->body]))
                ? $this->config->statuses[$response->body] : $response->body);
    }
686047
public function prepareResponse()
    {
        try {
            $this->setBaseMiddlewares();
            $this->handleRequest($this->middlewares);
            $this->router->build();
            $this->handleRequest($this->routeMiddlewares);
            $this->response = $this->router->run();
        } catch (Exception $exception) {
            $response = $this->container->call([$this->getExceptionHandler(), 'render'], [$exception]);
            $this->response = $response ?: $this->response;
        }
    }
907855
public function run()
    {
        try {
            $response = $this->buildResponse();
        } catch (Error\Base $ex) {
            $response = $this->handleError($ex);
        }

        $this->serializer->serialize($response, $this);

        return $this;
    }
844508
public function handler(): Response
    {
        $response = [];
        foreach (Bulletin::all() as $bulletin) {
            $response[] = [
                'id' => $bulletin->getId(),
                'createdAt' => $bulletin->getCreatedAt()->getTimestamp(),
                'title' => $bulletin->getTitle(),
                'abstract' => $bulletin->getAbstract(),
                'isDraft' => $bulletin->isDraft(),
                'statistics' => $bulletin->getStatistics()
            ];
        }
        return response($response);
    }
811965
function invoke() {
        parent::invoke();

        $result = true;

        // Set own core attributes
        $this->does_generate = ACTION_NONE;
        //$this->does_generate = ACTION_GENERATE_HTML;

        // These are always here
        global $CFG, $XMLDB;

        // Do the job, setting result as needed

        if (!data_submitted()) { // Basic prevention
            print_error('wrongcall', 'error');
        }

        // Get parameters
        $dirpath = required_param('dir', PARAM_PATH);
        $dirpath = $CFG->dirroot . $dirpath;

        $comment = required_param('comment', PARAM_CLEAN);
        $comment = $comment;

        // Set comment and recalculate hash
        $editeddir = $XMLDB->editeddirs[$dirpath];
        $structure = $editeddir->xml_file->getStructure();
        $structure->setComment($comment);
        $structure->calculateHash(true);


        // If the hash has changed from the original one, change the version
        // and mark the structure as changed
        $origdir = $XMLDB->dbdirs[$dirpath];
        $origstructure = $origdir->xml_file->getStructure();
        if ($structure->getHash() != $origstructure->getHash()) {
            $structure->setVersion(userdate(time(), '%Y%m%d', 99, false));
            $structure->setChanged(true);
        }

        // Launch postaction if exists (leave this here!)
        if ($this->getPostAction() && $result) {
            return $this->launch($this->getPostAction());
        }

        // Return ok if arrived here
        return $result;
    }
1170801
public function toResponse(): Response
    {
        $base = [
            'return_code' => is_null($this->fail) ? static::SUCCESS : static::FAIL,
            'return_msg' => $this->fail,
        ];

        $attributes = array_merge($base, $this->attributes);

        if ($this->sign) {
            $attributes['sign'] = Support\generate_sign($attributes, $this->app->getKey());
        }

        return new Response(XML::build($attributes));
    }
59991
public function execute()
    {
        if (is_string($this->callback)) {
            // Will call the controller here
            $parts = explode('::', $this->callback);
            $className = $parts[0];
            $classMethod = $parts[1];

            if (! class_exists($className)) {
                throw new RouterException("The callback class declared in your middleware is not found: '{$className}'");
            }

            $class = new $className();

            if (! $class instanceof BaseMiddleware) {
                throw new RouterException("The class in your middleware route doesn't extend the BaseMiddleware: '{$className}'"); // @codeCoverageIgnore
            }

            if (! method_exists($class, $classMethod)) {
                throw new RouterException("The class in your middleware route doesn't have the method you provided: '{$className}' method: {$classMethod}");
            }

            // Call the method. Catch return
            $result = call_user_func(array($class, $classMethod));

        } elseif (is_callable($this->callback)) {
            $result = call_user_func($this->callback);

        } else {
            throw new RouterException("Middleware callback is not a class or callable!"); // @codeCoverageIgnore
        }

        // See if we got a boolean back.
        if ($result === false && $this->position === 'before') {
            // We should stop!
            return false;
        }
        return true;
    }
141220
public function execute()
    {
        $this->_setOptions();

        $response = $this->_execute();
        $this->_saveStatusCode();

        $curlErrorNumber = $this->_getErrorNumber();

        $this->_close();

        if ($curlErrorNumber) {
            /**
             * @var \OxidEsales\Eshop\Core\Exception\StandardException $exception
             */
            $exception = oxNew(\OxidEsales\Eshop\Core\Exception\StandardException::class);
            $lang = \OxidEsales\Eshop\Core\Registry::getLang();
            $exception->setMessage(sprintf($lang->translateString('EXCEPTION_CURL_ERROR', $lang->getTplLanguage()), $curlErrorNumber));
            throw $exception;
        }

        return $response;
    }
1253672
public function postRevoke()
    {
        $oHttpCodes        = Factory::service('HttpCodes');
        $oAccessTokenModel = Factory::model('UserAccessToken', 'nails/module-auth');

        if (!isLoggedIn()) {
            throw new ApiException(
                'You must be logged in',
                $oHttpCodes::STATUS_UNAUTHORIZED
            );
        }

        $oInput       = Factory::service('Input');
        $sAccessToken = $oInput->post('access_token');

        if (empty($sAccessToken)) {
            throw new ApiException(
                'An access token to revoke must be provided',
                $oHttpCodes::STATUS_BAD_REQUEST
            );
        }

        if (!$oAccessTokenModel->revoke(activeUser('id'), $sAccessToken)) {
            throw new ApiException(
                'Failed to revoke access token. ' . $oAccessTokenModel->lastError(),
                $oHttpCodes::STATUS_INTERNAL_SERVER_ERROR
            );
        }

        return Factory::factory('ApiResponse', 'nails/module-api');
    }
789781
public function generateResponse(){
        // Create request
        $this->startTimeline("request.create");

        $request    = $this->container->get("app.request")
            ->withAttribute("app.debug", $this->debug)
        ;

        $this->endTimeline("request.create");

        // Create response
        $this->startTimeline("response.create");

        $response   = $this->container->newInstance(Response::class, [
            "handler"   => $this->generateHandler($request),
        ]);

        $this->endTimeline("response.create");

        return $response;
    }
651476
private function invoke($responseClass)
    {
        if (!$this->isValid()) {
            return $this->getErrorResponse($responseClass);
        }

        try {
            $caller = $this->getCaller();
            $response = call_user_func_array([$this, 'do'.ucfirst($caller['function'])], $caller['args']);

            return $this->wrapResponse($responseClass, $response);
        } catch (InvalidArgumentException $e) {
            $this->addError(self::ERROR_INVALID_ARGUMENT);
        } catch (MassAssignmentException $e) {
            $this->addError(self::ERROR_INVALID_ARGUMENT);
        }


        return $this->getErrorResponse($responseClass);
    }
646054
public function call() {
        $request = $this->createRequest();
        $response = $this->api->execute($request, $this);
        $this->response = $response;

        if ($this->shouldResponseBeProcessed($response)) {
            $instance = $this->api->instantiateResult($response, $this);

            return $instance;
        }
        return $response;
    }
162310
function invoke() {
        parent::invoke();

        $result = true;

        // Set own core attributes
        $this->does_generate = ACTION_GENERATE_HTML;

        // These are always here
        global $CFG, $XMLDB, $OUTPUT;

        // Do the job, setting result as needed
        // Get the dir containing the file
        $dirpath = required_param('dir', PARAM_PATH);
        $dirpath = $CFG->dirroot . $dirpath;

        // Get the correct dirs
        if (!empty($XMLDB->dbdirs)) {
            $dbdir = $XMLDB->dbdirs[$dirpath];
        } else {
            return false;
        }
        if (!empty($XMLDB->editeddirs)) {
            $editeddir = $XMLDB->editeddirs[$dirpath];
            $structure = $editeddir->xml_file->getStructure();
        }

        // Fetch request data
        $tableparam = required_param('table', PARAM_CLEAN);
        if (!$table = $structure->getTable($tableparam)) {
            $this->errormsg = 'Wrong table specified: ' . $tableparam;
            return false;
        }
        $keyparam = required_param('key', PARAM_CLEAN);
        if (!$key = $table->getKey($keyparam)) {
            // Arriving here from a name change, looking for the new key name
            $keyparam = required_param('name', PARAM_CLEAN);
            $key = $table->getKey($keyparam);
        }

        $dbdir = $XMLDB->dbdirs[$dirpath];
        $origstructure = $dbdir->xml_file->getStructure();

        // Add the main form
        $o = '<form id="form" action="index.php" method="post">';
        $o.= '<div>';
        $o.= '    <input type="hidden" name ="dir" value="' . str_replace($CFG->dirroot, '', $dirpath) . '" />';
        $o.= '    <input type="hidden" name ="table" value="' . $tableparam .'" />';
        $o.= '    <input type="hidden" name ="key" value="' . $keyparam .'" />';
        $o.= '    <input type="hidden" name ="sesskey" value="' . sesskey() .'" />';
        $o.= '    <input type="hidden" name ="action" value="edit_key_save" />';
        $o.= '    <input type="hidden" name ="postaction" value="edit_table" />';
        $o.= '    <table id="formelements" class="boxaligncenter">';
        // XMLDB key name
        // If the key has dependencies, we cannot change its name
        $disabled = '';
        if ($structure->getKeyUses($table->getName(), $key->getName())) {
            $disabled = ' disabled="disabled " ';
        }
        $o.= '      <tr valign="top"><td><label for="name" accesskey="n">Name:</label></td><td colspan="2"><input name="name" type="text" size="'.xmldb_field::NAME_MAX_LENGTH.'" id="name"' . $disabled . ' value="' . s($key->getName()) . '" /></td></tr>';
        // XMLDB key comment
        $o .= '      <tr valign="top"><td><label for="comment" accesskey="c">Comment:</label></td><td colspan="2">
                     <textarea name="comment" rows="3" cols="80" id="comment" class="form-control">' .
                     s($key->getComment()) . '</textarea></td></tr>';
        // xmldb_key Type
        $typeoptions = array (XMLDB_KEY_PRIMARY => $key->getXMLDBKeyName(XMLDB_KEY_PRIMARY),
                              XMLDB_KEY_UNIQUE  => $key->getXMLDBKeyName(XMLDB_KEY_UNIQUE),
                              XMLDB_KEY_FOREIGN   => $key->getXMLDBKeyName(XMLDB_KEY_FOREIGN),
                              XMLDB_KEY_FOREIGN_UNIQUE => $key->getXMLDBKeyName(XMLDB_KEY_FOREIGN_UNIQUE));
        // Only show the XMLDB_KEY_FOREIGN_UNIQUE if the Key has that type
        // if ($key->getType() != XMLDB_KEY_FOREIGN_UNIQUE) {
        // unset ($typeoptions[XMLDB_KEY_FOREIGN_UNIQUE);
        // }
        $select = html_writer::select($typeoptions, 'type', $key->getType(), false);

        $o.= '      <tr valign="top"><td><label for="menutype" accesskey="t">Type:</label></td>';
        $o.= '        <td colspan="2">' . $select . '</td></tr>';
        // xmldb_key Fields
        $o.= '      <tr valign="top"><td><label for="fields" accesskey="f">Fields:</label></td>';
        $o.= '        <td colspan="2"><input name="fields" type="text" size="40" maxlength="80" id="fields" value="' . s(implode(', ', $key->getFields())) . '" /></td></tr>';
        // xmldb_key Reftable
        $o.= '      <tr valign="top"><td><label for="reftable" accesskey="t">Reftable:</label></td>';
        $o.= '        <td colspan="2"><input name="reftable" type="text" size="20" maxlength="40" id="reftable" value="' . s($key->getReftable()) . '" /></td></tr>';
        // xmldb_key Reffields
        $o.= '      <tr valign="top"><td><label for="reffields" accesskey="t">Reffields:</label></td>';
        $o.= '        <td colspan="2"><input name="reffields" type="text" size="40" maxlength="80" id="reffields" value="' . s(implode(', ', $key->getRefFields())) . '" /></td></tr>';
        // Change button
        $o .= '      <tr valign="top"><td>&nbsp;</td><td colspan="2"><input type="submit" value="' .
                     $this->str['change'] . '" class="btn btn-secondary"/></td></tr>';
        $o.= '    </table>';
        $o.= '</div></form>';
        // Calculate the buttons
        $b = ' <p class="centerpara buttons">';
        // The view original XML button
        if ($table->getKey($keyparam)) {
            $b .= '&nbsp;<a href="index.php?action=view_key_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=original&amp;table=' . $tableparam . '&amp;key=' . $keyparam . '">[' . $this->str['vieworiginal'] . ']</a>';
        } else {
            $b .= '&nbsp;[' . $this->str['vieworiginal'] . ']';
        }
        // The view edited XML button
        if ($key->hasChanged()) {
            $b .= '&nbsp;<a href="index.php?action=view_key_xml&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '&amp;select=edited&amp;table=' . $tableparam . '&amp;key=' . $keyparam . '">[' . $this->str['viewedited'] . ']</a>';
        } else {
            $b .= '&nbsp;[' . $this->str['viewedited'] . ']';
        }
        // The back to edit table button
        $b .= '&nbsp;<a href="index.php?action=edit_table&amp;table=' . $tableparam . '&amp;dir=' . urlencode(str_replace($CFG->dirroot, '', $dirpath)) . '">[' . $this->str['back'] . ']</a>';
        $b .= '</p>';
        $o .= $b;

        $this->output = $o;

        // Launch postaction if exists (leave this here!)
        if ($this->getPostAction() && $result) {
            return $this->launch($this->getPostAction());
        }

        // Return ok if arrived here
        return $result;
    }
1338950
public function httpResponse()
    {
        if ($this->httpResponse === null) {
            throw new RuntimeException(sprintf(
                'PSR-7 HTTP Response is not defined for "%s"',
                get_class($this)
            ));
        }

        return $this->httpResponse;
    }
718804
protected function _processResponse()
    {
        $this->_factory
            ->getNewCancelProcessResponse($this->_response, $this->_order)
            ->process();
        return $this;
    }