MichelAuthPackage.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Michel\Auth\MichelPackage;
  3. use Michel\Auth\Command\AuthPasswordHashCommand;
  4. use Michel\Auth\Handler\FormAuthHandler;
  5. use Michel\Auth\Middlewares\AuthMiddleware;
  6. use Michel\Auth\UserProviderInterface;
  7. use Michel\Package\PackageInterface;
  8. use Michel\Session\Storage\SessionStorageInterface;
  9. use Psr\Container\ContainerInterface;
  10. use Psr\Http\Message\ResponseFactoryInterface;
  11. use Psr\Log\LoggerInterface;
  12. class MichelAuthPackage implements PackageInterface
  13. {
  14. public function getDefinitions(): array
  15. {
  16. return [
  17. AuthMiddleware::class => static function (ContainerInterface $container) {
  18. return new AuthMiddleware(
  19. $container->get(FormAuthHandler::class),
  20. $container->get(ResponseFactoryInterface::class),
  21. $container->get(LoggerInterface::class)
  22. );
  23. },
  24. FormAuthHandler::class => static function (ContainerInterface $container) {
  25. return new FormAuthHandler(
  26. $container->get(UserProviderInterface::class),
  27. $container->get(SessionStorageInterface::class),
  28. [
  29. 'login_path' => $container->get('auth.form_login_path'),
  30. 'login_key' => $container->get('auth.form_login_key'),
  31. 'password_key' => $container->get('auth.form_password_key'),
  32. 'on_failure' => $container->get('auth.form_on_failure')
  33. ]
  34. );
  35. },
  36. ];
  37. }
  38. public function getParameters(): array
  39. {
  40. return [
  41. 'auth.form_login_path' => '/login',
  42. 'auth.form_login_key' => '_username',
  43. 'auth.form_password_key' => '_password',
  44. 'auth.form_on_failure' => null
  45. ];
  46. }
  47. public function getRoutes(): array
  48. {
  49. return [];
  50. }
  51. public function getControllerSources(): array
  52. {
  53. return [];
  54. }
  55. public function getListeners(): array
  56. {
  57. return [];
  58. }
  59. public function getCommandSources(): array
  60. {
  61. return [
  62. AuthPasswordHashCommand::class
  63. ];
  64. }
  65. }