Skip to content

Latest commit

 

History

History
376 lines (300 loc) · 10.1 KB

File metadata and controls

376 lines (300 loc) · 10.1 KB

PivotPHP Core v1.0.0 - Framework Overview

Versão: 1.0.0
Data de Release: 7 de Julho, 2025
Status: Initial Stable Release

📋 Visão Geral

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.

🎯 Objetivos da Versão

  • Express.js-Inspired API: Interface familiar e intuitiva para desenvolvedores
  • High-Performance Framework: Otimizado para alta concorrência e throughput
  • PSR Standards Compliance: Compliance completa com padrões PHP modernos
  • Security-First Approach: Suite completa de recursos de segurança built-in
  • Developer Experience: Ferramentas e recursos para desenvolvimento produtivo

📊 Métricas da Versão

Performance Metrics

  • CORS Headers Generation: 2.57M ops/sec
  • Response Creation: 2.27M ops/sec
  • Route Resolution: 757K ops/sec
  • End-to-end Throughput: 1.4K req/sec
  • Memory Usage: 1.2 MB
  • Average Latency: 0.71 ms

Quality Metrics

  • PHPStan: Level 9, zero static analysis errors
  • PSR-12: 100% code style compliance
  • Test Coverage: 270+ comprehensive unit and integration tests
  • PHP Support: 8.1+ with full 8.4 compatibility
  • Performance Validated: Optimized for high-performance applications

Security Features

  • Built-in Protection: CORS, CSRF, XSS protection
  • Authentication: JWT, Basic Auth, Bearer Token, API Key support
  • Rate Limiting: Advanced rate limiting with multiple algorithms
  • Security Headers: Comprehensive security headers middleware

🆕 Recursos Principais v1.0.0

🚀 Express.js-Inspired API

Familiar and Intuitive:

use PivotPHP\Core\Application;

$app = new Application();

// Routes
$app->get('/users', function($req, $res) {
    return $res->json(['users' => $userService->all()]);
});

$app->get('/users/:id', function($req, $res) {
    $id = $req->param('id');
    $user = $userService->find($id);
    return $res->json(['user' => $user]);
});

$app->post('/users', function($req, $res) {
    $data = $req->body();
    $user = $userService->create($data);
    return $res->status(201)->json(['user' => $user]);
});

$app->listen(3000);

🛡️ Comprehensive Security Suite

Built-in Security Middleware:

// CORS Protection
$app->use(new CorsMiddleware([
    'origin' => ['https://mydomain.com'],
    'methods' => ['GET', 'POST', 'PUT', 'DELETE'],
    'headers' => ['Content-Type', 'Authorization']
]));

// CSRF Protection
$app->use(new CsrfMiddleware());

// XSS Protection
$app->use(new XssMiddleware());

// JWT Authentication
$app->use('/api', new AuthMiddleware([
    'secret' => 'your-jwt-secret',
    'algorithms' => ['HS256']
]));

⚡ High-Performance Routing

Advanced Router Features:

// Parameter constraints
$app->get('/users/:id<\\d+>', $handler);
$app->get('/files/:filename<[a-zA-Z0-9_-]+\\.[a-z]{2,4}>', $handler);

// Route groups
$app->group('/api/v1', function($group) {
    $group->get('/users', $usersHandler);
    $group->post('/users', $createUserHandler);
    $group->get('/users/:id', $userHandler);
});

// Middleware for specific routes
$app->get('/admin/*', [new AuthMiddleware(), $adminHandler]);

🔧 Dependency Injection Container

Advanced DI System:

// Service registration
$app->bind('database', function() {
    return new PDO('mysql:host=localhost;dbname=app', $user, $pass);
});

// Service providers
class DatabaseServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->bind('db', Database::class);
    }
    
    public function boot(): void
    {
        // Boot logic
    }
}

$app->register(new DatabaseServiceProvider());

📝 Middleware System

PSR-15 Compliant Middleware:

// Global middleware
$app->use(new LoggingMiddleware());
$app->use(new CompressionMiddleware());

// Route-specific middleware
$app->get('/users', [
    new AuthMiddleware(),
    new RateLimitMiddleware(100, 60), // 100 requests per minute
    $usersHandler
]);

// Custom middleware
class CustomMiddleware implements MiddlewareInterface
{
    public function process($request, $handler): ResponseInterface
    {
        // Pre-processing
        $response = $handler->handle($request);
        // Post-processing
        return $response;
    }
}

📊 Event System

PSR-14 Compliant Event Dispatcher:

// Event registration
$app->on('user.created', function(UserCreatedEvent $event) {
    // Send welcome email
    $emailService->sendWelcome($event->getUser());
});

// Event dispatch
$app->dispatch(new UserCreatedEvent($user));

// Hook system
$app->hook('before.request', function($request) {
    // Pre-request processing
});

$app->hook('after.response', function($response) {
    // Post-response processing
});

🏗️ Architecture Overview

Core Components

  • Application: Bootstrap e pipeline de middleware
  • Router: Sistema de roteamento de alta performance
  • Container: Sistema de injeção de dependência
  • Event Dispatcher: Sistema de eventos PSR-14
  • HTTP Layer: Implementação PSR-7 com API Express.js

Service Providers

  • Container Service Provider: Dependency injection
  • Event Service Provider: Event dispatching
  • Logging Service Provider: Logging system
  • Extension Service Provider: Plugin system

Performance Components

  • Performance Monitor: Built-in benchmarking
  • Memory Manager: Memory usage optimization
  • Route Cache: Route compilation and caching
  • Response Cache: Response caching system

🔧 Built-in Features

Authentication System

// JWT Helper
$token = JWTHelper::encode(['user_id' => 123], 'secret');
$payload = JWTHelper::decode($token, 'secret');

// Multiple auth methods
$app->use(new AuthMiddleware([
    'methods' => ['jwt', 'basic', 'bearer', 'api_key']
]));

Validation System

$validator = new Validator([
    'email' => 'required|email',
    'password' => 'required|min:8',
    'age' => 'integer|min:18'
]);

if ($validator->validate($data)) {
    // Data is valid
} else {
    $errors = $validator->getErrors();
}

Caching System

// File cache
$cache = new FileCache('/tmp/cache');
$cache->set('key', $data, 3600); // 1 hour TTL
$data = $cache->get('key');

// Memory cache
$cache = new MemoryCache();
$cache->remember('expensive_operation', 3600, function() {
    return performExpensiveOperation();
});

Error Handling

// Custom error handlers
$app->error(404, function($req, $res) {
    return $res->status(404)->json(['error' => 'Not Found']);
});

$app->error(500, function($req, $res, $exception) {
    $this->logger->error($exception->getMessage());
    return $res->status(500)->json(['error' => 'Internal Server Error']);
});

📚 PSR Standards Compliance

Implemented Standards

  • PSR-7: HTTP Message Interfaces
  • PSR-11: Container Interface
  • PSR-12: Extended Coding Style
  • PSR-14: Event Dispatcher
  • PSR-15: HTTP Server Request Handlers

Benefits

  • Interoperability: Compatible com ecosystem PHP moderno
  • Quality: Padrões estabelecidos pela comunidade
  • Maintainability: Código consistente e previsível
  • Future-Proof: Compatibility com desenvolvimentos futuros

🚀 Development Experience

Hot Reload

// Development mode
$app = new Application(['env' => 'development']);
$app->enableHotReload(); // Automatic code reloading

Comprehensive Logging

// Built-in logger
$app->logger->info('User logged in', ['user_id' => 123]);
$app->logger->error('Database connection failed', ['error' => $e->getMessage()]);

// Custom log handlers
$app->logger->addHandler(new FileHandler('/var/log/app.log'));
$app->logger->addHandler(new DatabaseHandler($pdo));

OpenAPI Support

// Automatic API documentation
$exporter = new OpenApiExporter($app);
$openApiSpec = $exporter->export();

// Save to file
file_put_contents('api-docs.json', json_encode($openApiSpec, JSON_PRETTY_PRINT));

🎯 Use Cases

API Development

  • RESTful APIs: Complete REST API development
  • Microservices: Lightweight microservice architecture
  • JSON APIs: High-performance JSON API development
  • GraphQL: GraphQL endpoint implementation

Web Applications

  • Single Page Applications: SPA backend development
  • Traditional Web Apps: Server-rendered applications
  • Progressive Web Apps: PWA backend services
  • Real-time Applications: WebSocket and SSE support

Enterprise Applications

  • High-Performance: Optimized for high-concurrency
  • Security-First: Comprehensive security features
  • Scalable: Built for horizontal scaling
  • Maintainable: Clean architecture and PSR compliance

📈 Performance Benchmarks

Throughput

  • Route Resolution: 757K ops/sec
  • Response Creation: 2.27M ops/sec
  • CORS Headers: 2.57M ops/sec
  • End-to-End: 1.4K req/sec

Memory

  • Base Memory: 1.2 MB
  • Per Request: ~50KB additional
  • Memory Leaks: Zero detected
  • GC Efficiency: Optimized for minimal GC pressure

Latency

  • Average: 0.71 ms
  • P95: <2 ms
  • P99: <5 ms
  • Cold Start: <10 ms

🎯 Roadmap

v1.0.x Series

  • Bug Fixes: Critical bug fixes and stability improvements
  • Performance: Additional performance optimizations
  • Documentation: Enhanced documentation and examples
  • Testing: Expanded test coverage

v1.1.x Series

  • PSR-7 Hybrid: Full PSR-7 support while maintaining Express.js API
  • Object Pooling: Advanced memory management
  • JSON Optimization: High-performance JSON processing
  • Architectural Improvements: Code organization and structure

Future Versions

  • Extensions: Ecosystem extensions (ORM, ReactPHP, etc.)
  • Performance: Advanced performance optimizations
  • Features: Additional framework features
  • Ecosystem: Complete framework ecosystem

PivotPHP Core v1.0.0 - Express.js simplicity, PHP power, modern standards.