php - How to handle dependencies that aren't "real" dependencies? -


I have a "validator" class that can perform arbitrary check on the array of data, for example, given within the array Check the length of the string for the value. Valuator can also check a given value and see whether it is unique in a database.

I would like to have proper dependency injection on this class, however, how do I implement it on this scenario. All other verification checks work fine without database connection that does not require a database connection to perform validation functions. Right now, I have the option of specifying the connection using property injection. Or, if a connection property is not specified by injection, then I am using Service Locator Pattern to resolve the default connection from the IoC container.

Am I doing this wrong? What is the correct way to handle the dependence of the class which is not necessary for the class to work?

I currently consume such verification:

  $ rules = array 'email' = & gt; 'Expected | Combined: user ',' password '= & gt; 'Required | Confirmation',); $ Validator = new validator ($ attributes, $ rules);   

Of course, the "unique" rule tells the verifier to check the specificity of the e-mail address on the "Users" table.

Use the interface or intangible class to load only the proper implementation for the current case. Personally, I do not have to use any of these, but they are specially designed to solve dependency problems.

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -