Giter Club home page Giter Club logo

zapheus's Introduction

Zapheus

Latest Version on Packagist Software License Build Status Coverage Status Quality Score Total Downloads

Inspired from PHP frameworks of all shape and sizes, Zapheus is a web application framework with a goal to be easy to use, educational, and fully extensible to the core. Whether a simple API project or a full enterprise application, Zapheus will try to adapt it according to developer's needs.

// Displays a "Hello World" text.

require 'vendor/autoload.php';

// Initializes the router application
$app = new Zapheus\Coordinator;

// Creates a HTTP route of GET /
$app->get('/', function ()
{
    return 'Hello world!';
});

// Handles the server request
echo $app->run();

Installation

Install Zapheus via Composer:

$ composer require zapheus/zapheus

Basic Usage

Using Coordinator

require 'vendor/autoload.php';

// Initializes the router application
$app = new Zapheus\Coordinator;

// Creates a HTTP route of GET /
$app->get('/', function ()
{
    return 'Hello world!';
});

// Handles the server request
echo $app->run();

Using Middlelayer

require 'vendor/autoload.php';

// Initializes the middleware application
$app = new Zapheus\Middlelayer;

// Initializes the router instance
$router = new Zapheus\Routing\Router;

// Creates a HTTP route of GET /
$router->get('/', function ()
{
    return 'Hello world!';
});

// Pipes the router middleware into the application
$app->pipe(function ($request, $next) use ($router)
{
    // Returns the request attribute value for a route
    $attribute = Zapheus\Application::ROUTE_ATTRIBUTE;

    // Returns the path from the URI instance
    $path = $request->uri()->path();

    // Returns the current HTTP method from the $_SERVER
    $method = $request->method();

    // Creates a new Routing\DispatcherInterface instance
    $dispatcher = new Zapheus\Routing\Dispatcher($router);

    // Dispatches the router against the current request
    $route = $dispatcher->dispatch($method, $path);

    // Sets the route attribute into the request in order to be
    // called inside the Application instance and return the response.
    $request = $request->push('attributes', $route, $attribute);

    // Go to the next middleware, if there are any
    return $next->handle($request);
});

// Handles the server request
echo $app->run();

Run the application using PHP's built-in web server:

$ php -S localhost:8000

Open your web browser and go to http://localhost:8000.

Features

No dependencies

Zapheus takes no dependencies from other frameworks or libraries. Each component is built with inspiration from the existing popular web frameworks to give developers the best development experience.

Extensible

All of Zapheus' classes have their own easy to understand interfaces. It enables developers to extend or optimize the core functionalities easily.

Interoperable

Even though Zapheus doesn't have dependencies from other libraries, it does have bridge packages to integrate your chosen libraries easily within the framework. These include the PHP Standards Recommendations (PSR) like PSR-07 and PSR-11.

// Converts a Zend Diactoros instance (a PSR-07 implementation)
// into a Zapheus HTTP request using the PSR-07 Bridge package

use Zapheus\Bridge\Psr\Zapheus\Request;
use Zend\Diactoros\ServerRequestFactory;

// Psr\Http\Message\ServerRequestInterface
$psr = ServerRequestFactory::fromGlobals();

// Zapheus\Http\Message\RequestInterface
$request = new Request($psr);

Framework-friendly

Frameworks like Laravel and Symfony have their way of integrating packages into their own ecosystem. With that, Zapheus will try to get them both work in the same application in order for the developers to utilize framework-specific packages to their arsenal.

// Registers a third-party Laravel Service Provider
// into Zapheus using the Illuminate Bridge package

use Acme\Providers\AuthServiceProvider;
use Acme\Providers\RoleServiceProvider;
use Illuminate\Container\Container;
use Zapheus\Bridge\Illuminate\IlluminateProvider;
use Zapheus\Container\Container as ZapheusContainer;

// A collection of Laravel Service Providers
$providers = array(AuthServiceProvider::class, RoleServiceProvider::class);

// Include the providers in the bridge instance
$provider = new IlluminateProvider($providers);

// Registers the bindings into a container
$container = $provider->register(new ZapheusContainer);

// Returns the Illuminate\Container\Container
$laravel = $container->get(Container::class);

Changelog

Please see CHANGELOG for more information what has changed recently.

Testing

$ composer test

Credits

License

The MIT License (MIT). Please see LICENSE for more information.

zapheus's People

Contributors

rougin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.