# Want to setup a Skeleton/Boilerplate project quickly?
Head over to the [flightphp/skeleton](https://github.com/flightphp/skeleton) repo to get started!
# Requirements
Flight requires `PHP 7.4` or greater.
# License
Flight is released under the [MIT](http://docs.flightphp.com/license) license.
# Installation
**1\. Download the files.**
If you're using [Composer](https://getcomposer.org), you can run the following
command:
```bash
composer require flightphp/core
```
OR you can [download](https://github.com/flightphp/core/archive/master.zip)
them directly and extract them to your web directory.
**2\. Configure your webserver.**
For *Apache*, edit your `.htaccess` file with the following:
```
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
```
> **Note**: If you need to use flight in a subdirectory add the line
> `RewriteBase /subdir/` just after `RewriteEngine On`.
> **Note**: If you want to protect all server files, like a db or env file.
> Put this in your `.htaccess` file:
```
RewriteEngine On
RewriteRule ^(.*)$ index.php
```
For *Nginx*, add the following to your server declaration:
```
server {
location / {
try_files $uri $uri/ /index.php;
}
}
```
**3\. Create your `index.php` file.**
First include the framework.
```php
require 'flight/Flight.php';
```
If you're using Composer, run the autoloader instead.
```php
require 'vendor/autoload.php';
```
Then define a route and assign a function to handle the request.
```php
Flight::route('/', function () {
echo 'hello world!';
});
```
Finally, start the framework.
```php
Flight::start();
```
## Skeleton App
## Skeleton App
Additionally you could install a skeleton app. Go to [flightphp/skeleton](https://github.com/flightphp/skeleton) for instructions on how to get started!
You can also install a skeleton app. Go to [flightphp/skeleton](https://github.com/flightphp/skeleton) for instructions on how to get started!
# Routing
Routing in Flight is done by matching a URL pattern with a callback function.
```php
# Documentation
Flight::route('/', function () {
echo 'hello world!';
});
```
The callback can be any object that is callable. So you can use a regular function:
```php
We have our own documentation website that is built with Flight (naturally). Learn more about the framework at [docs.flightphp.com](https://docs.flightphp.com).
function hello() {
echo 'hello world!';
}
Flight::route('/', 'hello');
```
Or a class method:
```php
class Greeting {
static function hello() {
echo 'hello world!';
}
}
Flight::route('/', [Greeting::class, 'hello']);
```
Or an object method:
```php
class Greeting {
private $name;
function __construct() {
# Community
$this->name = 'John Doe';
}
function hello() {
Chat with us on Matrix IRC [#flight-php-framework:matrix.org](https://matrix.to/#/#flight-php-framework:matrix.org)
echo "Hello, $this->name!";
}
}
$greeting = new Greeting;
Flight::route('/', [$greeting, 'hello']);
```
Routes are matched in the order they are defined. The first route to match a
request will be invoked.
# Configuration
You can customize certain behaviors of Flight by setting configuration values
through the `set` method.
```php
Flight::set('flight.log_errors', true);
```
The following is a list of all the available configuration settings:
- **flight.base_url** - Override the base url of the request. (default: null)
- **flight.case_sensitive** - Case sensitive matching for URLs. (default: false)
- **flight.handle_errors** - Allow Flight to handle all errors internally. (default: true)
- **flight.log_errors** - Log errors to the web server's error log file. (default: false)
Flight::register(string $name, string $class, array $params = [], ?callable $callback = null) // Registers a class to a framework method.
Flight::before(string $name, callable $callback) // Adds a filter before a framework method.
Flight::after(string $name, callable $callback) // Adds a filter after a framework method.
Flight::path(string $path) // Adds a path for autoloading classes.
Flight::get(string $key) // Gets a variable.
Flight::set(string $key, mixed $value) // Sets a variable.
Flight::has(string $key) // Checks if a variable is set.
Flight::clear(array|string $key = []) // Clears a variable.
Flight::init() // Initializes the framework to its default settings.
Flight::app() // Gets the application object instance
```
## Extensible Methods
Flight requires `PHP 7.4` or greater.
```php
**Note:** PHP 7.4 is supported because at the current time of writing (2024) PHP 7.4 is the default version for some LTS Linux distributions. Forcing a move to PHP >8 would cause a lot of heartburn for those users. The framework also supports PHP >8.
Flight::start() // Starts the framework.
Flight::stop() // Stops the framework and sends a response.
Flight::halt(int $code = 200, string $message = '') // Stop the framework with an optional status code and message.
Flight::route(string $pattern, callable $callback, bool $pass_route = false) // Maps a URL pattern to a callback.
Flight::group(string $pattern, callable $callback) // Creates groupping for urls, pattern must be a string.
Flight::redirect(string $url, int $code) // Redirects to another URL.