papi / papi
Slim Framework Builder
This package's canonical repository appears to be gone and the package has been frozen as a result. Email us for help if needed.
v2.1.1
2025-12-22 15:45 UTC
Requires
- php: >=8.3.0
- php-di/slim-bridge: ^3.4
- slim/psr7: ^1.8
- slim/slim: ^4.15
Requires (Dev)
- phpunit/phpunit: ^12.4
- squizlabs/php_codesniffer: ^4.0
README
Description
Help with creating new Slim API. Distributed under the Apache-2.0 license.
Installation
composer require papi/papi
Usage
require __DIR__ . "/../vendor/autoload.php"; use Papi\PapiBuilder; use function DI\create; $definitions = [ FooDefinition::class => create()->constructor() ]; $builder = new PapiBuilder(); $app = $builder->setActions(FooGet::class) ->setDefinition($definitions) ->setEvent(FooEvent::class, BarEvent::class) ->setModule(FooModule::class, BarModule::class) ->build(); $app->run();
Samples
Events
| Order | Phase | Options |
|---|---|---|
| 1 | START |
[] |
| 2 | CONFIGURE_DEFINITIONS |
[container_builder ➡ ContainerBuilder, definitions ➡ array] |
| 3 | CONFIGURE_MIDDLEWARES |
[app ➡ App, middlewares ➡ array] |
| 4 | CONFIGURE_ACTIONS |
[app ➡ App, actions ➡ array] |
| 5 | END |
[app ➡ App] |
Modules Availables
| Name | Github | Packagist |
|---|---|---|
| Cache | GitHub | Packagist |
| CORS | GitHub | Packagist |
| CORS | GitHub | Packagist |
| Date | GitHub | Packagist |
| DotEnv | GitHub | Packagist |
| Http Error | GitHub | Packagist |
Test
composer test
Call API From Test
use Papi\Test\PapiTestCase; use Papi\Test\mock\FooGet; use PHPUnit\Framework\Attributes\CoversClass; class CustomTest extends PapiTestCase { public function testLoadActions(): void { $body = [ "attribute" => 1 ]; $request = $this->createRequest('GET', '/foo', $body); $builder = new PapiBuilder(); $response = $builder ->setAction([FooGet::class]) ->handle($request); $this->assertEquals(200, $response->getStatusCode()); $this->assertEquals("foo", (string) $response->getBody()); } }
Resources
-
Thanks to Mauro Bonfietti for his contribution to the community. Writing PHP Unit Tests