Download the PHP package keisukesaichi/api-dto without Composer

On this page you can find all versions of the php package keisukesaichi/api-dto. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package api-dto

【現状】 俺の使うためのDTOのabstractクラスだ。

俺が使うために作ったが、お前らも使っていいぞ

インストール packagestに登録しているので、composerから使用できる。

$ composer require keisukesaichi/api_dto

現在の最新バーションは 1.0.0 だ。

概要 このライブラリは、API通信用の Request / Response DTO を 「雑に書いても後で壊れない」ようにするための基盤だ。

目的は以下:

・immutable(readonly)前提 ・deprecated を踏まない ・Reflection を乱用しない ・DTOに余計な仕事をさせない

DDDを厳密にやりたい人向けではない。 APIを殴るためのDTOを、ちゃんとした形で持ちたい人向け。

提供しているもの

BaseRequestDto APIリクエスト用DTOの基底クラス。

・readonly(immutable) ・setXxx() による fluent な組み立て ・array / query / json への変換を提供

主な機能:

・fromArray(array): static ・setXxx($value)(__call 経由) ・toArray(): array ・toQuery(QueryNestOpenMode): string ・toJson(): string

BaseResponseDto APIレスポンス用DTOの基底クラス。

・JSON / array / object を入口に受け取れる ・型宣言に基づいて自動キャスト ・ネストしたDTOにも対応(再帰)

対応している型:

・string / int / bool / null ・BackedEnum(tryFrom) ・BaseValueObject(fromValue) ・BaseResponseDto(fromResponse) ・array<Dto / Enum / ValueObject> ※ arrayの中身は @var list のDocBlockから推測する

BaseValueObject 値オブジェクト用の基底クラス。

・fromValue() を必須化 ・validate() を必須化 ・実装忘れは即例外(fail fast)

QueryNestOpenMode クエリ生成時に、配列などのネストをどう展開するかを指定するEnum。

・JSONIZE a=[1,2,3]

・IMPLODE_COMMA a=1,2,3

使用例(Request DTO)

final readonly class SearchRequest extends BaseRequestDto { public function __construct( public ?string $q = null, public int $limit = 10, public array $tags = [], ) {} }

$req = SearchRequest::empty() ->setQ('test') ->setLimit(20) ->setTags(['php', 'api']);

$query = $req->toQuery(QueryNestOpenMode::IMPLODE_COMMA); q=test&limit=20&tags=php,api

使用例(Response DTO)

final readonly class UserResponse extends BaseResponseDto { public function __construct( public int $id, public string $name, ) {} }

$user = UserResponse::fromResponse([ 'id' => 1, 'name' => 'Alice', ]);

設計方針

・DTOは状態を持たない ・DTOにロジックを書かない ・setterは immutable 前提 ・private / protected プロパティは使わない ・setAccessible() は使わない(PHP 8.1+ 対応)

「賢いDTO」ではなく 「壊れにくいDTO」を目指している。

向いている人

・APIクライアントを自作している ・古いSDKのdeprecatedに苦しんでいる ・arrayベタ書きDTOに疲れた ・PHP 8.1+ 前提で書きたい

向いていない人

・フルDDDフレームワークが欲しい人 ・魔法の自動マッピングが好きな人 ・DTOにビジネスロジックを書きたい人

ライセンス MIT


All versions of api-dto with dependencies

PHP Build Version
Package Version
No informations.
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package keisukesaichi/api-dto contains the following files

Loading the files please wait ...