repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/JobService.php
|
JobService.createOrUpdateCalendar
|
public function createOrUpdateCalendar(BaseCalendar $calendar, $calendarName, $replace = false, $updateTriggers = false)
{
$url = $this->service_url . '/jobs/calendars/' . rawurlencode($calendarName) . '?' .
Util::query_suffix(array("replace" => $replace, "updateTriggers" => $updateTriggers));
$body = $calendar->toJSON();
$this->service->prepAndSend($url, array(200), 'PUT', $body, false);
}
|
php
|
public function createOrUpdateCalendar(BaseCalendar $calendar, $calendarName, $replace = false, $updateTriggers = false)
{
$url = $this->service_url . '/jobs/calendars/' . rawurlencode($calendarName) . '?' .
Util::query_suffix(array("replace" => $replace, "updateTriggers" => $updateTriggers));
$body = $calendar->toJSON();
$this->service->prepAndSend($url, array(200), 'PUT', $body, false);
}
|
[
"public",
"function",
"createOrUpdateCalendar",
"(",
"BaseCalendar",
"$",
"calendar",
",",
"$",
"calendarName",
",",
"$",
"replace",
"=",
"false",
",",
"$",
"updateTriggers",
"=",
"false",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/jobs/calendars/'",
".",
"rawurlencode",
"(",
"$",
"calendarName",
")",
".",
"'?'",
".",
"Util",
"::",
"query_suffix",
"(",
"array",
"(",
"\"replace\"",
"=>",
"$",
"replace",
",",
"\"updateTriggers\"",
"=>",
"$",
"updateTriggers",
")",
")",
";",
"$",
"body",
"=",
"$",
"calendar",
"->",
"toJSON",
"(",
")",
";",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'PUT'",
",",
"$",
"body",
",",
"false",
")",
";",
"}"
] |
Create or Update a calendar
@param BaseCalendar $calendar A DTO representing the new or altered calendar
@param string $calendarName Name of the calendar to create or update
@param bool $replace Should an existing calendar of the same name be overwritten?
@param bool $updateTriggers Should an existing jobs using this calendar adhere to the changes made?
|
[
"Create",
"or",
"Update",
"a",
"calendar"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/JobService.php#L223-L229
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/JobService.php
|
JobService.deleteCalendar
|
public function deleteCalendar($calendarName) {
$url = $this->service_url . '/jobs/calendars/' . rawurlencode($calendarName);
$this->service->prepAndSend($url, array(204), 'DELETE');
}
|
php
|
public function deleteCalendar($calendarName) {
$url = $this->service_url . '/jobs/calendars/' . rawurlencode($calendarName);
$this->service->prepAndSend($url, array(204), 'DELETE');
}
|
[
"public",
"function",
"deleteCalendar",
"(",
"$",
"calendarName",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/jobs/calendars/'",
".",
"rawurlencode",
"(",
"$",
"calendarName",
")",
";",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"204",
")",
",",
"'DELETE'",
")",
";",
"}"
] |
Delete a calendar by its name
@param string $calendarName
|
[
"Delete",
"a",
"calendar",
"by",
"its",
"name"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/JobService.php#L236-L239
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Dto/Resource/CompositeResource.php
|
CompositeResource.createFromJSON
|
public static function createFromJSON($json_data, $type = null)
{
$className = explode('\\', $type);
$className = lcfirst(end($className));
$allFields = parent::createFromJSON($json_data, $type);
$compositeFields = CompositeDTOMapper::compositeFields(get_class($allFields));
foreach ($compositeFields as $key) {
if (isset($allFields->$key)) {
$allFields->$key = self::synthesizeSubresource($key, $json_data[$key], $className);
}
}
return $allFields;
}
|
php
|
public static function createFromJSON($json_data, $type = null)
{
$className = explode('\\', $type);
$className = lcfirst(end($className));
$allFields = parent::createFromJSON($json_data, $type);
$compositeFields = CompositeDTOMapper::compositeFields(get_class($allFields));
foreach ($compositeFields as $key) {
if (isset($allFields->$key)) {
$allFields->$key = self::synthesizeSubresource($key, $json_data[$key], $className);
}
}
return $allFields;
}
|
[
"public",
"static",
"function",
"createFromJSON",
"(",
"$",
"json_data",
",",
"$",
"type",
"=",
"null",
")",
"{",
"$",
"className",
"=",
"explode",
"(",
"'\\\\'",
",",
"$",
"type",
")",
";",
"$",
"className",
"=",
"lcfirst",
"(",
"end",
"(",
"$",
"className",
")",
")",
";",
"$",
"allFields",
"=",
"parent",
"::",
"createFromJSON",
"(",
"$",
"json_data",
",",
"$",
"type",
")",
";",
"$",
"compositeFields",
"=",
"CompositeDTOMapper",
"::",
"compositeFields",
"(",
"get_class",
"(",
"$",
"allFields",
")",
")",
";",
"foreach",
"(",
"$",
"compositeFields",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"allFields",
"->",
"$",
"key",
")",
")",
"{",
"$",
"allFields",
"->",
"$",
"key",
"=",
"self",
"::",
"synthesizeSubresource",
"(",
"$",
"key",
",",
"$",
"json_data",
"[",
"$",
"key",
"]",
",",
"$",
"className",
")",
";",
"}",
"}",
"return",
"$",
"allFields",
";",
"}"
] |
This function takes an array of elements provided by a decoded response from the server and uses
it to create a DTO representing the resource being deserialized.
@param $json_data array
@param $type string The class type to be created
@return array
|
[
"This",
"function",
"takes",
"an",
"array",
"of",
"elements",
"provided",
"by",
"a",
"decoded",
"response",
"from",
"the",
"server",
"and",
"uses",
"it",
"to",
"create",
"a",
"DTO",
"representing",
"the",
"resource",
"being",
"deserialized",
"."
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Dto/Resource/CompositeResource.php#L154-L168
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/RoleService.php
|
RoleService.searchRoles
|
public function searchRoles($organization = null, $includeSubOrgs = null, $user = null, $hasAllUsers = false, $q = null, $limit = 0, $offset = 0)
{
$result = array();
$url = self::makeUrl($organization, null, compact('includeSubOrgs', 'user', 'hasAllUsers', 'q', 'limit', 'offset'));
$data = $this->service->prepAndSend($url, array(200, 204), 'GET', null, true, 'application/json', 'application/json');
$data = (!empty($data)) ? json_decode($data, true) : null;
if ($data === null)
return $result;
foreach ($data['role'] as $r)
$result[] = @new Role($r['name'], $r['tenantId'], $r['externallyDefined']);
return $result;
}
|
php
|
public function searchRoles($organization = null, $includeSubOrgs = null, $user = null, $hasAllUsers = false, $q = null, $limit = 0, $offset = 0)
{
$result = array();
$url = self::makeUrl($organization, null, compact('includeSubOrgs', 'user', 'hasAllUsers', 'q', 'limit', 'offset'));
$data = $this->service->prepAndSend($url, array(200, 204), 'GET', null, true, 'application/json', 'application/json');
$data = (!empty($data)) ? json_decode($data, true) : null;
if ($data === null)
return $result;
foreach ($data['role'] as $r)
$result[] = @new Role($r['name'], $r['tenantId'], $r['externallyDefined']);
return $result;
}
|
[
"public",
"function",
"searchRoles",
"(",
"$",
"organization",
"=",
"null",
",",
"$",
"includeSubOrgs",
"=",
"null",
",",
"$",
"user",
"=",
"null",
",",
"$",
"hasAllUsers",
"=",
"false",
",",
"$",
"q",
"=",
"null",
",",
"$",
"limit",
"=",
"0",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"$",
"organization",
",",
"null",
",",
"compact",
"(",
"'includeSubOrgs'",
",",
"'user'",
",",
"'hasAllUsers'",
",",
"'q'",
",",
"'limit'",
",",
"'offset'",
")",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
",",
"204",
")",
",",
"'GET'",
",",
"null",
",",
"true",
",",
"'application/json'",
",",
"'application/json'",
")",
";",
"$",
"data",
"=",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"?",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
":",
"null",
";",
"if",
"(",
"$",
"data",
"===",
"null",
")",
"return",
"$",
"result",
";",
"foreach",
"(",
"$",
"data",
"[",
"'role'",
"]",
"as",
"$",
"r",
")",
"$",
"result",
"[",
"]",
"=",
"@",
"new",
"Role",
"(",
"$",
"r",
"[",
"'name'",
"]",
",",
"$",
"r",
"[",
"'tenantId'",
"]",
",",
"$",
"r",
"[",
"'externallyDefined'",
"]",
")",
";",
"return",
"$",
"result",
";",
"}"
] |
Search for many or all roles on the server.
You can search by organization as well.
@param string $organization
@param boolean $includeSubOrgs Return roles from suborganizations?
@param array $user retrieves the roles of specific user(s) in the array, users must be defined as username|organization if multitenancy is enabled (pro)
@param boolean $hasAllUsers Return the intersection of roles defined on all users in $user?
@param string $q A query string
@param int $limit Limit number of results for pagination
@param int $offset Begin search results from this point
@return array
@throws \Jaspersoft\Exception\RESTRequestException
|
[
"Search",
"for",
"many",
"or",
"all",
"roles",
"on",
"the",
"server",
".",
"You",
"can",
"search",
"by",
"organization",
"as",
"well",
"."
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/RoleService.php#L43-L54
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/RoleService.php
|
RoleService.getRole
|
public function getRole($roleName, $organization = null)
{
$url = self::makeUrl($organization, $roleName);
$resp = $this->service->prepAndSend($url, array(200), 'GET', null, true, 'application/json', 'application/json');
$data = json_decode($resp);
return @new Role($data->name, $data->tenantId, $data->externallyDefined);
}
|
php
|
public function getRole($roleName, $organization = null)
{
$url = self::makeUrl($organization, $roleName);
$resp = $this->service->prepAndSend($url, array(200), 'GET', null, true, 'application/json', 'application/json');
$data = json_decode($resp);
return @new Role($data->name, $data->tenantId, $data->externallyDefined);
}
|
[
"public",
"function",
"getRole",
"(",
"$",
"roleName",
",",
"$",
"organization",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"$",
"organization",
",",
"$",
"roleName",
")",
";",
"$",
"resp",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'GET'",
",",
"null",
",",
"true",
",",
"'application/json'",
",",
"'application/json'",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"resp",
")",
";",
"return",
"@",
"new",
"Role",
"(",
"$",
"data",
"->",
"name",
",",
"$",
"data",
"->",
"tenantId",
",",
"$",
"data",
"->",
"externallyDefined",
")",
";",
"}"
] |
Get a Role by its name
@param string $roleName
@param string $organization
@return \Jaspersoft\Dto\Role\Role
@throws \Jaspersoft\Exception\RESTRequestException
|
[
"Get",
"a",
"Role",
"by",
"its",
"name"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/RoleService.php#L64-L70
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/RoleService.php
|
RoleService.deleteRole
|
public function deleteRole(Role $role)
{
$url = self::makeUrl($role->tenantId, $role->name);
$this->service->prepAndSend($url, array(204), 'DELETE', null, false);
}
|
php
|
public function deleteRole(Role $role)
{
$url = self::makeUrl($role->tenantId, $role->name);
$this->service->prepAndSend($url, array(204), 'DELETE', null, false);
}
|
[
"public",
"function",
"deleteRole",
"(",
"Role",
"$",
"role",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"$",
"role",
"->",
"tenantId",
",",
"$",
"role",
"->",
"name",
")",
";",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"204",
")",
",",
"'DELETE'",
",",
"null",
",",
"false",
")",
";",
"}"
] |
Remove a role currently in existence.
Provide the Role object of the role you wish to remove. Use getRole() to retrieve Roles.
@param \Jaspersoft\Dto\Role\Role $role
@throws \Jaspersoft\Exception\RESTRequestException
|
[
"Remove",
"a",
"role",
"currently",
"in",
"existence",
"."
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/RoleService.php#L94-L98
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/RoleService.php
|
RoleService.updateRole
|
public function updateRole(Role $role, $oldName = null)
{
$url = self::makeUrl($role->tenantId, $oldName);
$this->service->prepAndSend($url, array(200, 201), 'PUT', json_encode($role), false, 'application/json', 'application/json');
}
|
php
|
public function updateRole(Role $role, $oldName = null)
{
$url = self::makeUrl($role->tenantId, $oldName);
$this->service->prepAndSend($url, array(200, 201), 'PUT', json_encode($role), false, 'application/json', 'application/json');
}
|
[
"public",
"function",
"updateRole",
"(",
"Role",
"$",
"role",
",",
"$",
"oldName",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"$",
"role",
"->",
"tenantId",
",",
"$",
"oldName",
")",
";",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
",",
"201",
")",
",",
"'PUT'",
",",
"json_encode",
"(",
"$",
"role",
")",
",",
"false",
",",
"'application/json'",
",",
"'application/json'",
")",
";",
"}"
] |
Update a role currently in existence.
Provide the Role object of the role you wish to change, then a string of the new name
you wish to give the role. You can optionally provide a new tenantId if you wish to change
that as well.
@param \Jaspersoft\Dto\Role\Role $role
@param string $oldName Previous name of role
@throws \Jaspersoft\Exception\RESTRequestException
|
[
"Update",
"a",
"role",
"currently",
"in",
"existence",
"."
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/RoleService.php#L111-L115
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/UserService.php
|
UserService.searchUsers
|
public function searchUsers($searchTerm = null, $organization = null,
$requiredRoles = null, $hasAllRequiredRoles = null, $includeSubOrgs = true, $limit = 0, $offset = 0)
{
$result = array();
$url = self::makeUserUrl($organization, null,
array('q' => $searchTerm,
'requiredRole' => $requiredRoles,
'hasAllRequiredRoles' => $hasAllRequiredRoles,
'includeSubOrgs' => $includeSubOrgs,
'limit' => $limit,
'offset' => $offset));
$data = $this->service->prepAndSend($url, array(200, 204), 'GET', null, true, 'application/json', 'application/json');
if (!empty($data)) {
$users = json_decode($data);
foreach ($users->user as $user) {
$result[] = @new UserLookup(
$user->username,
$user->fullName,
$user->externallyDefined,
$user->tenantId
);
}
}
return $result;
}
|
php
|
public function searchUsers($searchTerm = null, $organization = null,
$requiredRoles = null, $hasAllRequiredRoles = null, $includeSubOrgs = true, $limit = 0, $offset = 0)
{
$result = array();
$url = self::makeUserUrl($organization, null,
array('q' => $searchTerm,
'requiredRole' => $requiredRoles,
'hasAllRequiredRoles' => $hasAllRequiredRoles,
'includeSubOrgs' => $includeSubOrgs,
'limit' => $limit,
'offset' => $offset));
$data = $this->service->prepAndSend($url, array(200, 204), 'GET', null, true, 'application/json', 'application/json');
if (!empty($data)) {
$users = json_decode($data);
foreach ($users->user as $user) {
$result[] = @new UserLookup(
$user->username,
$user->fullName,
$user->externallyDefined,
$user->tenantId
);
}
}
return $result;
}
|
[
"public",
"function",
"searchUsers",
"(",
"$",
"searchTerm",
"=",
"null",
",",
"$",
"organization",
"=",
"null",
",",
"$",
"requiredRoles",
"=",
"null",
",",
"$",
"hasAllRequiredRoles",
"=",
"null",
",",
"$",
"includeSubOrgs",
"=",
"true",
",",
"$",
"limit",
"=",
"0",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"url",
"=",
"self",
"::",
"makeUserUrl",
"(",
"$",
"organization",
",",
"null",
",",
"array",
"(",
"'q'",
"=>",
"$",
"searchTerm",
",",
"'requiredRole'",
"=>",
"$",
"requiredRoles",
",",
"'hasAllRequiredRoles'",
"=>",
"$",
"hasAllRequiredRoles",
",",
"'includeSubOrgs'",
"=>",
"$",
"includeSubOrgs",
",",
"'limit'",
"=>",
"$",
"limit",
",",
"'offset'",
"=>",
"$",
"offset",
")",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
",",
"204",
")",
",",
"'GET'",
",",
"null",
",",
"true",
",",
"'application/json'",
",",
"'application/json'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"users",
"=",
"json_decode",
"(",
"$",
"data",
")",
";",
"foreach",
"(",
"$",
"users",
"->",
"user",
"as",
"$",
"user",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"@",
"new",
"UserLookup",
"(",
"$",
"user",
"->",
"username",
",",
"$",
"user",
"->",
"fullName",
",",
"$",
"user",
"->",
"externallyDefined",
",",
"$",
"user",
"->",
"tenantId",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Search for users based on the searchTerm provided.
An array of zero or more UserLookup objects will be returned. These can then be passed one by one to
the getUserByLookup function to return the User Object of the user.
If defining requiredRoles that exist in multiple organizations, you must suffix the ROLE name with
|organization_id (i.e: ROLE_USER|organization_1)
@param string $searchTerm A query to filter results by
@param string $organization
@param array $requiredRoles
@param boolean $hasAllRequiredRoles
@param boolean $includeSubOrgs
@param int $limit A number to limit results by (pagination controls)
@param int $offset A number to offset the results by (pagination controls)
@return array
|
[
"Search",
"for",
"users",
"based",
"on",
"the",
"searchTerm",
"provided",
"."
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/UserService.php#L70-L94
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/UserService.php
|
UserService.addOrUpdateUser
|
public function addOrUpdateUser($user)
{
$url = self::makeUserUrl($user->tenantId, $user->username);
$this->service->prepAndSend($url, array(200, 201), 'PUT', json_encode($user), true, 'application/json', 'application/json');
}
|
php
|
public function addOrUpdateUser($user)
{
$url = self::makeUserUrl($user->tenantId, $user->username);
$this->service->prepAndSend($url, array(200, 201), 'PUT', json_encode($user), true, 'application/json', 'application/json');
}
|
[
"public",
"function",
"addOrUpdateUser",
"(",
"$",
"user",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeUserUrl",
"(",
"$",
"user",
"->",
"tenantId",
",",
"$",
"user",
"->",
"username",
")",
";",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
",",
"201",
")",
",",
"'PUT'",
",",
"json_encode",
"(",
"$",
"user",
")",
",",
"true",
",",
"'application/json'",
",",
"'application/json'",
")",
";",
"}"
] |
Add or Update a user
@param \Jaspersoft\Dto\User\User
@throws \Jaspersoft\Exception\RESTRequestException
|
[
"Add",
"or",
"Update",
"a",
"user"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/UserService.php#L143-L147
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/UserService.php
|
UserService.deleteUser
|
public function deleteUser(User $user)
{
$url = self::makeUserUrl($user->tenantId, $user->username);
$this->service->prepAndSend($url, array(204), 'DELETE', null, false, 'application/json', 'application/json');
}
|
php
|
public function deleteUser(User $user)
{
$url = self::makeUserUrl($user->tenantId, $user->username);
$this->service->prepAndSend($url, array(204), 'DELETE', null, false, 'application/json', 'application/json');
}
|
[
"public",
"function",
"deleteUser",
"(",
"User",
"$",
"user",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeUserUrl",
"(",
"$",
"user",
"->",
"tenantId",
",",
"$",
"user",
"->",
"username",
")",
";",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"204",
")",
",",
"'DELETE'",
",",
"null",
",",
"false",
",",
"'application/json'",
",",
"'application/json'",
")",
";",
"}"
] |
This function will delete a user
First get the user using getUsers(), then provide the user you wish to delete
as the parameter for this function.
@param \Jaspersoft\Dto\User\User $user
|
[
"This",
"function",
"will",
"delete",
"a",
"user"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/UserService.php#L157-L161
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/UserService.php
|
UserService.addOrUpdateAttribute
|
public function addOrUpdateAttribute(User $user, $attribute)
{
$url = self::makeAttributeUrl($user->username, $user->tenantId, null, $attribute->name);
$data = json_encode($attribute);
$response = $this->service->prepAndSend($url, array(201, 200), 'PUT', $data, true);
return Attribute::createFromJSON(json_decode($response));
}
|
php
|
public function addOrUpdateAttribute(User $user, $attribute)
{
$url = self::makeAttributeUrl($user->username, $user->tenantId, null, $attribute->name);
$data = json_encode($attribute);
$response = $this->service->prepAndSend($url, array(201, 200), 'PUT', $data, true);
return Attribute::createFromJSON(json_decode($response));
}
|
[
"public",
"function",
"addOrUpdateAttribute",
"(",
"User",
"$",
"user",
",",
"$",
"attribute",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeAttributeUrl",
"(",
"$",
"user",
"->",
"username",
",",
"$",
"user",
"->",
"tenantId",
",",
"null",
",",
"$",
"attribute",
"->",
"name",
")",
";",
"$",
"data",
"=",
"json_encode",
"(",
"$",
"attribute",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"201",
",",
"200",
")",
",",
"'PUT'",
",",
"$",
"data",
",",
"true",
")",
";",
"return",
"Attribute",
"::",
"createFromJSON",
"(",
"json_decode",
"(",
"$",
"response",
")",
")",
";",
"}"
] |
Create a new attributes, or update an existing one.
If a new attribute is created, a truthy value will be returned, if the attribute is updated,
an Attribute object representing the updated attribute will be returned.
@param \Jaspersoft\Dto\User\User $user
@param \Jaspersoft\Dto\Attribute\Attribute $attribute
@return bool|\Jaspersoft\Dto\Attribute\Attribute
|
[
"Create",
"a",
"new",
"attributes",
"or",
"update",
"an",
"existing",
"one",
"."
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/UserService.php#L198-L205
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/UserService.php
|
UserService.deleteAttributes
|
public function deleteAttributes(User $user, $attributes = null)
{
$url = self::makeAttributeUrl($user->username, $user->tenantId);
if (!empty($attributes)) {
$url .= '?' . Util::query_suffix(array('name' => $attributes));
}
return $this->service->prepAndSend($url, array(204), 'DELETE', null, false);
}
|
php
|
public function deleteAttributes(User $user, $attributes = null)
{
$url = self::makeAttributeUrl($user->username, $user->tenantId);
if (!empty($attributes)) {
$url .= '?' . Util::query_suffix(array('name' => $attributes));
}
return $this->service->prepAndSend($url, array(204), 'DELETE', null, false);
}
|
[
"public",
"function",
"deleteAttributes",
"(",
"User",
"$",
"user",
",",
"$",
"attributes",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeAttributeUrl",
"(",
"$",
"user",
"->",
"username",
",",
"$",
"user",
"->",
"tenantId",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"$",
"url",
".=",
"'?'",
".",
"Util",
"::",
"query_suffix",
"(",
"array",
"(",
"'name'",
"=>",
"$",
"attributes",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"204",
")",
",",
"'DELETE'",
",",
"null",
",",
"false",
")",
";",
"}"
] |
Remove all attributes, or specific attributes from a user.
@param \Jaspersoft\Dto\User\User $user
@param array $attributes
@return bool
|
[
"Remove",
"all",
"attributes",
"or",
"specific",
"attributes",
"from",
"a",
"user",
"."
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/UserService.php#L235-L242
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/PermissionService.php
|
PermissionService.searchRepositoryPermissions
|
public function searchRepositoryPermissions($uri, $effectivePermissions = null, $recipientType = null, $recipientId = null, $resolveAll = null)
{
$url = $this->service_url . '/permissions' . $uri;
$url .= '?' . Util::query_suffix(array(
"effectivePermissions" => $effectivePermissions,
"recipientType" => $recipientType,
"recipientId" => $recipientId,
"resolveAll" => $resolveAll));
$data = $this->service->prepAndSend($url, array(200, 204), 'GET', null, true, 'application/json', 'application/json');
if (empty($data)) return array();
return self::batchDataToArray($data);
}
|
php
|
public function searchRepositoryPermissions($uri, $effectivePermissions = null, $recipientType = null, $recipientId = null, $resolveAll = null)
{
$url = $this->service_url . '/permissions' . $uri;
$url .= '?' . Util::query_suffix(array(
"effectivePermissions" => $effectivePermissions,
"recipientType" => $recipientType,
"recipientId" => $recipientId,
"resolveAll" => $resolveAll));
$data = $this->service->prepAndSend($url, array(200, 204), 'GET', null, true, 'application/json', 'application/json');
if (empty($data)) return array();
return self::batchDataToArray($data);
}
|
[
"public",
"function",
"searchRepositoryPermissions",
"(",
"$",
"uri",
",",
"$",
"effectivePermissions",
"=",
"null",
",",
"$",
"recipientType",
"=",
"null",
",",
"$",
"recipientId",
"=",
"null",
",",
"$",
"resolveAll",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/permissions'",
".",
"$",
"uri",
";",
"$",
"url",
".=",
"'?'",
".",
"Util",
"::",
"query_suffix",
"(",
"array",
"(",
"\"effectivePermissions\"",
"=>",
"$",
"effectivePermissions",
",",
"\"recipientType\"",
"=>",
"$",
"recipientType",
",",
"\"recipientId\"",
"=>",
"$",
"recipientId",
",",
"\"resolveAll\"",
"=>",
"$",
"resolveAll",
")",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
",",
"204",
")",
",",
"'GET'",
",",
"null",
",",
"true",
",",
"'application/json'",
",",
"'application/json'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"return",
"array",
"(",
")",
";",
"return",
"self",
"::",
"batchDataToArray",
"(",
"$",
"data",
")",
";",
"}"
] |
Obtain the permissions of a resource on the server
@param string $uri
@param boolean $effectivePermissions Show all permissions affected by URI?
@param string $recipientType Type of permission (e.g: user/role)
@param string $recipientId the id of the recipient (requires recipientType)
@param boolean $resolveAll Resolve for all matched recipients?
@return array A resultant set of RepositoryPermission
|
[
"Obtain",
"the",
"permissions",
"of",
"a",
"resource",
"on",
"the",
"server"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/PermissionService.php#L34-L45
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/PermissionService.php
|
PermissionService.getRepositoryPermission
|
public function getRepositoryPermission($uri, $recipientUri)
{
$url = $this->service_url . '/permissions' . $uri;
$url .= ";recipient=" . str_replace('/', '%2F', $recipientUri);
$data = $this->service->prepAndSend($url, array(200), 'GET', null, true);
return RepositoryPermission::createFromJSON($data);
}
|
php
|
public function getRepositoryPermission($uri, $recipientUri)
{
$url = $this->service_url . '/permissions' . $uri;
$url .= ";recipient=" . str_replace('/', '%2F', $recipientUri);
$data = $this->service->prepAndSend($url, array(200), 'GET', null, true);
return RepositoryPermission::createFromJSON($data);
}
|
[
"public",
"function",
"getRepositoryPermission",
"(",
"$",
"uri",
",",
"$",
"recipientUri",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/permissions'",
".",
"$",
"uri",
";",
"$",
"url",
".=",
"\";recipient=\"",
".",
"str_replace",
"(",
"'/'",
",",
"'%2F'",
",",
"$",
"recipientUri",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'GET'",
",",
"null",
",",
"true",
")",
";",
"return",
"RepositoryPermission",
"::",
"createFromJSON",
"(",
"$",
"data",
")",
";",
"}"
] |
Get a single permission
@param string $uri URI of the resource within the repository
@param string $recipientUri URI of recipient needed
@return \Jaspersoft\Dto\Permission\RepositoryPermission
|
[
"Get",
"a",
"single",
"permission"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/PermissionService.php#L55-L61
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/PermissionService.php
|
PermissionService.updateRepositoryPermission
|
public function updateRepositoryPermission(RepositoryPermission $permission)
{
$url = $this->service_url . '/permissions' . $permission->uri;
$url .= ";recipient=" . str_replace('/', '%2F', $permission->recipient);
$data = $this->service->prepAndSend($url, array(200), 'PUT', json_encode($permission), true);
return RepositoryPermission::createFromJSON($data);
}
|
php
|
public function updateRepositoryPermission(RepositoryPermission $permission)
{
$url = $this->service_url . '/permissions' . $permission->uri;
$url .= ";recipient=" . str_replace('/', '%2F', $permission->recipient);
$data = $this->service->prepAndSend($url, array(200), 'PUT', json_encode($permission), true);
return RepositoryPermission::createFromJSON($data);
}
|
[
"public",
"function",
"updateRepositoryPermission",
"(",
"RepositoryPermission",
"$",
"permission",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/permissions'",
".",
"$",
"permission",
"->",
"uri",
";",
"$",
"url",
".=",
"\";recipient=\"",
".",
"str_replace",
"(",
"'/'",
",",
"'%2F'",
",",
"$",
"permission",
"->",
"recipient",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'PUT'",
",",
"json_encode",
"(",
"$",
"permission",
")",
",",
"true",
")",
";",
"return",
"RepositoryPermission",
"::",
"createFromJSON",
"(",
"$",
"data",
")",
";",
"}"
] |
Update a single RepositoryPermission
Note: only the mask of a RepositoryPermission can be updated
@param \Jaspersoft\Dto\Permission\RepositoryPermission $permission updated RepositoryPermission object
@return RepositoryPermission
|
[
"Update",
"a",
"single",
"RepositoryPermission"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/PermissionService.php#L71-L77
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/PermissionService.php
|
PermissionService.updateRepositoryPermissions
|
public function updateRepositoryPermissions($uri, $permissions)
{
$url = $this->service_url . '/permissions' . $uri;
$body = json_encode(array('permission' => $permissions));
$permissions = $this->service->prepAndSend($url, array(200), 'PUT', $body, true, 'application/collection+json', 'application/json');
return self::batchDataToArray($permissions);
}
|
php
|
public function updateRepositoryPermissions($uri, $permissions)
{
$url = $this->service_url . '/permissions' . $uri;
$body = json_encode(array('permission' => $permissions));
$permissions = $this->service->prepAndSend($url, array(200), 'PUT', $body, true, 'application/collection+json', 'application/json');
return self::batchDataToArray($permissions);
}
|
[
"public",
"function",
"updateRepositoryPermissions",
"(",
"$",
"uri",
",",
"$",
"permissions",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/permissions'",
".",
"$",
"uri",
";",
"$",
"body",
"=",
"json_encode",
"(",
"array",
"(",
"'permission'",
"=>",
"$",
"permissions",
")",
")",
";",
"$",
"permissions",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'PUT'",
",",
"$",
"body",
",",
"true",
",",
"'application/collection+json'",
",",
"'application/json'",
")",
";",
"return",
"self",
"::",
"batchDataToArray",
"(",
"$",
"permissions",
")",
";",
"}"
] |
Update a set of RepositoryPermission
@param string $uri
@param array $permissions Set of updated RepositoryPermission objects
@return array Set of RepositoryPermissions that were updated
|
[
"Update",
"a",
"set",
"of",
"RepositoryPermission"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/PermissionService.php#L86-L92
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/PermissionService.php
|
PermissionService.createRepositoryPermissions
|
public function createRepositoryPermissions($permissions)
{
$url = $this->service_url . '/permissions';
$body = json_encode(array('permission' => $permissions));
$permissions = $this->service->prepAndSend($url, array(201), 'POST', $body, true, 'application/collection+json', 'application/json');
return self::batchDataToArray($permissions);
}
|
php
|
public function createRepositoryPermissions($permissions)
{
$url = $this->service_url . '/permissions';
$body = json_encode(array('permission' => $permissions));
$permissions = $this->service->prepAndSend($url, array(201), 'POST', $body, true, 'application/collection+json', 'application/json');
return self::batchDataToArray($permissions);
}
|
[
"public",
"function",
"createRepositoryPermissions",
"(",
"$",
"permissions",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/permissions'",
";",
"$",
"body",
"=",
"json_encode",
"(",
"array",
"(",
"'permission'",
"=>",
"$",
"permissions",
")",
")",
";",
"$",
"permissions",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"201",
")",
",",
"'POST'",
",",
"$",
"body",
",",
"true",
",",
"'application/collection+json'",
",",
"'application/json'",
")",
";",
"return",
"self",
"::",
"batchDataToArray",
"(",
"$",
"permissions",
")",
";",
"}"
] |
Create multiple RepositoryPermission
@param array $permissions A set of \Jaspersoft\Dto\Permission\RepositoryPermission
@return array A set of RepositoryPermission that were created
|
[
"Create",
"multiple",
"RepositoryPermission"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/PermissionService.php#L100-L106
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/PermissionService.php
|
PermissionService.createRepositoryPermission
|
public function createRepositoryPermission(RepositoryPermission $permission)
{
$url = $this->service_url . '/permissions';
$body = json_encode($permission);
$response = $this->service->prepAndSend($url, array(201), 'POST', $body, true);
return RepositoryPermission::createFromJSON($response);
}
|
php
|
public function createRepositoryPermission(RepositoryPermission $permission)
{
$url = $this->service_url . '/permissions';
$body = json_encode($permission);
$response = $this->service->prepAndSend($url, array(201), 'POST', $body, true);
return RepositoryPermission::createFromJSON($response);
}
|
[
"public",
"function",
"createRepositoryPermission",
"(",
"RepositoryPermission",
"$",
"permission",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/permissions'",
";",
"$",
"body",
"=",
"json_encode",
"(",
"$",
"permission",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"201",
")",
",",
"'POST'",
",",
"$",
"body",
",",
"true",
")",
";",
"return",
"RepositoryPermission",
"::",
"createFromJSON",
"(",
"$",
"response",
")",
";",
"}"
] |
Create a single RepositoryPermission
@param \Jaspersoft\Dto\Permission\RepositoryPermission $permission
@return \Jaspersoft\Dto\Permission\RepositoryPermission
|
[
"Create",
"a",
"single",
"RepositoryPermission"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/PermissionService.php#L114-L120
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/PermissionService.php
|
PermissionService.deleteRepositoryPermission
|
public function deleteRepositoryPermission(RepositoryPermission $permission)
{
$url = $this->service_url . '/permissions' . $permission->uri . ';recipient=' . str_replace('/', '%2F', $permission->recipient);
$this->service->prepAndSend($url, array(204), 'DELETE', null, false);
}
|
php
|
public function deleteRepositoryPermission(RepositoryPermission $permission)
{
$url = $this->service_url . '/permissions' . $permission->uri . ';recipient=' . str_replace('/', '%2F', $permission->recipient);
$this->service->prepAndSend($url, array(204), 'DELETE', null, false);
}
|
[
"public",
"function",
"deleteRepositoryPermission",
"(",
"RepositoryPermission",
"$",
"permission",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/permissions'",
".",
"$",
"permission",
"->",
"uri",
".",
"';recipient='",
".",
"str_replace",
"(",
"'/'",
",",
"'%2F'",
",",
"$",
"permission",
"->",
"recipient",
")",
";",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"204",
")",
",",
"'DELETE'",
",",
"null",
",",
"false",
")",
";",
"}"
] |
Delete a RepositoryPermission
@param \Jaspersoft\Dto\Permission\RepositoryPermission $permission
@throws \Jaspersoft\Exception\RESTRequestException
|
[
"Delete",
"a",
"RepositoryPermission"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/PermissionService.php#L128-L132
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Tool/Util.php
|
Util.query_suffix
|
public static function query_suffix($params)
{
foreach ($params as $k => $v) {
if (is_bool($v)) {
$params[$k] = ($v) ? 'true' : 'false';
}
}
$url = http_build_query($params, null, '&');
return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $url);
}
|
php
|
public static function query_suffix($params)
{
foreach ($params as $k => $v) {
if (is_bool($v)) {
$params[$k] = ($v) ? 'true' : 'false';
}
}
$url = http_build_query($params, null, '&');
return preg_replace('/%5B(?:[0-9]|[1-9][0-9]+)%5D=/', '=', $url);
}
|
[
"public",
"static",
"function",
"query_suffix",
"(",
"$",
"params",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"v",
")",
")",
"{",
"$",
"params",
"[",
"$",
"k",
"]",
"=",
"(",
"$",
"v",
")",
"?",
"'true'",
":",
"'false'",
";",
"}",
"}",
"$",
"url",
"=",
"http_build_query",
"(",
"$",
"params",
",",
"null",
",",
"'&'",
")",
";",
"return",
"preg_replace",
"(",
"'/%5B(?:[0-9]|[1-9][0-9]+)%5D=/'",
",",
"'='",
",",
"$",
"url",
")",
";",
"}"
] |
This function will create an HTTP query string that may include repeated values
@param $params
@return string
|
[
"This",
"function",
"will",
"create",
"an",
"HTTP",
"query",
"string",
"that",
"may",
"include",
"repeated",
"values"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Tool/Util.php#L11-L20
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/QueryService.php
|
QueryService.executeQuery
|
public function executeQuery($sourceUri, $query)
{
$url = $this->service_url . '/queryExecutor' . $sourceUri;
$data = $this->service->prepAndSend($url, array(200), 'POST', $query, true, 'text/plain', 'application/json');
return json_decode($data, true);
}
|
php
|
public function executeQuery($sourceUri, $query)
{
$url = $this->service_url . '/queryExecutor' . $sourceUri;
$data = $this->service->prepAndSend($url, array(200), 'POST', $query, true, 'text/plain', 'application/json');
return json_decode($data, true);
}
|
[
"public",
"function",
"executeQuery",
"(",
"$",
"sourceUri",
",",
"$",
"query",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/queryExecutor'",
".",
"$",
"sourceUri",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'POST'",
",",
"$",
"query",
",",
"true",
",",
"'text/plain'",
",",
"'application/json'",
")",
";",
"return",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"}"
] |
This function will execute a query on a data source or domain, and return the results of such query
@param string $sourceUri
@param string $query
@return array
|
[
"This",
"function",
"will",
"execute",
"a",
"query",
"on",
"a",
"data",
"source",
"or",
"domain",
"and",
"return",
"the",
"results",
"of",
"such",
"query"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/QueryService.php#L19-L24
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Client/Client.php
|
Client.logoutSession
|
public function logoutSession()
{
$url = $this->serverUrl . "/logout.html";
$this->restReq->prepAndSend($url, array(302), 'GET'); // Kill server session
$this->restReq->closeCurlHandle(true); // cleanup client resources
}
|
php
|
public function logoutSession()
{
$url = $this->serverUrl . "/logout.html";
$this->restReq->prepAndSend($url, array(302), 'GET'); // Kill server session
$this->restReq->closeCurlHandle(true); // cleanup client resources
}
|
[
"public",
"function",
"logoutSession",
"(",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"serverUrl",
".",
"\"/logout.html\"",
";",
"$",
"this",
"->",
"restReq",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"302",
")",
",",
"'GET'",
")",
";",
"// Kill server session",
"$",
"this",
"->",
"restReq",
"->",
"closeCurlHandle",
"(",
"true",
")",
";",
"// cleanup client resources",
"}"
] |
Destroy your session on the server and locally forget related cookies
|
[
"Destroy",
"your",
"session",
"on",
"the",
"server",
"and",
"locally",
"forget",
"related",
"cookies"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Client/Client.php#L223-L228
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/OrganizationService.php
|
OrganizationService.searchOrganizations
|
public function searchOrganizations($query = null, $rootTenantId = null, $maxDepth = null, $includeParents = null,
$limit = null, $offset = null)
{
$result = array();
$url = self::makeUrl(null, array(
'q' => $query,
'rootTenantId' => $rootTenantId,
'maxDepth' => $maxDepth,
'includeParents' => $includeParents,
'limit' => $limit,
'offset' => $offset));
$resp = $this->service->prepAndSend($url, array(200, 204), 'GET', null, true, 'application/json', 'application/json');
if (empty($resp))
return $result;
$orgs = json_decode($resp);
foreach ($orgs->organization as $org) {
$result[] = @new Organization($org->alias,
$org->id,
$org->parentId,
$org->tenantName,
$org->theme,
$org->tenantDesc,
$org->tenantFolderUri,
$org->tenantNote,
$org->tenantUri);
}
return $result;
}
|
php
|
public function searchOrganizations($query = null, $rootTenantId = null, $maxDepth = null, $includeParents = null,
$limit = null, $offset = null)
{
$result = array();
$url = self::makeUrl(null, array(
'q' => $query,
'rootTenantId' => $rootTenantId,
'maxDepth' => $maxDepth,
'includeParents' => $includeParents,
'limit' => $limit,
'offset' => $offset));
$resp = $this->service->prepAndSend($url, array(200, 204), 'GET', null, true, 'application/json', 'application/json');
if (empty($resp))
return $result;
$orgs = json_decode($resp);
foreach ($orgs->organization as $org) {
$result[] = @new Organization($org->alias,
$org->id,
$org->parentId,
$org->tenantName,
$org->theme,
$org->tenantDesc,
$org->tenantFolderUri,
$org->tenantNote,
$org->tenantUri);
}
return $result;
}
|
[
"public",
"function",
"searchOrganizations",
"(",
"$",
"query",
"=",
"null",
",",
"$",
"rootTenantId",
"=",
"null",
",",
"$",
"maxDepth",
"=",
"null",
",",
"$",
"includeParents",
"=",
"null",
",",
"$",
"limit",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"null",
",",
"array",
"(",
"'q'",
"=>",
"$",
"query",
",",
"'rootTenantId'",
"=>",
"$",
"rootTenantId",
",",
"'maxDepth'",
"=>",
"$",
"maxDepth",
",",
"'includeParents'",
"=>",
"$",
"includeParents",
",",
"'limit'",
"=>",
"$",
"limit",
",",
"'offset'",
"=>",
"$",
"offset",
")",
")",
";",
"$",
"resp",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
",",
"204",
")",
",",
"'GET'",
",",
"null",
",",
"true",
",",
"'application/json'",
",",
"'application/json'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"resp",
")",
")",
"return",
"$",
"result",
";",
"$",
"orgs",
"=",
"json_decode",
"(",
"$",
"resp",
")",
";",
"foreach",
"(",
"$",
"orgs",
"->",
"organization",
"as",
"$",
"org",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"@",
"new",
"Organization",
"(",
"$",
"org",
"->",
"alias",
",",
"$",
"org",
"->",
"id",
",",
"$",
"org",
"->",
"parentId",
",",
"$",
"org",
"->",
"tenantName",
",",
"$",
"org",
"->",
"theme",
",",
"$",
"org",
"->",
"tenantDesc",
",",
"$",
"org",
"->",
"tenantFolderUri",
",",
"$",
"org",
"->",
"tenantNote",
",",
"$",
"org",
"->",
"tenantUri",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Search for organizations
Unlike the searchUsers function, full Organization objects are returned with this function.
You will receive an array with zero or more elements which are Organization objects that can be manipulated
or used with other functions requiring Organization objects.
@param string $query
@param string $rootTenantId
@param int $maxDepth
@param boolean $includeParents
@param int $limit
@param int $offset
@return array
|
[
"Search",
"for",
"organizations"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/OrganizationService.php#L54-L81
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/OrganizationService.php
|
OrganizationService.deleteOrganization
|
public function deleteOrganization(Organization $org)
{
$url = self::makeUrl($org->id);
$this->service->prepAndSend($url, array(204), 'DELETE', null, false);
}
|
php
|
public function deleteOrganization(Organization $org)
{
$url = self::makeUrl($org->id);
$this->service->prepAndSend($url, array(204), 'DELETE', null, false);
}
|
[
"public",
"function",
"deleteOrganization",
"(",
"Organization",
"$",
"org",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"$",
"org",
"->",
"id",
")",
";",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"204",
")",
",",
"'DELETE'",
",",
"null",
",",
"false",
")",
";",
"}"
] |
Delete an organization
@param \Jaspersoft\Dto\Organization\Organization $org
@throws \Jaspersoft\Exception\RESTRequestException
|
[
"Delete",
"an",
"organization"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/OrganizationService.php#L103-L107
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/OrganizationService.php
|
OrganizationService.updateOrganization
|
public function updateOrganization(Organization $org)
{
$url = self::makeUrl($org->id);
$data = json_encode($org);
$this->service->prepAndSend($url, array(201, 200), 'PUT', $data, false, 'application/json', 'application/json');
}
|
php
|
public function updateOrganization(Organization $org)
{
$url = self::makeUrl($org->id);
$data = json_encode($org);
$this->service->prepAndSend($url, array(201, 200), 'PUT', $data, false, 'application/json', 'application/json');
}
|
[
"public",
"function",
"updateOrganization",
"(",
"Organization",
"$",
"org",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"$",
"org",
"->",
"id",
")",
";",
"$",
"data",
"=",
"json_encode",
"(",
"$",
"org",
")",
";",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"201",
",",
"200",
")",
",",
"'PUT'",
",",
"$",
"data",
",",
"false",
",",
"'application/json'",
",",
"'application/json'",
")",
";",
"}"
] |
Update an organization
@param \Jaspersoft\Dto\Organization\Organization $org
|
[
"Update",
"an",
"organization"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/OrganizationService.php#L114-L119
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/OrganizationService.php
|
OrganizationService.getOrganization
|
public function getOrganization($id)
{
$url = self::makeUrl($id);
$data = $this->service->prepAndSend($url, array(200, 204), 'GET', null, true, 'application/json', 'application/json');
$org = json_decode($data);
return @new Organization(
$org->alias,
$org->id,
$org->parentId,
$org->tenantName,
$org->theme,
$org->tenantDesc,
$org->tenantFolderUri,
$org->tenantNote,
$org->tenantUri
);
}
|
php
|
public function getOrganization($id)
{
$url = self::makeUrl($id);
$data = $this->service->prepAndSend($url, array(200, 204), 'GET', null, true, 'application/json', 'application/json');
$org = json_decode($data);
return @new Organization(
$org->alias,
$org->id,
$org->parentId,
$org->tenantName,
$org->theme,
$org->tenantDesc,
$org->tenantFolderUri,
$org->tenantNote,
$org->tenantUri
);
}
|
[
"public",
"function",
"getOrganization",
"(",
"$",
"id",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"$",
"id",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
",",
"204",
")",
",",
"'GET'",
",",
"null",
",",
"true",
",",
"'application/json'",
",",
"'application/json'",
")",
";",
"$",
"org",
"=",
"json_decode",
"(",
"$",
"data",
")",
";",
"return",
"@",
"new",
"Organization",
"(",
"$",
"org",
"->",
"alias",
",",
"$",
"org",
"->",
"id",
",",
"$",
"org",
"->",
"parentId",
",",
"$",
"org",
"->",
"tenantName",
",",
"$",
"org",
"->",
"theme",
",",
"$",
"org",
"->",
"tenantDesc",
",",
"$",
"org",
"->",
"tenantFolderUri",
",",
"$",
"org",
"->",
"tenantNote",
",",
"$",
"org",
"->",
"tenantUri",
")",
";",
"}"
] |
Get an organization by ID
@param int|string id The ID of the organization
@return \Jaspersoft\Dto\Organization\Organization
|
[
"Get",
"an",
"organization",
"by",
"ID"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/OrganizationService.php#L127-L143
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/OrganizationService.php
|
OrganizationService.getAttributes
|
public function getAttributes(Organization $organization, $attributeNames = null)
{
$result = array();
$url = self::makeAttributeUrl($organization->id, $attributeNames);
$data = $this->service->prepAndSend($url, array(200, 204), 'GET', null, true);
$jsonObj = json_decode($data);
if (!empty($jsonObj)) {
$result = array();
foreach ($jsonObj->attribute as $attr) {
$result[] = Attribute::createFromJSON($attr);
}
return $result;
} else {
return array();
}
}
|
php
|
public function getAttributes(Organization $organization, $attributeNames = null)
{
$result = array();
$url = self::makeAttributeUrl($organization->id, $attributeNames);
$data = $this->service->prepAndSend($url, array(200, 204), 'GET', null, true);
$jsonObj = json_decode($data);
if (!empty($jsonObj)) {
$result = array();
foreach ($jsonObj->attribute as $attr) {
$result[] = Attribute::createFromJSON($attr);
}
return $result;
} else {
return array();
}
}
|
[
"public",
"function",
"getAttributes",
"(",
"Organization",
"$",
"organization",
",",
"$",
"attributeNames",
"=",
"null",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"url",
"=",
"self",
"::",
"makeAttributeUrl",
"(",
"$",
"organization",
"->",
"id",
",",
"$",
"attributeNames",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
",",
"204",
")",
",",
"'GET'",
",",
"null",
",",
"true",
")",
";",
"$",
"jsonObj",
"=",
"json_decode",
"(",
"$",
"data",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"jsonObj",
")",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"jsonObj",
"->",
"attribute",
"as",
"$",
"attr",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"Attribute",
"::",
"createFromJSON",
"(",
"$",
"attr",
")",
";",
"}",
"return",
"$",
"result",
";",
"}",
"else",
"{",
"return",
"array",
"(",
")",
";",
"}",
"}"
] |
Retrieve attributes of an organization.
@param Organization $organization
@param array $attributeNames
@return null|array
@throws \Exception
|
[
"Retrieve",
"attributes",
"of",
"an",
"organization",
"."
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/OrganizationService.php#L153-L168
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/OrganizationService.php
|
OrganizationService.addOrUpdateAttribute
|
public function addOrUpdateAttribute(Organization $organization, $attribute)
{
$url = self::makeAttributeUrl($organization->id, null, $attribute->name);
$data = json_encode($attribute);
$response = $this->service->prepAndSend($url, array(201, 200), 'PUT', $data, true);
return Attribute::createFromJSON(json_decode($response));
}
|
php
|
public function addOrUpdateAttribute(Organization $organization, $attribute)
{
$url = self::makeAttributeUrl($organization->id, null, $attribute->name);
$data = json_encode($attribute);
$response = $this->service->prepAndSend($url, array(201, 200), 'PUT', $data, true);
return Attribute::createFromJSON(json_decode($response));
}
|
[
"public",
"function",
"addOrUpdateAttribute",
"(",
"Organization",
"$",
"organization",
",",
"$",
"attribute",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeAttributeUrl",
"(",
"$",
"organization",
"->",
"id",
",",
"null",
",",
"$",
"attribute",
"->",
"name",
")",
";",
"$",
"data",
"=",
"json_encode",
"(",
"$",
"attribute",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"201",
",",
"200",
")",
",",
"'PUT'",
",",
"$",
"data",
",",
"true",
")",
";",
"return",
"Attribute",
"::",
"createFromJSON",
"(",
"json_decode",
"(",
"$",
"response",
")",
")",
";",
"}"
] |
Create a non-existent attribute, or update an existing attribute
@param Organization $organization
@param Attribute $attribute
@return bool|null
|
[
"Create",
"a",
"non",
"-",
"existent",
"attribute",
"or",
"update",
"an",
"existing",
"attribute"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/OrganizationService.php#L177-L184
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Dto/Job/CalendarTrigger.php
|
CalendarTrigger.jsonSerialize
|
public function jsonSerialize()
{
$result = array();
foreach (get_object_vars($this) as $k => $v) {
// $v is not checked for null like other jsonSerialize functions, all values should be defined here
// Two special cases occur because they require sublevels in their JSON
// encoding to be considered valid.
if ($k == "months") {
$result[$k] = array("month" => $this->months);
}
else if ($k == "weekDays") {
$result[$k] = array("day" => $this->weekDays);
}
else {
$result[$k] = $v;
}
}
return array($this->name() => $result);
}
|
php
|
public function jsonSerialize()
{
$result = array();
foreach (get_object_vars($this) as $k => $v) {
// $v is not checked for null like other jsonSerialize functions, all values should be defined here
// Two special cases occur because they require sublevels in their JSON
// encoding to be considered valid.
if ($k == "months") {
$result[$k] = array("month" => $this->months);
}
else if ($k == "weekDays") {
$result[$k] = array("day" => $this->weekDays);
}
else {
$result[$k] = $v;
}
}
return array($this->name() => $result);
}
|
[
"public",
"function",
"jsonSerialize",
"(",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"get_object_vars",
"(",
"$",
"this",
")",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"// $v is not checked for null like other jsonSerialize functions, all values should be defined here",
"// Two special cases occur because they require sublevels in their JSON",
"// encoding to be considered valid.",
"if",
"(",
"$",
"k",
"==",
"\"months\"",
")",
"{",
"$",
"result",
"[",
"$",
"k",
"]",
"=",
"array",
"(",
"\"month\"",
"=>",
"$",
"this",
"->",
"months",
")",
";",
"}",
"else",
"if",
"(",
"$",
"k",
"==",
"\"weekDays\"",
")",
"{",
"$",
"result",
"[",
"$",
"k",
"]",
"=",
"array",
"(",
"\"day\"",
"=>",
"$",
"this",
"->",
"weekDays",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"}",
"}",
"return",
"array",
"(",
"$",
"this",
"->",
"name",
"(",
")",
"=>",
"$",
"result",
")",
";",
"}"
] |
Overrides Trigger to provide proper JSON hierarchy as described by JRS
@return array
|
[
"Overrides",
"Trigger",
"to",
"provide",
"proper",
"JSON",
"hierarchy",
"as",
"described",
"by",
"JRS"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Dto/Job/CalendarTrigger.php#L97-L116
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Dto/Job/CalendarTrigger.php
|
CalendarTrigger.createFromJSON
|
public static function createFromJSON($json_obj)
{
$result = new self();
foreach ($json_obj as $k => $v) {
if ($k == "months") {
$result->$k = $v->month;
}
else if ($k == "weekDays") {
$result->$k = $v->day;
}
else {
$result->$k = $v;
}
}
return $result;
}
|
php
|
public static function createFromJSON($json_obj)
{
$result = new self();
foreach ($json_obj as $k => $v) {
if ($k == "months") {
$result->$k = $v->month;
}
else if ($k == "weekDays") {
$result->$k = $v->day;
}
else {
$result->$k = $v;
}
}
return $result;
}
|
[
"public",
"static",
"function",
"createFromJSON",
"(",
"$",
"json_obj",
")",
"{",
"$",
"result",
"=",
"new",
"self",
"(",
")",
";",
"foreach",
"(",
"$",
"json_obj",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"k",
"==",
"\"months\"",
")",
"{",
"$",
"result",
"->",
"$",
"k",
"=",
"$",
"v",
"->",
"month",
";",
"}",
"else",
"if",
"(",
"$",
"k",
"==",
"\"weekDays\"",
")",
"{",
"$",
"result",
"->",
"$",
"k",
"=",
"$",
"v",
"->",
"day",
";",
"}",
"else",
"{",
"$",
"result",
"->",
"$",
"k",
"=",
"$",
"v",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
This function takes a \stdClass decoded by json_decode representing a scheduled job
and casts it as a CalendarTrigger Object
@param \stdClass $json_obj
@return CalendarTrigger
|
[
"This",
"function",
"takes",
"a",
"\\",
"stdClass",
"decoded",
"by",
"json_decode",
"representing",
"a",
"scheduled",
"job",
"and",
"casts",
"it",
"as",
"a",
"CalendarTrigger",
"Object"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Dto/Job/CalendarTrigger.php#L125-L140
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/ImportExportService.php
|
ImportExportService.startExportTask
|
public function startExportTask(ExportTask $et)
{
$url = $this->service_url . '/export';
$json_data = $et->toJSON();
$data = $this->service->prepAndSend($url, array(200), 'POST', $json_data, true, 'application/json', 'application/json');
return TaskState::createFromJSON(json_decode($data));
}
|
php
|
public function startExportTask(ExportTask $et)
{
$url = $this->service_url . '/export';
$json_data = $et->toJSON();
$data = $this->service->prepAndSend($url, array(200), 'POST', $json_data, true, 'application/json', 'application/json');
return TaskState::createFromJSON(json_decode($data));
}
|
[
"public",
"function",
"startExportTask",
"(",
"ExportTask",
"$",
"et",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/export'",
";",
"$",
"json_data",
"=",
"$",
"et",
"->",
"toJSON",
"(",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'POST'",
",",
"$",
"json_data",
",",
"true",
",",
"'application/json'",
",",
"'application/json'",
")",
";",
"return",
"TaskState",
"::",
"createFromJSON",
"(",
"json_decode",
"(",
"$",
"data",
")",
")",
";",
"}"
] |
Begin an export task
@param \Jaspersoft\Dto\ImportExport\ExportTask $et
@return \Jaspersoft\Dto\ImportExport\TaskState
|
[
"Begin",
"an",
"export",
"task"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/ImportExportService.php#L22-L28
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/ImportExportService.php
|
ImportExportService.fetchExport
|
public function fetchExport($id, $filename = 'export.zip')
{
$url = $this->service_url . '/export' . '/' . $id . '/' . $filename;
$data = $this->service->prepAndSend($url, array(200), 'GET', null, true, 'application/json', 'application/zip');
return $data;
}
|
php
|
public function fetchExport($id, $filename = 'export.zip')
{
$url = $this->service_url . '/export' . '/' . $id . '/' . $filename;
$data = $this->service->prepAndSend($url, array(200), 'GET', null, true, 'application/json', 'application/zip');
return $data;
}
|
[
"public",
"function",
"fetchExport",
"(",
"$",
"id",
",",
"$",
"filename",
"=",
"'export.zip'",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/export'",
".",
"'/'",
".",
"$",
"id",
".",
"'/'",
".",
"$",
"filename",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'GET'",
",",
"null",
",",
"true",
",",
"'application/json'",
",",
"'application/zip'",
")",
";",
"return",
"$",
"data",
";",
"}"
] |
Fetch the binary data of the report. This can only be called once before the server recycles the export request
The filename parameter determines the headers sent by the server describing the file.
@param int|string $id
@param string $filename
@return string Raw binary data
|
[
"Fetch",
"the",
"binary",
"data",
"of",
"the",
"report",
".",
"This",
"can",
"only",
"be",
"called",
"once",
"before",
"the",
"server",
"recycles",
"the",
"export",
"request"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/ImportExportService.php#L52-L57
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/ImportExportService.php
|
ImportExportService.startImportTask
|
public function startImportTask(ImportTask $it, $file_data)
{
$url = $this->service_url . '/import' . '?' . Util::query_suffix($it->queryData());
$data = $this->service->prepAndSend($url, array(200, 201), 'POST', $file_data, true, 'application/zip', 'application/json');
return TaskState::createFromJSON(json_decode($data));
}
|
php
|
public function startImportTask(ImportTask $it, $file_data)
{
$url = $this->service_url . '/import' . '?' . Util::query_suffix($it->queryData());
$data = $this->service->prepAndSend($url, array(200, 201), 'POST', $file_data, true, 'application/zip', 'application/json');
return TaskState::createFromJSON(json_decode($data));
}
|
[
"public",
"function",
"startImportTask",
"(",
"ImportTask",
"$",
"it",
",",
"$",
"file_data",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/import'",
".",
"'?'",
".",
"Util",
"::",
"query_suffix",
"(",
"$",
"it",
"->",
"queryData",
"(",
")",
")",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
",",
"201",
")",
",",
"'POST'",
",",
"$",
"file_data",
",",
"true",
",",
"'application/zip'",
",",
"'application/json'",
")",
";",
"return",
"TaskState",
"::",
"createFromJSON",
"(",
"json_decode",
"(",
"$",
"data",
")",
")",
";",
"}"
] |
Begin an import task
@param \Jaspersoft\Dto\Importexport\ImportTask $it
@param string $file_data Raw binary data of import zip
@return \Jaspersoft\Dto\ImportExport\TaskState
|
[
"Begin",
"an",
"import",
"task"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/ImportExportService.php#L66-L71
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/ImportExportService.php
|
ImportExportService.getImportState
|
public function getImportState($id)
{
$url = $this->service_url . '/import' . '/' . $id . '/state';
$data = $this->service->prepAndSend($url, array(200), 'GET', null, true, 'application/json', 'application/json');
return TaskState::createFromJSON(json_decode($data));
}
|
php
|
public function getImportState($id)
{
$url = $this->service_url . '/import' . '/' . $id . '/state';
$data = $this->service->prepAndSend($url, array(200), 'GET', null, true, 'application/json', 'application/json');
return TaskState::createFromJSON(json_decode($data));
}
|
[
"public",
"function",
"getImportState",
"(",
"$",
"id",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/import'",
".",
"'/'",
".",
"$",
"id",
".",
"'/state'",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'GET'",
",",
"null",
",",
"true",
",",
"'application/json'",
",",
"'application/json'",
")",
";",
"return",
"TaskState",
"::",
"createFromJSON",
"(",
"json_decode",
"(",
"$",
"data",
")",
")",
";",
"}"
] |
Obtain the state of an ongoing import task
@param int|string $id
@return \Jaspersoft\Dto\ImportExport\TaskState
|
[
"Obtain",
"the",
"state",
"of",
"an",
"ongoing",
"import",
"task"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/ImportExportService.php#L79-L84
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/ThumbnailService.php
|
ThumbnailService.getThumbnailAsBase64String
|
public function getThumbnailAsBase64String($uri, $defaultAllowed = false)
{
$url = self::makeUrl($uri, $defaultAllowed);
$response = $this->service->makeRequest($url, array(200, 204), 'GET', null, true, 'application/json', 'text/plain');
return $response['body'];
}
|
php
|
public function getThumbnailAsBase64String($uri, $defaultAllowed = false)
{
$url = self::makeUrl($uri, $defaultAllowed);
$response = $this->service->makeRequest($url, array(200, 204), 'GET', null, true, 'application/json', 'text/plain');
return $response['body'];
}
|
[
"public",
"function",
"getThumbnailAsBase64String",
"(",
"$",
"uri",
",",
"$",
"defaultAllowed",
"=",
"false",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"$",
"uri",
",",
"$",
"defaultAllowed",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"makeRequest",
"(",
"$",
"url",
",",
"array",
"(",
"200",
",",
"204",
")",
",",
"'GET'",
",",
"null",
",",
"true",
",",
"'application/json'",
",",
"'text/plain'",
")",
";",
"return",
"$",
"response",
"[",
"'body'",
"]",
";",
"}"
] |
Obtain a String of a thumbnail encoded in Base64
@param $uri
@param bool $defaultAllowed
@return mixed
|
[
"Obtain",
"a",
"String",
"of",
"a",
"thumbnail",
"encoded",
"in",
"Base64"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/ThumbnailService.php#L40-L46
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/ThumbnailService.php
|
ThumbnailService.getResourceThumbnails
|
public function getResourceThumbnails(array $uris, $defaultAllowed = false)
{
$result = array();
$url = self::makeUrl();
$postString = Util::query_suffix(array("uri" => $uris, "defaultAllowed" => $defaultAllowed));
$response = $this->service->makeRequest($url, array(200), 'POST', $postString, true, 'application/x-www-form-urlencoded');
$data = json_decode($response['body']);
if (isset($data)) {
foreach ($data as $thumbnail) {
$result[] = ResourceThumbnail::createFromJSON($thumbnail);
}
}
return $result;
}
|
php
|
public function getResourceThumbnails(array $uris, $defaultAllowed = false)
{
$result = array();
$url = self::makeUrl();
$postString = Util::query_suffix(array("uri" => $uris, "defaultAllowed" => $defaultAllowed));
$response = $this->service->makeRequest($url, array(200), 'POST', $postString, true, 'application/x-www-form-urlencoded');
$data = json_decode($response['body']);
if (isset($data)) {
foreach ($data as $thumbnail) {
$result[] = ResourceThumbnail::createFromJSON($thumbnail);
}
}
return $result;
}
|
[
"public",
"function",
"getResourceThumbnails",
"(",
"array",
"$",
"uris",
",",
"$",
"defaultAllowed",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
")",
";",
"$",
"postString",
"=",
"Util",
"::",
"query_suffix",
"(",
"array",
"(",
"\"uri\"",
"=>",
"$",
"uris",
",",
"\"defaultAllowed\"",
"=>",
"$",
"defaultAllowed",
")",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"makeRequest",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'POST'",
",",
"$",
"postString",
",",
"true",
",",
"'application/x-www-form-urlencoded'",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"response",
"[",
"'body'",
"]",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"thumbnail",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"ResourceThumbnail",
"::",
"createFromJSON",
"(",
"$",
"thumbnail",
")",
";",
"}",
"}",
"return",
"$",
"result",
";",
"}"
] |
Obtain a set of ResourceThumbnail objects representing the thumbnails for several reports,
these ResourceThumbnail objects will contain the image data as a Base64 String only
@param array $uris
@param bool $defaultAllowed
@return array
|
[
"Obtain",
"a",
"set",
"of",
"ResourceThumbnail",
"objects",
"representing",
"the",
"thumbnails",
"for",
"several",
"reports",
"these",
"ResourceThumbnail",
"objects",
"will",
"contain",
"the",
"image",
"data",
"as",
"a",
"Base64",
"String",
"only"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/ThumbnailService.php#L71-L85
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Tool/CompositeDTOMapper.php
|
CompositeDTOMapper.reverseResolve
|
private static function reverseResolve($field, $map)
{
$backwardMap = array_reverse($map);
if (array_key_exists($field, $backwardMap)) {
return $backwardMap[$field];
} else {
// TODO: Appropriate Exception
return null;
}
}
|
php
|
private static function reverseResolve($field, $map)
{
$backwardMap = array_reverse($map);
if (array_key_exists($field, $backwardMap)) {
return $backwardMap[$field];
} else {
// TODO: Appropriate Exception
return null;
}
}
|
[
"private",
"static",
"function",
"reverseResolve",
"(",
"$",
"field",
",",
"$",
"map",
")",
"{",
"$",
"backwardMap",
"=",
"array_reverse",
"(",
"$",
"map",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"field",
",",
"$",
"backwardMap",
")",
")",
"{",
"return",
"$",
"backwardMap",
"[",
"$",
"field",
"]",
";",
"}",
"else",
"{",
"// TODO: Appropriate Exception",
"return",
"null",
";",
"}",
"}"
] |
Return the key of a map given the value
This method assumes the data map has a one-to-one relationship
@param $field Field to be resolved
@param $map Map to use for resolution
@return string|null
|
[
"Return",
"the",
"key",
"of",
"a",
"map",
"given",
"the",
"value",
"This",
"method",
"assumes",
"the",
"data",
"map",
"has",
"a",
"one",
"-",
"to",
"-",
"one",
"relationship"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Tool/CompositeDTOMapper.php#L106-L115
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/ReportService.php
|
ReportService.runReport
|
public function runReport($uri, $format = 'pdf', $pages = null, $attachmentsPrefix = null, $inputControls = null,
$interactive = true, $onePagePerSheet = false, $freshData = true, $saveDataSnapshot = false, $transformerKey = null)
{
$url = $this->service_url . '/reports' . $uri . '.' . $format;
if (empty($inputControls))
$url .= '?' . Util::query_suffix(compact("pages", "attachmentsPrefix", "interactive", "onePagePerSheet", "freshData", "saveDataSnapshot", "transformerKey"));
else
$url .= '?' . Util::query_suffix(array_merge(compact("pages", "attachmentsPrefix", "interactive", "onePagePerSheet", "freshData", "saveDataSnapshot", "transformerKey"), $inputControls));
$binary = $this->service->prepAndSend($url, array(200), 'GET', null, true);
return $binary;
}
|
php
|
public function runReport($uri, $format = 'pdf', $pages = null, $attachmentsPrefix = null, $inputControls = null,
$interactive = true, $onePagePerSheet = false, $freshData = true, $saveDataSnapshot = false, $transformerKey = null)
{
$url = $this->service_url . '/reports' . $uri . '.' . $format;
if (empty($inputControls))
$url .= '?' . Util::query_suffix(compact("pages", "attachmentsPrefix", "interactive", "onePagePerSheet", "freshData", "saveDataSnapshot", "transformerKey"));
else
$url .= '?' . Util::query_suffix(array_merge(compact("pages", "attachmentsPrefix", "interactive", "onePagePerSheet", "freshData", "saveDataSnapshot", "transformerKey"), $inputControls));
$binary = $this->service->prepAndSend($url, array(200), 'GET', null, true);
return $binary;
}
|
[
"public",
"function",
"runReport",
"(",
"$",
"uri",
",",
"$",
"format",
"=",
"'pdf'",
",",
"$",
"pages",
"=",
"null",
",",
"$",
"attachmentsPrefix",
"=",
"null",
",",
"$",
"inputControls",
"=",
"null",
",",
"$",
"interactive",
"=",
"true",
",",
"$",
"onePagePerSheet",
"=",
"false",
",",
"$",
"freshData",
"=",
"true",
",",
"$",
"saveDataSnapshot",
"=",
"false",
",",
"$",
"transformerKey",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/reports'",
".",
"$",
"uri",
".",
"'.'",
".",
"$",
"format",
";",
"if",
"(",
"empty",
"(",
"$",
"inputControls",
")",
")",
"$",
"url",
".=",
"'?'",
".",
"Util",
"::",
"query_suffix",
"(",
"compact",
"(",
"\"pages\"",
",",
"\"attachmentsPrefix\"",
",",
"\"interactive\"",
",",
"\"onePagePerSheet\"",
",",
"\"freshData\"",
",",
"\"saveDataSnapshot\"",
",",
"\"transformerKey\"",
")",
")",
";",
"else",
"$",
"url",
".=",
"'?'",
".",
"Util",
"::",
"query_suffix",
"(",
"array_merge",
"(",
"compact",
"(",
"\"pages\"",
",",
"\"attachmentsPrefix\"",
",",
"\"interactive\"",
",",
"\"onePagePerSheet\"",
",",
"\"freshData\"",
",",
"\"saveDataSnapshot\"",
",",
"\"transformerKey\"",
")",
",",
"$",
"inputControls",
")",
")",
";",
"$",
"binary",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'GET'",
",",
"null",
",",
"true",
")",
";",
"return",
"$",
"binary",
";",
"}"
] |
This function runs and retrieves the binary data of a report.
@param string $uri URI for the report you wish to run
@param string $format The format you wish to receive the report in (default: pdf)
@param string $pages Request a specific page, or range of pages. Separate multiple pages or ranges by commas.
(e.g: "1,4-22,42,55-100")
@param string $attachmentsPrefix a URI to prefix all image attachment sources with
(must include trailing slash if needed)
@param array $inputControls associative array of key => value for any input controls
@param boolean $interactive Should reports using Highcharts be interactive?
@param boolean $onePagePerSheet Produce paginated XLS or XLSX?
@param boolean $freshData
@param boolean $saveDataSnapshot
@param string $transformerKey For use when running a report as a JasperPrint. Specifies print element transformers
@return string Binary data of report
|
[
"This",
"function",
"runs",
"and",
"retrieves",
"the",
"binary",
"data",
"of",
"a",
"report",
"."
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/ReportService.php#L32-L42
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/ReportService.php
|
ReportService.getInputControlStructure
|
public function getInputControlStructure($uri) {
$url = $this->service_url . '/reports' . $uri . '/inputControls';
$data = $this->service->prepAndSend($url, array(200, 204), 'GET', null, true);
if (empty($data)) {
return array();
}
$json_obj = json_decode($data);
$result = array();
foreach ($json_obj->inputControl as $control) {
$result[] = InputControl::createFromJSON($control);
}
return $result;
}
|
php
|
public function getInputControlStructure($uri) {
$url = $this->service_url . '/reports' . $uri . '/inputControls';
$data = $this->service->prepAndSend($url, array(200, 204), 'GET', null, true);
if (empty($data)) {
return array();
}
$json_obj = json_decode($data);
$result = array();
foreach ($json_obj->inputControl as $control) {
$result[] = InputControl::createFromJSON($control);
}
return $result;
}
|
[
"public",
"function",
"getInputControlStructure",
"(",
"$",
"uri",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/reports'",
".",
"$",
"uri",
".",
"'/inputControls'",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
",",
"204",
")",
",",
"'GET'",
",",
"null",
",",
"true",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"return",
"array",
"(",
")",
";",
"}",
"$",
"json_obj",
"=",
"json_decode",
"(",
"$",
"data",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"json_obj",
"->",
"inputControl",
"as",
"$",
"control",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"InputControl",
"::",
"createFromJSON",
"(",
"$",
"control",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Returns a set of InputControl objects defining input controls for a report
@param string $uri Report to obtain structure from
@return array
|
[
"Returns",
"a",
"set",
"of",
"InputControl",
"objects",
"defining",
"input",
"controls",
"for",
"a",
"report"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/ReportService.php#L101-L116
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/ReportService.php
|
ReportService.updateInputControlOrder
|
public function updateInputControlOrder($uri, array $controls)
{
$url = $this->service_url . '/reports' . $uri . '/inputControls';
$body = array("inputControl" => array());
foreach ($controls as $control) {
if ($control instanceof InputControl) {
$body['inputControl'][] = $control->jsonSerialize();
}
}
$response = $this->service->prepAndSend($url, array(200), 'PUT', json_encode($body), true);
$json_obj = json_decode($response);
$result = array();
foreach ($json_obj->inputControl as $control) {
$result[] = InputControl::createFromJSON($control);
}
return $result;
}
|
php
|
public function updateInputControlOrder($uri, array $controls)
{
$url = $this->service_url . '/reports' . $uri . '/inputControls';
$body = array("inputControl" => array());
foreach ($controls as $control) {
if ($control instanceof InputControl) {
$body['inputControl'][] = $control->jsonSerialize();
}
}
$response = $this->service->prepAndSend($url, array(200), 'PUT', json_encode($body), true);
$json_obj = json_decode($response);
$result = array();
foreach ($json_obj->inputControl as $control) {
$result[] = InputControl::createFromJSON($control);
}
return $result;
}
|
[
"public",
"function",
"updateInputControlOrder",
"(",
"$",
"uri",
",",
"array",
"$",
"controls",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/reports'",
".",
"$",
"uri",
".",
"'/inputControls'",
";",
"$",
"body",
"=",
"array",
"(",
"\"inputControl\"",
"=>",
"array",
"(",
")",
")",
";",
"foreach",
"(",
"$",
"controls",
"as",
"$",
"control",
")",
"{",
"if",
"(",
"$",
"control",
"instanceof",
"InputControl",
")",
"{",
"$",
"body",
"[",
"'inputControl'",
"]",
"[",
"]",
"=",
"$",
"control",
"->",
"jsonSerialize",
"(",
")",
";",
"}",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'PUT'",
",",
"json_encode",
"(",
"$",
"body",
")",
",",
"true",
")",
";",
"$",
"json_obj",
"=",
"json_decode",
"(",
"$",
"response",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"json_obj",
"->",
"inputControl",
"as",
"$",
"control",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"InputControl",
"::",
"createFromJSON",
"(",
"$",
"control",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Update the order of a report's input control structure.
The second argument must only contain elements that have not been changed except for their order since being
retrieved from getReportInputControlStructure.
@param string $uri
@param array $controls A set of InputControl
@return array The new structure
|
[
"Update",
"the",
"order",
"of",
"a",
"report",
"s",
"input",
"control",
"structure",
"."
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/ReportService.php#L128-L145
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/ReportService.php
|
ReportService.updateInputControlValues
|
public function updateInputControlValues($uri, array $parameters)
{
$url = $this->service_url . '/reports' . $uri . '/inputControls/' . join(';', array_keys($parameters)) . '/values';
$response = $this->service->prepAndSend($url, array(200), 'POST', json_encode($parameters), true);
$json_obj = json_decode($response);
$result = array();
foreach ($json_obj->inputControlState as $state) {
$result[] = InputControlState::createFromJSON($state);
}
return $result;
}
|
php
|
public function updateInputControlValues($uri, array $parameters)
{
$url = $this->service_url . '/reports' . $uri . '/inputControls/' . join(';', array_keys($parameters)) . '/values';
$response = $this->service->prepAndSend($url, array(200), 'POST', json_encode($parameters), true);
$json_obj = json_decode($response);
$result = array();
foreach ($json_obj->inputControlState as $state) {
$result[] = InputControlState::createFromJSON($state);
}
return $result;
}
|
[
"public",
"function",
"updateInputControlValues",
"(",
"$",
"uri",
",",
"array",
"$",
"parameters",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/reports'",
".",
"$",
"uri",
".",
"'/inputControls/'",
".",
"join",
"(",
"';'",
",",
"array_keys",
"(",
"$",
"parameters",
")",
")",
".",
"'/values'",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'POST'",
",",
"json_encode",
"(",
"$",
"parameters",
")",
",",
"true",
")",
";",
"$",
"json_obj",
"=",
"json_decode",
"(",
"$",
"response",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"json_obj",
"->",
"inputControlState",
"as",
"$",
"state",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"InputControlState",
"::",
"createFromJSON",
"(",
"$",
"state",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Update the values of a report's input controls, and obtain the updated input control states as a result
@param string $uri
@param array $parameters Set of parameters in format: array("id" => array("value"), "id2" => array("value2"));
@return array
|
[
"Update",
"the",
"values",
"of",
"a",
"report",
"s",
"input",
"controls",
"and",
"obtain",
"the",
"updated",
"input",
"control",
"states",
"as",
"a",
"result"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/ReportService.php#L155-L166
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/ReportService.php
|
ReportService.updateInputControls
|
public function updateInputControls($uri, array $parameters)
{
$url = $this->service_url . '/reports' . $uri . '/inputControls';
$response = $this->service->prepAndSend($url, array(200), 'POST', json_encode($parameters), true);
$json_obj = json_decode($response);
$result = array();
foreach ($json_obj->inputControl as $control) {
$result[] = InputControl::createFromJSON($control);
}
return $result;
}
|
php
|
public function updateInputControls($uri, array $parameters)
{
$url = $this->service_url . '/reports' . $uri . '/inputControls';
$response = $this->service->prepAndSend($url, array(200), 'POST', json_encode($parameters), true);
$json_obj = json_decode($response);
$result = array();
foreach ($json_obj->inputControl as $control) {
$result[] = InputControl::createFromJSON($control);
}
return $result;
}
|
[
"public",
"function",
"updateInputControls",
"(",
"$",
"uri",
",",
"array",
"$",
"parameters",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"service_url",
".",
"'/reports'",
".",
"$",
"uri",
".",
"'/inputControls'",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"prepAndSend",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'POST'",
",",
"json_encode",
"(",
"$",
"parameters",
")",
",",
"true",
")",
";",
"$",
"json_obj",
"=",
"json_decode",
"(",
"$",
"response",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"json_obj",
"->",
"inputControl",
"as",
"$",
"control",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"InputControl",
"::",
"createFromJSON",
"(",
"$",
"control",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
] |
Update the values of a report's input controls, and obtain the new structure as a result
@param string $uri
@param array $parameters Set of parameters in format: array("id" => array("value"), "id2" => array("value2"));
@return array Set of InputControl objects
|
[
"Update",
"the",
"values",
"of",
"a",
"report",
"s",
"input",
"controls",
"and",
"obtain",
"the",
"new",
"structure",
"as",
"a",
"result"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/ReportService.php#L175-L186
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/RepositoryService.php
|
RepositoryService.searchResources
|
public function searchResources(RepositorySearchCriteria $criteria = null)
{
$url = self::makeUrl($criteria);
$response = $this->service->makeRequest($url, array(200, 204), 'GET', null, true, 'application/json', 'application/json');
if ($response['statusCode'] == 204 || $response['body'] == null) {
// A SearchResourceResult with 0 counts, and no items
return new SearchResourcesResult(null, 0, 0, 0);
}
$data = $response['body'];
$headers = RESTRequest::splitHeaderArray($response['headers']);
// If forceTotalCount is not enabled, the server doesn't return totalCount when offset is specified
if(!isset($headers['Total-Count']))
$totalCount = null;
else
$totalCount = (int) $headers['Total-Count'];
return new SearchResourcesResult(json_decode($data), (int) $headers['Result-Count'], (int) $headers['Start-Index'], $totalCount);
}
|
php
|
public function searchResources(RepositorySearchCriteria $criteria = null)
{
$url = self::makeUrl($criteria);
$response = $this->service->makeRequest($url, array(200, 204), 'GET', null, true, 'application/json', 'application/json');
if ($response['statusCode'] == 204 || $response['body'] == null) {
// A SearchResourceResult with 0 counts, and no items
return new SearchResourcesResult(null, 0, 0, 0);
}
$data = $response['body'];
$headers = RESTRequest::splitHeaderArray($response['headers']);
// If forceTotalCount is not enabled, the server doesn't return totalCount when offset is specified
if(!isset($headers['Total-Count']))
$totalCount = null;
else
$totalCount = (int) $headers['Total-Count'];
return new SearchResourcesResult(json_decode($data), (int) $headers['Result-Count'], (int) $headers['Start-Index'], $totalCount);
}
|
[
"public",
"function",
"searchResources",
"(",
"RepositorySearchCriteria",
"$",
"criteria",
"=",
"null",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"$",
"criteria",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"makeRequest",
"(",
"$",
"url",
",",
"array",
"(",
"200",
",",
"204",
")",
",",
"'GET'",
",",
"null",
",",
"true",
",",
"'application/json'",
",",
"'application/json'",
")",
";",
"if",
"(",
"$",
"response",
"[",
"'statusCode'",
"]",
"==",
"204",
"||",
"$",
"response",
"[",
"'body'",
"]",
"==",
"null",
")",
"{",
"// A SearchResourceResult with 0 counts, and no items",
"return",
"new",
"SearchResourcesResult",
"(",
"null",
",",
"0",
",",
"0",
",",
"0",
")",
";",
"}",
"$",
"data",
"=",
"$",
"response",
"[",
"'body'",
"]",
";",
"$",
"headers",
"=",
"RESTRequest",
"::",
"splitHeaderArray",
"(",
"$",
"response",
"[",
"'headers'",
"]",
")",
";",
"// If forceTotalCount is not enabled, the server doesn't return totalCount when offset is specified",
"if",
"(",
"!",
"isset",
"(",
"$",
"headers",
"[",
"'Total-Count'",
"]",
")",
")",
"$",
"totalCount",
"=",
"null",
";",
"else",
"$",
"totalCount",
"=",
"(",
"int",
")",
"$",
"headers",
"[",
"'Total-Count'",
"]",
";",
"return",
"new",
"SearchResourcesResult",
"(",
"json_decode",
"(",
"$",
"data",
")",
",",
"(",
"int",
")",
"$",
"headers",
"[",
"'Result-Count'",
"]",
",",
"(",
"int",
")",
"$",
"headers",
"[",
"'Start-Index'",
"]",
",",
"$",
"totalCount",
")",
";",
"}"
] |
Search repository by criteria
@param \Jaspersoft\Service\Criteria\RepositorySearchCriteria $criteria
@return \Jaspersoft\Service\Result\SearchResourcesResult
|
[
"Search",
"repository",
"by",
"criteria"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/RepositoryService.php#L42-L62
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/RepositoryService.php
|
RepositoryService.getResource
|
public function getResource($uri, $expanded = false)
{
if (!$expanded)
$url = self::makeUrl(null, $uri);
else
$url = self::makeUrl(null, $uri, true);
// If getting the root folder, we must use repository.folder+json
if ($uri == "/")
$type = "application/repository.folder+json";
else
$type = "application/repository.file+json";
$response = $this->service->makeRequest($url, array(200, 204), 'GET', null, true, 'application/json', $type);
$data = $response['body'];
$headers = $response['headers'];
$content_type = array_values(preg_grep("#repository\.(.*)\+#", $headers));
preg_match("#repository\.(.*)\+#", $content_type[0], $resource_type);
$class = RESOURCE_NAMESPACE . '\\' . ucfirst($resource_type[1]);
if (class_exists($class) && is_subclass_of($class, RESOURCE_NAMESPACE . '\\Resource')) {
return $class::createFromJSON(json_decode($data, true), $class);
} else {
return Resource::createFromJSON(json_decode($data, true));
}
}
|
php
|
public function getResource($uri, $expanded = false)
{
if (!$expanded)
$url = self::makeUrl(null, $uri);
else
$url = self::makeUrl(null, $uri, true);
// If getting the root folder, we must use repository.folder+json
if ($uri == "/")
$type = "application/repository.folder+json";
else
$type = "application/repository.file+json";
$response = $this->service->makeRequest($url, array(200, 204), 'GET', null, true, 'application/json', $type);
$data = $response['body'];
$headers = $response['headers'];
$content_type = array_values(preg_grep("#repository\.(.*)\+#", $headers));
preg_match("#repository\.(.*)\+#", $content_type[0], $resource_type);
$class = RESOURCE_NAMESPACE . '\\' . ucfirst($resource_type[1]);
if (class_exists($class) && is_subclass_of($class, RESOURCE_NAMESPACE . '\\Resource')) {
return $class::createFromJSON(json_decode($data, true), $class);
} else {
return Resource::createFromJSON(json_decode($data, true));
}
}
|
[
"public",
"function",
"getResource",
"(",
"$",
"uri",
",",
"$",
"expanded",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"expanded",
")",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"null",
",",
"$",
"uri",
")",
";",
"else",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"null",
",",
"$",
"uri",
",",
"true",
")",
";",
"// If getting the root folder, we must use repository.folder+json",
"if",
"(",
"$",
"uri",
"==",
"\"/\"",
")",
"$",
"type",
"=",
"\"application/repository.folder+json\"",
";",
"else",
"$",
"type",
"=",
"\"application/repository.file+json\"",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"makeRequest",
"(",
"$",
"url",
",",
"array",
"(",
"200",
",",
"204",
")",
",",
"'GET'",
",",
"null",
",",
"true",
",",
"'application/json'",
",",
"$",
"type",
")",
";",
"$",
"data",
"=",
"$",
"response",
"[",
"'body'",
"]",
";",
"$",
"headers",
"=",
"$",
"response",
"[",
"'headers'",
"]",
";",
"$",
"content_type",
"=",
"array_values",
"(",
"preg_grep",
"(",
"\"#repository\\.(.*)\\+#\"",
",",
"$",
"headers",
")",
")",
";",
"preg_match",
"(",
"\"#repository\\.(.*)\\+#\"",
",",
"$",
"content_type",
"[",
"0",
"]",
",",
"$",
"resource_type",
")",
";",
"$",
"class",
"=",
"RESOURCE_NAMESPACE",
".",
"'\\\\'",
".",
"ucfirst",
"(",
"$",
"resource_type",
"[",
"1",
"]",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
"&&",
"is_subclass_of",
"(",
"$",
"class",
",",
"RESOURCE_NAMESPACE",
".",
"'\\\\Resource'",
")",
")",
"{",
"return",
"$",
"class",
"::",
"createFromJSON",
"(",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
",",
"$",
"class",
")",
";",
"}",
"else",
"{",
"return",
"Resource",
"::",
"createFromJSON",
"(",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
")",
";",
"}",
"}"
] |
Get resource by URI
@param string $uri
@param bool $expanded Return subresources as definitions and not references?
@return \Jaspersoft\Dto\Resource\Resource
|
[
"Get",
"resource",
"by",
"URI"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/RepositoryService.php#L71-L97
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/RepositoryService.php
|
RepositoryService.updateFileResource
|
public function updateFileResource(File $resource, $binaryData)
{
$url = self::makeUrl(null, $resource->uri);
$body = $binaryData;
$response = $this->service->sendBinary($url, array(201, 200), $body, MimeMapper::mapType($resource->type), 'attachment; filename=' . $resource->label, $resource->description, 'PUT');
return File::createFromJSON(json_decode($response, true), get_class($resource));
}
|
php
|
public function updateFileResource(File $resource, $binaryData)
{
$url = self::makeUrl(null, $resource->uri);
$body = $binaryData;
$response = $this->service->sendBinary($url, array(201, 200), $body, MimeMapper::mapType($resource->type), 'attachment; filename=' . $resource->label, $resource->description, 'PUT');
return File::createFromJSON(json_decode($response, true), get_class($resource));
}
|
[
"public",
"function",
"updateFileResource",
"(",
"File",
"$",
"resource",
",",
"$",
"binaryData",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"null",
",",
"$",
"resource",
"->",
"uri",
")",
";",
"$",
"body",
"=",
"$",
"binaryData",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"sendBinary",
"(",
"$",
"url",
",",
"array",
"(",
"201",
",",
"200",
")",
",",
"$",
"body",
",",
"MimeMapper",
"::",
"mapType",
"(",
"$",
"resource",
"->",
"type",
")",
",",
"'attachment; filename='",
".",
"$",
"resource",
"->",
"label",
",",
"$",
"resource",
"->",
"description",
",",
"'PUT'",
")",
";",
"return",
"File",
"::",
"createFromJSON",
"(",
"json_decode",
"(",
"$",
"response",
",",
"true",
")",
",",
"get_class",
"(",
"$",
"resource",
")",
")",
";",
"}"
] |
Update a file on the server by supplying binary data
@param \Jaspersoft\Dto\Resource\File $resource A resource descriptor for the File
@param string $binaryData The binary data of the file to update
@return \Jaspersoft\Dto\Resource\Resource
|
[
"Update",
"a",
"file",
"on",
"the",
"server",
"by",
"supplying",
"binary",
"data"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/RepositoryService.php#L173-L181
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/RepositoryService.php
|
RepositoryService.createFileResource
|
public function createFileResource(File $resource, $binaryData, $parentFolder, $createFolders = true)
{
$url = self::makeUrl(null, $parentFolder);
$url .= '?' . Util::query_suffix(array("createFolders" => $createFolders));
$body = $binaryData;
$response = $this->service->sendBinary($url, array(201, 200), $body, MimeMapper::mapType($resource->type), 'attachment; filename=' . $resource->label, $resource->description, 'POST');
return File::createFromJSON(json_decode($response, true), get_class($resource));
}
|
php
|
public function createFileResource(File $resource, $binaryData, $parentFolder, $createFolders = true)
{
$url = self::makeUrl(null, $parentFolder);
$url .= '?' . Util::query_suffix(array("createFolders" => $createFolders));
$body = $binaryData;
$response = $this->service->sendBinary($url, array(201, 200), $body, MimeMapper::mapType($resource->type), 'attachment; filename=' . $resource->label, $resource->description, 'POST');
return File::createFromJSON(json_decode($response, true), get_class($resource));
}
|
[
"public",
"function",
"createFileResource",
"(",
"File",
"$",
"resource",
",",
"$",
"binaryData",
",",
"$",
"parentFolder",
",",
"$",
"createFolders",
"=",
"true",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"null",
",",
"$",
"parentFolder",
")",
";",
"$",
"url",
".=",
"'?'",
".",
"Util",
"::",
"query_suffix",
"(",
"array",
"(",
"\"createFolders\"",
"=>",
"$",
"createFolders",
")",
")",
";",
"$",
"body",
"=",
"$",
"binaryData",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"sendBinary",
"(",
"$",
"url",
",",
"array",
"(",
"201",
",",
"200",
")",
",",
"$",
"body",
",",
"MimeMapper",
"::",
"mapType",
"(",
"$",
"resource",
"->",
"type",
")",
",",
"'attachment; filename='",
".",
"$",
"resource",
"->",
"label",
",",
"$",
"resource",
"->",
"description",
",",
"'POST'",
")",
";",
"return",
"File",
"::",
"createFromJSON",
"(",
"json_decode",
"(",
"$",
"response",
",",
"true",
")",
",",
"get_class",
"(",
"$",
"resource",
")",
")",
";",
"}"
] |
Create a file on the server by supplying binary data
If you are using a custom MIME type, you must add the type => mimeType mapping
to the \Jaspersoft\Tool\MimeMapper mimeMap.
@param \Jaspersoft\Dto\Resource\File $resource
@param string $binaryData
@param string $parentFolder string The folder to place the file in
@param boolean $createFolders
@return \Jaspersoft\Dto\Resource\File
|
[
"Create",
"a",
"file",
"on",
"the",
"server",
"by",
"supplying",
"binary",
"data"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/RepositoryService.php#L195-L203
|
train
|
Jaspersoft/jrs-rest-php-client
|
src/Jaspersoft/Service/RepositoryService.php
|
RepositoryService.copyResource
|
public function copyResource($resourceUri, $destinationFolderUri, $createFolders = true, $overwrite = false)
{
$url = self::makeUrl(null, $destinationFolderUri);
$url .= '?' . Util::query_suffix(array("createFolders" => $createFolders, "overwrite" => $overwrite));
$response = $this->service->makeRequest($url, array(200), 'POST', null, true, 'application/json', 'application/json', array("Content-Location: " . $resourceUri));
$data = $response['body'];
$headers = $response['headers'];
$content_type = array_values(preg_grep("#repository\.(.*)\+#", $headers));
preg_match("#repository\.(.*)\+#", $content_type[0], $resource_type);
$class = RESOURCE_NAMESPACE . '\\' . ucfirst($resource_type[1]);
if (class_exists($class) && is_subclass_of($class, RESOURCE_NAMESPACE . '\\Resource')) {
return $class::createFromJSON(json_decode($data, true), $class);
} else {
return Resource::createFromJSON(json_decode($data, true));
}
}
|
php
|
public function copyResource($resourceUri, $destinationFolderUri, $createFolders = true, $overwrite = false)
{
$url = self::makeUrl(null, $destinationFolderUri);
$url .= '?' . Util::query_suffix(array("createFolders" => $createFolders, "overwrite" => $overwrite));
$response = $this->service->makeRequest($url, array(200), 'POST', null, true, 'application/json', 'application/json', array("Content-Location: " . $resourceUri));
$data = $response['body'];
$headers = $response['headers'];
$content_type = array_values(preg_grep("#repository\.(.*)\+#", $headers));
preg_match("#repository\.(.*)\+#", $content_type[0], $resource_type);
$class = RESOURCE_NAMESPACE . '\\' . ucfirst($resource_type[1]);
if (class_exists($class) && is_subclass_of($class, RESOURCE_NAMESPACE . '\\Resource')) {
return $class::createFromJSON(json_decode($data, true), $class);
} else {
return Resource::createFromJSON(json_decode($data, true));
}
}
|
[
"public",
"function",
"copyResource",
"(",
"$",
"resourceUri",
",",
"$",
"destinationFolderUri",
",",
"$",
"createFolders",
"=",
"true",
",",
"$",
"overwrite",
"=",
"false",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"makeUrl",
"(",
"null",
",",
"$",
"destinationFolderUri",
")",
";",
"$",
"url",
".=",
"'?'",
".",
"Util",
"::",
"query_suffix",
"(",
"array",
"(",
"\"createFolders\"",
"=>",
"$",
"createFolders",
",",
"\"overwrite\"",
"=>",
"$",
"overwrite",
")",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"service",
"->",
"makeRequest",
"(",
"$",
"url",
",",
"array",
"(",
"200",
")",
",",
"'POST'",
",",
"null",
",",
"true",
",",
"'application/json'",
",",
"'application/json'",
",",
"array",
"(",
"\"Content-Location: \"",
".",
"$",
"resourceUri",
")",
")",
";",
"$",
"data",
"=",
"$",
"response",
"[",
"'body'",
"]",
";",
"$",
"headers",
"=",
"$",
"response",
"[",
"'headers'",
"]",
";",
"$",
"content_type",
"=",
"array_values",
"(",
"preg_grep",
"(",
"\"#repository\\.(.*)\\+#\"",
",",
"$",
"headers",
")",
")",
";",
"preg_match",
"(",
"\"#repository\\.(.*)\\+#\"",
",",
"$",
"content_type",
"[",
"0",
"]",
",",
"$",
"resource_type",
")",
";",
"$",
"class",
"=",
"RESOURCE_NAMESPACE",
".",
"'\\\\'",
".",
"ucfirst",
"(",
"$",
"resource_type",
"[",
"1",
"]",
")",
";",
"if",
"(",
"class_exists",
"(",
"$",
"class",
")",
"&&",
"is_subclass_of",
"(",
"$",
"class",
",",
"RESOURCE_NAMESPACE",
".",
"'\\\\Resource'",
")",
")",
"{",
"return",
"$",
"class",
"::",
"createFromJSON",
"(",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
",",
"$",
"class",
")",
";",
"}",
"else",
"{",
"return",
"Resource",
"::",
"createFromJSON",
"(",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
")",
";",
"}",
"}"
] |
Copy a resource from one location to another
@param string $resourceUri URI of resource to be copied
@param string $destinationFolderUri URI of folder the resource is to be copied to
@param boolean $createFolders Should folders be created if they do not already exist?
@param boolean $overwrite Should files be overwritten while performing this operation?
@return \Jaspersoft\Dto\Resource\Resource
|
[
"Copy",
"a",
"resource",
"from",
"one",
"location",
"to",
"another"
] |
32dc45485030c6339e636c309cd5280af6479bf4
|
https://github.com/Jaspersoft/jrs-rest-php-client/blob/32dc45485030c6339e636c309cd5280af6479bf4/src/Jaspersoft/Service/RepositoryService.php#L214-L233
|
train
|
PhpGt/Csrf
|
src/HTMLDocumentProtector.php
|
HTMLDocumentProtector.protectAndInject
|
public function protectAndInject(
string $tokenSharing = self::ONE_TOKEN_PER_PAGE
):void {
$forms = $this->document->forms;
if($forms->length > 0) {
$token = $this->tokenStore->generateNewToken();
$this->tokenStore->saveToken($token);
foreach($forms as $form) {
$formMethod = $form->getAttribute("method");
if(strtolower($formMethod) !== "post") {
continue;
}
$csrfElement = $this->document->createElement(
"input"
);
$csrfElement->setAttribute(
"name",
static::TOKEN_NAME
);
$csrfElement->setAttribute(
"value",
$token
);
$csrfElement->setAttribute(
"type",
"hidden"
);
$form->insertBefore(
$csrfElement,
$form->firstChild
);
if($tokenSharing === self::ONE_TOKEN_PER_FORM) {
$token = $this->tokenStore->generateNewToken();
$this->tokenStore->saveToken($token);
}
}
}
else {
$token = $this->tokenStore->generateNewToken();
$this->tokenStore->saveToken($token);
}
$meta = $this->document->querySelector(
"head meta[name='" . self::TOKEN_NAME . "']"
);
if(is_null($meta)) {
$meta = $this->document->createElement("meta");
$meta->setAttribute(
"name",
self::TOKEN_NAME
);
$head = $this->document->querySelector(
"head"
);
if(is_null($head)) {
$head = $this->document->createElement(
"head"
);
$htmlElement = $this->document->querySelector(
"html"
);
$htmlElement->appendChild($head);
}
$head->appendChild($meta);
}
$meta->setAttribute("content", $token);
}
|
php
|
public function protectAndInject(
string $tokenSharing = self::ONE_TOKEN_PER_PAGE
):void {
$forms = $this->document->forms;
if($forms->length > 0) {
$token = $this->tokenStore->generateNewToken();
$this->tokenStore->saveToken($token);
foreach($forms as $form) {
$formMethod = $form->getAttribute("method");
if(strtolower($formMethod) !== "post") {
continue;
}
$csrfElement = $this->document->createElement(
"input"
);
$csrfElement->setAttribute(
"name",
static::TOKEN_NAME
);
$csrfElement->setAttribute(
"value",
$token
);
$csrfElement->setAttribute(
"type",
"hidden"
);
$form->insertBefore(
$csrfElement,
$form->firstChild
);
if($tokenSharing === self::ONE_TOKEN_PER_FORM) {
$token = $this->tokenStore->generateNewToken();
$this->tokenStore->saveToken($token);
}
}
}
else {
$token = $this->tokenStore->generateNewToken();
$this->tokenStore->saveToken($token);
}
$meta = $this->document->querySelector(
"head meta[name='" . self::TOKEN_NAME . "']"
);
if(is_null($meta)) {
$meta = $this->document->createElement("meta");
$meta->setAttribute(
"name",
self::TOKEN_NAME
);
$head = $this->document->querySelector(
"head"
);
if(is_null($head)) {
$head = $this->document->createElement(
"head"
);
$htmlElement = $this->document->querySelector(
"html"
);
$htmlElement->appendChild($head);
}
$head->appendChild($meta);
}
$meta->setAttribute("content", $token);
}
|
[
"public",
"function",
"protectAndInject",
"(",
"string",
"$",
"tokenSharing",
"=",
"self",
"::",
"ONE_TOKEN_PER_PAGE",
")",
":",
"void",
"{",
"$",
"forms",
"=",
"$",
"this",
"->",
"document",
"->",
"forms",
";",
"if",
"(",
"$",
"forms",
"->",
"length",
">",
"0",
")",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"tokenStore",
"->",
"generateNewToken",
"(",
")",
";",
"$",
"this",
"->",
"tokenStore",
"->",
"saveToken",
"(",
"$",
"token",
")",
";",
"foreach",
"(",
"$",
"forms",
"as",
"$",
"form",
")",
"{",
"$",
"formMethod",
"=",
"$",
"form",
"->",
"getAttribute",
"(",
"\"method\"",
")",
";",
"if",
"(",
"strtolower",
"(",
"$",
"formMethod",
")",
"!==",
"\"post\"",
")",
"{",
"continue",
";",
"}",
"$",
"csrfElement",
"=",
"$",
"this",
"->",
"document",
"->",
"createElement",
"(",
"\"input\"",
")",
";",
"$",
"csrfElement",
"->",
"setAttribute",
"(",
"\"name\"",
",",
"static",
"::",
"TOKEN_NAME",
")",
";",
"$",
"csrfElement",
"->",
"setAttribute",
"(",
"\"value\"",
",",
"$",
"token",
")",
";",
"$",
"csrfElement",
"->",
"setAttribute",
"(",
"\"type\"",
",",
"\"hidden\"",
")",
";",
"$",
"form",
"->",
"insertBefore",
"(",
"$",
"csrfElement",
",",
"$",
"form",
"->",
"firstChild",
")",
";",
"if",
"(",
"$",
"tokenSharing",
"===",
"self",
"::",
"ONE_TOKEN_PER_FORM",
")",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"tokenStore",
"->",
"generateNewToken",
"(",
")",
";",
"$",
"this",
"->",
"tokenStore",
"->",
"saveToken",
"(",
"$",
"token",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"tokenStore",
"->",
"generateNewToken",
"(",
")",
";",
"$",
"this",
"->",
"tokenStore",
"->",
"saveToken",
"(",
"$",
"token",
")",
";",
"}",
"$",
"meta",
"=",
"$",
"this",
"->",
"document",
"->",
"querySelector",
"(",
"\"head meta[name='\"",
".",
"self",
"::",
"TOKEN_NAME",
".",
"\"']\"",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"meta",
")",
")",
"{",
"$",
"meta",
"=",
"$",
"this",
"->",
"document",
"->",
"createElement",
"(",
"\"meta\"",
")",
";",
"$",
"meta",
"->",
"setAttribute",
"(",
"\"name\"",
",",
"self",
"::",
"TOKEN_NAME",
")",
";",
"$",
"head",
"=",
"$",
"this",
"->",
"document",
"->",
"querySelector",
"(",
"\"head\"",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"head",
")",
")",
"{",
"$",
"head",
"=",
"$",
"this",
"->",
"document",
"->",
"createElement",
"(",
"\"head\"",
")",
";",
"$",
"htmlElement",
"=",
"$",
"this",
"->",
"document",
"->",
"querySelector",
"(",
"\"html\"",
")",
";",
"$",
"htmlElement",
"->",
"appendChild",
"(",
"$",
"head",
")",
";",
"}",
"$",
"head",
"->",
"appendChild",
"(",
"$",
"meta",
")",
";",
"}",
"$",
"meta",
"->",
"setAttribute",
"(",
"\"content\"",
",",
"$",
"token",
")",
";",
"}"
] |
Inject a CSRF token into each form in the html page, and add a meta tag to the header
with a "content" attribute containing a token.
The way the tokens are generated can be configured using the $tokenSharing parameter:
Specify self::ONE_TOKEN_PER_FORM if different tokens should be used for each form on the
page (and a different token again in the head meta tag). This is only required if
multiple forms from a single page could be submitted without reloading the page - using
AJAX for example. Note that the submitted token would still be "spent", so the server
response page should be parsed to lift out the new token and inject it into the form
that was just submitted.
Specify self::ONE_TOKEN_PER_PAGE if the same token can be used for all forms across the
page and the head meta tag. This is the default, and is considerably more efficient than
generating unique tokens. In most cases this default is suitable - wherever the normal
model of returning a new page in response to a form submit is used.
|
[
"Inject",
"a",
"CSRF",
"token",
"into",
"each",
"form",
"in",
"the",
"html",
"page",
"and",
"add",
"a",
"meta",
"tag",
"to",
"the",
"header",
"with",
"a",
"content",
"attribute",
"containing",
"a",
"token",
"."
] |
9eae22b0626f287346ff81c37397f8f1910bc845
|
https://github.com/PhpGt/Csrf/blob/9eae22b0626f287346ff81c37397f8f1910bc845/src/HTMLDocumentProtector.php#L48-L124
|
train
|
pattern-lab/patternengine-php-twig
|
src/PatternLab/PatternEngine/Twig/TwigUtil.php
|
TwigUtil.setInstance
|
public static function setInstance($instance = "") {
if (empty($instance) || !method_exists($instance,'addGlobal')) {
Console::writeError("please set the instance");
}
self::$instance = $instance;
}
|
php
|
public static function setInstance($instance = "") {
if (empty($instance) || !method_exists($instance,'addGlobal')) {
Console::writeError("please set the instance");
}
self::$instance = $instance;
}
|
[
"public",
"static",
"function",
"setInstance",
"(",
"$",
"instance",
"=",
"\"\"",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"instance",
")",
"||",
"!",
"method_exists",
"(",
"$",
"instance",
",",
"'addGlobal'",
")",
")",
"{",
"Console",
"::",
"writeError",
"(",
"\"please set the instance\"",
")",
";",
"}",
"self",
"::",
"$",
"instance",
"=",
"$",
"instance",
";",
"}"
] |
Set an instance of the Twig environment
@param {Instance} an instance of the Twig environment
|
[
"Set",
"an",
"instance",
"of",
"the",
"Twig",
"environment"
] |
edeb27a56a7a389e8f369e02ba9c50ee83a84cbb
|
https://github.com/pattern-lab/patternengine-php-twig/blob/edeb27a56a7a389e8f369e02ba9c50ee83a84cbb/src/PatternLab/PatternEngine/Twig/TwigUtil.php#L43-L51
|
train
|
pattern-lab/patternengine-php-twig
|
src/PatternLab/PatternEngine/Twig/TwigUtil.php
|
TwigUtil.loadDateFormats
|
public static function loadDateFormats() {
$dateFormat = Config::getOption("twigDefaultDateFormat");
$intervalFormat = Config::getOption("twigDefaultIntervalFormat");
if ($dateFormat && $intervalFormat && !empty($dateFormat) && !empty($intervalFormat)) {
self::$instance->getExtension("core")->setDateFormat($dateFormat, $intervalFormat);
}
}
|
php
|
public static function loadDateFormats() {
$dateFormat = Config::getOption("twigDefaultDateFormat");
$intervalFormat = Config::getOption("twigDefaultIntervalFormat");
if ($dateFormat && $intervalFormat && !empty($dateFormat) && !empty($intervalFormat)) {
self::$instance->getExtension("core")->setDateFormat($dateFormat, $intervalFormat);
}
}
|
[
"public",
"static",
"function",
"loadDateFormats",
"(",
")",
"{",
"$",
"dateFormat",
"=",
"Config",
"::",
"getOption",
"(",
"\"twigDefaultDateFormat\"",
")",
";",
"$",
"intervalFormat",
"=",
"Config",
"::",
"getOption",
"(",
"\"twigDefaultIntervalFormat\"",
")",
";",
"if",
"(",
"$",
"dateFormat",
"&&",
"$",
"intervalFormat",
"&&",
"!",
"empty",
"(",
"$",
"dateFormat",
")",
"&&",
"!",
"empty",
"(",
"$",
"intervalFormat",
")",
")",
"{",
"self",
"::",
"$",
"instance",
"->",
"getExtension",
"(",
"\"core\"",
")",
"->",
"setDateFormat",
"(",
"$",
"dateFormat",
",",
"$",
"intervalFormat",
")",
";",
"}",
"}"
] |
Load custom date formats for Twig
|
[
"Load",
"custom",
"date",
"formats",
"for",
"Twig"
] |
edeb27a56a7a389e8f369e02ba9c50ee83a84cbb
|
https://github.com/pattern-lab/patternengine-php-twig/blob/edeb27a56a7a389e8f369e02ba9c50ee83a84cbb/src/PatternLab/PatternEngine/Twig/TwigUtil.php#L138-L147
|
train
|
pattern-lab/patternengine-php-twig
|
src/PatternLab/PatternEngine/Twig/TwigUtil.php
|
TwigUtil.loadFilters
|
public static function loadFilters() {
// load defaults
$filterDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/filters";
$filterExt = Config::getOption("twigFilterExt");
$filterExt = $filterExt ? $filterExt : "filter.php";
if (is_dir($filterDir)) {
// loop through the filter dir...
$finder = new Finder();
$finder->files()->name("*\.".$filterExt)->in($filterDir);
$finder->sortByName();
foreach ($finder as $file) {
// see if the file should be ignored or not
$baseName = $file->getBasename();
if ($baseName[0] != "_") {
include($file->getPathname());
// $filter should be defined in the included file
if (isset($filter)) {
self::$instance->addFilter($filter);
unset($filter);
}
}
}
}
}
|
php
|
public static function loadFilters() {
// load defaults
$filterDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/filters";
$filterExt = Config::getOption("twigFilterExt");
$filterExt = $filterExt ? $filterExt : "filter.php";
if (is_dir($filterDir)) {
// loop through the filter dir...
$finder = new Finder();
$finder->files()->name("*\.".$filterExt)->in($filterDir);
$finder->sortByName();
foreach ($finder as $file) {
// see if the file should be ignored or not
$baseName = $file->getBasename();
if ($baseName[0] != "_") {
include($file->getPathname());
// $filter should be defined in the included file
if (isset($filter)) {
self::$instance->addFilter($filter);
unset($filter);
}
}
}
}
}
|
[
"public",
"static",
"function",
"loadFilters",
"(",
")",
"{",
"// load defaults",
"$",
"filterDir",
"=",
"Config",
"::",
"getOption",
"(",
"\"sourceDir\"",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"\"_twig-components/filters\"",
";",
"$",
"filterExt",
"=",
"Config",
"::",
"getOption",
"(",
"\"twigFilterExt\"",
")",
";",
"$",
"filterExt",
"=",
"$",
"filterExt",
"?",
"$",
"filterExt",
":",
"\"filter.php\"",
";",
"if",
"(",
"is_dir",
"(",
"$",
"filterDir",
")",
")",
"{",
"// loop through the filter dir...",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"\"*\\.\"",
".",
"$",
"filterExt",
")",
"->",
"in",
"(",
"$",
"filterDir",
")",
";",
"$",
"finder",
"->",
"sortByName",
"(",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"// see if the file should be ignored or not",
"$",
"baseName",
"=",
"$",
"file",
"->",
"getBasename",
"(",
")",
";",
"if",
"(",
"$",
"baseName",
"[",
"0",
"]",
"!=",
"\"_\"",
")",
"{",
"include",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"// $filter should be defined in the included file",
"if",
"(",
"isset",
"(",
"$",
"filter",
")",
")",
"{",
"self",
"::",
"$",
"instance",
"->",
"addFilter",
"(",
"$",
"filter",
")",
";",
"unset",
"(",
"$",
"filter",
")",
";",
"}",
"}",
"}",
"}",
"}"
] |
Load filters for the Twig PatternEngine
|
[
"Load",
"filters",
"for",
"the",
"Twig",
"PatternEngine"
] |
edeb27a56a7a389e8f369e02ba9c50ee83a84cbb
|
https://github.com/pattern-lab/patternengine-php-twig/blob/edeb27a56a7a389e8f369e02ba9c50ee83a84cbb/src/PatternLab/PatternEngine/Twig/TwigUtil.php#L163-L196
|
train
|
pattern-lab/patternengine-php-twig
|
src/PatternLab/PatternEngine/Twig/TwigUtil.php
|
TwigUtil.loadFunctions
|
public static function loadFunctions() {
// load defaults
$functionDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/functions";
$functionExt = Config::getOption("twigFunctionExt");
$functionExt = $functionExt ? $functionExt : "function.php";
if (is_dir($functionDir)) {
// loop through the function dir...
$finder = new Finder();
$finder->files()->name("*\.".$functionExt)->in($functionDir);
$finder->sortByName();
foreach ($finder as $file) {
// see if the file should be ignored or not
$baseName = $file->getBasename();
if ($baseName[0] != "_") {
include($file->getPathname());
// $function should be defined in the included file
if (isset($function)) {
self::$instance->addFunction($function);
unset($function);
}
}
}
}
}
|
php
|
public static function loadFunctions() {
// load defaults
$functionDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/functions";
$functionExt = Config::getOption("twigFunctionExt");
$functionExt = $functionExt ? $functionExt : "function.php";
if (is_dir($functionDir)) {
// loop through the function dir...
$finder = new Finder();
$finder->files()->name("*\.".$functionExt)->in($functionDir);
$finder->sortByName();
foreach ($finder as $file) {
// see if the file should be ignored or not
$baseName = $file->getBasename();
if ($baseName[0] != "_") {
include($file->getPathname());
// $function should be defined in the included file
if (isset($function)) {
self::$instance->addFunction($function);
unset($function);
}
}
}
}
}
|
[
"public",
"static",
"function",
"loadFunctions",
"(",
")",
"{",
"// load defaults",
"$",
"functionDir",
"=",
"Config",
"::",
"getOption",
"(",
"\"sourceDir\"",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"\"_twig-components/functions\"",
";",
"$",
"functionExt",
"=",
"Config",
"::",
"getOption",
"(",
"\"twigFunctionExt\"",
")",
";",
"$",
"functionExt",
"=",
"$",
"functionExt",
"?",
"$",
"functionExt",
":",
"\"function.php\"",
";",
"if",
"(",
"is_dir",
"(",
"$",
"functionDir",
")",
")",
"{",
"// loop through the function dir...",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"\"*\\.\"",
".",
"$",
"functionExt",
")",
"->",
"in",
"(",
"$",
"functionDir",
")",
";",
"$",
"finder",
"->",
"sortByName",
"(",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"// see if the file should be ignored or not",
"$",
"baseName",
"=",
"$",
"file",
"->",
"getBasename",
"(",
")",
";",
"if",
"(",
"$",
"baseName",
"[",
"0",
"]",
"!=",
"\"_\"",
")",
"{",
"include",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"// $function should be defined in the included file",
"if",
"(",
"isset",
"(",
"$",
"function",
")",
")",
"{",
"self",
"::",
"$",
"instance",
"->",
"addFunction",
"(",
"$",
"function",
")",
";",
"unset",
"(",
"$",
"function",
")",
";",
"}",
"}",
"}",
"}",
"}"
] |
Load functions for the Twig PatternEngine
|
[
"Load",
"functions",
"for",
"the",
"Twig",
"PatternEngine"
] |
edeb27a56a7a389e8f369e02ba9c50ee83a84cbb
|
https://github.com/pattern-lab/patternengine-php-twig/blob/edeb27a56a7a389e8f369e02ba9c50ee83a84cbb/src/PatternLab/PatternEngine/Twig/TwigUtil.php#L201-L234
|
train
|
pattern-lab/patternengine-php-twig
|
src/PatternLab/PatternEngine/Twig/TwigUtil.php
|
TwigUtil.loadMacros
|
public static function loadMacros() {
// load defaults
$macroDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_macros";
$macroExt = Config::getOption("twigMacroExt");
$macroExt = $macroExt ? $macroExt : "macro.twig";
if (is_dir($macroDir)) {
// loop through some macro containing dir and run...
$finder = new Finder();
$finder->files()->name("*.".$macroExt)->in($macroDir);
$finder->sortByName();
foreach ($finder as $file) {
// see if the file should be ignored
$baseName = $file->getBasename();
if ($baseName[0] != "_") {
// add the macro to the global context
self::$instance->addGlobal($file->getBasename(".".$macroExt), self::$instance->loadTemplate($baseName));
}
}
}
}
|
php
|
public static function loadMacros() {
// load defaults
$macroDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_macros";
$macroExt = Config::getOption("twigMacroExt");
$macroExt = $macroExt ? $macroExt : "macro.twig";
if (is_dir($macroDir)) {
// loop through some macro containing dir and run...
$finder = new Finder();
$finder->files()->name("*.".$macroExt)->in($macroDir);
$finder->sortByName();
foreach ($finder as $file) {
// see if the file should be ignored
$baseName = $file->getBasename();
if ($baseName[0] != "_") {
// add the macro to the global context
self::$instance->addGlobal($file->getBasename(".".$macroExt), self::$instance->loadTemplate($baseName));
}
}
}
}
|
[
"public",
"static",
"function",
"loadMacros",
"(",
")",
"{",
"// load defaults",
"$",
"macroDir",
"=",
"Config",
"::",
"getOption",
"(",
"\"sourceDir\"",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"\"_macros\"",
";",
"$",
"macroExt",
"=",
"Config",
"::",
"getOption",
"(",
"\"twigMacroExt\"",
")",
";",
"$",
"macroExt",
"=",
"$",
"macroExt",
"?",
"$",
"macroExt",
":",
"\"macro.twig\"",
";",
"if",
"(",
"is_dir",
"(",
"$",
"macroDir",
")",
")",
"{",
"// loop through some macro containing dir and run...",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"\"*.\"",
".",
"$",
"macroExt",
")",
"->",
"in",
"(",
"$",
"macroDir",
")",
";",
"$",
"finder",
"->",
"sortByName",
"(",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"// see if the file should be ignored",
"$",
"baseName",
"=",
"$",
"file",
"->",
"getBasename",
"(",
")",
";",
"if",
"(",
"$",
"baseName",
"[",
"0",
"]",
"!=",
"\"_\"",
")",
"{",
"// add the macro to the global context",
"self",
"::",
"$",
"instance",
"->",
"addGlobal",
"(",
"$",
"file",
"->",
"getBasename",
"(",
"\".\"",
".",
"$",
"macroExt",
")",
",",
"self",
"::",
"$",
"instance",
"->",
"loadTemplate",
"(",
"$",
"baseName",
")",
")",
";",
"}",
"}",
"}",
"}"
] |
Load macros for the Twig PatternEngine
|
[
"Load",
"macros",
"for",
"the",
"Twig",
"PatternEngine"
] |
edeb27a56a7a389e8f369e02ba9c50ee83a84cbb
|
https://github.com/pattern-lab/patternengine-php-twig/blob/edeb27a56a7a389e8f369e02ba9c50ee83a84cbb/src/PatternLab/PatternEngine/Twig/TwigUtil.php#L239-L267
|
train
|
pattern-lab/patternengine-php-twig
|
src/PatternLab/PatternEngine/Twig/TwigUtil.php
|
TwigUtil.loadTags
|
public static function loadTags() {
// load defaults
$tagDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/tags";
$tagExt = Config::getOption("twigTagExt");
$tagExt = $tagExt ? $tagExt : "tag.php";
if (is_dir($tagDir)) {
// loop through the tags and instantiate the class...
$finder = new Finder();
$finder->files()->name("*\.".$tagExt)->in($tagDir);
$finder->sortByName();
foreach ($finder as $file) {
// see if the file should be ignored or not
$baseName = $file->getBasename();
if ($baseName[0] != "_") {
include($file->getPathname());
// Project_{filenameBase}_TokenParser should be defined in the include
$className = "Project_".$file->getBasename(".".$tagExt)."_TokenParser";
self::$instance->addTokenParser(new $className());
}
}
}
}
|
php
|
public static function loadTags() {
// load defaults
$tagDir = Config::getOption("sourceDir").DIRECTORY_SEPARATOR."_twig-components/tags";
$tagExt = Config::getOption("twigTagExt");
$tagExt = $tagExt ? $tagExt : "tag.php";
if (is_dir($tagDir)) {
// loop through the tags and instantiate the class...
$finder = new Finder();
$finder->files()->name("*\.".$tagExt)->in($tagDir);
$finder->sortByName();
foreach ($finder as $file) {
// see if the file should be ignored or not
$baseName = $file->getBasename();
if ($baseName[0] != "_") {
include($file->getPathname());
// Project_{filenameBase}_TokenParser should be defined in the include
$className = "Project_".$file->getBasename(".".$tagExt)."_TokenParser";
self::$instance->addTokenParser(new $className());
}
}
}
}
|
[
"public",
"static",
"function",
"loadTags",
"(",
")",
"{",
"// load defaults",
"$",
"tagDir",
"=",
"Config",
"::",
"getOption",
"(",
"\"sourceDir\"",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"\"_twig-components/tags\"",
";",
"$",
"tagExt",
"=",
"Config",
"::",
"getOption",
"(",
"\"twigTagExt\"",
")",
";",
"$",
"tagExt",
"=",
"$",
"tagExt",
"?",
"$",
"tagExt",
":",
"\"tag.php\"",
";",
"if",
"(",
"is_dir",
"(",
"$",
"tagDir",
")",
")",
"{",
"// loop through the tags and instantiate the class...",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"name",
"(",
"\"*\\.\"",
".",
"$",
"tagExt",
")",
"->",
"in",
"(",
"$",
"tagDir",
")",
";",
"$",
"finder",
"->",
"sortByName",
"(",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"// see if the file should be ignored or not",
"$",
"baseName",
"=",
"$",
"file",
"->",
"getBasename",
"(",
")",
";",
"if",
"(",
"$",
"baseName",
"[",
"0",
"]",
"!=",
"\"_\"",
")",
"{",
"include",
"(",
"$",
"file",
"->",
"getPathname",
"(",
")",
")",
";",
"// Project_{filenameBase}_TokenParser should be defined in the include",
"$",
"className",
"=",
"\"Project_\"",
".",
"$",
"file",
"->",
"getBasename",
"(",
"\".\"",
".",
"$",
"tagExt",
")",
".",
"\"_TokenParser\"",
";",
"self",
"::",
"$",
"instance",
"->",
"addTokenParser",
"(",
"new",
"$",
"className",
"(",
")",
")",
";",
"}",
"}",
"}",
"}"
] |
Load tags for the Twig PatternEngine
|
[
"Load",
"tags",
"for",
"the",
"Twig",
"PatternEngine"
] |
edeb27a56a7a389e8f369e02ba9c50ee83a84cbb
|
https://github.com/pattern-lab/patternengine-php-twig/blob/edeb27a56a7a389e8f369e02ba9c50ee83a84cbb/src/PatternLab/PatternEngine/Twig/TwigUtil.php#L272-L303
|
train
|
icings/menu
|
src/View/Helper/MenuHelper.php
|
MenuHelper.create
|
public function create($name, array $options = [])
{
if (!is_string($name)) {
throw new \InvalidArgumentException(sprintf(
'The `$name` argument must be a string, `%s` given.',
Debugger::getType($name)
));
}
if (strlen(trim($name)) === 0) {
throw new \InvalidArgumentException('The `$name` argument must not be empty.');
}
$menu = $this->getMenuFactory()->createItem($name, $this->_extractMenuOptions($options));
$this->_addMenu($menu, $this->_extractRendererOptions($options));
return $menu;
}
|
php
|
public function create($name, array $options = [])
{
if (!is_string($name)) {
throw new \InvalidArgumentException(sprintf(
'The `$name` argument must be a string, `%s` given.',
Debugger::getType($name)
));
}
if (strlen(trim($name)) === 0) {
throw new \InvalidArgumentException('The `$name` argument must not be empty.');
}
$menu = $this->getMenuFactory()->createItem($name, $this->_extractMenuOptions($options));
$this->_addMenu($menu, $this->_extractRendererOptions($options));
return $menu;
}
|
[
"public",
"function",
"create",
"(",
"$",
"name",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The `$name` argument must be a string, `%s` given.'",
",",
"Debugger",
"::",
"getType",
"(",
"$",
"name",
")",
")",
")",
";",
"}",
"if",
"(",
"strlen",
"(",
"trim",
"(",
"$",
"name",
")",
")",
"===",
"0",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The `$name` argument must not be empty.'",
")",
";",
"}",
"$",
"menu",
"=",
"$",
"this",
"->",
"getMenuFactory",
"(",
")",
"->",
"createItem",
"(",
"$",
"name",
",",
"$",
"this",
"->",
"_extractMenuOptions",
"(",
"$",
"options",
")",
")",
";",
"$",
"this",
"->",
"_addMenu",
"(",
"$",
"menu",
",",
"$",
"this",
"->",
"_extractRendererOptions",
"(",
"$",
"options",
")",
")",
";",
"return",
"$",
"menu",
";",
"}"
] |
Creates a menu.
## Options
The `$options` argument supports the following keys:
- `menuAttributes`: The HTML attributes to apply to the menu element. Defaults to `null`.
Similar to the constructor, additional options that do not match the ones listed above will be
passed as options to the renderer.
@see __construct()
@throws \InvalidArgumentException In case the `$name` argument is not a string, or is empty.
@param string $name The name of the menu. The name serves as an identifier for retrieving
and rendering specific menus.
@param array $options An array of options, see the "Options" section in the method
description.
@return ItemInterface
|
[
"Creates",
"a",
"menu",
"."
] |
bcb4e3fe5962cbfd50dbf8c560204dc75206711e
|
https://github.com/icings/menu/blob/bcb4e3fe5962cbfd50dbf8c560204dc75206711e/src/View/Helper/MenuHelper.php#L191-L208
|
train
|
icings/menu
|
src/View/Helper/MenuHelper.php
|
MenuHelper._extractMenuOptions
|
protected function _extractMenuOptions(array &$options)
{
$menuOptions = array_intersect_key(
$options,
array_flip([
'templates',
'templateVars',
'menuAttributes'
])
);
$options = array_diff_key($options, $menuOptions);
return $menuOptions;
}
|
php
|
protected function _extractMenuOptions(array &$options)
{
$menuOptions = array_intersect_key(
$options,
array_flip([
'templates',
'templateVars',
'menuAttributes'
])
);
$options = array_diff_key($options, $menuOptions);
return $menuOptions;
}
|
[
"protected",
"function",
"_extractMenuOptions",
"(",
"array",
"&",
"$",
"options",
")",
"{",
"$",
"menuOptions",
"=",
"array_intersect_key",
"(",
"$",
"options",
",",
"array_flip",
"(",
"[",
"'templates'",
",",
"'templateVars'",
",",
"'menuAttributes'",
"]",
")",
")",
";",
"$",
"options",
"=",
"array_diff_key",
"(",
"$",
"options",
",",
"$",
"menuOptions",
")",
";",
"return",
"$",
"menuOptions",
";",
"}"
] |
Extracts the menu options from an options array.
Menu options are:
- `templates`
- `templateVars`
- `menuAttributes`
@param array $options The options array from which to extract (and remove) the menu options.
@return array The extracted renderer options.
|
[
"Extracts",
"the",
"menu",
"options",
"from",
"an",
"options",
"array",
"."
] |
bcb4e3fe5962cbfd50dbf8c560204dc75206711e
|
https://github.com/icings/menu/blob/bcb4e3fe5962cbfd50dbf8c560204dc75206711e/src/View/Helper/MenuHelper.php#L369-L383
|
train
|
icings/menu
|
src/View/Helper/MenuHelper.php
|
MenuHelper._extractRendererOptions
|
protected function _extractRendererOptions(array &$options)
{
$rendererOptions = array_diff_key(
$options,
array_flip([
'menuAttributes',
'matching',
'matcher',
'voters',
'renderer'
])
);
$options = array_diff_key($options, $rendererOptions);
return $rendererOptions;
}
|
php
|
protected function _extractRendererOptions(array &$options)
{
$rendererOptions = array_diff_key(
$options,
array_flip([
'menuAttributes',
'matching',
'matcher',
'voters',
'renderer'
])
);
$options = array_diff_key($options, $rendererOptions);
return $rendererOptions;
}
|
[
"protected",
"function",
"_extractRendererOptions",
"(",
"array",
"&",
"$",
"options",
")",
"{",
"$",
"rendererOptions",
"=",
"array_diff_key",
"(",
"$",
"options",
",",
"array_flip",
"(",
"[",
"'menuAttributes'",
",",
"'matching'",
",",
"'matcher'",
",",
"'voters'",
",",
"'renderer'",
"]",
")",
")",
";",
"$",
"options",
"=",
"array_diff_key",
"(",
"$",
"options",
",",
"$",
"rendererOptions",
")",
";",
"return",
"$",
"rendererOptions",
";",
"}"
] |
Extracts the renderer options from an options array.
Renderer options are all options except for:
- `menuAttributes`
- `matching`
- `matcher`
- `voters`
- `renderer`
@param array $options The options array from which to extract (and remove) the renderer
options.
@return array The extracted renderer options.
|
[
"Extracts",
"the",
"renderer",
"options",
"from",
"an",
"options",
"array",
"."
] |
bcb4e3fe5962cbfd50dbf8c560204dc75206711e
|
https://github.com/icings/menu/blob/bcb4e3fe5962cbfd50dbf8c560204dc75206711e/src/View/Helper/MenuHelper.php#L400-L416
|
train
|
icings/menu
|
src/View/Helper/MenuHelper.php
|
MenuHelper._createDefaultVoters
|
protected function _createDefaultVoters($type)
{
switch ($type) {
case static::MATCH_FUZZY_ROUTE:
return [
new FuzzyRouteVoter($this->getView()->getRequest())
];
case static::MATCH_URL:
return [
new UrlVoter($this->getView()->getRequest())
];
case static::MATCH_URL_WITH_QUERY_STRING:
return [
new UrlVoter($this->getView()->getRequest(), [
'ignoreQueryString' => false
])
];
}
return false;
}
|
php
|
protected function _createDefaultVoters($type)
{
switch ($type) {
case static::MATCH_FUZZY_ROUTE:
return [
new FuzzyRouteVoter($this->getView()->getRequest())
];
case static::MATCH_URL:
return [
new UrlVoter($this->getView()->getRequest())
];
case static::MATCH_URL_WITH_QUERY_STRING:
return [
new UrlVoter($this->getView()->getRequest(), [
'ignoreQueryString' => false
])
];
}
return false;
}
|
[
"protected",
"function",
"_createDefaultVoters",
"(",
"$",
"type",
")",
"{",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"static",
"::",
"MATCH_FUZZY_ROUTE",
":",
"return",
"[",
"new",
"FuzzyRouteVoter",
"(",
"$",
"this",
"->",
"getView",
"(",
")",
"->",
"getRequest",
"(",
")",
")",
"]",
";",
"case",
"static",
"::",
"MATCH_URL",
":",
"return",
"[",
"new",
"UrlVoter",
"(",
"$",
"this",
"->",
"getView",
"(",
")",
"->",
"getRequest",
"(",
")",
")",
"]",
";",
"case",
"static",
"::",
"MATCH_URL_WITH_QUERY_STRING",
":",
"return",
"[",
"new",
"UrlVoter",
"(",
"$",
"this",
"->",
"getView",
"(",
")",
"->",
"getRequest",
"(",
")",
",",
"[",
"'ignoreQueryString'",
"=>",
"false",
"]",
")",
"]",
";",
"}",
"return",
"false",
";",
"}"
] |
Creates default voters for the given type.
@param string $type The type of the voters to create.
@return VoterInterface[]|bool An array holding the created voters, or `false` for unsupported
types.
|
[
"Creates",
"default",
"voters",
"for",
"the",
"given",
"type",
"."
] |
bcb4e3fe5962cbfd50dbf8c560204dc75206711e
|
https://github.com/icings/menu/blob/bcb4e3fe5962cbfd50dbf8c560204dc75206711e/src/View/Helper/MenuHelper.php#L435-L455
|
train
|
icings/menu
|
src/Renderer/StringTemplateRenderer.php
|
StringTemplateRenderer._renderMenu
|
protected function _renderMenu(ItemInterface $item, array $options)
{
if (!$item->hasChildren() ||
$options['depth'] === 0 ||
!$item->getDisplayChildren()
) {
return '';
}
$templater = $this->templater();
$newTemplates =
(array)$item->getExtra('templates') +
(array)$options['templates'];
if ($newTemplates) {
$templater->push();
$templater->add($newTemplates);
}
$options['defaultTemplates'] = $templater->getConfig();
unset($options['templates']);
$templateVars =
(array)$item->getExtra('templateVars') +
(array)$options['templateVars'];
if (empty($templateVars)) {
$templateVars = null;
}
$options['defaultTemplateVars'] = $templateVars;
unset($options['templateVars']);
$rendered = (string)$templater->format('menu', [
'attrs' => $this->_formatAttributes($item->getChildrenAttributes(), $item),
'templateVars' => $templateVars,
'items' => $this->_renderChildren($item, $options)
]);
if ($newTemplates) {
$templater->pop();
}
return $rendered;
}
|
php
|
protected function _renderMenu(ItemInterface $item, array $options)
{
if (!$item->hasChildren() ||
$options['depth'] === 0 ||
!$item->getDisplayChildren()
) {
return '';
}
$templater = $this->templater();
$newTemplates =
(array)$item->getExtra('templates') +
(array)$options['templates'];
if ($newTemplates) {
$templater->push();
$templater->add($newTemplates);
}
$options['defaultTemplates'] = $templater->getConfig();
unset($options['templates']);
$templateVars =
(array)$item->getExtra('templateVars') +
(array)$options['templateVars'];
if (empty($templateVars)) {
$templateVars = null;
}
$options['defaultTemplateVars'] = $templateVars;
unset($options['templateVars']);
$rendered = (string)$templater->format('menu', [
'attrs' => $this->_formatAttributes($item->getChildrenAttributes(), $item),
'templateVars' => $templateVars,
'items' => $this->_renderChildren($item, $options)
]);
if ($newTemplates) {
$templater->pop();
}
return $rendered;
}
|
[
"protected",
"function",
"_renderMenu",
"(",
"ItemInterface",
"$",
"item",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"$",
"item",
"->",
"hasChildren",
"(",
")",
"||",
"$",
"options",
"[",
"'depth'",
"]",
"===",
"0",
"||",
"!",
"$",
"item",
"->",
"getDisplayChildren",
"(",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"templater",
"=",
"$",
"this",
"->",
"templater",
"(",
")",
";",
"$",
"newTemplates",
"=",
"(",
"array",
")",
"$",
"item",
"->",
"getExtra",
"(",
"'templates'",
")",
"+",
"(",
"array",
")",
"$",
"options",
"[",
"'templates'",
"]",
";",
"if",
"(",
"$",
"newTemplates",
")",
"{",
"$",
"templater",
"->",
"push",
"(",
")",
";",
"$",
"templater",
"->",
"add",
"(",
"$",
"newTemplates",
")",
";",
"}",
"$",
"options",
"[",
"'defaultTemplates'",
"]",
"=",
"$",
"templater",
"->",
"getConfig",
"(",
")",
";",
"unset",
"(",
"$",
"options",
"[",
"'templates'",
"]",
")",
";",
"$",
"templateVars",
"=",
"(",
"array",
")",
"$",
"item",
"->",
"getExtra",
"(",
"'templateVars'",
")",
"+",
"(",
"array",
")",
"$",
"options",
"[",
"'templateVars'",
"]",
";",
"if",
"(",
"empty",
"(",
"$",
"templateVars",
")",
")",
"{",
"$",
"templateVars",
"=",
"null",
";",
"}",
"$",
"options",
"[",
"'defaultTemplateVars'",
"]",
"=",
"$",
"templateVars",
";",
"unset",
"(",
"$",
"options",
"[",
"'templateVars'",
"]",
")",
";",
"$",
"rendered",
"=",
"(",
"string",
")",
"$",
"templater",
"->",
"format",
"(",
"'menu'",
",",
"[",
"'attrs'",
"=>",
"$",
"this",
"->",
"_formatAttributes",
"(",
"$",
"item",
"->",
"getChildrenAttributes",
"(",
")",
",",
"$",
"item",
")",
",",
"'templateVars'",
"=>",
"$",
"templateVars",
",",
"'items'",
"=>",
"$",
"this",
"->",
"_renderChildren",
"(",
"$",
"item",
",",
"$",
"options",
")",
"]",
")",
";",
"if",
"(",
"$",
"newTemplates",
")",
"{",
"$",
"templater",
"->",
"pop",
"(",
")",
";",
"}",
"return",
"$",
"rendered",
";",
"}"
] |
Renders the root menu item.
@param ItemInterface $item The menu item to render.
@param array $options The rendering options.
@return string The rendered menu item.
|
[
"Renders",
"the",
"root",
"menu",
"item",
"."
] |
bcb4e3fe5962cbfd50dbf8c560204dc75206711e
|
https://github.com/icings/menu/blob/bcb4e3fe5962cbfd50dbf8c560204dc75206711e/src/Renderer/StringTemplateRenderer.php#L170-L211
|
train
|
icings/menu
|
src/Renderer/StringTemplateRenderer.php
|
StringTemplateRenderer._renderNested
|
protected function _renderNested(ItemInterface $item, array $options)
{
if (!$item->hasChildren() ||
$options['depth'] === 0 ||
!$item->getDisplayChildren()
) {
return '';
}
$templater = $this->templater();
$attributes = $this->_formatAttributes($options['attributes'], $item);
unset($options['attributes']);
$templateVars = $options['templateVars'];
unset($options['templateVars']);
$newTemplates = $options['childrenTemplates'];
unset($options['childrenTemplates']);
if ($newTemplates) {
$templater->push();
$templater->add($newTemplates);
}
$items = $this->_renderChildren($item, $options);
if ($newTemplates) {
$templater->pop();
}
return (string)$templater->format('nest', [
'attrs' => $attributes,
'templateVars' => $templateVars,
'items' => $items
]);
}
|
php
|
protected function _renderNested(ItemInterface $item, array $options)
{
if (!$item->hasChildren() ||
$options['depth'] === 0 ||
!$item->getDisplayChildren()
) {
return '';
}
$templater = $this->templater();
$attributes = $this->_formatAttributes($options['attributes'], $item);
unset($options['attributes']);
$templateVars = $options['templateVars'];
unset($options['templateVars']);
$newTemplates = $options['childrenTemplates'];
unset($options['childrenTemplates']);
if ($newTemplates) {
$templater->push();
$templater->add($newTemplates);
}
$items = $this->_renderChildren($item, $options);
if ($newTemplates) {
$templater->pop();
}
return (string)$templater->format('nest', [
'attrs' => $attributes,
'templateVars' => $templateVars,
'items' => $items
]);
}
|
[
"protected",
"function",
"_renderNested",
"(",
"ItemInterface",
"$",
"item",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"!",
"$",
"item",
"->",
"hasChildren",
"(",
")",
"||",
"$",
"options",
"[",
"'depth'",
"]",
"===",
"0",
"||",
"!",
"$",
"item",
"->",
"getDisplayChildren",
"(",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"templater",
"=",
"$",
"this",
"->",
"templater",
"(",
")",
";",
"$",
"attributes",
"=",
"$",
"this",
"->",
"_formatAttributes",
"(",
"$",
"options",
"[",
"'attributes'",
"]",
",",
"$",
"item",
")",
";",
"unset",
"(",
"$",
"options",
"[",
"'attributes'",
"]",
")",
";",
"$",
"templateVars",
"=",
"$",
"options",
"[",
"'templateVars'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'templateVars'",
"]",
")",
";",
"$",
"newTemplates",
"=",
"$",
"options",
"[",
"'childrenTemplates'",
"]",
";",
"unset",
"(",
"$",
"options",
"[",
"'childrenTemplates'",
"]",
")",
";",
"if",
"(",
"$",
"newTemplates",
")",
"{",
"$",
"templater",
"->",
"push",
"(",
")",
";",
"$",
"templater",
"->",
"add",
"(",
"$",
"newTemplates",
")",
";",
"}",
"$",
"items",
"=",
"$",
"this",
"->",
"_renderChildren",
"(",
"$",
"item",
",",
"$",
"options",
")",
";",
"if",
"(",
"$",
"newTemplates",
")",
"{",
"$",
"templater",
"->",
"pop",
"(",
")",
";",
"}",
"return",
"(",
"string",
")",
"$",
"templater",
"->",
"format",
"(",
"'nest'",
",",
"[",
"'attrs'",
"=>",
"$",
"attributes",
",",
"'templateVars'",
"=>",
"$",
"templateVars",
",",
"'items'",
"=>",
"$",
"items",
"]",
")",
";",
"}"
] |
Renders the menu items children in a to be nested element.
## Options
- `attributes`: The HTML attributes to apply to the element.
- `templateVars`: The template variables to use for the element.
- `childrenTemplates`: The templates to use for the children of the element.
@param ItemInterface $item The menu whose children to render.
@param array $options The rendering options, see the "Options" section in the method
description for specific nesting element options.
@return string The rendered element.
|
[
"Renders",
"the",
"menu",
"items",
"children",
"in",
"a",
"to",
"be",
"nested",
"element",
"."
] |
bcb4e3fe5962cbfd50dbf8c560204dc75206711e
|
https://github.com/icings/menu/blob/bcb4e3fe5962cbfd50dbf8c560204dc75206711e/src/Renderer/StringTemplateRenderer.php#L227-L262
|
train
|
icings/menu
|
src/Renderer/StringTemplateRenderer.php
|
StringTemplateRenderer._renderChildren
|
protected function _renderChildren(ItemInterface $item, array $options)
{
if ($options['depth'] !== null) {
$options['depth'] = $options['depth'] - 1;
}
if ($options['matchingDepth'] !== null &&
$options['matchingDepth'] > 0
) {
$options['matchingDepth'] = $options['matchingDepth'] - 1;
}
$children = [];
foreach ($item->getChildren() as $child) {
$children[] = $this->_renderItem($child, $options);
}
return $children;
}
|
php
|
protected function _renderChildren(ItemInterface $item, array $options)
{
if ($options['depth'] !== null) {
$options['depth'] = $options['depth'] - 1;
}
if ($options['matchingDepth'] !== null &&
$options['matchingDepth'] > 0
) {
$options['matchingDepth'] = $options['matchingDepth'] - 1;
}
$children = [];
foreach ($item->getChildren() as $child) {
$children[] = $this->_renderItem($child, $options);
}
return $children;
}
|
[
"protected",
"function",
"_renderChildren",
"(",
"ItemInterface",
"$",
"item",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"$",
"options",
"[",
"'depth'",
"]",
"!==",
"null",
")",
"{",
"$",
"options",
"[",
"'depth'",
"]",
"=",
"$",
"options",
"[",
"'depth'",
"]",
"-",
"1",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'matchingDepth'",
"]",
"!==",
"null",
"&&",
"$",
"options",
"[",
"'matchingDepth'",
"]",
">",
"0",
")",
"{",
"$",
"options",
"[",
"'matchingDepth'",
"]",
"=",
"$",
"options",
"[",
"'matchingDepth'",
"]",
"-",
"1",
";",
"}",
"$",
"children",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"item",
"->",
"getChildren",
"(",
")",
"as",
"$",
"child",
")",
"{",
"$",
"children",
"[",
"]",
"=",
"$",
"this",
"->",
"_renderItem",
"(",
"$",
"child",
",",
"$",
"options",
")",
";",
"}",
"return",
"$",
"children",
";",
"}"
] |
Renders the menu items children.
@param ItemInterface $item The item whose children to render.
@param array $options The rendering options.
@return string[] The rendered children.
|
[
"Renders",
"the",
"menu",
"items",
"children",
"."
] |
bcb4e3fe5962cbfd50dbf8c560204dc75206711e
|
https://github.com/icings/menu/blob/bcb4e3fe5962cbfd50dbf8c560204dc75206711e/src/Renderer/StringTemplateRenderer.php#L271-L289
|
train
|
icings/menu
|
src/Renderer/StringTemplateRenderer.php
|
StringTemplateRenderer._renderLink
|
protected function _renderLink(ItemInterface $item, array $options)
{
if ($item->getUri() &&
(
!$item->isCurrent() ||
$options['currentAsLink']
)
) {
return $this->_renderLinkElement($item, $options);
} else {
return $this->_renderTextElement($item, $options);
}
}
|
php
|
protected function _renderLink(ItemInterface $item, array $options)
{
if ($item->getUri() &&
(
!$item->isCurrent() ||
$options['currentAsLink']
)
) {
return $this->_renderLinkElement($item, $options);
} else {
return $this->_renderTextElement($item, $options);
}
}
|
[
"protected",
"function",
"_renderLink",
"(",
"ItemInterface",
"$",
"item",
",",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"$",
"item",
"->",
"getUri",
"(",
")",
"&&",
"(",
"!",
"$",
"item",
"->",
"isCurrent",
"(",
")",
"||",
"$",
"options",
"[",
"'currentAsLink'",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_renderLinkElement",
"(",
"$",
"item",
",",
"$",
"options",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"_renderTextElement",
"(",
"$",
"item",
",",
"$",
"options",
")",
";",
"}",
"}"
] |
Renders the link for a menu item.
## Options
- `currentAsLink`: Whether to render active items as links, or as text elements.
@param ItemInterface $item The menu item for which to render a link.
@param array $options The rendering options, see the "Options" section in the method
description specific link options.
@return string The rendered link.
|
[
"Renders",
"the",
"link",
"for",
"a",
"menu",
"item",
"."
] |
bcb4e3fe5962cbfd50dbf8c560204dc75206711e
|
https://github.com/icings/menu/blob/bcb4e3fe5962cbfd50dbf8c560204dc75206711e/src/Renderer/StringTemplateRenderer.php#L431-L443
|
train
|
icings/menu
|
src/Renderer/StringTemplateRenderer.php
|
StringTemplateRenderer._renderLinkElement
|
protected function _renderLinkElement(ItemInterface $item, array $options)
{
return (string)$this->templater()->format('link', [
'attrs' => $this->_formatAttributes($item->getLinkAttributes(), $item),
'templateVars' => $options['templateVars'],
'url' => h($item->getUri()),
'label' => $this->_renderLabel($item)
]);
}
|
php
|
protected function _renderLinkElement(ItemInterface $item, array $options)
{
return (string)$this->templater()->format('link', [
'attrs' => $this->_formatAttributes($item->getLinkAttributes(), $item),
'templateVars' => $options['templateVars'],
'url' => h($item->getUri()),
'label' => $this->_renderLabel($item)
]);
}
|
[
"protected",
"function",
"_renderLinkElement",
"(",
"ItemInterface",
"$",
"item",
",",
"array",
"$",
"options",
")",
"{",
"return",
"(",
"string",
")",
"$",
"this",
"->",
"templater",
"(",
")",
"->",
"format",
"(",
"'link'",
",",
"[",
"'attrs'",
"=>",
"$",
"this",
"->",
"_formatAttributes",
"(",
"$",
"item",
"->",
"getLinkAttributes",
"(",
")",
",",
"$",
"item",
")",
",",
"'templateVars'",
"=>",
"$",
"options",
"[",
"'templateVars'",
"]",
",",
"'url'",
"=>",
"h",
"(",
"$",
"item",
"->",
"getUri",
"(",
")",
")",
",",
"'label'",
"=>",
"$",
"this",
"->",
"_renderLabel",
"(",
"$",
"item",
")",
"]",
")",
";",
"}"
] |
Renders the menu item as a link element.
## Options
- `templateVars`: The template variables to use for the link element.
@param ItemInterface $item The menu item which to render as a link element.
@param array $options The rendering options, see the "Options" section in the method
description specific link options.
@return string The rendered link element.
|
[
"Renders",
"the",
"menu",
"item",
"as",
"a",
"link",
"element",
"."
] |
bcb4e3fe5962cbfd50dbf8c560204dc75206711e
|
https://github.com/icings/menu/blob/bcb4e3fe5962cbfd50dbf8c560204dc75206711e/src/Renderer/StringTemplateRenderer.php#L457-L465
|
train
|
icings/menu
|
src/Renderer/StringTemplateRenderer.php
|
StringTemplateRenderer._renderLabel
|
protected function _renderLabel(ItemInterface $item)
{
if (!$item->getExtra('escapeLabel', true) ||
!$item->getExtra('escape', true)
) {
return $item->getLabel();
}
return (string)h($item->getLabel());
}
|
php
|
protected function _renderLabel(ItemInterface $item)
{
if (!$item->getExtra('escapeLabel', true) ||
!$item->getExtra('escape', true)
) {
return $item->getLabel();
}
return (string)h($item->getLabel());
}
|
[
"protected",
"function",
"_renderLabel",
"(",
"ItemInterface",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"$",
"item",
"->",
"getExtra",
"(",
"'escapeLabel'",
",",
"true",
")",
"||",
"!",
"$",
"item",
"->",
"getExtra",
"(",
"'escape'",
",",
"true",
")",
")",
"{",
"return",
"$",
"item",
"->",
"getLabel",
"(",
")",
";",
"}",
"return",
"(",
"string",
")",
"h",
"(",
"$",
"item",
"->",
"getLabel",
"(",
")",
")",
";",
"}"
] |
Renders a menu item label.
By default the label is being HTML entity encoded, unless explicitly disabled for the given
menu item via the `escape` or `escapeLabel` option.
@param ItemInterface $item The item whose label to render.
@return string The rendered label.
|
[
"Renders",
"a",
"menu",
"item",
"label",
"."
] |
bcb4e3fe5962cbfd50dbf8c560204dc75206711e
|
https://github.com/icings/menu/blob/bcb4e3fe5962cbfd50dbf8c560204dc75206711e/src/Renderer/StringTemplateRenderer.php#L497-L506
|
train
|
icings/menu
|
src/Renderer/StringTemplateRenderer.php
|
StringTemplateRenderer._formatAttributes
|
protected function _formatAttributes(array $attributes, ItemInterface $item)
{
if (!empty($attributes)) {
return $this->templater()->formatAttributes(
$attributes + ['escape' => $item->getExtra('escape', true)]
);
}
return '';
}
|
php
|
protected function _formatAttributes(array $attributes, ItemInterface $item)
{
if (!empty($attributes)) {
return $this->templater()->formatAttributes(
$attributes + ['escape' => $item->getExtra('escape', true)]
);
}
return '';
}
|
[
"protected",
"function",
"_formatAttributes",
"(",
"array",
"$",
"attributes",
",",
"ItemInterface",
"$",
"item",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"attributes",
")",
")",
"{",
"return",
"$",
"this",
"->",
"templater",
"(",
")",
"->",
"formatAttributes",
"(",
"$",
"attributes",
"+",
"[",
"'escape'",
"=>",
"$",
"item",
"->",
"getExtra",
"(",
"'escape'",
",",
"true",
")",
"]",
")",
";",
"}",
"return",
"''",
";",
"}"
] |
Formats an array of attributes as a string of HTML attributes.
@param array $attributes The attributes to format.
@param ItemInterface $item The menu item that defined the attributes.
@return string A formatted string of HTML attributes.
|
[
"Formats",
"an",
"array",
"of",
"attributes",
"as",
"a",
"string",
"of",
"HTML",
"attributes",
"."
] |
bcb4e3fe5962cbfd50dbf8c560204dc75206711e
|
https://github.com/icings/menu/blob/bcb4e3fe5962cbfd50dbf8c560204dc75206711e/src/Renderer/StringTemplateRenderer.php#L515-L524
|
train
|
icings/menu
|
src/Matcher/Voter/FuzzyRouteVoter.php
|
FuzzyRouteVoter._extractParams
|
protected function _extractParams(ServerRequest $request)
{
$params = $request->getAttribute('params');
$params['?'] = $request->getQueryParams();
$params['_method'] = $request->getMethod();
$params['_host'] = $request->host();
if (!isset($params['_ext'])) {
$params['_ext'] = null;
}
$pass = isset($params['pass']) ? $params['pass'] : [];
unset(
$params['pass'],
$params['paging'],
$params['models'],
$params['url'],
$params['autoRender'],
$params['bare'],
$params['requested'],
$params['return'],
$params['_Token'],
$params['_matchedRoute']
);
$params = array_merge($params, $pass);
$params += $params['?'];
$this->_normalizeParams($params);
return $params;
}
|
php
|
protected function _extractParams(ServerRequest $request)
{
$params = $request->getAttribute('params');
$params['?'] = $request->getQueryParams();
$params['_method'] = $request->getMethod();
$params['_host'] = $request->host();
if (!isset($params['_ext'])) {
$params['_ext'] = null;
}
$pass = isset($params['pass']) ? $params['pass'] : [];
unset(
$params['pass'],
$params['paging'],
$params['models'],
$params['url'],
$params['autoRender'],
$params['bare'],
$params['requested'],
$params['return'],
$params['_Token'],
$params['_matchedRoute']
);
$params = array_merge($params, $pass);
$params += $params['?'];
$this->_normalizeParams($params);
return $params;
}
|
[
"protected",
"function",
"_extractParams",
"(",
"ServerRequest",
"$",
"request",
")",
"{",
"$",
"params",
"=",
"$",
"request",
"->",
"getAttribute",
"(",
"'params'",
")",
";",
"$",
"params",
"[",
"'?'",
"]",
"=",
"$",
"request",
"->",
"getQueryParams",
"(",
")",
";",
"$",
"params",
"[",
"'_method'",
"]",
"=",
"$",
"request",
"->",
"getMethod",
"(",
")",
";",
"$",
"params",
"[",
"'_host'",
"]",
"=",
"$",
"request",
"->",
"host",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'_ext'",
"]",
")",
")",
"{",
"$",
"params",
"[",
"'_ext'",
"]",
"=",
"null",
";",
"}",
"$",
"pass",
"=",
"isset",
"(",
"$",
"params",
"[",
"'pass'",
"]",
")",
"?",
"$",
"params",
"[",
"'pass'",
"]",
":",
"[",
"]",
";",
"unset",
"(",
"$",
"params",
"[",
"'pass'",
"]",
",",
"$",
"params",
"[",
"'paging'",
"]",
",",
"$",
"params",
"[",
"'models'",
"]",
",",
"$",
"params",
"[",
"'url'",
"]",
",",
"$",
"params",
"[",
"'autoRender'",
"]",
",",
"$",
"params",
"[",
"'bare'",
"]",
",",
"$",
"params",
"[",
"'requested'",
"]",
",",
"$",
"params",
"[",
"'return'",
"]",
",",
"$",
"params",
"[",
"'_Token'",
"]",
",",
"$",
"params",
"[",
"'_matchedRoute'",
"]",
")",
";",
"$",
"params",
"=",
"array_merge",
"(",
"$",
"params",
",",
"$",
"pass",
")",
";",
"$",
"params",
"+=",
"$",
"params",
"[",
"'?'",
"]",
";",
"$",
"this",
"->",
"_normalizeParams",
"(",
"$",
"params",
")",
";",
"return",
"$",
"params",
";",
"}"
] |
Extracts the routing parameters from the given request.
@param ServerRequest $request The request object from where to extract the routing
parameters.
@return array An array of routing parameters.
|
[
"Extracts",
"the",
"routing",
"parameters",
"from",
"the",
"given",
"request",
"."
] |
bcb4e3fe5962cbfd50dbf8c560204dc75206711e
|
https://github.com/icings/menu/blob/bcb4e3fe5962cbfd50dbf8c560204dc75206711e/src/Matcher/Voter/FuzzyRouteVoter.php#L83-L113
|
train
|
icings/menu
|
src/Matcher/Voter/FuzzyRouteVoter.php
|
FuzzyRouteVoter._normalizeParams
|
protected function _normalizeParams(array &$params)
{
ksort($params, \SORT_STRING);
array_walk($params, function (&$value) {
if (is_numeric($value)) {
$value = (string)$value;
}
});
if (isset($params['?'])) {
$this->_normalizeParams($params['?']);
}
}
|
php
|
protected function _normalizeParams(array &$params)
{
ksort($params, \SORT_STRING);
array_walk($params, function (&$value) {
if (is_numeric($value)) {
$value = (string)$value;
}
});
if (isset($params['?'])) {
$this->_normalizeParams($params['?']);
}
}
|
[
"protected",
"function",
"_normalizeParams",
"(",
"array",
"&",
"$",
"params",
")",
"{",
"ksort",
"(",
"$",
"params",
",",
"\\",
"SORT_STRING",
")",
";",
"array_walk",
"(",
"$",
"params",
",",
"function",
"(",
"&",
"$",
"value",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"}",
"}",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'?'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_normalizeParams",
"(",
"$",
"params",
"[",
"'?'",
"]",
")",
";",
"}",
"}"
] |
Normalizes a set of routing parameters.
Normalization includes:
- casting numeric values to strings
- sorting elements by key
@param array $params The parameters to normalize.
@return void
|
[
"Normalizes",
"a",
"set",
"of",
"routing",
"parameters",
"."
] |
bcb4e3fe5962cbfd50dbf8c560204dc75206711e
|
https://github.com/icings/menu/blob/bcb4e3fe5962cbfd50dbf8c560204dc75206711e/src/Matcher/Voter/FuzzyRouteVoter.php#L126-L138
|
train
|
tobscure/json-api
|
src/ErrorHandler.php
|
ErrorHandler.handle
|
public function handle(Exception $e)
{
foreach ($this->handlers as $handler) {
if ($handler->manages($e)) {
return $handler->handle($e);
}
}
throw new RuntimeException('Exception handler for '.get_class($e).' not found.');
}
|
php
|
public function handle(Exception $e)
{
foreach ($this->handlers as $handler) {
if ($handler->manages($e)) {
return $handler->handle($e);
}
}
throw new RuntimeException('Exception handler for '.get_class($e).' not found.');
}
|
[
"public",
"function",
"handle",
"(",
"Exception",
"$",
"e",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"handlers",
"as",
"$",
"handler",
")",
"{",
"if",
"(",
"$",
"handler",
"->",
"manages",
"(",
"$",
"e",
")",
")",
"{",
"return",
"$",
"handler",
"->",
"handle",
"(",
"$",
"e",
")",
";",
"}",
"}",
"throw",
"new",
"RuntimeException",
"(",
"'Exception handler for '",
".",
"get_class",
"(",
"$",
"e",
")",
".",
"' not found.'",
")",
";",
"}"
] |
Handle the exception provided.
@param Exception $e
@throws RuntimeException
@return \Tobscure\JsonApi\Exception\Handler\ResponseBag
|
[
"Handle",
"the",
"exception",
"provided",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/ErrorHandler.php#L36-L45
|
train
|
tobscure/json-api
|
src/Relationship.php
|
Relationship.toArray
|
public function toArray()
{
$array = [];
if (! empty($this->data)) {
$array['data'] = $this->data->toIdentifier();
}
if (! empty($this->meta)) {
$array['meta'] = $this->meta;
}
if (! empty($this->links)) {
$array['links'] = $this->links;
}
return $array;
}
|
php
|
public function toArray()
{
$array = [];
if (! empty($this->data)) {
$array['data'] = $this->data->toIdentifier();
}
if (! empty($this->meta)) {
$array['meta'] = $this->meta;
}
if (! empty($this->links)) {
$array['links'] = $this->links;
}
return $array;
}
|
[
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"array",
"[",
"'data'",
"]",
"=",
"$",
"this",
"->",
"data",
"->",
"toIdentifier",
"(",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"meta",
")",
")",
"{",
"$",
"array",
"[",
"'meta'",
"]",
"=",
"$",
"this",
"->",
"meta",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"links",
")",
")",
"{",
"$",
"array",
"[",
"'links'",
"]",
"=",
"$",
"this",
"->",
"links",
";",
"}",
"return",
"$",
"array",
";",
"}"
] |
Map everything to an array.
@return array
|
[
"Map",
"everything",
"to",
"an",
"array",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Relationship.php#L65-L82
|
train
|
tobscure/json-api
|
src/LinksTrait.php
|
LinksTrait.addPaginationLink
|
protected function addPaginationLink($name, $url, array $queryParams, $offset, $limit)
{
if (! isset($queryParams['page']) || ! is_array($queryParams['page'])) {
$queryParams['page'] = [];
}
$page = &$queryParams['page'];
if (isset($page['number'])) {
$page['number'] = floor($offset / $limit) + 1;
if ($page['number'] <= 1) {
unset($page['number']);
}
} else {
$page['offset'] = $offset;
if ($page['offset'] <= 0) {
unset($page['offset']);
}
}
if (isset($page['limit'])) {
$page['limit'] = $limit;
}
$queryString = http_build_query($queryParams);
$this->addLink($name, $url.($queryString ? '?'.$queryString : ''));
}
|
php
|
protected function addPaginationLink($name, $url, array $queryParams, $offset, $limit)
{
if (! isset($queryParams['page']) || ! is_array($queryParams['page'])) {
$queryParams['page'] = [];
}
$page = &$queryParams['page'];
if (isset($page['number'])) {
$page['number'] = floor($offset / $limit) + 1;
if ($page['number'] <= 1) {
unset($page['number']);
}
} else {
$page['offset'] = $offset;
if ($page['offset'] <= 0) {
unset($page['offset']);
}
}
if (isset($page['limit'])) {
$page['limit'] = $limit;
}
$queryString = http_build_query($queryParams);
$this->addLink($name, $url.($queryString ? '?'.$queryString : ''));
}
|
[
"protected",
"function",
"addPaginationLink",
"(",
"$",
"name",
",",
"$",
"url",
",",
"array",
"$",
"queryParams",
",",
"$",
"offset",
",",
"$",
"limit",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"queryParams",
"[",
"'page'",
"]",
")",
"||",
"!",
"is_array",
"(",
"$",
"queryParams",
"[",
"'page'",
"]",
")",
")",
"{",
"$",
"queryParams",
"[",
"'page'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"page",
"=",
"&",
"$",
"queryParams",
"[",
"'page'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"page",
"[",
"'number'",
"]",
")",
")",
"{",
"$",
"page",
"[",
"'number'",
"]",
"=",
"floor",
"(",
"$",
"offset",
"/",
"$",
"limit",
")",
"+",
"1",
";",
"if",
"(",
"$",
"page",
"[",
"'number'",
"]",
"<=",
"1",
")",
"{",
"unset",
"(",
"$",
"page",
"[",
"'number'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"page",
"[",
"'offset'",
"]",
"=",
"$",
"offset",
";",
"if",
"(",
"$",
"page",
"[",
"'offset'",
"]",
"<=",
"0",
")",
"{",
"unset",
"(",
"$",
"page",
"[",
"'offset'",
"]",
")",
";",
"}",
"}",
"if",
"(",
"isset",
"(",
"$",
"page",
"[",
"'limit'",
"]",
")",
")",
"{",
"$",
"page",
"[",
"'limit'",
"]",
"=",
"$",
"limit",
";",
"}",
"$",
"queryString",
"=",
"http_build_query",
"(",
"$",
"queryParams",
")",
";",
"$",
"this",
"->",
"addLink",
"(",
"$",
"name",
",",
"$",
"url",
".",
"(",
"$",
"queryString",
"?",
"'?'",
".",
"$",
"queryString",
":",
"''",
")",
")",
";",
"}"
] |
Add a pagination link.
@param string $name The name of the link.
@param string $url The base URL for pagination links.
@param array $queryParams The query params provided in the request.
@param int $offset The offset to link to.
@param int $limit The current limit.
@return void
|
[
"Add",
"a",
"pagination",
"link",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/LinksTrait.php#L105-L134
|
train
|
tobscure/json-api
|
src/Collection.php
|
Collection.buildResources
|
protected function buildResources($data, SerializerInterface $serializer)
{
$resources = [];
foreach ($data as $resource) {
if (! ($resource instanceof Resource)) {
$resource = new Resource($resource, $serializer);
}
$resources[] = $resource;
}
return $resources;
}
|
php
|
protected function buildResources($data, SerializerInterface $serializer)
{
$resources = [];
foreach ($data as $resource) {
if (! ($resource instanceof Resource)) {
$resource = new Resource($resource, $serializer);
}
$resources[] = $resource;
}
return $resources;
}
|
[
"protected",
"function",
"buildResources",
"(",
"$",
"data",
",",
"SerializerInterface",
"$",
"serializer",
")",
"{",
"$",
"resources",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"resource",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"resource",
"instanceof",
"Resource",
")",
")",
"{",
"$",
"resource",
"=",
"new",
"Resource",
"(",
"$",
"resource",
",",
"$",
"serializer",
")",
";",
"}",
"$",
"resources",
"[",
"]",
"=",
"$",
"resource",
";",
"}",
"return",
"$",
"resources",
";",
"}"
] |
Convert an array of raw data to Resource objects.
@param mixed $data
@param SerializerInterface $serializer
@return \Tobscure\JsonApi\Resource[]
|
[
"Convert",
"an",
"array",
"of",
"raw",
"data",
"to",
"Resource",
"objects",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Collection.php#L40-L53
|
train
|
tobscure/json-api
|
src/Collection.php
|
Collection.with
|
public function with($relationships)
{
foreach ($this->resources as $resource) {
$resource->with($relationships);
}
return $this;
}
|
php
|
public function with($relationships)
{
foreach ($this->resources as $resource) {
$resource->with($relationships);
}
return $this;
}
|
[
"public",
"function",
"with",
"(",
"$",
"relationships",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"resources",
"as",
"$",
"resource",
")",
"{",
"$",
"resource",
"->",
"with",
"(",
"$",
"relationships",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Request a relationship to be included for all resources.
@param string|array $relationships
@return $this
|
[
"Request",
"a",
"relationship",
"to",
"be",
"included",
"for",
"all",
"resources",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Collection.php#L82-L89
|
train
|
tobscure/json-api
|
src/Collection.php
|
Collection.fields
|
public function fields($fields)
{
foreach ($this->resources as $resource) {
$resource->fields($fields);
}
return $this;
}
|
php
|
public function fields($fields)
{
foreach ($this->resources as $resource) {
$resource->fields($fields);
}
return $this;
}
|
[
"public",
"function",
"fields",
"(",
"$",
"fields",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"resources",
"as",
"$",
"resource",
")",
"{",
"$",
"resource",
"->",
"fields",
"(",
"$",
"fields",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] |
Request a restricted set of fields.
@param array|null $fields
@return $this
|
[
"Request",
"a",
"restricted",
"set",
"of",
"fields",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Collection.php#L98-L105
|
train
|
tobscure/json-api
|
src/AbstractSerializer.php
|
AbstractSerializer.getRelationshipMethodName
|
private function getRelationshipMethodName($name)
{
if (stripos($name, '-')) {
$name = lcfirst(implode('', array_map('ucfirst', explode('-', $name))));
}
if (stripos($name, '_')) {
$name = lcfirst(implode('', array_map('ucfirst', explode('_', $name))));
}
return $name;
}
|
php
|
private function getRelationshipMethodName($name)
{
if (stripos($name, '-')) {
$name = lcfirst(implode('', array_map('ucfirst', explode('-', $name))));
}
if (stripos($name, '_')) {
$name = lcfirst(implode('', array_map('ucfirst', explode('_', $name))));
}
return $name;
}
|
[
"private",
"function",
"getRelationshipMethodName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"name",
",",
"'-'",
")",
")",
"{",
"$",
"name",
"=",
"lcfirst",
"(",
"implode",
"(",
"''",
",",
"array_map",
"(",
"'ucfirst'",
",",
"explode",
"(",
"'-'",
",",
"$",
"name",
")",
")",
")",
")",
";",
"}",
"if",
"(",
"stripos",
"(",
"$",
"name",
",",
"'_'",
")",
")",
"{",
"$",
"name",
"=",
"lcfirst",
"(",
"implode",
"(",
"''",
",",
"array_map",
"(",
"'ucfirst'",
",",
"explode",
"(",
"'_'",
",",
"$",
"name",
")",
")",
")",
")",
";",
"}",
"return",
"$",
"name",
";",
"}"
] |
Get the serializer method name for the given relationship.
snake_case and kebab-case are converted into camelCase.
@param string $name
@return string
|
[
"Get",
"the",
"serializer",
"method",
"name",
"for",
"the",
"given",
"relationship",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/AbstractSerializer.php#L94-L105
|
train
|
tobscure/json-api
|
src/Parameters.php
|
Parameters.getInclude
|
public function getInclude(array $available = [])
{
if ($include = $this->getInput('include')) {
$relationships = explode(',', $include);
$invalid = array_diff($relationships, $available);
if (count($invalid)) {
throw new InvalidParameterException(
'Invalid includes ['.implode(',', $invalid).']',
1,
null,
'include'
);
}
return $relationships;
}
return [];
}
|
php
|
public function getInclude(array $available = [])
{
if ($include = $this->getInput('include')) {
$relationships = explode(',', $include);
$invalid = array_diff($relationships, $available);
if (count($invalid)) {
throw new InvalidParameterException(
'Invalid includes ['.implode(',', $invalid).']',
1,
null,
'include'
);
}
return $relationships;
}
return [];
}
|
[
"public",
"function",
"getInclude",
"(",
"array",
"$",
"available",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"$",
"include",
"=",
"$",
"this",
"->",
"getInput",
"(",
"'include'",
")",
")",
"{",
"$",
"relationships",
"=",
"explode",
"(",
"','",
",",
"$",
"include",
")",
";",
"$",
"invalid",
"=",
"array_diff",
"(",
"$",
"relationships",
",",
"$",
"available",
")",
";",
"if",
"(",
"count",
"(",
"$",
"invalid",
")",
")",
"{",
"throw",
"new",
"InvalidParameterException",
"(",
"'Invalid includes ['",
".",
"implode",
"(",
"','",
",",
"$",
"invalid",
")",
".",
"']'",
",",
"1",
",",
"null",
",",
"'include'",
")",
";",
"}",
"return",
"$",
"relationships",
";",
"}",
"return",
"[",
"]",
";",
"}"
] |
Get the includes.
@param array $available
@throws \Tobscure\JsonApi\Exception\InvalidParameterException
@return array
|
[
"Get",
"the",
"includes",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Parameters.php#L40-L60
|
train
|
tobscure/json-api
|
src/Parameters.php
|
Parameters.getOffset
|
public function getOffset($perPage = null)
{
if ($perPage && ($offset = $this->getOffsetFromNumber($perPage))) {
return $offset;
}
$offset = (int) $this->getPage('offset');
if ($offset < 0) {
throw new InvalidParameterException('page[offset] must be >=0', 2, null, 'page[offset]');
}
return $offset;
}
|
php
|
public function getOffset($perPage = null)
{
if ($perPage && ($offset = $this->getOffsetFromNumber($perPage))) {
return $offset;
}
$offset = (int) $this->getPage('offset');
if ($offset < 0) {
throw new InvalidParameterException('page[offset] must be >=0', 2, null, 'page[offset]');
}
return $offset;
}
|
[
"public",
"function",
"getOffset",
"(",
"$",
"perPage",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"perPage",
"&&",
"(",
"$",
"offset",
"=",
"$",
"this",
"->",
"getOffsetFromNumber",
"(",
"$",
"perPage",
")",
")",
")",
"{",
"return",
"$",
"offset",
";",
"}",
"$",
"offset",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"getPage",
"(",
"'offset'",
")",
";",
"if",
"(",
"$",
"offset",
"<",
"0",
")",
"{",
"throw",
"new",
"InvalidParameterException",
"(",
"'page[offset] must be >=0'",
",",
"2",
",",
"null",
",",
"'page[offset]'",
")",
";",
"}",
"return",
"$",
"offset",
";",
"}"
] |
Get number of offset.
@param int|null $perPage
@throws \Tobscure\JsonApi\Exception\InvalidParameterException
@return int
|
[
"Get",
"number",
"of",
"offset",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Parameters.php#L71-L84
|
train
|
tobscure/json-api
|
src/Parameters.php
|
Parameters.getSort
|
public function getSort(array $available = [])
{
$sort = [];
if ($input = $this->getInput('sort')) {
$fields = explode(',', $input);
foreach ($fields as $field) {
if (substr($field, 0, 1) === '-') {
$field = substr($field, 1);
$order = 'desc';
} else {
$order = 'asc';
}
$sort[$field] = $order;
}
$invalid = array_diff(array_keys($sort), $available);
if (count($invalid)) {
throw new InvalidParameterException(
'Invalid sort fields ['.implode(',', $invalid).']',
3,
null,
'sort'
);
}
}
return $sort;
}
|
php
|
public function getSort(array $available = [])
{
$sort = [];
if ($input = $this->getInput('sort')) {
$fields = explode(',', $input);
foreach ($fields as $field) {
if (substr($field, 0, 1) === '-') {
$field = substr($field, 1);
$order = 'desc';
} else {
$order = 'asc';
}
$sort[$field] = $order;
}
$invalid = array_diff(array_keys($sort), $available);
if (count($invalid)) {
throw new InvalidParameterException(
'Invalid sort fields ['.implode(',', $invalid).']',
3,
null,
'sort'
);
}
}
return $sort;
}
|
[
"public",
"function",
"getSort",
"(",
"array",
"$",
"available",
"=",
"[",
"]",
")",
"{",
"$",
"sort",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"input",
"=",
"$",
"this",
"->",
"getInput",
"(",
"'sort'",
")",
")",
"{",
"$",
"fields",
"=",
"explode",
"(",
"','",
",",
"$",
"input",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"field",
",",
"0",
",",
"1",
")",
"===",
"'-'",
")",
"{",
"$",
"field",
"=",
"substr",
"(",
"$",
"field",
",",
"1",
")",
";",
"$",
"order",
"=",
"'desc'",
";",
"}",
"else",
"{",
"$",
"order",
"=",
"'asc'",
";",
"}",
"$",
"sort",
"[",
"$",
"field",
"]",
"=",
"$",
"order",
";",
"}",
"$",
"invalid",
"=",
"array_diff",
"(",
"array_keys",
"(",
"$",
"sort",
")",
",",
"$",
"available",
")",
";",
"if",
"(",
"count",
"(",
"$",
"invalid",
")",
")",
"{",
"throw",
"new",
"InvalidParameterException",
"(",
"'Invalid sort fields ['",
".",
"implode",
"(",
"','",
",",
"$",
"invalid",
")",
".",
"']'",
",",
"3",
",",
"null",
",",
"'sort'",
")",
";",
"}",
"}",
"return",
"$",
"sort",
";",
"}"
] |
Get the sort.
@param array $available
@throws \Tobscure\JsonApi\Exception\InvalidParameterException
@return array
|
[
"Get",
"the",
"sort",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Parameters.php#L133-L164
|
train
|
tobscure/json-api
|
src/Parameters.php
|
Parameters.getFields
|
public function getFields()
{
$fields = $this->getInput('fields');
if (! is_array($fields)) {
return [];
}
return array_map(function ($fields) {
return explode(',', $fields);
}, $fields);
}
|
php
|
public function getFields()
{
$fields = $this->getInput('fields');
if (! is_array($fields)) {
return [];
}
return array_map(function ($fields) {
return explode(',', $fields);
}, $fields);
}
|
[
"public",
"function",
"getFields",
"(",
")",
"{",
"$",
"fields",
"=",
"$",
"this",
"->",
"getInput",
"(",
"'fields'",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"return",
"array_map",
"(",
"function",
"(",
"$",
"fields",
")",
"{",
"return",
"explode",
"(",
"','",
",",
"$",
"fields",
")",
";",
"}",
",",
"$",
"fields",
")",
";",
"}"
] |
Get the fields requested for inclusion.
@return array
|
[
"Get",
"the",
"fields",
"requested",
"for",
"inclusion",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Parameters.php#L171-L182
|
train
|
tobscure/json-api
|
src/Document.php
|
Document.getIncluded
|
protected function getIncluded(ElementInterface $element, $includeParent = false)
{
$included = [];
foreach ($element->getResources() as $resource) {
if ($resource->isIdentifier()) {
continue;
}
if ($includeParent) {
$included = $this->mergeResource($included, $resource);
} else {
$type = $resource->getType();
$id = $resource->getId();
}
foreach ($resource->getUnfilteredRelationships() as $relationship) {
$includedElement = $relationship->getData();
if (! $includedElement instanceof ElementInterface) {
continue;
}
foreach ($this->getIncluded($includedElement, true) as $child) {
// If this resource is the same as the top-level "data"
// resource, then we don't want it to show up again in the
// "included" array.
if (! $includeParent && $child->getType() === $type && $child->getId() === $id) {
continue;
}
$included = $this->mergeResource($included, $child);
}
}
}
$flattened = [];
array_walk_recursive($included, function ($a) use (&$flattened) {
$flattened[] = $a;
});
return $flattened;
}
|
php
|
protected function getIncluded(ElementInterface $element, $includeParent = false)
{
$included = [];
foreach ($element->getResources() as $resource) {
if ($resource->isIdentifier()) {
continue;
}
if ($includeParent) {
$included = $this->mergeResource($included, $resource);
} else {
$type = $resource->getType();
$id = $resource->getId();
}
foreach ($resource->getUnfilteredRelationships() as $relationship) {
$includedElement = $relationship->getData();
if (! $includedElement instanceof ElementInterface) {
continue;
}
foreach ($this->getIncluded($includedElement, true) as $child) {
// If this resource is the same as the top-level "data"
// resource, then we don't want it to show up again in the
// "included" array.
if (! $includeParent && $child->getType() === $type && $child->getId() === $id) {
continue;
}
$included = $this->mergeResource($included, $child);
}
}
}
$flattened = [];
array_walk_recursive($included, function ($a) use (&$flattened) {
$flattened[] = $a;
});
return $flattened;
}
|
[
"protected",
"function",
"getIncluded",
"(",
"ElementInterface",
"$",
"element",
",",
"$",
"includeParent",
"=",
"false",
")",
"{",
"$",
"included",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"element",
"->",
"getResources",
"(",
")",
"as",
"$",
"resource",
")",
"{",
"if",
"(",
"$",
"resource",
"->",
"isIdentifier",
"(",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"$",
"includeParent",
")",
"{",
"$",
"included",
"=",
"$",
"this",
"->",
"mergeResource",
"(",
"$",
"included",
",",
"$",
"resource",
")",
";",
"}",
"else",
"{",
"$",
"type",
"=",
"$",
"resource",
"->",
"getType",
"(",
")",
";",
"$",
"id",
"=",
"$",
"resource",
"->",
"getId",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"resource",
"->",
"getUnfilteredRelationships",
"(",
")",
"as",
"$",
"relationship",
")",
"{",
"$",
"includedElement",
"=",
"$",
"relationship",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"!",
"$",
"includedElement",
"instanceof",
"ElementInterface",
")",
"{",
"continue",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"getIncluded",
"(",
"$",
"includedElement",
",",
"true",
")",
"as",
"$",
"child",
")",
"{",
"// If this resource is the same as the top-level \"data\"",
"// resource, then we don't want it to show up again in the",
"// \"included\" array.",
"if",
"(",
"!",
"$",
"includeParent",
"&&",
"$",
"child",
"->",
"getType",
"(",
")",
"===",
"$",
"type",
"&&",
"$",
"child",
"->",
"getId",
"(",
")",
"===",
"$",
"id",
")",
"{",
"continue",
";",
"}",
"$",
"included",
"=",
"$",
"this",
"->",
"mergeResource",
"(",
"$",
"included",
",",
"$",
"child",
")",
";",
"}",
"}",
"}",
"$",
"flattened",
"=",
"[",
"]",
";",
"array_walk_recursive",
"(",
"$",
"included",
",",
"function",
"(",
"$",
"a",
")",
"use",
"(",
"&",
"$",
"flattened",
")",
"{",
"$",
"flattened",
"[",
"]",
"=",
"$",
"a",
";",
"}",
")",
";",
"return",
"$",
"flattened",
";",
"}"
] |
Get included resources.
@param \Tobscure\JsonApi\ElementInterface $element
@param bool $includeParent
@return \Tobscure\JsonApi\Resource[]
|
[
"Get",
"included",
"resources",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Document.php#L67-L110
|
train
|
tobscure/json-api
|
src/Document.php
|
Document.toArray
|
public function toArray()
{
$document = [];
if (! empty($this->links)) {
$document['links'] = $this->links;
}
if (! empty($this->data)) {
$document['data'] = $this->data->toArray();
$resources = $this->getIncluded($this->data);
if (count($resources)) {
$document['included'] = array_map(function (Resource $resource) {
return $resource->toArray();
}, $resources);
}
}
if (! empty($this->meta)) {
$document['meta'] = $this->meta;
}
if (! empty($this->errors)) {
$document['errors'] = $this->errors;
}
if (! empty($this->jsonapi)) {
$document['jsonapi'] = $this->jsonapi;
}
return $document;
}
|
php
|
public function toArray()
{
$document = [];
if (! empty($this->links)) {
$document['links'] = $this->links;
}
if (! empty($this->data)) {
$document['data'] = $this->data->toArray();
$resources = $this->getIncluded($this->data);
if (count($resources)) {
$document['included'] = array_map(function (Resource $resource) {
return $resource->toArray();
}, $resources);
}
}
if (! empty($this->meta)) {
$document['meta'] = $this->meta;
}
if (! empty($this->errors)) {
$document['errors'] = $this->errors;
}
if (! empty($this->jsonapi)) {
$document['jsonapi'] = $this->jsonapi;
}
return $document;
}
|
[
"public",
"function",
"toArray",
"(",
")",
"{",
"$",
"document",
"=",
"[",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"links",
")",
")",
"{",
"$",
"document",
"[",
"'links'",
"]",
"=",
"$",
"this",
"->",
"links",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"$",
"document",
"[",
"'data'",
"]",
"=",
"$",
"this",
"->",
"data",
"->",
"toArray",
"(",
")",
";",
"$",
"resources",
"=",
"$",
"this",
"->",
"getIncluded",
"(",
"$",
"this",
"->",
"data",
")",
";",
"if",
"(",
"count",
"(",
"$",
"resources",
")",
")",
"{",
"$",
"document",
"[",
"'included'",
"]",
"=",
"array_map",
"(",
"function",
"(",
"Resource",
"$",
"resource",
")",
"{",
"return",
"$",
"resource",
"->",
"toArray",
"(",
")",
";",
"}",
",",
"$",
"resources",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"meta",
")",
")",
"{",
"$",
"document",
"[",
"'meta'",
"]",
"=",
"$",
"this",
"->",
"meta",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"errors",
")",
")",
"{",
"$",
"document",
"[",
"'errors'",
"]",
"=",
"$",
"this",
"->",
"errors",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"jsonapi",
")",
")",
"{",
"$",
"document",
"[",
"'jsonapi'",
"]",
"=",
"$",
"this",
"->",
"jsonapi",
";",
"}",
"return",
"$",
"document",
";",
"}"
] |
Map everything to arrays.
@return array
|
[
"Map",
"everything",
"to",
"arrays",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Document.php#L179-L212
|
train
|
tobscure/json-api
|
src/Util.php
|
Util.parseRelationshipPaths
|
public static function parseRelationshipPaths(array $paths)
{
$tree = [];
foreach ($paths as $path) {
list($primary, $nested) = array_pad(explode('.', $path, 2), 2, null);
if (! isset($tree[$primary])) {
$tree[$primary] = [];
}
if ($nested) {
$tree[$primary][] = $nested;
}
}
return $tree;
}
|
php
|
public static function parseRelationshipPaths(array $paths)
{
$tree = [];
foreach ($paths as $path) {
list($primary, $nested) = array_pad(explode('.', $path, 2), 2, null);
if (! isset($tree[$primary])) {
$tree[$primary] = [];
}
if ($nested) {
$tree[$primary][] = $nested;
}
}
return $tree;
}
|
[
"public",
"static",
"function",
"parseRelationshipPaths",
"(",
"array",
"$",
"paths",
")",
"{",
"$",
"tree",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"path",
")",
"{",
"list",
"(",
"$",
"primary",
",",
"$",
"nested",
")",
"=",
"array_pad",
"(",
"explode",
"(",
"'.'",
",",
"$",
"path",
",",
"2",
")",
",",
"2",
",",
"null",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"tree",
"[",
"$",
"primary",
"]",
")",
")",
"{",
"$",
"tree",
"[",
"$",
"primary",
"]",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"$",
"nested",
")",
"{",
"$",
"tree",
"[",
"$",
"primary",
"]",
"[",
"]",
"=",
"$",
"nested",
";",
"}",
"}",
"return",
"$",
"tree",
";",
"}"
] |
Parse relationship paths.
Given a flat array of relationship paths like:
['user', 'user.employer', 'user.employer.country', 'comments']
create a nested array of relationship paths one-level deep that can
be passed on to other serializers:
['user' => ['employer', 'employer.country'], 'comments' => []]
@param array $paths
@return array
|
[
"Parse",
"relationship",
"paths",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Util.php#L32-L49
|
train
|
tobscure/json-api
|
src/Resource.php
|
Resource.getId
|
public function getId()
{
if (! is_object($this->data) && ! is_array($this->data)) {
return (string) $this->data;
}
return (string) $this->serializer->getId($this->data);
}
|
php
|
public function getId()
{
if (! is_object($this->data) && ! is_array($this->data)) {
return (string) $this->data;
}
return (string) $this->serializer->getId($this->data);
}
|
[
"public",
"function",
"getId",
"(",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"this",
"->",
"data",
")",
"&&",
"!",
"is_array",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"return",
"(",
"string",
")",
"$",
"this",
"->",
"data",
";",
"}",
"return",
"(",
"string",
")",
"$",
"this",
"->",
"serializer",
"->",
"getId",
"(",
"$",
"this",
"->",
"data",
")",
";",
"}"
] |
Get the resource ID.
@return string
|
[
"Get",
"the",
"resource",
"ID",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Resource.php#L167-L174
|
train
|
tobscure/json-api
|
src/Resource.php
|
Resource.getAttributes
|
public function getAttributes()
{
$attributes = (array) $this->serializer->getAttributes($this->data, $this->getOwnFields());
$attributes = $this->filterFields($attributes);
$attributes = $this->mergeAttributes($attributes);
return $attributes;
}
|
php
|
public function getAttributes()
{
$attributes = (array) $this->serializer->getAttributes($this->data, $this->getOwnFields());
$attributes = $this->filterFields($attributes);
$attributes = $this->mergeAttributes($attributes);
return $attributes;
}
|
[
"public",
"function",
"getAttributes",
"(",
")",
"{",
"$",
"attributes",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"serializer",
"->",
"getAttributes",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"this",
"->",
"getOwnFields",
"(",
")",
")",
";",
"$",
"attributes",
"=",
"$",
"this",
"->",
"filterFields",
"(",
"$",
"attributes",
")",
";",
"$",
"attributes",
"=",
"$",
"this",
"->",
"mergeAttributes",
"(",
"$",
"attributes",
")",
";",
"return",
"$",
"attributes",
";",
"}"
] |
Get the resource attributes.
@return array
|
[
"Get",
"the",
"resource",
"attributes",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Resource.php#L181-L190
|
train
|
tobscure/json-api
|
src/Resource.php
|
Resource.getOwnFields
|
protected function getOwnFields()
{
$type = $this->getType();
if (isset($this->fields[$type])) {
return $this->fields[$type];
}
}
|
php
|
protected function getOwnFields()
{
$type = $this->getType();
if (isset($this->fields[$type])) {
return $this->fields[$type];
}
}
|
[
"protected",
"function",
"getOwnFields",
"(",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"getType",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"fields",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"fields",
"[",
"$",
"type",
"]",
";",
"}",
"}"
] |
Get the requested fields for this resource type.
@return array|null
|
[
"Get",
"the",
"requested",
"fields",
"for",
"this",
"resource",
"type",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Resource.php#L197-L204
|
train
|
tobscure/json-api
|
src/Resource.php
|
Resource.mergeAttributes
|
protected function mergeAttributes(array $attributes)
{
foreach ($this->merged as $resource) {
$attributes = array_replace_recursive($attributes, $resource->getAttributes());
}
return $attributes;
}
|
php
|
protected function mergeAttributes(array $attributes)
{
foreach ($this->merged as $resource) {
$attributes = array_replace_recursive($attributes, $resource->getAttributes());
}
return $attributes;
}
|
[
"protected",
"function",
"mergeAttributes",
"(",
"array",
"$",
"attributes",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"merged",
"as",
"$",
"resource",
")",
"{",
"$",
"attributes",
"=",
"array_replace_recursive",
"(",
"$",
"attributes",
",",
"$",
"resource",
"->",
"getAttributes",
"(",
")",
")",
";",
"}",
"return",
"$",
"attributes",
";",
"}"
] |
Merge the attributes of merged resources into an array of attributes.
@param array $attributes
@return array
|
[
"Merge",
"the",
"attributes",
"of",
"merged",
"resources",
"into",
"an",
"array",
"of",
"attributes",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Resource.php#L230-L237
|
train
|
tobscure/json-api
|
src/Resource.php
|
Resource.getRelationshipsAsArray
|
public function getRelationshipsAsArray()
{
$relationships = $this->getRelationships();
$relationships = $this->convertRelationshipsToArray($relationships);
return $this->mergeRelationships($relationships);
}
|
php
|
public function getRelationshipsAsArray()
{
$relationships = $this->getRelationships();
$relationships = $this->convertRelationshipsToArray($relationships);
return $this->mergeRelationships($relationships);
}
|
[
"public",
"function",
"getRelationshipsAsArray",
"(",
")",
"{",
"$",
"relationships",
"=",
"$",
"this",
"->",
"getRelationships",
"(",
")",
";",
"$",
"relationships",
"=",
"$",
"this",
"->",
"convertRelationshipsToArray",
"(",
"$",
"relationships",
")",
";",
"return",
"$",
"this",
"->",
"mergeRelationships",
"(",
"$",
"relationships",
")",
";",
"}"
] |
Get the resource relationships as an array.
@return array
|
[
"Get",
"the",
"resource",
"relationships",
"as",
"an",
"array",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Resource.php#L266-L273
|
train
|
tobscure/json-api
|
src/Resource.php
|
Resource.buildRelationships
|
protected function buildRelationships()
{
if (isset($this->relationships)) {
return $this->relationships;
}
$paths = Util::parseRelationshipPaths($this->includes);
$relationships = [];
foreach ($paths as $name => $nested) {
$relationship = $this->serializer->getRelationship($this->data, $name);
if ($relationship) {
$relationshipData = $relationship->getData();
if ($relationshipData instanceof ElementInterface) {
$relationshipData->with($nested)->fields($this->fields);
}
$relationships[$name] = $relationship;
}
}
return $this->relationships = $relationships;
}
|
php
|
protected function buildRelationships()
{
if (isset($this->relationships)) {
return $this->relationships;
}
$paths = Util::parseRelationshipPaths($this->includes);
$relationships = [];
foreach ($paths as $name => $nested) {
$relationship = $this->serializer->getRelationship($this->data, $name);
if ($relationship) {
$relationshipData = $relationship->getData();
if ($relationshipData instanceof ElementInterface) {
$relationshipData->with($nested)->fields($this->fields);
}
$relationships[$name] = $relationship;
}
}
return $this->relationships = $relationships;
}
|
[
"protected",
"function",
"buildRelationships",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"relationships",
")",
")",
"{",
"return",
"$",
"this",
"->",
"relationships",
";",
"}",
"$",
"paths",
"=",
"Util",
"::",
"parseRelationshipPaths",
"(",
"$",
"this",
"->",
"includes",
")",
";",
"$",
"relationships",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"paths",
"as",
"$",
"name",
"=>",
"$",
"nested",
")",
"{",
"$",
"relationship",
"=",
"$",
"this",
"->",
"serializer",
"->",
"getRelationship",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"name",
")",
";",
"if",
"(",
"$",
"relationship",
")",
"{",
"$",
"relationshipData",
"=",
"$",
"relationship",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"$",
"relationshipData",
"instanceof",
"ElementInterface",
")",
"{",
"$",
"relationshipData",
"->",
"with",
"(",
"$",
"nested",
")",
"->",
"fields",
"(",
"$",
"this",
"->",
"fields",
")",
";",
"}",
"$",
"relationships",
"[",
"$",
"name",
"]",
"=",
"$",
"relationship",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"relationships",
"=",
"$",
"relationships",
";",
"}"
] |
Get an array of built relationships.
@return \Tobscure\JsonApi\Relationship[]
|
[
"Get",
"an",
"array",
"of",
"built",
"relationships",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Resource.php#L280-L304
|
train
|
tobscure/json-api
|
src/Resource.php
|
Resource.mergeRelationships
|
protected function mergeRelationships(array $relationships)
{
foreach ($this->merged as $resource) {
$relationships = array_replace_recursive($relationships, $resource->getRelationshipsAsArray());
}
return $relationships;
}
|
php
|
protected function mergeRelationships(array $relationships)
{
foreach ($this->merged as $resource) {
$relationships = array_replace_recursive($relationships, $resource->getRelationshipsAsArray());
}
return $relationships;
}
|
[
"protected",
"function",
"mergeRelationships",
"(",
"array",
"$",
"relationships",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"merged",
"as",
"$",
"resource",
")",
"{",
"$",
"relationships",
"=",
"array_replace_recursive",
"(",
"$",
"relationships",
",",
"$",
"resource",
"->",
"getRelationshipsAsArray",
"(",
")",
")",
";",
"}",
"return",
"$",
"relationships",
";",
"}"
] |
Merge the relationships of merged resources into an array of
relationships.
@param array $relationships
@return array
|
[
"Merge",
"the",
"relationships",
"of",
"merged",
"resources",
"into",
"an",
"array",
"of",
"relationships",
"."
] |
355b213927a1412ede81b67ac2a5605753382379
|
https://github.com/tobscure/json-api/blob/355b213927a1412ede81b67ac2a5605753382379/src/Resource.php#L314-L321
|
train
|
heureka/overeno-zakazniky
|
src/ShopCertification.php
|
ShopCertification.logOrder
|
public function logOrder()
{
if ($this->orderSent) {
throw new ShopCertification\Exception('You already sent one order. Please check your implementation.');
}
if (!$this->email) {
throw new ShopCertification\MissingInformationException("Customer email address isn't set and is mandatory.");
}
$postData['apiKey'] = $this->apiKey;
$postData['email'] = $this->email;
if ($this->orderId) {
$postData['orderId'] = $this->orderId;
}
if ($this->productItemIds) {
$postData['productItemIds'] = $this->productItemIds;
}
$result = $this->requester->request(IRequester::ACTION_LOG_ORDER, [], $postData);
$this->orderSent = true;
return $result;
}
|
php
|
public function logOrder()
{
if ($this->orderSent) {
throw new ShopCertification\Exception('You already sent one order. Please check your implementation.');
}
if (!$this->email) {
throw new ShopCertification\MissingInformationException("Customer email address isn't set and is mandatory.");
}
$postData['apiKey'] = $this->apiKey;
$postData['email'] = $this->email;
if ($this->orderId) {
$postData['orderId'] = $this->orderId;
}
if ($this->productItemIds) {
$postData['productItemIds'] = $this->productItemIds;
}
$result = $this->requester->request(IRequester::ACTION_LOG_ORDER, [], $postData);
$this->orderSent = true;
return $result;
}
|
[
"public",
"function",
"logOrder",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"orderSent",
")",
"{",
"throw",
"new",
"ShopCertification",
"\\",
"Exception",
"(",
"'You already sent one order. Please check your implementation.'",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"email",
")",
"{",
"throw",
"new",
"ShopCertification",
"\\",
"MissingInformationException",
"(",
"\"Customer email address isn't set and is mandatory.\"",
")",
";",
"}",
"$",
"postData",
"[",
"'apiKey'",
"]",
"=",
"$",
"this",
"->",
"apiKey",
";",
"$",
"postData",
"[",
"'email'",
"]",
"=",
"$",
"this",
"->",
"email",
";",
"if",
"(",
"$",
"this",
"->",
"orderId",
")",
"{",
"$",
"postData",
"[",
"'orderId'",
"]",
"=",
"$",
"this",
"->",
"orderId",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"productItemIds",
")",
"{",
"$",
"postData",
"[",
"'productItemIds'",
"]",
"=",
"$",
"this",
"->",
"productItemIds",
";",
"}",
"$",
"result",
"=",
"$",
"this",
"->",
"requester",
"->",
"request",
"(",
"IRequester",
"::",
"ACTION_LOG_ORDER",
",",
"[",
"]",
",",
"$",
"postData",
")",
";",
"$",
"this",
"->",
"orderSent",
"=",
"true",
";",
"return",
"$",
"result",
";",
"}"
] |
Sends the data you set to the Heureka ShopCertification service.
@return Response
@throws ShopCertification\Exception
|
[
"Sends",
"the",
"data",
"you",
"set",
"to",
"the",
"Heureka",
"ShopCertification",
"service",
"."
] |
c4f551dde7605eac45bc7e872a10156c4d4b0f85
|
https://github.com/heureka/overeno-zakazniky/blob/c4f551dde7605eac45bc7e872a10156c4d4b0f85/src/ShopCertification.php#L146-L172
|
train
|
fedemotta/yii2-widget-datatables
|
DataTables.php
|
DataTables.init
|
public function init()
{
parent::init();
//disable filter model by grid view
$this->filterModel = null;
//disable sort by grid view
$this->dataProvider->sort = false;
//disable pagination by grid view
$this->dataProvider->pagination = false;
//layout showing only items
$this->layout = "{items}";
//the table id must be set
if (!isset($this->tableOptions['id'])) {
$this->tableOptions['id'] = 'datatables_'.$this->getId();
}
}
|
php
|
public function init()
{
parent::init();
//disable filter model by grid view
$this->filterModel = null;
//disable sort by grid view
$this->dataProvider->sort = false;
//disable pagination by grid view
$this->dataProvider->pagination = false;
//layout showing only items
$this->layout = "{items}";
//the table id must be set
if (!isset($this->tableOptions['id'])) {
$this->tableOptions['id'] = 'datatables_'.$this->getId();
}
}
|
[
"public",
"function",
"init",
"(",
")",
"{",
"parent",
"::",
"init",
"(",
")",
";",
"//disable filter model by grid view",
"$",
"this",
"->",
"filterModel",
"=",
"null",
";",
"//disable sort by grid view",
"$",
"this",
"->",
"dataProvider",
"->",
"sort",
"=",
"false",
";",
"//disable pagination by grid view",
"$",
"this",
"->",
"dataProvider",
"->",
"pagination",
"=",
"false",
";",
"//layout showing only items",
"$",
"this",
"->",
"layout",
"=",
"\"{items}\"",
";",
"//the table id must be set",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"tableOptions",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"tableOptions",
"[",
"'id'",
"]",
"=",
"'datatables_'",
".",
"$",
"this",
"->",
"getId",
"(",
")",
";",
"}",
"}"
] |
Initializes the datatables widget disabling some GridView options like
search, sort and pagination and using DataTables JS functionalities
instead.
|
[
"Initializes",
"the",
"datatables",
"widget",
"disabling",
"some",
"GridView",
"options",
"like",
"search",
"sort",
"and",
"pagination",
"and",
"using",
"DataTables",
"JS",
"functionalities",
"instead",
"."
] |
0fc4fe00f336e5060d959bebef3b44a52bb7097b
|
https://github.com/fedemotta/yii2-widget-datatables/blob/0fc4fe00f336e5060d959bebef3b44a52bb7097b/DataTables.php#L81-L101
|
train
|
webmozart/json
|
src/JsonDecoder.php
|
JsonDecoder.decode
|
public function decode($json, $schema = null)
{
if (self::ASSOC_ARRAY === $this->objectDecoding && null !== $schema) {
throw new \InvalidArgumentException(
'Schema validation is not supported when objects are decoded '.
'as associative arrays. Call '.
'JsonDecoder::setObjectDecoding(JsonDecoder::JSON_OBJECT) to fix.'
);
}
$decoded = $this->decodeJson($json);
if (null !== $schema) {
$errors = $this->validator->validate($decoded, $schema);
if (count($errors) > 0) {
throw ValidationFailedException::fromErrors($errors);
}
}
return $decoded;
}
|
php
|
public function decode($json, $schema = null)
{
if (self::ASSOC_ARRAY === $this->objectDecoding && null !== $schema) {
throw new \InvalidArgumentException(
'Schema validation is not supported when objects are decoded '.
'as associative arrays. Call '.
'JsonDecoder::setObjectDecoding(JsonDecoder::JSON_OBJECT) to fix.'
);
}
$decoded = $this->decodeJson($json);
if (null !== $schema) {
$errors = $this->validator->validate($decoded, $schema);
if (count($errors) > 0) {
throw ValidationFailedException::fromErrors($errors);
}
}
return $decoded;
}
|
[
"public",
"function",
"decode",
"(",
"$",
"json",
",",
"$",
"schema",
"=",
"null",
")",
"{",
"if",
"(",
"self",
"::",
"ASSOC_ARRAY",
"===",
"$",
"this",
"->",
"objectDecoding",
"&&",
"null",
"!==",
"$",
"schema",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Schema validation is not supported when objects are decoded '",
".",
"'as associative arrays. Call '",
".",
"'JsonDecoder::setObjectDecoding(JsonDecoder::JSON_OBJECT) to fix.'",
")",
";",
"}",
"$",
"decoded",
"=",
"$",
"this",
"->",
"decodeJson",
"(",
"$",
"json",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"schema",
")",
"{",
"$",
"errors",
"=",
"$",
"this",
"->",
"validator",
"->",
"validate",
"(",
"$",
"decoded",
",",
"$",
"schema",
")",
";",
"if",
"(",
"count",
"(",
"$",
"errors",
")",
">",
"0",
")",
"{",
"throw",
"ValidationFailedException",
"::",
"fromErrors",
"(",
"$",
"errors",
")",
";",
"}",
"}",
"return",
"$",
"decoded",
";",
"}"
] |
Decodes and validates a JSON string.
If a schema is passed, the decoded object is validated against that
schema. The schema may be passed as file path or as object returned from
`JsonDecoder::decodeFile($schemaFile)`.
You can adjust the decoding with {@link setObjectDecoding()},
{@link setBigIntDecoding()} and {@link setMaxDepth()}.
Schema validation is not supported when objects are decoded as
associative arrays.
@param string $json The JSON string
@param string|object $schema The schema file or object
@return mixed The decoded value
@throws DecodingFailedException If the JSON string could not be decoded
@throws ValidationFailedException If the decoded string fails schema
validation
@throws InvalidSchemaException If the schema is invalid
|
[
"Decodes",
"and",
"validates",
"a",
"JSON",
"string",
"."
] |
d823428254474fc26aa499aebbda1315e2fedf3a
|
https://github.com/webmozart/json/blob/d823428254474fc26aa499aebbda1315e2fedf3a/src/JsonDecoder.php#L99-L120
|
train
|
webmozart/json
|
src/JsonDecoder.php
|
JsonDecoder.decodeFile
|
public function decodeFile($path, $schema = null)
{
if (!file_exists($path)) {
throw new FileNotFoundException(sprintf(
'The file %s does not exist.',
$path
));
}
$errorMessage = null;
$errorCode = 0;
set_error_handler(function ($errno, $errstr) use (&$errorMessage, &$errorCode) {
$errorMessage = $errstr;
$errorCode = $errno;
});
$content = file_get_contents($path);
restore_error_handler();
if (null !== $errorMessage) {
if (false !== $pos = strpos($errorMessage, '): ')) {
// cut "file_get_contents(%path%):" to make message more readable
$errorMessage = substr($errorMessage, $pos + 3);
}
throw new IOException(sprintf(
'Could not read %s: %s (%s)',
$path,
$errorMessage,
$errorCode
), $errorCode);
}
try {
return $this->decode($content, $schema);
} catch (DecodingFailedException $e) {
// Add the file name to the exception
throw new DecodingFailedException(sprintf(
'An error happened while decoding %s: %s',
$path,
$e->getMessage()
), $e->getCode(), $e);
} catch (ValidationFailedException $e) {
// Add the file name to the exception
throw new ValidationFailedException(sprintf(
"Validation of %s failed:\n%s",
$path,
$e->getErrorsAsString()
), $e->getErrors(), $e->getCode(), $e);
} catch (InvalidSchemaException $e) {
// Add the file name to the exception
throw new InvalidSchemaException(sprintf(
'An error happened while decoding %s: %s',
$path,
$e->getMessage()
), $e->getCode(), $e);
}
}
|
php
|
public function decodeFile($path, $schema = null)
{
if (!file_exists($path)) {
throw new FileNotFoundException(sprintf(
'The file %s does not exist.',
$path
));
}
$errorMessage = null;
$errorCode = 0;
set_error_handler(function ($errno, $errstr) use (&$errorMessage, &$errorCode) {
$errorMessage = $errstr;
$errorCode = $errno;
});
$content = file_get_contents($path);
restore_error_handler();
if (null !== $errorMessage) {
if (false !== $pos = strpos($errorMessage, '): ')) {
// cut "file_get_contents(%path%):" to make message more readable
$errorMessage = substr($errorMessage, $pos + 3);
}
throw new IOException(sprintf(
'Could not read %s: %s (%s)',
$path,
$errorMessage,
$errorCode
), $errorCode);
}
try {
return $this->decode($content, $schema);
} catch (DecodingFailedException $e) {
// Add the file name to the exception
throw new DecodingFailedException(sprintf(
'An error happened while decoding %s: %s',
$path,
$e->getMessage()
), $e->getCode(), $e);
} catch (ValidationFailedException $e) {
// Add the file name to the exception
throw new ValidationFailedException(sprintf(
"Validation of %s failed:\n%s",
$path,
$e->getErrorsAsString()
), $e->getErrors(), $e->getCode(), $e);
} catch (InvalidSchemaException $e) {
// Add the file name to the exception
throw new InvalidSchemaException(sprintf(
'An error happened while decoding %s: %s',
$path,
$e->getMessage()
), $e->getCode(), $e);
}
}
|
[
"public",
"function",
"decodeFile",
"(",
"$",
"path",
",",
"$",
"schema",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"FileNotFoundException",
"(",
"sprintf",
"(",
"'The file %s does not exist.'",
",",
"$",
"path",
")",
")",
";",
"}",
"$",
"errorMessage",
"=",
"null",
";",
"$",
"errorCode",
"=",
"0",
";",
"set_error_handler",
"(",
"function",
"(",
"$",
"errno",
",",
"$",
"errstr",
")",
"use",
"(",
"&",
"$",
"errorMessage",
",",
"&",
"$",
"errorCode",
")",
"{",
"$",
"errorMessage",
"=",
"$",
"errstr",
";",
"$",
"errorCode",
"=",
"$",
"errno",
";",
"}",
")",
";",
"$",
"content",
"=",
"file_get_contents",
"(",
"$",
"path",
")",
";",
"restore_error_handler",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"errorMessage",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"errorMessage",
",",
"'): '",
")",
")",
"{",
"// cut \"file_get_contents(%path%):\" to make message more readable",
"$",
"errorMessage",
"=",
"substr",
"(",
"$",
"errorMessage",
",",
"$",
"pos",
"+",
"3",
")",
";",
"}",
"throw",
"new",
"IOException",
"(",
"sprintf",
"(",
"'Could not read %s: %s (%s)'",
",",
"$",
"path",
",",
"$",
"errorMessage",
",",
"$",
"errorCode",
")",
",",
"$",
"errorCode",
")",
";",
"}",
"try",
"{",
"return",
"$",
"this",
"->",
"decode",
"(",
"$",
"content",
",",
"$",
"schema",
")",
";",
"}",
"catch",
"(",
"DecodingFailedException",
"$",
"e",
")",
"{",
"// Add the file name to the exception",
"throw",
"new",
"DecodingFailedException",
"(",
"sprintf",
"(",
"'An error happened while decoding %s: %s'",
",",
"$",
"path",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"ValidationFailedException",
"$",
"e",
")",
"{",
"// Add the file name to the exception",
"throw",
"new",
"ValidationFailedException",
"(",
"sprintf",
"(",
"\"Validation of %s failed:\\n%s\"",
",",
"$",
"path",
",",
"$",
"e",
"->",
"getErrorsAsString",
"(",
")",
")",
",",
"$",
"e",
"->",
"getErrors",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"catch",
"(",
"InvalidSchemaException",
"$",
"e",
")",
"{",
"// Add the file name to the exception",
"throw",
"new",
"InvalidSchemaException",
"(",
"sprintf",
"(",
"'An error happened while decoding %s: %s'",
",",
"$",
"path",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"}"
] |
Decodes and validates a JSON file.
@param string $path The path to the JSON file
@param string|object $schema The schema file or object
@return mixed The decoded file
@throws FileNotFoundException If the file was not found
@throws DecodingFailedException If the file could not be decoded
@throws ValidationFailedException If the decoded file fails schema
validation
@throws InvalidSchemaException If the schema is invalid
@see decode
|
[
"Decodes",
"and",
"validates",
"a",
"JSON",
"file",
"."
] |
d823428254474fc26aa499aebbda1315e2fedf3a
|
https://github.com/webmozart/json/blob/d823428254474fc26aa499aebbda1315e2fedf3a/src/JsonDecoder.php#L138-L197
|
train
|
webmozart/json
|
src/JsonDecoder.php
|
JsonDecoder.setMaxDepth
|
public function setMaxDepth($maxDepth)
{
if (!is_int($maxDepth)) {
throw new \InvalidArgumentException(sprintf(
'The maximum depth should be an integer. Got: %s',
is_object($maxDepth) ? get_class($maxDepth) : gettype($maxDepth)
));
}
if ($maxDepth < 1) {
throw new \InvalidArgumentException(sprintf(
'The maximum depth should 1 or greater. Got: %s',
$maxDepth
));
}
$this->maxDepth = $maxDepth;
}
|
php
|
public function setMaxDepth($maxDepth)
{
if (!is_int($maxDepth)) {
throw new \InvalidArgumentException(sprintf(
'The maximum depth should be an integer. Got: %s',
is_object($maxDepth) ? get_class($maxDepth) : gettype($maxDepth)
));
}
if ($maxDepth < 1) {
throw new \InvalidArgumentException(sprintf(
'The maximum depth should 1 or greater. Got: %s',
$maxDepth
));
}
$this->maxDepth = $maxDepth;
}
|
[
"public",
"function",
"setMaxDepth",
"(",
"$",
"maxDepth",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"maxDepth",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The maximum depth should be an integer. Got: %s'",
",",
"is_object",
"(",
"$",
"maxDepth",
")",
"?",
"get_class",
"(",
"$",
"maxDepth",
")",
":",
"gettype",
"(",
"$",
"maxDepth",
")",
")",
")",
";",
"}",
"if",
"(",
"$",
"maxDepth",
"<",
"1",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The maximum depth should 1 or greater. Got: %s'",
",",
"$",
"maxDepth",
")",
")",
";",
"}",
"$",
"this",
"->",
"maxDepth",
"=",
"$",
"maxDepth",
";",
"}"
] |
Sets the maximum recursion depth.
If the depth is exceeded during decoding, an {@link DecodingnFailedException}
will be thrown.
A depth of zero means that objects are not allowed. A depth of one means
only one level of objects or arrays is allowed.
@param int $maxDepth The maximum recursion depth
@throws \InvalidArgumentException If the depth is not an integer greater
than or equal to zero
|
[
"Sets",
"the",
"maximum",
"recursion",
"depth",
"."
] |
d823428254474fc26aa499aebbda1315e2fedf3a
|
https://github.com/webmozart/json/blob/d823428254474fc26aa499aebbda1315e2fedf3a/src/JsonDecoder.php#L226-L243
|
train
|
webmozart/json
|
src/JsonDecoder.php
|
JsonDecoder.setObjectDecoding
|
public function setObjectDecoding($decoding)
{
if (self::OBJECT !== $decoding && self::ASSOC_ARRAY !== $decoding) {
throw new \InvalidArgumentException(sprintf(
'Expected JsonDecoder::JSON_OBJECT or JsonDecoder::ASSOC_ARRAY. '.
'Got: %s',
$decoding
));
}
$this->objectDecoding = $decoding;
}
|
php
|
public function setObjectDecoding($decoding)
{
if (self::OBJECT !== $decoding && self::ASSOC_ARRAY !== $decoding) {
throw new \InvalidArgumentException(sprintf(
'Expected JsonDecoder::JSON_OBJECT or JsonDecoder::ASSOC_ARRAY. '.
'Got: %s',
$decoding
));
}
$this->objectDecoding = $decoding;
}
|
[
"public",
"function",
"setObjectDecoding",
"(",
"$",
"decoding",
")",
"{",
"if",
"(",
"self",
"::",
"OBJECT",
"!==",
"$",
"decoding",
"&&",
"self",
"::",
"ASSOC_ARRAY",
"!==",
"$",
"decoding",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Expected JsonDecoder::JSON_OBJECT or JsonDecoder::ASSOC_ARRAY. '",
".",
"'Got: %s'",
",",
"$",
"decoding",
")",
")",
";",
"}",
"$",
"this",
"->",
"objectDecoding",
"=",
"$",
"decoding",
";",
"}"
] |
Sets the decoding of JSON objects.
By default, JSON objects are decoded as instances of {@link \stdClass}.
@param int $decoding One of the constants {@link JSON_OBJECT} and {@link ASSOC_ARRAY}
@throws \InvalidArgumentException If the passed decoding is invalid
|
[
"Sets",
"the",
"decoding",
"of",
"JSON",
"objects",
"."
] |
d823428254474fc26aa499aebbda1315e2fedf3a
|
https://github.com/webmozart/json/blob/d823428254474fc26aa499aebbda1315e2fedf3a/src/JsonDecoder.php#L264-L275
|
train
|
webmozart/json
|
src/JsonDecoder.php
|
JsonDecoder.setBigIntDecoding
|
public function setBigIntDecoding($decoding)
{
if (self::FLOAT !== $decoding && self::STRING !== $decoding) {
throw new \InvalidArgumentException(sprintf(
'Expected JsonDecoder::FLOAT or JsonDecoder::JSON_STRING. '.
'Got: %s',
$decoding
));
}
$this->bigIntDecoding = $decoding;
}
|
php
|
public function setBigIntDecoding($decoding)
{
if (self::FLOAT !== $decoding && self::STRING !== $decoding) {
throw new \InvalidArgumentException(sprintf(
'Expected JsonDecoder::FLOAT or JsonDecoder::JSON_STRING. '.
'Got: %s',
$decoding
));
}
$this->bigIntDecoding = $decoding;
}
|
[
"public",
"function",
"setBigIntDecoding",
"(",
"$",
"decoding",
")",
"{",
"if",
"(",
"self",
"::",
"FLOAT",
"!==",
"$",
"decoding",
"&&",
"self",
"::",
"STRING",
"!==",
"$",
"decoding",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Expected JsonDecoder::FLOAT or JsonDecoder::JSON_STRING. '",
".",
"'Got: %s'",
",",
"$",
"decoding",
")",
")",
";",
"}",
"$",
"this",
"->",
"bigIntDecoding",
"=",
"$",
"decoding",
";",
"}"
] |
Sets the decoding of big integers.
By default, big integers are decoded as floats.
@param int $decoding One of the constants {@link FLOAT} and {@link JSON_STRING}
@throws \InvalidArgumentException If the passed decoding is invalid
|
[
"Sets",
"the",
"decoding",
"of",
"big",
"integers",
"."
] |
d823428254474fc26aa499aebbda1315e2fedf3a
|
https://github.com/webmozart/json/blob/d823428254474fc26aa499aebbda1315e2fedf3a/src/JsonDecoder.php#L296-L307
|
train
|
webmozart/json
|
src/JsonValidator.php
|
JsonValidator.validate
|
public function validate($data, $schema = null)
{
if (null === $schema && isset($data->{'$schema'})) {
$schema = $data->{'$schema'};
}
if (is_string($schema)) {
$schema = $this->loadSchema($schema);
} elseif (is_object($schema)) {
$this->assertSchemaValid($schema);
} else {
throw new InvalidSchemaException(sprintf(
'The schema must be given as string, object or in the "$schema" '.
'property of the JSON data. Got: %s',
is_object($schema) ? get_class($schema) : gettype($schema)
));
}
$this->validator->reset();
try {
$this->validator->check($data, $schema);
} catch (InvalidArgumentException $e) {
throw new InvalidSchemaException(sprintf(
'The schema is invalid: %s',
$e->getMessage()
), 0, $e);
}
$errors = array();
if (!$this->validator->isValid()) {
$errors = (array) $this->validator->getErrors();
foreach ($errors as $key => $error) {
$prefix = $error['property'] ? $error['property'].': ' : '';
$errors[$key] = $prefix.$error['message'];
}
}
return $errors;
}
|
php
|
public function validate($data, $schema = null)
{
if (null === $schema && isset($data->{'$schema'})) {
$schema = $data->{'$schema'};
}
if (is_string($schema)) {
$schema = $this->loadSchema($schema);
} elseif (is_object($schema)) {
$this->assertSchemaValid($schema);
} else {
throw new InvalidSchemaException(sprintf(
'The schema must be given as string, object or in the "$schema" '.
'property of the JSON data. Got: %s',
is_object($schema) ? get_class($schema) : gettype($schema)
));
}
$this->validator->reset();
try {
$this->validator->check($data, $schema);
} catch (InvalidArgumentException $e) {
throw new InvalidSchemaException(sprintf(
'The schema is invalid: %s',
$e->getMessage()
), 0, $e);
}
$errors = array();
if (!$this->validator->isValid()) {
$errors = (array) $this->validator->getErrors();
foreach ($errors as $key => $error) {
$prefix = $error['property'] ? $error['property'].': ' : '';
$errors[$key] = $prefix.$error['message'];
}
}
return $errors;
}
|
[
"public",
"function",
"validate",
"(",
"$",
"data",
",",
"$",
"schema",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"schema",
"&&",
"isset",
"(",
"$",
"data",
"->",
"{",
"'$schema'",
"}",
")",
")",
"{",
"$",
"schema",
"=",
"$",
"data",
"->",
"{",
"'$schema'",
"}",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"schema",
")",
")",
"{",
"$",
"schema",
"=",
"$",
"this",
"->",
"loadSchema",
"(",
"$",
"schema",
")",
";",
"}",
"elseif",
"(",
"is_object",
"(",
"$",
"schema",
")",
")",
"{",
"$",
"this",
"->",
"assertSchemaValid",
"(",
"$",
"schema",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidSchemaException",
"(",
"sprintf",
"(",
"'The schema must be given as string, object or in the \"$schema\" '",
".",
"'property of the JSON data. Got: %s'",
",",
"is_object",
"(",
"$",
"schema",
")",
"?",
"get_class",
"(",
"$",
"schema",
")",
":",
"gettype",
"(",
"$",
"schema",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"validator",
"->",
"reset",
"(",
")",
";",
"try",
"{",
"$",
"this",
"->",
"validator",
"->",
"check",
"(",
"$",
"data",
",",
"$",
"schema",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"throw",
"new",
"InvalidSchemaException",
"(",
"sprintf",
"(",
"'The schema is invalid: %s'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
",",
"0",
",",
"$",
"e",
")",
";",
"}",
"$",
"errors",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"validator",
"->",
"isValid",
"(",
")",
")",
"{",
"$",
"errors",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"validator",
"->",
"getErrors",
"(",
")",
";",
"foreach",
"(",
"$",
"errors",
"as",
"$",
"key",
"=>",
"$",
"error",
")",
"{",
"$",
"prefix",
"=",
"$",
"error",
"[",
"'property'",
"]",
"?",
"$",
"error",
"[",
"'property'",
"]",
".",
"': '",
":",
"''",
";",
"$",
"errors",
"[",
"$",
"key",
"]",
"=",
"$",
"prefix",
".",
"$",
"error",
"[",
"'message'",
"]",
";",
"}",
"}",
"return",
"$",
"errors",
";",
"}"
] |
Validates JSON data against a schema.
The schema may be passed as file path or as object returned from
`json_decode($schemaFile)`.
@param mixed $data The decoded JSON data
@param string|object|null $schema The schema file or object. If `null`,
the validator will look for a `$schema`
property
@return string[] The errors found during validation. Returns an empty
array if no errors were found
@throws InvalidSchemaException If the schema is invalid
|
[
"Validates",
"JSON",
"data",
"against",
"a",
"schema",
"."
] |
d823428254474fc26aa499aebbda1315e2fedf3a
|
https://github.com/webmozart/json/blob/d823428254474fc26aa499aebbda1315e2fedf3a/src/JsonValidator.php#L88-L129
|
train
|
webmozart/json
|
src/JsonError.php
|
JsonError.getErrorMessage
|
public static function getErrorMessage($error)
{
switch ($error) {
case JSON_ERROR_NONE:
return 'JSON_ERROR_NONE';
case JSON_ERROR_DEPTH:
return 'JSON_ERROR_DEPTH';
case JSON_ERROR_STATE_MISMATCH:
return 'JSON_ERROR_STATE_MISMATCH';
case JSON_ERROR_CTRL_CHAR:
return 'JSON_ERROR_CTRL_CHAR';
case JSON_ERROR_SYNTAX:
return 'JSON_ERROR_SYNTAX';
case JSON_ERROR_UTF8:
return 'JSON_ERROR_UTF8';
}
if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
switch ($error) {
case JSON_ERROR_RECURSION:
return 'JSON_ERROR_RECURSION';
case JSON_ERROR_INF_OR_NAN:
return 'JSON_ERROR_INF_OR_NAN';
case JSON_ERROR_UNSUPPORTED_TYPE:
return 'JSON_ERROR_UNSUPPORTED_TYPE';
}
}
return 'JSON_ERROR_UNKNOWN';
}
|
php
|
public static function getErrorMessage($error)
{
switch ($error) {
case JSON_ERROR_NONE:
return 'JSON_ERROR_NONE';
case JSON_ERROR_DEPTH:
return 'JSON_ERROR_DEPTH';
case JSON_ERROR_STATE_MISMATCH:
return 'JSON_ERROR_STATE_MISMATCH';
case JSON_ERROR_CTRL_CHAR:
return 'JSON_ERROR_CTRL_CHAR';
case JSON_ERROR_SYNTAX:
return 'JSON_ERROR_SYNTAX';
case JSON_ERROR_UTF8:
return 'JSON_ERROR_UTF8';
}
if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
switch ($error) {
case JSON_ERROR_RECURSION:
return 'JSON_ERROR_RECURSION';
case JSON_ERROR_INF_OR_NAN:
return 'JSON_ERROR_INF_OR_NAN';
case JSON_ERROR_UNSUPPORTED_TYPE:
return 'JSON_ERROR_UNSUPPORTED_TYPE';
}
}
return 'JSON_ERROR_UNKNOWN';
}
|
[
"public",
"static",
"function",
"getErrorMessage",
"(",
"$",
"error",
")",
"{",
"switch",
"(",
"$",
"error",
")",
"{",
"case",
"JSON_ERROR_NONE",
":",
"return",
"'JSON_ERROR_NONE'",
";",
"case",
"JSON_ERROR_DEPTH",
":",
"return",
"'JSON_ERROR_DEPTH'",
";",
"case",
"JSON_ERROR_STATE_MISMATCH",
":",
"return",
"'JSON_ERROR_STATE_MISMATCH'",
";",
"case",
"JSON_ERROR_CTRL_CHAR",
":",
"return",
"'JSON_ERROR_CTRL_CHAR'",
";",
"case",
"JSON_ERROR_SYNTAX",
":",
"return",
"'JSON_ERROR_SYNTAX'",
";",
"case",
"JSON_ERROR_UTF8",
":",
"return",
"'JSON_ERROR_UTF8'",
";",
"}",
"if",
"(",
"version_compare",
"(",
"PHP_VERSION",
",",
"'5.5.0'",
",",
"'>='",
")",
")",
"{",
"switch",
"(",
"$",
"error",
")",
"{",
"case",
"JSON_ERROR_RECURSION",
":",
"return",
"'JSON_ERROR_RECURSION'",
";",
"case",
"JSON_ERROR_INF_OR_NAN",
":",
"return",
"'JSON_ERROR_INF_OR_NAN'",
";",
"case",
"JSON_ERROR_UNSUPPORTED_TYPE",
":",
"return",
"'JSON_ERROR_UNSUPPORTED_TYPE'",
";",
"}",
"}",
"return",
"'JSON_ERROR_UNKNOWN'",
";",
"}"
] |
Returns the error message of a JSON error code.
@param int $error The error code
@return string The error message
|
[
"Returns",
"the",
"error",
"message",
"of",
"a",
"JSON",
"error",
"code",
"."
] |
d823428254474fc26aa499aebbda1315e2fedf3a
|
https://github.com/webmozart/json/blob/d823428254474fc26aa499aebbda1315e2fedf3a/src/JsonError.php#L38-L67
|
train
|
webmozart/json
|
src/Migration/MigrationManager.php
|
MigrationManager.migrate
|
public function migrate(stdClass $data, $targetVersion)
{
$sourceVersion = $this->versioner->parseVersion($data);
if (version_compare($targetVersion, $sourceVersion, '>')) {
$this->up($data, $sourceVersion, $targetVersion);
} elseif (version_compare($targetVersion, $sourceVersion, '<')) {
$this->down($data, $sourceVersion, $targetVersion);
}
}
|
php
|
public function migrate(stdClass $data, $targetVersion)
{
$sourceVersion = $this->versioner->parseVersion($data);
if (version_compare($targetVersion, $sourceVersion, '>')) {
$this->up($data, $sourceVersion, $targetVersion);
} elseif (version_compare($targetVersion, $sourceVersion, '<')) {
$this->down($data, $sourceVersion, $targetVersion);
}
}
|
[
"public",
"function",
"migrate",
"(",
"stdClass",
"$",
"data",
",",
"$",
"targetVersion",
")",
"{",
"$",
"sourceVersion",
"=",
"$",
"this",
"->",
"versioner",
"->",
"parseVersion",
"(",
"$",
"data",
")",
";",
"if",
"(",
"version_compare",
"(",
"$",
"targetVersion",
",",
"$",
"sourceVersion",
",",
"'>'",
")",
")",
"{",
"$",
"this",
"->",
"up",
"(",
"$",
"data",
",",
"$",
"sourceVersion",
",",
"$",
"targetVersion",
")",
";",
"}",
"elseif",
"(",
"version_compare",
"(",
"$",
"targetVersion",
",",
"$",
"sourceVersion",
",",
"'<'",
")",
")",
"{",
"$",
"this",
"->",
"down",
"(",
"$",
"data",
",",
"$",
"sourceVersion",
",",
"$",
"targetVersion",
")",
";",
"}",
"}"
] |
Migrates a JSON object to the given version.
@param stdClass $data The JSON object
@param string $targetVersion The version string
|
[
"Migrates",
"a",
"JSON",
"object",
"to",
"the",
"given",
"version",
"."
] |
d823428254474fc26aa499aebbda1315e2fedf3a
|
https://github.com/webmozart/json/blob/d823428254474fc26aa499aebbda1315e2fedf3a/src/Migration/MigrationManager.php#L83-L92
|
train
|
Art4/json-api-client
|
src/Input/StringInputTrait.php
|
StringInputTrait.decodeJson
|
protected function decodeJson($jsonString)
{
$jsonErrors = [
\JSON_ERROR_DEPTH => 'JSON_ERROR_DEPTH - Maximum stack depth exceeded',
\JSON_ERROR_STATE_MISMATCH => 'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch',
\JSON_ERROR_CTRL_CHAR => 'JSON_ERROR_CTRL_CHAR - Unexpected control character found',
\JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON',
\JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded'
];
// Can we use JSON_BIGINT_AS_STRING?
$options = (version_compare(\PHP_VERSION, '5.4.0', '>=') and ! (defined('JSON_C_VERSION') and \PHP_INT_SIZE > 4)) ? \JSON_BIGINT_AS_STRING : 0;
$data = json_decode($jsonString, false, 512, $options);
if (json_last_error() !== \JSON_ERROR_NONE) {
$last = json_last_error();
$error = 'Unknown error';
if (isset($jsonErrors[$last])) {
$error = $jsonErrors[$last];
}
throw new InputException('Unable to parse JSON data: ' . $error);
}
return $data;
}
|
php
|
protected function decodeJson($jsonString)
{
$jsonErrors = [
\JSON_ERROR_DEPTH => 'JSON_ERROR_DEPTH - Maximum stack depth exceeded',
\JSON_ERROR_STATE_MISMATCH => 'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch',
\JSON_ERROR_CTRL_CHAR => 'JSON_ERROR_CTRL_CHAR - Unexpected control character found',
\JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON',
\JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded'
];
// Can we use JSON_BIGINT_AS_STRING?
$options = (version_compare(\PHP_VERSION, '5.4.0', '>=') and ! (defined('JSON_C_VERSION') and \PHP_INT_SIZE > 4)) ? \JSON_BIGINT_AS_STRING : 0;
$data = json_decode($jsonString, false, 512, $options);
if (json_last_error() !== \JSON_ERROR_NONE) {
$last = json_last_error();
$error = 'Unknown error';
if (isset($jsonErrors[$last])) {
$error = $jsonErrors[$last];
}
throw new InputException('Unable to parse JSON data: ' . $error);
}
return $data;
}
|
[
"protected",
"function",
"decodeJson",
"(",
"$",
"jsonString",
")",
"{",
"$",
"jsonErrors",
"=",
"[",
"\\",
"JSON_ERROR_DEPTH",
"=>",
"'JSON_ERROR_DEPTH - Maximum stack depth exceeded'",
",",
"\\",
"JSON_ERROR_STATE_MISMATCH",
"=>",
"'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch'",
",",
"\\",
"JSON_ERROR_CTRL_CHAR",
"=>",
"'JSON_ERROR_CTRL_CHAR - Unexpected control character found'",
",",
"\\",
"JSON_ERROR_SYNTAX",
"=>",
"'JSON_ERROR_SYNTAX - Syntax error, malformed JSON'",
",",
"\\",
"JSON_ERROR_UTF8",
"=>",
"'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded'",
"]",
";",
"// Can we use JSON_BIGINT_AS_STRING?",
"$",
"options",
"=",
"(",
"version_compare",
"(",
"\\",
"PHP_VERSION",
",",
"'5.4.0'",
",",
"'>='",
")",
"and",
"!",
"(",
"defined",
"(",
"'JSON_C_VERSION'",
")",
"and",
"\\",
"PHP_INT_SIZE",
">",
"4",
")",
")",
"?",
"\\",
"JSON_BIGINT_AS_STRING",
":",
"0",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"jsonString",
",",
"false",
",",
"512",
",",
"$",
"options",
")",
";",
"if",
"(",
"json_last_error",
"(",
")",
"!==",
"\\",
"JSON_ERROR_NONE",
")",
"{",
"$",
"last",
"=",
"json_last_error",
"(",
")",
";",
"$",
"error",
"=",
"'Unknown error'",
";",
"if",
"(",
"isset",
"(",
"$",
"jsonErrors",
"[",
"$",
"last",
"]",
")",
")",
"{",
"$",
"error",
"=",
"$",
"jsonErrors",
"[",
"$",
"last",
"]",
";",
"}",
"throw",
"new",
"InputException",
"(",
"'Unable to parse JSON data: '",
".",
"$",
"error",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] |
Decodes a json string
@param string $jsonString
@throws InputException if somethin went wrong with the input
@return object
|
[
"Decodes",
"a",
"json",
"string"
] |
2e4148f73966fdc815b6406a3779ef3bb046e1a4
|
https://github.com/Art4/json-api-client/blob/2e4148f73966fdc815b6406a3779ef3bb046e1a4/src/Input/StringInputTrait.php#L59-L86
|
train
|
Art4/json-api-client
|
src/Manager/ErrorAbortManager.php
|
ErrorAbortManager.parse
|
public function parse(Input $input)
{
// fill config
$this->config = $this->default;
if ($input instanceof RequestInput) {
$this->config['optional_item_id'] = true;
}
$object = $input->getAsObject();
$document = $this->getFactory()->make(
'Document',
[$object, $this, new RootAccessable]
);
// Clear config
$this->config = [];
return $document;
}
|
php
|
public function parse(Input $input)
{
// fill config
$this->config = $this->default;
if ($input instanceof RequestInput) {
$this->config['optional_item_id'] = true;
}
$object = $input->getAsObject();
$document = $this->getFactory()->make(
'Document',
[$object, $this, new RootAccessable]
);
// Clear config
$this->config = [];
return $document;
}
|
[
"public",
"function",
"parse",
"(",
"Input",
"$",
"input",
")",
"{",
"// fill config",
"$",
"this",
"->",
"config",
"=",
"$",
"this",
"->",
"default",
";",
"if",
"(",
"$",
"input",
"instanceof",
"RequestInput",
")",
"{",
"$",
"this",
"->",
"config",
"[",
"'optional_item_id'",
"]",
"=",
"true",
";",
"}",
"$",
"object",
"=",
"$",
"input",
"->",
"getAsObject",
"(",
")",
";",
"$",
"document",
"=",
"$",
"this",
"->",
"getFactory",
"(",
")",
"->",
"make",
"(",
"'Document'",
",",
"[",
"$",
"object",
",",
"$",
"this",
",",
"new",
"RootAccessable",
"]",
")",
";",
"// Clear config",
"$",
"this",
"->",
"config",
"=",
"[",
"]",
";",
"return",
"$",
"document",
";",
"}"
] |
Parse the input
@param Art4\JsonApiClient\Input\Input $input
@throws Art4\JsonApiClient\Exception\ValidationException If $input contains invalid JSON API
@return \Art4\JsonApiClient\Accessable
|
[
"Parse",
"the",
"input"
] |
2e4148f73966fdc815b6406a3779ef3bb046e1a4
|
https://github.com/Art4/json-api-client/blob/2e4148f73966fdc815b6406a3779ef3bb046e1a4/src/Manager/ErrorAbortManager.php#L64-L84
|
train
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.