Skip to content

Commit 93135ae

Browse files
committed
feat: Adicionar documentação para a versão 1.0.0 do PivotPHP Core
1 parent 4f3df56 commit 93135ae

File tree

3 files changed

+765
-0
lines changed

3 files changed

+765
-0
lines changed
Lines changed: 376 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,376 @@
1+
# PivotPHP Core v1.0.0 - Framework Overview
2+
3+
**Versão:** 1.0.0
4+
**Data de Release:** 7 de Julho, 2025
5+
**Status:** Initial Stable Release
6+
7+
## 📋 Visão Geral
8+
9+
PivotPHP Core v1.0.0 é o **primeiro release estável** de um microframework PHP moderno inspirado no Express.js. Combina a simplicidade e familiaridade do Express.js com o poder e performance do PHP moderno, oferecendo uma solução completa para desenvolvimento de APIs e aplicações web de alta performance.
10+
11+
## 🎯 Objetivos da Versão
12+
13+
- **Express.js-Inspired API:** Interface familiar e intuitiva para desenvolvedores
14+
- **High-Performance Framework:** Otimizado para alta concorrência e throughput
15+
- **PSR Standards Compliance:** Compliance completa com padrões PHP modernos
16+
- **Security-First Approach:** Suite completa de recursos de segurança built-in
17+
- **Developer Experience:** Ferramentas e recursos para desenvolvimento produtivo
18+
19+
## 📊 Métricas da Versão
20+
21+
### Performance Metrics
22+
- **CORS Headers Generation:** 2.57M ops/sec
23+
- **Response Creation:** 2.27M ops/sec
24+
- **Route Resolution:** 757K ops/sec
25+
- **End-to-end Throughput:** 1.4K req/sec
26+
- **Memory Usage:** 1.2 MB
27+
- **Average Latency:** 0.71 ms
28+
29+
### Quality Metrics
30+
- **PHPStan:** Level 9, zero static analysis errors
31+
- **PSR-12:** 100% code style compliance
32+
- **Test Coverage:** 270+ comprehensive unit and integration tests
33+
- **PHP Support:** 8.1+ with full 8.4 compatibility
34+
- **Performance Validated:** Optimized for high-performance applications
35+
36+
### Security Features
37+
- **Built-in Protection:** CORS, CSRF, XSS protection
38+
- **Authentication:** JWT, Basic Auth, Bearer Token, API Key support
39+
- **Rate Limiting:** Advanced rate limiting with multiple algorithms
40+
- **Security Headers:** Comprehensive security headers middleware
41+
42+
## 🆕 Recursos Principais v1.0.0
43+
44+
### 🚀 Express.js-Inspired API
45+
46+
**Familiar and Intuitive:**
47+
```php
48+
use PivotPHP\Core\Application;
49+
50+
$app = new Application();
51+
52+
// Routes
53+
$app->get('/users', function($req, $res) {
54+
return $res->json(['users' => $userService->all()]);
55+
});
56+
57+
$app->get('/users/:id', function($req, $res) {
58+
$id = $req->param('id');
59+
$user = $userService->find($id);
60+
return $res->json(['user' => $user]);
61+
});
62+
63+
$app->post('/users', function($req, $res) {
64+
$data = $req->body();
65+
$user = $userService->create($data);
66+
return $res->status(201)->json(['user' => $user]);
67+
});
68+
69+
$app->listen(3000);
70+
```
71+
72+
### 🛡️ Comprehensive Security Suite
73+
74+
**Built-in Security Middleware:**
75+
```php
76+
// CORS Protection
77+
$app->use(new CorsMiddleware([
78+
'origin' => ['https://mydomain.com'],
79+
'methods' => ['GET', 'POST', 'PUT', 'DELETE'],
80+
'headers' => ['Content-Type', 'Authorization']
81+
]));
82+
83+
// CSRF Protection
84+
$app->use(new CsrfMiddleware());
85+
86+
// XSS Protection
87+
$app->use(new XssMiddleware());
88+
89+
// JWT Authentication
90+
$app->use('/api', new AuthMiddleware([
91+
'secret' => 'your-jwt-secret',
92+
'algorithms' => ['HS256']
93+
]));
94+
```
95+
96+
### ⚡ High-Performance Routing
97+
98+
**Advanced Router Features:**
99+
```php
100+
// Parameter constraints
101+
$app->get('/users/:id<\\d+>', $handler);
102+
$app->get('/files/:filename<[a-zA-Z0-9_-]+\\.[a-z]{2,4}>', $handler);
103+
104+
// Route groups
105+
$app->group('/api/v1', function($group) {
106+
$group->get('/users', $usersHandler);
107+
$group->post('/users', $createUserHandler);
108+
$group->get('/users/:id', $userHandler);
109+
});
110+
111+
// Middleware for specific routes
112+
$app->get('/admin/*', [new AuthMiddleware(), $adminHandler]);
113+
```
114+
115+
### 🔧 Dependency Injection Container
116+
117+
**Advanced DI System:**
118+
```php
119+
// Service registration
120+
$app->bind('database', function() {
121+
return new PDO('mysql:host=localhost;dbname=app', $user, $pass);
122+
});
123+
124+
// Service providers
125+
class DatabaseServiceProvider extends ServiceProvider
126+
{
127+
public function register(): void
128+
{
129+
$this->app->bind('db', Database::class);
130+
}
131+
132+
public function boot(): void
133+
{
134+
// Boot logic
135+
}
136+
}
137+
138+
$app->register(new DatabaseServiceProvider());
139+
```
140+
141+
### 📝 Middleware System
142+
143+
**PSR-15 Compliant Middleware:**
144+
```php
145+
// Global middleware
146+
$app->use(new LoggingMiddleware());
147+
$app->use(new CompressionMiddleware());
148+
149+
// Route-specific middleware
150+
$app->get('/users', [
151+
new AuthMiddleware(),
152+
new RateLimitMiddleware(100, 60), // 100 requests per minute
153+
$usersHandler
154+
]);
155+
156+
// Custom middleware
157+
class CustomMiddleware implements MiddlewareInterface
158+
{
159+
public function process($request, $handler): ResponseInterface
160+
{
161+
// Pre-processing
162+
$response = $handler->handle($request);
163+
// Post-processing
164+
return $response;
165+
}
166+
}
167+
```
168+
169+
### 📊 Event System
170+
171+
**PSR-14 Compliant Event Dispatcher:**
172+
```php
173+
// Event registration
174+
$app->on('user.created', function(UserCreatedEvent $event) {
175+
// Send welcome email
176+
$emailService->sendWelcome($event->getUser());
177+
});
178+
179+
// Event dispatch
180+
$app->dispatch(new UserCreatedEvent($user));
181+
182+
// Hook system
183+
$app->hook('before.request', function($request) {
184+
// Pre-request processing
185+
});
186+
187+
$app->hook('after.response', function($response) {
188+
// Post-response processing
189+
});
190+
```
191+
192+
## 🏗️ Architecture Overview
193+
194+
### Core Components
195+
- **Application**: Bootstrap e pipeline de middleware
196+
- **Router**: Sistema de roteamento de alta performance
197+
- **Container**: Sistema de injeção de dependência
198+
- **Event Dispatcher**: Sistema de eventos PSR-14
199+
- **HTTP Layer**: Implementação PSR-7 com API Express.js
200+
201+
### Service Providers
202+
- **Container Service Provider**: Dependency injection
203+
- **Event Service Provider**: Event dispatching
204+
- **Logging Service Provider**: Logging system
205+
- **Extension Service Provider**: Plugin system
206+
207+
### Performance Components
208+
- **Performance Monitor**: Built-in benchmarking
209+
- **Memory Manager**: Memory usage optimization
210+
- **Route Cache**: Route compilation and caching
211+
- **Response Cache**: Response caching system
212+
213+
## 🔧 Built-in Features
214+
215+
### Authentication System
216+
```php
217+
// JWT Helper
218+
$token = JWTHelper::encode(['user_id' => 123], 'secret');
219+
$payload = JWTHelper::decode($token, 'secret');
220+
221+
// Multiple auth methods
222+
$app->use(new AuthMiddleware([
223+
'methods' => ['jwt', 'basic', 'bearer', 'api_key']
224+
]));
225+
```
226+
227+
### Validation System
228+
```php
229+
$validator = new Validator([
230+
'email' => 'required|email',
231+
'password' => 'required|min:8',
232+
'age' => 'integer|min:18'
233+
]);
234+
235+
if ($validator->validate($data)) {
236+
// Data is valid
237+
} else {
238+
$errors = $validator->getErrors();
239+
}
240+
```
241+
242+
### Caching System
243+
```php
244+
// File cache
245+
$cache = new FileCache('/tmp/cache');
246+
$cache->set('key', $data, 3600); // 1 hour TTL
247+
$data = $cache->get('key');
248+
249+
// Memory cache
250+
$cache = new MemoryCache();
251+
$cache->remember('expensive_operation', 3600, function() {
252+
return performExpensiveOperation();
253+
});
254+
```
255+
256+
### Error Handling
257+
```php
258+
// Custom error handlers
259+
$app->error(404, function($req, $res) {
260+
return $res->status(404)->json(['error' => 'Not Found']);
261+
});
262+
263+
$app->error(500, function($req, $res, $exception) {
264+
$this->logger->error($exception->getMessage());
265+
return $res->status(500)->json(['error' => 'Internal Server Error']);
266+
});
267+
```
268+
269+
## 📚 PSR Standards Compliance
270+
271+
### Implemented Standards
272+
- **PSR-7**: HTTP Message Interfaces
273+
- **PSR-11**: Container Interface
274+
- **PSR-12**: Extended Coding Style
275+
- **PSR-14**: Event Dispatcher
276+
- **PSR-15**: HTTP Server Request Handlers
277+
278+
### Benefits
279+
- **Interoperability**: Compatible com ecosystem PHP moderno
280+
- **Quality**: Padrões estabelecidos pela comunidade
281+
- **Maintainability**: Código consistente e previsível
282+
- **Future-Proof**: Compatibility com desenvolvimentos futuros
283+
284+
## 🚀 Development Experience
285+
286+
### Hot Reload
287+
```php
288+
// Development mode
289+
$app = new Application(['env' => 'development']);
290+
$app->enableHotReload(); // Automatic code reloading
291+
```
292+
293+
### Comprehensive Logging
294+
```php
295+
// Built-in logger
296+
$app->logger->info('User logged in', ['user_id' => 123]);
297+
$app->logger->error('Database connection failed', ['error' => $e->getMessage()]);
298+
299+
// Custom log handlers
300+
$app->logger->addHandler(new FileHandler('/var/log/app.log'));
301+
$app->logger->addHandler(new DatabaseHandler($pdo));
302+
```
303+
304+
### OpenAPI Support
305+
```php
306+
// Automatic API documentation
307+
$exporter = new OpenApiExporter($app);
308+
$openApiSpec = $exporter->export();
309+
310+
// Save to file
311+
file_put_contents('api-docs.json', json_encode($openApiSpec, JSON_PRETTY_PRINT));
312+
```
313+
314+
## 🎯 Use Cases
315+
316+
### API Development
317+
- **RESTful APIs**: Complete REST API development
318+
- **Microservices**: Lightweight microservice architecture
319+
- **JSON APIs**: High-performance JSON API development
320+
- **GraphQL**: GraphQL endpoint implementation
321+
322+
### Web Applications
323+
- **Single Page Applications**: SPA backend development
324+
- **Traditional Web Apps**: Server-rendered applications
325+
- **Progressive Web Apps**: PWA backend services
326+
- **Real-time Applications**: WebSocket and SSE support
327+
328+
### Enterprise Applications
329+
- **High-Performance**: Optimized for high-concurrency
330+
- **Security-First**: Comprehensive security features
331+
- **Scalable**: Built for horizontal scaling
332+
- **Maintainable**: Clean architecture and PSR compliance
333+
334+
## 📈 Performance Benchmarks
335+
336+
### Throughput
337+
- **Route Resolution**: 757K ops/sec
338+
- **Response Creation**: 2.27M ops/sec
339+
- **CORS Headers**: 2.57M ops/sec
340+
- **End-to-End**: 1.4K req/sec
341+
342+
### Memory
343+
- **Base Memory**: 1.2 MB
344+
- **Per Request**: ~50KB additional
345+
- **Memory Leaks**: Zero detected
346+
- **GC Efficiency**: Optimized for minimal GC pressure
347+
348+
### Latency
349+
- **Average**: 0.71 ms
350+
- **P95**: <2 ms
351+
- **P99**: <5 ms
352+
- **Cold Start**: <10 ms
353+
354+
## 🎯 Roadmap
355+
356+
### v1.0.x Series
357+
- **Bug Fixes**: Critical bug fixes and stability improvements
358+
- **Performance**: Additional performance optimizations
359+
- **Documentation**: Enhanced documentation and examples
360+
- **Testing**: Expanded test coverage
361+
362+
### v1.1.x Series
363+
- **PSR-7 Hybrid**: Full PSR-7 support while maintaining Express.js API
364+
- **Object Pooling**: Advanced memory management
365+
- **JSON Optimization**: High-performance JSON processing
366+
- **Architectural Improvements**: Code organization and structure
367+
368+
### Future Versions
369+
- **Extensions**: Ecosystem extensions (ORM, ReactPHP, etc.)
370+
- **Performance**: Advanced performance optimizations
371+
- **Features**: Additional framework features
372+
- **Ecosystem**: Complete framework ecosystem
373+
374+
---
375+
376+
**PivotPHP Core v1.0.0** - Express.js simplicity, PHP power, modern standards.

0 commit comments

Comments
 (0)