I am trying to implement Dependency Injection in Symfony.
I created a class named Token as follows:
class Token
{
private $token;
private $key;
public function __construct(string $key)
{
$this->key = $key;
$this->settoken();
}
public function getToken(): string
{
return $this->token;
}
public function setToken(string $newString)
{
$token = $newString . '-' . $this->key;
return $this;
}
}
In the construct, I have a key which is defined in services.yml
Now I have injected this class into another controller like below.
$this->token->setToken('123456789');
dd($this->token->getToken())
But this is giving me 'Too few arguments to function setToken()' error. I think this is because in my Token class construct I have already passed key argument.
I am not sure how to properly use it.
Can anyone please help me.
Thank You.