![]() So, how do you get an implementation of a contract? It's actually quite simple. 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. In general, most applications can use facades without issue during development. As long as you are keeping your class' responsibilities focused, you will notice very few practical differences between using contracts and facades. ![]() Some parts of your applications may use facades while others depend on contracts. Contracts and facades are not mutually exclusive. Both contracts and facades can be used to create robust, well-tested Laravel applications. The decision to use contracts or facades will come down to personal taste and the tastes of your development team. 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. Unlike facades, which do not require you to require them in your class' constructor, contracts allow you to define explicit dependencies for your classes. ![]() In most cases, each facade has an equivalent contract. Laravel's 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. ![]() 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. For example, Laravel provides a queue implementation with a variety of drivers, and a mailer implementation that is powered by Symfony Mailer.Īll of the Laravel contracts live in their own GitHub repository. 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.Įach contract has a corresponding implementation provided by the framework. Laravel's "contracts" are a set of interfaces that define the core services provided by the framework. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |