N
N
nepster-web2017-02-09 13:34:56
PHP
nepster-web, 2017-02-09 13:34:56

How to reduce component coupling?

I am designing an application. There are the following concepts:
- components
- modules
- core
I have the following dilemma:
There is an auth component, jwt and a User module. The fact is that I need to authenticate the user by login and password (the auth component answers), give the user a jwt token (while making all the necessary entries in the database, the jwt component), and actually use the User entity and the repository from the User module.
It turns out that each of the components must know about the User module (more precisely, about the User entity and the repository).
However it would be desirable to reduce all this business with connectivity to a minimum.
For example, what the authentication component will look like:

public function attempt(CredentialsDTO $credentials)
    {
        $username = $credentials->getUsername();
        $password = $credentials->getPassword();

        if ($passwordHash = $this->userRepository->findPasswordHashByUsername($username)) {
            if ($this->hasher->check($password, $passwordHash)) {
                 $user = $this->userRepository->findByUsername($username);
                
                // TODO: сгенерировать jwt токен 
                
            }
        }
       
        return false;
    }

As it turns out, the auth component needs the User entity, the repository, and the jwt component to generate the token.
What is the right way to get away from this connection?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shagguboy, 2017-02-10
@shagguboy

pass everything necessary for the class to work, or to the constructor, or to the method, or to plant it through setters. classic Inversion of control

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question