{ private function __construct( public string $id, public string $name, ) { } public static function create(string $name): static { $id = (string)Ulid::generate(); return new User($id, $name); } }
public string $id, public string $name, ) { } public static function create(string $name): static { $id = (string)Ulid::generate(); return new User($id, $name); } } ① そのまま php-ulid を使った例
function ulid(): string { return (string)Ulid::generate(); } <?php use function MyUlid\ulid; readonly class User { private function __construct( public string $id, public string $name, ) { } public static function create(string $name): static { $id = ulid(); return new User($id, $name); } }
function ulid(): string { return (string)Ulid::generate(); } <?php use function MyUlid\ulid; readonly class User { private function __construct( public string $id, public string $name, ) { } public static function create(string $name): static { $id = ulid(); return new User($id, $name); } }
ClientInterface { /** * Sends a PSR-7 request and returns a PSR-7 response. * //(略) */ public function sendRequest(RequestInterface $request): ResponseInterface; }
* * Use an absolute path to override the base path of the client, or a * relative path to append to the base path of the client. The URL can * contain the query string as well. * * @param string|UriInterface $uri URI object or string. * @param array $options Request options to apply. * * @throws GuzzleException */ public function get($uri, array $options = []): ResponseInterface { return $this->request('GET', $uri, $options); }
* * Use an absolute path to override the base path of the client, or a * relative path to append to the base path of the client. The URL can * contain the query string as well. * * @param string|UriInterface $uri URI object or string. * @param array $options Request options to apply. * * @throws GuzzleException */ public function get($uri, array $options = []): ResponseInterface { return $this->request('GET', $uri, $options); } URI の文字列か、PSR に則っているので ここはそのまま使うという選択肢は充分ありえる
* * Use an absolute path to override the base path of the client, or a * relative path to append to the base path of the client. The URL can * contain the query string as well. * * @param string|UriInterface $uri URI object or string. * @param array $options Request options to apply. * * @throws GuzzleException */ public function get($uri, array $options = []): ResponseInterface { return $this->request('GET', $uri, $options); }
* * Use an absolute path to override the base path of the client, or a * relative path to append to the base path of the client. The URL can * contain the query string as well. * * @param string|UriInterface $uri URI object or string. * @param array $options Request options to apply. * * @throws GuzzleException */ public function get($uri, array $options = []): ResponseInterface { return $this->request('GET', $uri, $options); } GuzzleHttp 固有の例外なので 腐敗防止層では適切にハンドリングして • PHP 組み込みの例外に変換 • 独自定義の例外に変換 • 正常系として適切に処理 等の対応をしておきたい
* * Use an absolute path to override the base path of the client, or a * relative path to append to the base path of the client. The URL can * contain the query string as well. * * @param string|UriInterface $uri URI object or string. * @param array $options Request options to apply. * * @throws GuzzleException */ public function get($uri, array $options = []): ResponseInterface { return $this->request('GET', $uri, $options); }
* * Use an absolute path to override the base path of the client, or a * relative path to append to the base path of the client. The URL can * contain the query string as well. * * @param string|UriInterface $uri URI object or string. * @param array $options Request options to apply. * * @throws GuzzleException */ public function get($uri, array $options = []): ResponseInterface { return $this->request('GET', $uri, $options); } 確かに型情報としてはGuzzleHttpに依存していないが......