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.
in fact the action Pattern is called command Pattern
– Pedro Sanção