Module Development

PHP Service Classes for Drupal 8, 9

Sprout Video

In this course, we're going to continue on from the Introduction to Object-Oriented PHP series. We're working on the same spaceship project: it has ships, you choose them, then they engage in epic battle!

In an editor, far far away, you'll see a simple application that runs this: index.php is the homepage and battle.php does the magic and shows the results. In the first course, we created a single class called Ship, which describes all its properties—it's like a container for one ship's details. In this tutorial we're going to replace our flat functions and create a BattleManager service class to provide the methods we'll need to do that.