Get Next Task Available in Response Tasks Buffer

@param ArrayObject|false $response Webservice Call Response

@return false|mixed
176447
public static function getNextTask(&$response)
    {
        //====================================================================//
        // Analyze SOAP Results
        if (!$response || !isset($response->result) || (true != $response->result)) {
            return false;
        }
        //====================================================================//
        // Check if Tasks Buffer is Empty
        if (!Splash::count($response->tasks)) {
            return false;
        }
        //====================================================================//
        // Detect ArrayObjects
        if ($response->tasks instanceof ArrayObject) {
            $response->tasks = $response->tasks->getArrayCopy();
        }
        //====================================================================//
        // Shift Task Array
        return array_shift($response->tasks);
    }
1089603
public function getResponseError(ResponseInterface $response)
    {
        $code = $response->getStatusCode();
        if ($code >= 200 && $code < 300) {
            return false;
        }

        return $response->getReasonPhrase();
    }
1108118
public function httpAfterGet(RequestInterface $request, ResponseInterface $response)
    {
        $contentType = $response->getHeader('Content-Type');
        if (null === $contentType || false === strpos($contentType, 'text/calendar')) {
            return;
        }

        $result = HTTP\negotiateContentType(
            $request->getHeader('Accept'),
            ['text/calendar', 'application/calendar+json']
        );

        if ('application/calendar+json' !== $result) {
            // Do nothing
            return;
        }

        // Transforming.
        $vobj = VObject\Reader::read($response->getBody());

        $jsonBody = json_encode($vobj->jsonSerialize());
        $response->setBody($jsonBody);

        // Destroy circular references so PHP will garbage collect the object.
        $vobj->destroy();

        $response->setHeader('Content-Type', 'application/calendar+json');
        $response->setHeader('Content-Length', strlen($jsonBody));
    }
1133405
public function checkResponse($response) {
    if (!is_array($response)) {
      return FALSE;
    }

    $responseParams = array();
    foreach ($this->responseFields as $k => $mandatory) {
      if (isset($response[$k])) {
        $responseParams[$k] = $response[$k];
      }
      elseif (!isset($response[$k]) && $mandatory) {
        throw new \Exception('expected response field ' . $k . ' is missing');
      }
    }

    return $responseParams;
  }
585188
public function execute($response) {
        global $DB;

        $params = $this->parse_template();
        $contextid = $params['context_id'];
        $isget = $response->get_request_method() === self::HTTP_GET;
        if ($isget) {
            $contenttype = $response->get_accept();
        } else {
            $contenttype = $response->get_content_type();
        }
        $container = empty($contenttype) || ($contenttype === $this->formats[0]);
        // We will receive typeid when working with LTI 1.x, if not the we are in LTI 2.
        $typeid = optional_param('type_id', null, PARAM_ALPHANUM);
        if (is_null($typeid)) {
            if (!$this->check_tool_proxy(null, $response->get_request_data())) {
                $response->set_code(403);
                $response->set_reason("Invalid tool proxy specified.");
                return;
            }
        } else {
            switch ($response->get_request_method()) {
                case self::HTTP_GET:
                    if (!$this->check_type($typeid, $contextid, 'LineItem.collection:get', $response->get_request_data())) {
                        $response->set_code(403);
                        $response->set_reason("This resource does not support GET requests.");
                        return;
                    }
                    break;
                case self::HTTP_POST:
                    if (!$this->check_type($typeid, $contextid, 'LineItem.collection:post', $response->get_request_data())) {
                        $response->set_code(403);
                        $response->set_reason("This resource does not support POST requests.");
                        return;
                    }
                    break;
                default:  // Should not be possible.
                    $response->set_code(405);
                    $response->set_reason("Invalid request method specified.");
                    return;
            }
        }
        if (empty($contextid) || !($container ^ ($response->get_request_method() === self::HTTP_POST)) ||
                (!empty($contenttype) && !in_array($contenttype, $this->formats))) {
            $response->set_code(400);
            $response->set_reason("Invalid request made.");
            return;
        }
        if (!$DB->record_exists('course', array('id' => $contextid))) {
            $response->set_code(404);
            $response->set_reason("Not Found: Course $contextid doesn't exist.");
            return;
        }
        switch ($response->get_request_method()) {
            case self::HTTP_GET:
                $resourceid = optional_param('resource_id', null, PARAM_TEXT);
                $ltilinkid = optional_param('lti_link_id', null, PARAM_TEXT);
                $tag = optional_param('tag', null, PARAM_TEXT);
                $limitnum = optional_param('limit', 0, PARAM_INT);
                $limitfrom = optional_param('from', 0, PARAM_INT);
                $itemsandcount = $this->get_service()->get_lineitems($contextid, $resourceid, $ltilinkid, $tag, $limitfrom,
                        $limitnum, $typeid);
                $items = $itemsandcount[1];
                $totalcount = $itemsandcount[0];
                $json = $this->get_json_for_get_request($items, $resourceid, $ltilinkid, $tag, $limitfrom,
                        $limitnum, $totalcount, $typeid, $response);
                $response->set_content_type($this->formats[0]);
                break;
            case self::HTTP_POST:
                try {
                    $json = $this->get_json_for_post_request($response->get_request_data(), $contextid, $typeid);
                    $response->set_code(201);
                    $response->set_content_type($this->formats[1]);
                } catch (\Exception $e) {
                    $response->set_code($e->getCode());
                    $response->set_reason($e->getMessage());
                }
                break;
            default:  // Should not be possible.
                $response->set_code(405);
                $response->set_reason("Invalid request method specified.");
                return;
        }
        $response->set_body($json);
    }
1107548
private function transformGenericSearchToData($response)
    {
        if ($response instanceof ActiveQueryInterface) {
            return $response->asArray(true)->all();
        } elseif ($response instanceof QueryInterface) {
            return $response->all();
        }
        
        return $response;
    }
1344252
public function dispatch(Request $request, Response $response, $next = null)
    {
        $controller = $this->currentController;

        $controller->setRequest($request)->setResponse($response);

        $this->prepareExecute();

        // @event: onPackageBeforeExecute
        $this->getDispatcher()->triggerEvent('onPackageBeforeExecute', [
            'package' => $this,
            'controller' => &$controller,
            'task' => $controller,
        ]);

        $result = $controller->execute();

        $result = $this->postExecute($result);

        // @event: onPackageAfterExecute
        $this->getDispatcher()->triggerEvent('onPackageAfterExecute', [
            'package' => $this,
            'controller' => $controller,
            'result' => &$result
        ]);

        $response = $controller->getResponse();

        if ($result !== null) {
            // Render view if return value is a view object,
            // don't use (string) keyword to make sure we can get Exception when error occurred.
            // @see  https://bugs.php.net/bug.php?id=53648
            if ($result instanceof AbstractView) {
                $result = $result->render();
            } elseif (is_stringable($result)) {
                $result = (string) $result;
            } elseif (is_array($result) || is_object($result)) {
                $result = json_encode($result);
            }

            $response->getBody()->write((string) $result);
        }

        return $response;
    }
119973
protected function getStatus(array $response)
    {
        switch ($status = Arr::get($response, 'status', 'paid')) {
            case 'active':
            case 'trial':
            case 'unpaid':
            case 'failed':
                return new Status($status);
            case 'completed':
                return new Status('paid');
            case 'in_progress':
                return new Status('pending');
            case 'cancelled':
                return new Status('canceled');
            case 'verified':
                return new Status('active');
            case 'past_due':
                return new Status('failed');
            case 'deleted':
                return new Status('canceled');
        }
    }
437520
protected function getResultFromResponse(Response $response)
    {
        $result   = [];
        $included = $this->getIncludedArray($response->getIncluded());

        foreach ($response->getData() as $element) {
            $mapperClass = $this->getMapperClass($element['type']);
            if (is_null($mapperClass)) {
                throw new EntityNotFoundException("Entity mapper class for {$element['type']} was not found");
            }

            $result[$element['type']][] = $this->createObject($mapperClass, $element, $included);
        }

        return $result;
    }
871908
public function run(ServerRequestInterface $request, ResponseInterface $response, $next = null)
    {
        if (!$request->getAttribute('route') instanceof Route) {
            $route = $this->routes->getRoute($request);

            if (!$route) {
                return $this->notFound($request, $response);
            }

            $request = $request->withAttribute('route', $route);
        }
        
        $runner = $this->getRunner();

        return $runner($request, $response, $next);
    }
1273534
protected function getCrawler(Response $response)
    {
        if ($this->crawler) {
            return $this->crawler;
        }

        return $this->crawler = new Crawler($response->getContent());
    }
670089
public static function parseResponse($response)
    {
        $response = is_array($response) ? $response : json_decode($response, true);

        if ( $response && $response['code'] == self::COSAPI_SUCCESS) {
            return $response;
        }

        return false;
    }
256258
public function executeMiddlewares(
        ServerRequestInterface $request,
        ResponseInterface $response,
        callable $next = null
    ) : ResponseInterface {
        return $this->getMiddlewares()->__invoke($request, $response, $next);
    }
74167
protected function get_all_hits(array $response) {
        $hits = array();
        foreach ($this->places as $placeno => $place) {
            $rightchoice = $this->get_right_choice_for($placeno);
            $rightchoicekey = $this->choice($rightchoice);
            if (!array_key_exists($rightchoicekey, $response)) {
                continue;
            }
            $choicecoords = $response[$rightchoicekey];
            $coords = explode(';', $choicecoords);
            foreach ($coords as $itemno => $coord) {
                if (trim($coord) === '') {
                    continue;
                }
                $pointxy = explode(',', $coord);
                $pointxy[0] = round($pointxy[0]);
                $pointxy[1] = round($pointxy[1]);
                if ($place->drop_hit($pointxy)) {
                    if (!isset($hits[$placeno])) {
                        $hits[$placeno] = array();
                    }
                    $hits[$placeno][$itemno] = $coord;
                }
            }
        }
        // Reverse sort in order of number of hits per place (if two or more
        // hits per place then we want to make sure hits do not hit elsewhere).
        $sortcomparison = function ($a1, $a2){
            return (count($a1) - count($a2));
        };
        uasort($hits, $sortcomparison);
        return $hits;
    }
187222
protected function respond($response)
    {
        $success = Arr::get($response, 'success');

        return $this->mapResponse($success, $response);
    }
1071247
public function next(Request $request, Response $response, $next)
    {
        $response->setContentType('text/json');
        $next($request, $response);
    }
605818
private function wait($response) {
        if (is_array($response) && !empty($response['url'])) {
            $explodedUrl = explode('/', $response['url']);
            $arrayLength = count($explodedUrl);
            $processId = $explodedUrl[$arrayLength - 1];
            $jobId = $explodedUrl[$arrayLength - 3];
            $start_time = time();

            do {
                $delta = time() - $start_time;

                if ($delta > $this->getSyncTimeOut()) {
                    throw new SmartlingApiException(vsprintf('No response received after %s seconds.', [$delta]));
                }

                sleep(1);
                $result = $this->checkAsynchronousProcessingStatus($jobId, $processId);
            }
            while ($result['processState'] != 'COMPLETED');
        }
    }