Skip to content
On this page

Services

Services are any classes that perform additional ad hoc functions on top of the basic MVC structure.

They often get called by Controllers, but can also get called from Models or other Services depending on the use case.

For example you might have a service that generates fake data for a particular form during development, or another that calls a web api, or one that triggers a process.

Often, we use them to spin off functionality where another class is becoming or might become too heavy, in order to follow the single responsiblity principle.

The directory for generic services, is app/Services.

TIP

Where you have a number of related services that perform a particular type of functionality, and you start to see a pattern where they could be logically grouped together, you might want to rename and namespace them accordingly, and create an interface to formalise the api.

For example, in Forme apps, Registries are services that register WordPress features using the register method.

Code Generation

You can use the code generator.

bash
forme make service FooBar

This will create a new service called FooBarService in the app/Services folder.

Made by Moussa Clarke @ Sanders Web Works with ❤️