Last active
January 31, 2021 04:28
-
-
Save koriym/d848bad916f922b1cce82293df1829eb to your computer and use it in GitHub Desktop.
Minimum repository pattern with AOP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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