chubbyphp/chubbyphp-framework-router-hack-routing

This package is abandoned and no longer maintained. The author suggests using the chubbyphp/chubbyphp-framework-fastroute package instead.

Hack routing implementation for chubbyphp-framework.

dev-master / 1.0.x-dev 2023-12-02 17:58 UTC

This package is auto-updated.

Last update: 2023-12-02 17:57:38 UTC


README

CI Coverage Status Infection MSI Latest Stable Version Total Downloads Monthly Downloads

bugs code_smells coverage duplicated_lines_density ncloc sqale_rating alert_status reliability_rating security_rating sqale_index vulnerabilities

Description

Hack routing implementation for chubbyphp-framework.

DEPRECATED: I suggest to use chubbyphp-framework-router-fastroute.

Requirements

Installation

Through Composer as chubbyphp/chubbyphp-framework-router-hack-routing.

composer require chubbyphp/chubbyphp-framework-router-hack-routing "^1.0"

Usage

<?php

declare(strict_types=1);

namespace App;

use Chubbyphp\Framework\Application;
use Chubbyphp\Framework\Middleware\ExceptionMiddleware;
use Chubbyphp\Framework\Middleware\RouteMatcherMiddleware;
use Chubbyphp\Framework\RequestHandler\CallbackRequestHandler;
use Chubbyphp\Framework\Router\HackRouting\RouteMatcher;
use Chubbyphp\Framework\Router\Route;
use Chubbyphp\Framework\Router\Routes;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Psr7\Factory\ResponseFactory;
use Slim\Psr7\Factory\ServerRequestFactory;

$loader = require __DIR__.'/../vendor/autoload.php';

$responseFactory = new ResponseFactory();

$app = new Application([
    new ExceptionMiddleware($responseFactory, true),
    new RouteMatcherMiddleware(new RouteMatcher(new Routes([
        Route::get('/hello/{name:[a-z]+}', 'hello', new CallbackRequestHandler(
            function (ServerRequestInterface $request) use ($responseFactory) {
                $name = $request->getAttribute('name');
                $response = $responseFactory->createResponse();
                $response->getBody()->write(sprintf('Hello, %s', $name));

                return $response;
            }
        ))
    ]))),
]);

$app->emit($app->handle((new ServerRequestFactory())->createFromGlobals()));

Copyright

2023 Dominik Zogg