I have a tree of Employee objects (they are in a tree-like hierarchy, with everyone having one leader, and all leaders having more employees). All the Employees have a integer parameter called units.
/** * @ORM\Entity * @ORM\Table(name="employees") */ class Employee { /** * @ORM\Id * @ORM\Column(strategy="AUTO") */ protected $id; /** * @ORM\OneToMany(targetEntity="Employee", mappedBy="leader") */ protected $employees; /** * @ORM\ManyToOne(targetEntity("Employee", inversedBy="employees") */ protected $leader; } I need to get all the employees, who have at most N units, where N is defined in config.yml. At first, I was trying to push $configContainer into $GLOBALS, and use it in ArrayCollection::filter()'s Closure. Now I found a method, so I can use variables in the Closure:
public function getBestEmployees(&$configContainer) { return $this->getAllEmployees()->filter( function bestEmployees($employee) use ($configContainer) { return ($employee->getUnits() >= $configContainer->getParameter('best_unit_count')); } ); } Now I wonder if there is any other way to access the configuration parameters from an Entity, or do I really have to pass the whole configContainer as a reference? Or am I doing it totally wrong?