2
0

update docs for namespace

This commit is contained in:
Sky Johnson 2025-09-11 11:19:00 -05:00
parent 8a94183081
commit 405dcae482
2 changed files with 28 additions and 19 deletions

View File

@ -6,9 +6,12 @@ This file contains practical examples demonstrating how to use the Web framework
```php
<?php
require_once 'Web.php';
$app = new Web(debug: true);
namespace Web;
require_once 'App.php';
$app = new App(debug: true);
$app->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
<?php
require_once 'Web.php';
namespace Web;
require_once 'App.php';
require_once 'auth/Auth.php';
require_once 'auth/AuthMiddleware.php';
$app = new Web(debug: true);
$app = new App(debug: true);
// Setup auth
$auth = new Auth($app->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();

View File

@ -6,9 +6,12 @@ Web is a lightweight, high-performance PHP web framework built around a hyper-op
```php
<?php
require_once 'Web.php';
$app = new Web(debug: true);
namespace Web;
require_once 'App.php';
$app = new App(debug: true);
$app->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