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 |
---|---|---|---|---|---|---|---|---|---|---|---|
symbiote/silverstripe-versionedfiles | code/VersionedImageExtension.php | VersionedImageExtension.onBeforeWrite | public function onBeforeWrite()
{
if (!$this->owner->isChanged('CurrentVersionID')) {
return;
}
// Support new {@see Image::regenerateFormattedImages} method in 3.2
if ($this->owner->hasMethod('regenerateFormattedImages')) {
$this->owner->regenerateFormattedImages();
return;
}
if ($this->owner->ParentID) {
$base = $this->owner->Parent()->getFullPath();
} else {
$base = ASSETS_PATH . '/';
}
$resampled = "{$base}_resampled";
if (!is_dir($resampled)) {
return;
}
$files = scandir($resampled);
$iterator = new ArrayIterator($files);
$filter = new RegexIterator(
$iterator,
sprintf(
"/([a-z]+)([0-9]?[0-9a-f]*)-%s/i",
preg_quote($this->owner->Name)
),
RegexIterator::GET_MATCH
);
// grab each resampled image and regenerate it
foreach ($filter as $cachedImage) {
$path = "$resampled/{$cachedImage[0]}";
//skip resampled image files that don't exist
if (!file_exists($path)) {
continue;
}
$size = getimagesize($path);
$method = $cachedImage[1];
$arguments = $cachedImage[2];
unlink($path);
// Determine the arguments used to generate an image, and regenerate
// it. Different methods need different ways of determining the
// original arguments used.
switch (strtolower($method)) {
case 'paddedimage':
$color = preg_replace("/^{$size[0]}{$size[1]}/", '', $arguments);
$this->owner->$method($size[0], $size[1], $color);
break;
case 'resizedimage':
case 'setsize':
case 'croppedimage':
case 'setratiosize':
case 'croppedfocusedimage':
$this->owner->$method($size[0], $size[1]);
break;
case 'setwidth':
$this->owner->$method($size[0]);
break;
case 'setheight':
$this->owner->$method($size[1]);
break;
default:
$this->owner->$method($arguments);
break;
}
}
} | php | public function onBeforeWrite()
{
if (!$this->owner->isChanged('CurrentVersionID')) {
return;
}
// Support new {@see Image::regenerateFormattedImages} method in 3.2
if ($this->owner->hasMethod('regenerateFormattedImages')) {
$this->owner->regenerateFormattedImages();
return;
}
if ($this->owner->ParentID) {
$base = $this->owner->Parent()->getFullPath();
} else {
$base = ASSETS_PATH . '/';
}
$resampled = "{$base}_resampled";
if (!is_dir($resampled)) {
return;
}
$files = scandir($resampled);
$iterator = new ArrayIterator($files);
$filter = new RegexIterator(
$iterator,
sprintf(
"/([a-z]+)([0-9]?[0-9a-f]*)-%s/i",
preg_quote($this->owner->Name)
),
RegexIterator::GET_MATCH
);
// grab each resampled image and regenerate it
foreach ($filter as $cachedImage) {
$path = "$resampled/{$cachedImage[0]}";
//skip resampled image files that don't exist
if (!file_exists($path)) {
continue;
}
$size = getimagesize($path);
$method = $cachedImage[1];
$arguments = $cachedImage[2];
unlink($path);
// Determine the arguments used to generate an image, and regenerate
// it. Different methods need different ways of determining the
// original arguments used.
switch (strtolower($method)) {
case 'paddedimage':
$color = preg_replace("/^{$size[0]}{$size[1]}/", '', $arguments);
$this->owner->$method($size[0], $size[1], $color);
break;
case 'resizedimage':
case 'setsize':
case 'croppedimage':
case 'setratiosize':
case 'croppedfocusedimage':
$this->owner->$method($size[0], $size[1]);
break;
case 'setwidth':
$this->owner->$method($size[0]);
break;
case 'setheight':
$this->owner->$method($size[1]);
break;
default:
$this->owner->$method($arguments);
break;
}
}
} | [
"public",
"function",
"onBeforeWrite",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"owner",
"->",
"isChanged",
"(",
"'CurrentVersionID'",
")",
")",
"{",
"return",
";",
"}",
"// Support new {@see Image::regenerateFormattedImages} method in 3.2",
"if",
"(",
"$",
"this",
"->",
"owner",
"->",
"hasMethod",
"(",
"'regenerateFormattedImages'",
")",
")",
"{",
"$",
"this",
"->",
"owner",
"->",
"regenerateFormattedImages",
"(",
")",
";",
"return",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"owner",
"->",
"ParentID",
")",
"{",
"$",
"base",
"=",
"$",
"this",
"->",
"owner",
"->",
"Parent",
"(",
")",
"->",
"getFullPath",
"(",
")",
";",
"}",
"else",
"{",
"$",
"base",
"=",
"ASSETS_PATH",
".",
"'/'",
";",
"}",
"$",
"resampled",
"=",
"\"{$base}_resampled\"",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"resampled",
")",
")",
"{",
"return",
";",
"}",
"$",
"files",
"=",
"scandir",
"(",
"$",
"resampled",
")",
";",
"$",
"iterator",
"=",
"new",
"ArrayIterator",
"(",
"$",
"files",
")",
";",
"$",
"filter",
"=",
"new",
"RegexIterator",
"(",
"$",
"iterator",
",",
"sprintf",
"(",
"\"/([a-z]+)([0-9]?[0-9a-f]*)-%s/i\"",
",",
"preg_quote",
"(",
"$",
"this",
"->",
"owner",
"->",
"Name",
")",
")",
",",
"RegexIterator",
"::",
"GET_MATCH",
")",
";",
"// grab each resampled image and regenerate it",
"foreach",
"(",
"$",
"filter",
"as",
"$",
"cachedImage",
")",
"{",
"$",
"path",
"=",
"\"$resampled/{$cachedImage[0]}\"",
";",
"//skip resampled image files that don't exist",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"path",
")",
")",
"{",
"continue",
";",
"}",
"$",
"size",
"=",
"getimagesize",
"(",
"$",
"path",
")",
";",
"$",
"method",
"=",
"$",
"cachedImage",
"[",
"1",
"]",
";",
"$",
"arguments",
"=",
"$",
"cachedImage",
"[",
"2",
"]",
";",
"unlink",
"(",
"$",
"path",
")",
";",
"// Determine the arguments used to generate an image, and regenerate",
"// it. Different methods need different ways of determining the",
"// original arguments used.",
"switch",
"(",
"strtolower",
"(",
"$",
"method",
")",
")",
"{",
"case",
"'paddedimage'",
":",
"$",
"color",
"=",
"preg_replace",
"(",
"\"/^{$size[0]}{$size[1]}/\"",
",",
"''",
",",
"$",
"arguments",
")",
";",
"$",
"this",
"->",
"owner",
"->",
"$",
"method",
"(",
"$",
"size",
"[",
"0",
"]",
",",
"$",
"size",
"[",
"1",
"]",
",",
"$",
"color",
")",
";",
"break",
";",
"case",
"'resizedimage'",
":",
"case",
"'setsize'",
":",
"case",
"'croppedimage'",
":",
"case",
"'setratiosize'",
":",
"case",
"'croppedfocusedimage'",
":",
"$",
"this",
"->",
"owner",
"->",
"$",
"method",
"(",
"$",
"size",
"[",
"0",
"]",
",",
"$",
"size",
"[",
"1",
"]",
")",
";",
"break",
";",
"case",
"'setwidth'",
":",
"$",
"this",
"->",
"owner",
"->",
"$",
"method",
"(",
"$",
"size",
"[",
"0",
"]",
")",
";",
"break",
";",
"case",
"'setheight'",
":",
"$",
"this",
"->",
"owner",
"->",
"$",
"method",
"(",
"$",
"size",
"[",
"1",
"]",
")",
";",
"break",
";",
"default",
":",
"$",
"this",
"->",
"owner",
"->",
"$",
"method",
"(",
"$",
"arguments",
")",
";",
"break",
";",
"}",
"}",
"}"
]
| Regenerates all cached images if the version number has been changed. | [
"Regenerates",
"all",
"cached",
"images",
"if",
"the",
"version",
"number",
"has",
"been",
"changed",
"."
]
| 5f90cc3242491c16739dfd73e914a8748354ba59 | https://github.com/symbiote/silverstripe-versionedfiles/blob/5f90cc3242491c16739dfd73e914a8748354ba59/code/VersionedImageExtension.php#L13-L91 | train |
symbiote/silverstripe-versionedfiles | code/VersionedFileExtension.php | VersionedFileExtension.onAfterWrite | public function onAfterWrite()
{
$changed = $this->owner->getChangedFields(true, 2);
if (!$this->owner instanceof Folder && !$this->owner->CurrentVersionID) {
$this->createVersion();
}
if (array_key_exists('Filename', $changed)) {
if ($changed['Filename']['before'] == null) {
return;
}
$oldDirname = '/' . trim(dirname($changed['Filename']['before']), '/');
$newDirname = '/' . trim(dirname($changed['Filename']['after']), '/');
if ($oldDirname == $newDirname) {
return;
}
// First move the _versions directory across.
$versionsDir = FileVersion::VERSION_FOLDER . '/' . $this->owner->ID;
$oldVersions = BASE_PATH . $oldDirname . '/' . $versionsDir;
$newVersions = BASE_PATH . $newDirname . '/' . $versionsDir;
if (is_dir($oldVersions)) {
if (!is_dir($newVersions)) {
mkdir($newVersions, Config::inst()->get('Filesystem', 'folder_create_mask'), true);
}
if (!is_dir($newVersions)) {
rename($oldVersions, $newVersions);
}
}
// Then update individual version records to point to the new
// location.
foreach ($this->owner->Versions() as $version) {
if (strpos($version->Filename, $oldDirname) === 0) {
$version->Filename = $newDirname . substr($version->Filename, strlen($oldDirname));
$version->write();
}
}
}
} | php | public function onAfterWrite()
{
$changed = $this->owner->getChangedFields(true, 2);
if (!$this->owner instanceof Folder && !$this->owner->CurrentVersionID) {
$this->createVersion();
}
if (array_key_exists('Filename', $changed)) {
if ($changed['Filename']['before'] == null) {
return;
}
$oldDirname = '/' . trim(dirname($changed['Filename']['before']), '/');
$newDirname = '/' . trim(dirname($changed['Filename']['after']), '/');
if ($oldDirname == $newDirname) {
return;
}
// First move the _versions directory across.
$versionsDir = FileVersion::VERSION_FOLDER . '/' . $this->owner->ID;
$oldVersions = BASE_PATH . $oldDirname . '/' . $versionsDir;
$newVersions = BASE_PATH . $newDirname . '/' . $versionsDir;
if (is_dir($oldVersions)) {
if (!is_dir($newVersions)) {
mkdir($newVersions, Config::inst()->get('Filesystem', 'folder_create_mask'), true);
}
if (!is_dir($newVersions)) {
rename($oldVersions, $newVersions);
}
}
// Then update individual version records to point to the new
// location.
foreach ($this->owner->Versions() as $version) {
if (strpos($version->Filename, $oldDirname) === 0) {
$version->Filename = $newDirname . substr($version->Filename, strlen($oldDirname));
$version->write();
}
}
}
} | [
"public",
"function",
"onAfterWrite",
"(",
")",
"{",
"$",
"changed",
"=",
"$",
"this",
"->",
"owner",
"->",
"getChangedFields",
"(",
"true",
",",
"2",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"owner",
"instanceof",
"Folder",
"&&",
"!",
"$",
"this",
"->",
"owner",
"->",
"CurrentVersionID",
")",
"{",
"$",
"this",
"->",
"createVersion",
"(",
")",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"'Filename'",
",",
"$",
"changed",
")",
")",
"{",
"if",
"(",
"$",
"changed",
"[",
"'Filename'",
"]",
"[",
"'before'",
"]",
"==",
"null",
")",
"{",
"return",
";",
"}",
"$",
"oldDirname",
"=",
"'/'",
".",
"trim",
"(",
"dirname",
"(",
"$",
"changed",
"[",
"'Filename'",
"]",
"[",
"'before'",
"]",
")",
",",
"'/'",
")",
";",
"$",
"newDirname",
"=",
"'/'",
".",
"trim",
"(",
"dirname",
"(",
"$",
"changed",
"[",
"'Filename'",
"]",
"[",
"'after'",
"]",
")",
",",
"'/'",
")",
";",
"if",
"(",
"$",
"oldDirname",
"==",
"$",
"newDirname",
")",
"{",
"return",
";",
"}",
"// First move the _versions directory across.",
"$",
"versionsDir",
"=",
"FileVersion",
"::",
"VERSION_FOLDER",
".",
"'/'",
".",
"$",
"this",
"->",
"owner",
"->",
"ID",
";",
"$",
"oldVersions",
"=",
"BASE_PATH",
".",
"$",
"oldDirname",
".",
"'/'",
".",
"$",
"versionsDir",
";",
"$",
"newVersions",
"=",
"BASE_PATH",
".",
"$",
"newDirname",
".",
"'/'",
".",
"$",
"versionsDir",
";",
"if",
"(",
"is_dir",
"(",
"$",
"oldVersions",
")",
")",
"{",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"newVersions",
")",
")",
"{",
"mkdir",
"(",
"$",
"newVersions",
",",
"Config",
"::",
"inst",
"(",
")",
"->",
"get",
"(",
"'Filesystem'",
",",
"'folder_create_mask'",
")",
",",
"true",
")",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"newVersions",
")",
")",
"{",
"rename",
"(",
"$",
"oldVersions",
",",
"$",
"newVersions",
")",
";",
"}",
"}",
"// Then update individual version records to point to the new",
"// location.",
"foreach",
"(",
"$",
"this",
"->",
"owner",
"->",
"Versions",
"(",
")",
"as",
"$",
"version",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"version",
"->",
"Filename",
",",
"$",
"oldDirname",
")",
"===",
"0",
")",
"{",
"$",
"version",
"->",
"Filename",
"=",
"$",
"newDirname",
".",
"substr",
"(",
"$",
"version",
"->",
"Filename",
",",
"strlen",
"(",
"$",
"oldDirname",
")",
")",
";",
"$",
"version",
"->",
"write",
"(",
")",
";",
"}",
"}",
"}",
"}"
]
| Creates the initial version when the file is created, as well as updating
the version records when the parent file is moved. | [
"Creates",
"the",
"initial",
"version",
"when",
"the",
"file",
"is",
"created",
"as",
"well",
"as",
"updating",
"the",
"version",
"records",
"when",
"the",
"parent",
"file",
"is",
"moved",
"."
]
| 5f90cc3242491c16739dfd73e914a8748354ba59 | https://github.com/symbiote/silverstripe-versionedfiles/blob/5f90cc3242491c16739dfd73e914a8748354ba59/code/VersionedFileExtension.php#L126-L170 | train |
symbiote/silverstripe-versionedfiles | code/VersionedFileExtension.php | VersionedFileExtension.onBeforeDelete | public function onBeforeDelete()
{
$currentVersion = $this->owner->CurrentVersion();
// make sure there actually is a current version, otherwise we're going
// to end up deleting a bunch of incorrect stuff!
if ($currentVersion && $currentVersion->ID > 0) {
$folder = dirname($this->owner->CurrentVersion()->getFullPath());
if ($versions = $this->owner->Versions()) {
foreach ($versions as $version) {
$version->delete();
}
}
if (is_dir($folder)) {
Filesystem::removeFolder($folder);
}
// If the _versions folder is now empty - because there are no other versions of any assets - then we can
// delete the _versions folder
$folder = dirname($folder); // We want the parent of $folder, as we just deleted $folder
if (is_dir($folder)) {
$dir = opendir($folder);
$foundOtherFile = false;
while ($file = readdir($dir)) {
if (($file == '.' || $file == '..')) {
continue;
}
$foundOtherFile = true;
}
if (!$foundOtherFile) {
// No other files found, so we can delete the _versions folder
rmdir($folder);
}
}
}
} | php | public function onBeforeDelete()
{
$currentVersion = $this->owner->CurrentVersion();
// make sure there actually is a current version, otherwise we're going
// to end up deleting a bunch of incorrect stuff!
if ($currentVersion && $currentVersion->ID > 0) {
$folder = dirname($this->owner->CurrentVersion()->getFullPath());
if ($versions = $this->owner->Versions()) {
foreach ($versions as $version) {
$version->delete();
}
}
if (is_dir($folder)) {
Filesystem::removeFolder($folder);
}
// If the _versions folder is now empty - because there are no other versions of any assets - then we can
// delete the _versions folder
$folder = dirname($folder); // We want the parent of $folder, as we just deleted $folder
if (is_dir($folder)) {
$dir = opendir($folder);
$foundOtherFile = false;
while ($file = readdir($dir)) {
if (($file == '.' || $file == '..')) {
continue;
}
$foundOtherFile = true;
}
if (!$foundOtherFile) {
// No other files found, so we can delete the _versions folder
rmdir($folder);
}
}
}
} | [
"public",
"function",
"onBeforeDelete",
"(",
")",
"{",
"$",
"currentVersion",
"=",
"$",
"this",
"->",
"owner",
"->",
"CurrentVersion",
"(",
")",
";",
"// make sure there actually is a current version, otherwise we're going",
"// to end up deleting a bunch of incorrect stuff!",
"if",
"(",
"$",
"currentVersion",
"&&",
"$",
"currentVersion",
"->",
"ID",
">",
"0",
")",
"{",
"$",
"folder",
"=",
"dirname",
"(",
"$",
"this",
"->",
"owner",
"->",
"CurrentVersion",
"(",
")",
"->",
"getFullPath",
"(",
")",
")",
";",
"if",
"(",
"$",
"versions",
"=",
"$",
"this",
"->",
"owner",
"->",
"Versions",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"versions",
"as",
"$",
"version",
")",
"{",
"$",
"version",
"->",
"delete",
"(",
")",
";",
"}",
"}",
"if",
"(",
"is_dir",
"(",
"$",
"folder",
")",
")",
"{",
"Filesystem",
"::",
"removeFolder",
"(",
"$",
"folder",
")",
";",
"}",
"// If the _versions folder is now empty - because there are no other versions of any assets - then we can",
"// delete the _versions folder",
"$",
"folder",
"=",
"dirname",
"(",
"$",
"folder",
")",
";",
"// We want the parent of $folder, as we just deleted $folder",
"if",
"(",
"is_dir",
"(",
"$",
"folder",
")",
")",
"{",
"$",
"dir",
"=",
"opendir",
"(",
"$",
"folder",
")",
";",
"$",
"foundOtherFile",
"=",
"false",
";",
"while",
"(",
"$",
"file",
"=",
"readdir",
"(",
"$",
"dir",
")",
")",
"{",
"if",
"(",
"(",
"$",
"file",
"==",
"'.'",
"||",
"$",
"file",
"==",
"'..'",
")",
")",
"{",
"continue",
";",
"}",
"$",
"foundOtherFile",
"=",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"foundOtherFile",
")",
"{",
"// No other files found, so we can delete the _versions folder",
"rmdir",
"(",
"$",
"folder",
")",
";",
"}",
"}",
"}",
"}"
]
| Deletes all saved version of the file as well as the file itself. | [
"Deletes",
"all",
"saved",
"version",
"of",
"the",
"file",
"as",
"well",
"as",
"the",
"file",
"itself",
"."
]
| 5f90cc3242491c16739dfd73e914a8748354ba59 | https://github.com/symbiote/silverstripe-versionedfiles/blob/5f90cc3242491c16739dfd73e914a8748354ba59/code/VersionedFileExtension.php#L187-L226 | train |
symbiote/silverstripe-versionedfiles | code/VersionedFileExtension.php | VersionedFileExtension.savePreviousVersion | public function savePreviousVersion($version)
{
if (!is_numeric($version)) {
return;
}
try {
$this->setVersionNumber($version);
$this->owner->write();
} catch (Exception $e) {
throw new ValidationException(new ValidationResult(
false,
"Could not replace file #{$this->owner->ID} with version #$version."
));
}
} | php | public function savePreviousVersion($version)
{
if (!is_numeric($version)) {
return;
}
try {
$this->setVersionNumber($version);
$this->owner->write();
} catch (Exception $e) {
throw new ValidationException(new ValidationResult(
false,
"Could not replace file #{$this->owner->ID} with version #$version."
));
}
} | [
"public",
"function",
"savePreviousVersion",
"(",
"$",
"version",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"version",
")",
")",
"{",
"return",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"setVersionNumber",
"(",
"$",
"version",
")",
";",
"$",
"this",
"->",
"owner",
"->",
"write",
"(",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"e",
")",
"{",
"throw",
"new",
"ValidationException",
"(",
"new",
"ValidationResult",
"(",
"false",
",",
"\"Could not replace file #{$this->owner->ID} with version #$version.\"",
")",
")",
";",
"}",
"}"
]
| Handles rolling back to a selected version on save.
@param int $version | [
"Handles",
"rolling",
"back",
"to",
"a",
"selected",
"version",
"on",
"save",
"."
]
| 5f90cc3242491c16739dfd73e914a8748354ba59 | https://github.com/symbiote/silverstripe-versionedfiles/blob/5f90cc3242491c16739dfd73e914a8748354ba59/code/VersionedFileExtension.php#L274-L289 | train |
symbiote/silverstripe-versionedfiles | code/VersionedFileExtension.php | VersionedFileExtension.createVersion | public function createVersion()
{
if (!file_exists($this->owner->getFullPath())) {
return false;
}
$version = new FileVersion();
$version->FileID = $this->owner->ID;
$version->write();
$this->owner->CurrentVersionID = $version->ID;
return (bool) $this->owner->write();
} | php | public function createVersion()
{
if (!file_exists($this->owner->getFullPath())) {
return false;
}
$version = new FileVersion();
$version->FileID = $this->owner->ID;
$version->write();
$this->owner->CurrentVersionID = $version->ID;
return (bool) $this->owner->write();
} | [
"public",
"function",
"createVersion",
"(",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"this",
"->",
"owner",
"->",
"getFullPath",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"version",
"=",
"new",
"FileVersion",
"(",
")",
";",
"$",
"version",
"->",
"FileID",
"=",
"$",
"this",
"->",
"owner",
"->",
"ID",
";",
"$",
"version",
"->",
"write",
"(",
")",
";",
"$",
"this",
"->",
"owner",
"->",
"CurrentVersionID",
"=",
"$",
"version",
"->",
"ID",
";",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"owner",
"->",
"write",
"(",
")",
";",
"}"
]
| Creates a new file version and sets it as the current version.
@return boolean Whether file version is created | [
"Creates",
"a",
"new",
"file",
"version",
"and",
"sets",
"it",
"as",
"the",
"current",
"version",
"."
]
| 5f90cc3242491c16739dfd73e914a8748354ba59 | https://github.com/symbiote/silverstripe-versionedfiles/blob/5f90cc3242491c16739dfd73e914a8748354ba59/code/VersionedFileExtension.php#L297-L309 | train |
keboola/syrup | src/Keboola/Syrup/Controller/PublicController.php | PublicController.indexAction | public function indexAction()
{
$rootPath = str_replace('web/../', '', ROOT_PATH);
$filepath = $rootPath . '/../../composer/installed.json';
if (!file_exists($filepath)) {
$filepath = $rootPath . '/vendor/composer/installed.json';
}
$installedJson = file_get_contents($filepath);
$jsonDecoder = new JsonDecode(true);
$installedArr = $jsonDecoder->decode($installedJson, JsonEncoder::FORMAT);
$syrupComponents = array();
foreach ($installedArr as $package) {
$nameArr = explode("/", $package['name']);
if ($nameArr[0] == 'syrup' || $nameArr[0] == 'keboola') {
$syrupComponents[$package['name']] = $package['version'];
}
}
return new JsonResponse(array(
"host" => gethostname(),
"components" => $syrupComponents,
"documentation" => "http://documentation.keboola.com/syrup"
));
} | php | public function indexAction()
{
$rootPath = str_replace('web/../', '', ROOT_PATH);
$filepath = $rootPath . '/../../composer/installed.json';
if (!file_exists($filepath)) {
$filepath = $rootPath . '/vendor/composer/installed.json';
}
$installedJson = file_get_contents($filepath);
$jsonDecoder = new JsonDecode(true);
$installedArr = $jsonDecoder->decode($installedJson, JsonEncoder::FORMAT);
$syrupComponents = array();
foreach ($installedArr as $package) {
$nameArr = explode("/", $package['name']);
if ($nameArr[0] == 'syrup' || $nameArr[0] == 'keboola') {
$syrupComponents[$package['name']] = $package['version'];
}
}
return new JsonResponse(array(
"host" => gethostname(),
"components" => $syrupComponents,
"documentation" => "http://documentation.keboola.com/syrup"
));
} | [
"public",
"function",
"indexAction",
"(",
")",
"{",
"$",
"rootPath",
"=",
"str_replace",
"(",
"'web/../'",
",",
"''",
",",
"ROOT_PATH",
")",
";",
"$",
"filepath",
"=",
"$",
"rootPath",
".",
"'/../../composer/installed.json'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"filepath",
")",
")",
"{",
"$",
"filepath",
"=",
"$",
"rootPath",
".",
"'/vendor/composer/installed.json'",
";",
"}",
"$",
"installedJson",
"=",
"file_get_contents",
"(",
"$",
"filepath",
")",
";",
"$",
"jsonDecoder",
"=",
"new",
"JsonDecode",
"(",
"true",
")",
";",
"$",
"installedArr",
"=",
"$",
"jsonDecoder",
"->",
"decode",
"(",
"$",
"installedJson",
",",
"JsonEncoder",
"::",
"FORMAT",
")",
";",
"$",
"syrupComponents",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"installedArr",
"as",
"$",
"package",
")",
"{",
"$",
"nameArr",
"=",
"explode",
"(",
"\"/\"",
",",
"$",
"package",
"[",
"'name'",
"]",
")",
";",
"if",
"(",
"$",
"nameArr",
"[",
"0",
"]",
"==",
"'syrup'",
"||",
"$",
"nameArr",
"[",
"0",
"]",
"==",
"'keboola'",
")",
"{",
"$",
"syrupComponents",
"[",
"$",
"package",
"[",
"'name'",
"]",
"]",
"=",
"$",
"package",
"[",
"'version'",
"]",
";",
"}",
"}",
"return",
"new",
"JsonResponse",
"(",
"array",
"(",
"\"host\"",
"=>",
"gethostname",
"(",
")",
",",
"\"components\"",
"=>",
"$",
"syrupComponents",
",",
"\"documentation\"",
"=>",
"\"http://documentation.keboola.com/syrup\"",
")",
")",
";",
"}"
]
| Displays Syrup components with their recent version
@return JsonResponse | [
"Displays",
"Syrup",
"components",
"with",
"their",
"recent",
"version"
]
| 83c0704dff3cd0c2e44e88076caadc010d32cd0e | https://github.com/keboola/syrup/blob/83c0704dff3cd0c2e44e88076caadc010d32cd0e/src/Keboola/Syrup/Controller/PublicController.php#L31-L60 | train |
symbiote/silverstripe-versionedfiles | code/FileVersion.php | FileVersion.onBeforeWrite | public function onBeforeWrite()
{
if (!$this->isInDB()) {
$this->CreatorID = Member::currentUserID();
}
if (!$this->VersionNumber) {
$versions = DataObject::get(
'FileVersion', sprintf('"FileID" = %d', $this->FileID)
);
if ($versions) {
$this->VersionNumber = $versions->Count() + 1;
} else {
$this->VersionNumber = 1;
}
}
if (!$this->Filename) {
$this->Filename = $this->saveCurrentVersion();
}
parent::onBeforeWrite();
} | php | public function onBeforeWrite()
{
if (!$this->isInDB()) {
$this->CreatorID = Member::currentUserID();
}
if (!$this->VersionNumber) {
$versions = DataObject::get(
'FileVersion', sprintf('"FileID" = %d', $this->FileID)
);
if ($versions) {
$this->VersionNumber = $versions->Count() + 1;
} else {
$this->VersionNumber = 1;
}
}
if (!$this->Filename) {
$this->Filename = $this->saveCurrentVersion();
}
parent::onBeforeWrite();
} | [
"public",
"function",
"onBeforeWrite",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isInDB",
"(",
")",
")",
"{",
"$",
"this",
"->",
"CreatorID",
"=",
"Member",
"::",
"currentUserID",
"(",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"VersionNumber",
")",
"{",
"$",
"versions",
"=",
"DataObject",
"::",
"get",
"(",
"'FileVersion'",
",",
"sprintf",
"(",
"'\"FileID\" = %d'",
",",
"$",
"this",
"->",
"FileID",
")",
")",
";",
"if",
"(",
"$",
"versions",
")",
"{",
"$",
"this",
"->",
"VersionNumber",
"=",
"$",
"versions",
"->",
"Count",
"(",
")",
"+",
"1",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"VersionNumber",
"=",
"1",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"Filename",
")",
"{",
"$",
"this",
"->",
"Filename",
"=",
"$",
"this",
"->",
"saveCurrentVersion",
"(",
")",
";",
"}",
"parent",
"::",
"onBeforeWrite",
"(",
")",
";",
"}"
]
| Saves version meta-data, and generates the saved file version on first
write. | [
"Saves",
"version",
"meta",
"-",
"data",
"and",
"generates",
"the",
"saved",
"file",
"version",
"on",
"first",
"write",
"."
]
| 5f90cc3242491c16739dfd73e914a8748354ba59 | https://github.com/symbiote/silverstripe-versionedfiles/blob/5f90cc3242491c16739dfd73e914a8748354ba59/code/FileVersion.php#L26-L49 | train |
symbiote/silverstripe-versionedfiles | code/FileVersion.php | FileVersion.saveCurrentVersion | protected function saveCurrentVersion()
{
// Ensure we re-fetch fresh record from database (in case it was recently renamed / moved)
$file = File::get()->byID($this->FileID);
if ($file->ParentID) {
$base = Controller::join_links(
$file->Parent()->getFullPath(),
self::VERSION_FOLDER,
$this->FileID
);
} else {
$base = Controller::join_links(
Director::baseFolder(),
ASSETS_DIR,
self::VERSION_FOLDER,
$this->FileID
);
}
Filesystem::makeFolder($base);
$extension = $file->getExtension();
$basename = basename($file->Name, $extension);
$version = $this->VersionNumber;
$cachedPath = Controller::join_links(
$base, "{$basename}$version.$extension"
);
if (!copy($file->getFullPath(), $cachedPath)) {
throw new Exception(
"Unable to copy version #$version of file #$this->FileID from:\n \"{$file->getFullPath()}\"\nto:\n\"$cachedPath\""
);
}
return Director::makeRelative($cachedPath);
} | php | protected function saveCurrentVersion()
{
// Ensure we re-fetch fresh record from database (in case it was recently renamed / moved)
$file = File::get()->byID($this->FileID);
if ($file->ParentID) {
$base = Controller::join_links(
$file->Parent()->getFullPath(),
self::VERSION_FOLDER,
$this->FileID
);
} else {
$base = Controller::join_links(
Director::baseFolder(),
ASSETS_DIR,
self::VERSION_FOLDER,
$this->FileID
);
}
Filesystem::makeFolder($base);
$extension = $file->getExtension();
$basename = basename($file->Name, $extension);
$version = $this->VersionNumber;
$cachedPath = Controller::join_links(
$base, "{$basename}$version.$extension"
);
if (!copy($file->getFullPath(), $cachedPath)) {
throw new Exception(
"Unable to copy version #$version of file #$this->FileID from:\n \"{$file->getFullPath()}\"\nto:\n\"$cachedPath\""
);
}
return Director::makeRelative($cachedPath);
} | [
"protected",
"function",
"saveCurrentVersion",
"(",
")",
"{",
"// Ensure we re-fetch fresh record from database (in case it was recently renamed / moved)",
"$",
"file",
"=",
"File",
"::",
"get",
"(",
")",
"->",
"byID",
"(",
"$",
"this",
"->",
"FileID",
")",
";",
"if",
"(",
"$",
"file",
"->",
"ParentID",
")",
"{",
"$",
"base",
"=",
"Controller",
"::",
"join_links",
"(",
"$",
"file",
"->",
"Parent",
"(",
")",
"->",
"getFullPath",
"(",
")",
",",
"self",
"::",
"VERSION_FOLDER",
",",
"$",
"this",
"->",
"FileID",
")",
";",
"}",
"else",
"{",
"$",
"base",
"=",
"Controller",
"::",
"join_links",
"(",
"Director",
"::",
"baseFolder",
"(",
")",
",",
"ASSETS_DIR",
",",
"self",
"::",
"VERSION_FOLDER",
",",
"$",
"this",
"->",
"FileID",
")",
";",
"}",
"Filesystem",
"::",
"makeFolder",
"(",
"$",
"base",
")",
";",
"$",
"extension",
"=",
"$",
"file",
"->",
"getExtension",
"(",
")",
";",
"$",
"basename",
"=",
"basename",
"(",
"$",
"file",
"->",
"Name",
",",
"$",
"extension",
")",
";",
"$",
"version",
"=",
"$",
"this",
"->",
"VersionNumber",
";",
"$",
"cachedPath",
"=",
"Controller",
"::",
"join_links",
"(",
"$",
"base",
",",
"\"{$basename}$version.$extension\"",
")",
";",
"if",
"(",
"!",
"copy",
"(",
"$",
"file",
"->",
"getFullPath",
"(",
")",
",",
"$",
"cachedPath",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"\"Unable to copy version #$version of file #$this->FileID from:\\n \\\"{$file->getFullPath()}\\\"\\nto:\\n\\\"$cachedPath\\\"\"",
")",
";",
"}",
"return",
"Director",
"::",
"makeRelative",
"(",
"$",
"cachedPath",
")",
";",
"}"
]
| Saves the current version of the linked File object in a versions
directory, then returns the relative path to where it is stored.
@return string | [
"Saves",
"the",
"current",
"version",
"of",
"the",
"linked",
"File",
"object",
"in",
"a",
"versions",
"directory",
"then",
"returns",
"the",
"relative",
"path",
"to",
"where",
"it",
"is",
"stored",
"."
]
| 5f90cc3242491c16739dfd73e914a8748354ba59 | https://github.com/symbiote/silverstripe-versionedfiles/blob/5f90cc3242491c16739dfd73e914a8748354ba59/code/FileVersion.php#L112-L148 | train |
keboola/syrup | src/Keboola/Syrup/Controller/ApiController.php | ApiController.enqueue | protected function enqueue($jobId, $queueName = 'default', $otherData = [])
{
/** @var QueueService $queue */
$queue = $this->container->get('syrup.queue_factory')->get($queueName);
return $queue->enqueue($jobId, $otherData);
} | php | protected function enqueue($jobId, $queueName = 'default', $otherData = [])
{
/** @var QueueService $queue */
$queue = $this->container->get('syrup.queue_factory')->get($queueName);
return $queue->enqueue($jobId, $otherData);
} | [
"protected",
"function",
"enqueue",
"(",
"$",
"jobId",
",",
"$",
"queueName",
"=",
"'default'",
",",
"$",
"otherData",
"=",
"[",
"]",
")",
"{",
"/** @var QueueService $queue */",
"$",
"queue",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'syrup.queue_factory'",
")",
"->",
"get",
"(",
"$",
"queueName",
")",
";",
"return",
"$",
"queue",
"->",
"enqueue",
"(",
"$",
"jobId",
",",
"$",
"otherData",
")",
";",
"}"
]
| Add JobId to queue
@param $jobId
@param string $queueName
@param array $otherData
@return int $messageId | [
"Add",
"JobId",
"to",
"queue"
]
| 83c0704dff3cd0c2e44e88076caadc010d32cd0e | https://github.com/keboola/syrup/blob/83c0704dff3cd0c2e44e88076caadc010d32cd0e/src/Keboola/Syrup/Controller/ApiController.php#L146-L151 | train |
keboola/syrup | src/Keboola/Syrup/Exception/JobException.php | JobException.setStatus | public function setStatus($status)
{
$allowedStatuses = array(
Job::STATUS_ERROR,
Job::STATUS_SUCCESS,
Job::STATUS_WARNING,
Job::STATUS_TERMINATED
);
if (!in_array($status, $allowedStatuses)) {
throw new \InvalidArgumentException(sprintf('Status "%s" is not allowed in JobException', $status));
}
$this->status = (string) $status;
return $this;
} | php | public function setStatus($status)
{
$allowedStatuses = array(
Job::STATUS_ERROR,
Job::STATUS_SUCCESS,
Job::STATUS_WARNING,
Job::STATUS_TERMINATED
);
if (!in_array($status, $allowedStatuses)) {
throw new \InvalidArgumentException(sprintf('Status "%s" is not allowed in JobException', $status));
}
$this->status = (string) $status;
return $this;
} | [
"public",
"function",
"setStatus",
"(",
"$",
"status",
")",
"{",
"$",
"allowedStatuses",
"=",
"array",
"(",
"Job",
"::",
"STATUS_ERROR",
",",
"Job",
"::",
"STATUS_SUCCESS",
",",
"Job",
"::",
"STATUS_WARNING",
",",
"Job",
"::",
"STATUS_TERMINATED",
")",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"status",
",",
"$",
"allowedStatuses",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Status \"%s\" is not allowed in JobException'",
",",
"$",
"status",
")",
")",
";",
"}",
"$",
"this",
"->",
"status",
"=",
"(",
"string",
")",
"$",
"status",
";",
"return",
"$",
"this",
";",
"}"
]
| Set job status
@param string $status
@return $this
@throws \InvalidArgumentException | [
"Set",
"job",
"status"
]
| 83c0704dff3cd0c2e44e88076caadc010d32cd0e | https://github.com/keboola/syrup/blob/83c0704dff3cd0c2e44e88076caadc010d32cd0e/src/Keboola/Syrup/Exception/JobException.php#L56-L71 | train |
ADmad/cakephp-glide | src/Middleware/GlideMiddleware.php | GlideMiddleware._checkSignature | protected function _checkSignature()
{
if (!$this->getConfig('security.secureUrls')) {
return;
}
$signKey = $this->getConfig('security.signKey') ?: Security::getSalt();
try {
SignatureFactory::create($signKey)->validateRequest(
$this->_path,
$this->_params
);
} catch (Exception $exception) {
throw new SignatureException($exception->getMessage(), null, $exception);
}
} | php | protected function _checkSignature()
{
if (!$this->getConfig('security.secureUrls')) {
return;
}
$signKey = $this->getConfig('security.signKey') ?: Security::getSalt();
try {
SignatureFactory::create($signKey)->validateRequest(
$this->_path,
$this->_params
);
} catch (Exception $exception) {
throw new SignatureException($exception->getMessage(), null, $exception);
}
} | [
"protected",
"function",
"_checkSignature",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"getConfig",
"(",
"'security.secureUrls'",
")",
")",
"{",
"return",
";",
"}",
"$",
"signKey",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'security.signKey'",
")",
"?",
":",
"Security",
"::",
"getSalt",
"(",
")",
";",
"try",
"{",
"SignatureFactory",
"::",
"create",
"(",
"$",
"signKey",
")",
"->",
"validateRequest",
"(",
"$",
"this",
"->",
"_path",
",",
"$",
"this",
"->",
"_params",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
"{",
"throw",
"new",
"SignatureException",
"(",
"$",
"exception",
"->",
"getMessage",
"(",
")",
",",
"null",
",",
"$",
"exception",
")",
";",
"}",
"}"
]
| Check signature token if secure URLs are enabled.
@throws \ADmad\Glide\Exception\SignatureException
@return void | [
"Check",
"signature",
"token",
"if",
"secure",
"URLs",
"are",
"enabled",
"."
]
| b6f421ef802b739a0ba3fd9602c727a46a55a896 | https://github.com/ADmad/cakephp-glide/blob/b6f421ef802b739a0ba3fd9602c727a46a55a896/src/Middleware/GlideMiddleware.php#L153-L168 | train |
ADmad/cakephp-glide | src/Middleware/GlideMiddleware.php | GlideMiddleware._checkModified | protected function _checkModified($request, $response, $server)
{
$modifiedTime = false;
try {
/** @var int|string|false $modifiedTime */
$modifiedTime = $server->getSource()
->getTimestamp($server->getSourcePath($this->_path));
} catch (Exception $exception) {
return $this->_handleException($request, $response, $exception);
}
if ($modifiedTime === false) {
return $modifiedTime;
}
if ($this->_isNotModified($request, $modifiedTime)) {
$response = new Response(['status' => 304]);
$response = $this->_withCustomHeaders($response);
return $response->withHeader('Last-Modified', (string)$modifiedTime);
}
return (int)$modifiedTime;
} | php | protected function _checkModified($request, $response, $server)
{
$modifiedTime = false;
try {
/** @var int|string|false $modifiedTime */
$modifiedTime = $server->getSource()
->getTimestamp($server->getSourcePath($this->_path));
} catch (Exception $exception) {
return $this->_handleException($request, $response, $exception);
}
if ($modifiedTime === false) {
return $modifiedTime;
}
if ($this->_isNotModified($request, $modifiedTime)) {
$response = new Response(['status' => 304]);
$response = $this->_withCustomHeaders($response);
return $response->withHeader('Last-Modified', (string)$modifiedTime);
}
return (int)$modifiedTime;
} | [
"protected",
"function",
"_checkModified",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"server",
")",
"{",
"$",
"modifiedTime",
"=",
"false",
";",
"try",
"{",
"/** @var int|string|false $modifiedTime */",
"$",
"modifiedTime",
"=",
"$",
"server",
"->",
"getSource",
"(",
")",
"->",
"getTimestamp",
"(",
"$",
"server",
"->",
"getSourcePath",
"(",
"$",
"this",
"->",
"_path",
")",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
"{",
"return",
"$",
"this",
"->",
"_handleException",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"exception",
")",
";",
"}",
"if",
"(",
"$",
"modifiedTime",
"===",
"false",
")",
"{",
"return",
"$",
"modifiedTime",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"_isNotModified",
"(",
"$",
"request",
",",
"$",
"modifiedTime",
")",
")",
"{",
"$",
"response",
"=",
"new",
"Response",
"(",
"[",
"'status'",
"=>",
"304",
"]",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"_withCustomHeaders",
"(",
"$",
"response",
")",
";",
"return",
"$",
"response",
"->",
"withHeader",
"(",
"'Last-Modified'",
",",
"(",
"string",
")",
"$",
"modifiedTime",
")",
";",
"}",
"return",
"(",
"int",
")",
"$",
"modifiedTime",
";",
"}"
]
| Get file's modified time.
After comparing with "If-Modified-Since" either return modified time or
response with 304 Not Modified status.
@param \Psr\Http\Message\ServerRequestInterface $request The request.
@param \Psr\Http\Message\ResponseInterface $response The response.
@param \League\Glide\Server $server Glide server.
@return \Psr\Http\Message\ResponseInterface|int|false | [
"Get",
"file",
"s",
"modified",
"time",
"."
]
| b6f421ef802b739a0ba3fd9602c727a46a55a896 | https://github.com/ADmad/cakephp-glide/blob/b6f421ef802b739a0ba3fd9602c727a46a55a896/src/Middleware/GlideMiddleware.php#L182-L206 | train |
ADmad/cakephp-glide | src/Middleware/GlideMiddleware.php | GlideMiddleware._getResponse | protected function _getResponse($request, $response, $server)
{
if ((empty($this->_params) ||
(count($this->_params) === 1 && isset($this->_params['s'])))
&& $this->getConfig('originalPassThrough')
) {
try {
$response = $this->_passThrough($request, $response, $server);
} catch (Exception $exception) {
return $this->_handleException($request, $response, $exception);
}
return $response;
}
/** @var \League\Glide\Responses\ResponseFactoryInterface|null */
$responseFactory = $server->getResponseFactory();
if ($responseFactory === null) {
$server->setResponseFactory(new PsrResponseFactory());
}
try {
$response = $server->getImageResponse($this->_path, $this->_params);
} catch (Exception $exception) {
return $this->_handleException($request, $response, $exception);
}
return $response;
} | php | protected function _getResponse($request, $response, $server)
{
if ((empty($this->_params) ||
(count($this->_params) === 1 && isset($this->_params['s'])))
&& $this->getConfig('originalPassThrough')
) {
try {
$response = $this->_passThrough($request, $response, $server);
} catch (Exception $exception) {
return $this->_handleException($request, $response, $exception);
}
return $response;
}
/** @var \League\Glide\Responses\ResponseFactoryInterface|null */
$responseFactory = $server->getResponseFactory();
if ($responseFactory === null) {
$server->setResponseFactory(new PsrResponseFactory());
}
try {
$response = $server->getImageResponse($this->_path, $this->_params);
} catch (Exception $exception) {
return $this->_handleException($request, $response, $exception);
}
return $response;
} | [
"protected",
"function",
"_getResponse",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"server",
")",
"{",
"if",
"(",
"(",
"empty",
"(",
"$",
"this",
"->",
"_params",
")",
"||",
"(",
"count",
"(",
"$",
"this",
"->",
"_params",
")",
"===",
"1",
"&&",
"isset",
"(",
"$",
"this",
"->",
"_params",
"[",
"'s'",
"]",
")",
")",
")",
"&&",
"$",
"this",
"->",
"getConfig",
"(",
"'originalPassThrough'",
")",
")",
"{",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"_passThrough",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"server",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
"{",
"return",
"$",
"this",
"->",
"_handleException",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"exception",
")",
";",
"}",
"return",
"$",
"response",
";",
"}",
"/** @var \\League\\Glide\\Responses\\ResponseFactoryInterface|null */",
"$",
"responseFactory",
"=",
"$",
"server",
"->",
"getResponseFactory",
"(",
")",
";",
"if",
"(",
"$",
"responseFactory",
"===",
"null",
")",
"{",
"$",
"server",
"->",
"setResponseFactory",
"(",
"new",
"PsrResponseFactory",
"(",
")",
")",
";",
"}",
"try",
"{",
"$",
"response",
"=",
"$",
"server",
"->",
"getImageResponse",
"(",
"$",
"this",
"->",
"_path",
",",
"$",
"this",
"->",
"_params",
")",
";",
"}",
"catch",
"(",
"Exception",
"$",
"exception",
")",
"{",
"return",
"$",
"this",
"->",
"_handleException",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"exception",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
]
| Get response instance which contains image to render.
@param \Psr\Http\Message\ServerRequestInterface $request The request.
@param \Psr\Http\Message\ResponseInterface $response The response.
@param \League\Glide\Server $server Glide server.
@return \Psr\Http\Message\ResponseInterface|null Response instance on success else null | [
"Get",
"response",
"instance",
"which",
"contains",
"image",
"to",
"render",
"."
]
| b6f421ef802b739a0ba3fd9602c727a46a55a896 | https://github.com/ADmad/cakephp-glide/blob/b6f421ef802b739a0ba3fd9602c727a46a55a896/src/Middleware/GlideMiddleware.php#L217-L245 | train |
ADmad/cakephp-glide | src/Middleware/GlideMiddleware.php | GlideMiddleware._passThrough | protected function _passThrough($request, $response, $server)
{
$source = $server->getSource();
$path = $server->getSourcePath($this->_path);
$resource = $source->readStream($path);
if ($resource === false) {
throw new ResponseException();
}
$stream = new Stream($resource);
$contentType = $source->getMimetype($path);
$contentLength = $source->getSize($path);
return (new Response())->withBody($stream)
->withHeader('Content-Type', $contentType)
->withHeader('Content-Length', $contentLength);
} | php | protected function _passThrough($request, $response, $server)
{
$source = $server->getSource();
$path = $server->getSourcePath($this->_path);
$resource = $source->readStream($path);
if ($resource === false) {
throw new ResponseException();
}
$stream = new Stream($resource);
$contentType = $source->getMimetype($path);
$contentLength = $source->getSize($path);
return (new Response())->withBody($stream)
->withHeader('Content-Type', $contentType)
->withHeader('Content-Length', $contentLength);
} | [
"protected",
"function",
"_passThrough",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"server",
")",
"{",
"$",
"source",
"=",
"$",
"server",
"->",
"getSource",
"(",
")",
";",
"$",
"path",
"=",
"$",
"server",
"->",
"getSourcePath",
"(",
"$",
"this",
"->",
"_path",
")",
";",
"$",
"resource",
"=",
"$",
"source",
"->",
"readStream",
"(",
"$",
"path",
")",
";",
"if",
"(",
"$",
"resource",
"===",
"false",
")",
"{",
"throw",
"new",
"ResponseException",
"(",
")",
";",
"}",
"$",
"stream",
"=",
"new",
"Stream",
"(",
"$",
"resource",
")",
";",
"$",
"contentType",
"=",
"$",
"source",
"->",
"getMimetype",
"(",
"$",
"path",
")",
";",
"$",
"contentLength",
"=",
"$",
"source",
"->",
"getSize",
"(",
"$",
"path",
")",
";",
"return",
"(",
"new",
"Response",
"(",
")",
")",
"->",
"withBody",
"(",
"$",
"stream",
")",
"->",
"withHeader",
"(",
"'Content-Type'",
",",
"$",
"contentType",
")",
"->",
"withHeader",
"(",
"'Content-Length'",
",",
"$",
"contentLength",
")",
";",
"}"
]
| Generate response using original image.
@param \Psr\Http\Message\ServerRequestInterface $request The request.
@param \Psr\Http\Message\ResponseInterface $response The response.
@param \League\Glide\Server $server Glide server.
@return \Psr\Http\Message\ResponseInterface Response instance | [
"Generate",
"response",
"using",
"original",
"image",
"."
]
| b6f421ef802b739a0ba3fd9602c727a46a55a896 | https://github.com/ADmad/cakephp-glide/blob/b6f421ef802b739a0ba3fd9602c727a46a55a896/src/Middleware/GlideMiddleware.php#L256-L273 | train |
ADmad/cakephp-glide | src/Middleware/GlideMiddleware.php | GlideMiddleware._isNotModified | protected function _isNotModified($request, $modifiedTime)
{
$modifiedSince = $request->getHeaderLine('If-Modified-Since');
if (!$modifiedSince) {
return false;
}
return strtotime($modifiedSince) === (int)$modifiedTime;
} | php | protected function _isNotModified($request, $modifiedTime)
{
$modifiedSince = $request->getHeaderLine('If-Modified-Since');
if (!$modifiedSince) {
return false;
}
return strtotime($modifiedSince) === (int)$modifiedTime;
} | [
"protected",
"function",
"_isNotModified",
"(",
"$",
"request",
",",
"$",
"modifiedTime",
")",
"{",
"$",
"modifiedSince",
"=",
"$",
"request",
"->",
"getHeaderLine",
"(",
"'If-Modified-Since'",
")",
";",
"if",
"(",
"!",
"$",
"modifiedSince",
")",
"{",
"return",
"false",
";",
"}",
"return",
"strtotime",
"(",
"$",
"modifiedSince",
")",
"===",
"(",
"int",
")",
"$",
"modifiedTime",
";",
"}"
]
| Compare file's modfied time with "If-Modified-Since" header.
@param \Psr\Http\Message\ServerRequestInterface $request The request to check.
@param string|int $modifiedTime Last modified time of file.
@return bool | [
"Compare",
"file",
"s",
"modfied",
"time",
"with",
"If",
"-",
"Modified",
"-",
"Since",
"header",
"."
]
| b6f421ef802b739a0ba3fd9602c727a46a55a896 | https://github.com/ADmad/cakephp-glide/blob/b6f421ef802b739a0ba3fd9602c727a46a55a896/src/Middleware/GlideMiddleware.php#L283-L291 | train |
ADmad/cakephp-glide | src/Middleware/GlideMiddleware.php | GlideMiddleware._withCacheHeaders | protected function _withCacheHeaders($response, $cacheTime, $modifiedTime)
{
$expire = strtotime($cacheTime);
$maxAge = $expire - time();
return $response
->withHeader('Cache-Control', 'public,max-age=' . $maxAge)
->withHeader('Date', gmdate('D, j M Y G:i:s \G\M\T', time()))
->withHeader('Last-Modified', gmdate('D, j M Y G:i:s \G\M\T', (int)$modifiedTime))
->withHeader('Expires', gmdate('D, j M Y G:i:s \G\M\T', $expire));
} | php | protected function _withCacheHeaders($response, $cacheTime, $modifiedTime)
{
$expire = strtotime($cacheTime);
$maxAge = $expire - time();
return $response
->withHeader('Cache-Control', 'public,max-age=' . $maxAge)
->withHeader('Date', gmdate('D, j M Y G:i:s \G\M\T', time()))
->withHeader('Last-Modified', gmdate('D, j M Y G:i:s \G\M\T', (int)$modifiedTime))
->withHeader('Expires', gmdate('D, j M Y G:i:s \G\M\T', $expire));
} | [
"protected",
"function",
"_withCacheHeaders",
"(",
"$",
"response",
",",
"$",
"cacheTime",
",",
"$",
"modifiedTime",
")",
"{",
"$",
"expire",
"=",
"strtotime",
"(",
"$",
"cacheTime",
")",
";",
"$",
"maxAge",
"=",
"$",
"expire",
"-",
"time",
"(",
")",
";",
"return",
"$",
"response",
"->",
"withHeader",
"(",
"'Cache-Control'",
",",
"'public,max-age='",
".",
"$",
"maxAge",
")",
"->",
"withHeader",
"(",
"'Date'",
",",
"gmdate",
"(",
"'D, j M Y G:i:s \\G\\M\\T'",
",",
"time",
"(",
")",
")",
")",
"->",
"withHeader",
"(",
"'Last-Modified'",
",",
"gmdate",
"(",
"'D, j M Y G:i:s \\G\\M\\T'",
",",
"(",
"int",
")",
"$",
"modifiedTime",
")",
")",
"->",
"withHeader",
"(",
"'Expires'",
",",
"gmdate",
"(",
"'D, j M Y G:i:s \\G\\M\\T'",
",",
"$",
"expire",
")",
")",
";",
"}"
]
| Return response instance with caching headers.
@param \Psr\Http\Message\ResponseInterface $response The response.
@param string $cacheTime Cache time.
@param int|string $modifiedTime Modified time.
@return \Psr\Http\Message\ResponseInterface | [
"Return",
"response",
"instance",
"with",
"caching",
"headers",
"."
]
| b6f421ef802b739a0ba3fd9602c727a46a55a896 | https://github.com/ADmad/cakephp-glide/blob/b6f421ef802b739a0ba3fd9602c727a46a55a896/src/Middleware/GlideMiddleware.php#L302-L312 | train |
ADmad/cakephp-glide | src/Middleware/GlideMiddleware.php | GlideMiddleware._withCustomHeaders | protected function _withCustomHeaders($response)
{
foreach ((array)$this->getConfig('headers') as $key => $value) {
$response = $response->withHeader($key, $value);
}
return $response;
} | php | protected function _withCustomHeaders($response)
{
foreach ((array)$this->getConfig('headers') as $key => $value) {
$response = $response->withHeader($key, $value);
}
return $response;
} | [
"protected",
"function",
"_withCustomHeaders",
"(",
"$",
"response",
")",
"{",
"foreach",
"(",
"(",
"array",
")",
"$",
"this",
"->",
"getConfig",
"(",
"'headers'",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"response",
"=",
"$",
"response",
"->",
"withHeader",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
]
| Return response instance with headers specified in config.
@param \Psr\Http\Message\ResponseInterface $response The response.
@return \Psr\Http\Message\ResponseInterface | [
"Return",
"response",
"instance",
"with",
"headers",
"specified",
"in",
"config",
"."
]
| b6f421ef802b739a0ba3fd9602c727a46a55a896 | https://github.com/ADmad/cakephp-glide/blob/b6f421ef802b739a0ba3fd9602c727a46a55a896/src/Middleware/GlideMiddleware.php#L321-L328 | train |
ADmad/cakephp-glide | src/View/Helper/GlideHelper.php | GlideHelper.url | public function url($path, array $params = [])
{
$base = true;
if (isset($params['_base'])) {
$base = $params['_base'];
unset($params['_base']);
}
$url = $this->urlBuilder()->getUrl($path, $params);
if ($base && strpos($url, 'http') !== 0) {
$url = $this->request->getAttribute('webroot') . ltrim($url, '/');
}
return $url;
} | php | public function url($path, array $params = [])
{
$base = true;
if (isset($params['_base'])) {
$base = $params['_base'];
unset($params['_base']);
}
$url = $this->urlBuilder()->getUrl($path, $params);
if ($base && strpos($url, 'http') !== 0) {
$url = $this->request->getAttribute('webroot') . ltrim($url, '/');
}
return $url;
} | [
"public",
"function",
"url",
"(",
"$",
"path",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"base",
"=",
"true",
";",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'_base'",
"]",
")",
")",
"{",
"$",
"base",
"=",
"$",
"params",
"[",
"'_base'",
"]",
";",
"unset",
"(",
"$",
"params",
"[",
"'_base'",
"]",
")",
";",
"}",
"$",
"url",
"=",
"$",
"this",
"->",
"urlBuilder",
"(",
")",
"->",
"getUrl",
"(",
"$",
"path",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"base",
"&&",
"strpos",
"(",
"$",
"url",
",",
"'http'",
")",
"!==",
"0",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"request",
"->",
"getAttribute",
"(",
"'webroot'",
")",
".",
"ltrim",
"(",
"$",
"url",
",",
"'/'",
")",
";",
"}",
"return",
"$",
"url",
";",
"}"
]
| URL with query string based on resizing params.
@param string $path Image path.
@param array $params Image manipulation parameters.
@return string Image URL.
@see http://glide.thephpleague.com/1.0/api/quick-reference/ | [
"URL",
"with",
"query",
"string",
"based",
"on",
"resizing",
"params",
"."
]
| b6f421ef802b739a0ba3fd9602c727a46a55a896 | https://github.com/ADmad/cakephp-glide/blob/b6f421ef802b739a0ba3fd9602c727a46a55a896/src/View/Helper/GlideHelper.php#L75-L88 | train |
ADmad/cakephp-glide | src/View/Helper/GlideHelper.php | GlideHelper.urlBuilder | public function urlBuilder($urlBuilder = null)
{
if ($urlBuilder !== null) {
return $this->_urlBuilder = $urlBuilder;
}
if (!isset($this->_urlBuilder)) {
$config = $this->getConfig();
$this->_urlBuilder = UrlBuilderFactory::create(
$config['baseUrl'],
$config['secureUrls'] ? ($config['signKey'] ?: Security::getSalt()) : null
);
}
return $this->_urlBuilder;
} | php | public function urlBuilder($urlBuilder = null)
{
if ($urlBuilder !== null) {
return $this->_urlBuilder = $urlBuilder;
}
if (!isset($this->_urlBuilder)) {
$config = $this->getConfig();
$this->_urlBuilder = UrlBuilderFactory::create(
$config['baseUrl'],
$config['secureUrls'] ? ($config['signKey'] ?: Security::getSalt()) : null
);
}
return $this->_urlBuilder;
} | [
"public",
"function",
"urlBuilder",
"(",
"$",
"urlBuilder",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"urlBuilder",
"!==",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_urlBuilder",
"=",
"$",
"urlBuilder",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"_urlBuilder",
")",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"$",
"this",
"->",
"_urlBuilder",
"=",
"UrlBuilderFactory",
"::",
"create",
"(",
"$",
"config",
"[",
"'baseUrl'",
"]",
",",
"$",
"config",
"[",
"'secureUrls'",
"]",
"?",
"(",
"$",
"config",
"[",
"'signKey'",
"]",
"?",
":",
"Security",
"::",
"getSalt",
"(",
")",
")",
":",
"null",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_urlBuilder",
";",
"}"
]
| Get URL builder instance.
@param \League\Glide\Urls\UrlBuilder|null $urlBuilder URL builder instance to
set or null to get instance.
@return \League\Glide\Urls\UrlBuilder URL builder instance. | [
"Get",
"URL",
"builder",
"instance",
"."
]
| b6f421ef802b739a0ba3fd9602c727a46a55a896 | https://github.com/ADmad/cakephp-glide/blob/b6f421ef802b739a0ba3fd9602c727a46a55a896/src/View/Helper/GlideHelper.php#L98-L114 | train |
josegonzalez/cakephp-environments | src/Environment.php | Environment.getInstance | public static function getInstance()
{
if (!self::$_instance) {
self::$_instance = new Environment();
Configure::write('Environment.initialized', true);
}
return self::$_instance;
} | php | public static function getInstance()
{
if (!self::$_instance) {
self::$_instance = new Environment();
Configure::write('Environment.initialized', true);
}
return self::$_instance;
} | [
"public",
"static",
"function",
"getInstance",
"(",
")",
"{",
"if",
"(",
"!",
"self",
"::",
"$",
"_instance",
")",
"{",
"self",
"::",
"$",
"_instance",
"=",
"new",
"Environment",
"(",
")",
";",
"Configure",
"::",
"write",
"(",
"'Environment.initialized'",
",",
"true",
")",
";",
"}",
"return",
"self",
"::",
"$",
"_instance",
";",
"}"
]
| Retrieves the current instance of an environment
@return Josegonzalez\Environments\Environment | [
"Retrieves",
"the",
"current",
"instance",
"of",
"an",
"environment"
]
| b17bce3e867d47e920d8a05cf2667a9ade789fbb | https://github.com/josegonzalez/cakephp-environments/blob/b17bce3e867d47e920d8a05cf2667a9ade789fbb/src/Environment.php#L49-L57 | train |
josegonzalez/cakephp-environments | src/Environment.php | Environment.configure | public static function configure($name, $params, $config = null, $callable = null)
{
$_this = Environment::getInstance();
$_this->environments[$name] = compact('name', 'params', 'config', 'callable');
} | php | public static function configure($name, $params, $config = null, $callable = null)
{
$_this = Environment::getInstance();
$_this->environments[$name] = compact('name', 'params', 'config', 'callable');
} | [
"public",
"static",
"function",
"configure",
"(",
"$",
"name",
",",
"$",
"params",
",",
"$",
"config",
"=",
"null",
",",
"$",
"callable",
"=",
"null",
")",
"{",
"$",
"_this",
"=",
"Environment",
"::",
"getInstance",
"(",
")",
";",
"$",
"_this",
"->",
"environments",
"[",
"$",
"name",
"]",
"=",
"compact",
"(",
"'name'",
",",
"'params'",
",",
"'config'",
",",
"'callable'",
")",
";",
"}"
]
| Configures a given environment with certain instructions
@param string $name Name of the environment we are checking for
@param array $params Array of keys to check
@param array $config Array of configure keys
@param callable $callable A callable to invoke when an environment matches
@return bool | [
"Configures",
"a",
"given",
"environment",
"with",
"certain",
"instructions"
]
| b17bce3e867d47e920d8a05cf2667a9ade789fbb | https://github.com/josegonzalez/cakephp-environments/blob/b17bce3e867d47e920d8a05cf2667a9ade789fbb/src/Environment.php#L68-L72 | train |
josegonzalez/cakephp-environments | src/Environment.php | Environment.is | public static function is($environment = null)
{
$current = Configure::read('Environment.name');
if (! $environment) {
return $current;
}
return $current === $environment;
} | php | public static function is($environment = null)
{
$current = Configure::read('Environment.name');
if (! $environment) {
return $current;
}
return $current === $environment;
} | [
"public",
"static",
"function",
"is",
"(",
"$",
"environment",
"=",
"null",
")",
"{",
"$",
"current",
"=",
"Configure",
"::",
"read",
"(",
"'Environment.name'",
")",
";",
"if",
"(",
"!",
"$",
"environment",
")",
"{",
"return",
"$",
"current",
";",
"}",
"return",
"$",
"current",
"===",
"$",
"environment",
";",
"}"
]
| Checks if the current environment matches the passed environment
@param string $environment Name of the environment we are checking for
@return bool | [
"Checks",
"if",
"the",
"current",
"environment",
"matches",
"the",
"passed",
"environment"
]
| b17bce3e867d47e920d8a05cf2667a9ade789fbb | https://github.com/josegonzalez/cakephp-environments/blob/b17bce3e867d47e920d8a05cf2667a9ade789fbb/src/Environment.php#L93-L102 | train |
josegonzalez/cakephp-environments | src/Environment.php | Environment.setup | public function setup($environment = null, $default = 'development')
{
if (Configure::read('Environment.setup')) {
return false;
}
$current = $this->currentEnvironment($environment, $default);
if (!isset($this->environments[$current])) {
throw new Exception(sprintf('Environment %s does not exist.', $current));
}
$config = array_merge(
$this->environments[$current]['config'],
['Environment.name' => $current]
);
foreach ($config as $param => $value) {
Configure::write($param, $value);
}
if (is_callable($this->environments[$current]['callable'])) {
$this->environments[$current]['callable']();
}
Configure::write('Environment.setup', true);
return true;
} | php | public function setup($environment = null, $default = 'development')
{
if (Configure::read('Environment.setup')) {
return false;
}
$current = $this->currentEnvironment($environment, $default);
if (!isset($this->environments[$current])) {
throw new Exception(sprintf('Environment %s does not exist.', $current));
}
$config = array_merge(
$this->environments[$current]['config'],
['Environment.name' => $current]
);
foreach ($config as $param => $value) {
Configure::write($param, $value);
}
if (is_callable($this->environments[$current]['callable'])) {
$this->environments[$current]['callable']();
}
Configure::write('Environment.setup', true);
return true;
} | [
"public",
"function",
"setup",
"(",
"$",
"environment",
"=",
"null",
",",
"$",
"default",
"=",
"'development'",
")",
"{",
"if",
"(",
"Configure",
"::",
"read",
"(",
"'Environment.setup'",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"current",
"=",
"$",
"this",
"->",
"currentEnvironment",
"(",
"$",
"environment",
",",
"$",
"default",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"environments",
"[",
"$",
"current",
"]",
")",
")",
"{",
"throw",
"new",
"Exception",
"(",
"sprintf",
"(",
"'Environment %s does not exist.'",
",",
"$",
"current",
")",
")",
";",
"}",
"$",
"config",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"environments",
"[",
"$",
"current",
"]",
"[",
"'config'",
"]",
",",
"[",
"'Environment.name'",
"=>",
"$",
"current",
"]",
")",
";",
"foreach",
"(",
"$",
"config",
"as",
"$",
"param",
"=>",
"$",
"value",
")",
"{",
"Configure",
"::",
"write",
"(",
"$",
"param",
",",
"$",
"value",
")",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"this",
"->",
"environments",
"[",
"$",
"current",
"]",
"[",
"'callable'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"environments",
"[",
"$",
"current",
"]",
"[",
"'callable'",
"]",
"(",
")",
";",
"}",
"Configure",
"::",
"write",
"(",
"'Environment.setup'",
",",
"true",
")",
";",
"return",
"true",
";",
"}"
]
| Configures the current environment
@param string $environment Name of the environment we want to force setup for
@param string $default Default environment name
@return bool
@throws Cake\Core\Exception\Exception | [
"Configures",
"the",
"current",
"environment"
]
| b17bce3e867d47e920d8a05cf2667a9ade789fbb | https://github.com/josegonzalez/cakephp-environments/blob/b17bce3e867d47e920d8a05cf2667a9ade789fbb/src/Environment.php#L112-L139 | train |
josegonzalez/cakephp-environments | src/Environment.php | Environment.currentEnvironment | protected function currentEnvironment($environment = null, $default = 'development')
{
$current = ($environment === null) ? $default : $environment;
if (empty($environment)) {
foreach ($this->environments as $name => $config) {
if ($this->_match($name, $config['params'])) {
$current = $name;
break;
}
}
}
return $current;
} | php | protected function currentEnvironment($environment = null, $default = 'development')
{
$current = ($environment === null) ? $default : $environment;
if (empty($environment)) {
foreach ($this->environments as $name => $config) {
if ($this->_match($name, $config['params'])) {
$current = $name;
break;
}
}
}
return $current;
} | [
"protected",
"function",
"currentEnvironment",
"(",
"$",
"environment",
"=",
"null",
",",
"$",
"default",
"=",
"'development'",
")",
"{",
"$",
"current",
"=",
"(",
"$",
"environment",
"===",
"null",
")",
"?",
"$",
"default",
":",
"$",
"environment",
";",
"if",
"(",
"empty",
"(",
"$",
"environment",
")",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"environments",
"as",
"$",
"name",
"=>",
"$",
"config",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"_match",
"(",
"$",
"name",
",",
"$",
"config",
"[",
"'params'",
"]",
")",
")",
"{",
"$",
"current",
"=",
"$",
"name",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"current",
";",
"}"
]
| Gets the current environment
@param string $environment Name of the environment we want to force setup for
@param string $default Default environment name
@return string | [
"Gets",
"the",
"current",
"environment"
]
| b17bce3e867d47e920d8a05cf2667a9ade789fbb | https://github.com/josegonzalez/cakephp-environments/blob/b17bce3e867d47e920d8a05cf2667a9ade789fbb/src/Environment.php#L148-L161 | train |
josegonzalez/cakephp-environments | src/Environment.php | Environment._match | protected function _match($environment, $params)
{
$cakeEnv = env('CAKE_ENV');
if (!empty($cakeEnv)) {
return env('CAKE_ENV') == $environment;
}
if (is_bool($params)) {
return $params;
}
if (is_callable($params) || (is_string($params) && function_exists($params))) {
return $params();
}
foreach ($params as $param => $value) {
if (function_exists($param)) {
$match = call_user_func($param, $value);
} elseif (is_array($value)) {
$match = in_array(env($param), $value);
} else {
$match = (env($param) === $value);
}
if (!$match) {
return false;
}
}
return true;
} | php | protected function _match($environment, $params)
{
$cakeEnv = env('CAKE_ENV');
if (!empty($cakeEnv)) {
return env('CAKE_ENV') == $environment;
}
if (is_bool($params)) {
return $params;
}
if (is_callable($params) || (is_string($params) && function_exists($params))) {
return $params();
}
foreach ($params as $param => $value) {
if (function_exists($param)) {
$match = call_user_func($param, $value);
} elseif (is_array($value)) {
$match = in_array(env($param), $value);
} else {
$match = (env($param) === $value);
}
if (!$match) {
return false;
}
}
return true;
} | [
"protected",
"function",
"_match",
"(",
"$",
"environment",
",",
"$",
"params",
")",
"{",
"$",
"cakeEnv",
"=",
"env",
"(",
"'CAKE_ENV'",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"cakeEnv",
")",
")",
"{",
"return",
"env",
"(",
"'CAKE_ENV'",
")",
"==",
"$",
"environment",
";",
"}",
"if",
"(",
"is_bool",
"(",
"$",
"params",
")",
")",
"{",
"return",
"$",
"params",
";",
"}",
"if",
"(",
"is_callable",
"(",
"$",
"params",
")",
"||",
"(",
"is_string",
"(",
"$",
"params",
")",
"&&",
"function_exists",
"(",
"$",
"params",
")",
")",
")",
"{",
"return",
"$",
"params",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"function_exists",
"(",
"$",
"param",
")",
")",
"{",
"$",
"match",
"=",
"call_user_func",
"(",
"$",
"param",
",",
"$",
"value",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"match",
"=",
"in_array",
"(",
"env",
"(",
"$",
"param",
")",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"match",
"=",
"(",
"env",
"(",
"$",
"param",
")",
"===",
"$",
"value",
")",
";",
"}",
"if",
"(",
"!",
"$",
"match",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
]
| Matches the current setup to a given environment
@param string $environment Name of the environment
@param array $params Array of keys to check
@return bool | [
"Matches",
"the",
"current",
"setup",
"to",
"a",
"given",
"environment"
]
| b17bce3e867d47e920d8a05cf2667a9ade789fbb | https://github.com/josegonzalez/cakephp-environments/blob/b17bce3e867d47e920d8a05cf2667a9ade789fbb/src/Environment.php#L170-L199 | train |
ikkez/f3-pagination | lib/pagination.php | Pagination.setLimit | public function setLimit($limit) {
if(is_numeric($limit))
$this->items_per_page = $limit;
$this->setCurrent( self::findCurrentPage($this->routeKey));
} | php | public function setLimit($limit) {
if(is_numeric($limit))
$this->items_per_page = $limit;
$this->setCurrent( self::findCurrentPage($this->routeKey));
} | [
"public",
"function",
"setLimit",
"(",
"$",
"limit",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"limit",
")",
")",
"$",
"this",
"->",
"items_per_page",
"=",
"$",
"limit",
";",
"$",
"this",
"->",
"setCurrent",
"(",
"self",
"::",
"findCurrentPage",
"(",
"$",
"this",
"->",
"routeKey",
")",
")",
";",
"}"
]
| set maximum items shown on one page
@param $limit int | [
"set",
"maximum",
"items",
"shown",
"on",
"one",
"page"
]
| 099cd47a7b52c827e3d8f33aed977beee4565565 | https://github.com/ikkez/f3-pagination/blob/099cd47a7b52c827e3d8f33aed977beee4565565/lib/pagination.php#L49-L53 | train |
ikkez/f3-pagination | lib/pagination.php | Pagination.setCurrent | public function setCurrent($current) {
if(!$this->routeKeyPrefix)
$current = str_replace($this->routeKeyPrefix,'',$current);
if(!is_numeric($current)) return;
if($current <= $this->getMax()) $this->current_page = $current;
else $this->current_page = $this->getMax();
} | php | public function setCurrent($current) {
if(!$this->routeKeyPrefix)
$current = str_replace($this->routeKeyPrefix,'',$current);
if(!is_numeric($current)) return;
if($current <= $this->getMax()) $this->current_page = $current;
else $this->current_page = $this->getMax();
} | [
"public",
"function",
"setCurrent",
"(",
"$",
"current",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"routeKeyPrefix",
")",
"$",
"current",
"=",
"str_replace",
"(",
"$",
"this",
"->",
"routeKeyPrefix",
",",
"''",
",",
"$",
"current",
")",
";",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"current",
")",
")",
"return",
";",
"if",
"(",
"$",
"current",
"<=",
"$",
"this",
"->",
"getMax",
"(",
")",
")",
"$",
"this",
"->",
"current_page",
"=",
"$",
"current",
";",
"else",
"$",
"this",
"->",
"current_page",
"=",
"$",
"this",
"->",
"getMax",
"(",
")",
";",
"}"
]
| set the current page number
@param $current int | [
"set",
"the",
"current",
"page",
"number"
]
| 099cd47a7b52c827e3d8f33aed977beee4565565 | https://github.com/ikkez/f3-pagination/blob/099cd47a7b52c827e3d8f33aed977beee4565565/lib/pagination.php#L91-L97 | train |
ikkez/f3-pagination | lib/pagination.php | Pagination.setLinkPath | public function setLinkPath($linkPath) {
$this->linkPath = (substr($linkPath,0,1) != '/') ? '/'.$linkPath:$linkPath;
if(substr($this->linkPath,-1) != '/') $this->linkPath .= '/';
} | php | public function setLinkPath($linkPath) {
$this->linkPath = (substr($linkPath,0,1) != '/') ? '/'.$linkPath:$linkPath;
if(substr($this->linkPath,-1) != '/') $this->linkPath .= '/';
} | [
"public",
"function",
"setLinkPath",
"(",
"$",
"linkPath",
")",
"{",
"$",
"this",
"->",
"linkPath",
"=",
"(",
"substr",
"(",
"$",
"linkPath",
",",
"0",
",",
"1",
")",
"!=",
"'/'",
")",
"?",
"'/'",
".",
"$",
"linkPath",
":",
"$",
"linkPath",
";",
"if",
"(",
"substr",
"(",
"$",
"this",
"->",
"linkPath",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"$",
"this",
"->",
"linkPath",
".=",
"'/'",
";",
"}"
]
| set path to current routing for link building
@param $linkPath | [
"set",
"path",
"to",
"current",
"routing",
"for",
"link",
"building"
]
| 099cd47a7b52c827e3d8f33aed977beee4565565 | https://github.com/ikkez/f3-pagination/blob/099cd47a7b52c827e3d8f33aed977beee4565565/lib/pagination.php#L103-L106 | train |
ikkez/f3-pagination | lib/pagination.php | Pagination.findCurrentPage | static public function findCurrentPage($key='page') {
$f3 = \Base::instance();
return $f3->exists('PARAMS.'.$key) ?
preg_replace("/[^0-9]/", "", $f3->get('PARAMS.'.$key)) : 1;
} | php | static public function findCurrentPage($key='page') {
$f3 = \Base::instance();
return $f3->exists('PARAMS.'.$key) ?
preg_replace("/[^0-9]/", "", $f3->get('PARAMS.'.$key)) : 1;
} | [
"static",
"public",
"function",
"findCurrentPage",
"(",
"$",
"key",
"=",
"'page'",
")",
"{",
"$",
"f3",
"=",
"\\",
"Base",
"::",
"instance",
"(",
")",
";",
"return",
"$",
"f3",
"->",
"exists",
"(",
"'PARAMS.'",
".",
"$",
"key",
")",
"?",
"preg_replace",
"(",
"\"/[^0-9]/\"",
",",
"\"\"",
",",
"$",
"f3",
"->",
"get",
"(",
"'PARAMS.'",
".",
"$",
"key",
")",
")",
":",
"1",
";",
"}"
]
| extract the current page number from the route parameter token
@param string $key
@return int|mixed | [
"extract",
"the",
"current",
"page",
"number",
"from",
"the",
"route",
"parameter",
"token"
]
| 099cd47a7b52c827e3d8f33aed977beee4565565 | https://github.com/ikkez/f3-pagination/blob/099cd47a7b52c827e3d8f33aed977beee4565565/lib/pagination.php#L113-L117 | train |
ikkez/f3-pagination | lib/pagination.php | Pagination.getLast | public function getLast() {
return ($this->current_page < $this->getMax() - $this->range ) ? $this->getMax() : false;
} | php | public function getLast() {
return ($this->current_page < $this->getMax() - $this->range ) ? $this->getMax() : false;
} | [
"public",
"function",
"getLast",
"(",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"current_page",
"<",
"$",
"this",
"->",
"getMax",
"(",
")",
"-",
"$",
"this",
"->",
"range",
")",
"?",
"$",
"this",
"->",
"getMax",
"(",
")",
":",
"false",
";",
"}"
]
| return last page number, if current page is not in range
@return bool|int | [
"return",
"last",
"page",
"number",
"if",
"current",
"page",
"is",
"not",
"in",
"range"
]
| 099cd47a7b52c827e3d8f33aed977beee4565565 | https://github.com/ikkez/f3-pagination/blob/099cd47a7b52c827e3d8f33aed977beee4565565/lib/pagination.php#L168-L170 | train |
ikkez/f3-pagination | lib/pagination.php | Pagination.getInRange | public function getInRange($range = null) {
if(is_null($range))
$range = $this->range;
$current_range = array( ($this->current_page-$range < 1 ? 1 : $this->current_page-$range),
($this->current_page+$range > $this->getMax() ? $this->getMax() : $this->current_page+$range));
$rangeIDs = array();
for($x = $current_range[0]; $x <= $current_range[1]; ++$x) {
$rangeIDs[] = $x;
}
return $rangeIDs;
} | php | public function getInRange($range = null) {
if(is_null($range))
$range = $this->range;
$current_range = array( ($this->current_page-$range < 1 ? 1 : $this->current_page-$range),
($this->current_page+$range > $this->getMax() ? $this->getMax() : $this->current_page+$range));
$rangeIDs = array();
for($x = $current_range[0]; $x <= $current_range[1]; ++$x) {
$rangeIDs[] = $x;
}
return $rangeIDs;
} | [
"public",
"function",
"getInRange",
"(",
"$",
"range",
"=",
"null",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"range",
")",
")",
"$",
"range",
"=",
"$",
"this",
"->",
"range",
";",
"$",
"current_range",
"=",
"array",
"(",
"(",
"$",
"this",
"->",
"current_page",
"-",
"$",
"range",
"<",
"1",
"?",
"1",
":",
"$",
"this",
"->",
"current_page",
"-",
"$",
"range",
")",
",",
"(",
"$",
"this",
"->",
"current_page",
"+",
"$",
"range",
">",
"$",
"this",
"->",
"getMax",
"(",
")",
"?",
"$",
"this",
"->",
"getMax",
"(",
")",
":",
"$",
"this",
"->",
"current_page",
"+",
"$",
"range",
")",
")",
";",
"$",
"rangeIDs",
"=",
"array",
"(",
")",
";",
"for",
"(",
"$",
"x",
"=",
"$",
"current_range",
"[",
"0",
"]",
";",
"$",
"x",
"<=",
"$",
"current_range",
"[",
"1",
"]",
";",
"++",
"$",
"x",
")",
"{",
"$",
"rangeIDs",
"[",
"]",
"=",
"$",
"x",
";",
"}",
"return",
"$",
"rangeIDs",
";",
"}"
]
| return all page numbers within the given range
@param $range int
@return array page numbers in range | [
"return",
"all",
"page",
"numbers",
"within",
"the",
"given",
"range"
]
| 099cd47a7b52c827e3d8f33aed977beee4565565 | https://github.com/ikkez/f3-pagination/blob/099cd47a7b52c827e3d8f33aed977beee4565565/lib/pagination.php#L185-L195 | train |
ikkez/f3-pagination | lib/pagination.php | Pagination.serve | public function serve() {
if(is_null($this->linkPath)) {
$route = $this->fw->get('PARAMS.0');
if($this->fw->exists('PARAMS.'.$this->routeKey))
$route = preg_replace('/'.preg_quote($this->routeKeyPrefix.
$this->fw->get('PARAMS.'.$this->routeKey)).'$/','',$route);
elseif(substr($route,-1) != '/')
$route.= '/';
} else
$route = $this->linkPath;
$this->fw->set('pg.route',$route);
$this->fw->set('pg.prefix',$this->routeKeyPrefix);
$this->fw->set('pg.currentPage',$this->current_page);
$this->fw->set('pg.nextPage',$this->getNext());
$this->fw->set('pg.prevPage',$this->getPrev());
$this->fw->set('pg.firstPage',$this->getFirst());
$this->fw->set('pg.lastPage',$this->getLast());
$this->fw->set('pg.rangePages',$this->getInRange());
$this->fw->set('pg.allPages',$this->getMax());
$output = \Template::instance()->render($this->template);
$this->fw->clear('pg');
return $output;
} | php | public function serve() {
if(is_null($this->linkPath)) {
$route = $this->fw->get('PARAMS.0');
if($this->fw->exists('PARAMS.'.$this->routeKey))
$route = preg_replace('/'.preg_quote($this->routeKeyPrefix.
$this->fw->get('PARAMS.'.$this->routeKey)).'$/','',$route);
elseif(substr($route,-1) != '/')
$route.= '/';
} else
$route = $this->linkPath;
$this->fw->set('pg.route',$route);
$this->fw->set('pg.prefix',$this->routeKeyPrefix);
$this->fw->set('pg.currentPage',$this->current_page);
$this->fw->set('pg.nextPage',$this->getNext());
$this->fw->set('pg.prevPage',$this->getPrev());
$this->fw->set('pg.firstPage',$this->getFirst());
$this->fw->set('pg.lastPage',$this->getLast());
$this->fw->set('pg.rangePages',$this->getInRange());
$this->fw->set('pg.allPages',$this->getMax());
$output = \Template::instance()->render($this->template);
$this->fw->clear('pg');
return $output;
} | [
"public",
"function",
"serve",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"linkPath",
")",
")",
"{",
"$",
"route",
"=",
"$",
"this",
"->",
"fw",
"->",
"get",
"(",
"'PARAMS.0'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"fw",
"->",
"exists",
"(",
"'PARAMS.'",
".",
"$",
"this",
"->",
"routeKey",
")",
")",
"$",
"route",
"=",
"preg_replace",
"(",
"'/'",
".",
"preg_quote",
"(",
"$",
"this",
"->",
"routeKeyPrefix",
".",
"$",
"this",
"->",
"fw",
"->",
"get",
"(",
"'PARAMS.'",
".",
"$",
"this",
"->",
"routeKey",
")",
")",
".",
"'$/'",
",",
"''",
",",
"$",
"route",
")",
";",
"elseif",
"(",
"substr",
"(",
"$",
"route",
",",
"-",
"1",
")",
"!=",
"'/'",
")",
"$",
"route",
".=",
"'/'",
";",
"}",
"else",
"$",
"route",
"=",
"$",
"this",
"->",
"linkPath",
";",
"$",
"this",
"->",
"fw",
"->",
"set",
"(",
"'pg.route'",
",",
"$",
"route",
")",
";",
"$",
"this",
"->",
"fw",
"->",
"set",
"(",
"'pg.prefix'",
",",
"$",
"this",
"->",
"routeKeyPrefix",
")",
";",
"$",
"this",
"->",
"fw",
"->",
"set",
"(",
"'pg.currentPage'",
",",
"$",
"this",
"->",
"current_page",
")",
";",
"$",
"this",
"->",
"fw",
"->",
"set",
"(",
"'pg.nextPage'",
",",
"$",
"this",
"->",
"getNext",
"(",
")",
")",
";",
"$",
"this",
"->",
"fw",
"->",
"set",
"(",
"'pg.prevPage'",
",",
"$",
"this",
"->",
"getPrev",
"(",
")",
")",
";",
"$",
"this",
"->",
"fw",
"->",
"set",
"(",
"'pg.firstPage'",
",",
"$",
"this",
"->",
"getFirst",
"(",
")",
")",
";",
"$",
"this",
"->",
"fw",
"->",
"set",
"(",
"'pg.lastPage'",
",",
"$",
"this",
"->",
"getLast",
"(",
")",
")",
";",
"$",
"this",
"->",
"fw",
"->",
"set",
"(",
"'pg.rangePages'",
",",
"$",
"this",
"->",
"getInRange",
"(",
")",
")",
";",
"$",
"this",
"->",
"fw",
"->",
"set",
"(",
"'pg.allPages'",
",",
"$",
"this",
"->",
"getMax",
"(",
")",
")",
";",
"$",
"output",
"=",
"\\",
"Template",
"::",
"instance",
"(",
")",
"->",
"render",
"(",
"$",
"this",
"->",
"template",
")",
";",
"$",
"this",
"->",
"fw",
"->",
"clear",
"(",
"'pg'",
")",
";",
"return",
"$",
"output",
";",
"}"
]
| generates the pagination output
@return string | [
"generates",
"the",
"pagination",
"output"
]
| 099cd47a7b52c827e3d8f33aed977beee4565565 | https://github.com/ikkez/f3-pagination/blob/099cd47a7b52c827e3d8f33aed977beee4565565/lib/pagination.php#L209-L231 | train |
ikkez/f3-pagination | lib/pagination.php | Pagination.renderTag | static public function renderTag($args){
$attr = $args['@attrib'];
$tmp = Template::instance();
foreach($attr as &$att)
$att = $tmp->token($att);
$pn_code = '$pn = new Pagination('.$attr['items'].');';
if(array_key_exists('limit',$attr))
$pn_code .= '$pn->setLimit('.$attr['limit'].');';
if(array_key_exists('range',$attr))
$pn_code .= '$pn->setRange('.$attr['range'].');';
if(array_key_exists('src',$attr))
$pn_code .= '$pn->setTemplate("'.$attr['src'].'");';
if(array_key_exists('token',$attr))
$pn_code .= '$pn->setRouteKey("'.$attr['token'].'");';
if(array_key_exists('link-path',$attr))
$pn_code .= '$pn->setLinkPath("'.$attr['link-path'].'");';
if(array_key_exists('token-prefix',$attr))
$pn_code .= '$pn->setRouteKeyPrefix("'.$attr['token-prefix'].'");';
$pn_code .= 'echo $pn->serve();';
return '<?php '.$pn_code.' ?>';
} | php | static public function renderTag($args){
$attr = $args['@attrib'];
$tmp = Template::instance();
foreach($attr as &$att)
$att = $tmp->token($att);
$pn_code = '$pn = new Pagination('.$attr['items'].');';
if(array_key_exists('limit',$attr))
$pn_code .= '$pn->setLimit('.$attr['limit'].');';
if(array_key_exists('range',$attr))
$pn_code .= '$pn->setRange('.$attr['range'].');';
if(array_key_exists('src',$attr))
$pn_code .= '$pn->setTemplate("'.$attr['src'].'");';
if(array_key_exists('token',$attr))
$pn_code .= '$pn->setRouteKey("'.$attr['token'].'");';
if(array_key_exists('link-path',$attr))
$pn_code .= '$pn->setLinkPath("'.$attr['link-path'].'");';
if(array_key_exists('token-prefix',$attr))
$pn_code .= '$pn->setRouteKeyPrefix("'.$attr['token-prefix'].'");';
$pn_code .= 'echo $pn->serve();';
return '<?php '.$pn_code.' ?>';
} | [
"static",
"public",
"function",
"renderTag",
"(",
"$",
"args",
")",
"{",
"$",
"attr",
"=",
"$",
"args",
"[",
"'@attrib'",
"]",
";",
"$",
"tmp",
"=",
"Template",
"::",
"instance",
"(",
")",
";",
"foreach",
"(",
"$",
"attr",
"as",
"&",
"$",
"att",
")",
"$",
"att",
"=",
"$",
"tmp",
"->",
"token",
"(",
"$",
"att",
")",
";",
"$",
"pn_code",
"=",
"'$pn = new Pagination('",
".",
"$",
"attr",
"[",
"'items'",
"]",
".",
"');'",
";",
"if",
"(",
"array_key_exists",
"(",
"'limit'",
",",
"$",
"attr",
")",
")",
"$",
"pn_code",
".=",
"'$pn->setLimit('",
".",
"$",
"attr",
"[",
"'limit'",
"]",
".",
"');'",
";",
"if",
"(",
"array_key_exists",
"(",
"'range'",
",",
"$",
"attr",
")",
")",
"$",
"pn_code",
".=",
"'$pn->setRange('",
".",
"$",
"attr",
"[",
"'range'",
"]",
".",
"');'",
";",
"if",
"(",
"array_key_exists",
"(",
"'src'",
",",
"$",
"attr",
")",
")",
"$",
"pn_code",
".=",
"'$pn->setTemplate(\"'",
".",
"$",
"attr",
"[",
"'src'",
"]",
".",
"'\");'",
";",
"if",
"(",
"array_key_exists",
"(",
"'token'",
",",
"$",
"attr",
")",
")",
"$",
"pn_code",
".=",
"'$pn->setRouteKey(\"'",
".",
"$",
"attr",
"[",
"'token'",
"]",
".",
"'\");'",
";",
"if",
"(",
"array_key_exists",
"(",
"'link-path'",
",",
"$",
"attr",
")",
")",
"$",
"pn_code",
".=",
"'$pn->setLinkPath(\"'",
".",
"$",
"attr",
"[",
"'link-path'",
"]",
".",
"'\");'",
";",
"if",
"(",
"array_key_exists",
"(",
"'token-prefix'",
",",
"$",
"attr",
")",
")",
"$",
"pn_code",
".=",
"'$pn->setRouteKeyPrefix(\"'",
".",
"$",
"attr",
"[",
"'token-prefix'",
"]",
".",
"'\");'",
";",
"$",
"pn_code",
".=",
"'echo $pn->serve();'",
";",
"return",
"'<?php '",
".",
"$",
"pn_code",
".",
"' ?>'",
";",
"}"
]
| magic render function for custom tags
@static
@param $args
@return string | [
"magic",
"render",
"function",
"for",
"custom",
"tags"
]
| 099cd47a7b52c827e3d8f33aed977beee4565565 | https://github.com/ikkez/f3-pagination/blob/099cd47a7b52c827e3d8f33aed977beee4565565/lib/pagination.php#L239-L259 | train |
PsychicCat/monero-php | src/Wallet.php | Wallet._request | public function _request($body)
{
if(isset($body['params'])){
$response = $this->client->send($this->client->request(0, $body['method'], $body['params']));
} else {
$response = $this->client->send($this->client->request(0, $body['method']));
}
$response = json_decode($response->getBody());
// if there is an error, return the error message otherwise respond with result
if(property_exists($response, 'error')){
return json_encode($response->error);
} else {
return json_encode($response->result);
}
} | php | public function _request($body)
{
if(isset($body['params'])){
$response = $this->client->send($this->client->request(0, $body['method'], $body['params']));
} else {
$response = $this->client->send($this->client->request(0, $body['method']));
}
$response = json_decode($response->getBody());
// if there is an error, return the error message otherwise respond with result
if(property_exists($response, 'error')){
return json_encode($response->error);
} else {
return json_encode($response->result);
}
} | [
"public",
"function",
"_request",
"(",
"$",
"body",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"body",
"[",
"'params'",
"]",
")",
")",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"send",
"(",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"0",
",",
"$",
"body",
"[",
"'method'",
"]",
",",
"$",
"body",
"[",
"'params'",
"]",
")",
")",
";",
"}",
"else",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"send",
"(",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"0",
",",
"$",
"body",
"[",
"'method'",
"]",
")",
")",
";",
"}",
"$",
"response",
"=",
"json_decode",
"(",
"$",
"response",
"->",
"getBody",
"(",
")",
")",
";",
"// if there is an error, return the error message otherwise respond with result",
"if",
"(",
"property_exists",
"(",
"$",
"response",
",",
"'error'",
")",
")",
"{",
"return",
"json_encode",
"(",
"$",
"response",
"->",
"error",
")",
";",
"}",
"else",
"{",
"return",
"json_encode",
"(",
"$",
"response",
"->",
"result",
")",
";",
"}",
"}"
]
| Helper function for creating wallet requests
@param array $body
@return string | [
"Helper",
"function",
"for",
"creating",
"wallet",
"requests"
]
| 41c9cb55e816f2a118ef4fc25bc9848d082d50e4 | https://github.com/PsychicCat/monero-php/blob/41c9cb55e816f2a118ef4fc25bc9848d082d50e4/src/Wallet.php#L25-L39 | train |
PsychicCat/monero-php | src/Wallet.php | Wallet._buildTransfer | public function _buildTransfer($options)
{
$destinations = $options['destinations'];
// Convert Monero amount to atomic units
if(gettype($destinations) == "object"){
$destinations->amount = $destinations->amount * 1e12;
$destinations = array($destinations);
} else {
foreach ($destinations as &$destination){
$destination->amount = $destination->amount * 1e12;
}
}
// Define Mixin
$mixin = (isset($options['mixin']) ? $options['mixin'] : 4);
// Define Unlock Time
$unlock_time = (isset($options['unlock_time']) ? $options['unlock_time'] : 0);
// Define Payment ID
$payment_id = (isset($options['payment_id']) ? $options['payment_id'] : null);
// Build params array
$params = [
'destinations' => $destinations,
'mixin' => $mixin,
'unlock_time' => $unlock_time,
'payment_id' => $payment_id
];
// Set algorithm type if using transfer_split method
if($options['method'] == "transfer_split"){
$new_algorithm = (isset($options['new_algorithm']) ? $options['new_algorithm'] : false);
$params['new_algorithm'] = $new_algorithm;
}
// Build request body
$body = [
'method' => $options['method'],
'params' => $params
];
return $body;
} | php | public function _buildTransfer($options)
{
$destinations = $options['destinations'];
// Convert Monero amount to atomic units
if(gettype($destinations) == "object"){
$destinations->amount = $destinations->amount * 1e12;
$destinations = array($destinations);
} else {
foreach ($destinations as &$destination){
$destination->amount = $destination->amount * 1e12;
}
}
// Define Mixin
$mixin = (isset($options['mixin']) ? $options['mixin'] : 4);
// Define Unlock Time
$unlock_time = (isset($options['unlock_time']) ? $options['unlock_time'] : 0);
// Define Payment ID
$payment_id = (isset($options['payment_id']) ? $options['payment_id'] : null);
// Build params array
$params = [
'destinations' => $destinations,
'mixin' => $mixin,
'unlock_time' => $unlock_time,
'payment_id' => $payment_id
];
// Set algorithm type if using transfer_split method
if($options['method'] == "transfer_split"){
$new_algorithm = (isset($options['new_algorithm']) ? $options['new_algorithm'] : false);
$params['new_algorithm'] = $new_algorithm;
}
// Build request body
$body = [
'method' => $options['method'],
'params' => $params
];
return $body;
} | [
"public",
"function",
"_buildTransfer",
"(",
"$",
"options",
")",
"{",
"$",
"destinations",
"=",
"$",
"options",
"[",
"'destinations'",
"]",
";",
"// Convert Monero amount to atomic units",
"if",
"(",
"gettype",
"(",
"$",
"destinations",
")",
"==",
"\"object\"",
")",
"{",
"$",
"destinations",
"->",
"amount",
"=",
"$",
"destinations",
"->",
"amount",
"*",
"1e12",
";",
"$",
"destinations",
"=",
"array",
"(",
"$",
"destinations",
")",
";",
"}",
"else",
"{",
"foreach",
"(",
"$",
"destinations",
"as",
"&",
"$",
"destination",
")",
"{",
"$",
"destination",
"->",
"amount",
"=",
"$",
"destination",
"->",
"amount",
"*",
"1e12",
";",
"}",
"}",
"// Define Mixin",
"$",
"mixin",
"=",
"(",
"isset",
"(",
"$",
"options",
"[",
"'mixin'",
"]",
")",
"?",
"$",
"options",
"[",
"'mixin'",
"]",
":",
"4",
")",
";",
"// Define Unlock Time",
"$",
"unlock_time",
"=",
"(",
"isset",
"(",
"$",
"options",
"[",
"'unlock_time'",
"]",
")",
"?",
"$",
"options",
"[",
"'unlock_time'",
"]",
":",
"0",
")",
";",
"// Define Payment ID",
"$",
"payment_id",
"=",
"(",
"isset",
"(",
"$",
"options",
"[",
"'payment_id'",
"]",
")",
"?",
"$",
"options",
"[",
"'payment_id'",
"]",
":",
"null",
")",
";",
"// Build params array",
"$",
"params",
"=",
"[",
"'destinations'",
"=>",
"$",
"destinations",
",",
"'mixin'",
"=>",
"$",
"mixin",
",",
"'unlock_time'",
"=>",
"$",
"unlock_time",
",",
"'payment_id'",
"=>",
"$",
"payment_id",
"]",
";",
"// Set algorithm type if using transfer_split method",
"if",
"(",
"$",
"options",
"[",
"'method'",
"]",
"==",
"\"transfer_split\"",
")",
"{",
"$",
"new_algorithm",
"=",
"(",
"isset",
"(",
"$",
"options",
"[",
"'new_algorithm'",
"]",
")",
"?",
"$",
"options",
"[",
"'new_algorithm'",
"]",
":",
"false",
")",
";",
"$",
"params",
"[",
"'new_algorithm'",
"]",
"=",
"$",
"new_algorithm",
";",
"}",
"// Build request body",
"$",
"body",
"=",
"[",
"'method'",
"=>",
"$",
"options",
"[",
"'method'",
"]",
",",
"'params'",
"=>",
"$",
"params",
"]",
";",
"return",
"$",
"body",
";",
"}"
]
| Helper function for building transfer or transfer split request body
@param array $options
@return string | [
"Helper",
"function",
"for",
"building",
"transfer",
"or",
"transfer",
"split",
"request",
"body"
]
| 41c9cb55e816f2a118ef4fc25bc9848d082d50e4 | https://github.com/PsychicCat/monero-php/blob/41c9cb55e816f2a118ef4fc25bc9848d082d50e4/src/Wallet.php#L46-L82 | train |
PsychicCat/monero-php | src/Wallet.php | Wallet.transfer | public function transfer($options)
{
$options['method'] = 'transfer';
$body = $this->_buildTransfer($options);
return $this->_request($body);
} | php | public function transfer($options)
{
$options['method'] = 'transfer';
$body = $this->_buildTransfer($options);
return $this->_request($body);
} | [
"public",
"function",
"transfer",
"(",
"$",
"options",
")",
"{",
"$",
"options",
"[",
"'method'",
"]",
"=",
"'transfer'",
";",
"$",
"body",
"=",
"$",
"this",
"->",
"_buildTransfer",
"(",
"$",
"options",
")",
";",
"return",
"$",
"this",
"->",
"_request",
"(",
"$",
"body",
")",
";",
"}"
]
| Transfer Monero to a single recipient or group of recipients
@param array $options
@return string | [
"Transfer",
"Monero",
"to",
"a",
"single",
"recipient",
"or",
"group",
"of",
"recipients"
]
| 41c9cb55e816f2a118ef4fc25bc9848d082d50e4 | https://github.com/PsychicCat/monero-php/blob/41c9cb55e816f2a118ef4fc25bc9848d082d50e4/src/Wallet.php#L119-L124 | train |
PsychicCat/monero-php | src/Wallet.php | Wallet.getBulkPayments | public function getBulkPayments($payment_ids, $height)
{
$params = [
'payment_ids' => $payment_ids,
'min_block_height' => $height
];
$body = [
'method' => 'get_bulk_payments',
'params' => $params
];
return $this->_request($body);
} | php | public function getBulkPayments($payment_ids, $height)
{
$params = [
'payment_ids' => $payment_ids,
'min_block_height' => $height
];
$body = [
'method' => 'get_bulk_payments',
'params' => $params
];
return $this->_request($body);
} | [
"public",
"function",
"getBulkPayments",
"(",
"$",
"payment_ids",
",",
"$",
"height",
")",
"{",
"$",
"params",
"=",
"[",
"'payment_ids'",
"=>",
"$",
"payment_ids",
",",
"'min_block_height'",
"=>",
"$",
"height",
"]",
";",
"$",
"body",
"=",
"[",
"'method'",
"=>",
"'get_bulk_payments'",
",",
"'params'",
"=>",
"$",
"params",
"]",
";",
"return",
"$",
"this",
"->",
"_request",
"(",
"$",
"body",
")",
";",
"}"
]
| Get a list of incoming payments from a single payment ID or list of payment IDs from a given height.
@param $payment_ids array
@param $height int
@return string | [
"Get",
"a",
"list",
"of",
"incoming",
"payments",
"from",
"a",
"single",
"payment",
"ID",
"or",
"list",
"of",
"payment",
"IDs",
"from",
"a",
"given",
"height",
"."
]
| 41c9cb55e816f2a118ef4fc25bc9848d082d50e4 | https://github.com/PsychicCat/monero-php/blob/41c9cb55e816f2a118ef4fc25bc9848d082d50e4/src/Wallet.php#L179-L190 | train |
PsychicCat/monero-php | src/Wallet.php | Wallet.integratedAddress | public function integratedAddress($payment_id = null)
{
$params = ['payment_id' => $payment_id];
$body = [
'method' => 'make_integrated_address',
'params' => $params
];
return $this->_request($body);
} | php | public function integratedAddress($payment_id = null)
{
$params = ['payment_id' => $payment_id];
$body = [
'method' => 'make_integrated_address',
'params' => $params
];
return $this->_request($body);
} | [
"public",
"function",
"integratedAddress",
"(",
"$",
"payment_id",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"[",
"'payment_id'",
"=>",
"$",
"payment_id",
"]",
";",
"$",
"body",
"=",
"[",
"'method'",
"=>",
"'make_integrated_address'",
",",
"'params'",
"=>",
"$",
"params",
"]",
";",
"return",
"$",
"this",
"->",
"_request",
"(",
"$",
"body",
")",
";",
"}"
]
| Make an integrated address from the wallet address and a payment id.
@param string $payment_id
@return string | [
"Make",
"an",
"integrated",
"address",
"from",
"the",
"wallet",
"address",
"and",
"a",
"payment",
"id",
"."
]
| 41c9cb55e816f2a118ef4fc25bc9848d082d50e4 | https://github.com/PsychicCat/monero-php/blob/41c9cb55e816f2a118ef4fc25bc9848d082d50e4/src/Wallet.php#L227-L235 | train |
bitbeans/Yubikey | src/Yubikey.php | Yubikey.getNextURLpart | public function getNextURLpart()
{
$url_list = ($this->_url_list) ? $this->_url_list : config('yubikey.URL_LIST');
return ($this->_url_index >= count($url_list)) ? false : $url_list[$this->_url_index++];
} | php | public function getNextURLpart()
{
$url_list = ($this->_url_list) ? $this->_url_list : config('yubikey.URL_LIST');
return ($this->_url_index >= count($url_list)) ? false : $url_list[$this->_url_index++];
} | [
"public",
"function",
"getNextURLpart",
"(",
")",
"{",
"$",
"url_list",
"=",
"(",
"$",
"this",
"->",
"_url_list",
")",
"?",
"$",
"this",
"->",
"_url_list",
":",
"config",
"(",
"'yubikey.URL_LIST'",
")",
";",
"return",
"(",
"$",
"this",
"->",
"_url_index",
">=",
"count",
"(",
"$",
"url_list",
")",
")",
"?",
"false",
":",
"$",
"url_list",
"[",
"$",
"this",
"->",
"_url_index",
"++",
"]",
";",
"}"
]
| Get next URL part from list to use for validation.
@return mixed string with URL part of false if no more URLs in list
@access public | [
"Get",
"next",
"URL",
"part",
"from",
"list",
"to",
"use",
"for",
"validation",
"."
]
| 5cceea8864935c3197e03622016884f87e3d81f3 | https://github.com/bitbeans/Yubikey/blob/5cceea8864935c3197e03622016884f87e3d81f3/src/Yubikey.php#L145-L149 | train |
bitbeans/Yubikey | src/Yubikey.php | Yubikey.parsePasswordOTP | public function parsePasswordOTP($str, $delim = '[:]')
{
if (!preg_match("/^((.*)" . $delim . ")?(([cbdefghijklnrtuvCBDEFGHIJKLNRTUV]{0,16})([cbdefghijklnrtuvCBDEFGHIJKLNRTUV]{32}))$/", $str, $matches)) {
/* Dvorak? */
if (!preg_match("/^((.*)" . $delim . ")?(([jxe.uidchtnbpygkJXE.UIDCHTNBPYGK]{0,16})([jxe.uidchtnbpygkJXE.UIDCHTNBPYGK]{32}))$/", $str, $matches)) {
return false;
} else {
$ret['otp'] = strtr($matches[3], "jxe.uidchtnbpygk", "cbdefghijklnrtuv");
}
} else {
$ret['otp'] = $matches[3];
}
$ret['password'] = $matches[2];
$ret['prefix'] = $matches[4];
$ret['ciphertext'] = $matches[5];
return $ret;
} | php | public function parsePasswordOTP($str, $delim = '[:]')
{
if (!preg_match("/^((.*)" . $delim . ")?(([cbdefghijklnrtuvCBDEFGHIJKLNRTUV]{0,16})([cbdefghijklnrtuvCBDEFGHIJKLNRTUV]{32}))$/", $str, $matches)) {
/* Dvorak? */
if (!preg_match("/^((.*)" . $delim . ")?(([jxe.uidchtnbpygkJXE.UIDCHTNBPYGK]{0,16})([jxe.uidchtnbpygkJXE.UIDCHTNBPYGK]{32}))$/", $str, $matches)) {
return false;
} else {
$ret['otp'] = strtr($matches[3], "jxe.uidchtnbpygk", "cbdefghijklnrtuv");
}
} else {
$ret['otp'] = $matches[3];
}
$ret['password'] = $matches[2];
$ret['prefix'] = $matches[4];
$ret['ciphertext'] = $matches[5];
return $ret;
} | [
"public",
"function",
"parsePasswordOTP",
"(",
"$",
"str",
",",
"$",
"delim",
"=",
"'[:]'",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"\"/^((.*)\"",
".",
"$",
"delim",
".",
"\")?(([cbdefghijklnrtuvCBDEFGHIJKLNRTUV]{0,16})([cbdefghijklnrtuvCBDEFGHIJKLNRTUV]{32}))$/\"",
",",
"$",
"str",
",",
"$",
"matches",
")",
")",
"{",
"/* Dvorak? */",
"if",
"(",
"!",
"preg_match",
"(",
"\"/^((.*)\"",
".",
"$",
"delim",
".",
"\")?(([jxe.uidchtnbpygkJXE.UIDCHTNBPYGK]{0,16})([jxe.uidchtnbpygkJXE.UIDCHTNBPYGK]{32}))$/\"",
",",
"$",
"str",
",",
"$",
"matches",
")",
")",
"{",
"return",
"false",
";",
"}",
"else",
"{",
"$",
"ret",
"[",
"'otp'",
"]",
"=",
"strtr",
"(",
"$",
"matches",
"[",
"3",
"]",
",",
"\"jxe.uidchtnbpygk\"",
",",
"\"cbdefghijklnrtuv\"",
")",
";",
"}",
"}",
"else",
"{",
"$",
"ret",
"[",
"'otp'",
"]",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"}",
"$",
"ret",
"[",
"'password'",
"]",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"$",
"ret",
"[",
"'prefix'",
"]",
"=",
"$",
"matches",
"[",
"4",
"]",
";",
"$",
"ret",
"[",
"'ciphertext'",
"]",
"=",
"$",
"matches",
"[",
"5",
"]",
";",
"return",
"$",
"ret",
";",
"}"
]
| Parse input string into password, yubikey prefix,
ciphertext, and OTP.
@param $str
@param string $delim
@return bool Keyed array with fields
@access public | [
"Parse",
"input",
"string",
"into",
"password",
"yubikey",
"prefix",
"ciphertext",
"and",
"OTP",
"."
]
| 5cceea8864935c3197e03622016884f87e3d81f3 | https://github.com/bitbeans/Yubikey/blob/5cceea8864935c3197e03622016884f87e3d81f3/src/Yubikey.php#L202-L220 | train |
bitbeans/Yubikey | src/Yubikey.php | Yubikey.getParameters | public function getParameters()
{
$params = explode("\n", trim($this->_response));
foreach ($params as $param) {
list($key, $val) = explode('=', $param, 2);
$param_array[$key] = $val;
}
$param_array['identity'] = substr($param_array['otp'], 0, 12);
return $param_array;
} | php | public function getParameters()
{
$params = explode("\n", trim($this->_response));
foreach ($params as $param) {
list($key, $val) = explode('=', $param, 2);
$param_array[$key] = $val;
}
$param_array['identity'] = substr($param_array['otp'], 0, 12);
return $param_array;
} | [
"public",
"function",
"getParameters",
"(",
")",
"{",
"$",
"params",
"=",
"explode",
"(",
"\"\\n\"",
",",
"trim",
"(",
"$",
"this",
"->",
"_response",
")",
")",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"list",
"(",
"$",
"key",
",",
"$",
"val",
")",
"=",
"explode",
"(",
"'='",
",",
"$",
"param",
",",
"2",
")",
";",
"$",
"param_array",
"[",
"$",
"key",
"]",
"=",
"$",
"val",
";",
"}",
"$",
"param_array",
"[",
"'identity'",
"]",
"=",
"substr",
"(",
"$",
"param_array",
"[",
"'otp'",
"]",
",",
"0",
",",
"12",
")",
";",
"return",
"$",
"param_array",
";",
"}"
]
| Parse parameters from last response
@return array parameter array from last response
@access public | [
"Parse",
"parameters",
"from",
"last",
"response"
]
| 5cceea8864935c3197e03622016884f87e3d81f3 | https://github.com/bitbeans/Yubikey/blob/5cceea8864935c3197e03622016884f87e3d81f3/src/Yubikey.php#L228-L240 | train |
bitbeans/Yubikey | src/Yubikey.php | Yubikey.getParameter | public function getParameter($parameter)
{
$param_array = $this->getParameters();
if (!empty($param_array) && array_key_exists($parameter, $param_array)) {
return $param_array[$parameter];
} else {
throw new \Exception('UNKNOWN_PARAMETER');
}
} | php | public function getParameter($parameter)
{
$param_array = $this->getParameters();
if (!empty($param_array) && array_key_exists($parameter, $param_array)) {
return $param_array[$parameter];
} else {
throw new \Exception('UNKNOWN_PARAMETER');
}
} | [
"public",
"function",
"getParameter",
"(",
"$",
"parameter",
")",
"{",
"$",
"param_array",
"=",
"$",
"this",
"->",
"getParameters",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"param_array",
")",
"&&",
"array_key_exists",
"(",
"$",
"parameter",
",",
"$",
"param_array",
")",
")",
"{",
"return",
"$",
"param_array",
"[",
"$",
"parameter",
"]",
";",
"}",
"else",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'UNKNOWN_PARAMETER'",
")",
";",
"}",
"}"
]
| Get one parameter from last response
@return mixed Exception on error, string otherwise
@access public
@throws \Exception | [
"Get",
"one",
"parameter",
"from",
"last",
"response"
]
| 5cceea8864935c3197e03622016884f87e3d81f3 | https://github.com/bitbeans/Yubikey/blob/5cceea8864935c3197e03622016884f87e3d81f3/src/Yubikey.php#L249-L258 | train |
bitbeans/Yubikey | src/Yubikey.php | Yubikey.hashEquals | protected static function hashEquals($knownString, $userString)
{
static $exists = null;
if ($exists === null) $exists = \function_exists('\\hash_equals');
if ($exists) return \hash_equals($knownString, $userString);
$length = self::safeStrlen($knownString);
if ($length !== self::safeStrlen($userString)) return false;
$r = 0;
for ($i = 0; $i < $length; ++$i) {
$r |= \ord($userString[$i]) ^ \ord($knownString[$i]);
}
return $r === 0;
} | php | protected static function hashEquals($knownString, $userString)
{
static $exists = null;
if ($exists === null) $exists = \function_exists('\\hash_equals');
if ($exists) return \hash_equals($knownString, $userString);
$length = self::safeStrlen($knownString);
if ($length !== self::safeStrlen($userString)) return false;
$r = 0;
for ($i = 0; $i < $length; ++$i) {
$r |= \ord($userString[$i]) ^ \ord($knownString[$i]);
}
return $r === 0;
} | [
"protected",
"static",
"function",
"hashEquals",
"(",
"$",
"knownString",
",",
"$",
"userString",
")",
"{",
"static",
"$",
"exists",
"=",
"null",
";",
"if",
"(",
"$",
"exists",
"===",
"null",
")",
"$",
"exists",
"=",
"\\",
"function_exists",
"(",
"'\\\\hash_equals'",
")",
";",
"if",
"(",
"$",
"exists",
")",
"return",
"\\",
"hash_equals",
"(",
"$",
"knownString",
",",
"$",
"userString",
")",
";",
"$",
"length",
"=",
"self",
"::",
"safeStrlen",
"(",
"$",
"knownString",
")",
";",
"if",
"(",
"$",
"length",
"!==",
"self",
"::",
"safeStrlen",
"(",
"$",
"userString",
")",
")",
"return",
"false",
";",
"$",
"r",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"length",
";",
"++",
"$",
"i",
")",
"{",
"$",
"r",
"|=",
"\\",
"ord",
"(",
"$",
"userString",
"[",
"$",
"i",
"]",
")",
"^",
"\\",
"ord",
"(",
"$",
"knownString",
"[",
"$",
"i",
"]",
")",
";",
"}",
"return",
"$",
"r",
"===",
"0",
";",
"}"
]
| Compare two hashes in constant time
@param string $knownString
@param string $userString
@return boolean | [
"Compare",
"two",
"hashes",
"in",
"constant",
"time"
]
| 5cceea8864935c3197e03622016884f87e3d81f3 | https://github.com/bitbeans/Yubikey/blob/5cceea8864935c3197e03622016884f87e3d81f3/src/Yubikey.php#L478-L490 | train |
bitbeans/Yubikey | src/Yubikey.php | Yubikey.getRandomBytes | protected static function getRandomBytes($num = 16)
{
static $which = null;
if ($which === null) {
if (\function_exists('\\random_bytes') && \version_compare(\phpversion(), '7.0.0', '>=')) {
$which = 'php7';
} elseif (\function_exists('\\openssl_random_pseudo_bytes')) {
$which = 'openssl';
} elseif (\function_exists('\\mcrypt_create_iv')) {
$which = 'mcrypt';
} elseif (\is_readable('/dev/urandom')) {
$which = 'urandom';
} else {
$which = 'fallback';
}
}
if ($num < 1 || $num > PHP_INT_MAX) {
return false;
}
// Now let's get some random bytes
switch ($which) {
case 'php7':
return \random_bytes($num);
case 'mcrypt':
return \mcrypt_create_iv($num, MCRYPT_DEV_URANDOM);
case 'openssl';
return \openssl_random_pseudo_bytes($num);
case 'urandom':
$fp = \fopen('/dev/urandom', 'rb');
\stream_set_read_buffer($fp, 0);
$bytes = \fread($fp, $num);
\fclose($fp);
return $bytes;
default:
// I really hope this is never necessary
$bytes = '';
for ($i = 0; $i < $num; ++$i) {
$bytes .= \chr(\mt_rand(0, 255) ^ \rand(0, 255));
}
$xorbuf = \sha1(\json_encode($_SERVER), true);
while (self::safeStrlen($xorbuf) < $num) {
$xorbuf .= \sha1(
\uniqid(
\md5(
\microtime(true) . \lcg_value()
),
true
),
true
);
}
for ($i = 0; $i < $num; ++$i) {
$bytes[$i] ^= $xorbuf[$i];
}
return $bytes;
}
} | php | protected static function getRandomBytes($num = 16)
{
static $which = null;
if ($which === null) {
if (\function_exists('\\random_bytes') && \version_compare(\phpversion(), '7.0.0', '>=')) {
$which = 'php7';
} elseif (\function_exists('\\openssl_random_pseudo_bytes')) {
$which = 'openssl';
} elseif (\function_exists('\\mcrypt_create_iv')) {
$which = 'mcrypt';
} elseif (\is_readable('/dev/urandom')) {
$which = 'urandom';
} else {
$which = 'fallback';
}
}
if ($num < 1 || $num > PHP_INT_MAX) {
return false;
}
// Now let's get some random bytes
switch ($which) {
case 'php7':
return \random_bytes($num);
case 'mcrypt':
return \mcrypt_create_iv($num, MCRYPT_DEV_URANDOM);
case 'openssl';
return \openssl_random_pseudo_bytes($num);
case 'urandom':
$fp = \fopen('/dev/urandom', 'rb');
\stream_set_read_buffer($fp, 0);
$bytes = \fread($fp, $num);
\fclose($fp);
return $bytes;
default:
// I really hope this is never necessary
$bytes = '';
for ($i = 0; $i < $num; ++$i) {
$bytes .= \chr(\mt_rand(0, 255) ^ \rand(0, 255));
}
$xorbuf = \sha1(\json_encode($_SERVER), true);
while (self::safeStrlen($xorbuf) < $num) {
$xorbuf .= \sha1(
\uniqid(
\md5(
\microtime(true) . \lcg_value()
),
true
),
true
);
}
for ($i = 0; $i < $num; ++$i) {
$bytes[$i] ^= $xorbuf[$i];
}
return $bytes;
}
} | [
"protected",
"static",
"function",
"getRandomBytes",
"(",
"$",
"num",
"=",
"16",
")",
"{",
"static",
"$",
"which",
"=",
"null",
";",
"if",
"(",
"$",
"which",
"===",
"null",
")",
"{",
"if",
"(",
"\\",
"function_exists",
"(",
"'\\\\random_bytes'",
")",
"&&",
"\\",
"version_compare",
"(",
"\\",
"phpversion",
"(",
")",
",",
"'7.0.0'",
",",
"'>='",
")",
")",
"{",
"$",
"which",
"=",
"'php7'",
";",
"}",
"elseif",
"(",
"\\",
"function_exists",
"(",
"'\\\\openssl_random_pseudo_bytes'",
")",
")",
"{",
"$",
"which",
"=",
"'openssl'",
";",
"}",
"elseif",
"(",
"\\",
"function_exists",
"(",
"'\\\\mcrypt_create_iv'",
")",
")",
"{",
"$",
"which",
"=",
"'mcrypt'",
";",
"}",
"elseif",
"(",
"\\",
"is_readable",
"(",
"'/dev/urandom'",
")",
")",
"{",
"$",
"which",
"=",
"'urandom'",
";",
"}",
"else",
"{",
"$",
"which",
"=",
"'fallback'",
";",
"}",
"}",
"if",
"(",
"$",
"num",
"<",
"1",
"||",
"$",
"num",
">",
"PHP_INT_MAX",
")",
"{",
"return",
"false",
";",
"}",
"// Now let's get some random bytes",
"switch",
"(",
"$",
"which",
")",
"{",
"case",
"'php7'",
":",
"return",
"\\",
"random_bytes",
"(",
"$",
"num",
")",
";",
"case",
"'mcrypt'",
":",
"return",
"\\",
"mcrypt_create_iv",
"(",
"$",
"num",
",",
"MCRYPT_DEV_URANDOM",
")",
";",
"case",
"'openssl'",
";",
"return",
"\\",
"openssl_random_pseudo_bytes",
"(",
"$",
"num",
")",
";",
"case",
"'urandom'",
":",
"$",
"fp",
"=",
"\\",
"fopen",
"(",
"'/dev/urandom'",
",",
"'rb'",
")",
";",
"\\",
"stream_set_read_buffer",
"(",
"$",
"fp",
",",
"0",
")",
";",
"$",
"bytes",
"=",
"\\",
"fread",
"(",
"$",
"fp",
",",
"$",
"num",
")",
";",
"\\",
"fclose",
"(",
"$",
"fp",
")",
";",
"return",
"$",
"bytes",
";",
"default",
":",
"// I really hope this is never necessary",
"$",
"bytes",
"=",
"''",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"num",
";",
"++",
"$",
"i",
")",
"{",
"$",
"bytes",
".=",
"\\",
"chr",
"(",
"\\",
"mt_rand",
"(",
"0",
",",
"255",
")",
"^",
"\\",
"rand",
"(",
"0",
",",
"255",
")",
")",
";",
"}",
"$",
"xorbuf",
"=",
"\\",
"sha1",
"(",
"\\",
"json_encode",
"(",
"$",
"_SERVER",
")",
",",
"true",
")",
";",
"while",
"(",
"self",
"::",
"safeStrlen",
"(",
"$",
"xorbuf",
")",
"<",
"$",
"num",
")",
"{",
"$",
"xorbuf",
".=",
"\\",
"sha1",
"(",
"\\",
"uniqid",
"(",
"\\",
"md5",
"(",
"\\",
"microtime",
"(",
"true",
")",
".",
"\\",
"lcg_value",
"(",
")",
")",
",",
"true",
")",
",",
"true",
")",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"num",
";",
"++",
"$",
"i",
")",
"{",
"$",
"bytes",
"[",
"$",
"i",
"]",
"^=",
"$",
"xorbuf",
"[",
"$",
"i",
"]",
";",
"}",
"return",
"$",
"bytes",
";",
"}",
"}"
]
| Get a string of cryptographically secure pseudorandom bytes
@param int $num
@return string
@throws \Exception | [
"Get",
"a",
"string",
"of",
"cryptographically",
"secure",
"pseudorandom",
"bytes"
]
| 5cceea8864935c3197e03622016884f87e3d81f3 | https://github.com/bitbeans/Yubikey/blob/5cceea8864935c3197e03622016884f87e3d81f3/src/Yubikey.php#L499-L559 | train |
bitbeans/Yubikey | src/Yubikey.php | Yubikey.safeStrlen | protected static function safeStrlen($string)
{
// Optimization -- only search once:
static $exists = null;
if ($exists === null) $exists = \function_exists('mb_strlen');
if ($exists) return \mb_strlen($string, '8bit');
return \strlen($string);
} | php | protected static function safeStrlen($string)
{
// Optimization -- only search once:
static $exists = null;
if ($exists === null) $exists = \function_exists('mb_strlen');
if ($exists) return \mb_strlen($string, '8bit');
return \strlen($string);
} | [
"protected",
"static",
"function",
"safeStrlen",
"(",
"$",
"string",
")",
"{",
"// Optimization -- only search once:",
"static",
"$",
"exists",
"=",
"null",
";",
"if",
"(",
"$",
"exists",
"===",
"null",
")",
"$",
"exists",
"=",
"\\",
"function_exists",
"(",
"'mb_strlen'",
")",
";",
"if",
"(",
"$",
"exists",
")",
"return",
"\\",
"mb_strlen",
"(",
"$",
"string",
",",
"'8bit'",
")",
";",
"return",
"\\",
"strlen",
"(",
"$",
"string",
")",
";",
"}"
]
| Get the length of a string, irrespective to mbstring.func_overload
@param string $string
@return int | [
"Get",
"the",
"length",
"of",
"a",
"string",
"irrespective",
"to",
"mbstring",
".",
"func_overload"
]
| 5cceea8864935c3197e03622016884f87e3d81f3 | https://github.com/bitbeans/Yubikey/blob/5cceea8864935c3197e03622016884f87e3d81f3/src/Yubikey.php#L567-L574 | train |
lukasoppermann/http-status | src/Httpstatus.php | Httpstatus.mergeHttpStatus | public function mergeHttpStatus($code, $text)
{
$code = $this->filterStatusCode($code);
$text = $this->filterReasonPhrase($text);
if ($this->hasReasonPhrase($text) && $this->getStatusCode($text) !== $code) {
throw new RuntimeException('The submitted reason phrase is already present in the collection');
}
$this->httpStatus[$code] = $text;
} | php | public function mergeHttpStatus($code, $text)
{
$code = $this->filterStatusCode($code);
$text = $this->filterReasonPhrase($text);
if ($this->hasReasonPhrase($text) && $this->getStatusCode($text) !== $code) {
throw new RuntimeException('The submitted reason phrase is already present in the collection');
}
$this->httpStatus[$code] = $text;
} | [
"public",
"function",
"mergeHttpStatus",
"(",
"$",
"code",
",",
"$",
"text",
")",
"{",
"$",
"code",
"=",
"$",
"this",
"->",
"filterStatusCode",
"(",
"$",
"code",
")",
";",
"$",
"text",
"=",
"$",
"this",
"->",
"filterReasonPhrase",
"(",
"$",
"text",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasReasonPhrase",
"(",
"$",
"text",
")",
"&&",
"$",
"this",
"->",
"getStatusCode",
"(",
"$",
"text",
")",
"!==",
"$",
"code",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'The submitted reason phrase is already present in the collection'",
")",
";",
"}",
"$",
"this",
"->",
"httpStatus",
"[",
"$",
"code",
"]",
"=",
"$",
"text",
";",
"}"
]
| Add or Update the HTTP Status array.
@param int $code a HTTP status Code
@param string $text a associated reason phrase
@throws RuntimeException if the HTTP status code or the reason phrase are invalid | [
"Add",
"or",
"Update",
"the",
"HTTP",
"Status",
"array",
"."
]
| c123b3844d1dafb94ef6efc08ea6a14c27a02cc4 | https://github.com/lukasoppermann/http-status/blob/c123b3844d1dafb94ef6efc08ea6a14c27a02cc4/src/Httpstatus.php#L150-L159 | train |
lukasoppermann/http-status | src/Httpstatus.php | Httpstatus.filterReasonPhrase | protected function filterReasonPhrase($text)
{
if (!(is_object($text) && method_exists($text, '__toString')) && !is_string($text)) {
throw new InvalidArgumentException('The reason phrase must be a string');
}
$text = trim($text);
if (preg_match(',[\r\n],', $text)) {
throw new InvalidArgumentException('The reason phrase can not contain carriage return characters');
}
return $text;
} | php | protected function filterReasonPhrase($text)
{
if (!(is_object($text) && method_exists($text, '__toString')) && !is_string($text)) {
throw new InvalidArgumentException('The reason phrase must be a string');
}
$text = trim($text);
if (preg_match(',[\r\n],', $text)) {
throw new InvalidArgumentException('The reason phrase can not contain carriage return characters');
}
return $text;
} | [
"protected",
"function",
"filterReasonPhrase",
"(",
"$",
"text",
")",
"{",
"if",
"(",
"!",
"(",
"is_object",
"(",
"$",
"text",
")",
"&&",
"method_exists",
"(",
"$",
"text",
",",
"'__toString'",
")",
")",
"&&",
"!",
"is_string",
"(",
"$",
"text",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The reason phrase must be a string'",
")",
";",
"}",
"$",
"text",
"=",
"trim",
"(",
"$",
"text",
")",
";",
"if",
"(",
"preg_match",
"(",
"',[\\r\\n],'",
",",
"$",
"text",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The reason phrase can not contain carriage return characters'",
")",
";",
"}",
"return",
"$",
"text",
";",
"}"
]
| Filter a Reason Phrase.
@param string $text
@throws InvalidArgumentException if the reason phrase is not a string
@throws InvalidArgumentException if the reason phrase contains carriage return characters
@see http://tools.ietf.org/html/rfc2616#section-6.1.1
@return string | [
"Filter",
"a",
"Reason",
"Phrase",
"."
]
| c123b3844d1dafb94ef6efc08ea6a14c27a02cc4 | https://github.com/lukasoppermann/http-status/blob/c123b3844d1dafb94ef6efc08ea6a14c27a02cc4/src/Httpstatus.php#L197-L209 | train |
lukasoppermann/http-status | src/Httpstatus.php | Httpstatus.getStatusCode | public function getStatusCode($statusText)
{
$statusText = $this->filterReasonPhrase($statusText);
$statusCode = $this->fetchStatusCode($statusText);
if ($statusCode !== false) {
return $statusCode;
}
throw new OutOfBoundsException(sprintf('No Http status code is associated to `%s`', $statusText));
} | php | public function getStatusCode($statusText)
{
$statusText = $this->filterReasonPhrase($statusText);
$statusCode = $this->fetchStatusCode($statusText);
if ($statusCode !== false) {
return $statusCode;
}
throw new OutOfBoundsException(sprintf('No Http status code is associated to `%s`', $statusText));
} | [
"public",
"function",
"getStatusCode",
"(",
"$",
"statusText",
")",
"{",
"$",
"statusText",
"=",
"$",
"this",
"->",
"filterReasonPhrase",
"(",
"$",
"statusText",
")",
";",
"$",
"statusCode",
"=",
"$",
"this",
"->",
"fetchStatusCode",
"(",
"$",
"statusText",
")",
";",
"if",
"(",
"$",
"statusCode",
"!==",
"false",
")",
"{",
"return",
"$",
"statusCode",
";",
"}",
"throw",
"new",
"OutOfBoundsException",
"(",
"sprintf",
"(",
"'No Http status code is associated to `%s`'",
",",
"$",
"statusText",
")",
")",
";",
"}"
]
| Get the code for a given status text.
@param string $statusText http status text
@throws InvalidArgumentException If the requested $statusText is not valid
@throws OutOfBoundsException If not status code is found
@return string Returns code for the given status text | [
"Get",
"the",
"code",
"for",
"a",
"given",
"status",
"text",
"."
]
| c123b3844d1dafb94ef6efc08ea6a14c27a02cc4 | https://github.com/lukasoppermann/http-status/blob/c123b3844d1dafb94ef6efc08ea6a14c27a02cc4/src/Httpstatus.php#L242-L251 | train |
lukasoppermann/http-status | src/Httpstatus.php | Httpstatus.hasStatusCode | public function hasStatusCode($statusCode)
{
try {
$statusCode = $this->filterStatusCode($statusCode);
} catch (InvalidArgumentException $e) {
return false;
}
return isset($this->httpStatus[$statusCode]);
} | php | public function hasStatusCode($statusCode)
{
try {
$statusCode = $this->filterStatusCode($statusCode);
} catch (InvalidArgumentException $e) {
return false;
}
return isset($this->httpStatus[$statusCode]);
} | [
"public",
"function",
"hasStatusCode",
"(",
"$",
"statusCode",
")",
"{",
"try",
"{",
"$",
"statusCode",
"=",
"$",
"this",
"->",
"filterStatusCode",
"(",
"$",
"statusCode",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"httpStatus",
"[",
"$",
"statusCode",
"]",
")",
";",
"}"
]
| Check if the code exists in a collection.
@param int $statusCode http status code
@throws InvalidArgumentException If the requested $statusCode is not valid
@return bool true|false | [
"Check",
"if",
"the",
"code",
"exists",
"in",
"a",
"collection",
"."
]
| c123b3844d1dafb94ef6efc08ea6a14c27a02cc4 | https://github.com/lukasoppermann/http-status/blob/c123b3844d1dafb94ef6efc08ea6a14c27a02cc4/src/Httpstatus.php#L274-L283 | train |
lukasoppermann/http-status | src/Httpstatus.php | Httpstatus.hasReasonPhrase | public function hasReasonPhrase($statusText)
{
try {
$statusText = $this->filterReasonPhrase($statusText);
} catch (InvalidArgumentException $e) {
return false;
}
return (bool) $this->fetchStatusCode($statusText);
} | php | public function hasReasonPhrase($statusText)
{
try {
$statusText = $this->filterReasonPhrase($statusText);
} catch (InvalidArgumentException $e) {
return false;
}
return (bool) $this->fetchStatusCode($statusText);
} | [
"public",
"function",
"hasReasonPhrase",
"(",
"$",
"statusText",
")",
"{",
"try",
"{",
"$",
"statusText",
"=",
"$",
"this",
"->",
"filterReasonPhrase",
"(",
"$",
"statusText",
")",
";",
"}",
"catch",
"(",
"InvalidArgumentException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"bool",
")",
"$",
"this",
"->",
"fetchStatusCode",
"(",
"$",
"statusText",
")",
";",
"}"
]
| Check if the hasReasonPhrase exists in a collection.
@param int $statusText http status text
@throws InvalidArgumentException If the requested $statusText is not valid
@return bool true|false | [
"Check",
"if",
"the",
"hasReasonPhrase",
"exists",
"in",
"a",
"collection",
"."
]
| c123b3844d1dafb94ef6efc08ea6a14c27a02cc4 | https://github.com/lukasoppermann/http-status/blob/c123b3844d1dafb94ef6efc08ea6a14c27a02cc4/src/Httpstatus.php#L294-L303 | train |
lukasoppermann/http-status | src/Httpstatus.php | Httpstatus.getResponseClass | public function getResponseClass($statusCode)
{
$responseClass = [
1 => self::CLASS_INFORMATIONAL,
2 => self::CLASS_SUCCESS,
3 => self::CLASS_REDIRECTION,
4 => self::CLASS_CLIENT_ERROR,
5 => self::CLASS_SERVER_ERROR,
];
$statusCode = $this->filterStatusCode($statusCode);
return $responseClass[(int) substr($statusCode, 0, 1)];
} | php | public function getResponseClass($statusCode)
{
$responseClass = [
1 => self::CLASS_INFORMATIONAL,
2 => self::CLASS_SUCCESS,
3 => self::CLASS_REDIRECTION,
4 => self::CLASS_CLIENT_ERROR,
5 => self::CLASS_SERVER_ERROR,
];
$statusCode = $this->filterStatusCode($statusCode);
return $responseClass[(int) substr($statusCode, 0, 1)];
} | [
"public",
"function",
"getResponseClass",
"(",
"$",
"statusCode",
")",
"{",
"$",
"responseClass",
"=",
"[",
"1",
"=>",
"self",
"::",
"CLASS_INFORMATIONAL",
",",
"2",
"=>",
"self",
"::",
"CLASS_SUCCESS",
",",
"3",
"=>",
"self",
"::",
"CLASS_REDIRECTION",
",",
"4",
"=>",
"self",
"::",
"CLASS_CLIENT_ERROR",
",",
"5",
"=>",
"self",
"::",
"CLASS_SERVER_ERROR",
",",
"]",
";",
"$",
"statusCode",
"=",
"$",
"this",
"->",
"filterStatusCode",
"(",
"$",
"statusCode",
")",
";",
"return",
"$",
"responseClass",
"[",
"(",
"int",
")",
"substr",
"(",
"$",
"statusCode",
",",
"0",
",",
"1",
")",
"]",
";",
"}"
]
| Determines the response class of a response code.
See the `CLASS_` constants for possible return values
@param int $statusCode
@throws InvalidArgumentException If the requested $statusCode is not valid
@return int | [
"Determines",
"the",
"response",
"class",
"of",
"a",
"response",
"code",
"."
]
| c123b3844d1dafb94ef6efc08ea6a14c27a02cc4 | https://github.com/lukasoppermann/http-status/blob/c123b3844d1dafb94ef6efc08ea6a14c27a02cc4/src/Httpstatus.php#L316-L329 | train |
samrap/acf-fluent | src/Acf.php | Acf.field | public static function field($name, $id = null)
{
return self::getInstance()
->getBuilder(FieldBehavior::class)
->field($name)
->id($id);
} | php | public static function field($name, $id = null)
{
return self::getInstance()
->getBuilder(FieldBehavior::class)
->field($name)
->id($id);
} | [
"public",
"static",
"function",
"field",
"(",
"$",
"name",
",",
"$",
"id",
"=",
"null",
")",
"{",
"return",
"self",
"::",
"getInstance",
"(",
")",
"->",
"getBuilder",
"(",
"FieldBehavior",
"::",
"class",
")",
"->",
"field",
"(",
"$",
"name",
")",
"->",
"id",
"(",
"$",
"id",
")",
";",
"}"
]
| Return a new builder instance for a field call.
@param string $name
@param int $id
@return \Samrap\Acf\Fluent\Builder | [
"Return",
"a",
"new",
"builder",
"instance",
"for",
"a",
"field",
"call",
"."
]
| fb612e9f99fcdc2ee042bc915d9de90b83ff1d52 | https://github.com/samrap/acf-fluent/blob/fb612e9f99fcdc2ee042bc915d9de90b83ff1d52/src/Acf.php#L64-L70 | train |
samrap/acf-fluent | src/Acf.php | Acf.getBuilder | private function getBuilder($behavior)
{
// Create a new behavior of the given type if one does not yet exist.
if (! isset($this->behaviors[$behavior])) {
$this->behaviors[$behavior] = new $behavior();
}
return new Builder(new Runner($this->behaviors[$behavior]), $this->macros);
} | php | private function getBuilder($behavior)
{
// Create a new behavior of the given type if one does not yet exist.
if (! isset($this->behaviors[$behavior])) {
$this->behaviors[$behavior] = new $behavior();
}
return new Builder(new Runner($this->behaviors[$behavior]), $this->macros);
} | [
"private",
"function",
"getBuilder",
"(",
"$",
"behavior",
")",
"{",
"// Create a new behavior of the given type if one does not yet exist.",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"behaviors",
"[",
"$",
"behavior",
"]",
")",
")",
"{",
"$",
"this",
"->",
"behaviors",
"[",
"$",
"behavior",
"]",
"=",
"new",
"$",
"behavior",
"(",
")",
";",
"}",
"return",
"new",
"Builder",
"(",
"new",
"Runner",
"(",
"$",
"this",
"->",
"behaviors",
"[",
"$",
"behavior",
"]",
")",
",",
"$",
"this",
"->",
"macros",
")",
";",
"}"
]
| Return a builder instance with the given behavior.
@param string $behavior
@return \Samrap\Acf\Fluent\Builder | [
"Return",
"a",
"builder",
"instance",
"with",
"the",
"given",
"behavior",
"."
]
| fb612e9f99fcdc2ee042bc915d9de90b83ff1d52 | https://github.com/samrap/acf-fluent/blob/fb612e9f99fcdc2ee042bc915d9de90b83ff1d52/src/Acf.php#L117-L125 | train |
samrap/acf-fluent | src/Fluent/Runner.php | Runner.get | public function get(Builder $builder)
{
// First, we will retrieve the field's value using our composed behavior.
$value = $this->behavior->get(
$builder->field,
$builder->id,
! $builder->raw
);
// Next, we will iterate over the defined components and pass our value
// through each component's method if it was defined on the builder.
foreach ($this->components as $component) {
if (! is_null($builder->$component)) {
$method = 'run'.ucfirst($component);
$value = $this->$method($builder->$component, $value);
}
}
return $value;
} | php | public function get(Builder $builder)
{
// First, we will retrieve the field's value using our composed behavior.
$value = $this->behavior->get(
$builder->field,
$builder->id,
! $builder->raw
);
// Next, we will iterate over the defined components and pass our value
// through each component's method if it was defined on the builder.
foreach ($this->components as $component) {
if (! is_null($builder->$component)) {
$method = 'run'.ucfirst($component);
$value = $this->$method($builder->$component, $value);
}
}
return $value;
} | [
"public",
"function",
"get",
"(",
"Builder",
"$",
"builder",
")",
"{",
"// First, we will retrieve the field's value using our composed behavior.",
"$",
"value",
"=",
"$",
"this",
"->",
"behavior",
"->",
"get",
"(",
"$",
"builder",
"->",
"field",
",",
"$",
"builder",
"->",
"id",
",",
"!",
"$",
"builder",
"->",
"raw",
")",
";",
"// Next, we will iterate over the defined components and pass our value",
"// through each component's method if it was defined on the builder.",
"foreach",
"(",
"$",
"this",
"->",
"components",
"as",
"$",
"component",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"builder",
"->",
"$",
"component",
")",
")",
"{",
"$",
"method",
"=",
"'run'",
".",
"ucfirst",
"(",
"$",
"component",
")",
";",
"$",
"value",
"=",
"$",
"this",
"->",
"$",
"method",
"(",
"$",
"builder",
"->",
"$",
"component",
",",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"value",
";",
"}"
]
| Run the ACF 'get' behavior from the given builder.
@param \Samrap\Acf\Fluent\Builder $builder
@return mixed | [
"Run",
"the",
"ACF",
"get",
"behavior",
"from",
"the",
"given",
"builder",
"."
]
| fb612e9f99fcdc2ee042bc915d9de90b83ff1d52 | https://github.com/samrap/acf-fluent/blob/fb612e9f99fcdc2ee042bc915d9de90b83ff1d52/src/Fluent/Runner.php#L70-L90 | train |
samrap/acf-fluent | src/Fluent/Runner.php | Runner.update | public function update(Builder $builder, $value)
{
$this->behavior->update($builder->field, $value, $builder->id);
} | php | public function update(Builder $builder, $value)
{
$this->behavior->update($builder->field, $value, $builder->id);
} | [
"public",
"function",
"update",
"(",
"Builder",
"$",
"builder",
",",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"behavior",
"->",
"update",
"(",
"$",
"builder",
"->",
"field",
",",
"$",
"value",
",",
"$",
"builder",
"->",
"id",
")",
";",
"}"
]
| Run the ACF 'update' behavior from the given builder.
@param \Samrap\Acf\Fluent\Builder $builder
@param mixed $value
@return void | [
"Run",
"the",
"ACF",
"update",
"behavior",
"from",
"the",
"given",
"builder",
"."
]
| fb612e9f99fcdc2ee042bc915d9de90b83ff1d52 | https://github.com/samrap/acf-fluent/blob/fb612e9f99fcdc2ee042bc915d9de90b83ff1d52/src/Fluent/Runner.php#L99-L102 | train |
samrap/acf-fluent | src/Fluent/Runner.php | Runner.runDefault | protected function runDefault($default, $value)
{
if (is_string($value) && strlen($value) === 0) {
return $default;
} elseif (is_array($value) && empty($value)) {
return $default;
}
return $value ?? $default;
} | php | protected function runDefault($default, $value)
{
if (is_string($value) && strlen($value) === 0) {
return $default;
} elseif (is_array($value) && empty($value)) {
return $default;
}
return $value ?? $default;
} | [
"protected",
"function",
"runDefault",
"(",
"$",
"default",
",",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"&&",
"strlen",
"(",
"$",
"value",
")",
"===",
"0",
")",
"{",
"return",
"$",
"default",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"empty",
"(",
"$",
"value",
")",
")",
"{",
"return",
"$",
"default",
";",
"}",
"return",
"$",
"value",
"??",
"$",
"default",
";",
"}"
]
| Return the default value if the given value is empty or null.
@param mixed $default
@param mixed $value
@return mixed | [
"Return",
"the",
"default",
"value",
"if",
"the",
"given",
"value",
"is",
"empty",
"or",
"null",
"."
]
| fb612e9f99fcdc2ee042bc915d9de90b83ff1d52 | https://github.com/samrap/acf-fluent/blob/fb612e9f99fcdc2ee042bc915d9de90b83ff1d52/src/Fluent/Runner.php#L135-L144 | train |
samrap/acf-fluent | src/Fluent/Runner.php | Runner.runEscape | protected function runEscape($func, $value)
{
if (! is_string($value)) {
throw new RunnerException('Cannot escape value of type '.gettype($value));
}
$whitelist = [
'esc_attr',
'esc_html',
'esc_js',
'esc_textarea',
'esc_url',
'htmlspecialchars',
'urlencode',
];
return (in_array($func, $whitelist))
? call_user_func($func, $value)
: $value;
} | php | protected function runEscape($func, $value)
{
if (! is_string($value)) {
throw new RunnerException('Cannot escape value of type '.gettype($value));
}
$whitelist = [
'esc_attr',
'esc_html',
'esc_js',
'esc_textarea',
'esc_url',
'htmlspecialchars',
'urlencode',
];
return (in_array($func, $whitelist))
? call_user_func($func, $value)
: $value;
} | [
"protected",
"function",
"runEscape",
"(",
"$",
"func",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"RunnerException",
"(",
"'Cannot escape value of type '",
".",
"gettype",
"(",
"$",
"value",
")",
")",
";",
"}",
"$",
"whitelist",
"=",
"[",
"'esc_attr'",
",",
"'esc_html'",
",",
"'esc_js'",
",",
"'esc_textarea'",
",",
"'esc_url'",
",",
"'htmlspecialchars'",
",",
"'urlencode'",
",",
"]",
";",
"return",
"(",
"in_array",
"(",
"$",
"func",
",",
"$",
"whitelist",
")",
")",
"?",
"call_user_func",
"(",
"$",
"func",
",",
"$",
"value",
")",
":",
"$",
"value",
";",
"}"
]
| Escape the value with the given function.
@param callable $func
@param string $value
@return string | [
"Escape",
"the",
"value",
"with",
"the",
"given",
"function",
"."
]
| fb612e9f99fcdc2ee042bc915d9de90b83ff1d52 | https://github.com/samrap/acf-fluent/blob/fb612e9f99fcdc2ee042bc915d9de90b83ff1d52/src/Fluent/Runner.php#L153-L172 | train |
samrap/acf-fluent | src/Fluent/Runner.php | Runner.runShortcodes | protected function runShortcodes($_, $value)
{
if (! is_string($value)) {
throw new RunnerException(
'Cannot do shortcode on value of type '.gettype($value)
);
}
return do_shortcode($value);
} | php | protected function runShortcodes($_, $value)
{
if (! is_string($value)) {
throw new RunnerException(
'Cannot do shortcode on value of type '.gettype($value)
);
}
return do_shortcode($value);
} | [
"protected",
"function",
"runShortcodes",
"(",
"$",
"_",
",",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"RunnerException",
"(",
"'Cannot do shortcode on value of type '",
".",
"gettype",
"(",
"$",
"value",
")",
")",
";",
"}",
"return",
"do_shortcode",
"(",
"$",
"value",
")",
";",
"}"
]
| Do shortcodes on the given value.
@param bool $_
@param mixed $value
@return mixed | [
"Do",
"shortcodes",
"on",
"the",
"given",
"value",
"."
]
| fb612e9f99fcdc2ee042bc915d9de90b83ff1d52 | https://github.com/samrap/acf-fluent/blob/fb612e9f99fcdc2ee042bc915d9de90b83ff1d52/src/Fluent/Runner.php#L181-L190 | train |
PayEx/PayEx.Ecommerce.Php | src/PayEx/Api/Response.php | Response.getOperationByRel | public function getOperationByRel($rel, $single = true)
{
$operations = isset($this->object['operations']) ? $this->object['operations'] : [];
$operation = array_filter($operations, function ($value, $key) use ($rel) {
return (is_array($value) && $value['rel'] === $rel);
}, ARRAY_FILTER_USE_BOTH);
if (count($operation) > 0) {
$operation = array_shift($operation);
return $single ? $operation['href'] : $operation;
}
return false;
} | php | public function getOperationByRel($rel, $single = true)
{
$operations = isset($this->object['operations']) ? $this->object['operations'] : [];
$operation = array_filter($operations, function ($value, $key) use ($rel) {
return (is_array($value) && $value['rel'] === $rel);
}, ARRAY_FILTER_USE_BOTH);
if (count($operation) > 0) {
$operation = array_shift($operation);
return $single ? $operation['href'] : $operation;
}
return false;
} | [
"public",
"function",
"getOperationByRel",
"(",
"$",
"rel",
",",
"$",
"single",
"=",
"true",
")",
"{",
"$",
"operations",
"=",
"isset",
"(",
"$",
"this",
"->",
"object",
"[",
"'operations'",
"]",
")",
"?",
"$",
"this",
"->",
"object",
"[",
"'operations'",
"]",
":",
"[",
"]",
";",
"$",
"operation",
"=",
"array_filter",
"(",
"$",
"operations",
",",
"function",
"(",
"$",
"value",
",",
"$",
"key",
")",
"use",
"(",
"$",
"rel",
")",
"{",
"return",
"(",
"is_array",
"(",
"$",
"value",
")",
"&&",
"$",
"value",
"[",
"'rel'",
"]",
"===",
"$",
"rel",
")",
";",
"}",
",",
"ARRAY_FILTER_USE_BOTH",
")",
";",
"if",
"(",
"count",
"(",
"$",
"operation",
")",
">",
"0",
")",
"{",
"$",
"operation",
"=",
"array_shift",
"(",
"$",
"operation",
")",
";",
"return",
"$",
"single",
"?",
"$",
"operation",
"[",
"'href'",
"]",
":",
"$",
"operation",
";",
"}",
"return",
"false",
";",
"}"
]
| Extract operation value from operations list
@param string $rel
@param bool $single
@return bool|string|array | [
"Extract",
"operation",
"value",
"from",
"operations",
"list"
]
| c95e7b41ac0c1a9cdd3f94780001802649df26c2 | https://github.com/PayEx/PayEx.Ecommerce.Php/blob/c95e7b41ac0c1a9cdd3f94780001802649df26c2/src/PayEx/Api/Response.php#L211-L225 | train |
dereuromark/cakephp-flash | src/Controller/Component/FlashComponent.php | FlashComponent._transformCrudOptions | protected function _transformCrudOptions(array $options) {
if (isset($options['params']['class']) && !isset($options['type'])) {
$class = $options['params']['class'];
$pos = strrpos($class, ' ');
if ($pos !== false) {
$class = substr($class, $pos + 1);
}
$options['type'] = $class;
$options['element'] = $class;
unset($options['params']['class']);
unset($options['params']['original']);
}
return $options;
} | php | protected function _transformCrudOptions(array $options) {
if (isset($options['params']['class']) && !isset($options['type'])) {
$class = $options['params']['class'];
$pos = strrpos($class, ' ');
if ($pos !== false) {
$class = substr($class, $pos + 1);
}
$options['type'] = $class;
$options['element'] = $class;
unset($options['params']['class']);
unset($options['params']['original']);
}
return $options;
} | [
"protected",
"function",
"_transformCrudOptions",
"(",
"array",
"$",
"options",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'params'",
"]",
"[",
"'class'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"options",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"class",
"=",
"$",
"options",
"[",
"'params'",
"]",
"[",
"'class'",
"]",
";",
"$",
"pos",
"=",
"strrpos",
"(",
"$",
"class",
",",
"' '",
")",
";",
"if",
"(",
"$",
"pos",
"!==",
"false",
")",
"{",
"$",
"class",
"=",
"substr",
"(",
"$",
"class",
",",
"$",
"pos",
"+",
"1",
")",
";",
"}",
"$",
"options",
"[",
"'type'",
"]",
"=",
"$",
"class",
";",
"$",
"options",
"[",
"'element'",
"]",
"=",
"$",
"class",
";",
"unset",
"(",
"$",
"options",
"[",
"'params'",
"]",
"[",
"'class'",
"]",
")",
";",
"unset",
"(",
"$",
"options",
"[",
"'params'",
"]",
"[",
"'original'",
"]",
")",
";",
"}",
"return",
"$",
"options",
";",
"}"
]
| Transforms Crud plugin flashs into Flash messages.
@param array $options
@return array | [
"Transforms",
"Crud",
"plugin",
"flashs",
"into",
"Flash",
"messages",
"."
]
| e8a1a65bc1803c5b66987f28254fc788859e75e8 | https://github.com/dereuromark/cakephp-flash/blob/e8a1a65bc1803c5b66987f28254fc788859e75e8/src/Controller/Component/FlashComponent.php#L228-L242 | train |
dereuromark/cakephp-flash | src/View/Helper/FlashHelper.php | FlashHelper.render | public function render($key = 'flash', array $options = []) {
$options += ['types' => []];
// Get the messages from the session
$messages = (array)$this->_View->getRequest()->getSession()->read('Flash.' . $key);
$transientMessages = (array)Configure::read('TransientFlash.' . $key);
if ($transientMessages) {
$messages = array_merge($messages, $transientMessages);
}
$messages = $this->_order($messages);
$html = '';
foreach ($messages as $message) {
if ($options['types'] && !in_array($message['type'], $options['types'])) {
continue;
}
$message = $options + $message;
$html .= $this->_View->element($message['element'], $message);
}
if ($options['types']) {
$messages = (array)$this->_View->getRequest()->getSession()->read('Flash.' . $key);
foreach ($messages as $index => $message) {
if (!in_array($message['type'], $options['types'])) {
continue;
}
$this->_View->getRequest()->getSession()->delete('Flash.' . $key . '.' . $index);
}
foreach ($transientMessages as $index => $message) {
if (!in_array($message['type'], $options['types'])) {
continue;
}
Configure::delete('TransientFlash.' . $key . '.' . $index);
}
} else {
$this->_View->getRequest()->getSession()->delete('Flash.' . $key);
Configure::delete('TransientFlash.' . $key);
}
return $html;
} | php | public function render($key = 'flash', array $options = []) {
$options += ['types' => []];
// Get the messages from the session
$messages = (array)$this->_View->getRequest()->getSession()->read('Flash.' . $key);
$transientMessages = (array)Configure::read('TransientFlash.' . $key);
if ($transientMessages) {
$messages = array_merge($messages, $transientMessages);
}
$messages = $this->_order($messages);
$html = '';
foreach ($messages as $message) {
if ($options['types'] && !in_array($message['type'], $options['types'])) {
continue;
}
$message = $options + $message;
$html .= $this->_View->element($message['element'], $message);
}
if ($options['types']) {
$messages = (array)$this->_View->getRequest()->getSession()->read('Flash.' . $key);
foreach ($messages as $index => $message) {
if (!in_array($message['type'], $options['types'])) {
continue;
}
$this->_View->getRequest()->getSession()->delete('Flash.' . $key . '.' . $index);
}
foreach ($transientMessages as $index => $message) {
if (!in_array($message['type'], $options['types'])) {
continue;
}
Configure::delete('TransientFlash.' . $key . '.' . $index);
}
} else {
$this->_View->getRequest()->getSession()->delete('Flash.' . $key);
Configure::delete('TransientFlash.' . $key);
}
return $html;
} | [
"public",
"function",
"render",
"(",
"$",
"key",
"=",
"'flash'",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"$",
"options",
"+=",
"[",
"'types'",
"=>",
"[",
"]",
"]",
";",
"// Get the messages from the session",
"$",
"messages",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"_View",
"->",
"getRequest",
"(",
")",
"->",
"getSession",
"(",
")",
"->",
"read",
"(",
"'Flash.'",
".",
"$",
"key",
")",
";",
"$",
"transientMessages",
"=",
"(",
"array",
")",
"Configure",
"::",
"read",
"(",
"'TransientFlash.'",
".",
"$",
"key",
")",
";",
"if",
"(",
"$",
"transientMessages",
")",
"{",
"$",
"messages",
"=",
"array_merge",
"(",
"$",
"messages",
",",
"$",
"transientMessages",
")",
";",
"}",
"$",
"messages",
"=",
"$",
"this",
"->",
"_order",
"(",
"$",
"messages",
")",
";",
"$",
"html",
"=",
"''",
";",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"message",
")",
"{",
"if",
"(",
"$",
"options",
"[",
"'types'",
"]",
"&&",
"!",
"in_array",
"(",
"$",
"message",
"[",
"'type'",
"]",
",",
"$",
"options",
"[",
"'types'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"message",
"=",
"$",
"options",
"+",
"$",
"message",
";",
"$",
"html",
".=",
"$",
"this",
"->",
"_View",
"->",
"element",
"(",
"$",
"message",
"[",
"'element'",
"]",
",",
"$",
"message",
")",
";",
"}",
"if",
"(",
"$",
"options",
"[",
"'types'",
"]",
")",
"{",
"$",
"messages",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"_View",
"->",
"getRequest",
"(",
")",
"->",
"getSession",
"(",
")",
"->",
"read",
"(",
"'Flash.'",
".",
"$",
"key",
")",
";",
"foreach",
"(",
"$",
"messages",
"as",
"$",
"index",
"=>",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"message",
"[",
"'type'",
"]",
",",
"$",
"options",
"[",
"'types'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"$",
"this",
"->",
"_View",
"->",
"getRequest",
"(",
")",
"->",
"getSession",
"(",
")",
"->",
"delete",
"(",
"'Flash.'",
".",
"$",
"key",
".",
"'.'",
".",
"$",
"index",
")",
";",
"}",
"foreach",
"(",
"$",
"transientMessages",
"as",
"$",
"index",
"=>",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"message",
"[",
"'type'",
"]",
",",
"$",
"options",
"[",
"'types'",
"]",
")",
")",
"{",
"continue",
";",
"}",
"Configure",
"::",
"delete",
"(",
"'TransientFlash.'",
".",
"$",
"key",
".",
"'.'",
".",
"$",
"index",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"_View",
"->",
"getRequest",
"(",
")",
"->",
"getSession",
"(",
")",
"->",
"delete",
"(",
"'Flash.'",
".",
"$",
"key",
")",
";",
"Configure",
"::",
"delete",
"(",
"'TransientFlash.'",
".",
"$",
"key",
")",
";",
"}",
"return",
"$",
"html",
";",
"}"
]
| Displays flash messages.
Options:
- types: Types to render out, defaults to all
@param string $key The [Flash.]key you are rendering in the view.
@param array $options Additional options to use for the creation of this flash message.
Supports the 'params', and 'element' keys that are used in the helper.
@return string|null Rendered flash message or null if flash key does not exist
in session.
@throws \UnexpectedValueException If value for flash settings key is not an array. | [
"Displays",
"flash",
"messages",
"."
]
| e8a1a65bc1803c5b66987f28254fc788859e75e8 | https://github.com/dereuromark/cakephp-flash/blob/e8a1a65bc1803c5b66987f28254fc788859e75e8/src/View/Helper/FlashHelper.php#L41-L83 | train |
dereuromark/cakephp-flash | src/View/Helper/FlashHelper.php | FlashHelper.message | public function message($message, $options = null) {
$options = $this->_mergeOptions($options);
$options['message'] = $message;
return $this->_View->element($options['element'], $options);
} | php | public function message($message, $options = null) {
$options = $this->_mergeOptions($options);
$options['message'] = $message;
return $this->_View->element($options['element'], $options);
} | [
"public",
"function",
"message",
"(",
"$",
"message",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"_mergeOptions",
"(",
"$",
"options",
")",
";",
"$",
"options",
"[",
"'message'",
"]",
"=",
"$",
"message",
";",
"return",
"$",
"this",
"->",
"_View",
"->",
"element",
"(",
"$",
"options",
"[",
"'element'",
"]",
",",
"$",
"options",
")",
";",
"}"
]
| Outputs a single flash message directly.
Note that this does not use the Session.
@param string $message String to output.
@param array|string|null $options Options
@return string HTML | [
"Outputs",
"a",
"single",
"flash",
"message",
"directly",
".",
"Note",
"that",
"this",
"does",
"not",
"use",
"the",
"Session",
"."
]
| e8a1a65bc1803c5b66987f28254fc788859e75e8 | https://github.com/dereuromark/cakephp-flash/blob/e8a1a65bc1803c5b66987f28254fc788859e75e8/src/View/Helper/FlashHelper.php#L124-L129 | train |
dereuromark/cakephp-flash | src/View/Helper/FlashHelper.php | FlashHelper.addTransientMessage | public function addTransientMessage($message, $options = null) {
$options = $this->_mergeOptions($options);
$options['message'] = $message;
$messages = (array)Configure::read('TransientFlash.' . $options['key']);
if ($messages && count($messages) > $this->getConfig('limit')) {
array_shift($messages);
}
$messages[] = $options;
Configure::write('TransientFlash.' . $options['key'], $messages);
} | php | public function addTransientMessage($message, $options = null) {
$options = $this->_mergeOptions($options);
$options['message'] = $message;
$messages = (array)Configure::read('TransientFlash.' . $options['key']);
if ($messages && count($messages) > $this->getConfig('limit')) {
array_shift($messages);
}
$messages[] = $options;
Configure::write('TransientFlash.' . $options['key'], $messages);
} | [
"public",
"function",
"addTransientMessage",
"(",
"$",
"message",
",",
"$",
"options",
"=",
"null",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"_mergeOptions",
"(",
"$",
"options",
")",
";",
"$",
"options",
"[",
"'message'",
"]",
"=",
"$",
"message",
";",
"$",
"messages",
"=",
"(",
"array",
")",
"Configure",
"::",
"read",
"(",
"'TransientFlash.'",
".",
"$",
"options",
"[",
"'key'",
"]",
")",
";",
"if",
"(",
"$",
"messages",
"&&",
"count",
"(",
"$",
"messages",
")",
">",
"$",
"this",
"->",
"getConfig",
"(",
"'limit'",
")",
")",
"{",
"array_shift",
"(",
"$",
"messages",
")",
";",
"}",
"$",
"messages",
"[",
"]",
"=",
"$",
"options",
";",
"Configure",
"::",
"write",
"(",
"'TransientFlash.'",
".",
"$",
"options",
"[",
"'key'",
"]",
",",
"$",
"messages",
")",
";",
"}"
]
| Add a message on the fly
@param string $message
@param array|string|null $options
@return void | [
"Add",
"a",
"message",
"on",
"the",
"fly"
]
| e8a1a65bc1803c5b66987f28254fc788859e75e8 | https://github.com/dereuromark/cakephp-flash/blob/e8a1a65bc1803c5b66987f28254fc788859e75e8/src/View/Helper/FlashHelper.php#L138-L148 | train |
spatie/fractalistic | src/Fractal.php | Fractal.collection | public function collection($data, $transformer = null, $resourceName = null)
{
if (! is_null($resourceName)) {
$this->resourceName = $resourceName;
}
return $this->data('collection', $data, $transformer);
} | php | public function collection($data, $transformer = null, $resourceName = null)
{
if (! is_null($resourceName)) {
$this->resourceName = $resourceName;
}
return $this->data('collection', $data, $transformer);
} | [
"public",
"function",
"collection",
"(",
"$",
"data",
",",
"$",
"transformer",
"=",
"null",
",",
"$",
"resourceName",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"resourceName",
")",
")",
"{",
"$",
"this",
"->",
"resourceName",
"=",
"$",
"resourceName",
";",
"}",
"return",
"$",
"this",
"->",
"data",
"(",
"'collection'",
",",
"$",
"data",
",",
"$",
"transformer",
")",
";",
"}"
]
| Set the collection data that must be transformed.
@param mixed $data
@param null|string|callable|\League\Fractal\TransformerAbstract $transformer
@param null|string $resourceName
@return $this | [
"Set",
"the",
"collection",
"data",
"that",
"must",
"be",
"transformed",
"."
]
| bc588a3207c4166bb685aca0ee44d33c8958d8e2 | https://github.com/spatie/fractalistic/blob/bc588a3207c4166bb685aca0ee44d33c8958d8e2/src/Fractal.php#L88-L95 | train |
spatie/fractalistic | src/Fractal.php | Fractal.item | public function item($data, $transformer = null, $resourceName = null)
{
if (! is_null($resourceName)) {
$this->resourceName = $resourceName;
}
return $this->data('item', $data, $transformer);
} | php | public function item($data, $transformer = null, $resourceName = null)
{
if (! is_null($resourceName)) {
$this->resourceName = $resourceName;
}
return $this->data('item', $data, $transformer);
} | [
"public",
"function",
"item",
"(",
"$",
"data",
",",
"$",
"transformer",
"=",
"null",
",",
"$",
"resourceName",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"resourceName",
")",
")",
"{",
"$",
"this",
"->",
"resourceName",
"=",
"$",
"resourceName",
";",
"}",
"return",
"$",
"this",
"->",
"data",
"(",
"'item'",
",",
"$",
"data",
",",
"$",
"transformer",
")",
";",
"}"
]
| Set the item data that must be transformed.
@param mixed $data
@param null|string|callable|\League\Fractal\TransformerAbstract $transformer
@param null|string $resourceName
@return $this | [
"Set",
"the",
"item",
"data",
"that",
"must",
"be",
"transformed",
"."
]
| bc588a3207c4166bb685aca0ee44d33c8958d8e2 | https://github.com/spatie/fractalistic/blob/bc588a3207c4166bb685aca0ee44d33c8958d8e2/src/Fractal.php#L106-L113 | train |
spatie/fractalistic | src/Fractal.php | Fractal.primitive | public function primitive($data, $transformer = null, $resourceName = null)
{
if (! is_null($resourceName)) {
$this->resourceName = $resourceName;
}
return $this->data('primitive', $data, $transformer);
} | php | public function primitive($data, $transformer = null, $resourceName = null)
{
if (! is_null($resourceName)) {
$this->resourceName = $resourceName;
}
return $this->data('primitive', $data, $transformer);
} | [
"public",
"function",
"primitive",
"(",
"$",
"data",
",",
"$",
"transformer",
"=",
"null",
",",
"$",
"resourceName",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"resourceName",
")",
")",
"{",
"$",
"this",
"->",
"resourceName",
"=",
"$",
"resourceName",
";",
"}",
"return",
"$",
"this",
"->",
"data",
"(",
"'primitive'",
",",
"$",
"data",
",",
"$",
"transformer",
")",
";",
"}"
]
| Set the primitive data that must be transformed.
@param mixed $data
@param null|string|callable|\League\Fractal\TransformerAbstract $transformer
@param null|string $resourceName
@return $this | [
"Set",
"the",
"primitive",
"data",
"that",
"must",
"be",
"transformed",
"."
]
| bc588a3207c4166bb685aca0ee44d33c8958d8e2 | https://github.com/spatie/fractalistic/blob/bc588a3207c4166bb685aca0ee44d33c8958d8e2/src/Fractal.php#L124-L131 | train |
spatie/fractalistic | src/Fractal.php | Fractal.data | public function data($dataType, $data, $transformer = null)
{
$this->dataType = $dataType;
$this->data = $data;
if (! is_null($transformer)) {
$this->transformer = $transformer;
}
return $this;
} | php | public function data($dataType, $data, $transformer = null)
{
$this->dataType = $dataType;
$this->data = $data;
if (! is_null($transformer)) {
$this->transformer = $transformer;
}
return $this;
} | [
"public",
"function",
"data",
"(",
"$",
"dataType",
",",
"$",
"data",
",",
"$",
"transformer",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"dataType",
"=",
"$",
"dataType",
";",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"transformer",
")",
")",
"{",
"$",
"this",
"->",
"transformer",
"=",
"$",
"transformer",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set the data that must be transformed.
@param string $dataType
@param mixed $data
@param null|string|callable|\League\Fractal\TransformerAbstract $transformer
@return $this | [
"Set",
"the",
"data",
"that",
"must",
"be",
"transformed",
"."
]
| bc588a3207c4166bb685aca0ee44d33c8958d8e2 | https://github.com/spatie/fractalistic/blob/bc588a3207c4166bb685aca0ee44d33c8958d8e2/src/Fractal.php#L142-L153 | train |
spatie/fractalistic | src/Fractal.php | Fractal.parseIncludes | public function parseIncludes($includes)
{
$includes = $this->normalizeIncludesOrExcludes($includes);
$this->includes = array_merge($this->includes, (array) $includes);
return $this;
} | php | public function parseIncludes($includes)
{
$includes = $this->normalizeIncludesOrExcludes($includes);
$this->includes = array_merge($this->includes, (array) $includes);
return $this;
} | [
"public",
"function",
"parseIncludes",
"(",
"$",
"includes",
")",
"{",
"$",
"includes",
"=",
"$",
"this",
"->",
"normalizeIncludesOrExcludes",
"(",
"$",
"includes",
")",
";",
"$",
"this",
"->",
"includes",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"includes",
",",
"(",
"array",
")",
"$",
"includes",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Specify the includes.
@param array|string $includes Array or string of resources to include.
@return $this | [
"Specify",
"the",
"includes",
"."
]
| bc588a3207c4166bb685aca0ee44d33c8958d8e2 | https://github.com/spatie/fractalistic/blob/bc588a3207c4166bb685aca0ee44d33c8958d8e2/src/Fractal.php#L240-L247 | train |
spatie/fractalistic | src/Fractal.php | Fractal.parseExcludes | public function parseExcludes($excludes)
{
$excludes = $this->normalizeIncludesOrExcludes($excludes);
$this->excludes = array_merge($this->excludes, (array) $excludes);
return $this;
} | php | public function parseExcludes($excludes)
{
$excludes = $this->normalizeIncludesOrExcludes($excludes);
$this->excludes = array_merge($this->excludes, (array) $excludes);
return $this;
} | [
"public",
"function",
"parseExcludes",
"(",
"$",
"excludes",
")",
"{",
"$",
"excludes",
"=",
"$",
"this",
"->",
"normalizeIncludesOrExcludes",
"(",
"$",
"excludes",
")",
";",
"$",
"this",
"->",
"excludes",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"excludes",
",",
"(",
"array",
")",
"$",
"excludes",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Specify the excludes.
@param array|string $excludes Array or string of resources to exclude.
@return $this | [
"Specify",
"the",
"excludes",
"."
]
| bc588a3207c4166bb685aca0ee44d33c8958d8e2 | https://github.com/spatie/fractalistic/blob/bc588a3207c4166bb685aca0ee44d33c8958d8e2/src/Fractal.php#L256-L263 | train |
spatie/fractalistic | src/Fractal.php | Fractal.parseFieldsets | public function parseFieldsets(array $fieldsets)
{
foreach ($fieldsets as $key => $fields) {
if (is_array($fields)) {
$fieldsets[$key] = implode(',', $fields);
}
}
$this->fieldsets = array_merge($this->fieldsets, $fieldsets);
return $this;
} | php | public function parseFieldsets(array $fieldsets)
{
foreach ($fieldsets as $key => $fields) {
if (is_array($fields)) {
$fieldsets[$key] = implode(',', $fields);
}
}
$this->fieldsets = array_merge($this->fieldsets, $fieldsets);
return $this;
} | [
"public",
"function",
"parseFieldsets",
"(",
"array",
"$",
"fieldsets",
")",
"{",
"foreach",
"(",
"$",
"fieldsets",
"as",
"$",
"key",
"=>",
"$",
"fields",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"$",
"fieldsets",
"[",
"$",
"key",
"]",
"=",
"implode",
"(",
"','",
",",
"$",
"fields",
")",
";",
"}",
"}",
"$",
"this",
"->",
"fieldsets",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"fieldsets",
",",
"$",
"fieldsets",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Specify the fieldsets to include in the response.
@param array $fieldsets array with key = resourceName and value = fields to include
(array or comma separated string with field names)
@return $this | [
"Specify",
"the",
"fieldsets",
"to",
"include",
"in",
"the",
"response",
"."
]
| bc588a3207c4166bb685aca0ee44d33c8958d8e2 | https://github.com/spatie/fractalistic/blob/bc588a3207c4166bb685aca0ee44d33c8958d8e2/src/Fractal.php#L273-L284 | train |
spatie/fractalistic | src/Fractal.php | Fractal.normalizeIncludesOrExcludes | protected function normalizeIncludesOrExcludes($includesOrExcludes = '')
{
if (! is_string($includesOrExcludes)) {
return $includesOrExcludes;
}
return array_map(function ($value) {
return trim($value);
}, explode(',', $includesOrExcludes));
} | php | protected function normalizeIncludesOrExcludes($includesOrExcludes = '')
{
if (! is_string($includesOrExcludes)) {
return $includesOrExcludes;
}
return array_map(function ($value) {
return trim($value);
}, explode(',', $includesOrExcludes));
} | [
"protected",
"function",
"normalizeIncludesOrExcludes",
"(",
"$",
"includesOrExcludes",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"includesOrExcludes",
")",
")",
"{",
"return",
"$",
"includesOrExcludes",
";",
"}",
"return",
"array_map",
"(",
"function",
"(",
"$",
"value",
")",
"{",
"return",
"trim",
"(",
"$",
"value",
")",
";",
"}",
",",
"explode",
"(",
"','",
",",
"$",
"includesOrExcludes",
")",
")",
";",
"}"
]
| Normalize the includes an excludes.
@param array|string $includesOrExcludes
@return array|string | [
"Normalize",
"the",
"includes",
"an",
"excludes",
"."
]
| bc588a3207c4166bb685aca0ee44d33c8958d8e2 | https://github.com/spatie/fractalistic/blob/bc588a3207c4166bb685aca0ee44d33c8958d8e2/src/Fractal.php#L293-L302 | train |
spatie/fractalistic | src/Fractal.php | Fractal.addMeta | public function addMeta()
{
foreach (func_get_args() as $meta) {
if (is_array($meta)) {
$this->meta += $meta;
}
}
return $this;
} | php | public function addMeta()
{
foreach (func_get_args() as $meta) {
if (is_array($meta)) {
$this->meta += $meta;
}
}
return $this;
} | [
"public",
"function",
"addMeta",
"(",
")",
"{",
"foreach",
"(",
"func_get_args",
"(",
")",
"as",
"$",
"meta",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"meta",
")",
")",
"{",
"$",
"this",
"->",
"meta",
"+=",
"$",
"meta",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| Set the meta data.
@param $array,...
@return $this | [
"Set",
"the",
"meta",
"data",
"."
]
| bc588a3207c4166bb685aca0ee44d33c8958d8e2 | https://github.com/spatie/fractalistic/blob/bc588a3207c4166bb685aca0ee44d33c8958d8e2/src/Fractal.php#L311-L320 | train |
spatie/fractalistic | src/Fractal.php | Fractal.createData | public function createData()
{
if (is_null($this->transformer)) {
throw new NoTransformerSpecified();
}
if (is_string($this->serializer)) {
$this->serializer = new $this->serializer;
}
if (! is_null($this->serializer)) {
$this->manager->setSerializer($this->serializer);
}
$this->manager->setRecursionLimit($this->recursionLimit);
if (! empty($this->includes)) {
$this->manager->parseIncludes($this->includes);
}
if (! empty($this->excludes)) {
$this->manager->parseExcludes($this->excludes);
}
if (! empty($this->fieldsets)) {
$this->manager->parseFieldsets($this->fieldsets);
}
return $this->manager->createData($this->getResource(), $this->resourceName);
} | php | public function createData()
{
if (is_null($this->transformer)) {
throw new NoTransformerSpecified();
}
if (is_string($this->serializer)) {
$this->serializer = new $this->serializer;
}
if (! is_null($this->serializer)) {
$this->manager->setSerializer($this->serializer);
}
$this->manager->setRecursionLimit($this->recursionLimit);
if (! empty($this->includes)) {
$this->manager->parseIncludes($this->includes);
}
if (! empty($this->excludes)) {
$this->manager->parseExcludes($this->excludes);
}
if (! empty($this->fieldsets)) {
$this->manager->parseFieldsets($this->fieldsets);
}
return $this->manager->createData($this->getResource(), $this->resourceName);
} | [
"public",
"function",
"createData",
"(",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"this",
"->",
"transformer",
")",
")",
"{",
"throw",
"new",
"NoTransformerSpecified",
"(",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"serializer",
")",
")",
"{",
"$",
"this",
"->",
"serializer",
"=",
"new",
"$",
"this",
"->",
"serializer",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"serializer",
")",
")",
"{",
"$",
"this",
"->",
"manager",
"->",
"setSerializer",
"(",
"$",
"this",
"->",
"serializer",
")",
";",
"}",
"$",
"this",
"->",
"manager",
"->",
"setRecursionLimit",
"(",
"$",
"this",
"->",
"recursionLimit",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"includes",
")",
")",
"{",
"$",
"this",
"->",
"manager",
"->",
"parseIncludes",
"(",
"$",
"this",
"->",
"includes",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"excludes",
")",
")",
"{",
"$",
"this",
"->",
"manager",
"->",
"parseExcludes",
"(",
"$",
"this",
"->",
"excludes",
")",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"fieldsets",
")",
")",
"{",
"$",
"this",
"->",
"manager",
"->",
"parseFieldsets",
"(",
"$",
"this",
"->",
"fieldsets",
")",
";",
"}",
"return",
"$",
"this",
"->",
"manager",
"->",
"createData",
"(",
"$",
"this",
"->",
"getResource",
"(",
")",
",",
"$",
"this",
"->",
"resourceName",
")",
";",
"}"
]
| Create fractal data.
@return \League\Fractal\Scope
@throws \Spatie\Fractalistic\Exceptions\InvalidTransformation
@throws \Spatie\Fractalistic\Exceptions\NoTransformerSpecified | [
"Create",
"fractal",
"data",
"."
]
| bc588a3207c4166bb685aca0ee44d33c8958d8e2 | https://github.com/spatie/fractalistic/blob/bc588a3207c4166bb685aca0ee44d33c8958d8e2/src/Fractal.php#L380-L409 | train |
spatie/fractalistic | src/Fractal.php | Fractal.getResource | public function getResource()
{
$resourceClass = 'League\\Fractal\\Resource\\'.ucfirst($this->dataType);
if (! class_exists($resourceClass)) {
throw new InvalidTransformation();
}
if (is_string($this->transformer)) {
$this->transformer = new $this->transformer;
}
$resource = new $resourceClass($this->data, $this->transformer, $this->resourceName);
$resource->setMeta($this->meta);
if (! is_null($this->paginator)) {
$resource->setPaginator($this->paginator);
}
if (! is_null($this->cursor)) {
$resource->setCursor($this->cursor);
}
return $resource;
} | php | public function getResource()
{
$resourceClass = 'League\\Fractal\\Resource\\'.ucfirst($this->dataType);
if (! class_exists($resourceClass)) {
throw new InvalidTransformation();
}
if (is_string($this->transformer)) {
$this->transformer = new $this->transformer;
}
$resource = new $resourceClass($this->data, $this->transformer, $this->resourceName);
$resource->setMeta($this->meta);
if (! is_null($this->paginator)) {
$resource->setPaginator($this->paginator);
}
if (! is_null($this->cursor)) {
$resource->setCursor($this->cursor);
}
return $resource;
} | [
"public",
"function",
"getResource",
"(",
")",
"{",
"$",
"resourceClass",
"=",
"'League\\\\Fractal\\\\Resource\\\\'",
".",
"ucfirst",
"(",
"$",
"this",
"->",
"dataType",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"resourceClass",
")",
")",
"{",
"throw",
"new",
"InvalidTransformation",
"(",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"this",
"->",
"transformer",
")",
")",
"{",
"$",
"this",
"->",
"transformer",
"=",
"new",
"$",
"this",
"->",
"transformer",
";",
"}",
"$",
"resource",
"=",
"new",
"$",
"resourceClass",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"this",
"->",
"transformer",
",",
"$",
"this",
"->",
"resourceName",
")",
";",
"$",
"resource",
"->",
"setMeta",
"(",
"$",
"this",
"->",
"meta",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"paginator",
")",
")",
"{",
"$",
"resource",
"->",
"setPaginator",
"(",
"$",
"this",
"->",
"paginator",
")",
";",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"cursor",
")",
")",
"{",
"$",
"resource",
"->",
"setCursor",
"(",
"$",
"this",
"->",
"cursor",
")",
";",
"}",
"return",
"$",
"resource",
";",
"}"
]
| Get the resource.
@return \League\Fractal\Resource\ResourceInterface
@throws \Spatie\Fractalistic\Exceptions\InvalidTransformation | [
"Get",
"the",
"resource",
"."
]
| bc588a3207c4166bb685aca0ee44d33c8958d8e2 | https://github.com/spatie/fractalistic/blob/bc588a3207c4166bb685aca0ee44d33c8958d8e2/src/Fractal.php#L418-L443 | train |
dwightwatson/sitemap | src/Watson/Sitemap/Sitemap.php | Sitemap.addSitemap | public function addSitemap($location, $lastModified = null)
{
$sitemap = $location instanceof SitemapTag ? $location : new SitemapTag($location, $lastModified);
$this->sitemaps[] = $sitemap;
} | php | public function addSitemap($location, $lastModified = null)
{
$sitemap = $location instanceof SitemapTag ? $location : new SitemapTag($location, $lastModified);
$this->sitemaps[] = $sitemap;
} | [
"public",
"function",
"addSitemap",
"(",
"$",
"location",
",",
"$",
"lastModified",
"=",
"null",
")",
"{",
"$",
"sitemap",
"=",
"$",
"location",
"instanceof",
"SitemapTag",
"?",
"$",
"location",
":",
"new",
"SitemapTag",
"(",
"$",
"location",
",",
"$",
"lastModified",
")",
";",
"$",
"this",
"->",
"sitemaps",
"[",
"]",
"=",
"$",
"sitemap",
";",
"}"
]
| Add new sitemap to the sitemaps index.
@param \Watson\Sitemap\Tags\Sitemap|string $location
@param \DateTime|string $lastModified
@return void | [
"Add",
"new",
"sitemap",
"to",
"the",
"sitemaps",
"index",
"."
]
| 835db7342ddd40fb63c8e9b7982f623c9eb00e1b | https://github.com/dwightwatson/sitemap/blob/835db7342ddd40fb63c8e9b7982f623c9eb00e1b/src/Watson/Sitemap/Sitemap.php#L62-L67 | train |
dwightwatson/sitemap | src/Watson/Sitemap/Sitemap.php | Sitemap.index | public function index()
{
if ($cachedView = $this->getCachedView()) {
return response()->make($cachedView, 200, ['Content-type' => 'text/xml']);
}
$sitemapIndex = response()->view('sitemap::sitemaps', ['__sitemaps' => $this->getSitemaps()], 200, ['Content-type' => 'text/xml']);
$this->saveCachedView($sitemapIndex);
return $sitemapIndex;
} | php | public function index()
{
if ($cachedView = $this->getCachedView()) {
return response()->make($cachedView, 200, ['Content-type' => 'text/xml']);
}
$sitemapIndex = response()->view('sitemap::sitemaps', ['__sitemaps' => $this->getSitemaps()], 200, ['Content-type' => 'text/xml']);
$this->saveCachedView($sitemapIndex);
return $sitemapIndex;
} | [
"public",
"function",
"index",
"(",
")",
"{",
"if",
"(",
"$",
"cachedView",
"=",
"$",
"this",
"->",
"getCachedView",
"(",
")",
")",
"{",
"return",
"response",
"(",
")",
"->",
"make",
"(",
"$",
"cachedView",
",",
"200",
",",
"[",
"'Content-type'",
"=>",
"'text/xml'",
"]",
")",
";",
"}",
"$",
"sitemapIndex",
"=",
"response",
"(",
")",
"->",
"view",
"(",
"'sitemap::sitemaps'",
",",
"[",
"'__sitemaps'",
"=>",
"$",
"this",
"->",
"getSitemaps",
"(",
")",
"]",
",",
"200",
",",
"[",
"'Content-type'",
"=>",
"'text/xml'",
"]",
")",
";",
"$",
"this",
"->",
"saveCachedView",
"(",
"$",
"sitemapIndex",
")",
";",
"return",
"$",
"sitemapIndex",
";",
"}"
]
| Render an index of sitemaps.
@return \Illuminate\Http\Response | [
"Render",
"an",
"index",
"of",
"sitemaps",
"."
]
| 835db7342ddd40fb63c8e9b7982f623c9eb00e1b | https://github.com/dwightwatson/sitemap/blob/835db7342ddd40fb63c8e9b7982f623c9eb00e1b/src/Watson/Sitemap/Sitemap.php#L84-L95 | train |
dwightwatson/sitemap | src/Watson/Sitemap/Sitemap.php | Sitemap.addTag | public function addTag($location, $lastModified = null, $changeFrequency = null, $priority = null)
{
$tag = $location instanceof Tag ? $location : new Tag($location, $lastModified, $changeFrequency, $priority);
$this->tags[] = $tag;
return $tag;
} | php | public function addTag($location, $lastModified = null, $changeFrequency = null, $priority = null)
{
$tag = $location instanceof Tag ? $location : new Tag($location, $lastModified, $changeFrequency, $priority);
$this->tags[] = $tag;
return $tag;
} | [
"public",
"function",
"addTag",
"(",
"$",
"location",
",",
"$",
"lastModified",
"=",
"null",
",",
"$",
"changeFrequency",
"=",
"null",
",",
"$",
"priority",
"=",
"null",
")",
"{",
"$",
"tag",
"=",
"$",
"location",
"instanceof",
"Tag",
"?",
"$",
"location",
":",
"new",
"Tag",
"(",
"$",
"location",
",",
"$",
"lastModified",
",",
"$",
"changeFrequency",
",",
"$",
"priority",
")",
";",
"$",
"this",
"->",
"tags",
"[",
"]",
"=",
"$",
"tag",
";",
"return",
"$",
"tag",
";",
"}"
]
| Add a new sitemap tag to the sitemap.
@param \Watson\Sitemap\Tags\Tag|string $location
@param \DateTime|string $lastModified
@param string $changeFrequency
@param string $priority
@return \Watson\Sitemap\Tags\Tag | [
"Add",
"a",
"new",
"sitemap",
"tag",
"to",
"the",
"sitemap",
"."
]
| 835db7342ddd40fb63c8e9b7982f623c9eb00e1b | https://github.com/dwightwatson/sitemap/blob/835db7342ddd40fb63c8e9b7982f623c9eb00e1b/src/Watson/Sitemap/Sitemap.php#L116-L123 | train |
dwightwatson/sitemap | src/Watson/Sitemap/Sitemap.php | Sitemap.addExpiredTag | public function addExpiredTag($location, $expired = null)
{
$tag = $location instanceof ExpiredTag ? $location : new ExpiredTag($location, $expired);
$this->tags[] = $tag;
} | php | public function addExpiredTag($location, $expired = null)
{
$tag = $location instanceof ExpiredTag ? $location : new ExpiredTag($location, $expired);
$this->tags[] = $tag;
} | [
"public",
"function",
"addExpiredTag",
"(",
"$",
"location",
",",
"$",
"expired",
"=",
"null",
")",
"{",
"$",
"tag",
"=",
"$",
"location",
"instanceof",
"ExpiredTag",
"?",
"$",
"location",
":",
"new",
"ExpiredTag",
"(",
"$",
"location",
",",
"$",
"expired",
")",
";",
"$",
"this",
"->",
"tags",
"[",
"]",
"=",
"$",
"tag",
";",
"}"
]
| Add a new expired tag to the sitemap.
@param string $location
@param \DateTime|string $expired
@return void | [
"Add",
"a",
"new",
"expired",
"tag",
"to",
"the",
"sitemap",
"."
]
| 835db7342ddd40fb63c8e9b7982f623c9eb00e1b | https://github.com/dwightwatson/sitemap/blob/835db7342ddd40fb63c8e9b7982f623c9eb00e1b/src/Watson/Sitemap/Sitemap.php#L132-L137 | train |
dwightwatson/sitemap | src/Watson/Sitemap/Sitemap.php | Sitemap.render | public function render()
{
if ($cachedView = $this->getCachedView()) {
return response()->make($cachedView, 200, ['Content-type' => 'text/xml']);
}
$sitemap = response()->view('sitemap::sitemap', [
'__tags' => $this->getTags(),
'__hasImages' => $this->imagesPresent(),
'__hasVideos' => $this->videosPresent(),
'__isMultilingual' => $this->multilingualTagsPresent()
], 200, ['Content-type' => 'text/xml']);
$this->saveCachedView($sitemap);
return $sitemap;
} | php | public function render()
{
if ($cachedView = $this->getCachedView()) {
return response()->make($cachedView, 200, ['Content-type' => 'text/xml']);
}
$sitemap = response()->view('sitemap::sitemap', [
'__tags' => $this->getTags(),
'__hasImages' => $this->imagesPresent(),
'__hasVideos' => $this->videosPresent(),
'__isMultilingual' => $this->multilingualTagsPresent()
], 200, ['Content-type' => 'text/xml']);
$this->saveCachedView($sitemap);
return $sitemap;
} | [
"public",
"function",
"render",
"(",
")",
"{",
"if",
"(",
"$",
"cachedView",
"=",
"$",
"this",
"->",
"getCachedView",
"(",
")",
")",
"{",
"return",
"response",
"(",
")",
"->",
"make",
"(",
"$",
"cachedView",
",",
"200",
",",
"[",
"'Content-type'",
"=>",
"'text/xml'",
"]",
")",
";",
"}",
"$",
"sitemap",
"=",
"response",
"(",
")",
"->",
"view",
"(",
"'sitemap::sitemap'",
",",
"[",
"'__tags'",
"=>",
"$",
"this",
"->",
"getTags",
"(",
")",
",",
"'__hasImages'",
"=>",
"$",
"this",
"->",
"imagesPresent",
"(",
")",
",",
"'__hasVideos'",
"=>",
"$",
"this",
"->",
"videosPresent",
"(",
")",
",",
"'__isMultilingual'",
"=>",
"$",
"this",
"->",
"multilingualTagsPresent",
"(",
")",
"]",
",",
"200",
",",
"[",
"'Content-type'",
"=>",
"'text/xml'",
"]",
")",
";",
"$",
"this",
"->",
"saveCachedView",
"(",
"$",
"sitemap",
")",
";",
"return",
"$",
"sitemap",
";",
"}"
]
| Render a sitemap.
@return \Illuminate\Http\Response | [
"Render",
"a",
"sitemap",
"."
]
| 835db7342ddd40fb63c8e9b7982f623c9eb00e1b | https://github.com/dwightwatson/sitemap/blob/835db7342ddd40fb63c8e9b7982f623c9eb00e1b/src/Watson/Sitemap/Sitemap.php#L174-L190 | train |
dwightwatson/sitemap | src/Watson/Sitemap/Sitemap.php | Sitemap.hasCachedView | public function hasCachedView()
{
if (config('sitemap.cache_enabled')) {
$key = $this->getCacheKey();
return $this->cache->has($key);
}
return false;
} | php | public function hasCachedView()
{
if (config('sitemap.cache_enabled')) {
$key = $this->getCacheKey();
return $this->cache->has($key);
}
return false;
} | [
"public",
"function",
"hasCachedView",
"(",
")",
"{",
"if",
"(",
"config",
"(",
"'sitemap.cache_enabled'",
")",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getCacheKey",
"(",
")",
";",
"return",
"$",
"this",
"->",
"cache",
"->",
"has",
"(",
"$",
"key",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| Check whether the sitemap has a cached view or not.
@return bool | [
"Check",
"whether",
"the",
"sitemap",
"has",
"a",
"cached",
"view",
"or",
"not",
"."
]
| 835db7342ddd40fb63c8e9b7982f623c9eb00e1b | https://github.com/dwightwatson/sitemap/blob/835db7342ddd40fb63c8e9b7982f623c9eb00e1b/src/Watson/Sitemap/Sitemap.php#L237-L246 | train |
dwightwatson/sitemap | src/Watson/Sitemap/Sitemap.php | Sitemap.getCachedView | protected function getCachedView()
{
if ($this->hasCachedView()) {
$key = $this->getCacheKey();
return $this->cache->get($key);
}
return false;
} | php | protected function getCachedView()
{
if ($this->hasCachedView()) {
$key = $this->getCacheKey();
return $this->cache->get($key);
}
return false;
} | [
"protected",
"function",
"getCachedView",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasCachedView",
"(",
")",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getCacheKey",
"(",
")",
";",
"return",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"$",
"key",
")",
";",
"}",
"return",
"false",
";",
"}"
]
| Check to see whether a view has already been cached for the current
route and if so, return it.
@return mixed | [
"Check",
"to",
"see",
"whether",
"a",
"view",
"has",
"already",
"been",
"cached",
"for",
"the",
"current",
"route",
"and",
"if",
"so",
"return",
"it",
"."
]
| 835db7342ddd40fb63c8e9b7982f623c9eb00e1b | https://github.com/dwightwatson/sitemap/blob/835db7342ddd40fb63c8e9b7982f623c9eb00e1b/src/Watson/Sitemap/Sitemap.php#L302-L311 | train |
dwightwatson/sitemap | src/Watson/Sitemap/Sitemap.php | Sitemap.saveCachedView | protected function saveCachedView(Response $response)
{
if (config('sitemap.cache_enabled')) {
$key = $this->getCacheKey();
$content = $response->getOriginalContent()->render();
if (!$this->cache->get($key)) {
$this->cache->put($key, $content, config('sitemap.cache_length'));
}
}
} | php | protected function saveCachedView(Response $response)
{
if (config('sitemap.cache_enabled')) {
$key = $this->getCacheKey();
$content = $response->getOriginalContent()->render();
if (!$this->cache->get($key)) {
$this->cache->put($key, $content, config('sitemap.cache_length'));
}
}
} | [
"protected",
"function",
"saveCachedView",
"(",
"Response",
"$",
"response",
")",
"{",
"if",
"(",
"config",
"(",
"'sitemap.cache_enabled'",
")",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getCacheKey",
"(",
")",
";",
"$",
"content",
"=",
"$",
"response",
"->",
"getOriginalContent",
"(",
")",
"->",
"render",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"cache",
"->",
"get",
"(",
"$",
"key",
")",
")",
"{",
"$",
"this",
"->",
"cache",
"->",
"put",
"(",
"$",
"key",
",",
"$",
"content",
",",
"config",
"(",
"'sitemap.cache_length'",
")",
")",
";",
"}",
"}",
"}"
]
| Save a cached view if caching is enabled.
@param \Illuminate\Http\Response $response
@return void | [
"Save",
"a",
"cached",
"view",
"if",
"caching",
"is",
"enabled",
"."
]
| 835db7342ddd40fb63c8e9b7982f623c9eb00e1b | https://github.com/dwightwatson/sitemap/blob/835db7342ddd40fb63c8e9b7982f623c9eb00e1b/src/Watson/Sitemap/Sitemap.php#L319-L330 | train |
dwightwatson/sitemap | src/Watson/Sitemap/Tags/BaseTag.php | BaseTag.setLastModified | public function setLastModified($lastModified)
{
if ($lastModified instanceof DateTime) {
$this->lastModified = $lastModified;
return;
} elseif ($lastModified instanceof Model) {
$this->lastModified = $lastModified->updated_at;
return;
}
$this->lastModified = new DateTime($lastModified);
} | php | public function setLastModified($lastModified)
{
if ($lastModified instanceof DateTime) {
$this->lastModified = $lastModified;
return;
} elseif ($lastModified instanceof Model) {
$this->lastModified = $lastModified->updated_at;
return;
}
$this->lastModified = new DateTime($lastModified);
} | [
"public",
"function",
"setLastModified",
"(",
"$",
"lastModified",
")",
"{",
"if",
"(",
"$",
"lastModified",
"instanceof",
"DateTime",
")",
"{",
"$",
"this",
"->",
"lastModified",
"=",
"$",
"lastModified",
";",
"return",
";",
"}",
"elseif",
"(",
"$",
"lastModified",
"instanceof",
"Model",
")",
"{",
"$",
"this",
"->",
"lastModified",
"=",
"$",
"lastModified",
"->",
"updated_at",
";",
"return",
";",
"}",
"$",
"this",
"->",
"lastModified",
"=",
"new",
"DateTime",
"(",
"$",
"lastModified",
")",
";",
"}"
]
| Set the last modified timestamp.
@param \DateTime|string $lastModified
@return void | [
"Set",
"the",
"last",
"modified",
"timestamp",
"."
]
| 835db7342ddd40fb63c8e9b7982f623c9eb00e1b | https://github.com/dwightwatson/sitemap/blob/835db7342ddd40fb63c8e9b7982f623c9eb00e1b/src/Watson/Sitemap/Tags/BaseTag.php#L102-L113 | train |
dwightwatson/sitemap | src/Watson/Sitemap/Tags/BaseTag.php | BaseTag.addImage | public function addImage($location, $caption = null, $geoLocation = null, $title = null, $license = null)
{
$image = $location instanceof ImageTag ? $location : new ImageTag($location, $caption, $geoLocation, $title, $license);
$this->images[] = $image;
} | php | public function addImage($location, $caption = null, $geoLocation = null, $title = null, $license = null)
{
$image = $location instanceof ImageTag ? $location : new ImageTag($location, $caption, $geoLocation, $title, $license);
$this->images[] = $image;
} | [
"public",
"function",
"addImage",
"(",
"$",
"location",
",",
"$",
"caption",
"=",
"null",
",",
"$",
"geoLocation",
"=",
"null",
",",
"$",
"title",
"=",
"null",
",",
"$",
"license",
"=",
"null",
")",
"{",
"$",
"image",
"=",
"$",
"location",
"instanceof",
"ImageTag",
"?",
"$",
"location",
":",
"new",
"ImageTag",
"(",
"$",
"location",
",",
"$",
"caption",
",",
"$",
"geoLocation",
",",
"$",
"title",
",",
"$",
"license",
")",
";",
"$",
"this",
"->",
"images",
"[",
"]",
"=",
"$",
"image",
";",
"}"
]
| Add an image tag to the tag.
@param string $location
@param string $caption
@param string $geo_location
@param string $title
@param string $license
@return void | [
"Add",
"an",
"image",
"tag",
"to",
"the",
"tag",
"."
]
| 835db7342ddd40fb63c8e9b7982f623c9eb00e1b | https://github.com/dwightwatson/sitemap/blob/835db7342ddd40fb63c8e9b7982f623c9eb00e1b/src/Watson/Sitemap/Tags/BaseTag.php#L125-L130 | train |
dwightwatson/sitemap | src/Watson/Sitemap/Tags/BaseTag.php | BaseTag.addVideo | public function addVideo($location, $title = null, $description = null, $thumbnailLocation = null)
{
$video = $location instanceof VideoTag ? $location : new VideoTag($location, $title, $description, $thumbnailLocation);
$this->videos[] = $video;
} | php | public function addVideo($location, $title = null, $description = null, $thumbnailLocation = null)
{
$video = $location instanceof VideoTag ? $location : new VideoTag($location, $title, $description, $thumbnailLocation);
$this->videos[] = $video;
} | [
"public",
"function",
"addVideo",
"(",
"$",
"location",
",",
"$",
"title",
"=",
"null",
",",
"$",
"description",
"=",
"null",
",",
"$",
"thumbnailLocation",
"=",
"null",
")",
"{",
"$",
"video",
"=",
"$",
"location",
"instanceof",
"VideoTag",
"?",
"$",
"location",
":",
"new",
"VideoTag",
"(",
"$",
"location",
",",
"$",
"title",
",",
"$",
"description",
",",
"$",
"thumbnailLocation",
")",
";",
"$",
"this",
"->",
"videos",
"[",
"]",
"=",
"$",
"video",
";",
"}"
]
| Add a video tag to the tag.
@param string $location
@param string $title
@param string $description
@param string $thumbnailLocation
@return void | [
"Add",
"a",
"video",
"tag",
"to",
"the",
"tag",
"."
]
| 835db7342ddd40fb63c8e9b7982f623c9eb00e1b | https://github.com/dwightwatson/sitemap/blob/835db7342ddd40fb63c8e9b7982f623c9eb00e1b/src/Watson/Sitemap/Tags/BaseTag.php#L141-L146 | train |
dwightwatson/sitemap | src/Watson/Sitemap/Tags/ExpiredTag.php | ExpiredTag.setExpired | public function setExpired($expired)
{
if ($expired instanceof DateTime) {
$this->expired = $expired;
return;
} elseif ($expired instanceof Model) {
$this->expired = $expired->deleted_at ?: $expired->updated_at;
return;
}
$this->expired = new DateTime($expired);
} | php | public function setExpired($expired)
{
if ($expired instanceof DateTime) {
$this->expired = $expired;
return;
} elseif ($expired instanceof Model) {
$this->expired = $expired->deleted_at ?: $expired->updated_at;
return;
}
$this->expired = new DateTime($expired);
} | [
"public",
"function",
"setExpired",
"(",
"$",
"expired",
")",
"{",
"if",
"(",
"$",
"expired",
"instanceof",
"DateTime",
")",
"{",
"$",
"this",
"->",
"expired",
"=",
"$",
"expired",
";",
"return",
";",
"}",
"elseif",
"(",
"$",
"expired",
"instanceof",
"Model",
")",
"{",
"$",
"this",
"->",
"expired",
"=",
"$",
"expired",
"->",
"deleted_at",
"?",
":",
"$",
"expired",
"->",
"updated_at",
";",
"return",
";",
"}",
"$",
"this",
"->",
"expired",
"=",
"new",
"DateTime",
"(",
"$",
"expired",
")",
";",
"}"
]
| Set the expiration date
@param \DateTime|string $expired
@return void | [
"Set",
"the",
"expiration",
"date"
]
| 835db7342ddd40fb63c8e9b7982f623c9eb00e1b | https://github.com/dwightwatson/sitemap/blob/835db7342ddd40fb63c8e9b7982f623c9eb00e1b/src/Watson/Sitemap/Tags/ExpiredTag.php#L55-L66 | train |
BluePsyduck/MultiCurl | src/MultiCurlManager.php | MultiCurlManager.executeNextWaitingRequest | protected function executeNextWaitingRequest()
{
if (($this->numberOfParallelRequests === 0 || count($this->runningRequests) < $this->numberOfParallelRequests)
&& count($this->waitingRequests) > 0
) {
$this->executeRequest(reset($this->waitingRequests));
}
return $this;
} | php | protected function executeNextWaitingRequest()
{
if (($this->numberOfParallelRequests === 0 || count($this->runningRequests) < $this->numberOfParallelRequests)
&& count($this->waitingRequests) > 0
) {
$this->executeRequest(reset($this->waitingRequests));
}
return $this;
} | [
"protected",
"function",
"executeNextWaitingRequest",
"(",
")",
"{",
"if",
"(",
"(",
"$",
"this",
"->",
"numberOfParallelRequests",
"===",
"0",
"||",
"count",
"(",
"$",
"this",
"->",
"runningRequests",
")",
"<",
"$",
"this",
"->",
"numberOfParallelRequests",
")",
"&&",
"count",
"(",
"$",
"this",
"->",
"waitingRequests",
")",
">",
"0",
")",
"{",
"$",
"this",
"->",
"executeRequest",
"(",
"reset",
"(",
"$",
"this",
"->",
"waitingRequests",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Executes the next waiting request, if there is still one to be executed.
@return $this | [
"Executes",
"the",
"next",
"waiting",
"request",
"if",
"there",
"is",
"still",
"one",
"to",
"be",
"executed",
"."
]
| 9b80a1e59ab21106073effc029aaeb7aa13e2964 | https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/MultiCurlManager.php#L78-L86 | train |
BluePsyduck/MultiCurl | src/MultiCurlManager.php | MultiCurlManager.executeRequest | protected function executeRequest(Request $request)
{
$index = array_search($request, $this->waitingRequests);
if ($index !== false) {
unset($this->waitingRequests[$index]);
$this->hydrateCurlFromRequest($request, $request->getCurl())
->triggerCallback($request->getOnInitializeCallback(), $request);
$this->multiCurl->addCurl($request->getCurl());
$this->runningRequests[] = $request;
$this->executeMultiCurl();
}
return $this;
} | php | protected function executeRequest(Request $request)
{
$index = array_search($request, $this->waitingRequests);
if ($index !== false) {
unset($this->waitingRequests[$index]);
$this->hydrateCurlFromRequest($request, $request->getCurl())
->triggerCallback($request->getOnInitializeCallback(), $request);
$this->multiCurl->addCurl($request->getCurl());
$this->runningRequests[] = $request;
$this->executeMultiCurl();
}
return $this;
} | [
"protected",
"function",
"executeRequest",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"index",
"=",
"array_search",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"waitingRequests",
")",
";",
"if",
"(",
"$",
"index",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"waitingRequests",
"[",
"$",
"index",
"]",
")",
";",
"$",
"this",
"->",
"hydrateCurlFromRequest",
"(",
"$",
"request",
",",
"$",
"request",
"->",
"getCurl",
"(",
")",
")",
"->",
"triggerCallback",
"(",
"$",
"request",
"->",
"getOnInitializeCallback",
"(",
")",
",",
"$",
"request",
")",
";",
"$",
"this",
"->",
"multiCurl",
"->",
"addCurl",
"(",
"$",
"request",
"->",
"getCurl",
"(",
")",
")",
";",
"$",
"this",
"->",
"runningRequests",
"[",
"]",
"=",
"$",
"request",
";",
"$",
"this",
"->",
"executeMultiCurl",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Executes the specified request, if it is still waiting.
@param Request $request
@return $this | [
"Executes",
"the",
"specified",
"request",
"if",
"it",
"is",
"still",
"waiting",
"."
]
| 9b80a1e59ab21106073effc029aaeb7aa13e2964 | https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/MultiCurlManager.php#L93-L106 | train |
BluePsyduck/MultiCurl | src/MultiCurlManager.php | MultiCurlManager.hydrateCurlFromRequest | protected function hydrateCurlFromRequest(Request $request, Curl $curl)
{
$curl->setOption(CURLOPT_CUSTOMREQUEST, $request->getMethod())
->setOption(CURLOPT_URL, $request->getUrl())
->setOption(CURLOPT_RETURNTRANSFER, true)
->setOption(CURLOPT_HEADER, true)
->setOption(CURLOPT_FOLLOWLOCATION, true)
->setOption(CURLOPT_HTTPHEADER, $this->prepareRequestHeader($request->getHeader()));
if (strlen($request->getRequestData()) > 0) {
$curl->setOption(CURLOPT_POSTFIELDS, $request->getRequestData());
}
if ($request->getTimeout() > 0) {
$curl->setOption(CURLOPT_TIMEOUT, $request->getTimeout());
}
if ($request->getBasicAuthUsername() && $request->getBasicAuthPassword()) {
$credentials = $request->getBasicAuthUsername() . ':' . $request->getBasicAuthPassword();
$curl->setOption(CURLOPT_USERPWD, $credentials);
}
return $this;
} | php | protected function hydrateCurlFromRequest(Request $request, Curl $curl)
{
$curl->setOption(CURLOPT_CUSTOMREQUEST, $request->getMethod())
->setOption(CURLOPT_URL, $request->getUrl())
->setOption(CURLOPT_RETURNTRANSFER, true)
->setOption(CURLOPT_HEADER, true)
->setOption(CURLOPT_FOLLOWLOCATION, true)
->setOption(CURLOPT_HTTPHEADER, $this->prepareRequestHeader($request->getHeader()));
if (strlen($request->getRequestData()) > 0) {
$curl->setOption(CURLOPT_POSTFIELDS, $request->getRequestData());
}
if ($request->getTimeout() > 0) {
$curl->setOption(CURLOPT_TIMEOUT, $request->getTimeout());
}
if ($request->getBasicAuthUsername() && $request->getBasicAuthPassword()) {
$credentials = $request->getBasicAuthUsername() . ':' . $request->getBasicAuthPassword();
$curl->setOption(CURLOPT_USERPWD, $credentials);
}
return $this;
} | [
"protected",
"function",
"hydrateCurlFromRequest",
"(",
"Request",
"$",
"request",
",",
"Curl",
"$",
"curl",
")",
"{",
"$",
"curl",
"->",
"setOption",
"(",
"CURLOPT_CUSTOMREQUEST",
",",
"$",
"request",
"->",
"getMethod",
"(",
")",
")",
"->",
"setOption",
"(",
"CURLOPT_URL",
",",
"$",
"request",
"->",
"getUrl",
"(",
")",
")",
"->",
"setOption",
"(",
"CURLOPT_RETURNTRANSFER",
",",
"true",
")",
"->",
"setOption",
"(",
"CURLOPT_HEADER",
",",
"true",
")",
"->",
"setOption",
"(",
"CURLOPT_FOLLOWLOCATION",
",",
"true",
")",
"->",
"setOption",
"(",
"CURLOPT_HTTPHEADER",
",",
"$",
"this",
"->",
"prepareRequestHeader",
"(",
"$",
"request",
"->",
"getHeader",
"(",
")",
")",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"request",
"->",
"getRequestData",
"(",
")",
")",
">",
"0",
")",
"{",
"$",
"curl",
"->",
"setOption",
"(",
"CURLOPT_POSTFIELDS",
",",
"$",
"request",
"->",
"getRequestData",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"request",
"->",
"getTimeout",
"(",
")",
">",
"0",
")",
"{",
"$",
"curl",
"->",
"setOption",
"(",
"CURLOPT_TIMEOUT",
",",
"$",
"request",
"->",
"getTimeout",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"request",
"->",
"getBasicAuthUsername",
"(",
")",
"&&",
"$",
"request",
"->",
"getBasicAuthPassword",
"(",
")",
")",
"{",
"$",
"credentials",
"=",
"$",
"request",
"->",
"getBasicAuthUsername",
"(",
")",
".",
"':'",
".",
"$",
"request",
"->",
"getBasicAuthPassword",
"(",
")",
";",
"$",
"curl",
"->",
"setOption",
"(",
"CURLOPT_USERPWD",
",",
"$",
"credentials",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Hydrates the cURL instance with the data from the specified request.
@param Request $request
@param Curl $curl
@return $this Implementing fluent interface. | [
"Hydrates",
"the",
"cURL",
"instance",
"with",
"the",
"data",
"from",
"the",
"specified",
"request",
"."
]
| 9b80a1e59ab21106073effc029aaeb7aa13e2964 | https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/MultiCurlManager.php#L114-L134 | train |
BluePsyduck/MultiCurl | src/MultiCurlManager.php | MultiCurlManager.prepareRequestHeader | protected function prepareRequestHeader(Header $header): array
{
$result = [];
foreach ($header as $name => $value) {
$result[] = $name . ': ' . $value;
}
return $result;
} | php | protected function prepareRequestHeader(Header $header): array
{
$result = [];
foreach ($header as $name => $value) {
$result[] = $name . ': ' . $value;
}
return $result;
} | [
"protected",
"function",
"prepareRequestHeader",
"(",
"Header",
"$",
"header",
")",
":",
"array",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"header",
"as",
"$",
"name",
"=>",
"$",
"value",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"name",
".",
"': '",
".",
"$",
"value",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| Prepares the header for the request.
@param Header $header
@return array|string[] | [
"Prepares",
"the",
"header",
"for",
"the",
"request",
"."
]
| 9b80a1e59ab21106073effc029aaeb7aa13e2964 | https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/MultiCurlManager.php#L141-L148 | train |
BluePsyduck/MultiCurl | src/MultiCurlManager.php | MultiCurlManager.executeMultiCurl | protected function executeMultiCurl()
{
do {
$this->multiCurl->execute();
$this->checkStatusMessages();
} while ($this->multiCurl->getCurrentExecutionCode() === CURLM_CALL_MULTI_PERFORM);
return $this;
} | php | protected function executeMultiCurl()
{
do {
$this->multiCurl->execute();
$this->checkStatusMessages();
} while ($this->multiCurl->getCurrentExecutionCode() === CURLM_CALL_MULTI_PERFORM);
return $this;
} | [
"protected",
"function",
"executeMultiCurl",
"(",
")",
"{",
"do",
"{",
"$",
"this",
"->",
"multiCurl",
"->",
"execute",
"(",
")",
";",
"$",
"this",
"->",
"checkStatusMessages",
"(",
")",
";",
"}",
"while",
"(",
"$",
"this",
"->",
"multiCurl",
"->",
"getCurrentExecutionCode",
"(",
")",
"===",
"CURLM_CALL_MULTI_PERFORM",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Executes the requests of the multi cUrl.
@return $this Implementing fluent interface. | [
"Executes",
"the",
"requests",
"of",
"the",
"multi",
"cUrl",
"."
]
| 9b80a1e59ab21106073effc029aaeb7aa13e2964 | https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/MultiCurlManager.php#L154-L161 | train |
BluePsyduck/MultiCurl | src/MultiCurlManager.php | MultiCurlManager.checkStatusMessages | protected function checkStatusMessages()
{
while (($message = $this->multiCurl->readInfo()) !== false) {
$this->processCurlResponse((int) $message['result'], $message['handle'])
->executeNextWaitingRequest();
}
return $this;
} | php | protected function checkStatusMessages()
{
while (($message = $this->multiCurl->readInfo()) !== false) {
$this->processCurlResponse((int) $message['result'], $message['handle'])
->executeNextWaitingRequest();
}
return $this;
} | [
"protected",
"function",
"checkStatusMessages",
"(",
")",
"{",
"while",
"(",
"(",
"$",
"message",
"=",
"$",
"this",
"->",
"multiCurl",
"->",
"readInfo",
"(",
")",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"processCurlResponse",
"(",
"(",
"int",
")",
"$",
"message",
"[",
"'result'",
"]",
",",
"$",
"message",
"[",
"'handle'",
"]",
")",
"->",
"executeNextWaitingRequest",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Checks for any waiting status messages of the cURL requests.
@return $this | [
"Checks",
"for",
"any",
"waiting",
"status",
"messages",
"of",
"the",
"cURL",
"requests",
"."
]
| 9b80a1e59ab21106073effc029aaeb7aa13e2964 | https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/MultiCurlManager.php#L167-L174 | train |
BluePsyduck/MultiCurl | src/MultiCurlManager.php | MultiCurlManager.processCurlResponse | protected function processCurlResponse(int $statusCode, $curlHandle)
{
foreach ($this->runningRequests as $index => $request) {
if ($request->getCurl()->getHandle() === $curlHandle) {
$this->parseResponse($request, $statusCode)
->triggerCallback($request->getOnCompleteCallback(), $request);
$this->multiCurl->removeCurl($request->getCurl());
unset($this->runningRequests[$index]);
break;
}
}
return $this;
} | php | protected function processCurlResponse(int $statusCode, $curlHandle)
{
foreach ($this->runningRequests as $index => $request) {
if ($request->getCurl()->getHandle() === $curlHandle) {
$this->parseResponse($request, $statusCode)
->triggerCallback($request->getOnCompleteCallback(), $request);
$this->multiCurl->removeCurl($request->getCurl());
unset($this->runningRequests[$index]);
break;
}
}
return $this;
} | [
"protected",
"function",
"processCurlResponse",
"(",
"int",
"$",
"statusCode",
",",
"$",
"curlHandle",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"runningRequests",
"as",
"$",
"index",
"=>",
"$",
"request",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"getCurl",
"(",
")",
"->",
"getHandle",
"(",
")",
"===",
"$",
"curlHandle",
")",
"{",
"$",
"this",
"->",
"parseResponse",
"(",
"$",
"request",
",",
"$",
"statusCode",
")",
"->",
"triggerCallback",
"(",
"$",
"request",
"->",
"getOnCompleteCallback",
"(",
")",
",",
"$",
"request",
")",
";",
"$",
"this",
"->",
"multiCurl",
"->",
"removeCurl",
"(",
"$",
"request",
"->",
"getCurl",
"(",
")",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"runningRequests",
"[",
"$",
"index",
"]",
")",
";",
"break",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
]
| processes the response of the specified curl handle.
@param int $statusCode
@param resource $curlHandle
@return $this | [
"processes",
"the",
"response",
"of",
"the",
"specified",
"curl",
"handle",
"."
]
| 9b80a1e59ab21106073effc029aaeb7aa13e2964 | https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/MultiCurlManager.php#L182-L195 | train |
BluePsyduck/MultiCurl | src/MultiCurlManager.php | MultiCurlManager.parseResponse | protected function parseResponse(Request $request, int $errorCode)
{
$curl = $request->getCurl();
$response = $request->getResponse();
$response->setErrorCode($errorCode)
->setErrorMessage($curl->getErrorMessage());
if ($errorCode === CURLE_OK) {
$this->hydrateResponseFromCurl($response, $curl);
}
return $this;
} | php | protected function parseResponse(Request $request, int $errorCode)
{
$curl = $request->getCurl();
$response = $request->getResponse();
$response->setErrorCode($errorCode)
->setErrorMessage($curl->getErrorMessage());
if ($errorCode === CURLE_OK) {
$this->hydrateResponseFromCurl($response, $curl);
}
return $this;
} | [
"protected",
"function",
"parseResponse",
"(",
"Request",
"$",
"request",
",",
"int",
"$",
"errorCode",
")",
"{",
"$",
"curl",
"=",
"$",
"request",
"->",
"getCurl",
"(",
")",
";",
"$",
"response",
"=",
"$",
"request",
"->",
"getResponse",
"(",
")",
";",
"$",
"response",
"->",
"setErrorCode",
"(",
"$",
"errorCode",
")",
"->",
"setErrorMessage",
"(",
"$",
"curl",
"->",
"getErrorMessage",
"(",
")",
")",
";",
"if",
"(",
"$",
"errorCode",
"===",
"CURLE_OK",
")",
"{",
"$",
"this",
"->",
"hydrateResponseFromCurl",
"(",
"$",
"response",
",",
"$",
"curl",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Creates the response of the specified request.
@param Request $request
@param int $errorCode
@return $this | [
"Creates",
"the",
"response",
"of",
"the",
"specified",
"request",
"."
]
| 9b80a1e59ab21106073effc029aaeb7aa13e2964 | https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/MultiCurlManager.php#L203-L214 | train |
BluePsyduck/MultiCurl | src/MultiCurlManager.php | MultiCurlManager.hydrateResponseFromCurl | protected function hydrateResponseFromCurl(Response $response, Curl $curl)
{
$headerSize = $curl->getInfo(CURLINFO_HEADER_SIZE);
$rawContent = $this->multiCurl->getContent($curl);
$response->setStatusCode($curl->getInfo(CURLINFO_HTTP_CODE))
->setContent(substr($rawContent, $headerSize));
$this->parseResponseHeaders($response, substr($rawContent, 0, $headerSize));
return $this;
} | php | protected function hydrateResponseFromCurl(Response $response, Curl $curl)
{
$headerSize = $curl->getInfo(CURLINFO_HEADER_SIZE);
$rawContent = $this->multiCurl->getContent($curl);
$response->setStatusCode($curl->getInfo(CURLINFO_HTTP_CODE))
->setContent(substr($rawContent, $headerSize));
$this->parseResponseHeaders($response, substr($rawContent, 0, $headerSize));
return $this;
} | [
"protected",
"function",
"hydrateResponseFromCurl",
"(",
"Response",
"$",
"response",
",",
"Curl",
"$",
"curl",
")",
"{",
"$",
"headerSize",
"=",
"$",
"curl",
"->",
"getInfo",
"(",
"CURLINFO_HEADER_SIZE",
")",
";",
"$",
"rawContent",
"=",
"$",
"this",
"->",
"multiCurl",
"->",
"getContent",
"(",
"$",
"curl",
")",
";",
"$",
"response",
"->",
"setStatusCode",
"(",
"$",
"curl",
"->",
"getInfo",
"(",
"CURLINFO_HTTP_CODE",
")",
")",
"->",
"setContent",
"(",
"substr",
"(",
"$",
"rawContent",
",",
"$",
"headerSize",
")",
")",
";",
"$",
"this",
"->",
"parseResponseHeaders",
"(",
"$",
"response",
",",
"substr",
"(",
"$",
"rawContent",
",",
"0",
",",
"$",
"headerSize",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| Hydrates the response from the specified cUrl request.
@param Response $response
@param Curl $curl
@return $this | [
"Hydrates",
"the",
"response",
"from",
"the",
"specified",
"cUrl",
"request",
"."
]
| 9b80a1e59ab21106073effc029aaeb7aa13e2964 | https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/MultiCurlManager.php#L222-L230 | train |
BluePsyduck/MultiCurl | src/MultiCurlManager.php | MultiCurlManager.parseResponseHeaders | protected function parseResponseHeaders(Response $response, string $headerString)
{
foreach (array_filter(explode("\r\n\r\n", $headerString)) as $responseHeader) {
$header = new Header();
foreach (explode("\r\n", $responseHeader) as $headerLine) {
$parts = explode(':', $headerLine, 2);
if (count($parts) === 2) {
$header->set(trim($parts[0]), trim($parts[1]));
}
}
$response->addHeader($header);
}
return $this;
} | php | protected function parseResponseHeaders(Response $response, string $headerString)
{
foreach (array_filter(explode("\r\n\r\n", $headerString)) as $responseHeader) {
$header = new Header();
foreach (explode("\r\n", $responseHeader) as $headerLine) {
$parts = explode(':', $headerLine, 2);
if (count($parts) === 2) {
$header->set(trim($parts[0]), trim($parts[1]));
}
}
$response->addHeader($header);
}
return $this;
} | [
"protected",
"function",
"parseResponseHeaders",
"(",
"Response",
"$",
"response",
",",
"string",
"$",
"headerString",
")",
"{",
"foreach",
"(",
"array_filter",
"(",
"explode",
"(",
"\"\\r\\n\\r\\n\"",
",",
"$",
"headerString",
")",
")",
"as",
"$",
"responseHeader",
")",
"{",
"$",
"header",
"=",
"new",
"Header",
"(",
")",
";",
"foreach",
"(",
"explode",
"(",
"\"\\r\\n\"",
",",
"$",
"responseHeader",
")",
"as",
"$",
"headerLine",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"':'",
",",
"$",
"headerLine",
",",
"2",
")",
";",
"if",
"(",
"count",
"(",
"$",
"parts",
")",
"===",
"2",
")",
"{",
"$",
"header",
"->",
"set",
"(",
"trim",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
",",
"trim",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
")",
";",
"}",
"}",
"$",
"response",
"->",
"addHeader",
"(",
"$",
"header",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Parses the header string into the response.
@param Response $response
@param string $headerString
@return $this | [
"Parses",
"the",
"header",
"string",
"into",
"the",
"response",
"."
]
| 9b80a1e59ab21106073effc029aaeb7aa13e2964 | https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/MultiCurlManager.php#L238-L251 | train |
BluePsyduck/MultiCurl | src/MultiCurlManager.php | MultiCurlManager.waitForAllRequests | public function waitForAllRequests()
{
while ($this->multiCurl->getStillRunningRequests() > 0
&& $this->multiCurl->getCurrentExecutionCode() === CURLM_OK
) {
$this->multiCurl->select();
$this->executeMultiCurl();
}
return $this;
} | php | public function waitForAllRequests()
{
while ($this->multiCurl->getStillRunningRequests() > 0
&& $this->multiCurl->getCurrentExecutionCode() === CURLM_OK
) {
$this->multiCurl->select();
$this->executeMultiCurl();
}
return $this;
} | [
"public",
"function",
"waitForAllRequests",
"(",
")",
"{",
"while",
"(",
"$",
"this",
"->",
"multiCurl",
"->",
"getStillRunningRequests",
"(",
")",
">",
"0",
"&&",
"$",
"this",
"->",
"multiCurl",
"->",
"getCurrentExecutionCode",
"(",
")",
"===",
"CURLM_OK",
")",
"{",
"$",
"this",
"->",
"multiCurl",
"->",
"select",
"(",
")",
";",
"$",
"this",
"->",
"executeMultiCurl",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Delays the script execution until all requests have been finished.
@return $this Implementing fluent interface. | [
"Delays",
"the",
"script",
"execution",
"until",
"all",
"requests",
"have",
"been",
"finished",
"."
]
| 9b80a1e59ab21106073effc029aaeb7aa13e2964 | https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/MultiCurlManager.php#L271-L280 | train |
BluePsyduck/MultiCurl | src/MultiCurlManager.php | MultiCurlManager.waitForSingleRequest | public function waitForSingleRequest(Request $request)
{
$this->executeRequest($request);
while ($this->multiCurl->getStillRunningRequests() > 0
&& $this->multiCurl->getCurrentExecutionCode() === CURLM_OK
&& in_array($request, $this->runningRequests)
) {
$this->multiCurl->select();
$this->executeMultiCurl();
}
return $this;
} | php | public function waitForSingleRequest(Request $request)
{
$this->executeRequest($request);
while ($this->multiCurl->getStillRunningRequests() > 0
&& $this->multiCurl->getCurrentExecutionCode() === CURLM_OK
&& in_array($request, $this->runningRequests)
) {
$this->multiCurl->select();
$this->executeMultiCurl();
}
return $this;
} | [
"public",
"function",
"waitForSingleRequest",
"(",
"Request",
"$",
"request",
")",
"{",
"$",
"this",
"->",
"executeRequest",
"(",
"$",
"request",
")",
";",
"while",
"(",
"$",
"this",
"->",
"multiCurl",
"->",
"getStillRunningRequests",
"(",
")",
">",
"0",
"&&",
"$",
"this",
"->",
"multiCurl",
"->",
"getCurrentExecutionCode",
"(",
")",
"===",
"CURLM_OK",
"&&",
"in_array",
"(",
"$",
"request",
",",
"$",
"this",
"->",
"runningRequests",
")",
")",
"{",
"$",
"this",
"->",
"multiCurl",
"->",
"select",
"(",
")",
";",
"$",
"this",
"->",
"executeMultiCurl",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| Delays the script execution until at least the specified request has been finished.
@param Request $request
@return $this Implementing fluent interface. | [
"Delays",
"the",
"script",
"execution",
"until",
"at",
"least",
"the",
"specified",
"request",
"has",
"been",
"finished",
"."
]
| 9b80a1e59ab21106073effc029aaeb7aa13e2964 | https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/MultiCurlManager.php#L287-L298 | train |
BluePsyduck/MultiCurl | src/Entity/Header.php | Header.set | public function set(string $name, string $value)
{
$this->values[$name] = $value;
return $this;
} | php | public function set(string $name, string $value)
{
$this->values[$name] = $value;
return $this;
} | [
"public",
"function",
"set",
"(",
"string",
"$",
"name",
",",
"string",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
]
| Sets a value to the header.
@param string $name
@param string $value
@return $this | [
"Sets",
"a",
"value",
"to",
"the",
"header",
"."
]
| 9b80a1e59ab21106073effc029aaeb7aa13e2964 | https://github.com/BluePsyduck/MultiCurl/blob/9b80a1e59ab21106073effc029aaeb7aa13e2964/src/Entity/Header.php#L29-L33 | train |
dmt-software/jms-soap-serializer | src/SoapMessageEventSubscriber.php | SoapMessageEventSubscriber.moveChildNamespacesToEnvelope | protected function moveChildNamespacesToEnvelope(\SimpleXMLElement $element): \SimpleXMLElement
{
$dom = dom_import_simplexml($element);
foreach ($element->getNamespaces(true) as $prefix => $namespace) {
if (!in_array($namespace, $element->getDocNamespaces())) {
$dom->setAttributeNS(
'http://www.w3.org/2000/xmlns/',
$prefix ? 'xmlns:' . $prefix : 'xmlns',
$namespace
);
}
}
return simplexml_import_dom($dom->ownerDocument);
} | php | protected function moveChildNamespacesToEnvelope(\SimpleXMLElement $element): \SimpleXMLElement
{
$dom = dom_import_simplexml($element);
foreach ($element->getNamespaces(true) as $prefix => $namespace) {
if (!in_array($namespace, $element->getDocNamespaces())) {
$dom->setAttributeNS(
'http://www.w3.org/2000/xmlns/',
$prefix ? 'xmlns:' . $prefix : 'xmlns',
$namespace
);
}
}
return simplexml_import_dom($dom->ownerDocument);
} | [
"protected",
"function",
"moveChildNamespacesToEnvelope",
"(",
"\\",
"SimpleXMLElement",
"$",
"element",
")",
":",
"\\",
"SimpleXMLElement",
"{",
"$",
"dom",
"=",
"dom_import_simplexml",
"(",
"$",
"element",
")",
";",
"foreach",
"(",
"$",
"element",
"->",
"getNamespaces",
"(",
"true",
")",
"as",
"$",
"prefix",
"=>",
"$",
"namespace",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"namespace",
",",
"$",
"element",
"->",
"getDocNamespaces",
"(",
")",
")",
")",
"{",
"$",
"dom",
"->",
"setAttributeNS",
"(",
"'http://www.w3.org/2000/xmlns/'",
",",
"$",
"prefix",
"?",
"'xmlns:'",
".",
"$",
"prefix",
":",
"'xmlns'",
",",
"$",
"namespace",
")",
";",
"}",
"}",
"return",
"simplexml_import_dom",
"(",
"$",
"dom",
"->",
"ownerDocument",
")",
";",
"}"
]
| Move all underlying namespaces to root element.
@param \SimpleXMLElement $element
@return \SimpleXMLElement | [
"Move",
"all",
"underlying",
"namespaces",
"to",
"root",
"element",
"."
]
| 47d42012a9836d73642fcc451d90926d70cc9275 | https://github.com/dmt-software/jms-soap-serializer/blob/47d42012a9836d73642fcc451d90926d70cc9275/src/SoapMessageEventSubscriber.php#L106-L121 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.