Readouble

Laravel 8.x 契約

イントロダクションIntroduction

Laravelの「契約」は、フレームワークが提供するコアサービスを定義する一連のインターフェイスです。たとえば、Illuminate\Contracts\Queue\Queue契約は、ジョブのキューイングに必要なメソッドを定義し、Illuminate\Contracts\Mail\Mailer契約は、メールの送信に必要なメソッドを定義します。Laravel's "contracts" are a set of interfaces that define the core services provided by the framework. For example, an Illuminate\Contracts\Queue\Queue contract defines the methods needed for queueing jobs, while the Illuminate\Contracts\Mail\Mailer contract defines the methods needed for sending e-mail.

フレームワークが提供する実装が、各契約に対応して用意してあります。たとえばLaravelは、さまざまなドライバを使用したキューの実装や、SwiftMailerを利用したメーラーの実装を提供します。Each contract has a corresponding implementation provided by the framework. For example, Laravel provides a queue implementation with a variety of drivers, and a mailer implementation that is powered by SwiftMailer[https://swiftmailer.symfony.com/].

すべてのLaravel契約は、独自のGitHubリポジトリにあります。これは、利用可能なすべての契約のクイックリファレンスポイントと、Laravelサービスと相互関係するパッケージを構築するときに利用できる単一の分離されたパッケージを提供しています。All of the Laravel contracts live in their own GitHub repository[https://github.com/illuminate/contracts]. This provides a quick reference point for all available contracts, as well as a single, decoupled package that may be utilized when building packages that interact with Laravel services.

契約対ファサードContracts Vs. Facades

Laravelのファサードとヘルパ関数は、サービスコンテナから契約を入力して解決する必要なしに、Laravelのサービスを利用する簡単な方法を提供します。ほとんどの場合、各ファサードには同等の契約があります。Laravel's facades[/docs/{{version}}/facades] and helper functions provide a simple way of utilizing Laravel's services without needing to type-hint and resolve contracts out of the service container. In most cases, each facade has an equivalent contract.

クラスのコンストラクターでファサードをリクエストする必要がないファサードとは異なり、契約を使用すると、クラスの明示的な依存関係を定義できます。一部の開発者は、この方法で依存関係を明示的に定義することを好み、したがって契約を使用することを好みますが、他の開発者はファサードの便利さを楽しんでいます。一般に、ほとんどのアプリケーションは開発中に問題なくファサードを使用できます。Unlike facades, which do not require you to require them in your class' constructor, contracts allow you to define explicit dependencies for your classes. Some developers prefer to explicitly define their dependencies in this way and therefore prefer to use contracts, while other developers enjoy the convenience of facades. In general, most applications can use facades without issue during development.

契約を使うときWhen To Use Contracts

契約またはファサードを使用するかどうかの決定は、個人的な好みと開発チームの好みに依存します。契約とファサードの両方を使用して、堅牢で十分にテストされたLaravelアプリケーションを作成できます。契約とファサードは相互に排他的ではありません。アプリケーションの一部はファサードを使用し、他の部分は契約に依存できます。クラスの責任を集中させている限り、契約とファサードの使用の実際的な違いはほとんどありません。The decision to use contracts or facades will come down to personal taste and the tastes of your development team. Both contracts and facades can be used to create robust, well-tested Laravel applications. Contracts and facades are not mutually exclusive. Some parts of your applications may use facades while others depend on contracts. As long as you are keeping your class' responsibilities focused, you will notice very few practical differences between using contracts and facades.

一般に、ほとんどのアプリケーションは、開発中に問題なくファサードを使用できます。複数のPHPフレームワークと統合するパッケージを構築している場合は、パッケージのcomposer.jsonファイルにLaravelの具体的な実装をリクエストすることなく、illuminate/contractsパッケージを使用してLaravelのサービスとの統合を定義することをお勧めします。In general, most applications can use facades without issue during development. If you are building a package that integrates with multiple PHP frameworks you may wish to use the illuminate/contracts package to define your integration with Laravel's services without the need to require Laravel's concrete implementations in your package's composer.json file.

契約の使用法How To Use Contracts

では、どのようにして契約を実装するのでしょう?本当にとても簡単です。So, how do you get an implementation of a contract? It's actually quite simple.

Laravelの多種のクラスは、サービスコンテナを介して解決されます。これには、コントローラ、イベントリスナ、ミドルウェア、キュー投入するジョブ、さらにルートクロージャまでも含みます。したがって、契約の実装を取得するには、解決されるクラスのコンストラクターでインターフェイスを「タイプヒント」するだけです。Many types of classes in Laravel are resolved through the service container[/docs/{{version}}/container], including controllers, event listeners, middleware, queued jobs, and even route closures. So, to get an implementation of a contract, you can just "type-hint" the interface in the constructor of the class being resolved.

たとえば、以下のイベントリスナを見てください。For example, take a look at this event listener:

<?php

namespace App\Listeners;

use App\Events\OrderWasPlaced;
use App\Models\User;
use Illuminate\Contracts\Redis\Factory;

class CacheOrderInformation
{
    /**
     * Redisファクトリの実装
     *
     * @var \Illuminate\Contracts\Redis\Factory
     */
    protected $redis;

    /**
     * 新しいイベントハンドラインスタンスの生成
     *
     * @param  \Illuminate\Contracts\Redis\Factory  $redis
     * @return void
     */
    public function __construct(Factory $redis)
    {
        $this->redis = $redis;
    }

    /**
     * イベントの処理
     *
     * @param  \App\Events\OrderWasPlaced  $event
     * @return void
     */
    public function handle(OrderWasPlaced $event)
    {
        //
    }
}

このイベントリスナが依存解決されるとき、サービスコンテナはクラスコンストラクタのタイプヒントを読み取り、適切な値を依存注入します。サービスコンテナへの登録の詳細は、ドキュメントをご覧ください。When the event listener is resolved, the service container will read the type-hints on the constructor of the class, and inject the appropriate value. To learn more about registering things in the service container, check out its documentation[/docs/{{version}}/container].

契約リファレンスContract Reference

この一覧表は、すべてのLaravel契約とそれに該当するファサードのクイックリファレンスです。This table provides a quick reference to all of the Laravel contracts and their equivalent facades:

契約Contract ファサードの参照References Facade
Illuminate\Contracts\Auth\Access\AuthorizableIlluminate\Contracts\Auth\Access\Authorizable[https://github.com/illuminate/contracts/blob/{{version}}/Auth/Access/Authorizable.php]     
Illuminate\Contracts\Auth\Access\GateIlluminate\Contracts\Auth\Access\Gate[https://github.com/illuminate/contracts/blob/{{version}}/Auth/Access/Gate.php] GateGate
Illuminate\Contracts\Auth\AuthenticatableIlluminate\Contracts\Auth\Authenticatable[https://github.com/illuminate/contracts/blob/{{version}}/Auth/Authenticatable.php]     
Illuminate\Contracts\Auth\CanResetPasswordIlluminate\Contracts\Auth\CanResetPassword[https://github.com/illuminate/contracts/blob/{{version}}/Auth/CanResetPassword.php]   
Illuminate\Contracts\Auth\FactoryIlluminate\Contracts\Auth\Factory[https://github.com/illuminate/contracts/blob/{{version}}/Auth/Factory.php] AuthAuth
Illuminate\Contracts\Auth\GuardIlluminate\Contracts\Auth\Guard[https://github.com/illuminate/contracts/blob/{{version}}/Auth/Guard.php] Auth::guard()Auth::guard()
Illuminate\Contracts\Auth\PasswordBrokerIlluminate\Contracts\Auth\PasswordBroker[https://github.com/illuminate/contracts/blob/{{version}}/Auth/PasswordBroker.php] Password::broker()Password::broker()
Illuminate\Contracts\Auth\PasswordBrokerFactoryIlluminate\Contracts\Auth\PasswordBrokerFactory[https://github.com/illuminate/contracts/blob/{{version}}/Auth/PasswordBrokerFactory.php] PasswordPassword
Illuminate\Contracts\Auth\StatefulGuardIlluminate\Contracts\Auth\StatefulGuard[https://github.com/illuminate/contracts/blob/{{version}}/Auth/StatefulGuard.php]   
Illuminate\Contracts\Auth\SupportsBasicAuthIlluminate\Contracts\Auth\SupportsBasicAuth[https://github.com/illuminate/contracts/blob/{{version}}/Auth/SupportsBasicAuth.php]   
Illuminate\Contracts\Auth\UserProviderIlluminate\Contracts\Auth\UserProvider[https://github.com/illuminate/contracts/blob/{{version}}/Auth/UserProvider.php]   
Illuminate\Contracts\Bus\DispatcherIlluminate\Contracts\Bus\Dispatcher[https://github.com/illuminate/contracts/blob/{{version}}/Bus/Dispatcher.php] BusBus
Illuminate\Contracts\Bus\QueueingDispatcherIlluminate\Contracts\Bus\QueueingDispatcher[https://github.com/illuminate/contracts/blob/{{version}}/Bus/QueueingDispatcher.php] Bus::dispatchToQueue()Bus::dispatchToQueue()
Illuminate\Contracts\Broadcasting\FactoryIlluminate\Contracts\Broadcasting\Factory[https://github.com/illuminate/contracts/blob/{{version}}/Broadcasting/Factory.php] BroadcastBroadcast
Illuminate\Contracts\Broadcasting\BroadcasterIlluminate\Contracts\Broadcasting\Broadcaster[https://github.com/illuminate/contracts/blob/{{version}}/Broadcasting/Broadcaster.php] Broadcast::connection()Broadcast::connection()
Illuminate\Contracts\Broadcasting\ShouldBroadcastIlluminate\Contracts\Broadcasting\ShouldBroadcast[https://github.com/illuminate/contracts/blob/{{version}}/Broadcasting/ShouldBroadcast.php]   
Illuminate\Contracts\Broadcasting\ShouldBroadcastNowIlluminate\Contracts\Broadcasting\ShouldBroadcastNow[https://github.com/illuminate/contracts/blob/{{version}}/Broadcasting/ShouldBroadcastNow.php]   
Illuminate\Contracts\Cache\FactoryIlluminate\Contracts\Cache\Factory[https://github.com/illuminate/contracts/blob/{{version}}/Cache/Factory.php] CacheCache
Illuminate\Contracts\Cache\LockIlluminate\Contracts\Cache\Lock[https://github.com/illuminate/contracts/blob/{{version}}/Cache/Lock.php]   
Illuminate\Contracts\Cache\LockProviderIlluminate\Contracts\Cache\LockProvider[https://github.com/illuminate/contracts/blob/{{version}}/Cache/LockProvider.php]   
Illuminate\Contracts\Cache\RepositoryIlluminate\Contracts\Cache\Repository[https://github.com/illuminate/contracts/blob/{{version}}/Cache/Repository.php] Cache::driver()Cache::driver()
Illuminate\Contracts\Cache\StoreIlluminate\Contracts\Cache\Store[https://github.com/illuminate/contracts/blob/{{version}}/Cache/Store.php]   
Illuminate\Contracts\Config\RepositoryIlluminate\Contracts\Config\Repository[https://github.com/illuminate/contracts/blob/{{version}}/Config/Repository.php] ConfigConfig
Illuminate\Contracts\Console\ApplicationIlluminate\Contracts\Console\Application[https://github.com/illuminate/contracts/blob/{{version}}/Console/Application.php]   
Illuminate\Contracts\Console\KernelIlluminate\Contracts\Console\Kernel[https://github.com/illuminate/contracts/blob/{{version}}/Console/Kernel.php] ArtisanArtisan
Illuminate\Contracts\Container\ContainerIlluminate\Contracts\Container\Container[https://github.com/illuminate/contracts/blob/{{version}}/Container/Container.php] AppApp
Illuminate\Contracts\Cookie\FactoryIlluminate\Contracts\Cookie\Factory[https://github.com/illuminate/contracts/blob/{{version}}/Cookie/Factory.php] CookieCookie
Illuminate\Contracts\Cookie\QueueingFactoryIlluminate\Contracts\Cookie\QueueingFactory[https://github.com/illuminate/contracts/blob/{{version}}/Cookie/QueueingFactory.php] Cookie::queue()Cookie::queue()
Illuminate\Contracts\Database\ModelIdentifierIlluminate\Contracts\Database\ModelIdentifier[https://github.com/illuminate/contracts/blob/{{version}}/Database/ModelIdentifier.php]   
Illuminate\Contracts\Debug\ExceptionHandlerIlluminate\Contracts\Debug\ExceptionHandler[https://github.com/illuminate/contracts/blob/{{version}}/Debug/ExceptionHandler.php]   
Illuminate\Contracts\Encryption\EncrypterIlluminate\Contracts\Encryption\Encrypter[https://github.com/illuminate/contracts/blob/{{version}}/Encryption/Encrypter.php] CryptCrypt
Illuminate\Contracts\Events\DispatcherIlluminate\Contracts\Events\Dispatcher[https://github.com/illuminate/contracts/blob/{{version}}/Events/Dispatcher.php] EventEvent
Illuminate\Contracts\Filesystem\CloudIlluminate\Contracts\Filesystem\Cloud[https://github.com/illuminate/contracts/blob/{{version}}/Filesystem/Cloud.php] Storage::cloud()Storage::cloud()
Illuminate\Contracts\Filesystem\FactoryIlluminate\Contracts\Filesystem\Factory[https://github.com/illuminate/contracts/blob/{{version}}/Filesystem/Factory.php] StorageStorage
Illuminate\Contracts\Filesystem\FilesystemIlluminate\Contracts\Filesystem\Filesystem[https://github.com/illuminate/contracts/blob/{{version}}/Filesystem/Filesystem.php] Storage::disk()Storage::disk()
Illuminate\Contracts\Foundation\ApplicationIlluminate\Contracts\Foundation\Application[https://github.com/illuminate/contracts/blob/{{version}}/Foundation/Application.php] AppApp
Illuminate\Contracts\Hashing\HasherIlluminate\Contracts\Hashing\Hasher[https://github.com/illuminate/contracts/blob/{{version}}/Hashing/Hasher.php] HashHash
Illuminate\Contracts\Http\KernelIlluminate\Contracts\Http\Kernel[https://github.com/illuminate/contracts/blob/{{version}}/Http/Kernel.php]   
Illuminate\Contracts\Mail\MailQueueIlluminate\Contracts\Mail\MailQueue[https://github.com/illuminate/contracts/blob/{{version}}/Mail/MailQueue.php] Mail::queue()Mail::queue()
Illuminate\Contracts\Mail\MailableIlluminate\Contracts\Mail\Mailable[https://github.com/illuminate/contracts/blob/{{version}}/Mail/Mailable.php]   
Illuminate\Contracts\Mail\MailerIlluminate\Contracts\Mail\Mailer[https://github.com/illuminate/contracts/blob/{{version}}/Mail/Mailer.php] MailMail
Illuminate\Contracts\Notifications\DispatcherIlluminate\Contracts\Notifications\Dispatcher[https://github.com/illuminate/contracts/blob/{{version}}/Notifications/Dispatcher.php] NotificationNotification
Illuminate\Contracts\Notifications\FactoryIlluminate\Contracts\Notifications\Factory[https://github.com/illuminate/contracts/blob/{{version}}/Notifications/Factory.php] NotificationNotification
Illuminate\Contracts\Pagination\LengthAwarePaginatorIlluminate\Contracts\Pagination\LengthAwarePaginator[https://github.com/illuminate/contracts/blob/{{version}}/Pagination/LengthAwarePaginator.php]   
Illuminate\Contracts\Pagination\PaginatorIlluminate\Contracts\Pagination\Paginator[https://github.com/illuminate/contracts/blob/{{version}}/Pagination/Paginator.php]   
Illuminate\Contracts\Pipeline\HubIlluminate\Contracts\Pipeline\Hub[https://github.com/illuminate/contracts/blob/{{version}}/Pipeline/Hub.php]   
Illuminate\Contracts\Pipeline\PipelineIlluminate\Contracts\Pipeline\Pipeline[https://github.com/illuminate/contracts/blob/{{version}}/Pipeline/Pipeline.php]   
Illuminate\Contracts\Queue\EntityResolverIlluminate\Contracts\Queue\EntityResolver[https://github.com/illuminate/contracts/blob/{{version}}/Queue/EntityResolver.php]   
Illuminate\Contracts\Queue\FactoryIlluminate\Contracts\Queue\Factory[https://github.com/illuminate/contracts/blob/{{version}}/Queue/Factory.php] QueueQueue
Illuminate\Contracts\Queue\JobIlluminate\Contracts\Queue\Job[https://github.com/illuminate/contracts/blob/{{version}}/Queue/Job.php]   
Illuminate\Contracts\Queue\MonitorIlluminate\Contracts\Queue\Monitor[https://github.com/illuminate/contracts/blob/{{version}}/Queue/Monitor.php] QueueQueue
Illuminate\Contracts\Queue\QueueIlluminate\Contracts\Queue\Queue[https://github.com/illuminate/contracts/blob/{{version}}/Queue/Queue.php] Queue::connection()Queue::connection()
Illuminate\Contracts\Queue\QueueableCollectionIlluminate\Contracts\Queue\QueueableCollection[https://github.com/illuminate/contracts/blob/{{version}}/Queue/QueueableCollection.php]   
Illuminate\Contracts\Queue\QueueableEntityIlluminate\Contracts\Queue\QueueableEntity[https://github.com/illuminate/contracts/blob/{{version}}/Queue/QueueableEntity.php]   
Illuminate\Contracts\Queue\ShouldQueueIlluminate\Contracts\Queue\ShouldQueue[https://github.com/illuminate/contracts/blob/{{version}}/Queue/ShouldQueue.php]   
Illuminate\Contracts\Redis\FactoryIlluminate\Contracts\Redis\Factory[https://github.com/illuminate/contracts/blob/{{version}}/Redis/Factory.php] RedisRedis
Illuminate\Contracts\Routing\BindingRegistrarIlluminate\Contracts\Routing\BindingRegistrar[https://github.com/illuminate/contracts/blob/{{version}}/Routing/BindingRegistrar.php] RouteRoute
Illuminate\Contracts\Routing\RegistrarIlluminate\Contracts\Routing\Registrar[https://github.com/illuminate/contracts/blob/{{version}}/Routing/Registrar.php] RouteRoute
Illuminate\Contracts\Routing\ResponseFactoryIlluminate\Contracts\Routing\ResponseFactory[https://github.com/illuminate/contracts/blob/{{version}}/Routing/ResponseFactory.php] ResponseResponse
Illuminate\Contracts\Routing\UrlGeneratorIlluminate\Contracts\Routing\UrlGenerator[https://github.com/illuminate/contracts/blob/{{version}}/Routing/UrlGenerator.php] URLURL
Illuminate\Contracts\Routing\UrlRoutableIlluminate\Contracts\Routing\UrlRoutable[https://github.com/illuminate/contracts/blob/{{version}}/Routing/UrlRoutable.php]   
Illuminate\Contracts\Session\SessionIlluminate\Contracts\Session\Session[https://github.com/illuminate/contracts/blob/{{version}}/Session/Session.php] Session::driver()Session::driver()
Illuminate\Contracts\Support\ArrayableIlluminate\Contracts\Support\Arrayable[https://github.com/illuminate/contracts/blob/{{version}}/Support/Arrayable.php]   
Illuminate\Contracts\Support\HtmlableIlluminate\Contracts\Support\Htmlable[https://github.com/illuminate/contracts/blob/{{version}}/Support/Htmlable.php]   
Illuminate\Contracts\Support\JsonableIlluminate\Contracts\Support\Jsonable[https://github.com/illuminate/contracts/blob/{{version}}/Support/Jsonable.php]   
Illuminate\Contracts\Support\MessageBagIlluminate\Contracts\Support\MessageBag[https://github.com/illuminate/contracts/blob/{{version}}/Support/MessageBag.php]   
Illuminate\Contracts\Support\MessageProviderIlluminate\Contracts\Support\MessageProvider[https://github.com/illuminate/contracts/blob/{{version}}/Support/MessageProvider.php]   
Illuminate\Contracts\Support\RenderableIlluminate\Contracts\Support\Renderable[https://github.com/illuminate/contracts/blob/{{version}}/Support/Renderable.php]   
Illuminate\Contracts\Support\ResponsableIlluminate\Contracts\Support\Responsable[https://github.com/illuminate/contracts/blob/{{version}}/Support/Responsable.php]   
Illuminate\Contracts\Translation\LoaderIlluminate\Contracts\Translation\Loader[https://github.com/illuminate/contracts/blob/{{version}}/Translation/Loader.php]   
Illuminate\Contracts\Translation\TranslatorIlluminate\Contracts\Translation\Translator[https://github.com/illuminate/contracts/blob/{{version}}/Translation/Translator.php] LangLang
Illuminate\Contracts\Validation\FactoryIlluminate\Contracts\Validation\Factory[https://github.com/illuminate/contracts/blob/{{version}}/Validation/Factory.php] ValidatorValidator
Illuminate\Contracts\Validation\ImplicitRuleIlluminate\Contracts\Validation\ImplicitRule[https://github.com/illuminate/contracts/blob/{{version}}/Validation/ImplicitRule.php]   
Illuminate\Contracts\Validation\RuleIlluminate\Contracts\Validation\Rule[https://github.com/illuminate/contracts/blob/{{version}}/Validation/Rule.php]   
Illuminate\Contracts\Validation\ValidatesWhenResolvedIlluminate\Contracts\Validation\ValidatesWhenResolved[https://github.com/illuminate/contracts/blob/{{version}}/Validation/ValidatesWhenResolved.php]   
Illuminate\Contracts\Validation\ValidatorIlluminate\Contracts\Validation\Validator[https://github.com/illuminate/contracts/blob/{{version}}/Validation/Validator.php] Validator::make()Validator::make()
Illuminate\Contracts\View\EngineIlluminate\Contracts\View\Engine[https://github.com/illuminate/contracts/blob/{{version}}/View/Engine.php]   
Illuminate\Contracts\View\FactoryIlluminate\Contracts\View\Factory[https://github.com/illuminate/contracts/blob/{{version}}/View/Factory.php] ViewView
Illuminate\Contracts\View\ViewIlluminate\Contracts\View\View[https://github.com/illuminate/contracts/blob/{{version}}/View/View.php] View::make()View::make()

章選択

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

テストコード表示
両コード表示
Pestのみ表示
PHPUnitのみ表示
OS表示
全OS表示
macOSのみ表示
windowsのみ表示
linuxのみ表示
和文変換

対象文字列と置換文字列を半角スペースで区切ってください。(最大5組各10文字まで)

本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作