# php-built-in-web-server-router

> A router library for your PHP Built-in Webserver.

Latest version **1.6.1** (published 2018-06-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install php-built-in-web-server-router
pnpm add php-built-in-web-server-router
yarn add php-built-in-web-server-router
bun add php-built-in-web-server-router
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.6.1 |
| Published | 2018-06-17 |
| First published | 2017-07-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 827.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 11 |
| Author | darklightcode |
| Maintainers | darklightcode |
| Keywords | php-router, router.php, router-development, php built-in webserver, php webserver, php development, node-php-awesome-server |

## Links

- npm: https://www.npmjs.com/package/php-built-in-web-server-router
- Repository: https://github.com/darklightcode/PHP-Built-in-web-server-Router
- Homepage: https://github.com/darklightcode/PHP-Built-in-web-server-Router#readme
- Issues: https://github.com/darklightcode/PHP-Built-in-web-server-Router/issues
- npm.io page: https://npm.io/package/php-built-in-web-server-router

## Alternatives

- [express-promise-router](https://npm.io/package/express-promise-router.md) — 736.1K weekly downloads
- [next-usequerystate](https://npm.io/package/next-usequerystate.md) — 29.8K weekly downloads
- [@bitkyc08/opencodex](https://npm.io/package/@bitkyc08/opencodex.md) — 4.6K weekly downloads
- [lynkr](https://npm.io/package/lynkr.md) — 575 weekly downloads
- [baremetal.js](https://npm.io/package/baremetal.js.md) — 42 weekly downloads

## Recent versions

- 1.6.1 (latest) — 2018-06-17
- 1.6.0 — 2018-06-17
- 1.5.1 — 2017-12-02
- 1.5.0 — 2017-12-01
- 1.4.0 — 2017-10-31
- 1.3.0 — 2017-10-17
- 1.2.3 — 2017-08-04
- 1.2.2 — 2017-07-26
- 1.2.1 — 2017-07-26
- 1.2.0 — 2017-07-17
- 1.1.0 — 2017-07-17
- 1.0.0 — 2017-07-17

## README

# **Use this only in a development environment**

# PHP-Built-in-web-server-Router
![PHP-Built-in-web-server-Router](./src/php_5.png)
![PHP-Built-in-web-server-Router](./src/php_7.png)

This library comes with **caching support** for [**PHP built-in web-server**](http://php.net/manual/en/features.commandline.webserver.php)

Router.php is loaded before index.php, so you can:
* Have **CORS** enabled 
* Set up your environment variables and constants
* And **CACHE EVERYTHING**

It also comes with a custom console function to output string|array into terminal ( check out index.php for usage ).

Don't forget to delete it after usage, this function is meant only for Development !

```console_output( $string , 'another', array('show'=>1) , ...args )```

### NODE.JS
I highly recommend [node-php-awesome-server](https://www.npmjs.com/package/node-php-awesome-server) if you need a php webserver in a node environment, it uses this router as default router, and much more various configuration options.
```
npm install node-php-awesome-server --save-dev
```
If you install this as a npm package you can only retrieve the absolute paths of the router, the library file and a cURL certificate.
```
npm install php-built-in-web-server-router --save-dev
```
```javascript
let router = require('php-built-in-web-server-router');

console.log('Router path: ', router.path);
console.log('Router library: ', router.lib);
console.log('cURL certificate: ', router.cert);

```

# Requirements
PHP 5.4.0+ and /src/mimes.json file.

# Usage

Bellow you'll find a few examples. Additional params may be found [here](http://php.net/manual/en/features.commandline.webserver.php)

1. If router.php is located in the root folder
```cli
php -S localhost:8000 router.php
```
2. If router.php is located in separate folder:
```cli
php -S localhost:8000 misc/router.php
```
3. If your project structure is something like this, use '-t' parameter to set the document root to your public folder

```
./www/
    - your_php_framework/
        - private_framework_stuff/
          ...
        - public/
    - misc/
        - router.php
        - mimes.json
    - onefile.php
    
    
 php -S localhost:8000 -t ./your_php_framework/public misc/router.php 
```

# Edit router.php

This are the default settings.


```
# class PHP_Webserver_Router{...}
#    or   

include('router.class.php');
    
###
# Set up early your environment variables/constants
###
    
$_SERVER["ENVIRONMENT"] = "development";
error_reporting(E_ALL);

 
$php_web_server = new PHP_Webserver_Router();

    
###
# Uncomment to Disable http output in console:
###
//$php_web_server->log_enable = FALSE;

###
# Change this if your "index.php" has another name. By default is index.php
###
//$php_web_server->indexPath = "my_new_index_file.php";

return $php_web_server->listen();
```

# Notes
I've tested this with the following php frameworks:
* Slim 3 ( **the newest addition to this list** )
* Yii2
* CodeIgniter 3
* Wordpress 4
* Drupal 7 and 8

On the first request sent to router.php, it will attempt to download and create mimes.json, if that fails, you can find mimes.json in ./src/ and copy it next to router.php

Personally I bind the webserver to ```php -S 0.0.0.0 ...``` so I can test from other remote devices.

# Thanks
The method create_mime_file() is a modified version of [Josh Sean's generateUpToDateMimeArray function](http://php.net/manual/ro/function.mime-content-type.php#107798)

---
_Source: https://npm.io/package/php-built-in-web-server-router · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
