1. Go to this page and download the library: Download pivotphp/core 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/ */
pivotphp / core example snippets
PivotPHP\Core\Core\Application;
use PivotPHP\Core\Http\Psr15\Middleware\{SecurityMiddleware, CorsMiddleware, AuthMiddleware};
$app = new Application();
// Middlewares de segurança (PSR-15)
$app->use(new SecurityMiddleware());
$app->use(new CorsMiddleware());
$app->use(new AuthMiddleware([
'authMethods' => ['jwt'],
'jwtSecret' => 'sua_chave_secreta'
]));
// API RESTful
$app->get('/api/users', function($req, $res) {
$res->json(['users' => $userService->getAll()]);
});
$app->post('/api/users', function($req, $res) {
$user = $userService->create($req->body);
$res->status(201)->json(['user' => $user]);
});
// Rotas com validação regex
$app->get('/api/users/:id<\d+>', function($req, $res) {
// Aceita apenas IDs numéricos
$res->json(['user_id' => $req->param('id')]);
});
$app->get('/posts/:year<\d{4}>/:month<\d{2}>/:slug<slug>', function($req, $res) {
// Validação de data e slug na rota
$res->json([
'year' => $req->param('year'),
'month' => $req->param('month'),
'slug' => $req->param('slug')
]);
});
$app->run();
use PivotPHP\ReactPHP\ReactServiceProvider;
$app->register(new ReactServiceProvider([
'server' => [
'host' => '0.0.0.0',
'port' => 8080
]
]));
// Executar servidor assíncrono
$app->runAsync(); // Em vez de $app->run()
namespace MeuProjeto\Providers;
use PivotPHP\Core\Providers\ServiceProvider;
class MinhaExtensaoServiceProvider extends ServiceProvider
{
public function register(): void
{
// Registrar serviços
$this->container->singleton('meu.servico', function() {
return new MeuServico();
});
}
public function boot(): void
{
// Lógica de inicialização
$this->app->get('/minha-rota', function($req, $res) {
$res->json(['extensao' => 'ativa']);
});
}
}
// Imports antigos (ainda funcionam via aliases)
use PivotPHP\Core\Http\Psr15\Middleware\CorsMiddleware;
use PivotPHP\Core\Support\Arr;
// Imports recomendados (nova estrutura)
use PivotPHP\Core\Middleware\Http\CorsMiddleware;
use PivotPHP\Core\Utils\Arr;
bash
php scripts/switch-psr7-version.php --check
bash
# Mudar para PSR-7 v1.x (compatível com ReactPHP)
php scripts/switch-psr7-version.php 1
# Mudar para PSR-7 v2.x (padrão moderno)
php scripts/switch-psr7-version.php 2