Download the PHP package tanahiro2010/slim-router-dsl without Composer

On this page you can find all versions of the php package tanahiro2010/slim-router-dsl. 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 slim-router-dsl

Slim Router DSL

Slim Framework のルーティングを「登録処理」ではなく「宣言的なルートツリー」として定義し、Routes::deploy() によってSlimへ展開する軽量DSLライブラリです。

このコードだけで、/api 配下・Auth Middleware適用・usersエンドポイント群・deploy() によるSlimへの登録、という構造が一目でわかります。

詳細なドキュメントは /example を参照してください。

インストール

なぜ使うか

Slim標準のルーティングは以下のように命令的に登録します。

ルート数やネストが増えると、構造と登録処理が混在し、Middlewareの適用範囲も視覚的に把握しにくくなります。

Slim Router DSLでは、ルーティングをまずデータ構造として定義し、deploy() によって初めてSlimへ登録します。DSL定義の時点ではSlimへの副作用は一切発生しません。

基本API

HTTP Route

Handlerには Callable、[Controller::class, 'method']、Invokable Classのいずれも指定できます。Controllerの解決は行わずSlim / Containerに委ねます。

Group

Groupはネスト可能で、パスは子ノードへ継承されます。/api + /users/api/ + /users/api + users はいずれも /api/users に正規化されます。

Middleware

MiddlewareはGroupと自由にネストでき、Middleware情報は子ノードへ継承されます。DSL上で記述した順序(外側 → 内側)と実行順序が一致するように deploy() 時に登録順が調整されます。

Route単位のFluent Middleware / Route Name

HttpRoute はimmutableなので、middleware() / name() はどちらも新しいインスタンスを返します。元のインスタンスは変更されません。Route単位のmiddlewareは、GroupやMiddlewareから継承したmiddlewareより後(Handlerに最も近い位置)に実行されます。name() で指定した名前は deploy() 時にSlimの setName() に渡されます。

Metadata

meta() もimmutableな Fluent APIで、複数回呼び出すと後から指定したキーが上書きされる形でマージされます(Group/Middleware単位での継承は行わず、Route単位のみ)。付与したメタデータは compile()/toArray() の結果や filter() から参照できます。

Route Dump / toArray() / compile()

列は dump(bool $showMiddleware = true, bool $showName = true, bool $showHandler = false) で調整できます。

compile() は同じ内容を CompiledRoute[]methods/path/handler/middleware/name/metadata を持つreadonlyオブジェクト)として返す、より低レベルなAPIです。toArray()/dump()/後述のInspection APIはすべてこの compile() の結果を利用しています。

いずれもSlimへdeploy()する前に呼び出せる、Slimに依存しないルートツリーの解析APIです。

Route Inspection

Validation

deploy() 前に呼び出すことで、以下を検出できます(deploy() は自動でvalidateしません、明示的に呼び出してください)。

いずれも最初に見つかった時点でthrowされます(method+pathの重複チェックが先、name重複チェックが後)。

Route::resource()

展開結果(Handlerはそれぞれ [UserController::class, '<action>']):

only/except で生成対象を絞り込めます(同時指定は InvalidRouteException)。

Route::controller()

Route::controller() の配下では、Handlerに文字列を渡すと [UserController::class, '<文字列>'] として解決されます。Closureや [Class, method] 配列など文字列以外のHandlerは影響を受けません。また Route::controller() の外側で文字列Handlerを使う場合(Slimのコンテナ名解決など)は従来通り変化しません。Route::group()/Route::middleware() と自由にネストできます。

deploy()

Routes の構築時点ではルートツリーをメモリ上に構築するだけで、deploy(App $app) を呼んだ時点で初めてSlimへ登録されます。

CLI

--bootstrap で指定したPHPファイルが Routes インスタンスを return する必要があります(未指定時はカレントディレクトリの ./routes.php を探索)。

routes コマンドはSlimの App を一切生成せず Routes::compile()/dump()/toArray()(v1.1)のみを利用するため、DIコンテナ全体を起動せずにルート一覧を確認できます。validate コマンドは Routes::validate()(v1.1)を実行し、問題があればexit code 1で終了します。

例外

すべてのライブラリ独自例外は RouterDslExceptionRuntimeException を継承)を共通の基底とし、一括catchできます。

v1 Scope

v1.0では以下を提供しました(MVP Scope + Optional Scope)。

v1.1では以下を追加しました。

v1.2では以下を追加しました。

v1.3では以下を追加しました。

v1.4では以下を追加しました。

詳細は slim-router-dsl-prd.md を参照してください。

動作要件

テスト

License

MIT License. 詳細は LICENSE を参照してください。


All versions of slim-router-dsl with dependencies

PHP Build Version
Package Version
Requires slim/slim Version ^4.15
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 tanahiro2010/slim-router-dsl contains the following files

Loading the files please wait ...