Luminova Framework

PHP Luminova: Group Attributes for CLI Command Controllers

Last updated: 2026-11-28 20:57:12

Set a default command group for a CLI controller and its command attributes.

The Group attribute is designed for CLI command controller classes.It allows you to organize and unify commands within a single controller class, making it easier for the routing system to detect and execute commands efficiently.

The Group attribute was introduced in Luminova version 3.5.6 as part of improvements to the routing attribute compiler. It is applied at the class level and is non-repeatable.

Note:

  • Each attribute-routed command needs a group. Set it on the controller with Group or supply it to the Command attribute.
  • For method-based routing, attributes are not required.

Usages

Command Grouping

The following example demonstrates how to apply the Group attribute to define a command group name for handling CLI command execution.

Basic Example

// /app/Controllers/Cli/ListCommand.php

namespace App\Controllers\Cli;

use Luminova\Base\Cli\AbstractController;
use Luminova\Attributes\Group;
use Luminova\Attributes\Command;

#[Group(name: 'list')]
class ListCommand extends AbstractController
{
   // Group name matches the Group attribute
   protected string $group = 'list';

   public function help(array $helps): int
   {
      return STATUS_ERROR;
   }

   #[Command('users')]
   #[Command('users/limit/(:int)')]
   public function listCommand(int|string $limit = 10): int
   {
      // Method implementation
      return STATUS_SUCCESS;
   }

   // Additional methods handling list-related routes
}

In this example, the ListCommand class handles all commands routes starting with list *, such as index.php list users.


Class Definition

  • Full namespace: Luminova\Attributes\Group
  • This class is final.

__construct

Defines a unique command group to CLI controllers.

This attribute assigns a group name to a routable CLI controller, so all commands within that group share a common name during command routing execution. Each controller can only have one group.

public function __construct(string $name)

Parameters:

ParameterTypeDescription
$namestringDefault command group name, such as list. A command can override it using its group argument.

Only one Group attribute can be assigned to a controller class.