, total: int} * * @since 0.1.0 */ public function handle(): array { $templates = $this->templates->all(); $items = []; foreach ( $templates as $template ) { $items[] = $this->to_admin_array( $template ); } return [ 'items' => $items, 'total' => count( $items ) ]; } /** * Map a template entity to the admin API shape. * * @param NotificationTemplate $template Template entity. * @return array */ private function to_admin_array( NotificationTemplate $template ): array { return [ 'id' => $template->id(), 'key' => $template->key(), 'name' => $this->humanise_key( $template->key() ), 'channel' => $template->channel(), 'enabled' => $template->is_enabled(), ]; } /** * Convert a template key to a human-readable name. * * @param string $key Template key. */ private function humanise_key( string $key ): string { return ucwords( str_replace( [ '_', '.' ], ' ', $key ) ); } }