Drupal Services Muzaffargarh
Drupal introduces the concept of services to decouple reusable functionality and makes these services plug gable and replaceable by registering them with a service container.
Another important benefit of dependency injection is that code will be easier to test via PHP Unit tests, because your domain's business logic will be separated from the huge amount of Drupal dependencies. Dependency injection makes testing your unique business logic much easier and reduces the processing time. The official PHP Unit documentation teaches you how to write tests for your unique business logic.
As a developer, it is best practice to access any of the services provided by Drupal via the service container to ensure the decoupled nature of these systems is respected. The Symphony documentation has a great introduction to services.
As a developer, services are used to perform operations like accessing the database or sending an e-mail. Rather than use PHP's native MySQL functions, we use the core-provided service via the service container to perform this operation so that our code can simply access the database without having to worry about whether the database is MySQL or SQLite, or if the mechanism for sending e-mail is SMTP or something else.
The Service Container
This is the second part of the ‘Understanding Drupal 8’ article. In the first part, we have seen the general structure of Drupal and how it relates to Symfony. Symfony (and Drupal 8) consists out of several components. In this article you will learn about the service container and how it is used in Drupal 8. It is very important to know about it before learning about routing.
No comments:
Post a Comment