{ "uuid": [ { "value": "15089c84-d265-4024-981e-e3c1ca354659" } ], "langcode": [ { "value": "en" } ], "type": [ { "target_id": "daily_email", "target_type": "node_type", "target_uuid": "8bde1f2f-eef9-4f2d-ae9c-96921f8193d7" } ], "revision_timestamp": [ { "value": "2025-06-23T21:19:48+00:00" } ], "revision_uid": [ { "target_type": "user", "target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849" } ], "revision_log": [], "status": [ { "value": true } ], "uid": [ { "target_type": "user", "target_uuid": "b8966985-d4b2-42a7-a319-2e94ccfbb849" } ], "title": [ { "value": "My thoughts on the Action pattern" } ], "created": [ { "value": "2025-06-20T20:26:30+00:00" } ], "changed": [ { "value": "2025-06-23T21:19:48+00:00" } ], "promote": [ { "value": false } ], "sticky": [ { "value": false } ], "default_langcode": [ { "value": true } ], "revision_translation_affected": [ { "value": true } ], "path": [ { "alias": "\/daily\/2025\/06\/20\/my-thoughts-action-pattern", "langcode": "en" } ], "body": [ { "value": "The Action pattern is a relatively new design pattern that's become popular in the PHP community, particularly with Laravel Developers.\r\n\r\nThe pattern is a simplified version of the Command pattern, with no separate Handler class. The Action class is responsible for the handling and execution logic.\r\n\r\nIn most cases, an Action class only has a single public method called `execute()` or `handle()`, or uses PHP's `__invoke()` magic method.\r\n\r\nThis is a different approach from a Service class that has multiple methods to perform different tasks.\r\n\r\nHere's a simplified version of the code of an Action from my website:\r\n\r\n```php\r\nThe Action pattern is a relatively new design pattern that's become popular in the PHP community, particularly with Laravel Developers.<\/p>\n
The pattern is a simplified version of the Command pattern, with no separate Handler class. The Action class is responsible for the handling and execution logic.<\/p>\n
In most cases, an Action class only has a single public method called This is a different approach from a Service class that has multiple methods to perform different tasks.<\/p>\n Here's a simplified version of the code of an Action from my website:<\/p>\nexecute()<\/code> or
handle()<\/code>, or uses PHP's
__invoke()<\/code> magic method.<\/p>\n
<?php\n\nreadonly final class AddRandomCtaToDailyEmail {\n\n public function __construct(private EntityTypeManagerInterface $entityTypeManager) {\n }\n\n public function __invoke(DailyEmail $email): void {\n \/\/ Checks a call to action isn't already added.\n \/\/ If not, a random one is selected and added.\n }\n\n}\n<\/code><\/pre>