Skip to content

[Workflow] Add a method to the Registry which returns all workflows associated to a certain object #26618

@alexpozzi

Description

@alexpozzi
Q A
Bug report? no
Feature request? yes
BC Break report? no
RFC? no
Symfony version 3.4.x/4.x

First of all thanks for the great work!

It would be great to have a method in the Registry class that returns all the workflows associated to a specific object class.
This would add the possibility to easily implement, for example, an admin UI where the admin can see the status of all the workflows associated to a specific object.

Would it be useful?
Is there a reason why it has not been implemented yet?

I would implement it this way:

class Registry
{
   ...

   /**
     * @param object      $subject
     *
     * @return Workflow[]
     */
    public function all($subject)
    {
        $matched = array();
        foreach ($this->workflows as list($workflow, $supportStrategy)) {
            if ($supportStrategy->supports($workflow, $subject)) {
                $matched[] = $workflow;
            }
        }
        if (empty($matched)) {
            throw new InvalidArgumentException(sprintf('Unable to find any workflow for class "%s".', get_class($subject)));
        }
        return $matched;
    }

   ...
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions