Skip to content

Instantly share code, notes, and snippets.

@koriym
Last active January 31, 2021 04:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koriym/d848bad916f922b1cce82293df1829eb to your computer and use it in GitHub Desktop.
Save koriym/d848bad916f922b1cce82293df1829eb to your computer and use it in GitHub Desktop.
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