| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  | // Copyright 1999-2019. Plesk International GmbH. | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | namespace PleskX\Api\Operator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | use PleskX\Api\Struct\SiteAlias as Struct; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | class SiteAlias extends \PleskX\Api\Operator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |      * @param array $properties | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |      * @param array $preferences | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |      * @return Struct\Info | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |     public function create(array $properties, array $preferences = []) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |         $packet = $this->_client->getPacket(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |         $info = $packet->addChild($this->_wrapperTag)->addChild('create'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |         if (count($preferences) > 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |             $prefs = $info->addChild('pref'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |             foreach ($preferences as $key => $value) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |                 $prefs->addChild($key, is_bool($value) ? ($value ? 1 : 0) : $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |             } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         $info->addChild('site-id', $properties['site-id']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         $info->addChild('name', $properties['name']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |         $response = $this->_client->request($packet); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         return new Struct\Info($response); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |      * @param string $field | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |      * @param integer|string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @return Struct\Info | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |     public function get($field, $value) | 
            
                                                                        
                            
            
                                    
            
            
                | 41 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |         $items = $this->getAll($field, $value); | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |         return reset($items); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |      * @param string $field | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * @param integer|string $value | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      * @return Struct\Info[] | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 51 |  | View Code Duplication |     public function getAll($field = null, $value = null) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |         $packet = $this->_client->getPacket(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |         $getTag = $packet->addChild($this->_wrapperTag)->addChild('get'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |         $filterTag = $getTag->addChild('filter'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |         if (!is_null($field)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             $filterTag->addChild($field, $value); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |         $response = $this->_client->request($packet, \PleskX\Api\Client::RESPONSE_FULL); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $items = []; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |         foreach ($response->xpath('//result') as $xmlResult) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             $item = new Struct\GeneralInfo($xmlResult->info); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |             $items[] = $item; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         return $items; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 69 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 70 |  |  |  |