ody/foundation

Core for ODY framework

0.1.9 2025-03-25 17:33 UTC

This package is auto-updated.

Last update: 2025-03-30 19:54:10 UTC


README

⚠️ IMPORTANT: This repository is automatically generated from the ody repo and is read-only.

The Foundation module is the core of the ODY PHP Framework, providing essential functionality for building high-performance API applications with Swoole coroutines.

Overview

The Foundation module serves as the backbone of the ODY framework.

  • Routing: Efficient request routing with FastRoute
  • Middleware: PSR-15 compatible middleware implementation
  • HTTP Handling: PSR-7 compatible request/response handling
  • Service Container: Dependency injection and service management
  • Service Providers: Modular service registration
  • Error Handling: Exception handling

Installation

composer require ody/foundation

Key Features

Swoole Integration

ODY's foundation is built with native support for Swoole's coroutines, allowing for highly concurrent PHP applications:

<?php
// Start an HTTP server with Swoole
HttpServer::start(ServerManager::init(ServerType::HTTP_SERVER)
    ->createServer($config)
    ->setServerConfig($config['additional'])
    ->registerCallbacks($config['callbacks'])
    ->getServerInstance()
);

Routing System

Define routes with a clean, expressive syntax:

<?php
// Define routes
Router::get('/users', [UserController::class, 'index']);
Router::post('/users', [UserController::class, 'store']);
Router::get('/users/{id}', [UserController::class, 'show']);

// Group routes with shared attributes
Router::group(['prefix' => '/api', 'middleware' => ['auth:api']], function ($router) {
    $router->get('/profile', [ProfileController::class, 'show']);
    $router->put('/profile', [ProfileController::class, 'update']);
});

Middleware Pipeline

Create and register middleware for request/response processing:

<?php
// Register middleware
$app->middleware->add('auth', AuthMiddleware::class);
$app->middleware->add('throttle', ThrottleMiddleware::class);

// Apply to routes
Router::get('/admin/dashboard', [AdminController::class, 'dashboard'])
    ->middleware('auth')
    ->middleware('throttle:60,1');

Service Providers

Organize your application with service providers:

<?php
class MyServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->container->singleton(MyService::class, function () {
            return new MyService();
        });
    }

    public function boot(): void
    {
        // Bootstrap the service
    }
}

Getting Started

Create a new ODY application:

<?php
use Ody\Foundation\Bootstrap;

// Initialize the application
$app = Bootstrap::init();

// Bootstrap and run
$app->bootstrap();
$app->run();

Configuration

Configuration files should be placed in the config directory. The main configuration file is config/app.php.

Documentation

For more detailed documentation, please visit https://ody.dev/docs.

License

The ODY Framework is open-sourced software licensed under the MIT license.