PHPackages                             iamshobe/flight - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Framework](/categories/framework)
4. /
5. iamshobe/flight

ActiveFramework[Framework](/categories/framework)

iamshobe/flight
===============

Lightweight PHP framework for dispatching and routing

v0.2.2(7y ago)0221MITPHP

Since Jul 21Pushed 7y agoCompare

[ Source](https://github.com/IamShobe/flight)[ Packagist](https://packagist.org/packages/iamshobe/flight)[ RSS](/packages/iamshobe-flight/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (4)DependenciesVersions (5)Used By (0)

Flight - Simplified PHP Framework
=================================

[](#flight---simplified-php-framework)

This framework is used for simple web navigation. Originally I wanted something similar to Python Django framework but simpler, and I wanted to experience development of a web framework - just for a fun side project.

The first basic dispatcher I came across was , but I wanted something a little more complicated (with support of nested uris and regex!), so part of the code is taken from that repo and got wrapped with classes.

### How to Install?

[](#how-to-install)

in your project:

```
$ composer require iamshobe/flight
$ composer update  # if already installed
```

```
require_once "./vendor/autoload.php";
```

### Documentation

[](#documentation)

##### \\Flight

[](#flight)

###### class Dispatcher($base\_dir, $urls, $use\_static=true)

[](#class-dispatcherbase_dir-urls-use_statictrue)

$base\_dir - is the directory of the application root. $urls - the root urls array using URL class objects. $use\_static - true/false if the app uses static folder.

Dispatcher::dispatch(...$args) - the dispatch method - call at the end of the main file.

- ...$args - arguments to send to all the views.

##### \\Flight\\URLS

[](#flighturls)

###### class URL($regex, $handler, $methods = \["GET", "POST", "PUT", "DELETE", "PATCH"\])

[](#class-urlregex-handler-methods--get-post-put-delete-patch)

$regex - the regex of the uri. $handler - an handler view that will be called. $methods - which methods should the url be active on.

###### class IncludeURLS($urls)

[](#class-includeurlsurls)

$urls - the expanded sub urls that should be included from a different location.

##### \\Flight\\Views

[](#flightviews)

###### class View()

[](#class-view)

View::\_\_invoke($vars) - this method should be overrided by inheriting views. the return value should be a response function that will be activated once the view is on.

static View::response($data, $status\_code = 200, $headers = \[\]) - a response function. $data - the data to send $status\_code - response status code. $headers - the headers of the response.

View::static\_file($path) - serve a static file. $path - the path of the file.

View::page($path, $vars) - render a phtml file. $path - the path of the file. $vars - the vars that should be passed to the template file.

###### class StaticFile()

[](#class-staticfile)

static file serve view.

### How to Use Example

[](#how-to-use-example)

.htaccess file:

```
RewriteEngine On

RewriteCond %{REQUEST_URI} !^/index.php$
RewriteRule .* ./index.php

```

your project working tree:

```
project_dir/
+-- vendor/
|   +-- .....(libs)....
|   +-- autoload.php
+-- src/
|   +-- URLS
|   |   +-- URLS.php
|   +-- Views
|   |   +-- Index.php
|   |   +-- File.php
+-- static/
|  +-- js/
|  |  +-- test.js
+-- template/
|  +-- index.phtml
+-- index.php

```

src/Views/Index.php:

```
