1. Go to this page and download the library: Download riverwaysoft/api-tools 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/ */
riverwaysoft / api-tools example snippets
class UserRegisteredMessage {
public function __construct(public string $username) {}
}
use Riverwaysoft\ApiTools\DomainEvents\EventSourceCollector;
class User extends EventSourceCollector {
public function signUp(string $username){
$this->rememberMessage(new UserRegisteredMessage($username));
}
}
# After that message can be consumed with:
$user = new User();
$messages = $user->popMessages();
class UserFilter
{
public function __construct(
public int $ageGreaterThan,
public string $name,
) {
}
}
class CreateUserInput {
public function __construct(
public int $age,
public string $name,
) {
}
}
use Riverwaysoft\ApiTools\InputValueResolver\Query;
use Riverwaysoft\ApiTools\InputValueResolver\Input;
class UserController
{
#[Route('/api/users', methods: ['GET'])]
public function getUsers(#[Query] UserFilter $userFilter)
{
// Use $userFilter for requests like
// /api/users?ageGreaterThan=18&name=test
}
#[Route('/api/users', methods: ['POST'])]
public function createUser(#[Input] CreateUserInput $input)
{
// variable $input will be automatically created
// from the request body
}
}
use Riverwaysoft\ApiTools\Testing\UnicodeIgnoreOrderJsonDriver;
//
public function assertMatchesJsonUnicodeSnapshot(mixed $actual): void
{
$this->assertMatchesSnapshot($actual, new UnicodeIgnoreOrderJsonDriver());
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.