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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.getFriendStories | function getFriendStories($force = FALSE) {
if (!$force) {
$result = $this->cache->get('stories');
if ($result) {
return $result;
}
}
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/all_updates',
array(
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
if (!empty($result->stories_response)) {
$this->cache->set('stories', $result->stories_response);
}
else {
return FALSE;
}
$stories = array();
foreach ($result->stories_response->friend_stories as $group) {
foreach ($group->stories as $story) {
$stories[] = $story->story;
}
}
return $stories;
} | php | function getFriendStories($force = FALSE) {
if (!$force) {
$result = $this->cache->get('stories');
if ($result) {
return $result;
}
}
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/all_updates',
array(
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
if (!empty($result->stories_response)) {
$this->cache->set('stories', $result->stories_response);
}
else {
return FALSE;
}
$stories = array();
foreach ($result->stories_response->friend_stories as $group) {
foreach ($group->stories as $story) {
$stories[] = $story->story;
}
}
return $stories;
} | [
"function",
"getFriendStories",
"(",
"$",
"force",
"=",
"FALSE",
")",
"{",
"if",
"(",
"!",
"$",
"force",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"'stories'",
")",
";",
"if",
"(",
"$",
"result",
")",
"{",
"retur... | Gets friends' stories.
@param bool $force
Forces an update even if there's fresh data in the cache. Defaults
to FALSE.
@return mixed
An array of stories or FALSE on failure. | [
"Gets",
"friends",
"stories",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L315-L356 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.findFriends | public function findFriends($numbers, $country = 'US') {
$batches = array_chunk(array_flip($numbers), 30, TRUE);
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$results = array();
foreach ($batches as $batch) {
$timestamp = parent::timestamp();
$result = parent::post(
'/find_friends',
array(
'countryCode' => $country,
'numbers' => json_encode($batch),
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
if (isset($result->results)) {
$results = $results + $result->results;
}
}
return $results;
} | php | public function findFriends($numbers, $country = 'US') {
$batches = array_chunk(array_flip($numbers), 30, TRUE);
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$results = array();
foreach ($batches as $batch) {
$timestamp = parent::timestamp();
$result = parent::post(
'/find_friends',
array(
'countryCode' => $country,
'numbers' => json_encode($batch),
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
if (isset($result->results)) {
$results = $results + $result->results;
}
}
return $results;
} | [
"public",
"function",
"findFriends",
"(",
"$",
"numbers",
",",
"$",
"country",
"=",
"'US'",
")",
"{",
"$",
"batches",
"=",
"array_chunk",
"(",
"array_flip",
"(",
"$",
"numbers",
")",
",",
"30",
",",
"TRUE",
")",
";",
"// Make sure we're logged in and have a ... | Queries the friend-finding service.
@todo
If over 30 numbers are passed in, spread the query across multiple
requests. The API won't return more than 30 results at once.
@param array $numbers
An array of phone numbers.
@param string $country
The country code. Defaults to US.
@return mixed
An array of user objects or FALSE on failure. | [
"Queries",
"the",
"friend",
"-",
"finding",
"service",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L373-L404 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.addFriend | public function addFriend($username) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/friend',
array(
'action' => 'add',
'friend' => $username,
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
// Sigh...
if (strpos($result->message, 'Sorry! Couldn\'t find') === 0) {
return FALSE;
}
return !empty($result->message);
} | php | public function addFriend($username) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/friend',
array(
'action' => 'add',
'friend' => $username,
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
// Sigh...
if (strpos($result->message, 'Sorry! Couldn\'t find') === 0) {
return FALSE;
}
return !empty($result->message);
} | [
"public",
"function",
"addFriend",
"(",
"$",
"username",
")",
"{",
"// Make sure we're logged in and have a valid access token.",
"if",
"(",
"!",
"$",
"this",
"->",
"auth_token",
"||",
"!",
"$",
"this",
"->",
"username",
")",
"{",
"return",
"FALSE",
";",
"}",
... | Adds a friend.
@param string $username
The username of the friend to add.
@return bool
TRUE if successful, FALSE otherwise. | [
"Adds",
"a",
"friend",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L447-L474 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.addFriends | public function addFriends($usernames) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$friends = array();
foreach ($usernames as $username) {
$friends[] = (object) array(
'display' => '',
'name' => $username,
'type' => self::FRIEND_UNCONFIRMED,
);
}
$timestamp = parent::timestamp();
$result = parent::post(
'/friend',
array(
'action' => 'multiadddelete',
'friend' => json_encode(array(
'friendsToAdd' => $friends,
'friendsToDelete' => array(),
)),
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return !empty($result->message);
} | php | public function addFriends($usernames) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$friends = array();
foreach ($usernames as $username) {
$friends[] = (object) array(
'display' => '',
'name' => $username,
'type' => self::FRIEND_UNCONFIRMED,
);
}
$timestamp = parent::timestamp();
$result = parent::post(
'/friend',
array(
'action' => 'multiadddelete',
'friend' => json_encode(array(
'friendsToAdd' => $friends,
'friendsToDelete' => array(),
)),
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return !empty($result->message);
} | [
"public",
"function",
"addFriends",
"(",
"$",
"usernames",
")",
"{",
"// Make sure we're logged in and have a valid access token.",
"if",
"(",
"!",
"$",
"this",
"->",
"auth_token",
"||",
"!",
"$",
"this",
"->",
"username",
")",
"{",
"return",
"FALSE",
";",
"}",
... | Adds multiple friends.
@param array $usernames
Usernames of friends to add.
@return bool
TRUE if successful, FALSE otherwise. | [
"Adds",
"multiple",
"friends",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L485-L519 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.setDisplayName | public function setDisplayName($username, $display) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/friend',
array(
'action' => 'display',
'display' => $display,
'friend' => $username,
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return !empty($result->message);
} | php | public function setDisplayName($username, $display) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/friend',
array(
'action' => 'display',
'display' => $display,
'friend' => $username,
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return !empty($result->message);
} | [
"public",
"function",
"setDisplayName",
"(",
"$",
"username",
",",
"$",
"display",
")",
"{",
"// Make sure we're logged in and have a valid access token.",
"if",
"(",
"!",
"$",
"this",
"->",
"auth_token",
"||",
"!",
"$",
"this",
"->",
"username",
")",
"{",
"retu... | Sets a friend's display name.
@param string $username
The username of the user to modify.
@param string $display
The new display name.
@return bool
TRUE if successful, FALSE otherwise. | [
"Sets",
"a",
"friend",
"s",
"display",
"name",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L568-L591 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.getMedia | public function getMedia($id) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/blob',
array(
'id' => $id,
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
if (parent::isMedia(substr($result, 0, 2))) {
return $result;
}
else {
$result = parent::decryptECB($result);
if (parent::isMedia(substr($result, 0, 2))) {
return $result;
}
//When a snapchat video is sent with "text" or overlay
//the overlay is a transparent PNG file Zipped together
//with the M4V file.
//First two bytes are "PK" x50x4B; thus the previous media check
//will fail and would've returned a FALSE on an available media.
if (parent::isCompressed(substr($result, 0, 2))) {
//Uncompress
$result = parent::unCompress($result);
//Return Media and Overlay
return $result;
}
}
return FALSE;
} | php | public function getMedia($id) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/blob',
array(
'id' => $id,
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
if (parent::isMedia(substr($result, 0, 2))) {
return $result;
}
else {
$result = parent::decryptECB($result);
if (parent::isMedia(substr($result, 0, 2))) {
return $result;
}
//When a snapchat video is sent with "text" or overlay
//the overlay is a transparent PNG file Zipped together
//with the M4V file.
//First two bytes are "PK" x50x4B; thus the previous media check
//will fail and would've returned a FALSE on an available media.
if (parent::isCompressed(substr($result, 0, 2))) {
//Uncompress
$result = parent::unCompress($result);
//Return Media and Overlay
return $result;
}
}
return FALSE;
} | [
"public",
"function",
"getMedia",
"(",
"$",
"id",
")",
"{",
"// Make sure we're logged in and have a valid access token.",
"if",
"(",
"!",
"$",
"this",
"->",
"auth_token",
"||",
"!",
"$",
"this",
"->",
"username",
")",
"{",
"return",
"FALSE",
";",
"}",
"$",
... | Downloads a snap.
@param string $id
The snap ID.
@return mixed
The snap data or FALSE on failure.
Snap data can returned as an Array of more than one file.
array(
overlay~zip-CE6F660A-4A9F-4BD6-8183-245C9C75B8A0 => overlay_file_data,
media~zip-CE6F660A-4A9F-4BD6-8183-245C9C75B8A0 => m4v_file_data
) | [
"Downloads",
"a",
"snap",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L674-L718 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.sendEvents | public function sendEvents($events, $snap_info = array()) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/update_snaps',
array(
'events' => json_encode($events),
'json' => json_encode($snap_info),
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return is_null($result);
} | php | public function sendEvents($events, $snap_info = array()) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/update_snaps',
array(
'events' => json_encode($events),
'json' => json_encode($snap_info),
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return is_null($result);
} | [
"public",
"function",
"sendEvents",
"(",
"$",
"events",
",",
"$",
"snap_info",
"=",
"array",
"(",
")",
")",
"{",
"// Make sure we're logged in and have a valid access token.",
"if",
"(",
"!",
"$",
"this",
"->",
"auth_token",
"||",
"!",
"$",
"this",
"->",
"user... | Sends event information to Snapchat.
@param array $events
An array of events. This seems to be used only to report usage data.
@param array $snap_info
Data to send along in addition to the event array. This is used to
mark snaps as viewed. Defaults to an empty array.
@return bool
TRUE if successful, FALSE otherwise. | [
"Sends",
"event",
"information",
"to",
"Snapchat",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L732-L754 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.markSnapViewed | public function markSnapViewed($id, $time = 1) {
$snap_info = array(
$id => array(
// Here Snapchat saw fit to use time as a float instead of
// straight milliseconds.
't' => microtime(TRUE),
// We add a small variation here just to make it look more
// realistic.
'sv' => $time + (mt_rand() / mt_getrandmax() / 10),
),
);
$events = array(
array(
'eventName' => 'SNAP_VIEW',
'params' => array(
'id' => $id,
// There are others, but it wouldn't be worth the effort to
// put them in here since they likely don't matter.
),
'ts' => time() - $time,
),
array(
'eventName' => 'SNAP_EXPIRED',
'params' => array(
'id' => $id,
),
'ts' => time()
),
);
return $this->sendEvents($events, $snap_info);
} | php | public function markSnapViewed($id, $time = 1) {
$snap_info = array(
$id => array(
// Here Snapchat saw fit to use time as a float instead of
// straight milliseconds.
't' => microtime(TRUE),
// We add a small variation here just to make it look more
// realistic.
'sv' => $time + (mt_rand() / mt_getrandmax() / 10),
),
);
$events = array(
array(
'eventName' => 'SNAP_VIEW',
'params' => array(
'id' => $id,
// There are others, but it wouldn't be worth the effort to
// put them in here since they likely don't matter.
),
'ts' => time() - $time,
),
array(
'eventName' => 'SNAP_EXPIRED',
'params' => array(
'id' => $id,
),
'ts' => time()
),
);
return $this->sendEvents($events, $snap_info);
} | [
"public",
"function",
"markSnapViewed",
"(",
"$",
"id",
",",
"$",
"time",
"=",
"1",
")",
"{",
"$",
"snap_info",
"=",
"array",
"(",
"$",
"id",
"=>",
"array",
"(",
"// Here Snapchat saw fit to use time as a float instead of",
"// straight milliseconds.",
"'t'",
"=>"... | Marks a snap as viewed.
Snaps can be downloaded an (apparently) unlimited amount of times before
they are viewed. Once marked as viewed, they are deleted.
It's worth noting that it seems possible to mark others' snaps as viewed
as long as you know the ID. This hasn't been tested thoroughly, but it
could be useful if you send a snap that you immediately regret.
@param string $id
The snap to mark as viewed.
@param int $time
The amount of time (in seconds) the snap was viewed. Defaults to 1.
@return bool
TRUE if successful, FALSE otherwise. | [
"Marks",
"a",
"snap",
"as",
"viewed",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L774-L806 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.markSnapShot | public function markSnapShot($id, $time = 1) {
$snap_info = array(
$id => array(
// We use the same time values as in markSnapViewed, but add in the
// screenshot status.
't' => microtime(TRUE),
'sv' => $time + (mt_rand() / mt_getrandmax() / 10),
'c' => self::STATUS_SCREENSHOT,
),
);
$events = array(
array(
'eventName' => 'SNAP_SCREENSHOT',
'params' => array(
'id' => $id,
),
'ts' => time() - $time,
),
);
return $this->sendEvents($events, $snap_info);
} | php | public function markSnapShot($id, $time = 1) {
$snap_info = array(
$id => array(
// We use the same time values as in markSnapViewed, but add in the
// screenshot status.
't' => microtime(TRUE),
'sv' => $time + (mt_rand() / mt_getrandmax() / 10),
'c' => self::STATUS_SCREENSHOT,
),
);
$events = array(
array(
'eventName' => 'SNAP_SCREENSHOT',
'params' => array(
'id' => $id,
),
'ts' => time() - $time,
),
);
return $this->sendEvents($events, $snap_info);
} | [
"public",
"function",
"markSnapShot",
"(",
"$",
"id",
",",
"$",
"time",
"=",
"1",
")",
"{",
"$",
"snap_info",
"=",
"array",
"(",
"$",
"id",
"=>",
"array",
"(",
"// We use the same time values as in markSnapViewed, but add in the",
"// screenshot status.",
"'t'",
"... | Sends a screenshot event.
@param string $id
The snap to mark as shot.
@param int $time
The amount of time (in seconds) the snap was viewed. Defaults to 1.
@return bool
TRUE if successful, FALSE otherwise. | [
"Sends",
"a",
"screenshot",
"event",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L819-L841 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.upload | public function upload($type, $data) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
// To make cURL happy, we write the data to a file first.
$temp = tempnam(sys_get_temp_dir(), 'Snap');
file_put_contents($temp, parent::encryptECB($data));
if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
$cfile = curl_file_create($temp, ($type == self::MEDIA_IMAGE ? 'image/jpeg' : 'video/quicktime'), 'snap');
}
$media_id = strtoupper($this->username) . '~' . time();
$timestamp = parent::timestamp();
$result = parent::post(
'/upload',
array(
'media_id' => $media_id,
'type' => $type,
'data' => (version_compare(PHP_VERSION, '5.5.0', '>=') ? $cfile : '@' . $temp . ';filename=data'),
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
),
TRUE
);
unlink($temp);
return is_null($result) ? $media_id : FALSE;
} | php | public function upload($type, $data) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
// To make cURL happy, we write the data to a file first.
$temp = tempnam(sys_get_temp_dir(), 'Snap');
file_put_contents($temp, parent::encryptECB($data));
if (version_compare(PHP_VERSION, '5.5.0', '>=')) {
$cfile = curl_file_create($temp, ($type == self::MEDIA_IMAGE ? 'image/jpeg' : 'video/quicktime'), 'snap');
}
$media_id = strtoupper($this->username) . '~' . time();
$timestamp = parent::timestamp();
$result = parent::post(
'/upload',
array(
'media_id' => $media_id,
'type' => $type,
'data' => (version_compare(PHP_VERSION, '5.5.0', '>=') ? $cfile : '@' . $temp . ';filename=data'),
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
),
TRUE
);
unlink($temp);
return is_null($result) ? $media_id : FALSE;
} | [
"public",
"function",
"upload",
"(",
"$",
"type",
",",
"$",
"data",
")",
"{",
"// Make sure we're logged in and have a valid access token.",
"if",
"(",
"!",
"$",
"this",
"->",
"auth_token",
"||",
"!",
"$",
"this",
"->",
"username",
")",
"{",
"return",
"FALSE",... | Uploads a snap.
@todo
Fix media ID generation; it looks like they're GUIDs now.
@param int $type
The media type, i.e. MEDIA_IMAGE or MEDIA_VIDEO.
@param data $data
The file data to upload.
@return mixed
The ID of the uploaded media or FALSE on failure. | [
"Uploads",
"a",
"snap",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L857-L892 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.send | public function send($media_id, $recipients, $time = 3) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/send',
array(
'media_id' => $media_id,
'recipient' => implode(',', $recipients),
'time' => $time,
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return is_null($result);
} | php | public function send($media_id, $recipients, $time = 3) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/send',
array(
'media_id' => $media_id,
'recipient' => implode(',', $recipients),
'time' => $time,
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return is_null($result);
} | [
"public",
"function",
"send",
"(",
"$",
"media_id",
",",
"$",
"recipients",
",",
"$",
"time",
"=",
"3",
")",
"{",
"// Make sure we're logged in and have a valid access token.",
"if",
"(",
"!",
"$",
"this",
"->",
"auth_token",
"||",
"!",
"$",
"this",
"->",
"u... | Sends a snap.
@param string $media_id
The media ID of the snap to send.
@param array $recipients
An array of recipient usernames.
@param int $time
The time in seconds the snap should be available (1-10). Defaults to 3.
@return bool
TRUE if successful, FALSE otherwise. | [
"Sends",
"a",
"snap",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L907-L930 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.setStory | public function setStory($media_id, $media_type, $time = 3) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/post_story',
array(
'client_id' => $media_id,
'media_id' => $media_id,
'time' => $time,
'timestamp' => $timestamp,
'type' => $media_type,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return is_null($result);
} | php | public function setStory($media_id, $media_type, $time = 3) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/post_story',
array(
'client_id' => $media_id,
'media_id' => $media_id,
'time' => $time,
'timestamp' => $timestamp,
'type' => $media_type,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return is_null($result);
} | [
"public",
"function",
"setStory",
"(",
"$",
"media_id",
",",
"$",
"media_type",
",",
"$",
"time",
"=",
"3",
")",
"{",
"// Make sure we're logged in and have a valid access token.",
"if",
"(",
"!",
"$",
"this",
"->",
"auth_token",
"||",
"!",
"$",
"this",
"->",
... | Sets a story.
@param string $media_id
The media ID of the story to set.
@param int $media_type
The media type of the story to set (i.e. MEDIA_IMAGE or MEDIA_VIDEO).
@param int $time
The time in seconds the story should be available (1-10). Defaults to 3.
@return bool
TRUE if successful, FALSE otherwise. | [
"Sets",
"a",
"story",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L945-L969 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.getStory | public function getStory($media_id, $key, $iv) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
// Retrieve encrypted story and decrypt.
$blob = parent::get('/story_blob?story_id=' . $media_id);
if (!empty($blob)) {
return parent::decryptCBC($blob, $key, $iv);
}
return FALSE;
} | php | public function getStory($media_id, $key, $iv) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
// Retrieve encrypted story and decrypt.
$blob = parent::get('/story_blob?story_id=' . $media_id);
if (!empty($blob)) {
return parent::decryptCBC($blob, $key, $iv);
}
return FALSE;
} | [
"public",
"function",
"getStory",
"(",
"$",
"media_id",
",",
"$",
"key",
",",
"$",
"iv",
")",
"{",
"// Make sure we're logged in and have a valid access token.",
"if",
"(",
"!",
"$",
"this",
"->",
"auth_token",
"||",
"!",
"$",
"this",
"->",
"username",
")",
... | Downloads a story.
@param string $media_id
The media ID of the story.
@param string $key
The base64-encoded key of the story.
@param string $iv
The base64-encoded IV of the story.
@return mixed
The story data or FALSE on failure. | [
"Downloads",
"a",
"story",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L984-L998 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.markStoryViewed | public function markStoryViewed($id, $screenshot_count = 0) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
// Mark story as viewed.
$timestamp = parent::timestamp();
$result = parent::post(
'/update_stories',
array(
'friend_stories' => json_encode(array(
array(
'id' => $id,
'screenshot_count' => $screenshot_count,
'timestamp' => $timestamp,
),
)),
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return is_null($result);
} | php | public function markStoryViewed($id, $screenshot_count = 0) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
// Mark story as viewed.
$timestamp = parent::timestamp();
$result = parent::post(
'/update_stories',
array(
'friend_stories' => json_encode(array(
array(
'id' => $id,
'screenshot_count' => $screenshot_count,
'timestamp' => $timestamp,
),
)),
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return is_null($result);
} | [
"public",
"function",
"markStoryViewed",
"(",
"$",
"id",
",",
"$",
"screenshot_count",
"=",
"0",
")",
"{",
"// Make sure we're logged in and have a valid access token.",
"if",
"(",
"!",
"$",
"this",
"->",
"auth_token",
"||",
"!",
"$",
"this",
"->",
"username",
"... | Marks a story as viewed.
@param string $id
The ID of the story.
@param int $screenshot_count
Amount of times screenshotted. Defaults to 0.
@return bool
TRUE if successful, FALSE otherwise. | [
"Marks",
"a",
"story",
"as",
"viewed",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L1040-L1068 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.getBests | public function getBests($friends) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/bests',
array(
'friend_usernames' => json_encode($friends),
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
if (empty($result)) {
return FALSE;
}
$friends = array();
foreach((array) $result as $friend => $bests) {
$friends[$friend] = (array) $bests;
}
return $friends;
} | php | public function getBests($friends) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/bests',
array(
'friend_usernames' => json_encode($friends),
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
if (empty($result)) {
return FALSE;
}
$friends = array();
foreach((array) $result as $friend => $bests) {
$friends[$friend] = (array) $bests;
}
return $friends;
} | [
"public",
"function",
"getBests",
"(",
"$",
"friends",
")",
"{",
"// Make sure we're logged in and have a valid access token.",
"if",
"(",
"!",
"$",
"this",
"->",
"auth_token",
"||",
"!",
"$",
"this",
"->",
"username",
")",
"{",
"return",
"FALSE",
";",
"}",
"$... | Gets the best friends and scores of the specified users.
@param array $friends
An array of usernames for which to retrieve best friend information.
@return mixed
An dictionary of friends by username or FALSE on failure. | [
"Gets",
"the",
"best",
"friends",
"and",
"scores",
"of",
"the",
"specified",
"users",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L1079-L1109 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.clearFeed | public function clearFeed() {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/clear',
array(
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return is_null($result);
} | php | public function clearFeed() {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/clear',
array(
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return is_null($result);
} | [
"public",
"function",
"clearFeed",
"(",
")",
"{",
"// Make sure we're logged in and have a valid access token.",
"if",
"(",
"!",
"$",
"this",
"->",
"auth_token",
"||",
"!",
"$",
"this",
"->",
"username",
")",
"{",
"return",
"FALSE",
";",
"}",
"$",
"timestamp",
... | Clears the current user's feed.
@return bool
TRUE if successful, FALSE otherwise. | [
"Clears",
"the",
"current",
"user",
"s",
"feed",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L1117-L1137 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.updatePrivacy | public function updatePrivacy($setting) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/settings',
array(
'action' => 'updatePrivacy',
'privacySetting' => $setting,
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return isset($result->param) && $result->param == $setting;
} | php | public function updatePrivacy($setting) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/settings',
array(
'action' => 'updatePrivacy',
'privacySetting' => $setting,
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return isset($result->param) && $result->param == $setting;
} | [
"public",
"function",
"updatePrivacy",
"(",
"$",
"setting",
")",
"{",
"// Make sure we're logged in and have a valid access token.",
"if",
"(",
"!",
"$",
"this",
"->",
"auth_token",
"||",
"!",
"$",
"this",
"->",
"username",
")",
"{",
"return",
"FALSE",
";",
"}",... | Updates the current user's privacy setting.
@param int $setting
The privacy setting, i.e. PRIVACY_EVERYONE or PRIVACY_FRIENDS.
@return bool
TRUE if successful, FALSE otherwise. | [
"Updates",
"the",
"current",
"user",
"s",
"privacy",
"setting",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L1148-L1170 | train |
JorgenPhi/php-snapchat | src/snapchat.php | Snapchat.updateEmail | public function updateEmail($email) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/settings',
array(
'action' => 'updateEmail',
'email' => $email,
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return isset($result->param) && $result->param == $email;
} | php | public function updateEmail($email) {
// Make sure we're logged in and have a valid access token.
if (!$this->auth_token || !$this->username) {
return FALSE;
}
$timestamp = parent::timestamp();
$result = parent::post(
'/settings',
array(
'action' => 'updateEmail',
'email' => $email,
'timestamp' => $timestamp,
'username' => $this->username,
),
array(
$this->auth_token,
$timestamp,
)
);
return isset($result->param) && $result->param == $email;
} | [
"public",
"function",
"updateEmail",
"(",
"$",
"email",
")",
"{",
"// Make sure we're logged in and have a valid access token.",
"if",
"(",
"!",
"$",
"this",
"->",
"auth_token",
"||",
"!",
"$",
"this",
"->",
"username",
")",
"{",
"return",
"FALSE",
";",
"}",
"... | Updates the current user's email address.
@param string $email
The new email address.
@return bool
TRUE if successful, FALSE otherwise. | [
"Updates",
"the",
"current",
"user",
"s",
"email",
"address",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat.php#L1181-L1203 | train |
JorgenPhi/php-snapchat | src/snapchat_cache.php | SnapchatCache.get | public function get($key) {
// First, check to see if the result has been cached.
if (!isset($this->_cache[$key])) {
return FALSE;
}
// Second, check its freshness.
if ($this->_cache[$key]['time'] < time() - self::$_lifespan) {
return FALSE;
}
return $this->_cache[$key]['data'];
} | php | public function get($key) {
// First, check to see if the result has been cached.
if (!isset($this->_cache[$key])) {
return FALSE;
}
// Second, check its freshness.
if ($this->_cache[$key]['time'] < time() - self::$_lifespan) {
return FALSE;
}
return $this->_cache[$key]['data'];
} | [
"public",
"function",
"get",
"(",
"$",
"key",
")",
"{",
"// First, check to see if the result has been cached.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_cache",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"FALSE",
";",
"}",
"// Second, check it... | Gets a result from the cache if it's fresh enough.
@param string $key
The key of the result to retrieve.
@return mixed
The result or FALSE on failure. | [
"Gets",
"a",
"result",
"from",
"the",
"cache",
"if",
"it",
"s",
"fresh",
"enough",
"."
] | 2dd71130e8f9ddd2b14e312b57063baa376cfe48 | https://github.com/JorgenPhi/php-snapchat/blob/2dd71130e8f9ddd2b14e312b57063baa376cfe48/src/snapchat_cache.php#L30-L42 | train |
pimax/fb-messenger-php | FbBotApp.php | FbBotApp.debug | public function debug($fb_id, $message)
{
$responses = [];
$maxlength = 2000;
$length = strlen(json_encode( $message, JSON_UNESCAPED_SLASHES ) );
$pages = ceil($length/$maxlength);
for ($x=0; $x<$pages; $x++) {
$responses[] = $this->send( new Message($fb_id,substr( json_encode( $message, JSON_UNESCAPED_SLASHES ), $x*$maxlength, $maxlength), false, "ISSUE_RESOLUTION", "REGULAR", "MESSAGE_TAG" ) );
}
return $responses;
} | php | public function debug($fb_id, $message)
{
$responses = [];
$maxlength = 2000;
$length = strlen(json_encode( $message, JSON_UNESCAPED_SLASHES ) );
$pages = ceil($length/$maxlength);
for ($x=0; $x<$pages; $x++) {
$responses[] = $this->send( new Message($fb_id,substr( json_encode( $message, JSON_UNESCAPED_SLASHES ), $x*$maxlength, $maxlength), false, "ISSUE_RESOLUTION", "REGULAR", "MESSAGE_TAG" ) );
}
return $responses;
} | [
"public",
"function",
"debug",
"(",
"$",
"fb_id",
",",
"$",
"message",
")",
"{",
"$",
"responses",
"=",
"[",
"]",
";",
"$",
"maxlength",
"=",
"2000",
";",
"$",
"length",
"=",
"strlen",
"(",
"json_encode",
"(",
"$",
"message",
",",
"JSON_UNESCAPED_SLASH... | Debugging Tool - Can accept an object, array, string, number
@param Message $message
@return array | [
"Debugging",
"Tool",
"-",
"Can",
"accept",
"an",
"object",
"array",
"string",
"number"
] | 1054610d3fc65a2ae93de64f0546286e55e68aa6 | https://github.com/pimax/fb-messenger-php/blob/1054610d3fc65a2ae93de64f0546286e55e68aa6/FbBotApp.php#L179-L198 | train |
pimax/fb-messenger-php | FbBotApp.php | FbBotApp.userProfile | public function userProfile($id, $fields = 'first_name,last_name,profile_pic,locale,timezone,gender')
{
return new UserProfile($this->call($id, [
'fields' => $fields
], self::TYPE_GET));
} | php | public function userProfile($id, $fields = 'first_name,last_name,profile_pic,locale,timezone,gender')
{
return new UserProfile($this->call($id, [
'fields' => $fields
], self::TYPE_GET));
} | [
"public",
"function",
"userProfile",
"(",
"$",
"id",
",",
"$",
"fields",
"=",
"'first_name,last_name,profile_pic,locale,timezone,gender'",
")",
"{",
"return",
"new",
"UserProfile",
"(",
"$",
"this",
"->",
"call",
"(",
"$",
"id",
",",
"[",
"'fields'",
"=>",
"$"... | Get User Profile Info
@param int $id
@param string $fields
@return UserProfile | [
"Get",
"User",
"Profile",
"Info"
] | 1054610d3fc65a2ae93de64f0546286e55e68aa6 | https://github.com/pimax/fb-messenger-php/blob/1054610d3fc65a2ae93de64f0546286e55e68aa6/FbBotApp.php#L223-L228 | train |
pimax/fb-messenger-php | FbBotApp.php | FbBotApp.setTargetAudience | public function setTargetAudience($audience_type, $list_type=null, $countries_array=null){
if ($audience_type === "custom") {
return $this->call('me/messenger_profile', [
'target_audience' => [
'audience_type' => $audience_type,
'countries' => [
$list_type => $countries_array
]
]
], self::TYPE_POST);
} else {
return $this->call('me/messenger_profile', [
'target_audience' => [
'audience_type' => $audience_type
]
], self::TYPE_POST);
}
} | php | public function setTargetAudience($audience_type, $list_type=null, $countries_array=null){
if ($audience_type === "custom") {
return $this->call('me/messenger_profile', [
'target_audience' => [
'audience_type' => $audience_type,
'countries' => [
$list_type => $countries_array
]
]
], self::TYPE_POST);
} else {
return $this->call('me/messenger_profile', [
'target_audience' => [
'audience_type' => $audience_type
]
], self::TYPE_POST);
}
} | [
"public",
"function",
"setTargetAudience",
"(",
"$",
"audience_type",
",",
"$",
"list_type",
"=",
"null",
",",
"$",
"countries_array",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"audience_type",
"===",
"\"custom\"",
")",
"{",
"return",
"$",
"this",
"->",
"call... | Set Target Audience
@see https://developers.facebook.com/docs/messenger-platform/messenger-profile/target-audience
@param string $audience_type ("all", "custom", "none")
@param string $list_type ("whitelist", "blacklist")
@param array $countries_array
@return array | [
"Set",
"Target",
"Audience"
] | 1054610d3fc65a2ae93de64f0546286e55e68aa6 | https://github.com/pimax/fb-messenger-php/blob/1054610d3fc65a2ae93de64f0546286e55e68aa6/FbBotApp.php#L306-L324 | train |
pimax/fb-messenger-php | FbBotApp.php | FbBotApp.setDomainWhitelist | public function setDomainWhitelist($domains){
if(!is_array($domains))
$domains = array($domains);
return $this->call('me/messenger_profile', [
'whitelisted_domains' => $domains
], self::TYPE_POST);
} | php | public function setDomainWhitelist($domains){
if(!is_array($domains))
$domains = array($domains);
return $this->call('me/messenger_profile', [
'whitelisted_domains' => $domains
], self::TYPE_POST);
} | [
"public",
"function",
"setDomainWhitelist",
"(",
"$",
"domains",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"domains",
")",
")",
"$",
"domains",
"=",
"array",
"(",
"$",
"domains",
")",
";",
"return",
"$",
"this",
"->",
"call",
"(",
"'me/messenger_... | Set Domain Whitelisting
@see https://developers.facebook.com/docs/messenger-platform/messenger-profile/domain-whitelisting
@param array|string $domains
@return array | [
"Set",
"Domain",
"Whitelisting"
] | 1054610d3fc65a2ae93de64f0546286e55e68aa6 | https://github.com/pimax/fb-messenger-php/blob/1054610d3fc65a2ae93de64f0546286e55e68aa6/FbBotApp.php#L358-L366 | train |
pimax/fb-messenger-php | FbBotApp.php | FbBotApp.setHomeUrl | public function setHomeUrl($url, $webview_height_ratio = 'tall', $webview_share_button = 'hide', $in_test = false){
return $this->call('me/messenger_profile', [
'home_url' => [
'url' => $url,
'webview_height_ratio' => $webview_height_ratio,
'webview_share_button' => $webview_share_button,
'in_test' => $in_test
]
], self::TYPE_POST);
} | php | public function setHomeUrl($url, $webview_height_ratio = 'tall', $webview_share_button = 'hide', $in_test = false){
return $this->call('me/messenger_profile', [
'home_url' => [
'url' => $url,
'webview_height_ratio' => $webview_height_ratio,
'webview_share_button' => $webview_share_button,
'in_test' => $in_test
]
], self::TYPE_POST);
} | [
"public",
"function",
"setHomeUrl",
"(",
"$",
"url",
",",
"$",
"webview_height_ratio",
"=",
"'tall'",
",",
"$",
"webview_share_button",
"=",
"'hide'",
",",
"$",
"in_test",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"call",
"(",
"'me/messenger_profi... | Set Chat Extension Home URL
@see https://developers.facebook.com/docs/messenger-platform/messenger-profile/home-url/
@param string $url
@param string $webview_height_ratio
@param string $webview_share_button
@param boolean $in_test
@return array | [
"Set",
"Chat",
"Extension",
"Home",
"URL"
] | 1054610d3fc65a2ae93de64f0546286e55e68aa6 | https://github.com/pimax/fb-messenger-php/blob/1054610d3fc65a2ae93de64f0546286e55e68aa6/FbBotApp.php#L403-L412 | train |
pimax/fb-messenger-php | FbBotApp.php | FbBotApp.setPersistentMenu | public function setPersistentMenu($localizedMenu)
{
$elements = [];
foreach ($localizedMenu as $menu) {
$elements[] = $menu->getData();
}
return $this->call('me/messenger_profile', [
'persistent_menu' => $elements
], self::TYPE_POST);
} | php | public function setPersistentMenu($localizedMenu)
{
$elements = [];
foreach ($localizedMenu as $menu) {
$elements[] = $menu->getData();
}
return $this->call('me/messenger_profile', [
'persistent_menu' => $elements
], self::TYPE_POST);
} | [
"public",
"function",
"setPersistentMenu",
"(",
"$",
"localizedMenu",
")",
"{",
"$",
"elements",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"localizedMenu",
"as",
"$",
"menu",
")",
"{",
"$",
"elements",
"[",
"]",
"=",
"$",
"menu",
"->",
"getData",
"(",
... | Set Nested Menu
@see https://developers.facebook.com/docs/messenger-platform/messenger-profile/persistent-menu
@params $localizedMenu
@return array | [
"Set",
"Nested",
"Menu"
] | 1054610d3fc65a2ae93de64f0546286e55e68aa6 | https://github.com/pimax/fb-messenger-php/blob/1054610d3fc65a2ae93de64f0546286e55e68aa6/FbBotApp.php#L446-L457 | train |
pimax/fb-messenger-php | FbBotApp.php | FbBotApp.setNLP | public function setNLP($nlp_enabled = true, $model = 'ENGLISH', $custom_token = null, $verbose = false, $n_best = 1){
return $this->call('me/nlp_configs', [
'nlp_enabled' => $nlp_enabled,
'model' => $model,
'custom_token' => $custom_token,
'verbose' => $verbose,
'n_best' => $n_best
], self::TYPE_POST);
} | php | public function setNLP($nlp_enabled = true, $model = 'ENGLISH', $custom_token = null, $verbose = false, $n_best = 1){
return $this->call('me/nlp_configs', [
'nlp_enabled' => $nlp_enabled,
'model' => $model,
'custom_token' => $custom_token,
'verbose' => $verbose,
'n_best' => $n_best
], self::TYPE_POST);
} | [
"public",
"function",
"setNLP",
"(",
"$",
"nlp_enabled",
"=",
"true",
",",
"$",
"model",
"=",
"'ENGLISH'",
",",
"$",
"custom_token",
"=",
"null",
",",
"$",
"verbose",
"=",
"false",
",",
"$",
"n_best",
"=",
"1",
")",
"{",
"return",
"$",
"this",
"->",
... | Set NLP Settings
@see https://developers.facebook.com/docs/messenger-platform/built-in-nlp
@return array | [
"Set",
"NLP",
"Settings"
] | 1054610d3fc65a2ae93de64f0546286e55e68aa6 | https://github.com/pimax/fb-messenger-php/blob/1054610d3fc65a2ae93de64f0546286e55e68aa6/FbBotApp.php#L492-L500 | train |
pimax/fb-messenger-php | Messages/AccountLink.php | AccountLink.getData | public function getData()
{
if($this->logout)
{
$buttons = new MessageButton( MessageButton::TYPE_ACCOUNT_UNLINK, '');
}
else
{
$buttons = new MessageButton( MessageButton::TYPE_ACCOUNT_LINK, '', $this->url);
}
$result = [
'title' => $this->title,
'subtitle' => $this->subtitle,
'image_url' => $this->image_url,
'buttons' => [$buttons->getData()]
];
return $result;
} | php | public function getData()
{
if($this->logout)
{
$buttons = new MessageButton( MessageButton::TYPE_ACCOUNT_UNLINK, '');
}
else
{
$buttons = new MessageButton( MessageButton::TYPE_ACCOUNT_LINK, '', $this->url);
}
$result = [
'title' => $this->title,
'subtitle' => $this->subtitle,
'image_url' => $this->image_url,
'buttons' => [$buttons->getData()]
];
return $result;
} | [
"public",
"function",
"getData",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"logout",
")",
"{",
"$",
"buttons",
"=",
"new",
"MessageButton",
"(",
"MessageButton",
"::",
"TYPE_ACCOUNT_UNLINK",
",",
"''",
")",
";",
"}",
"else",
"{",
"$",
"buttons",
"="... | Get AccountLink data
@return array | [
"Get",
"AccountLink",
"data"
] | 1054610d3fc65a2ae93de64f0546286e55e68aa6 | https://github.com/pimax/fb-messenger-php/blob/1054610d3fc65a2ae93de64f0546286e55e68aa6/Messages/AccountLink.php#L67-L85 | train |
php-ds/polyfill | src/Traits/Capacity.php | Capacity.decreaseCapacity | protected function decreaseCapacity()
{
$this->capacity = max(self::MIN_CAPACITY, $this->capacity * $this->getDecayFactor());
} | php | protected function decreaseCapacity()
{
$this->capacity = max(self::MIN_CAPACITY, $this->capacity * $this->getDecayFactor());
} | [
"protected",
"function",
"decreaseCapacity",
"(",
")",
"{",
"$",
"this",
"->",
"capacity",
"=",
"max",
"(",
"self",
"::",
"MIN_CAPACITY",
",",
"$",
"this",
"->",
"capacity",
"*",
"$",
"this",
"->",
"getDecayFactor",
"(",
")",
")",
";",
"}"
] | Called when capacity should be decrease if it drops below a threshold. | [
"Called",
"when",
"capacity",
"should",
"be",
"decrease",
"if",
"it",
"drops",
"below",
"a",
"threshold",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Traits/Capacity.php#L89-L92 | train |
php-ds/polyfill | src/Map.php | Map.apply | public function apply(callable $callback)
{
foreach ($this->pairs as &$pair) {
$pair->value = $callback($pair->key, $pair->value);
}
} | php | public function apply(callable $callback)
{
foreach ($this->pairs as &$pair) {
$pair->value = $callback($pair->key, $pair->value);
}
} | [
"public",
"function",
"apply",
"(",
"callable",
"$",
"callback",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"pairs",
"as",
"&",
"$",
"pair",
")",
"{",
"$",
"pair",
"->",
"value",
"=",
"$",
"callback",
"(",
"$",
"pair",
"->",
"key",
",",
"$",
"p... | Updates all values by applying a callback function to each value.
@param callable $callback Accepts two arguments: key and value, should
return what the updated value will be. | [
"Updates",
"all",
"values",
"by",
"applying",
"a",
"callback",
"function",
"to",
"each",
"value",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L45-L50 | train |
php-ds/polyfill | src/Map.php | Map.last | public function last(): Pair
{
if ($this->isEmpty()) {
throw new UnderflowException();
}
return $this->pairs[count($this->pairs) - 1];
} | php | public function last(): Pair
{
if ($this->isEmpty()) {
throw new UnderflowException();
}
return $this->pairs[count($this->pairs) - 1];
} | [
"public",
"function",
"last",
"(",
")",
":",
"Pair",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"UnderflowException",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"pairs",
"[",
"count",
"(",
"$",
"this",
... | Return the last Pair from the Map
@return Pair
@throws UnderflowException | [
"Return",
"the",
"last",
"Pair",
"from",
"the",
"Map"
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L84-L91 | train |
php-ds/polyfill | src/Map.php | Map.skip | public function skip(int $position): Pair
{
if ($position < 0 || $position >= count($this->pairs)) {
throw new OutOfRangeException();
}
return $this->pairs[$position]->copy();
} | php | public function skip(int $position): Pair
{
if ($position < 0 || $position >= count($this->pairs)) {
throw new OutOfRangeException();
}
return $this->pairs[$position]->copy();
} | [
"public",
"function",
"skip",
"(",
"int",
"$",
"position",
")",
":",
"Pair",
"{",
"if",
"(",
"$",
"position",
"<",
"0",
"||",
"$",
"position",
">=",
"count",
"(",
"$",
"this",
"->",
"pairs",
")",
")",
"{",
"throw",
"new",
"OutOfRangeException",
"(",
... | Return the pair at a specified position in the Map
@param int $position
@return Pair
@throws OutOfRangeException | [
"Return",
"the",
"pair",
"at",
"a",
"specified",
"position",
"in",
"the",
"Map"
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L102-L109 | train |
php-ds/polyfill | src/Map.php | Map.merge | public function merge($values): Map
{
$merged = new self($this);
$merged->putAll($values);
return $merged;
} | php | public function merge($values): Map
{
$merged = new self($this);
$merged->putAll($values);
return $merged;
} | [
"public",
"function",
"merge",
"(",
"$",
"values",
")",
":",
"Map",
"{",
"$",
"merged",
"=",
"new",
"self",
"(",
"$",
"this",
")",
";",
"$",
"merged",
"->",
"putAll",
"(",
"$",
"values",
")",
";",
"return",
"$",
"merged",
";",
"}"
] | Returns the result of associating all keys of a given traversable object
or array with their corresponding values, as well as those of this map.
@param array|\Traversable $values
@return Map | [
"Returns",
"the",
"result",
"of",
"associating",
"all",
"keys",
"of",
"a",
"given",
"traversable",
"object",
"or",
"array",
"with",
"their",
"corresponding",
"values",
"as",
"well",
"as",
"those",
"of",
"this",
"map",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L119-L124 | train |
php-ds/polyfill | src/Map.php | Map.keysAreEqual | private function keysAreEqual($a, $b): bool
{
if (is_object($a) && $a instanceof Hashable) {
return get_class($a) === get_class($b) && $a->equals($b);
}
return $a === $b;
} | php | private function keysAreEqual($a, $b): bool
{
if (is_object($a) && $a instanceof Hashable) {
return get_class($a) === get_class($b) && $a->equals($b);
}
return $a === $b;
} | [
"private",
"function",
"keysAreEqual",
"(",
"$",
"a",
",",
"$",
"b",
")",
":",
"bool",
"{",
"if",
"(",
"is_object",
"(",
"$",
"a",
")",
"&&",
"$",
"a",
"instanceof",
"Hashable",
")",
"{",
"return",
"get_class",
"(",
"$",
"a",
")",
"===",
"get_class... | Determines whether two keys are equal.
@param mixed $a
@param mixed $b
@return bool | [
"Determines",
"whether",
"two",
"keys",
"are",
"equal",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L169-L176 | train |
php-ds/polyfill | src/Map.php | Map.get | public function get($key, $default = null)
{
if (($pair = $this->lookupKey($key))) {
return $pair->value;
}
// Check if a default was provided.
if (func_num_args() === 1) {
throw new OutOfBoundsException();
}
return $default;
} | php | public function get($key, $default = null)
{
if (($pair = $this->lookupKey($key))) {
return $pair->value;
}
// Check if a default was provided.
if (func_num_args() === 1) {
throw new OutOfBoundsException();
}
return $default;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"(",
"$",
"pair",
"=",
"$",
"this",
"->",
"lookupKey",
"(",
"$",
"key",
")",
")",
")",
"{",
"return",
"$",
"pair",
"->",
"value",
";",
"}",
"... | Returns the value associated with a key, or an optional default if the
key is not associated with a value.
@param mixed $key
@param mixed $default
@return mixed The associated value or fallback default if provided.
@throws OutOfBoundsException if no default was provided and the key is
not associated with a value. | [
"Returns",
"the",
"value",
"associated",
"with",
"a",
"key",
"or",
"an",
"optional",
"default",
"if",
"the",
"key",
"is",
"not",
"associated",
"with",
"a",
"value",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L277-L289 | train |
php-ds/polyfill | src/Map.php | Map.keys | public function keys(): Set
{
$key = function($pair) {
return $pair->key;
};
return new Set(array_map($key, $this->pairs));
} | php | public function keys(): Set
{
$key = function($pair) {
return $pair->key;
};
return new Set(array_map($key, $this->pairs));
} | [
"public",
"function",
"keys",
"(",
")",
":",
"Set",
"{",
"$",
"key",
"=",
"function",
"(",
"$",
"pair",
")",
"{",
"return",
"$",
"pair",
"->",
"key",
";",
"}",
";",
"return",
"new",
"Set",
"(",
"array_map",
"(",
"$",
"key",
",",
"$",
"this",
"-... | Returns a set of all the keys in the map.
@return Set | [
"Returns",
"a",
"set",
"of",
"all",
"the",
"keys",
"in",
"the",
"map",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L296-L303 | train |
php-ds/polyfill | src/Map.php | Map.map | public function map(callable $callback): Map
{
$apply = function($pair) use ($callback) {
return $callback($pair->key, $pair->value);
};
return new self(array_map($apply, $this->pairs));
} | php | public function map(callable $callback): Map
{
$apply = function($pair) use ($callback) {
return $callback($pair->key, $pair->value);
};
return new self(array_map($apply, $this->pairs));
} | [
"public",
"function",
"map",
"(",
"callable",
"$",
"callback",
")",
":",
"Map",
"{",
"$",
"apply",
"=",
"function",
"(",
"$",
"pair",
")",
"use",
"(",
"$",
"callback",
")",
"{",
"return",
"$",
"callback",
"(",
"$",
"pair",
"->",
"key",
",",
"$",
... | Returns a new map using the results of applying a callback to each value.
The keys will be equal in both maps.
@param callable $callback Accepts two arguments: key and value, should
return what the updated value will be.
@return Map | [
"Returns",
"a",
"new",
"map",
"using",
"the",
"results",
"of",
"applying",
"a",
"callback",
"to",
"each",
"value",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L315-L322 | train |
php-ds/polyfill | src/Map.php | Map.pairs | public function pairs(): Sequence
{
$copy = function($pair) {
return $pair->copy();
};
return new Vector(array_map($copy, $this->pairs));
} | php | public function pairs(): Sequence
{
$copy = function($pair) {
return $pair->copy();
};
return new Vector(array_map($copy, $this->pairs));
} | [
"public",
"function",
"pairs",
"(",
")",
":",
"Sequence",
"{",
"$",
"copy",
"=",
"function",
"(",
"$",
"pair",
")",
"{",
"return",
"$",
"pair",
"->",
"copy",
"(",
")",
";",
"}",
";",
"return",
"new",
"Vector",
"(",
"array_map",
"(",
"$",
"copy",
... | Returns a sequence of pairs representing all associations.
@return Sequence | [
"Returns",
"a",
"sequence",
"of",
"pairs",
"representing",
"all",
"associations",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L329-L336 | train |
php-ds/polyfill | src/Map.php | Map.reduce | public function reduce(callable $callback, $initial = null)
{
$carry = $initial;
foreach ($this->pairs as $pair) {
$carry = $callback($carry, $pair->key, $pair->value);
}
return $carry;
} | php | public function reduce(callable $callback, $initial = null)
{
$carry = $initial;
foreach ($this->pairs as $pair) {
$carry = $callback($carry, $pair->key, $pair->value);
}
return $carry;
} | [
"public",
"function",
"reduce",
"(",
"callable",
"$",
"callback",
",",
"$",
"initial",
"=",
"null",
")",
"{",
"$",
"carry",
"=",
"$",
"initial",
";",
"foreach",
"(",
"$",
"this",
"->",
"pairs",
"as",
"$",
"pair",
")",
"{",
"$",
"carry",
"=",
"$",
... | Iteratively reduces the map to a single value using a callback.
@param callable $callback Accepts the carry, key, and value, and
returns an updated carry value.
@param mixed|null $initial Optional initial carry value.
@return mixed The carry value of the final iteration, or the initial
value if the map was empty. | [
"Iteratively",
"reduces",
"the",
"map",
"to",
"a",
"single",
"value",
"using",
"a",
"callback",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L382-L391 | train |
php-ds/polyfill | src/Map.php | Map.delete | private function delete(int $position)
{
$pair = $this->pairs[$position];
$value = $pair->value;
array_splice($this->pairs, $position, 1, null);
$this->checkCapacity();
return $value;
} | php | private function delete(int $position)
{
$pair = $this->pairs[$position];
$value = $pair->value;
array_splice($this->pairs, $position, 1, null);
$this->checkCapacity();
return $value;
} | [
"private",
"function",
"delete",
"(",
"int",
"$",
"position",
")",
"{",
"$",
"pair",
"=",
"$",
"this",
"->",
"pairs",
"[",
"$",
"position",
"]",
";",
"$",
"value",
"=",
"$",
"pair",
"->",
"value",
";",
"array_splice",
"(",
"$",
"this",
"->",
"pairs... | Completely removes a pair from the internal array by position. It is
important to remove it from the array and not just use 'unset'. | [
"Completely",
"removes",
"a",
"pair",
"from",
"the",
"internal",
"array",
"by",
"position",
".",
"It",
"is",
"important",
"to",
"remove",
"it",
"from",
"the",
"array",
"and",
"not",
"just",
"use",
"unset",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L397-L406 | train |
php-ds/polyfill | src/Map.php | Map.remove | public function remove($key, $default = null)
{
foreach ($this->pairs as $position => $pair) {
if ($this->keysAreEqual($pair->key, $key)) {
return $this->delete($position);
}
}
// Check if a default was provided
if (func_num_args() === 1) {
throw new \OutOfBoundsException();
}
return $default;
} | php | public function remove($key, $default = null)
{
foreach ($this->pairs as $position => $pair) {
if ($this->keysAreEqual($pair->key, $key)) {
return $this->delete($position);
}
}
// Check if a default was provided
if (func_num_args() === 1) {
throw new \OutOfBoundsException();
}
return $default;
} | [
"public",
"function",
"remove",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"pairs",
"as",
"$",
"position",
"=>",
"$",
"pair",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"keysAreEqual",
"(",
"$",
"... | Removes a key's association from the map and returns the associated value
or a provided default if provided.
@param mixed $key
@param mixed $default
@return mixed The associated value or fallback default if provided.
@throws \OutOfBoundsException if no default was provided and the key is
not associated with a value. | [
"Removes",
"a",
"key",
"s",
"association",
"from",
"the",
"map",
"and",
"returns",
"the",
"associated",
"value",
"or",
"a",
"provided",
"default",
"if",
"provided",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L420-L434 | train |
php-ds/polyfill | src/Map.php | Map.reversed | public function reversed(): Map
{
$reversed = new self();
$reversed->pairs = array_reverse($this->pairs);
return $reversed;
} | php | public function reversed(): Map
{
$reversed = new self();
$reversed->pairs = array_reverse($this->pairs);
return $reversed;
} | [
"public",
"function",
"reversed",
"(",
")",
":",
"Map",
"{",
"$",
"reversed",
"=",
"new",
"self",
"(",
")",
";",
"$",
"reversed",
"->",
"pairs",
"=",
"array_reverse",
"(",
"$",
"this",
"->",
"pairs",
")",
";",
"return",
"$",
"reversed",
";",
"}"
] | Returns a reversed copy of the map.
@return Map | [
"Returns",
"a",
"reversed",
"copy",
"of",
"the",
"map",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L451-L457 | train |
php-ds/polyfill | src/Map.php | Map.values | public function values(): Sequence
{
$value = function($pair) {
return $pair->value;
};
return new Vector(array_map($value, $this->pairs));
} | php | public function values(): Sequence
{
$value = function($pair) {
return $pair->value;
};
return new Vector(array_map($value, $this->pairs));
} | [
"public",
"function",
"values",
"(",
")",
":",
"Sequence",
"{",
"$",
"value",
"=",
"function",
"(",
"$",
"pair",
")",
"{",
"return",
"$",
"pair",
"->",
"value",
";",
"}",
";",
"return",
"new",
"Vector",
"(",
"array_map",
"(",
"$",
"value",
",",
"$"... | Returns a sequence of all the associated values in the Map.
@return Sequence | [
"Returns",
"a",
"sequence",
"of",
"all",
"the",
"associated",
"values",
"in",
"the",
"Map",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L600-L607 | train |
php-ds/polyfill | src/Map.php | Map.xor | public function xor(Map $map): Map
{
return $this->merge($map)->filter(function($key) use ($map) {
return $this->hasKey($key) ^ $map->hasKey($key);
});
} | php | public function xor(Map $map): Map
{
return $this->merge($map)->filter(function($key) use ($map) {
return $this->hasKey($key) ^ $map->hasKey($key);
});
} | [
"public",
"function",
"xor",
"(",
"Map",
"$",
"map",
")",
":",
"Map",
"{",
"return",
"$",
"this",
"->",
"merge",
"(",
"$",
"map",
")",
"->",
"filter",
"(",
"function",
"(",
"$",
"key",
")",
"use",
"(",
"$",
"map",
")",
"{",
"return",
"$",
"this... | Creates a new map using keys of either the current instance or of another
map, but not of both.
@param Map $map
@return Map A new map containing keys in the current instance as well
as another map, but not in both. | [
"Creates",
"a",
"new",
"map",
"using",
"keys",
"of",
"either",
"the",
"current",
"instance",
"or",
"of",
"another",
"map",
"but",
"not",
"of",
"both",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Map.php#L632-L637 | train |
php-ds/polyfill | src/PriorityQueue.php | PriorityQueue.compare | private function compare(int $a, int $b)
{
$x = $this->heap[$a];
$y = $this->heap[$b];
// Compare priority, using insertion stamp as fallback.
return ($x->priority <=> $y->priority) ?: ($y->stamp <=> $x->stamp);
} | php | private function compare(int $a, int $b)
{
$x = $this->heap[$a];
$y = $this->heap[$b];
// Compare priority, using insertion stamp as fallback.
return ($x->priority <=> $y->priority) ?: ($y->stamp <=> $x->stamp);
} | [
"private",
"function",
"compare",
"(",
"int",
"$",
"a",
",",
"int",
"$",
"b",
")",
"{",
"$",
"x",
"=",
"$",
"this",
"->",
"heap",
"[",
"$",
"a",
"]",
";",
"$",
"y",
"=",
"$",
"this",
"->",
"heap",
"[",
"$",
"b",
"]",
";",
"// Compare priority... | Compares two indices of the heap.
@param int $a
@param int $b
@return int | [
"Compares",
"two",
"indices",
"of",
"the",
"heap",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/PriorityQueue.php#L131-L138 | train |
php-ds/polyfill | src/PriorityQueue.php | PriorityQueue.swap | private function swap(int $a, int $b)
{
$temp = $this->heap[$a];
$this->heap[$a] = $this->heap[$b];
$this->heap[$b] = $temp;
} | php | private function swap(int $a, int $b)
{
$temp = $this->heap[$a];
$this->heap[$a] = $this->heap[$b];
$this->heap[$b] = $temp;
} | [
"private",
"function",
"swap",
"(",
"int",
"$",
"a",
",",
"int",
"$",
"b",
")",
"{",
"$",
"temp",
"=",
"$",
"this",
"->",
"heap",
"[",
"$",
"a",
"]",
";",
"$",
"this",
"->",
"heap",
"[",
"$",
"a",
"]",
"=",
"$",
"this",
"->",
"heap",
"[",
... | Swaps the nodes at two indices of the heap.
@param int $a
@param int $b | [
"Swaps",
"the",
"nodes",
"at",
"two",
"indices",
"of",
"the",
"heap",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/PriorityQueue.php#L146-L151 | train |
php-ds/polyfill | src/PriorityQueue.php | PriorityQueue.getLargestLeaf | private function getLargestLeaf(int $parent)
{
$left = $this->left($parent);
$right = $this->right($parent);
if ($right < count($this->heap) && $this->compare($left, $right) < 0) {
return $right;
}
return $left;
} | php | private function getLargestLeaf(int $parent)
{
$left = $this->left($parent);
$right = $this->right($parent);
if ($right < count($this->heap) && $this->compare($left, $right) < 0) {
return $right;
}
return $left;
} | [
"private",
"function",
"getLargestLeaf",
"(",
"int",
"$",
"parent",
")",
"{",
"$",
"left",
"=",
"$",
"this",
"->",
"left",
"(",
"$",
"parent",
")",
";",
"$",
"right",
"=",
"$",
"this",
"->",
"right",
"(",
"$",
"parent",
")",
";",
"if",
"(",
"$",
... | Returns the index of a node's largest leaf node.
@param int $parent the parent node.
@return int the index of the node's largest leaf node. | [
"Returns",
"the",
"index",
"of",
"a",
"node",
"s",
"largest",
"leaf",
"node",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/PriorityQueue.php#L160-L170 | train |
php-ds/polyfill | src/PriorityQueue.php | PriorityQueue.siftDown | private function siftDown(int $node)
{
$last = floor(count($this->heap) / 2);
for ($parent = $node; $parent < $last; $parent = $leaf) {
// Determine the largest leaf to potentially swap with the parent.
$leaf = $this->getLargestLeaf($parent);
// Done if the parent is not greater than its largest leaf
if ($this->compare($parent, $leaf) > 0) {
break;
}
$this->swap($parent, $leaf);
}
} | php | private function siftDown(int $node)
{
$last = floor(count($this->heap) / 2);
for ($parent = $node; $parent < $last; $parent = $leaf) {
// Determine the largest leaf to potentially swap with the parent.
$leaf = $this->getLargestLeaf($parent);
// Done if the parent is not greater than its largest leaf
if ($this->compare($parent, $leaf) > 0) {
break;
}
$this->swap($parent, $leaf);
}
} | [
"private",
"function",
"siftDown",
"(",
"int",
"$",
"node",
")",
"{",
"$",
"last",
"=",
"floor",
"(",
"count",
"(",
"$",
"this",
"->",
"heap",
")",
"/",
"2",
")",
";",
"for",
"(",
"$",
"parent",
"=",
"$",
"node",
";",
"$",
"parent",
"<",
"$",
... | Starts the process of sifting down a given node index to ensure that
the heap's properties are preserved.
@param int $node | [
"Starts",
"the",
"process",
"of",
"sifting",
"down",
"a",
"given",
"node",
"index",
"to",
"ensure",
"that",
"the",
"heap",
"s",
"properties",
"are",
"preserved",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/PriorityQueue.php#L178-L194 | train |
php-ds/polyfill | src/PriorityQueue.php | PriorityQueue.pop | public function pop()
{
if ($this->isEmpty()) {
throw new UnderflowException();
}
// Last leaf of the heap to become the new root.
$leaf = array_pop($this->heap);
if (empty($this->heap)) {
return $leaf->value;
}
// Cache the current root value to return before replacing with next.
$value = $this->getRoot()->value;
// Replace the root, then sift down.
$this->setRoot($leaf);
$this->checkCapacity();
return $value;
} | php | public function pop()
{
if ($this->isEmpty()) {
throw new UnderflowException();
}
// Last leaf of the heap to become the new root.
$leaf = array_pop($this->heap);
if (empty($this->heap)) {
return $leaf->value;
}
// Cache the current root value to return before replacing with next.
$value = $this->getRoot()->value;
// Replace the root, then sift down.
$this->setRoot($leaf);
$this->checkCapacity();
return $value;
} | [
"public",
"function",
"pop",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
"{",
"throw",
"new",
"UnderflowException",
"(",
")",
";",
"}",
"// Last leaf of the heap to become the new root.",
"$",
"leaf",
"=",
"array_pop",
"(",
"$",
... | Returns and removes the value with the highest priority in the queue.
@return mixed | [
"Returns",
"and",
"removes",
"the",
"value",
"with",
"the",
"highest",
"priority",
"in",
"the",
"queue",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/PriorityQueue.php#L222-L243 | train |
php-ds/polyfill | src/PriorityQueue.php | PriorityQueue.siftUp | private function siftUp(int $leaf)
{
for (; $leaf > 0; $leaf = $parent) {
$parent = $this->parent($leaf);
// Done when parent priority is greater.
if ($this->compare($leaf, $parent) < 0) {
break;
}
$this->swap($parent, $leaf);
}
} | php | private function siftUp(int $leaf)
{
for (; $leaf > 0; $leaf = $parent) {
$parent = $this->parent($leaf);
// Done when parent priority is greater.
if ($this->compare($leaf, $parent) < 0) {
break;
}
$this->swap($parent, $leaf);
}
} | [
"private",
"function",
"siftUp",
"(",
"int",
"$",
"leaf",
")",
"{",
"for",
"(",
";",
"$",
"leaf",
">",
"0",
";",
"$",
"leaf",
"=",
"$",
"parent",
")",
"{",
"$",
"parent",
"=",
"$",
"this",
"->",
"parent",
"(",
"$",
"leaf",
")",
";",
"// Done wh... | Sifts a node up the heap until it's in the right position.
@param int $leaf | [
"Sifts",
"a",
"node",
"up",
"the",
"heap",
"until",
"it",
"s",
"in",
"the",
"right",
"position",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/PriorityQueue.php#L250-L262 | train |
php-ds/polyfill | src/Set.php | Set.contains | public function contains(...$values): bool
{
foreach ($values as $value) {
if ( ! $this->table->hasKey($value)) {
return false;
}
}
return true;
} | php | public function contains(...$values): bool
{
foreach ($values as $value) {
if ( ! $this->table->hasKey($value)) {
return false;
}
}
return true;
} | [
"public",
"function",
"contains",
"(",
"...",
"$",
"values",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"table",
"->",
"hasKey",
"(",
"$",
"value",
")",
")",
"{",
"return... | Determines whether the set contains all of zero or more values.
@param mixed ...$values
@return bool true if at least one value was provided and the set
contains all given values, false otherwise. | [
"Determines",
"whether",
"the",
"set",
"contains",
"all",
"of",
"zero",
"or",
"more",
"values",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Set.php#L90-L99 | train |
php-ds/polyfill | src/Set.php | Set.diff | public function diff(Set $set): Set
{
return $this->table->diff($set->table)->keys();
} | php | public function diff(Set $set): Set
{
return $this->table->diff($set->table)->keys();
} | [
"public",
"function",
"diff",
"(",
"Set",
"$",
"set",
")",
":",
"Set",
"{",
"return",
"$",
"this",
"->",
"table",
"->",
"diff",
"(",
"$",
"set",
"->",
"table",
")",
"->",
"keys",
"(",
")",
";",
"}"
] | Creates a new set using values from this set that aren't in another set.
Formally: A \ B = {x ∈ A | x ∉ B}
@param Set $set
@return Set | [
"Creates",
"a",
"new",
"set",
"using",
"values",
"from",
"this",
"set",
"that",
"aren",
"t",
"in",
"another",
"set",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Set.php#L128-L131 | train |
php-ds/polyfill | src/Set.php | Set.intersect | public function intersect(Set $set): Set
{
return $this->table->intersect($set->table)->keys();
} | php | public function intersect(Set $set): Set
{
return $this->table->intersect($set->table)->keys();
} | [
"public",
"function",
"intersect",
"(",
"Set",
"$",
"set",
")",
":",
"Set",
"{",
"return",
"$",
"this",
"->",
"table",
"->",
"intersect",
"(",
"$",
"set",
"->",
"table",
")",
"->",
"keys",
"(",
")",
";",
"}"
] | Creates a new set using values common to both this set and another set.
In other words, returns a copy of this set with all values removed that
aren't in the other set.
Formally: A ∩ B = {x : x ∈ A ∧ x ∈ B}
@param Set $set
@return Set | [
"Creates",
"a",
"new",
"set",
"using",
"values",
"common",
"to",
"both",
"this",
"set",
"and",
"another",
"set",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Set.php#L199-L202 | train |
php-ds/polyfill | src/Set.php | Set.reduce | public function reduce(callable $callback, $initial = null)
{
$carry = $initial;
foreach ($this as $value) {
$carry = $callback($carry, $value);
}
return $carry;
} | php | public function reduce(callable $callback, $initial = null)
{
$carry = $initial;
foreach ($this as $value) {
$carry = $callback($carry, $value);
}
return $carry;
} | [
"public",
"function",
"reduce",
"(",
"callable",
"$",
"callback",
",",
"$",
"initial",
"=",
"null",
")",
"{",
"$",
"carry",
"=",
"$",
"initial",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"value",
")",
"{",
"$",
"carry",
"=",
"$",
"callback",
"("... | Iteratively reduces the set to a single value using a callback.
@param callable $callback Accepts the carry and current value, and
returns an updated carry value.
@param mixed|null $initial Optional initial carry value.
@return mixed The carry value of the final iteration, or the initial
value if the set was empty. | [
"Iteratively",
"reduces",
"the",
"set",
"to",
"a",
"single",
"value",
"using",
"a",
"callback",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Set.php#L246-L255 | train |
php-ds/polyfill | src/Set.php | Set.remove | public function remove(...$values)
{
foreach ($values as $value) {
$this->table->remove($value, null);
}
} | php | public function remove(...$values)
{
foreach ($values as $value) {
$this->table->remove($value, null);
}
} | [
"public",
"function",
"remove",
"(",
"...",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"table",
"->",
"remove",
"(",
"$",
"value",
",",
"null",
")",
";",
"}",
"}"
] | Removes zero or more values from the set.
@param mixed ...$values | [
"Removes",
"zero",
"or",
"more",
"values",
"from",
"the",
"set",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Set.php#L262-L267 | train |
php-ds/polyfill | src/Set.php | Set.slice | public function slice(int $offset, int $length = null): Set
{
$sliced = new self();
$sliced->table = $this->table->slice($offset, $length);
return $sliced;
} | php | public function slice(int $offset, int $length = null): Set
{
$sliced = new self();
$sliced->table = $this->table->slice($offset, $length);
return $sliced;
} | [
"public",
"function",
"slice",
"(",
"int",
"$",
"offset",
",",
"int",
"$",
"length",
"=",
"null",
")",
":",
"Set",
"{",
"$",
"sliced",
"=",
"new",
"self",
"(",
")",
";",
"$",
"sliced",
"->",
"table",
"=",
"$",
"this",
"->",
"table",
"->",
"slice"... | Returns a subset of a given length starting at a specified offset.
@param int $offset If the offset is non-negative, the set will start
at that offset in the set. If offset is negative,
the set will start that far from the end.
@param int $length If a length is given and is positive, the resulting
set will have up to that many values in it.
If the requested length results in an overflow, only
values up to the end of the set will be included.
If a length is given and is negative, the set
will stop that many values from the end.
If a length is not provided, the resulting set
will contains all values between the offset and the
end of the set.
@return Set | [
"Returns",
"a",
"subset",
"of",
"a",
"given",
"length",
"starting",
"at",
"a",
"specified",
"offset",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Set.php#L311-L317 | train |
php-ds/polyfill | src/Set.php | Set.union | public function union(Set $set): Set
{
$union = new self();
foreach ($this as $value) {
$union->add($value);
}
foreach ($set as $value) {
$union->add($value);
}
return $union;
} | php | public function union(Set $set): Set
{
$union = new self();
foreach ($this as $value) {
$union->add($value);
}
foreach ($set as $value) {
$union->add($value);
}
return $union;
} | [
"public",
"function",
"union",
"(",
"Set",
"$",
"set",
")",
":",
"Set",
"{",
"$",
"union",
"=",
"new",
"self",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"value",
")",
"{",
"$",
"union",
"->",
"add",
"(",
"$",
"value",
")",
";",
"... | Creates a new set that contains the values of this set as well as the
values of another set.
Formally: A ∪ B = {x: x ∈ A ∨ x ∈ B}
@param Set $set
@return Set | [
"Creates",
"a",
"new",
"set",
"that",
"contains",
"the",
"values",
"of",
"this",
"set",
"as",
"well",
"as",
"the",
"values",
"of",
"another",
"set",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Set.php#L393-L406 | train |
php-ds/polyfill | src/Traits/SquaredCapacity.php | SquaredCapacity.allocate | public function allocate(int $capacity)
{
$this->capacity = max($this->square($capacity), $this->capacity);
} | php | public function allocate(int $capacity)
{
$this->capacity = max($this->square($capacity), $this->capacity);
} | [
"public",
"function",
"allocate",
"(",
"int",
"$",
"capacity",
")",
"{",
"$",
"this",
"->",
"capacity",
"=",
"max",
"(",
"$",
"this",
"->",
"square",
"(",
"$",
"capacity",
")",
",",
"$",
"this",
"->",
"capacity",
")",
";",
"}"
] | Ensures that enough memory is allocated for a specified capacity. This
potentially reduces the number of reallocations as the size increases.
@param int $capacity The number of values for which capacity should be
allocated. Capacity will stay the same if this value
is less than or equal to the current capacity. | [
"Ensures",
"that",
"enough",
"memory",
"is",
"allocated",
"for",
"a",
"specified",
"capacity",
".",
"This",
"potentially",
"reduces",
"the",
"number",
"of",
"reallocations",
"as",
"the",
"size",
"increases",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Traits/SquaredCapacity.php#L31-L34 | train |
php-ds/polyfill | src/Traits/SquaredCapacity.php | SquaredCapacity.increaseCapacity | protected function increaseCapacity()
{
$this->capacity = $this->square(max(count($this) + 1, $this->capacity * $this->getGrowthFactor()));
} | php | protected function increaseCapacity()
{
$this->capacity = $this->square(max(count($this) + 1, $this->capacity * $this->getGrowthFactor()));
} | [
"protected",
"function",
"increaseCapacity",
"(",
")",
"{",
"$",
"this",
"->",
"capacity",
"=",
"$",
"this",
"->",
"square",
"(",
"max",
"(",
"count",
"(",
"$",
"this",
")",
"+",
"1",
",",
"$",
"this",
"->",
"capacity",
"*",
"$",
"this",
"->",
"get... | Called when capacity should be increased to accommodate new values. | [
"Called",
"when",
"capacity",
"should",
"be",
"increased",
"to",
"accommodate",
"new",
"values",
"."
] | 72301e845b6daf07a20a90e870d4c4c4b0e8cc2e | https://github.com/php-ds/polyfill/blob/72301e845b6daf07a20a90e870d4c4c4b0e8cc2e/src/Traits/SquaredCapacity.php#L39-L42 | train |
swaggest/json-diff | src/JsonValueReplace.php | JsonValueReplace.process | public function process($data)
{
$check = true;
if ($this->pathFilterRegex && !preg_match($this->pathFilterRegex, $this->path)) {
$check = false;
}
if (!is_array($data) && !is_object($data)) {
if ($check && $data === $this->search) {
$this->affectedPaths[] = $this->path;
return $this->replace;
} else {
return $data;
}
}
$originalKeys = $data instanceof \stdClass ? get_object_vars($data) : $data;
if ($check) {
$diff = new JsonDiff($data, $this->search, JsonDiff::STOP_ON_DIFF);
if ($diff->getDiffCnt() === 0) {
$this->affectedPaths[] = $this->path;
return $this->replace;
}
}
$result = array();
foreach ($originalKeys as $key => $originalValue) {
$path = $this->path;
$pathItems = $this->pathItems;
$actualKey = $key;
$this->path .= '/' . JsonPointer::escapeSegment($actualKey);
$this->pathItems[] = $actualKey;
$result[$key] = $this->process($originalValue);
$this->path = $path;
$this->pathItems = $pathItems;
}
return $data instanceof \stdClass ? (object)$result : $result;
} | php | public function process($data)
{
$check = true;
if ($this->pathFilterRegex && !preg_match($this->pathFilterRegex, $this->path)) {
$check = false;
}
if (!is_array($data) && !is_object($data)) {
if ($check && $data === $this->search) {
$this->affectedPaths[] = $this->path;
return $this->replace;
} else {
return $data;
}
}
$originalKeys = $data instanceof \stdClass ? get_object_vars($data) : $data;
if ($check) {
$diff = new JsonDiff($data, $this->search, JsonDiff::STOP_ON_DIFF);
if ($diff->getDiffCnt() === 0) {
$this->affectedPaths[] = $this->path;
return $this->replace;
}
}
$result = array();
foreach ($originalKeys as $key => $originalValue) {
$path = $this->path;
$pathItems = $this->pathItems;
$actualKey = $key;
$this->path .= '/' . JsonPointer::escapeSegment($actualKey);
$this->pathItems[] = $actualKey;
$result[$key] = $this->process($originalValue);
$this->path = $path;
$this->pathItems = $pathItems;
}
return $data instanceof \stdClass ? (object)$result : $result;
} | [
"public",
"function",
"process",
"(",
"$",
"data",
")",
"{",
"$",
"check",
"=",
"true",
";",
"if",
"(",
"$",
"this",
"->",
"pathFilterRegex",
"&&",
"!",
"preg_match",
"(",
"$",
"this",
"->",
"pathFilterRegex",
",",
"$",
"this",
"->",
"path",
")",
")"... | Recursively replaces all nodes equal to `search` value with `replace` value.
@param mixed $data
@return mixed
@throws Exception | [
"Recursively",
"replaces",
"all",
"nodes",
"equal",
"to",
"search",
"value",
"with",
"replace",
"value",
"."
] | 53c412ad8e3fc1293d4e6fdf06f7839698ad897d | https://github.com/swaggest/json-diff/blob/53c412ad8e3fc1293d4e6fdf06f7839698ad897d/src/JsonValueReplace.php#L35-L77 | train |
flagrow/upload | src/Listeners/AddUploadsApi.php | AddUploadsApi.prepareApiAttributes | public function prepareApiAttributes(Serializing $event)
{
if ($event->isSerializer(ForumSerializer::class)) {
$event->attributes['canUpload'] = $event->actor->can('flagrow.upload');
$event->attributes['canDownload'] = $event->actor->can('flagrow.upload.download');
}
} | php | public function prepareApiAttributes(Serializing $event)
{
if ($event->isSerializer(ForumSerializer::class)) {
$event->attributes['canUpload'] = $event->actor->can('flagrow.upload');
$event->attributes['canDownload'] = $event->actor->can('flagrow.upload.download');
}
} | [
"public",
"function",
"prepareApiAttributes",
"(",
"Serializing",
"$",
"event",
")",
"{",
"if",
"(",
"$",
"event",
"->",
"isSerializer",
"(",
"ForumSerializer",
"::",
"class",
")",
")",
"{",
"$",
"event",
"->",
"attributes",
"[",
"'canUpload'",
"]",
"=",
"... | Gets the api attributes and makes them available to the forum.
@param Serializing $event | [
"Gets",
"the",
"api",
"attributes",
"and",
"makes",
"them",
"available",
"to",
"the",
"forum",
"."
] | 4e6fb47ce01f1a6f3592dec3d5904570cdbba07b | https://github.com/flagrow/upload/blob/4e6fb47ce01f1a6f3592dec3d5904570cdbba07b/src/Listeners/AddUploadsApi.php#L37-L43 | train |
flagrow/upload | src/Adapters/Flysystem.php | Flysystem.delete | public function delete(File $file)
{
if ($this->adapter->delete($file->path)) {
return $file;
}
return false;
} | php | public function delete(File $file)
{
if ($this->adapter->delete($file->path)) {
return $file;
}
return false;
} | [
"public",
"function",
"delete",
"(",
"File",
"$",
"file",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"adapter",
"->",
"delete",
"(",
"$",
"file",
"->",
"path",
")",
")",
"{",
"return",
"$",
"file",
";",
"}",
"return",
"false",
";",
"}"
] | In case deletion is not possible, return false.
@param File $file
@return File|bool | [
"In",
"case",
"deletion",
"is",
"not",
"possible",
"return",
"false",
"."
] | 4e6fb47ce01f1a6f3592dec3d5904570cdbba07b | https://github.com/flagrow/upload/blob/4e6fb47ce01f1a6f3592dec3d5904570cdbba07b/src/Adapters/Flysystem.php#L97-L104 | train |
flagrow/upload | src/Repositories/FileRepository.php | FileRepository.removeFromTemp | public function removeFromTemp(Upload $file)
{
return $this->getTempFilesystem($file->getPath())->delete($file->getBasename());
} | php | public function removeFromTemp(Upload $file)
{
return $this->getTempFilesystem($file->getPath())->delete($file->getBasename());
} | [
"public",
"function",
"removeFromTemp",
"(",
"Upload",
"$",
"file",
")",
"{",
"return",
"$",
"this",
"->",
"getTempFilesystem",
"(",
"$",
"file",
"->",
"getPath",
"(",
")",
")",
"->",
"delete",
"(",
"$",
"file",
"->",
"getBasename",
"(",
")",
")",
";",... | Deletes a file from the temporary file location.
@param Upload $file
@return bool | [
"Deletes",
"a",
"file",
"from",
"the",
"temporary",
"file",
"location",
"."
] | 4e6fb47ce01f1a6f3592dec3d5904570cdbba07b | https://github.com/flagrow/upload/blob/4e6fb47ce01f1a6f3592dec3d5904570cdbba07b/src/Repositories/FileRepository.php#L138-L141 | train |
flagrow/upload | src/Templates/AbstractTemplate.php | AbstractTemplate.preview | public function preview(File $file)
{
$bbcode = $this->bbcode();
return preg_replace_callback_array([
'/\](?<find>.*)\[/' => function ($m) use ($file) {
return str_replace($m['find'], $file->base_name, $m[0]);
},
'/size=(?<find>{.*?})/' => function ($m) use ($file) {
return str_replace($m['find'], $file->humanSize, $m[0]);
},
'/uuid=(?<find>{.*?})/' => function ($m) use ($file) {
return str_replace($m['find'], $file->uuid, $m[0]);
},
'/url=(?<find>{.*?})/' => function ($m) use ($file) {
return str_replace($m['find'], $file->url, $m[0]);
},
], $bbcode);
} | php | public function preview(File $file)
{
$bbcode = $this->bbcode();
return preg_replace_callback_array([
'/\](?<find>.*)\[/' => function ($m) use ($file) {
return str_replace($m['find'], $file->base_name, $m[0]);
},
'/size=(?<find>{.*?})/' => function ($m) use ($file) {
return str_replace($m['find'], $file->humanSize, $m[0]);
},
'/uuid=(?<find>{.*?})/' => function ($m) use ($file) {
return str_replace($m['find'], $file->uuid, $m[0]);
},
'/url=(?<find>{.*?})/' => function ($m) use ($file) {
return str_replace($m['find'], $file->url, $m[0]);
},
], $bbcode);
} | [
"public",
"function",
"preview",
"(",
"File",
"$",
"file",
")",
"{",
"$",
"bbcode",
"=",
"$",
"this",
"->",
"bbcode",
"(",
")",
";",
"return",
"preg_replace_callback_array",
"(",
"[",
"'/\\](?<find>.*)\\[/'",
"=>",
"function",
"(",
"$",
"m",
")",
"use",
... | Generates a preview bbcode string.
@param File $file
@return string | [
"Generates",
"a",
"preview",
"bbcode",
"string",
"."
] | 4e6fb47ce01f1a6f3592dec3d5904570cdbba07b | https://github.com/flagrow/upload/blob/4e6fb47ce01f1a6f3592dec3d5904570cdbba07b/src/Templates/AbstractTemplate.php#L82-L100 | train |
flagrow/upload | src/Helpers/Settings.php | Settings.toArrayFrontend | public function toArrayFrontend($prefixed = true, array $only = [])
{
$only = array_merge($only, $this->frontend);
return $this->toArray($prefixed, $only);
} | php | public function toArrayFrontend($prefixed = true, array $only = [])
{
$only = array_merge($only, $this->frontend);
return $this->toArray($prefixed, $only);
} | [
"public",
"function",
"toArrayFrontend",
"(",
"$",
"prefixed",
"=",
"true",
",",
"array",
"$",
"only",
"=",
"[",
"]",
")",
"{",
"$",
"only",
"=",
"array_merge",
"(",
"$",
"only",
",",
"$",
"this",
"->",
"frontend",
")",
";",
"return",
"$",
"this",
... | Loads only settings used in the frontend.
@param bool $prefixed
@param array|null $only
@return array | [
"Loads",
"only",
"settings",
"used",
"in",
"the",
"frontend",
"."
] | 4e6fb47ce01f1a6f3592dec3d5904570cdbba07b | https://github.com/flagrow/upload/blob/4e6fb47ce01f1a6f3592dec3d5904570cdbba07b/src/Helpers/Settings.php#L151-L156 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/DropboxRequest.php | DropboxRequest.setParams | public function setParams(array $params = [])
{
//Process Params
$params = $this->processParams($params);
//Set the params
$this->params = $params;
return $this;
} | php | public function setParams(array $params = [])
{
//Process Params
$params = $this->processParams($params);
//Set the params
$this->params = $params;
return $this;
} | [
"public",
"function",
"setParams",
"(",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"//Process Params",
"$",
"params",
"=",
"$",
"this",
"->",
"processParams",
"(",
"$",
"params",
")",
";",
"//Set the params",
"$",
"this",
"->",
"params",
"=",
"$",
... | Set the Request Params
@param array
@return \Kunnu\Dropbox\DropboxRequest | [
"Set",
"the",
"Request",
"Params"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/DropboxRequest.php#L276-L286 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Store/PersistentDataStoreFactory.php | PersistentDataStoreFactory.makePersistentDataStore | public static function makePersistentDataStore($store = null)
{
if (is_null($store) || $store === 'session') {
return new SessionPersistentDataStore();
}
if ($store instanceof PersistentDataStoreInterface) {
return $store;
}
throw new InvalidArgumentException('The persistent data store must be set to null, "session" or be an instance of use \Kunnu\Dropbox\Store\PersistentDataStoreInterface');
} | php | public static function makePersistentDataStore($store = null)
{
if (is_null($store) || $store === 'session') {
return new SessionPersistentDataStore();
}
if ($store instanceof PersistentDataStoreInterface) {
return $store;
}
throw new InvalidArgumentException('The persistent data store must be set to null, "session" or be an instance of use \Kunnu\Dropbox\Store\PersistentDataStoreInterface');
} | [
"public",
"static",
"function",
"makePersistentDataStore",
"(",
"$",
"store",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"store",
")",
"||",
"$",
"store",
"===",
"'session'",
")",
"{",
"return",
"new",
"SessionPersistentDataStore",
"(",
")",
";... | Make Persistent Data Store
@param null|string|\Kunnu\Dropbox\Store\PersistentDataStoreInterface $store
@throws InvalidArgumentException
@return \Kunnu\Dropbox\Store\PersistentDataStoreInterface | [
"Make",
"Persistent",
"Data",
"Store"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Store/PersistentDataStoreFactory.php#L22-L33 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Models/ModelFactory.php | ModelFactory.make | public static function make(array $data = array())
{
if (static::isFileOrFolder($data)) {
$tag = $data['.tag'];
//File
if (static::isFile($tag)) {
return new FileMetadata($data);
}
//Folder
if (static::isFolder($tag)) {
return new FolderMetadata($data);
}
}
//Temporary Link
if (static::isTemporaryLink($data)) {
return new TemporaryLink($data);
}
//List
if (static::isList($data)) {
return new MetadataCollection($data);
}
//Search Results
if (static::isSearchResult($data)) {
return new SearchResults($data);
}
//Deleted File/Folder
if (static::isDeletedFileOrFolder($data)) {
return new DeletedMetadata($data);
}
//Base Model
return new BaseModel($data);
} | php | public static function make(array $data = array())
{
if (static::isFileOrFolder($data)) {
$tag = $data['.tag'];
//File
if (static::isFile($tag)) {
return new FileMetadata($data);
}
//Folder
if (static::isFolder($tag)) {
return new FolderMetadata($data);
}
}
//Temporary Link
if (static::isTemporaryLink($data)) {
return new TemporaryLink($data);
}
//List
if (static::isList($data)) {
return new MetadataCollection($data);
}
//Search Results
if (static::isSearchResult($data)) {
return new SearchResults($data);
}
//Deleted File/Folder
if (static::isDeletedFileOrFolder($data)) {
return new DeletedMetadata($data);
}
//Base Model
return new BaseModel($data);
} | [
"public",
"static",
"function",
"make",
"(",
"array",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"static",
"::",
"isFileOrFolder",
"(",
"$",
"data",
")",
")",
"{",
"$",
"tag",
"=",
"$",
"data",
"[",
"'.tag'",
"]",
";",
"//File",
"i... | Make a Model Factory
@param array $data Model Data
@return \Kunnu\Dropbox\Models\ModelInterface | [
"Make",
"a",
"Model",
"Factory"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Models/ModelFactory.php#L15-L53 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Authentication/DropboxAuthHelper.php | DropboxAuthHelper.getAuthUrl | public function getAuthUrl($redirectUri = null, array $params = [], $urlState = null)
{
// If no redirect URI
// is provided, the
// CSRF validation
// is being handled
// explicitly.
$state = null;
// Redirect URI is provided
// thus, CSRF validation
// needs to be handled.
if (!is_null($redirectUri)) {
//Get CSRF State Token
$state = $this->getCsrfToken();
//Set the CSRF State Token in the Persistent Data Store
$this->getPersistentDataStore()->set('state', $state);
//Additional User Provided State Data
if (!is_null($urlState)) {
$state .= "|";
$state .= $urlState;
}
}
//Get OAuth2 Authorization URL
return $this->getOAuth2Client()->getAuthorizationUrl($redirectUri, $state, $params);
} | php | public function getAuthUrl($redirectUri = null, array $params = [], $urlState = null)
{
// If no redirect URI
// is provided, the
// CSRF validation
// is being handled
// explicitly.
$state = null;
// Redirect URI is provided
// thus, CSRF validation
// needs to be handled.
if (!is_null($redirectUri)) {
//Get CSRF State Token
$state = $this->getCsrfToken();
//Set the CSRF State Token in the Persistent Data Store
$this->getPersistentDataStore()->set('state', $state);
//Additional User Provided State Data
if (!is_null($urlState)) {
$state .= "|";
$state .= $urlState;
}
}
//Get OAuth2 Authorization URL
return $this->getOAuth2Client()->getAuthorizationUrl($redirectUri, $state, $params);
} | [
"public",
"function",
"getAuthUrl",
"(",
"$",
"redirectUri",
"=",
"null",
",",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"$",
"urlState",
"=",
"null",
")",
"{",
"// If no redirect URI",
"// is provided, the",
"// CSRF validation",
"// is being handled",
"// expl... | Get Authorization URL
@param string $redirectUri Callback URL to redirect to after authorization
@param array $params Additional Params
@param string $urlState Additional User Provided State Data
@link https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize
@return string | [
"Get",
"Authorization",
"URL"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Authentication/DropboxAuthHelper.php#L116-L144 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Authentication/DropboxAuthHelper.php | DropboxAuthHelper.decodeState | protected function decodeState($state)
{
$csrfToken = $state;
$urlState = null;
$splitPos = strpos($state, "|");
if ($splitPos !== false) {
$csrfToken = substr($state, 0, $splitPos);
$urlState = substr($state, $splitPos + 1);
}
return ['csrfToken' => $csrfToken, 'urlState' => $urlState];
} | php | protected function decodeState($state)
{
$csrfToken = $state;
$urlState = null;
$splitPos = strpos($state, "|");
if ($splitPos !== false) {
$csrfToken = substr($state, 0, $splitPos);
$urlState = substr($state, $splitPos + 1);
}
return ['csrfToken' => $csrfToken, 'urlState' => $urlState];
} | [
"protected",
"function",
"decodeState",
"(",
"$",
"state",
")",
"{",
"$",
"csrfToken",
"=",
"$",
"state",
";",
"$",
"urlState",
"=",
"null",
";",
"$",
"splitPos",
"=",
"strpos",
"(",
"$",
"state",
",",
"\"|\"",
")",
";",
"if",
"(",
"$",
"splitPos",
... | Decode State to get the CSRF Token and the URL State
@param string $state State
@return array | [
"Decode",
"State",
"to",
"get",
"the",
"CSRF",
"Token",
"and",
"the",
"URL",
"State"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Authentication/DropboxAuthHelper.php#L153-L166 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php | DropboxGuzzleHttpClient.getResponseBody | protected function getResponseBody($response)
{
//Response must be string
$body = $response;
if ($response instanceof ResponseInterface) {
//Fetch the body
$body = $response->getBody();
}
if ($body instanceof StreamInterface) {
$body = $body->getContents();
}
return (string) $body;
} | php | protected function getResponseBody($response)
{
//Response must be string
$body = $response;
if ($response instanceof ResponseInterface) {
//Fetch the body
$body = $response->getBody();
}
if ($body instanceof StreamInterface) {
$body = $body->getContents();
}
return (string) $body;
} | [
"protected",
"function",
"getResponseBody",
"(",
"$",
"response",
")",
"{",
"//Response must be string",
"$",
"body",
"=",
"$",
"response",
";",
"if",
"(",
"$",
"response",
"instanceof",
"ResponseInterface",
")",
"{",
"//Fetch the body",
"$",
"body",
"=",
"$",
... | Get the Response Body.
@param string|\Psr\Http\Message\ResponseInterface $response Response object
@return string | [
"Get",
"the",
"Response",
"Body",
"."
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Http/Clients/DropboxGuzzleHttpClient.php#L95-L110 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Models/AccountList.php | AccountList.processItems | protected function processItems(array $items)
{
$processedItems = [];
foreach ($items as $entry) {
$processedItems[] = new Account($entry);
}
return $processedItems;
} | php | protected function processItems(array $items)
{
$processedItems = [];
foreach ($items as $entry) {
$processedItems[] = new Account($entry);
}
return $processedItems;
} | [
"protected",
"function",
"processItems",
"(",
"array",
"$",
"items",
")",
"{",
"$",
"processedItems",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"items",
"as",
"$",
"entry",
")",
"{",
"$",
"processedItems",
"[",
"]",
"=",
"new",
"Account",
"(",
"$",
"e... | Process items and cast them
to Account Model
@param array $items Unprocessed Items
@return array Array of Account models | [
"Process",
"items",
"and",
"cast",
"them",
"to",
"Account",
"Model"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Models/AccountList.php#L25-L34 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Dropbox.php | Dropbox.postToAPI | public function postToAPI($endpoint, array $params = [], $accessToken = null)
{
return $this->sendRequest("POST", $endpoint, 'api', $params, $accessToken);
} | php | public function postToAPI($endpoint, array $params = [], $accessToken = null)
{
return $this->sendRequest("POST", $endpoint, 'api', $params, $accessToken);
} | [
"public",
"function",
"postToAPI",
"(",
"$",
"endpoint",
",",
"array",
"$",
"params",
"=",
"[",
"]",
",",
"$",
"accessToken",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"sendRequest",
"(",
"\"POST\"",
",",
"$",
"endpoint",
",",
"'api'",
",",
... | Make a HTTP POST Request to the API endpoint type
@param string $endpoint API Endpoint to send Request to
@param array $params Request Query Params
@param string $accessToken Access Token to send with the Request
@return \Kunnu\Dropbox\DropboxResponse | [
"Make",
"a",
"HTTP",
"POST",
"Request",
"to",
"the",
"API",
"endpoint",
"type"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Dropbox.php#L239-L242 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Dropbox.php | Dropbox.makeModelFromResponse | public function makeModelFromResponse(DropboxResponse $response)
{
//Get the Decoded Body
$body = $response->getDecodedBody();
if (is_null($body)) {
$body = [];
}
//Make and Return the Model
return ModelFactory::make($body);
} | php | public function makeModelFromResponse(DropboxResponse $response)
{
//Get the Decoded Body
$body = $response->getDecodedBody();
if (is_null($body)) {
$body = [];
}
//Make and Return the Model
return ModelFactory::make($body);
} | [
"public",
"function",
"makeModelFromResponse",
"(",
"DropboxResponse",
"$",
"response",
")",
"{",
"//Get the Decoded Body",
"$",
"body",
"=",
"$",
"response",
"->",
"getDecodedBody",
"(",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"body",
")",
")",
"{",
"$",
... | Make Model from DropboxResponse
@param DropboxResponse $response
@return \Kunnu\Dropbox\Models\ModelInterface
@throws \Kunnu\Dropbox\Exceptions\DropboxClientException | [
"Make",
"Model",
"from",
"DropboxResponse"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Dropbox.php#L307-L318 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Dropbox.php | Dropbox.listFolder | public function listFolder($path = null, array $params = [])
{
//Specify the root folder as an
//empty string rather than as "/"
if ($path === '/') {
$path = "";
}
//Set the path
$params['path'] = $path;
//Get File Metadata
$response = $this->postToAPI('/files/list_folder', $params);
//Make and Return the Model
return $this->makeModelFromResponse($response);
} | php | public function listFolder($path = null, array $params = [])
{
//Specify the root folder as an
//empty string rather than as "/"
if ($path === '/') {
$path = "";
}
//Set the path
$params['path'] = $path;
//Get File Metadata
$response = $this->postToAPI('/files/list_folder', $params);
//Make and Return the Model
return $this->makeModelFromResponse($response);
} | [
"public",
"function",
"listFolder",
"(",
"$",
"path",
"=",
"null",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"//Specify the root folder as an",
"//empty string rather than as \"/\"",
"if",
"(",
"$",
"path",
"===",
"'/'",
")",
"{",
"$",
"path",
"=... | Get the contents of a Folder
@param string $path Path to the folder. Defaults to root.
@param array $params Additional Params
@link https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder
@return \Kunnu\Dropbox\Models\MetadataCollection | [
"Get",
"the",
"contents",
"of",
"a",
"Folder"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Dropbox.php#L330-L346 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Dropbox.php | Dropbox.upload | public function upload($dropboxFile, $path, array $params = [])
{
//Make Dropbox File
$dropboxFile = $this->makeDropboxFile($dropboxFile);
//If the file is larger than the Chunked Upload Threshold
if ($dropboxFile->getSize() > static::AUTO_CHUNKED_UPLOAD_THRESHOLD) {
//Upload the file in sessions/chunks
return $this->uploadChunked($dropboxFile, $path, null, null, $params);
}
//Simple file upload
return $this->simpleUpload($dropboxFile, $path, $params);
} | php | public function upload($dropboxFile, $path, array $params = [])
{
//Make Dropbox File
$dropboxFile = $this->makeDropboxFile($dropboxFile);
//If the file is larger than the Chunked Upload Threshold
if ($dropboxFile->getSize() > static::AUTO_CHUNKED_UPLOAD_THRESHOLD) {
//Upload the file in sessions/chunks
return $this->uploadChunked($dropboxFile, $path, null, null, $params);
}
//Simple file upload
return $this->simpleUpload($dropboxFile, $path, $params);
} | [
"public",
"function",
"upload",
"(",
"$",
"dropboxFile",
",",
"$",
"path",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"//Make Dropbox File",
"$",
"dropboxFile",
"=",
"$",
"this",
"->",
"makeDropboxFile",
"(",
"$",
"dropboxFile",
")",
";",
"//I... | Upload a File to Dropbox
@param string|DropboxFile $dropboxFile DropboxFile object or Path to file
@param string $path Path to upload the file to
@param array $params Additional Params
@link https://www.dropbox.com/developers/documentation/http/documentation#files-upload
@return \Kunnu\Dropbox\Models\FileMetadata | [
"Upload",
"a",
"File",
"to",
"Dropbox"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Dropbox.php#L780-L793 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Dropbox.php | Dropbox.makeDropboxFile | public function makeDropboxFile($dropboxFile, $maxLength = null, $offset = null, $mode = DropboxFile::MODE_READ)
{
//Uploading file by file path
if (!$dropboxFile instanceof DropboxFile) {
//Create a DropboxFile Object
$dropboxFile = new DropboxFile($dropboxFile, $mode);
} elseif ($mode !== $dropboxFile->getMode()) {
//Reopen the file with expected mode
$dropboxFile->close();
$dropboxFile = new DropboxFile($dropboxFile->getFilePath(), $mode);
}
if (!is_null($offset)) {
$dropboxFile->setOffset($offset);
}
if (!is_null($maxLength)) {
$dropboxFile->setMaxLength($maxLength);
}
//Return the DropboxFile Object
return $dropboxFile;
} | php | public function makeDropboxFile($dropboxFile, $maxLength = null, $offset = null, $mode = DropboxFile::MODE_READ)
{
//Uploading file by file path
if (!$dropboxFile instanceof DropboxFile) {
//Create a DropboxFile Object
$dropboxFile = new DropboxFile($dropboxFile, $mode);
} elseif ($mode !== $dropboxFile->getMode()) {
//Reopen the file with expected mode
$dropboxFile->close();
$dropboxFile = new DropboxFile($dropboxFile->getFilePath(), $mode);
}
if (!is_null($offset)) {
$dropboxFile->setOffset($offset);
}
if (!is_null($maxLength)) {
$dropboxFile->setMaxLength($maxLength);
}
//Return the DropboxFile Object
return $dropboxFile;
} | [
"public",
"function",
"makeDropboxFile",
"(",
"$",
"dropboxFile",
",",
"$",
"maxLength",
"=",
"null",
",",
"$",
"offset",
"=",
"null",
",",
"$",
"mode",
"=",
"DropboxFile",
"::",
"MODE_READ",
")",
"{",
"//Uploading file by file path",
"if",
"(",
"!",
"$",
... | Make DropboxFile Object
@param string|DropboxFile $dropboxFile DropboxFile object or Path to file
@param int $maxLength Max Bytes to read from the file
@param int $offset Seek to specified offset before reading
@param string $mode The type of access
@return \Kunnu\Dropbox\DropboxFile | [
"Make",
"DropboxFile",
"Object"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Dropbox.php#L805-L827 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Dropbox.php | Dropbox.startUploadSession | public function startUploadSession($dropboxFile, $chunkSize = -1, $close = false)
{
//Make Dropbox File with the given chunk size
$dropboxFile = $this->makeDropboxFile($dropboxFile, $chunkSize);
//Set the close param
$params = [
'close' => $close ? true : false,
'file' => $dropboxFile
];
//Upload File
$file = $this->postToContent('/files/upload_session/start', $params);
$body = $file->getDecodedBody();
//Cannot retrieve Session ID
if (!isset($body['session_id'])) {
throw new DropboxClientException("Could not retrieve Session ID.");
}
//Return the Session ID
return $body['session_id'];
} | php | public function startUploadSession($dropboxFile, $chunkSize = -1, $close = false)
{
//Make Dropbox File with the given chunk size
$dropboxFile = $this->makeDropboxFile($dropboxFile, $chunkSize);
//Set the close param
$params = [
'close' => $close ? true : false,
'file' => $dropboxFile
];
//Upload File
$file = $this->postToContent('/files/upload_session/start', $params);
$body = $file->getDecodedBody();
//Cannot retrieve Session ID
if (!isset($body['session_id'])) {
throw new DropboxClientException("Could not retrieve Session ID.");
}
//Return the Session ID
return $body['session_id'];
} | [
"public",
"function",
"startUploadSession",
"(",
"$",
"dropboxFile",
",",
"$",
"chunkSize",
"=",
"-",
"1",
",",
"$",
"close",
"=",
"false",
")",
"{",
"//Make Dropbox File with the given chunk size",
"$",
"dropboxFile",
"=",
"$",
"this",
"->",
"makeDropboxFile",
... | Start an Upload Session
@param string|DropboxFile $dropboxFile DropboxFile object or Path to file
@param int $chunkSize Size of file chunk to upload
@param boolean $close Closes the session for "appendUploadSession"
@return string Unique identifier for the upload session
@throws \Kunnu\Dropbox\Exceptions\DropboxClientException
@link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-start | [
"Start",
"an",
"Upload",
"Session"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Dropbox.php#L908-L930 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Dropbox.php | Dropbox.appendUploadSession | public function appendUploadSession($dropboxFile, $sessionId, $offset, $chunkSize, $close = false)
{
//Make Dropbox File
$dropboxFile = $this->makeDropboxFile($dropboxFile, $chunkSize, $offset);
//Session ID, offset, chunkSize and path cannot be null
if (is_null($sessionId) || is_null($offset) || is_null($chunkSize)) {
throw new DropboxClientException("Session ID, offset and chunk size cannot be null");
}
$params = [];
//Set the File
$params['file'] = $dropboxFile;
//Set the Cursor: Session ID and Offset
$params['cursor'] = ['session_id' => $sessionId, 'offset' => $offset];
//Set the close param
$params['close'] = $close ? true : false;
//Since this endpoint doesn't have
//any return values, we'll disable the
//response validation for this request.
$params['validateResponse'] = false;
//Upload File
$this->postToContent('/files/upload_session/append_v2', $params);
//Make and Return the Model
return $sessionId;
} | php | public function appendUploadSession($dropboxFile, $sessionId, $offset, $chunkSize, $close = false)
{
//Make Dropbox File
$dropboxFile = $this->makeDropboxFile($dropboxFile, $chunkSize, $offset);
//Session ID, offset, chunkSize and path cannot be null
if (is_null($sessionId) || is_null($offset) || is_null($chunkSize)) {
throw new DropboxClientException("Session ID, offset and chunk size cannot be null");
}
$params = [];
//Set the File
$params['file'] = $dropboxFile;
//Set the Cursor: Session ID and Offset
$params['cursor'] = ['session_id' => $sessionId, 'offset' => $offset];
//Set the close param
$params['close'] = $close ? true : false;
//Since this endpoint doesn't have
//any return values, we'll disable the
//response validation for this request.
$params['validateResponse'] = false;
//Upload File
$this->postToContent('/files/upload_session/append_v2', $params);
//Make and Return the Model
return $sessionId;
} | [
"public",
"function",
"appendUploadSession",
"(",
"$",
"dropboxFile",
",",
"$",
"sessionId",
",",
"$",
"offset",
",",
"$",
"chunkSize",
",",
"$",
"close",
"=",
"false",
")",
"{",
"//Make Dropbox File",
"$",
"dropboxFile",
"=",
"$",
"this",
"->",
"makeDropbox... | Append more data to an Upload Session
@param string|DropboxFile $dropboxFile DropboxFile object or Path to file
@param string $sessionId Session ID returned by `startUploadSession`
@param int $offset The amount of data that has been uploaded so far
@param int $chunkSize The amount of data to upload
@param boolean $close Closes the session for futher "appendUploadSession" calls
@return string Unique identifier for the upload session
@throws \Kunnu\Dropbox\Exceptions\DropboxClientException
@link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-append_v2 | [
"Append",
"more",
"data",
"to",
"an",
"Upload",
"Session"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Dropbox.php#L963-L994 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Dropbox.php | Dropbox.finishUploadSession | public function finishUploadSession($dropboxFile, $sessionId, $offset, $remaining, $path, array $params = [])
{
//Make Dropbox File
$dropboxFile = $this->makeDropboxFile($dropboxFile, $remaining, $offset);
//Session ID, offset, remaining and path cannot be null
if (is_null($sessionId) || is_null($path) || is_null($offset) || is_null($remaining)) {
throw new DropboxClientException("Session ID, offset, remaining and path cannot be null");
}
$queryParams = [];
//Set the File
$queryParams['file'] = $dropboxFile;
//Set the Cursor: Session ID and Offset
$queryParams['cursor'] = ['session_id' => $sessionId, 'offset' => $offset];
//Set the path
$params['path'] = $path;
//Set the Commit
$queryParams['commit'] = $params;
//Upload File
$file = $this->postToContent('/files/upload_session/finish', $queryParams);
$body = $file->getDecodedBody();
//Make and Return the Model
return new FileMetadata($body);
} | php | public function finishUploadSession($dropboxFile, $sessionId, $offset, $remaining, $path, array $params = [])
{
//Make Dropbox File
$dropboxFile = $this->makeDropboxFile($dropboxFile, $remaining, $offset);
//Session ID, offset, remaining and path cannot be null
if (is_null($sessionId) || is_null($path) || is_null($offset) || is_null($remaining)) {
throw new DropboxClientException("Session ID, offset, remaining and path cannot be null");
}
$queryParams = [];
//Set the File
$queryParams['file'] = $dropboxFile;
//Set the Cursor: Session ID and Offset
$queryParams['cursor'] = ['session_id' => $sessionId, 'offset' => $offset];
//Set the path
$params['path'] = $path;
//Set the Commit
$queryParams['commit'] = $params;
//Upload File
$file = $this->postToContent('/files/upload_session/finish', $queryParams);
$body = $file->getDecodedBody();
//Make and Return the Model
return new FileMetadata($body);
} | [
"public",
"function",
"finishUploadSession",
"(",
"$",
"dropboxFile",
",",
"$",
"sessionId",
",",
"$",
"offset",
",",
"$",
"remaining",
",",
"$",
"path",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"//Make Dropbox File",
"$",
"dropboxFile",
"=",
... | Finish an upload session and save the uploaded data to the given file path
@param string|DropboxFile $dropboxFile DropboxFile object or Path to file
@param string $sessionId Session ID returned by `startUploadSession`
@param int $offset The amount of data that has been uploaded so far
@param int $remaining The amount of data that is remaining
@param string $path Path to save the file to, on Dropbox
@param array $params Additional Params
@return \Kunnu\Dropbox\Models\FileMetadata
@throws \Kunnu\Dropbox\Exceptions\DropboxClientException
@link https://www.dropbox.com/developers/documentation/http/documentation#files-upload_session-finish | [
"Finish",
"an",
"upload",
"session",
"and",
"save",
"the",
"uploaded",
"data",
"to",
"the",
"given",
"file",
"path"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Dropbox.php#L1013-L1042 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Dropbox.php | Dropbox.simpleUpload | public function simpleUpload($dropboxFile, $path, array $params = [])
{
//Make Dropbox File
$dropboxFile = $this->makeDropboxFile($dropboxFile);
//Set the path and file
$params['path'] = $path;
$params['file'] = $dropboxFile;
//Upload File
$file = $this->postToContent('/files/upload', $params);
$body = $file->getDecodedBody();
//Make and Return the Model
return new FileMetadata($body);
} | php | public function simpleUpload($dropboxFile, $path, array $params = [])
{
//Make Dropbox File
$dropboxFile = $this->makeDropboxFile($dropboxFile);
//Set the path and file
$params['path'] = $path;
$params['file'] = $dropboxFile;
//Upload File
$file = $this->postToContent('/files/upload', $params);
$body = $file->getDecodedBody();
//Make and Return the Model
return new FileMetadata($body);
} | [
"public",
"function",
"simpleUpload",
"(",
"$",
"dropboxFile",
",",
"$",
"path",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"//Make Dropbox File",
"$",
"dropboxFile",
"=",
"$",
"this",
"->",
"makeDropboxFile",
"(",
"$",
"dropboxFile",
")",
";",
... | Upload a File to Dropbox in a single request
@param string|DropboxFile $dropboxFile DropboxFile object or Path to file
@param string $path Path to upload the file to
@param array $params Additional Params
@link https://www.dropbox.com/developers/documentation/http/documentation#files-upload
@return \Kunnu\Dropbox\Models\FileMetadata | [
"Upload",
"a",
"File",
"to",
"Dropbox",
"in",
"a",
"single",
"request"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Dropbox.php#L1055-L1070 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Dropbox.php | Dropbox.getMetadataFromResponseHeaders | protected function getMetadataFromResponseHeaders(DropboxResponse $response)
{
//Response Headers
$headers = $response->getHeaders();
//Empty metadata for when
//metadata isn't returned
$metadata = [];
//If metadata is available
if (isset($headers[static::METADATA_HEADER])) {
//File Metadata
$data = $headers[static::METADATA_HEADER];
//The metadata is present in the first index
//of the metadata response header array
if (is_array($data) && isset($data[0])) {
$data = $data[0];
}
//Since the metadata is returned as a json string
//it needs to be decoded into an associative array
$metadata = json_decode((string)$data, true);
}
//Return the metadata
return $metadata;
} | php | protected function getMetadataFromResponseHeaders(DropboxResponse $response)
{
//Response Headers
$headers = $response->getHeaders();
//Empty metadata for when
//metadata isn't returned
$metadata = [];
//If metadata is available
if (isset($headers[static::METADATA_HEADER])) {
//File Metadata
$data = $headers[static::METADATA_HEADER];
//The metadata is present in the first index
//of the metadata response header array
if (is_array($data) && isset($data[0])) {
$data = $data[0];
}
//Since the metadata is returned as a json string
//it needs to be decoded into an associative array
$metadata = json_decode((string)$data, true);
}
//Return the metadata
return $metadata;
} | [
"protected",
"function",
"getMetadataFromResponseHeaders",
"(",
"DropboxResponse",
"$",
"response",
")",
"{",
"//Response Headers",
"$",
"headers",
"=",
"$",
"response",
"->",
"getHeaders",
"(",
")",
";",
"//Empty metadata for when",
"//metadata isn't returned",
"$",
"m... | Get metadata from response headers
@param DropboxResponse $response
@return array | [
"Get",
"metadata",
"from",
"response",
"headers"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Dropbox.php#L1141-L1168 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Dropbox.php | Dropbox.getAccounts | public function getAccounts(array $account_ids = [])
{
//Get account
$response = $this->postToAPI('/users/get_account_batch', ['account_ids' => $account_ids]);
$body = $response->getDecodedBody();
//Make and return the model
return new AccountList($body);
} | php | public function getAccounts(array $account_ids = [])
{
//Get account
$response = $this->postToAPI('/users/get_account_batch', ['account_ids' => $account_ids]);
$body = $response->getDecodedBody();
//Make and return the model
return new AccountList($body);
} | [
"public",
"function",
"getAccounts",
"(",
"array",
"$",
"account_ids",
"=",
"[",
"]",
")",
"{",
"//Get account",
"$",
"response",
"=",
"$",
"this",
"->",
"postToAPI",
"(",
"'/users/get_account_batch'",
",",
"[",
"'account_ids'",
"=>",
"$",
"account_ids",
"]",
... | Get Multiple Accounts in one call
@param array $account_ids IDs of the accounts to get details for
@link https://www.dropbox.com/developers/documentation/http/documentation#users-get_account_batch
@return \Kunnu\Dropbox\Models\AccountList | [
"Get",
"Multiple",
"Accounts",
"in",
"one",
"call"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Dropbox.php#L1251-L1259 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Authentication/OAuth2Client.php | OAuth2Client.getAuthorizationUrl | public function getAuthorizationUrl($redirectUri = null, $state = null, array $params = [])
{
//Request Parameters
$params = array_merge([
'client_id' => $this->getApp()->getClientId(),
'response_type' => 'code',
'state' => $state,
], $params);
if (!is_null($redirectUri)) {
$params['redirect_uri'] = $redirectUri;
}
return $this->buildUrl('/oauth2/authorize', $params);
} | php | public function getAuthorizationUrl($redirectUri = null, $state = null, array $params = [])
{
//Request Parameters
$params = array_merge([
'client_id' => $this->getApp()->getClientId(),
'response_type' => 'code',
'state' => $state,
], $params);
if (!is_null($redirectUri)) {
$params['redirect_uri'] = $redirectUri;
}
return $this->buildUrl('/oauth2/authorize', $params);
} | [
"public",
"function",
"getAuthorizationUrl",
"(",
"$",
"redirectUri",
"=",
"null",
",",
"$",
"state",
"=",
"null",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"//Request Parameters",
"$",
"params",
"=",
"array_merge",
"(",
"[",
"'client_id'",
"=>... | Get the OAuth2 Authorization URL
@param string $redirectUri Callback URL to redirect user after authorization.
If null is passed, redirect_uri will be omitted
from the url and the code will be presented directly
to the user.
@param string $state CSRF Token
@param array $params Additional Params
@link https://www.dropbox.com/developers/documentation/http/documentation#oauth2-authorize
@return string | [
"Get",
"the",
"OAuth2",
"Authorization",
"URL"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Authentication/OAuth2Client.php#L109-L123 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Authentication/OAuth2Client.php | OAuth2Client.revokeAccessToken | public function revokeAccessToken()
{
//Access Token
$accessToken = $this->getApp()->getAccessToken();
//Request
$request = new DropboxRequest("POST", "/auth/token/revoke", $accessToken);
// Do not validate the response
// since the /token/revoke endpoint
// doesn't return anything in the response.
// See: https://www.dropbox.com/developers/documentation/http/documentation#auth-token-revoke
$request->setParams(['validateResponse' => false]);
//Revoke Access Token
$this->getClient()->sendRequest($request);
} | php | public function revokeAccessToken()
{
//Access Token
$accessToken = $this->getApp()->getAccessToken();
//Request
$request = new DropboxRequest("POST", "/auth/token/revoke", $accessToken);
// Do not validate the response
// since the /token/revoke endpoint
// doesn't return anything in the response.
// See: https://www.dropbox.com/developers/documentation/http/documentation#auth-token-revoke
$request->setParams(['validateResponse' => false]);
//Revoke Access Token
$this->getClient()->sendRequest($request);
} | [
"public",
"function",
"revokeAccessToken",
"(",
")",
"{",
"//Access Token",
"$",
"accessToken",
"=",
"$",
"this",
"->",
"getApp",
"(",
")",
"->",
"getAccessToken",
"(",
")",
";",
"//Request",
"$",
"request",
"=",
"new",
"DropboxRequest",
"(",
"\"POST\"",
","... | Disables the access token
@return void | [
"Disables",
"the",
"access",
"token"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Authentication/OAuth2Client.php#L169-L184 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/DropboxResponse.php | DropboxResponse.getDecodedBody | public function getDecodedBody()
{
if (empty($this->decodedBody) || $this->decodedBody === null) {
//Decode the Response Body
$this->decodeBody();
}
return $this->decodedBody;
} | php | public function getDecodedBody()
{
if (empty($this->decodedBody) || $this->decodedBody === null) {
//Decode the Response Body
$this->decodeBody();
}
return $this->decodedBody;
} | [
"public",
"function",
"getDecodedBody",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"decodedBody",
")",
"||",
"$",
"this",
"->",
"decodedBody",
"===",
"null",
")",
"{",
"//Decode the Response Body",
"$",
"this",
"->",
"decodeBody",
"(",
")",... | Get the Decoded Body
@return array | [
"Get",
"the",
"Decoded",
"Body"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/DropboxResponse.php#L108-L116 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/DropboxResponse.php | DropboxResponse.decodeBody | protected function decodeBody()
{
$body = $this->getBody();
if (isset($this->headers['Content-Type']) && in_array('application/json', $this->headers['Content-Type'])) {
$this->decodedBody = (array) json_decode((string) $body, true);
}
// If the response needs to be validated
if ($this->getRequest()->validateResponse()) {
//Validate Response
$this->validateResponse();
}
} | php | protected function decodeBody()
{
$body = $this->getBody();
if (isset($this->headers['Content-Type']) && in_array('application/json', $this->headers['Content-Type'])) {
$this->decodedBody = (array) json_decode((string) $body, true);
}
// If the response needs to be validated
if ($this->getRequest()->validateResponse()) {
//Validate Response
$this->validateResponse();
}
} | [
"protected",
"function",
"decodeBody",
"(",
")",
"{",
"$",
"body",
"=",
"$",
"this",
"->",
"getBody",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
"'Content-Type'",
"]",
")",
"&&",
"in_array",
"(",
"'application/json'",
",... | Decode the Body
@throws DropboxClientException
@return void | [
"Decode",
"the",
"Body"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/DropboxResponse.php#L155-L168 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/DropboxFile.php | DropboxFile.createByStream | public static function createByStream($fileName, $resource, $mode = self::MODE_READ)
{
// create a new stream and set it to the dropbox file
$stream = \GuzzleHttp\Psr7\stream_for($resource);
if (!$stream) {
throw new DropboxClientException('Failed to create DropboxFile instance. Unable to open the given resource.');
}
// Try to get the file path from the stream (we'll need this for uploading bigger files)
$filePath = $stream->getMetadata('uri');
if (!is_null($filePath)) {
$fileName = $filePath;
}
$dropboxFile = new self($fileName, $mode);
$dropboxFile->setStream($stream);
return $dropboxFile;
} | php | public static function createByStream($fileName, $resource, $mode = self::MODE_READ)
{
// create a new stream and set it to the dropbox file
$stream = \GuzzleHttp\Psr7\stream_for($resource);
if (!$stream) {
throw new DropboxClientException('Failed to create DropboxFile instance. Unable to open the given resource.');
}
// Try to get the file path from the stream (we'll need this for uploading bigger files)
$filePath = $stream->getMetadata('uri');
if (!is_null($filePath)) {
$fileName = $filePath;
}
$dropboxFile = new self($fileName, $mode);
$dropboxFile->setStream($stream);
return $dropboxFile;
} | [
"public",
"static",
"function",
"createByStream",
"(",
"$",
"fileName",
",",
"$",
"resource",
",",
"$",
"mode",
"=",
"self",
"::",
"MODE_READ",
")",
"{",
"// create a new stream and set it to the dropbox file",
"$",
"stream",
"=",
"\\",
"GuzzleHttp",
"\\",
"Psr7",... | Create a new DropboxFile instance using a file stream
@param $fileName
@param $resource
@param string $mode
@return DropboxFile
@throws DropboxClientException | [
"Create",
"a",
"new",
"DropboxFile",
"instance",
"using",
"a",
"file",
"stream"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/DropboxFile.php#L82-L100 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Models/BaseModel.php | BaseModel.getDataProperty | public function getDataProperty($property)
{
return isset($this->data[$property]) ? $this->data[$property] : null;
} | php | public function getDataProperty($property)
{
return isset($this->data[$property]) ? $this->data[$property] : null;
} | [
"public",
"function",
"getDataProperty",
"(",
"$",
"property",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"data",
"[",
"$",
"property",
"]",
")",
"?",
"$",
"this",
"->",
"data",
"[",
"$",
"property",
"]",
":",
"null",
";",
"}"
] | Get Data Property
@param string $property
@return mixed | [
"Get",
"Data",
"Property"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Models/BaseModel.php#L41-L44 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Models/MediaInfo.php | MediaInfo.setMediaMetadata | protected function setMediaMetadata()
{
$mediaMetadata = $this->getDataProperty('metadata');
if (is_array($mediaMetadata)) {
if ($mediaMetadata['.tag'] === 'photo') {
//Media is Photo
$this->mediaMetadata = new PhotoMetadata($mediaMetadata);
} elseif ($mediaMetadata['.tag'] === 'video') {
//Media is Video
$this->mediaMetadata = new VideoMetadata($mediaMetadata);
} else {
//Unknown Media (Quite unlikely, though.)
$this->mediaMetadata = new MediaMetadata($mediaMetadata);
}
}
} | php | protected function setMediaMetadata()
{
$mediaMetadata = $this->getDataProperty('metadata');
if (is_array($mediaMetadata)) {
if ($mediaMetadata['.tag'] === 'photo') {
//Media is Photo
$this->mediaMetadata = new PhotoMetadata($mediaMetadata);
} elseif ($mediaMetadata['.tag'] === 'video') {
//Media is Video
$this->mediaMetadata = new VideoMetadata($mediaMetadata);
} else {
//Unknown Media (Quite unlikely, though.)
$this->mediaMetadata = new MediaMetadata($mediaMetadata);
}
}
} | [
"protected",
"function",
"setMediaMetadata",
"(",
")",
"{",
"$",
"mediaMetadata",
"=",
"$",
"this",
"->",
"getDataProperty",
"(",
"'metadata'",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"mediaMetadata",
")",
")",
"{",
"if",
"(",
"$",
"mediaMetadata",
"[",... | Set Media Metadata | [
"Set",
"Media",
"Metadata"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Models/MediaInfo.php#L38-L53 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Store/SessionPersistentDataStore.php | SessionPersistentDataStore.clear | public function clear($key)
{
if (isset($_SESSION[$this->prefix . $key])) {
unset($_SESSION[$this->prefix . $key]);
}
} | php | public function clear($key)
{
if (isset($_SESSION[$this->prefix . $key])) {
unset($_SESSION[$this->prefix . $key]);
}
} | [
"public",
"function",
"clear",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"prefix",
".",
"$",
"key",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"_SESSION",
"[",
"$",
"this",
"->",
"prefix",
".",
"$"... | Clear the key from the store
@param $key Data Key
@return void | [
"Clear",
"the",
"key",
"from",
"the",
"store"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Store/SessionPersistentDataStore.php#L59-L64 | train |
kunalvarma05/dropbox-php-sdk | src/Dropbox/Security/RandomStringGeneratorFactory.php | RandomStringGeneratorFactory.makeRandomStringGenerator | public static function makeRandomStringGenerator($generator = null)
{
//No generator provided
if (is_null($generator)) {
//Generate default random string generator
return static::defaultRandomStringGenerator();
}
//RandomStringGeneratorInterface
if ($generator instanceof RandomStringGeneratorInterface) {
return $generator;
}
// Mcrypt
if ('mcrypt' === $generator) {
return new McryptRandomStringGenerator();
}
//OpenSSL
if ('openssl' === $generator) {
return new OpenSslRandomStringGenerator();
}
//Invalid Argument
throw new InvalidArgumentException('The random string generator must be set to "mcrypt", "openssl" or be an instance of Kunnu\Dropbox\Security\RandomStringGeneratorInterface');
} | php | public static function makeRandomStringGenerator($generator = null)
{
//No generator provided
if (is_null($generator)) {
//Generate default random string generator
return static::defaultRandomStringGenerator();
}
//RandomStringGeneratorInterface
if ($generator instanceof RandomStringGeneratorInterface) {
return $generator;
}
// Mcrypt
if ('mcrypt' === $generator) {
return new McryptRandomStringGenerator();
}
//OpenSSL
if ('openssl' === $generator) {
return new OpenSslRandomStringGenerator();
}
//Invalid Argument
throw new InvalidArgumentException('The random string generator must be set to "mcrypt", "openssl" or be an instance of Kunnu\Dropbox\Security\RandomStringGeneratorInterface');
} | [
"public",
"static",
"function",
"makeRandomStringGenerator",
"(",
"$",
"generator",
"=",
"null",
")",
"{",
"//No generator provided",
"if",
"(",
"is_null",
"(",
"$",
"generator",
")",
")",
"{",
"//Generate default random string generator",
"return",
"static",
"::",
... | Make a Random String Generator
@param null|string|\Kunnu\Dropbox\Security\RandomStringGeneratorInterface $generator
@throws \Kunnu\Dropbox\Exceptions\DropboxClientException
@return \Kunnu\Dropbox\Security\RandomStringGeneratorInterface | [
"Make",
"a",
"Random",
"String",
"Generator"
] | f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff | https://github.com/kunalvarma05/dropbox-php-sdk/blob/f8ab4d32fb832ea18a20ac8fbba76f675e7a6fff/src/Dropbox/Security/RandomStringGeneratorFactory.php#L23-L48 | train |
StydeNet/html | src/FormBuilder.php | FormBuilder.novalidate | public function novalidate($value = null)
{
if ($value !== null) {
$this->novalidate = $value;
}
return $this->novalidate;
} | php | public function novalidate($value = null)
{
if ($value !== null) {
$this->novalidate = $value;
}
return $this->novalidate;
} | [
"public",
"function",
"novalidate",
"(",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"!==",
"null",
")",
"{",
"$",
"this",
"->",
"novalidate",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"this",
"->",
"novalidate",
";",
"}"
] | Allows user to set the novalidate option for every form generated with
the form open method, so developers can skin HTML5 validation, in order
to test backend validation in a local or development environment.
@param null $value
@return bool|null | [
"Allows",
"user",
"to",
"set",
"the",
"novalidate",
"option",
"for",
"every",
"form",
"generated",
"with",
"the",
"form",
"open",
"method",
"so",
"developers",
"can",
"skin",
"HTML5",
"validation",
"in",
"order",
"to",
"test",
"backend",
"validation",
"in",
... | b93eda3606edf049dc579c6b9c903cbcf0605d71 | https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/FormBuilder.php#L48-L55 | train |
StydeNet/html | src/FormBuilder.php | FormBuilder.radios | public function radios($name, $options = array(), $selected = null, $attributes = array(), $hasErrors = false)
{
$selected = $this->getValueAttribute($name, $selected);
$defaultTemplate = in_array('inline', $attributes)
? 'forms.radios-inline'
: 'forms.radios';
$template = isset($attributes['template'])
? $attributes['template']
: null;
$radios = [];
foreach ($options as $value => $label) {
$radios[] = [
'name' => $name,
'value' => $value,
'label' => $label,
'selected' => $selected == $value,
'id' => $name.'_'.Str::slug($value),
];
}
unset ($attributes['inline'], $attributes['template']);
return $this->theme->render(
$template,
compact('name', 'radios', 'attributes', 'hasErrors'),
$defaultTemplate
);
} | php | public function radios($name, $options = array(), $selected = null, $attributes = array(), $hasErrors = false)
{
$selected = $this->getValueAttribute($name, $selected);
$defaultTemplate = in_array('inline', $attributes)
? 'forms.radios-inline'
: 'forms.radios';
$template = isset($attributes['template'])
? $attributes['template']
: null;
$radios = [];
foreach ($options as $value => $label) {
$radios[] = [
'name' => $name,
'value' => $value,
'label' => $label,
'selected' => $selected == $value,
'id' => $name.'_'.Str::slug($value),
];
}
unset ($attributes['inline'], $attributes['template']);
return $this->theme->render(
$template,
compact('name', 'radios', 'attributes', 'hasErrors'),
$defaultTemplate
);
} | [
"public",
"function",
"radios",
"(",
"$",
"name",
",",
"$",
"options",
"=",
"array",
"(",
")",
",",
"$",
"selected",
"=",
"null",
",",
"$",
"attributes",
"=",
"array",
"(",
")",
",",
"$",
"hasErrors",
"=",
"false",
")",
"{",
"$",
"selected",
"=",
... | Create a list of radios.
This function is very similar to Form::select but it generates a
collection of radios instead of options.
i.e. Form::radios('status', ['a' => 'Active', 'i' => 'Inactive'])
You can pass 'inline' as a value of the attribute's array, to set the
radios as inline (they'll be rendered with the 'radios-inline' template).
@param string $name
@param array $options
@param string $selected
@param array $attributes
@param bool $hasErrors
@return string | [
"Create",
"a",
"list",
"of",
"radios",
"."
] | b93eda3606edf049dc579c6b9c903cbcf0605d71 | https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/FormBuilder.php#L116-L147 | train |
StydeNet/html | src/Str.php | Str.title | public static function title($string)
{
$stringr = $string[0].preg_replace('@[_-]|([A-Z])@', ' $1', substr($string, 1));
return ucfirst(strtolower($stringr));
} | php | public static function title($string)
{
$stringr = $string[0].preg_replace('@[_-]|([A-Z])@', ' $1', substr($string, 1));
return ucfirst(strtolower($stringr));
} | [
"public",
"static",
"function",
"title",
"(",
"$",
"string",
")",
"{",
"$",
"stringr",
"=",
"$",
"string",
"[",
"0",
"]",
".",
"preg_replace",
"(",
"'@[_-]|([A-Z])@'",
",",
"' $1'",
",",
"substr",
"(",
"$",
"string",
",",
"1",
")",
")",
";",
"return"... | Convert camel cases, underscore and hyphen separated strings to human
format.
@param $string
@return string | [
"Convert",
"camel",
"cases",
"underscore",
"and",
"hyphen",
"separated",
"strings",
"to",
"human",
"format",
"."
] | b93eda3606edf049dc579c6b9c903cbcf0605d71 | https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Str.php#L15-L19 | train |
StydeNet/html | src/Menu/Menu.php | Menu.render | public function render($customTemplate = null)
{
$items = $this->generateItems($this->items);
return $this->theme->render(
$customTemplate,
['items' => $items, 'class' => $this->class],
'menu'
);
} | php | public function render($customTemplate = null)
{
$items = $this->generateItems($this->items);
return $this->theme->render(
$customTemplate,
['items' => $items, 'class' => $this->class],
'menu'
);
} | [
"public",
"function",
"render",
"(",
"$",
"customTemplate",
"=",
"null",
")",
"{",
"$",
"items",
"=",
"$",
"this",
"->",
"generateItems",
"(",
"$",
"this",
"->",
"items",
")",
";",
"return",
"$",
"this",
"->",
"theme",
"->",
"render",
"(",
"$",
"cust... | Renders a new menu
@param string|null $customTemplate
@return string the menu's HTML | [
"Renders",
"a",
"new",
"menu"
] | b93eda3606edf049dc579c6b9c903cbcf0605d71 | https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Menu/Menu.php#L253-L262 | train |
StydeNet/html | src/Menu/Menu.php | Menu.generateItems | protected function generateItems($items)
{
foreach ($items as $id => &$values) {
$values = $this->setDefaultValues($id, $values);
if (!$this->checkAccess($values)) {
unset($items[$id]);
continue;
}
$values['title'] = $this->getTitle($id, $values['title']);
$values['url'] = $this->generateUrl($values);
if (isset($values['submenu'])) {
$values['submenu'] = $this->generateItems($values['submenu']);
}
if ($this->isActiveUrl($values)) {
$values['active'] = true;
$this->currentId = $id;
} elseif (isset ($values['submenu'])) {
// Check if there is an active item in the submenu, if
// so it'll mark the current item as active as well.
foreach ($values['submenu'] as $subitem) {
if ($subitem['active']) {
$values['active'] = true;
break;
}
}
}
if ($values['active']) {
$values['class'] .= ' '.$this->activeClass;
}
if ($values['submenu']) {
$values['class'] .= ' '.$this->dropDownClass;
}
$values['class'] = trim($values['class']);
unset(
$values['callback'], $values['logged'], $values['roles'], $values['secure'],
$values['params'], $values['route'], $values['action'], $values['full_url'],
$values['allows'], $values['check'], $values['denies'], $values['exact']
);
}
return $items;
} | php | protected function generateItems($items)
{
foreach ($items as $id => &$values) {
$values = $this->setDefaultValues($id, $values);
if (!$this->checkAccess($values)) {
unset($items[$id]);
continue;
}
$values['title'] = $this->getTitle($id, $values['title']);
$values['url'] = $this->generateUrl($values);
if (isset($values['submenu'])) {
$values['submenu'] = $this->generateItems($values['submenu']);
}
if ($this->isActiveUrl($values)) {
$values['active'] = true;
$this->currentId = $id;
} elseif (isset ($values['submenu'])) {
// Check if there is an active item in the submenu, if
// so it'll mark the current item as active as well.
foreach ($values['submenu'] as $subitem) {
if ($subitem['active']) {
$values['active'] = true;
break;
}
}
}
if ($values['active']) {
$values['class'] .= ' '.$this->activeClass;
}
if ($values['submenu']) {
$values['class'] .= ' '.$this->dropDownClass;
}
$values['class'] = trim($values['class']);
unset(
$values['callback'], $values['logged'], $values['roles'], $values['secure'],
$values['params'], $values['route'], $values['action'], $values['full_url'],
$values['allows'], $values['check'], $values['denies'], $values['exact']
);
}
return $items;
} | [
"protected",
"function",
"generateItems",
"(",
"$",
"items",
")",
"{",
"foreach",
"(",
"$",
"items",
"as",
"$",
"id",
"=>",
"&",
"$",
"values",
")",
"{",
"$",
"values",
"=",
"$",
"this",
"->",
"setDefaultValues",
"(",
"$",
"id",
",",
"$",
"values",
... | Generate the items for a menu or sub-menu.
This method will called itself if an item has a 'submenu' key.
@param array $items
@return array | [
"Generate",
"the",
"items",
"for",
"a",
"menu",
"or",
"sub",
"-",
"menu",
"."
] | b93eda3606edf049dc579c6b9c903cbcf0605d71 | https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Menu/Menu.php#L297-L347 | train |
StydeNet/html | src/Menu/Menu.php | Menu.isActiveUrl | protected function isActiveUrl(array $values)
{
// Do we have a custom resolver? If so, use it:
if($activeUrlResolver = $this->activeUrlResolver) {
return $activeUrlResolver($values);
}
// If the current URL is the base URL or the exact attribute is set to true, then check for the exact URL
if ($values['exact'] ?? false || $values['url'] == $this->baseUrl) {
return $this->activeUrl === $values['url'];
}
// Otherwise use the default resolver:
return strpos($this->activeUrl, $values['url']) === 0;
} | php | protected function isActiveUrl(array $values)
{
// Do we have a custom resolver? If so, use it:
if($activeUrlResolver = $this->activeUrlResolver) {
return $activeUrlResolver($values);
}
// If the current URL is the base URL or the exact attribute is set to true, then check for the exact URL
if ($values['exact'] ?? false || $values['url'] == $this->baseUrl) {
return $this->activeUrl === $values['url'];
}
// Otherwise use the default resolver:
return strpos($this->activeUrl, $values['url']) === 0;
} | [
"protected",
"function",
"isActiveUrl",
"(",
"array",
"$",
"values",
")",
"{",
"// Do we have a custom resolver? If so, use it:",
"if",
"(",
"$",
"activeUrlResolver",
"=",
"$",
"this",
"->",
"activeUrlResolver",
")",
"{",
"return",
"$",
"activeUrlResolver",
"(",
"$"... | Checks whether this is the current URL or not
@param array $values
@return bool | [
"Checks",
"whether",
"this",
"is",
"the",
"current",
"URL",
"or",
"not"
] | b93eda3606edf049dc579c6b9c903cbcf0605d71 | https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Menu/Menu.php#L372-L386 | train |
StydeNet/html | src/Menu/Menu.php | Menu.translateTitle | protected function translateTitle($key)
{
$translation = $this->lang->get('menu.'.$key);
if ($translation != 'menu.'.$key) {
return $translation;
}
return Str::title($key);
} | php | protected function translateTitle($key)
{
$translation = $this->lang->get('menu.'.$key);
if ($translation != 'menu.'.$key) {
return $translation;
}
return Str::title($key);
} | [
"protected",
"function",
"translateTitle",
"(",
"$",
"key",
")",
"{",
"$",
"translation",
"=",
"$",
"this",
"->",
"lang",
"->",
"get",
"(",
"'menu.'",
".",
"$",
"key",
")",
";",
"if",
"(",
"$",
"translation",
"!=",
"'menu.'",
".",
"$",
"key",
")",
... | Translates and return a title for a menu item.
This method will attempt to find a "menu.key_item" through the translator
component. If no translation is found for this item, it will attempt to
transform the item $key string to a title readable format.
@param $key
@return string | [
"Translates",
"and",
"return",
"a",
"title",
"for",
"a",
"menu",
"item",
"."
] | b93eda3606edf049dc579c6b9c903cbcf0605d71 | https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Menu/Menu.php#L423-L432 | train |
StydeNet/html | src/Menu/Menu.php | Menu.getRouteAndParameters | protected function getRouteAndParameters($params)
{
if (is_string($params)) {
return [$params, []];
}
return [
// The first position in the array is the route or action name
array_shift($params),
// After that they are parameters and they could be dynamic
$this->replaceDynamicParameters($params)
];
} | php | protected function getRouteAndParameters($params)
{
if (is_string($params)) {
return [$params, []];
}
return [
// The first position in the array is the route or action name
array_shift($params),
// After that they are parameters and they could be dynamic
$this->replaceDynamicParameters($params)
];
} | [
"protected",
"function",
"getRouteAndParameters",
"(",
"$",
"params",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"params",
")",
")",
"{",
"return",
"[",
"$",
"params",
",",
"[",
"]",
"]",
";",
"}",
"return",
"[",
"// The first position in the array is the r... | Retrieve a route or action name and its parameters
If $params is a string, then it returns it as the name of the route or
action and the parameters will be an empty array.
If it is an array then it takes the first element as the name of the
route or action and the other elements as the parameters.
Then it will try to replace any dynamic parameters (relying on the
replaceDynamicParameters method, see below)
Finally it will return an array where the first value will be the name of
the route or action and the second value will be the array of parameters.
@param $params
@return array | [
"Retrieve",
"a",
"route",
"or",
"action",
"name",
"and",
"its",
"parameters"
] | b93eda3606edf049dc579c6b9c903cbcf0605d71 | https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Menu/Menu.php#L452-L464 | train |
StydeNet/html | src/Menu/Menu.php | Menu.replaceDynamicParameters | protected function replaceDynamicParameters(array $params)
{
foreach ($params as &$param) {
if (strpos($param, ':') !== 0) {
continue;
}
$name = substr($param, 1);
if (isset($this->params[$name])) {
$param = $this->params[$name];
}
}
return $params;
} | php | protected function replaceDynamicParameters(array $params)
{
foreach ($params as &$param) {
if (strpos($param, ':') !== 0) {
continue;
}
$name = substr($param, 1);
if (isset($this->params[$name])) {
$param = $this->params[$name];
}
}
return $params;
} | [
"protected",
"function",
"replaceDynamicParameters",
"(",
"array",
"$",
"params",
")",
"{",
"foreach",
"(",
"$",
"params",
"as",
"&",
"$",
"param",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"param",
",",
"':'",
")",
"!==",
"0",
")",
"{",
"continue",
"... | Allows variable or dynamic parameters for all the menu's routes and URLs
Just precede the parameter's name with ":"
For example: :user_id
This method will cycle through all the parameters and replace the dynamic
ones with their corresponding values stored through the setParams and
setParam methods,
If a dynamic value is not found the literal value will be returned.
@param array $params
@return array | [
"Allows",
"variable",
"or",
"dynamic",
"parameters",
"for",
"all",
"the",
"menu",
"s",
"routes",
"and",
"URLs"
] | b93eda3606edf049dc579c6b9c903cbcf0605d71 | https://github.com/StydeNet/html/blob/b93eda3606edf049dc579c6b9c903cbcf0605d71/src/Menu/Menu.php#L481-L494 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.