diff --git a/EXAMPLES.md b/EXAMPLES.md index e8976dc..c3e82c7 100644 --- a/EXAMPLES.md +++ b/EXAMPLES.md @@ -6,9 +6,12 @@ This file contains practical examples demonstrating how to use the Web framework ```php get('/', function(Context $context) { return 'Hello World!'; @@ -22,13 +25,13 @@ $app->run(); ?> ``` -## Web Application Examples +## App (Application) Examples ### Basic Setup ```php // Create application with debug mode -$app = new Web(debug: true); +$app = new App(debug: true); // Add global middleware $app->use(function(Context $context, callable $next) { @@ -46,7 +49,7 @@ $app->delete('/path', $handler); $app->head('/path', $handler); // Route groups -$app->group('/api', function(Web $app) { +$app->group('/api', function(App $app) { $app->get('/users', $usersHandler); $app->post('/users', $createUserHandler); }); @@ -56,7 +59,7 @@ $app->setErrorHandler(404, function(Context $context) { $context->json(['error' => 'Custom 404'], 404); }); -$app->setDefaultErrorHandler(function(Context $context, int $status, string $message, ?Exception $e) { +$app->setDefaultErrorHandler(function(Context $context, int $status, string $message, ?\Exception $e) { $context->json(['error' => $message, 'status' => $status], $status); }); @@ -363,7 +366,7 @@ $allCookies = $context->cookie->all(); $context->cookie->clear(); // Configure cookie defaults for the application -$app = new Web(debug: true, cookieDefaults: [ +$app = new App(debug: true, cookieDefaults: [ 'path' => '/', 'domain' => '.example.com', 'secure' => true, @@ -566,7 +569,7 @@ $errorHandler->register(404, function(Context $context, int $status, string $mes $context->json(['error' => 'Custom not found'], 404); }); -$errorHandler->setDefaultHandler(function(Context $context, int $status, string $message, ?Exception $e) { +$errorHandler->setDefaultHandler(function(Context $context, int $status, string $message, ?\Exception $e) { $context->json(['error' => $message, 'code' => $status], $status); }); @@ -695,11 +698,14 @@ $app->post('/upload', function(Context $context) { ```php context->session); @@ -737,7 +743,7 @@ $app->post('/logout', function(Context $context) use ($auth) { }); // Protected routes -$app->group('/api', function(Web $app) use ($authMiddleware) { +$app->group('/api', function(App $app) use ($authMiddleware) { $app->use($authMiddleware->requireAuth()); $app->use($authMiddleware->rateLimit(100, 1)); @@ -791,7 +797,7 @@ $app->group('/api', function(Web $app) use ($authMiddleware) { }); // Admin routes -$app->group('/admin', function(Web $app) use ($authMiddleware) { +$app->group('/admin', function(App $app) use ($authMiddleware) { $app->use($authMiddleware->requireRole('admin')); $app->get('/users', function(Context $context) { @@ -813,7 +819,7 @@ $app->group('/admin', function(Web $app) use ($authMiddleware) { }); // Public API routes -$app->group('/public', function(Web $app) { +$app->group('/public', function(App $app) { $app->get('/posts', function(Context $context) { $posts = getPublicPosts(); return ['posts' => $posts]; @@ -861,7 +867,7 @@ function testRoute($method, $path, $data = []) { $_POST = $data; } - $app = new Web(); + $app = new App(); // Setup your routes... ob_start(); diff --git a/README.md b/README.md index f3ace55..7b24a99 100644 --- a/README.md +++ b/README.md @@ -6,9 +6,12 @@ Web is a lightweight, high-performance PHP web framework built around a hyper-op ```php get('/', function(Context $context) { return 'Hello World!'; @@ -26,7 +29,7 @@ See [EXAMPLES.md](EXAMPLES.md) for comprehensive examples and usage patterns. ## Core Components -### Web Application +### App (Application) The main application class that handles routing, middleware, and request processing. - Route registration (`get()`, `post()`, `put()`, `patch()`, `delete()`, `head()`) - Middleware support (`use()`) @@ -107,9 +110,9 @@ Comprehensive error and exception handling. ## API Reference -### Web Class +### App Class ```php -new Web(bool $debug = false, array $cookieDefaults = []) +new App(bool $debug = false, array $cookieDefaults = []) use(callable $middleware): self get|post|put|patch|delete|head(string $route, callable $handler): self group(string $prefix, callable $callback): self