I have a "Validator" class that can perform arbitrary checks on a data array. For example, check the string length of a given value in an array. The validator can also check the setpoint and see if it is unique in the database.
I would like to make the correct dependency injection in this class, however I am struggling with how to implement it in this scenario. Validator is not required connecting the database to the function. All other validation checks work fine without connecting to the database. Right now I have the option to specify a connection using property injection. Or, if the connection is not established by pasting properties, I use the Locator service template to resolve the default connection from the IoC container.
Am I doing it wrong? What is the correct way to handle class dependencies that are not required for the class to function?
I am currently using the validator as follows:
$rules = array( 'email' => 'required|unqiue:users', 'password' => 'required|confirmed', ); $validator = new Validator($attributes, $rules);
Of course, the "unique" rule tells the validator to check the uniqueness of the email address in the "users" table.
source share