Skip to content

Instantly share code, notes, and snippets.

@koriym
Last active Jan 31, 2021
Embed
What would you like to do?
Minimum repository pattern with AOP
<?php
// The next Rqy.Query
namespace Ray\Query\Fake\Media;
use Ray\Query\Annotation\Sql;
interface RegisterUserInterface
{
public function __invoke(string $name, int $age): void;
}
final class RegisterUser implements RegisterUserInterface
{
#[Sql(id: 'register_user', transactional: true)]
public function __invoke(string $name, int $age): void
{
}
}
/**
* @psalm-type UserItemArray array{id: string, name: string: age: int}
*/
interface UserItemInterface
{
/**
* @return UserItemArray
*/
public function __invoke(string $id): array;
}
final class UserItem implements UserItemInterface
{
#[Sql(id: 'user_item')]
public function __invoke(string $id): array
{
}
}
/**
* @psalm-import-type UserItemArray from UserItemInterface
*/
interface UserListInterface
{
/**
* @psalm-return list<UserItemArray>
*/
public function __invoke(): array;
}
final class UserList implements UserListInterface
{
#[Sql(id: 'user_list')]
public function __invoke(): array
{
}
}
final class FakeUserItem implements UserItemInterface
{
public function __invoke(string $id) : array
{
return ['id' => 1, 'name'=> 'ray', 'age' => 10];
}
}
final class WebApiUserItem implements UserItemInterface
{
#[WebApi(id: 'user_item')]
public function __invoke(string $id) : array
{
}
}
final class WebApiUserItemUriTemplate implements UserItemInterface
{
#[WebApi(uri: 'http://example.com/users{?id}')]
public function __invoke(string $id) : array
{
}
}
// sql/register_user.sql
// sql/user_item.sql
// sql/user_list.sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment