jowy / vinnige
High Performance & Non-Blocking I/O PHP Web Framework
v1.0.6
2015-10-22 03:39 UTC
Requires
- filp/whoops: ^1.1
- illuminate/container: ^5.1
- monolog/monolog: ^1.15
- nikic/fast-route: ^0.6.0
- phpixie/http: 3.*@dev
- phpixie/slice: 3.*@dev
- relay/relay: ^0.2.0
- symfony/event-dispatcher: ^2.7
Requires (Dev)
- henrikbjorn/phpspec-code-coverage: ^1.0
- phpspec/phpspec: ^2.2
This package is not auto-updated.
Last update: 2024-12-21 18:59:33 UTC
README
High Performance & Non-Blocking I/O PHP Web Framework
Usage
Create php files for example index.php then copy code below
<?php use Vinnige\Application; use Vinnige\Middlewares\RoutingMiddleware; use PHPixie\HTTP\Messages\Stream\StringStream; use PHPixie\HTTP\Messages\Message\Response; use Vinnige\Lib\Logger\Handler\AsyncRotatingFileHandler; use Vinnige\Lib\Config\Config; use Vinnige\Lib\Container\LaravelContainer; use Illuminate\Container\Container; use Vinnige\Providers\KernelServiceProvider; use Vinnige\Providers\MonologServiceProvider; use Monolog\Formatter\LineFormatter; use Vinnige\Providers\SwooleServerServiceProvider; use Vinnige\Providers\RoutingServiceProvider; use Vinnige\Providers\MiddlewareDispatcherServiceProvider; use Vinnige\Providers\ErrorHandlerProvider; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ResponseInterface; require 'vendor/autoload.php'; $app = new Application( new Config( [ 'server.hostname' => 'localhost', 'server.port' => 8000, 'server.config' => [ 'worker_num' => 4, 'reactor_thread' => 4, 'dispatch_mode' => 2, 'max_request' => 10000 ], 'debug' => true ] ), new LaravelContainer(new Container()) ); /** * default service provider */ $app->register(new KernelServiceProvider(), [ 'http.streams' => [ StringStream::class => '' ], 'http.response' => [ 'class' => Response::class, 'protocol.version' => '1.1', 'header' => [], 'stream' => StringStream::class ], ]); $app->register(new MonologServiceProvider(), [ 'logger.name' => 'vinige', 'logger.handler' => [ AsyncRotatingFileHandler::class => [ 'args' => [ __DIR__ ], 'formatter' => [ LineFormatter::class => [] ] ] ] ]); $app->register(new SwooleServerServiceProvider()); $app->register(new RoutingServiceProvider()); $app->register(new MiddlewareDispatcherServiceProvider()); $app->register(new ErrorHandlerProvider()); /** * register onRequest callback */ $app->serverEvent('request', [$app['ServerRequestHandler'], 'handleRequest']); /** * define routes */ $app->get( '/hello', function (ServerRequestInterface $request, ResponseInterface $response) { $response->getBody()->write('hello world'); return $response->withHeader('Content-Type', 'text/html'); } ); /** * default middleware */ $app->middleware(RoutingMiddleware::class); /** * run app */ $app->run();
then run via cli
php index.php