PHP code example of ody / foundation

1. Go to this page and download the library: Download ody/foundation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ody / foundation example snippets



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


// 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']);
});


// 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');


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

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


use Ody\Foundation\Bootstrap;

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

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