Search by

trypoint / point

madalinmariusstan

A lightweight, modular PHP microframework built for flexibility and extensibility.

v0.1.0 2026-11-28 15:40 UTC

README

Point is a lightweight, modular PHP microframework built for flexibility and extensibility.

Point Framework v0.1.0 Stable is published. See the changelog and GitHub Release for release details.

PHP Version License Build Status

Features

  • PSR-7 / PSR-15 / PSR-17 compliant HTTP message handling
  • PSR-11 compatible dependency injection container (built-in, with PHP-DI support)
  • FastRoute based routing with dynamic parameters and route groups
  • Middleware pipeline with FIFO execution order
  • Content negotiation for JSON and HTML error responses, with optional XML and plain-text middleware
  • Error handling with detailed stack traces in development
  • Default PSR-7 implementation via httpsoft (no additional packages required)
  • Optional PSR-7 implementations via nyholm/psr7, laminas/laminas-diactoros, guzzlehttp/psr7
  • PHP 8.4 / 8.5 native with strict typing

Requirements

  • PHP >= 8.4.27
  • Composer 2.x
  • Optional XML middleware requires SimpleXML for request parsing or DOM for error rendering.

The release CI matrix covers PHP 8.4.27, PHP 8.4, and PHP 8.5 on Ubuntu and Windows. The Ubuntu Nginx/PHP-FPM job validates a CI fixture; it does not certify a production host or deployment topology.

Installation

composer require trypoint/point

Point includes httpsoft/http-message and httpsoft/http-server-request as the bundled PSR-7/PSR-17 fallback. Automatic discovery can select a complete installed alternative first.

Optional: replace with an alternative PSR-7 implementation:

# Nyholm (fast, lightweight)
composer require nyholm/psr7 nyholm/psr7-server

# Laminas
composer require laminas/laminas-diactoros

# Guzzle
composer require guzzlehttp/psr7

Quick Start

<?php

require __DIR__ . '/../vendor/autoload.php';

use Point\Factory\AppFactory;

// Create application
$app = AppFactory::create();

// GET route
$app->get('/', function ($request, $response) {
    $response->getBody()->write('Hello, World!');
    return $response;
});

// Dynamic route with parameters
$app->get('/user/{id}', function ($request, $response, array $args) {
    $response->getBody()->write('User: ' . $args['id']);
    return $response;
});

// JSON response
$app->get('/api/users', function ($request, $response) {
    $data = [
        ['id' => 1, 'name' => 'Alice'],
        ['id' => 2, 'name' => 'Bob'],
    ];
    $response->getBody()->write(json_encode($data));
    return $response->withHeader('Content-Type', 'application/json');
});

// Run the application
$app->run();

Save as public/index.php and serve with PHP's built-in server:

php -S localhost:8080 -t public

Visit http://localhost:8080/ to see the response.

Routing

Moving an existing Slim app? See the Slim migration guide.

Basic Routes

$app->get('/users', $handler);
$app->post('/users', $handler);
$app->put('/users/{id}', $handler);
$app->delete('/users/{id}', $handler);
$app->patch('/users/{id}', $handler);
$app->options('/users', $handler);
$app->any('/users', $handler); // Matches any HTTP method

Route Parameters

$app->get('/users/{id}', function ($request, $response, array $args) {
    // $args['id'] contains the matched value
    return $response;
});

// Optional parameters
$app->get('/users[/{id}]', $handler);

// Constraints via regex
$app->get('/users/{id:\d+}', $handler); // Only digits

Route Groups

$app->group('/api', function ($group) use ($handler) {
    $group->get('/users', $handler);
    $group->post('/users', $handler);
    
    $group->group('/v1', function ($group) use ($handler) {
        $group->get('/posts', $handler);
    });
});

Route Middleware

$app->get('/admin', $handler)->add($authMiddleware);

$app->group('/api', function ($group) use ($rateLimitMiddleware, $handler) {
    $group->add($rateLimitMiddleware);
    $group->get('/users', $handler);
});

Named Routes & URL Generation

$route = $app->get('/user/{id}', $handler)->setName('user.profile');

$urlGenerator = $app->getContainer()->get(\Point\Interfaces\UrlGeneratorInterface::class);
$url = $urlGenerator->urlFor('user.profile', ['id' => 123]); // /user/123

Pass raw parameter values. Point percent-encodes each substituted value. Encoded slashes (%2F and %2f) in request paths return HTTP 404. Use separate route segments for values that span a slash.

Middleware

Middleware follows PSR-15 (MiddlewareInterface) and executes in FIFO order (first added = outermost).

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class ExampleMiddleware implements MiddlewareInterface
{
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
    {
        // Before: modify request, add attributes, etc.
        $request = $request->withAttribute('startTime', microtime(true));
        
        $response = $handler->handle($request);
        
        // After: modify response, add headers, logging, etc.
        $duration = microtime(true) - $request->getAttribute('startTime');
        return $response->withHeader('X-Response-Time', (string)$duration);
    }
}

// Add to application
$app->add(new ExampleMiddleware());
// Alternatively, register ExampleMiddleware::class in the container and add it by ID.

Built-in Middleware

Middleware Purpose
RoutingMiddleware Resolves routes, adds RouteMatch to request
EndpointMiddleware Executes matched route handler
ErrorExceptionMiddleware Converts PHP errors to ErrorException
HtmlExceptionMiddleware Renders HTML error pages
JsonExceptionMiddleware Renders JSON error responses
XmlExceptionMiddleware Renders XML error responses
PlainTextExceptionMiddleware Renders plain text error responses
ExceptionLoggingMiddleware Logs exceptions via PSR-3 logger
HeadMethodMiddleware Removes body for HEAD requests
MethodOverrideMiddleware Allows _method parameter override
ContentLengthMiddleware Adds Content-Length for known body sizes, except on HTTP 204
OutputBufferingMiddleware Captures output buffering
ResponseFactoryMiddleware Short-circuits the pipeline with an empty response
BasePathMiddleware Handles subdirectory deployments

Error Handling

// Development: detailed errors
$app->addErrorMiddleware(true, true, true);

// Production: minimal errors
$app->addErrorMiddleware(false, true, false, $logger);

// Custom error handler
$app->addErrorMiddleware(
    displayErrorDetails: false,
    logErrors: true,
    logErrorDetails: true,
    logger: $customPsr3Logger
);

Dependency Injection

Point includes a PSR-11 compatible container (SimpleContainer) for explicitly registered values, instances, and factories.

$app = AppFactory::create();
$container = $app->getContainer();

// Register an instance and a factory that uses it
$container->set(DateTimeZone::class, new DateTimeZone('UTC'));
$container->set(DateTimeImmutable::class, static function ($c): DateTimeImmutable {
    return new DateTimeImmutable('now', $c->get(DateTimeZone::class));
});

$startedAt = $container->get(DateTimeImmutable::class);

The factory runs on first lookup, and subsequent lookups return the same result. For an unregistered ID, has() returns false and get() throws Psr\Container\NotFoundExceptionInterface.

Using PHP-DI (Optional)

Use an external PHP-DI container if your application needs constructor autowiring.

use DI\ContainerBuilder;
use Point\Factory\AppFactory;
use Point\Container\Definition\PointDefinitions;
use Point\Container\Definition\HttpDefinitions;

$builder = new ContainerBuilder();
$builder->addDefinitions((new PointDefinitions())->getDefinitions());
$builder->addDefinitions((new HttpDefinitions())->getDefinitions());

$app = AppFactory::createFromContainer($builder->build())->withDefaults();

PSR Interoperability

Point accepts PSR-7 messages and uses PSR-17 factories for server requests, responses, streams, uploaded files, and URIs. The bundled HttpSoft provider is the fallback. Automatic discovery checks for a complete provider in this order: Nyholm (including nyholm/psr7-server), Laminas Diactoros, Guzzle PSR-7, then HttpSoft.

// Bundled HttpSoft provider
$responseFactory = new \HttpSoft\Message\ResponseFactory();
$requestFactory = new \HttpSoft\Message\ServerRequestFactory();

Alternative implementations (install separately):

// Nyholm (fast, lightweight)
$psr17 = new \Nyholm\Psr7\Factory\Psr17Factory();

// Laminas
$responseFactory = new \Laminas\Diactoros\ResponseFactory();
$requestFactory = new \Laminas\Diactoros\ServerRequestFactory();

// Guzzle
$factory = new \GuzzleHttp\Psr7\HttpFactory();

Pass overrides at bootstrap. Replacing a PSR-17 factory does not replace Point's separate request-from-globals service.

$app = AppFactory::create([
    \Psr\Http\Message\ResponseFactoryInterface::class => new \HttpSoft\Message\ResponseFactory(),
]);

Use the provider's own request factory for outbound client requests. Point's built-in definitions bind the five server-side factory interfaces listed above.

API Compatibility

The v0.1.0 Stable API freeze was approved on 2026-11-28. Documented stable APIs are covered by the approved compatibility policy; explicitly provisional APIs retain their documented behavior for v0.1.0 without a stable compatibility promise. See the API freeze record.

Testing

# Run all tests
composer test

# Run static analysis and the configured style check
composer stan
composer cs:check

The full-tree style command still reports the documented RC.1 baseline exception. Requires development dependencies:

composer install

Deployment

Apache (.htaccess)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [QSA,L]

Nginx

location / {
    try_files $uri $uri/ /index.php?$query_string;
}

location ~ \.php$ {
    fastcgi_pass unix:/var/run/php/php8.4-fpm.sock;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

PHP Built-in Server (Development)

php -S localhost:8080 -t public

Security

Report vulnerabilities to security.point@madalinmariusstan.dev.

See SECURITY.md for supported versions and disclosure policy.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Ensure tests pass: composer test:all
  4. Submit a pull request

See CONTRIBUTING.md for detailed guidelines.

License

MIT License. See LICENSE.md for details.

Copyright (c) 2011-2024 Josh Lockhart (original Slim Framework) Copyright (c) 2024 Madalin Marius Stan (Point Framework)