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 |
---|---|---|---|---|---|---|---|---|---|---|---|
rokka-io/rokka-client-php | src/LocalImage/RokkaHash.php | RokkaHash.getContent | public function getContent()
{
if (null === $this->templateHelper) {
throw new \RuntimeException('Rokka TemplateHelper is not set in RokkaHash. Needed for downloading images.');
}
if (null === $this->content) {
$rokkaHash = $this->getRokkaHash();
if (null !== $rokkaHash) {
$this->content = $this->templateHelper->getRokkaClient()->getSourceImageContents($rokkaHash);
}
}
return $this->content;
} | php | public function getContent()
{
if (null === $this->templateHelper) {
throw new \RuntimeException('Rokka TemplateHelper is not set in RokkaHash. Needed for downloading images.');
}
if (null === $this->content) {
$rokkaHash = $this->getRokkaHash();
if (null !== $rokkaHash) {
$this->content = $this->templateHelper->getRokkaClient()->getSourceImageContents($rokkaHash);
}
}
return $this->content;
} | [
"public",
"function",
"getContent",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"templateHelper",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Rokka TemplateHelper is not set in RokkaHash. Needed for downloading images.'",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"content",
")",
"{",
"$",
"rokkaHash",
"=",
"$",
"this",
"->",
"getRokkaHash",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"rokkaHash",
")",
"{",
"$",
"this",
"->",
"content",
"=",
"$",
"this",
"->",
"templateHelper",
"->",
"getRokkaClient",
"(",
")",
"->",
"getSourceImageContents",
"(",
"$",
"rokkaHash",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"content",
";",
"}"
]
| Returns the actual content of an image.
@since 1.3.0
@throws \GuzzleHttp\Exception\GuzzleException
@return null|string | [
"Returns",
"the",
"actual",
"content",
"of",
"an",
"image",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/LocalImage/RokkaHash.php#L68-L81 | train |
tsugiproject/tsugi-php | src/Core/Launch.php | Launch.ltiParameterUpdate | public function ltiParameterUpdate($varname, $value) {
$lti = $this->session_get('lti', false);
if ( ! $lti ) $lti = array(); // Should never happen
if ( is_array($lti) ) $lti[$varname] = $value;
$lti = $this->session_put('lti', $lti);
} | php | public function ltiParameterUpdate($varname, $value) {
$lti = $this->session_get('lti', false);
if ( ! $lti ) $lti = array(); // Should never happen
if ( is_array($lti) ) $lti[$varname] = $value;
$lti = $this->session_put('lti', $lti);
} | [
"public",
"function",
"ltiParameterUpdate",
"(",
"$",
"varname",
",",
"$",
"value",
")",
"{",
"$",
"lti",
"=",
"$",
"this",
"->",
"session_get",
"(",
"'lti'",
",",
"false",
")",
";",
"if",
"(",
"!",
"$",
"lti",
")",
"$",
"lti",
"=",
"array",
"(",
")",
";",
"// Should never happen",
"if",
"(",
"is_array",
"(",
"$",
"lti",
")",
")",
"$",
"lti",
"[",
"$",
"varname",
"]",
"=",
"$",
"value",
";",
"$",
"lti",
"=",
"$",
"this",
"->",
"session_put",
"(",
"'lti'",
",",
"$",
"lti",
")",
";",
"}"
]
| Update a keyed variable from the LTI data in the current session with default | [
"Update",
"a",
"keyed",
"variable",
"from",
"the",
"LTI",
"data",
"in",
"the",
"current",
"session",
"with",
"default"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Launch.php#L129-L134 | train |
tsugiproject/tsugi-php | src/Core/Launch.php | Launch.isSakai | public function isSakai() {
$ext_lms = $this->ltiRawParameter('ext_lms', false);
$ext_lms = strtolower($ext_lms);
return strpos($ext_lms, 'sakai') === 0 ;
} | php | public function isSakai() {
$ext_lms = $this->ltiRawParameter('ext_lms', false);
$ext_lms = strtolower($ext_lms);
return strpos($ext_lms, 'sakai') === 0 ;
} | [
"public",
"function",
"isSakai",
"(",
")",
"{",
"$",
"ext_lms",
"=",
"$",
"this",
"->",
"ltiRawParameter",
"(",
"'ext_lms'",
",",
"false",
")",
";",
"$",
"ext_lms",
"=",
"strtolower",
"(",
"$",
"ext_lms",
")",
";",
"return",
"strpos",
"(",
"$",
"ext_lms",
",",
"'sakai'",
")",
"===",
"0",
";",
"}"
]
| Indicate if this launch came from Sakai | [
"Indicate",
"if",
"this",
"launch",
"came",
"from",
"Sakai"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Launch.php#L165-L169 | train |
tsugiproject/tsugi-php | src/Core/Launch.php | Launch.isMoodle | public function isMoodle() {
$ext_lms = $this->ltiRawParameter('ext_lms', false);
$ext_lms = strtolower($ext_lms);
return strpos($ext_lms, 'moodle') === 0 ;
} | php | public function isMoodle() {
$ext_lms = $this->ltiRawParameter('ext_lms', false);
$ext_lms = strtolower($ext_lms);
return strpos($ext_lms, 'moodle') === 0 ;
} | [
"public",
"function",
"isMoodle",
"(",
")",
"{",
"$",
"ext_lms",
"=",
"$",
"this",
"->",
"ltiRawParameter",
"(",
"'ext_lms'",
",",
"false",
")",
";",
"$",
"ext_lms",
"=",
"strtolower",
"(",
"$",
"ext_lms",
")",
";",
"return",
"strpos",
"(",
"$",
"ext_lms",
",",
"'moodle'",
")",
"===",
"0",
";",
"}"
]
| Indicate if this launch came from Moodle | [
"Indicate",
"if",
"this",
"launch",
"came",
"from",
"Moodle"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Launch.php#L182-L186 | train |
tsugiproject/tsugi-php | src/Core/Launch.php | Launch.isCoursera | public function isCoursera() {
$product = $this->ltiRawParameter('tool_consumer_info_product_family_code', false);
$tci_description = $this->ltiRawParameter('tool_consumer_instance_description', false);
return ( $product == 'ims' && $tci_description == 'Coursera');
} | php | public function isCoursera() {
$product = $this->ltiRawParameter('tool_consumer_info_product_family_code', false);
$tci_description = $this->ltiRawParameter('tool_consumer_instance_description', false);
return ( $product == 'ims' && $tci_description == 'Coursera');
} | [
"public",
"function",
"isCoursera",
"(",
")",
"{",
"$",
"product",
"=",
"$",
"this",
"->",
"ltiRawParameter",
"(",
"'tool_consumer_info_product_family_code'",
",",
"false",
")",
";",
"$",
"tci_description",
"=",
"$",
"this",
"->",
"ltiRawParameter",
"(",
"'tool_consumer_instance_description'",
",",
"false",
")",
";",
"return",
"(",
"$",
"product",
"==",
"'ims'",
"&&",
"$",
"tci_description",
"==",
"'Coursera'",
")",
";",
"}"
]
| Indicate if this launch came from Coursera | [
"Indicate",
"if",
"this",
"launch",
"came",
"from",
"Coursera"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Launch.php#L191-L195 | train |
tsugiproject/tsugi-php | src/Core/Launch.php | Launch.newLaunch | public function newLaunch($send_name=true, $send_email=true) {
$parms = array(
'lti_message_type' => 'basic-lti-launch-request',
'tool_consumer_info_product_family_code' => 'tsugi',
'tool_consumer_info_version' => '1.1',
);
// Some Tsugi Goodness
$form_id = "tsugi_form_id_".bin2Hex(openssl_random_pseudo_bytes(4));
$parms['ext_lti_form_id'] = $form_id;
if ( $this->user ) {
$parms['user_id'] = $this->user->id;
$parms['roles'] = $this->user->instructor ? 'Instructor' : 'Learner';
if ( $send_name ) $parms['lis_person_name_full'] = $this->user->displayname;
if ( $send_email ) $parms['lis_person_contact_email_primary'] = $this->user->email;
if ( $send_email || $send_email ) $parms['image'] = $this->user->image;
}
if ( $this->context ) {
$parms['context_id'] = $this->context->id;
$parms['context_title'] = $this->context->title;
$parms['context_label'] = $this->context->title;
}
if ( $this->link ) {
$parms['resource_link_id'] = $this->link->id;
$parms['resource_link_title'] = $this->link->title;
}
if ( $this->result ) {
$parms['resource_link_id'] = $this->link->id;
$parms['resource_link_title'] = $this->link->title;
}
foreach ( $parms as $k => $v ) {
if ( $v === false || $v === null ) unset($parms[$k]);
}
return $parms;
} | php | public function newLaunch($send_name=true, $send_email=true) {
$parms = array(
'lti_message_type' => 'basic-lti-launch-request',
'tool_consumer_info_product_family_code' => 'tsugi',
'tool_consumer_info_version' => '1.1',
);
// Some Tsugi Goodness
$form_id = "tsugi_form_id_".bin2Hex(openssl_random_pseudo_bytes(4));
$parms['ext_lti_form_id'] = $form_id;
if ( $this->user ) {
$parms['user_id'] = $this->user->id;
$parms['roles'] = $this->user->instructor ? 'Instructor' : 'Learner';
if ( $send_name ) $parms['lis_person_name_full'] = $this->user->displayname;
if ( $send_email ) $parms['lis_person_contact_email_primary'] = $this->user->email;
if ( $send_email || $send_email ) $parms['image'] = $this->user->image;
}
if ( $this->context ) {
$parms['context_id'] = $this->context->id;
$parms['context_title'] = $this->context->title;
$parms['context_label'] = $this->context->title;
}
if ( $this->link ) {
$parms['resource_link_id'] = $this->link->id;
$parms['resource_link_title'] = $this->link->title;
}
if ( $this->result ) {
$parms['resource_link_id'] = $this->link->id;
$parms['resource_link_title'] = $this->link->title;
}
foreach ( $parms as $k => $v ) {
if ( $v === false || $v === null ) unset($parms[$k]);
}
return $parms;
} | [
"public",
"function",
"newLaunch",
"(",
"$",
"send_name",
"=",
"true",
",",
"$",
"send_email",
"=",
"true",
")",
"{",
"$",
"parms",
"=",
"array",
"(",
"'lti_message_type'",
"=>",
"'basic-lti-launch-request'",
",",
"'tool_consumer_info_product_family_code'",
"=>",
"'tsugi'",
",",
"'tool_consumer_info_version'",
"=>",
"'1.1'",
",",
")",
";",
"// Some Tsugi Goodness",
"$",
"form_id",
"=",
"\"tsugi_form_id_\"",
".",
"bin2Hex",
"(",
"openssl_random_pseudo_bytes",
"(",
"4",
")",
")",
";",
"$",
"parms",
"[",
"'ext_lti_form_id'",
"]",
"=",
"$",
"form_id",
";",
"if",
"(",
"$",
"this",
"->",
"user",
")",
"{",
"$",
"parms",
"[",
"'user_id'",
"]",
"=",
"$",
"this",
"->",
"user",
"->",
"id",
";",
"$",
"parms",
"[",
"'roles'",
"]",
"=",
"$",
"this",
"->",
"user",
"->",
"instructor",
"?",
"'Instructor'",
":",
"'Learner'",
";",
"if",
"(",
"$",
"send_name",
")",
"$",
"parms",
"[",
"'lis_person_name_full'",
"]",
"=",
"$",
"this",
"->",
"user",
"->",
"displayname",
";",
"if",
"(",
"$",
"send_email",
")",
"$",
"parms",
"[",
"'lis_person_contact_email_primary'",
"]",
"=",
"$",
"this",
"->",
"user",
"->",
"email",
";",
"if",
"(",
"$",
"send_email",
"||",
"$",
"send_email",
")",
"$",
"parms",
"[",
"'image'",
"]",
"=",
"$",
"this",
"->",
"user",
"->",
"image",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"context",
")",
"{",
"$",
"parms",
"[",
"'context_id'",
"]",
"=",
"$",
"this",
"->",
"context",
"->",
"id",
";",
"$",
"parms",
"[",
"'context_title'",
"]",
"=",
"$",
"this",
"->",
"context",
"->",
"title",
";",
"$",
"parms",
"[",
"'context_label'",
"]",
"=",
"$",
"this",
"->",
"context",
"->",
"title",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"link",
")",
"{",
"$",
"parms",
"[",
"'resource_link_id'",
"]",
"=",
"$",
"this",
"->",
"link",
"->",
"id",
";",
"$",
"parms",
"[",
"'resource_link_title'",
"]",
"=",
"$",
"this",
"->",
"link",
"->",
"title",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"result",
")",
"{",
"$",
"parms",
"[",
"'resource_link_id'",
"]",
"=",
"$",
"this",
"->",
"link",
"->",
"id",
";",
"$",
"parms",
"[",
"'resource_link_title'",
"]",
"=",
"$",
"this",
"->",
"link",
"->",
"title",
";",
"}",
"foreach",
"(",
"$",
"parms",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"v",
"===",
"false",
"||",
"$",
"v",
"===",
"null",
")",
"unset",
"(",
"$",
"parms",
"[",
"$",
"k",
"]",
")",
";",
"}",
"return",
"$",
"parms",
";",
"}"
]
| set up parameters for an outbound launch from this launch | [
"set",
"up",
"parameters",
"for",
"an",
"outbound",
"launch",
"from",
"this",
"launch"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Launch.php#L200-L235 | train |
rokka-io/rokka-client-php | src/User.php | User.getCurrentUserId | public function getCurrentUserId()
{
$contents = $this
->call('GET', self::USER_RESOURCE)
->getBody()
->getContents();
$json = json_decode($contents, true);
return $json['user_id'];
} | php | public function getCurrentUserId()
{
$contents = $this
->call('GET', self::USER_RESOURCE)
->getBody()
->getContents();
$json = json_decode($contents, true);
return $json['user_id'];
} | [
"public",
"function",
"getCurrentUserId",
"(",
")",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"call",
"(",
"'GET'",
",",
"self",
"::",
"USER_RESOURCE",
")",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
";",
"$",
"json",
"=",
"json_decode",
"(",
"$",
"contents",
",",
"true",
")",
";",
"return",
"$",
"json",
"[",
"'user_id'",
"]",
";",
"}"
]
| Get current user.
@since 1.7.0
@throws GuzzleException
@throws \RuntimeException
@return string | [
"Get",
"current",
"user",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/User.php#L71-L81 | train |
rokka-io/rokka-client-php | src/User.php | User.createOrganization | public function createOrganization($name, $billingMail, $displayName = '')
{
$options = ['json' => [
'billing_email' => $billingMail,
]];
if (!empty($displayName)) {
$options['json']['display_name'] = $displayName;
}
$contents = $this
->call('PUT', self::ORGANIZATION_RESOURCE.'/'.$name, $options)
->getBody()
->getContents()
;
return Organization::createFromJsonResponse($contents);
} | php | public function createOrganization($name, $billingMail, $displayName = '')
{
$options = ['json' => [
'billing_email' => $billingMail,
]];
if (!empty($displayName)) {
$options['json']['display_name'] = $displayName;
}
$contents = $this
->call('PUT', self::ORGANIZATION_RESOURCE.'/'.$name, $options)
->getBody()
->getContents()
;
return Organization::createFromJsonResponse($contents);
} | [
"public",
"function",
"createOrganization",
"(",
"$",
"name",
",",
"$",
"billingMail",
",",
"$",
"displayName",
"=",
"''",
")",
"{",
"$",
"options",
"=",
"[",
"'json'",
"=>",
"[",
"'billing_email'",
"=>",
"$",
"billingMail",
",",
"]",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"displayName",
")",
")",
"{",
"$",
"options",
"[",
"'json'",
"]",
"[",
"'display_name'",
"]",
"=",
"$",
"displayName",
";",
"}",
"$",
"contents",
"=",
"$",
"this",
"->",
"call",
"(",
"'PUT'",
",",
"self",
"::",
"ORGANIZATION_RESOURCE",
".",
"'/'",
".",
"$",
"name",
",",
"$",
"options",
")",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
";",
"return",
"Organization",
"::",
"createFromJsonResponse",
"(",
"$",
"contents",
")",
";",
"}"
]
| Create an organization.
@param string $name Organization name
@param string $billingMail Billing mail
@param string $displayName Optional display name
@throws GuzzleException
@throws \RuntimeException
@return Organization | [
"Create",
"an",
"organization",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/User.php#L95-L112 | train |
rokka-io/rokka-client-php | src/User.php | User.getOrganization | public function getOrganization($organization = '')
{
$contents = $this
->call('GET', self::ORGANIZATION_RESOURCE.'/'.$this->getOrganizationName($organization))
->getBody()
->getContents()
;
return Organization::createFromJsonResponse($contents);
} | php | public function getOrganization($organization = '')
{
$contents = $this
->call('GET', self::ORGANIZATION_RESOURCE.'/'.$this->getOrganizationName($organization))
->getBody()
->getContents()
;
return Organization::createFromJsonResponse($contents);
} | [
"public",
"function",
"getOrganization",
"(",
"$",
"organization",
"=",
"''",
")",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"call",
"(",
"'GET'",
",",
"self",
"::",
"ORGANIZATION_RESOURCE",
".",
"'/'",
".",
"$",
"this",
"->",
"getOrganizationName",
"(",
"$",
"organization",
")",
")",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
";",
"return",
"Organization",
"::",
"createFromJsonResponse",
"(",
"$",
"contents",
")",
";",
"}"
]
| Return an organization.
@since 1.7.0
@param string $organization Organization name
@throws GuzzleException
@throws \RuntimeException
@return Organization | [
"Return",
"an",
"organization",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/User.php#L126-L135 | train |
rokka-io/rokka-client-php | src/User.php | User.createMembership | public function createMembership($userId, $roles = [Membership::ROLE_READ], $organization = '')
{
if (\is_string($roles)) {
$roles = [$roles];
}
$roles = array_map(function ($role) {
return strtolower($role);
}, $roles);
$contents = $this
->call('PUT', implode('/', [self::ORGANIZATION_RESOURCE, $this->getOrganizationName($organization), 'memberships', $userId]), ['json' => [
'roles' => $roles,
]])
->getBody()
->getContents();
// get the membership, if it already exists
if (empty($contents)) {
return $this->getMembership($userId, $this->getOrganizationName($organization));
}
return $this->getSingleMemberShipFromJsonResponse($contents);
} | php | public function createMembership($userId, $roles = [Membership::ROLE_READ], $organization = '')
{
if (\is_string($roles)) {
$roles = [$roles];
}
$roles = array_map(function ($role) {
return strtolower($role);
}, $roles);
$contents = $this
->call('PUT', implode('/', [self::ORGANIZATION_RESOURCE, $this->getOrganizationName($organization), 'memberships', $userId]), ['json' => [
'roles' => $roles,
]])
->getBody()
->getContents();
// get the membership, if it already exists
if (empty($contents)) {
return $this->getMembership($userId, $this->getOrganizationName($organization));
}
return $this->getSingleMemberShipFromJsonResponse($contents);
} | [
"public",
"function",
"createMembership",
"(",
"$",
"userId",
",",
"$",
"roles",
"=",
"[",
"Membership",
"::",
"ROLE_READ",
"]",
",",
"$",
"organization",
"=",
"''",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"roles",
")",
")",
"{",
"$",
"roles",
"=",
"[",
"$",
"roles",
"]",
";",
"}",
"$",
"roles",
"=",
"array_map",
"(",
"function",
"(",
"$",
"role",
")",
"{",
"return",
"strtolower",
"(",
"$",
"role",
")",
";",
"}",
",",
"$",
"roles",
")",
";",
"$",
"contents",
"=",
"$",
"this",
"->",
"call",
"(",
"'PUT'",
",",
"implode",
"(",
"'/'",
",",
"[",
"self",
"::",
"ORGANIZATION_RESOURCE",
",",
"$",
"this",
"->",
"getOrganizationName",
"(",
"$",
"organization",
")",
",",
"'memberships'",
",",
"$",
"userId",
"]",
")",
",",
"[",
"'json'",
"=>",
"[",
"'roles'",
"=>",
"$",
"roles",
",",
"]",
"]",
")",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
";",
"// get the membership, if it already exists",
"if",
"(",
"empty",
"(",
"$",
"contents",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getMembership",
"(",
"$",
"userId",
",",
"$",
"this",
"->",
"getOrganizationName",
"(",
"$",
"organization",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getSingleMemberShipFromJsonResponse",
"(",
"$",
"contents",
")",
";",
"}"
]
| Create a membership.
@since 1.7.0
@param string $organization Organization
@param string $userId User ID
@param string|array $roles Role to add
@throws GuzzleException
@throws \RuntimeException
@return Membership | [
"Create",
"a",
"membership",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/User.php#L151-L172 | train |
rokka-io/rokka-client-php | src/User.php | User.createUserAndMembership | public function createUserAndMembership($roles = [Membership::ROLE_READ], $organization = '')
{
if (\is_string($roles)) {
$roles = [$roles];
}
$roles = array_map(function ($role) {
return strtolower($role);
}, $roles);
$contents = $this
->call('POST',
implode('/', [self::ORGANIZATION_RESOURCE, $this->getOrganizationName($organization), 'memberships']),
['json' => [
'roles' => $roles,
]])
->getBody()
->getContents();
return $this->getSingleMemberShipFromJsonResponse($contents);
} | php | public function createUserAndMembership($roles = [Membership::ROLE_READ], $organization = '')
{
if (\is_string($roles)) {
$roles = [$roles];
}
$roles = array_map(function ($role) {
return strtolower($role);
}, $roles);
$contents = $this
->call('POST',
implode('/', [self::ORGANIZATION_RESOURCE, $this->getOrganizationName($organization), 'memberships']),
['json' => [
'roles' => $roles,
]])
->getBody()
->getContents();
return $this->getSingleMemberShipFromJsonResponse($contents);
} | [
"public",
"function",
"createUserAndMembership",
"(",
"$",
"roles",
"=",
"[",
"Membership",
"::",
"ROLE_READ",
"]",
",",
"$",
"organization",
"=",
"''",
")",
"{",
"if",
"(",
"\\",
"is_string",
"(",
"$",
"roles",
")",
")",
"{",
"$",
"roles",
"=",
"[",
"$",
"roles",
"]",
";",
"}",
"$",
"roles",
"=",
"array_map",
"(",
"function",
"(",
"$",
"role",
")",
"{",
"return",
"strtolower",
"(",
"$",
"role",
")",
";",
"}",
",",
"$",
"roles",
")",
";",
"$",
"contents",
"=",
"$",
"this",
"->",
"call",
"(",
"'POST'",
",",
"implode",
"(",
"'/'",
",",
"[",
"self",
"::",
"ORGANIZATION_RESOURCE",
",",
"$",
"this",
"->",
"getOrganizationName",
"(",
"$",
"organization",
")",
",",
"'memberships'",
"]",
")",
",",
"[",
"'json'",
"=>",
"[",
"'roles'",
"=>",
"$",
"roles",
",",
"]",
"]",
")",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
";",
"return",
"$",
"this",
"->",
"getSingleMemberShipFromJsonResponse",
"(",
"$",
"contents",
")",
";",
"}"
]
| Create a user and membership associated to this organization.
@since 1.7.0
@param string $organization Organization
@param string|array $roles Role to add
@throws GuzzleException
@throws \RuntimeException
@return Membership | [
"Create",
"a",
"user",
"and",
"membership",
"associated",
"to",
"this",
"organization",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/User.php#L187-L205 | train |
rokka-io/rokka-client-php | src/User.php | User.getMembership | public function getMembership($userId, $organization = '')
{
$contents = $this
->call('GET', implode('/', [self::ORGANIZATION_RESOURCE, $this->getOrganizationName($organization), 'memberships', $userId]))
->getBody()
->getContents();
return $this->getSingleMemberShipFromJsonResponse($contents);
} | php | public function getMembership($userId, $organization = '')
{
$contents = $this
->call('GET', implode('/', [self::ORGANIZATION_RESOURCE, $this->getOrganizationName($organization), 'memberships', $userId]))
->getBody()
->getContents();
return $this->getSingleMemberShipFromJsonResponse($contents);
} | [
"public",
"function",
"getMembership",
"(",
"$",
"userId",
",",
"$",
"organization",
"=",
"''",
")",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"call",
"(",
"'GET'",
",",
"implode",
"(",
"'/'",
",",
"[",
"self",
"::",
"ORGANIZATION_RESOURCE",
",",
"$",
"this",
"->",
"getOrganizationName",
"(",
"$",
"organization",
")",
",",
"'memberships'",
",",
"$",
"userId",
"]",
")",
")",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
";",
"return",
"$",
"this",
"->",
"getSingleMemberShipFromJsonResponse",
"(",
"$",
"contents",
")",
";",
"}"
]
| Get the membership metadata for the given organization and user's ID.
@since 1.7.0
@param string $organization Organization
@param string $userId User ID
@throws GuzzleException
@throws \RuntimeException
@return Membership | [
"Get",
"the",
"membership",
"metadata",
"for",
"the",
"given",
"organization",
"and",
"user",
"s",
"ID",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/User.php#L220-L228 | train |
rokka-io/rokka-client-php | src/User.php | User.deleteMembership | public function deleteMembership($userId, $organization = '')
{
try {
$response = $this
->call('DELETE', implode('/', [self::ORGANIZATION_RESOURCE, $this->getOrganizationName($organization), 'memberships', $userId]));
} catch (GuzzleException $e) {
if (404 == $e->getCode()) {
return false;
}
throw $e;
}
return '204' == $response->getStatusCode();
} | php | public function deleteMembership($userId, $organization = '')
{
try {
$response = $this
->call('DELETE', implode('/', [self::ORGANIZATION_RESOURCE, $this->getOrganizationName($organization), 'memberships', $userId]));
} catch (GuzzleException $e) {
if (404 == $e->getCode()) {
return false;
}
throw $e;
}
return '204' == $response->getStatusCode();
} | [
"public",
"function",
"deleteMembership",
"(",
"$",
"userId",
",",
"$",
"organization",
"=",
"''",
")",
"{",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"call",
"(",
"'DELETE'",
",",
"implode",
"(",
"'/'",
",",
"[",
"self",
"::",
"ORGANIZATION_RESOURCE",
",",
"$",
"this",
"->",
"getOrganizationName",
"(",
"$",
"organization",
")",
",",
"'memberships'",
",",
"$",
"userId",
"]",
")",
")",
";",
"}",
"catch",
"(",
"GuzzleException",
"$",
"e",
")",
"{",
"if",
"(",
"404",
"==",
"$",
"e",
"->",
"getCode",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"throw",
"$",
"e",
";",
"}",
"return",
"'204'",
"==",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"}"
]
| Deletes a membership for the given organization and user's ID.
@since 1.7.0
@param string $organization Organization
@param string $userId User ID
@throws GuzzleException
@throws \RuntimeException
@return bool | [
"Deletes",
"a",
"membership",
"for",
"the",
"given",
"organization",
"and",
"user",
"s",
"ID",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/User.php#L243-L257 | train |
rokka-io/rokka-client-php | src/User.php | User.listMemberships | public function listMemberships($organization = '')
{
$contents = $this
->call('GET', implode('/', [self::ORGANIZATION_RESOURCE, $this->getOrganizationName($organization), 'memberships']))
->getBody()
->getContents()
;
$membership = Membership::createFromJsonResponse($contents);
if (!\is_array($membership)) {
throw new \RuntimeException('Something went wrong, return was not array, but should be');
}
return $membership;
} | php | public function listMemberships($organization = '')
{
$contents = $this
->call('GET', implode('/', [self::ORGANIZATION_RESOURCE, $this->getOrganizationName($organization), 'memberships']))
->getBody()
->getContents()
;
$membership = Membership::createFromJsonResponse($contents);
if (!\is_array($membership)) {
throw new \RuntimeException('Something went wrong, return was not array, but should be');
}
return $membership;
} | [
"public",
"function",
"listMemberships",
"(",
"$",
"organization",
"=",
"''",
")",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"call",
"(",
"'GET'",
",",
"implode",
"(",
"'/'",
",",
"[",
"self",
"::",
"ORGANIZATION_RESOURCE",
",",
"$",
"this",
"->",
"getOrganizationName",
"(",
"$",
"organization",
")",
",",
"'memberships'",
"]",
")",
")",
"->",
"getBody",
"(",
")",
"->",
"getContents",
"(",
")",
";",
"$",
"membership",
"=",
"Membership",
"::",
"createFromJsonResponse",
"(",
"$",
"contents",
")",
";",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"membership",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Something went wrong, return was not array, but should be'",
")",
";",
"}",
"return",
"$",
"membership",
";",
"}"
]
| List the membership metadata for the given organization.
@since 1.7.0
@param string $organization Organization
@throws GuzzleException
@throws \RuntimeException
@return Membership[] | [
"List",
"the",
"membership",
"metadata",
"for",
"the",
"given",
"organization",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/User.php#L271-L285 | train |
tsugiproject/tsugi-php | src/Core/JsonTrait.php | JsonTrait.getJson | public function getJson()
{
global $CFG, $PDOX;
$row = $PDOX->rowDie("SELECT json FROM {$CFG->dbprefix}{$this->TABLE_NAME}
WHERE $this->PRIMARY_KEY = :PK",
array(":PK" => $this->id));
if ( $row === false ) return false;
$json = $row['json'];
if ( $json === null ) return false;
return $json;
} | php | public function getJson()
{
global $CFG, $PDOX;
$row = $PDOX->rowDie("SELECT json FROM {$CFG->dbprefix}{$this->TABLE_NAME}
WHERE $this->PRIMARY_KEY = :PK",
array(":PK" => $this->id));
if ( $row === false ) return false;
$json = $row['json'];
if ( $json === null ) return false;
return $json;
} | [
"public",
"function",
"getJson",
"(",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"PDOX",
";",
"$",
"row",
"=",
"$",
"PDOX",
"->",
"rowDie",
"(",
"\"SELECT json FROM {$CFG->dbprefix}{$this->TABLE_NAME}\n WHERE $this->PRIMARY_KEY = :PK\"",
",",
"array",
"(",
"\":PK\"",
"=>",
"$",
"this",
"->",
"id",
")",
")",
";",
"if",
"(",
"$",
"row",
"===",
"false",
")",
"return",
"false",
";",
"$",
"json",
"=",
"$",
"row",
"[",
"'json'",
"]",
";",
"if",
"(",
"$",
"json",
"===",
"null",
")",
"return",
"false",
";",
"return",
"$",
"json",
";",
"}"
]
| Load the json field for this entity
@return string This returns the json string - it is not parsed - if there is
nothing to return - this returns "false" | [
"Load",
"the",
"json",
"field",
"for",
"this",
"entity"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/JsonTrait.php#L21-L32 | train |
tsugiproject/tsugi-php | src/Core/JsonTrait.php | JsonTrait.getJsonKey | public function getJsonKey($key,$default=false)
{
global $CFG, $PDOX;
$jsonStr = $this->getJson();
if ( ! $jsonStr ) return $default;
$json = json_decode($jsonStr, true);
if ( ! $json ) return $default;
return U::get($json, $key, $default);
} | php | public function getJsonKey($key,$default=false)
{
global $CFG, $PDOX;
$jsonStr = $this->getJson();
if ( ! $jsonStr ) return $default;
$json = json_decode($jsonStr, true);
if ( ! $json ) return $default;
return U::get($json, $key, $default);
} | [
"public",
"function",
"getJsonKey",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"false",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"PDOX",
";",
"$",
"jsonStr",
"=",
"$",
"this",
"->",
"getJson",
"(",
")",
";",
"if",
"(",
"!",
"$",
"jsonStr",
")",
"return",
"$",
"default",
";",
"$",
"json",
"=",
"json_decode",
"(",
"$",
"jsonStr",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"json",
")",
"return",
"$",
"default",
";",
"return",
"U",
"::",
"get",
"(",
"$",
"json",
",",
"$",
"key",
",",
"$",
"default",
")",
";",
"}"
]
| Get a JSON key for this entity
@params $key The key to be retrieved from the JSON
@params $default The default value (optional) | [
"Get",
"a",
"JSON",
"key",
"for",
"this",
"entity"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/JsonTrait.php#L41-L50 | train |
tsugiproject/tsugi-php | src/Core/JsonTrait.php | JsonTrait.setJson | public function setJson($json)
{
global $CFG, $PDOX;
$q = $PDOX->queryDie("UPDATE {$CFG->dbprefix}{$this->TABLE_NAME}
SET json = :SET WHERE $this->PRIMARY_KEY = :PK",
array(":SET" => $json, ":PK" => $this->id)
);
} | php | public function setJson($json)
{
global $CFG, $PDOX;
$q = $PDOX->queryDie("UPDATE {$CFG->dbprefix}{$this->TABLE_NAME}
SET json = :SET WHERE $this->PRIMARY_KEY = :PK",
array(":SET" => $json, ":PK" => $this->id)
);
} | [
"public",
"function",
"setJson",
"(",
"$",
"json",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"PDOX",
";",
"$",
"q",
"=",
"$",
"PDOX",
"->",
"queryDie",
"(",
"\"UPDATE {$CFG->dbprefix}{$this->TABLE_NAME}\n SET json = :SET WHERE $this->PRIMARY_KEY = :PK\"",
",",
"array",
"(",
"\":SET\"",
"=>",
"$",
"json",
",",
"\":PK\"",
"=>",
"$",
"this",
"->",
"id",
")",
")",
";",
"}"
]
| Set the JSON entry for this entity
@params $json This is a string - no validation is done | [
"Set",
"the",
"JSON",
"entry",
"for",
"this",
"entity"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/JsonTrait.php#L58-L66 | train |
rokka-io/rokka-client-php | src/Factory.php | Factory.getImageClient | public static function getImageClient($organization, $apiKey, $options = [])
{
$baseUrl = BaseClient::DEFAULT_API_BASE_URL;
if (!\is_array($options)) { // $options was introduced later, if that is an array, we're on the new sig, nothing to change
if (\func_num_args() > 3) { // if more than 3 args, the 4th is the baseUrl
$baseUrl = func_get_arg(3);
} elseif (3 === \func_num_args()) { // if exactly 3 args
//if $baseUrl doesn't start with http, it may be a secret from the old signature, remove that, it's not used anymore
if ('http' !== substr($options, 0, 4)) {
$baseUrl = BaseClient::DEFAULT_API_BASE_URL;
} else {
$baseUrl = $options;
}
}
$options = [];
} else {
if (isset($options[self::API_BASE_URL])) {
$baseUrl = $options[self::API_BASE_URL];
}
}
$client = self::getGuzzleClient($baseUrl, $options);
return new ImageClient($client, $organization, $apiKey);
} | php | public static function getImageClient($organization, $apiKey, $options = [])
{
$baseUrl = BaseClient::DEFAULT_API_BASE_URL;
if (!\is_array($options)) { // $options was introduced later, if that is an array, we're on the new sig, nothing to change
if (\func_num_args() > 3) { // if more than 3 args, the 4th is the baseUrl
$baseUrl = func_get_arg(3);
} elseif (3 === \func_num_args()) { // if exactly 3 args
//if $baseUrl doesn't start with http, it may be a secret from the old signature, remove that, it's not used anymore
if ('http' !== substr($options, 0, 4)) {
$baseUrl = BaseClient::DEFAULT_API_BASE_URL;
} else {
$baseUrl = $options;
}
}
$options = [];
} else {
if (isset($options[self::API_BASE_URL])) {
$baseUrl = $options[self::API_BASE_URL];
}
}
$client = self::getGuzzleClient($baseUrl, $options);
return new ImageClient($client, $organization, $apiKey);
} | [
"public",
"static",
"function",
"getImageClient",
"(",
"$",
"organization",
",",
"$",
"apiKey",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"baseUrl",
"=",
"BaseClient",
"::",
"DEFAULT_API_BASE_URL",
";",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"options",
")",
")",
"{",
"// $options was introduced later, if that is an array, we're on the new sig, nothing to change",
"if",
"(",
"\\",
"func_num_args",
"(",
")",
">",
"3",
")",
"{",
"// if more than 3 args, the 4th is the baseUrl",
"$",
"baseUrl",
"=",
"func_get_arg",
"(",
"3",
")",
";",
"}",
"elseif",
"(",
"3",
"===",
"\\",
"func_num_args",
"(",
")",
")",
"{",
"// if exactly 3 args",
"//if $baseUrl doesn't start with http, it may be a secret from the old signature, remove that, it's not used anymore",
"if",
"(",
"'http'",
"!==",
"substr",
"(",
"$",
"options",
",",
"0",
",",
"4",
")",
")",
"{",
"$",
"baseUrl",
"=",
"BaseClient",
"::",
"DEFAULT_API_BASE_URL",
";",
"}",
"else",
"{",
"$",
"baseUrl",
"=",
"$",
"options",
";",
"}",
"}",
"$",
"options",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"self",
"::",
"API_BASE_URL",
"]",
")",
")",
"{",
"$",
"baseUrl",
"=",
"$",
"options",
"[",
"self",
"::",
"API_BASE_URL",
"]",
";",
"}",
"}",
"$",
"client",
"=",
"self",
"::",
"getGuzzleClient",
"(",
"$",
"baseUrl",
",",
"$",
"options",
")",
";",
"return",
"new",
"ImageClient",
"(",
"$",
"client",
",",
"$",
"organization",
",",
"$",
"apiKey",
")",
";",
"}"
]
| Return an image client.
@param string $organization Organization name
@param string $apiKey API key
@param array|string $options Options like api_base_url or proxy
@throws \RuntimeException
@return Image | [
"Return",
"an",
"image",
"client",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Factory.php#L38-L62 | train |
rokka-io/rokka-client-php | src/Factory.php | Factory.getUserClient | public static function getUserClient($organization = null, $apiKey = null, $options = [])
{
$baseUrl = BaseClient::DEFAULT_API_BASE_URL;
//bc compability, when first param was $options
if (\is_array($organization)) {
$options = $organization;
$organization = null;
$apiKey = null;
}
if (isset($options[self::API_BASE_URL])) {
$baseUrl = $options[self::API_BASE_URL];
}
$client = self::getGuzzleClient($baseUrl, $options);
return new UserClient($client, $organization, $apiKey);
} | php | public static function getUserClient($organization = null, $apiKey = null, $options = [])
{
$baseUrl = BaseClient::DEFAULT_API_BASE_URL;
//bc compability, when first param was $options
if (\is_array($organization)) {
$options = $organization;
$organization = null;
$apiKey = null;
}
if (isset($options[self::API_BASE_URL])) {
$baseUrl = $options[self::API_BASE_URL];
}
$client = self::getGuzzleClient($baseUrl, $options);
return new UserClient($client, $organization, $apiKey);
} | [
"public",
"static",
"function",
"getUserClient",
"(",
"$",
"organization",
"=",
"null",
",",
"$",
"apiKey",
"=",
"null",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"baseUrl",
"=",
"BaseClient",
"::",
"DEFAULT_API_BASE_URL",
";",
"//bc compability, when first param was $options",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"organization",
")",
")",
"{",
"$",
"options",
"=",
"$",
"organization",
";",
"$",
"organization",
"=",
"null",
";",
"$",
"apiKey",
"=",
"null",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"self",
"::",
"API_BASE_URL",
"]",
")",
")",
"{",
"$",
"baseUrl",
"=",
"$",
"options",
"[",
"self",
"::",
"API_BASE_URL",
"]",
";",
"}",
"$",
"client",
"=",
"self",
"::",
"getGuzzleClient",
"(",
"$",
"baseUrl",
",",
"$",
"options",
")",
";",
"return",
"new",
"UserClient",
"(",
"$",
"client",
",",
"$",
"organization",
",",
"$",
"apiKey",
")",
";",
"}"
]
| Return a user client.
@param string|null|array $organization
@param string|null $apiKey API key
@param array $options Options like api_base_url or proxy
@throws \RuntimeException
@return UserClient | [
"Return",
"a",
"user",
"client",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Factory.php#L75-L92 | train |
rokka-io/rokka-client-php | src/Factory.php | Factory.getGuzzleClient | private static function getGuzzleClient($baseUrl, $options = [])
{
$guzzleOptions = [];
if (isset($options[self::PROXY])) {
$guzzleOptions[self::PROXY] = $options[self::PROXY];
}
if (isset($options[self::GUZZLE_OPTIONS])) {
$guzzleOptions = array_merge($guzzleOptions, $options[self::GUZZLE_OPTIONS]);
}
$handlerStack = HandlerStack::create();
$handlerStack->unshift(Middleware::retry(self::retryDecider(), self::retryDelay()));
$options = array_merge(['base_uri' => $baseUrl, 'handler' => $handlerStack], $guzzleOptions);
return new GuzzleClient($options);
} | php | private static function getGuzzleClient($baseUrl, $options = [])
{
$guzzleOptions = [];
if (isset($options[self::PROXY])) {
$guzzleOptions[self::PROXY] = $options[self::PROXY];
}
if (isset($options[self::GUZZLE_OPTIONS])) {
$guzzleOptions = array_merge($guzzleOptions, $options[self::GUZZLE_OPTIONS]);
}
$handlerStack = HandlerStack::create();
$handlerStack->unshift(Middleware::retry(self::retryDecider(), self::retryDelay()));
$options = array_merge(['base_uri' => $baseUrl, 'handler' => $handlerStack], $guzzleOptions);
return new GuzzleClient($options);
} | [
"private",
"static",
"function",
"getGuzzleClient",
"(",
"$",
"baseUrl",
",",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"guzzleOptions",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"self",
"::",
"PROXY",
"]",
")",
")",
"{",
"$",
"guzzleOptions",
"[",
"self",
"::",
"PROXY",
"]",
"=",
"$",
"options",
"[",
"self",
"::",
"PROXY",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"self",
"::",
"GUZZLE_OPTIONS",
"]",
")",
")",
"{",
"$",
"guzzleOptions",
"=",
"array_merge",
"(",
"$",
"guzzleOptions",
",",
"$",
"options",
"[",
"self",
"::",
"GUZZLE_OPTIONS",
"]",
")",
";",
"}",
"$",
"handlerStack",
"=",
"HandlerStack",
"::",
"create",
"(",
")",
";",
"$",
"handlerStack",
"->",
"unshift",
"(",
"Middleware",
"::",
"retry",
"(",
"self",
"::",
"retryDecider",
"(",
")",
",",
"self",
"::",
"retryDelay",
"(",
")",
")",
")",
";",
"$",
"options",
"=",
"array_merge",
"(",
"[",
"'base_uri'",
"=>",
"$",
"baseUrl",
",",
"'handler'",
"=>",
"$",
"handlerStack",
"]",
",",
"$",
"guzzleOptions",
")",
";",
"return",
"new",
"GuzzleClient",
"(",
"$",
"options",
")",
";",
"}"
]
| Returns a Guzzle client with a retry middleware.
@param string $baseUrl base url
@param array $options
@throws \RuntimeException
@return GuzzleClient GuzzleClient to connect to the backend | [
"Returns",
"a",
"Guzzle",
"client",
"with",
"a",
"retry",
"middleware",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Factory.php#L104-L119 | train |
rokka-io/rokka-client-php | src/Factory.php | Factory.retryDecider | private static function retryDecider()
{
return function (
$retries,
Request $request,
Response $response = null,
RequestException $exception = null
) {
// Limit the number of retries to 10
if ($retries >= 10) {
return false;
}
// Retry connection exceptions
if ($exception instanceof ConnectException) {
return true;
}
if ($response) {
// Retry on server errors or overload
$statusCode = $response->getStatusCode();
if (429 == $statusCode || 504 == $statusCode || 503 == $statusCode || 502 == $statusCode) {
return true;
}
}
return false;
};
} | php | private static function retryDecider()
{
return function (
$retries,
Request $request,
Response $response = null,
RequestException $exception = null
) {
// Limit the number of retries to 10
if ($retries >= 10) {
return false;
}
// Retry connection exceptions
if ($exception instanceof ConnectException) {
return true;
}
if ($response) {
// Retry on server errors or overload
$statusCode = $response->getStatusCode();
if (429 == $statusCode || 504 == $statusCode || 503 == $statusCode || 502 == $statusCode) {
return true;
}
}
return false;
};
} | [
"private",
"static",
"function",
"retryDecider",
"(",
")",
"{",
"return",
"function",
"(",
"$",
"retries",
",",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
"=",
"null",
",",
"RequestException",
"$",
"exception",
"=",
"null",
")",
"{",
"// Limit the number of retries to 10",
"if",
"(",
"$",
"retries",
">=",
"10",
")",
"{",
"return",
"false",
";",
"}",
"// Retry connection exceptions",
"if",
"(",
"$",
"exception",
"instanceof",
"ConnectException",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"response",
")",
"{",
"// Retry on server errors or overload",
"$",
"statusCode",
"=",
"$",
"response",
"->",
"getStatusCode",
"(",
")",
";",
"if",
"(",
"429",
"==",
"$",
"statusCode",
"||",
"504",
"==",
"$",
"statusCode",
"||",
"503",
"==",
"$",
"statusCode",
"||",
"502",
"==",
"$",
"statusCode",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
";",
"}"
]
| Returns a Closure for the Retry Middleware to decide if it should retry the request when it failed.
@return \Closure | [
"Returns",
"a",
"Closure",
"for",
"the",
"Retry",
"Middleware",
"to",
"decide",
"if",
"it",
"should",
"retry",
"the",
"request",
"when",
"it",
"failed",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Factory.php#L126-L154 | train |
tsugiproject/tsugi-php | src/Core/ContentItem.php | ContentItem.returnUrl | public static function returnUrl($postdata=false) {
if ( ! $postdata ) $postdata = LTIX::ltiRawPostArray();
return parent::returnUrl($postdata);
} | php | public static function returnUrl($postdata=false) {
if ( ! $postdata ) $postdata = LTIX::ltiRawPostArray();
return parent::returnUrl($postdata);
} | [
"public",
"static",
"function",
"returnUrl",
"(",
"$",
"postdata",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"postdata",
")",
"$",
"postdata",
"=",
"LTIX",
"::",
"ltiRawPostArray",
"(",
")",
";",
"return",
"parent",
"::",
"returnUrl",
"(",
"$",
"postdata",
")",
";",
"}"
]
| returnUrl - Returns the content_item_return_url
@return string The content_item_return_url or false | [
"returnUrl",
"-",
"Returns",
"the",
"content_item_return_url"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/ContentItem.php#L19-L22 | train |
tsugiproject/tsugi-php | src/Core/ContentItem.php | ContentItem.allowImportItem | public static function allowImportItem($postdata=false) {
if ( ! $postdata ) $postdata = LTIX::ltiRawPostArray();
return parent::allowImportItem($postdata);
} | php | public static function allowImportItem($postdata=false) {
if ( ! $postdata ) $postdata = LTIX::ltiRawPostArray();
return parent::allowImportItem($postdata);
} | [
"public",
"static",
"function",
"allowImportItem",
"(",
"$",
"postdata",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"postdata",
")",
"$",
"postdata",
"=",
"LTIX",
"::",
"ltiRawPostArray",
"(",
")",
";",
"return",
"parent",
"::",
"allowImportItem",
"(",
"$",
"postdata",
")",
";",
"}"
]
| allowImportItem - Returns true if we can return Common Cartridges | [
"allowImportItem",
"-",
"Returns",
"true",
"if",
"we",
"can",
"return",
"Common",
"Cartridges"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/ContentItem.php#L43-L46 | train |
tsugiproject/tsugi-php | src/Core/ContentItem.php | ContentItem.prepareResponse | function prepareResponse($endform=false) {
$return_url = $this->returnUrl();
$parms = $this->getContentItemSelection();
$parms = LTIX::signParameters($parms, $return_url, "POST", "Install Content");
$endform = '<a href="index.php" class="btn btn-warning">Back to Store</a>';
$content = LTI::postLaunchHTML($parms, $return_url, true, false, $endform);
return $content;
} | php | function prepareResponse($endform=false) {
$return_url = $this->returnUrl();
$parms = $this->getContentItemSelection();
$parms = LTIX::signParameters($parms, $return_url, "POST", "Install Content");
$endform = '<a href="index.php" class="btn btn-warning">Back to Store</a>';
$content = LTI::postLaunchHTML($parms, $return_url, true, false, $endform);
return $content;
} | [
"function",
"prepareResponse",
"(",
"$",
"endform",
"=",
"false",
")",
"{",
"$",
"return_url",
"=",
"$",
"this",
"->",
"returnUrl",
"(",
")",
";",
"$",
"parms",
"=",
"$",
"this",
"->",
"getContentItemSelection",
"(",
")",
";",
"$",
"parms",
"=",
"LTIX",
"::",
"signParameters",
"(",
"$",
"parms",
",",
"$",
"return_url",
",",
"\"POST\"",
",",
"\"Install Content\"",
")",
";",
"$",
"endform",
"=",
"'<a href=\"index.php\" class=\"btn btn-warning\">Back to Store</a>'",
";",
"$",
"content",
"=",
"LTI",
"::",
"postLaunchHTML",
"(",
"$",
"parms",
",",
"$",
"return_url",
",",
"true",
",",
"false",
",",
"$",
"endform",
")",
";",
"return",
"$",
"content",
";",
"}"
]
| Make up a response
@param $endform Some HTML to be included before the form closing tag
$endform = '<a href="index.php" class="btn btn-warning">Back to Store</a>'; | [
"Make",
"up",
"a",
"response"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/ContentItem.php#L65-L72 | train |
tsugiproject/tsugi-php | src/UI/Analytics.php | Analytics.button | public static function button($right = false)
{
global $LINK;
if ( $right ) echo('<span style="position: fixed; right: 10px; top: 5px;">');
echo('<button onclick="showModal(\''.__('Analytics').' '.htmlentities($LINK->title).'\',\'analytics_div\'); return false;" type="button" class="btn btn-default">');
echo('<span class="glyphicon glyphicon-signal"></span></button>'."\n");
if ( $right ) echo('</span>');
} | php | public static function button($right = false)
{
global $LINK;
if ( $right ) echo('<span style="position: fixed; right: 10px; top: 5px;">');
echo('<button onclick="showModal(\''.__('Analytics').' '.htmlentities($LINK->title).'\',\'analytics_div\'); return false;" type="button" class="btn btn-default">');
echo('<span class="glyphicon glyphicon-signal"></span></button>'."\n");
if ( $right ) echo('</span>');
} | [
"public",
"static",
"function",
"button",
"(",
"$",
"right",
"=",
"false",
")",
"{",
"global",
"$",
"LINK",
";",
"if",
"(",
"$",
"right",
")",
"echo",
"(",
"'<span style=\"position: fixed; right: 10px; top: 5px;\">'",
")",
";",
"echo",
"(",
"'<button onclick=\"showModal(\\''",
".",
"__",
"(",
"'Analytics'",
")",
".",
"' '",
".",
"htmlentities",
"(",
"$",
"LINK",
"->",
"title",
")",
".",
"'\\',\\'analytics_div\\'); return false;\" type=\"button\" class=\"btn btn-default\">'",
")",
";",
"echo",
"(",
"'<span class=\"glyphicon glyphicon-signal\"></span></button>'",
".",
"\"\\n\"",
")",
";",
"if",
"(",
"$",
"right",
")",
"echo",
"(",
"'</span>'",
")",
";",
"}"
]
| Emit a properly styled "settings" button
This is just the button, using the pencil icon. Wrap in a
span or div tag if you want to move it around | [
"Emit",
"a",
"properly",
"styled",
"settings",
"button"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/Analytics.php#L16-L23 | train |
tsugiproject/tsugi-php | src/UI/HandleBars.php | HandleBars.templateInclude | public static function templateInclude($name) {
if ( is_array($name) ) {
foreach($name as $n) {
self::templateInclude($n);
}
return;
}
echo('<script id="script-template-'.$name.'" type="text/x-handlebars-template">'."\n");
$template = file_get_contents('templates/'.$name.'.hbs');
echo(self::templateProcess($template));
echo("</script>\n");
} | php | public static function templateInclude($name) {
if ( is_array($name) ) {
foreach($name as $n) {
self::templateInclude($n);
}
return;
}
echo('<script id="script-template-'.$name.'" type="text/x-handlebars-template">'."\n");
$template = file_get_contents('templates/'.$name.'.hbs');
echo(self::templateProcess($template));
echo("</script>\n");
} | [
"public",
"static",
"function",
"templateInclude",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"foreach",
"(",
"$",
"name",
"as",
"$",
"n",
")",
"{",
"self",
"::",
"templateInclude",
"(",
"$",
"n",
")",
";",
"}",
"return",
";",
"}",
"echo",
"(",
"'<script id=\"script-template-'",
".",
"$",
"name",
".",
"'\" type=\"text/x-handlebars-template\">'",
".",
"\"\\n\"",
")",
";",
"$",
"template",
"=",
"file_get_contents",
"(",
"'templates/'",
".",
"$",
"name",
".",
"'.hbs'",
")",
";",
"echo",
"(",
"self",
"::",
"templateProcess",
"(",
"$",
"template",
")",
")",
";",
"echo",
"(",
"\"</script>\\n\"",
")",
";",
"}"
]
| templateInclude - Include a handlebars template, dealing with i18n
This is a normal handlebars template except we can ask for a translation
of text as follows:
...
{{__ 'Hello world' }}
...
The i18n replacement will be handled in the server in the template. Single
or Double quotes can be used. | [
"templateInclude",
"-",
"Include",
"a",
"handlebars",
"template",
"dealing",
"with",
"i18n"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/HandleBars.php#L26-L37 | train |
tsugiproject/tsugi-php | src/UI/HandleBars.php | HandleBars.templateProcess | public static function templateProcess($template) {
$new = preg_replace_callback(
'|{{__ *\'([^\']*)\' *}}|',
function ($matches) {
return __(htmlent_utf8(trim($matches[1])));
},
$template
);
$new = preg_replace_callback(
'|{{__ *"([^"]*)" *}}|',
function ($matches) {
return __(htmlent_utf8(trim($matches[1])));
},
$new
);
$new = preg_replace_callback(
'|{{>> *([^ ]*) *}}|',
function ($matches) {
$name = 'templates/'.trim($matches[1]);
if ( file_exists($name) ) {
return file_get_contents($name);
}
return "Unable to open $name";
},
$new
);
return $new;
} | php | public static function templateProcess($template) {
$new = preg_replace_callback(
'|{{__ *\'([^\']*)\' *}}|',
function ($matches) {
return __(htmlent_utf8(trim($matches[1])));
},
$template
);
$new = preg_replace_callback(
'|{{__ *"([^"]*)" *}}|',
function ($matches) {
return __(htmlent_utf8(trim($matches[1])));
},
$new
);
$new = preg_replace_callback(
'|{{>> *([^ ]*) *}}|',
function ($matches) {
$name = 'templates/'.trim($matches[1]);
if ( file_exists($name) ) {
return file_get_contents($name);
}
return "Unable to open $name";
},
$new
);
return $new;
} | [
"public",
"static",
"function",
"templateProcess",
"(",
"$",
"template",
")",
"{",
"$",
"new",
"=",
"preg_replace_callback",
"(",
"'|{{__ *\\'([^\\']*)\\' *}}|'",
",",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"__",
"(",
"htmlent_utf8",
"(",
"trim",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
")",
")",
";",
"}",
",",
"$",
"template",
")",
";",
"$",
"new",
"=",
"preg_replace_callback",
"(",
"'|{{__ *\"([^\"]*)\" *}}|'",
",",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"__",
"(",
"htmlent_utf8",
"(",
"trim",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
")",
")",
";",
"}",
",",
"$",
"new",
")",
";",
"$",
"new",
"=",
"preg_replace_callback",
"(",
"'|{{>> *([^ ]*) *}}|'",
",",
"function",
"(",
"$",
"matches",
")",
"{",
"$",
"name",
"=",
"'templates/'",
".",
"trim",
"(",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"name",
")",
")",
"{",
"return",
"file_get_contents",
"(",
"$",
"name",
")",
";",
"}",
"return",
"\"Unable to open $name\"",
";",
"}",
",",
"$",
"new",
")",
";",
"return",
"$",
"new",
";",
"}"
]
| templateProcess - Process a handlebars template, dealing with i18n
This is a normal handlebars template except we can ask for a translation
of text as follows:
...
{{__ 'Hello world' }}
...
The i18n replacement will be handled in the server in the template. Single
or double quotes can be used. | [
"templateProcess",
"-",
"Process",
"a",
"handlebars",
"template",
"dealing",
"with",
"i18n"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/UI/HandleBars.php#L52-L79 | train |
tsugiproject/tsugi-php | src/Util/LTI.php | LTI.isRequestCheck | public static function isRequestCheck($request_data=false) {
if ( $request_data === false ) $request_data = $_REQUEST;
if ( !isset($request_data["lti_message_type"]) ) return false;
if ( !isset($request_data["lti_version"]) ) return false;
$good_lti_version = self::isValidVersion($request_data["lti_version"]);
if ( ! $good_lti_version ) return "Invalid LTI version ".$request_data["lti_version"];
$good_message_type = self::isValidMessageType($request_data["lti_message_type"]);
if ( ! $good_message_type ) return "Invalid message type ".$request_data["lti_message_type"];
return true;
} | php | public static function isRequestCheck($request_data=false) {
if ( $request_data === false ) $request_data = $_REQUEST;
if ( !isset($request_data["lti_message_type"]) ) return false;
if ( !isset($request_data["lti_version"]) ) return false;
$good_lti_version = self::isValidVersion($request_data["lti_version"]);
if ( ! $good_lti_version ) return "Invalid LTI version ".$request_data["lti_version"];
$good_message_type = self::isValidMessageType($request_data["lti_message_type"]);
if ( ! $good_message_type ) return "Invalid message type ".$request_data["lti_message_type"];
return true;
} | [
"public",
"static",
"function",
"isRequestCheck",
"(",
"$",
"request_data",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"request_data",
"===",
"false",
")",
"$",
"request_data",
"=",
"$",
"_REQUEST",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"request_data",
"[",
"\"lti_message_type\"",
"]",
")",
")",
"return",
"false",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"request_data",
"[",
"\"lti_version\"",
"]",
")",
")",
"return",
"false",
";",
"$",
"good_lti_version",
"=",
"self",
"::",
"isValidVersion",
"(",
"$",
"request_data",
"[",
"\"lti_version\"",
"]",
")",
";",
"if",
"(",
"!",
"$",
"good_lti_version",
")",
"return",
"\"Invalid LTI version \"",
".",
"$",
"request_data",
"[",
"\"lti_version\"",
"]",
";",
"$",
"good_message_type",
"=",
"self",
"::",
"isValidMessageType",
"(",
"$",
"request_data",
"[",
"\"lti_message_type\"",
"]",
")",
";",
"if",
"(",
"!",
"$",
"good_message_type",
")",
"return",
"\"Invalid message type \"",
".",
"$",
"request_data",
"[",
"\"lti_message_type\"",
"]",
";",
"return",
"true",
";",
"}"
]
| Determines if this is a valid Basic LTI message
@retval mixed Returns true if this is a Basic LTI message
with minimum values to meet the protocol. Returns false
if this is not even close to an LTI launch. If this is a
broken launch, it returns an error as to why. | [
"Determines",
"if",
"this",
"is",
"a",
"valid",
"Basic",
"LTI",
"message"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI.php#L33-L42 | train |
tsugiproject/tsugi-php | src/Util/LTI.php | LTI.verifyKeyAndSecret | public static function verifyKeyAndSecret($key, $secret, $http_url=NULL, $parameters=null, $http_method=NULL) {
global $LastOAuthBodyBaseString;
if ( ! ($key && $secret) ) return array("Missing key or secret", "");
$store = new TrivialOAuthDataStore();
$store->add_consumer($key, $secret);
$server = new OAuthServer($store);
$method = new OAuthSignatureMethod_HMAC_SHA1();
$server->add_signature_method($method);
$method = new OAuthSignatureMethod_HMAC_SHA256();
$server->add_signature_method($method);
$request = OAuthRequest::from_request($http_method, $http_url, $parameters);
$LastOAuthBodyBaseString = $request->get_signature_base_string();
try {
$server->verify_request($request);
return true;
} catch (\Exception $e) {
return array($e->getMessage(), $LastOAuthBodyBaseString);
}
} | php | public static function verifyKeyAndSecret($key, $secret, $http_url=NULL, $parameters=null, $http_method=NULL) {
global $LastOAuthBodyBaseString;
if ( ! ($key && $secret) ) return array("Missing key or secret", "");
$store = new TrivialOAuthDataStore();
$store->add_consumer($key, $secret);
$server = new OAuthServer($store);
$method = new OAuthSignatureMethod_HMAC_SHA1();
$server->add_signature_method($method);
$method = new OAuthSignatureMethod_HMAC_SHA256();
$server->add_signature_method($method);
$request = OAuthRequest::from_request($http_method, $http_url, $parameters);
$LastOAuthBodyBaseString = $request->get_signature_base_string();
try {
$server->verify_request($request);
return true;
} catch (\Exception $e) {
return array($e->getMessage(), $LastOAuthBodyBaseString);
}
} | [
"public",
"static",
"function",
"verifyKeyAndSecret",
"(",
"$",
"key",
",",
"$",
"secret",
",",
"$",
"http_url",
"=",
"NULL",
",",
"$",
"parameters",
"=",
"null",
",",
"$",
"http_method",
"=",
"NULL",
")",
"{",
"global",
"$",
"LastOAuthBodyBaseString",
";",
"if",
"(",
"!",
"(",
"$",
"key",
"&&",
"$",
"secret",
")",
")",
"return",
"array",
"(",
"\"Missing key or secret\"",
",",
"\"\"",
")",
";",
"$",
"store",
"=",
"new",
"TrivialOAuthDataStore",
"(",
")",
";",
"$",
"store",
"->",
"add_consumer",
"(",
"$",
"key",
",",
"$",
"secret",
")",
";",
"$",
"server",
"=",
"new",
"OAuthServer",
"(",
"$",
"store",
")",
";",
"$",
"method",
"=",
"new",
"OAuthSignatureMethod_HMAC_SHA1",
"(",
")",
";",
"$",
"server",
"->",
"add_signature_method",
"(",
"$",
"method",
")",
";",
"$",
"method",
"=",
"new",
"OAuthSignatureMethod_HMAC_SHA256",
"(",
")",
";",
"$",
"server",
"->",
"add_signature_method",
"(",
"$",
"method",
")",
";",
"$",
"request",
"=",
"OAuthRequest",
"::",
"from_request",
"(",
"$",
"http_method",
",",
"$",
"http_url",
",",
"$",
"parameters",
")",
";",
"$",
"LastOAuthBodyBaseString",
"=",
"$",
"request",
"->",
"get_signature_base_string",
"(",
")",
";",
"try",
"{",
"$",
"server",
"->",
"verify_request",
"(",
"$",
"request",
")",
";",
"return",
"true",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"array",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"LastOAuthBodyBaseString",
")",
";",
"}",
"}"
]
| Verify the message signature for this request
@return mixed This returns true if the request verified. If the request did not verify,
this returns an array with the first element as an error string, and the second element
as the base string of the request. | [
"Verify",
"the",
"message",
"signature",
"for",
"this",
"request"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI.php#L79-L102 | train |
tsugiproject/tsugi-php | src/Util/LTI.php | LTI.sendJSONGrade | public static function sendJSONGrade($grade, $comment, $result_url, $key_key, $secret, &$debug_log=false, $signature=false) {
global $LastJSONGradeResponse;
$LastJSONGradeResponse = false;
$content_type = "application/vnd.ims.lis.v2.result+json";
if ( is_array($debug_log) ) $debug_log[] = array('Sending '.$grade.' to result_url='.$result_url);
$addStructureRequest = self::getResultJSON($grade, $comment);
$postBody = self::jsonIndent(json_encode($addStructureRequest));
if ( is_array($debug_log) ) $debug_log[] = array('Grade JSON Request',$postBody);
$more_headers = false;
$response = self::sendOAuthBody("PUT", $result_url, $key_key,
$secret, $content_type, $postBody, $more_headers, $signature);
if ( is_array($debug_log) ) $debug_log[] = array('Grade JSON Response',$response);
global $LastOAuthBodyBaseString;
$lbs = $LastOAuthBodyBaseString;
if ( is_array($debug_log) ) $debug_log[] = array('Our base string',$lbs);
// TODO: Be smarter about this :)
return true;
} | php | public static function sendJSONGrade($grade, $comment, $result_url, $key_key, $secret, &$debug_log=false, $signature=false) {
global $LastJSONGradeResponse;
$LastJSONGradeResponse = false;
$content_type = "application/vnd.ims.lis.v2.result+json";
if ( is_array($debug_log) ) $debug_log[] = array('Sending '.$grade.' to result_url='.$result_url);
$addStructureRequest = self::getResultJSON($grade, $comment);
$postBody = self::jsonIndent(json_encode($addStructureRequest));
if ( is_array($debug_log) ) $debug_log[] = array('Grade JSON Request',$postBody);
$more_headers = false;
$response = self::sendOAuthBody("PUT", $result_url, $key_key,
$secret, $content_type, $postBody, $more_headers, $signature);
if ( is_array($debug_log) ) $debug_log[] = array('Grade JSON Response',$response);
global $LastOAuthBodyBaseString;
$lbs = $LastOAuthBodyBaseString;
if ( is_array($debug_log) ) $debug_log[] = array('Our base string',$lbs);
// TODO: Be smarter about this :)
return true;
} | [
"public",
"static",
"function",
"sendJSONGrade",
"(",
"$",
"grade",
",",
"$",
"comment",
",",
"$",
"result_url",
",",
"$",
"key_key",
",",
"$",
"secret",
",",
"&",
"$",
"debug_log",
"=",
"false",
",",
"$",
"signature",
"=",
"false",
")",
"{",
"global",
"$",
"LastJSONGradeResponse",
";",
"$",
"LastJSONGradeResponse",
"=",
"false",
";",
"$",
"content_type",
"=",
"\"application/vnd.ims.lis.v2.result+json\"",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"array",
"(",
"'Sending '",
".",
"$",
"grade",
".",
"' to result_url='",
".",
"$",
"result_url",
")",
";",
"$",
"addStructureRequest",
"=",
"self",
"::",
"getResultJSON",
"(",
"$",
"grade",
",",
"$",
"comment",
")",
";",
"$",
"postBody",
"=",
"self",
"::",
"jsonIndent",
"(",
"json_encode",
"(",
"$",
"addStructureRequest",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"array",
"(",
"'Grade JSON Request'",
",",
"$",
"postBody",
")",
";",
"$",
"more_headers",
"=",
"false",
";",
"$",
"response",
"=",
"self",
"::",
"sendOAuthBody",
"(",
"\"PUT\"",
",",
"$",
"result_url",
",",
"$",
"key_key",
",",
"$",
"secret",
",",
"$",
"content_type",
",",
"$",
"postBody",
",",
"$",
"more_headers",
",",
"$",
"signature",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"array",
"(",
"'Grade JSON Response'",
",",
"$",
"response",
")",
";",
"global",
"$",
"LastOAuthBodyBaseString",
";",
"$",
"lbs",
"=",
"$",
"LastOAuthBodyBaseString",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"array",
"(",
"'Our base string'",
",",
"$",
"lbs",
")",
";",
"// TODO: Be smarter about this :)",
"return",
"true",
";",
"}"
]
| Send a grade using the JSON protocol from IMS LTI 2.x
@param debug_log This can either be false or an empty array. If
this is an array, it is filled with data as the steps progress.
Each step is an array with a string message as the first element
and optional debug detail (i.e. like a post body) as the second
element.
@return mixed If things go well this returns true.
If this goes badly, this returns a string with an error message. | [
"Send",
"a",
"grade",
"using",
"the",
"JSON",
"protocol",
"from",
"IMS",
"LTI",
"2",
".",
"x"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI.php#L810-L835 | train |
tsugiproject/tsugi-php | src/Util/LTI.php | LTI.sendJSONSettings | public static function sendJSONSettings($settings, $settings_url, $key_key, $secret, &$debug_log=false, $signature=false) {
$content_type = "application/vnd.ims.lti.v2.toolsettings.simple+json";
if ( is_array($debug_log) ) $debug_log[] = array('Sending '.count($settings).' settings to settings_url='.$settings_url);
// Make sure everything is a string
$sendsettings = array();
foreach ( $settings as $k => $v ) {
$sendsettings[$k] = "".$v;
}
$postBody = self::jsonIndent(json_encode($sendsettings));
if ( is_array($debug_log) ) $debug_log[] = array('Settings JSON Request',$postBody);
$more_headers = false;
$response = self::sendOAuthBody("PUT", $settings_url, $key_key,
$secret, $content_type, $postBody, $more_headers, $signature);
if ( is_array($debug_log) ) $debug_log[] = array('Settings JSON Response',$response);
global $LastOAuthBodyBaseString;
$lbs = $LastOAuthBodyBaseString;
if ( is_array($debug_log) ) $debug_log[] = array('Our base string',$lbs);
// TODO: Be better at error checking...
return true;
} | php | public static function sendJSONSettings($settings, $settings_url, $key_key, $secret, &$debug_log=false, $signature=false) {
$content_type = "application/vnd.ims.lti.v2.toolsettings.simple+json";
if ( is_array($debug_log) ) $debug_log[] = array('Sending '.count($settings).' settings to settings_url='.$settings_url);
// Make sure everything is a string
$sendsettings = array();
foreach ( $settings as $k => $v ) {
$sendsettings[$k] = "".$v;
}
$postBody = self::jsonIndent(json_encode($sendsettings));
if ( is_array($debug_log) ) $debug_log[] = array('Settings JSON Request',$postBody);
$more_headers = false;
$response = self::sendOAuthBody("PUT", $settings_url, $key_key,
$secret, $content_type, $postBody, $more_headers, $signature);
if ( is_array($debug_log) ) $debug_log[] = array('Settings JSON Response',$response);
global $LastOAuthBodyBaseString;
$lbs = $LastOAuthBodyBaseString;
if ( is_array($debug_log) ) $debug_log[] = array('Our base string',$lbs);
// TODO: Be better at error checking...
return true;
} | [
"public",
"static",
"function",
"sendJSONSettings",
"(",
"$",
"settings",
",",
"$",
"settings_url",
",",
"$",
"key_key",
",",
"$",
"secret",
",",
"&",
"$",
"debug_log",
"=",
"false",
",",
"$",
"signature",
"=",
"false",
")",
"{",
"$",
"content_type",
"=",
"\"application/vnd.ims.lti.v2.toolsettings.simple+json\"",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"array",
"(",
"'Sending '",
".",
"count",
"(",
"$",
"settings",
")",
".",
"' settings to settings_url='",
".",
"$",
"settings_url",
")",
";",
"// Make sure everything is a string",
"$",
"sendsettings",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"sendsettings",
"[",
"$",
"k",
"]",
"=",
"\"\"",
".",
"$",
"v",
";",
"}",
"$",
"postBody",
"=",
"self",
"::",
"jsonIndent",
"(",
"json_encode",
"(",
"$",
"sendsettings",
")",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"array",
"(",
"'Settings JSON Request'",
",",
"$",
"postBody",
")",
";",
"$",
"more_headers",
"=",
"false",
";",
"$",
"response",
"=",
"self",
"::",
"sendOAuthBody",
"(",
"\"PUT\"",
",",
"$",
"settings_url",
",",
"$",
"key_key",
",",
"$",
"secret",
",",
"$",
"content_type",
",",
"$",
"postBody",
",",
"$",
"more_headers",
",",
"$",
"signature",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"array",
"(",
"'Settings JSON Response'",
",",
"$",
"response",
")",
";",
"global",
"$",
"LastOAuthBodyBaseString",
";",
"$",
"lbs",
"=",
"$",
"LastOAuthBodyBaseString",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"array",
"(",
"'Our base string'",
",",
"$",
"lbs",
")",
";",
"// TODO: Be better at error checking...",
"return",
"true",
";",
"}"
]
| Send setings data using the JSON protocol from IMS LTI 2.x
@param debug_log This can either be false or an empty array. If
this is an array, it is filled with data as the steps progress.
Each step is an array with a string message as the first element
and optional debug detail (i.e. like a post body) as the second
element.
@return mixed If things go well this returns true.
If this goes badly, this returns a string with an error message. | [
"Send",
"setings",
"data",
"using",
"the",
"JSON",
"protocol",
"from",
"IMS",
"LTI",
"2",
".",
"x"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI.php#L865-L890 | train |
tsugiproject/tsugi-php | src/Util/LTI.php | LTI.sendJSONBody | public static function sendJSONBody($method, $postBody, $content_type,
$rest_url, $key_key, $secret, &$debug_log=false, $signature=false)
{
if ( is_array($debug_log) ) $debug_log[] = array('Sending '.strlen($postBody).' bytes to rest_url='.$rest_url);
$more_headers = false;
$response = self::sendOAuthBody($method, $rest_url, $key_key,
$secret, $content_type, $postBody);
if ( is_array($debug_log) ) $debug_log[] = array('Caliper JSON Response',$response);
global $LastOAuthBodyBaseString;
$lbs = $LastOAuthBodyBaseString;
if ( is_array($debug_log) ) $debug_log[] = array('Our base string',$lbs);
return true;
} | php | public static function sendJSONBody($method, $postBody, $content_type,
$rest_url, $key_key, $secret, &$debug_log=false, $signature=false)
{
if ( is_array($debug_log) ) $debug_log[] = array('Sending '.strlen($postBody).' bytes to rest_url='.$rest_url);
$more_headers = false;
$response = self::sendOAuthBody($method, $rest_url, $key_key,
$secret, $content_type, $postBody);
if ( is_array($debug_log) ) $debug_log[] = array('Caliper JSON Response',$response);
global $LastOAuthBodyBaseString;
$lbs = $LastOAuthBodyBaseString;
if ( is_array($debug_log) ) $debug_log[] = array('Our base string',$lbs);
return true;
} | [
"public",
"static",
"function",
"sendJSONBody",
"(",
"$",
"method",
",",
"$",
"postBody",
",",
"$",
"content_type",
",",
"$",
"rest_url",
",",
"$",
"key_key",
",",
"$",
"secret",
",",
"&",
"$",
"debug_log",
"=",
"false",
",",
"$",
"signature",
"=",
"false",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"array",
"(",
"'Sending '",
".",
"strlen",
"(",
"$",
"postBody",
")",
".",
"' bytes to rest_url='",
".",
"$",
"rest_url",
")",
";",
"$",
"more_headers",
"=",
"false",
";",
"$",
"response",
"=",
"self",
"::",
"sendOAuthBody",
"(",
"$",
"method",
",",
"$",
"rest_url",
",",
"$",
"key_key",
",",
"$",
"secret",
",",
"$",
"content_type",
",",
"$",
"postBody",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"array",
"(",
"'Caliper JSON Response'",
",",
"$",
"response",
")",
";",
"global",
"$",
"LastOAuthBodyBaseString",
";",
"$",
"lbs",
"=",
"$",
"LastOAuthBodyBaseString",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"array",
"(",
"'Our base string'",
",",
"$",
"lbs",
")",
";",
"return",
"true",
";",
"}"
]
| Send a JSON body LTI 2.x Style
@param debug_log This can either be false or an empty array. If
this is an array, it is filled with data as the steps progress.
Each step is an array with a string message as the first element
and optional debug detail (i.e. like a post body) as the second
element.
@return mixed If things go well this returns true.
If this goes badly, this returns a string with an error message. | [
"Send",
"a",
"JSON",
"body",
"LTI",
"2",
".",
"x",
"Style"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI.php#L904-L920 | train |
tsugiproject/tsugi-php | src/Util/LTI.php | LTI.ltiLinkUrl | public static function ltiLinkUrl($postdata=false) {
if ( $postdata === false ) $postData = $_POST;
if ( ! isset($postdata['content_item_return_url']) ) return false;
if ( isset($postdata['accept_media_types']) ) {
$ltilink_mimetype = 'application/vnd.ims.lti.v1.ltilink';
$m = new Mimeparse;
$ltilink_allowed = $m->best_match(array($ltilink_mimetype), $postdata['accept_media_types']);
if ( $ltilink_mimetype != $ltilink_allowed ) return false;
return $postdata['content_item_return_url'];
}
return false;
} | php | public static function ltiLinkUrl($postdata=false) {
if ( $postdata === false ) $postData = $_POST;
if ( ! isset($postdata['content_item_return_url']) ) return false;
if ( isset($postdata['accept_media_types']) ) {
$ltilink_mimetype = 'application/vnd.ims.lti.v1.ltilink';
$m = new Mimeparse;
$ltilink_allowed = $m->best_match(array($ltilink_mimetype), $postdata['accept_media_types']);
if ( $ltilink_mimetype != $ltilink_allowed ) return false;
return $postdata['content_item_return_url'];
}
return false;
} | [
"public",
"static",
"function",
"ltiLinkUrl",
"(",
"$",
"postdata",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"postdata",
"===",
"false",
")",
"$",
"postData",
"=",
"$",
"_POST",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"postdata",
"[",
"'content_item_return_url'",
"]",
")",
")",
"return",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"postdata",
"[",
"'accept_media_types'",
"]",
")",
")",
"{",
"$",
"ltilink_mimetype",
"=",
"'application/vnd.ims.lti.v1.ltilink'",
";",
"$",
"m",
"=",
"new",
"Mimeparse",
";",
"$",
"ltilink_allowed",
"=",
"$",
"m",
"->",
"best_match",
"(",
"array",
"(",
"$",
"ltilink_mimetype",
")",
",",
"$",
"postdata",
"[",
"'accept_media_types'",
"]",
")",
";",
"if",
"(",
"$",
"ltilink_mimetype",
"!=",
"$",
"ltilink_allowed",
")",
"return",
"false",
";",
"return",
"$",
"postdata",
"[",
"'content_item_return_url'",
"]",
";",
"}",
"return",
"false",
";",
"}"
]
| ltiLinkUrl - Returns true if we can return LTI Links for this launch
IMS Public Draft: http://www.imsglobal.org/specs/lticiv1p0
@return string The content_item_return_url or false | [
"ltiLinkUrl",
"-",
"Returns",
"true",
"if",
"we",
"can",
"return",
"LTI",
"Links",
"for",
"this",
"launch"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI.php#L929-L940 | train |
tsugiproject/tsugi-php | src/Util/LTI.php | LTI.getLtiLinkJSON | public static function getLtiLinkJSON($url, $title=false, $text=false,
$icon=false, $fa_icon=false, $custom=false )
{
$return = '{
"@context" : "http://purl.imsglobal.org/ctx/lti/v1/ContentItem",
"@graph" : [
{ "@type" : "LtiLinkItem",
"@id" : ":item2",
"title" : "A cool tool hosted in the Tsugi environment.",
"mediaType" : "application/vnd.ims.lti.v1.ltilink",
"text" : "For more information on how to build and host powerful LTI-based Tools quickly, see www.tsugi.org",
"url" : "http://www.tsugi.org/",
"placementAdvice" : {
"presentationDocumentTarget" : "window",
"displayHeight" : 1024,
"displayWidth" : 800
},
"icon" : {
"@id" : "https://static.tsugi.org/img/default-icon.png",
"fa_icon" : "fa-magic",
"width" : 64,
"height" : 64
}
}
]
}';
$json = json_decode($return);
$json->{'@graph'}[0]->url = $url;
if ( $title ) $json->{'@graph'}[0]->{'title'} = $title;
if ( $text ) $json->{'@graph'}[0]->{'text'} = $text;
if ( $icon ) $json->{'@graph'}[0]->{'icon'}->{'@id'} = $icon;
if ( $fa_icon ) $json->{'@graph'}[0]->icon->fa_icon = $fa_icon;
if ( $custom ) $json->{'@graph'}[0]->custom = $custom;
return $json;
} | php | public static function getLtiLinkJSON($url, $title=false, $text=false,
$icon=false, $fa_icon=false, $custom=false )
{
$return = '{
"@context" : "http://purl.imsglobal.org/ctx/lti/v1/ContentItem",
"@graph" : [
{ "@type" : "LtiLinkItem",
"@id" : ":item2",
"title" : "A cool tool hosted in the Tsugi environment.",
"mediaType" : "application/vnd.ims.lti.v1.ltilink",
"text" : "For more information on how to build and host powerful LTI-based Tools quickly, see www.tsugi.org",
"url" : "http://www.tsugi.org/",
"placementAdvice" : {
"presentationDocumentTarget" : "window",
"displayHeight" : 1024,
"displayWidth" : 800
},
"icon" : {
"@id" : "https://static.tsugi.org/img/default-icon.png",
"fa_icon" : "fa-magic",
"width" : 64,
"height" : 64
}
}
]
}';
$json = json_decode($return);
$json->{'@graph'}[0]->url = $url;
if ( $title ) $json->{'@graph'}[0]->{'title'} = $title;
if ( $text ) $json->{'@graph'}[0]->{'text'} = $text;
if ( $icon ) $json->{'@graph'}[0]->{'icon'}->{'@id'} = $icon;
if ( $fa_icon ) $json->{'@graph'}[0]->icon->fa_icon = $fa_icon;
if ( $custom ) $json->{'@graph'}[0]->custom = $custom;
return $json;
} | [
"public",
"static",
"function",
"getLtiLinkJSON",
"(",
"$",
"url",
",",
"$",
"title",
"=",
"false",
",",
"$",
"text",
"=",
"false",
",",
"$",
"icon",
"=",
"false",
",",
"$",
"fa_icon",
"=",
"false",
",",
"$",
"custom",
"=",
"false",
")",
"{",
"$",
"return",
"=",
"'{\n \"@context\" : \"http://purl.imsglobal.org/ctx/lti/v1/ContentItem\",\n \"@graph\" : [\n { \"@type\" : \"LtiLinkItem\",\n \"@id\" : \":item2\",\n \"title\" : \"A cool tool hosted in the Tsugi environment.\",\n \"mediaType\" : \"application/vnd.ims.lti.v1.ltilink\",\n \"text\" : \"For more information on how to build and host powerful LTI-based Tools quickly, see www.tsugi.org\",\n \"url\" : \"http://www.tsugi.org/\",\n \"placementAdvice\" : {\n\t \"presentationDocumentTarget\" : \"window\",\n\t \"displayHeight\" : 1024,\n\t \"displayWidth\" : 800\n },\n \"icon\" : {\n \"@id\" : \"https://static.tsugi.org/img/default-icon.png\",\n \"fa_icon\" : \"fa-magic\",\n \"width\" : 64,\n \"height\" : 64\n }\n }\n ]\n }'",
";",
"$",
"json",
"=",
"json_decode",
"(",
"$",
"return",
")",
";",
"$",
"json",
"->",
"{",
"'@graph'",
"}",
"[",
"0",
"]",
"->",
"url",
"=",
"$",
"url",
";",
"if",
"(",
"$",
"title",
")",
"$",
"json",
"->",
"{",
"'@graph'",
"}",
"[",
"0",
"]",
"->",
"{",
"'title'",
"}",
"=",
"$",
"title",
";",
"if",
"(",
"$",
"text",
")",
"$",
"json",
"->",
"{",
"'@graph'",
"}",
"[",
"0",
"]",
"->",
"{",
"'text'",
"}",
"=",
"$",
"text",
";",
"if",
"(",
"$",
"icon",
")",
"$",
"json",
"->",
"{",
"'@graph'",
"}",
"[",
"0",
"]",
"->",
"{",
"'icon'",
"}",
"->",
"{",
"'@id'",
"}",
"=",
"$",
"icon",
";",
"if",
"(",
"$",
"fa_icon",
")",
"$",
"json",
"->",
"{",
"'@graph'",
"}",
"[",
"0",
"]",
"->",
"icon",
"->",
"fa_icon",
"=",
"$",
"fa_icon",
";",
"if",
"(",
"$",
"custom",
")",
"$",
"json",
"->",
"{",
"'@graph'",
"}",
"[",
"0",
"]",
"->",
"custom",
"=",
"$",
"custom",
";",
"return",
"$",
"json",
";",
"}"
]
| getLtiLinkJson - Get a JSON object for an LTI Link Content Item Return
@param url The launch URL of the tool that is about to be placed
@param title A plain text title of the content-item.
@param text A plain text description of the content-item.
@param icon An image URL of an icon
@param fa_icon The class name of a FontAwesome icon | [
"getLtiLinkJson",
"-",
"Get",
"a",
"JSON",
"object",
"for",
"an",
"LTI",
"Link",
"Content",
"Item",
"Return"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI.php#L952-L987 | train |
tsugiproject/tsugi-php | src/Blob/BlobUtil.php | BlobUtil.validateUpload | public static function validateUpload($FILE_DESCRIPTOR, $SAFETY_CHECK=true)
{
$retval = true;
$filename = isset($FILE_DESCRIPTOR['name']) ? basename($FILE_DESCRIPTOR['name']) : false;
if ( $FILE_DESCRIPTOR['error'] == 1) {
$retval = _m("General upload failure");
} else if ( $FILE_DESCRIPTOR['error'] == 4) {
$retval = _m('Missing file, make sure to select file(s) before pressing submit');
} else if ( $filename === false ) {
$retval = _m("Uploaded file has no name");
} else if ( $FILE_DESCRIPTOR['size'] < 1 ) {
$retval = _m("File is empty: ").$filename;
} else if ( $FILE_DESCRIPTOR['error'] == 0 ) {
if ( $SAFETY_CHECK && preg_match(self::BAD_FILE_SUFFIXES, $filename) ) $retval = _m("File suffix not allowed");
} else {
$retval = _m("Upload failure=").$FILE_DESCRIPTOR['error'];
}
return $retval;
} | php | public static function validateUpload($FILE_DESCRIPTOR, $SAFETY_CHECK=true)
{
$retval = true;
$filename = isset($FILE_DESCRIPTOR['name']) ? basename($FILE_DESCRIPTOR['name']) : false;
if ( $FILE_DESCRIPTOR['error'] == 1) {
$retval = _m("General upload failure");
} else if ( $FILE_DESCRIPTOR['error'] == 4) {
$retval = _m('Missing file, make sure to select file(s) before pressing submit');
} else if ( $filename === false ) {
$retval = _m("Uploaded file has no name");
} else if ( $FILE_DESCRIPTOR['size'] < 1 ) {
$retval = _m("File is empty: ").$filename;
} else if ( $FILE_DESCRIPTOR['error'] == 0 ) {
if ( $SAFETY_CHECK && preg_match(self::BAD_FILE_SUFFIXES, $filename) ) $retval = _m("File suffix not allowed");
} else {
$retval = _m("Upload failure=").$FILE_DESCRIPTOR['error'];
}
return $retval;
} | [
"public",
"static",
"function",
"validateUpload",
"(",
"$",
"FILE_DESCRIPTOR",
",",
"$",
"SAFETY_CHECK",
"=",
"true",
")",
"{",
"$",
"retval",
"=",
"true",
";",
"$",
"filename",
"=",
"isset",
"(",
"$",
"FILE_DESCRIPTOR",
"[",
"'name'",
"]",
")",
"?",
"basename",
"(",
"$",
"FILE_DESCRIPTOR",
"[",
"'name'",
"]",
")",
":",
"false",
";",
"if",
"(",
"$",
"FILE_DESCRIPTOR",
"[",
"'error'",
"]",
"==",
"1",
")",
"{",
"$",
"retval",
"=",
"_m",
"(",
"\"General upload failure\"",
")",
";",
"}",
"else",
"if",
"(",
"$",
"FILE_DESCRIPTOR",
"[",
"'error'",
"]",
"==",
"4",
")",
"{",
"$",
"retval",
"=",
"_m",
"(",
"'Missing file, make sure to select file(s) before pressing submit'",
")",
";",
"}",
"else",
"if",
"(",
"$",
"filename",
"===",
"false",
")",
"{",
"$",
"retval",
"=",
"_m",
"(",
"\"Uploaded file has no name\"",
")",
";",
"}",
"else",
"if",
"(",
"$",
"FILE_DESCRIPTOR",
"[",
"'size'",
"]",
"<",
"1",
")",
"{",
"$",
"retval",
"=",
"_m",
"(",
"\"File is empty: \"",
")",
".",
"$",
"filename",
";",
"}",
"else",
"if",
"(",
"$",
"FILE_DESCRIPTOR",
"[",
"'error'",
"]",
"==",
"0",
")",
"{",
"if",
"(",
"$",
"SAFETY_CHECK",
"&&",
"preg_match",
"(",
"self",
"::",
"BAD_FILE_SUFFIXES",
",",
"$",
"filename",
")",
")",
"$",
"retval",
"=",
"_m",
"(",
"\"File suffix not allowed\"",
")",
";",
"}",
"else",
"{",
"$",
"retval",
"=",
"_m",
"(",
"\"Upload failure=\"",
")",
".",
"$",
"FILE_DESCRIPTOR",
"[",
"'error'",
"]",
";",
"}",
"return",
"$",
"retval",
";",
"}"
]
| Returns true if this is a good upload, an error string if not | [
"Returns",
"true",
"if",
"this",
"is",
"a",
"good",
"upload",
"an",
"error",
"string",
"if",
"not"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Blob/BlobUtil.php#L73-L92 | train |
tsugiproject/tsugi-php | src/Blob/BlobUtil.php | BlobUtil.isPngOrJpeg | public static function isPngOrJpeg($FILE_DESCRIPTOR)
{
if ( !isset($FILE_DESCRIPTOR['name']) ) return false;
if ( !isset($FILE_DESCRIPTOR['tmp_name']) ) return false;
$info = getimagesize($FILE_DESCRIPTOR['tmp_name']);
if ( ! is_array($info) ) return false;
$image_type = $info[2];
return $image_type == IMAGETYPE_JPEG || $image_type == IMAGETYPE_PNG;
} | php | public static function isPngOrJpeg($FILE_DESCRIPTOR)
{
if ( !isset($FILE_DESCRIPTOR['name']) ) return false;
if ( !isset($FILE_DESCRIPTOR['tmp_name']) ) return false;
$info = getimagesize($FILE_DESCRIPTOR['tmp_name']);
if ( ! is_array($info) ) return false;
$image_type = $info[2];
return $image_type == IMAGETYPE_JPEG || $image_type == IMAGETYPE_PNG;
} | [
"public",
"static",
"function",
"isPngOrJpeg",
"(",
"$",
"FILE_DESCRIPTOR",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"FILE_DESCRIPTOR",
"[",
"'name'",
"]",
")",
")",
"return",
"false",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"FILE_DESCRIPTOR",
"[",
"'tmp_name'",
"]",
")",
")",
"return",
"false",
";",
"$",
"info",
"=",
"getimagesize",
"(",
"$",
"FILE_DESCRIPTOR",
"[",
"'tmp_name'",
"]",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"info",
")",
")",
"return",
"false",
";",
"$",
"image_type",
"=",
"$",
"info",
"[",
"2",
"]",
";",
"return",
"$",
"image_type",
"==",
"IMAGETYPE_JPEG",
"||",
"$",
"image_type",
"==",
"IMAGETYPE_PNG",
";",
"}"
]
| Make sure the contents of this file are a PNG or JPEG | [
"Make",
"sure",
"the",
"contents",
"of",
"this",
"file",
"are",
"a",
"PNG",
"or",
"JPEG"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Blob/BlobUtil.php#L111-L120 | train |
tsugiproject/tsugi-php | src/Blob/BlobUtil.php | BlobUtil.uploadToBlob | public static function uploadToBlob($FILE_DESCRIPTOR, $SAFETY_CHECK=true)
{
$retval = self::uploadFileToBlob($FILE_DESCRIPTOR, $SAFETY_CHECK);
if ( is_array($retval) ) $retval = $retval[0];
return $retval;
} | php | public static function uploadToBlob($FILE_DESCRIPTOR, $SAFETY_CHECK=true)
{
$retval = self::uploadFileToBlob($FILE_DESCRIPTOR, $SAFETY_CHECK);
if ( is_array($retval) ) $retval = $retval[0];
return $retval;
} | [
"public",
"static",
"function",
"uploadToBlob",
"(",
"$",
"FILE_DESCRIPTOR",
",",
"$",
"SAFETY_CHECK",
"=",
"true",
")",
"{",
"$",
"retval",
"=",
"self",
"::",
"uploadFileToBlob",
"(",
"$",
"FILE_DESCRIPTOR",
",",
"$",
"SAFETY_CHECK",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"retval",
")",
")",
"$",
"retval",
"=",
"$",
"retval",
"[",
"0",
"]",
";",
"return",
"$",
"retval",
";",
"}"
]
| uploadToBlob - returns blob_id or false
Returns false for any number of failures, for better detail, use
validateUpload() before calling this to do the actual upload. | [
"uploadToBlob",
"-",
"returns",
"blob_id",
"or",
"false"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Blob/BlobUtil.php#L171-L176 | train |
tsugiproject/tsugi-php | src/Blob/BlobUtil.php | BlobUtil.migrate | public static function migrate($file_id, $test_key=false)
{
global $CFG, $PDOX;
$retval = false;
// Check to see where we are moving to...
if ( isset($CFG->dataroot) && strlen($CFG->dataroot) > 0 ) {
if ( ! $test_key ) {
$retval = self::blob2file($file_id);
}
} else {
$retval = self::blob2blob($file_id);
}
return $retval;
} | php | public static function migrate($file_id, $test_key=false)
{
global $CFG, $PDOX;
$retval = false;
// Check to see where we are moving to...
if ( isset($CFG->dataroot) && strlen($CFG->dataroot) > 0 ) {
if ( ! $test_key ) {
$retval = self::blob2file($file_id);
}
} else {
$retval = self::blob2blob($file_id);
}
return $retval;
} | [
"public",
"static",
"function",
"migrate",
"(",
"$",
"file_id",
",",
"$",
"test_key",
"=",
"false",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"PDOX",
";",
"$",
"retval",
"=",
"false",
";",
"// Check to see where we are moving to...",
"if",
"(",
"isset",
"(",
"$",
"CFG",
"->",
"dataroot",
")",
"&&",
"strlen",
"(",
"$",
"CFG",
"->",
"dataroot",
")",
">",
"0",
")",
"{",
"if",
"(",
"!",
"$",
"test_key",
")",
"{",
"$",
"retval",
"=",
"self",
"::",
"blob2file",
"(",
"$",
"file_id",
")",
";",
"}",
"}",
"else",
"{",
"$",
"retval",
"=",
"self",
"::",
"blob2blob",
"(",
"$",
"file_id",
")",
";",
"}",
"return",
"$",
"retval",
";",
"}"
]
| Check and migrate a blob from an old place to the right new place
@return mixed true if the file was migrated, false if the file
was not migrated, and a string if an error was enountered | [
"Check",
"and",
"migrate",
"a",
"blob",
"from",
"an",
"old",
"place",
"to",
"the",
"right",
"new",
"place"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Blob/BlobUtil.php#L339-L354 | train |
tsugiproject/tsugi-php | src/Blob/BlobUtil.php | BlobUtil.blob2file | public static function blob2file($file_id)
{
global $CFG, $PDOX;
if ( !isset($CFG->dataroot) || strlen($CFG->dataroot) < 1 ) return;
$stmt = $PDOX->prepare("SELECT file_sha256, blob_id
FROM {$CFG->dbprefix}blob_file
WHERE path IS NULL AND file_id = :ID");
$stmt->execute(array(':ID' => $file_id));
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
if ( ! $row ) return false;
$blob_id = $row['blob_id'];
$file_sha256 = $row['file_sha256'];
$blob_folder = BlobUtil::mkdirSha256($file_sha256);
if ( ! $blob_folder ) {
return "Error: migrate=$file_id folder failed sha=$file_sha256";
}
$blob_name = $blob_folder . '/' . $file_sha256;
$lob = false;
if ( ! $blob_id ) {
// Cope gracefully when there is no content column in blob_file
try {
$lstmt = $PDOX->prepare("SELECT content FROM {$CFG->dbprefix}blob_file WHERE file_id = :ID");
$lstmt->execute(array(":ID" => $file_id));
$lstmt->bindColumn(1, $lob, \PDO::PARAM_LOB);
$lstmt->fetch(\PDO::FETCH_BOUND);
} catch (\Exception $e) {
return "Error: No content to migrate for legacy blob file_id=$file_id";
}
} else {
$lstmt = $PDOX->prepare("SELECT content FROM {$CFG->dbprefix}blob_blob WHERE blob_id = :ID");
$lstmt->execute(array(":ID" => $blob_id));
$lstmt->bindColumn(1, $lob, \PDO::PARAM_LOB);
$lstmt->fetch(\PDO::FETCH_BOUND);
}
if ( ! is_string($lob) ) {
return "Error: LOB is not a string. fi=$file_id bi=$blob_id";
}
$retval = file_put_contents($blob_name, $lob);
if ( $retval != strlen($lob) ) {
return "Error: Failed to write fi=$file_id (".strlen($lob).") to $blob_name";
}
error_log("Migrated fi=$file_id (".strlen($lob).") to $blob_name");
$lstmt = $PDOX->prepare("UPDATE {$CFG->dbprefix}blob_file
SET path=:PATH, blob_id=NULL WHERE file_id = :ID");
$lstmt->execute(array(
":ID" => $file_id,
":PATH" => $blob_name
));
// Make sure to handle the fact that content might not be there...
try {
$lstmt = $PDOX->prepare("UPDATE {$CFG->dbprefix}blob_file
SET content=NULL WHERE file_id = :ID");
$lstmt->execute(array( ":ID" => $file_id));
} catch (\Exception $e ) {
// No problem - the column won't be there...
}
return true;
} | php | public static function blob2file($file_id)
{
global $CFG, $PDOX;
if ( !isset($CFG->dataroot) || strlen($CFG->dataroot) < 1 ) return;
$stmt = $PDOX->prepare("SELECT file_sha256, blob_id
FROM {$CFG->dbprefix}blob_file
WHERE path IS NULL AND file_id = :ID");
$stmt->execute(array(':ID' => $file_id));
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
if ( ! $row ) return false;
$blob_id = $row['blob_id'];
$file_sha256 = $row['file_sha256'];
$blob_folder = BlobUtil::mkdirSha256($file_sha256);
if ( ! $blob_folder ) {
return "Error: migrate=$file_id folder failed sha=$file_sha256";
}
$blob_name = $blob_folder . '/' . $file_sha256;
$lob = false;
if ( ! $blob_id ) {
// Cope gracefully when there is no content column in blob_file
try {
$lstmt = $PDOX->prepare("SELECT content FROM {$CFG->dbprefix}blob_file WHERE file_id = :ID");
$lstmt->execute(array(":ID" => $file_id));
$lstmt->bindColumn(1, $lob, \PDO::PARAM_LOB);
$lstmt->fetch(\PDO::FETCH_BOUND);
} catch (\Exception $e) {
return "Error: No content to migrate for legacy blob file_id=$file_id";
}
} else {
$lstmt = $PDOX->prepare("SELECT content FROM {$CFG->dbprefix}blob_blob WHERE blob_id = :ID");
$lstmt->execute(array(":ID" => $blob_id));
$lstmt->bindColumn(1, $lob, \PDO::PARAM_LOB);
$lstmt->fetch(\PDO::FETCH_BOUND);
}
if ( ! is_string($lob) ) {
return "Error: LOB is not a string. fi=$file_id bi=$blob_id";
}
$retval = file_put_contents($blob_name, $lob);
if ( $retval != strlen($lob) ) {
return "Error: Failed to write fi=$file_id (".strlen($lob).") to $blob_name";
}
error_log("Migrated fi=$file_id (".strlen($lob).") to $blob_name");
$lstmt = $PDOX->prepare("UPDATE {$CFG->dbprefix}blob_file
SET path=:PATH, blob_id=NULL WHERE file_id = :ID");
$lstmt->execute(array(
":ID" => $file_id,
":PATH" => $blob_name
));
// Make sure to handle the fact that content might not be there...
try {
$lstmt = $PDOX->prepare("UPDATE {$CFG->dbprefix}blob_file
SET content=NULL WHERE file_id = :ID");
$lstmt->execute(array( ":ID" => $file_id));
} catch (\Exception $e ) {
// No problem - the column won't be there...
}
return true;
} | [
"public",
"static",
"function",
"blob2file",
"(",
"$",
"file_id",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"PDOX",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"CFG",
"->",
"dataroot",
")",
"||",
"strlen",
"(",
"$",
"CFG",
"->",
"dataroot",
")",
"<",
"1",
")",
"return",
";",
"$",
"stmt",
"=",
"$",
"PDOX",
"->",
"prepare",
"(",
"\"SELECT file_sha256, blob_id\n FROM {$CFG->dbprefix}blob_file\n WHERE path IS NULL AND file_id = :ID\"",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"array",
"(",
"':ID'",
"=>",
"$",
"file_id",
")",
")",
";",
"$",
"row",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"if",
"(",
"!",
"$",
"row",
")",
"return",
"false",
";",
"$",
"blob_id",
"=",
"$",
"row",
"[",
"'blob_id'",
"]",
";",
"$",
"file_sha256",
"=",
"$",
"row",
"[",
"'file_sha256'",
"]",
";",
"$",
"blob_folder",
"=",
"BlobUtil",
"::",
"mkdirSha256",
"(",
"$",
"file_sha256",
")",
";",
"if",
"(",
"!",
"$",
"blob_folder",
")",
"{",
"return",
"\"Error: migrate=$file_id folder failed sha=$file_sha256\"",
";",
"}",
"$",
"blob_name",
"=",
"$",
"blob_folder",
".",
"'/'",
".",
"$",
"file_sha256",
";",
"$",
"lob",
"=",
"false",
";",
"if",
"(",
"!",
"$",
"blob_id",
")",
"{",
"// Cope gracefully when there is no content column in blob_file",
"try",
"{",
"$",
"lstmt",
"=",
"$",
"PDOX",
"->",
"prepare",
"(",
"\"SELECT content FROM {$CFG->dbprefix}blob_file WHERE file_id = :ID\"",
")",
";",
"$",
"lstmt",
"->",
"execute",
"(",
"array",
"(",
"\":ID\"",
"=>",
"$",
"file_id",
")",
")",
";",
"$",
"lstmt",
"->",
"bindColumn",
"(",
"1",
",",
"$",
"lob",
",",
"\\",
"PDO",
"::",
"PARAM_LOB",
")",
";",
"$",
"lstmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_BOUND",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"\"Error: No content to migrate for legacy blob file_id=$file_id\"",
";",
"}",
"}",
"else",
"{",
"$",
"lstmt",
"=",
"$",
"PDOX",
"->",
"prepare",
"(",
"\"SELECT content FROM {$CFG->dbprefix}blob_blob WHERE blob_id = :ID\"",
")",
";",
"$",
"lstmt",
"->",
"execute",
"(",
"array",
"(",
"\":ID\"",
"=>",
"$",
"blob_id",
")",
")",
";",
"$",
"lstmt",
"->",
"bindColumn",
"(",
"1",
",",
"$",
"lob",
",",
"\\",
"PDO",
"::",
"PARAM_LOB",
")",
";",
"$",
"lstmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_BOUND",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"lob",
")",
")",
"{",
"return",
"\"Error: LOB is not a string. fi=$file_id bi=$blob_id\"",
";",
"}",
"$",
"retval",
"=",
"file_put_contents",
"(",
"$",
"blob_name",
",",
"$",
"lob",
")",
";",
"if",
"(",
"$",
"retval",
"!=",
"strlen",
"(",
"$",
"lob",
")",
")",
"{",
"return",
"\"Error: Failed to write fi=$file_id (\"",
".",
"strlen",
"(",
"$",
"lob",
")",
".",
"\") to $blob_name\"",
";",
"}",
"error_log",
"(",
"\"Migrated fi=$file_id (\"",
".",
"strlen",
"(",
"$",
"lob",
")",
".",
"\") to $blob_name\"",
")",
";",
"$",
"lstmt",
"=",
"$",
"PDOX",
"->",
"prepare",
"(",
"\"UPDATE {$CFG->dbprefix}blob_file\n SET path=:PATH, blob_id=NULL WHERE file_id = :ID\"",
")",
";",
"$",
"lstmt",
"->",
"execute",
"(",
"array",
"(",
"\":ID\"",
"=>",
"$",
"file_id",
",",
"\":PATH\"",
"=>",
"$",
"blob_name",
")",
")",
";",
"// Make sure to handle the fact that content might not be there...",
"try",
"{",
"$",
"lstmt",
"=",
"$",
"PDOX",
"->",
"prepare",
"(",
"\"UPDATE {$CFG->dbprefix}blob_file\n SET content=NULL WHERE file_id = :ID\"",
")",
";",
"$",
"lstmt",
"->",
"execute",
"(",
"array",
"(",
"\":ID\"",
"=>",
"$",
"file_id",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// No problem - the column won't be there...",
"}",
"return",
"true",
";",
"}"
]
| Check and migrate a blob to its corresponding file
@return mixed true if the file was migrated, false if the file
was not migrated, and a string if an error was enountered | [
"Check",
"and",
"migrate",
"a",
"blob",
"to",
"its",
"corresponding",
"file"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Blob/BlobUtil.php#L445-L510 | train |
tsugiproject/tsugi-php | src/Core/Activity.php | Activity.pushCaliperEvents | public static function pushCaliperEvents($seconds=3, $max=100, $debug=false) {
// Remove broken events
$purged = self::purgeCaliperEvents();
$start = time();
$count = 0;
$now = $start;
$end = $start + $seconds;
$failure = 0;
$failure_code = false;
$retval = array();
if ( U::apcAvailable() ) {
$found = false;
$last_push = apc_fetch('last_event_push_time',$found);
$diff = $start - $last_push;
if ( $found && $diff < self::PUSH_REPEAT_SECONDS ) {
// error_log("Last push was $diff seconds ago");
$retval['count'] = $count;
$retval['fail'] = $failure;
$retval['failcode'] = 999;
$retval['seconds'] = 0;
$retval['purged'] = $purged;
return $retval;
}
apc_store('last_event_push_time',$start);
}
while ($count < $max && $now < $end ) {
$result = self::sendCaliperEvent(!$debug);
if ( $debug ) {
echo("\nResults of sendCaliperEvent:\n");
echo(U::safe_var_dump($result));
}
if ( $result === false ) break;
if ( $result['code'] != 200 ) {
$failure++;
if ( $failure_code === false ) $failure_code = $result['code'];
}
$count++;
$now = time();
$delta = $now - $start;
}
$now = time();
$delta = $now - $start;
$retval['count'] = $count;
$retval['fail'] = $failure;
if ( $failure_code !== false ) $retval['failcode'] = $failure_code;
$retval['seconds'] = $delta;
$retval['purged'] = $purged;
return $retval;
} | php | public static function pushCaliperEvents($seconds=3, $max=100, $debug=false) {
// Remove broken events
$purged = self::purgeCaliperEvents();
$start = time();
$count = 0;
$now = $start;
$end = $start + $seconds;
$failure = 0;
$failure_code = false;
$retval = array();
if ( U::apcAvailable() ) {
$found = false;
$last_push = apc_fetch('last_event_push_time',$found);
$diff = $start - $last_push;
if ( $found && $diff < self::PUSH_REPEAT_SECONDS ) {
// error_log("Last push was $diff seconds ago");
$retval['count'] = $count;
$retval['fail'] = $failure;
$retval['failcode'] = 999;
$retval['seconds'] = 0;
$retval['purged'] = $purged;
return $retval;
}
apc_store('last_event_push_time',$start);
}
while ($count < $max && $now < $end ) {
$result = self::sendCaliperEvent(!$debug);
if ( $debug ) {
echo("\nResults of sendCaliperEvent:\n");
echo(U::safe_var_dump($result));
}
if ( $result === false ) break;
if ( $result['code'] != 200 ) {
$failure++;
if ( $failure_code === false ) $failure_code = $result['code'];
}
$count++;
$now = time();
$delta = $now - $start;
}
$now = time();
$delta = $now - $start;
$retval['count'] = $count;
$retval['fail'] = $failure;
if ( $failure_code !== false ) $retval['failcode'] = $failure_code;
$retval['seconds'] = $delta;
$retval['purged'] = $purged;
return $retval;
} | [
"public",
"static",
"function",
"pushCaliperEvents",
"(",
"$",
"seconds",
"=",
"3",
",",
"$",
"max",
"=",
"100",
",",
"$",
"debug",
"=",
"false",
")",
"{",
"// Remove broken events",
"$",
"purged",
"=",
"self",
"::",
"purgeCaliperEvents",
"(",
")",
";",
"$",
"start",
"=",
"time",
"(",
")",
";",
"$",
"count",
"=",
"0",
";",
"$",
"now",
"=",
"$",
"start",
";",
"$",
"end",
"=",
"$",
"start",
"+",
"$",
"seconds",
";",
"$",
"failure",
"=",
"0",
";",
"$",
"failure_code",
"=",
"false",
";",
"$",
"retval",
"=",
"array",
"(",
")",
";",
"if",
"(",
"U",
"::",
"apcAvailable",
"(",
")",
")",
"{",
"$",
"found",
"=",
"false",
";",
"$",
"last_push",
"=",
"apc_fetch",
"(",
"'last_event_push_time'",
",",
"$",
"found",
")",
";",
"$",
"diff",
"=",
"$",
"start",
"-",
"$",
"last_push",
";",
"if",
"(",
"$",
"found",
"&&",
"$",
"diff",
"<",
"self",
"::",
"PUSH_REPEAT_SECONDS",
")",
"{",
"// error_log(\"Last push was $diff seconds ago\");",
"$",
"retval",
"[",
"'count'",
"]",
"=",
"$",
"count",
";",
"$",
"retval",
"[",
"'fail'",
"]",
"=",
"$",
"failure",
";",
"$",
"retval",
"[",
"'failcode'",
"]",
"=",
"999",
";",
"$",
"retval",
"[",
"'seconds'",
"]",
"=",
"0",
";",
"$",
"retval",
"[",
"'purged'",
"]",
"=",
"$",
"purged",
";",
"return",
"$",
"retval",
";",
"}",
"apc_store",
"(",
"'last_event_push_time'",
",",
"$",
"start",
")",
";",
"}",
"while",
"(",
"$",
"count",
"<",
"$",
"max",
"&&",
"$",
"now",
"<",
"$",
"end",
")",
"{",
"$",
"result",
"=",
"self",
"::",
"sendCaliperEvent",
"(",
"!",
"$",
"debug",
")",
";",
"if",
"(",
"$",
"debug",
")",
"{",
"echo",
"(",
"\"\\nResults of sendCaliperEvent:\\n\"",
")",
";",
"echo",
"(",
"U",
"::",
"safe_var_dump",
"(",
"$",
"result",
")",
")",
";",
"}",
"if",
"(",
"$",
"result",
"===",
"false",
")",
"break",
";",
"if",
"(",
"$",
"result",
"[",
"'code'",
"]",
"!=",
"200",
")",
"{",
"$",
"failure",
"++",
";",
"if",
"(",
"$",
"failure_code",
"===",
"false",
")",
"$",
"failure_code",
"=",
"$",
"result",
"[",
"'code'",
"]",
";",
"}",
"$",
"count",
"++",
";",
"$",
"now",
"=",
"time",
"(",
")",
";",
"$",
"delta",
"=",
"$",
"now",
"-",
"$",
"start",
";",
"}",
"$",
"now",
"=",
"time",
"(",
")",
";",
"$",
"delta",
"=",
"$",
"now",
"-",
"$",
"start",
";",
"$",
"retval",
"[",
"'count'",
"]",
"=",
"$",
"count",
";",
"$",
"retval",
"[",
"'fail'",
"]",
"=",
"$",
"failure",
";",
"if",
"(",
"$",
"failure_code",
"!==",
"false",
")",
"$",
"retval",
"[",
"'failcode'",
"]",
"=",
"$",
"failure_code",
";",
"$",
"retval",
"[",
"'seconds'",
"]",
"=",
"$",
"delta",
";",
"$",
"retval",
"[",
"'purged'",
"]",
"=",
"$",
"purged",
";",
"return",
"$",
"retval",
";",
"}"
]
| Send the backlog of caliper events, but don't overrun | [
"Send",
"the",
"backlog",
"of",
"caliper",
"events",
"but",
"don",
"t",
"overrun"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Activity.php#L21-L73 | train |
tsugiproject/tsugi-php | src/Core/Activity.php | Activity.purgeCaliperEvents | public static function purgeCaliperEvents() {
global $CFG;
// We really want some quiet time...
if ( U::apcAvailable() ) {
$push_found = false;
$last_push = apc_fetch('last_event_push_time',$push_found);
$push_diff = time() - $last_push;
$purge_found = false;
$last_purge = apc_fetch('last_event_purge_time',$purge_found);
$purge_diff = time() - $last_purge;
if ( ($push_found && $push_diff < self::PUSH_REPEAT_SECONDS) ||
($purge_found && $purge_diff < self::PURGE_REPEAT_SECONDS) ) {
// error_log("Last purge was $purge_diff seconds ago last push was $push_diff seconds ago");
return 0;
}
apc_store('last_event_purge_time', time());
} else { // purge probabilistically
$check = isset($CFG->eventcheck) ? $CFG->eventcheck : 1000;
if ( $check < 1 ) $check = 1000;
if ( time() % $check !== 0 ) return 0;
}
$eventtime = isset($CFG->eventtime) ? $CFG->eventtime : 24*60*60; // one day
$PDOX = LTIX::getConnection();
$stmt = $PDOX->queryDie("DELETE FROM {$CFG->dbprefix}cal_event WHERE
created_at < DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL -{$eventtime} SECOND)");
if ( $stmt->rowCount() > 0 ) {
error_log("Event table cleanup rows=".$stmt->rowCount());
}
return $stmt->rowCount();
} | php | public static function purgeCaliperEvents() {
global $CFG;
// We really want some quiet time...
if ( U::apcAvailable() ) {
$push_found = false;
$last_push = apc_fetch('last_event_push_time',$push_found);
$push_diff = time() - $last_push;
$purge_found = false;
$last_purge = apc_fetch('last_event_purge_time',$purge_found);
$purge_diff = time() - $last_purge;
if ( ($push_found && $push_diff < self::PUSH_REPEAT_SECONDS) ||
($purge_found && $purge_diff < self::PURGE_REPEAT_SECONDS) ) {
// error_log("Last purge was $purge_diff seconds ago last push was $push_diff seconds ago");
return 0;
}
apc_store('last_event_purge_time', time());
} else { // purge probabilistically
$check = isset($CFG->eventcheck) ? $CFG->eventcheck : 1000;
if ( $check < 1 ) $check = 1000;
if ( time() % $check !== 0 ) return 0;
}
$eventtime = isset($CFG->eventtime) ? $CFG->eventtime : 24*60*60; // one day
$PDOX = LTIX::getConnection();
$stmt = $PDOX->queryDie("DELETE FROM {$CFG->dbprefix}cal_event WHERE
created_at < DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL -{$eventtime} SECOND)");
if ( $stmt->rowCount() > 0 ) {
error_log("Event table cleanup rows=".$stmt->rowCount());
}
return $stmt->rowCount();
} | [
"public",
"static",
"function",
"purgeCaliperEvents",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"// We really want some quiet time...",
"if",
"(",
"U",
"::",
"apcAvailable",
"(",
")",
")",
"{",
"$",
"push_found",
"=",
"false",
";",
"$",
"last_push",
"=",
"apc_fetch",
"(",
"'last_event_push_time'",
",",
"$",
"push_found",
")",
";",
"$",
"push_diff",
"=",
"time",
"(",
")",
"-",
"$",
"last_push",
";",
"$",
"purge_found",
"=",
"false",
";",
"$",
"last_purge",
"=",
"apc_fetch",
"(",
"'last_event_purge_time'",
",",
"$",
"purge_found",
")",
";",
"$",
"purge_diff",
"=",
"time",
"(",
")",
"-",
"$",
"last_purge",
";",
"if",
"(",
"(",
"$",
"push_found",
"&&",
"$",
"push_diff",
"<",
"self",
"::",
"PUSH_REPEAT_SECONDS",
")",
"||",
"(",
"$",
"purge_found",
"&&",
"$",
"purge_diff",
"<",
"self",
"::",
"PURGE_REPEAT_SECONDS",
")",
")",
"{",
"// error_log(\"Last purge was $purge_diff seconds ago last push was $push_diff seconds ago\");",
"return",
"0",
";",
"}",
"apc_store",
"(",
"'last_event_purge_time'",
",",
"time",
"(",
")",
")",
";",
"}",
"else",
"{",
"// purge probabilistically",
"$",
"check",
"=",
"isset",
"(",
"$",
"CFG",
"->",
"eventcheck",
")",
"?",
"$",
"CFG",
"->",
"eventcheck",
":",
"1000",
";",
"if",
"(",
"$",
"check",
"<",
"1",
")",
"$",
"check",
"=",
"1000",
";",
"if",
"(",
"time",
"(",
")",
"%",
"$",
"check",
"!==",
"0",
")",
"return",
"0",
";",
"}",
"$",
"eventtime",
"=",
"isset",
"(",
"$",
"CFG",
"->",
"eventtime",
")",
"?",
"$",
"CFG",
"->",
"eventtime",
":",
"24",
"*",
"60",
"*",
"60",
";",
"// one day",
"$",
"PDOX",
"=",
"LTIX",
"::",
"getConnection",
"(",
")",
";",
"$",
"stmt",
"=",
"$",
"PDOX",
"->",
"queryDie",
"(",
"\"DELETE FROM {$CFG->dbprefix}cal_event WHERE\n created_at < DATE_ADD(CURRENT_TIMESTAMP(), INTERVAL -{$eventtime} SECOND)\"",
")",
";",
"if",
"(",
"$",
"stmt",
"->",
"rowCount",
"(",
")",
">",
"0",
")",
"{",
"error_log",
"(",
"\"Event table cleanup rows=\"",
".",
"$",
"stmt",
"->",
"rowCount",
"(",
")",
")",
";",
"}",
"return",
"$",
"stmt",
"->",
"rowCount",
"(",
")",
";",
"}"
]
| Periodic cleanup of broken Caliper events
This is needed when an lti_key has Caliper turned on for a while
and then later turns it off - the non-pushed events are stranded
since they no longer have a good caliper_url / caliper_key. So
once in a great while, we clean these up. | [
"Periodic",
"cleanup",
"of",
"broken",
"Caliper",
"events"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Activity.php#L83-L120 | train |
Rxnet/eventstore-client | src/Rxnet/EventStore/EventStore.php | EventStore.heartbeat | protected function heartbeat(): DisposableInterface
{
return $this->readBuffer
->timeout($this->heartBeatRate)
->filter(
function (SocketMessage $message) {
return $message->getMessageType()->getType() === MessageType::HEARTBEAT_REQUEST_COMMAND;
}
)
->subscribe(
new CallbackObserver(
function (SocketMessage $message) {
$this->writer->composeAndWrite(MessageType::HEARTBEAT_RESPONSE_COMMAND, null, $message->getCorrelationID());
},
[$this->connectionSubject, 'onError']
)
);
} | php | protected function heartbeat(): DisposableInterface
{
return $this->readBuffer
->timeout($this->heartBeatRate)
->filter(
function (SocketMessage $message) {
return $message->getMessageType()->getType() === MessageType::HEARTBEAT_REQUEST_COMMAND;
}
)
->subscribe(
new CallbackObserver(
function (SocketMessage $message) {
$this->writer->composeAndWrite(MessageType::HEARTBEAT_RESPONSE_COMMAND, null, $message->getCorrelationID());
},
[$this->connectionSubject, 'onError']
)
);
} | [
"protected",
"function",
"heartbeat",
"(",
")",
":",
"DisposableInterface",
"{",
"return",
"$",
"this",
"->",
"readBuffer",
"->",
"timeout",
"(",
"$",
"this",
"->",
"heartBeatRate",
")",
"->",
"filter",
"(",
"function",
"(",
"SocketMessage",
"$",
"message",
")",
"{",
"return",
"$",
"message",
"->",
"getMessageType",
"(",
")",
"->",
"getType",
"(",
")",
"===",
"MessageType",
"::",
"HEARTBEAT_REQUEST_COMMAND",
";",
"}",
")",
"->",
"subscribe",
"(",
"new",
"CallbackObserver",
"(",
"function",
"(",
"SocketMessage",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"writer",
"->",
"composeAndWrite",
"(",
"MessageType",
"::",
"HEARTBEAT_RESPONSE_COMMAND",
",",
"null",
",",
"$",
"message",
"->",
"getCorrelationID",
"(",
")",
")",
";",
"}",
",",
"[",
"$",
"this",
"->",
"connectionSubject",
",",
"'onError'",
"]",
")",
")",
";",
"}"
]
| Intercept heartbeat message and answer automatically | [
"Intercept",
"heartbeat",
"message",
"and",
"answer",
"automatically"
]
| ec4c4f3dd97c78e4a6f476178851a61acfa73975 | https://github.com/Rxnet/eventstore-client/blob/ec4c4f3dd97c78e4a6f476178851a61acfa73975/src/Rxnet/EventStore/EventStore.php#L188-L205 | train |
Rxnet/eventstore-client | src/Rxnet/EventStore/EventStore.php | EventStore.catchUpSubscription | public function catchUpSubscription(
string $streamId,
int $startFrom = self::POSITION_START,
bool $resolveLink = false
): Observable {
return $this->readEventsForward($streamId, $startFrom, self::DEFAULT_MAX_EVENTS, $resolveLink)
->concat($this->volatileSubscription($streamId, $resolveLink));
} | php | public function catchUpSubscription(
string $streamId,
int $startFrom = self::POSITION_START,
bool $resolveLink = false
): Observable {
return $this->readEventsForward($streamId, $startFrom, self::DEFAULT_MAX_EVENTS, $resolveLink)
->concat($this->volatileSubscription($streamId, $resolveLink));
} | [
"public",
"function",
"catchUpSubscription",
"(",
"string",
"$",
"streamId",
",",
"int",
"$",
"startFrom",
"=",
"self",
"::",
"POSITION_START",
",",
"bool",
"$",
"resolveLink",
"=",
"false",
")",
":",
"Observable",
"{",
"return",
"$",
"this",
"->",
"readEventsForward",
"(",
"$",
"streamId",
",",
"$",
"startFrom",
",",
"self",
"::",
"DEFAULT_MAX_EVENTS",
",",
"$",
"resolveLink",
")",
"->",
"concat",
"(",
"$",
"this",
"->",
"volatileSubscription",
"(",
"$",
"streamId",
",",
"$",
"resolveLink",
")",
")",
";",
"}"
]
| This kind of subscription specifies a starting point, in the form of an event number
or transaction file position.
The given function will be called for events from the starting point until the end of the stream,
and then for subsequently written events.
For example, if a starting point of 50 is specified when a stream has 100 events in it,
the subscriber can expect to see events 51 through 100, and then any events subsequently
written until such time as the subscription is dropped or closed.
@throws \Exception | [
"This",
"kind",
"of",
"subscription",
"specifies",
"a",
"starting",
"point",
"in",
"the",
"form",
"of",
"an",
"event",
"number",
"or",
"transaction",
"file",
"position",
".",
"The",
"given",
"function",
"will",
"be",
"called",
"for",
"events",
"from",
"the",
"starting",
"point",
"until",
"the",
"end",
"of",
"the",
"stream",
"and",
"then",
"for",
"subsequently",
"written",
"events",
"."
]
| ec4c4f3dd97c78e4a6f476178851a61acfa73975 | https://github.com/Rxnet/eventstore-client/blob/ec4c4f3dd97c78e4a6f476178851a61acfa73975/src/Rxnet/EventStore/EventStore.php#L272-L279 | train |
Rxnet/eventstore-client | src/Rxnet/EventStore/EventStore.php | EventStore.volatileSubscription | public function volatileSubscription(string $streamId, bool $resolveLink = false): Observable
{
$event = new SubscribeToStream();
$event->setEventStreamId($streamId);
$event->setResolveLinkTos($resolveLink);
return Observable::create(function (ObserverInterface $observer) use ($event) {
$correlationID = $this->writer->createUUIDIfNeeded();
$this->writer
->composeAndWrite(
MessageType::SUBSCRIBE_TO_STREAM,
$event,
$correlationID
)
// When written wait for all responses
->merge(
$this->readBuffer
->filter(
function (SocketMessage $message) use ($correlationID) {
// Use same correlationID to pass by this filter
return $message->getCorrelationID() == $correlationID;
}
)
)
->flatMap(
function (SocketMessage $message) {
$data = $message->getData();
if (!$data) {
throw new \RuntimeException('Data should not be null in volatile subscription');
}
switch (get_class($data)) {
case SubscriptionDropped::class:
return Observable::error(new \Exception("Subscription dropped, for reason : {$data->getReason()}"));
case SubscriptionConfirmation::class:
return Observable::empty();
default:
return Observable::of($data);
}
}
)
->map(
function (StreamEventAppeared $eventAppeared) {
$record = $eventAppeared->getEvent()->getEvent();
/* @var \Rxnet\EventStore\Data\EventRecord $record */
return EventRecordFactory::fromEventRecord($record);
}
)
->subscribe($observer);
return new CallbackDisposable(function () {
$event = new UnsubscribeFromStream();
$this->writer->composeAndWrite(
MessageType::UNSUBSCRIBE_FROM_STREAM,
$event
);
});
});
} | php | public function volatileSubscription(string $streamId, bool $resolveLink = false): Observable
{
$event = new SubscribeToStream();
$event->setEventStreamId($streamId);
$event->setResolveLinkTos($resolveLink);
return Observable::create(function (ObserverInterface $observer) use ($event) {
$correlationID = $this->writer->createUUIDIfNeeded();
$this->writer
->composeAndWrite(
MessageType::SUBSCRIBE_TO_STREAM,
$event,
$correlationID
)
// When written wait for all responses
->merge(
$this->readBuffer
->filter(
function (SocketMessage $message) use ($correlationID) {
// Use same correlationID to pass by this filter
return $message->getCorrelationID() == $correlationID;
}
)
)
->flatMap(
function (SocketMessage $message) {
$data = $message->getData();
if (!$data) {
throw new \RuntimeException('Data should not be null in volatile subscription');
}
switch (get_class($data)) {
case SubscriptionDropped::class:
return Observable::error(new \Exception("Subscription dropped, for reason : {$data->getReason()}"));
case SubscriptionConfirmation::class:
return Observable::empty();
default:
return Observable::of($data);
}
}
)
->map(
function (StreamEventAppeared $eventAppeared) {
$record = $eventAppeared->getEvent()->getEvent();
/* @var \Rxnet\EventStore\Data\EventRecord $record */
return EventRecordFactory::fromEventRecord($record);
}
)
->subscribe($observer);
return new CallbackDisposable(function () {
$event = new UnsubscribeFromStream();
$this->writer->composeAndWrite(
MessageType::UNSUBSCRIBE_FROM_STREAM,
$event
);
});
});
} | [
"public",
"function",
"volatileSubscription",
"(",
"string",
"$",
"streamId",
",",
"bool",
"$",
"resolveLink",
"=",
"false",
")",
":",
"Observable",
"{",
"$",
"event",
"=",
"new",
"SubscribeToStream",
"(",
")",
";",
"$",
"event",
"->",
"setEventStreamId",
"(",
"$",
"streamId",
")",
";",
"$",
"event",
"->",
"setResolveLinkTos",
"(",
"$",
"resolveLink",
")",
";",
"return",
"Observable",
"::",
"create",
"(",
"function",
"(",
"ObserverInterface",
"$",
"observer",
")",
"use",
"(",
"$",
"event",
")",
"{",
"$",
"correlationID",
"=",
"$",
"this",
"->",
"writer",
"->",
"createUUIDIfNeeded",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"composeAndWrite",
"(",
"MessageType",
"::",
"SUBSCRIBE_TO_STREAM",
",",
"$",
"event",
",",
"$",
"correlationID",
")",
"// When written wait for all responses",
"->",
"merge",
"(",
"$",
"this",
"->",
"readBuffer",
"->",
"filter",
"(",
"function",
"(",
"SocketMessage",
"$",
"message",
")",
"use",
"(",
"$",
"correlationID",
")",
"{",
"// Use same correlationID to pass by this filter",
"return",
"$",
"message",
"->",
"getCorrelationID",
"(",
")",
"==",
"$",
"correlationID",
";",
"}",
")",
")",
"->",
"flatMap",
"(",
"function",
"(",
"SocketMessage",
"$",
"message",
")",
"{",
"$",
"data",
"=",
"$",
"message",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"!",
"$",
"data",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Data should not be null in volatile subscription'",
")",
";",
"}",
"switch",
"(",
"get_class",
"(",
"$",
"data",
")",
")",
"{",
"case",
"SubscriptionDropped",
"::",
"class",
":",
"return",
"Observable",
"::",
"error",
"(",
"new",
"\\",
"Exception",
"(",
"\"Subscription dropped, for reason : {$data->getReason()}\"",
")",
")",
";",
"case",
"SubscriptionConfirmation",
"::",
"class",
":",
"return",
"Observable",
"::",
"empty",
"(",
")",
";",
"default",
":",
"return",
"Observable",
"::",
"of",
"(",
"$",
"data",
")",
";",
"}",
"}",
")",
"->",
"map",
"(",
"function",
"(",
"StreamEventAppeared",
"$",
"eventAppeared",
")",
"{",
"$",
"record",
"=",
"$",
"eventAppeared",
"->",
"getEvent",
"(",
")",
"->",
"getEvent",
"(",
")",
";",
"/* @var \\Rxnet\\EventStore\\Data\\EventRecord $record */",
"return",
"EventRecordFactory",
"::",
"fromEventRecord",
"(",
"$",
"record",
")",
";",
"}",
")",
"->",
"subscribe",
"(",
"$",
"observer",
")",
";",
"return",
"new",
"CallbackDisposable",
"(",
"function",
"(",
")",
"{",
"$",
"event",
"=",
"new",
"UnsubscribeFromStream",
"(",
")",
";",
"$",
"this",
"->",
"writer",
"->",
"composeAndWrite",
"(",
"MessageType",
"::",
"UNSUBSCRIBE_FROM_STREAM",
",",
"$",
"event",
")",
";",
"}",
")",
";",
"}",
")",
";",
"}"
]
| This kind of subscription calls a given function for events written after
the subscription is established.
For example, if a stream has 100 events in it when a subscriber connects,
the subscriber can expect to see event number 101 onwards until the time
the subscription is closed or dropped. | [
"This",
"kind",
"of",
"subscription",
"calls",
"a",
"given",
"function",
"for",
"events",
"written",
"after",
"the",
"subscription",
"is",
"established",
"."
]
| ec4c4f3dd97c78e4a6f476178851a61acfa73975 | https://github.com/Rxnet/eventstore-client/blob/ec4c4f3dd97c78e4a6f476178851a61acfa73975/src/Rxnet/EventStore/EventStore.php#L289-L349 | train |
rokka-io/rokka-client-php | src/Core/DynamicMetadata/MultiAreas.php | MultiAreas.getAreasByName | public function getAreasByName($name)
{
if (!isset($this->areas[$name])) {
return null;
}
return $this->areas[$name];
} | php | public function getAreasByName($name)
{
if (!isset($this->areas[$name])) {
return null;
}
return $this->areas[$name];
} | [
"public",
"function",
"getAreasByName",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"areas",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"areas",
"[",
"$",
"name",
"]",
";",
"}"
]
| Gets an array of Areas with a specific name.
@param string $name The area name to look up
@return DynamicMetadataInterface[]|null | [
"Gets",
"an",
"array",
"of",
"Areas",
"with",
"a",
"specific",
"name",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Core/DynamicMetadata/MultiAreas.php#L47-L54 | train |
rokka-io/rokka-client-php | src/Core/DynamicMetadata/MultiAreas.php | MultiAreas.createFromDecodedJsonResponse | public static function createFromDecodedJsonResponse($data)
{
$areas = [];
foreach ($data as $name => $area) {
$areas[$name] = [];
foreach ($area as $class => $data) {
$metaClass = DynamicMetadataHelper::getDynamicMetadataClassName($class);
/* @var DynamicMetadataInterface $metaClass */
$areas[$name][] = $metaClass::createFromDecodedJsonResponse($data);
}
}
return new self($areas);
} | php | public static function createFromDecodedJsonResponse($data)
{
$areas = [];
foreach ($data as $name => $area) {
$areas[$name] = [];
foreach ($area as $class => $data) {
$metaClass = DynamicMetadataHelper::getDynamicMetadataClassName($class);
/* @var DynamicMetadataInterface $metaClass */
$areas[$name][] = $metaClass::createFromDecodedJsonResponse($data);
}
}
return new self($areas);
} | [
"public",
"static",
"function",
"createFromDecodedJsonResponse",
"(",
"$",
"data",
")",
"{",
"$",
"areas",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"as",
"$",
"name",
"=>",
"$",
"area",
")",
"{",
"$",
"areas",
"[",
"$",
"name",
"]",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"area",
"as",
"$",
"class",
"=>",
"$",
"data",
")",
"{",
"$",
"metaClass",
"=",
"DynamicMetadataHelper",
"::",
"getDynamicMetadataClassName",
"(",
"$",
"class",
")",
";",
"/* @var DynamicMetadataInterface $metaClass */",
"$",
"areas",
"[",
"$",
"name",
"]",
"[",
"]",
"=",
"$",
"metaClass",
"::",
"createFromDecodedJsonResponse",
"(",
"$",
"data",
")",
";",
"}",
"}",
"return",
"new",
"self",
"(",
"$",
"areas",
")",
";",
"}"
]
| Create a DynamicMetadata from the decoded JSON data.
@param array $data Decoded JSON data
@return DynamicMetadataInterface | [
"Create",
"a",
"DynamicMetadata",
"from",
"the",
"decoded",
"JSON",
"data",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Core/DynamicMetadata/MultiAreas.php#L82-L95 | train |
tsugiproject/tsugi-php | src/Core/Link.php | Link.loadLinkInfo | public static function loadLinkInfo($link_id)
{
global $CFG, $PDOX, $CONTEXT;
$cacheloc = 'lti_link';
$row = Cache::check($cacheloc, $link_id);
if ( $row != false ) return $row;
$stmt = $PDOX->queryDie(
"SELECT title FROM {$CFG->dbprefix}lti_link
WHERE link_id = :LID AND context_id = :CID",
array(":LID" => $link_id, ":CID" => $CONTEXT->id)
);
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
Cache::set($cacheloc, $link_id, $row);
return $row;
} | php | public static function loadLinkInfo($link_id)
{
global $CFG, $PDOX, $CONTEXT;
$cacheloc = 'lti_link';
$row = Cache::check($cacheloc, $link_id);
if ( $row != false ) return $row;
$stmt = $PDOX->queryDie(
"SELECT title FROM {$CFG->dbprefix}lti_link
WHERE link_id = :LID AND context_id = :CID",
array(":LID" => $link_id, ":CID" => $CONTEXT->id)
);
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
Cache::set($cacheloc, $link_id, $row);
return $row;
} | [
"public",
"static",
"function",
"loadLinkInfo",
"(",
"$",
"link_id",
")",
"{",
"global",
"$",
"CFG",
",",
"$",
"PDOX",
",",
"$",
"CONTEXT",
";",
"$",
"cacheloc",
"=",
"'lti_link'",
";",
"$",
"row",
"=",
"Cache",
"::",
"check",
"(",
"$",
"cacheloc",
",",
"$",
"link_id",
")",
";",
"if",
"(",
"$",
"row",
"!=",
"false",
")",
"return",
"$",
"row",
";",
"$",
"stmt",
"=",
"$",
"PDOX",
"->",
"queryDie",
"(",
"\"SELECT title FROM {$CFG->dbprefix}lti_link\n WHERE link_id = :LID AND context_id = :CID\"",
",",
"array",
"(",
"\":LID\"",
"=>",
"$",
"link_id",
",",
"\":CID\"",
"=>",
"$",
"CONTEXT",
"->",
"id",
")",
")",
";",
"$",
"row",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"Cache",
"::",
"set",
"(",
"$",
"cacheloc",
",",
"$",
"link_id",
",",
"$",
"row",
")",
";",
"return",
"$",
"row",
";",
"}"
]
| Load link information for a different link than current
Make sure not to cross Context silos.
Returns a row or false. | [
"Load",
"link",
"information",
"for",
"a",
"different",
"link",
"than",
"current"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Link.php#L72-L87 | train |
tsugiproject/tsugi-php | src/Core/Link.php | Link.getPlacementSecret | public function getPlacementSecret()
{
global $CFG;
$PDOX = $this->launch->pdox;
$stmt = $PDOX->queryDie(
"SELECT placementsecret FROM {$CFG->dbprefix}lti_link
WHERE link_id = :LID",
array(':LID' => $this->id)
);
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
$placementsecret = $row['placementsecret'];
if ( $placementsecret) return $placementsecret;
// Set the placement secret
$placementsecret = bin2Hex(openssl_random_pseudo_bytes(32));
$stmt = $PDOX->queryDie(
"UPDATE {$CFG->dbprefix}lti_link SET placementsecret=:PC
WHERE link_id = :LID",
array(':LID' => $this->id,
':PC' => $placementsecret
)
);
return $placementsecret;
} | php | public function getPlacementSecret()
{
global $CFG;
$PDOX = $this->launch->pdox;
$stmt = $PDOX->queryDie(
"SELECT placementsecret FROM {$CFG->dbprefix}lti_link
WHERE link_id = :LID",
array(':LID' => $this->id)
);
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
$placementsecret = $row['placementsecret'];
if ( $placementsecret) return $placementsecret;
// Set the placement secret
$placementsecret = bin2Hex(openssl_random_pseudo_bytes(32));
$stmt = $PDOX->queryDie(
"UPDATE {$CFG->dbprefix}lti_link SET placementsecret=:PC
WHERE link_id = :LID",
array(':LID' => $this->id,
':PC' => $placementsecret
)
);
return $placementsecret;
} | [
"public",
"function",
"getPlacementSecret",
"(",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"PDOX",
"=",
"$",
"this",
"->",
"launch",
"->",
"pdox",
";",
"$",
"stmt",
"=",
"$",
"PDOX",
"->",
"queryDie",
"(",
"\"SELECT placementsecret FROM {$CFG->dbprefix}lti_link\n WHERE link_id = :LID\"",
",",
"array",
"(",
"':LID'",
"=>",
"$",
"this",
"->",
"id",
")",
")",
";",
"$",
"row",
"=",
"$",
"stmt",
"->",
"fetch",
"(",
"\\",
"PDO",
"::",
"FETCH_ASSOC",
")",
";",
"$",
"placementsecret",
"=",
"$",
"row",
"[",
"'placementsecret'",
"]",
";",
"if",
"(",
"$",
"placementsecret",
")",
"return",
"$",
"placementsecret",
";",
"// Set the placement secret",
"$",
"placementsecret",
"=",
"bin2Hex",
"(",
"openssl_random_pseudo_bytes",
"(",
"32",
")",
")",
";",
"$",
"stmt",
"=",
"$",
"PDOX",
"->",
"queryDie",
"(",
"\"UPDATE {$CFG->dbprefix}lti_link SET placementsecret=:PC\n WHERE link_id = :LID\"",
",",
"array",
"(",
"':LID'",
"=>",
"$",
"this",
"->",
"id",
",",
"':PC'",
"=>",
"$",
"placementsecret",
")",
")",
";",
"return",
"$",
"placementsecret",
";",
"}"
]
| Get the placement secret for this Link | [
"Get",
"the",
"placement",
"secret",
"for",
"this",
"Link"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Core/Link.php#L92-L117 | train |
tsugiproject/tsugi-php | src/Util/DeepLinkRequest.php | DeepLinkRequest.returnUrl | public function returnUrl() {
if ( ! isset($this->claim) ) return false;
return isset($this->claim->deep_link_return_url) ? $this->claim->deep_link_return_url : false;
} | php | public function returnUrl() {
if ( ! isset($this->claim) ) return false;
return isset($this->claim->deep_link_return_url) ? $this->claim->deep_link_return_url : false;
} | [
"public",
"function",
"returnUrl",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"claim",
")",
")",
"return",
"false",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"claim",
"->",
"deep_link_return_url",
")",
"?",
"$",
"this",
"->",
"claim",
"->",
"deep_link_return_url",
":",
"false",
";",
"}"
]
| returnUrl - Returns the deep_link_return_url
@return string The deep_link_return_url or false | [
"returnUrl",
"-",
"Returns",
"the",
"deep_link_return_url"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/DeepLinkRequest.php#L38-L41 | train |
tsugiproject/tsugi-php | src/Util/DeepLinkRequest.php | DeepLinkRequest.allowMimetype | public function allowMimetype($Mimetype) {
if ( ! $this->returnUrl() ) return false;
if ( isset($this->claim->accept_media_types) ) {
$ma = $Mimetype;
if ( ! is_array($ma) ) $ma = array($Mimetype);
$m = new Mimeparse;
$allowed = $m->best_match($ma, $this->claim->accept_media_types);
if ( $Mimetype != $allowed ) return false;
return true;
}
return false;
} | php | public function allowMimetype($Mimetype) {
if ( ! $this->returnUrl() ) return false;
if ( isset($this->claim->accept_media_types) ) {
$ma = $Mimetype;
if ( ! is_array($ma) ) $ma = array($Mimetype);
$m = new Mimeparse;
$allowed = $m->best_match($ma, $this->claim->accept_media_types);
if ( $Mimetype != $allowed ) return false;
return true;
}
return false;
} | [
"public",
"function",
"allowMimetype",
"(",
"$",
"Mimetype",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"returnUrl",
"(",
")",
")",
"return",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"claim",
"->",
"accept_media_types",
")",
")",
"{",
"$",
"ma",
"=",
"$",
"Mimetype",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"ma",
")",
")",
"$",
"ma",
"=",
"array",
"(",
"$",
"Mimetype",
")",
";",
"$",
"m",
"=",
"new",
"Mimeparse",
";",
"$",
"allowed",
"=",
"$",
"m",
"->",
"best_match",
"(",
"$",
"ma",
",",
"$",
"this",
"->",
"claim",
"->",
"accept_media_types",
")",
";",
"if",
"(",
"$",
"Mimetype",
"!=",
"$",
"allowed",
")",
"return",
"false",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| allowMimetype - Returns true if we can return LTI Link Items | [
"allowMimetype",
"-",
"Returns",
"true",
"if",
"we",
"can",
"return",
"LTI",
"Link",
"Items"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/DeepLinkRequest.php#L46-L57 | train |
tsugiproject/tsugi-php | src/Util/DeepLinkRequest.php | DeepLinkRequest.acceptType | public function acceptType($type) {
if ( ! isset($this->claim->accept_types) ) return false;
if ( ! is_array($this->claim->accept_types) ) return false;
return in_array($type, $this->claim->accept_types);
} | php | public function acceptType($type) {
if ( ! isset($this->claim->accept_types) ) return false;
if ( ! is_array($this->claim->accept_types) ) return false;
return in_array($type, $this->claim->accept_types);
} | [
"public",
"function",
"acceptType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"claim",
"->",
"accept_types",
")",
")",
"return",
"false",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"claim",
"->",
"accept_types",
")",
")",
"return",
"false",
";",
"return",
"in_array",
"(",
"$",
"type",
",",
"$",
"this",
"->",
"claim",
"->",
"accept_types",
")",
";",
"}"
]
| acceptType - Returns true if the string is in the accept_types
"accept_types": ["link", "file", "html", "ltiResourceLink", "image"], | [
"acceptType",
"-",
"Returns",
"true",
"if",
"the",
"string",
"is",
"in",
"the",
"accept_types"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/DeepLinkRequest.php#L64-L68 | train |
tsugiproject/tsugi-php | src/Config/ConfigInfo.php | ConfigInfo.getScriptFolder | function getScriptFolder() {
$path = self::getScriptPathFull();
if ( $path === false ) return false;
// Don't use DIRECTORY_SEPARATOR, PHP makes these forward slashes on Windows
$pieces = explode('/', $path);
if ( count($pieces) < 1 ) return false;
return $pieces[count($pieces)-1];
} | php | function getScriptFolder() {
$path = self::getScriptPathFull();
if ( $path === false ) return false;
// Don't use DIRECTORY_SEPARATOR, PHP makes these forward slashes on Windows
$pieces = explode('/', $path);
if ( count($pieces) < 1 ) return false;
return $pieces[count($pieces)-1];
} | [
"function",
"getScriptFolder",
"(",
")",
"{",
"$",
"path",
"=",
"self",
"::",
"getScriptPathFull",
"(",
")",
";",
"if",
"(",
"$",
"path",
"===",
"false",
")",
"return",
"false",
";",
"// Don't use DIRECTORY_SEPARATOR, PHP makes these forward slashes on Windows",
"$",
"pieces",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"if",
"(",
"count",
"(",
"$",
"pieces",
")",
"<",
"1",
")",
"return",
"false",
";",
"return",
"$",
"pieces",
"[",
"count",
"(",
"$",
"pieces",
")",
"-",
"1",
"]",
";",
"}"
]
| This function will return "attend" | [
"This",
"function",
"will",
"return",
"attend"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Config/ConfigInfo.php#L381-L388 | train |
tsugiproject/tsugi-php | src/Config/ConfigInfo.php | ConfigInfo.getPwd | function getPwd($file) {
$root = $this->dirroot;
$path = realpath(dirname($file));
$root .= '/'; // Add the trailing slash
if ( strlen($path) < strlen($root) ) return false;
// The root must be the prefix of path
if ( strpos($path, $root) !== 0 ) return false;
$retval = substr($path, strlen($root));
return $retval;
} | php | function getPwd($file) {
$root = $this->dirroot;
$path = realpath(dirname($file));
$root .= '/'; // Add the trailing slash
if ( strlen($path) < strlen($root) ) return false;
// The root must be the prefix of path
if ( strpos($path, $root) !== 0 ) return false;
$retval = substr($path, strlen($root));
return $retval;
} | [
"function",
"getPwd",
"(",
"$",
"file",
")",
"{",
"$",
"root",
"=",
"$",
"this",
"->",
"dirroot",
";",
"$",
"path",
"=",
"realpath",
"(",
"dirname",
"(",
"$",
"file",
")",
")",
";",
"$",
"root",
".=",
"'/'",
";",
"// Add the trailing slash",
"if",
"(",
"strlen",
"(",
"$",
"path",
")",
"<",
"strlen",
"(",
"$",
"root",
")",
")",
"return",
"false",
";",
"// The root must be the prefix of path",
"if",
"(",
"strpos",
"(",
"$",
"path",
",",
"$",
"root",
")",
"!==",
"0",
")",
"return",
"false",
";",
"$",
"retval",
"=",
"substr",
"(",
"$",
"path",
",",
"strlen",
"(",
"$",
"root",
")",
")",
";",
"return",
"$",
"retval",
";",
"}"
]
| Get the current working directory of a file | [
"Get",
"the",
"current",
"working",
"directory",
"of",
"a",
"file"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Config/ConfigInfo.php#L402-L411 | train |
tsugiproject/tsugi-php | src/Config/ConfigInfo.php | ConfigInfo.getCurrentUrl | public function getCurrentUrl() {
$script = self::getScriptName();
if ( $script === false ) return false;
$pieces = $this->apphome;
if ( $this->apphome ) {
$pieces = parse_url($this->apphome);
}
// We only take scheme, host, and port from wwwroot / apphome
if ( ! isset($pieces['scheme']) ) return false;
$retval = $pieces['scheme'].'://'.$pieces['host'];
if ( isset($pieces['port']) ) $retval .= ':'.$pieces['port'];
return $retval . $script;
} | php | public function getCurrentUrl() {
$script = self::getScriptName();
if ( $script === false ) return false;
$pieces = $this->apphome;
if ( $this->apphome ) {
$pieces = parse_url($this->apphome);
}
// We only take scheme, host, and port from wwwroot / apphome
if ( ! isset($pieces['scheme']) ) return false;
$retval = $pieces['scheme'].'://'.$pieces['host'];
if ( isset($pieces['port']) ) $retval .= ':'.$pieces['port'];
return $retval . $script;
} | [
"public",
"function",
"getCurrentUrl",
"(",
")",
"{",
"$",
"script",
"=",
"self",
"::",
"getScriptName",
"(",
")",
";",
"if",
"(",
"$",
"script",
"===",
"false",
")",
"return",
"false",
";",
"$",
"pieces",
"=",
"$",
"this",
"->",
"apphome",
";",
"if",
"(",
"$",
"this",
"->",
"apphome",
")",
"{",
"$",
"pieces",
"=",
"parse_url",
"(",
"$",
"this",
"->",
"apphome",
")",
";",
"}",
"// We only take scheme, host, and port from wwwroot / apphome",
"if",
"(",
"!",
"isset",
"(",
"$",
"pieces",
"[",
"'scheme'",
"]",
")",
")",
"return",
"false",
";",
"$",
"retval",
"=",
"$",
"pieces",
"[",
"'scheme'",
"]",
".",
"'://'",
".",
"$",
"pieces",
"[",
"'host'",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"pieces",
"[",
"'port'",
"]",
")",
")",
"$",
"retval",
".=",
"':'",
".",
"$",
"pieces",
"[",
"'port'",
"]",
";",
"return",
"$",
"retval",
".",
"$",
"script",
";",
"}"
]
| Get the current URL we are executing - no query parameters
http://localhost:8888/py4e/mod/peer-grade/maint.php | [
"Get",
"the",
"current",
"URL",
"we",
"are",
"executing",
"-",
"no",
"query",
"parameters"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Config/ConfigInfo.php#L451-L463 | train |
tsugiproject/tsugi-php | src/Config/ConfigInfo.php | ConfigInfo.getCurrentUrlFolder | public function getCurrentUrlFolder() {
$url = self::getCurrentUrl();
$pieces = explode('/', $url);
array_pop($pieces);
$retval = implode('/', $pieces);
return $retval;
} | php | public function getCurrentUrlFolder() {
$url = self::getCurrentUrl();
$pieces = explode('/', $url);
array_pop($pieces);
$retval = implode('/', $pieces);
return $retval;
} | [
"public",
"function",
"getCurrentUrlFolder",
"(",
")",
"{",
"$",
"url",
"=",
"self",
"::",
"getCurrentUrl",
"(",
")",
";",
"$",
"pieces",
"=",
"explode",
"(",
"'/'",
",",
"$",
"url",
")",
";",
"array_pop",
"(",
"$",
"pieces",
")",
";",
"$",
"retval",
"=",
"implode",
"(",
"'/'",
",",
"$",
"pieces",
")",
";",
"return",
"$",
"retval",
";",
"}"
]
| Get the current folder of the URL we are executing - no trailing slash
input: http://localhost:8888/py4e/mod/peer-grade/maint.php
output: http://localhost:8888/py4e/mod/peer-grade | [
"Get",
"the",
"current",
"folder",
"of",
"the",
"URL",
"we",
"are",
"executing",
"-",
"no",
"trailing",
"slash"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Config/ConfigInfo.php#L472-L478 | train |
tsugiproject/tsugi-php | src/Config/ConfigInfo.php | ConfigInfo.localhost | public function localhost() {
if ( strpos($this->wwwroot,'://localhost') !== false ) return true;
if ( strpos($this->wwwroot,'://127.0.0.1') !== false ) return true;
return false;
} | php | public function localhost() {
if ( strpos($this->wwwroot,'://localhost') !== false ) return true;
if ( strpos($this->wwwroot,'://127.0.0.1') !== false ) return true;
return false;
} | [
"public",
"function",
"localhost",
"(",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"wwwroot",
",",
"'://localhost'",
")",
"!==",
"false",
")",
"return",
"true",
";",
"if",
"(",
"strpos",
"(",
"$",
"this",
"->",
"wwwroot",
",",
"'://127.0.0.1'",
")",
"!==",
"false",
")",
"return",
"true",
";",
"return",
"false",
";",
"}"
]
| Are we on localhost? | [
"Are",
"we",
"on",
"localhost?"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Config/ConfigInfo.php#L483-L487 | train |
rokka-io/rokka-client-php | src/Core/SourceImage.php | SourceImage.createFromDecodedJsonResponse | public static function createFromDecodedJsonResponse($data)
{
if (!isset($data['user_metadata'])) {
$data['user_metadata'] = [];
} else {
foreach ($data['user_metadata'] as $key => $value) {
if (0 === strpos($key, 'date:')) {
$data['user_metadata'][$key] = new \DateTime($value);
}
}
}
if (!isset($data['static_metadata'])) {
$data['static_metadata'] = [];
}
$dynamic_metadata = [];
// Rebuild the DynamicMetadata associated to the current SourceImage
if (isset($data['dynamic_metadata'])) {
foreach ($data['dynamic_metadata'] as $name => $metadata) {
$metadata = DynamicMetadataHelper::buildDynamicMetadata($name, $metadata);
if ($metadata) {
$dynamic_metadata[$name] = $metadata;
}
}
}
return new self(
$data['organization'],
$data['binary_hash'],
$data['hash'],
$data['name'],
$data['format'],
$data['size'],
$data['width'],
$data['height'],
$data['user_metadata'],
$dynamic_metadata,
$data['static_metadata'],
new \DateTime($data['created']),
$data['link'],
$data['short_hash']
);
} | php | public static function createFromDecodedJsonResponse($data)
{
if (!isset($data['user_metadata'])) {
$data['user_metadata'] = [];
} else {
foreach ($data['user_metadata'] as $key => $value) {
if (0 === strpos($key, 'date:')) {
$data['user_metadata'][$key] = new \DateTime($value);
}
}
}
if (!isset($data['static_metadata'])) {
$data['static_metadata'] = [];
}
$dynamic_metadata = [];
// Rebuild the DynamicMetadata associated to the current SourceImage
if (isset($data['dynamic_metadata'])) {
foreach ($data['dynamic_metadata'] as $name => $metadata) {
$metadata = DynamicMetadataHelper::buildDynamicMetadata($name, $metadata);
if ($metadata) {
$dynamic_metadata[$name] = $metadata;
}
}
}
return new self(
$data['organization'],
$data['binary_hash'],
$data['hash'],
$data['name'],
$data['format'],
$data['size'],
$data['width'],
$data['height'],
$data['user_metadata'],
$dynamic_metadata,
$data['static_metadata'],
new \DateTime($data['created']),
$data['link'],
$data['short_hash']
);
} | [
"public",
"static",
"function",
"createFromDecodedJsonResponse",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'user_metadata'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'user_metadata'",
"]",
"=",
"[",
"]",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"data",
"[",
"'user_metadata'",
"]",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"0",
"===",
"strpos",
"(",
"$",
"key",
",",
"'date:'",
")",
")",
"{",
"$",
"data",
"[",
"'user_metadata'",
"]",
"[",
"$",
"key",
"]",
"=",
"new",
"\\",
"DateTime",
"(",
"$",
"value",
")",
";",
"}",
"}",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"[",
"'static_metadata'",
"]",
")",
")",
"{",
"$",
"data",
"[",
"'static_metadata'",
"]",
"=",
"[",
"]",
";",
"}",
"$",
"dynamic_metadata",
"=",
"[",
"]",
";",
"// Rebuild the DynamicMetadata associated to the current SourceImage",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'dynamic_metadata'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"[",
"'dynamic_metadata'",
"]",
"as",
"$",
"name",
"=>",
"$",
"metadata",
")",
"{",
"$",
"metadata",
"=",
"DynamicMetadataHelper",
"::",
"buildDynamicMetadata",
"(",
"$",
"name",
",",
"$",
"metadata",
")",
";",
"if",
"(",
"$",
"metadata",
")",
"{",
"$",
"dynamic_metadata",
"[",
"$",
"name",
"]",
"=",
"$",
"metadata",
";",
"}",
"}",
"}",
"return",
"new",
"self",
"(",
"$",
"data",
"[",
"'organization'",
"]",
",",
"$",
"data",
"[",
"'binary_hash'",
"]",
",",
"$",
"data",
"[",
"'hash'",
"]",
",",
"$",
"data",
"[",
"'name'",
"]",
",",
"$",
"data",
"[",
"'format'",
"]",
",",
"$",
"data",
"[",
"'size'",
"]",
",",
"$",
"data",
"[",
"'width'",
"]",
",",
"$",
"data",
"[",
"'height'",
"]",
",",
"$",
"data",
"[",
"'user_metadata'",
"]",
",",
"$",
"dynamic_metadata",
",",
"$",
"data",
"[",
"'static_metadata'",
"]",
",",
"new",
"\\",
"DateTime",
"(",
"$",
"data",
"[",
"'created'",
"]",
")",
",",
"$",
"data",
"[",
"'link'",
"]",
",",
"$",
"data",
"[",
"'short_hash'",
"]",
")",
";",
"}"
]
| Create a source image from the decoded JSON data.
@param array $data Decoded JSON data
@return SourceImage | [
"Create",
"a",
"source",
"image",
"from",
"the",
"decoded",
"JSON",
"data",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Core/SourceImage.php#L143-L186 | train |
tsugiproject/tsugi-php | src/Util/Git.php | Git.& | public static function &clone_remote($repo_path, $remote, $reference = null) {
return GitRepo::create_new($repo_path, $remote, true, $reference);
} | php | public static function &clone_remote($repo_path, $remote, $reference = null) {
return GitRepo::create_new($repo_path, $remote, true, $reference);
} | [
"public",
"static",
"function",
"&",
"clone_remote",
"(",
"$",
"repo_path",
",",
"$",
"remote",
",",
"$",
"reference",
"=",
"null",
")",
"{",
"return",
"GitRepo",
"::",
"create_new",
"(",
"$",
"repo_path",
",",
"$",
"remote",
",",
"true",
",",
"$",
"reference",
")",
";",
"}"
]
| Clones a remote repo into a directory and then returns a GitRepo object
for the newly created local repo
Accepts a creation path and a remote to clone from
@access public
@param string repository path
@param string remote source
@param string reference path
@return GitRepo | [
"Clones",
"a",
"remote",
"repo",
"into",
"a",
"directory",
"and",
"then",
"returns",
"a",
"GitRepo",
"object",
"for",
"the",
"newly",
"created",
"local",
"repo"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/Git.php#L100-L102 | train |
rokka-io/rokka-client-php | src/SearchHelper.php | SearchHelper.buildSearchSortParameter | public static function buildSearchSortParameter(array $sorts)
{
if (empty($sorts)) {
return '';
}
$sorting = [];
foreach ($sorts as $sortField => $direction) {
if (!self::validateFieldName((string) $sortField)) {
throw new \LogicException(sprintf('Invalid field name "%s" for sorting field', $sortField));
}
if (!\in_array($direction, [true, 'desc', 'asc'], true)) {
throw new \LogicException(sprintf('Wrong sorting direction "%s" for field "%s". Use either "desc", "asc"',
$direction, $sortField
));
}
// Only output the "desc" direction as "asc" is the default sorting
$sorting[] = $sortField.('desc' === $direction ? ' '.$direction : '');
}
if (empty($sorting)) {
return '';
}
return implode(',', $sorting);
} | php | public static function buildSearchSortParameter(array $sorts)
{
if (empty($sorts)) {
return '';
}
$sorting = [];
foreach ($sorts as $sortField => $direction) {
if (!self::validateFieldName((string) $sortField)) {
throw new \LogicException(sprintf('Invalid field name "%s" for sorting field', $sortField));
}
if (!\in_array($direction, [true, 'desc', 'asc'], true)) {
throw new \LogicException(sprintf('Wrong sorting direction "%s" for field "%s". Use either "desc", "asc"',
$direction, $sortField
));
}
// Only output the "desc" direction as "asc" is the default sorting
$sorting[] = $sortField.('desc' === $direction ? ' '.$direction : '');
}
if (empty($sorting)) {
return '';
}
return implode(',', $sorting);
} | [
"public",
"static",
"function",
"buildSearchSortParameter",
"(",
"array",
"$",
"sorts",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"sorts",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"sorting",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"sorts",
"as",
"$",
"sortField",
"=>",
"$",
"direction",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"validateFieldName",
"(",
"(",
"string",
")",
"$",
"sortField",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'Invalid field name \"%s\" for sorting field'",
",",
"$",
"sortField",
")",
")",
";",
"}",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"direction",
",",
"[",
"true",
",",
"'desc'",
",",
"'asc'",
"]",
",",
"true",
")",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"sprintf",
"(",
"'Wrong sorting direction \"%s\" for field \"%s\". Use either \"desc\", \"asc\"'",
",",
"$",
"direction",
",",
"$",
"sortField",
")",
")",
";",
"}",
"// Only output the \"desc\" direction as \"asc\" is the default sorting",
"$",
"sorting",
"[",
"]",
"=",
"$",
"sortField",
".",
"(",
"'desc'",
"===",
"$",
"direction",
"?",
"' '",
".",
"$",
"direction",
":",
"''",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"sorting",
")",
")",
"{",
"return",
"''",
";",
"}",
"return",
"implode",
"(",
"','",
",",
"$",
"sorting",
")",
";",
"}"
]
| Builds the "sort" parameter for the source image listing API endpoint.
The sort direction can either be: "asc", "desc" (or the boolean TRUE value, treated as "asc")
@param array $sorts The sorting options, as an associative array "field => sort-direction"
@return string | [
"Builds",
"the",
"sort",
"parameter",
"for",
"the",
"source",
"image",
"listing",
"API",
"endpoint",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/SearchHelper.php#L32-L57 | train |
tsugiproject/tsugi-php | src/Util/LTI13.php | LTI13.isRequestDetail | public static function isRequestDetail($request_data=false) {
$raw_jwt = self::raw_jwt($request_data);
if ( ! $raw_jwt ) return false;
$jwt = self::parse_jwt($raw_jwt);
if ( is_string($jwt) ) {
return $jwt;
}
return is_object($jwt);
} | php | public static function isRequestDetail($request_data=false) {
$raw_jwt = self::raw_jwt($request_data);
if ( ! $raw_jwt ) return false;
$jwt = self::parse_jwt($raw_jwt);
if ( is_string($jwt) ) {
return $jwt;
}
return is_object($jwt);
} | [
"public",
"static",
"function",
"isRequestDetail",
"(",
"$",
"request_data",
"=",
"false",
")",
"{",
"$",
"raw_jwt",
"=",
"self",
"::",
"raw_jwt",
"(",
"$",
"request_data",
")",
";",
"if",
"(",
"!",
"$",
"raw_jwt",
")",
"return",
"false",
";",
"$",
"jwt",
"=",
"self",
"::",
"parse_jwt",
"(",
"$",
"raw_jwt",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"jwt",
")",
")",
"{",
"return",
"$",
"jwt",
";",
"}",
"return",
"is_object",
"(",
"$",
"jwt",
")",
";",
"}"
]
| Returns true, false , or a string | [
"Returns",
"true",
"false",
"or",
"a",
"string"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI13.php#L69-L77 | train |
tsugiproject/tsugi-php | src/Util/LTI13.php | LTI13.isRequest | public static function isRequest($request_data=false) {
$retval = self::isRequestDetail($request_data);
if ( is_string($retval) ) {
error_log("Bad launch ".$retval);
return false;
}
return is_object($retval);
} | php | public static function isRequest($request_data=false) {
$retval = self::isRequestDetail($request_data);
if ( is_string($retval) ) {
error_log("Bad launch ".$retval);
return false;
}
return is_object($retval);
} | [
"public",
"static",
"function",
"isRequest",
"(",
"$",
"request_data",
"=",
"false",
")",
"{",
"$",
"retval",
"=",
"self",
"::",
"isRequestDetail",
"(",
"$",
"request_data",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"retval",
")",
")",
"{",
"error_log",
"(",
"\"Bad launch \"",
".",
"$",
"retval",
")",
";",
"return",
"false",
";",
"}",
"return",
"is_object",
"(",
"$",
"retval",
")",
";",
"}"
]
| Returns true or false | [
"Returns",
"true",
"or",
"false"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI13.php#L82-L89 | train |
tsugiproject/tsugi-php | src/Util/LTI13.php | LTI13.verifyPublicKey | public static function verifyPublicKey($raw_jwt, $public_key, $algs) {
try {
// $decoded = JWT::decode($raw_jwt, $public_key, array('RS256'));
$decoded = JWT::decode($raw_jwt, $public_key, $algs);
// $decoded_array = json_decode(json_encode($decoded), true);
return true;
} catch(\Exception $e) {
return $e;
}
} | php | public static function verifyPublicKey($raw_jwt, $public_key, $algs) {
try {
// $decoded = JWT::decode($raw_jwt, $public_key, array('RS256'));
$decoded = JWT::decode($raw_jwt, $public_key, $algs);
// $decoded_array = json_decode(json_encode($decoded), true);
return true;
} catch(\Exception $e) {
return $e;
}
} | [
"public",
"static",
"function",
"verifyPublicKey",
"(",
"$",
"raw_jwt",
",",
"$",
"public_key",
",",
"$",
"algs",
")",
"{",
"try",
"{",
"// $decoded = JWT::decode($raw_jwt, $public_key, array('RS256'));",
"$",
"decoded",
"=",
"JWT",
"::",
"decode",
"(",
"$",
"raw_jwt",
",",
"$",
"public_key",
",",
"$",
"algs",
")",
";",
"// $decoded_array = json_decode(json_encode($decoded), true);",
"return",
"true",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"return",
"$",
"e",
";",
"}",
"}"
]
| Verify the Public Key for this request
@return mixed This returns true if the request verified. If the request did not verify,
this returns the exception that was generated. | [
"Verify",
"the",
"Public",
"Key",
"for",
"this",
"request"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI13.php#L97-L106 | train |
tsugiproject/tsugi-php | src/Util/LTI13.php | LTI13.jonPostel | public static function jonPostel($body, &$failures) {
if ( isset($CFG->jon_postel) ) return; // We are on Jon Postel mode
// Sanity checks
$version = false;
if ( isset($body->{self::VERSION_CLAIM}) ) $version = $body->{self::VERSION_CLAIM};
if ( strpos($version, '1.3') !== 0 ) $failures[] = "Bad LTI version: ".$version;
$message_type = false;
if ( isset($body->{self::MESSAGE_TYPE_CLAIM}) ) $message_type = $body->{self::MESSAGE_TYPE_CLAIM};
if ( ! $message_type ) {
$failures[] = "Missing message type";
} else if ( $message_type == self::MESSAGE_TYPE_RESOURCE ) {
// Required
if ( ! isset($body->{self::RESOURCE_LINK_CLAIM}) ) $failures[] = "Missing required resource_link claim";
if ( ! isset($body->{self::RESOURCE_LINK_CLAIM}->id) ) $failures[] = "Missing required resource_link id";
} else if ( $message_type == self::MESSAGE_TYPE_DEEPLINK ) {
// OK
} else {
$failures[] = "Bad message type: ".$message_type;
}
if ( ! isset($body->{self::ROLES_CLAIM}) ) $failures[] = "Missing required role claim";
if ( ! isset($body->{self::DEPLOYMENT_ID}) ) $failures[] = "Missing required deployment_id claim";
} | php | public static function jonPostel($body, &$failures) {
if ( isset($CFG->jon_postel) ) return; // We are on Jon Postel mode
// Sanity checks
$version = false;
if ( isset($body->{self::VERSION_CLAIM}) ) $version = $body->{self::VERSION_CLAIM};
if ( strpos($version, '1.3') !== 0 ) $failures[] = "Bad LTI version: ".$version;
$message_type = false;
if ( isset($body->{self::MESSAGE_TYPE_CLAIM}) ) $message_type = $body->{self::MESSAGE_TYPE_CLAIM};
if ( ! $message_type ) {
$failures[] = "Missing message type";
} else if ( $message_type == self::MESSAGE_TYPE_RESOURCE ) {
// Required
if ( ! isset($body->{self::RESOURCE_LINK_CLAIM}) ) $failures[] = "Missing required resource_link claim";
if ( ! isset($body->{self::RESOURCE_LINK_CLAIM}->id) ) $failures[] = "Missing required resource_link id";
} else if ( $message_type == self::MESSAGE_TYPE_DEEPLINK ) {
// OK
} else {
$failures[] = "Bad message type: ".$message_type;
}
if ( ! isset($body->{self::ROLES_CLAIM}) ) $failures[] = "Missing required role claim";
if ( ! isset($body->{self::DEPLOYMENT_ID}) ) $failures[] = "Missing required deployment_id claim";
} | [
"public",
"static",
"function",
"jonPostel",
"(",
"$",
"body",
",",
"&",
"$",
"failures",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"CFG",
"->",
"jon_postel",
")",
")",
"return",
";",
"// We are on Jon Postel mode",
"// Sanity checks",
"$",
"version",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"body",
"->",
"{",
"self",
"::",
"VERSION_CLAIM",
"}",
")",
")",
"$",
"version",
"=",
"$",
"body",
"->",
"{",
"self",
"::",
"VERSION_CLAIM",
"}",
";",
"if",
"(",
"strpos",
"(",
"$",
"version",
",",
"'1.3'",
")",
"!==",
"0",
")",
"$",
"failures",
"[",
"]",
"=",
"\"Bad LTI version: \"",
".",
"$",
"version",
";",
"$",
"message_type",
"=",
"false",
";",
"if",
"(",
"isset",
"(",
"$",
"body",
"->",
"{",
"self",
"::",
"MESSAGE_TYPE_CLAIM",
"}",
")",
")",
"$",
"message_type",
"=",
"$",
"body",
"->",
"{",
"self",
"::",
"MESSAGE_TYPE_CLAIM",
"}",
";",
"if",
"(",
"!",
"$",
"message_type",
")",
"{",
"$",
"failures",
"[",
"]",
"=",
"\"Missing message type\"",
";",
"}",
"else",
"if",
"(",
"$",
"message_type",
"==",
"self",
"::",
"MESSAGE_TYPE_RESOURCE",
")",
"{",
"// Required",
"if",
"(",
"!",
"isset",
"(",
"$",
"body",
"->",
"{",
"self",
"::",
"RESOURCE_LINK_CLAIM",
"}",
")",
")",
"$",
"failures",
"[",
"]",
"=",
"\"Missing required resource_link claim\"",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"body",
"->",
"{",
"self",
"::",
"RESOURCE_LINK_CLAIM",
"}",
"->",
"id",
")",
")",
"$",
"failures",
"[",
"]",
"=",
"\"Missing required resource_link id\"",
";",
"}",
"else",
"if",
"(",
"$",
"message_type",
"==",
"self",
"::",
"MESSAGE_TYPE_DEEPLINK",
")",
"{",
"// OK",
"}",
"else",
"{",
"$",
"failures",
"[",
"]",
"=",
"\"Bad message type: \"",
".",
"$",
"message_type",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"body",
"->",
"{",
"self",
"::",
"ROLES_CLAIM",
"}",
")",
")",
"$",
"failures",
"[",
"]",
"=",
"\"Missing required role claim\"",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"body",
"->",
"{",
"self",
"::",
"DEPLOYMENT_ID",
"}",
")",
")",
"$",
"failures",
"[",
"]",
"=",
"\"Missing required deployment_id claim\"",
";",
"}"
]
| Apply Jon Postel's Law as appropriate
Postel's Law - https://en.wikipedia.org/wiki/Robustness_principle
"TCP implementations should follow a general principle of robustness:
be conservative in what you do, be liberal in what you accept from others."
By default, Jon Postel mode is off and we are stricter than we need to be.
This works well because it reduces the arguments with the certification
folks. But if you add:
$CFG->jon_postel = true;
Tsugi will follow Jon Postel's law. | [
"Apply",
"Jon",
"Postel",
"s",
"Law",
"as",
"appropriate"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI13.php#L137-L161 | train |
tsugiproject/tsugi-php | src/Util/LTI13.php | LTI13.loadRoster | public static function loadRoster($membership_url, $access_token, &$debug_log=false) {
$ch = curl_init();
$membership_url = trim($membership_url);
$headers = [
'Authorization: Bearer '. $access_token,
'Accept: '.self::MEDIA_TYPE_MEMBERSHIPS,
'Content-Type: '.self::MEDIA_TYPE_MEMBERSHIPS // TODO: Remove when certification is fixed
];
curl_setopt($ch, CURLOPT_URL, $membership_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ( is_array($debug_log) ) $debug_log[] = $membership_url;
if ( is_array($debug_log) ) $debug_log[] = $headers;
$membership = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
if ( is_array($debug_log) ) $debug_log[] = "Sent roster request, received status=$httpcode (".strlen($membership)." characters)";
if ( strlen($membership) < 1 ) {
return "No data retrieved status=" . $httpcode;
}
$json = json_decode($membership, false); // Top level object
if ( $json === null ) {
$retval = "Unable to parse returned roster JSON:". json_last_error_msg();
if ( is_array($debug_log) ) {
if (is_array($debug_log) ) $debug_log[] = $retval;
if (is_array($debug_log) ) $debug_log[] = substr($membership, 0, 3000);
}
return $retval;
}
if ( $httpcode == 200 && isset($json->members) ) {
if ( is_array($debug_log) ) $debug_log[] = "Loaded ".count($json->members)." roster entries";
return $json;
}
$status = isset($json->error) ? $json->error : "Unable to load results";
if ( is_array($debug_log) ) $debug_log[] = "Error status: $status";
return $status;
} | php | public static function loadRoster($membership_url, $access_token, &$debug_log=false) {
$ch = curl_init();
$membership_url = trim($membership_url);
$headers = [
'Authorization: Bearer '. $access_token,
'Accept: '.self::MEDIA_TYPE_MEMBERSHIPS,
'Content-Type: '.self::MEDIA_TYPE_MEMBERSHIPS // TODO: Remove when certification is fixed
];
curl_setopt($ch, CURLOPT_URL, $membership_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ( is_array($debug_log) ) $debug_log[] = $membership_url;
if ( is_array($debug_log) ) $debug_log[] = $headers;
$membership = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
if ( is_array($debug_log) ) $debug_log[] = "Sent roster request, received status=$httpcode (".strlen($membership)." characters)";
if ( strlen($membership) < 1 ) {
return "No data retrieved status=" . $httpcode;
}
$json = json_decode($membership, false); // Top level object
if ( $json === null ) {
$retval = "Unable to parse returned roster JSON:". json_last_error_msg();
if ( is_array($debug_log) ) {
if (is_array($debug_log) ) $debug_log[] = $retval;
if (is_array($debug_log) ) $debug_log[] = substr($membership, 0, 3000);
}
return $retval;
}
if ( $httpcode == 200 && isset($json->members) ) {
if ( is_array($debug_log) ) $debug_log[] = "Loaded ".count($json->members)." roster entries";
return $json;
}
$status = isset($json->error) ? $json->error : "Unable to load results";
if ( is_array($debug_log) ) $debug_log[] = "Error status: $status";
return $status;
} | [
"public",
"static",
"function",
"loadRoster",
"(",
"$",
"membership_url",
",",
"$",
"access_token",
",",
"&",
"$",
"debug_log",
"=",
"false",
")",
"{",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"$",
"membership_url",
"=",
"trim",
"(",
"$",
"membership_url",
")",
";",
"$",
"headers",
"=",
"[",
"'Authorization: Bearer '",
".",
"$",
"access_token",
",",
"'Accept: '",
".",
"self",
"::",
"MEDIA_TYPE_MEMBERSHIPS",
",",
"'Content-Type: '",
".",
"self",
"::",
"MEDIA_TYPE_MEMBERSHIPS",
"// TODO: Remove when certification is fixed",
"]",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_URL",
",",
"$",
"membership_url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"$",
"membership_url",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"$",
"headers",
";",
"$",
"membership",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"$",
"httpcode",
"=",
"curl_getinfo",
"(",
"$",
"ch",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"\"Sent roster request, received status=$httpcode (\"",
".",
"strlen",
"(",
"$",
"membership",
")",
".",
"\" characters)\"",
";",
"if",
"(",
"strlen",
"(",
"$",
"membership",
")",
"<",
"1",
")",
"{",
"return",
"\"No data retrieved status=\"",
".",
"$",
"httpcode",
";",
"}",
"$",
"json",
"=",
"json_decode",
"(",
"$",
"membership",
",",
"false",
")",
";",
"// Top level object",
"if",
"(",
"$",
"json",
"===",
"null",
")",
"{",
"$",
"retval",
"=",
"\"Unable to parse returned roster JSON:\"",
".",
"json_last_error_msg",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"$",
"retval",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"substr",
"(",
"$",
"membership",
",",
"0",
",",
"3000",
")",
";",
"}",
"return",
"$",
"retval",
";",
"}",
"if",
"(",
"$",
"httpcode",
"==",
"200",
"&&",
"isset",
"(",
"$",
"json",
"->",
"members",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"\"Loaded \"",
".",
"count",
"(",
"$",
"json",
"->",
"members",
")",
".",
"\" roster entries\"",
";",
"return",
"$",
"json",
";",
"}",
"$",
"status",
"=",
"isset",
"(",
"$",
"json",
"->",
"error",
")",
"?",
"$",
"json",
"->",
"error",
":",
"\"Unable to load results\"",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"\"Error status: $status\"",
";",
"return",
"$",
"status",
";",
"}"
]
| Call memberships and roles | [
"Call",
"memberships",
"and",
"roles"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI13.php#L254-L300 | train |
tsugiproject/tsugi-php | src/Util/LTI13.php | LTI13.loadLineItem | public static function loadLineItem($lineitem_url, $access_token, &$debug_log=false) {
$lineitem_url = trim($lineitem_url);
$ch = curl_init();
$headers = [
'Authorization: Bearer '. $access_token,
'Accept: '.self::MEDIA_TYPE_LINEITEM,
];
curl_setopt($ch, CURLOPT_URL, $lineitem_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (is_array($debug_log) ) $debug_log[] = 'Line Items URL: '.$lineitem_url;
if (is_array($debug_log) ) $debug_log[] = $headers;
$lineitem = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
if ( is_array($debug_log) ) $debug_log[] = "Sent lineitem request, received status=$httpcode (".strlen($lineitem)." characters)";
$json = json_decode($lineitem, false);
if ( $json === null ) {
$retval = "Unable to parse returned lineitem JSON:". json_last_error_msg();
if ( is_array($debug_log) ) {
if (is_array($debug_log) ) $debug_log[] = $retval;
if (is_array($debug_log) ) $debug_log[] = substr($lineitem, 0, 1000);
}
return $retval;
}
if ( $httpcode == 200 && is_object($json) ) {
if ( is_array($debug_log) ) $debug_log[] = "Loaded lineitem";
return $json;
}
$status = isset($json->error) ? $json->error : "Unable to load results";
if ( is_array($debug_log) ) $debug_log[] = "Error status: $status";
return $status;
} | php | public static function loadLineItem($lineitem_url, $access_token, &$debug_log=false) {
$lineitem_url = trim($lineitem_url);
$ch = curl_init();
$headers = [
'Authorization: Bearer '. $access_token,
'Accept: '.self::MEDIA_TYPE_LINEITEM,
];
curl_setopt($ch, CURLOPT_URL, $lineitem_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (is_array($debug_log) ) $debug_log[] = 'Line Items URL: '.$lineitem_url;
if (is_array($debug_log) ) $debug_log[] = $headers;
$lineitem = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
if ( is_array($debug_log) ) $debug_log[] = "Sent lineitem request, received status=$httpcode (".strlen($lineitem)." characters)";
$json = json_decode($lineitem, false);
if ( $json === null ) {
$retval = "Unable to parse returned lineitem JSON:". json_last_error_msg();
if ( is_array($debug_log) ) {
if (is_array($debug_log) ) $debug_log[] = $retval;
if (is_array($debug_log) ) $debug_log[] = substr($lineitem, 0, 1000);
}
return $retval;
}
if ( $httpcode == 200 && is_object($json) ) {
if ( is_array($debug_log) ) $debug_log[] = "Loaded lineitem";
return $json;
}
$status = isset($json->error) ? $json->error : "Unable to load results";
if ( is_array($debug_log) ) $debug_log[] = "Error status: $status";
return $status;
} | [
"public",
"static",
"function",
"loadLineItem",
"(",
"$",
"lineitem_url",
",",
"$",
"access_token",
",",
"&",
"$",
"debug_log",
"=",
"false",
")",
"{",
"$",
"lineitem_url",
"=",
"trim",
"(",
"$",
"lineitem_url",
")",
";",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"$",
"headers",
"=",
"[",
"'Authorization: Bearer '",
".",
"$",
"access_token",
",",
"'Accept: '",
".",
"self",
"::",
"MEDIA_TYPE_LINEITEM",
",",
"]",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_URL",
",",
"$",
"lineitem_url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"'Line Items URL: '",
".",
"$",
"lineitem_url",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"$",
"headers",
";",
"$",
"lineitem",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"$",
"httpcode",
"=",
"curl_getinfo",
"(",
"$",
"ch",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"\"Sent lineitem request, received status=$httpcode (\"",
".",
"strlen",
"(",
"$",
"lineitem",
")",
".",
"\" characters)\"",
";",
"$",
"json",
"=",
"json_decode",
"(",
"$",
"lineitem",
",",
"false",
")",
";",
"if",
"(",
"$",
"json",
"===",
"null",
")",
"{",
"$",
"retval",
"=",
"\"Unable to parse returned lineitem JSON:\"",
".",
"json_last_error_msg",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"$",
"retval",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"substr",
"(",
"$",
"lineitem",
",",
"0",
",",
"1000",
")",
";",
"}",
"return",
"$",
"retval",
";",
"}",
"if",
"(",
"$",
"httpcode",
"==",
"200",
"&&",
"is_object",
"(",
"$",
"json",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"\"Loaded lineitem\"",
";",
"return",
"$",
"json",
";",
"}",
"$",
"status",
"=",
"isset",
"(",
"$",
"json",
"->",
"error",
")",
"?",
"$",
"json",
"->",
"error",
":",
"\"Unable to load results\"",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"\"Error status: $status\"",
";",
"return",
"$",
"status",
";",
"}"
]
| Load A LineItem | [
"Load",
"A",
"LineItem"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI13.php#L346-L386 | train |
tsugiproject/tsugi-php | src/Util/LTI13.php | LTI13.loadResults | public static function loadResults($lineitem_url, $access_token, &$debug_log=false) {
$lineitem_url = trim($lineitem_url);
$ch = curl_init();
$headers = [
'Authorization: Bearer '. $access_token,
'Content-Type: '.self::RESULTS_TYPE, // TODO: Convince Claude this is wrong
'Accept: '.self::RESULTS_TYPE
];
$actual_url = $lineitem_url."/results";
curl_setopt($ch, CURLOPT_URL, $actual_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (is_array($debug_log) ) $debug_log[] = 'Line Items URL: '.$actual_url;
if (is_array($debug_log) ) $debug_log[] = $headers;
$results = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
if ( is_array($debug_log) ) $debug_log[] = "Sent results request, received status=$httpcode (".strlen($results)." characters)";
if ( is_array($debug_log)) $debug_log[] = substr($results, 0, 3000);
$json = json_decode($results, false);
if ( $json === null ) {
$retval = "Unable to parse returned results JSON:". json_last_error_msg();
if ( is_array($debug_log) ) $debug_log[] = $retval;
return $retval;
}
if ( $httpcode == 200 && is_array($json) ) {
if ( is_array($debug_log) ) $debug_log[] = "Loaded results";
return $json;
}
$status = isset($json->error) ? $json->error : "Unable to load results";
if ( is_array($debug_log) ) $debug_log[] = "Error status: $status";
return $status;
} | php | public static function loadResults($lineitem_url, $access_token, &$debug_log=false) {
$lineitem_url = trim($lineitem_url);
$ch = curl_init();
$headers = [
'Authorization: Bearer '. $access_token,
'Content-Type: '.self::RESULTS_TYPE, // TODO: Convince Claude this is wrong
'Accept: '.self::RESULTS_TYPE
];
$actual_url = $lineitem_url."/results";
curl_setopt($ch, CURLOPT_URL, $actual_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (is_array($debug_log) ) $debug_log[] = 'Line Items URL: '.$actual_url;
if (is_array($debug_log) ) $debug_log[] = $headers;
$results = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
if ( is_array($debug_log) ) $debug_log[] = "Sent results request, received status=$httpcode (".strlen($results)." characters)";
if ( is_array($debug_log)) $debug_log[] = substr($results, 0, 3000);
$json = json_decode($results, false);
if ( $json === null ) {
$retval = "Unable to parse returned results JSON:". json_last_error_msg();
if ( is_array($debug_log) ) $debug_log[] = $retval;
return $retval;
}
if ( $httpcode == 200 && is_array($json) ) {
if ( is_array($debug_log) ) $debug_log[] = "Loaded results";
return $json;
}
$status = isset($json->error) ? $json->error : "Unable to load results";
if ( is_array($debug_log) ) $debug_log[] = "Error status: $status";
return $status;
} | [
"public",
"static",
"function",
"loadResults",
"(",
"$",
"lineitem_url",
",",
"$",
"access_token",
",",
"&",
"$",
"debug_log",
"=",
"false",
")",
"{",
"$",
"lineitem_url",
"=",
"trim",
"(",
"$",
"lineitem_url",
")",
";",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"$",
"headers",
"=",
"[",
"'Authorization: Bearer '",
".",
"$",
"access_token",
",",
"'Content-Type: '",
".",
"self",
"::",
"RESULTS_TYPE",
",",
"// TODO: Convince Claude this is wrong",
"'Accept: '",
".",
"self",
"::",
"RESULTS_TYPE",
"]",
";",
"$",
"actual_url",
"=",
"$",
"lineitem_url",
".",
"\"/results\"",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_URL",
",",
"$",
"actual_url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"'Line Items URL: '",
".",
"$",
"actual_url",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"$",
"headers",
";",
"$",
"results",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"$",
"httpcode",
"=",
"curl_getinfo",
"(",
"$",
"ch",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"\"Sent results request, received status=$httpcode (\"",
".",
"strlen",
"(",
"$",
"results",
")",
".",
"\" characters)\"",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"substr",
"(",
"$",
"results",
",",
"0",
",",
"3000",
")",
";",
"$",
"json",
"=",
"json_decode",
"(",
"$",
"results",
",",
"false",
")",
";",
"if",
"(",
"$",
"json",
"===",
"null",
")",
"{",
"$",
"retval",
"=",
"\"Unable to parse returned results JSON:\"",
".",
"json_last_error_msg",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"$",
"retval",
";",
"return",
"$",
"retval",
";",
"}",
"if",
"(",
"$",
"httpcode",
"==",
"200",
"&&",
"is_array",
"(",
"$",
"json",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"\"Loaded results\"",
";",
"return",
"$",
"json",
";",
"}",
"$",
"status",
"=",
"isset",
"(",
"$",
"json",
"->",
"error",
")",
"?",
"$",
"json",
"->",
"error",
":",
"\"Unable to load results\"",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"\"Error status: $status\"",
";",
"return",
"$",
"status",
";",
"}"
]
| Load results for a LineItem | [
"Load",
"results",
"for",
"a",
"LineItem"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI13.php#L389-L430 | train |
tsugiproject/tsugi-php | src/Util/LTI13.php | LTI13.deleteLineItem | public static function deleteLineItem($lineitem_url, $access_token, &$debug_log=false) {
$lineitem_url = trim($lineitem_url);
$ch = curl_init();
$headers = [
'Authorization: Bearer '. $access_token
];
curl_setopt($ch, CURLOPT_URL, $lineitem_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
if (is_array($debug_log) ) $debug_log[] = 'Line Item URL: '.$lineitem_url;
if (is_array($debug_log) ) $debug_log[] = $headers;
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
if ( is_array($debug_log) ) $debug_log[] = "Sent lineitem delete, received status=$httpcode (".strlen($response)." characters)";
if ( $httpcode == 200 ) {
if ( is_array($debug_log) ) $debug_log[] = "Deleted lineitem";
return true;
}
if ( strlen($response) < 1 ) {
return "Failed with no response body and code=".$httpcode;
}
$json = json_decode($response, false);
if ( $json === null ) {
$retval = "Unable to parse returned lineitem JSON:". json_last_error_msg();
if ( is_array($debug_log) ) {
if (is_array($debug_log) ) $debug_log[] = $retval;
if (is_array($debug_log) ) $debug_log[] = substr($lineitem, 0, 1000);
}
return $retval;
}
$status = U::get($json, "error", "Unable to delete lineitem");
if ( is_array($debug_log) ) $debug_log[] = "Error status: $status";
return $status;
} | php | public static function deleteLineItem($lineitem_url, $access_token, &$debug_log=false) {
$lineitem_url = trim($lineitem_url);
$ch = curl_init();
$headers = [
'Authorization: Bearer '. $access_token
];
curl_setopt($ch, CURLOPT_URL, $lineitem_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
if (is_array($debug_log) ) $debug_log[] = 'Line Item URL: '.$lineitem_url;
if (is_array($debug_log) ) $debug_log[] = $headers;
$response = curl_exec($ch);
$httpcode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close ($ch);
if ( is_array($debug_log) ) $debug_log[] = "Sent lineitem delete, received status=$httpcode (".strlen($response)." characters)";
if ( $httpcode == 200 ) {
if ( is_array($debug_log) ) $debug_log[] = "Deleted lineitem";
return true;
}
if ( strlen($response) < 1 ) {
return "Failed with no response body and code=".$httpcode;
}
$json = json_decode($response, false);
if ( $json === null ) {
$retval = "Unable to parse returned lineitem JSON:". json_last_error_msg();
if ( is_array($debug_log) ) {
if (is_array($debug_log) ) $debug_log[] = $retval;
if (is_array($debug_log) ) $debug_log[] = substr($lineitem, 0, 1000);
}
return $retval;
}
$status = U::get($json, "error", "Unable to delete lineitem");
if ( is_array($debug_log) ) $debug_log[] = "Error status: $status";
return $status;
} | [
"public",
"static",
"function",
"deleteLineItem",
"(",
"$",
"lineitem_url",
",",
"$",
"access_token",
",",
"&",
"$",
"debug_log",
"=",
"false",
")",
"{",
"$",
"lineitem_url",
"=",
"trim",
"(",
"$",
"lineitem_url",
")",
";",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"$",
"headers",
"=",
"[",
"'Authorization: Bearer '",
".",
"$",
"access_token",
"]",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_URL",
",",
"$",
"lineitem_url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HTTPHEADER",
",",
"$",
"headers",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_CUSTOMREQUEST",
",",
"\"DELETE\"",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"'Line Item URL: '",
".",
"$",
"lineitem_url",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"$",
"headers",
";",
"$",
"response",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"$",
"httpcode",
"=",
"curl_getinfo",
"(",
"$",
"ch",
",",
"CURLINFO_HTTP_CODE",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"\"Sent lineitem delete, received status=$httpcode (\"",
".",
"strlen",
"(",
"$",
"response",
")",
".",
"\" characters)\"",
";",
"if",
"(",
"$",
"httpcode",
"==",
"200",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"\"Deleted lineitem\"",
";",
"return",
"true",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"response",
")",
"<",
"1",
")",
"{",
"return",
"\"Failed with no response body and code=\"",
".",
"$",
"httpcode",
";",
"}",
"$",
"json",
"=",
"json_decode",
"(",
"$",
"response",
",",
"false",
")",
";",
"if",
"(",
"$",
"json",
"===",
"null",
")",
"{",
"$",
"retval",
"=",
"\"Unable to parse returned lineitem JSON:\"",
".",
"json_last_error_msg",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"$",
"retval",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"substr",
"(",
"$",
"lineitem",
",",
"0",
",",
"1000",
")",
";",
"}",
"return",
"$",
"retval",
";",
"}",
"$",
"status",
"=",
"U",
"::",
"get",
"(",
"$",
"json",
",",
"\"error\"",
",",
"\"Unable to delete lineitem\"",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"debug_log",
")",
")",
"$",
"debug_log",
"[",
"]",
"=",
"\"Error status: $status\"",
";",
"return",
"$",
"status",
";",
"}"
]
| Delete A LineItem | [
"Delete",
"A",
"LineItem"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/LTI13.php#L433-L478 | train |
tsugiproject/tsugi-php | src/Util/Caliper.php | Caliper.getISO8601 | public static function getISO8601($timestamp=false) {
if ( $timestamp === false ) {
$dt = new \DateTime();
} else {
$format = 'Y-m-d H:i:s';
$dt = \DateTime::createFromFormat($format, $timestamp);
}
// 2017-08-16T16:26:31-1000
$iso8601 = $dt->format(\DateTime::ISO8601);
// 2017-08-20T10:34:05.000Z
$iso8601 = str_replace('-1000','.000Z',$iso8601);
return $iso8601;
} | php | public static function getISO8601($timestamp=false) {
if ( $timestamp === false ) {
$dt = new \DateTime();
} else {
$format = 'Y-m-d H:i:s';
$dt = \DateTime::createFromFormat($format, $timestamp);
}
// 2017-08-16T16:26:31-1000
$iso8601 = $dt->format(\DateTime::ISO8601);
// 2017-08-20T10:34:05.000Z
$iso8601 = str_replace('-1000','.000Z',$iso8601);
return $iso8601;
} | [
"public",
"static",
"function",
"getISO8601",
"(",
"$",
"timestamp",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"timestamp",
"===",
"false",
")",
"{",
"$",
"dt",
"=",
"new",
"\\",
"DateTime",
"(",
")",
";",
"}",
"else",
"{",
"$",
"format",
"=",
"'Y-m-d H:i:s'",
";",
"$",
"dt",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"timestamp",
")",
";",
"}",
"// 2017-08-16T16:26:31-1000",
"$",
"iso8601",
"=",
"$",
"dt",
"->",
"format",
"(",
"\\",
"DateTime",
"::",
"ISO8601",
")",
";",
"// 2017-08-20T10:34:05.000Z",
"$",
"iso8601",
"=",
"str_replace",
"(",
"'-1000'",
",",
"'.000Z'",
",",
"$",
"iso8601",
")",
";",
"return",
"$",
"iso8601",
";",
"}"
]
| Get Caliper-style ISO8601 Datetime from unix timestamp | [
"Get",
"Caliper",
"-",
"style",
"ISO8601",
"Datetime",
"from",
"unix",
"timestamp"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/Caliper.php#L21-L36 | train |
tsugiproject/tsugi-php | src/Util/Caliper.php | Caliper.sensorCanvasPageView | public static function sensorCanvasPageView ($user, $application, $page,
$timestamp=false, $name, $duration='PT5M30S') {
$caliper = json_decode('{
"@context" : "http://purl.imsglobal.org/ctx/caliper/v1/ViewEvent",
"@type" : "http://purl.imsglobal.org/caliper/v1/ViewEvent",
"action" : "viewed",
"startedAtTime" : "Time.now.utc.to_i",
"duration" : "PT5M30S",
"actor" : {
"@id" : "user_id",
"@type" : "http://purl.imsglobal.org/caliper/v1/lis/Person"
},
"object" : {
"@id" : "context_url",
"@type" : "http://www.idpf.org/epub/vocab/structure/#volume",
"name" : "Test LTI Tool"
},
"edApp" : {
"@id" :"context_url",
"@type" : "http://purl.imsglobal.org/caliper/v1/SoftwareApplication",
"name" : "LTI Tool of All Things",
"properties" : {},
"lastModifiedTime" : "Time.now.utc.to_i"
}
}');
if ( ! $timestamp ) $timestamp = time();
$caliper->startedAtTime = $timestamp;
$caliper->actor->{'@id'} = $user;
$caliper->object->{'@id'} = $page;
$caliper->edApp->{'@id'} = $application;
$caliper->edApp->name = $name;
$caliper->duration = $duration;
$caliper = json_encode($caliper, JSON_PRETTY_PRINT);
return $caliper;
} | php | public static function sensorCanvasPageView ($user, $application, $page,
$timestamp=false, $name, $duration='PT5M30S') {
$caliper = json_decode('{
"@context" : "http://purl.imsglobal.org/ctx/caliper/v1/ViewEvent",
"@type" : "http://purl.imsglobal.org/caliper/v1/ViewEvent",
"action" : "viewed",
"startedAtTime" : "Time.now.utc.to_i",
"duration" : "PT5M30S",
"actor" : {
"@id" : "user_id",
"@type" : "http://purl.imsglobal.org/caliper/v1/lis/Person"
},
"object" : {
"@id" : "context_url",
"@type" : "http://www.idpf.org/epub/vocab/structure/#volume",
"name" : "Test LTI Tool"
},
"edApp" : {
"@id" :"context_url",
"@type" : "http://purl.imsglobal.org/caliper/v1/SoftwareApplication",
"name" : "LTI Tool of All Things",
"properties" : {},
"lastModifiedTime" : "Time.now.utc.to_i"
}
}');
if ( ! $timestamp ) $timestamp = time();
$caliper->startedAtTime = $timestamp;
$caliper->actor->{'@id'} = $user;
$caliper->object->{'@id'} = $page;
$caliper->edApp->{'@id'} = $application;
$caliper->edApp->name = $name;
$caliper->duration = $duration;
$caliper = json_encode($caliper, JSON_PRETTY_PRINT);
return $caliper;
} | [
"public",
"static",
"function",
"sensorCanvasPageView",
"(",
"$",
"user",
",",
"$",
"application",
",",
"$",
"page",
",",
"$",
"timestamp",
"=",
"false",
",",
"$",
"name",
",",
"$",
"duration",
"=",
"'PT5M30S'",
")",
"{",
"$",
"caliper",
"=",
"json_decode",
"(",
"'{\n \"@context\" : \"http://purl.imsglobal.org/ctx/caliper/v1/ViewEvent\",\n \"@type\" : \"http://purl.imsglobal.org/caliper/v1/ViewEvent\",\n \"action\" : \"viewed\",\n \"startedAtTime\" : \"Time.now.utc.to_i\",\n \"duration\" : \"PT5M30S\",\n \"actor\" : {\n \"@id\" : \"user_id\",\n \"@type\" : \"http://purl.imsglobal.org/caliper/v1/lis/Person\"\n },\n \"object\" : {\n \"@id\" : \"context_url\",\n \"@type\" : \"http://www.idpf.org/epub/vocab/structure/#volume\",\n \"name\" : \"Test LTI Tool\"\n },\n \"edApp\" : {\n \"@id\" :\"context_url\",\n \"@type\" : \"http://purl.imsglobal.org/caliper/v1/SoftwareApplication\",\n \"name\" : \"LTI Tool of All Things\",\n \"properties\" : {},\n \"lastModifiedTime\" : \"Time.now.utc.to_i\"\n }\n }'",
")",
";",
"if",
"(",
"!",
"$",
"timestamp",
")",
"$",
"timestamp",
"=",
"time",
"(",
")",
";",
"$",
"caliper",
"->",
"startedAtTime",
"=",
"$",
"timestamp",
";",
"$",
"caliper",
"->",
"actor",
"->",
"{",
"'@id'",
"}",
"=",
"$",
"user",
";",
"$",
"caliper",
"->",
"object",
"->",
"{",
"'@id'",
"}",
"=",
"$",
"page",
";",
"$",
"caliper",
"->",
"edApp",
"->",
"{",
"'@id'",
"}",
"=",
"$",
"application",
";",
"$",
"caliper",
"->",
"edApp",
"->",
"name",
"=",
"$",
"name",
";",
"$",
"caliper",
"->",
"duration",
"=",
"$",
"duration",
";",
"$",
"caliper",
"=",
"json_encode",
"(",
"$",
"caliper",
",",
"JSON_PRETTY_PRINT",
")",
";",
"return",
"$",
"caliper",
";",
"}"
]
| This is just a test method to return properly formatted JSON for the Canvas prototype Caliper
This is just a starting point to lay some initial groundwork.
@param $application string This is the name of the application - typically it is
the base domain name of the application like https://lti-tools.dr-chuck.com/tsugi/
@param $page This is the url of page of that was viewed.
@param $duration This is the duration of the activity on the page. | [
"This",
"is",
"just",
"a",
"test",
"method",
"to",
"return",
"properly",
"formatted",
"JSON",
"for",
"the",
"Canvas",
"prototype",
"Caliper"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/Caliper.php#L104-L140 | train |
JayBizzle/Laravel-Migrations-Organiser | src/Commands/MigrateDisorganise.php | MigrateDisorganise.cleanup | public function cleanup()
{
if ($this->option('force')) {
$this->deleteDirs();
} elseif ($this->confirm('Delete all subdirectories in migrations folder?', true)) {
$this->deleteDirs();
}
} | php | public function cleanup()
{
if ($this->option('force')) {
$this->deleteDirs();
} elseif ($this->confirm('Delete all subdirectories in migrations folder?', true)) {
$this->deleteDirs();
}
} | [
"public",
"function",
"cleanup",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"option",
"(",
"'force'",
")",
")",
"{",
"$",
"this",
"->",
"deleteDirs",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"confirm",
"(",
"'Delete all subdirectories in migrations folder?'",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"deleteDirs",
"(",
")",
";",
"}",
"}"
]
| Decide whether or not to delete directories.
@return void | [
"Decide",
"whether",
"or",
"not",
"to",
"delete",
"directories",
"."
]
| 571ba7fc00869f9641eda1c26c1959e292aefbe4 | https://github.com/JayBizzle/Laravel-Migrations-Organiser/blob/571ba7fc00869f9641eda1c26c1959e292aefbe4/src/Commands/MigrateDisorganise.php#L98-L105 | train |
JayBizzle/Laravel-Migrations-Organiser | src/Commands/MigrateDisorganise.php | MigrateDisorganise.deleteDirs | public function deleteDirs()
{
$dirs = $this->files->directories($this->basePath);
foreach ($dirs as $dir) {
$this->files->deleteDirectory($dir);
}
$this->info('Subdirectories deleted');
} | php | public function deleteDirs()
{
$dirs = $this->files->directories($this->basePath);
foreach ($dirs as $dir) {
$this->files->deleteDirectory($dir);
}
$this->info('Subdirectories deleted');
} | [
"public",
"function",
"deleteDirs",
"(",
")",
"{",
"$",
"dirs",
"=",
"$",
"this",
"->",
"files",
"->",
"directories",
"(",
"$",
"this",
"->",
"basePath",
")",
";",
"foreach",
"(",
"$",
"dirs",
"as",
"$",
"dir",
")",
"{",
"$",
"this",
"->",
"files",
"->",
"deleteDirectory",
"(",
"$",
"dir",
")",
";",
"}",
"$",
"this",
"->",
"info",
"(",
"'Subdirectories deleted'",
")",
";",
"}"
]
| Delete subdirectories in the migrations folder.
@return void | [
"Delete",
"subdirectories",
"in",
"the",
"migrations",
"folder",
"."
]
| 571ba7fc00869f9641eda1c26c1959e292aefbe4 | https://github.com/JayBizzle/Laravel-Migrations-Organiser/blob/571ba7fc00869f9641eda1c26c1959e292aefbe4/src/Commands/MigrateDisorganise.php#L112-L121 | train |
rokka-io/rokka-client-php | src/Core/Stack.php | Stack.createFromDecodedJsonResponse | public static function createFromDecodedJsonResponse($data)
{
$stack_operations = [];
if (isset($data['stack_operations']) && \is_array($data['stack_operations'])) {
foreach ($data['stack_operations'] as $operation) {
$stack_operations[] = StackOperation::createFromDecodedJsonResponse($operation);
}
}
$stack = new self(
$data['organization'],
$data['name'],
$stack_operations,
[],
new \DateTime($data['created'])
);
if (isset($data['stack_options']) && \is_array($data['stack_options'])) {
$stack->setStackOptions($data['stack_options']);
}
if (isset($data['stack_variables']) && \is_array($data['stack_variables'])) {
$stack->setStackVariables($data['stack_variables']);
}
if (isset($data['stack_expressions']) && \is_array($data['stack_expressions'])) {
$stack_expressions = [];
foreach ($data['stack_expressions'] as $expression) {
$stack_expressions[] = StackExpression::createFromDecodedJsonResponse($expression);
}
$stack->setStackExpressions($stack_expressions);
}
return $stack;
} | php | public static function createFromDecodedJsonResponse($data)
{
$stack_operations = [];
if (isset($data['stack_operations']) && \is_array($data['stack_operations'])) {
foreach ($data['stack_operations'] as $operation) {
$stack_operations[] = StackOperation::createFromDecodedJsonResponse($operation);
}
}
$stack = new self(
$data['organization'],
$data['name'],
$stack_operations,
[],
new \DateTime($data['created'])
);
if (isset($data['stack_options']) && \is_array($data['stack_options'])) {
$stack->setStackOptions($data['stack_options']);
}
if (isset($data['stack_variables']) && \is_array($data['stack_variables'])) {
$stack->setStackVariables($data['stack_variables']);
}
if (isset($data['stack_expressions']) && \is_array($data['stack_expressions'])) {
$stack_expressions = [];
foreach ($data['stack_expressions'] as $expression) {
$stack_expressions[] = StackExpression::createFromDecodedJsonResponse($expression);
}
$stack->setStackExpressions($stack_expressions);
}
return $stack;
} | [
"public",
"static",
"function",
"createFromDecodedJsonResponse",
"(",
"$",
"data",
")",
"{",
"$",
"stack_operations",
"=",
"[",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'stack_operations'",
"]",
")",
"&&",
"\\",
"is_array",
"(",
"$",
"data",
"[",
"'stack_operations'",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"data",
"[",
"'stack_operations'",
"]",
"as",
"$",
"operation",
")",
"{",
"$",
"stack_operations",
"[",
"]",
"=",
"StackOperation",
"::",
"createFromDecodedJsonResponse",
"(",
"$",
"operation",
")",
";",
"}",
"}",
"$",
"stack",
"=",
"new",
"self",
"(",
"$",
"data",
"[",
"'organization'",
"]",
",",
"$",
"data",
"[",
"'name'",
"]",
",",
"$",
"stack_operations",
",",
"[",
"]",
",",
"new",
"\\",
"DateTime",
"(",
"$",
"data",
"[",
"'created'",
"]",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'stack_options'",
"]",
")",
"&&",
"\\",
"is_array",
"(",
"$",
"data",
"[",
"'stack_options'",
"]",
")",
")",
"{",
"$",
"stack",
"->",
"setStackOptions",
"(",
"$",
"data",
"[",
"'stack_options'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'stack_variables'",
"]",
")",
"&&",
"\\",
"is_array",
"(",
"$",
"data",
"[",
"'stack_variables'",
"]",
")",
")",
"{",
"$",
"stack",
"->",
"setStackVariables",
"(",
"$",
"data",
"[",
"'stack_variables'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"'stack_expressions'",
"]",
")",
"&&",
"\\",
"is_array",
"(",
"$",
"data",
"[",
"'stack_expressions'",
"]",
")",
")",
"{",
"$",
"stack_expressions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"data",
"[",
"'stack_expressions'",
"]",
"as",
"$",
"expression",
")",
"{",
"$",
"stack_expressions",
"[",
"]",
"=",
"StackExpression",
"::",
"createFromDecodedJsonResponse",
"(",
"$",
"expression",
")",
";",
"}",
"$",
"stack",
"->",
"setStackExpressions",
"(",
"$",
"stack_expressions",
")",
";",
"}",
"return",
"$",
"stack",
";",
"}"
]
| Create a stack from a decoded JSON data returned by the rokka.io API.
@param array $data Decoded JSON data
@return Stack | [
"Create",
"a",
"stack",
"from",
"a",
"decoded",
"JSON",
"data",
"returned",
"by",
"the",
"rokka",
".",
"io",
"API",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Core/Stack.php#L52-L87 | train |
rokka-io/rokka-client-php | src/Core/Stack.php | Stack.createFromConfig | public static function createFromConfig($stackName, array $config, $organization = null)
{
$stack = new static($organization, $stackName);
if (isset($config['operations'])) {
$stack->setStackOperations($config['operations']);
}
if (isset($config['options'])) {
$stack->setStackOptions($config['options']);
}
if (isset($config['expressions'])) {
$stack->setStackExpressions($config['expressions']);
}
if (isset($config['variables'])) {
$stack->setStackVariables($config['variables']);
}
return $stack;
} | php | public static function createFromConfig($stackName, array $config, $organization = null)
{
$stack = new static($organization, $stackName);
if (isset($config['operations'])) {
$stack->setStackOperations($config['operations']);
}
if (isset($config['options'])) {
$stack->setStackOptions($config['options']);
}
if (isset($config['expressions'])) {
$stack->setStackExpressions($config['expressions']);
}
if (isset($config['variables'])) {
$stack->setStackVariables($config['variables']);
}
return $stack;
} | [
"public",
"static",
"function",
"createFromConfig",
"(",
"$",
"stackName",
",",
"array",
"$",
"config",
",",
"$",
"organization",
"=",
"null",
")",
"{",
"$",
"stack",
"=",
"new",
"static",
"(",
"$",
"organization",
",",
"$",
"stackName",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'operations'",
"]",
")",
")",
"{",
"$",
"stack",
"->",
"setStackOperations",
"(",
"$",
"config",
"[",
"'operations'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'options'",
"]",
")",
")",
"{",
"$",
"stack",
"->",
"setStackOptions",
"(",
"$",
"config",
"[",
"'options'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'expressions'",
"]",
")",
")",
"{",
"$",
"stack",
"->",
"setStackExpressions",
"(",
"$",
"config",
"[",
"'expressions'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"config",
"[",
"'variables'",
"]",
")",
")",
"{",
"$",
"stack",
"->",
"setStackVariables",
"(",
"$",
"config",
"[",
"'variables'",
"]",
")",
";",
"}",
"return",
"$",
"stack",
";",
"}"
]
| Creates a Stack object from an array.
$config = ['operations' => StackOperation[]
'options' => $options,
'expressions' => $expressions
]
All are optional, if operations doesn't exist, it will be a noop operation.
@since 1.1.0
@param string $stackName
@param array $config
@param string|null $organization
@return self | [
"Creates",
"a",
"Stack",
"object",
"from",
"an",
"array",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Core/Stack.php#L119-L139 | train |
rokka-io/rokka-client-php | src/Core/Stack.php | Stack.getDynamicUriString | public function getDynamicUriString()
{
$stack = new StackUri('dynamic', $this->getStackOperations(), $this->getStackOptions(), $this->getStackVariables());
return $stack->getStackUriString();
} | php | public function getDynamicUriString()
{
$stack = new StackUri('dynamic', $this->getStackOperations(), $this->getStackOptions(), $this->getStackVariables());
return $stack->getStackUriString();
} | [
"public",
"function",
"getDynamicUriString",
"(",
")",
"{",
"$",
"stack",
"=",
"new",
"StackUri",
"(",
"'dynamic'",
",",
"$",
"this",
"->",
"getStackOperations",
"(",
")",
",",
"$",
"this",
"->",
"getStackOptions",
"(",
")",
",",
"$",
"this",
"->",
"getStackVariables",
"(",
")",
")",
";",
"return",
"$",
"stack",
"->",
"getStackUriString",
"(",
")",
";",
"}"
]
| Returns the stack url part as a dynamic stack for previewing.
@since 1.2.0
@throws \RuntimeException When the stack name could not be parsed correctly
@return string | [
"Returns",
"the",
"stack",
"url",
"part",
"as",
"a",
"dynamic",
"stack",
"for",
"previewing",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Core/Stack.php#L247-L252 | train |
rokka-io/rokka-client-php | src/Core/StackCollection.php | StackCollection.createFromJsonResponse | public static function createFromJsonResponse($data)
{
$data = json_decode($data, true);
$stacks = array_map(function ($stack) {
return Stack::createFromDecodedJsonResponse($stack);
}, $data['items']);
return new self($stacks);
} | php | public static function createFromJsonResponse($data)
{
$data = json_decode($data, true);
$stacks = array_map(function ($stack) {
return Stack::createFromDecodedJsonResponse($stack);
}, $data['items']);
return new self($stacks);
} | [
"public",
"static",
"function",
"createFromJsonResponse",
"(",
"$",
"data",
")",
"{",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"$",
"stacks",
"=",
"array_map",
"(",
"function",
"(",
"$",
"stack",
")",
"{",
"return",
"Stack",
"::",
"createFromDecodedJsonResponse",
"(",
"$",
"stack",
")",
";",
"}",
",",
"$",
"data",
"[",
"'items'",
"]",
")",
";",
"return",
"new",
"self",
"(",
"$",
"stacks",
")",
";",
"}"
]
| Create a stack from the JSON data returned by the rokka.io API.
@param string $data JSON data
@return StackCollection | [
"Create",
"a",
"stack",
"from",
"the",
"JSON",
"data",
"returned",
"by",
"the",
"rokka",
".",
"io",
"API",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Core/StackCollection.php#L63-L72 | train |
tsugiproject/tsugi-php | src/Event/Entry.php | Entry.click | public function click($time=null) {
$this->total++;
if ( ! $this->timestart ) {
$this->timestart = (int) ( time() / $this->scale );
}
if ( ! $time ) $time = time();
$time = (int) ($time / $this->scale);
$delta = $time - $this->timestart;
if ( $delta < 0 ) $delta = 0; // 0 is OK
if ( isset($this->buckets[$delta]) ) {
$this->buckets[$delta]++;
} else {
$this->buckets[$delta] = 1;
}
} | php | public function click($time=null) {
$this->total++;
if ( ! $this->timestart ) {
$this->timestart = (int) ( time() / $this->scale );
}
if ( ! $time ) $time = time();
$time = (int) ($time / $this->scale);
$delta = $time - $this->timestart;
if ( $delta < 0 ) $delta = 0; // 0 is OK
if ( isset($this->buckets[$delta]) ) {
$this->buckets[$delta]++;
} else {
$this->buckets[$delta] = 1;
}
} | [
"public",
"function",
"click",
"(",
"$",
"time",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"total",
"++",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"timestart",
")",
"{",
"$",
"this",
"->",
"timestart",
"=",
"(",
"int",
")",
"(",
"time",
"(",
")",
"/",
"$",
"this",
"->",
"scale",
")",
";",
"}",
"if",
"(",
"!",
"$",
"time",
")",
"$",
"time",
"=",
"time",
"(",
")",
";",
"$",
"time",
"=",
"(",
"int",
")",
"(",
"$",
"time",
"/",
"$",
"this",
"->",
"scale",
")",
";",
"$",
"delta",
"=",
"$",
"time",
"-",
"$",
"this",
"->",
"timestart",
";",
"if",
"(",
"$",
"delta",
"<",
"0",
")",
"$",
"delta",
"=",
"0",
";",
"// 0 is OK",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"buckets",
"[",
"$",
"delta",
"]",
")",
")",
"{",
"$",
"this",
"->",
"buckets",
"[",
"$",
"delta",
"]",
"++",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"buckets",
"[",
"$",
"delta",
"]",
"=",
"1",
";",
"}",
"}"
]
| Record a click... | [
"Record",
"a",
"click",
"..."
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Event/Entry.php#L43-L57 | train |
tsugiproject/tsugi-php | src/Event/Entry.php | Entry.reconstruct | public function reconstruct() {
$retval = array();
foreach($this->buckets as $k => $v) {
$t = ($this->timestart + $k) * $this->scale;
$retval[$t] = $v;
}
return $retval;
} | php | public function reconstruct() {
$retval = array();
foreach($this->buckets as $k => $v) {
$t = ($this->timestart + $k) * $this->scale;
$retval[$t] = $v;
}
return $retval;
} | [
"public",
"function",
"reconstruct",
"(",
")",
"{",
"$",
"retval",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"buckets",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"t",
"=",
"(",
"$",
"this",
"->",
"timestart",
"+",
"$",
"k",
")",
"*",
"$",
"this",
"->",
"scale",
";",
"$",
"retval",
"[",
"$",
"t",
"]",
"=",
"$",
"v",
";",
"}",
"return",
"$",
"retval",
";",
"}"
]
| Reconstruct to the actual times | [
"Reconstruct",
"to",
"the",
"actual",
"times"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Event/Entry.php#L62-L69 | train |
tsugiproject/tsugi-php | src/Event/Entry.php | Entry.viewModel | public function viewModel() {
$retval = new \stdClass();
$buckets = $this->reconstruct();
$retval->timestart = $this->timestart * $this->scale;
$retval->width = $this->scale;
$max = false;
$maxt = false;
$min = false;
$rows = array();
foreach($buckets as $k => $v ) {
if ( $maxt === false || $k > $maxt ) $maxt = $k;
if ( $max === false || $v > $max ) $max = $v;
if ( $min === false || $v < $min ) $min = $v;
$rows[] = array($k,$v);
}
$retval->rows = $rows;
$retval->n = count($rows);
$retval->max = $max;
$retval->min = $min;
$retval->timeend = $maxt;
return $retval;
} | php | public function viewModel() {
$retval = new \stdClass();
$buckets = $this->reconstruct();
$retval->timestart = $this->timestart * $this->scale;
$retval->width = $this->scale;
$max = false;
$maxt = false;
$min = false;
$rows = array();
foreach($buckets as $k => $v ) {
if ( $maxt === false || $k > $maxt ) $maxt = $k;
if ( $max === false || $v > $max ) $max = $v;
if ( $min === false || $v < $min ) $min = $v;
$rows[] = array($k,$v);
}
$retval->rows = $rows;
$retval->n = count($rows);
$retval->max = $max;
$retval->min = $min;
$retval->timeend = $maxt;
return $retval;
} | [
"public",
"function",
"viewModel",
"(",
")",
"{",
"$",
"retval",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"buckets",
"=",
"$",
"this",
"->",
"reconstruct",
"(",
")",
";",
"$",
"retval",
"->",
"timestart",
"=",
"$",
"this",
"->",
"timestart",
"*",
"$",
"this",
"->",
"scale",
";",
"$",
"retval",
"->",
"width",
"=",
"$",
"this",
"->",
"scale",
";",
"$",
"max",
"=",
"false",
";",
"$",
"maxt",
"=",
"false",
";",
"$",
"min",
"=",
"false",
";",
"$",
"rows",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"buckets",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"$",
"maxt",
"===",
"false",
"||",
"$",
"k",
">",
"$",
"maxt",
")",
"$",
"maxt",
"=",
"$",
"k",
";",
"if",
"(",
"$",
"max",
"===",
"false",
"||",
"$",
"v",
">",
"$",
"max",
")",
"$",
"max",
"=",
"$",
"v",
";",
"if",
"(",
"$",
"min",
"===",
"false",
"||",
"$",
"v",
"<",
"$",
"min",
")",
"$",
"min",
"=",
"$",
"v",
";",
"$",
"rows",
"[",
"]",
"=",
"array",
"(",
"$",
"k",
",",
"$",
"v",
")",
";",
"}",
"$",
"retval",
"->",
"rows",
"=",
"$",
"rows",
";",
"$",
"retval",
"->",
"n",
"=",
"count",
"(",
"$",
"rows",
")",
";",
"$",
"retval",
"->",
"max",
"=",
"$",
"max",
";",
"$",
"retval",
"->",
"min",
"=",
"$",
"min",
";",
"$",
"retval",
"->",
"timeend",
"=",
"$",
"maxt",
";",
"return",
"$",
"retval",
";",
"}"
]
| Produce an view model of the entire object
This is a "view model" in that it is intended to be easily used
in rendering situations. | [
"Produce",
"an",
"view",
"model",
"of",
"the",
"entire",
"object"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Event/Entry.php#L77-L98 | train |
tsugiproject/tsugi-php | src/Event/Entry.php | Entry.uncompressEntry | public static function uncompressEntry($text) {
if ( $text === null | $text === false ) return $text;
$needed = false;
for ($i = 0; $i < strlen($text); $i++){
$ch = $text[$i];
if ( $ch >= '0' && $ch <= '9' ) continue;
if ( $ch == ':' || $ch == ',' || $ch == '=' ) continue;
$needed = true;
break;
}
if ( ! $needed ) return $text;
return gzuncompress($text);
} | php | public static function uncompressEntry($text) {
if ( $text === null | $text === false ) return $text;
$needed = false;
for ($i = 0; $i < strlen($text); $i++){
$ch = $text[$i];
if ( $ch >= '0' && $ch <= '9' ) continue;
if ( $ch == ':' || $ch == ',' || $ch == '=' ) continue;
$needed = true;
break;
}
if ( ! $needed ) return $text;
return gzuncompress($text);
} | [
"public",
"static",
"function",
"uncompressEntry",
"(",
"$",
"text",
")",
"{",
"if",
"(",
"$",
"text",
"===",
"null",
"|",
"$",
"text",
"===",
"false",
")",
"return",
"$",
"text",
";",
"$",
"needed",
"=",
"false",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"strlen",
"(",
"$",
"text",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"ch",
"=",
"$",
"text",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"$",
"ch",
">=",
"'0'",
"&&",
"$",
"ch",
"<=",
"'9'",
")",
"continue",
";",
"if",
"(",
"$",
"ch",
"==",
"':'",
"||",
"$",
"ch",
"==",
"','",
"||",
"$",
"ch",
"==",
"'='",
")",
"continue",
";",
"$",
"needed",
"=",
"true",
";",
"break",
";",
"}",
"if",
"(",
"!",
"$",
"needed",
")",
"return",
"$",
"text",
";",
"return",
"gzuncompress",
"(",
"$",
"text",
")",
";",
"}"
]
| Optionally uncompress a serialized entry if it is compressed | [
"Optionally",
"uncompress",
"a",
"serialized",
"entry",
"if",
"it",
"is",
"compressed"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Event/Entry.php#L123-L135 | train |
tsugiproject/tsugi-php | src/Event/Entry.php | Entry.serialize | public function serialize($maxlength=null, $compress=false) {
if ( ! $maxlength ) $maxlength = $this->maxlen;
$retval = $this->scale . ':' .$this->timestart . ':' . U::array_Integer_Serialize($this->buckets);
if ( strlen($retval) <= $maxlength ) return $retval;
$allowCompress = $compress && function_exists('gzcompress') && function_exists('gzuncompress');
// Stratey 1 - Compress if we are allowed - since it is lossless
if ( $allowCompress ) {
$compressed = gzcompress($retval);
if ( strlen($retval) <= $maxlength ) return $retval;
}
// Strategy 2 - Double or Quadruple Scale as long as buckets < 24 hours
if ( $this->scale < 24*60*60 ) {
foreach(array(2,4) as $factor ) {
$newbuckets = $this->reScale($factor);
$newscale = $this->scale * $factor;
$newstart = (int) ($this->timestart / $factor);
$retval = $newscale . ':' .$newstart . ':' . U::array_Integer_Serialize($newbuckets);
if ( strlen($retval) <= $maxlength ) return $retval;
if ( $allowCompress ) {
$compressed = gzcompress($retval);
if ( strlen($retval) <= $maxlength ) return $retval;
}
}
}
// Strategy 3, pitch data
$oldbuckets = $this->buckets;
$newstart = $this->timestart;
$firstoffset = null;
while( count($oldbuckets) > 4 ) {
$fewerbuckets = array();
$pos = 0;
$fistoffset = null;
foreach($oldbuckets as $oldoffset => $v ) {
$pos++;
if ( $pos == 1 ) continue; // first entry
if ( $pos == 2 ) $firstoffset = $oldoffset;
$newoffset = $oldoffset - $firstoffset;
$fewerbuckets[$newoffset] = $oldbuckets[$oldoffset];
}
if ( count($oldbuckets)-1 != count($fewerbuckets) ) {
throw new Exception('Internal failure during serialization');
}
$newstart = $newstart + $firstoffset;
$retval = $this->scale . ':' .$newstart . ':' . U::array_Integer_Serialize($fewerbuckets);
if ( strlen($retval) <= $maxlength ) return $retval;
if ( $allowCompress ) {
$compressed = gzcompress($retval);
if ( strlen($retval) <= $maxlength ) return $retval;
}
$oldbuckets = $fewerbuckets;
}
// Strategy 4: Violate the max request :)
return $retval;
} | php | public function serialize($maxlength=null, $compress=false) {
if ( ! $maxlength ) $maxlength = $this->maxlen;
$retval = $this->scale . ':' .$this->timestart . ':' . U::array_Integer_Serialize($this->buckets);
if ( strlen($retval) <= $maxlength ) return $retval;
$allowCompress = $compress && function_exists('gzcompress') && function_exists('gzuncompress');
// Stratey 1 - Compress if we are allowed - since it is lossless
if ( $allowCompress ) {
$compressed = gzcompress($retval);
if ( strlen($retval) <= $maxlength ) return $retval;
}
// Strategy 2 - Double or Quadruple Scale as long as buckets < 24 hours
if ( $this->scale < 24*60*60 ) {
foreach(array(2,4) as $factor ) {
$newbuckets = $this->reScale($factor);
$newscale = $this->scale * $factor;
$newstart = (int) ($this->timestart / $factor);
$retval = $newscale . ':' .$newstart . ':' . U::array_Integer_Serialize($newbuckets);
if ( strlen($retval) <= $maxlength ) return $retval;
if ( $allowCompress ) {
$compressed = gzcompress($retval);
if ( strlen($retval) <= $maxlength ) return $retval;
}
}
}
// Strategy 3, pitch data
$oldbuckets = $this->buckets;
$newstart = $this->timestart;
$firstoffset = null;
while( count($oldbuckets) > 4 ) {
$fewerbuckets = array();
$pos = 0;
$fistoffset = null;
foreach($oldbuckets as $oldoffset => $v ) {
$pos++;
if ( $pos == 1 ) continue; // first entry
if ( $pos == 2 ) $firstoffset = $oldoffset;
$newoffset = $oldoffset - $firstoffset;
$fewerbuckets[$newoffset] = $oldbuckets[$oldoffset];
}
if ( count($oldbuckets)-1 != count($fewerbuckets) ) {
throw new Exception('Internal failure during serialization');
}
$newstart = $newstart + $firstoffset;
$retval = $this->scale . ':' .$newstart . ':' . U::array_Integer_Serialize($fewerbuckets);
if ( strlen($retval) <= $maxlength ) return $retval;
if ( $allowCompress ) {
$compressed = gzcompress($retval);
if ( strlen($retval) <= $maxlength ) return $retval;
}
$oldbuckets = $fewerbuckets;
}
// Strategy 4: Violate the max request :)
return $retval;
} | [
"public",
"function",
"serialize",
"(",
"$",
"maxlength",
"=",
"null",
",",
"$",
"compress",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"$",
"maxlength",
")",
"$",
"maxlength",
"=",
"$",
"this",
"->",
"maxlen",
";",
"$",
"retval",
"=",
"$",
"this",
"->",
"scale",
".",
"':'",
".",
"$",
"this",
"->",
"timestart",
".",
"':'",
".",
"U",
"::",
"array_Integer_Serialize",
"(",
"$",
"this",
"->",
"buckets",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"retval",
")",
"<=",
"$",
"maxlength",
")",
"return",
"$",
"retval",
";",
"$",
"allowCompress",
"=",
"$",
"compress",
"&&",
"function_exists",
"(",
"'gzcompress'",
")",
"&&",
"function_exists",
"(",
"'gzuncompress'",
")",
";",
"// Stratey 1 - Compress if we are allowed - since it is lossless",
"if",
"(",
"$",
"allowCompress",
")",
"{",
"$",
"compressed",
"=",
"gzcompress",
"(",
"$",
"retval",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"retval",
")",
"<=",
"$",
"maxlength",
")",
"return",
"$",
"retval",
";",
"}",
"// Strategy 2 - Double or Quadruple Scale as long as buckets < 24 hours",
"if",
"(",
"$",
"this",
"->",
"scale",
"<",
"24",
"*",
"60",
"*",
"60",
")",
"{",
"foreach",
"(",
"array",
"(",
"2",
",",
"4",
")",
"as",
"$",
"factor",
")",
"{",
"$",
"newbuckets",
"=",
"$",
"this",
"->",
"reScale",
"(",
"$",
"factor",
")",
";",
"$",
"newscale",
"=",
"$",
"this",
"->",
"scale",
"*",
"$",
"factor",
";",
"$",
"newstart",
"=",
"(",
"int",
")",
"(",
"$",
"this",
"->",
"timestart",
"/",
"$",
"factor",
")",
";",
"$",
"retval",
"=",
"$",
"newscale",
".",
"':'",
".",
"$",
"newstart",
".",
"':'",
".",
"U",
"::",
"array_Integer_Serialize",
"(",
"$",
"newbuckets",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"retval",
")",
"<=",
"$",
"maxlength",
")",
"return",
"$",
"retval",
";",
"if",
"(",
"$",
"allowCompress",
")",
"{",
"$",
"compressed",
"=",
"gzcompress",
"(",
"$",
"retval",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"retval",
")",
"<=",
"$",
"maxlength",
")",
"return",
"$",
"retval",
";",
"}",
"}",
"}",
"// Strategy 3, pitch data",
"$",
"oldbuckets",
"=",
"$",
"this",
"->",
"buckets",
";",
"$",
"newstart",
"=",
"$",
"this",
"->",
"timestart",
";",
"$",
"firstoffset",
"=",
"null",
";",
"while",
"(",
"count",
"(",
"$",
"oldbuckets",
")",
">",
"4",
")",
"{",
"$",
"fewerbuckets",
"=",
"array",
"(",
")",
";",
"$",
"pos",
"=",
"0",
";",
"$",
"fistoffset",
"=",
"null",
";",
"foreach",
"(",
"$",
"oldbuckets",
"as",
"$",
"oldoffset",
"=>",
"$",
"v",
")",
"{",
"$",
"pos",
"++",
";",
"if",
"(",
"$",
"pos",
"==",
"1",
")",
"continue",
";",
"// first entry",
"if",
"(",
"$",
"pos",
"==",
"2",
")",
"$",
"firstoffset",
"=",
"$",
"oldoffset",
";",
"$",
"newoffset",
"=",
"$",
"oldoffset",
"-",
"$",
"firstoffset",
";",
"$",
"fewerbuckets",
"[",
"$",
"newoffset",
"]",
"=",
"$",
"oldbuckets",
"[",
"$",
"oldoffset",
"]",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"oldbuckets",
")",
"-",
"1",
"!=",
"count",
"(",
"$",
"fewerbuckets",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"'Internal failure during serialization'",
")",
";",
"}",
"$",
"newstart",
"=",
"$",
"newstart",
"+",
"$",
"firstoffset",
";",
"$",
"retval",
"=",
"$",
"this",
"->",
"scale",
".",
"':'",
".",
"$",
"newstart",
".",
"':'",
".",
"U",
"::",
"array_Integer_Serialize",
"(",
"$",
"fewerbuckets",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"retval",
")",
"<=",
"$",
"maxlength",
")",
"return",
"$",
"retval",
";",
"if",
"(",
"$",
"allowCompress",
")",
"{",
"$",
"compressed",
"=",
"gzcompress",
"(",
"$",
"retval",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"retval",
")",
"<=",
"$",
"maxlength",
")",
"return",
"$",
"retval",
";",
"}",
"$",
"oldbuckets",
"=",
"$",
"fewerbuckets",
";",
"}",
"// Strategy 4: Violate the max request :)",
"return",
"$",
"retval",
";",
"}"
]
| Serialize to a key=value pair | [
"Serialize",
"to",
"a",
"key",
"=",
"value",
"pair"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Event/Entry.php#L160-L222 | train |
tsugiproject/tsugi-php | src/Google/GoogleLogin.php | GoogleLogin.getLoginUrl | function getLoginUrl($state) {
$loginUrl = "https://accounts.google.com/o/oauth2/auth?"
. "client_id=" . $this->client_id
. "&redirect_uri=" . $this->redirect
. "&state=" . $state
. "&response_type=code"
. "&scope=email%20profile"
. "&include_granted_scopes=true";
if ( $this->openid_realm ) {
$loginUrl .= "&openid.realm=" . $this->openid_realm;
}
return $loginUrl;
} | php | function getLoginUrl($state) {
$loginUrl = "https://accounts.google.com/o/oauth2/auth?"
. "client_id=" . $this->client_id
. "&redirect_uri=" . $this->redirect
. "&state=" . $state
. "&response_type=code"
. "&scope=email%20profile"
. "&include_granted_scopes=true";
if ( $this->openid_realm ) {
$loginUrl .= "&openid.realm=" . $this->openid_realm;
}
return $loginUrl;
} | [
"function",
"getLoginUrl",
"(",
"$",
"state",
")",
"{",
"$",
"loginUrl",
"=",
"\"https://accounts.google.com/o/oauth2/auth?\"",
".",
"\"client_id=\"",
".",
"$",
"this",
"->",
"client_id",
".",
"\"&redirect_uri=\"",
".",
"$",
"this",
"->",
"redirect",
".",
"\"&state=\"",
".",
"$",
"state",
".",
"\"&response_type=code\"",
".",
"\"&scope=email%20profile\"",
".",
"\"&include_granted_scopes=true\"",
";",
"if",
"(",
"$",
"this",
"->",
"openid_realm",
")",
"{",
"$",
"loginUrl",
".=",
"\"&openid.realm=\"",
".",
"$",
"this",
"->",
"openid_realm",
";",
"}",
"return",
"$",
"loginUrl",
";",
"}"
]
| Get the login url | [
"Get",
"the",
"login",
"url"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Google/GoogleLogin.php#L39-L52 | train |
tsugiproject/tsugi-php | src/Util/U.php | U.route_get_local_path | public static function route_get_local_path($dir) {
$uri = $_SERVER['REQUEST_URI']; // /tsugi/lti/some/cool/stuff
$root = $_SERVER['DOCUMENT_ROOT']; // /Applications/MAMP/htdocs
$cwd = $dir; // /Applications/MAMP/htdocs/tsugi/lti
if ( strlen($cwd) < strlen($root) + 1 ) return false;
$lwd = substr($cwd,strlen($root)); // /tsugi/lti
if ( strlen($uri) < strlen($lwd) + 2 ) return false;
$local = substr($uri,strlen($lwd)+1); // some/cool/stuff
return $local;
} | php | public static function route_get_local_path($dir) {
$uri = $_SERVER['REQUEST_URI']; // /tsugi/lti/some/cool/stuff
$root = $_SERVER['DOCUMENT_ROOT']; // /Applications/MAMP/htdocs
$cwd = $dir; // /Applications/MAMP/htdocs/tsugi/lti
if ( strlen($cwd) < strlen($root) + 1 ) return false;
$lwd = substr($cwd,strlen($root)); // /tsugi/lti
if ( strlen($uri) < strlen($lwd) + 2 ) return false;
$local = substr($uri,strlen($lwd)+1); // some/cool/stuff
return $local;
} | [
"public",
"static",
"function",
"route_get_local_path",
"(",
"$",
"dir",
")",
"{",
"$",
"uri",
"=",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
";",
"// /tsugi/lti/some/cool/stuff",
"$",
"root",
"=",
"$",
"_SERVER",
"[",
"'DOCUMENT_ROOT'",
"]",
";",
"// /Applications/MAMP/htdocs",
"$",
"cwd",
"=",
"$",
"dir",
";",
"// /Applications/MAMP/htdocs/tsugi/lti",
"if",
"(",
"strlen",
"(",
"$",
"cwd",
")",
"<",
"strlen",
"(",
"$",
"root",
")",
"+",
"1",
")",
"return",
"false",
";",
"$",
"lwd",
"=",
"substr",
"(",
"$",
"cwd",
",",
"strlen",
"(",
"$",
"root",
")",
")",
";",
"// /tsugi/lti",
"if",
"(",
"strlen",
"(",
"$",
"uri",
")",
"<",
"strlen",
"(",
"$",
"lwd",
")",
"+",
"2",
")",
"return",
"false",
";",
"$",
"local",
"=",
"substr",
"(",
"$",
"uri",
",",
"strlen",
"(",
"$",
"lwd",
")",
"+",
"1",
")",
";",
"// some/cool/stuff",
"return",
"$",
"local",
";",
"}"
]
| Convienence method to get the local path if we are doing | [
"Convienence",
"method",
"to",
"get",
"the",
"local",
"path",
"if",
"we",
"are",
"doing"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/U.php#L67-L76 | train |
tsugiproject/tsugi-php | src/Util/U.php | U.get_request_document | public static function get_request_document() {
$uri = $_SERVER['REQUEST_URI']; // /tsugi/lti/some/cool/stuff
$pieces = explode('/',$uri);
if ( count($pieces) > 1 ) {
$local_path = $pieces[count($pieces)-1];
$pos = strpos($local_path,'?');
if ( $pos > 0 ) $local_path = substr($local_path,0,$pos);
return $local_path;
}
return false;
} | php | public static function get_request_document() {
$uri = $_SERVER['REQUEST_URI']; // /tsugi/lti/some/cool/stuff
$pieces = explode('/',$uri);
if ( count($pieces) > 1 ) {
$local_path = $pieces[count($pieces)-1];
$pos = strpos($local_path,'?');
if ( $pos > 0 ) $local_path = substr($local_path,0,$pos);
return $local_path;
}
return false;
} | [
"public",
"static",
"function",
"get_request_document",
"(",
")",
"{",
"$",
"uri",
"=",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
";",
"// /tsugi/lti/some/cool/stuff",
"$",
"pieces",
"=",
"explode",
"(",
"'/'",
",",
"$",
"uri",
")",
";",
"if",
"(",
"count",
"(",
"$",
"pieces",
")",
">",
"1",
")",
"{",
"$",
"local_path",
"=",
"$",
"pieces",
"[",
"count",
"(",
"$",
"pieces",
")",
"-",
"1",
"]",
";",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"local_path",
",",
"'?'",
")",
";",
"if",
"(",
"$",
"pos",
">",
"0",
")",
"$",
"local_path",
"=",
"substr",
"(",
"$",
"local_path",
",",
"0",
",",
"$",
"pos",
")",
";",
"return",
"$",
"local_path",
";",
"}",
"return",
"false",
";",
"}"
]
| Get the last bit of the path
input: /py4e/lessons/intro?x=2
output: intro | [
"Get",
"the",
"last",
"bit",
"of",
"the",
"path"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/U.php#L84-L94 | train |
tsugiproject/tsugi-php | src/Util/U.php | U.get_base_url | public static function get_base_url($url) {
$pieces = parse_url($url);
$retval = $pieces['scheme'].'://'.$pieces['host'];
$port = self::get($pieces,'port');
if ( $port && $port != 80 && $port != 443 ) $retval .= ':' . $port;
return $retval;
} | php | public static function get_base_url($url) {
$pieces = parse_url($url);
$retval = $pieces['scheme'].'://'.$pieces['host'];
$port = self::get($pieces,'port');
if ( $port && $port != 80 && $port != 443 ) $retval .= ':' . $port;
return $retval;
} | [
"public",
"static",
"function",
"get_base_url",
"(",
"$",
"url",
")",
"{",
"$",
"pieces",
"=",
"parse_url",
"(",
"$",
"url",
")",
";",
"$",
"retval",
"=",
"$",
"pieces",
"[",
"'scheme'",
"]",
".",
"'://'",
".",
"$",
"pieces",
"[",
"'host'",
"]",
";",
"$",
"port",
"=",
"self",
"::",
"get",
"(",
"$",
"pieces",
",",
"'port'",
")",
";",
"if",
"(",
"$",
"port",
"&&",
"$",
"port",
"!=",
"80",
"&&",
"$",
"port",
"!=",
"443",
")",
"$",
"retval",
".=",
"':'",
".",
"$",
"port",
";",
"return",
"$",
"retval",
";",
"}"
]
| Get the protocol, host, and port from an absolute URL
input: http://localhost:8888/tsugi
output: http://localhost:8888 | [
"Get",
"the",
"protocol",
"host",
"and",
"port",
"from",
"an",
"absolute",
"URL"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/U.php#L102-L108 | train |
tsugiproject/tsugi-php | src/Util/U.php | U.parse_rest_path | public static function parse_rest_path($uri=false, $SERVER_SCRIPT_NAME=false /* unit test only */) {
if ( ! $SERVER_SCRIPT_NAME ) $SERVER_SCRIPT_NAME = $_SERVER["SCRIPT_NAME"]; // /py4e/koseu.php
if ( ! $uri ) $uri = $_SERVER['REQUEST_URI']; // /py4e/lessons/intro/happy
// Remove Query string...
$pos = strpos($uri, '?');
if ( $pos !== false ) $uri = substr($uri,0,$pos);
$cwd = dirname($SERVER_SCRIPT_NAME);
if ( strpos($uri,$cwd) !== 0 ) return false;
$controller = '';
$extra = '';
$remainder = substr($uri, strlen($cwd));
if ( strpos($remainder,'/') === 0 ) $remainder = substr($remainder,1);
if ( strlen($remainder) > 1 ) {
$pieces = explode('/',$remainder,2);
if ( count($pieces) > 0 ) $controller = $pieces[0];
if ( count($pieces) > 1 ) $extra = $pieces[1];
}
if ( $cwd == '/' ) $cwd = '';
$retval = array($cwd, $controller, $extra);
return $retval;
} | php | public static function parse_rest_path($uri=false, $SERVER_SCRIPT_NAME=false /* unit test only */) {
if ( ! $SERVER_SCRIPT_NAME ) $SERVER_SCRIPT_NAME = $_SERVER["SCRIPT_NAME"]; // /py4e/koseu.php
if ( ! $uri ) $uri = $_SERVER['REQUEST_URI']; // /py4e/lessons/intro/happy
// Remove Query string...
$pos = strpos($uri, '?');
if ( $pos !== false ) $uri = substr($uri,0,$pos);
$cwd = dirname($SERVER_SCRIPT_NAME);
if ( strpos($uri,$cwd) !== 0 ) return false;
$controller = '';
$extra = '';
$remainder = substr($uri, strlen($cwd));
if ( strpos($remainder,'/') === 0 ) $remainder = substr($remainder,1);
if ( strlen($remainder) > 1 ) {
$pieces = explode('/',$remainder,2);
if ( count($pieces) > 0 ) $controller = $pieces[0];
if ( count($pieces) > 1 ) $extra = $pieces[1];
}
if ( $cwd == '/' ) $cwd = '';
$retval = array($cwd, $controller, $extra);
return $retval;
} | [
"public",
"static",
"function",
"parse_rest_path",
"(",
"$",
"uri",
"=",
"false",
",",
"$",
"SERVER_SCRIPT_NAME",
"=",
"false",
"/* unit test only */",
")",
"{",
"if",
"(",
"!",
"$",
"SERVER_SCRIPT_NAME",
")",
"$",
"SERVER_SCRIPT_NAME",
"=",
"$",
"_SERVER",
"[",
"\"SCRIPT_NAME\"",
"]",
";",
"// /py4e/koseu.php",
"if",
"(",
"!",
"$",
"uri",
")",
"$",
"uri",
"=",
"$",
"_SERVER",
"[",
"'REQUEST_URI'",
"]",
";",
"// /py4e/lessons/intro/happy",
"// Remove Query string...",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"uri",
",",
"'?'",
")",
";",
"if",
"(",
"$",
"pos",
"!==",
"false",
")",
"$",
"uri",
"=",
"substr",
"(",
"$",
"uri",
",",
"0",
",",
"$",
"pos",
")",
";",
"$",
"cwd",
"=",
"dirname",
"(",
"$",
"SERVER_SCRIPT_NAME",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"uri",
",",
"$",
"cwd",
")",
"!==",
"0",
")",
"return",
"false",
";",
"$",
"controller",
"=",
"''",
";",
"$",
"extra",
"=",
"''",
";",
"$",
"remainder",
"=",
"substr",
"(",
"$",
"uri",
",",
"strlen",
"(",
"$",
"cwd",
")",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"remainder",
",",
"'/'",
")",
"===",
"0",
")",
"$",
"remainder",
"=",
"substr",
"(",
"$",
"remainder",
",",
"1",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"remainder",
")",
">",
"1",
")",
"{",
"$",
"pieces",
"=",
"explode",
"(",
"'/'",
",",
"$",
"remainder",
",",
"2",
")",
";",
"if",
"(",
"count",
"(",
"$",
"pieces",
")",
">",
"0",
")",
"$",
"controller",
"=",
"$",
"pieces",
"[",
"0",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"pieces",
")",
">",
"1",
")",
"$",
"extra",
"=",
"$",
"pieces",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"$",
"cwd",
"==",
"'/'",
")",
"$",
"cwd",
"=",
"''",
";",
"$",
"retval",
"=",
"array",
"(",
"$",
"cwd",
",",
"$",
"controller",
",",
"$",
"extra",
")",
";",
"return",
"$",
"retval",
";",
"}"
]
| Get the controller for the current request
executing script: /py4e/koseu.php
input: /py4e/lessons/intro?x=2
output: (/py4e, lessons, intro)
input: /py4e/lessons/intro/?x=2
output: /py4e/lessons/intro | [
"Get",
"the",
"controller",
"for",
"the",
"current",
"request"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/U.php#L165-L187 | train |
tsugiproject/tsugi-php | src/Util/U.php | U.rest_path | public static function rest_path($uri=false, $SERVER_SCRIPT_NAME=false /* unit test only */) {
global $CFG;
$retval = self::parse_rest_path($uri, $SERVER_SCRIPT_NAME);
if ( ! is_array($retval) ) return false;
$retobj = new \stdClass();
if ( $retval[0] == '/' ) {
$retobj->parent = '';
} else {
$retobj->parent = $retval[0];
}
$retobj->base_url = self::get_base_url($CFG->wwwroot);
$retobj->controller = $retval[1];
$retobj->extra = $retval[2];
$pieces = explode('/', $retval[2]);
$retobj->action = false;
$retobj->parameters = array();
if ( count($pieces) > 0 && strlen($pieces[0]) ) {
$retobj->action = array_shift($pieces);
$retobj->parameters = $pieces;
}
$retobj->current = $retobj->parent;
$retobj->full = $retobj->parent;
if ( strlen($retobj->controller) > 0 ) {
$retobj->current .= '/' . $retobj->controller;
$retobj->full .= '/' . $retobj->controller;
}
if ( strlen($retobj->extra) > 0 ) {
$retobj->full .= '/' . $retobj->extra;
}
return $retobj;
} | php | public static function rest_path($uri=false, $SERVER_SCRIPT_NAME=false /* unit test only */) {
global $CFG;
$retval = self::parse_rest_path($uri, $SERVER_SCRIPT_NAME);
if ( ! is_array($retval) ) return false;
$retobj = new \stdClass();
if ( $retval[0] == '/' ) {
$retobj->parent = '';
} else {
$retobj->parent = $retval[0];
}
$retobj->base_url = self::get_base_url($CFG->wwwroot);
$retobj->controller = $retval[1];
$retobj->extra = $retval[2];
$pieces = explode('/', $retval[2]);
$retobj->action = false;
$retobj->parameters = array();
if ( count($pieces) > 0 && strlen($pieces[0]) ) {
$retobj->action = array_shift($pieces);
$retobj->parameters = $pieces;
}
$retobj->current = $retobj->parent;
$retobj->full = $retobj->parent;
if ( strlen($retobj->controller) > 0 ) {
$retobj->current .= '/' . $retobj->controller;
$retobj->full .= '/' . $retobj->controller;
}
if ( strlen($retobj->extra) > 0 ) {
$retobj->full .= '/' . $retobj->extra;
}
return $retobj;
} | [
"public",
"static",
"function",
"rest_path",
"(",
"$",
"uri",
"=",
"false",
",",
"$",
"SERVER_SCRIPT_NAME",
"=",
"false",
"/* unit test only */",
")",
"{",
"global",
"$",
"CFG",
";",
"$",
"retval",
"=",
"self",
"::",
"parse_rest_path",
"(",
"$",
"uri",
",",
"$",
"SERVER_SCRIPT_NAME",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"retval",
")",
")",
"return",
"false",
";",
"$",
"retobj",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"if",
"(",
"$",
"retval",
"[",
"0",
"]",
"==",
"'/'",
")",
"{",
"$",
"retobj",
"->",
"parent",
"=",
"''",
";",
"}",
"else",
"{",
"$",
"retobj",
"->",
"parent",
"=",
"$",
"retval",
"[",
"0",
"]",
";",
"}",
"$",
"retobj",
"->",
"base_url",
"=",
"self",
"::",
"get_base_url",
"(",
"$",
"CFG",
"->",
"wwwroot",
")",
";",
"$",
"retobj",
"->",
"controller",
"=",
"$",
"retval",
"[",
"1",
"]",
";",
"$",
"retobj",
"->",
"extra",
"=",
"$",
"retval",
"[",
"2",
"]",
";",
"$",
"pieces",
"=",
"explode",
"(",
"'/'",
",",
"$",
"retval",
"[",
"2",
"]",
")",
";",
"$",
"retobj",
"->",
"action",
"=",
"false",
";",
"$",
"retobj",
"->",
"parameters",
"=",
"array",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"pieces",
")",
">",
"0",
"&&",
"strlen",
"(",
"$",
"pieces",
"[",
"0",
"]",
")",
")",
"{",
"$",
"retobj",
"->",
"action",
"=",
"array_shift",
"(",
"$",
"pieces",
")",
";",
"$",
"retobj",
"->",
"parameters",
"=",
"$",
"pieces",
";",
"}",
"$",
"retobj",
"->",
"current",
"=",
"$",
"retobj",
"->",
"parent",
";",
"$",
"retobj",
"->",
"full",
"=",
"$",
"retobj",
"->",
"parent",
";",
"if",
"(",
"strlen",
"(",
"$",
"retobj",
"->",
"controller",
")",
">",
"0",
")",
"{",
"$",
"retobj",
"->",
"current",
".=",
"'/'",
".",
"$",
"retobj",
"->",
"controller",
";",
"$",
"retobj",
"->",
"full",
".=",
"'/'",
".",
"$",
"retobj",
"->",
"controller",
";",
"}",
"if",
"(",
"strlen",
"(",
"$",
"retobj",
"->",
"extra",
")",
">",
"0",
")",
"{",
"$",
"retobj",
"->",
"full",
".=",
"'/'",
".",
"$",
"retobj",
"->",
"extra",
";",
"}",
"return",
"$",
"retobj",
";",
"}"
]
| Return a rest-path
This knows the current working folder we are in. The model
is that a folder is an "application" with many possible controllers
and within each controller there are actions followed by parameters.
for example, assume these files exist in a folder:
../tsugi/mod/zap/index.php
../tsugi/mod/zap/rows.php
../tsugi/mod/zap/store.php
If this URL were called with .htaccess and tsugi.php set up, rows.php
would be run and this would be the output:
http://localhost:8888/tsugi/mod/zap/rows/add/1/2
base_url: http://localhost:8888
parent: /tsugi/mod/zap
current: /tsugi/mod/zap/rows
controller: rows
action: add
parameters: (1, 2)
full: /tsugi/mod/zap/rows/add/1/2
As a special case, when the index.php runs (not through tsugi.php)
The results are as follows:
http://localhost:8888/tsugi/mod/zap/
base_url: http://localhost:8888
parent: /tsugi/mod/zap
current: /tsugi/mod/zap
controller: empty string
action: empty string
parameters: empty array
full: /tsugi/mod/zap | [
"Return",
"a",
"rest",
"-",
"path"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/U.php#L226-L257 | train |
tsugiproject/tsugi-php | src/Util/U.php | U.remove_relative_path | public static function remove_relative_path($path) {
$pieces = explode('/', $path);
$new_pieces = array();
for($i=0; $i < count($pieces); $i++) {
if ($pieces[$i] == '.' ) continue;
if ($pieces[$i] == '..' ) {
array_pop($new_pieces);
continue;
}
$new_pieces[] = $pieces[$i];
}
$retval = implode("/",$new_pieces);
return $retval;
} | php | public static function remove_relative_path($path) {
$pieces = explode('/', $path);
$new_pieces = array();
for($i=0; $i < count($pieces); $i++) {
if ($pieces[$i] == '.' ) continue;
if ($pieces[$i] == '..' ) {
array_pop($new_pieces);
continue;
}
$new_pieces[] = $pieces[$i];
}
$retval = implode("/",$new_pieces);
return $retval;
} | [
"public",
"static",
"function",
"remove_relative_path",
"(",
"$",
"path",
")",
"{",
"$",
"pieces",
"=",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
";",
"$",
"new_pieces",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"pieces",
")",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"$",
"pieces",
"[",
"$",
"i",
"]",
"==",
"'.'",
")",
"continue",
";",
"if",
"(",
"$",
"pieces",
"[",
"$",
"i",
"]",
"==",
"'..'",
")",
"{",
"array_pop",
"(",
"$",
"new_pieces",
")",
";",
"continue",
";",
"}",
"$",
"new_pieces",
"[",
"]",
"=",
"$",
"pieces",
"[",
"$",
"i",
"]",
";",
"}",
"$",
"retval",
"=",
"implode",
"(",
"\"/\"",
",",
"$",
"new_pieces",
")",
";",
"return",
"$",
"retval",
";",
"}"
]
| Remove any relative elements from a path
Before After
a/b/c a/b/c
a/b/c/ a/b/c/
a/./c/ a/c/
a/../c/ c/ | [
"Remove",
"any",
"relative",
"elements",
"from",
"a",
"path"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/U.php#L324-L337 | train |
tsugiproject/tsugi-php | src/Util/U.php | U.http_response_code | public static function http_response_code($newcode = NULL)
{
static $code = 200;
if($newcode !== NULL)
{
header('X-PHP-Response-Code: '.$newcode, true, $newcode);
if(!headers_sent())
$code = $newcode;
}
return $code;
} | php | public static function http_response_code($newcode = NULL)
{
static $code = 200;
if($newcode !== NULL)
{
header('X-PHP-Response-Code: '.$newcode, true, $newcode);
if(!headers_sent())
$code = $newcode;
}
return $code;
} | [
"public",
"static",
"function",
"http_response_code",
"(",
"$",
"newcode",
"=",
"NULL",
")",
"{",
"static",
"$",
"code",
"=",
"200",
";",
"if",
"(",
"$",
"newcode",
"!==",
"NULL",
")",
"{",
"header",
"(",
"'X-PHP-Response-Code: '",
".",
"$",
"newcode",
",",
"true",
",",
"$",
"newcode",
")",
";",
"if",
"(",
"!",
"headers_sent",
"(",
")",
")",
"$",
"code",
"=",
"$",
"newcode",
";",
"}",
"return",
"$",
"code",
";",
"}"
]
| For 4.3.0 <= PHP <= 5.4.0 | [
"For",
"4",
".",
"3",
".",
"0",
"<",
"=",
"PHP",
"<",
"=",
"5",
".",
"4",
".",
"0"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/U.php#L356-L366 | train |
tsugiproject/tsugi-php | src/Util/U.php | U.array_Integer_Deserialize | public static function array_Integer_Deserialize($input) {
$r = array();
preg_match_all("/([^,= ]+)=([^,= ]+)/", $input, $r);
$result = array();
for($i=0; $i<count($r[1]);$i++) {
$k = $r[1][$i];
$v = $r[2][$i];
if ( !is_numeric($k) || !is_numeric($v) ) {
throw new \Exception('array_Integer_Deserialize requires integers '.$k.'='.$v.' ('.$i.')');
}
$k = $k + 0;
$v = $v + 0;
if ( ! is_int($k) || ! is_int($v) ) {
throw new \Exception('array_Integer_Deserialize requires integers '.$k.'='.$v.' ('.$i.')');
}
$result[$k] = $v;
}
return $result;
} | php | public static function array_Integer_Deserialize($input) {
$r = array();
preg_match_all("/([^,= ]+)=([^,= ]+)/", $input, $r);
$result = array();
for($i=0; $i<count($r[1]);$i++) {
$k = $r[1][$i];
$v = $r[2][$i];
if ( !is_numeric($k) || !is_numeric($v) ) {
throw new \Exception('array_Integer_Deserialize requires integers '.$k.'='.$v.' ('.$i.')');
}
$k = $k + 0;
$v = $v + 0;
if ( ! is_int($k) || ! is_int($v) ) {
throw new \Exception('array_Integer_Deserialize requires integers '.$k.'='.$v.' ('.$i.')');
}
$result[$k] = $v;
}
return $result;
} | [
"public",
"static",
"function",
"array_Integer_Deserialize",
"(",
"$",
"input",
")",
"{",
"$",
"r",
"=",
"array",
"(",
")",
";",
"preg_match_all",
"(",
"\"/([^,= ]+)=([^,= ]+)/\"",
",",
"$",
"input",
",",
"$",
"r",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"count",
"(",
"$",
"r",
"[",
"1",
"]",
")",
";",
"$",
"i",
"++",
")",
"{",
"$",
"k",
"=",
"$",
"r",
"[",
"1",
"]",
"[",
"$",
"i",
"]",
";",
"$",
"v",
"=",
"$",
"r",
"[",
"2",
"]",
"[",
"$",
"i",
"]",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"k",
")",
"||",
"!",
"is_numeric",
"(",
"$",
"v",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'array_Integer_Deserialize requires integers '",
".",
"$",
"k",
".",
"'='",
".",
"$",
"v",
".",
"' ('",
".",
"$",
"i",
".",
"')'",
")",
";",
"}",
"$",
"k",
"=",
"$",
"k",
"+",
"0",
";",
"$",
"v",
"=",
"$",
"v",
"+",
"0",
";",
"if",
"(",
"!",
"is_int",
"(",
"$",
"k",
")",
"||",
"!",
"is_int",
"(",
"$",
"v",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'array_Integer_Deserialize requires integers '",
".",
"$",
"k",
".",
"'='",
".",
"$",
"v",
".",
"' ('",
".",
"$",
"i",
".",
"')'",
")",
";",
"}",
"$",
"result",
"[",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Deserialize an tightly serialized integer-only PHP array
$str = '1=42,2=43,3=44';
$arar = U::array_Integer_Deserialize($str);
print_r($arar); // Array ( '1' => 42 ,'2' => 43, '3' => 44 );
https://stackoverflow.com/questions/4923951/php-split-string-in-key-value-pairs | [
"Deserialize",
"an",
"tightly",
"serialized",
"integer",
"-",
"only",
"PHP",
"array"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/U.php#L483-L502 | train |
tsugiproject/tsugi-php | src/Util/U.php | U.getCaller | public static function getCaller($count=1)
{
$dbts=debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS,6+$count);
if ( ! is_array($dbts) || count($dbts) < 2 ) return null;
if ( ! isset($dbts[0]['file']) ) return null;
$myfile = $dbts[0]['file'];
$retval = '';
foreach($dbts as $dbt) {
if ( ! isset($dbt['file']) ) continue;
if ( ! isset($dbt['line']) ) continue;
if ( $myfile != $dbt['file'] ) {
if ( strlen($retval) > 0 ) $retval .= " ";
$retval.= $dbt['file'].':'.$dbt['line'];
$count--;
if ( $count < 1 ) return $retval;
}
}
return $retval;
} | php | public static function getCaller($count=1)
{
$dbts=debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS,6+$count);
if ( ! is_array($dbts) || count($dbts) < 2 ) return null;
if ( ! isset($dbts[0]['file']) ) return null;
$myfile = $dbts[0]['file'];
$retval = '';
foreach($dbts as $dbt) {
if ( ! isset($dbt['file']) ) continue;
if ( ! isset($dbt['line']) ) continue;
if ( $myfile != $dbt['file'] ) {
if ( strlen($retval) > 0 ) $retval .= " ";
$retval.= $dbt['file'].':'.$dbt['line'];
$count--;
if ( $count < 1 ) return $retval;
}
}
return $retval;
} | [
"public",
"static",
"function",
"getCaller",
"(",
"$",
"count",
"=",
"1",
")",
"{",
"$",
"dbts",
"=",
"debug_backtrace",
"(",
"DEBUG_BACKTRACE_IGNORE_ARGS",
",",
"6",
"+",
"$",
"count",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"dbts",
")",
"||",
"count",
"(",
"$",
"dbts",
")",
"<",
"2",
")",
"return",
"null",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"dbts",
"[",
"0",
"]",
"[",
"'file'",
"]",
")",
")",
"return",
"null",
";",
"$",
"myfile",
"=",
"$",
"dbts",
"[",
"0",
"]",
"[",
"'file'",
"]",
";",
"$",
"retval",
"=",
"''",
";",
"foreach",
"(",
"$",
"dbts",
"as",
"$",
"dbt",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"dbt",
"[",
"'file'",
"]",
")",
")",
"continue",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"dbt",
"[",
"'line'",
"]",
")",
")",
"continue",
";",
"if",
"(",
"$",
"myfile",
"!=",
"$",
"dbt",
"[",
"'file'",
"]",
")",
"{",
"if",
"(",
"strlen",
"(",
"$",
"retval",
")",
">",
"0",
")",
"$",
"retval",
".=",
"\" \"",
";",
"$",
"retval",
".=",
"$",
"dbt",
"[",
"'file'",
"]",
".",
"':'",
".",
"$",
"dbt",
"[",
"'line'",
"]",
";",
"$",
"count",
"--",
";",
"if",
"(",
"$",
"count",
"<",
"1",
")",
"return",
"$",
"retval",
";",
"}",
"}",
"return",
"$",
"retval",
";",
"}"
]
| Need to replicate the code or U.php will be in the traceback | [
"Need",
"to",
"replicate",
"the",
"code",
"or",
"U",
".",
"php",
"will",
"be",
"in",
"the",
"traceback"
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/Util/U.php#L598-L616 | train |
bearsunday/BEAR.Resource | src/Linker.php | Linker.annotationCrawl | private function annotationCrawl(array $annotations, LinkType $link, ResourceObject $current) : ResourceObject
{
$isList = $this->isList($current->body);
$bodyList = $isList ? (array) $current->body : [$current->body];
foreach ($bodyList as &$body) {
/* @noinspection ExceptionsAnnotatingAndHandlingInspection */
$this->crawl($annotations, $link, $body);
}
unset($body);
$current->body = $isList ? $bodyList : $bodyList[0];
return $current;
} | php | private function annotationCrawl(array $annotations, LinkType $link, ResourceObject $current) : ResourceObject
{
$isList = $this->isList($current->body);
$bodyList = $isList ? (array) $current->body : [$current->body];
foreach ($bodyList as &$body) {
/* @noinspection ExceptionsAnnotatingAndHandlingInspection */
$this->crawl($annotations, $link, $body);
}
unset($body);
$current->body = $isList ? $bodyList : $bodyList[0];
return $current;
} | [
"private",
"function",
"annotationCrawl",
"(",
"array",
"$",
"annotations",
",",
"LinkType",
"$",
"link",
",",
"ResourceObject",
"$",
"current",
")",
":",
"ResourceObject",
"{",
"$",
"isList",
"=",
"$",
"this",
"->",
"isList",
"(",
"$",
"current",
"->",
"body",
")",
";",
"$",
"bodyList",
"=",
"$",
"isList",
"?",
"(",
"array",
")",
"$",
"current",
"->",
"body",
":",
"[",
"$",
"current",
"->",
"body",
"]",
";",
"foreach",
"(",
"$",
"bodyList",
"as",
"&",
"$",
"body",
")",
"{",
"/* @noinspection ExceptionsAnnotatingAndHandlingInspection */",
"$",
"this",
"->",
"crawl",
"(",
"$",
"annotations",
",",
"$",
"link",
",",
"$",
"body",
")",
";",
"}",
"unset",
"(",
"$",
"body",
")",
";",
"$",
"current",
"->",
"body",
"=",
"$",
"isList",
"?",
"$",
"bodyList",
":",
"$",
"bodyList",
"[",
"0",
"]",
";",
"return",
"$",
"current",
";",
"}"
]
| Link annotation crawl
@throws \BEAR\Resource\Exception\MethodException | [
"Link",
"annotation",
"crawl"
]
| c3b396a6c725ecce9345565b1e4d563d95e11bec | https://github.com/bearsunday/BEAR.Resource/blob/c3b396a6c725ecce9345565b1e4d563d95e11bec/src/Linker.php#L149-L161 | train |
rokka-io/rokka-client-php | src/Core/AbstractStack.php | AbstractStack.getStackOperationsByName | public function getStackOperationsByName($name)
{
$stackOperations = [];
foreach ($this->stackOperations as $stackOperation) {
if ($stackOperation->name === $name) {
$stackOperations[] = $stackOperation;
}
}
return $stackOperations;
} | php | public function getStackOperationsByName($name)
{
$stackOperations = [];
foreach ($this->stackOperations as $stackOperation) {
if ($stackOperation->name === $name) {
$stackOperations[] = $stackOperation;
}
}
return $stackOperations;
} | [
"public",
"function",
"getStackOperationsByName",
"(",
"$",
"name",
")",
"{",
"$",
"stackOperations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"stackOperations",
"as",
"$",
"stackOperation",
")",
"{",
"if",
"(",
"$",
"stackOperation",
"->",
"name",
"===",
"$",
"name",
")",
"{",
"$",
"stackOperations",
"[",
"]",
"=",
"$",
"stackOperation",
";",
"}",
"}",
"return",
"$",
"stackOperations",
";",
"}"
]
| Returns all operations matching name.
@since 1.2.0
@param string $name operation name
@return StackOperation[] | [
"Returns",
"all",
"operations",
"matching",
"name",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Core/AbstractStack.php#L76-L86 | train |
tsugiproject/tsugi-php | src/OAuth/OAuthUtil.php | OAuthUtil.get_headers | public static function get_headers() {
$headers = OAuthUtil::get_headers_internal();
if ( ! is_array($headers) ) return $headers;
if ( (! isset($headers['Authorization'])) && isset($headers['X-Oauth1-Authorization']) ) {
$headers['Authorization'] = $headers['X-Oauth1-Authorization'];
}
return $headers;
} | php | public static function get_headers() {
$headers = OAuthUtil::get_headers_internal();
if ( ! is_array($headers) ) return $headers;
if ( (! isset($headers['Authorization'])) && isset($headers['X-Oauth1-Authorization']) ) {
$headers['Authorization'] = $headers['X-Oauth1-Authorization'];
}
return $headers;
} | [
"public",
"static",
"function",
"get_headers",
"(",
")",
"{",
"$",
"headers",
"=",
"OAuthUtil",
"::",
"get_headers_internal",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"headers",
")",
")",
"return",
"$",
"headers",
";",
"if",
"(",
"(",
"!",
"isset",
"(",
"$",
"headers",
"[",
"'Authorization'",
"]",
")",
")",
"&&",
"isset",
"(",
"$",
"headers",
"[",
"'X-Oauth1-Authorization'",
"]",
")",
")",
"{",
"$",
"headers",
"[",
"'Authorization'",
"]",
"=",
"$",
"headers",
"[",
"'X-Oauth1-Authorization'",
"]",
";",
"}",
"return",
"$",
"headers",
";",
"}"
]
| header on our behalf - fall back to the alternate Authorization header. | [
"header",
"on",
"our",
"behalf",
"-",
"fall",
"back",
"to",
"the",
"alternate",
"Authorization",
"header",
"."
]
| b5397a98540f6cf4dc3981f1802c450b90d1fa44 | https://github.com/tsugiproject/tsugi-php/blob/b5397a98540f6cf4dc3981f1802c450b90d1fa44/src/OAuth/OAuthUtil.php#L81-L88 | train |
rokka-io/rokka-client-php | src/Core/UriComponents.php | UriComponents.createFromArray | public static function createFromArray($config)
{
if (!isset($config['stack'])) {
throw new \RuntimeException('Stack has to be set');
}
$hash = isset($config['hash']) ? $config['hash'] : null;
$format = isset($config['format']) ? $config['format'] : null;
$filename = isset($config['filename']) ? $config['filename'] : null;
return new self($config['stack'], $hash, $format, $filename);
} | php | public static function createFromArray($config)
{
if (!isset($config['stack'])) {
throw new \RuntimeException('Stack has to be set');
}
$hash = isset($config['hash']) ? $config['hash'] : null;
$format = isset($config['format']) ? $config['format'] : null;
$filename = isset($config['filename']) ? $config['filename'] : null;
return new self($config['stack'], $hash, $format, $filename);
} | [
"public",
"static",
"function",
"createFromArray",
"(",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'stack'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Stack has to be set'",
")",
";",
"}",
"$",
"hash",
"=",
"isset",
"(",
"$",
"config",
"[",
"'hash'",
"]",
")",
"?",
"$",
"config",
"[",
"'hash'",
"]",
":",
"null",
";",
"$",
"format",
"=",
"isset",
"(",
"$",
"config",
"[",
"'format'",
"]",
")",
"?",
"$",
"config",
"[",
"'format'",
"]",
":",
"null",
";",
"$",
"filename",
"=",
"isset",
"(",
"$",
"config",
"[",
"'filename'",
"]",
")",
"?",
"$",
"config",
"[",
"'filename'",
"]",
":",
"null",
";",
"return",
"new",
"self",
"(",
"$",
"config",
"[",
"'stack'",
"]",
",",
"$",
"hash",
",",
"$",
"format",
",",
"$",
"filename",
")",
";",
"}"
]
| Creates a UriComponent object from an array with 'stack', 'hash', 'format', 'filename' and 'stack' as keys.
@since 1.2.0
@param mixed $config | [
"Creates",
"a",
"UriComponent",
"object",
"from",
"an",
"array",
"with",
"stack",
"hash",
"format",
"filename",
"and",
"stack",
"as",
"keys",
"."
]
| ab037e0fd38b110211a0f7afb70f379e30756bdc | https://github.com/rokka-io/rokka-client-php/blob/ab037e0fd38b110211a0f7afb70f379e30756bdc/src/Core/UriComponents.php#L59-L69 | train |
grasmash/drupal-security-warning | src/Composer/Plugin.php | Plugin.isPackageSupported | protected function isPackageSupported($package)
{
$extra = $package->getExtra();
if (!empty($extra['drupal']['security-coverage']['status'])
&& $extra['drupal']['security-coverage']['status'] == 'not-covered') {
return false;
}
return true;
} | php | protected function isPackageSupported($package)
{
$extra = $package->getExtra();
if (!empty($extra['drupal']['security-coverage']['status'])
&& $extra['drupal']['security-coverage']['status'] == 'not-covered') {
return false;
}
return true;
} | [
"protected",
"function",
"isPackageSupported",
"(",
"$",
"package",
")",
"{",
"$",
"extra",
"=",
"$",
"package",
"->",
"getExtra",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"extra",
"[",
"'drupal'",
"]",
"[",
"'security-coverage'",
"]",
"[",
"'status'",
"]",
")",
"&&",
"$",
"extra",
"[",
"'drupal'",
"]",
"[",
"'security-coverage'",
"]",
"[",
"'status'",
"]",
"==",
"'not-covered'",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Checks to see if this Drupal package is supported by the Drupal Security Team.
@param \Composer\Package\PackageInterface $package
@return bool | [
"Checks",
"to",
"see",
"if",
"this",
"Drupal",
"package",
"is",
"supported",
"by",
"the",
"Drupal",
"Security",
"Team",
"."
]
| 59ff99aed70f17020c5d5018e30e3d8f0eaa6ee7 | https://github.com/grasmash/drupal-security-warning/blob/59ff99aed70f17020c5d5018e30e3d8f0eaa6ee7/src/Composer/Plugin.php#L86-L94 | train |
grasmash/drupal-security-warning | src/Composer/Plugin.php | Plugin.onPostCmdEvent | public function onPostCmdEvent(\Composer\Script\Event $event)
{
if (!empty($this->unsupportedPackages)) {
$this->io->write(
'<error>You are using Drupal packages that are not supported by the Drupal Security Team!</error>'
);
foreach ($this->unsupportedPackages as $package_name => $package) {
$extra = $package->getExtra();
$this->io->write(
" - <comment>$package_name:{$package->getVersion()}</comment>: {$extra['drupal']['security-coverage']['message']}"
);
}
$this->io->write(
'<comment>See https://www.drupal.org/security-advisory-policy for more information.</comment>'
);
}
} | php | public function onPostCmdEvent(\Composer\Script\Event $event)
{
if (!empty($this->unsupportedPackages)) {
$this->io->write(
'<error>You are using Drupal packages that are not supported by the Drupal Security Team!</error>'
);
foreach ($this->unsupportedPackages as $package_name => $package) {
$extra = $package->getExtra();
$this->io->write(
" - <comment>$package_name:{$package->getVersion()}</comment>: {$extra['drupal']['security-coverage']['message']}"
);
}
$this->io->write(
'<comment>See https://www.drupal.org/security-advisory-policy for more information.</comment>'
);
}
} | [
"public",
"function",
"onPostCmdEvent",
"(",
"\\",
"Composer",
"\\",
"Script",
"\\",
"Event",
"$",
"event",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"unsupportedPackages",
")",
")",
"{",
"$",
"this",
"->",
"io",
"->",
"write",
"(",
"'<error>You are using Drupal packages that are not supported by the Drupal Security Team!</error>'",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"unsupportedPackages",
"as",
"$",
"package_name",
"=>",
"$",
"package",
")",
"{",
"$",
"extra",
"=",
"$",
"package",
"->",
"getExtra",
"(",
")",
";",
"$",
"this",
"->",
"io",
"->",
"write",
"(",
"\" - <comment>$package_name:{$package->getVersion()}</comment>: {$extra['drupal']['security-coverage']['message']}\"",
")",
";",
"}",
"$",
"this",
"->",
"io",
"->",
"write",
"(",
"'<comment>See https://www.drupal.org/security-advisory-policy for more information.</comment>'",
")",
";",
"}",
"}"
]
| Execute blt update after update command has been executed, if applicable.
@param \Composer\Script\Event $event | [
"Execute",
"blt",
"update",
"after",
"update",
"command",
"has",
"been",
"executed",
"if",
"applicable",
"."
]
| 59ff99aed70f17020c5d5018e30e3d8f0eaa6ee7 | https://github.com/grasmash/drupal-security-warning/blob/59ff99aed70f17020c5d5018e30e3d8f0eaa6ee7/src/Composer/Plugin.php#L101-L117 | train |
grasmash/drupal-security-warning | src/Composer/Plugin.php | Plugin.getDrupalPackage | protected function getDrupalPackage($operation)
{
if ($operation instanceof InstallOperation) {
$package = $operation->getPackage();
} elseif ($operation instanceof UpdateOperation) {
$package = $operation->getTargetPackage();
}
if ($this->isDrupalPackage($package)) {
return $package;
}
return null;
} | php | protected function getDrupalPackage($operation)
{
if ($operation instanceof InstallOperation) {
$package = $operation->getPackage();
} elseif ($operation instanceof UpdateOperation) {
$package = $operation->getTargetPackage();
}
if ($this->isDrupalPackage($package)) {
return $package;
}
return null;
} | [
"protected",
"function",
"getDrupalPackage",
"(",
"$",
"operation",
")",
"{",
"if",
"(",
"$",
"operation",
"instanceof",
"InstallOperation",
")",
"{",
"$",
"package",
"=",
"$",
"operation",
"->",
"getPackage",
"(",
")",
";",
"}",
"elseif",
"(",
"$",
"operation",
"instanceof",
"UpdateOperation",
")",
"{",
"$",
"package",
"=",
"$",
"operation",
"->",
"getTargetPackage",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isDrupalPackage",
"(",
"$",
"package",
")",
")",
"{",
"return",
"$",
"package",
";",
"}",
"return",
"null",
";",
"}"
]
| Gets the package if it is a Drupal related package.
@param $operation
@return mixed
If the package is a Drupal package, it will be returned. Otherwise, NULL. | [
"Gets",
"the",
"package",
"if",
"it",
"is",
"a",
"Drupal",
"related",
"package",
"."
]
| 59ff99aed70f17020c5d5018e30e3d8f0eaa6ee7 | https://github.com/grasmash/drupal-security-warning/blob/59ff99aed70f17020c5d5018e30e3d8f0eaa6ee7/src/Composer/Plugin.php#L127-L138 | train |
grasmash/drupal-security-warning | src/Composer/Plugin.php | Plugin.isDrupalPackage | protected function isDrupalPackage($package)
{
if (isset($package) && $package instanceof PackageInterface && strstr($package->getName(), 'drupal/')) {
return true;
}
return false;
} | php | protected function isDrupalPackage($package)
{
if (isset($package) && $package instanceof PackageInterface && strstr($package->getName(), 'drupal/')) {
return true;
}
return false;
} | [
"protected",
"function",
"isDrupalPackage",
"(",
"$",
"package",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"package",
")",
"&&",
"$",
"package",
"instanceof",
"PackageInterface",
"&&",
"strstr",
"(",
"$",
"package",
"->",
"getName",
"(",
")",
",",
"'drupal/'",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| Checks to see if a given package is a Drupal package.
@param $package
@return bool
TRUE if the package is a Drupal package. | [
"Checks",
"to",
"see",
"if",
"a",
"given",
"package",
"is",
"a",
"Drupal",
"package",
"."
]
| 59ff99aed70f17020c5d5018e30e3d8f0eaa6ee7 | https://github.com/grasmash/drupal-security-warning/blob/59ff99aed70f17020c5d5018e30e3d8f0eaa6ee7/src/Composer/Plugin.php#L148-L154 | train |
tom--/yii2-dynamic-ar | DynamicActiveQuery.php | DynamicActiveQuery.indexBy | public function indexBy($column)
{
if (!$this->asArray) {
return parent::indexBy($column);
}
/** @var DynamicActiveRecord $modelClass */
$modelClass = $this->modelClass;
$this->indexBy = function ($row) use ($column, $modelClass) {
if (isset($row[$column])) {
return $row[$column];
}
$dynamicColumn = $modelClass::dynamicColumn();
if (!isset($row[$dynamicColumn])) {
throw new UnknownPropertyException("Dynamic column {$dynamicColumn} does not exist - wasn't set in select");
}
$dynamicAttributes = DynamicActiveRecord::dynColDecode($row[$dynamicColumn]);
$value = $this->getDotNotatedValue($dynamicAttributes, $column);
return $value;
};
return $this;
} | php | public function indexBy($column)
{
if (!$this->asArray) {
return parent::indexBy($column);
}
/** @var DynamicActiveRecord $modelClass */
$modelClass = $this->modelClass;
$this->indexBy = function ($row) use ($column, $modelClass) {
if (isset($row[$column])) {
return $row[$column];
}
$dynamicColumn = $modelClass::dynamicColumn();
if (!isset($row[$dynamicColumn])) {
throw new UnknownPropertyException("Dynamic column {$dynamicColumn} does not exist - wasn't set in select");
}
$dynamicAttributes = DynamicActiveRecord::dynColDecode($row[$dynamicColumn]);
$value = $this->getDotNotatedValue($dynamicAttributes, $column);
return $value;
};
return $this;
} | [
"public",
"function",
"indexBy",
"(",
"$",
"column",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"asArray",
")",
"{",
"return",
"parent",
"::",
"indexBy",
"(",
"$",
"column",
")",
";",
"}",
"/** @var DynamicActiveRecord $modelClass */",
"$",
"modelClass",
"=",
"$",
"this",
"->",
"modelClass",
";",
"$",
"this",
"->",
"indexBy",
"=",
"function",
"(",
"$",
"row",
")",
"use",
"(",
"$",
"column",
",",
"$",
"modelClass",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"row",
"[",
"$",
"column",
"]",
")",
")",
"{",
"return",
"$",
"row",
"[",
"$",
"column",
"]",
";",
"}",
"$",
"dynamicColumn",
"=",
"$",
"modelClass",
"::",
"dynamicColumn",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"row",
"[",
"$",
"dynamicColumn",
"]",
")",
")",
"{",
"throw",
"new",
"UnknownPropertyException",
"(",
"\"Dynamic column {$dynamicColumn} does not exist - wasn't set in select\"",
")",
";",
"}",
"$",
"dynamicAttributes",
"=",
"DynamicActiveRecord",
"::",
"dynColDecode",
"(",
"$",
"row",
"[",
"$",
"dynamicColumn",
"]",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"getDotNotatedValue",
"(",
"$",
"dynamicAttributes",
",",
"$",
"column",
")",
";",
"return",
"$",
"value",
";",
"}",
";",
"return",
"$",
"this",
";",
"}"
]
| Converts the indexBy column name an anonymous function that writes rows to the
result array indexed an attribute name that may be in dotted notation.
@param callable|string $column name of the column by which the query results should be indexed
@return $this | [
"Converts",
"the",
"indexBy",
"column",
"name",
"an",
"anonymous",
"function",
"that",
"writes",
"rows",
"to",
"the",
"result",
"array",
"indexed",
"an",
"attribute",
"name",
"that",
"may",
"be",
"in",
"dotted",
"notation",
"."
]
| d2fd52763fb92a5197b044917e924f58fb3e4e9a | https://github.com/tom--/yii2-dynamic-ar/blob/d2fd52763fb92a5197b044917e924f58fb3e4e9a/DynamicActiveQuery.php#L61-L86 | train |
tom--/yii2-dynamic-ar | DynamicActiveQuery.php | DynamicActiveQuery.prepare | public function prepare($builder)
{
/** @var DynamicActiveRecord $modelClass */
$modelClass = $this->modelClass;
$this->_dynamicColumn = $modelClass::dynamicColumn();
if (empty($this->_dynamicColumn)) {
/** @var string $modelClass */
throw new \yii\base\InvalidConfigException(
$modelClass . '::dynamicColumn() must return an attribute name'
);
}
if (empty($this->select)) {
$this->select[] = '*';
}
if (is_array($this->select) && in_array('*', $this->select)) {
$db = $modelClass::getDb();
$this->select[$this->_dynamicColumn] =
'COLUMN_JSON(' . $db->quoteColumnName($this->_dynamicColumn) . ')';
}
return parent::prepare($builder);
} | php | public function prepare($builder)
{
/** @var DynamicActiveRecord $modelClass */
$modelClass = $this->modelClass;
$this->_dynamicColumn = $modelClass::dynamicColumn();
if (empty($this->_dynamicColumn)) {
/** @var string $modelClass */
throw new \yii\base\InvalidConfigException(
$modelClass . '::dynamicColumn() must return an attribute name'
);
}
if (empty($this->select)) {
$this->select[] = '*';
}
if (is_array($this->select) && in_array('*', $this->select)) {
$db = $modelClass::getDb();
$this->select[$this->_dynamicColumn] =
'COLUMN_JSON(' . $db->quoteColumnName($this->_dynamicColumn) . ')';
}
return parent::prepare($builder);
} | [
"public",
"function",
"prepare",
"(",
"$",
"builder",
")",
"{",
"/** @var DynamicActiveRecord $modelClass */",
"$",
"modelClass",
"=",
"$",
"this",
"->",
"modelClass",
";",
"$",
"this",
"->",
"_dynamicColumn",
"=",
"$",
"modelClass",
"::",
"dynamicColumn",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"_dynamicColumn",
")",
")",
"{",
"/** @var string $modelClass */",
"throw",
"new",
"\\",
"yii",
"\\",
"base",
"\\",
"InvalidConfigException",
"(",
"$",
"modelClass",
".",
"'::dynamicColumn() must return an attribute name'",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"select",
")",
")",
"{",
"$",
"this",
"->",
"select",
"[",
"]",
"=",
"'*'",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"select",
")",
"&&",
"in_array",
"(",
"'*'",
",",
"$",
"this",
"->",
"select",
")",
")",
"{",
"$",
"db",
"=",
"$",
"modelClass",
"::",
"getDb",
"(",
")",
";",
"$",
"this",
"->",
"select",
"[",
"$",
"this",
"->",
"_dynamicColumn",
"]",
"=",
"'COLUMN_JSON('",
".",
"$",
"db",
"->",
"quoteColumnName",
"(",
"$",
"this",
"->",
"_dynamicColumn",
")",
".",
"')'",
";",
"}",
"return",
"parent",
"::",
"prepare",
"(",
"$",
"builder",
")",
";",
"}"
]
| Maria-specific preparation for building a query that includes a dynamic column.
@param \yii\db\QueryBuilder $builder
@return \yii\db\Query
@throws \yii\base\Exception
@throws \yii\base\InvalidConfigException | [
"Maria",
"-",
"specific",
"preparation",
"for",
"building",
"a",
"query",
"that",
"includes",
"a",
"dynamic",
"column",
"."
]
| d2fd52763fb92a5197b044917e924f58fb3e4e9a | https://github.com/tom--/yii2-dynamic-ar/blob/d2fd52763fb92a5197b044917e924f58fb3e4e9a/DynamicActiveQuery.php#L97-L121 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.