id int32 0 241k | 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 |
|---|---|---|---|---|---|---|---|---|---|---|---|
33,200 | alterphp/components | src/AlterPHP/Component/Behavior/StatusableEntity.php | StatusableEntity.getStatusBetween | public static function getStatusBetween($from = null, $to = null, $strict = false, $strictTo = null)
{
$statusList = static::getStatusList();
$strictFrom = $strict;
$strictTo = isset($strictTo) ? (bool) $strictTo : $strict;
// Remove status before given $from
if (isset($from)) {
static::checkAllowedStatus($from);
foreach ($statusList as $key => $status) {
if ($from !== $status) {
unset($statusList[$key]);
} else {
if ($strictFrom) {
unset($statusList[$key]);
}
break;
}
}
}
// Remove status after given $to
if (isset($to)) {
static::checkAllowedStatus($to);
// On inverse l'ordre des statuts
$statusList = array_reverse($statusList);
foreach ($statusList as $key => $status) {
if ($to !== $status) {
unset($statusList[$key]);
} else {
if ($strictTo) {
unset($statusList[$key]);
}
break;
}
}
// On inverse l'ordre des statuts
$statusList = array_reverse($statusList);
}
return array_values($statusList);
} | php | public static function getStatusBetween($from = null, $to = null, $strict = false, $strictTo = null)
{
$statusList = static::getStatusList();
$strictFrom = $strict;
$strictTo = isset($strictTo) ? (bool) $strictTo : $strict;
// Remove status before given $from
if (isset($from)) {
static::checkAllowedStatus($from);
foreach ($statusList as $key => $status) {
if ($from !== $status) {
unset($statusList[$key]);
} else {
if ($strictFrom) {
unset($statusList[$key]);
}
break;
}
}
}
// Remove status after given $to
if (isset($to)) {
static::checkAllowedStatus($to);
// On inverse l'ordre des statuts
$statusList = array_reverse($statusList);
foreach ($statusList as $key => $status) {
if ($to !== $status) {
unset($statusList[$key]);
} else {
if ($strictTo) {
unset($statusList[$key]);
}
break;
}
}
// On inverse l'ordre des statuts
$statusList = array_reverse($statusList);
}
return array_values($statusList);
} | [
"public",
"static",
"function",
"getStatusBetween",
"(",
"$",
"from",
"=",
"null",
",",
"$",
"to",
"=",
"null",
",",
"$",
"strict",
"=",
"false",
",",
"$",
"strictTo",
"=",
"null",
")",
"{",
"$",
"statusList",
"=",
"static",
"::",
"getStatusList",
"(",
")",
";",
"$",
"strictFrom",
"=",
"$",
"strict",
";",
"$",
"strictTo",
"=",
"isset",
"(",
"$",
"strictTo",
")",
"?",
"(",
"bool",
")",
"$",
"strictTo",
":",
"$",
"strict",
";",
"// Remove status before given $from",
"if",
"(",
"isset",
"(",
"$",
"from",
")",
")",
"{",
"static",
"::",
"checkAllowedStatus",
"(",
"$",
"from",
")",
";",
"foreach",
"(",
"$",
"statusList",
"as",
"$",
"key",
"=>",
"$",
"status",
")",
"{",
"if",
"(",
"$",
"from",
"!==",
"$",
"status",
")",
"{",
"unset",
"(",
"$",
"statusList",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"strictFrom",
")",
"{",
"unset",
"(",
"$",
"statusList",
"[",
"$",
"key",
"]",
")",
";",
"}",
"break",
";",
"}",
"}",
"}",
"// Remove status after given $to",
"if",
"(",
"isset",
"(",
"$",
"to",
")",
")",
"{",
"static",
"::",
"checkAllowedStatus",
"(",
"$",
"to",
")",
";",
"// On inverse l'ordre des statuts",
"$",
"statusList",
"=",
"array_reverse",
"(",
"$",
"statusList",
")",
";",
"foreach",
"(",
"$",
"statusList",
"as",
"$",
"key",
"=>",
"$",
"status",
")",
"{",
"if",
"(",
"$",
"to",
"!==",
"$",
"status",
")",
"{",
"unset",
"(",
"$",
"statusList",
"[",
"$",
"key",
"]",
")",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"strictTo",
")",
"{",
"unset",
"(",
"$",
"statusList",
"[",
"$",
"key",
"]",
")",
";",
"}",
"break",
";",
"}",
"}",
"// On inverse l'ordre des statuts",
"$",
"statusList",
"=",
"array_reverse",
"(",
"$",
"statusList",
")",
";",
"}",
"return",
"array_values",
"(",
"$",
"statusList",
")",
";",
"}"
] | Returns list of status between a "from" and a "to" status.
@param string $from
@param string $to
@param bool $strict Is lower bound strict (or both bounds if $strictTo is null) ?
@param bool $strictTo Is higher bound strict ?
@return array | [
"Returns",
"list",
"of",
"status",
"between",
"a",
"from",
"and",
"a",
"to",
"status",
"."
] | a2fa91bf02746f9493ffc742ab3ef1d2f18b56d5 | https://github.com/alterphp/components/blob/a2fa91bf02746f9493ffc742ab3ef1d2f18b56d5/src/AlterPHP/Component/Behavior/StatusableEntity.php#L97-L139 |
33,201 | alterphp/components | src/AlterPHP/Component/Behavior/StatusableEntity.php | StatusableEntity.isGreaterThan | public static function isGreaterThan($status1, $status2, $strict = true)
{
static::checkAllowedStatus($status1);
static::checkAllowedStatus($status2);
$entityStatusIdx = array_search($status1, static::getStatusList());
$comparedStatusIdx = array_search($status2, static::getStatusList());
if ($strict) {
return $entityStatusIdx > $comparedStatusIdx;
}
return $entityStatusIdx >= $comparedStatusIdx;
} | php | public static function isGreaterThan($status1, $status2, $strict = true)
{
static::checkAllowedStatus($status1);
static::checkAllowedStatus($status2);
$entityStatusIdx = array_search($status1, static::getStatusList());
$comparedStatusIdx = array_search($status2, static::getStatusList());
if ($strict) {
return $entityStatusIdx > $comparedStatusIdx;
}
return $entityStatusIdx >= $comparedStatusIdx;
} | [
"public",
"static",
"function",
"isGreaterThan",
"(",
"$",
"status1",
",",
"$",
"status2",
",",
"$",
"strict",
"=",
"true",
")",
"{",
"static",
"::",
"checkAllowedStatus",
"(",
"$",
"status1",
")",
";",
"static",
"::",
"checkAllowedStatus",
"(",
"$",
"status2",
")",
";",
"$",
"entityStatusIdx",
"=",
"array_search",
"(",
"$",
"status1",
",",
"static",
"::",
"getStatusList",
"(",
")",
")",
";",
"$",
"comparedStatusIdx",
"=",
"array_search",
"(",
"$",
"status2",
",",
"static",
"::",
"getStatusList",
"(",
")",
")",
";",
"if",
"(",
"$",
"strict",
")",
"{",
"return",
"$",
"entityStatusIdx",
">",
"$",
"comparedStatusIdx",
";",
"}",
"return",
"$",
"entityStatusIdx",
">=",
"$",
"comparedStatusIdx",
";",
"}"
] | Compare first status to second passed status.
@param string $status1
@param string $status2
@param bool $strict
@return bool | [
"Compare",
"first",
"status",
"to",
"second",
"passed",
"status",
"."
] | a2fa91bf02746f9493ffc742ab3ef1d2f18b56d5 | https://github.com/alterphp/components/blob/a2fa91bf02746f9493ffc742ab3ef1d2f18b56d5/src/AlterPHP/Component/Behavior/StatusableEntity.php#L166-L179 |
33,202 | alterphp/components | src/AlterPHP/Component/Behavior/StatusableEntity.php | StatusableEntity.getStatusLabel | public function getStatusLabel()
{
$statusList = array_flip($this->getStatusList(true));
return isset($statusList[$this->status]) ? $statusList[$this->status] : $this->status;
} | php | public function getStatusLabel()
{
$statusList = array_flip($this->getStatusList(true));
return isset($statusList[$this->status]) ? $statusList[$this->status] : $this->status;
} | [
"public",
"function",
"getStatusLabel",
"(",
")",
"{",
"$",
"statusList",
"=",
"array_flip",
"(",
"$",
"this",
"->",
"getStatusList",
"(",
"true",
")",
")",
";",
"return",
"isset",
"(",
"$",
"statusList",
"[",
"$",
"this",
"->",
"status",
"]",
")",
"?",
"$",
"statusList",
"[",
"$",
"this",
"->",
"status",
"]",
":",
"$",
"this",
"->",
"status",
";",
"}"
] | Get statusLabel.
@return string | [
"Get",
"statusLabel",
"."
] | a2fa91bf02746f9493ffc742ab3ef1d2f18b56d5 | https://github.com/alterphp/components/blob/a2fa91bf02746f9493ffc742ab3ef1d2f18b56d5/src/AlterPHP/Component/Behavior/StatusableEntity.php#L262-L267 |
33,203 | alterphp/components | src/AlterPHP/Component/Mailer/Mailer.php | Mailer.forceFlushForCommand | public function forceFlushForCommand()
{
// L'envoi des emails est déclenché sur une réponse du Kernel (inactif en mode commande)
$transport = $this->swift->getTransport();
if (!$transport instanceof \Swift_Transport_SpoolTransport) {
return;
}
$spool = $transport->getSpool();
if (!$spool instanceof \Swift_MemorySpool) {
return;
}
return $spool->flushQueue($this->mailerRealTransport);
} | php | public function forceFlushForCommand()
{
// L'envoi des emails est déclenché sur une réponse du Kernel (inactif en mode commande)
$transport = $this->swift->getTransport();
if (!$transport instanceof \Swift_Transport_SpoolTransport) {
return;
}
$spool = $transport->getSpool();
if (!$spool instanceof \Swift_MemorySpool) {
return;
}
return $spool->flushQueue($this->mailerRealTransport);
} | [
"public",
"function",
"forceFlushForCommand",
"(",
")",
"{",
"// L'envoi des emails est déclenché sur une réponse du Kernel (inactif en mode commande)",
"$",
"transport",
"=",
"$",
"this",
"->",
"swift",
"->",
"getTransport",
"(",
")",
";",
"if",
"(",
"!",
"$",
"transport",
"instanceof",
"\\",
"Swift_Transport_SpoolTransport",
")",
"{",
"return",
";",
"}",
"$",
"spool",
"=",
"$",
"transport",
"->",
"getSpool",
"(",
")",
";",
"if",
"(",
"!",
"$",
"spool",
"instanceof",
"\\",
"Swift_MemorySpool",
")",
"{",
"return",
";",
"}",
"return",
"$",
"spool",
"->",
"flushQueue",
"(",
"$",
"this",
"->",
"mailerRealTransport",
")",
";",
"}"
] | Force l'envoi des mails en mode Command
@return integer Number of emails sent | [
"Force",
"l",
"envoi",
"des",
"mails",
"en",
"mode",
"Command"
] | a2fa91bf02746f9493ffc742ab3ef1d2f18b56d5 | https://github.com/alterphp/components/blob/a2fa91bf02746f9493ffc742ab3ef1d2f18b56d5/src/AlterPHP/Component/Mailer/Mailer.php#L144-L157 |
33,204 | alterphp/components | src/AlterPHP/Component/ToolBox/PolylineEncoder.php | PolylineEncoder.dpEncode | public function dpEncode() {
if(count($this->points) > 2) {
$stack[] = array(0, count($this->points)-1);
while(count($stack) > 0) {
$current = array_pop($stack);
$maxDist = 0;
$absMaxDist = 0;
for($i = $current[0]+1; $i < $current[1]; $i++) {
$temp = self::distance($this->points[$i], $this->points[$current[0]], $this->points[$current[1]]);
if($temp > $maxDist) {
$maxDist = $temp;
$maxLoc = $i;
if($maxDist > $absMaxDist) {
$absMaxDist = $maxDist;
}
}
}
if($maxDist > $this->verySmall) {
$dists[$maxLoc] = $maxDist;
array_push($stack, array($current[0], $maxLoc));
array_push($stack, array($maxLoc, $current[1]));
}
}
}
$encodedPoints = self::createEncodings($this->points, $dists);
$encodedLevels = self::encodeLevels($this->points, $dists, $absMaxDist);
$encodedPointsLiteral = str_replace('\\',"\\\\",$encodedPoints);
$polyline["Points"] = $encodedPoints;
$polyline["Levels"] = $encodedLevels;
$polyline["PointsLiteral"] = $encodedPointsLiteral;
$polyline["ZoomFactor"] = $this->zoomFactor;
$polyline["NumLevels"] = $this->numLevels;
return $polyline;
} | php | public function dpEncode() {
if(count($this->points) > 2) {
$stack[] = array(0, count($this->points)-1);
while(count($stack) > 0) {
$current = array_pop($stack);
$maxDist = 0;
$absMaxDist = 0;
for($i = $current[0]+1; $i < $current[1]; $i++) {
$temp = self::distance($this->points[$i], $this->points[$current[0]], $this->points[$current[1]]);
if($temp > $maxDist) {
$maxDist = $temp;
$maxLoc = $i;
if($maxDist > $absMaxDist) {
$absMaxDist = $maxDist;
}
}
}
if($maxDist > $this->verySmall) {
$dists[$maxLoc] = $maxDist;
array_push($stack, array($current[0], $maxLoc));
array_push($stack, array($maxLoc, $current[1]));
}
}
}
$encodedPoints = self::createEncodings($this->points, $dists);
$encodedLevels = self::encodeLevels($this->points, $dists, $absMaxDist);
$encodedPointsLiteral = str_replace('\\',"\\\\",$encodedPoints);
$polyline["Points"] = $encodedPoints;
$polyline["Levels"] = $encodedLevels;
$polyline["PointsLiteral"] = $encodedPointsLiteral;
$polyline["ZoomFactor"] = $this->zoomFactor;
$polyline["NumLevels"] = $this->numLevels;
return $polyline;
} | [
"public",
"function",
"dpEncode",
"(",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"points",
")",
">",
"2",
")",
"{",
"$",
"stack",
"[",
"]",
"=",
"array",
"(",
"0",
",",
"count",
"(",
"$",
"this",
"->",
"points",
")",
"-",
"1",
")",
";",
"while",
"(",
"count",
"(",
"$",
"stack",
")",
">",
"0",
")",
"{",
"$",
"current",
"=",
"array_pop",
"(",
"$",
"stack",
")",
";",
"$",
"maxDist",
"=",
"0",
";",
"$",
"absMaxDist",
"=",
"0",
";",
"for",
"(",
"$",
"i",
"=",
"$",
"current",
"[",
"0",
"]",
"+",
"1",
";",
"$",
"i",
"<",
"$",
"current",
"[",
"1",
"]",
";",
"$",
"i",
"++",
")",
"{",
"$",
"temp",
"=",
"self",
"::",
"distance",
"(",
"$",
"this",
"->",
"points",
"[",
"$",
"i",
"]",
",",
"$",
"this",
"->",
"points",
"[",
"$",
"current",
"[",
"0",
"]",
"]",
",",
"$",
"this",
"->",
"points",
"[",
"$",
"current",
"[",
"1",
"]",
"]",
")",
";",
"if",
"(",
"$",
"temp",
">",
"$",
"maxDist",
")",
"{",
"$",
"maxDist",
"=",
"$",
"temp",
";",
"$",
"maxLoc",
"=",
"$",
"i",
";",
"if",
"(",
"$",
"maxDist",
">",
"$",
"absMaxDist",
")",
"{",
"$",
"absMaxDist",
"=",
"$",
"maxDist",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"maxDist",
">",
"$",
"this",
"->",
"verySmall",
")",
"{",
"$",
"dists",
"[",
"$",
"maxLoc",
"]",
"=",
"$",
"maxDist",
";",
"array_push",
"(",
"$",
"stack",
",",
"array",
"(",
"$",
"current",
"[",
"0",
"]",
",",
"$",
"maxLoc",
")",
")",
";",
"array_push",
"(",
"$",
"stack",
",",
"array",
"(",
"$",
"maxLoc",
",",
"$",
"current",
"[",
"1",
"]",
")",
")",
";",
"}",
"}",
"}",
"$",
"encodedPoints",
"=",
"self",
"::",
"createEncodings",
"(",
"$",
"this",
"->",
"points",
",",
"$",
"dists",
")",
";",
"$",
"encodedLevels",
"=",
"self",
"::",
"encodeLevels",
"(",
"$",
"this",
"->",
"points",
",",
"$",
"dists",
",",
"$",
"absMaxDist",
")",
";",
"$",
"encodedPointsLiteral",
"=",
"str_replace",
"(",
"'\\\\'",
",",
"\"\\\\\\\\\"",
",",
"$",
"encodedPoints",
")",
";",
"$",
"polyline",
"[",
"\"Points\"",
"]",
"=",
"$",
"encodedPoints",
";",
"$",
"polyline",
"[",
"\"Levels\"",
"]",
"=",
"$",
"encodedLevels",
";",
"$",
"polyline",
"[",
"\"PointsLiteral\"",
"]",
"=",
"$",
"encodedPointsLiteral",
";",
"$",
"polyline",
"[",
"\"ZoomFactor\"",
"]",
"=",
"$",
"this",
"->",
"zoomFactor",
";",
"$",
"polyline",
"[",
"\"NumLevels\"",
"]",
"=",
"$",
"this",
"->",
"numLevels",
";",
"return",
"$",
"polyline",
";",
"}"
] | It also returns the zoomFactor and numLevels | [
"It",
"also",
"returns",
"the",
"zoomFactor",
"and",
"numLevels"
] | a2fa91bf02746f9493ffc742ab3ef1d2f18b56d5 | https://github.com/alterphp/components/blob/a2fa91bf02746f9493ffc742ab3ef1d2f18b56d5/src/AlterPHP/Component/ToolBox/PolylineEncoder.php#L102-L142 |
33,205 | box-project/box2-lib | src/lib/Herrera/Box/Box.php | Box.addFromString | public function addFromString($local, $contents)
{
$this->phar->addFromString(
$local,
$this->replaceValues($this->compactContents($local, $contents))
);
} | php | public function addFromString($local, $contents)
{
$this->phar->addFromString(
$local,
$this->replaceValues($this->compactContents($local, $contents))
);
} | [
"public",
"function",
"addFromString",
"(",
"$",
"local",
",",
"$",
"contents",
")",
"{",
"$",
"this",
"->",
"phar",
"->",
"addFromString",
"(",
"$",
"local",
",",
"$",
"this",
"->",
"replaceValues",
"(",
"$",
"this",
"->",
"compactContents",
"(",
"$",
"local",
",",
"$",
"contents",
")",
")",
")",
";",
"}"
] | Adds the contents from a file to the Phar, after compacting it and
replacing its placeholders.
@param string $local The local name.
@param string $contents The contents. | [
"Adds",
"the",
"contents",
"from",
"a",
"file",
"to",
"the",
"Phar",
"after",
"compacting",
"it",
"and",
"replacing",
"its",
"placeholders",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Box.php#L115-L121 |
33,206 | box-project/box2-lib | src/lib/Herrera/Box/Box.php | Box.compactContents | public function compactContents($file, $contents)
{
foreach ($this->compactors as $compactor) {
/** @var $compactor CompactorInterface */
if ($compactor->supports($file)) {
$contents = $compactor->compact($contents);
}
}
return $contents;
} | php | public function compactContents($file, $contents)
{
foreach ($this->compactors as $compactor) {
/** @var $compactor CompactorInterface */
if ($compactor->supports($file)) {
$contents = $compactor->compact($contents);
}
}
return $contents;
} | [
"public",
"function",
"compactContents",
"(",
"$",
"file",
",",
"$",
"contents",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"compactors",
"as",
"$",
"compactor",
")",
"{",
"/** @var $compactor CompactorInterface */",
"if",
"(",
"$",
"compactor",
"->",
"supports",
"(",
"$",
"file",
")",
")",
"{",
"$",
"contents",
"=",
"$",
"compactor",
"->",
"compact",
"(",
"$",
"contents",
")",
";",
"}",
"}",
"return",
"$",
"contents",
";",
"}"
] | Compacts the file contents using the supported compactors.
@param string $file The file name.
@param string $contents The file contents.
@return string The compacted contents. | [
"Compacts",
"the",
"file",
"contents",
"using",
"the",
"supported",
"compactors",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Box.php#L222-L232 |
33,207 | box-project/box2-lib | src/lib/Herrera/Box/Box.php | Box.create | public static function create($file, $flags = null, $alias = null)
{
return new Box(new Phar($file, $flags, $alias), $file);
} | php | public static function create($file, $flags = null, $alias = null)
{
return new Box(new Phar($file, $flags, $alias), $file);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"file",
",",
"$",
"flags",
"=",
"null",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"return",
"new",
"Box",
"(",
"new",
"Phar",
"(",
"$",
"file",
",",
"$",
"flags",
",",
"$",
"alias",
")",
",",
"$",
"file",
")",
";",
"}"
] | Creates a new Phar and Box instance.
@param string $file The file name.
@param integer $flags The RecursiveDirectoryIterator flags.
@param string $alias The Phar alias.
@return Box The Box instance. | [
"Creates",
"a",
"new",
"Phar",
"and",
"Box",
"instance",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Box.php#L243-L246 |
33,208 | box-project/box2-lib | src/lib/Herrera/Box/Box.php | Box.replaceValues | public function replaceValues($contents)
{
return str_replace(
array_keys($this->values),
array_values($this->values),
$contents
);
} | php | public function replaceValues($contents)
{
return str_replace(
array_keys($this->values),
array_values($this->values),
$contents
);
} | [
"public",
"function",
"replaceValues",
"(",
"$",
"contents",
")",
"{",
"return",
"str_replace",
"(",
"array_keys",
"(",
"$",
"this",
"->",
"values",
")",
",",
"array_values",
"(",
"$",
"this",
"->",
"values",
")",
",",
"$",
"contents",
")",
";",
"}"
] | Replaces the placeholders with their values.
@param string $contents The contents.
@return string The replaced contents. | [
"Replaces",
"the",
"placeholders",
"with",
"their",
"values",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Box.php#L279-L286 |
33,209 | box-project/box2-lib | src/lib/Herrera/Box/Box.php | Box.setStubUsingFile | public function setStubUsingFile($file, $replace = false)
{
if (false === is_file($file)) {
throw FileException::create(
'The file "%s" does not exist or is not a file.',
$file
);
}
if (false === ($contents = @file_get_contents($file))) {
throw FileException::lastError();
}
if ($replace) {
$contents = $this->replaceValues($contents);
}
$this->phar->setStub($contents);
} | php | public function setStubUsingFile($file, $replace = false)
{
if (false === is_file($file)) {
throw FileException::create(
'The file "%s" does not exist or is not a file.',
$file
);
}
if (false === ($contents = @file_get_contents($file))) {
throw FileException::lastError();
}
if ($replace) {
$contents = $this->replaceValues($contents);
}
$this->phar->setStub($contents);
} | [
"public",
"function",
"setStubUsingFile",
"(",
"$",
"file",
",",
"$",
"replace",
"=",
"false",
")",
"{",
"if",
"(",
"false",
"===",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"FileException",
"::",
"create",
"(",
"'The file \"%s\" does not exist or is not a file.'",
",",
"$",
"file",
")",
";",
"}",
"if",
"(",
"false",
"===",
"(",
"$",
"contents",
"=",
"@",
"file_get_contents",
"(",
"$",
"file",
")",
")",
")",
"{",
"throw",
"FileException",
"::",
"lastError",
"(",
")",
";",
"}",
"if",
"(",
"$",
"replace",
")",
"{",
"$",
"contents",
"=",
"$",
"this",
"->",
"replaceValues",
"(",
"$",
"contents",
")",
";",
"}",
"$",
"this",
"->",
"phar",
"->",
"setStub",
"(",
"$",
"contents",
")",
";",
"}"
] | Sets the bootstrap loader stub using a file.
@param string $file The file path.
@param boolean $replace Replace placeholders?
@throws Exception\Exception
@throws FileException If the stub file could not be used. | [
"Sets",
"the",
"bootstrap",
"loader",
"stub",
"using",
"a",
"file",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Box.php#L297-L315 |
33,210 | box-project/box2-lib | src/lib/Herrera/Box/Box.php | Box.setValues | public function setValues(array $values)
{
foreach ($values as $value) {
if (false === is_scalar($value)) {
throw InvalidArgumentException::create(
'Non-scalar values (such as %s) are not supported.',
gettype($value)
);
}
}
$this->values = $values;
} | php | public function setValues(array $values)
{
foreach ($values as $value) {
if (false === is_scalar($value)) {
throw InvalidArgumentException::create(
'Non-scalar values (such as %s) are not supported.',
gettype($value)
);
}
}
$this->values = $values;
} | [
"public",
"function",
"setValues",
"(",
"array",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"false",
"===",
"is_scalar",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"InvalidArgumentException",
"::",
"create",
"(",
"'Non-scalar values (such as %s) are not supported.'",
",",
"gettype",
"(",
"$",
"value",
")",
")",
";",
"}",
"}",
"$",
"this",
"->",
"values",
"=",
"$",
"values",
";",
"}"
] | Sets the placeholder values.
@param array $values The values.
@throws Exception\Exception
@throws InvalidArgumentException If a non-scalar value is used. | [
"Sets",
"the",
"placeholder",
"values",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Box.php#L325-L337 |
33,211 | box-project/box2-lib | src/lib/Herrera/Box/Box.php | Box.sign | public function sign($key, $password = null)
{
OpenSslException::reset();
if (false === extension_loaded('openssl')) {
// @codeCoverageIgnoreStart
throw OpenSslException::create(
'The "openssl" extension is not available.'
);
// @codeCoverageIgnoreEnd
}
if (false === ($resource = openssl_pkey_get_private($key, $password))) {
// @codeCoverageIgnoreStart
throw OpenSslException::lastError();
// @codeCoverageIgnoreEnd
}
if (false === openssl_pkey_export($resource, $private)) {
// @codeCoverageIgnoreStart
throw OpenSslException::lastError();
// @codeCoverageIgnoreEnd
}
if (false === ($details = openssl_pkey_get_details($resource))) {
// @codeCoverageIgnoreStart
throw OpenSslException::lastError();
// @codeCoverageIgnoreEnd
}
$this->phar->setSignatureAlgorithm(Phar::OPENSSL, $private);
if (false === @file_put_contents($this->file . '.pubkey', $details['key'])) {
throw FileException::lastError();
}
} | php | public function sign($key, $password = null)
{
OpenSslException::reset();
if (false === extension_loaded('openssl')) {
// @codeCoverageIgnoreStart
throw OpenSslException::create(
'The "openssl" extension is not available.'
);
// @codeCoverageIgnoreEnd
}
if (false === ($resource = openssl_pkey_get_private($key, $password))) {
// @codeCoverageIgnoreStart
throw OpenSslException::lastError();
// @codeCoverageIgnoreEnd
}
if (false === openssl_pkey_export($resource, $private)) {
// @codeCoverageIgnoreStart
throw OpenSslException::lastError();
// @codeCoverageIgnoreEnd
}
if (false === ($details = openssl_pkey_get_details($resource))) {
// @codeCoverageIgnoreStart
throw OpenSslException::lastError();
// @codeCoverageIgnoreEnd
}
$this->phar->setSignatureAlgorithm(Phar::OPENSSL, $private);
if (false === @file_put_contents($this->file . '.pubkey', $details['key'])) {
throw FileException::lastError();
}
} | [
"public",
"function",
"sign",
"(",
"$",
"key",
",",
"$",
"password",
"=",
"null",
")",
"{",
"OpenSslException",
"::",
"reset",
"(",
")",
";",
"if",
"(",
"false",
"===",
"extension_loaded",
"(",
"'openssl'",
")",
")",
"{",
"// @codeCoverageIgnoreStart",
"throw",
"OpenSslException",
"::",
"create",
"(",
"'The \"openssl\" extension is not available.'",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"if",
"(",
"false",
"===",
"(",
"$",
"resource",
"=",
"openssl_pkey_get_private",
"(",
"$",
"key",
",",
"$",
"password",
")",
")",
")",
"{",
"// @codeCoverageIgnoreStart",
"throw",
"OpenSslException",
"::",
"lastError",
"(",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"if",
"(",
"false",
"===",
"openssl_pkey_export",
"(",
"$",
"resource",
",",
"$",
"private",
")",
")",
"{",
"// @codeCoverageIgnoreStart",
"throw",
"OpenSslException",
"::",
"lastError",
"(",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"if",
"(",
"false",
"===",
"(",
"$",
"details",
"=",
"openssl_pkey_get_details",
"(",
"$",
"resource",
")",
")",
")",
"{",
"// @codeCoverageIgnoreStart",
"throw",
"OpenSslException",
"::",
"lastError",
"(",
")",
";",
"// @codeCoverageIgnoreEnd",
"}",
"$",
"this",
"->",
"phar",
"->",
"setSignatureAlgorithm",
"(",
"Phar",
"::",
"OPENSSL",
",",
"$",
"private",
")",
";",
"if",
"(",
"false",
"===",
"@",
"file_put_contents",
"(",
"$",
"this",
"->",
"file",
".",
"'.pubkey'",
",",
"$",
"details",
"[",
"'key'",
"]",
")",
")",
"{",
"throw",
"FileException",
"::",
"lastError",
"(",
")",
";",
"}",
"}"
] | Signs the Phar using a private key.
@param string $key The private key.
@param string $password The private key password.
@throws Exception\Exception
@throws OpenSslException If the "openssl" extension could not be used
or has generated an error. | [
"Signs",
"the",
"Phar",
"using",
"a",
"private",
"key",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Box.php#L349-L384 |
33,212 | box-project/box2-lib | src/lib/Herrera/Box/Box.php | Box.signUsingFile | public function signUsingFile($file, $password = null)
{
if (false === is_file($file)) {
throw FileException::create(
'The file "%s" does not exist or is not a file.',
$file
);
}
if (false === ($key = @file_get_contents($file))) {
throw FileException::lastError();
}
$this->sign($key, $password);
} | php | public function signUsingFile($file, $password = null)
{
if (false === is_file($file)) {
throw FileException::create(
'The file "%s" does not exist or is not a file.',
$file
);
}
if (false === ($key = @file_get_contents($file))) {
throw FileException::lastError();
}
$this->sign($key, $password);
} | [
"public",
"function",
"signUsingFile",
"(",
"$",
"file",
",",
"$",
"password",
"=",
"null",
")",
"{",
"if",
"(",
"false",
"===",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"FileException",
"::",
"create",
"(",
"'The file \"%s\" does not exist or is not a file.'",
",",
"$",
"file",
")",
";",
"}",
"if",
"(",
"false",
"===",
"(",
"$",
"key",
"=",
"@",
"file_get_contents",
"(",
"$",
"file",
")",
")",
")",
"{",
"throw",
"FileException",
"::",
"lastError",
"(",
")",
";",
"}",
"$",
"this",
"->",
"sign",
"(",
"$",
"key",
",",
"$",
"password",
")",
";",
"}"
] | Signs the Phar using a private key file.
@param string $file The private key file name.
@param string $password The private key password.
@throws Exception\Exception
@throws FileException If the private key file could not be read. | [
"Signs",
"the",
"Phar",
"using",
"a",
"private",
"key",
"file",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Box.php#L395-L409 |
33,213 | box-project/box2-lib | src/lib/Herrera/Box/Signature.php | Signature.get | public function get($required = null)
{
if (null === $required) {
$required = (bool) ini_get('phar.require_hash');
}
$this->seek(-4, SEEK_END);
if ('GBMB' !== $this->read(4)) {
if ($required) {
throw new PharException(
sprintf(
'The phar "%s" is not signed.',
$this->file
)
);
}
return null;
}
$this->seek(-8, SEEK_END);
$flag = unpack('V', $this->read(4));
$flag = $flag[1];
foreach (self::$types as $type) {
if ($flag === $type['flag']) {
break;
}
unset($type);
}
if (!isset($type)) {
throw new PharException(
sprintf(
'The signature type (%x) is not recognized for the phar "%s".',
$flag,
$this->file
)
);
}
$offset = -8;
if (0x10 === $type['flag']) {
$offset = -12;
$this->seek(-12, SEEK_END);
$type['size'] = unpack('V', $this->read(4));
$type['size'] = $type['size'][1];
}
$this->seek($offset - $type['size'], SEEK_END);
$hash = $this->read($type['size']);
$hash = unpack('H*', $hash);
return array(
'hash_type' => $type['name'],
'hash' => strtoupper($hash[1])
);
} | php | public function get($required = null)
{
if (null === $required) {
$required = (bool) ini_get('phar.require_hash');
}
$this->seek(-4, SEEK_END);
if ('GBMB' !== $this->read(4)) {
if ($required) {
throw new PharException(
sprintf(
'The phar "%s" is not signed.',
$this->file
)
);
}
return null;
}
$this->seek(-8, SEEK_END);
$flag = unpack('V', $this->read(4));
$flag = $flag[1];
foreach (self::$types as $type) {
if ($flag === $type['flag']) {
break;
}
unset($type);
}
if (!isset($type)) {
throw new PharException(
sprintf(
'The signature type (%x) is not recognized for the phar "%s".',
$flag,
$this->file
)
);
}
$offset = -8;
if (0x10 === $type['flag']) {
$offset = -12;
$this->seek(-12, SEEK_END);
$type['size'] = unpack('V', $this->read(4));
$type['size'] = $type['size'][1];
}
$this->seek($offset - $type['size'], SEEK_END);
$hash = $this->read($type['size']);
$hash = unpack('H*', $hash);
return array(
'hash_type' => $type['name'],
'hash' => strtoupper($hash[1])
);
} | [
"public",
"function",
"get",
"(",
"$",
"required",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"required",
")",
"{",
"$",
"required",
"=",
"(",
"bool",
")",
"ini_get",
"(",
"'phar.require_hash'",
")",
";",
"}",
"$",
"this",
"->",
"seek",
"(",
"-",
"4",
",",
"SEEK_END",
")",
";",
"if",
"(",
"'GBMB'",
"!==",
"$",
"this",
"->",
"read",
"(",
"4",
")",
")",
"{",
"if",
"(",
"$",
"required",
")",
"{",
"throw",
"new",
"PharException",
"(",
"sprintf",
"(",
"'The phar \"%s\" is not signed.'",
",",
"$",
"this",
"->",
"file",
")",
")",
";",
"}",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"seek",
"(",
"-",
"8",
",",
"SEEK_END",
")",
";",
"$",
"flag",
"=",
"unpack",
"(",
"'V'",
",",
"$",
"this",
"->",
"read",
"(",
"4",
")",
")",
";",
"$",
"flag",
"=",
"$",
"flag",
"[",
"1",
"]",
";",
"foreach",
"(",
"self",
"::",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"flag",
"===",
"$",
"type",
"[",
"'flag'",
"]",
")",
"{",
"break",
";",
"}",
"unset",
"(",
"$",
"type",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"type",
")",
")",
"{",
"throw",
"new",
"PharException",
"(",
"sprintf",
"(",
"'The signature type (%x) is not recognized for the phar \"%s\".'",
",",
"$",
"flag",
",",
"$",
"this",
"->",
"file",
")",
")",
";",
"}",
"$",
"offset",
"=",
"-",
"8",
";",
"if",
"(",
"0x10",
"===",
"$",
"type",
"[",
"'flag'",
"]",
")",
"{",
"$",
"offset",
"=",
"-",
"12",
";",
"$",
"this",
"->",
"seek",
"(",
"-",
"12",
",",
"SEEK_END",
")",
";",
"$",
"type",
"[",
"'size'",
"]",
"=",
"unpack",
"(",
"'V'",
",",
"$",
"this",
"->",
"read",
"(",
"4",
")",
")",
";",
"$",
"type",
"[",
"'size'",
"]",
"=",
"$",
"type",
"[",
"'size'",
"]",
"[",
"1",
"]",
";",
"}",
"$",
"this",
"->",
"seek",
"(",
"$",
"offset",
"-",
"$",
"type",
"[",
"'size'",
"]",
",",
"SEEK_END",
")",
";",
"$",
"hash",
"=",
"$",
"this",
"->",
"read",
"(",
"$",
"type",
"[",
"'size'",
"]",
")",
";",
"$",
"hash",
"=",
"unpack",
"(",
"'H*'",
",",
"$",
"hash",
")",
";",
"return",
"array",
"(",
"'hash_type'",
"=>",
"$",
"type",
"[",
"'name'",
"]",
",",
"'hash'",
"=>",
"strtoupper",
"(",
"$",
"hash",
"[",
"1",
"]",
")",
")",
";",
"}"
] | Returns the signature for the phar.
The value returned is identical to that of `Phar->getSignature()`. If
$required is not given, it will default to the `phar.require_hash`
current value.
@param boolean $required Is the signature required?
@return array The signature.
@throws PharException If the phar is not valid. | [
"Returns",
"the",
"signature",
"for",
"the",
"phar",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Signature.php#L138-L202 |
33,214 | box-project/box2-lib | src/lib/Herrera/Box/Signature.php | Signature.verify | public function verify()
{
$signature = $this->get();
$size = $this->size;
$type = null;
foreach (self::$types as $type) {
if ($type['name'] === $signature['hash_type']) {
if (0x10 === $type['flag']) {
$this->seek(-12, SEEK_END);
$less = $this->read(4);
$less = unpack('V', $less);
$less = $less[1];
$size -= 12 + $less;
} else {
$size -= 8 + $type['size'];
}
break;
}
}
$this->seek(0);
/** @var $verify VerifyInterface */
$verify = new $type['class']();
$verify->init($type['name'], $this->file);
$buffer = 64;
while (0 < $size) {
if ($size < $buffer) {
$buffer = $size;
$size = 0;
}
$verify->update($this->read($buffer));
$size -= $buffer;
}
return $verify->verify($signature['hash']);
} | php | public function verify()
{
$signature = $this->get();
$size = $this->size;
$type = null;
foreach (self::$types as $type) {
if ($type['name'] === $signature['hash_type']) {
if (0x10 === $type['flag']) {
$this->seek(-12, SEEK_END);
$less = $this->read(4);
$less = unpack('V', $less);
$less = $less[1];
$size -= 12 + $less;
} else {
$size -= 8 + $type['size'];
}
break;
}
}
$this->seek(0);
/** @var $verify VerifyInterface */
$verify = new $type['class']();
$verify->init($type['name'], $this->file);
$buffer = 64;
while (0 < $size) {
if ($size < $buffer) {
$buffer = $size;
$size = 0;
}
$verify->update($this->read($buffer));
$size -= $buffer;
}
return $verify->verify($signature['hash']);
} | [
"public",
"function",
"verify",
"(",
")",
"{",
"$",
"signature",
"=",
"$",
"this",
"->",
"get",
"(",
")",
";",
"$",
"size",
"=",
"$",
"this",
"->",
"size",
";",
"$",
"type",
"=",
"null",
";",
"foreach",
"(",
"self",
"::",
"$",
"types",
"as",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"[",
"'name'",
"]",
"===",
"$",
"signature",
"[",
"'hash_type'",
"]",
")",
"{",
"if",
"(",
"0x10",
"===",
"$",
"type",
"[",
"'flag'",
"]",
")",
"{",
"$",
"this",
"->",
"seek",
"(",
"-",
"12",
",",
"SEEK_END",
")",
";",
"$",
"less",
"=",
"$",
"this",
"->",
"read",
"(",
"4",
")",
";",
"$",
"less",
"=",
"unpack",
"(",
"'V'",
",",
"$",
"less",
")",
";",
"$",
"less",
"=",
"$",
"less",
"[",
"1",
"]",
";",
"$",
"size",
"-=",
"12",
"+",
"$",
"less",
";",
"}",
"else",
"{",
"$",
"size",
"-=",
"8",
"+",
"$",
"type",
"[",
"'size'",
"]",
";",
"}",
"break",
";",
"}",
"}",
"$",
"this",
"->",
"seek",
"(",
"0",
")",
";",
"/** @var $verify VerifyInterface */",
"$",
"verify",
"=",
"new",
"$",
"type",
"[",
"'class'",
"]",
"(",
")",
";",
"$",
"verify",
"->",
"init",
"(",
"$",
"type",
"[",
"'name'",
"]",
",",
"$",
"this",
"->",
"file",
")",
";",
"$",
"buffer",
"=",
"64",
";",
"while",
"(",
"0",
"<",
"$",
"size",
")",
"{",
"if",
"(",
"$",
"size",
"<",
"$",
"buffer",
")",
"{",
"$",
"buffer",
"=",
"$",
"size",
";",
"$",
"size",
"=",
"0",
";",
"}",
"$",
"verify",
"->",
"update",
"(",
"$",
"this",
"->",
"read",
"(",
"$",
"buffer",
")",
")",
";",
"$",
"size",
"-=",
"$",
"buffer",
";",
"}",
"return",
"$",
"verify",
"->",
"verify",
"(",
"$",
"signature",
"[",
"'hash'",
"]",
")",
";",
"}"
] | Verifies the signature of the phar.
@return boolean TRUE if verified, FALSE if not.
@throws Exception
@throws FileException If the private key could not be read.
@throws OpenSslException If there is an OpenSSL error. | [
"Verifies",
"the",
"signature",
"of",
"the",
"phar",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Signature.php#L213-L258 |
33,215 | box-project/box2-lib | src/lib/Herrera/Box/Signature.php | Signature.handle | private function handle()
{
if (!$this->handle) {
if (!($this->handle = @fopen($this->file, 'rb'))) {
throw FileException::lastError();
}
}
return $this->handle;
} | php | private function handle()
{
if (!$this->handle) {
if (!($this->handle = @fopen($this->file, 'rb'))) {
throw FileException::lastError();
}
}
return $this->handle;
} | [
"private",
"function",
"handle",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"handle",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"this",
"->",
"handle",
"=",
"@",
"fopen",
"(",
"$",
"this",
"->",
"file",
",",
"'rb'",
")",
")",
")",
"{",
"throw",
"FileException",
"::",
"lastError",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"handle",
";",
"}"
] | Returns the file handle.
If the file handle is not opened, it will be automatically opened.
@return resource The file handle.
@throws Exception
@throws FileException If the file could not be opened. | [
"Returns",
"the",
"file",
"handle",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Signature.php#L282-L291 |
33,216 | box-project/box2-lib | src/lib/Herrera/Box/Signature.php | Signature.read | private function read($bytes)
{
if (false === ($read = @fread($this->handle(), $bytes))) {
throw FileException::lastError();
}
if (($actual = strlen($read)) !== $bytes) {
throw FileException::create(
'Only read %d of %d bytes from "%s".',
$actual,
$bytes,
$this->file
);
}
return $read;
} | php | private function read($bytes)
{
if (false === ($read = @fread($this->handle(), $bytes))) {
throw FileException::lastError();
}
if (($actual = strlen($read)) !== $bytes) {
throw FileException::create(
'Only read %d of %d bytes from "%s".',
$actual,
$bytes,
$this->file
);
}
return $read;
} | [
"private",
"function",
"read",
"(",
"$",
"bytes",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"read",
"=",
"@",
"fread",
"(",
"$",
"this",
"->",
"handle",
"(",
")",
",",
"$",
"bytes",
")",
")",
")",
"{",
"throw",
"FileException",
"::",
"lastError",
"(",
")",
";",
"}",
"if",
"(",
"(",
"$",
"actual",
"=",
"strlen",
"(",
"$",
"read",
")",
")",
"!==",
"$",
"bytes",
")",
"{",
"throw",
"FileException",
"::",
"create",
"(",
"'Only read %d of %d bytes from \"%s\".'",
",",
"$",
"actual",
",",
"$",
"bytes",
",",
"$",
"this",
"->",
"file",
")",
";",
"}",
"return",
"$",
"read",
";",
"}"
] | Reads a number of bytes from the file.
@param integer $bytes The number of bytes.
@return string The read bytes.
@throws Exception
@throws FileException If the file could not be read. | [
"Reads",
"a",
"number",
"of",
"bytes",
"from",
"the",
"file",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Signature.php#L303-L319 |
33,217 | box-project/box2-lib | src/lib/Herrera/Box/Compactor/Php.php | Php.setTokenizer | public function setTokenizer(Tokenizer $tokenizer)
{
if (null === $this->converter) {
$this->converter = new ToString();
}
$this->tokenizer = $tokenizer;
} | php | public function setTokenizer(Tokenizer $tokenizer)
{
if (null === $this->converter) {
$this->converter = new ToString();
}
$this->tokenizer = $tokenizer;
} | [
"public",
"function",
"setTokenizer",
"(",
"Tokenizer",
"$",
"tokenizer",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"converter",
")",
"{",
"$",
"this",
"->",
"converter",
"=",
"new",
"ToString",
"(",
")",
";",
"}",
"$",
"this",
"->",
"tokenizer",
"=",
"$",
"tokenizer",
";",
"}"
] | Sets the annotations tokenizer.
@param Tokenizer $tokenizer The tokenizer. | [
"Sets",
"the",
"annotations",
"tokenizer",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Compactor/Php.php#L76-L83 |
33,218 | box-project/box2-lib | src/lib/Herrera/Box/Compactor/Php.php | Php.compactAnnotations | private function compactAnnotations($docblock)
{
$annotations = array();
$index = -1;
$inside = 0;
$tokens = $this->tokenizer->parse($docblock);
if (empty($tokens)) {
return str_repeat("\n", substr_count($docblock, "\n"));
}
foreach ($tokens as $token) {
if ((0 === $inside) && (DocLexer::T_AT === $token[0])) {
$index++;
} elseif (DocLexer::T_OPEN_PARENTHESIS === $token[0]) {
$inside++;
} elseif (DocLexer::T_CLOSE_PARENTHESIS === $token[0]) {
$inside--;
}
if (!isset($annotations[$index])) {
$annotations[$index] = array();
}
$annotations[$index][] = $token;
}
$breaks = substr_count($docblock, "\n");
$docblock = "/**";
foreach ($annotations as $annotation) {
$annotation = new Tokens($annotation);
$docblock .= "\n" . $this->converter->convert($annotation);
}
$breaks -= count($annotations);
if ($breaks > 0) {
$docblock .= str_repeat("\n", $breaks - 1);
$docblock .= "\n*/";
} else {
$docblock .= ' */';
}
return $docblock;
} | php | private function compactAnnotations($docblock)
{
$annotations = array();
$index = -1;
$inside = 0;
$tokens = $this->tokenizer->parse($docblock);
if (empty($tokens)) {
return str_repeat("\n", substr_count($docblock, "\n"));
}
foreach ($tokens as $token) {
if ((0 === $inside) && (DocLexer::T_AT === $token[0])) {
$index++;
} elseif (DocLexer::T_OPEN_PARENTHESIS === $token[0]) {
$inside++;
} elseif (DocLexer::T_CLOSE_PARENTHESIS === $token[0]) {
$inside--;
}
if (!isset($annotations[$index])) {
$annotations[$index] = array();
}
$annotations[$index][] = $token;
}
$breaks = substr_count($docblock, "\n");
$docblock = "/**";
foreach ($annotations as $annotation) {
$annotation = new Tokens($annotation);
$docblock .= "\n" . $this->converter->convert($annotation);
}
$breaks -= count($annotations);
if ($breaks > 0) {
$docblock .= str_repeat("\n", $breaks - 1);
$docblock .= "\n*/";
} else {
$docblock .= ' */';
}
return $docblock;
} | [
"private",
"function",
"compactAnnotations",
"(",
"$",
"docblock",
")",
"{",
"$",
"annotations",
"=",
"array",
"(",
")",
";",
"$",
"index",
"=",
"-",
"1",
";",
"$",
"inside",
"=",
"0",
";",
"$",
"tokens",
"=",
"$",
"this",
"->",
"tokenizer",
"->",
"parse",
"(",
"$",
"docblock",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"tokens",
")",
")",
"{",
"return",
"str_repeat",
"(",
"\"\\n\"",
",",
"substr_count",
"(",
"$",
"docblock",
",",
"\"\\n\"",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"tokens",
"as",
"$",
"token",
")",
"{",
"if",
"(",
"(",
"0",
"===",
"$",
"inside",
")",
"&&",
"(",
"DocLexer",
"::",
"T_AT",
"===",
"$",
"token",
"[",
"0",
"]",
")",
")",
"{",
"$",
"index",
"++",
";",
"}",
"elseif",
"(",
"DocLexer",
"::",
"T_OPEN_PARENTHESIS",
"===",
"$",
"token",
"[",
"0",
"]",
")",
"{",
"$",
"inside",
"++",
";",
"}",
"elseif",
"(",
"DocLexer",
"::",
"T_CLOSE_PARENTHESIS",
"===",
"$",
"token",
"[",
"0",
"]",
")",
"{",
"$",
"inside",
"--",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"annotations",
"[",
"$",
"index",
"]",
")",
")",
"{",
"$",
"annotations",
"[",
"$",
"index",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"annotations",
"[",
"$",
"index",
"]",
"[",
"]",
"=",
"$",
"token",
";",
"}",
"$",
"breaks",
"=",
"substr_count",
"(",
"$",
"docblock",
",",
"\"\\n\"",
")",
";",
"$",
"docblock",
"=",
"\"/**\"",
";",
"foreach",
"(",
"$",
"annotations",
"as",
"$",
"annotation",
")",
"{",
"$",
"annotation",
"=",
"new",
"Tokens",
"(",
"$",
"annotation",
")",
";",
"$",
"docblock",
".=",
"\"\\n\"",
".",
"$",
"this",
"->",
"converter",
"->",
"convert",
"(",
"$",
"annotation",
")",
";",
"}",
"$",
"breaks",
"-=",
"count",
"(",
"$",
"annotations",
")",
";",
"if",
"(",
"$",
"breaks",
">",
"0",
")",
"{",
"$",
"docblock",
".=",
"str_repeat",
"(",
"\"\\n\"",
",",
"$",
"breaks",
"-",
"1",
")",
";",
"$",
"docblock",
".=",
"\"\\n*/\"",
";",
"}",
"else",
"{",
"$",
"docblock",
".=",
"' */'",
";",
"}",
"return",
"$",
"docblock",
";",
"}"
] | Compacts the docblock and its annotations.
@param string $docblock The docblock.
@return string The compacted docblock. | [
"Compacts",
"the",
"docblock",
"and",
"its",
"annotations",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Compactor/Php.php#L92-L137 |
33,219 | box-project/box2-lib | src/lib/Herrera/Box/Extract.php | Extract.findStubLength | public static function findStubLength(
$file,
$pattern = self::PATTERN_OPEN
) {
if (!($fp = fopen($file, 'rb'))) {
throw new RuntimeException(
sprintf(
'The phar "%s" could not be opened for reading.',
$file
)
);
}
$stub = null;
$offset = 0;
$combo = str_split($pattern);
while (!feof($fp)) {
if (fgetc($fp) === $combo[$offset]) {
$offset++;
if (!isset($combo[$offset])) {
$stub = ftell($fp);
break;
}
} else {
$offset = 0;
}
}
fclose($fp);
if (null === $stub) {
throw new InvalidArgumentException(
sprintf(
'The pattern could not be found in "%s".',
$file
)
);
}
return $stub;
} | php | public static function findStubLength(
$file,
$pattern = self::PATTERN_OPEN
) {
if (!($fp = fopen($file, 'rb'))) {
throw new RuntimeException(
sprintf(
'The phar "%s" could not be opened for reading.',
$file
)
);
}
$stub = null;
$offset = 0;
$combo = str_split($pattern);
while (!feof($fp)) {
if (fgetc($fp) === $combo[$offset]) {
$offset++;
if (!isset($combo[$offset])) {
$stub = ftell($fp);
break;
}
} else {
$offset = 0;
}
}
fclose($fp);
if (null === $stub) {
throw new InvalidArgumentException(
sprintf(
'The pattern could not be found in "%s".',
$file
)
);
}
return $stub;
} | [
"public",
"static",
"function",
"findStubLength",
"(",
"$",
"file",
",",
"$",
"pattern",
"=",
"self",
"::",
"PATTERN_OPEN",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"file",
",",
"'rb'",
")",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'The phar \"%s\" could not be opened for reading.'",
",",
"$",
"file",
")",
")",
";",
"}",
"$",
"stub",
"=",
"null",
";",
"$",
"offset",
"=",
"0",
";",
"$",
"combo",
"=",
"str_split",
"(",
"$",
"pattern",
")",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"fp",
")",
")",
"{",
"if",
"(",
"fgetc",
"(",
"$",
"fp",
")",
"===",
"$",
"combo",
"[",
"$",
"offset",
"]",
")",
"{",
"$",
"offset",
"++",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"combo",
"[",
"$",
"offset",
"]",
")",
")",
"{",
"$",
"stub",
"=",
"ftell",
"(",
"$",
"fp",
")",
";",
"break",
";",
"}",
"}",
"else",
"{",
"$",
"offset",
"=",
"0",
";",
"}",
"}",
"fclose",
"(",
"$",
"fp",
")",
";",
"if",
"(",
"null",
"===",
"$",
"stub",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The pattern could not be found in \"%s\".'",
",",
"$",
"file",
")",
")",
";",
"}",
"return",
"$",
"stub",
";",
"}"
] | Finds the phar's stub length using the end pattern.
A "pattern" is a sequence of characters that indicate the end of a
stub, and the beginning of a manifest. This determines the complete
size of a stub, and is used as an offset to begin parsing the data
contained in the phar's manifest.
The stub generated included with the Box library uses what I like
to call an open-ended pattern. This pattern uses the function
"__HALT_COMPILER();" at the end, with no following whitespace or
closing PHP tag. By default, this method will use that pattern,
defined as `Extract::PATTERN_OPEN`.
The Phar class generates its own default stub. The pattern for the
default stub is slightly different than the one used by Box. This
pattern is defined as `Extract::PATTERN_DEFAULT`.
If you have used your own custom stub, you will need to specify its
pattern as the `$pattern` argument, if you cannot use either of the
pattern constants defined.
@param string $file The phar file path.
@param string $pattern The stub end pattern.
@return integer The stub length.
@throws InvalidArgumentException If the pattern could not be found.
@throws RuntimeException If the phar could not be read. | [
"Finds",
"the",
"phar",
"s",
"stub",
"length",
"using",
"the",
"end",
"pattern",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Extract.php#L145-L188 |
33,220 | box-project/box2-lib | src/lib/Herrera/Box/Extract.php | Extract.go | public function go($dir = null)
{
// set up the output directory
if (null === $dir) {
$dir = rtrim(sys_get_temp_dir(), '\\/')
. DIRECTORY_SEPARATOR
. 'pharextract'
. DIRECTORY_SEPARATOR
. basename($this->file, '.phar');
} else {
$dir = realpath($dir);
}
// skip if already extracted
$md5 = $dir . DIRECTORY_SEPARATOR . md5_file($this->file);
if (file_exists($md5)) {
return $dir;
}
if (!is_dir($dir)) {
$this->createDir($dir);
}
// open the file and skip stub
$this->open();
if (-1 === fseek($this->handle, $this->stub)) {
throw new RuntimeException(
sprintf(
'Could not seek to %d in the file "%s".',
$this->stub,
$this->file
)
);
}
// read the manifest
$info = $this->readManifest();
if ($info['flags'] & self::GZ) {
if (!function_exists('gzinflate')) {
throw new RuntimeException(
'The zlib extension is (gzinflate()) is required for "%s.',
$this->file
);
}
}
if ($info['flags'] & self::BZ2) {
if (!function_exists('bzdecompress')) {
throw new RuntimeException(
'The bzip2 extension (bzdecompress()) is required for "%s".',
$this->file
);
}
}
self::purge($dir);
$this->createDir($dir);
$this->createFile($md5);
foreach ($info['files'] as $info) {
$path = $dir . DIRECTORY_SEPARATOR . $info['path'];
$parent = dirname($path);
if (!is_dir($parent)) {
$this->createDir($parent);
}
if (preg_match('{/$}', $info['path'])) {
$this->createDir($path, 0777, false);
} else {
$this->createFile(
$path,
$this->extractFile($info)
);
}
}
return $dir;
} | php | public function go($dir = null)
{
// set up the output directory
if (null === $dir) {
$dir = rtrim(sys_get_temp_dir(), '\\/')
. DIRECTORY_SEPARATOR
. 'pharextract'
. DIRECTORY_SEPARATOR
. basename($this->file, '.phar');
} else {
$dir = realpath($dir);
}
// skip if already extracted
$md5 = $dir . DIRECTORY_SEPARATOR . md5_file($this->file);
if (file_exists($md5)) {
return $dir;
}
if (!is_dir($dir)) {
$this->createDir($dir);
}
// open the file and skip stub
$this->open();
if (-1 === fseek($this->handle, $this->stub)) {
throw new RuntimeException(
sprintf(
'Could not seek to %d in the file "%s".',
$this->stub,
$this->file
)
);
}
// read the manifest
$info = $this->readManifest();
if ($info['flags'] & self::GZ) {
if (!function_exists('gzinflate')) {
throw new RuntimeException(
'The zlib extension is (gzinflate()) is required for "%s.',
$this->file
);
}
}
if ($info['flags'] & self::BZ2) {
if (!function_exists('bzdecompress')) {
throw new RuntimeException(
'The bzip2 extension (bzdecompress()) is required for "%s".',
$this->file
);
}
}
self::purge($dir);
$this->createDir($dir);
$this->createFile($md5);
foreach ($info['files'] as $info) {
$path = $dir . DIRECTORY_SEPARATOR . $info['path'];
$parent = dirname($path);
if (!is_dir($parent)) {
$this->createDir($parent);
}
if (preg_match('{/$}', $info['path'])) {
$this->createDir($path, 0777, false);
} else {
$this->createFile(
$path,
$this->extractFile($info)
);
}
}
return $dir;
} | [
"public",
"function",
"go",
"(",
"$",
"dir",
"=",
"null",
")",
"{",
"// set up the output directory",
"if",
"(",
"null",
"===",
"$",
"dir",
")",
"{",
"$",
"dir",
"=",
"rtrim",
"(",
"sys_get_temp_dir",
"(",
")",
",",
"'\\\\/'",
")",
".",
"DIRECTORY_SEPARATOR",
".",
"'pharextract'",
".",
"DIRECTORY_SEPARATOR",
".",
"basename",
"(",
"$",
"this",
"->",
"file",
",",
"'.phar'",
")",
";",
"}",
"else",
"{",
"$",
"dir",
"=",
"realpath",
"(",
"$",
"dir",
")",
";",
"}",
"// skip if already extracted",
"$",
"md5",
"=",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"md5_file",
"(",
"$",
"this",
"->",
"file",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"md5",
")",
")",
"{",
"return",
"$",
"dir",
";",
"}",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"$",
"this",
"->",
"createDir",
"(",
"$",
"dir",
")",
";",
"}",
"// open the file and skip stub",
"$",
"this",
"->",
"open",
"(",
")",
";",
"if",
"(",
"-",
"1",
"===",
"fseek",
"(",
"$",
"this",
"->",
"handle",
",",
"$",
"this",
"->",
"stub",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Could not seek to %d in the file \"%s\".'",
",",
"$",
"this",
"->",
"stub",
",",
"$",
"this",
"->",
"file",
")",
")",
";",
"}",
"// read the manifest",
"$",
"info",
"=",
"$",
"this",
"->",
"readManifest",
"(",
")",
";",
"if",
"(",
"$",
"info",
"[",
"'flags'",
"]",
"&",
"self",
"::",
"GZ",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'gzinflate'",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'The zlib extension is (gzinflate()) is required for \"%s.'",
",",
"$",
"this",
"->",
"file",
")",
";",
"}",
"}",
"if",
"(",
"$",
"info",
"[",
"'flags'",
"]",
"&",
"self",
"::",
"BZ2",
")",
"{",
"if",
"(",
"!",
"function_exists",
"(",
"'bzdecompress'",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'The bzip2 extension (bzdecompress()) is required for \"%s\".'",
",",
"$",
"this",
"->",
"file",
")",
";",
"}",
"}",
"self",
"::",
"purge",
"(",
"$",
"dir",
")",
";",
"$",
"this",
"->",
"createDir",
"(",
"$",
"dir",
")",
";",
"$",
"this",
"->",
"createFile",
"(",
"$",
"md5",
")",
";",
"foreach",
"(",
"$",
"info",
"[",
"'files'",
"]",
"as",
"$",
"info",
")",
"{",
"$",
"path",
"=",
"$",
"dir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"info",
"[",
"'path'",
"]",
";",
"$",
"parent",
"=",
"dirname",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"is_dir",
"(",
"$",
"parent",
")",
")",
"{",
"$",
"this",
"->",
"createDir",
"(",
"$",
"parent",
")",
";",
"}",
"if",
"(",
"preg_match",
"(",
"'{/$}'",
",",
"$",
"info",
"[",
"'path'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"createDir",
"(",
"$",
"path",
",",
"0777",
",",
"false",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"createFile",
"(",
"$",
"path",
",",
"$",
"this",
"->",
"extractFile",
"(",
"$",
"info",
")",
")",
";",
"}",
"}",
"return",
"$",
"dir",
";",
"}"
] | Extracts the phar to the directory path.
If no directory path is given, a temporary one will be generated and
returned. If a directory path is given, the returned directory path
will be the same.
@param string $dir The directory to extract to.
@return string The directory extracted to.
@throws LengthException
@throws RuntimeException | [
"Extracts",
"the",
"phar",
"to",
"the",
"directory",
"path",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Extract.php#L204-L285 |
33,221 | box-project/box2-lib | src/lib/Herrera/Box/Extract.php | Extract.purge | public static function purge($path)
{
if (is_dir($path)) {
foreach (scandir($path) as $item) {
if (('.' === $item) || ('..' === $item)) {
continue;
}
self::purge($path . DIRECTORY_SEPARATOR . $item);
}
if (!rmdir($path)) {
throw new RuntimeException(
sprintf(
'The directory "%s" could not be deleted.',
$path
)
);
}
} else {
if (!unlink($path)) {
throw new RuntimeException(
sprintf(
'The file "%s" could not be deleted.',
$path
)
);
}
}
} | php | public static function purge($path)
{
if (is_dir($path)) {
foreach (scandir($path) as $item) {
if (('.' === $item) || ('..' === $item)) {
continue;
}
self::purge($path . DIRECTORY_SEPARATOR . $item);
}
if (!rmdir($path)) {
throw new RuntimeException(
sprintf(
'The directory "%s" could not be deleted.',
$path
)
);
}
} else {
if (!unlink($path)) {
throw new RuntimeException(
sprintf(
'The file "%s" could not be deleted.',
$path
)
);
}
}
} | [
"public",
"static",
"function",
"purge",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"path",
")",
")",
"{",
"foreach",
"(",
"scandir",
"(",
"$",
"path",
")",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"(",
"'.'",
"===",
"$",
"item",
")",
"||",
"(",
"'..'",
"===",
"$",
"item",
")",
")",
"{",
"continue",
";",
"}",
"self",
"::",
"purge",
"(",
"$",
"path",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"item",
")",
";",
"}",
"if",
"(",
"!",
"rmdir",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'The directory \"%s\" could not be deleted.'",
",",
"$",
"path",
")",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"!",
"unlink",
"(",
"$",
"path",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'The file \"%s\" could not be deleted.'",
",",
"$",
"path",
")",
")",
";",
"}",
"}",
"}"
] | Recursively deletes the directory or file path.
@param string $path The path to delete.
@throws RuntimeException If the path could not be deleted. | [
"Recursively",
"deletes",
"the",
"directory",
"or",
"file",
"path",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Extract.php#L294-L323 |
33,222 | box-project/box2-lib | src/lib/Herrera/Box/Extract.php | Extract.extractFile | private function extractFile($info)
{
if (0 === $info['size']) {
return '';
}
$data = $this->read($info['compressed_size']);
if ($info['flags'] & self::GZ) {
if (false === ($data = gzinflate($data))) {
throw new RuntimeException(
sprintf(
'The "%s" file could not be inflated (gzip) from "%s".',
$info['path'],
$this->file
)
);
}
} elseif ($info['flags'] & self::BZ2) {
if (false === ($data = bzdecompress($data))) {
throw new RuntimeException(
sprintf(
'The "%s" file could not be inflated (bzip2) from "%s".',
$info['path'],
$this->file
)
);
}
}
if (($actual = strlen($data)) !== $info['size']) {
throw new UnexpectedValueException(
sprintf(
'The size of "%s" (%d) did not match what was expected (%d) in "%s".',
$info['path'],
$actual,
$info['size'],
$this->file
)
);
}
$crc32 = sprintf('%u', crc32($data) & 0xffffffff);
if ($info['crc32'] != $crc32) {
throw new UnexpectedValueException(
sprintf(
'The crc32 checksum (%s) for "%s" did not match what was expected (%s) in "%s".',
$crc32,
$info['path'],
$info['crc32'],
$this->file
)
);
}
return $data;
} | php | private function extractFile($info)
{
if (0 === $info['size']) {
return '';
}
$data = $this->read($info['compressed_size']);
if ($info['flags'] & self::GZ) {
if (false === ($data = gzinflate($data))) {
throw new RuntimeException(
sprintf(
'The "%s" file could not be inflated (gzip) from "%s".',
$info['path'],
$this->file
)
);
}
} elseif ($info['flags'] & self::BZ2) {
if (false === ($data = bzdecompress($data))) {
throw new RuntimeException(
sprintf(
'The "%s" file could not be inflated (bzip2) from "%s".',
$info['path'],
$this->file
)
);
}
}
if (($actual = strlen($data)) !== $info['size']) {
throw new UnexpectedValueException(
sprintf(
'The size of "%s" (%d) did not match what was expected (%d) in "%s".',
$info['path'],
$actual,
$info['size'],
$this->file
)
);
}
$crc32 = sprintf('%u', crc32($data) & 0xffffffff);
if ($info['crc32'] != $crc32) {
throw new UnexpectedValueException(
sprintf(
'The crc32 checksum (%s) for "%s" did not match what was expected (%s) in "%s".',
$crc32,
$info['path'],
$info['crc32'],
$this->file
)
);
}
return $data;
} | [
"private",
"function",
"extractFile",
"(",
"$",
"info",
")",
"{",
"if",
"(",
"0",
"===",
"$",
"info",
"[",
"'size'",
"]",
")",
"{",
"return",
"''",
";",
"}",
"$",
"data",
"=",
"$",
"this",
"->",
"read",
"(",
"$",
"info",
"[",
"'compressed_size'",
"]",
")",
";",
"if",
"(",
"$",
"info",
"[",
"'flags'",
"]",
"&",
"self",
"::",
"GZ",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"data",
"=",
"gzinflate",
"(",
"$",
"data",
")",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'The \"%s\" file could not be inflated (gzip) from \"%s\".'",
",",
"$",
"info",
"[",
"'path'",
"]",
",",
"$",
"this",
"->",
"file",
")",
")",
";",
"}",
"}",
"elseif",
"(",
"$",
"info",
"[",
"'flags'",
"]",
"&",
"self",
"::",
"BZ2",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"data",
"=",
"bzdecompress",
"(",
"$",
"data",
")",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'The \"%s\" file could not be inflated (bzip2) from \"%s\".'",
",",
"$",
"info",
"[",
"'path'",
"]",
",",
"$",
"this",
"->",
"file",
")",
")",
";",
"}",
"}",
"if",
"(",
"(",
"$",
"actual",
"=",
"strlen",
"(",
"$",
"data",
")",
")",
"!==",
"$",
"info",
"[",
"'size'",
"]",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'The size of \"%s\" (%d) did not match what was expected (%d) in \"%s\".'",
",",
"$",
"info",
"[",
"'path'",
"]",
",",
"$",
"actual",
",",
"$",
"info",
"[",
"'size'",
"]",
",",
"$",
"this",
"->",
"file",
")",
")",
";",
"}",
"$",
"crc32",
"=",
"sprintf",
"(",
"'%u'",
",",
"crc32",
"(",
"$",
"data",
")",
"&",
"0xffffffff",
")",
";",
"if",
"(",
"$",
"info",
"[",
"'crc32'",
"]",
"!=",
"$",
"crc32",
")",
"{",
"throw",
"new",
"UnexpectedValueException",
"(",
"sprintf",
"(",
"'The crc32 checksum (%s) for \"%s\" did not match what was expected (%s) in \"%s\".'",
",",
"$",
"crc32",
",",
"$",
"info",
"[",
"'path'",
"]",
",",
"$",
"info",
"[",
"'crc32'",
"]",
",",
"$",
"this",
"->",
"file",
")",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Extracts a single file from the phar.
@param array $info The file information.
@return string The file data.
@throws RuntimeException If the file could not be extracted.
@throws UnexpectedValueException If the crc32 checksum does not
match the expected value. | [
"Extracts",
"a",
"single",
"file",
"from",
"the",
"phar",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Extract.php#L388-L445 |
33,223 | box-project/box2-lib | src/lib/Herrera/Box/Extract.php | Extract.open | private function open()
{
if (null === ($this->handle = fopen($this->file, 'rb'))) {
$this->handle = null;
throw new RuntimeException(
sprintf(
'The file "%s" could not be opened for reading.',
$this->file
)
);
}
} | php | private function open()
{
if (null === ($this->handle = fopen($this->file, 'rb'))) {
$this->handle = null;
throw new RuntimeException(
sprintf(
'The file "%s" could not be opened for reading.',
$this->file
)
);
}
} | [
"private",
"function",
"open",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"(",
"$",
"this",
"->",
"handle",
"=",
"fopen",
"(",
"$",
"this",
"->",
"file",
",",
"'rb'",
")",
")",
")",
"{",
"$",
"this",
"->",
"handle",
"=",
"null",
";",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'The file \"%s\" could not be opened for reading.'",
",",
"$",
"this",
"->",
"file",
")",
")",
";",
"}",
"}"
] | Opens the file for reading.
@throws RuntimeException If the file could not be opened. | [
"Opens",
"the",
"file",
"for",
"reading",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Extract.php#L452-L464 |
33,224 | box-project/box2-lib | src/lib/Herrera/Box/Extract.php | Extract.read | private function read($bytes)
{
$read = '';
$total = $bytes;
while (!feof($this->handle) && $bytes) {
if (false === ($chunk = fread($this->handle, $bytes))) {
throw new RuntimeException(
sprintf(
'Could not read %d bytes from "%s".',
$bytes,
$this->file
)
);
}
$read .= $chunk;
$bytes -= strlen($chunk);
}
if (($actual = strlen($read)) !== $total) {
throw new RuntimeException(
sprintf(
'Only read %d of %d in "%s".',
$actual,
$total,
$this->file
)
);
}
return $read;
} | php | private function read($bytes)
{
$read = '';
$total = $bytes;
while (!feof($this->handle) && $bytes) {
if (false === ($chunk = fread($this->handle, $bytes))) {
throw new RuntimeException(
sprintf(
'Could not read %d bytes from "%s".',
$bytes,
$this->file
)
);
}
$read .= $chunk;
$bytes -= strlen($chunk);
}
if (($actual = strlen($read)) !== $total) {
throw new RuntimeException(
sprintf(
'Only read %d of %d in "%s".',
$actual,
$total,
$this->file
)
);
}
return $read;
} | [
"private",
"function",
"read",
"(",
"$",
"bytes",
")",
"{",
"$",
"read",
"=",
"''",
";",
"$",
"total",
"=",
"$",
"bytes",
";",
"while",
"(",
"!",
"feof",
"(",
"$",
"this",
"->",
"handle",
")",
"&&",
"$",
"bytes",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"chunk",
"=",
"fread",
"(",
"$",
"this",
"->",
"handle",
",",
"$",
"bytes",
")",
")",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Could not read %d bytes from \"%s\".'",
",",
"$",
"bytes",
",",
"$",
"this",
"->",
"file",
")",
")",
";",
"}",
"$",
"read",
".=",
"$",
"chunk",
";",
"$",
"bytes",
"-=",
"strlen",
"(",
"$",
"chunk",
")",
";",
"}",
"if",
"(",
"(",
"$",
"actual",
"=",
"strlen",
"(",
"$",
"read",
")",
")",
"!==",
"$",
"total",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"sprintf",
"(",
"'Only read %d of %d in \"%s\".'",
",",
"$",
"actual",
",",
"$",
"total",
",",
"$",
"this",
"->",
"file",
")",
")",
";",
"}",
"return",
"$",
"read",
";",
"}"
] | Reads the number of bytes from the file.
@param integer $bytes The number of bytes.
@return string The binary string read.
@throws RuntimeException If the read fails. | [
"Reads",
"the",
"number",
"of",
"bytes",
"from",
"the",
"file",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Extract.php#L475-L507 |
33,225 | box-project/box2-lib | src/lib/Herrera/Box/Extract.php | Extract.readManifest | private function readManifest()
{
$size = unpack('V', $this->read(4));
$size = $size[1];
$raw = $this->read($size);
// ++ start skip: API version, global flags, alias, and metadata
$count = unpack('V', substr($raw, 0, 4));
$count = $count[1];
$aliasSize = unpack('V', substr($raw, 10, 4));
$aliasSize = $aliasSize[1];
$raw = substr($raw, 14 + $aliasSize);
$metaSize = unpack('V', substr($raw, 0, 4));
$metaSize = $metaSize[1];
$offset = 0;
$start = 4 + $metaSize;
// -- end skip
$manifest = array(
'files' => array(),
'flags' => 0,
);
for ($i = 0; $i < $count; $i++) {
$length = unpack('V', substr($raw, $start, 4));
$length = $length[1];
$start += 4;
$path = substr($raw, $start, $length);
$start += $length;
$file = unpack(
'Vsize/Vtimestamp/Vcompressed_size/Vcrc32/Vflags/Vmetadata_length',
substr($raw, $start, 24)
);
$file['path'] = $path;
$file['crc32'] = sprintf('%u', $file['crc32'] & 0xffffffff);
$file['offset'] = $offset;
$offset += $file['compressed_size'];
$start += 24 + $file['metadata_length'];
$manifest['flags'] |= $file['flags'] & self::MASK;
$manifest['files'][] = $file;
}
return $manifest;
} | php | private function readManifest()
{
$size = unpack('V', $this->read(4));
$size = $size[1];
$raw = $this->read($size);
// ++ start skip: API version, global flags, alias, and metadata
$count = unpack('V', substr($raw, 0, 4));
$count = $count[1];
$aliasSize = unpack('V', substr($raw, 10, 4));
$aliasSize = $aliasSize[1];
$raw = substr($raw, 14 + $aliasSize);
$metaSize = unpack('V', substr($raw, 0, 4));
$metaSize = $metaSize[1];
$offset = 0;
$start = 4 + $metaSize;
// -- end skip
$manifest = array(
'files' => array(),
'flags' => 0,
);
for ($i = 0; $i < $count; $i++) {
$length = unpack('V', substr($raw, $start, 4));
$length = $length[1];
$start += 4;
$path = substr($raw, $start, $length);
$start += $length;
$file = unpack(
'Vsize/Vtimestamp/Vcompressed_size/Vcrc32/Vflags/Vmetadata_length',
substr($raw, $start, 24)
);
$file['path'] = $path;
$file['crc32'] = sprintf('%u', $file['crc32'] & 0xffffffff);
$file['offset'] = $offset;
$offset += $file['compressed_size'];
$start += 24 + $file['metadata_length'];
$manifest['flags'] |= $file['flags'] & self::MASK;
$manifest['files'][] = $file;
}
return $manifest;
} | [
"private",
"function",
"readManifest",
"(",
")",
"{",
"$",
"size",
"=",
"unpack",
"(",
"'V'",
",",
"$",
"this",
"->",
"read",
"(",
"4",
")",
")",
";",
"$",
"size",
"=",
"$",
"size",
"[",
"1",
"]",
";",
"$",
"raw",
"=",
"$",
"this",
"->",
"read",
"(",
"$",
"size",
")",
";",
"// ++ start skip: API version, global flags, alias, and metadata",
"$",
"count",
"=",
"unpack",
"(",
"'V'",
",",
"substr",
"(",
"$",
"raw",
",",
"0",
",",
"4",
")",
")",
";",
"$",
"count",
"=",
"$",
"count",
"[",
"1",
"]",
";",
"$",
"aliasSize",
"=",
"unpack",
"(",
"'V'",
",",
"substr",
"(",
"$",
"raw",
",",
"10",
",",
"4",
")",
")",
";",
"$",
"aliasSize",
"=",
"$",
"aliasSize",
"[",
"1",
"]",
";",
"$",
"raw",
"=",
"substr",
"(",
"$",
"raw",
",",
"14",
"+",
"$",
"aliasSize",
")",
";",
"$",
"metaSize",
"=",
"unpack",
"(",
"'V'",
",",
"substr",
"(",
"$",
"raw",
",",
"0",
",",
"4",
")",
")",
";",
"$",
"metaSize",
"=",
"$",
"metaSize",
"[",
"1",
"]",
";",
"$",
"offset",
"=",
"0",
";",
"$",
"start",
"=",
"4",
"+",
"$",
"metaSize",
";",
"// -- end skip",
"$",
"manifest",
"=",
"array",
"(",
"'files'",
"=>",
"array",
"(",
")",
",",
"'flags'",
"=>",
"0",
",",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"count",
";",
"$",
"i",
"++",
")",
"{",
"$",
"length",
"=",
"unpack",
"(",
"'V'",
",",
"substr",
"(",
"$",
"raw",
",",
"$",
"start",
",",
"4",
")",
")",
";",
"$",
"length",
"=",
"$",
"length",
"[",
"1",
"]",
";",
"$",
"start",
"+=",
"4",
";",
"$",
"path",
"=",
"substr",
"(",
"$",
"raw",
",",
"$",
"start",
",",
"$",
"length",
")",
";",
"$",
"start",
"+=",
"$",
"length",
";",
"$",
"file",
"=",
"unpack",
"(",
"'Vsize/Vtimestamp/Vcompressed_size/Vcrc32/Vflags/Vmetadata_length'",
",",
"substr",
"(",
"$",
"raw",
",",
"$",
"start",
",",
"24",
")",
")",
";",
"$",
"file",
"[",
"'path'",
"]",
"=",
"$",
"path",
";",
"$",
"file",
"[",
"'crc32'",
"]",
"=",
"sprintf",
"(",
"'%u'",
",",
"$",
"file",
"[",
"'crc32'",
"]",
"&",
"0xffffffff",
")",
";",
"$",
"file",
"[",
"'offset'",
"]",
"=",
"$",
"offset",
";",
"$",
"offset",
"+=",
"$",
"file",
"[",
"'compressed_size'",
"]",
";",
"$",
"start",
"+=",
"24",
"+",
"$",
"file",
"[",
"'metadata_length'",
"]",
";",
"$",
"manifest",
"[",
"'flags'",
"]",
"|=",
"$",
"file",
"[",
"'flags'",
"]",
"&",
"self",
"::",
"MASK",
";",
"$",
"manifest",
"[",
"'files'",
"]",
"[",
"]",
"=",
"$",
"file",
";",
"}",
"return",
"$",
"manifest",
";",
"}"
] | Reads and unpacks the manifest data from the phar.
@return array The manifest. | [
"Reads",
"and",
"unpacks",
"the",
"manifest",
"data",
"from",
"the",
"phar",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/Extract.php#L514-L567 |
33,226 | box-project/box2-lib | src/lib/Herrera/Box/StubGenerator.php | StubGenerator.extract | public function extract($extract, $force = false)
{
$this->extract = $extract;
$this->extractForce = $force;
if ($extract) {
$this->extractCode = array(
'constants' => array(),
'class' => array(),
);
$compactor = new Php();
$code = file_get_contents(__DIR__ . '/Extract.php');
$code = $compactor->compact($code);
$code = preg_replace('/\n+/', "\n", $code);
$code = explode("\n", $code);
$code = array_slice($code, 2);
foreach ($code as $i => $line) {
if ((0 === strpos($line, 'use'))
&& (false === strpos($line, '\\'))
) {
unset($code[$i]);
} elseif (0 === strpos($line, 'define')) {
$this->extractCode['constants'][] = $line;
} else {
$this->extractCode['class'][] = $line;
}
}
}
return $this;
} | php | public function extract($extract, $force = false)
{
$this->extract = $extract;
$this->extractForce = $force;
if ($extract) {
$this->extractCode = array(
'constants' => array(),
'class' => array(),
);
$compactor = new Php();
$code = file_get_contents(__DIR__ . '/Extract.php');
$code = $compactor->compact($code);
$code = preg_replace('/\n+/', "\n", $code);
$code = explode("\n", $code);
$code = array_slice($code, 2);
foreach ($code as $i => $line) {
if ((0 === strpos($line, 'use'))
&& (false === strpos($line, '\\'))
) {
unset($code[$i]);
} elseif (0 === strpos($line, 'define')) {
$this->extractCode['constants'][] = $line;
} else {
$this->extractCode['class'][] = $line;
}
}
}
return $this;
} | [
"public",
"function",
"extract",
"(",
"$",
"extract",
",",
"$",
"force",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"extract",
"=",
"$",
"extract",
";",
"$",
"this",
"->",
"extractForce",
"=",
"$",
"force",
";",
"if",
"(",
"$",
"extract",
")",
"{",
"$",
"this",
"->",
"extractCode",
"=",
"array",
"(",
"'constants'",
"=>",
"array",
"(",
")",
",",
"'class'",
"=>",
"array",
"(",
")",
",",
")",
";",
"$",
"compactor",
"=",
"new",
"Php",
"(",
")",
";",
"$",
"code",
"=",
"file_get_contents",
"(",
"__DIR__",
".",
"'/Extract.php'",
")",
";",
"$",
"code",
"=",
"$",
"compactor",
"->",
"compact",
"(",
"$",
"code",
")",
";",
"$",
"code",
"=",
"preg_replace",
"(",
"'/\\n+/'",
",",
"\"\\n\"",
",",
"$",
"code",
")",
";",
"$",
"code",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"code",
")",
";",
"$",
"code",
"=",
"array_slice",
"(",
"$",
"code",
",",
"2",
")",
";",
"foreach",
"(",
"$",
"code",
"as",
"$",
"i",
"=>",
"$",
"line",
")",
"{",
"if",
"(",
"(",
"0",
"===",
"strpos",
"(",
"$",
"line",
",",
"'use'",
")",
")",
"&&",
"(",
"false",
"===",
"strpos",
"(",
"$",
"line",
",",
"'\\\\'",
")",
")",
")",
"{",
"unset",
"(",
"$",
"code",
"[",
"$",
"i",
"]",
")",
";",
"}",
"elseif",
"(",
"0",
"===",
"strpos",
"(",
"$",
"line",
",",
"'define'",
")",
")",
"{",
"$",
"this",
"->",
"extractCode",
"[",
"'constants'",
"]",
"[",
"]",
"=",
"$",
"line",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"extractCode",
"[",
"'class'",
"]",
"[",
"]",
"=",
"$",
"line",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Embed the Extract class in the stub?
@param boolean $extract Embed the class?
@param boolean $force Force the use of the class?
@return StubGenerator The stub generator. | [
"Embed",
"the",
"Extract",
"class",
"in",
"the",
"stub?"
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/StubGenerator.php#L166-L198 |
33,227 | box-project/box2-lib | src/lib/Herrera/Box/StubGenerator.php | StubGenerator.mung | public function mung(array $list)
{
foreach ($list as $value) {
if (false === in_array($value, self::$allowedMung)) {
throw InvalidArgumentException::create(
'The $_SERVER variable "%s" is not allowed.',
$value
);
}
}
$this->mung = $list;
return $this;
} | php | public function mung(array $list)
{
foreach ($list as $value) {
if (false === in_array($value, self::$allowedMung)) {
throw InvalidArgumentException::create(
'The $_SERVER variable "%s" is not allowed.',
$value
);
}
}
$this->mung = $list;
return $this;
} | [
"public",
"function",
"mung",
"(",
"array",
"$",
"list",
")",
"{",
"foreach",
"(",
"$",
"list",
"as",
"$",
"value",
")",
"{",
"if",
"(",
"false",
"===",
"in_array",
"(",
"$",
"value",
",",
"self",
"::",
"$",
"allowedMung",
")",
")",
"{",
"throw",
"InvalidArgumentException",
"::",
"create",
"(",
"'The $_SERVER variable \"%s\" is not allowed.'",
",",
"$",
"value",
")",
";",
"}",
"}",
"$",
"this",
"->",
"mung",
"=",
"$",
"list",
";",
"return",
"$",
"this",
";",
"}"
] | Sets the list of server variables to modify.
@param array $list The list.
@return StubGenerator The stub generator.
@throws Exception\Exception
@throws InvalidArgumentException If the list contains an invalid value. | [
"Sets",
"the",
"list",
"of",
"server",
"variables",
"to",
"modify",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/StubGenerator.php#L308-L322 |
33,228 | box-project/box2-lib | src/lib/Herrera/Box/StubGenerator.php | StubGenerator.getAlias | private function getAlias()
{
$stub = '';
$prefix = '';
if ($this->extractForce) {
$prefix = '$dir/';
}
if ($this->web) {
$stub .= 'Phar::webPhar(' . $this->arg($this->alias);
if ($this->index) {
$stub .= ', ' . $this->arg($prefix . $this->index, '"');
if ($this->notFound) {
$stub .= ', ' . $this->arg($prefix . $this->notFound, '"');
if ($this->mimetypes) {
$stub .= ', ' . var_export(
$this->mimetypes,
true
);
if ($this->rewrite) {
$stub .= ', ' . $this->arg($this->rewrite);
}
}
}
}
$stub .= ');';
} else {
$stub .= 'Phar::mapPhar(' . $this->arg($this->alias) . ');';
}
return $stub;
} | php | private function getAlias()
{
$stub = '';
$prefix = '';
if ($this->extractForce) {
$prefix = '$dir/';
}
if ($this->web) {
$stub .= 'Phar::webPhar(' . $this->arg($this->alias);
if ($this->index) {
$stub .= ', ' . $this->arg($prefix . $this->index, '"');
if ($this->notFound) {
$stub .= ', ' . $this->arg($prefix . $this->notFound, '"');
if ($this->mimetypes) {
$stub .= ', ' . var_export(
$this->mimetypes,
true
);
if ($this->rewrite) {
$stub .= ', ' . $this->arg($this->rewrite);
}
}
}
}
$stub .= ');';
} else {
$stub .= 'Phar::mapPhar(' . $this->arg($this->alias) . ');';
}
return $stub;
} | [
"private",
"function",
"getAlias",
"(",
")",
"{",
"$",
"stub",
"=",
"''",
";",
"$",
"prefix",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"extractForce",
")",
"{",
"$",
"prefix",
"=",
"'$dir/'",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"web",
")",
"{",
"$",
"stub",
".=",
"'Phar::webPhar('",
".",
"$",
"this",
"->",
"arg",
"(",
"$",
"this",
"->",
"alias",
")",
";",
"if",
"(",
"$",
"this",
"->",
"index",
")",
"{",
"$",
"stub",
".=",
"', '",
".",
"$",
"this",
"->",
"arg",
"(",
"$",
"prefix",
".",
"$",
"this",
"->",
"index",
",",
"'\"'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"notFound",
")",
"{",
"$",
"stub",
".=",
"', '",
".",
"$",
"this",
"->",
"arg",
"(",
"$",
"prefix",
".",
"$",
"this",
"->",
"notFound",
",",
"'\"'",
")",
";",
"if",
"(",
"$",
"this",
"->",
"mimetypes",
")",
"{",
"$",
"stub",
".=",
"', '",
".",
"var_export",
"(",
"$",
"this",
"->",
"mimetypes",
",",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"rewrite",
")",
"{",
"$",
"stub",
".=",
"', '",
".",
"$",
"this",
"->",
"arg",
"(",
"$",
"this",
"->",
"rewrite",
")",
";",
"}",
"}",
"}",
"}",
"$",
"stub",
".=",
"');'",
";",
"}",
"else",
"{",
"$",
"stub",
".=",
"'Phar::mapPhar('",
".",
"$",
"this",
"->",
"arg",
"(",
"$",
"this",
"->",
"alias",
")",
".",
"');'",
";",
"}",
"return",
"$",
"stub",
";",
"}"
] | Returns the alias map.
@return string The alias map. | [
"Returns",
"the",
"alias",
"map",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/StubGenerator.php#L398-L435 |
33,229 | box-project/box2-lib | src/lib/Herrera/Box/StubGenerator.php | StubGenerator.getPharSections | private function getPharSections()
{
$stub = array(
'if (class_exists(\'Phar\')) {',
$this->getAlias(),
);
if ($this->intercept) {
$stub[] = "Phar::interceptFileFuncs();";
}
if ($this->mung) {
$stub[] = 'Phar::mungServer(' . var_export($this->mung, true) . ");";
}
if ($this->index && !$this->web && !$this->extractForce) {
$stub[] = "require 'phar://' . __FILE__ . '/{$this->index}';";
}
$stub[] = '}';
return $stub;
} | php | private function getPharSections()
{
$stub = array(
'if (class_exists(\'Phar\')) {',
$this->getAlias(),
);
if ($this->intercept) {
$stub[] = "Phar::interceptFileFuncs();";
}
if ($this->mung) {
$stub[] = 'Phar::mungServer(' . var_export($this->mung, true) . ");";
}
if ($this->index && !$this->web && !$this->extractForce) {
$stub[] = "require 'phar://' . __FILE__ . '/{$this->index}';";
}
$stub[] = '}';
return $stub;
} | [
"private",
"function",
"getPharSections",
"(",
")",
"{",
"$",
"stub",
"=",
"array",
"(",
"'if (class_exists(\\'Phar\\')) {'",
",",
"$",
"this",
"->",
"getAlias",
"(",
")",
",",
")",
";",
"if",
"(",
"$",
"this",
"->",
"intercept",
")",
"{",
"$",
"stub",
"[",
"]",
"=",
"\"Phar::interceptFileFuncs();\"",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"mung",
")",
"{",
"$",
"stub",
"[",
"]",
"=",
"'Phar::mungServer('",
".",
"var_export",
"(",
"$",
"this",
"->",
"mung",
",",
"true",
")",
".",
"\");\"",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"index",
"&&",
"!",
"$",
"this",
"->",
"web",
"&&",
"!",
"$",
"this",
"->",
"extractForce",
")",
"{",
"$",
"stub",
"[",
"]",
"=",
"\"require 'phar://' . __FILE__ . '/{$this->index}';\"",
";",
"}",
"$",
"stub",
"[",
"]",
"=",
"'}'",
";",
"return",
"$",
"stub",
";",
"}"
] | Returns the sections of the stub that use the Phar class.
@return array The stub sections. | [
"Returns",
"the",
"sections",
"of",
"the",
"stub",
"that",
"use",
"the",
"Phar",
"class",
"."
] | 1c5d528d0c44af9d084c2e68ed8b5863db9abe0c | https://github.com/box-project/box2-lib/blob/1c5d528d0c44af9d084c2e68ed8b5863db9abe0c/src/lib/Herrera/Box/StubGenerator.php#L475-L497 |
33,230 | desarrolla2/Cache | src/Packer/PackingTrait.php | PackingTrait.getPacker | protected function getPacker(): PackerInterface
{
if (!isset($this->packer)) {
$this->packer = static::createDefaultPacker();
}
return $this->packer;
} | php | protected function getPacker(): PackerInterface
{
if (!isset($this->packer)) {
$this->packer = static::createDefaultPacker();
}
return $this->packer;
} | [
"protected",
"function",
"getPacker",
"(",
")",
":",
"PackerInterface",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"packer",
")",
")",
"{",
"$",
"this",
"->",
"packer",
"=",
"static",
"::",
"createDefaultPacker",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"packer",
";",
"}"
] | Get the packer
@return PackerInterface | [
"Get",
"the",
"packer"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/Packer/PackingTrait.php#L55-L62 |
33,231 | desarrolla2/Cache | src/Option/FilenameTrait.php | FilenameTrait.setFilenameOption | protected function setFilenameOption($filename): void
{
if (is_string($filename)) {
$filename = new BasicFilename($filename);
}
if (!is_callable($filename)) {
throw new TypeError("Filename should be a string or callable");
}
$this->filename = $filename;
} | php | protected function setFilenameOption($filename): void
{
if (is_string($filename)) {
$filename = new BasicFilename($filename);
}
if (!is_callable($filename)) {
throw new TypeError("Filename should be a string or callable");
}
$this->filename = $filename;
} | [
"protected",
"function",
"setFilenameOption",
"(",
"$",
"filename",
")",
":",
"void",
"{",
"if",
"(",
"is_string",
"(",
"$",
"filename",
")",
")",
"{",
"$",
"filename",
"=",
"new",
"BasicFilename",
"(",
"$",
"filename",
")",
";",
"}",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"filename",
")",
")",
"{",
"throw",
"new",
"TypeError",
"(",
"\"Filename should be a string or callable\"",
")",
";",
"}",
"$",
"this",
"->",
"filename",
"=",
"$",
"filename",
";",
"}"
] | Filename format or callable.
The filename format will be applied using sprintf, replacing `%s` with the key.
@param string|callable $filename
@return void | [
"Filename",
"format",
"or",
"callable",
".",
"The",
"filename",
"format",
"will",
"be",
"applied",
"using",
"sprintf",
"replacing",
"%s",
"with",
"the",
"key",
"."
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/Option/FilenameTrait.php#L39-L50 |
33,232 | desarrolla2/Cache | src/Option/FilenameTrait.php | FilenameTrait.getFilenameOption | protected function getFilenameOption(): callable
{
if (!isset($this->filename)) {
$this->filename = new BasicFilename('%s.' . $this->getPacker()->getType());
}
return $this->filename;
} | php | protected function getFilenameOption(): callable
{
if (!isset($this->filename)) {
$this->filename = new BasicFilename('%s.' . $this->getPacker()->getType());
}
return $this->filename;
} | [
"protected",
"function",
"getFilenameOption",
"(",
")",
":",
"callable",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"filename",
")",
")",
"{",
"$",
"this",
"->",
"filename",
"=",
"new",
"BasicFilename",
"(",
"'%s.'",
".",
"$",
"this",
"->",
"getPacker",
"(",
")",
"->",
"getType",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"filename",
";",
"}"
] | Get the filename callable
@return callable | [
"Get",
"the",
"filename",
"callable"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/Option/FilenameTrait.php#L57-L64 |
33,233 | desarrolla2/Cache | src/Option/FilenameTrait.php | FilenameTrait.getFilename | protected function getFilename($key): string
{
$id = $this->keyToId($key);
$generator = $this->getFilenameOption();
return $this->cacheDir . DIRECTORY_SEPARATOR . $generator($id);
} | php | protected function getFilename($key): string
{
$id = $this->keyToId($key);
$generator = $this->getFilenameOption();
return $this->cacheDir . DIRECTORY_SEPARATOR . $generator($id);
} | [
"protected",
"function",
"getFilename",
"(",
"$",
"key",
")",
":",
"string",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"keyToId",
"(",
"$",
"key",
")",
";",
"$",
"generator",
"=",
"$",
"this",
"->",
"getFilenameOption",
"(",
")",
";",
"return",
"$",
"this",
"->",
"cacheDir",
".",
"DIRECTORY_SEPARATOR",
".",
"$",
"generator",
"(",
"$",
"id",
")",
";",
"}"
] | Create a filename based on the key
@param string|mixed $key
@return string | [
"Create",
"a",
"filename",
"based",
"on",
"the",
"key"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/Option/FilenameTrait.php#L72-L78 |
33,234 | desarrolla2/Cache | src/File.php | File.getTtl | protected function getTtl(string $cacheFile)
{
switch ($this->ttlStrategy) {
case 'embed':
return (int)$this->readLine($cacheFile);
case 'file':
return file_exists("$cacheFile.ttl")
? (int)file_get_contents("$cacheFile.ttl")
: PHP_INT_MAX;
case 'mtime':
return $this->getTtl() > 0 ? filemtime($cacheFile) + $this->ttl : PHP_INT_MAX;
}
} | php | protected function getTtl(string $cacheFile)
{
switch ($this->ttlStrategy) {
case 'embed':
return (int)$this->readLine($cacheFile);
case 'file':
return file_exists("$cacheFile.ttl")
? (int)file_get_contents("$cacheFile.ttl")
: PHP_INT_MAX;
case 'mtime':
return $this->getTtl() > 0 ? filemtime($cacheFile) + $this->ttl : PHP_INT_MAX;
}
} | [
"protected",
"function",
"getTtl",
"(",
"string",
"$",
"cacheFile",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"ttlStrategy",
")",
"{",
"case",
"'embed'",
":",
"return",
"(",
"int",
")",
"$",
"this",
"->",
"readLine",
"(",
"$",
"cacheFile",
")",
";",
"case",
"'file'",
":",
"return",
"file_exists",
"(",
"\"$cacheFile.ttl\"",
")",
"?",
"(",
"int",
")",
"file_get_contents",
"(",
"\"$cacheFile.ttl\"",
")",
":",
"PHP_INT_MAX",
";",
"case",
"'mtime'",
":",
"return",
"$",
"this",
"->",
"getTtl",
"(",
")",
">",
"0",
"?",
"filemtime",
"(",
"$",
"cacheFile",
")",
"+",
"$",
"this",
"->",
"ttl",
":",
"PHP_INT_MAX",
";",
"}",
"}"
] | Get the TTL using one of the strategies
@param string $cacheFile
@return int | [
"Get",
"the",
"TTL",
"using",
"one",
"of",
"the",
"strategies"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/File.php#L76-L88 |
33,235 | desarrolla2/Cache | src/File.php | File.setTtl | protected function setTtl($expiration, $contents, $cacheFile)
{
switch ($this->ttlStrategy) {
case 'embed':
$contents = ($expiration ?? PHP_INT_MAX) . "\n" . $contents;
break;
case 'file':
if (isset($expiration)) {
file_put_contents("$cacheFile.ttl", $expiration);
}
break;
case 'mtime':
// nothing
break;
}
return $contents;
} | php | protected function setTtl($expiration, $contents, $cacheFile)
{
switch ($this->ttlStrategy) {
case 'embed':
$contents = ($expiration ?? PHP_INT_MAX) . "\n" . $contents;
break;
case 'file':
if (isset($expiration)) {
file_put_contents("$cacheFile.ttl", $expiration);
}
break;
case 'mtime':
// nothing
break;
}
return $contents;
} | [
"protected",
"function",
"setTtl",
"(",
"$",
"expiration",
",",
"$",
"contents",
",",
"$",
"cacheFile",
")",
"{",
"switch",
"(",
"$",
"this",
"->",
"ttlStrategy",
")",
"{",
"case",
"'embed'",
":",
"$",
"contents",
"=",
"(",
"$",
"expiration",
"??",
"PHP_INT_MAX",
")",
".",
"\"\\n\"",
".",
"$",
"contents",
";",
"break",
";",
"case",
"'file'",
":",
"if",
"(",
"isset",
"(",
"$",
"expiration",
")",
")",
"{",
"file_put_contents",
"(",
"\"$cacheFile.ttl\"",
",",
"$",
"expiration",
")",
";",
"}",
"break",
";",
"case",
"'mtime'",
":",
"// nothing",
"break",
";",
"}",
"return",
"$",
"contents",
";",
"}"
] | Set the TTL using one of the strategies
@param int $expiration
@param string $contents
@param string $cacheFile
@return string The (modified) contents | [
"Set",
"the",
"TTL",
"using",
"one",
"of",
"the",
"strategies"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/File.php#L98-L115 |
33,236 | desarrolla2/Cache | src/AbstractFile.php | AbstractFile.readLine | protected function readLine(string $cacheFile): string
{
$fp = fopen($cacheFile, 'r');
$line = fgets($fp);
fclose($fp);
return $line;
} | php | protected function readLine(string $cacheFile): string
{
$fp = fopen($cacheFile, 'r');
$line = fgets($fp);
fclose($fp);
return $line;
} | [
"protected",
"function",
"readLine",
"(",
"string",
"$",
"cacheFile",
")",
":",
"string",
"{",
"$",
"fp",
"=",
"fopen",
"(",
"$",
"cacheFile",
",",
"'r'",
")",
";",
"$",
"line",
"=",
"fgets",
"(",
"$",
"fp",
")",
";",
"fclose",
"(",
"$",
"fp",
")",
";",
"return",
"$",
"line",
";",
"}"
] | Read the first line of the cache file
@param string $cacheFile
@return string | [
"Read",
"the",
"first",
"line",
"of",
"the",
"cache",
"file"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/AbstractFile.php#L87-L94 |
33,237 | desarrolla2/Cache | src/AbstractFile.php | AbstractFile.writeFile | protected function writeFile(string $cacheFile, string $contents): bool
{
$dir = dirname($cacheFile);
if ($dir !== $this->cacheDir && !is_dir($dir)) {
mkdir($dir, 0775, true);
}
return (bool)file_put_contents($cacheFile, $contents);
} | php | protected function writeFile(string $cacheFile, string $contents): bool
{
$dir = dirname($cacheFile);
if ($dir !== $this->cacheDir && !is_dir($dir)) {
mkdir($dir, 0775, true);
}
return (bool)file_put_contents($cacheFile, $contents);
} | [
"protected",
"function",
"writeFile",
"(",
"string",
"$",
"cacheFile",
",",
"string",
"$",
"contents",
")",
":",
"bool",
"{",
"$",
"dir",
"=",
"dirname",
"(",
"$",
"cacheFile",
")",
";",
"if",
"(",
"$",
"dir",
"!==",
"$",
"this",
"->",
"cacheDir",
"&&",
"!",
"is_dir",
"(",
"$",
"dir",
")",
")",
"{",
"mkdir",
"(",
"$",
"dir",
",",
"0775",
",",
"true",
")",
";",
"}",
"return",
"(",
"bool",
")",
"file_put_contents",
"(",
"$",
"cacheFile",
",",
"$",
"contents",
")",
";",
"}"
] | Create a cache file
@param string $cacheFile
@param string $contents
@return bool | [
"Create",
"a",
"cache",
"file"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/AbstractFile.php#L103-L112 |
33,238 | desarrolla2/Cache | src/Memcached.php | Memcached.ttlToMemcachedTime | protected function ttlToMemcachedTime($ttl)
{
$seconds = $this->ttlToSeconds($ttl);
if ($seconds <= 0) {
return isset($seconds) ? false : 0;
}
/* 2592000 seconds = 30 days */
return $seconds <= 2592000 ? $seconds : $this->ttlToTimestamp($ttl);
} | php | protected function ttlToMemcachedTime($ttl)
{
$seconds = $this->ttlToSeconds($ttl);
if ($seconds <= 0) {
return isset($seconds) ? false : 0;
}
/* 2592000 seconds = 30 days */
return $seconds <= 2592000 ? $seconds : $this->ttlToTimestamp($ttl);
} | [
"protected",
"function",
"ttlToMemcachedTime",
"(",
"$",
"ttl",
")",
"{",
"$",
"seconds",
"=",
"$",
"this",
"->",
"ttlToSeconds",
"(",
"$",
"ttl",
")",
";",
"if",
"(",
"$",
"seconds",
"<=",
"0",
")",
"{",
"return",
"isset",
"(",
"$",
"seconds",
")",
"?",
"false",
":",
"0",
";",
"}",
"/* 2592000 seconds = 30 days */",
"return",
"$",
"seconds",
"<=",
"2592000",
"?",
"$",
"seconds",
":",
"$",
"this",
"->",
"ttlToTimestamp",
"(",
"$",
"ttl",
")",
";",
"}"
] | Convert ttl to timestamp or seconds.
@see http://php.net/manual/en/memcached.expiration.php
@param null|int|DateInterval $ttl
@return int|null
@throws InvalidArgumentException | [
"Convert",
"ttl",
"to",
"timestamp",
"or",
"seconds",
"."
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/Memcached.php#L207-L217 |
33,239 | desarrolla2/Cache | src/PhpFile.php | PhpFile.createScript | public function createScript($value, ?int $ttl): string
{
$macro = var_export($value, true);
if (strpos($macro, 'stdClass::__set_state') !== false) {
$macro = preg_replace_callback("/('([^'\\\\]++|''\\.)')|stdClass::__set_state/", $macro, function($match) {
return empty($match[1]) ? '(object)' : $match[1];
});
}
return $ttl !== null
? "<?php return time() < {$ttl} ? {$macro} : false;"
: "<?php return {$macro};";
} | php | public function createScript($value, ?int $ttl): string
{
$macro = var_export($value, true);
if (strpos($macro, 'stdClass::__set_state') !== false) {
$macro = preg_replace_callback("/('([^'\\\\]++|''\\.)')|stdClass::__set_state/", $macro, function($match) {
return empty($match[1]) ? '(object)' : $match[1];
});
}
return $ttl !== null
? "<?php return time() < {$ttl} ? {$macro} : false;"
: "<?php return {$macro};";
} | [
"public",
"function",
"createScript",
"(",
"$",
"value",
",",
"?",
"int",
"$",
"ttl",
")",
":",
"string",
"{",
"$",
"macro",
"=",
"var_export",
"(",
"$",
"value",
",",
"true",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"macro",
",",
"'stdClass::__set_state'",
")",
"!==",
"false",
")",
"{",
"$",
"macro",
"=",
"preg_replace_callback",
"(",
"\"/('([^'\\\\\\\\]++|''\\\\.)')|stdClass::__set_state/\"",
",",
"$",
"macro",
",",
"function",
"(",
"$",
"match",
")",
"{",
"return",
"empty",
"(",
"$",
"match",
"[",
"1",
"]",
")",
"?",
"'(object)'",
":",
"$",
"match",
"[",
"1",
"]",
";",
"}",
")",
";",
"}",
"return",
"$",
"ttl",
"!==",
"null",
"?",
"\"<?php return time() < {$ttl} ? {$macro} : false;\"",
":",
"\"<?php return {$macro};\"",
";",
"}"
] | Create a PHP script returning the cached value
@param mixed $value
@param int|null $ttl
@return string | [
"Create",
"a",
"PHP",
"script",
"returning",
"the",
"cached",
"value"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/PhpFile.php#L60-L73 |
33,240 | desarrolla2/Cache | src/AbstractCache.php | AbstractCache.assertKey | protected function assertKey($key): void
{
if (!is_string($key)) {
$type = (is_object($key) ? get_class($key) . ' ' : '') . gettype($key);
throw new InvalidArgumentException("Expected key to be a string, not $type");
}
if ($key === '' || preg_match('~[{}()/\\\\@:]~', $key)) {
throw new InvalidArgumentException("Invalid key '$key'");
}
} | php | protected function assertKey($key): void
{
if (!is_string($key)) {
$type = (is_object($key) ? get_class($key) . ' ' : '') . gettype($key);
throw new InvalidArgumentException("Expected key to be a string, not $type");
}
if ($key === '' || preg_match('~[{}()/\\\\@:]~', $key)) {
throw new InvalidArgumentException("Invalid key '$key'");
}
} | [
"protected",
"function",
"assertKey",
"(",
"$",
"key",
")",
":",
"void",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"$",
"type",
"=",
"(",
"is_object",
"(",
"$",
"key",
")",
"?",
"get_class",
"(",
"$",
"key",
")",
".",
"' '",
":",
"''",
")",
".",
"gettype",
"(",
"$",
"key",
")",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Expected key to be a string, not $type\"",
")",
";",
"}",
"if",
"(",
"$",
"key",
"===",
"''",
"||",
"preg_match",
"(",
"'~[{}()/\\\\\\\\@:]~'",
",",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"Invalid key '$key'\"",
")",
";",
"}",
"}"
] | Validate the key
@param string $key
@return void
@throws InvalidArgumentException | [
"Validate",
"the",
"key"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/AbstractCache.php#L99-L109 |
33,241 | desarrolla2/Cache | src/AbstractCache.php | AbstractCache.assertIterable | protected function assertIterable($subject, $msg): void
{
$iterable = function_exists('is_iterable')
? is_iterable($subject)
: is_array($subject) || $subject instanceof Traversable;
if (!$iterable) {
throw new InvalidArgumentException($msg);
}
} | php | protected function assertIterable($subject, $msg): void
{
$iterable = function_exists('is_iterable')
? is_iterable($subject)
: is_array($subject) || $subject instanceof Traversable;
if (!$iterable) {
throw new InvalidArgumentException($msg);
}
} | [
"protected",
"function",
"assertIterable",
"(",
"$",
"subject",
",",
"$",
"msg",
")",
":",
"void",
"{",
"$",
"iterable",
"=",
"function_exists",
"(",
"'is_iterable'",
")",
"?",
"is_iterable",
"(",
"$",
"subject",
")",
":",
"is_array",
"(",
"$",
"subject",
")",
"||",
"$",
"subject",
"instanceof",
"Traversable",
";",
"if",
"(",
"!",
"$",
"iterable",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"$",
"msg",
")",
";",
"}",
"}"
] | Assert that the keys are an array or traversable
@param iterable $subject
@param string $msg
@return void
@throws InvalidArgumentException if subject are not iterable | [
"Assert",
"that",
"the",
"keys",
"are",
"an",
"array",
"or",
"traversable"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/AbstractCache.php#L119-L128 |
33,242 | desarrolla2/Cache | src/AbstractCache.php | AbstractCache.keyToId | protected function keyToId($key): string
{
$this->assertKey($key);
return sprintf('%s%s', $this->prefix, $key);
} | php | protected function keyToId($key): string
{
$this->assertKey($key);
return sprintf('%s%s', $this->prefix, $key);
} | [
"protected",
"function",
"keyToId",
"(",
"$",
"key",
")",
":",
"string",
"{",
"$",
"this",
"->",
"assertKey",
"(",
"$",
"key",
")",
";",
"return",
"sprintf",
"(",
"'%s%s'",
",",
"$",
"this",
"->",
"prefix",
",",
"$",
"key",
")",
";",
"}"
] | Turn the key into a cache identifier
@param string $key
@return string
@throws InvalidArgumentException | [
"Turn",
"the",
"key",
"into",
"a",
"cache",
"identifier"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/AbstractCache.php#L137-L142 |
33,243 | desarrolla2/Cache | src/AbstractCache.php | AbstractCache.mapKeysToIds | protected function mapKeysToIds($keys): array
{
$this->assertIterable($keys, 'keys not iterable');
$map = [];
foreach ($keys as $key) {
$id = $this->keyToId($key);
$map[$id] = $key;
}
return $map;
} | php | protected function mapKeysToIds($keys): array
{
$this->assertIterable($keys, 'keys not iterable');
$map = [];
foreach ($keys as $key) {
$id = $this->keyToId($key);
$map[$id] = $key;
}
return $map;
} | [
"protected",
"function",
"mapKeysToIds",
"(",
"$",
"keys",
")",
":",
"array",
"{",
"$",
"this",
"->",
"assertIterable",
"(",
"$",
"keys",
",",
"'keys not iterable'",
")",
";",
"$",
"map",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"keyToId",
"(",
"$",
"key",
")",
";",
"$",
"map",
"[",
"$",
"id",
"]",
"=",
"$",
"key",
";",
"}",
"return",
"$",
"map",
";",
"}"
] | Create a map with keys and ids
@param iterable $keys
@return array
@throws InvalidArgumentException | [
"Create",
"a",
"map",
"with",
"keys",
"and",
"ids"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/AbstractCache.php#L151-L163 |
33,244 | desarrolla2/Cache | src/AbstractCache.php | AbstractCache.ttlToSeconds | protected function ttlToSeconds($ttl): ?int
{
if (!isset($ttl)) {
return $this->ttl;
}
if ($ttl instanceof DateInterval) {
$reference = new DateTimeImmutable();
$endTime = $reference->add($ttl);
$ttl = $endTime->getTimestamp() - $reference->getTimestamp();
}
if (!is_int($ttl)) {
$type = (is_object($ttl) ? get_class($ttl) . ' ' : '') . gettype($ttl);
throw new InvalidArgumentException("ttl should be of type int or DateInterval, not $type");
}
return isset($this->ttl) ? min($ttl, $this->ttl) : $ttl;
} | php | protected function ttlToSeconds($ttl): ?int
{
if (!isset($ttl)) {
return $this->ttl;
}
if ($ttl instanceof DateInterval) {
$reference = new DateTimeImmutable();
$endTime = $reference->add($ttl);
$ttl = $endTime->getTimestamp() - $reference->getTimestamp();
}
if (!is_int($ttl)) {
$type = (is_object($ttl) ? get_class($ttl) . ' ' : '') . gettype($ttl);
throw new InvalidArgumentException("ttl should be of type int or DateInterval, not $type");
}
return isset($this->ttl) ? min($ttl, $this->ttl) : $ttl;
} | [
"protected",
"function",
"ttlToSeconds",
"(",
"$",
"ttl",
")",
":",
"?",
"int",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"ttl",
")",
")",
"{",
"return",
"$",
"this",
"->",
"ttl",
";",
"}",
"if",
"(",
"$",
"ttl",
"instanceof",
"DateInterval",
")",
"{",
"$",
"reference",
"=",
"new",
"DateTimeImmutable",
"(",
")",
";",
"$",
"endTime",
"=",
"$",
"reference",
"->",
"add",
"(",
"$",
"ttl",
")",
";",
"$",
"ttl",
"=",
"$",
"endTime",
"->",
"getTimestamp",
"(",
")",
"-",
"$",
"reference",
"->",
"getTimestamp",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_int",
"(",
"$",
"ttl",
")",
")",
"{",
"$",
"type",
"=",
"(",
"is_object",
"(",
"$",
"ttl",
")",
"?",
"get_class",
"(",
"$",
"ttl",
")",
".",
"' '",
":",
"''",
")",
".",
"gettype",
"(",
"$",
"ttl",
")",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"ttl should be of type int or DateInterval, not $type\"",
")",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"ttl",
")",
"?",
"min",
"(",
"$",
"ttl",
",",
"$",
"this",
"->",
"ttl",
")",
":",
"$",
"ttl",
";",
"}"
] | Convert TTL to seconds from now
@param null|int|DateInterval $ttl
@return int|null
@throws InvalidArgumentException | [
"Convert",
"TTL",
"to",
"seconds",
"from",
"now"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/AbstractCache.php#L252-L271 |
33,245 | desarrolla2/Cache | src/AbstractCache.php | AbstractCache.ttlToTimestamp | protected function ttlToTimestamp($ttl): ?int
{
if (!isset($ttl)) {
return isset($this->ttl) ? time() + $this->ttl : null;
}
if (is_int($ttl)) {
return time() + (isset($this->ttl) ? min($ttl, $this->ttl) : $ttl);
}
if ($ttl instanceof DateInterval) {
$timestamp = (new DateTimeImmutable())->add($ttl)->getTimestamp();
return isset($this->ttl) ? min($timestamp, time() + $this->ttl) : $timestamp;
}
$type = (is_object($ttl) ? get_class($ttl) . ' ' : '') . gettype($ttl);
throw new InvalidArgumentException("ttl should be of type int or DateInterval, not $type");
} | php | protected function ttlToTimestamp($ttl): ?int
{
if (!isset($ttl)) {
return isset($this->ttl) ? time() + $this->ttl : null;
}
if (is_int($ttl)) {
return time() + (isset($this->ttl) ? min($ttl, $this->ttl) : $ttl);
}
if ($ttl instanceof DateInterval) {
$timestamp = (new DateTimeImmutable())->add($ttl)->getTimestamp();
return isset($this->ttl) ? min($timestamp, time() + $this->ttl) : $timestamp;
}
$type = (is_object($ttl) ? get_class($ttl) . ' ' : '') . gettype($ttl);
throw new InvalidArgumentException("ttl should be of type int or DateInterval, not $type");
} | [
"protected",
"function",
"ttlToTimestamp",
"(",
"$",
"ttl",
")",
":",
"?",
"int",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"ttl",
")",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"ttl",
")",
"?",
"time",
"(",
")",
"+",
"$",
"this",
"->",
"ttl",
":",
"null",
";",
"}",
"if",
"(",
"is_int",
"(",
"$",
"ttl",
")",
")",
"{",
"return",
"time",
"(",
")",
"+",
"(",
"isset",
"(",
"$",
"this",
"->",
"ttl",
")",
"?",
"min",
"(",
"$",
"ttl",
",",
"$",
"this",
"->",
"ttl",
")",
":",
"$",
"ttl",
")",
";",
"}",
"if",
"(",
"$",
"ttl",
"instanceof",
"DateInterval",
")",
"{",
"$",
"timestamp",
"=",
"(",
"new",
"DateTimeImmutable",
"(",
")",
")",
"->",
"add",
"(",
"$",
"ttl",
")",
"->",
"getTimestamp",
"(",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"ttl",
")",
"?",
"min",
"(",
"$",
"timestamp",
",",
"time",
"(",
")",
"+",
"$",
"this",
"->",
"ttl",
")",
":",
"$",
"timestamp",
";",
"}",
"$",
"type",
"=",
"(",
"is_object",
"(",
"$",
"ttl",
")",
"?",
"get_class",
"(",
"$",
"ttl",
")",
".",
"' '",
":",
"''",
")",
".",
"gettype",
"(",
"$",
"ttl",
")",
";",
"throw",
"new",
"InvalidArgumentException",
"(",
"\"ttl should be of type int or DateInterval, not $type\"",
")",
";",
"}"
] | Convert TTL to epoch timestamp
@param null|int|DateInterval $ttl
@return int|null
@throws InvalidArgumentException | [
"Convert",
"TTL",
"to",
"epoch",
"timestamp"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/AbstractCache.php#L280-L298 |
33,246 | desarrolla2/Cache | src/Mysqli.php | Mysqli.initialize | protected function initialize()
{
if ($this->initialized !== false) {
return;
}
$this->query(
"CREATE TABLE IF NOT EXISTS `{table}` "
. "( `key` VARCHAR(255), `value` TEXT, `ttl` INT UNSIGNED, PRIMARY KEY (`key`) )"
);
$this->query(
"CREATE EVENT IF NOT EXISTS `apply_ttl_{$this->table}` ON SCHEDULE EVERY 1 HOUR DO BEGIN"
. " DELETE FROM {table} WHERE `ttl` < NOW();"
. " END"
);
$this->initialized = true;
} | php | protected function initialize()
{
if ($this->initialized !== false) {
return;
}
$this->query(
"CREATE TABLE IF NOT EXISTS `{table}` "
. "( `key` VARCHAR(255), `value` TEXT, `ttl` INT UNSIGNED, PRIMARY KEY (`key`) )"
);
$this->query(
"CREATE EVENT IF NOT EXISTS `apply_ttl_{$this->table}` ON SCHEDULE EVERY 1 HOUR DO BEGIN"
. " DELETE FROM {table} WHERE `ttl` < NOW();"
. " END"
);
$this->initialized = true;
} | [
"protected",
"function",
"initialize",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"initialized",
"!==",
"false",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"query",
"(",
"\"CREATE TABLE IF NOT EXISTS `{table}` \"",
".",
"\"( `key` VARCHAR(255), `value` TEXT, `ttl` INT UNSIGNED, PRIMARY KEY (`key`) )\"",
")",
";",
"$",
"this",
"->",
"query",
"(",
"\"CREATE EVENT IF NOT EXISTS `apply_ttl_{$this->table}` ON SCHEDULE EVERY 1 HOUR DO BEGIN\"",
".",
"\" DELETE FROM {table} WHERE `ttl` < NOW();\"",
".",
"\" END\"",
")",
";",
"$",
"this",
"->",
"initialized",
"=",
"true",
";",
"}"
] | Initialize table.
Automatically delete old cache. | [
"Initialize",
"table",
".",
"Automatically",
"delete",
"old",
"cache",
"."
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/Mysqli.php#L60-L78 |
33,247 | desarrolla2/Cache | src/Mysqli.php | Mysqli.query | protected function query($query, ...$params)
{
$saveParams = array_map([$this, 'quote'], $params);
$baseSql = str_replace('{table}', $this->table, $query);
$sql = vsprintf($baseSql, $saveParams);
$ret = $this->server->query($sql);
if ($ret === false) {
trigger_error($this->server->error . " $sql", E_USER_NOTICE);
}
return $ret;
} | php | protected function query($query, ...$params)
{
$saveParams = array_map([$this, 'quote'], $params);
$baseSql = str_replace('{table}', $this->table, $query);
$sql = vsprintf($baseSql, $saveParams);
$ret = $this->server->query($sql);
if ($ret === false) {
trigger_error($this->server->error . " $sql", E_USER_NOTICE);
}
return $ret;
} | [
"protected",
"function",
"query",
"(",
"$",
"query",
",",
"...",
"$",
"params",
")",
"{",
"$",
"saveParams",
"=",
"array_map",
"(",
"[",
"$",
"this",
",",
"'quote'",
"]",
",",
"$",
"params",
")",
";",
"$",
"baseSql",
"=",
"str_replace",
"(",
"'{table}'",
",",
"$",
"this",
"->",
"table",
",",
"$",
"query",
")",
";",
"$",
"sql",
"=",
"vsprintf",
"(",
"$",
"baseSql",
",",
"$",
"saveParams",
")",
";",
"$",
"ret",
"=",
"$",
"this",
"->",
"server",
"->",
"query",
"(",
"$",
"sql",
")",
";",
"if",
"(",
"$",
"ret",
"===",
"false",
")",
"{",
"trigger_error",
"(",
"$",
"this",
"->",
"server",
"->",
"error",
".",
"\" $sql\"",
",",
"E_USER_NOTICE",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | Query the MySQL server
@param string $query
@param mixed[] $params
@return \mysqli_result|false | [
"Query",
"the",
"MySQL",
"server"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/Mysqli.php#L266-L280 |
33,248 | desarrolla2/Cache | src/Mysqli.php | Mysqli.quote | protected function quote($value)
{
if ($value === null) {
return 'NULL';
}
if (is_array($value)) {
return join(', ', array_map([$this, 'quote'], $value));
}
return is_string($value)
? ('"' . $this->server->real_escape_string($value) . '"')
: (is_float($value) ? (float)$value : (int)$value);
} | php | protected function quote($value)
{
if ($value === null) {
return 'NULL';
}
if (is_array($value)) {
return join(', ', array_map([$this, 'quote'], $value));
}
return is_string($value)
? ('"' . $this->server->real_escape_string($value) . '"')
: (is_float($value) ? (float)$value : (int)$value);
} | [
"protected",
"function",
"quote",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"'NULL'",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"return",
"join",
"(",
"', '",
",",
"array_map",
"(",
"[",
"$",
"this",
",",
"'quote'",
"]",
",",
"$",
"value",
")",
")",
";",
"}",
"return",
"is_string",
"(",
"$",
"value",
")",
"?",
"(",
"'\"'",
".",
"$",
"this",
"->",
"server",
"->",
"real_escape_string",
"(",
"$",
"value",
")",
".",
"'\"'",
")",
":",
"(",
"is_float",
"(",
"$",
"value",
")",
"?",
"(",
"float",
")",
"$",
"value",
":",
"(",
"int",
")",
"$",
"value",
")",
";",
"}"
] | Quote a value to be used in an array
@param mixed $value
@return mixed | [
"Quote",
"a",
"value",
"to",
"be",
"used",
"in",
"an",
"array"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/Mysqli.php#L288-L301 |
33,249 | desarrolla2/Cache | src/Predis.php | Predis.execCommand | protected function execCommand(string $cmd, ...$args)
{
$command = $this->predis->createCommand($cmd, $args);
$response = $this->predis->executeCommand($command);
if ($response instanceof ErrorInterface) {
return false;
}
if ($response instanceof Status) {
return $response->getPayload() === 'OK';
}
return $response;
} | php | protected function execCommand(string $cmd, ...$args)
{
$command = $this->predis->createCommand($cmd, $args);
$response = $this->predis->executeCommand($command);
if ($response instanceof ErrorInterface) {
return false;
}
if ($response instanceof Status) {
return $response->getPayload() === 'OK';
}
return $response;
} | [
"protected",
"function",
"execCommand",
"(",
"string",
"$",
"cmd",
",",
"...",
"$",
"args",
")",
"{",
"$",
"command",
"=",
"$",
"this",
"->",
"predis",
"->",
"createCommand",
"(",
"$",
"cmd",
",",
"$",
"args",
")",
";",
"$",
"response",
"=",
"$",
"this",
"->",
"predis",
"->",
"executeCommand",
"(",
"$",
"command",
")",
";",
"if",
"(",
"$",
"response",
"instanceof",
"ErrorInterface",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"response",
"instanceof",
"Status",
")",
"{",
"return",
"$",
"response",
"->",
"getPayload",
"(",
")",
"===",
"'OK'",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Run a predis command.
@param string $cmd
@param mixed
@return mixed|bool | [
"Run",
"a",
"predis",
"command",
"."
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/Predis.php#L70-L84 |
33,250 | desarrolla2/Cache | src/MongoDB.php | MongoDB.filter | protected function filter($key)
{
if (is_array($key)) {
$key = ['$in' => $key];
}
return [
'_id' => $key,
'$or' => [
['ttl' => ['$gt' => new BSONUTCDateTime($this->currentTimestamp() * 1000)]],
['ttl' => null]
]
];
} | php | protected function filter($key)
{
if (is_array($key)) {
$key = ['$in' => $key];
}
return [
'_id' => $key,
'$or' => [
['ttl' => ['$gt' => new BSONUTCDateTime($this->currentTimestamp() * 1000)]],
['ttl' => null]
]
];
} | [
"protected",
"function",
"filter",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"key",
")",
")",
"{",
"$",
"key",
"=",
"[",
"'$in'",
"=>",
"$",
"key",
"]",
";",
"}",
"return",
"[",
"'_id'",
"=>",
"$",
"key",
",",
"'$or'",
"=>",
"[",
"[",
"'ttl'",
"=>",
"[",
"'$gt'",
"=>",
"new",
"BSONUTCDateTime",
"(",
"$",
"this",
"->",
"currentTimestamp",
"(",
")",
"*",
"1000",
")",
"]",
"]",
",",
"[",
"'ttl'",
"=>",
"null",
"]",
"]",
"]",
";",
"}"
] | Get filter for key and ttl.
@param string|iterable $key
@return array | [
"Get",
"filter",
"for",
"key",
"and",
"ttl",
"."
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/MongoDB.php#L74-L87 |
33,251 | desarrolla2/Cache | src/MongoDB.php | MongoDB.getTtlBSON | protected function getTtlBSON($ttl): ?BSONUTCDatetime
{
return isset($ttl) ? new BSONUTCDateTime($this->ttlToTimestamp($ttl) * 1000) : null;
} | php | protected function getTtlBSON($ttl): ?BSONUTCDatetime
{
return isset($ttl) ? new BSONUTCDateTime($this->ttlToTimestamp($ttl) * 1000) : null;
} | [
"protected",
"function",
"getTtlBSON",
"(",
"$",
"ttl",
")",
":",
"?",
"BSONUTCDatetime",
"{",
"return",
"isset",
"(",
"$",
"ttl",
")",
"?",
"new",
"BSONUTCDateTime",
"(",
"$",
"this",
"->",
"ttlToTimestamp",
"(",
"$",
"ttl",
")",
"*",
"1000",
")",
":",
"null",
";",
"}"
] | Get TTL as Date type BSON object
@param null|int|DateInterval $ttl
@return BSONUTCDatetime|null | [
"Get",
"TTL",
"as",
"Date",
"type",
"BSON",
"object"
] | e25b51fe0f9b386161c9c35e1d591f587617fcfa | https://github.com/desarrolla2/Cache/blob/e25b51fe0f9b386161c9c35e1d591f587617fcfa/src/MongoDB.php#L269-L272 |
33,252 | fpoirotte/pssht | src/Transport.php | Transport.setAddress | public function setAddress($address)
{
if (!is_string($address)) {
throw new \InvalidArgumentException();
}
if ($this->address !== null) {
throw new \RuntimeException();
}
$this->address = $address;
return $this;
} | php | public function setAddress($address)
{
if (!is_string($address)) {
throw new \InvalidArgumentException();
}
if ($this->address !== null) {
throw new \RuntimeException();
}
$this->address = $address;
return $this;
} | [
"public",
"function",
"setAddress",
"(",
"$",
"address",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"address",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"address",
"!==",
"null",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
")",
";",
"}",
"$",
"this",
"->",
"address",
"=",
"$",
"address",
";",
"return",
"$",
"this",
";",
"}"
] | Set the IP address of the client associated
with this transport layer.
\param string $address
IP address of the client.
\retval Transport
Returns this transport layer.
\note
This method is intended for use with
hostbased authentication methods.
Moreover, this method may only be called
once. Subsequent calls will result in a
RuntimeException being raised. | [
"Set",
"the",
"IP",
"address",
"of",
"the",
"client",
"associated",
"with",
"this",
"transport",
"layer",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Transport.php#L213-L225 |
33,253 | fpoirotte/pssht | src/Transport.php | Transport.updateWriteStats | public function updateWriteStats($written)
{
if (!is_int($written)) {
throw new \InvalidArgumentException('Not an integer');
}
$time = time();
$this->context['rekeyingBytes'] += $written;
if (isset($this->context['rekeying'])) {
// Do not restart key exchange
// if already rekeying.
return;
}
$logging = \Plop\Plop::getInstance();
$stats = array(
'bytes' => $this->context['rekeyingBytes'],
'duration' =>
$time - $this->context['rekeyingTime'] +
$this->rekeyingTime,
);
$logging->debug(
'%(bytes)d bytes sent in %(duration)d seconds',
$stats
);
if ($this->context['rekeyingBytes'] >= $this->rekeyingBytes ||
$time >= $this->context['rekeyingTime']) {
$logging->debug('Initiating rekeying');
$this->context['rekeying'] = 'server';
$this->context['rekeyingBytes'] = 0;
$this->context['rekeyingTime'] = $time + $this->rekeyingTime;
$kexinit = new \fpoirotte\Pssht\Handlers\InitialState();
$kexinit->handleKEXINIT($this, $this->context);
}
} | php | public function updateWriteStats($written)
{
if (!is_int($written)) {
throw new \InvalidArgumentException('Not an integer');
}
$time = time();
$this->context['rekeyingBytes'] += $written;
if (isset($this->context['rekeying'])) {
// Do not restart key exchange
// if already rekeying.
return;
}
$logging = \Plop\Plop::getInstance();
$stats = array(
'bytes' => $this->context['rekeyingBytes'],
'duration' =>
$time - $this->context['rekeyingTime'] +
$this->rekeyingTime,
);
$logging->debug(
'%(bytes)d bytes sent in %(duration)d seconds',
$stats
);
if ($this->context['rekeyingBytes'] >= $this->rekeyingBytes ||
$time >= $this->context['rekeyingTime']) {
$logging->debug('Initiating rekeying');
$this->context['rekeying'] = 'server';
$this->context['rekeyingBytes'] = 0;
$this->context['rekeyingTime'] = $time + $this->rekeyingTime;
$kexinit = new \fpoirotte\Pssht\Handlers\InitialState();
$kexinit->handleKEXINIT($this, $this->context);
}
} | [
"public",
"function",
"updateWriteStats",
"(",
"$",
"written",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"written",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Not an integer'",
")",
";",
"}",
"$",
"time",
"=",
"time",
"(",
")",
";",
"$",
"this",
"->",
"context",
"[",
"'rekeyingBytes'",
"]",
"+=",
"$",
"written",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"context",
"[",
"'rekeying'",
"]",
")",
")",
"{",
"// Do not restart key exchange",
"// if already rekeying.",
"return",
";",
"}",
"$",
"logging",
"=",
"\\",
"Plop",
"\\",
"Plop",
"::",
"getInstance",
"(",
")",
";",
"$",
"stats",
"=",
"array",
"(",
"'bytes'",
"=>",
"$",
"this",
"->",
"context",
"[",
"'rekeyingBytes'",
"]",
",",
"'duration'",
"=>",
"$",
"time",
"-",
"$",
"this",
"->",
"context",
"[",
"'rekeyingTime'",
"]",
"+",
"$",
"this",
"->",
"rekeyingTime",
",",
")",
";",
"$",
"logging",
"->",
"debug",
"(",
"'%(bytes)d bytes sent in %(duration)d seconds'",
",",
"$",
"stats",
")",
";",
"if",
"(",
"$",
"this",
"->",
"context",
"[",
"'rekeyingBytes'",
"]",
">=",
"$",
"this",
"->",
"rekeyingBytes",
"||",
"$",
"time",
">=",
"$",
"this",
"->",
"context",
"[",
"'rekeyingTime'",
"]",
")",
"{",
"$",
"logging",
"->",
"debug",
"(",
"'Initiating rekeying'",
")",
";",
"$",
"this",
"->",
"context",
"[",
"'rekeying'",
"]",
"=",
"'server'",
";",
"$",
"this",
"->",
"context",
"[",
"'rekeyingBytes'",
"]",
"=",
"0",
";",
"$",
"this",
"->",
"context",
"[",
"'rekeyingTime'",
"]",
"=",
"$",
"time",
"+",
"$",
"this",
"->",
"rekeyingTime",
";",
"$",
"kexinit",
"=",
"new",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Handlers",
"\\",
"InitialState",
"(",
")",
";",
"$",
"kexinit",
"->",
"handleKEXINIT",
"(",
"$",
"this",
",",
"$",
"this",
"->",
"context",
")",
";",
"}",
"}"
] | Update statistics about the number of bytes
written to the client.
\param int $written
Number of additional bytes written.
\return
This method does not return anything. | [
"Update",
"statistics",
"about",
"the",
"number",
"of",
"bytes",
"written",
"to",
"the",
"client",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Transport.php#L251-L287 |
33,254 | fpoirotte/pssht | src/Transport.php | Transport.setCompressor | public function setCompressor(\fpoirotte\Pssht\CompressionInterface $compressor)
{
if ($compressor->getMode() !== \fpoirotte\Pssht\CompressionInterface::MODE_COMPRESS) {
throw new \InvalidArgumentException();
}
$this->compressor = $compressor;
return $this;
} | php | public function setCompressor(\fpoirotte\Pssht\CompressionInterface $compressor)
{
if ($compressor->getMode() !== \fpoirotte\Pssht\CompressionInterface::MODE_COMPRESS) {
throw new \InvalidArgumentException();
}
$this->compressor = $compressor;
return $this;
} | [
"public",
"function",
"setCompressor",
"(",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"CompressionInterface",
"$",
"compressor",
")",
"{",
"if",
"(",
"$",
"compressor",
"->",
"getMode",
"(",
")",
"!==",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"CompressionInterface",
"::",
"MODE_COMPRESS",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"this",
"->",
"compressor",
"=",
"$",
"compressor",
";",
"return",
"$",
"this",
";",
"}"
] | Set the object used to compress outgoing packets.
\param fpoirotte::Pssht::CompressionInterface $compressor
Outgoing packets' compressor.
\retval Transport
Return this transport layer. | [
"Set",
"the",
"object",
"used",
"to",
"compress",
"outgoing",
"packets",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Transport.php#L331-L339 |
33,255 | fpoirotte/pssht | src/Transport.php | Transport.setUncompressor | public function setUncompressor(\fpoirotte\Pssht\CompressionInterface $uncompressor)
{
if ($uncompressor->getMode() !== \fpoirotte\Pssht\CompressionInterface::MODE_UNCOMPRESS) {
throw new \InvalidArgumentException();
}
$this->uncompressor = $uncompressor;
return $this;
} | php | public function setUncompressor(\fpoirotte\Pssht\CompressionInterface $uncompressor)
{
if ($uncompressor->getMode() !== \fpoirotte\Pssht\CompressionInterface::MODE_UNCOMPRESS) {
throw new \InvalidArgumentException();
}
$this->uncompressor = $uncompressor;
return $this;
} | [
"public",
"function",
"setUncompressor",
"(",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"CompressionInterface",
"$",
"uncompressor",
")",
"{",
"if",
"(",
"$",
"uncompressor",
"->",
"getMode",
"(",
")",
"!==",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"CompressionInterface",
"::",
"MODE_UNCOMPRESS",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"this",
"->",
"uncompressor",
"=",
"$",
"uncompressor",
";",
"return",
"$",
"this",
";",
"}"
] | Set the object used to uncompress incoming packets.
\param fpoirotte::Pssht::CompressionInterface $uncompressor
Incoming packets' uncompressor.
\retval Transport
Return this transport layer. | [
"Set",
"the",
"object",
"used",
"to",
"uncompress",
"incoming",
"packets",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Transport.php#L361-L369 |
33,256 | fpoirotte/pssht | src/Transport.php | Transport.getHandler | public function getHandler($type)
{
if (!is_int($type) || $type < 0 || $type > 255) {
throw new \InvalidArgumentException();
}
if (isset($this->handlers[$type])) {
return $this->handlers[$type];
}
return null;
} | php | public function getHandler($type)
{
if (!is_int($type) || $type < 0 || $type > 255) {
throw new \InvalidArgumentException();
}
if (isset($this->handlers[$type])) {
return $this->handlers[$type];
}
return null;
} | [
"public",
"function",
"getHandler",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"type",
")",
"||",
"$",
"type",
"<",
"0",
"||",
"$",
"type",
">",
"255",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"handlers",
"[",
"$",
"type",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"handlers",
"[",
"$",
"type",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Retrieve the current handler for a given message type.
\param int $type
Message type.
\retval fpoirotte::Pssht::HandlerInterface
Handler associated with the given message type.
\retval null
There is no handler currently registered
for the given message type. | [
"Retrieve",
"the",
"current",
"handler",
"for",
"a",
"given",
"message",
"type",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Transport.php#L547-L557 |
33,257 | fpoirotte/pssht | src/Transport.php | Transport.setHandler | public function setHandler($type, \fpoirotte\Pssht\HandlerInterface $handler)
{
if (!is_int($type) || $type < 0 || $type > 255) {
throw new \InvalidArgumentException();
}
$this->handlers[$type] = $handler;
return $this;
} | php | public function setHandler($type, \fpoirotte\Pssht\HandlerInterface $handler)
{
if (!is_int($type) || $type < 0 || $type > 255) {
throw new \InvalidArgumentException();
}
$this->handlers[$type] = $handler;
return $this;
} | [
"public",
"function",
"setHandler",
"(",
"$",
"type",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"HandlerInterface",
"$",
"handler",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"type",
")",
"||",
"$",
"type",
"<",
"0",
"||",
"$",
"type",
">",
"255",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"this",
"->",
"handlers",
"[",
"$",
"type",
"]",
"=",
"$",
"handler",
";",
"return",
"$",
"this",
";",
"}"
] | Register a handler for a specific SSH message type.
\param int $type
Message type.
\param fpoirotte::Pssht::HandlerInterface $handler
Handler to register for that message type.
\retval Transport
Returns this transport layer.
\note
The given handler will overwrite any previously
registered handler for that message type. | [
"Register",
"a",
"handler",
"for",
"a",
"specific",
"SSH",
"message",
"type",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Transport.php#L575-L583 |
33,258 | fpoirotte/pssht | src/Transport.php | Transport.unsetHandler | public function unsetHandler($type, \fpoirotte\Pssht\HandlerInterface $handler)
{
if (!is_int($type) || $type < 0 || $type > 255) {
throw new \InvalidArgumentException();
}
if (isset($this->handlers[$type]) && $this->handlers[$type] === $handler) {
unset($this->handlers[$type]);
}
return $this;
} | php | public function unsetHandler($type, \fpoirotte\Pssht\HandlerInterface $handler)
{
if (!is_int($type) || $type < 0 || $type > 255) {
throw new \InvalidArgumentException();
}
if (isset($this->handlers[$type]) && $this->handlers[$type] === $handler) {
unset($this->handlers[$type]);
}
return $this;
} | [
"public",
"function",
"unsetHandler",
"(",
"$",
"type",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"HandlerInterface",
"$",
"handler",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"type",
")",
"||",
"$",
"type",
"<",
"0",
"||",
"$",
"type",
">",
"255",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"handlers",
"[",
"$",
"type",
"]",
")",
"&&",
"$",
"this",
"->",
"handlers",
"[",
"$",
"type",
"]",
"===",
"$",
"handler",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"handlers",
"[",
"$",
"type",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Unregister a handler for a specific SSH message type.
\param int $type
Message type.
\param fpoirotte::Pssht::HandlerInterface $handler
Handler to unregister for that message type.
\retval Transport
Returns this transport layer. | [
"Unregister",
"a",
"handler",
"for",
"a",
"specific",
"SSH",
"message",
"type",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Transport.php#L597-L607 |
33,259 | fpoirotte/pssht | src/Application/EchoService.php | EchoService.handle | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$message = \fpoirotte\Pssht\Messages\CHANNEL\DATA::unserialize($decoder);
$channel = $message->getChannel();
$response = new \fpoirotte\Pssht\Messages\CHANNEL\DATA($channel, $message->getData());
$transport->writeMessage($response);
return true;
} | php | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$message = \fpoirotte\Pssht\Messages\CHANNEL\DATA::unserialize($decoder);
$channel = $message->getChannel();
$response = new \fpoirotte\Pssht\Messages\CHANNEL\DATA($channel, $message->getData());
$transport->writeMessage($response);
return true;
} | [
"public",
"function",
"handle",
"(",
"$",
"msgType",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Wire",
"\\",
"Decoder",
"$",
"decoder",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Transport",
"$",
"transport",
",",
"array",
"&",
"$",
"context",
")",
"{",
"$",
"message",
"=",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"CHANNEL",
"\\",
"DATA",
"::",
"unserialize",
"(",
"$",
"decoder",
")",
";",
"$",
"channel",
"=",
"$",
"message",
"->",
"getChannel",
"(",
")",
";",
"$",
"response",
"=",
"new",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"CHANNEL",
"\\",
"DATA",
"(",
"$",
"channel",
",",
"$",
"message",
"->",
"getData",
"(",
")",
")",
";",
"$",
"transport",
"->",
"writeMessage",
"(",
"$",
"response",
")",
";",
"return",
"true",
";",
"}"
] | SSH_MSG_CHANNEL_DATA = 94 | [
"SSH_MSG_CHANNEL_DATA",
"=",
"94"
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Application/EchoService.php#L24-L35 |
33,260 | fpoirotte/pssht | src/Handlers/DEBUG.php | DEBUG.handle | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$message = \fpoirotte\Pssht\Messages\DEBUG::unserialize($decoder);
if ($message->mustAlwaysDisplay()) {
echo escape($message->getMessage()) . PHP_EOL;
}
return true;
} | php | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$message = \fpoirotte\Pssht\Messages\DEBUG::unserialize($decoder);
if ($message->mustAlwaysDisplay()) {
echo escape($message->getMessage()) . PHP_EOL;
}
return true;
} | [
"public",
"function",
"handle",
"(",
"$",
"msgType",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Wire",
"\\",
"Decoder",
"$",
"decoder",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Transport",
"$",
"transport",
",",
"array",
"&",
"$",
"context",
")",
"{",
"$",
"message",
"=",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"DEBUG",
"::",
"unserialize",
"(",
"$",
"decoder",
")",
";",
"if",
"(",
"$",
"message",
"->",
"mustAlwaysDisplay",
"(",
")",
")",
"{",
"echo",
"escape",
"(",
"$",
"message",
"->",
"getMessage",
"(",
")",
")",
".",
"PHP_EOL",
";",
"}",
"return",
"true",
";",
"}"
] | SSH_MSG_DEBUG = 4 | [
"SSH_MSG_DEBUG",
"=",
"4"
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/DEBUG.php#L20-L31 |
33,261 | fpoirotte/pssht | src/KeyStore.php | KeyStore.getIdentifier | protected function getIdentifier(\fpoirotte\Pssht\PublicKeyInterface $key)
{
$encoder = new \fpoirotte\Pssht\Wire\Encoder();
$key->serialize($encoder);
return $encoder->getBuffer()->get(0);
} | php | protected function getIdentifier(\fpoirotte\Pssht\PublicKeyInterface $key)
{
$encoder = new \fpoirotte\Pssht\Wire\Encoder();
$key->serialize($encoder);
return $encoder->getBuffer()->get(0);
} | [
"protected",
"function",
"getIdentifier",
"(",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"PublicKeyInterface",
"$",
"key",
")",
"{",
"$",
"encoder",
"=",
"new",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Wire",
"\\",
"Encoder",
"(",
")",
";",
"$",
"key",
"->",
"serialize",
"(",
"$",
"encoder",
")",
";",
"return",
"$",
"encoder",
"->",
"getBuffer",
"(",
")",
"->",
"get",
"(",
"0",
")",
";",
"}"
] | Return the identifier for a key.
\param fpoirotte::Pssht::PublicKeyInterface $key
Public or private key.
\retval string
SSH identifier for the key. | [
"Return",
"the",
"identifier",
"for",
"a",
"key",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/KeyStore.php#L39-L44 |
33,262 | fpoirotte/pssht | src/KeyStore.php | KeyStore.add | public function add($user, \fpoirotte\Pssht\PublicKeyInterface $key)
{
if (!is_string($user)) {
throw new \InvalidArgumentException();
}
$this->keys[$user][$this->getIdentifier($key)] = $key;
} | php | public function add($user, \fpoirotte\Pssht\PublicKeyInterface $key)
{
if (!is_string($user)) {
throw new \InvalidArgumentException();
}
$this->keys[$user][$this->getIdentifier($key)] = $key;
} | [
"public",
"function",
"add",
"(",
"$",
"user",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"PublicKeyInterface",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"user",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"this",
"->",
"keys",
"[",
"$",
"user",
"]",
"[",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"key",
")",
"]",
"=",
"$",
"key",
";",
"}"
] | Add a new key in the store.
\param string $user
User the key belongs to.
\param fpoirotte::Pssht::PublicKeyInterface $key
Public/private key to add. | [
"Add",
"a",
"new",
"key",
"in",
"the",
"store",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/KeyStore.php#L55-L62 |
33,263 | fpoirotte/pssht | src/KeyStore.php | KeyStore.get | public function get($user)
{
if (!is_string($user)) {
throw new \InvalidArgumentException();
}
if (!isset($this->keys[$user])) {
return new \ArrayIterator();
}
return new \ArrayIterator($this->keys[$user]);
} | php | public function get($user)
{
if (!is_string($user)) {
throw new \InvalidArgumentException();
}
if (!isset($this->keys[$user])) {
return new \ArrayIterator();
}
return new \ArrayIterator($this->keys[$user]);
} | [
"public",
"function",
"get",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"user",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"keys",
"[",
"$",
"user",
"]",
")",
")",
"{",
"return",
"new",
"\\",
"ArrayIterator",
"(",
")",
";",
"}",
"return",
"new",
"\\",
"ArrayIterator",
"(",
"$",
"this",
"->",
"keys",
"[",
"$",
"user",
"]",
")",
";",
"}"
] | Retrieve a list of the keys currently
stored for the given user.
\param string $user
User whose keys should be retrieved.
\retval array
Public/private keys for the given user. | [
"Retrieve",
"a",
"list",
"of",
"the",
"keys",
"currently",
"stored",
"for",
"the",
"given",
"user",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/KeyStore.php#L92-L103 |
33,264 | fpoirotte/pssht | src/KeyStore.php | KeyStore.exists | public function exists($user, $key)
{
if (!is_string($user)) {
throw new \InvalidArgumentException();
}
if ($key instanceof \fpoirotte\Pssht\PublicKeyInterface) {
$key = $this->getIdentifier($key);
}
if (!is_string($key)) {
throw new \InvalidArgumentException();
}
return isset($this->keys[$user][$key]);
} | php | public function exists($user, $key)
{
if (!is_string($user)) {
throw new \InvalidArgumentException();
}
if ($key instanceof \fpoirotte\Pssht\PublicKeyInterface) {
$key = $this->getIdentifier($key);
}
if (!is_string($key)) {
throw new \InvalidArgumentException();
}
return isset($this->keys[$user][$key]);
} | [
"public",
"function",
"exists",
"(",
"$",
"user",
",",
"$",
"key",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"user",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"$",
"key",
"instanceof",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"PublicKeyInterface",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"key",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"keys",
"[",
"$",
"user",
"]",
"[",
"$",
"key",
"]",
")",
";",
"}"
] | Test whether a given key as been registered
for a specific user.
\param string $user
User for which the key is tested.
\param string|fpoirotte::Pssht::PublicKeyInterface $key
Key to test.
\retval bool
\c true if the given key has been registered
for the given user, \c false otherwise. | [
"Test",
"whether",
"a",
"given",
"key",
"as",
"been",
"registered",
"for",
"a",
"specific",
"user",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/KeyStore.php#L119-L133 |
33,265 | fpoirotte/pssht | src/KeyStore.php | KeyStore.count | public function count($user)
{
if (!is_string($user)) {
throw new \InvalidArgumentException();
}
if (!isset($this->keys[$user])) {
return 0;
}
return count($this->keys[$user]);
} | php | public function count($user)
{
if (!is_string($user)) {
throw new \InvalidArgumentException();
}
if (!isset($this->keys[$user])) {
return 0;
}
return count($this->keys[$user]);
} | [
"public",
"function",
"count",
"(",
"$",
"user",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"user",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"keys",
"[",
"$",
"user",
"]",
")",
")",
"{",
"return",
"0",
";",
"}",
"return",
"count",
"(",
"$",
"this",
"->",
"keys",
"[",
"$",
"user",
"]",
")",
";",
"}"
] | Return the number of keys currently registered
for the given user.
\param string $user
User whose keys must be counted.
\retval int
Number of available keys for the given user. | [
"Return",
"the",
"number",
"of",
"keys",
"currently",
"registered",
"for",
"the",
"given",
"user",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/KeyStore.php#L145-L156 |
33,266 | fpoirotte/pssht | src/Handlers/CHANNEL/REQUEST.php | REQUEST.handle | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$encoder = new \fpoirotte\Pssht\Wire\Encoder();
$channel = $decoder->decodeUint32();
$type = $decoder->decodeString();
$wantsReply = $decoder->decodeBoolean();
$encoder->encodeUint32($channel);
$encoder->encodeString($type);
$encoder->encodeBoolean($wantsReply);
$decoder->getBuffer()->unget($encoder->getBuffer()->get(0));
$remoteChannel = $this->connection->getChannel($channel);
switch ($type) {
case 'exec':
case 'shell':
case 'pty-req':
// Normalize the name.
// Eg. "pty-req" becomes "PtyReq".
$cls = str_replace(' ', '', ucwords(str_replace('-', ' ', $type)));
$cls = '\\fpoirotte\\Pssht\\Messages\\CHANNEL\\REQUEST\\' . $cls;
$message = $cls::unserialize($decoder);
break;
default:
if ($wantsReply) {
$response = new \fpoirotte\Pssht\Messages\CHANNEL\FAILURE($remoteChannel);
$transport->writeMessage($response);
}
return true;
}
if (!$wantsReply) {
return true;
}
if (in_array($type, array('shell', 'exec'), true)) {
$response = new \fpoirotte\Pssht\Messages\CHANNEL\SUCCESS($remoteChannel);
} else {
$response = new \fpoirotte\Pssht\Messages\CHANNEL\FAILURE($remoteChannel);
}
$transport->writeMessage($response);
if (in_array($type, array('shell', 'exec'), true)) {
$callable = $transport->getApplicationFactory();
if ($callable !== null) {
call_user_func($callable, $transport, $this->connection, $message);
}
}
return true;
} | php | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$encoder = new \fpoirotte\Pssht\Wire\Encoder();
$channel = $decoder->decodeUint32();
$type = $decoder->decodeString();
$wantsReply = $decoder->decodeBoolean();
$encoder->encodeUint32($channel);
$encoder->encodeString($type);
$encoder->encodeBoolean($wantsReply);
$decoder->getBuffer()->unget($encoder->getBuffer()->get(0));
$remoteChannel = $this->connection->getChannel($channel);
switch ($type) {
case 'exec':
case 'shell':
case 'pty-req':
// Normalize the name.
// Eg. "pty-req" becomes "PtyReq".
$cls = str_replace(' ', '', ucwords(str_replace('-', ' ', $type)));
$cls = '\\fpoirotte\\Pssht\\Messages\\CHANNEL\\REQUEST\\' . $cls;
$message = $cls::unserialize($decoder);
break;
default:
if ($wantsReply) {
$response = new \fpoirotte\Pssht\Messages\CHANNEL\FAILURE($remoteChannel);
$transport->writeMessage($response);
}
return true;
}
if (!$wantsReply) {
return true;
}
if (in_array($type, array('shell', 'exec'), true)) {
$response = new \fpoirotte\Pssht\Messages\CHANNEL\SUCCESS($remoteChannel);
} else {
$response = new \fpoirotte\Pssht\Messages\CHANNEL\FAILURE($remoteChannel);
}
$transport->writeMessage($response);
if (in_array($type, array('shell', 'exec'), true)) {
$callable = $transport->getApplicationFactory();
if ($callable !== null) {
call_user_func($callable, $transport, $this->connection, $message);
}
}
return true;
} | [
"public",
"function",
"handle",
"(",
"$",
"msgType",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Wire",
"\\",
"Decoder",
"$",
"decoder",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Transport",
"$",
"transport",
",",
"array",
"&",
"$",
"context",
")",
"{",
"$",
"encoder",
"=",
"new",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Wire",
"\\",
"Encoder",
"(",
")",
";",
"$",
"channel",
"=",
"$",
"decoder",
"->",
"decodeUint32",
"(",
")",
";",
"$",
"type",
"=",
"$",
"decoder",
"->",
"decodeString",
"(",
")",
";",
"$",
"wantsReply",
"=",
"$",
"decoder",
"->",
"decodeBoolean",
"(",
")",
";",
"$",
"encoder",
"->",
"encodeUint32",
"(",
"$",
"channel",
")",
";",
"$",
"encoder",
"->",
"encodeString",
"(",
"$",
"type",
")",
";",
"$",
"encoder",
"->",
"encodeBoolean",
"(",
"$",
"wantsReply",
")",
";",
"$",
"decoder",
"->",
"getBuffer",
"(",
")",
"->",
"unget",
"(",
"$",
"encoder",
"->",
"getBuffer",
"(",
")",
"->",
"get",
"(",
"0",
")",
")",
";",
"$",
"remoteChannel",
"=",
"$",
"this",
"->",
"connection",
"->",
"getChannel",
"(",
"$",
"channel",
")",
";",
"switch",
"(",
"$",
"type",
")",
"{",
"case",
"'exec'",
":",
"case",
"'shell'",
":",
"case",
"'pty-req'",
":",
"// Normalize the name.",
"// Eg. \"pty-req\" becomes \"PtyReq\".",
"$",
"cls",
"=",
"str_replace",
"(",
"' '",
",",
"''",
",",
"ucwords",
"(",
"str_replace",
"(",
"'-'",
",",
"' '",
",",
"$",
"type",
")",
")",
")",
";",
"$",
"cls",
"=",
"'\\\\fpoirotte\\\\Pssht\\\\Messages\\\\CHANNEL\\\\REQUEST\\\\'",
".",
"$",
"cls",
";",
"$",
"message",
"=",
"$",
"cls",
"::",
"unserialize",
"(",
"$",
"decoder",
")",
";",
"break",
";",
"default",
":",
"if",
"(",
"$",
"wantsReply",
")",
"{",
"$",
"response",
"=",
"new",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"CHANNEL",
"\\",
"FAILURE",
"(",
"$",
"remoteChannel",
")",
";",
"$",
"transport",
"->",
"writeMessage",
"(",
"$",
"response",
")",
";",
"}",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"$",
"wantsReply",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"type",
",",
"array",
"(",
"'shell'",
",",
"'exec'",
")",
",",
"true",
")",
")",
"{",
"$",
"response",
"=",
"new",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"CHANNEL",
"\\",
"SUCCESS",
"(",
"$",
"remoteChannel",
")",
";",
"}",
"else",
"{",
"$",
"response",
"=",
"new",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"CHANNEL",
"\\",
"FAILURE",
"(",
"$",
"remoteChannel",
")",
";",
"}",
"$",
"transport",
"->",
"writeMessage",
"(",
"$",
"response",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"type",
",",
"array",
"(",
"'shell'",
",",
"'exec'",
")",
",",
"true",
")",
")",
"{",
"$",
"callable",
"=",
"$",
"transport",
"->",
"getApplicationFactory",
"(",
")",
";",
"if",
"(",
"$",
"callable",
"!==",
"null",
")",
"{",
"call_user_func",
"(",
"$",
"callable",
",",
"$",
"transport",
",",
"$",
"this",
"->",
"connection",
",",
"$",
"message",
")",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | SSH_MSG_CHANNEL_REQUEST = 98 | [
"SSH_MSG_CHANNEL_REQUEST",
"=",
"98"
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/CHANNEL/REQUEST.php#L20-L75 |
33,267 | fpoirotte/pssht | src/Handlers/KEXDH/INIT.php | INIT.handle | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$hostAlgo = null;
foreach ($context['kex']['client']->getServerHostKeyAlgos() as $algo) {
if (isset($context['serverKeys'][$algo])) {
$hostAlgo = $algo;
break;
}
}
if ($hostAlgo === null) {
throw new \RuntimeException();
}
$response = $this->createResponse($decoder, $transport, $context, $hostAlgo);
$logging = \Plop\Plop::getInstance();
$secret = gmp_strval($response->getSharedSecret(), 16);
$logging->debug(
"Shared secret:\r\n%s",
array(
wordwrap($secret, 16, ' ', true)
)
);
$logging->debug(
'Hash: %s',
array(
wordwrap(bin2hex($response->getExchangeHash()), 16, ' ', true)
)
);
if (!isset($context['sessionIdentifier'])) {
$context['sessionIdentifier'] = $response->getExchangeHash();
}
$context['DH'] = $response;
$transport->writeMessage($response);
return true;
} | php | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$hostAlgo = null;
foreach ($context['kex']['client']->getServerHostKeyAlgos() as $algo) {
if (isset($context['serverKeys'][$algo])) {
$hostAlgo = $algo;
break;
}
}
if ($hostAlgo === null) {
throw new \RuntimeException();
}
$response = $this->createResponse($decoder, $transport, $context, $hostAlgo);
$logging = \Plop\Plop::getInstance();
$secret = gmp_strval($response->getSharedSecret(), 16);
$logging->debug(
"Shared secret:\r\n%s",
array(
wordwrap($secret, 16, ' ', true)
)
);
$logging->debug(
'Hash: %s',
array(
wordwrap(bin2hex($response->getExchangeHash()), 16, ' ', true)
)
);
if (!isset($context['sessionIdentifier'])) {
$context['sessionIdentifier'] = $response->getExchangeHash();
}
$context['DH'] = $response;
$transport->writeMessage($response);
return true;
} | [
"public",
"function",
"handle",
"(",
"$",
"msgType",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Wire",
"\\",
"Decoder",
"$",
"decoder",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Transport",
"$",
"transport",
",",
"array",
"&",
"$",
"context",
")",
"{",
"$",
"hostAlgo",
"=",
"null",
";",
"foreach",
"(",
"$",
"context",
"[",
"'kex'",
"]",
"[",
"'client'",
"]",
"->",
"getServerHostKeyAlgos",
"(",
")",
"as",
"$",
"algo",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"context",
"[",
"'serverKeys'",
"]",
"[",
"$",
"algo",
"]",
")",
")",
"{",
"$",
"hostAlgo",
"=",
"$",
"algo",
";",
"break",
";",
"}",
"}",
"if",
"(",
"$",
"hostAlgo",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"createResponse",
"(",
"$",
"decoder",
",",
"$",
"transport",
",",
"$",
"context",
",",
"$",
"hostAlgo",
")",
";",
"$",
"logging",
"=",
"\\",
"Plop",
"\\",
"Plop",
"::",
"getInstance",
"(",
")",
";",
"$",
"secret",
"=",
"gmp_strval",
"(",
"$",
"response",
"->",
"getSharedSecret",
"(",
")",
",",
"16",
")",
";",
"$",
"logging",
"->",
"debug",
"(",
"\"Shared secret:\\r\\n%s\"",
",",
"array",
"(",
"wordwrap",
"(",
"$",
"secret",
",",
"16",
",",
"' '",
",",
"true",
")",
")",
")",
";",
"$",
"logging",
"->",
"debug",
"(",
"'Hash: %s'",
",",
"array",
"(",
"wordwrap",
"(",
"bin2hex",
"(",
"$",
"response",
"->",
"getExchangeHash",
"(",
")",
")",
",",
"16",
",",
"' '",
",",
"true",
")",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"context",
"[",
"'sessionIdentifier'",
"]",
")",
")",
"{",
"$",
"context",
"[",
"'sessionIdentifier'",
"]",
"=",
"$",
"response",
"->",
"getExchangeHash",
"(",
")",
";",
"}",
"$",
"context",
"[",
"'DH'",
"]",
"=",
"$",
"response",
";",
"$",
"transport",
"->",
"writeMessage",
"(",
"$",
"response",
")",
";",
"return",
"true",
";",
"}"
] | SSH_MSG_KEXDH_INIT = 30 | [
"SSH_MSG_KEXDH_INIT",
"=",
"30"
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/KEXDH/INIT.php#L20-L60 |
33,268 | fpoirotte/pssht | src/Handlers/USERAUTH/REQUEST.php | REQUEST.failure | protected function failure(
\fpoirotte\Pssht\Transport $transport,
array &$context,
$partial = false
) {
if (!is_bool($partial)) {
throw new \InvalidArgumentException();
}
$remaining = $context['authMethods'];
unset($remaining['none']);
$remaining = array_keys($remaining);
$response = new \fpoirotte\Pssht\Messages\USERAUTH\FAILURE($remaining, $partial);
$transport->writeMessage($response);
return true;
} | php | protected function failure(
\fpoirotte\Pssht\Transport $transport,
array &$context,
$partial = false
) {
if (!is_bool($partial)) {
throw new \InvalidArgumentException();
}
$remaining = $context['authMethods'];
unset($remaining['none']);
$remaining = array_keys($remaining);
$response = new \fpoirotte\Pssht\Messages\USERAUTH\FAILURE($remaining, $partial);
$transport->writeMessage($response);
return true;
} | [
"protected",
"function",
"failure",
"(",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Transport",
"$",
"transport",
",",
"array",
"&",
"$",
"context",
",",
"$",
"partial",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"is_bool",
"(",
"$",
"partial",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"remaining",
"=",
"$",
"context",
"[",
"'authMethods'",
"]",
";",
"unset",
"(",
"$",
"remaining",
"[",
"'none'",
"]",
")",
";",
"$",
"remaining",
"=",
"array_keys",
"(",
"$",
"remaining",
")",
";",
"$",
"response",
"=",
"new",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"USERAUTH",
"\\",
"FAILURE",
"(",
"$",
"remaining",
",",
"$",
"partial",
")",
";",
"$",
"transport",
"->",
"writeMessage",
"(",
"$",
"response",
")",
";",
"return",
"true",
";",
"}"
] | Report an authentication failure.
\param fpoirotte::Pssht::Transport $transport
Transport layer used to report the failure.
\param array &$context
SSH session context (containing authentication methods
that may continue).
\param bool $partial
(optional) Indicates whether the request ended with
a partial success (\b true) or not (\b false).
If omitted, \b false is implied.
\retval true
This method always returns true. | [
"Report",
"an",
"authentication",
"failure",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/USERAUTH/REQUEST.php#L165-L180 |
33,269 | fpoirotte/pssht | src/Handlers/SERVICE/REQUEST.php | REQUEST.handle | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$message = \fpoirotte\Pssht\Messages\SERVICE\REQUEST::unserialize($decoder);
$service = $message->getServiceName();
if ($service === 'ssh-userauth') {
$response = new \fpoirotte\Pssht\Messages\SERVICE\ACCEPT($service);
$transport->setHandler(
\fpoirotte\Pssht\Messages\USERAUTH\REQUEST\Base::getMessageId(),
$this->userAuthRequestHandler
);
} else {
$response = new DISCONNECT(
DISCONNECT::SSH_DISCONNECT_SERVICE_NOT_AVAILABLE,
'No such service'
);
}
$transport->writeMessage($response);
return true;
} | php | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$message = \fpoirotte\Pssht\Messages\SERVICE\REQUEST::unserialize($decoder);
$service = $message->getServiceName();
if ($service === 'ssh-userauth') {
$response = new \fpoirotte\Pssht\Messages\SERVICE\ACCEPT($service);
$transport->setHandler(
\fpoirotte\Pssht\Messages\USERAUTH\REQUEST\Base::getMessageId(),
$this->userAuthRequestHandler
);
} else {
$response = new DISCONNECT(
DISCONNECT::SSH_DISCONNECT_SERVICE_NOT_AVAILABLE,
'No such service'
);
}
$transport->writeMessage($response);
return true;
} | [
"public",
"function",
"handle",
"(",
"$",
"msgType",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Wire",
"\\",
"Decoder",
"$",
"decoder",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Transport",
"$",
"transport",
",",
"array",
"&",
"$",
"context",
")",
"{",
"$",
"message",
"=",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"SERVICE",
"\\",
"REQUEST",
"::",
"unserialize",
"(",
"$",
"decoder",
")",
";",
"$",
"service",
"=",
"$",
"message",
"->",
"getServiceName",
"(",
")",
";",
"if",
"(",
"$",
"service",
"===",
"'ssh-userauth'",
")",
"{",
"$",
"response",
"=",
"new",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"SERVICE",
"\\",
"ACCEPT",
"(",
"$",
"service",
")",
";",
"$",
"transport",
"->",
"setHandler",
"(",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"USERAUTH",
"\\",
"REQUEST",
"\\",
"Base",
"::",
"getMessageId",
"(",
")",
",",
"$",
"this",
"->",
"userAuthRequestHandler",
")",
";",
"}",
"else",
"{",
"$",
"response",
"=",
"new",
"DISCONNECT",
"(",
"DISCONNECT",
"::",
"SSH_DISCONNECT_SERVICE_NOT_AVAILABLE",
",",
"'No such service'",
")",
";",
"}",
"$",
"transport",
"->",
"writeMessage",
"(",
"$",
"response",
")",
";",
"return",
"true",
";",
"}"
] | SSH_MSG_SERVICE_REQUEST = 5 | [
"SSH_MSG_SERVICE_REQUEST",
"=",
"5"
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/SERVICE/REQUEST.php#L36-L59 |
33,270 | fpoirotte/pssht | src/Connection.php | Connection.allocateChannel | public function allocateChannel(\fpoirotte\Pssht\Messages\CHANNEL\OPEN $message)
{
for ($i = 0; isset($this->channels[$i]); ++$i) {
// Do nothing.
}
$this->channels[$i] = $message->getChannel();
$this->handlers[$i] = array();
return $i;
} | php | public function allocateChannel(\fpoirotte\Pssht\Messages\CHANNEL\OPEN $message)
{
for ($i = 0; isset($this->channels[$i]); ++$i) {
// Do nothing.
}
$this->channels[$i] = $message->getChannel();
$this->handlers[$i] = array();
return $i;
} | [
"public",
"function",
"allocateChannel",
"(",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"CHANNEL",
"\\",
"OPEN",
"$",
"message",
")",
"{",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"isset",
"(",
"$",
"this",
"->",
"channels",
"[",
"$",
"i",
"]",
")",
";",
"++",
"$",
"i",
")",
"{",
"// Do nothing.",
"}",
"$",
"this",
"->",
"channels",
"[",
"$",
"i",
"]",
"=",
"$",
"message",
"->",
"getChannel",
"(",
")",
";",
"$",
"this",
"->",
"handlers",
"[",
"$",
"i",
"]",
"=",
"array",
"(",
")",
";",
"return",
"$",
"i",
";",
"}"
] | Allocate a new communication channel.
\param fpoirotte::Pssht::Messages::CHANNEL::OPEN $message
Original message requesting channel allocation.
\return int
Newly allocated channel's identifier. | [
"Allocate",
"a",
"new",
"communication",
"channel",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Connection.php#L93-L101 |
33,271 | fpoirotte/pssht | src/Connection.php | Connection.freeChannel | public function freeChannel($id)
{
if (!is_int($id)) {
throw new \InvalidArgumentException();
}
unset($this->channels[$id]);
unset($this->handlers[$id]);
return $this;
} | php | public function freeChannel($id)
{
if (!is_int($id)) {
throw new \InvalidArgumentException();
}
unset($this->channels[$id]);
unset($this->handlers[$id]);
return $this;
} | [
"public",
"function",
"freeChannel",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"id",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"channels",
"[",
"$",
"id",
"]",
")",
";",
"unset",
"(",
"$",
"this",
"->",
"handlers",
"[",
"$",
"id",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Free a channel allocation.
\param int $id
Channel identifier.
\retval Connection
Returns this connection. | [
"Free",
"a",
"channel",
"allocation",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Connection.php#L112-L121 |
33,272 | fpoirotte/pssht | src/Connection.php | Connection.getChannel | public function getChannel($message)
{
if (is_int($message)) {
return $this->channels[$message];
}
return $this->channels[$message->getChannel()];
} | php | public function getChannel($message)
{
if (is_int($message)) {
return $this->channels[$message];
}
return $this->channels[$message->getChannel()];
} | [
"public",
"function",
"getChannel",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"message",
")",
")",
"{",
"return",
"$",
"this",
"->",
"channels",
"[",
"$",
"message",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"channels",
"[",
"$",
"message",
"->",
"getChannel",
"(",
")",
"]",
";",
"}"
] | Retrieve the channel associated with a message.
\param int|fpoirotte::Pssht::Messages::CHANNEL::REQUEST::Base $message
Either a message or the message's channel identifier.
\retval int
Remote channel associated with the message. | [
"Retrieve",
"the",
"channel",
"associated",
"with",
"a",
"message",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Connection.php#L132-L138 |
33,273 | fpoirotte/pssht | src/Connection.php | Connection.setHandler | public function setHandler(
$message,
$type,
\fpoirotte\Pssht\HandlerInterface $handler
) {
if (!is_int($type) || $type < 0 || $type > 255) {
throw new \InvalidArgumentException();
}
if (!is_int($message)) {
if (!($message instanceof \fpoirotte\Pssht\Messages\CHANNEL\REQUEST\Base)) {
throw new \InvalidArgumentException();
}
$message = $message->getChannel();
}
$this->handlers[$message][$type] = $handler;
return $this;
} | php | public function setHandler(
$message,
$type,
\fpoirotte\Pssht\HandlerInterface $handler
) {
if (!is_int($type) || $type < 0 || $type > 255) {
throw new \InvalidArgumentException();
}
if (!is_int($message)) {
if (!($message instanceof \fpoirotte\Pssht\Messages\CHANNEL\REQUEST\Base)) {
throw new \InvalidArgumentException();
}
$message = $message->getChannel();
}
$this->handlers[$message][$type] = $handler;
return $this;
} | [
"public",
"function",
"setHandler",
"(",
"$",
"message",
",",
"$",
"type",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"HandlerInterface",
"$",
"handler",
")",
"{",
"if",
"(",
"!",
"is_int",
"(",
"$",
"type",
")",
"||",
"$",
"type",
"<",
"0",
"||",
"$",
"type",
">",
"255",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_int",
"(",
"$",
"message",
")",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"message",
"instanceof",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"CHANNEL",
"\\",
"REQUEST",
"\\",
"Base",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"message",
"=",
"$",
"message",
"->",
"getChannel",
"(",
")",
";",
"}",
"$",
"this",
"->",
"handlers",
"[",
"$",
"message",
"]",
"[",
"$",
"type",
"]",
"=",
"$",
"handler",
";",
"return",
"$",
"this",
";",
"}"
] | Register a handler.
\param int|fpoirotte::Pssht::Messages::CHANNEL::REQUEST::Base $message
Either a message or the message's channel identifier.
\param int $type
Message type.
\param fpoirotte::Pssht::HandlerInterface $handler
Handler to associate with the message. | [
"Register",
"a",
"handler",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Connection.php#L152-L170 |
33,274 | fpoirotte/pssht | src/Algorithms.php | Algorithms.getValidClass | protected function getValidClass($type, $name)
{
$logging = \Plop\Plop::getInstance();;
$w = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890\\';
if (!is_string($name) || strspn($name, $w) !== strlen($name)) {
$logging->debug(
'Skipping %(type)s algorithm "%(name)s" (invalid class name)',
array('type' => $type, 'name' => $name)
);
return null;
}
// Non-existing classes.
$class = "\\fpoirotte\\Pssht\\$type$name";
if (!class_exists($class)) {
if (!interface_exists($class)) {
$logging->debug(
'Skipping %(type)s algorithm "%(name)s" (class does not exist)',
array('type' => $type, 'name' => $name)
);
}
return null;
}
// Abstract classes.
$reflector = new \ReflectionClass($class);
if ($reflector->isAbstract()) {
return null;
}
// Classes that implement AvailabilityInterface
// where the algorithm is not currently available.
$iface = '\\fpoirotte\\Pssht\\AvailabilityInterface';
if ($reflector->implementsInterface($iface) && !$class::isAvailable()) {
$logging->debug(
'Skipping %(type)s algorithm "%(name)s" (not available)',
array('type' => $type, 'name' => $name)
);
return null;
}
// Classes that do not implement the proper interface.
$iface = $this->interfaces[$type];
if ($iface !== null && !$reflector->implementsInterface($iface)) {
$logging->debug(
'Skipping %(type)s algorithm "%(name)s" (invalid interface)',
array('type' => $type, 'name' => $name)
);
return null;
}
return $class;
} | php | protected function getValidClass($type, $name)
{
$logging = \Plop\Plop::getInstance();;
$w = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890\\';
if (!is_string($name) || strspn($name, $w) !== strlen($name)) {
$logging->debug(
'Skipping %(type)s algorithm "%(name)s" (invalid class name)',
array('type' => $type, 'name' => $name)
);
return null;
}
// Non-existing classes.
$class = "\\fpoirotte\\Pssht\\$type$name";
if (!class_exists($class)) {
if (!interface_exists($class)) {
$logging->debug(
'Skipping %(type)s algorithm "%(name)s" (class does not exist)',
array('type' => $type, 'name' => $name)
);
}
return null;
}
// Abstract classes.
$reflector = new \ReflectionClass($class);
if ($reflector->isAbstract()) {
return null;
}
// Classes that implement AvailabilityInterface
// where the algorithm is not currently available.
$iface = '\\fpoirotte\\Pssht\\AvailabilityInterface';
if ($reflector->implementsInterface($iface) && !$class::isAvailable()) {
$logging->debug(
'Skipping %(type)s algorithm "%(name)s" (not available)',
array('type' => $type, 'name' => $name)
);
return null;
}
// Classes that do not implement the proper interface.
$iface = $this->interfaces[$type];
if ($iface !== null && !$reflector->implementsInterface($iface)) {
$logging->debug(
'Skipping %(type)s algorithm "%(name)s" (invalid interface)',
array('type' => $type, 'name' => $name)
);
return null;
}
return $class;
} | [
"protected",
"function",
"getValidClass",
"(",
"$",
"type",
",",
"$",
"name",
")",
"{",
"$",
"logging",
"=",
"\\",
"Plop",
"\\",
"Plop",
"::",
"getInstance",
"(",
")",
";",
";",
"$",
"w",
"=",
"'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_1234567890\\\\'",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
"||",
"strspn",
"(",
"$",
"name",
",",
"$",
"w",
")",
"!==",
"strlen",
"(",
"$",
"name",
")",
")",
"{",
"$",
"logging",
"->",
"debug",
"(",
"'Skipping %(type)s algorithm \"%(name)s\" (invalid class name)'",
",",
"array",
"(",
"'type'",
"=>",
"$",
"type",
",",
"'name'",
"=>",
"$",
"name",
")",
")",
";",
"return",
"null",
";",
"}",
"// Non-existing classes.",
"$",
"class",
"=",
"\"\\\\fpoirotte\\\\Pssht\\\\$type$name\"",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"if",
"(",
"!",
"interface_exists",
"(",
"$",
"class",
")",
")",
"{",
"$",
"logging",
"->",
"debug",
"(",
"'Skipping %(type)s algorithm \"%(name)s\" (class does not exist)'",
",",
"array",
"(",
"'type'",
"=>",
"$",
"type",
",",
"'name'",
"=>",
"$",
"name",
")",
")",
";",
"}",
"return",
"null",
";",
"}",
"// Abstract classes.",
"$",
"reflector",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"if",
"(",
"$",
"reflector",
"->",
"isAbstract",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"// Classes that implement AvailabilityInterface",
"// where the algorithm is not currently available.",
"$",
"iface",
"=",
"'\\\\fpoirotte\\\\Pssht\\\\AvailabilityInterface'",
";",
"if",
"(",
"$",
"reflector",
"->",
"implementsInterface",
"(",
"$",
"iface",
")",
"&&",
"!",
"$",
"class",
"::",
"isAvailable",
"(",
")",
")",
"{",
"$",
"logging",
"->",
"debug",
"(",
"'Skipping %(type)s algorithm \"%(name)s\" (not available)'",
",",
"array",
"(",
"'type'",
"=>",
"$",
"type",
",",
"'name'",
"=>",
"$",
"name",
")",
")",
";",
"return",
"null",
";",
"}",
"// Classes that do not implement the proper interface.",
"$",
"iface",
"=",
"$",
"this",
"->",
"interfaces",
"[",
"$",
"type",
"]",
";",
"if",
"(",
"$",
"iface",
"!==",
"null",
"&&",
"!",
"$",
"reflector",
"->",
"implementsInterface",
"(",
"$",
"iface",
")",
")",
"{",
"$",
"logging",
"->",
"debug",
"(",
"'Skipping %(type)s algorithm \"%(name)s\" (invalid interface)'",
",",
"array",
"(",
"'type'",
"=>",
"$",
"type",
",",
"'name'",
"=>",
"$",
"name",
")",
")",
";",
"return",
"null",
";",
"}",
"return",
"$",
"class",
";",
"}"
] | Check for valid classnames.
\param string $type
Expected type of class (algorithm name).
\param string $name
Name of the class.
\retval string
Full classname (with namespace).
\retval null
No valid class found with this type and name. | [
"Check",
"for",
"valid",
"classnames",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L129-L181 |
33,275 | fpoirotte/pssht | src/Algorithms.php | Algorithms.getValidAlgorithm | protected function getValidAlgorithm($class)
{
$logging = \Plop\Plop::getInstance();;
$w = 'abcdefghijklmnopqrstuvwxyz' .
'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
'1234567890-@.';
$name = $class::getName();
if (!is_string($name) || strspn($name, $w) !== strlen($name)) {
$logging->debug(
'Skipping algorithm "%(name)s" (invalid algorithm name)',
array('name' => $name)
);
return null;
}
return $name;
} | php | protected function getValidAlgorithm($class)
{
$logging = \Plop\Plop::getInstance();;
$w = 'abcdefghijklmnopqrstuvwxyz' .
'ABCDEFGHIJKLMNOPQRSTUVWXYZ' .
'1234567890-@.';
$name = $class::getName();
if (!is_string($name) || strspn($name, $w) !== strlen($name)) {
$logging->debug(
'Skipping algorithm "%(name)s" (invalid algorithm name)',
array('name' => $name)
);
return null;
}
return $name;
} | [
"protected",
"function",
"getValidAlgorithm",
"(",
"$",
"class",
")",
"{",
"$",
"logging",
"=",
"\\",
"Plop",
"\\",
"Plop",
"::",
"getInstance",
"(",
")",
";",
";",
"$",
"w",
"=",
"'abcdefghijklmnopqrstuvwxyz'",
".",
"'ABCDEFGHIJKLMNOPQRSTUVWXYZ'",
".",
"'1234567890-@.'",
";",
"$",
"name",
"=",
"$",
"class",
"::",
"getName",
"(",
")",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
"||",
"strspn",
"(",
"$",
"name",
",",
"$",
"w",
")",
"!==",
"strlen",
"(",
"$",
"name",
")",
")",
"{",
"$",
"logging",
"->",
"debug",
"(",
"'Skipping algorithm \"%(name)s\" (invalid algorithm name)'",
",",
"array",
"(",
"'name'",
"=>",
"$",
"name",
")",
")",
";",
"return",
"null",
";",
"}",
"return",
"$",
"name",
";",
"}"
] | Check for valid algorithm names.
\param string $class
Name of the class whose algorithm name must be checked.
\retval string
The class' algorithm name.
\retval null
No valid algorithm name for the given class. | [
"Check",
"for",
"valid",
"algorithm",
"names",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L195-L210 |
33,276 | fpoirotte/pssht | src/Algorithms.php | Algorithms.register | public function register($type, $class)
{
if (is_object($class)) {
$class = get_class($class);
}
if (!is_string($class) || !class_exists($class)) {
throw new \InvalidArgumentException();
}
if (!is_string($type) || !isset($this->algos[$type])) {
throw new \InvalidArgumentException();
}
$name = $this->getValidAlgorithm($class);
if ($name === null) {
throw new \InvalidArgumentException();
}
$this->algos[$type][$name] = $class;
uksort($this->algos[$type], array('self', 'sortAlgorithms'));
return $this;
} | php | public function register($type, $class)
{
if (is_object($class)) {
$class = get_class($class);
}
if (!is_string($class) || !class_exists($class)) {
throw new \InvalidArgumentException();
}
if (!is_string($type) || !isset($this->algos[$type])) {
throw new \InvalidArgumentException();
}
$name = $this->getValidAlgorithm($class);
if ($name === null) {
throw new \InvalidArgumentException();
}
$this->algos[$type][$name] = $class;
uksort($this->algos[$type], array('self', 'sortAlgorithms'));
return $this;
} | [
"public",
"function",
"register",
"(",
"$",
"type",
",",
"$",
"class",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"class",
")",
")",
"{",
"$",
"class",
"=",
"get_class",
"(",
"$",
"class",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"class",
")",
"||",
"!",
"class_exists",
"(",
"$",
"class",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"algos",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"name",
"=",
"$",
"this",
"->",
"getValidAlgorithm",
"(",
"$",
"class",
")",
";",
"if",
"(",
"$",
"name",
"===",
"null",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"this",
"->",
"algos",
"[",
"$",
"type",
"]",
"[",
"$",
"name",
"]",
"=",
"$",
"class",
";",
"uksort",
"(",
"$",
"this",
"->",
"algos",
"[",
"$",
"type",
"]",
",",
"array",
"(",
"'self'",
",",
"'sortAlgorithms'",
")",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Register a new algorithm.
\param string $type
Type of algorithm provided by the class.
\param string|object $class
Class or object that provides the algorithm.
\retval Algorithms
Returns the singleton.
\note
A class registered with this method will overwrite
any previously registered class with the same
algorithm name. | [
"Register",
"a",
"new",
"algorithm",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L229-L248 |
33,277 | fpoirotte/pssht | src/Algorithms.php | Algorithms.unregister | public function unregister($type, $name)
{
if (!is_string($type) || !isset($this->algos[$type])) {
throw new \InvalidArgumentException();
}
if (!is_string($name)) {
throw new \InvalidArgumentException();
}
unset($this->algos[$type][$name]);
return $this;
} | php | public function unregister($type, $name)
{
if (!is_string($type) || !isset($this->algos[$type])) {
throw new \InvalidArgumentException();
}
if (!is_string($name)) {
throw new \InvalidArgumentException();
}
unset($this->algos[$type][$name]);
return $this;
} | [
"public",
"function",
"unregister",
"(",
"$",
"type",
",",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"algos",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"unset",
"(",
"$",
"this",
"->",
"algos",
"[",
"$",
"type",
"]",
"[",
"$",
"name",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Unregister an algorithm.
\param string $type
Algorithm type.
\param string $name
Name of the algorithm to unregister.
\retval Algorithms
Returns the singleton. | [
"Unregister",
"an",
"algorithm",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L262-L272 |
33,278 | fpoirotte/pssht | src/Algorithms.php | Algorithms.restore | public function restore($type, $name)
{
if (!is_string($type) || !isset($this->algos[$type])) {
throw new \InvalidArgumentException();
}
if (isset($this->savedAlgos[$type][$name])) {
$this->algos[$type][$name] = $this->savedAlgos[$type][$name];
}
return $this;
} | php | public function restore($type, $name)
{
if (!is_string($type) || !isset($this->algos[$type])) {
throw new \InvalidArgumentException();
}
if (isset($this->savedAlgos[$type][$name])) {
$this->algos[$type][$name] = $this->savedAlgos[$type][$name];
}
return $this;
} | [
"public",
"function",
"restore",
"(",
"$",
"type",
",",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"algos",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"savedAlgos",
"[",
"$",
"type",
"]",
"[",
"$",
"name",
"]",
")",
")",
"{",
"$",
"this",
"->",
"algos",
"[",
"$",
"type",
"]",
"[",
"$",
"name",
"]",
"=",
"$",
"this",
"->",
"savedAlgos",
"[",
"$",
"type",
"]",
"[",
"$",
"name",
"]",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Restore an algorithm.
Reset the class in charge of providing
a given algorithm to its initial value.
\param string $type
Algorithm type.
\param string $name
Name of the algorithm to restore.
\retval Algorithms
Returns the singleton. | [
"Restore",
"an",
"algorithm",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L289-L298 |
33,279 | fpoirotte/pssht | src/Algorithms.php | Algorithms.getAlgorithms | public function getAlgorithms($type)
{
if (!is_string($type) || !isset($this->algos[$type])) {
throw new \InvalidArgumentException();
}
return array_keys($this->algos[$type]);
} | php | public function getAlgorithms($type)
{
if (!is_string($type) || !isset($this->algos[$type])) {
throw new \InvalidArgumentException();
}
return array_keys($this->algos[$type]);
} | [
"public",
"function",
"getAlgorithms",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"algos",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"return",
"array_keys",
"(",
"$",
"this",
"->",
"algos",
"[",
"$",
"type",
"]",
")",
";",
"}"
] | Get a list of all registered algorithms
with the given type.
\param string $type
Type of algorithms to retrieve.
\retval array
A list with the names of all the algorithms
currently registered with the given type. | [
"Get",
"a",
"list",
"of",
"all",
"registered",
"algorithms",
"with",
"the",
"given",
"type",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L311-L317 |
33,280 | fpoirotte/pssht | src/Algorithms.php | Algorithms.getClasses | public function getClasses($type)
{
if (!is_string($type) || !isset($this->algos[$type])) {
throw new \InvalidArgumentException();
}
return $this->algos[$type];
} | php | public function getClasses($type)
{
if (!is_string($type) || !isset($this->algos[$type])) {
throw new \InvalidArgumentException();
}
return $this->algos[$type];
} | [
"public",
"function",
"getClasses",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"algos",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"algos",
"[",
"$",
"type",
"]",
";",
"}"
] | Get a list of all registered classes
with the given type.
\param string $type
Type of algorithms to retrieve.
\retval array
A list with the names of the classes currently
registered providing algorithms of the given type. | [
"Get",
"a",
"list",
"of",
"all",
"registered",
"classes",
"with",
"the",
"given",
"type",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L330-L336 |
33,281 | fpoirotte/pssht | src/Algorithms.php | Algorithms.getClass | public function getClass($type, $name)
{
if (!is_string($type) || !isset($this->algos[$type])) {
throw new \InvalidArgumentException();
}
if (!is_string($name)) {
throw new \InvalidArgumentException();
}
if (!isset($this->algos[$type][$name])) {
return null;
}
return $this->algos[$type][$name];
} | php | public function getClass($type, $name)
{
if (!is_string($type) || !isset($this->algos[$type])) {
throw new \InvalidArgumentException();
}
if (!is_string($name)) {
throw new \InvalidArgumentException();
}
if (!isset($this->algos[$type][$name])) {
return null;
}
return $this->algos[$type][$name];
} | [
"public",
"function",
"getClass",
"(",
"$",
"type",
",",
"$",
"name",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"type",
")",
"||",
"!",
"isset",
"(",
"$",
"this",
"->",
"algos",
"[",
"$",
"type",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"algos",
"[",
"$",
"type",
"]",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"algos",
"[",
"$",
"type",
"]",
"[",
"$",
"name",
"]",
";",
"}"
] | Get the class responsible for providing
the algorithm with the given type and name.
\param string $type
Type of algorithm to retrieve.
\param string $name
Name of the algorithm.
\retval string
Full name (with namespace) of the class
providing the given algorithm.
\retval null
No class provides an algorithm with the given
type and name. | [
"Get",
"the",
"class",
"responsible",
"for",
"providing",
"the",
"algorithm",
"with",
"the",
"given",
"type",
"and",
"name",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L356-L368 |
33,282 | fpoirotte/pssht | src/Algorithms.php | Algorithms.sortAlgorithms | public static function sortAlgorithms($a, $b)
{
static $preferences = array(
// DH (KEX)
'curve25519-sha256@libssh.org',
'ecdh-sha2-nistp256',
'ecdh-sha2-nistp384',
'ecdh-sha2-nistp521',
'diffie-hellman-group-exchange-sha256',
'diffie-hellman-group-exchange-sha1',
'diffie-hellman-group14-sha1',
'diffie-hellman-group1-sha1',
// PublicKey
'ecdsa-sha2-nistp256-cert-v01@openssh.com',
'ecdsa-sha2-nistp384-cert-v01@openssh.com',
'ecdsa-sha2-nistp521-cert-v01@openssh.com',
'ecdsa-sha2-nistp256',
'ecdsa-sha2-nistp384',
'ecdsa-sha2-nistp521',
'ssh-ed25519-cert-v01@openssh.com',
'ssh-rsa-cert-v01@openssh.com',
'ssh-dss-cert-v01@openssh.com',
'ssh-rsa-cert-v00@openssh.com',
'ssh-dss-cert-v00@openssh.com',
'ssh-ed25519',
'ssh-rsa',
'ssh-dss',
// Encryption
'aes128-ctr',
'aes192-ctr',
'aes256-ctr',
'aes128-gcm@openssh.com',
'aes256-gcm@openssh.com',
'chacha20-poly1305@openssh.com',
'arcfour256',
'arcfour128',
'aes128-cbc',
'3des-cbc',
'blowfish-cbc',
'cast128-cbc',
'aes192-cbc',
'aes256-cbc',
'arcfour',
'rijndael-cbc@lysator.liu.se',
// MAC
'umac-64-etm@openssh.com',
'umac-128-etm@openssh.com',
'hmac-sha2-256-etm@openssh.com',
'hmac-sha2-512-etm@openssh.com',
'hmac-sha1-etm@openssh.com',
'umac-64@openssh.com',
'umac-128@openssh.com',
'hmac-sha2-256',
'hmac-sha2-512',
'hmac-sha1',
'hmac-md5-etm@openssh.com',
'hmac-ripemd160-etm@openssh.com',
'hmac-sha1-96-etm@openssh.com',
'hmac-md5-96-etm@openssh.com',
'hmac-md5',
'hmac-ripemd160',
'hmac-ripemd160@openssh.com',
'hmac-sha1-96',
'hmac-md5-96',
// Compression
'none',
'zlib@openssh.com',
'zlib',
);
$iA = array_search($a, $preferences, true);
$iB = array_search($b, $preferences, true);
if ($iA === false) {
return ($iB === false ? 0 : 1);
}
if ($iB === false) {
return -1;
}
return ($iA - $iB);
} | php | public static function sortAlgorithms($a, $b)
{
static $preferences = array(
// DH (KEX)
'curve25519-sha256@libssh.org',
'ecdh-sha2-nistp256',
'ecdh-sha2-nistp384',
'ecdh-sha2-nistp521',
'diffie-hellman-group-exchange-sha256',
'diffie-hellman-group-exchange-sha1',
'diffie-hellman-group14-sha1',
'diffie-hellman-group1-sha1',
// PublicKey
'ecdsa-sha2-nistp256-cert-v01@openssh.com',
'ecdsa-sha2-nistp384-cert-v01@openssh.com',
'ecdsa-sha2-nistp521-cert-v01@openssh.com',
'ecdsa-sha2-nistp256',
'ecdsa-sha2-nistp384',
'ecdsa-sha2-nistp521',
'ssh-ed25519-cert-v01@openssh.com',
'ssh-rsa-cert-v01@openssh.com',
'ssh-dss-cert-v01@openssh.com',
'ssh-rsa-cert-v00@openssh.com',
'ssh-dss-cert-v00@openssh.com',
'ssh-ed25519',
'ssh-rsa',
'ssh-dss',
// Encryption
'aes128-ctr',
'aes192-ctr',
'aes256-ctr',
'aes128-gcm@openssh.com',
'aes256-gcm@openssh.com',
'chacha20-poly1305@openssh.com',
'arcfour256',
'arcfour128',
'aes128-cbc',
'3des-cbc',
'blowfish-cbc',
'cast128-cbc',
'aes192-cbc',
'aes256-cbc',
'arcfour',
'rijndael-cbc@lysator.liu.se',
// MAC
'umac-64-etm@openssh.com',
'umac-128-etm@openssh.com',
'hmac-sha2-256-etm@openssh.com',
'hmac-sha2-512-etm@openssh.com',
'hmac-sha1-etm@openssh.com',
'umac-64@openssh.com',
'umac-128@openssh.com',
'hmac-sha2-256',
'hmac-sha2-512',
'hmac-sha1',
'hmac-md5-etm@openssh.com',
'hmac-ripemd160-etm@openssh.com',
'hmac-sha1-96-etm@openssh.com',
'hmac-md5-96-etm@openssh.com',
'hmac-md5',
'hmac-ripemd160',
'hmac-ripemd160@openssh.com',
'hmac-sha1-96',
'hmac-md5-96',
// Compression
'none',
'zlib@openssh.com',
'zlib',
);
$iA = array_search($a, $preferences, true);
$iB = array_search($b, $preferences, true);
if ($iA === false) {
return ($iB === false ? 0 : 1);
}
if ($iB === false) {
return -1;
}
return ($iA - $iB);
} | [
"public",
"static",
"function",
"sortAlgorithms",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"static",
"$",
"preferences",
"=",
"array",
"(",
"// DH (KEX)",
"'curve25519-sha256@libssh.org'",
",",
"'ecdh-sha2-nistp256'",
",",
"'ecdh-sha2-nistp384'",
",",
"'ecdh-sha2-nistp521'",
",",
"'diffie-hellman-group-exchange-sha256'",
",",
"'diffie-hellman-group-exchange-sha1'",
",",
"'diffie-hellman-group14-sha1'",
",",
"'diffie-hellman-group1-sha1'",
",",
"// PublicKey",
"'ecdsa-sha2-nistp256-cert-v01@openssh.com'",
",",
"'ecdsa-sha2-nistp384-cert-v01@openssh.com'",
",",
"'ecdsa-sha2-nistp521-cert-v01@openssh.com'",
",",
"'ecdsa-sha2-nistp256'",
",",
"'ecdsa-sha2-nistp384'",
",",
"'ecdsa-sha2-nistp521'",
",",
"'ssh-ed25519-cert-v01@openssh.com'",
",",
"'ssh-rsa-cert-v01@openssh.com'",
",",
"'ssh-dss-cert-v01@openssh.com'",
",",
"'ssh-rsa-cert-v00@openssh.com'",
",",
"'ssh-dss-cert-v00@openssh.com'",
",",
"'ssh-ed25519'",
",",
"'ssh-rsa'",
",",
"'ssh-dss'",
",",
"// Encryption",
"'aes128-ctr'",
",",
"'aes192-ctr'",
",",
"'aes256-ctr'",
",",
"'aes128-gcm@openssh.com'",
",",
"'aes256-gcm@openssh.com'",
",",
"'chacha20-poly1305@openssh.com'",
",",
"'arcfour256'",
",",
"'arcfour128'",
",",
"'aes128-cbc'",
",",
"'3des-cbc'",
",",
"'blowfish-cbc'",
",",
"'cast128-cbc'",
",",
"'aes192-cbc'",
",",
"'aes256-cbc'",
",",
"'arcfour'",
",",
"'rijndael-cbc@lysator.liu.se'",
",",
"// MAC",
"'umac-64-etm@openssh.com'",
",",
"'umac-128-etm@openssh.com'",
",",
"'hmac-sha2-256-etm@openssh.com'",
",",
"'hmac-sha2-512-etm@openssh.com'",
",",
"'hmac-sha1-etm@openssh.com'",
",",
"'umac-64@openssh.com'",
",",
"'umac-128@openssh.com'",
",",
"'hmac-sha2-256'",
",",
"'hmac-sha2-512'",
",",
"'hmac-sha1'",
",",
"'hmac-md5-etm@openssh.com'",
",",
"'hmac-ripemd160-etm@openssh.com'",
",",
"'hmac-sha1-96-etm@openssh.com'",
",",
"'hmac-md5-96-etm@openssh.com'",
",",
"'hmac-md5'",
",",
"'hmac-ripemd160'",
",",
"'hmac-ripemd160@openssh.com'",
",",
"'hmac-sha1-96'",
",",
"'hmac-md5-96'",
",",
"// Compression",
"'none'",
",",
"'zlib@openssh.com'",
",",
"'zlib'",
",",
")",
";",
"$",
"iA",
"=",
"array_search",
"(",
"$",
"a",
",",
"$",
"preferences",
",",
"true",
")",
";",
"$",
"iB",
"=",
"array_search",
"(",
"$",
"b",
",",
"$",
"preferences",
",",
"true",
")",
";",
"if",
"(",
"$",
"iA",
"===",
"false",
")",
"{",
"return",
"(",
"$",
"iB",
"===",
"false",
"?",
"0",
":",
"1",
")",
";",
"}",
"if",
"(",
"$",
"iB",
"===",
"false",
")",
"{",
"return",
"-",
"1",
";",
"}",
"return",
"(",
"$",
"iA",
"-",
"$",
"iB",
")",
";",
"}"
] | Sort algorithms based on preferences.
\param string $a
Name of the first algorithm.
\param string $b
Name of the second algorithm.
\retval int
An integer that is less than zero if the first algorithm
should be preferred, equal to zero if both algorithms have
the same preference and greater than zero when the second
algorithm should be preferred. | [
"Sort",
"algorithms",
"based",
"on",
"preferences",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Algorithms.php#L385-L468 |
33,283 | fpoirotte/pssht | src/Handlers/DISCONNECT.php | DISCONNECT.handle | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$message = \fpoirotte\Pssht\Messages\DISCONNECT::unserialize($decoder);
throw new $message;
} | php | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$message = \fpoirotte\Pssht\Messages\DISCONNECT::unserialize($decoder);
throw new $message;
} | [
"public",
"function",
"handle",
"(",
"$",
"msgType",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Wire",
"\\",
"Decoder",
"$",
"decoder",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Transport",
"$",
"transport",
",",
"array",
"&",
"$",
"context",
")",
"{",
"$",
"message",
"=",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"DISCONNECT",
"::",
"unserialize",
"(",
"$",
"decoder",
")",
";",
"throw",
"new",
"$",
"message",
";",
"}"
] | SSH_MSG_DISCONNECT = 1 | [
"SSH_MSG_DISCONNECT",
"=",
"1"
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/DISCONNECT.php#L20-L28 |
33,284 | fpoirotte/pssht | src/Buffer.php | Buffer.getLength | protected function getLength($limit)
{
$size = strlen($this->data);
if ($limit <= 0) {
$limit += $size;
}
if ($limit > $size) {
return null;
}
$res = (string) substr($this->data, 0, $limit);
$this->data = (string) substr($this->data, $limit);
return $res;
} | php | protected function getLength($limit)
{
$size = strlen($this->data);
if ($limit <= 0) {
$limit += $size;
}
if ($limit > $size) {
return null;
}
$res = (string) substr($this->data, 0, $limit);
$this->data = (string) substr($this->data, $limit);
return $res;
} | [
"protected",
"function",
"getLength",
"(",
"$",
"limit",
")",
"{",
"$",
"size",
"=",
"strlen",
"(",
"$",
"this",
"->",
"data",
")",
";",
"if",
"(",
"$",
"limit",
"<=",
"0",
")",
"{",
"$",
"limit",
"+=",
"$",
"size",
";",
"}",
"if",
"(",
"$",
"limit",
">",
"$",
"size",
")",
"{",
"return",
"null",
";",
"}",
"$",
"res",
"=",
"(",
"string",
")",
"substr",
"(",
"$",
"this",
"->",
"data",
",",
"0",
",",
"$",
"limit",
")",
";",
"$",
"this",
"->",
"data",
"=",
"(",
"string",
")",
"substr",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"limit",
")",
";",
"return",
"$",
"res",
";",
"}"
] | Return a limited amount of data from the buffer.
\param int $limit
Number of bytes to retrieve from the buffer.
\retval string
Exactly $limit bytes of data from the buffer.
\retval null
The buffer contains less than $limit bytes
of data. | [
"Return",
"a",
"limited",
"amount",
"of",
"data",
"from",
"the",
"buffer",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Buffer.php#L63-L77 |
33,285 | fpoirotte/pssht | src/Buffer.php | Buffer.getDelimiter | protected function getDelimiter($limit)
{
if ($limit === '') {
throw new \InvalidArgumentException();
}
$pos = strpos($this->data, $limit);
if ($pos === false) {
return null;
}
$pos += strlen($limit);
$res = substr($this->data, 0, $pos);
$this->data = (string) substr($this->data, $pos);
return $res;
} | php | protected function getDelimiter($limit)
{
if ($limit === '') {
throw new \InvalidArgumentException();
}
$pos = strpos($this->data, $limit);
if ($pos === false) {
return null;
}
$pos += strlen($limit);
$res = substr($this->data, 0, $pos);
$this->data = (string) substr($this->data, $pos);
return $res;
} | [
"protected",
"function",
"getDelimiter",
"(",
"$",
"limit",
")",
"{",
"if",
"(",
"$",
"limit",
"===",
"''",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"limit",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"return",
"null",
";",
"}",
"$",
"pos",
"+=",
"strlen",
"(",
"$",
"limit",
")",
";",
"$",
"res",
"=",
"substr",
"(",
"$",
"this",
"->",
"data",
",",
"0",
",",
"$",
"pos",
")",
";",
"$",
"this",
"->",
"data",
"=",
"(",
"string",
")",
"substr",
"(",
"$",
"this",
"->",
"data",
",",
"$",
"pos",
")",
";",
"return",
"$",
"res",
";",
"}"
] | Return a delimited string from the buffer.
\param string $limit
Delimiter.
\retval string
All the data at the beginning of the buffer
up to (and including) the delimiter.
\retval null
The given delimiter does not appear
in the buffer. | [
"Return",
"a",
"delimited",
"string",
"from",
"the",
"buffer",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Buffer.php#L93-L108 |
33,286 | fpoirotte/pssht | src/Buffer.php | Buffer.get | public function get($limit)
{
if (is_int($limit)) {
return $this->getLength($limit);
}
if (is_string($limit)) {
return $this->getDelimiter($limit);
}
throw new \InvalidArgumentException();
} | php | public function get($limit)
{
if (is_int($limit)) {
return $this->getLength($limit);
}
if (is_string($limit)) {
return $this->getDelimiter($limit);
}
throw new \InvalidArgumentException();
} | [
"public",
"function",
"get",
"(",
"$",
"limit",
")",
"{",
"if",
"(",
"is_int",
"(",
"$",
"limit",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getLength",
"(",
"$",
"limit",
")",
";",
"}",
"if",
"(",
"is_string",
"(",
"$",
"limit",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getDelimiter",
"(",
"$",
"limit",
")",
";",
"}",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}"
] | Get limited data from the beginning of the buffer.
\param int|string $limit
Either the number of bytes to retrieve
from the buffer, or a string delimiter
to look for.
\retval string
The data at the beginning of the buffer, until the given
limit is reached. For string delimiters, the delimiter
is part of the result. | [
"Get",
"limited",
"data",
"from",
"the",
"beginning",
"of",
"the",
"buffer",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Buffer.php#L123-L134 |
33,287 | fpoirotte/pssht | src/Buffer.php | Buffer.unget | public function unget($data)
{
if (!is_string($data)) {
throw new \InvalidArgumentException();
}
$this->data = $data . $this->data;
return $this;
} | php | public function unget($data)
{
if (!is_string($data)) {
throw new \InvalidArgumentException();
}
$this->data = $data . $this->data;
return $this;
} | [
"public",
"function",
"unget",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"data",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"this",
"->",
"data",
"=",
"$",
"data",
".",
"$",
"this",
"->",
"data",
";",
"return",
"$",
"this",
";",
"}"
] | Prepend data to the beginning of the buffer.
\param string $data
Data to prepend.
\retval Buffer
Returns this buffer. | [
"Prepend",
"data",
"to",
"the",
"beginning",
"of",
"the",
"buffer",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Buffer.php#L145-L153 |
33,288 | fpoirotte/pssht | src/Handlers/CHANNEL/CLOSE.php | CLOSE.handle | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$message = \fpoirotte\Pssht\Messages\CHANNEL\CLOSE::unserialize($decoder);
$channel = $message->getChannel();
$response = new \fpoirotte\Pssht\Messages\CHANNEL\CLOSE(
$this->connection->getChannel($channel)
);
$transport->writeMessage($response);
$this->connection->freeChannel($channel);
return true;
} | php | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$message = \fpoirotte\Pssht\Messages\CHANNEL\CLOSE::unserialize($decoder);
$channel = $message->getChannel();
$response = new \fpoirotte\Pssht\Messages\CHANNEL\CLOSE(
$this->connection->getChannel($channel)
);
$transport->writeMessage($response);
$this->connection->freeChannel($channel);
return true;
} | [
"public",
"function",
"handle",
"(",
"$",
"msgType",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Wire",
"\\",
"Decoder",
"$",
"decoder",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Transport",
"$",
"transport",
",",
"array",
"&",
"$",
"context",
")",
"{",
"$",
"message",
"=",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"CHANNEL",
"\\",
"CLOSE",
"::",
"unserialize",
"(",
"$",
"decoder",
")",
";",
"$",
"channel",
"=",
"$",
"message",
"->",
"getChannel",
"(",
")",
";",
"$",
"response",
"=",
"new",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"CHANNEL",
"\\",
"CLOSE",
"(",
"$",
"this",
"->",
"connection",
"->",
"getChannel",
"(",
"$",
"channel",
")",
")",
";",
"$",
"transport",
"->",
"writeMessage",
"(",
"$",
"response",
")",
";",
"$",
"this",
"->",
"connection",
"->",
"freeChannel",
"(",
"$",
"channel",
")",
";",
"return",
"true",
";",
"}"
] | SSH_MSG_CHANNEL_CLOSE = 97 | [
"SSH_MSG_CHANNEL_CLOSE",
"=",
"97"
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/CHANNEL/CLOSE.php#L20-L34 |
33,289 | fpoirotte/pssht | src/KeyStoreLoader/File.php | File.load | public function load($user, $file)
{
if (!is_string($user)) {
throw new \InvalidArgumentException();
}
if (!is_string($file)) {
throw new \InvalidArgumentException();
}
$algos = \fpoirotte\Pssht\Algorithms::factory();
$types = array(
'ssh-dss',
'ssh-rsa',
# 'ecdsa-sha2-nistp256',
# 'ecdsa-sha2-nistp384',
# 'ecdsa-sha2-nistp521',
);
foreach (file($file) as $line) {
$fields = explode(' ', preg_replace('/\\s+/', ' ', trim($line)));
$max = count($fields);
for ($i = 0; $i < $max; $i++) {
if (in_array($fields[$i], $types, true)) {
$cls = $algos->getClass('PublicKey', $fields[$i]);
$this->store->add($user, $cls::loadPublic($fields[$i+1]));
break;
}
}
}
return $this;
} | php | public function load($user, $file)
{
if (!is_string($user)) {
throw new \InvalidArgumentException();
}
if (!is_string($file)) {
throw new \InvalidArgumentException();
}
$algos = \fpoirotte\Pssht\Algorithms::factory();
$types = array(
'ssh-dss',
'ssh-rsa',
# 'ecdsa-sha2-nistp256',
# 'ecdsa-sha2-nistp384',
# 'ecdsa-sha2-nistp521',
);
foreach (file($file) as $line) {
$fields = explode(' ', preg_replace('/\\s+/', ' ', trim($line)));
$max = count($fields);
for ($i = 0; $i < $max; $i++) {
if (in_array($fields[$i], $types, true)) {
$cls = $algos->getClass('PublicKey', $fields[$i]);
$this->store->add($user, $cls::loadPublic($fields[$i+1]));
break;
}
}
}
return $this;
} | [
"public",
"function",
"load",
"(",
"$",
"user",
",",
"$",
"file",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"user",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_string",
"(",
"$",
"file",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"algos",
"=",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Algorithms",
"::",
"factory",
"(",
")",
";",
"$",
"types",
"=",
"array",
"(",
"'ssh-dss'",
",",
"'ssh-rsa'",
",",
"# 'ecdsa-sha2-nistp256',",
"# 'ecdsa-sha2-nistp384',",
"# 'ecdsa-sha2-nistp521',",
")",
";",
"foreach",
"(",
"file",
"(",
"$",
"file",
")",
"as",
"$",
"line",
")",
"{",
"$",
"fields",
"=",
"explode",
"(",
"' '",
",",
"preg_replace",
"(",
"'/\\\\s+/'",
",",
"' '",
",",
"trim",
"(",
"$",
"line",
")",
")",
")",
";",
"$",
"max",
"=",
"count",
"(",
"$",
"fields",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"max",
";",
"$",
"i",
"++",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"fields",
"[",
"$",
"i",
"]",
",",
"$",
"types",
",",
"true",
")",
")",
"{",
"$",
"cls",
"=",
"$",
"algos",
"->",
"getClass",
"(",
"'PublicKey'",
",",
"$",
"fields",
"[",
"$",
"i",
"]",
")",
";",
"$",
"this",
"->",
"store",
"->",
"add",
"(",
"$",
"user",
",",
"$",
"cls",
"::",
"loadPublic",
"(",
"$",
"fields",
"[",
"$",
"i",
"+",
"1",
"]",
")",
")",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Load the keys in the given file as if they belonged
to the specified user.
\param string $user
User the keys belong to.
\param string $file
File containing the keys to load.
It should follow the format of OpenSSH's
authorized_keys file.
\retval File
Returns this loader. | [
"Load",
"the",
"keys",
"in",
"the",
"given",
"file",
"as",
"if",
"they",
"belonged",
"to",
"the",
"specified",
"user",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/KeyStoreLoader/File.php#L54-L86 |
33,290 | fpoirotte/pssht | src/KeyStoreLoader/File.php | File.loadBulk | public function loadBulk(array $bulk)
{
foreach ($bulk as $user => $files) {
if (!is_string($user)) {
throw new \InvalidArgumentException();
}
if (!is_array($files) && !is_string($files)) {
throw new \InvalidArgumentException();
}
$files = (array) $files;
foreach ($files as $file) {
$this->load($user, $file);
}
}
return $this;
} | php | public function loadBulk(array $bulk)
{
foreach ($bulk as $user => $files) {
if (!is_string($user)) {
throw new \InvalidArgumentException();
}
if (!is_array($files) && !is_string($files)) {
throw new \InvalidArgumentException();
}
$files = (array) $files;
foreach ($files as $file) {
$this->load($user, $file);
}
}
return $this;
} | [
"public",
"function",
"loadBulk",
"(",
"array",
"$",
"bulk",
")",
"{",
"foreach",
"(",
"$",
"bulk",
"as",
"$",
"user",
"=>",
"$",
"files",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"user",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"files",
")",
"&&",
"!",
"is_string",
"(",
"$",
"files",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"$",
"files",
"=",
"(",
"array",
")",
"$",
"files",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"load",
"(",
"$",
"user",
",",
"$",
"file",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Bulk-load keys.
\param array $bulk
An array with information on the keys to load.
The keys in the array indicate users while
the values contain (an array of) files containing
the keys to load.
\retval File
Returns this loader. | [
"Bulk",
"-",
"load",
"keys",
"."
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/KeyStoreLoader/File.php#L100-L117 |
33,291 | fpoirotte/pssht | src/Handlers/IGNORE.php | IGNORE.handle | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
return true;
} | php | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
return true;
} | [
"public",
"function",
"handle",
"(",
"$",
"msgType",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Wire",
"\\",
"Decoder",
"$",
"decoder",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Transport",
"$",
"transport",
",",
"array",
"&",
"$",
"context",
")",
"{",
"return",
"true",
";",
"}"
] | SSH_MSG_IGNORE = 2 | [
"SSH_MSG_IGNORE",
"=",
"2"
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/IGNORE.php#L20-L27 |
33,292 | fpoirotte/pssht | src/Handlers/CHANNEL/OPEN.php | OPEN.handle | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$message = \fpoirotte\Pssht\Messages\CHANNEL\OPEN::unserialize($decoder);
$recipientChannel = $message->getChannel();
if ($message->getType() === 'session') {
$response = new \fpoirotte\Pssht\Messages\CHANNEL\OPEN\CONFIRMATION(
$recipientChannel,
$this->connection->allocateChannel($message),
0x200000,
0x800000
);
} else {
$response = new \fpoirotte\Pssht\Messages\CHANNEL\OPEN\FAILURE(
$recipientChannel,
\fpoirotte\Pssht\Messages\CHANNEL\OPEN\FAILURE::SSH_OPEN_UNKNOWN_CHANNEL_TYPE,
'No such channel type'
);
}
$transport->writeMessage($response);
return true;
} | php | public function handle(
$msgType,
\fpoirotte\Pssht\Wire\Decoder $decoder,
\fpoirotte\Pssht\Transport $transport,
array &$context
) {
$message = \fpoirotte\Pssht\Messages\CHANNEL\OPEN::unserialize($decoder);
$recipientChannel = $message->getChannel();
if ($message->getType() === 'session') {
$response = new \fpoirotte\Pssht\Messages\CHANNEL\OPEN\CONFIRMATION(
$recipientChannel,
$this->connection->allocateChannel($message),
0x200000,
0x800000
);
} else {
$response = new \fpoirotte\Pssht\Messages\CHANNEL\OPEN\FAILURE(
$recipientChannel,
\fpoirotte\Pssht\Messages\CHANNEL\OPEN\FAILURE::SSH_OPEN_UNKNOWN_CHANNEL_TYPE,
'No such channel type'
);
}
$transport->writeMessage($response);
return true;
} | [
"public",
"function",
"handle",
"(",
"$",
"msgType",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Wire",
"\\",
"Decoder",
"$",
"decoder",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Transport",
"$",
"transport",
",",
"array",
"&",
"$",
"context",
")",
"{",
"$",
"message",
"=",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"CHANNEL",
"\\",
"OPEN",
"::",
"unserialize",
"(",
"$",
"decoder",
")",
";",
"$",
"recipientChannel",
"=",
"$",
"message",
"->",
"getChannel",
"(",
")",
";",
"if",
"(",
"$",
"message",
"->",
"getType",
"(",
")",
"===",
"'session'",
")",
"{",
"$",
"response",
"=",
"new",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"CHANNEL",
"\\",
"OPEN",
"\\",
"CONFIRMATION",
"(",
"$",
"recipientChannel",
",",
"$",
"this",
"->",
"connection",
"->",
"allocateChannel",
"(",
"$",
"message",
")",
",",
"0x200000",
",",
"0x800000",
")",
";",
"}",
"else",
"{",
"$",
"response",
"=",
"new",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"CHANNEL",
"\\",
"OPEN",
"\\",
"FAILURE",
"(",
"$",
"recipientChannel",
",",
"\\",
"fpoirotte",
"\\",
"Pssht",
"\\",
"Messages",
"\\",
"CHANNEL",
"\\",
"OPEN",
"\\",
"FAILURE",
"::",
"SSH_OPEN_UNKNOWN_CHANNEL_TYPE",
",",
"'No such channel type'",
")",
";",
"}",
"$",
"transport",
"->",
"writeMessage",
"(",
"$",
"response",
")",
";",
"return",
"true",
";",
"}"
] | SSH_MSG_CHANNEL_OPEN = 90 | [
"SSH_MSG_CHANNEL_OPEN",
"=",
"90"
] | 26bbbc18956144e355317f1e2e468be24bbb3e35 | https://github.com/fpoirotte/pssht/blob/26bbbc18956144e355317f1e2e468be24bbb3e35/src/Handlers/CHANNEL/OPEN.php#L20-L45 |
33,293 | go1com/flood | Flood.php | Flood.isAllowed | public function isAllowed($name, $threshold, $window = 3600, $identifier = null)
{
return $threshold > $this->count($name, $window, $identifier);
} | php | public function isAllowed($name, $threshold, $window = 3600, $identifier = null)
{
return $threshold > $this->count($name, $window, $identifier);
} | [
"public",
"function",
"isAllowed",
"(",
"$",
"name",
",",
"$",
"threshold",
",",
"$",
"window",
"=",
"3600",
",",
"$",
"identifier",
"=",
"null",
")",
"{",
"return",
"$",
"threshold",
">",
"$",
"this",
"->",
"count",
"(",
"$",
"name",
",",
"$",
"window",
",",
"$",
"identifier",
")",
";",
"}"
] | Checks whether a user is allowed to proceed with the specified event.
Events can have thresholds saying that each user can only do that event
a certain number of times in a time window. This function verifies that the
current user has not exceeded this threshold.
@param string $name The unique name of the event.
@param int $threshold The maximum number of times each user can do this event per time window.
@param int $window Number of seconds in the time window for this event (default is 3600 seconds/1 hour).
@param $identifier Unique identifier of the current user. Defaults to their IP address.
@return bool | [
"Checks",
"whether",
"a",
"user",
"is",
"allowed",
"to",
"proceed",
"with",
"the",
"specified",
"event",
"."
] | 2ac77219479f010b0290265ad5d0c02a4b34930a | https://github.com/go1com/flood/blob/2ac77219479f010b0290265ad5d0c02a4b34930a/Flood.php#L67-L70 |
33,294 | go1com/flood | Flood.php | Flood.register | public function register($name, $window = 3600, $identifier = null)
{
$this
->connection
->insert($this->tableName, [
'event' => $name,
'identifier' => $identifier ?: $this->ip(),
'timestamp' => time(),
'expiration' => time() + $window,
]);
} | php | public function register($name, $window = 3600, $identifier = null)
{
$this
->connection
->insert($this->tableName, [
'event' => $name,
'identifier' => $identifier ?: $this->ip(),
'timestamp' => time(),
'expiration' => time() + $window,
]);
} | [
"public",
"function",
"register",
"(",
"$",
"name",
",",
"$",
"window",
"=",
"3600",
",",
"$",
"identifier",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"insert",
"(",
"$",
"this",
"->",
"tableName",
",",
"[",
"'event'",
"=>",
"$",
"name",
",",
"'identifier'",
"=>",
"$",
"identifier",
"?",
":",
"$",
"this",
"->",
"ip",
"(",
")",
",",
"'timestamp'",
"=>",
"time",
"(",
")",
",",
"'expiration'",
"=>",
"time",
"(",
")",
"+",
"$",
"window",
",",
"]",
")",
";",
"}"
] | Registers an event for the current visitor to the flood control mechanism.
@param string $name The name of an event.
@param int $window Time to live in seconds.
@param int $identifier Optional identifier (defaults to the current user's IP address). | [
"Registers",
"an",
"event",
"for",
"the",
"current",
"visitor",
"to",
"the",
"flood",
"control",
"mechanism",
"."
] | 2ac77219479f010b0290265ad5d0c02a4b34930a | https://github.com/go1com/flood/blob/2ac77219479f010b0290265ad5d0c02a4b34930a/Flood.php#L91-L101 |
33,295 | flash-global/entities | src/AbstractEntity.php | AbstractEntity.mapFrom | public function mapFrom($field)
{
return isset($this->mapping[$field]) ? $this->mapping[$field] : $field;
} | php | public function mapFrom($field)
{
return isset($this->mapping[$field]) ? $this->mapping[$field] : $field;
} | [
"public",
"function",
"mapFrom",
"(",
"$",
"field",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"mapping",
"[",
"$",
"field",
"]",
")",
"?",
"$",
"this",
"->",
"mapping",
"[",
"$",
"field",
"]",
":",
"$",
"field",
";",
"}"
] | Map DB field name to property name
@param $field
@return mixed | [
"Map",
"DB",
"field",
"name",
"to",
"property",
"name"
] | 7469b60bb0bb5b63491a78872bf9c3f38d4c8e75 | https://github.com/flash-global/entities/blob/7469b60bb0bb5b63491a78872bf9c3f38d4c8e75/src/AbstractEntity.php#L127-L130 |
33,296 | flash-global/entities | src/AbstractEntity.php | AbstractEntity.mapTo | public function mapTo($property)
{
if (!$this->mappingTo) {
$this->mappingTo = array_flip($this->mapping);
}
return isset($this->mappingTo[$property]) ? $this->mappingTo[$property] : $property;
} | php | public function mapTo($property)
{
if (!$this->mappingTo) {
$this->mappingTo = array_flip($this->mapping);
}
return isset($this->mappingTo[$property]) ? $this->mappingTo[$property] : $property;
} | [
"public",
"function",
"mapTo",
"(",
"$",
"property",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"mappingTo",
")",
"{",
"$",
"this",
"->",
"mappingTo",
"=",
"array_flip",
"(",
"$",
"this",
"->",
"mapping",
")",
";",
"}",
"return",
"isset",
"(",
"$",
"this",
"->",
"mappingTo",
"[",
"$",
"property",
"]",
")",
"?",
"$",
"this",
"->",
"mappingTo",
"[",
"$",
"property",
"]",
":",
"$",
"property",
";",
"}"
] | Map property name to DB field name
@param $property
@return mixed | [
"Map",
"property",
"name",
"to",
"DB",
"field",
"name"
] | 7469b60bb0bb5b63491a78872bf9c3f38d4c8e75 | https://github.com/flash-global/entities/blob/7469b60bb0bb5b63491a78872bf9c3f38d4c8e75/src/AbstractEntity.php#L153-L160 |
33,297 | flash-global/entities | src/Extractor/JsonApiExtractor.php | JsonApiExtractor.extract | public function extract(array $json)
{
if (!$this->hasData($json)) {
return null;
}
if (!$this->isCollection($json)) {
return $this->extractOne($json, $json['data']);
} else {
$data = $this->extractMultiple($json);
if ($this->isPaginated($json)) {
return (new PaginatedEntitySet($data))
->setPerPage($json['meta']['pagination']['per_page'])
->setCurrentPage($json['meta']['pagination']['current_page'])
->setTotal($json['meta']['pagination']['total']);
}
return new EntitySet($data);
}
} | php | public function extract(array $json)
{
if (!$this->hasData($json)) {
return null;
}
if (!$this->isCollection($json)) {
return $this->extractOne($json, $json['data']);
} else {
$data = $this->extractMultiple($json);
if ($this->isPaginated($json)) {
return (new PaginatedEntitySet($data))
->setPerPage($json['meta']['pagination']['per_page'])
->setCurrentPage($json['meta']['pagination']['current_page'])
->setTotal($json['meta']['pagination']['total']);
}
return new EntitySet($data);
}
} | [
"public",
"function",
"extract",
"(",
"array",
"$",
"json",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasData",
"(",
"$",
"json",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"isCollection",
"(",
"$",
"json",
")",
")",
"{",
"return",
"$",
"this",
"->",
"extractOne",
"(",
"$",
"json",
",",
"$",
"json",
"[",
"'data'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"data",
"=",
"$",
"this",
"->",
"extractMultiple",
"(",
"$",
"json",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isPaginated",
"(",
"$",
"json",
")",
")",
"{",
"return",
"(",
"new",
"PaginatedEntitySet",
"(",
"$",
"data",
")",
")",
"->",
"setPerPage",
"(",
"$",
"json",
"[",
"'meta'",
"]",
"[",
"'pagination'",
"]",
"[",
"'per_page'",
"]",
")",
"->",
"setCurrentPage",
"(",
"$",
"json",
"[",
"'meta'",
"]",
"[",
"'pagination'",
"]",
"[",
"'current_page'",
"]",
")",
"->",
"setTotal",
"(",
"$",
"json",
"[",
"'meta'",
"]",
"[",
"'pagination'",
"]",
"[",
"'total'",
"]",
")",
";",
"}",
"return",
"new",
"EntitySet",
"(",
"$",
"data",
")",
";",
"}",
"}"
] | Extract entities form an JSON API data
@param array $json
@return EntityInterface|EntitySet|PaginatedEntitySet|null | [
"Extract",
"entities",
"form",
"an",
"JSON",
"API",
"data"
] | 7469b60bb0bb5b63491a78872bf9c3f38d4c8e75 | https://github.com/flash-global/entities/blob/7469b60bb0bb5b63491a78872bf9c3f38d4c8e75/src/Extractor/JsonApiExtractor.php#L23-L40 |
33,298 | flash-global/entities | src/Extractor/JsonApiExtractor.php | JsonApiExtractor.extractOne | protected function extractOne(array $json, array $data)
{
if ($this->dataHasType($data)) {
return $this->createInstanceWithRelations($json, $data);
}
throw new JsonApiExtractException('No data type provided');
} | php | protected function extractOne(array $json, array $data)
{
if ($this->dataHasType($data)) {
return $this->createInstanceWithRelations($json, $data);
}
throw new JsonApiExtractException('No data type provided');
} | [
"protected",
"function",
"extractOne",
"(",
"array",
"$",
"json",
",",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"dataHasType",
"(",
"$",
"data",
")",
")",
"{",
"return",
"$",
"this",
"->",
"createInstanceWithRelations",
"(",
"$",
"json",
",",
"$",
"data",
")",
";",
"}",
"throw",
"new",
"JsonApiExtractException",
"(",
"'No data type provided'",
")",
";",
"}"
] | Extract an entity from data
@param array $json
@param array $data
@return array|EntityInterface
@throws JsonApiExtractException | [
"Extract",
"an",
"entity",
"from",
"data"
] | 7469b60bb0bb5b63491a78872bf9c3f38d4c8e75 | https://github.com/flash-global/entities/blob/7469b60bb0bb5b63491a78872bf9c3f38d4c8e75/src/Extractor/JsonApiExtractor.php#L75-L81 |
33,299 | flash-global/entities | src/Extractor/JsonApiExtractor.php | JsonApiExtractor.isPaginated | protected function isPaginated(array $json)
{
if (!array_key_exists('links', $json) || !array_key_exists('meta', $json)) {
return false;
}
if (is_array($json['links'])
&& array_key_exists('self', $json['links'])
&& array_key_exists('first', $json['links'])
&& array_key_exists('last', $json['links'])
&& isset($json['meta']['pagination'])
&& is_array($json['meta']['pagination'])
&& array_key_exists('total', $json['meta']['pagination'])
&& array_key_exists('count', $json['meta']['pagination'])
&& array_key_exists('per_page', $json['meta']['pagination'])
&& array_key_exists('current_page', $json['meta']['pagination'])
&& array_key_exists('total_pages', $json['meta']['pagination'])
) {
return true;
}
return false;
} | php | protected function isPaginated(array $json)
{
if (!array_key_exists('links', $json) || !array_key_exists('meta', $json)) {
return false;
}
if (is_array($json['links'])
&& array_key_exists('self', $json['links'])
&& array_key_exists('first', $json['links'])
&& array_key_exists('last', $json['links'])
&& isset($json['meta']['pagination'])
&& is_array($json['meta']['pagination'])
&& array_key_exists('total', $json['meta']['pagination'])
&& array_key_exists('count', $json['meta']['pagination'])
&& array_key_exists('per_page', $json['meta']['pagination'])
&& array_key_exists('current_page', $json['meta']['pagination'])
&& array_key_exists('total_pages', $json['meta']['pagination'])
) {
return true;
}
return false;
} | [
"protected",
"function",
"isPaginated",
"(",
"array",
"$",
"json",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'links'",
",",
"$",
"json",
")",
"||",
"!",
"array_key_exists",
"(",
"'meta'",
",",
"$",
"json",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"json",
"[",
"'links'",
"]",
")",
"&&",
"array_key_exists",
"(",
"'self'",
",",
"$",
"json",
"[",
"'links'",
"]",
")",
"&&",
"array_key_exists",
"(",
"'first'",
",",
"$",
"json",
"[",
"'links'",
"]",
")",
"&&",
"array_key_exists",
"(",
"'last'",
",",
"$",
"json",
"[",
"'links'",
"]",
")",
"&&",
"isset",
"(",
"$",
"json",
"[",
"'meta'",
"]",
"[",
"'pagination'",
"]",
")",
"&&",
"is_array",
"(",
"$",
"json",
"[",
"'meta'",
"]",
"[",
"'pagination'",
"]",
")",
"&&",
"array_key_exists",
"(",
"'total'",
",",
"$",
"json",
"[",
"'meta'",
"]",
"[",
"'pagination'",
"]",
")",
"&&",
"array_key_exists",
"(",
"'count'",
",",
"$",
"json",
"[",
"'meta'",
"]",
"[",
"'pagination'",
"]",
")",
"&&",
"array_key_exists",
"(",
"'per_page'",
",",
"$",
"json",
"[",
"'meta'",
"]",
"[",
"'pagination'",
"]",
")",
"&&",
"array_key_exists",
"(",
"'current_page'",
",",
"$",
"json",
"[",
"'meta'",
"]",
"[",
"'pagination'",
"]",
")",
"&&",
"array_key_exists",
"(",
"'total_pages'",
",",
"$",
"json",
"[",
"'meta'",
"]",
"[",
"'pagination'",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Test if JSON API data provided is paginated
@param array $json
@return bool | [
"Test",
"if",
"JSON",
"API",
"data",
"provided",
"is",
"paginated"
] | 7469b60bb0bb5b63491a78872bf9c3f38d4c8e75 | https://github.com/flash-global/entities/blob/7469b60bb0bb5b63491a78872bf9c3f38d4c8e75/src/Extractor/JsonApiExtractor.php#L202-L222 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.