# flywp/0.3/includes/Api.php

FlyWP Helper – Page Cache, Page Optimization, Emails for FlyWP Server Control Panel, version 0.3. 62 lines.

- Page: https://pluginprobe.com/plugins/flywp/0.3/code/includes/Api.php
- Raw: https://pluginprobe.com/plugins/flywp/0.3/raw/includes/Api.php
- Modified: 2023-06-14T09:50:22+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/flywp/0.3/code/includes/Api.php#L10-L20`.

```php
<?php

namespace FlyWP;

/**
 * API class.
 *
 * @since 1.0.0
 */
class Api {

    /**
     * API constructor.
     */
    public function __construct() {
        $router = flywp()->router;
        $router->init();

        new Api\Ping();

        if ( ! $this->has_valid_key() ) {
            return;
        }

        new Api\Plugins();
        new Api\Themes();
        new Api\Updates();
    }

    /**
     * Check if API key is valid.
     *
     * @return bool
     */
    public function has_valid_key() {
        if ( flywp()->has_key() && flywp()->get_key() === $this->get_bearer_token() ) {
            return true;
        }

        return false;
    }

    /**
     * Get bearer token from Authorization header.
     *
     * @return string|bool
     */
    public function get_bearer_token() {
        if ( ! isset( $_SERVER['HTTP_AUTHORIZATION'] ) ) {
            return false;
        }

        $auth_header = $_SERVER['HTTP_AUTHORIZATION'];

        if ( ! preg_match( '/Bearer\s(\S+)/', $auth_header, $matches ) ) {
            return false;
        }

        return $matches[1];
    }
}

```
