I would like to run my function hashPassword, which is in my class, from the command line. I have found many post on the topic but I never succeed to make it run apparently.
How should I run it ?
<?php
namespace App;
use App\Entity\User;
use Doctrine\ORM\EntityManagerInterface;
class TestHashPassword
{
private $entityManager;
private $passwordHasher;
public function __construct(EntityManagerInterface $em,UserPasswordHasherInterface $passwordHasherInterface){
$this->entityManager = $em;
$this->passwordHasher = $passwordHasherInterface;
parent::__construct();
}
public function hashPassword(){
$userAll = $this->entityManager
->getRepository(User::class)
->findAll();
echo("coucou");
foreach($userAll as $user){
$comb = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$pass = array();
$combLen = strlen($comb) - 1;
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $combLen);
$pass[] = $comb[$n];
};
echo("coucou");
$user->setDescription($pass);
$hashedPassword = $this->passwordHasher->hashPassword(
$user,
$pass
);
$user->setPassword($hashedPassword);
$this->entityManager->persist($user);
$this->entityManager->flush();
}
}
}
I have tried :
php -r "include 'App\TestHashPassword.php'; TestHashPassword::hashPassword();"
php -r "include 'TestHashPassword.php'; TestHashPassword::hashPassword();"
php "require 'TestHashPassword.php'; hashPassword();"
php -r "require 'TestHashPassword.php'; hashPassword();"
...
I also have tested without the require or include. Tried with another file which call the function but nothing works.