Action Pattern VS. Controller Pattern: What’s the difference?

Asked

Viewed 37 times

2

I was taking a look at the architecture of a PHP project, and I noticed the use of Action Pattern instead of Controller Pattern.

I would like to know the difference between the Standards as well as understand the advantages and devaluations of each of them.

The following is an example of an Action Pattern:

abstract class UserAction extends Action
{
    /**
     * @var UserRepository
     */
    protected $userRepository;

    /**
     * @param LoggerInterface $logger
     * @param UserRepository  $userRepository
     */
    public function __construct(LoggerInterface $logger, UserRepository $userRepository)
    {
        parent::__construct($logger);
        $this->userRepository = $userRepository;
    }
}

A class that inherits this abstract basis:

class ListUsersAction extends UserAction
{
    /**
     * {@inheritdoc}
     */
    protected function action(): Response
    {
        $users = $this->userRepository->findAll();

        $this->logger->info("Users list was viewed.");

        return $this->respondWithData($users);
    }
}

Grateful for the help.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.