Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/pmill/Plesk/CreateSession.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
namespace pmill\Plesk;

class CreateSession extends BaseRequest
{
/**
* @var string
*/
public $xml_packet = <<<EOT
<?xml version="1.0"?>
<packet>
<server>
<create_session>
<login>{USERNAME}</login>
<data>
<user_ip>{USER_IP}</user_ip>
<source_server>{SOURCE_SERVER}</source_server>
</data>
</create_session>
</server>
</packet>
EOT;

/**
* @var array
*/
protected $default_params = [
'username' => null,
'user_ip' => null,
'source_server' => null,
];

/**
* @var string
*/
public $id;

/**
* @param array $config
* @param array $params
*/
public function __construct(array $config, array $params = [])
{
$params['nodes'] = $this->generateNodeList($params);
parent::__construct($config, $params);
}

/**
* @param $xml
* @return bool
* @throws ApiRequestException
*/
protected function processResponse($xml)
{
$result = $xml->server->create_session->result;

if ($result->status == 'error') {
throw new ApiRequestException($result);
}

$this->id = (string)$xml->{'server'}->create_session->result->id;
return true;
}
}