protected static function generateCapabilities(string $contrName, array $actions, array $assignationFields, string $assignationType = ''): array
    {
        $result = [];

        if (empty($contrName) || empty($actions)) {
            return $result;
        }

        if (empty($assignationFields)) {
            return $result;
        }

        foreach ($actions as $action) {
            // skip rest of the logic if assignment fields are not found
            // or if current action does not support assignment (Example: add / create)
            if (in_array($action, static::$nonAssignedActions)) {
                continue;
            }

            // generate action's owner (assignment field) type capabilities
            foreach ($assignationFields as $assignationField) {
                $label = static::generateCapabilityLabel($contrName, $action . '_' . $assignationField);
                $suffix = ' if ' . (!empty($assignationType) ? $assignationType : 'owner') . ' (' . Inflector::humanize($assignationField) . ')';
                $description = static::generateCapabilityDescription(
                    $contrName,
                    static::humanizeActionName($action) . $suffix
                );
                $field = $assignationField;

                $name = static::generateCapabilityName($contrName, $action . '_' . $assignationField);
                $options = [
                    'label' => $label,
                    'description' => $description,
                    'field' => $field
                ];

                if (!empty($assignationType)) {
                    $result[$assignationType . '_(_' . $assignationField . '_)'][] = new Cap($name, $options);
                } else {
                    $result[] = new Cap($name, $options);
                }
            }
        }

        return $result;
    }
protected static function generateCapabilities(string $contrName, array $actions, array $assignationFields, string $assignationType = ''): array
    {
        $result = [];

        if (empty($contrName) || empty($actions)) {
            return $result;
        }

        if (empty($assignationFields)) {
            return $result;
        }

        foreach ($actions as $action) {
            // skip rest of the logic if assignment fields are not found
            // or if current action does not support assignment (Example: add / create)
            if (in_array($action, static::$nonAssignedActions)) {
                continue;
            }

            // generate action's owner (assignment field) type capabilities
            foreach ($assignationFields as $assignationField) {
                $label = static::generateCapabilityLabel($contrName, $action . '_' . $assignationField);
                $suffix = ' if ' . (!empty($assignationType) ? $assignationType : 'owner') . ' (' . Inflector::humanize($assignationField) . ')';
                $description = static::generateCapabilityDescription(
                    $contrName,
                    static::humanizeActionName($action) . $suffix
                );
                $field = $assignationField;

                $name = static::generateCapabilityName($contrName, $action . '_' . $assignationField);
                $options = [
                    'label' => $label,
                    'description' => $description,
                    'field' => $field
                ];

                if (!empty($assignationType)) {
                    $result[$assignationType . '_(_' . $assignationField . '_)'][] = new Cap($name, $options);
                } else {
                    $result[] = new Cap($name, $options);
                }
            }
        }

        return $result;
    }
protected static function generateCapabilities ( string $ contrName , array $ actions , array $ assignationFields , string $ assignationType = '' ) : array { $ result = [ ] ; if ( empty ( $ contrName ) || empty ( $ actions ) ) { return $ result ; } if ( empty ( $ assignationFields ) ) { return $ result ; } foreach ( $ actions as $ action ) { // skip rest of the logic if assignment fields are not found // or if current action does not support assignment (Example: add / create) if ( in_array ( $ action , static :: $ nonAssignedActions ) ) { continue ; } // generate action's owner (assignment field) type capabilities foreach ( $ assignationFields as $ assignationField ) { $ label = static :: generateCapabilityLabel ( $ contrName , $ action . '_' . $ assignationField ) ; $ suffix = ' if ' . ( ! empty ( $ assignationType ) ? $ assignationType : 'owner' ) . ' (' . Inflector :: humanize ( $ assignationField ) . ')' ; $ description = static :: generateCapabilityDescription ( $ contrName , static :: humanizeActionName ( $ action ) . $ suffix ) ; $ field = $ assignationField ; $ name = static :: generateCapabilityName ( $ contrName , $ action . '_' . $ assignationField ) ; $ options = [ 'label' => $ label , 'description' => $ description , 'field' => $ field ] ; if ( ! empty ( $ assignationType ) ) { $ result [ $ assignationType . '_(_' . $ assignationField . '_)' ] [ ] = new Cap ( $ name , $ options ) ; } else { $ result [ ] = new Cap ( $ name , $ options ) ; } } } return $ result ; }
generateCapabilities method to generate controller belongs to capabilities

@param string $contrName Controller name
@param mixed[] $actions Controller actions
@param mixed[] $assignationFields list of assignation fields
@param string $assignationType Type of association
@return mixed[]
generateCapabilities method to generate controller belongs to capabilities