https://github.com/zapheus/zapheus
An independent and framework-friendly PHP micro-framework.
https://github.com/zapheus/zapheus
interoperable php-framework php-library zapheus
Last synced: 3 months ago
JSON representation
An independent and framework-friendly PHP micro-framework.
- Host: GitHub
- URL: https://github.com/zapheus/zapheus
- Owner: zapheus
- License: mit
- Created: 2017-12-14T05:12:25.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2020-10-05T03:04:12.000Z (over 5 years ago)
- Last Synced: 2025-11-27T16:52:29.050Z (5 months ago)
- Topics: interoperable, php-framework, php-library, zapheus
- Language: PHP
- Homepage: https://roug.in/zapheus/
- Size: 310 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Zapheus
[![Latest Version on Packagist][ico-version]][link-packagist]
[![Software License][ico-license]][link-license]
[![Build Status][ico-travis]][link-travis]
[![Coverage Status][ico-scrutinizer]][link-scrutinizer]
[![Quality Score][ico-code-quality]][link-code-quality]
[![Total Downloads][ico-downloads]][link-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.
``` php
// 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](https://getcomposer.org/):
``` bash
$ composer require zapheus/zapheus
```
## Basic Usage
### Using `Coordinator`
``` php
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`
``` php
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:
``` bash
$ php -S localhost:8000
```
Open your web browser and go to [http://localhost:8000](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](https://github.com/zapheus?utf8=%E2%9C%93&q=bridge) to integrate your chosen libraries easily within the framework. These include the [PHP Standards Recommendations](https://www.php-fig.org/psr/) (PSR) like [PSR-07](https://github.com/zapheus/psr-07-bridge) and [PSR-11](https://github.com/zapheus/psr-11-bridge).
``` php
// 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.
``` php
// 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][link-changelog] for more information what has changed recently.
## Testing
``` bash
$ composer test
```
## Credits
- [All contributors][link-contributors]
## License
The MIT License (MIT). Please see [LICENSE][link-license] for more information.
[ico-code-quality]: https://img.shields.io/scrutinizer/g/zapheus/zapheus.svg?style=flat-square
[ico-downloads]: https://img.shields.io/packagist/dt/zapheus/zapheus.svg?style=flat-square
[ico-license]: https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square
[ico-scrutinizer]: https://img.shields.io/scrutinizer/coverage/g/zapheus/zapheus.svg?style=flat-square
[ico-travis]: https://img.shields.io/travis/zapheus/zapheus/master.svg?style=flat-square
[ico-version]: https://img.shields.io/packagist/v/zapheus/zapheus.svg?style=flat-square
[link-changelog]: https://github.com/zapheus/zapheus/blob/master/CHANGELOG.md
[link-code-quality]: https://scrutinizer-ci.com/g/zapheus/zapheus
[link-contributors]: https://github.com/zapheus/zapheus/contributors
[link-downloads]: https://packagist.org/packages/zapheus/zapheus
[link-license]: https://github.com/zapheus/zapheus/blob/master/LICENSE.md
[link-packagist]: https://packagist.org/packages/zapheus/zapheus
[link-scrutinizer]: https://scrutinizer-ci.com/g/zapheus/zapheus/code-structure
[link-travis]: https://travis-ci.org/zapheus/zapheus