Flight PHP Framework

repository·master·Indexed 25 days ago

https://github.com/flightphp/core

A fast, simple, and extensible micro-framework for PHP designed for building RESTful web applications. Flight features zero dependencies and requires PHP 7.4 or greater. It includes tools for route mapping, controller scaffolding via `make:controller`, route listing, and AI-driven coding instruction generation through commands like `ai:init` and `ai:generate-instructions`.

Tokens
1.3K
Snippets
4
Records
14
Agent score
84%

What's inside Flight

  1. Basic Usage of Flight

    master

    After installation, you can define routes and start the framework. If installed via Composer, require the vendor/autoload.php file. Use Flight::route() to map a URL pattern to a callback function, and Flight::start() to begin processing requests.

    // if installed with composer
    require 'vendor/autoload.php';
    // or if installed manually by zip file
    // require 'flight/Flight.php';
    
    Flight::route('/', function () {
      echo 'hello world!';
    });
    
    Flight::start();
  2. Configure AI provider settings via ai:init

    master

    When running ai:init, you will be prompted to select one of the following supported LLM API providers:

    1. openai (Default base URL: https://api.openai.com)
    2. grok (Default base URL: https://api.x.ai)
    3. claude (Default base URL: https://api.anthropic.com)

    After selecting a provider, you must provide a valid Base URL, an API key, and a Model name. The resulting configuration is stored in your application's ai configuration block.

  3. Configure AI credentials for instruction generation

    master

    To use the ai:generate-instructions command, you must provide AI configuration. While a --config-file option exists for legacy .runway-config.json files, it is deprecated.

    Recommended Method: Add your AI configuration to the runway key within your config.php file. The configuration requires an OpenAI-compatible structure with the following keys:

    • api_key: Your LLM API key.
    • model: The name of the model to use.
    • base_url: The base URL for the LLM API (e.g., an OpenAI-compatible endpoint).

    Example structure for config.php:

    'runway' => [
        'ai' => [
            'api_key' => 'your_api_key',
            'model' => 'gpt-4',
            'base_url' => 'https://api.openai.com/v1',
        ]
    ]
  4. Filter routes by HTTP method

    master

    When using the routes command, you can use the following flags to limit the output to specific request methods:

    • --get: Only return GET requests
    • --post: Only return POST requests
    • --delete: Only return DELETE requests
    • --put: Only return PUT requests
    • --patch: Only return PATCH requests

    If no method flag is provided, the command returns all routes.

    --get
    --post
    --delete
    --put
    --patch
  5. Create a controller with make:controller

    master

    Use the make:controller command to scaffold a new controller class. The command automatically appends the Controller suffix if it is not provided and places the file in the controllers/ directory relative to your configured app_root.

    Arguments

    • <controller>: The name of the controller to create (with or without the Controller suffix).

    Requirements

    • Your configuration must have app_root defined in your application configuration (either in app/config/config.php or a .runway-config.json file).
    • Controller names must only contain letters, numbers, and underscores.
  6. Generate project-specific AI coding instructions with `ai:generate-instructions`

    master

    The ai:generate-instructions command generates or updates project-specific AI coding instructions by prompting you for project details (such as database type, templating engine, and security requirements) and sending them to an LLM.

    It automatically updates several AI context files in your project root:

    • .github/copilot-instructions.md
    • .cursor/rules/project-overview.mdc
    • .gemini/GEMINI.md
    • .windsurfrules
    • AGENTS.md

    Prerequisites:

    • You must have run the ai:init command first to configure your AI credentials.
    • You must have an OpenAI-compatible LLM configured in your config.php under the runway key.