@@ -9,9 +9,9 @@  | 
                                                    ||
| 9 | 9 | |
| 10 | 10 | class GuzzleClient extends Client  | 
                                                        
| 11 | 11 |  { | 
                                                        
| 12 | - public function __construct(VmwareApiClient $client,array $config = [])  | 
                                                        |
| 12 | + public function __construct(VmwareApiClient $client, array $config=[])  | 
                                                        |
| 13 | 13 |      { | 
                                                        
| 14 | - $guzzleConfig = array_merge([  | 
                                                        |
| 14 | + $guzzleConfig=array_merge([  | 
                                                        |
| 15 | 15 | 'base_uri' => $client->getBaseUrl(),  | 
                                                        
| 16 | 16 | "verify"=>$client->ssl,  | 
                                                        
| 17 | 17 | 'headers' => [  | 
                                                        
@@ -10,10 +10,10 @@  | 
                                                    ||
| 10 | 10 | class ApiResponse  | 
                                                        
| 11 | 11 |  { | 
                                                        
| 12 | 12 | const OK=200;  | 
                                                        
| 13 | -    public static function BodyResponse(ResponseInterface $response){ | 
                                                        |
| 13 | +    public static function BodyResponse(ResponseInterface $response) { | 
                                                        |
| 14 | 14 | return json_decode($response->getBody());  | 
                                                        
| 15 | 15 | }  | 
                                                        
| 16 | -    public static function HasError(ResponseInterface $response){ | 
                                                        |
| 17 | - return !($response->getStatusCode()>=200 and $response->getStatusCode() <300);  | 
                                                        |
| 16 | +    public static function HasError(ResponseInterface $response) { | 
                                                        |
| 17 | + return !($response->getStatusCode()>=200 and $response->getStatusCode()<300);  | 
                                                        |
| 18 | 18 | }  | 
                                                        
| 19 | 19 | }  | 
                                                        
| 20 | 20 | \ No newline at end of file  | 
                                                        
@@ -9,11 +9,11 @@ discard block  | 
                                                    ||
| 9 | 9 | |
| 10 | 10 | class SessionHandler  | 
                                                        
| 11 | 11 |  { | 
                                                        
| 12 | -    public static function getSession(VmwareApiClient $client){ | 
                                                        |
| 12 | +    public static function getSession(VmwareApiClient $client) { | 
                                                        |
| 13 | 13 | self::validateCredentials($client);  | 
                                                        
| 14 | 14 | return self::isSessionExist($client->credential) ? $client->credential['Vmware-Api-Session-Id'] : self::authRequest($client);  | 
                                                        
| 15 | 15 | }  | 
                                                        
| 16 | -    public static function authRequest(VmwareApiClient $client){ | 
                                                        |
| 16 | +    public static function authRequest(VmwareApiClient $client) { | 
                                                        |
| 17 | 17 | $HttpClient=new Client(  | 
                                                        
| 18 | 18 | [  | 
                                                        
| 19 | 19 | "verify"=>$client->ssl,  | 
                                                        
@@ -24,23 +24,23 @@ discard block  | 
                                                    ||
| 24 | 24 | ]  | 
                                                        
| 25 | 25 | ]  | 
                                                        
| 26 | 26 | );  | 
                                                        
| 27 | -        $response=$HttpClient->request('GET',$client->getAuthUrl(),[ | 
                                                        |
| 27 | +        $response=$HttpClient->request('GET', $client->getAuthUrl(), [ | 
                                                        |
| 28 | 28 | "query"=>[  | 
                                                        
| 29 | 29 | "~method"=>"post"  | 
                                                        
| 30 | 30 | ]  | 
                                                        
| 31 | 31 | ]);  | 
                                                        
| 32 | 32 | return json_decode($response->getBody())->value;  | 
                                                        
| 33 | 33 | }  | 
                                                        
| 34 | -    public static function isSessionExist($credential){ | 
                                                        |
| 35 | -        return array_key_exists("Vmware-Api-Session-Id",$credential); | 
                                                        |
| 34 | +    public static function isSessionExist($credential) { | 
                                                        |
| 35 | +        return array_key_exists("Vmware-Api-Session-Id", $credential); | 
                                                        |
| 36 | 36 | }  | 
                                                        
| 37 | 37 | public static function validateCredentials(VmwareApiClient $client)  | 
                                                        
| 38 | 38 |      { | 
                                                        
| 39 | -        if((array_key_exists("username",$client->credential) && array_key_exists("password",$client->credential)) or array_key_exists("Vmware-Api-Session-Id",$client->credential)) | 
                                                        |
| 39 | +        if ((array_key_exists("username", $client->credential) && array_key_exists("password", $client->credential)) or array_key_exists("Vmware-Api-Session-Id", $client->credential)) | 
                                                        |
| 40 | 40 | return true;  | 
                                                        
| 41 | 41 |          throw new CredentialException("required parameter you should send session-id or username-password for auth api "); | 
                                                        
| 42 | 42 | }  | 
                                                        
| 43 | -    public static function convertCredentials($credentials){ | 
                                                        |
| 43 | +    public static function convertCredentials($credentials) { | 
                                                        |
| 44 | 44 | return base64_encode($credentials['username'].":".$credentials['password']);  | 
                                                        
| 45 | 45 | }  | 
                                                        
| 46 | 46 | |
@@ -36,8 +36,9 @@  | 
                                                    ||
| 36 | 36 | }  | 
                                                        
| 37 | 37 | public static function validateCredentials(VmwareApiClient $client)  | 
                                                        
| 38 | 38 |      { | 
                                                        
| 39 | -        if((array_key_exists("username",$client->credential) && array_key_exists("password",$client->credential)) or array_key_exists("Vmware-Api-Session-Id",$client->credential)) | 
                                                        |
| 40 | - return true;  | 
                                                        |
| 39 | +        if((array_key_exists("username",$client->credential) && array_key_exists("password",$client->credential)) or array_key_exists("Vmware-Api-Session-Id",$client->credential)) { | 
                                                        |
| 40 | + return true;  | 
                                                        |
| 41 | + }  | 
                                                        |
| 41 | 42 |          throw new CredentialException("required parameter you should send session-id or username-password for auth api "); | 
                                                        
| 42 | 43 | }  | 
                                                        
| 43 | 44 |      public static function convertCredentials($credentials){ | 
                                                        
@@ -12,8 +12,8 @@  | 
                                                    ||
| 12 | 12 | class ConsoleTickets extends InitClass  | 
                                                        
| 13 | 13 |  { | 
                                                        
| 14 | 14 | use MOID;  | 
                                                        
| 15 | -    public function createConsoleTickets(array $body,$moid=null){ | 
                                                        |
| 16 | -        return ApiResponse::BodyResponse($this->HttpClient->post("vm/{$this->getMoid($moid)}/console/tickets",[ | 
                                                        |
| 15 | +    public function createConsoleTickets(array $body, $moid=null) { | 
                                                        |
| 16 | +        return ApiResponse::BodyResponse($this->HttpClient->post("vm/{$this->getMoid($moid)}/console/tickets", [ | 
                                                        |
| 17 | 17 | RequestOptions::JSON=>$body  | 
                                                        
| 18 | 18 | ]));  | 
                                                        
| 19 | 19 | }  | 
                                                        
@@ -21,7 +21,7 @@ discard block  | 
                                                    ||
| 21 | 21 | const POWERED_ON="POWERED_ON";  | 
                                                        
| 22 | 22 | const POWERED_OFF="POWERED_OFF";  | 
                                                        
| 23 | 23 | const SUSPENDED="SUSPENDED";  | 
                                                        
| 24 | - public function __construct(Client $HttpClient,$properties,$moid)  | 
                                                        |
| 24 | + public function __construct(Client $HttpClient, $properties, $moid)  | 
                                                        |
| 25 | 25 |      { | 
                                                        
| 26 | 26 | $this->HttpClient=$HttpClient;  | 
                                                        
| 27 | 27 | $this->properties=isset($properties->value) ? $properties->value : $properties;  | 
                                                        
@@ -31,32 +31,32 @@ discard block  | 
                                                    ||
| 31 | 31 |      { | 
                                                        
| 32 | 32 |          return $this->properties->{$name}; | 
                                                        
| 33 | 33 | }  | 
                                                        
| 34 | -    public function reloadProperties(){ | 
                                                        |
| 34 | +    public function reloadProperties() { | 
                                                        |
| 35 | 35 |          $this->properties=ApiResponse::BodyResponse($this->HttpClient->get("vm/{$this->moid}"))->value; | 
                                                        
| 36 | 36 | return $this;  | 
                                                        
| 37 | 37 | }  | 
                                                        
| 38 | -    public function power(){ | 
                                                        |
| 39 | - return new Power($this->HttpClient,$this);  | 
                                                        |
| 38 | +    public function power() { | 
                                                        |
| 39 | + return new Power($this->HttpClient, $this);  | 
                                                        |
| 40 | 40 | }  | 
                                                        
| 41 | -    public function guestPower(){ | 
                                                        |
| 42 | - return new GuestPower($this->HttpClient,$this);  | 
                                                        |
| 41 | +    public function guestPower() { | 
                                                        |
| 42 | + return new GuestPower($this->HttpClient, $this);  | 
                                                        |
| 43 | 43 | }  | 
                                                        
| 44 | -    public function tools(){ | 
                                                        |
| 45 | - return new Tools($this->HttpClient,$this);  | 
                                                        |
| 44 | +    public function tools() { | 
                                                        |
| 45 | + return new Tools($this->HttpClient, $this);  | 
                                                        |
| 46 | 46 | }  | 
                                                        
| 47 | -    public function consoleTicket(){ | 
                                                        |
| 48 | - return new ConsoleTickets($this->HttpClient,$this);  | 
                                                        |
| 47 | +    public function consoleTicket() { | 
                                                        |
| 48 | + return new ConsoleTickets($this->HttpClient, $this);  | 
                                                        |
| 49 | 49 | }  | 
                                                        
| 50 | -    public function hardWare(){ | 
                                                        |
| 51 | - return new Hardware($this->HttpClient,$this);  | 
                                                        |
| 50 | +    public function hardWare() { | 
                                                        |
| 51 | + return new Hardware($this->HttpClient, $this);  | 
                                                        |
| 52 | 52 | }  | 
                                                        
| 53 | -    public function isPoweredOn(){ | 
                                                        |
| 53 | +    public function isPoweredOn() { | 
                                                        |
| 54 | 54 | return $this->properties->power_state==self::POWERED_ON;  | 
                                                        
| 55 | 55 | }  | 
                                                        
| 56 | -    public function isPoweredOff(){ | 
                                                        |
| 56 | +    public function isPoweredOff() { | 
                                                        |
| 57 | 57 | return $this->properties->power_state==self::POWERED_OFF;  | 
                                                        
| 58 | 58 | }  | 
                                                        
| 59 | -    public function isSuspended(){ | 
                                                        |
| 59 | +    public function isSuspended() { | 
                                                        |
| 60 | 60 | return $this->properties->power_state==self::SUSPENDED;  | 
                                                        
| 61 | 61 | }  | 
                                                        
| 62 | 62 | }  | 
                                                        
| 63 | 63 | \ No newline at end of file  | 
                                                        
@@ -11,7 +11,7 @@  | 
                                                    ||
| 11 | 11 | class Hardware extends InitClass  | 
                                                        
| 12 | 12 |  { | 
                                                        
| 13 | 13 | use MOID;  | 
                                                        
| 14 | -    public function getHardware($moid=null){ | 
                                                        |
| 14 | +    public function getHardware($moid=null) { | 
                                                        |
| 15 | 15 |          return ApiResponse::BodyResponse($this->HttpClient->get("vm/{$this->getMoid($moid)}/hardware")); | 
                                                        
| 16 | 16 | }  | 
                                                        
| 17 | 17 | |
@@ -37,7 +37,7 @@  | 
                                                    ||
| 37 | 37 |      public function upgradeTools($body, $moid=null){ | 
                                                        
| 38 | 38 |          return !ApiResponse::BodyResponse($this->HttpClient->post("vm/{$this->getMoid($moid)}/tools",[ | 
                                                        
| 39 | 39 | "query"=>[  | 
                                                        
| 40 | - "action"=>"upgrade"  | 
                                                        |
| 40 | + "action"=>"upgrade"  | 
                                                        |
| 41 | 41 | ],  | 
                                                        
| 42 | 42 | RequestOptions::JSON=>$body  | 
                                                        
| 43 | 43 | ]));  | 
                                                        
@@ -18,15 +18,15 @@ discard block  | 
                                                    ||
| 18 | 18 | /**  | 
                                                        
| 19 | 19 | * Get the properties of VMware Tools.  | 
                                                        
| 20 | 20 | */  | 
                                                        
| 21 | -    public function tools($moid=null){ | 
                                                        |
| 21 | +    public function tools($moid=null) { | 
                                                        |
| 22 | 22 |          return ApiResponse::BodyResponse($this->HttpClient->get("vm/{$this->getMoid($moid)}/tools")); | 
                                                        
| 23 | 23 | }  | 
                                                        
| 24 | 24 | |
| 25 | 25 | /**  | 
                                                        
| 26 | 26 | * Update the properties of VMware Tools.  | 
                                                        
| 27 | 27 | */  | 
                                                        
| 28 | -    public function updateTools(array $body,$moid=null){ | 
                                                        |
| 29 | -        return !ApiResponse::HasError($this->HttpClient->patch("vm/{$this->getMoid($moid)}/tools",[ | 
                                                        |
| 28 | +    public function updateTools(array $body, $moid=null) { | 
                                                        |
| 29 | +        return !ApiResponse::HasError($this->HttpClient->patch("vm/{$this->getMoid($moid)}/tools", [ | 
                                                        |
| 30 | 30 | RequestOptions::JSON=>$body  | 
                                                        
| 31 | 31 | ]));  | 
                                                        
| 32 | 32 | }  | 
                                                        
@@ -34,8 +34,8 @@ discard block  | 
                                                    ||
| 34 | 34 | /**  | 
                                                        
| 35 | 35 | * Begins the Tools upgrade process. To monitor the status of the Tools upgrade, clients should check the Tools status by calling Tools.get and examining Tools.Info.version-status and Tools.Info.run-state.  | 
                                                        
| 36 | 36 | */  | 
                                                        
| 37 | -    public function upgradeTools($body, $moid=null){ | 
                                                        |
| 38 | -        return !ApiResponse::BodyResponse($this->HttpClient->post("vm/{$this->getMoid($moid)}/tools",[ | 
                                                        |
| 37 | +    public function upgradeTools($body, $moid=null) { | 
                                                        |
| 38 | +        return !ApiResponse::BodyResponse($this->HttpClient->post("vm/{$this->getMoid($moid)}/tools", [ | 
                                                        |
| 39 | 39 | "query"=>[  | 
                                                        
| 40 | 40 | "action"=>"upgrade"  | 
                                                        
| 41 | 41 | ],  | 
                                                        
@@ -5,22 +5,22 @@  | 
                                                    ||
| 5 | 5 | use FNDEV\vShpare\Api\VM\Traits\IterableObject;  | 
                                                        
| 6 | 6 | use GuzzleHttp\Psr7\Response;  | 
                                                        
| 7 | 7 | |
| 8 | -    class ManageVms implements \Iterator,\Countable { | 
                                                        |
| 9 | - use IterableObject,CountAbleObject;  | 
                                                        |
| 8 | +    class ManageVms implements \Iterator, \Countable { | 
                                                        |
| 9 | + use IterableObject, CountAbleObject;  | 
                                                        |
| 10 | 10 | |
| 11 | - private array $items = [];  | 
                                                        |
| 12 | - private int $position = 0;  | 
                                                        |
| 13 | - public function __construct($vms,$HttpClient)  | 
                                                        |
| 11 | + private array $items=[];  | 
                                                        |
| 12 | + private int $position=0;  | 
                                                        |
| 13 | + public function __construct($vms, $HttpClient)  | 
                                                        |
| 14 | 14 |          { | 
                                                        
| 15 | - $this->parseObjects($vms,$HttpClient);  | 
                                                        |
| 15 | + $this->parseObjects($vms, $HttpClient);  | 
                                                        |
| 16 | 16 | }  | 
                                                        
| 17 | -        public function parseObjects($vms,$HttpClient){ | 
                                                        |
| 18 | -            foreach ($vms->value as $VmProperties){ | 
                                                        |
| 19 | - array_push($this->items,new VmSource($HttpClient,$VmProperties,$VmProperties->vm));  | 
                                                        |
| 17 | +        public function parseObjects($vms, $HttpClient) { | 
                                                        |
| 18 | +            foreach ($vms->value as $VmProperties) { | 
                                                        |
| 19 | + array_push($this->items, new VmSource($HttpClient, $VmProperties, $VmProperties->vm));  | 
                                                        |
| 20 | 20 | }  | 
                                                        
| 21 | 21 | }  | 
                                                        
| 22 | -        public function first(){ | 
                                                        |
| 23 | - return (count($this->items) >= 1) ? $this->items[0] : null ;  | 
                                                        |
| 22 | +        public function first() { | 
                                                        |
| 23 | + return (count($this->items)>=1) ? $this->items[0] : null;  | 
                                                        |
| 24 | 24 | }  | 
                                                        
| 25 | 25 | |
| 26 | 26 | |
@@ -20,11 +20,11 @@  | 
                                                    ||
| 20 | 20 | }  | 
                                                        
| 21 | 21 | public function valid()  | 
                                                        
| 22 | 22 |      { | 
                                                        
| 23 | - return array_key_exists($this->position,$this->items);  | 
                                                        |
| 23 | + return array_key_exists($this->position, $this->items);  | 
                                                        |
| 24 | 24 | }  | 
                                                        
| 25 | 25 | public function rewind()  | 
                                                        
| 26 | 26 |      { | 
                                                        
| 27 | - $this->position = 0;  | 
                                                        |
| 27 | + $this->position=0;  | 
                                                        |
| 28 | 28 | }  | 
                                                        
| 29 | 29 | |
| 30 | 30 | }  | 
                                                        
| 31 | 31 | \ No newline at end of file  |