Download the PHP package apparel-php/warp without Composer

On this page you can find all versions of the php package apparel-php/warp. 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 warp

Warp - Web Application Routing Preprocessor

Warp は、PHP の Web フレームワーク Woof のためのルーティング機構を提供する拡張ライブラリです。

オブジェクト指向の原則に基づいた、堅牢で型安全なルーティング機構が最大の特徴です。 他の主要フレームワークのルーティング機構に見られるような、リフレクションやマジックメソッドなどの「黒魔術」を排し、 RoutingContext (処理経過をあらわすオブジェクト) と Resolver (URL の解決を担当するクラス) の連携によって、予測可能でスケーラブルなアプリケーション設計を実現します。

Note: Warp は Woof の API に依存する拡張ライブラリであり、単体では動作しません。 また、Woof は Warp の使用を強制するものではなく、小規模なアプリケーションであれば独自のルーティングをスクラッチで実装することも、 別のルーティングライブラリを採用することも可能です。

特徴

基本方針

Warp のルーティングは、以下の 4 つのインタフェースまたはクラスで構成されます。

  1. RoutingContext: 現在のリクエストパスや、未処理のパスセグメントを保持するコンテキストです。
  2. Resolver: コンテキストを評価し、実行すべき Controller を Target として返します。
  3. Target: Resolver の処理結果です。実行すべき Controller が見つかった場合は Target::found(), 見つからなかった場合は Target::empty() でインスタンス化します。
  4. Controller: Web アプリケーションの実際の処理を行い、結果を Response として返します。(Woof 内の API)

Warp のルーティングの仕組みは、DNS の名前解決においてルートサーバーから下位のネームサーバーへと解決を移譲していくシステムに似ています。 巨大なルーティング定義を 1 箇所に集約するのではなく、パスの階層ごとに担当する Resolver を定義し、 責任をリレーしていくことで見通しと保守性を高く保ちます。


ルーティング API の基本

Warp のルーティング機構を利用する上で前提となる「セグメント」の概念と、 RoutingContext が提供する主要 API について説明します。

これらの前提を踏まえ、Resolver 内で以下のメソッドを活用してルーティングを行います。


使い方 (サンプルアプリケーション)

以下のような URL 構成を持つオウンドメディアおよびその管理画面システムを例に、Warp の実装パターンを紹介します。

1. フロントコントローラ (index.php)

アプリケーションの起点となる index.php の構成例です。 HTTP リクエストを受け取り、RootResolver を起点として解決された Controller を実行します。

2. RootResolver (アプリケーションの入り口)

アプリケーションのルート階層を担当する Resolver です。静的なパスを完全一致 (getPartialPath()) で解決しつつ、特定のディレクトリへのアクセスは専用の子 Resolver へ移譲 (shift()) します。

3. AdminResolver (管理画面のルーティング)

移譲された AdminResolver では、管理画面固有の機能をルーティングします。 余分なセグメント (例: /admin/login/extra) が存在した場合は 404 扱いにする必要があるため、 完全一致 (getPartialPath()) でマッチングを行います。 さらに深い /admin/posts/ 以下の階層の処理については、別の子 Resolver へと分割します。

4. 動的パラメータのマッチングと前処理の分離

/admin/posts/{id}/... のような各種 CRUD 操作では、Warp の matchPath() を利用してプレースホルダを抽出します。 Warp では Resolver 内で直接データベースへのアクセス (エンティティの存在確認) を行わず、 前処理用のコントローラー(今回のサンプルでは PostItemActionController) に解決させることで、 ルーティングのパフォーマンスと保守性を高める設計を推奨しています。

5. 前処理コントローラーでのエンティティ取得と分岐

PostItemActionController は、リクエストの実行フェーズ (handle()) で初めてデータベースからエンティティを取得します。 取得できなかった場合は 404 Not Found のレスポンスを返し、存在した場合は switch 文を用いて対象の具象コントローラーへ委譲します。 このパターンを用いることで、共通処理 (存在確認など) をシンプルにまとめることができます。


Tips: URL の正規化 (CanonicalPathResolver)

Warp は末尾のスラッシュの有無や連続するスラッシュを厳密に区別するため、 ユーザーの URL 指定の表記ブレによって意図しない 404 Not Found が発生する可能性があります。 URL のブレを吸収して安全にルーティングを行いたい場合は、起点となる Resolver を CanonicalPathResolver でラップすると便利です。

Tips: シンプルなリダイレクト (RedirectController)

Controller の実装で特定の URL にリダイレクトさせる処理は頻出ですが、 HTTP レスポンスに対する追加処理 (たとえば Cookie の送信やセッションデータの更新など) を伴わないシンプルなリダイレクトで良いのであれば、Warp の提供している Warp\Standard\RedirectController にそのまま処理を渡して、結果を return するという方法が便利です。

インストール

Composer からインストールできます。 例えば下記のコマンドを実行することで vendor ディレクトリ内に追加されて、使えるようになります。

※ 依存ライブラリとして Woof も自動的にインストールされます。

動作要件: PHP 7.0 以上


All versions of warp with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0
apparel-php/woof Version >=1.0
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 apparel-php/warp contains the following files

Loading the files please wait ...