| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | namespace seregazhuk\HeadHunterApi\EndPoints; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | use seregazhuk\HeadHunterApi\Exceptions\HeadHunterApiException; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  |  * Class Suggests | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |  * @method educationalInstitutions(string $text, string $locale = 'RU') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * @method companies(string $text, string $locale = 'RU') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * @method fieldsOfStudy(string $text, string $locale = 'RU') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @method skillSet(string $text, string $locale = 'RU') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  * @method positions(string $text, string $locale = 'RU') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  * @method areas(string $text, string $locale = 'RU') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |  * @method vacancySearchKeyword(string $text, string $locale = 'RU') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |  * @package seregazhuk\HeadHunterApi\EndPoints | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  | class Suggests extends Endpoint | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     const RESOURCE = 'suggests'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |      * @var array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     protected $suggestions = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         'educationalInstitutions', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         'companies', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         'fieldsOfStudy', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         'skillSet', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         'positions', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         'areas', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         'vacancySearchKeyword', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     public function __call($name, $arguments) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |         if(!in_array($name, $this->suggestions)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |             throw new HeadHunterApiException("Suggestion $name not allowed"); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |         $methodName = $this->resolveSuggestionName($name); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |         return $this->getSuggestsFor($methodName, ...$arguments); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @param string $verb | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      * @param string $text | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |      * @param string $locale | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |      * @return array | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |     protected function getSuggestsFor($verb, $text, $locale = 'RU') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         return $this->getResource($verb, ['text' => $text, 'locale' => $locale]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @param $suggestion | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @return string | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 62 |  |  |      */ | 
            
                                                        
            
                                    
            
            
                | 63 |  |  |     protected function resolveSuggestionName($suggestion) | 
            
                                                        
            
                                    
            
            
                | 64 |  |  |     { | 
            
                                                        
            
                                    
            
            
                | 65 |  |  |         return strtolower(preg_replace('([A-Z])', '_$0', $suggestion)); | 
            
                                                        
            
                                    
            
            
                | 66 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 67 |  |  | } |