Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Text
Posted by: userc865b
Added: Jan 30, 2018 11:12 PM
Modified: Jan 31, 2018 7:56 PM
Views: 20
Tags: symfony
bind class constructor interface dependency injection
  1. // https://symfony.com/doc/current/service_container/autowiring.html
  2.  
  3.    AppBundle\WetterApi\Criteria\CriteriaInterFace: '@AppBundle\WetterApi\Criteria\CriteriaNaming' # default injection of concrete object by interface
  4.  
  5.     daytemp:  '@AppBundle\WetterApi\Criteria\CriteriaDayTemp' # set alias for concrete classes to inject interface
  6.     rival:    '@AppBundle\WetterApi\Criteria\CriteriaRival'
  7.  
  8.     check_criteria:  
  9.         class: AppBundle\WetterApi\CheckCriteria
  10.         arguments:
  11.           $criteria2: '@daytemp' # setting specific classs other then default class for argument 2
  12.           $criteria3: '@rival'  
  13.  
  14.     AppBundle\WetterApi\WeatherData:  # manually injecting specific parameter!
  15.         arguments: ['Hamburg']
  16.  
  17.  
  18. #######################ALTERNATIVE###########################
  19. ####################Manage Criteria###################
  20.     # example: just delete: '@rival' or other critera alias. you can also switch them the order doesnt matter.
  21.     # implement new criteria:
  22.     # 1. create new class in AppBundle\WetterApi\Criteria implement the CriteriaInterface
  23.     # 2. add the Criteria to the AppBundle\WetterApi\Criteria\CheckCriteria constructor
  24.     # 3. add the class alias to the check_criteria arguments thats it!
  25.     check_criteria:
  26.         class: AppBundle\WetterApi\CheckCriteria
  27.         arguments: ['@daytemp', '@rival']
  28.         AppBundle\WetterApi\Criteria\CriteriaInterFace: '@naming' # default match class for CriteriaInterface
  29. ######################################################
  30.     AppBundle\WetterApi\WeatherData:
  31.         arguments: ['%city%'] # injects route parameter (the city the user requested)
  32.  
  33.  
  34.  
  35.