2017 © Pedro Peláez
 

library server

Express style server

image

eden/server

Express style server

  • Friday, November 13, 2015
  • by cblanquera
  • Repository
  • 4 Watchers
  • 1 Stars
  • 7,615 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 1 % Grown

The README.md

logo Eden Server

Build Status

====, (*1)

, (*2)

Install

composer install eden/server, (*3)

====, (*4)

, (*5)

Introduction

Eden Server is an Express style web service. It allows all kinds of webframeworks to be developed because heavily relies on external middleware. A quick example of this usage is found below., (*6)

eden('server')
    ->route('*', function($request, $response) {
        $response->set('body', 'Hello World!');
    })
    ->render();

There are 3 kinds of middleware it accepts and are called during specific times during the response process., (*7)

Global Middleware

Global Middleware are called before any response is generated. Some examples of global middleware can be, (*8)

  • Security - like CSRF checking, Captcha, CORS, HTPASSWD, etc.
  • API - like Facebook Login, Paypal, etc.
  • Utility - like geoip, localization, internationalization, etc.

You can simply add global middleware in this fashion., (*9)

eden('server')->add(function($request, $response) {
    $response->set('body', 'Hello World!');
});

Route Middleware

Route Middleware are called when the request is formed right after the Global Middleware. To make a route available you will need the request method, desired route path and the callback handler., (*10)

You can simply add route middleware in this fashion., (*11)

eden('server')->route('POST', '/some/path/*/foo', function($request, $response) {
    $response->set('body', 'Hello World!');
});

Routes can accept dynamic variables denoted as *, described in the example route /some/path/*/foo. These variables are accessable by calling $id = $request->get('variables', 0); in your route handler callback. If your route is using a common request method like POST, GET, PUT, DELETE, there are wrapper methods recommended to use instead., (*12)

eden('server')->post('/some/path/*/foo', function($request, $response) {
    $response->set('body', 'Hello World!');
});
eden('server')->get('/some/path/*/foo', function($request, $response) {
    $response->set('body', 'Hello World!');
});
eden('server')->put('/some/path/*/foo', function($request, $response) {
    $response->set('body', 'Hello World!');
});
eden('server')->delete('/some/path/*/foo', function($request, $response) {
    $response->set('body', 'Hello World!');
});

For all the above methods you can also set the response by returning the string like below., (*13)

eden('server')->get('/some/path/*/foo', function($request, $response) {
    return 'Hello World';
});

Error Middleware

Error Middleware are called when either the Global or the Route Middleware throws an Exception. You can simply add an error middleware in this fashion., (*14)

eden('server')->error(function(
        $request, 
        $response, 
        $type,
        $level,
        $class,
        $file,
        $line,
        $message
    ) {
        $response->set('body', 'Hello World!');
    });

====, (*15)

, (*16)

API

====, (*17)

, (*18)

add

Adds global middleware, (*19)

Usage

eden('server')->add(function $callback);

Parameters

  • function $callback - The middleware handler

Returns Eden\Server\Index, (*20)

Example

eden('server')->add(function($request, $response) {
    $response->set('body', 'Hello World!');
});

====, (*21)

, (*22)

all

Adds routing middleware for all methods, (*23)

Usage

eden('server')->all(string $path, function $callback);

Parameters

  • string $path - The route path
  • function $callback - The middleware handler

Returns Eden\Server\Index, (*24)

Example

eden('server')->all('/some/*/path', function($request, $response) {
    $response->set('body', 'Hello World!');
});

====, (*25)

, (*26)

child

Returns a new instance with the same configuration, (*27)

Usage

eden('server')->child();

Parameters

Returns Eden\Server\Index, (*28)

====, (*29)

, (*30)

delete

Adds routing middleware for delete method, (*31)

Usage

eden('server')->delete(string $path, function $callback);

Parameters

  • string $path - The route path
  • function $callback - The middleware handler

Returns Eden\Server\Index, (*32)

Example

eden('server')->delete('/some/*/path', function($request, $response) {
    $response->set('body', 'Hello World!');
});

====, (*33)

, (*34)

error

Adds error middleware, (*35)

Usage

eden('server')->error(function $callback);

Parameters

  • function $callback - The middleware handler

Returns Eden\Server\Index, (*36)

Example

eden('server')->error('/some/*/path', function($request, $response) {
    $response->set('body', 'Hello World!');
});

====, (*37)

, (*38)

get

Adds routing middleware for get method, (*39)

Usage

eden('server')->get(string $path, function $callback);

Parameters

  • string $path - The route path
  • function $callback - The middleware handler

Returns Eden\Server\Index, (*40)

Example

eden('server')->get('/some/*/path', function($request, $response) {
    $response->set('body', 'Hello World!');
});

====, (*41)

, (*42)

getRequest

Returns a request object, (*43)

Usage

eden('server')->getRequest();

Parameters

Returns Eden\Registry\Index, (*44)

====, (*45)

, (*46)

getResponse

Returns a response object, (*47)

Usage

eden('server')->getResponse();

Parameters

Returns Eden\Registry\Index, (*48)

====, (*49)

, (*50)

getParent

Returns the parent server, (*51)

Usage

eden('server')->getParent();

Parameters

Returns Eden\Server\Index, (*52)

====, (*53)

, (*54)

output

Evaluates the response in order to determine the output. Then of course, output it, (*55)

Usage

eden('server')->output(Eden\Registry\Index $response);

Parameters

  • Eden\Registry\Index $response - The response object to evaluate

Returns Eden\Server\Index, (*56)

Example

eden('server')->output($response);

====, (*57)

, (*58)

post

Adds routing middleware for post method, (*59)

Usage

eden('server')->post(string $path, function $callback);

Parameters

  • string $path - The route path
  • function $callback - The middleware handler

Returns Eden\Server\Index, (*60)

Example

eden('server')->post('/some/*/path', function($request, $response) {
    $response->set('body', 'Hello World!');
});

====, (*61)

, (*62)

process

Starts to process the request, (*63)

Usage

eden('server')->process();

Parameters

Returns array - with request and response inside, (*64)

====, (*65)

, (*66)

put

Adds routing middleware for put method, (*67)

Usage

eden('server')->put(string $path, function $callback);

Parameters

  • string $path - The route path
  • function $callback - The middleware handler

Returns Eden\Server\Index, (*68)

Example

eden('server')->put('/some/*/path', function($request, $response) {
    $response->set('body', 'Hello World!');
});

====, (*69)

, (*70)

redirect

Browser redirect, (*71)

Usage

eden('server')->redirect(string $path);

Parameters

  • string $path - Where to redirect to

Returns mixed, (*72)

Example

eden('server')->redirect();

====, (*73)

, (*74)

render

Process and output, (*75)

Usage

eden('server')->render();

Parameters

Returns Eden\Server\Index, (*76)

====, (*77)

, (*78)

route

Adds routing middleware, (*79)

Usage

eden('server')->route(string $method, string $path, function $callback);

Parameters

  • string $method - The request method
  • string $path - The route path
  • function $callback - The middleware handler

Returns Eden\Server\Index, (*80)

Example

eden('server')->route('POST', '/some/*/path', function($request, $response) {
    $response->set('body', 'Hello World!');
});

====, (*81)

, (*82)

setParent

Returns if we were able to output something, (*83)

Usage

eden('server')->setParent(Eden\Server\Index $parent);

Parameters

  • Eden\Server\Index $parent - The parent server

Returns Eden\Server\Index, (*84)

Example

eden('server')->setParent($parent);

====, (*85)

, (*86)

success

Returns if we were able to output something, (*87)

Usage

eden('server')->success();

Parameters

Returns bool, (*88)

====, (*89)

, (*90)

Contributing to Eden

Contributions to Eden are following the Github work flow. Please read up before contributing., (*91)

Setting up your machine with the Eden repository and your fork

  1. Fork the repository
  2. Fire up your local terminal create a new branch from the v4 branch of your fork with a branch name describing what your changes are. Possible branch name types:
    • bugfix
    • feature
    • improvement
  3. Make your changes. Always make sure to sign-off (-s) on all commits made (git commit -s -m "Commit message")

Making pull requests

  1. Please ensure to run phpunit before making a pull request.
  2. Push your code to your remote forked version.
  3. Go back to your forked version on GitHub and submit a pull request.
  4. An Eden developer will review your code and merge it in when it has been classified as suitable.

The Versions

13/11 2015

dev-master

9999999-dev http://eden-php.com

Express style server

  Sources   Download

MIT

The Requires

 

by Christian Blanquera

library eden

13/11 2015

4.0.2

4.0.2.0 http://eden-php.com

Express style server

  Sources   Download

MIT

The Requires

 

by Christian Blanquera

library eden

13/11 2015

4.x-dev

4.9999999.9999999.9999999-dev http://eden-php.com

Express style server

  Sources   Download

MIT

The Requires

 

by Christian Blanquera

library eden

13/10 2015

4.0.1

4.0.1.0 http://eden-php.com

Express style server

  Sources   Download

MIT

The Requires

 

by Christian Blanquera

library eden

06/10 2015

v4.0.0

4.0.0.0 http://eden-php.com

Express style server

  Sources   Download

MIT

The Requires

 

by Christian Blanquera

library eden