@param string $requestId
@param string $url
@param UserEvent $event
@param EventQueue $queue

@return Request
184337
public function createRequest($requestId, $url, UserEvent $event, EventQueue $queue)
    {
        $start = microtime(true);
        return new Request([
            'url' => $url,
            'responseCallback' => function ($headers, $code) use ($requestId, $start) {
                $end = microtime(true);
                $this->logDebug('[' . $requestId . ']Reponse (after ' . ($end - $start) . 's): ' . $code);
            },
            'resolveCallback' =>
                function (Response $response) use ($requestId, $url, $event, $queue, $start) {
                    $data = $response->getBody()->getContents();
                    $headers = $response->getHeaders();
                    array_walk($headers, function (&$value, $key) use ($response) {
                        $value = $response->getHeader($key);
                    });
                    $code = $response->getStatusCode();
                    $end = microtime(true);
                    $message = '[';
                    $message .= $requestId;
                    $message .= ']Download complete (after ';
                    $message .= ($end - $start);
                    $message .= 's): ';
                    $message .= strlen($data);
                    $message .= ' in length length';
                    $this->logDebug($message);
                    $this->emitShorteningEvents($requestId, $url)->then(
                        function ($shortUrl) use ($url, $data, $headers, $code, $end, $start, $event, $queue) {
                            $this->sendMessage(
                                new Url($url, $data, $headers, $code, $end - $start, $shortUrl),
                                $event,
                                $queue
                            );
                        },
                        function () use ($url, $data, $headers, $code, $end, $start, $event, $queue) {
                            $this->sendMessage(new Url($url, $data, $headers, $code, $end - $start), $event, $queue);
                        }
                    );
                },
        ]);
    }
850370
public function onClientRequest(RequestEvent $event)
    {
        $errors = $this->validator->validate($event->getRequest());

        if (count($errors)) {
            throw new RequestException((string) $errors);
        }
    }
1059874
public function post(Provider $provider, $userId, $requestScope, $requestUri, array $postBody, array $requestHeaders = [])
    {
        return $this->send($provider, $userId, $requestScope, Request::post($requestUri, $postBody, $requestHeaders));
    }
1049627
public function dispatch($requestUrl = null, $requestMethod = null) 
	{
		$params = array();
		$match = false;
		// set Request Url if it isn't passed as parameter
		if ($requestUrl === null) {
			$requestUrl = isset($_SERVER['REQUEST_URI']) ? $_SERVER['REQUEST_URI'] : '/';
		}
		// strip base path from request url
		$requestUrl = substr($requestUrl, strlen($this->basePath));
		// Strip query string (?a=b) from Request Url
		if (($strpos = strpos($requestUrl, '?')) !== false) {
			$requestUrl = substr($requestUrl, 0, $strpos);
		}
		// Strip anchors from the url
		// if (($strpos = strpos($requestUrl, '#')) !== false) {
		// 	$requestUrl = substr($requestUrl, 0, $strpos);
		// }
		// set Request Method if it isn't passed as a parameter
		if ($requestMethod === null) {
			$requestMethod = isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : 'GET';
		}
		foreach ($this->routes as $handler) {
			list($method, $_route, $target, $name) = $handler;
			$methods = explode('|', $method);
			$method_match = false;
			// Check if request method matches. If not, abandon early. (CHEAP)
			foreach ($methods as $method) {
				if (strcasecmp($requestMethod, $method) === 0) {
					$method_match = true;
					break;
				}
			}
			// Method did not match, continue to next route.
			if (!$method_match) {
				continue;
			}
			// Check for a wildcard (matches all)
			if ($_route === '*') {
				$match = true;
			} elseif (isset($_route[0]) && $_route[0] === '@') {
				$pattern = '`' . substr($_route, 1) . '`u';
				$match = preg_match($pattern, $requestUrl, $params);
			} else {
				$route = null;
				$regex = false;
				$j = 0;
				$n = isset($_route[0]) ? $_route[0] : null;
				$i = 0;
				// Find the longest non-regex substring and match it against the URI
				while (true) {
					if (!isset($_route[$i])) {
						break;
					} elseif (false === $regex) {
						$c = $n;
						$regex = $c === '[' || $c === '(' || $c === '.';
						if (false === $regex && false !== isset($_route[$i+1])) {
							$n = $_route[$i + 1];
							$regex = $n === '?' || $n === '+' || $n === '*' || $n === '{';
						}
						if (false === $regex && $c !== '/' && (!isset($requestUrl[$j]) || $c !== $requestUrl[$j])) {
							continue 2;
						}
						$j++;
					}
					$route .= $_route[$i++];
				}
				$regex = $this->compileRoute($route);
				$match = preg_match($regex, $requestUrl, $params);
			}
			if (($match == true || $match > 0)) {
				if ($params) {
					foreach ($params as $key => $value) {
						if (is_numeric($key)) unset($params[$key]);
					}
				}			
				$mm = array(
					'target' => $target,
					'params' => $params,
					'name' => $name
				);
				if ($match) {	
				  //we are going to change this to use all be in the router function
				  //break up the target at the @ symbol. first part is function second is the file 
				  $target = explode('@', $mm['target']);
				  $method = $target[0];
				  $class = "\\App\\Controllers\\".$target[1];
				  //include the source file
				  include $this->controllersDir . str_replace('\\', '/', $target[1]) . '.php';
				  //instantiate the class
				  $instance = new $class();
				  //this is where we will place our middleware. first check to see if the there is an alias in 
				  //the middleware array and then execute it against our controller.
				  //get the middleware array from the instance
				  $instanceMiddleware = $instance->getMiddleware();
				  $middleware = $this->getMiddleWareArray();
					//count the instance middleware array
					$middlewareCnt = count($instanceMiddleware);
				  $middlewareInstances = [];
				  //build an acceptible middleware list to send to relay
				  $i = 0;
				  foreach($instanceMiddleware as $val) {
				  	//then loop through the middleware and see if we have a match
					  foreach ($middleware as $key => $value) {
							if($val==$key) {
						  	//check if its an array if it is we have to add them to the container individually.
						  	$middlewareInstances[$i][]=$instanceMiddleware[$i];
						  	if (is_array($value)) {
						  		//first index is the middleware class and the second index is the plugin
						  		for($j=0;$j<count($value);$j++) {
						  			$middlewareInstances[$i][] = $value[$j];
					  				$i++;
						  		}
						  	} else {
						  		//just a middleware class. This class will extend from another and doesnt need the plugin portion
					  			$middlewareInstances[$i][] = $value;
					  			$i++;
						  	}
						  }
					  }
				  }
				  //get the request array
				if (defined('PHPUNIT_BETASYNTAX_TESTSUITE') == true) { 
					$requestMethod = $requestMethod;
				}
				// } else {
				// 	if($requestMethod === null) {
			 //  			$requestMethod = $_SERVER['REQUEST_METHOD'];	
				// 	} else {
				// 		$requestMethod = $_SERVER['REQUEST_METHOD'];
				// 	}
				// }
			  	//instantiate our request and response for Relay
			  	$request = new Request($requestMethod,$requestUrl);
			  	$response = new Response;
			  	$queue = [];
			  	//build the middleware queue
			  	for($i=0;$i<count($middlewareInstances);$i++) {
			  			$queue[] = $middlewareInstances[$i][1];
			  	}
			  	//setup the automatic resolver
					$resolver = function ($class) {
					    return new $class();
					};
					//build the Relay builder class
					$relayBuilder = new RelayBuilder($resolver);
					$relay = $relayBuilder->newInstance($queue);
					//run the middleware against our controller
					$response = $relay($request, $response);
					//finally if all our middleware passed on the response we can then run our intended controller action				
					if (!defined('PHPUNIT_BETASYNTAX_TESTSUITE') == true) { 
						$instance->$method($mm['params']);
					} 
					$this->routeFound=true;
				}
			}
		}
		if(!$this->routeFound) {
			if (defined('PHPUNIT_BETASYNTAX_TESTSUITE') == true) { 
				return true;
			} else {
				view('Errors/404.haml'); 	
			}
		} else {
			return false;
		}
	}
760771
protected function createRequest($service, $requestId, array $parameters = [])
    {
        try {
            return $this->factory()->create($service, $requestId, $parameters);
        } catch (RuntimeException $exception) {
            $this->logBuildError($service, $requestId, $exception);
            throw $exception;
        } catch (\Exception $exception) {
            $this->logBuildError($service, $requestId, $exception);
            throw new RequestBuildException($exception);
        }
    }
783095
public function deliverMessage(UserEventInterface $event, EventQueueInterface $queue)
    {
        if ($event->getNick() != $event->getConnection()->getNickname()) {
            $messages = $this->database->retrieveMessages($event->getNick());
            foreach ($messages as $row) {
                $message = sprintf('(%s) %s: %s',
                    (new \DateTime($row['timestamp']))->format('m/d h:ia'),
                    $row['sender'],
                    $row['message']);
                $queue->ircNotice($event->getNick(), $message);
            }
        }
    }
242614
public function load($userid, $apikey, $scope, $name, $args)
    {
        $key = $this->getKey($userid, $apikey, $scope, $name, $args);
        return (string) $this->memcache->get($key);
    }
21714
@Override
  public void doUserDataRequestEvent(ServerShSession session, UserDataRequest request)
      throws InternalException, IllegalDiameterStateException, RouteException, OverloadException {
    // TODO Auto-generated method stub
  }
842579
public function load($userid, $apikey, $scope, $name, $args)
    {
        $this->prepareStatements();

        $argumentString = $this->serializeArguments($args);

        $statement = $this->statements['load'];
        /* @var $statement \PDOStatement */

        if ($userid === null) {
            // Fix for null value userids
            // e. g. for global calls to /eve/
            $userid = 0;
        }

        try {
            $statement->execute(
                array(
                    ':userId' => $userid,
                    ':scope'  => $scope,
                    ':name'   => $name,
                    ':args'   => $argumentString,
                )
            );

            $result = $statement->fetch();
        } catch (\PDOException $e) {
            throw new PhealException('Loading from cache failed!', null, $e);
        }

        if (empty($result)) {
            return false;
        }

        if (!$this->validateCache($result['cachedUntil'])) {
            return false;
        }

        return $result['xml'];
    }
17777
public function onKickChannels(UserEventInterface $event, EventQueueInterface $queue)
    {
        $this->joinOnMatch($event->getParams()['user'], $event, $queue);
    }
1012191
public static function get_download_link(\context_user $usercontext, $requestid) {
        $downloadurl = moodle_url::make_pluginfile_url($usercontext->id,
                'tool_dataprivacy', 'export', $requestid, '/', 'export.zip', true);
        $downloadtext = get_string('download', 'tool_dataprivacy');
        return new \action_menu_link_secondary($downloadurl, null, $downloadtext);
    }
427085
public static function can_create_data_deletion_request_for_children(int $userid, int $requesterid = null): bool {
        global $USER;
        $requesterid = $requesterid ?: $USER->id;
        return has_capability('tool/dataprivacy:makedatadeletionrequestsforchildren', \context_user::instance($userid),
            $requesterid);
    }
1187560
public GetQYUserInviteResponse invite(String userid){
        BeanUtil.requireNonNull(userid, "userid is null");
        GetQYUserInviteResponse response;
        String url = BASE_API_URL + "cgi-bin/invite/send?access_token=#";
        final Map<String, String> params = new HashMap<String, String>();
        params.put("userid", userid);
        BaseResponse r = executePost(url, JSONUtil.toJson(params));
        String resultJson = isSuccess(r.getErrcode()) ? r.getErrmsg() : r.toJsonString();
        response = JSONUtil.toBean(resultJson, GetQYUserInviteResponse.class);
        return response;
    }
682246
public function post($url, $requestBody = null) {
        $posturl = $this->url . $url;
        return $this->restRequest($posturl, 'POST', $requestBody);
    }
134229
protected function emitUrlEvents($requestId, $url, UserEvent $event, EventQueue $queue)
    {
        $host = Url::extractHost($url);

        $eventName = 'url.host.' . $host;
        if (count($this->emitter->listeners($eventName)) > 0) {
            $this->logDebug('[' . $requestId . ']Emitting: ' . $eventName);
            $this->emitter->emit($eventName, [$url, $event, $queue]);
            return false;
        } else {
            return true;
        }
    }
868359
function queueOrRequest( el ){
			var url = el.data( "url" );
			if( o.proxy && $.inArray( url, urllist ) === -1 ){
				urllist.push( url );
				elQueue = elQueue.add( el );
			}
			else{
				AI.makeReq( url, el );
			}
		}
1096046
public static function create_contact_request(int $userid, int $requesteduserid) : \stdClass {
        global $DB, $PAGE;

        $request = new \stdClass();
        $request->userid = $userid;
        $request->requesteduserid = $requesteduserid;
        $request->timecreated = time();

        $request->id = $DB->insert_record('message_contact_requests', $request);

        // Send a notification.
        $userfrom = \core_user::get_user($userid);
        $userfromfullname = fullname($userfrom);
        $userto = \core_user::get_user($requesteduserid);
        $url = new \moodle_url('/message/pendingcontactrequests.php');

        $subject = get_string('messagecontactrequestsnotificationsubject', 'core_message', $userfromfullname);
        $fullmessage = get_string('messagecontactrequestsnotification', 'core_message', $userfromfullname);

        $message = new \core\message\message();
        $message->courseid = SITEID;
        $message->component = 'moodle';
        $message->name = 'messagecontactrequests';
        $message->notification = 1;
        $message->userfrom = $userfrom;
        $message->userto = $userto;
        $message->subject = $subject;
        $message->fullmessage = text_to_html($fullmessage);
        $message->fullmessageformat = FORMAT_HTML;
        $message->fullmessagehtml = $fullmessage;
        $message->smallmessage = '';
        $message->contexturl = $url->out(false);
        $userpicture = new \user_picture($userfrom);
        $userpicture->includetoken = $userto->id; // Generate an out-of-session token for the user receiving the message.
        $message->customdata = [
            'notificationiconurl' => $userpicture->get_url($PAGE)->out(false),
            'actionbuttons' => [
                'accept' => get_string_manager()->get_string('accept', 'moodle', null, $userto->lang),
                'reject' => get_string_manager()->get_string('reject', 'moodle', null, $userto->lang),
            ],
        ];

        message_send($message);

        return $request;
    }