I have a file with employees and I want to import it and make a lot of validations.
I have a service which receives each loaded employee data, does a lot of validations, create or edit the employee based on his name, and persists the entity.
that do stuff with an employee and, after that, create or edit an employee entity and persists it.
class EmployeeModel()
{
public function __contruct(string $employeeName);
public function setEntityManager(EntityManager $em);
}
I don't want to use the container, I want to go with dependency injection.
If I make a
new EmployeeModel("John Doe");
I'll have no entityManager in the $this->em because the setter wasn't called.
I could make a factory, but I don't know how to pass a runtime variable like $employeeName.
All examples I found for parameters in factories work with defined parameters, like in parameters.yml.
model.employee:
class: AppBundle\EmployeeModel
factory_service: factory.employee
factory_method: get
arguments:
- "%this_exists_in_parameter_yml%"
So, what should be the best way to do this?
Basically I need to instantiate a class and, yet, have access to services but I don't want to use the container directly. I would like to go with dependency injection.
Btw, use forms validators won't work since I am not using forms.