Defines REST API callbacks

@return bool
168557
public function apiInit() {
		try {
			if ( ! is_plugin_active( 'h5p/h5p.php' ) ) {
				\H5P_Plugin::get_instance()->rest_api_init();
			}
			if ( get_option( 'blog_public' ) ) {
				add_filter( 'h5p_rest_api_all_permission', '__return_true' );
			}
		} catch ( \Throwable $e ) {
			return false;
		}
		return true;
	}
389641
public static function dispatch()
    {
        $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
        $method = $_SERVER['REQUEST_METHOD'];

        $searches = array_keys(static::$patterns);
        $replaces = array_values(static::$patterns);

        $found_route = false;

        self::$routes = preg_replace('/\/+/', '/', self::$routes);

        // Check if route is defined without regex
        if (in_array($uri, self::$routes)) {
            $route_pos = array_keys(self::$routes, $uri);
            foreach ($route_pos as $route) {

                // Using an ANY option to match both GET and POST requests
                if (self::$methods[$route] == $method || self::$methods[$route] == 'ANY' || in_array($method, self::$maps[$route])) {
                    $found_route = true;

                    // If route is not an object
                    if (!is_object(self::$callbacks[$route])) {

                        // Grab all parts based on a / separator
                        $parts = explode('/', self::$callbacks[$route]);

                        // Collect the last index of the array
                        $last = end($parts);

                        // Grab the controller name and method call
                        $segments = explode('@', $last);

                        // Instanitate controller
                        $controller = new $segments[0]();

                        // Call method
                        $controller->{$segments[1]}();

                        if (self::$halts) return;
                    } else {
                        // Call closure
                        call_user_func(self::$callbacks[$route]);

                        if (self::$halts) return;
                    }
                }
            }
        } else {
            // Check if defined with regex
            $pos = 0;
            foreach (self::$routes as $route) {
                if (strpos($route, ':') !== false) {
                    $route = str_replace($searches, $replaces, $route);
                }

                if (preg_match('#^' . $route . '$#', $uri, $matched)) {
                    if (self::$methods[$pos] == $method || self::$methods[$pos] == 'ANY' || in_array($method, self::$maps[$pos])) {
                        $found_route = true;

                        // Remove $matched[0] as [1] is the first parameter.
                        array_shift($matched);

                        if (!is_object(self::$callbacks[$pos])) {

                            // Grab all parts based on a / separator
                            $parts = explode('/', self::$callbacks[$pos]);

                            // Collect the last index of the array
                            $last = end($parts);

                            // Grab the controller name and method call
                            $segments = explode('@', $last);

                            // Instanitate controller
                            $controller = new $segments[0]();

                            // Fix multi parameters
                            if (!method_exists($controller, $segments[1])) {
                                echo "controller and action not found";
                            } else {
                                call_user_func_array(array($controller, $segments[1]), $matched);
                            }

                            if (self::$halts) return;
                        } else {
                            call_user_func_array(self::$callbacks[$pos], $matched);

                            if (self::$halts) return;
                        }
                    }
                }
                $pos++;
            }
        }

        // Run the error callback if the route was not found
        if ($found_route == false) {
            if (!self::$error_callback) {
                self::$error_callback = function () {
                    header($_SERVER['SERVER_PROTOCOL'] . " 404 Not Found");
                    throw new \Exception(Config::get('error_message'));
                };
            } else {
                if (is_string(self::$error_callback)) {
                    self::get($_SERVER['REQUEST_URI'], self::$error_callback);
                    self::$error_callback = null;
                    self::dispatch();
                    return;
                }
            }
            call_user_func(self::$error_callback);
        }
    }
876862
public function callback() {
		$timestamp = date('c');

		// To standardize the way of accessing data, objects are translated to arrays
		$this->auth = $this->recursiveGetObjectVars($this->auth);

		$this->auth['provider'] = $this->strategy['strategy_name'];

		$params = array(
			'auth' => $this->auth,
			'timestamp' => $timestamp,
			'signature' => $this->sign($timestamp)
		);

		$this->shipToCallback($params);
	}
1123464
protected function bindAuthForApiToken()
    {
        Auth::viaRequest('api', function ($request) {
            if ($request->input('api_token')) {
                return User::where('api_token', $request->input('api_token'))->first();
            }
        });
    }
1046477
private function callApiEdit()
    {
        $this->callApiTokens();
        $result = $this->callApi('action=edit&token=' . urlencode($this->apiEditToken), $this->getApiEditData());
        $this->checkApiResponseResult('edit', $result);
    }
1173876
public function callbackSubmit()
    {
        // Get values from the submitted form
        $email       = $this->form->value("email");

        if (strpos($email, '%') !== false) {
            $this->form->addOutput("% is not allowed");
            return false;
        }


        if (!$this->di->get('session')->get("user")) {
            return false;
        }
        $name = $this->di->get('session')->get("user");
          $user = new User();
          $user->setDb($this->di->get("db"));
          $user->find("name", $name);

          $user->email = $email;
          $user->save();
          return true;
    }
1374755
public function transform() {
        $this->resListCallBack = $this->listCallBack->map(function ($call) {
            return new HttpCallBack(
                $call['method'],   
                $call['path'],
                $call['fn']
            );
            
        });
    }
279273
public function listHostedServices()
    {
        $context = new HttpCallContext();
        $context->setMethod(Resources::HTTP_GET);
        $context->setPath($this->_getHostedServicePath());
        $context->addStatusCode(Resources::STATUS_OK);

        $response = $this->sendHttpContext($context);
        $serialized = $this->dataSerializer->unserialize($response->getBody());

        return ListHostedServicesResult::create($serialized);
    }
462444
public function callbackSubmit()
    {
        // Get values from the submitted form
        $username       = $this->form->value("username");
        $password       = $this->form->value("password");

        // Connect to databse and se if user exists and if so compare password
        $user = new User();
        $user->setDb($this->di->get("db"));
        $res = $user->verifyPassword($username, $password);

        if (!$res) {
            $this->form->rememberValues();
            $this->form->addOutput("User or password did not match.");
            return false;
        }

        // Get the user
        $user->find("username", $username);

        // Check if user is deleted
        if (isset($user->deleted)) {
            $this->form->rememberValues();
            $this->form->addOutput("User is inactive. Contact administrator.");
            return false;
        }

        // Save user to session
        $this->di->get("session")->set("user_id", $user->id);
        $this->di->get("session")->set("username", $user->username);
        $this->di->get("session")->set("user_role", $user->role);

        // Redirect to profile page
        $this->di->get("response")->redirect($this->di->get("url")->create("comment"));
    }
1344401
protected function setApiClient()
    {
        $apiDomain = "https://{$this->domain}";

        $client = new ApiClient(
            [
                'domain' => $apiDomain,
                'basePath' => '/',
                'guzzleOptions' => $this->guzzleOptions
            ]
        );

        $this->apiClient = $client;
    }
620058
protected function do_request() {

		return $this->client->make_api_call( $this->request_method, $this->get_endpoint_path(), $this->get_request_data() );
	}
684239
public function dispatch()
    {
        foreach ($this->middleware as $mw) {
            call_user_func_array($mw, array($this));
        }

        $return = call_user_func_array($this->getCallable(), array_values($this->getParams()));
        return ($return === false) ? false : true;
    }
653738
protected function call_hook()
    {
        $args = func_get_args();
        $name = array_shift($args);

        if ($this->has_hook($name)) {
            $callback = $this->_hooks[$name];

            if ( ! is_callable($callback)) {
                return false;
            }

            if (is_php('5.4.0') and $callback instanceof Closure) {
                $callback->bindTo($this);
            }

            return call_user_func_array($callback, $args);
        }

        return false;
    }
165398
public static function dispatch()
    {
        $uri = strtok($_SERVER["REQUEST_URI"],'?');
        $qs = parse_url($_SERVER["REQUEST_URI"], PHP_URL_QUERY);
        $method = $_SERVER['REQUEST_METHOD'];
        
        
        foreach (self::$routes as $name=>$route) {


            $route  = self::parsePattern($route);

            $matched = array();
            if ($route=='' || preg_match('#' . $route . '#', $uri, $matched) && (self::$methods[$name] == 'ANY' || self::$methods[$name] == $method)) {
                
                array_shift($matched);

                if (self::$qs[$name]!='' && preg_match('#' . self::$qs[$name] . '#', $qs, $qsmatched)) {

                    array_shift($qsmatched);

                    $matched = array_merge($matched, $qsmatched);
                    self::$catched[] = $name;
                    BurpEvent::listen($name, self::$callbacks[$name]);
                    BurpEvent::queue($name, $matched);

                } elseif (self::$qs[$name] == '') {
                    self::$catched[] = $name;
                    BurpEvent::listen($name, self::$callbacks[$name]);
                    BurpEvent::queue($name, $matched);
                }
            }

        }

        //call missing if needed
        if (!is_null(self::$missing_callback) ) {
            $diff = array_diff(self::$tocatch, self::$catched);
            if (count($diff) >= count(self::$tocatch)) {
                call_user_func(self::$missing_callback);
                BurpEvent::listen('missing', self::$callbacks[$name]);
                BurpEvent::fire('missing');

            }

        }

        BurpEvent::flushAll();
    }
829442
public static function dispatch()
    {

        $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
        $method = $_SERVER['REQUEST_METHOD'];

        $searches = array_keys(static::$patterns);
        $replaces = array_values(static::$patterns);

        self::$routes = str_replace('//', '/', self::$routes);

        $foundRoute = false;

        // Parse query parameters
        {
            $query = '';
            $q_arr = array();
            if (strpos($uri, '&') > 0) {
                $query = substr($uri, strpos($uri, '&') + 1);
                $uri = substr($uri, 0, strpos($uri, '&'));
                $q_arr = explode('&', $query);
                foreach ($q_arr as $q) {
                    $qobj = explode('=', $q);
                    $q_arr[] = array($qobj[0] => $qobj[1]);
                    if (!isset($_GET[$qobj[0]])) {
                        $_GET[$qobj[0]] = $qobj[1];
                    }
                }
            }
        }

        // Check if route is defined without regex

        if (in_array($uri, self::$routes)) {

            $routePos = array_keys(self::$routes, $uri);

            // Foreach route position
            foreach ($routePos as $route) {

                if (self::$methods[$route] == $method || self::$methods[$route] == 'ANY') {
                    $foundRoute = true;

                    // If route is not an object

                    if (!is_object(self::$callbacks[$route])) {

                        // Call object controller and method

                        self::invokeObject(self::$callbacks[$route]);
                        if (self::$halts) return;

                    } else {

                        // Call closure

                        call_user_func(self::$callbacks[$route]);
                        if (self::$halts) return;

                    }
                }

            }

        } else {

            // Check if defined with regex
            $pos = 0;

            // Foreach routes

            foreach (self::$routes as $route) {

                $route = str_replace('//', '/', $route);

                if (strpos($route, ':') !== false) {
                    $route = str_replace($searches, $replaces, $route);
                }

                if (preg_match('#^' . $route . '$#', $uri, $matched)) {

                    if (self::$methods[$pos] == $method || self::$methods[$pos] == 'ANY') {
                        $foundRoute = true;

                        // Remove $matched[0] as [1] is the first parameter.

                        array_shift($matched);

                        if (!is_object(self::$callbacks[$pos])) {

                            // Call object controller and method

                            self::invokeObject(self::$callbacks[$pos], $matched);
                            if (self::$halts) return;

                        } else {

                            // Call closure
                            call_user_func_array(self::$callbacks[$pos], $matched);
                            if (self::$halts) return;

                        }
                    }
                }

                $pos++;
            }
        }

        // Run the error callback if the route was not found

        if (!$foundRoute) {

            if (!self::$errorCallback) {

                self::$errorCallback = function () {
                    header($_SERVER['SERVER_PROTOCOL'] . " 404 Not Found");
                    echo '404';
                };
            }

            if (!is_object(self::$errorCallback)) {

                // Call object controller and method
                self::invokeObject(self::$errorCallback, null, 'No routes found.');
                if (self::$halts) return;

            } else {

                call_user_func(self::$errorCallback);
                if (self::$halts) return;

            }
        }
    }
14654
private function callApiTokens()
    {
        $result = $this->callApi('action=tokens&type=edit');
        if (false == isset($result['tokens']) || false == isset($result['tokens']['edittoken'])) {
            throw new BuildException('Wiki token not found');
        }

        $this->apiEditToken = $result['tokens']['edittoken'];
    }
39352
public function call()
    {
        if ('application/json' !== $this->app->request()->headers('Accept')) {

            $this->next->call();

            return; //Only JSON can be turned into JSONP
        }

        $callback = $this->app->request()->get('callback');

        $this->next->call();

        if (empty($callback)) {
            return; //Not a JSONP request
        }

        $this->app->contentType('application/javascript');
        $jsonp = htmlspecialchars($callback) . "(" .$this->app->response()->body() . ")";

        $this->app->response()->body($jsonp);
    }