Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix bug where the php client throws exceptions when there is no input… #26

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion src/Jaspersoft/Client/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class Client
protected $username;
protected $password;
protected $orgId;
protected $authToken;
protected $repositoryService;
protected $userService;
protected $organizationService;
Expand All @@ -36,12 +37,13 @@ class Client
protected $logCollectorService;
protected $serverService;

public function __construct($serverUrl, $username, $password, $orgId = null)
public function __construct($serverUrl, $username, $password, $orgId = null, $authToken = null)
{
$this->serverUrl = $serverUrl;
$this->username = $username;
$this->password = $password;
$this->orgId = $orgId;
$this->authToken = $authToken;

$this->restReq = new RESTRequest();
if (!empty($this->orgId)) {
Expand All @@ -51,6 +53,10 @@ public function __construct($serverUrl, $username, $password, $orgId = null)
}
$this->restReq->setPassword($this->password);
$this->restUrl2 = $this->serverUrl . BASE_REST2_URL;
if($authToken !== null)
{
$this->restReq->setAuthToken($authToken);
}
}

public function repositoryService()
Expand Down Expand Up @@ -173,6 +179,11 @@ public function serverService()
return $this->serverService;
}

public function setAuthToken($token)
{
$this->authToken = $token;
$this->restReq->setAuthToken($token);
}

/**
* Set the amount of time cURL is permitted to wait for a response to a request before timing out.
Expand Down
14 changes: 8 additions & 6 deletions src/Jaspersoft/Dto/Report/InputControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,16 @@ public static function createFromJSON($json)
{
$data_array = json_decode($json, true);
$result = array();
foreach($data_array['inputControlState'] as $k) {
$temp = @new self($k['uri'], $k['id'], $k['value'], $k['error']);
if (!empty($k['options'])) {
foreach ($k['options'] as $o) {
@$temp->addOption($o['label'], $o['value'], $o['selected']);
if(isset($data_array['inputControlState'])) {
foreach ($data_array['inputControlState'] as $k) {
$temp = @new self($k['uri'], $k['id'], $k['value'], $k['error']);
if (!empty($k['options'])) {
foreach ($k['options'] as $o) {
@$temp->addOption($o['label'], $o['value'], $o['selected']);
}
}
$result[] = $temp;
}
$result[] = $temp;
}
return $result;
}
Expand Down
10 changes: 9 additions & 1 deletion src/Jaspersoft/Tool/RESTRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public function __construct ($url = null, $verb = 'GET', $request_body = null)
$this->curl_timeout = 30;
$this->curl_handle = curl_init();
$this->curl_cookiejar = null;
$this->auth_token = null;

if ($this->request_body !== null)
{
Expand Down Expand Up @@ -284,6 +285,8 @@ protected function setCurlOpts (&$curlHandle)
$this->headers[] = "Content-Type: " . $this->content_type;
if (!empty($this->accept_type))
$this->headers[] = "Accept: " . $this->accept_type;
if ($this->auth_token !== null)
$this->headers[] = "pp: " . $this->auth_token;
if (!empty($this->headers))
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, $this->headers);
}
Expand All @@ -292,7 +295,8 @@ protected function setAuth (&$curlHandle)
{
if ($this->username !== null && $this->password !== null)
{
if (empty($this->curl_cookiejar)) {
curl_setopt($curlHandle, CURLOPT_HTTPHEADER, array('Authorization'));
if (empty($this->curl_cookiejar)) {
$this->curl_cookiejar = tempnam(sys_get_temp_dir(), "jrscookies_");
}
curl_setopt($curlHandle, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
Expand Down Expand Up @@ -376,6 +380,10 @@ public function setVerb ($verb)
{
$this->verb = $verb;
}
public function setAuthToken ($auth_token)
{
$this->auth_token = $auth_token;
}

public function closeCurlHandle($close_cookies = false) {
if (is_resource($this->curl_handle)) {
Expand Down