repository_name stringlengths 5 67 | func_path_in_repository stringlengths 4 234 | func_name stringlengths 0 314 | whole_func_string stringlengths 52 3.87M | language stringclasses 6 values | func_code_string stringlengths 52 3.87M | func_code_tokens listlengths 15 672k | func_documentation_string stringlengths 1 47.2k | func_documentation_tokens listlengths 1 3.92k | split_name stringclasses 1 value | func_code_url stringlengths 85 339 |
|---|---|---|---|---|---|---|---|---|---|---|
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableDiff.php | TableDiff.parseTableStructure | protected function parseTableStructure($text)
{
$dom = $this->createDocumentWithHtml($text);
$tableNode = $dom->getElementsByTagName('table')->item(0);
$table = new Table($tableNode);
$this->parseTable($table);
return $table;
} | php | protected function parseTableStructure($text)
{
$dom = $this->createDocumentWithHtml($text);
$tableNode = $dom->getElementsByTagName('table')->item(0);
$table = new Table($tableNode);
$this->parseTable($table);
return $table;
} | [
"protected",
"function",
"parseTableStructure",
"(",
"$",
"text",
")",
"{",
"$",
"dom",
"=",
"$",
"this",
"->",
"createDocumentWithHtml",
"(",
"$",
"text",
")",
";",
"$",
"tableNode",
"=",
"$",
"dom",
"->",
"getElementsByTagName",
"(",
"'table'",
")",
"->"... | @param string $text
@return Table | [
"@param",
"string",
"$text"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableDiff.php#L644-L655 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableDiff.php | TableDiff.getInnerHtml | protected function getInnerHtml($node)
{
$innerHtml = '';
$children = $node->childNodes;
foreach ($children as $child) {
$innerHtml .= $this->htmlFromNode($child);
}
return $innerHtml;
} | php | protected function getInnerHtml($node)
{
$innerHtml = '';
$children = $node->childNodes;
foreach ($children as $child) {
$innerHtml .= $this->htmlFromNode($child);
}
return $innerHtml;
} | [
"protected",
"function",
"getInnerHtml",
"(",
"$",
"node",
")",
"{",
"$",
"innerHtml",
"=",
"''",
";",
"$",
"children",
"=",
"$",
"node",
"->",
"childNodes",
";",
"foreach",
"(",
"$",
"children",
"as",
"$",
"child",
")",
"{",
"$",
"innerHtml",
".=",
... | @param \DOMNode $node
@return string | [
"@param",
"\\",
"DOMNode",
"$node"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableDiff.php#L703-L713 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableDiff.php | TableDiff.htmlFromNode | protected function htmlFromNode($node)
{
$domDocument = new \DOMDocument();
$newNode = $domDocument->importNode($node, true);
$domDocument->appendChild($newNode);
return $domDocument->saveHTML();
} | php | protected function htmlFromNode($node)
{
$domDocument = new \DOMDocument();
$newNode = $domDocument->importNode($node, true);
$domDocument->appendChild($newNode);
return $domDocument->saveHTML();
} | [
"protected",
"function",
"htmlFromNode",
"(",
"$",
"node",
")",
"{",
"$",
"domDocument",
"=",
"new",
"\\",
"DOMDocument",
"(",
")",
";",
"$",
"newNode",
"=",
"$",
"domDocument",
"->",
"importNode",
"(",
"$",
"node",
",",
"true",
")",
";",
"$",
"domDocu... | @param \DOMNode $node
@return string | [
"@param",
"\\",
"DOMNode",
"$node"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableDiff.php#L720-L727 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableDiff.php | TableDiff.diffCellsAndIncrementCounters | protected function diffCellsAndIncrementCounters(
$oldCell,
$newCell,
&$cellsWithMultipleRows,
$diffRow,
DiffRowPosition $position,
$usingExtraRow = false
) {
$diffCell = $this->diffCells($oldCell, $newCell, $usingExtraRow);
// Store cell in appliedRowSpans if spans multiple rows
if ($diffCell->getAttribute('rowspan') > 1) {
$cellsWithMultipleRows[$diffCell->getAttribute('rowspan')][] = $diffCell;
}
$diffRow->appendChild($diffCell);
if ($newCell !== null) {
$position->incrementIndexInNew();
$position->incrementColumnInNew($newCell->getColspan());
}
if ($oldCell !== null) {
$position->incrementIndexInOld();
$position->incrementColumnInOld($oldCell->getColspan());
}
return $diffCell;
} | php | protected function diffCellsAndIncrementCounters(
$oldCell,
$newCell,
&$cellsWithMultipleRows,
$diffRow,
DiffRowPosition $position,
$usingExtraRow = false
) {
$diffCell = $this->diffCells($oldCell, $newCell, $usingExtraRow);
// Store cell in appliedRowSpans if spans multiple rows
if ($diffCell->getAttribute('rowspan') > 1) {
$cellsWithMultipleRows[$diffCell->getAttribute('rowspan')][] = $diffCell;
}
$diffRow->appendChild($diffCell);
if ($newCell !== null) {
$position->incrementIndexInNew();
$position->incrementColumnInNew($newCell->getColspan());
}
if ($oldCell !== null) {
$position->incrementIndexInOld();
$position->incrementColumnInOld($oldCell->getColspan());
}
return $diffCell;
} | [
"protected",
"function",
"diffCellsAndIncrementCounters",
"(",
"$",
"oldCell",
",",
"$",
"newCell",
",",
"&",
"$",
"cellsWithMultipleRows",
",",
"$",
"diffRow",
",",
"DiffRowPosition",
"$",
"position",
",",
"$",
"usingExtraRow",
"=",
"false",
")",
"{",
"$",
"d... | @param null|TableCell $oldCell
@param null|TableCell $newCell
@param array $cellsWithMultipleRows
@param \DOMElement $diffRow
@param DiffRowPosition $position
@param bool $usingExtraRow
@return \DOMElement | [
"@param",
"null|TableCell",
"$oldCell",
"@param",
"null|TableCell",
"$newCell",
"@param",
"array",
"$cellsWithMultipleRows",
"@param",
"\\",
"DOMElement",
"$diffRow",
"@param",
"DiffRowPosition",
"$position",
"@param",
"bool",
"$usingExtraRow"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableDiff.php#L811-L837 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/TableDiff.php | TableDiff.getMatchPercentage | protected function getMatchPercentage(TableRow $oldRow, TableRow $newRow, $oldIndex, $newIndex)
{
$firstCellWeight = 1.5;
$indexDeltaWeight = 0.25 * (abs($oldIndex - $newIndex));
$thresholdCount = 0;
$minCells = min(count($newRow->getCells()), count($oldRow->getCells()));
$totalCount = ($minCells + $firstCellWeight + $indexDeltaWeight) * 100;
foreach ($newRow->getCells() as $newIndex => $newCell) {
$oldCell = $oldRow->getCell($newIndex);
if ($oldCell) {
$percentage = null;
similar_text($oldCell->getInnerHtml(), $newCell->getInnerHtml(), $percentage);
if ($percentage > ($this->config->getMatchThreshold() * 0.50)) {
$increment = $percentage;
if ($newIndex === 0 && $percentage > 95) {
$increment = $increment * $firstCellWeight;
}
$thresholdCount += $increment;
}
}
}
return ($totalCount > 0) ? ($thresholdCount / $totalCount) : 0;
} | php | protected function getMatchPercentage(TableRow $oldRow, TableRow $newRow, $oldIndex, $newIndex)
{
$firstCellWeight = 1.5;
$indexDeltaWeight = 0.25 * (abs($oldIndex - $newIndex));
$thresholdCount = 0;
$minCells = min(count($newRow->getCells()), count($oldRow->getCells()));
$totalCount = ($minCells + $firstCellWeight + $indexDeltaWeight) * 100;
foreach ($newRow->getCells() as $newIndex => $newCell) {
$oldCell = $oldRow->getCell($newIndex);
if ($oldCell) {
$percentage = null;
similar_text($oldCell->getInnerHtml(), $newCell->getInnerHtml(), $percentage);
if ($percentage > ($this->config->getMatchThreshold() * 0.50)) {
$increment = $percentage;
if ($newIndex === 0 && $percentage > 95) {
$increment = $increment * $firstCellWeight;
}
$thresholdCount += $increment;
}
}
}
return ($totalCount > 0) ? ($thresholdCount / $totalCount) : 0;
} | [
"protected",
"function",
"getMatchPercentage",
"(",
"TableRow",
"$",
"oldRow",
",",
"TableRow",
"$",
"newRow",
",",
"$",
"oldIndex",
",",
"$",
"newIndex",
")",
"{",
"$",
"firstCellWeight",
"=",
"1.5",
";",
"$",
"indexDeltaWeight",
"=",
"0.25",
"*",
"(",
"a... | @param TableRow $oldRow
@param TableRow $newRow
@param int $oldIndex
@param int $newIndex
@return float|int | [
"@param",
"TableRow",
"$oldRow",
"@param",
"TableRow",
"$newRow",
"@param",
"int",
"$oldIndex",
"@param",
"int",
"$newIndex"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/TableDiff.php#L869-L894 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiffConfig.php | HtmlDiffConfig.addSpecialCaseChar | public function addSpecialCaseChar($char)
{
if (!in_array($char, $this->specialCaseChars)) {
$this->specialCaseChars[] = $char;
}
return $this;
} | php | public function addSpecialCaseChar($char)
{
if (!in_array($char, $this->specialCaseChars)) {
$this->specialCaseChars[] = $char;
}
return $this;
} | [
"public",
"function",
"addSpecialCaseChar",
"(",
"$",
"char",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"char",
",",
"$",
"this",
"->",
"specialCaseChars",
")",
")",
"{",
"$",
"this",
"->",
"specialCaseChars",
"[",
"]",
"=",
"$",
"char",
";",
"... | @param string $char
@return $this | [
"@param",
"string",
"$char"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiffConfig.php#L145-L152 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiffConfig.php | HtmlDiffConfig.removeSpecialCaseChar | public function removeSpecialCaseChar($char)
{
$key = array_search($char, $this->specialCaseChars);
if ($key !== false) {
unset($this->specialCaseChars[$key]);
}
return $this;
} | php | public function removeSpecialCaseChar($char)
{
$key = array_search($char, $this->specialCaseChars);
if ($key !== false) {
unset($this->specialCaseChars[$key]);
}
return $this;
} | [
"public",
"function",
"removeSpecialCaseChar",
"(",
"$",
"char",
")",
"{",
"$",
"key",
"=",
"array_search",
"(",
"$",
"char",
",",
"$",
"this",
"->",
"specialCaseChars",
")",
";",
"if",
"(",
"$",
"key",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"t... | @param string $char
@return $this | [
"@param",
"string",
"$char"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiffConfig.php#L159-L167 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiffConfig.php | HtmlDiffConfig.setSpecialCaseTags | public function setSpecialCaseTags(array $tags = array())
{
$this->specialCaseTags = $tags;
$this->specialCaseOpeningTags = array();
$this->specialCaseClosingTags = array();
foreach ($this->specialCaseTags as $tag) {
$this->addSpecialCaseTag($tag);
}
return $this;
} | php | public function setSpecialCaseTags(array $tags = array())
{
$this->specialCaseTags = $tags;
$this->specialCaseOpeningTags = array();
$this->specialCaseClosingTags = array();
foreach ($this->specialCaseTags as $tag) {
$this->addSpecialCaseTag($tag);
}
return $this;
} | [
"public",
"function",
"setSpecialCaseTags",
"(",
"array",
"$",
"tags",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"specialCaseTags",
"=",
"$",
"tags",
";",
"$",
"this",
"->",
"specialCaseOpeningTags",
"=",
"array",
"(",
")",
";",
"$",
"this",
... | @param array $tags
@return $this | [
"@param",
"array",
"$tags"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiffConfig.php#L174-L185 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiffConfig.php | HtmlDiffConfig.addSpecialCaseTag | public function addSpecialCaseTag($tag)
{
if (!in_array($tag, $this->specialCaseTags)) {
$this->specialCaseTags[] = $tag;
}
$opening = $this->getOpeningTag($tag);
$closing = $this->getClosingTag($tag);
if (!in_array($opening, $this->specialCaseOpeningTags)) {
$this->specialCaseOpeningTags[] = $opening;
}
if (!in_array($closing, $this->specialCaseClosingTags)) {
$this->specialCaseClosingTags[] = $closing;
}
return $this;
} | php | public function addSpecialCaseTag($tag)
{
if (!in_array($tag, $this->specialCaseTags)) {
$this->specialCaseTags[] = $tag;
}
$opening = $this->getOpeningTag($tag);
$closing = $this->getClosingTag($tag);
if (!in_array($opening, $this->specialCaseOpeningTags)) {
$this->specialCaseOpeningTags[] = $opening;
}
if (!in_array($closing, $this->specialCaseClosingTags)) {
$this->specialCaseClosingTags[] = $closing;
}
return $this;
} | [
"public",
"function",
"addSpecialCaseTag",
"(",
"$",
"tag",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"tag",
",",
"$",
"this",
"->",
"specialCaseTags",
")",
")",
"{",
"$",
"this",
"->",
"specialCaseTags",
"[",
"]",
"=",
"$",
"tag",
";",
"}",
... | @param string $tag
@return $this | [
"@param",
"string",
"$tag"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiffConfig.php#L192-L209 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiffConfig.php | HtmlDiffConfig.removeSpecialCaseTag | public function removeSpecialCaseTag($tag)
{
if (($key = array_search($tag, $this->specialCaseTags)) !== false) {
unset($this->specialCaseTags[$key]);
$opening = $this->getOpeningTag($tag);
$closing = $this->getClosingTag($tag);
if (($key = array_search($opening, $this->specialCaseOpeningTags)) !== false) {
unset($this->specialCaseOpeningTags[$key]);
}
if (($key = array_search($closing, $this->specialCaseClosingTags)) !== false) {
unset($this->specialCaseClosingTags[$key]);
}
}
return $this;
} | php | public function removeSpecialCaseTag($tag)
{
if (($key = array_search($tag, $this->specialCaseTags)) !== false) {
unset($this->specialCaseTags[$key]);
$opening = $this->getOpeningTag($tag);
$closing = $this->getClosingTag($tag);
if (($key = array_search($opening, $this->specialCaseOpeningTags)) !== false) {
unset($this->specialCaseOpeningTags[$key]);
}
if (($key = array_search($closing, $this->specialCaseClosingTags)) !== false) {
unset($this->specialCaseClosingTags[$key]);
}
}
return $this;
} | [
"public",
"function",
"removeSpecialCaseTag",
"(",
"$",
"tag",
")",
"{",
"if",
"(",
"(",
"$",
"key",
"=",
"array_search",
"(",
"$",
"tag",
",",
"$",
"this",
"->",
"specialCaseTags",
")",
")",
"!==",
"false",
")",
"{",
"unset",
"(",
"$",
"this",
"->",... | @param string $tag
@return $this | [
"@param",
"string",
"$tag"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiffConfig.php#L216-L233 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiffConfig.php | HtmlDiffConfig.addIsolatedDiffTag | public function addIsolatedDiffTag($tag, $placeholder = null)
{
if (null === $placeholder) {
$placeholder = sprintf('[[REPLACE_%s]]', mb_strtoupper($tag));
}
if ($this->isIsolatedDiffTag($tag) && $this->isolatedDiffTags[$tag] !== $placeholder) {
throw new \InvalidArgumentException(
sprintf('Isolated diff tag "%s" already exists using a different placeholder', $tag)
);
}
$matchingKey = array_search($placeholder, $this->isolatedDiffTags, true);
if (false !== $matchingKey && $matchingKey !== $tag) {
throw new \InvalidArgumentException(
sprintf('Placeholder already being used for a different tag "%s"', $tag)
);
}
if (!array_key_exists($tag, $this->isolatedDiffTags)) {
$this->isolatedDiffTags[$tag] = $placeholder;
}
return $this;
} | php | public function addIsolatedDiffTag($tag, $placeholder = null)
{
if (null === $placeholder) {
$placeholder = sprintf('[[REPLACE_%s]]', mb_strtoupper($tag));
}
if ($this->isIsolatedDiffTag($tag) && $this->isolatedDiffTags[$tag] !== $placeholder) {
throw new \InvalidArgumentException(
sprintf('Isolated diff tag "%s" already exists using a different placeholder', $tag)
);
}
$matchingKey = array_search($placeholder, $this->isolatedDiffTags, true);
if (false !== $matchingKey && $matchingKey !== $tag) {
throw new \InvalidArgumentException(
sprintf('Placeholder already being used for a different tag "%s"', $tag)
);
}
if (!array_key_exists($tag, $this->isolatedDiffTags)) {
$this->isolatedDiffTags[$tag] = $placeholder;
}
return $this;
} | [
"public",
"function",
"addIsolatedDiffTag",
"(",
"$",
"tag",
",",
"$",
"placeholder",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"placeholder",
")",
"{",
"$",
"placeholder",
"=",
"sprintf",
"(",
"'[[REPLACE_%s]]'",
",",
"mb_strtoupper",
"(",
"$"... | @param string $tag
@param null|string $placeholder
@return $this | [
"@param",
"string",
"$tag",
"@param",
"null|string",
"$placeholder"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiffConfig.php#L345-L369 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/HtmlDiffConfig.php | HtmlDiffConfig.setCacheProvider | public function setCacheProvider(\Doctrine\Common\Cache\Cache $cacheProvider = null)
{
$this->cacheProvider = $cacheProvider;
return $this;
} | php | public function setCacheProvider(\Doctrine\Common\Cache\Cache $cacheProvider = null)
{
$this->cacheProvider = $cacheProvider;
return $this;
} | [
"public",
"function",
"setCacheProvider",
"(",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Cache",
"\\",
"Cache",
"$",
"cacheProvider",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"cacheProvider",
"=",
"$",
"cacheProvider",
";",
"return",
"$",
"this",
";",
"}"
... | @param null|\Doctrine\Common\Cache\Cache $cacheProvider
@return $this | [
"@param",
"null|",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Cache",
"\\",
"Cache",
"$cacheProvider"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/HtmlDiffConfig.php#L456-L461 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/DiffRowPosition.php | DiffRowPosition.incrementIndex | public function incrementIndex($type, $increment = 1)
{
if ($type === 'new') {
return $this->incrementIndexInNew($increment);
}
return $this->incrementIndexInOld($increment);
} | php | public function incrementIndex($type, $increment = 1)
{
if ($type === 'new') {
return $this->incrementIndexInNew($increment);
}
return $this->incrementIndexInOld($increment);
} | [
"public",
"function",
"incrementIndex",
"(",
"$",
"type",
",",
"$",
"increment",
"=",
"1",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"'new'",
")",
"{",
"return",
"$",
"this",
"->",
"incrementIndexInNew",
"(",
"$",
"increment",
")",
";",
"}",
"return",
... | @param string $type
@param int $increment
@return int | [
"@param",
"string",
"$type",
"@param",
"int",
"$increment"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/DiffRowPosition.php#L180-L187 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/DiffRowPosition.php | DiffRowPosition.incrementColumn | public function incrementColumn($type, $increment = 1)
{
if ($type === 'new') {
return $this->incrementColumnInNew($increment);
}
return $this->incrementColumnInOld($increment);
} | php | public function incrementColumn($type, $increment = 1)
{
if ($type === 'new') {
return $this->incrementColumnInNew($increment);
}
return $this->incrementColumnInOld($increment);
} | [
"public",
"function",
"incrementColumn",
"(",
"$",
"type",
",",
"$",
"increment",
"=",
"1",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"'new'",
")",
"{",
"return",
"$",
"this",
"->",
"incrementColumnInNew",
"(",
"$",
"increment",
")",
";",
"}",
"return",... | @param string $type
@param int $increment
@return int | [
"@param",
"string",
"$type",
"@param",
"int",
"$increment"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/DiffRowPosition.php#L195-L202 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Table/DiffRowPosition.php | DiffRowPosition.isColumnLessThanOther | public function isColumnLessThanOther($type)
{
if ($type === 'new') {
return $this->getColumnInNew() < $this->getColumnInOld();
}
return $this->getColumnInOld() < $this->getColumnInNew();
} | php | public function isColumnLessThanOther($type)
{
if ($type === 'new') {
return $this->getColumnInNew() < $this->getColumnInOld();
}
return $this->getColumnInOld() < $this->getColumnInNew();
} | [
"public",
"function",
"isColumnLessThanOther",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"type",
"===",
"'new'",
")",
"{",
"return",
"$",
"this",
"->",
"getColumnInNew",
"(",
")",
"<",
"$",
"this",
"->",
"getColumnInOld",
"(",
")",
";",
"}",
"return"... | @param string $type
@return bool | [
"@param",
"string",
"$type"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Table/DiffRowPosition.php#L209-L216 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/LcsService.php | LcsService.longestCommonSubsequence | public function longestCommonSubsequence(array $a, array $b)
{
$c = array();
$m = count($a);
$n = count($b);
for ($i = 0; $i <= $m; $i++) {
$c[$i][0] = 0;
}
for ($j = 0; $j <= $n; $j++) {
$c[0][$j] = 0;
}
for ($i = 1; $i <= $m; $i++) {
for ($j = 1; $j <= $n; $j++) {
if ($this->matchStrategy->isMatch($a[$i - 1], $b[$j - 1])) {
$c[$i][$j] = 1 + (isset($c[$i - 1][$j - 1]) ? $c[$i - 1][$j - 1] : 0);
} else {
$c[$i][$j] = max(
isset($c[$i][$j - 1]) ? $c[$i][$j - 1] : 0,
isset($c[$i - 1][$j]) ? $c[$i - 1][$j] : 0
);
}
}
}
$lcs = array_pad(array(), $m + 1, 0);
$this->compileMatches($c, $a, $b, $m, $n, $lcs);
return $lcs;
} | php | public function longestCommonSubsequence(array $a, array $b)
{
$c = array();
$m = count($a);
$n = count($b);
for ($i = 0; $i <= $m; $i++) {
$c[$i][0] = 0;
}
for ($j = 0; $j <= $n; $j++) {
$c[0][$j] = 0;
}
for ($i = 1; $i <= $m; $i++) {
for ($j = 1; $j <= $n; $j++) {
if ($this->matchStrategy->isMatch($a[$i - 1], $b[$j - 1])) {
$c[$i][$j] = 1 + (isset($c[$i - 1][$j - 1]) ? $c[$i - 1][$j - 1] : 0);
} else {
$c[$i][$j] = max(
isset($c[$i][$j - 1]) ? $c[$i][$j - 1] : 0,
isset($c[$i - 1][$j]) ? $c[$i - 1][$j] : 0
);
}
}
}
$lcs = array_pad(array(), $m + 1, 0);
$this->compileMatches($c, $a, $b, $m, $n, $lcs);
return $lcs;
} | [
"public",
"function",
"longestCommonSubsequence",
"(",
"array",
"$",
"a",
",",
"array",
"$",
"b",
")",
"{",
"$",
"c",
"=",
"array",
"(",
")",
";",
"$",
"m",
"=",
"count",
"(",
"$",
"a",
")",
";",
"$",
"n",
"=",
"count",
"(",
"$",
"b",
")",
";... | @param array $a
@param array $b
@return array | [
"@param",
"array",
"$a",
"@param",
"array",
"$b"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/LcsService.php#L35-L67 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/DiffCache.php | DiffCache.contains | public function contains($oldText, $newText)
{
return $this->cacheProvider->contains($this->getHashKey($oldText, $newText));
} | php | public function contains($oldText, $newText)
{
return $this->cacheProvider->contains($this->getHashKey($oldText, $newText));
} | [
"public",
"function",
"contains",
"(",
"$",
"oldText",
",",
"$",
"newText",
")",
"{",
"return",
"$",
"this",
"->",
"cacheProvider",
"->",
"contains",
"(",
"$",
"this",
"->",
"getHashKey",
"(",
"$",
"oldText",
",",
"$",
"newText",
")",
")",
";",
"}"
] | @param string $oldText
@param string $newText
@return bool | [
"@param",
"string",
"$oldText",
"@param",
"string",
"$newText"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/DiffCache.php#L53-L56 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/DiffCache.php | DiffCache.fetch | public function fetch($oldText, $newText)
{
return $this->cacheProvider->fetch($this->getHashKey($oldText, $newText));
} | php | public function fetch($oldText, $newText)
{
return $this->cacheProvider->fetch($this->getHashKey($oldText, $newText));
} | [
"public",
"function",
"fetch",
"(",
"$",
"oldText",
",",
"$",
"newText",
")",
"{",
"return",
"$",
"this",
"->",
"cacheProvider",
"->",
"fetch",
"(",
"$",
"this",
"->",
"getHashKey",
"(",
"$",
"oldText",
",",
"$",
"newText",
")",
")",
";",
"}"
] | @param string $oldText
@param string $newText
@return string | [
"@param",
"string",
"$oldText",
"@param",
"string",
"$newText"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/DiffCache.php#L64-L67 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/DiffCache.php | DiffCache.save | public function save($oldText, $newText, $data, $lifeTime = 0)
{
return $this->cacheProvider->save($this->getHashKey($oldText, $newText), $data, $lifeTime);
} | php | public function save($oldText, $newText, $data, $lifeTime = 0)
{
return $this->cacheProvider->save($this->getHashKey($oldText, $newText), $data, $lifeTime);
} | [
"public",
"function",
"save",
"(",
"$",
"oldText",
",",
"$",
"newText",
",",
"$",
"data",
",",
"$",
"lifeTime",
"=",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"cacheProvider",
"->",
"save",
"(",
"$",
"this",
"->",
"getHashKey",
"(",
"$",
"oldText",... | @param string $oldText
@param string $newText
@param string $data
@param int $lifeTime
@return bool | [
"@param",
"string",
"$oldText",
"@param",
"string",
"$newText",
"@param",
"string",
"$data",
"@param",
"int",
"$lifeTime"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/DiffCache.php#L77-L80 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/DiffCache.php | DiffCache.delete | public function delete($oldText, $newText)
{
return $this->cacheProvider->delete($this->getHashKey($oldText, $newText));
} | php | public function delete($oldText, $newText)
{
return $this->cacheProvider->delete($this->getHashKey($oldText, $newText));
} | [
"public",
"function",
"delete",
"(",
"$",
"oldText",
",",
"$",
"newText",
")",
"{",
"return",
"$",
"this",
"->",
"cacheProvider",
"->",
"delete",
"(",
"$",
"this",
"->",
"getHashKey",
"(",
"$",
"oldText",
",",
"$",
"newText",
")",
")",
";",
"}"
] | @param string $oldText
@param string $newText
@return bool | [
"@param",
"string",
"$oldText",
"@param",
"string",
"$newText"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/DiffCache.php#L88-L91 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/ListDiffLines.php | ListDiffLines.build | public function build()
{
$this->prepare();
if ($this->hasDiffCache() && $this->getDiffCache()->contains($this->oldText, $this->newText)) {
$this->content = $this->getDiffCache()->fetch($this->oldText, $this->newText);
return $this->content;
}
$matchStrategy = new ListItemMatchStrategy($this->stringUtil, $this->config->getMatchThreshold());
$this->lcsService = new LcsService($matchStrategy);
return $this->listByLines($this->oldText, $this->newText);
} | php | public function build()
{
$this->prepare();
if ($this->hasDiffCache() && $this->getDiffCache()->contains($this->oldText, $this->newText)) {
$this->content = $this->getDiffCache()->fetch($this->oldText, $this->newText);
return $this->content;
}
$matchStrategy = new ListItemMatchStrategy($this->stringUtil, $this->config->getMatchThreshold());
$this->lcsService = new LcsService($matchStrategy);
return $this->listByLines($this->oldText, $this->newText);
} | [
"public",
"function",
"build",
"(",
")",
"{",
"$",
"this",
"->",
"prepare",
"(",
")",
";",
"if",
"(",
"$",
"this",
"->",
"hasDiffCache",
"(",
")",
"&&",
"$",
"this",
"->",
"getDiffCache",
"(",
")",
"->",
"contains",
"(",
"$",
"this",
"->",
"oldText... | {@inheritDoc} | [
"{"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/ListDiffLines.php#L58-L72 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/ListDiffLines.php | ListDiffLines.listByLines | protected function listByLines($old, $new)
{
/* @var $newDom \simple_html_dom */
$newDom = HtmlDomParser::str_get_html($new);
/* @var $oldDom \simple_html_dom */
$oldDom = HtmlDomParser::str_get_html($old);
$newListNode = $this->findListNode($newDom);
$oldListNode = $this->findListNode($oldDom);
$operations = $this->getListItemOperations($oldListNode, $newListNode);
return $this->processOperations($operations, $oldListNode, $newListNode);
} | php | protected function listByLines($old, $new)
{
/* @var $newDom \simple_html_dom */
$newDom = HtmlDomParser::str_get_html($new);
/* @var $oldDom \simple_html_dom */
$oldDom = HtmlDomParser::str_get_html($old);
$newListNode = $this->findListNode($newDom);
$oldListNode = $this->findListNode($oldDom);
$operations = $this->getListItemOperations($oldListNode, $newListNode);
return $this->processOperations($operations, $oldListNode, $newListNode);
} | [
"protected",
"function",
"listByLines",
"(",
"$",
"old",
",",
"$",
"new",
")",
"{",
"/* @var $newDom \\simple_html_dom */",
"$",
"newDom",
"=",
"HtmlDomParser",
"::",
"str_get_html",
"(",
"$",
"new",
")",
";",
"/* @var $oldDom \\simple_html_dom */",
"$",
"oldDom",
... | @param string $old
@param string $new
@return string | [
"@param",
"string",
"$old",
"@param",
"string",
"$new"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/ListDiffLines.php#L80-L93 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/ListDiffLines.php | ListDiffLines.getListItemOperations | protected function getListItemOperations($oldListNode, $newListNode)
{
// Prepare arrays of list item content to use in LCS algorithm
$oldListText = $this->getListTextArray($oldListNode);
$newListText = $this->getListTextArray($newListNode);
$lcsMatches = $this->lcsService->longestCommonSubsequence($oldListText, $newListText);
$oldLength = count($oldListText);
$newLength = count($newListText);
$operations = array();
$currentLineInOld = 0;
$currentLineInNew = 0;
$lcsMatches[$oldLength + 1] = $newLength + 1;
foreach ($lcsMatches as $matchInOld => $matchInNew) {
// No matching line in new list
if ($matchInNew === 0) {
continue;
}
$nextLineInOld = $currentLineInOld + 1;
$nextLineInNew = $currentLineInNew + 1;
if ($matchInNew > $nextLineInNew && $matchInOld > $nextLineInOld) {
// Change
$operations[] = new Operation(
Operation::CHANGED,
$nextLineInOld,
$matchInOld - 1,
$nextLineInNew,
$matchInNew - 1
);
} elseif ($matchInNew > $nextLineInNew && $matchInOld === $nextLineInOld) {
// Add items before this
$operations[] = new Operation(
Operation::ADDED,
$currentLineInOld,
$currentLineInOld,
$nextLineInNew,
$matchInNew - 1
);
} elseif ($matchInNew === $nextLineInNew && $matchInOld > $nextLineInOld) {
// Delete items before this
$operations[] = new Operation(
Operation::DELETED,
$nextLineInOld,
$matchInOld - 1,
$currentLineInNew,
$currentLineInNew
);
}
$currentLineInNew = $matchInNew;
$currentLineInOld = $matchInOld;
}
return $operations;
} | php | protected function getListItemOperations($oldListNode, $newListNode)
{
// Prepare arrays of list item content to use in LCS algorithm
$oldListText = $this->getListTextArray($oldListNode);
$newListText = $this->getListTextArray($newListNode);
$lcsMatches = $this->lcsService->longestCommonSubsequence($oldListText, $newListText);
$oldLength = count($oldListText);
$newLength = count($newListText);
$operations = array();
$currentLineInOld = 0;
$currentLineInNew = 0;
$lcsMatches[$oldLength + 1] = $newLength + 1;
foreach ($lcsMatches as $matchInOld => $matchInNew) {
// No matching line in new list
if ($matchInNew === 0) {
continue;
}
$nextLineInOld = $currentLineInOld + 1;
$nextLineInNew = $currentLineInNew + 1;
if ($matchInNew > $nextLineInNew && $matchInOld > $nextLineInOld) {
// Change
$operations[] = new Operation(
Operation::CHANGED,
$nextLineInOld,
$matchInOld - 1,
$nextLineInNew,
$matchInNew - 1
);
} elseif ($matchInNew > $nextLineInNew && $matchInOld === $nextLineInOld) {
// Add items before this
$operations[] = new Operation(
Operation::ADDED,
$currentLineInOld,
$currentLineInOld,
$nextLineInNew,
$matchInNew - 1
);
} elseif ($matchInNew === $nextLineInNew && $matchInOld > $nextLineInOld) {
// Delete items before this
$operations[] = new Operation(
Operation::DELETED,
$nextLineInOld,
$matchInOld - 1,
$currentLineInNew,
$currentLineInNew
);
}
$currentLineInNew = $matchInNew;
$currentLineInOld = $matchInOld;
}
return $operations;
} | [
"protected",
"function",
"getListItemOperations",
"(",
"$",
"oldListNode",
",",
"$",
"newListNode",
")",
"{",
"// Prepare arrays of list item content to use in LCS algorithm",
"$",
"oldListText",
"=",
"$",
"this",
"->",
"getListTextArray",
"(",
"$",
"oldListNode",
")",
... | @param \simple_html_dom_node $oldListNode
@param \simple_html_dom_node $newListNode
@return array|Operation[] | [
"@param",
"\\",
"simple_html_dom_node",
"$oldListNode",
"@param",
"\\",
"simple_html_dom_node",
"$newListNode"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/ListDiffLines.php#L111-L169 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/ListDiffLines.php | ListDiffLines.getListTextArray | protected function getListTextArray($listNode)
{
$output = array();
foreach ($listNode->children() as $listItem) {
$output[] = $this->getRelevantNodeText($listItem);
}
return $output;
} | php | protected function getListTextArray($listNode)
{
$output = array();
foreach ($listNode->children() as $listItem) {
$output[] = $this->getRelevantNodeText($listItem);
}
return $output;
} | [
"protected",
"function",
"getListTextArray",
"(",
"$",
"listNode",
")",
"{",
"$",
"output",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"listNode",
"->",
"children",
"(",
")",
"as",
"$",
"listItem",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
... | @param \simple_html_dom_node $listNode
@return array | [
"@param",
"\\",
"simple_html_dom_node",
"$listNode"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/ListDiffLines.php#L176-L184 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/ListDiffLines.php | ListDiffLines.getRelevantNodeText | protected function getRelevantNodeText($node)
{
if (!$node->hasChildNodes()) {
return $node->innertext();
}
$output = '';
foreach ($node->nodes as $child) {
/* @var $child \simple_html_dom_node */
if (!$child->hasChildNodes()) {
$output .= $child->outertext();
} elseif (in_array($child->nodeName(), static::$listContentTags, true)) {
$output .= sprintf('<%1$s>%2$s</%1$s>', $child->nodeName(), $this->getRelevantNodeText($child));
}
}
return $output;
} | php | protected function getRelevantNodeText($node)
{
if (!$node->hasChildNodes()) {
return $node->innertext();
}
$output = '';
foreach ($node->nodes as $child) {
/* @var $child \simple_html_dom_node */
if (!$child->hasChildNodes()) {
$output .= $child->outertext();
} elseif (in_array($child->nodeName(), static::$listContentTags, true)) {
$output .= sprintf('<%1$s>%2$s</%1$s>', $child->nodeName(), $this->getRelevantNodeText($child));
}
}
return $output;
} | [
"protected",
"function",
"getRelevantNodeText",
"(",
"$",
"node",
")",
"{",
"if",
"(",
"!",
"$",
"node",
"->",
"hasChildNodes",
"(",
")",
")",
"{",
"return",
"$",
"node",
"->",
"innertext",
"(",
")",
";",
"}",
"$",
"output",
"=",
"''",
";",
"foreach"... | @param \simple_html_dom_node $node
@return string | [
"@param",
"\\",
"simple_html_dom_node",
"$node"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/ListDiffLines.php#L191-L208 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/ListDiffLines.php | ListDiffLines.deleteListItem | protected function deleteListItem($li)
{
$this->addClassToNode($li, self::CLASS_LIST_ITEM_DELETED);
$li->innertext = sprintf('<del>%s</del>', $li->innertext);
return $li->outertext;
} | php | protected function deleteListItem($li)
{
$this->addClassToNode($li, self::CLASS_LIST_ITEM_DELETED);
$li->innertext = sprintf('<del>%s</del>', $li->innertext);
return $li->outertext;
} | [
"protected",
"function",
"deleteListItem",
"(",
"$",
"li",
")",
"{",
"$",
"this",
"->",
"addClassToNode",
"(",
"$",
"li",
",",
"self",
"::",
"CLASS_LIST_ITEM_DELETED",
")",
";",
"$",
"li",
"->",
"innertext",
"=",
"sprintf",
"(",
"'<del>%s</del>'",
",",
"$"... | @param \simple_html_dom_node $li
@return string | [
"@param",
"\\",
"simple_html_dom_node",
"$li"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/ListDiffLines.php#L215-L221 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/ListDiffLines.php | ListDiffLines.addListItem | protected function addListItem($li, $replacement = false)
{
$this->addClassToNode($li, $replacement ? self::CLASS_LIST_ITEM_CHANGED : self::CLASS_LIST_ITEM_ADDED);
$li->innertext = sprintf('<ins>%s</ins>', $li->innertext);
return $li->outertext;
} | php | protected function addListItem($li, $replacement = false)
{
$this->addClassToNode($li, $replacement ? self::CLASS_LIST_ITEM_CHANGED : self::CLASS_LIST_ITEM_ADDED);
$li->innertext = sprintf('<ins>%s</ins>', $li->innertext);
return $li->outertext;
} | [
"protected",
"function",
"addListItem",
"(",
"$",
"li",
",",
"$",
"replacement",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"addClassToNode",
"(",
"$",
"li",
",",
"$",
"replacement",
"?",
"self",
"::",
"CLASS_LIST_ITEM_CHANGED",
":",
"self",
"::",
"CLASS_L... | @param \simple_html_dom_node $li
@param bool $replacement
@return string | [
"@param",
"\\",
"simple_html_dom_node",
"$li",
"@param",
"bool",
"$replacement"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/ListDiffLines.php#L229-L235 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/ListDiffLines.php | ListDiffLines.processOperations | protected function processOperations($operations, $oldListNode, $newListNode)
{
$output = '';
$indexInOld = 0;
$indexInNew = 0;
$lastOperation = null;
foreach ($operations as $operation) {
$replaced = false;
while ($operation->startInOld > ($operation->action === Operation::ADDED ? $indexInOld : $indexInOld + 1)) {
$li = $oldListNode->children($indexInOld);
$matchingLi = null;
if ($operation->startInNew > ($operation->action === Operation::DELETED ? $indexInNew
: $indexInNew + 1)
) {
$matchingLi = $newListNode->children($indexInNew);
}
if (null !== $matchingLi) {
$htmlDiff = HtmlDiff::create($li->innertext, $matchingLi->innertext, $this->config);
$li->innertext = $htmlDiff->build();
$indexInNew++;
}
$class = self::CLASS_LIST_ITEM_NONE;
if ($lastOperation === Operation::DELETED && !$replaced) {
$class = self::CLASS_LIST_ITEM_CHANGED;
$replaced = true;
}
$li->setAttribute('class', trim($li->getAttribute('class').' '.$class));
$output .= $li->outertext;
$indexInOld++;
}
switch ($operation->action) {
case Operation::ADDED:
for ($i = $operation->startInNew; $i <= $operation->endInNew; $i++) {
$output .= $this->addListItem($newListNode->children($i - 1));
}
$indexInNew = $operation->endInNew;
break;
case Operation::DELETED:
for ($i = $operation->startInOld; $i <= $operation->endInOld; $i++) {
$output .= $this->deleteListItem($oldListNode->children($i - 1));
}
$indexInOld = $operation->endInOld;
break;
case Operation::CHANGED:
$changeDelta = 0;
for ($i = $operation->startInOld; $i <= $operation->endInOld; $i++) {
$output .= $this->deleteListItem($oldListNode->children($i - 1));
$changeDelta--;
}
for ($i = $operation->startInNew; $i <= $operation->endInNew; $i++) {
$output .= $this->addListItem($newListNode->children($i - 1), $changeDelta < 0);
$changeDelta++;
}
$indexInOld = $operation->endInOld;
$indexInNew = $operation->endInNew;
break;
}
$lastOperation = $operation->action;
}
$oldCount = count($oldListNode->children());
$newCount = count($newListNode->children());
while ($indexInOld < $oldCount) {
$li = $oldListNode->children($indexInOld);
$matchingLi = null;
if ($indexInNew < $newCount) {
$matchingLi = $newListNode->children($indexInNew);
}
if (null !== $matchingLi) {
$htmlDiff = HtmlDiff::create($li->innertext(), $matchingLi->innertext(), $this->config);
$li->innertext = $htmlDiff->build();
$indexInNew++;
}
$class = self::CLASS_LIST_ITEM_NONE;
if ($lastOperation === Operation::DELETED) {
$class = self::CLASS_LIST_ITEM_CHANGED;
}
$li->setAttribute('class', trim($li->getAttribute('class').' '.$class));
$output .= $li->outertext;
$indexInOld++;
}
$newListNode->innertext = $output;
$newListNode->setAttribute('class', trim($newListNode->getAttribute('class').' diff-list'));
return $newListNode->outertext;
} | php | protected function processOperations($operations, $oldListNode, $newListNode)
{
$output = '';
$indexInOld = 0;
$indexInNew = 0;
$lastOperation = null;
foreach ($operations as $operation) {
$replaced = false;
while ($operation->startInOld > ($operation->action === Operation::ADDED ? $indexInOld : $indexInOld + 1)) {
$li = $oldListNode->children($indexInOld);
$matchingLi = null;
if ($operation->startInNew > ($operation->action === Operation::DELETED ? $indexInNew
: $indexInNew + 1)
) {
$matchingLi = $newListNode->children($indexInNew);
}
if (null !== $matchingLi) {
$htmlDiff = HtmlDiff::create($li->innertext, $matchingLi->innertext, $this->config);
$li->innertext = $htmlDiff->build();
$indexInNew++;
}
$class = self::CLASS_LIST_ITEM_NONE;
if ($lastOperation === Operation::DELETED && !$replaced) {
$class = self::CLASS_LIST_ITEM_CHANGED;
$replaced = true;
}
$li->setAttribute('class', trim($li->getAttribute('class').' '.$class));
$output .= $li->outertext;
$indexInOld++;
}
switch ($operation->action) {
case Operation::ADDED:
for ($i = $operation->startInNew; $i <= $operation->endInNew; $i++) {
$output .= $this->addListItem($newListNode->children($i - 1));
}
$indexInNew = $operation->endInNew;
break;
case Operation::DELETED:
for ($i = $operation->startInOld; $i <= $operation->endInOld; $i++) {
$output .= $this->deleteListItem($oldListNode->children($i - 1));
}
$indexInOld = $operation->endInOld;
break;
case Operation::CHANGED:
$changeDelta = 0;
for ($i = $operation->startInOld; $i <= $operation->endInOld; $i++) {
$output .= $this->deleteListItem($oldListNode->children($i - 1));
$changeDelta--;
}
for ($i = $operation->startInNew; $i <= $operation->endInNew; $i++) {
$output .= $this->addListItem($newListNode->children($i - 1), $changeDelta < 0);
$changeDelta++;
}
$indexInOld = $operation->endInOld;
$indexInNew = $operation->endInNew;
break;
}
$lastOperation = $operation->action;
}
$oldCount = count($oldListNode->children());
$newCount = count($newListNode->children());
while ($indexInOld < $oldCount) {
$li = $oldListNode->children($indexInOld);
$matchingLi = null;
if ($indexInNew < $newCount) {
$matchingLi = $newListNode->children($indexInNew);
}
if (null !== $matchingLi) {
$htmlDiff = HtmlDiff::create($li->innertext(), $matchingLi->innertext(), $this->config);
$li->innertext = $htmlDiff->build();
$indexInNew++;
}
$class = self::CLASS_LIST_ITEM_NONE;
if ($lastOperation === Operation::DELETED) {
$class = self::CLASS_LIST_ITEM_CHANGED;
}
$li->setAttribute('class', trim($li->getAttribute('class').' '.$class));
$output .= $li->outertext;
$indexInOld++;
}
$newListNode->innertext = $output;
$newListNode->setAttribute('class', trim($newListNode->getAttribute('class').' diff-list'));
return $newListNode->outertext;
} | [
"protected",
"function",
"processOperations",
"(",
"$",
"operations",
",",
"$",
"oldListNode",
",",
"$",
"newListNode",
")",
"{",
"$",
"output",
"=",
"''",
";",
"$",
"indexInOld",
"=",
"0",
";",
"$",
"indexInNew",
"=",
"0",
";",
"$",
"lastOperation",
"="... | @param Operation[]|array $operations
@param \simple_html_dom_node $oldListNode
@param \simple_html_dom_node $newListNode
@return string | [
"@param",
"Operation",
"[]",
"|array",
"$operations",
"@param",
"\\",
"simple_html_dom_node",
"$oldListNode",
"@param",
"\\",
"simple_html_dom_node",
"$newListNode"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/ListDiffLines.php#L244-L340 |
caxy/php-htmldiff | lib/Caxy/HtmlDiff/Strategy/ListItemMatchStrategy.php | ListItemMatchStrategy.isMatch | public function isMatch($a, $b)
{
$percentage = null;
// Strip tags and check similarity
$aStripped = strip_tags($a);
$bStripped = strip_tags($b);
similar_text($aStripped, $bStripped, $percentage);
if ($percentage >= $this->similarityThreshold) {
return true;
}
// Check w/o stripped tags
similar_text($a, $b, $percentage);
if ($percentage >= $this->similarityThreshold) {
return true;
}
// Check common prefix/ suffix length
$aCleaned = trim($aStripped);
$bCleaned = trim($bStripped);
if ($this->stringUtil->strlen($aCleaned) === 0 || $this->stringUtil->strlen($bCleaned) === 0) {
$aCleaned = $a;
$bCleaned = $b;
}
if ($this->stringUtil->strlen($aCleaned) === 0 || $this->stringUtil->strlen($bCleaned) === 0) {
return false;
}
$prefixIndex = Preprocessor::diffCommonPrefix($aCleaned, $bCleaned, $this->stringUtil);
$suffixIndex = Preprocessor::diffCommonSuffix($aCleaned, $bCleaned, $this->stringUtil);
// Use shorter string, and see how much of it is leftover
$len = min($this->stringUtil->strlen($aCleaned), $this->stringUtil->strlen($bCleaned));
$remaining = $len - ($prefixIndex + $suffixIndex);
$strLengthPercent = $len / max($this->stringUtil->strlen($a), $this->stringUtil->strlen($b));
if ($remaining === 0 && $strLengthPercent > $this->lengthRatioThreshold) {
return true;
}
$percentCommon = ($prefixIndex + $suffixIndex) / $len;
if ($strLengthPercent > 0.1 && $percentCommon > $this->commonTextRatioThreshold) {
return true;
}
return false;
} | php | public function isMatch($a, $b)
{
$percentage = null;
// Strip tags and check similarity
$aStripped = strip_tags($a);
$bStripped = strip_tags($b);
similar_text($aStripped, $bStripped, $percentage);
if ($percentage >= $this->similarityThreshold) {
return true;
}
// Check w/o stripped tags
similar_text($a, $b, $percentage);
if ($percentage >= $this->similarityThreshold) {
return true;
}
// Check common prefix/ suffix length
$aCleaned = trim($aStripped);
$bCleaned = trim($bStripped);
if ($this->stringUtil->strlen($aCleaned) === 0 || $this->stringUtil->strlen($bCleaned) === 0) {
$aCleaned = $a;
$bCleaned = $b;
}
if ($this->stringUtil->strlen($aCleaned) === 0 || $this->stringUtil->strlen($bCleaned) === 0) {
return false;
}
$prefixIndex = Preprocessor::diffCommonPrefix($aCleaned, $bCleaned, $this->stringUtil);
$suffixIndex = Preprocessor::diffCommonSuffix($aCleaned, $bCleaned, $this->stringUtil);
// Use shorter string, and see how much of it is leftover
$len = min($this->stringUtil->strlen($aCleaned), $this->stringUtil->strlen($bCleaned));
$remaining = $len - ($prefixIndex + $suffixIndex);
$strLengthPercent = $len / max($this->stringUtil->strlen($a), $this->stringUtil->strlen($b));
if ($remaining === 0 && $strLengthPercent > $this->lengthRatioThreshold) {
return true;
}
$percentCommon = ($prefixIndex + $suffixIndex) / $len;
if ($strLengthPercent > 0.1 && $percentCommon > $this->commonTextRatioThreshold) {
return true;
}
return false;
} | [
"public",
"function",
"isMatch",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"$",
"percentage",
"=",
"null",
";",
"// Strip tags and check similarity",
"$",
"aStripped",
"=",
"strip_tags",
"(",
"$",
"a",
")",
";",
"$",
"bStripped",
"=",
"strip_tags",
"(",
"$... | @param string $a
@param string $b
@return bool | [
"@param",
"string",
"$a",
"@param",
"string",
"$b"
] | train | https://github.com/caxy/php-htmldiff/blob/d304b3cd8205c7fcc6ae93aa323a12b878103f87/lib/Caxy/HtmlDiff/Strategy/ListItemMatchStrategy.php#L52-L100 |
PUGX/badge-poser | src/PUGX/BadgeBundle/Controller/Badge/ComposerlockController.php | ComposerlockController.composerlockAction | public function composerlockAction(Request $request, $repository, $format='svg')
{
if ($request->query->get('format') == 'plastic') {
$format = 'plastic';
}
$this->useCase = $this->container->get('use_case_badge_composerlock');
$this->imageFactory = $this->container->get('image_factory');
$badge = $this->useCase->createComposerLockBadge($repository, $format);
$image = $this->imageFactory->createFromBadge($badge);
return ResponseFactory::createFromImage($image, 200);
} | php | public function composerlockAction(Request $request, $repository, $format='svg')
{
if ($request->query->get('format') == 'plastic') {
$format = 'plastic';
}
$this->useCase = $this->container->get('use_case_badge_composerlock');
$this->imageFactory = $this->container->get('image_factory');
$badge = $this->useCase->createComposerLockBadge($repository, $format);
$image = $this->imageFactory->createFromBadge($badge);
return ResponseFactory::createFromImage($image, 200);
} | [
"public",
"function",
"composerlockAction",
"(",
"Request",
"$",
"request",
",",
"$",
"repository",
",",
"$",
"format",
"=",
"'svg'",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'format'",
")",
"==",
"'plastic'",
")",
"{",
"$... | Version action.
@param string $repository repository
@Route("/{repository}/composerlock",
name="pugx_badge_composerlock",
requirements={"repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"}
)
@Method({"GET"})
@Cache(maxage="3600", smaxage="3600", public=true)
@return Response | [
"Version",
"action",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/BadgeBundle/Controller/Badge/ComposerlockController.php#L45-L59 |
PUGX/badge-poser | src/Badge/src/Model/UseCase/CreateLicenseBadge.php | CreateLicenseBadge.createLicenseBadge | public function createLicenseBadge($repository, $format = 'svg')
{
return $this->createBadgeFromRepository($repository, self::SUBJECT, self::COLOR, $format);
} | php | public function createLicenseBadge($repository, $format = 'svg')
{
return $this->createBadgeFromRepository($repository, self::SUBJECT, self::COLOR, $format);
} | [
"public",
"function",
"createLicenseBadge",
"(",
"$",
"repository",
",",
"$",
"format",
"=",
"'svg'",
")",
"{",
"return",
"$",
"this",
"->",
"createBadgeFromRepository",
"(",
"$",
"repository",
",",
"self",
"::",
"SUBJECT",
",",
"self",
"::",
"COLOR",
",",
... | @param string $repository
@param string $format
@return \PUGX\Badge\Model\Badge | [
"@param",
"string",
"$repository",
"@param",
"string",
"$format"
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/Badge/src/Model/UseCase/CreateLicenseBadge.php#L29-L32 |
PUGX/badge-poser | src/PUGX/BadgeBundle/Controller/Badge/GitattributesController.php | GitattributesController.gitattributesAction | public function gitattributesAction(Request $request, $repository, $format='svg')
{
if ($request->query->get('format') == 'plastic') {
$format = 'plastic';
}
$this->useCase = $this->container->get('use_case_badge_gitattributes');
$this->imageFactory = $this->container->get('image_factory');
$badge = $this->useCase->createGitattributesBadge($repository, $format);
$image = $this->imageFactory->createFromBadge($badge);
return ResponseFactory::createFromImage($image, 200);
} | php | public function gitattributesAction(Request $request, $repository, $format='svg')
{
if ($request->query->get('format') == 'plastic') {
$format = 'plastic';
}
$this->useCase = $this->container->get('use_case_badge_gitattributes');
$this->imageFactory = $this->container->get('image_factory');
$badge = $this->useCase->createGitattributesBadge($repository, $format);
$image = $this->imageFactory->createFromBadge($badge);
return ResponseFactory::createFromImage($image, 200);
} | [
"public",
"function",
"gitattributesAction",
"(",
"Request",
"$",
"request",
",",
"$",
"repository",
",",
"$",
"format",
"=",
"'svg'",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'format'",
")",
"==",
"'plastic'",
")",
"{",
"... | .gitattributes action.
@param string $repository repository
@Route("/{repository}/gitattributes",
name="pugx_badge_gitattributes",
requirements={"repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"}
)
@Method({"GET"})
@Cache(maxage="3600", smaxage="3600", public=true)
@return Response | [
".",
"gitattributes",
"action",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/BadgeBundle/Controller/Badge/GitattributesController.php#L44-L58 |
PUGX/badge-poser | src/Badge/src/Model/UseCase/CreateComposerLockBadge.php | CreateComposerLockBadge.createComposerLockBadge | public function createComposerLockBadge($repository, $format = 'svg')
{
$repo = str_replace('.git', '', $this->packageRepository
->fetchByRepository($repository)
->getOriginalObject()
->getRepository()
);
$request = $this->client->head(
$repo . '/blob/master/composer.lock',
array(),
array(
'timeout' => 2,
'connect_timeout' => 1,
'exceptions' => false,
)
);
$response = $this->client->send($request);
$status = 500;
if ($request) {
$status = $response->getStatusCode();
}
$this->text = self::LOCK_ERROR;
$color = self::COLOR_ERROR;
$subject = self::SUBJECT_ERROR;
if (200 === $status) {
$this->text = self::LOCK_COMMITTED;
$color = self::COLOR_COMMITTED;
$subject = self::SUBJECT;
} elseif (404 === $status) {
$this->text = self::LOCK_UNCOMMITTED;
$color = self::COLOR_UNCOMMITTED;
$subject = self::SUBJECT;
}
return $this->createBadgeFromRepository($repository, $subject, $color, $format);
} | php | public function createComposerLockBadge($repository, $format = 'svg')
{
$repo = str_replace('.git', '', $this->packageRepository
->fetchByRepository($repository)
->getOriginalObject()
->getRepository()
);
$request = $this->client->head(
$repo . '/blob/master/composer.lock',
array(),
array(
'timeout' => 2,
'connect_timeout' => 1,
'exceptions' => false,
)
);
$response = $this->client->send($request);
$status = 500;
if ($request) {
$status = $response->getStatusCode();
}
$this->text = self::LOCK_ERROR;
$color = self::COLOR_ERROR;
$subject = self::SUBJECT_ERROR;
if (200 === $status) {
$this->text = self::LOCK_COMMITTED;
$color = self::COLOR_COMMITTED;
$subject = self::SUBJECT;
} elseif (404 === $status) {
$this->text = self::LOCK_UNCOMMITTED;
$color = self::COLOR_UNCOMMITTED;
$subject = self::SUBJECT;
}
return $this->createBadgeFromRepository($repository, $subject, $color, $format);
} | [
"public",
"function",
"createComposerLockBadge",
"(",
"$",
"repository",
",",
"$",
"format",
"=",
"'svg'",
")",
"{",
"$",
"repo",
"=",
"str_replace",
"(",
"'.git'",
",",
"''",
",",
"$",
"this",
"->",
"packageRepository",
"->",
"fetchByRepository",
"(",
"$",
... | @param string $repository
@param string $format
@return \PUGX\Badge\Model\Badge | [
"@param",
"string",
"$repository",
"@param",
"string",
"$format"
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/Badge/src/Model/UseCase/CreateComposerLockBadge.php#L51-L89 |
PUGX/badge-poser | src/PUGX/BadgeBundle/Controller/Badge/DownloadsController.php | DownloadsController.downloadsAction | public function downloadsAction(Request $request, $repository, $type, $format = 'svg')
{
$this->useCase = $this->container->get('use_case_badge_downloads');
$this->imageFactory = $this->container->get('image_factory');
if (in_array($request->query->get('format'), $this->container->get('poser')->validFormats())) {
$format = $request->query->get('format');
}
$badge = $this->useCase->createDownloadsBadge($repository, $type, $format);
$image = $this->imageFactory->createFromBadge($badge);
return ResponseFactory::createFromImage($image, 200);
} | php | public function downloadsAction(Request $request, $repository, $type, $format = 'svg')
{
$this->useCase = $this->container->get('use_case_badge_downloads');
$this->imageFactory = $this->container->get('image_factory');
if (in_array($request->query->get('format'), $this->container->get('poser')->validFormats())) {
$format = $request->query->get('format');
}
$badge = $this->useCase->createDownloadsBadge($repository, $type, $format);
$image = $this->imageFactory->createFromBadge($badge);
return ResponseFactory::createFromImage($image, 200);
} | [
"public",
"function",
"downloadsAction",
"(",
"Request",
"$",
"request",
",",
"$",
"repository",
",",
"$",
"type",
",",
"$",
"format",
"=",
"'svg'",
")",
"{",
"$",
"this",
"->",
"useCase",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'use_ca... | Downloads action.
@param string $repository repository
@param string $type badge type
@param string $format
@Route("/{repository}/downloads",
name = "pugx_badge_download",
defaults = {"type" = "total"},
requirements = {
"repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
}
)
@Route("/{repository}/d/{type}",
name = "pugx_badge_download_type",
requirements = {
"type" = "total|daily|monthly",
"repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
}
)
@Method({"GET"})
@Cache(maxage="3600", smaxage="3600", public=true)
@todo: remove container
@return \Symfony\Component\HttpFoundation\Response | [
"Downloads",
"action",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/BadgeBundle/Controller/Badge/DownloadsController.php#L60-L74 |
PUGX/badge-poser | src/Badge/src/Infrastructure/Package/PackageRepository.php | PackageRepository.fetchByRepository | public function fetchByRepository($repository)
{
$apiPackage = $this->client->get($repository);
if ($apiPackage && $apiPackage instanceof ApiPackage) {
// create a new Package from the ApiPackage
$class = self::$packageClass;
return $class::createFromApi($apiPackage);
}
throw new UnexpectedValueException(sprintf('Impossible to fetch package by "%s" repository.', $repository));
} | php | public function fetchByRepository($repository)
{
$apiPackage = $this->client->get($repository);
if ($apiPackage && $apiPackage instanceof ApiPackage) {
// create a new Package from the ApiPackage
$class = self::$packageClass;
return $class::createFromApi($apiPackage);
}
throw new UnexpectedValueException(sprintf('Impossible to fetch package by "%s" repository.', $repository));
} | [
"public",
"function",
"fetchByRepository",
"(",
"$",
"repository",
")",
"{",
"$",
"apiPackage",
"=",
"$",
"this",
"->",
"client",
"->",
"get",
"(",
"$",
"repository",
")",
";",
"if",
"(",
"$",
"apiPackage",
"&&",
"$",
"apiPackage",
"instanceof",
"ApiPackag... | Returns package if founded.
@param string $repository
@return Package
@throws UnexpectedValueException | [
"Returns",
"package",
"if",
"founded",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/Badge/src/Infrastructure/Package/PackageRepository.php#L45-L56 |
PUGX/badge-poser | src/PUGX/BadgeBundle/Controller/SnippetController.php | SnippetController.allAction | public function allAction()
{
$repository = $this->container->get('request')->get('repository');
$response = new JsonResponse();
if (!$this->isValidRepositoryName($repository)) {
$response->setData(array('msg' => 'Package not found. Please check the package name. eg. (symfony/symfony)'));
$response->setStatusCode(404);
return $response;
}
try {
$badges = $this->container->get('snippet_generator')->generateAllSnippets($repository);
$response->setData($badges);
} catch (ClientErrorResponseException $e) {
$response->setData(array('msg' => 'Package not found. Please check the package name. eg. (symfony/symfony)'));
$response->setStatusCode(404);
} catch (\Exception $e) {
$response->setData(array('msg' => 'Server Error'));
$response->setStatusCode(500);
}
return $response;
} | php | public function allAction()
{
$repository = $this->container->get('request')->get('repository');
$response = new JsonResponse();
if (!$this->isValidRepositoryName($repository)) {
$response->setData(array('msg' => 'Package not found. Please check the package name. eg. (symfony/symfony)'));
$response->setStatusCode(404);
return $response;
}
try {
$badges = $this->container->get('snippet_generator')->generateAllSnippets($repository);
$response->setData($badges);
} catch (ClientErrorResponseException $e) {
$response->setData(array('msg' => 'Package not found. Please check the package name. eg. (symfony/symfony)'));
$response->setStatusCode(404);
} catch (\Exception $e) {
$response->setData(array('msg' => 'Server Error'));
$response->setStatusCode(500);
}
return $response;
} | [
"public",
"function",
"allAction",
"(",
")",
"{",
"$",
"repository",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'request'",
")",
"->",
"get",
"(",
"'repository'",
")",
";",
"$",
"response",
"=",
"new",
"JsonResponse",
"(",
")",
";",
"if",
... | @Route("/snippet/all/",
name="pugx_snippet_all"
)
@Method({"GET"})
@Cache(smaxage="3600", maxage="3600", public=true)
@return JsonResponse | [
"@Route",
"(",
"/",
"snippet",
"/",
"all",
"/",
"name",
"=",
"pugx_snippet_all",
")",
"@Method",
"(",
"{",
"GET",
"}",
")",
"@Cache",
"(",
"smaxage",
"=",
"3600",
"maxage",
"=",
"3600",
"public",
"=",
"true",
")"
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/BadgeBundle/Controller/SnippetController.php#L38-L62 |
PUGX/badge-poser | src/Badge/src/Model/UseCase/CreateGitattributesBadge.php | CreateGitattributesBadge.createGitattributesBadge | public function createGitattributesBadge($repository, $format = 'svg')
{
$repo = str_replace('.git', '', $this->packageRepository
->fetchByRepository($repository)
->getOriginalObject()
->getRepository()
);
$request = $this->client->head(
$repo . '/blob/master/.gitattributes',
array(),
array(
'timeout' => 2,
'connect_timeout' => 1,
'exceptions' => false,
)
);
$response = $this->client->send($request);
$status = 500;
if ($request) {
$status = $response->getStatusCode();
}
$this->text = self::GITATTRIBUTES_ERROR;
$color = self::COLOR_ERROR;
$subject = self::SUBJECT_ERROR;
if (200 === $status) {
$this->text = self::GITATTRIBUTES_COMMITTED;
$color = self::COLOR_COMMITTED;
$subject = self::SUBJECT;
} elseif (404 === $status) {
$this->text = self::GITATTRIBUTES_UNCOMMITTED;
$color = self::COLOR_UNCOMMITTED;
$subject = self::SUBJECT;
}
return $this->createBadgeFromRepository(
$repository,
$subject,
$color,
$format
);
} | php | public function createGitattributesBadge($repository, $format = 'svg')
{
$repo = str_replace('.git', '', $this->packageRepository
->fetchByRepository($repository)
->getOriginalObject()
->getRepository()
);
$request = $this->client->head(
$repo . '/blob/master/.gitattributes',
array(),
array(
'timeout' => 2,
'connect_timeout' => 1,
'exceptions' => false,
)
);
$response = $this->client->send($request);
$status = 500;
if ($request) {
$status = $response->getStatusCode();
}
$this->text = self::GITATTRIBUTES_ERROR;
$color = self::COLOR_ERROR;
$subject = self::SUBJECT_ERROR;
if (200 === $status) {
$this->text = self::GITATTRIBUTES_COMMITTED;
$color = self::COLOR_COMMITTED;
$subject = self::SUBJECT;
} elseif (404 === $status) {
$this->text = self::GITATTRIBUTES_UNCOMMITTED;
$color = self::COLOR_UNCOMMITTED;
$subject = self::SUBJECT;
}
return $this->createBadgeFromRepository(
$repository,
$subject,
$color,
$format
);
} | [
"public",
"function",
"createGitattributesBadge",
"(",
"$",
"repository",
",",
"$",
"format",
"=",
"'svg'",
")",
"{",
"$",
"repo",
"=",
"str_replace",
"(",
"'.git'",
",",
"''",
",",
"$",
"this",
"->",
"packageRepository",
"->",
"fetchByRepository",
"(",
"$",... | @param string $repository
@param string $format
@return \PUGX\Badge\Model\Badge | [
"@param",
"string",
"$repository",
"@param",
"string",
"$format"
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/Badge/src/Model/UseCase/CreateGitattributesBadge.php#L50-L93 |
PUGX/badge-poser | src/Badge/src/Model/Package.php | Package.getPackageDownloads | public function getPackageDownloads($type)
{
$statsType = 'get' . ucfirst($type);
if (($download = $this->getDownloads()) && $download instanceof \Packagist\Api\Result\Package\Downloads) {
return $download->{$statsType}();
}
} | php | public function getPackageDownloads($type)
{
$statsType = 'get' . ucfirst($type);
if (($download = $this->getDownloads()) && $download instanceof \Packagist\Api\Result\Package\Downloads) {
return $download->{$statsType}();
}
} | [
"public",
"function",
"getPackageDownloads",
"(",
"$",
"type",
")",
"{",
"$",
"statsType",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"type",
")",
";",
"if",
"(",
"(",
"$",
"download",
"=",
"$",
"this",
"->",
"getDownloads",
"(",
")",
")",
"&&",
"$",
... | Take the Type of the Downloads (total, monthly or daily).
@param string $type
@return string | [
"Take",
"the",
"Type",
"of",
"the",
"Downloads",
"(",
"total",
"monthly",
"or",
"daily",
")",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/Badge/src/Model/Package.php#L58-L64 |
PUGX/badge-poser | src/Badge/src/Model/Package.php | Package.getBranchAliases | private function getBranchAliases(ApiPackage\Version $version)
{
$extra = $version->getExtra();
if (null !== $extra
&& isset($extra["branch-alias"])
&& is_array($extra["branch-alias"])
) {
return $extra["branch-alias"];
}
return null;
} | php | private function getBranchAliases(ApiPackage\Version $version)
{
$extra = $version->getExtra();
if (null !== $extra
&& isset($extra["branch-alias"])
&& is_array($extra["branch-alias"])
) {
return $extra["branch-alias"];
}
return null;
} | [
"private",
"function",
"getBranchAliases",
"(",
"ApiPackage",
"\\",
"Version",
"$",
"version",
")",
"{",
"$",
"extra",
"=",
"$",
"version",
"->",
"getExtra",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"extra",
"&&",
"isset",
"(",
"$",
"extra",
"[",
... | Get all the branch aliases.
@param ApiPackage\Version $version
@return null|array | [
"Get",
"all",
"the",
"branch",
"aliases",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/Badge/src/Model/Package.php#L112-L123 |
PUGX/badge-poser | src/PUGX/BadgeBundle/Controller/Badge/LicenseController.php | LicenseController.licenseAction | public function licenseAction(Request $request, $repository, $format='svg')
{
$this->useCase = $this->container->get('use_case_badge_license');
$this->imageFactory = $this->container->get('image_factory');
if (in_array($request->query->get('format'), $this->container->get('poser')->validFormats())) {
$format = $request->query->get('format');
}
$badge = $this->useCase->createLicenseBadge($repository, $format);
$image = $this->imageFactory->createFromBadge($badge);
return ResponseFactory::createFromImage($image, 200);
} | php | public function licenseAction(Request $request, $repository, $format='svg')
{
$this->useCase = $this->container->get('use_case_badge_license');
$this->imageFactory = $this->container->get('image_factory');
if (in_array($request->query->get('format'), $this->container->get('poser')->validFormats())) {
$format = $request->query->get('format');
}
$badge = $this->useCase->createLicenseBadge($repository, $format);
$image = $this->imageFactory->createFromBadge($badge);
return ResponseFactory::createFromImage($image, 200);
} | [
"public",
"function",
"licenseAction",
"(",
"Request",
"$",
"request",
",",
"$",
"repository",
",",
"$",
"format",
"=",
"'svg'",
")",
"{",
"$",
"this",
"->",
"useCase",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'use_case_badge_license'",
")",... | License action.
@param string $repository repository
@Route("/{repository}/license",
name="pugx_badge_license",
requirements={"repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"}
)
@Method({"GET"})
@Cache(maxage="3600", smaxage="3600", public=true)
@return Response | [
"License",
"action",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/BadgeBundle/Controller/Badge/LicenseController.php#L48-L61 |
PUGX/badge-poser | src/PUGX/BadgeBundle/Controller/Badge/VersionController.php | VersionController.versionAction | public function versionAction(Request $request, $repository, $latest, $format='svg')
{
if (in_array($request->query->get('format'), $this->container->get('poser')->validFormats())) {
$format = $request->query->get('format');
}
$this->useCase = $this->container->get('use_case_badge_version');
$this->imageFactory = $this->container->get('image_factory');
$function = 'create'.ucfirst($latest).'Badge';
$badge = $this->useCase->{$function}($repository, $format);
$image = $this->imageFactory->createFromBadge($badge);
return ResponseFactory::createFromImage($image, 200);
} | php | public function versionAction(Request $request, $repository, $latest, $format='svg')
{
if (in_array($request->query->get('format'), $this->container->get('poser')->validFormats())) {
$format = $request->query->get('format');
}
$this->useCase = $this->container->get('use_case_badge_version');
$this->imageFactory = $this->container->get('image_factory');
$function = 'create'.ucfirst($latest).'Badge';
$badge = $this->useCase->{$function}($repository, $format);
$image = $this->imageFactory->createFromBadge($badge);
return ResponseFactory::createFromImage($image, 200);
} | [
"public",
"function",
"versionAction",
"(",
"Request",
"$",
"request",
",",
"$",
"repository",
",",
"$",
"latest",
",",
"$",
"format",
"=",
"'svg'",
")",
"{",
"if",
"(",
"in_array",
"(",
"$",
"request",
"->",
"query",
"->",
"get",
"(",
"'format'",
")",... | Version action.
@param string $repository repository
@param string $latest latest
@Route("/{repository}/version",
name="pugx_badge_version",
defaults = {"latest" = "stable"},
requirements={"repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"}
)
@Route("/{repository}/v/{latest}",
name = "pugx_badge_version_latest",
requirements = {
"latest" = "stable|unstable",
"repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"
}
)
@Method({"GET"})
@Cache(maxage="3600", smaxage="3600", public=true)
@return Response | [
"Version",
"action",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/BadgeBundle/Controller/Badge/VersionController.php#L56-L71 |
PUGX/badge-poser | src/Badge/src/Model/UseCase/CreateDownloadsBadge.php | CreateDownloadsBadge.createDownloadsBadge | public function createDownloadsBadge($repository, $type, $format)
{
return $this->createBadgeFromRepository($repository, self::SUBJECT, self::COLOR, $format, $type);
} | php | public function createDownloadsBadge($repository, $type, $format)
{
return $this->createBadgeFromRepository($repository, self::SUBJECT, self::COLOR, $format, $type);
} | [
"public",
"function",
"createDownloadsBadge",
"(",
"$",
"repository",
",",
"$",
"type",
",",
"$",
"format",
")",
"{",
"return",
"$",
"this",
"->",
"createBadgeFromRepository",
"(",
"$",
"repository",
",",
"self",
"::",
"SUBJECT",
",",
"self",
"::",
"COLOR",
... | @param $repository
@param $type
@param $format
@return \PUGX\Badge\Model\Badge | [
"@param",
"$repository",
"@param",
"$type",
"@param",
"$format"
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/Badge/src/Model/UseCase/CreateDownloadsBadge.php#L50-L53 |
PUGX/badge-poser | src/Badge/src/Service/TextNormalizer.php | TextNormalizer.normalizeNumber | private function normalizeNumber($number)
{
if (!is_numeric($number)) {
throw new InvalidArgumentException('Number expected');
}
$number = floatval($number);
if ($number < 0) {
throw new InvalidArgumentException('The number expected was >= 0');
}
return max($number, 1);
} | php | private function normalizeNumber($number)
{
if (!is_numeric($number)) {
throw new InvalidArgumentException('Number expected');
}
$number = floatval($number);
if ($number < 0) {
throw new InvalidArgumentException('The number expected was >= 0');
}
return max($number, 1);
} | [
"private",
"function",
"normalizeNumber",
"(",
"$",
"number",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"number",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Number expected'",
")",
";",
"}",
"$",
"number",
"=",
"floatval",
"(... | This function transform a number to a float value or raise an Exception.
@param mixed $number number to be normalized
@return int
@throws InvalidArgumentException | [
"This",
"function",
"transform",
"a",
"number",
"to",
"a",
"float",
"value",
"or",
"raise",
"an",
"Exception",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/Badge/src/Service/TextNormalizer.php#L38-L51 |
PUGX/badge-poser | src/PUGX/StatsBundle/Service/RedisPersister.php | RedisPersister.incrementTotalAccess | public function incrementTotalAccess()
{
$this->redis->incr($this->keyTotal);
$key = $this->createDailyKey($this->keyTotal);
$this->redis->incr($key);
$key = $this->createMonthlyKey($this->keyTotal);
$this->redis->incr($key);
$key = $this->createYearlyKey($this->keyTotal);
$this->redis->incr($key);
return $this;
} | php | public function incrementTotalAccess()
{
$this->redis->incr($this->keyTotal);
$key = $this->createDailyKey($this->keyTotal);
$this->redis->incr($key);
$key = $this->createMonthlyKey($this->keyTotal);
$this->redis->incr($key);
$key = $this->createYearlyKey($this->keyTotal);
$this->redis->incr($key);
return $this;
} | [
"public",
"function",
"incrementTotalAccess",
"(",
")",
"{",
"$",
"this",
"->",
"redis",
"->",
"incr",
"(",
"$",
"this",
"->",
"keyTotal",
")",
";",
"$",
"key",
"=",
"$",
"this",
"->",
"createDailyKey",
"(",
"$",
"this",
"->",
"keyTotal",
")",
";",
"... | Increment by one the total accesses.
@return PersisterInterface | [
"Increment",
"by",
"one",
"the",
"total",
"accesses",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/StatsBundle/Service/RedisPersister.php#L60-L74 |
PUGX/badge-poser | src/PUGX/StatsBundle/Service/RedisPersister.php | RedisPersister.incrementRepositoryAccess | public function incrementRepositoryAccess($repository)
{
$this->redis->hincrby($this->concatenateKeys($this->keyHash, $repository), self::KEY_TOTAL, 1);
$key = $this->createDailyKey(self::KEY_TOTAL);
$this->redis->hincrby($this->concatenateKeys($this->keyHash, $repository), $key, 1);
$key = $this->createMonthlyKey(self::KEY_TOTAL);
$this->redis->hincrby($this->concatenateKeys($this->keyHash, $repository), $key, 1);
$key = $this->createYearlyKey(self::KEY_TOTAL);
$this->redis->hincrby($this->concatenateKeys($this->keyHash, $repository), $key, 1);
return $this;
} | php | public function incrementRepositoryAccess($repository)
{
$this->redis->hincrby($this->concatenateKeys($this->keyHash, $repository), self::KEY_TOTAL, 1);
$key = $this->createDailyKey(self::KEY_TOTAL);
$this->redis->hincrby($this->concatenateKeys($this->keyHash, $repository), $key, 1);
$key = $this->createMonthlyKey(self::KEY_TOTAL);
$this->redis->hincrby($this->concatenateKeys($this->keyHash, $repository), $key, 1);
$key = $this->createYearlyKey(self::KEY_TOTAL);
$this->redis->hincrby($this->concatenateKeys($this->keyHash, $repository), $key, 1);
return $this;
} | [
"public",
"function",
"incrementRepositoryAccess",
"(",
"$",
"repository",
")",
"{",
"$",
"this",
"->",
"redis",
"->",
"hincrby",
"(",
"$",
"this",
"->",
"concatenateKeys",
"(",
"$",
"this",
"->",
"keyHash",
",",
"$",
"repository",
")",
",",
"self",
"::",
... | Increment by one the repository accesses.
@param string $repository
@return PersisterInterface | [
"Increment",
"by",
"one",
"the",
"repository",
"accesses",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/StatsBundle/Service/RedisPersister.php#L83-L97 |
PUGX/badge-poser | src/PUGX/StatsBundle/Service/RedisPersister.php | RedisPersister.incrementRepositoryAccessType | public function incrementRepositoryAccessType($repository, $type)
{
$this->redis->hincrby($this->concatenateKeys($this->keyHash, $repository), $type, 1);
return $this;
} | php | public function incrementRepositoryAccessType($repository, $type)
{
$this->redis->hincrby($this->concatenateKeys($this->keyHash, $repository), $type, 1);
return $this;
} | [
"public",
"function",
"incrementRepositoryAccessType",
"(",
"$",
"repository",
",",
"$",
"type",
")",
"{",
"$",
"this",
"->",
"redis",
"->",
"hincrby",
"(",
"$",
"this",
"->",
"concatenateKeys",
"(",
"$",
"this",
"->",
"keyHash",
",",
"$",
"repository",
")... | Increment by one the repository accesses type.
@param string $repository
@param string $type
@return PersisterInterface | [
"Increment",
"by",
"one",
"the",
"repository",
"accesses",
"type",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/StatsBundle/Service/RedisPersister.php#L107-L112 |
PUGX/badge-poser | src/PUGX/StatsBundle/Service/RedisPersister.php | RedisPersister.addReferer | public function addReferer($url)
{
$this->redis->zadd($this->concatenateKeys($this->keyList, self::KEY_REFERER_SUFFIX), time() ,$url);
return $this;
} | php | public function addReferer($url)
{
$this->redis->zadd($this->concatenateKeys($this->keyList, self::KEY_REFERER_SUFFIX), time() ,$url);
return $this;
} | [
"public",
"function",
"addReferer",
"(",
"$",
"url",
")",
"{",
"$",
"this",
"->",
"redis",
"->",
"zadd",
"(",
"$",
"this",
"->",
"concatenateKeys",
"(",
"$",
"this",
"->",
"keyList",
",",
"self",
"::",
"KEY_REFERER_SUFFIX",
")",
",",
"time",
"(",
")",
... | Add the referrer to a subset.
@param string $url
@return PersisterInterface | [
"Add",
"the",
"referrer",
"to",
"a",
"subset",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/StatsBundle/Service/RedisPersister.php#L136-L141 |
PUGX/badge-poser | src/PUGX/StatsBundle/Service/RedisPersister.php | RedisPersister.createYearlyKey | private function createYearlyKey($prefix, \DateTime $datetime = null)
{
return sprintf("%s_%s", $prefix, $this->formatDate($datetime, 'Y'));
} | php | private function createYearlyKey($prefix, \DateTime $datetime = null)
{
return sprintf("%s_%s", $prefix, $this->formatDate($datetime, 'Y'));
} | [
"private",
"function",
"createYearlyKey",
"(",
"$",
"prefix",
",",
"\\",
"DateTime",
"$",
"datetime",
"=",
"null",
")",
"{",
"return",
"sprintf",
"(",
"\"%s_%s\"",
",",
"$",
"prefix",
",",
"$",
"this",
"->",
"formatDate",
"(",
"$",
"datetime",
",",
"'Y'"... | Create the yearly key with prefix eg. 'total_2003'
@param string $prefix
@param \DateTime $datetime
@return string | [
"Create",
"the",
"yearly",
"key",
"with",
"prefix",
"eg",
".",
"total_2003"
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/StatsBundle/Service/RedisPersister.php#L151-L154 |
PUGX/badge-poser | src/PUGX/StatsBundle/Service/RedisPersister.php | RedisPersister.createMonthlyKey | private function createMonthlyKey($prefix, \DateTime $datetime = null)
{
return sprintf("%s_%s", $prefix, $this->formatDate($datetime, 'Y_m'));
} | php | private function createMonthlyKey($prefix, \DateTime $datetime = null)
{
return sprintf("%s_%s", $prefix, $this->formatDate($datetime, 'Y_m'));
} | [
"private",
"function",
"createMonthlyKey",
"(",
"$",
"prefix",
",",
"\\",
"DateTime",
"$",
"datetime",
"=",
"null",
")",
"{",
"return",
"sprintf",
"(",
"\"%s_%s\"",
",",
"$",
"prefix",
",",
"$",
"this",
"->",
"formatDate",
"(",
"$",
"datetime",
",",
"'Y_... | Create the monthly key with prefix eg. 'total_2003_11'
@param string $prefix
@param \DateTime $datetime
@return string | [
"Create",
"the",
"monthly",
"key",
"with",
"prefix",
"eg",
".",
"total_2003_11"
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/StatsBundle/Service/RedisPersister.php#L164-L167 |
PUGX/badge-poser | src/PUGX/StatsBundle/Service/RedisPersister.php | RedisPersister.createDailyKey | private function createDailyKey($prefix, \DateTime $datetime = null)
{
return sprintf("%s_%s", $prefix, $this->formatDate($datetime, 'Y_m_d'));
} | php | private function createDailyKey($prefix, \DateTime $datetime = null)
{
return sprintf("%s_%s", $prefix, $this->formatDate($datetime, 'Y_m_d'));
} | [
"private",
"function",
"createDailyKey",
"(",
"$",
"prefix",
",",
"\\",
"DateTime",
"$",
"datetime",
"=",
"null",
")",
"{",
"return",
"sprintf",
"(",
"\"%s_%s\"",
",",
"$",
"prefix",
",",
"$",
"this",
"->",
"formatDate",
"(",
"$",
"datetime",
",",
"'Y_m_... | Create the daily key with prefix eg. 'total_2003_11_29'
@param string $prefix
@param \DateTime $datetime
@return string | [
"Create",
"the",
"daily",
"key",
"with",
"prefix",
"eg",
".",
"total_2003_11_29"
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/StatsBundle/Service/RedisPersister.php#L177-L180 |
PUGX/badge-poser | src/PUGX/StatsBundle/Service/RedisPersister.php | RedisPersister.formatDate | private function formatDate(\DateTime $datetime = null, $format = 'Y_m_d')
{
if (null == $datetime) {
$datetime = new \DateTime('now');
}
return $datetime->format($format);
} | php | private function formatDate(\DateTime $datetime = null, $format = 'Y_m_d')
{
if (null == $datetime) {
$datetime = new \DateTime('now');
}
return $datetime->format($format);
} | [
"private",
"function",
"formatDate",
"(",
"\\",
"DateTime",
"$",
"datetime",
"=",
"null",
",",
"$",
"format",
"=",
"'Y_m_d'",
")",
"{",
"if",
"(",
"null",
"==",
"$",
"datetime",
")",
"{",
"$",
"datetime",
"=",
"new",
"\\",
"DateTime",
"(",
"'now'",
"... | format a date.
@param \DateTime $datetime
@param string $format
@return string | [
"format",
"a",
"date",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/StatsBundle/Service/RedisPersister.php#L190-L197 |
PUGX/badge-poser | src/PUGX/BadgeBundle/Controller/PageController.php | PageController.homeAction | public function homeAction($repository)
{
$redisReader = $this->container->get('stats_reader');
$poser = $this->container->get('poser');
$prefix = sprintf('More than %s', number_format($redisReader->totalAccess()));
$text = 'badges served !!';
$formats = array_diff($poser->validFormats(), ["svg"]);
return array(
'repository' => $repository,
'badges_served_svg' => $poser->generate($prefix, $text, 'CC0066', 'flat'),
'formats' => $formats
);
} | php | public function homeAction($repository)
{
$redisReader = $this->container->get('stats_reader');
$poser = $this->container->get('poser');
$prefix = sprintf('More than %s', number_format($redisReader->totalAccess()));
$text = 'badges served !!';
$formats = array_diff($poser->validFormats(), ["svg"]);
return array(
'repository' => $repository,
'badges_served_svg' => $poser->generate($prefix, $text, 'CC0066', 'flat'),
'formats' => $formats
);
} | [
"public",
"function",
"homeAction",
"(",
"$",
"repository",
")",
"{",
"$",
"redisReader",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'stats_reader'",
")",
";",
"$",
"poser",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"'poser'",
... | @Route("/",
name = "pugx_page_home",
defaults = {"repository" = "phpunit/phpunit"}
)
@Route("/show/{repository}",
name = "pugx_page_home_show",
requirements = {"repository" = "[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"}
)
@Method({"GET"})
@Template
@Cache(maxage="3600", smaxage="3600", public=true)
@return Response | [
"@Route",
"(",
"/",
"name",
"=",
"pugx_page_home",
"defaults",
"=",
"{",
"repository",
"=",
"phpunit",
"/",
"phpunit",
"}",
")"
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/BadgeBundle/Controller/PageController.php#L45-L58 |
PUGX/badge-poser | src/PUGX/StatsBundle/Listener/StatsListener.php | StatsListener.persistData | public function persistData(Request $request, $controller)
{
if (null === ($repository = $request->get('repository', null)) || $this->isRoutedFromHome($request)) {
return;
}
$referer = $request->headers->get('referer');
$this->client->incrementTotalAccess();
$this->client->incrementRepositoryAccess($repository);
$this->client->addRepositoryToLatestAccessed($repository);
$this->client->incrementRepositoryAccessType($repository, $controller);
if ($referer) {
$this->client->addReferer($referer);
}
return true;
} | php | public function persistData(Request $request, $controller)
{
if (null === ($repository = $request->get('repository', null)) || $this->isRoutedFromHome($request)) {
return;
}
$referer = $request->headers->get('referer');
$this->client->incrementTotalAccess();
$this->client->incrementRepositoryAccess($repository);
$this->client->addRepositoryToLatestAccessed($repository);
$this->client->incrementRepositoryAccessType($repository, $controller);
if ($referer) {
$this->client->addReferer($referer);
}
return true;
} | [
"public",
"function",
"persistData",
"(",
"Request",
"$",
"request",
",",
"$",
"controller",
")",
"{",
"if",
"(",
"null",
"===",
"(",
"$",
"repository",
"=",
"$",
"request",
"->",
"get",
"(",
"'repository'",
",",
"null",
")",
")",
"||",
"$",
"this",
... | Persist data.
@param Request $request The request
@param string $controller The controller Name
@return Boolean | [
"Persist",
"data",
"."
] | train | https://github.com/PUGX/badge-poser/blob/7815b67791b05cd3b0e101bb977240b639a14143/src/PUGX/StatsBundle/Listener/StatsListener.php#L68-L84 |
kakserpom/phpdaemon | PHPDaemon/Examples/ExamplePubSubWebSocketRoute.php | ExamplePubSubWebSocketRoute.onFrame | public function onFrame($data, $type)
{
$ws = $this;
$req = json_decode($data, true);
if ($req['type'] === 'subscribe') {
$eventName = $req['event'];
$this->appInstance->pubsub->sub($req['event'], $this, function ($data) use ($ws, $eventName) {
$ws->sendObject([
'type' => 'event',
'event' => $eventName,
'data' => $data,
]);
});
}
} | php | public function onFrame($data, $type)
{
$ws = $this;
$req = json_decode($data, true);
if ($req['type'] === 'subscribe') {
$eventName = $req['event'];
$this->appInstance->pubsub->sub($req['event'], $this, function ($data) use ($ws, $eventName) {
$ws->sendObject([
'type' => 'event',
'event' => $eventName,
'data' => $data,
]);
});
}
} | [
"public",
"function",
"onFrame",
"(",
"$",
"data",
",",
"$",
"type",
")",
"{",
"$",
"ws",
"=",
"$",
"this",
";",
"$",
"req",
"=",
"json_decode",
"(",
"$",
"data",
",",
"true",
")",
";",
"if",
"(",
"$",
"req",
"[",
"'type'",
"]",
"===",
"'subscr... | Called when new frame received.
@param string Frame's contents.
@param integer Frame's type.
@return void | [
"Called",
"when",
"new",
"frame",
"received",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Examples/ExamplePubSubWebSocketRoute.php#L14-L28 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Basic/BasicRecoverFrame.php | BasicRecoverFrame.create | public static function create(
$requeue = null
)
{
$frame = new self();
if (null !== $requeue) {
$frame->requeue = $requeue;
}
return $frame;
} | php | public static function create(
$requeue = null
)
{
$frame = new self();
if (null !== $requeue) {
$frame->requeue = $requeue;
}
return $frame;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"requeue",
"=",
"null",
")",
"{",
"$",
"frame",
"=",
"new",
"self",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"requeue",
")",
"{",
"$",
"frame",
"->",
"requeue",
"=",
"$",
"requeue",
";",
"}... | bit | [
"bit"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Basic/BasicRecoverFrame.php#L20-L31 |
kakserpom/phpdaemon | PHPDaemon/SockJS/Methods/Jsonp.php | Jsonp.sendFrame | protected function sendFrame($frame)
{
$c = &$this->attrs->get['c'];
if (!is_string($c)) {
$this->header('400 Bad Request');
$this->finish();
return;
}
$this->outputFrame($c . '(' . json_encode($frame, JSON_UNESCAPED_SLASHES) . ");\r\n");
parent::sendFrame($frame);
} | php | protected function sendFrame($frame)
{
$c = &$this->attrs->get['c'];
if (!is_string($c)) {
$this->header('400 Bad Request');
$this->finish();
return;
}
$this->outputFrame($c . '(' . json_encode($frame, JSON_UNESCAPED_SLASHES) . ");\r\n");
parent::sendFrame($frame);
} | [
"protected",
"function",
"sendFrame",
"(",
"$",
"frame",
")",
"{",
"$",
"c",
"=",
"&",
"$",
"this",
"->",
"attrs",
"->",
"get",
"[",
"'c'",
"]",
";",
"if",
"(",
"!",
"is_string",
"(",
"$",
"c",
")",
")",
"{",
"$",
"this",
"->",
"header",
"(",
... | Send frame
@param string $frame
@return void | [
"Send",
"frame"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/Jsonp.php#L22-L32 |
kakserpom/phpdaemon | PHPDaemon/Servers/Ident/Pool.php | Pool.RPCall | public function RPCall($method, $args)
{
if ($method === 'registerPair') {
list($local, $foreign, $user) = $args;
$this->pairs[$local . ':' . $foreign] = $user;
} elseif ($method === 'unregisterPair') {
list($local, $foreign) = $args;
unset($this->pairs[$local . ':' . $foreign]);
}
} | php | public function RPCall($method, $args)
{
if ($method === 'registerPair') {
list($local, $foreign, $user) = $args;
$this->pairs[$local . ':' . $foreign] = $user;
} elseif ($method === 'unregisterPair') {
list($local, $foreign) = $args;
unset($this->pairs[$local . ':' . $foreign]);
}
} | [
"public",
"function",
"RPCall",
"(",
"$",
"method",
",",
"$",
"args",
")",
"{",
"if",
"(",
"$",
"method",
"===",
"'registerPair'",
")",
"{",
"list",
"(",
"$",
"local",
",",
"$",
"foreign",
",",
"$",
"user",
")",
"=",
"$",
"args",
";",
"$",
"this"... | Function handles incoming Remote Procedure Calls
You can override it
@param string $method Method name.
@param array $args Arguments.
@return void | [
"Function",
"handles",
"incoming",
"Remote",
"Procedure",
"Calls",
"You",
"can",
"override",
"it"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/Ident/Pool.php#L21-L30 |
kakserpom/phpdaemon | PHPDaemon/Servers/Ident/Pool.php | Pool.registerPair | public function registerPair($local, $foreign, $user)
{
$this->appInstance->broadcastCall('registerPair', [
$local,
$foreign,
is_array($user) ? implode(' : ', $user) : $user
]);
} | php | public function registerPair($local, $foreign, $user)
{
$this->appInstance->broadcastCall('registerPair', [
$local,
$foreign,
is_array($user) ? implode(' : ', $user) : $user
]);
} | [
"public",
"function",
"registerPair",
"(",
"$",
"local",
",",
"$",
"foreign",
",",
"$",
"user",
")",
"{",
"$",
"this",
"->",
"appInstance",
"->",
"broadcastCall",
"(",
"'registerPair'",
",",
"[",
"$",
"local",
",",
"$",
"foreign",
",",
"is_array",
"(",
... | Register pair
@param integer $local Local
@param integer $foreign Foreign
@param string $user User
@return void | [
"Register",
"pair"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/Ident/Pool.php#L40-L47 |
kakserpom/phpdaemon | PHPDaemon/Servers/Ident/Pool.php | Pool.findPair | public function findPair($local, $foreign)
{
$k = $local . ':' . $foreign;
return
isset($this->pairs[$k])
? $this->pairs[$k]
: false;
} | php | public function findPair($local, $foreign)
{
$k = $local . ':' . $foreign;
return
isset($this->pairs[$k])
? $this->pairs[$k]
: false;
} | [
"public",
"function",
"findPair",
"(",
"$",
"local",
",",
"$",
"foreign",
")",
"{",
"$",
"k",
"=",
"$",
"local",
".",
"':'",
".",
"$",
"foreign",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"pairs",
"[",
"$",
"k",
"]",
")",
"?",
"$",
"this"... | Find pair
@param integer $local Local
@param integer $foreign Foreign
@return string User | [
"Find",
"pair"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/Ident/Pool.php#L66-L73 |
kakserpom/phpdaemon | PHPDaemon/Config/Entry/Number.php | Number.humanToPlain | public static function humanToPlain($value)
{
if ($value === null) {
return null;
}
$l = substr($value, -1);
if (($l === 'k') || ($l === 'K')) {
return ((int)substr($value, 0, -1) * 1000);
}
if (($l === 'm') || ($l === 'M')) {
return ((int)substr($value, 0, -1) * 1000 * 1000);
}
if (($l === 'g') || ($l === 'G')) {
return ((int)substr($value, 0, -1) * 1000 * 1000 * 1000);
}
return (int)$value;
} | php | public static function humanToPlain($value)
{
if ($value === null) {
return null;
}
$l = substr($value, -1);
if (($l === 'k') || ($l === 'K')) {
return ((int)substr($value, 0, -1) * 1000);
}
if (($l === 'm') || ($l === 'M')) {
return ((int)substr($value, 0, -1) * 1000 * 1000);
}
if (($l === 'g') || ($l === 'G')) {
return ((int)substr($value, 0, -1) * 1000 * 1000 * 1000);
}
return (int)$value;
} | [
"public",
"static",
"function",
"humanToPlain",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"$",
"l",
"=",
"substr",
"(",
"$",
"value",
",",
"-",
"1",
")",
";",
"if",
"(",
"(",
"$",... | Converts human-readable value to plain
@param $value
@return int|null | [
"Converts",
"human",
"-",
"readable",
"value",
"to",
"plain"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Config/Entry/Number.php#L20-L39 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Exchange/ExchangeDeclareFrame.php | ExchangeDeclareFrame.create | public static function create(
$exchange = null, $type = null, $passive = null, $durable = null, $autoDelete = null, $internal = null, $nowait = null, $arguments = null
)
{
$frame = new self();
if (null !== $exchange) {
$frame->exchange = $exchange;
}
if (null !== $type) {
$frame->type = $type;
}
if (null !== $passive) {
$frame->passive = $passive;
}
if (null !== $durable) {
$frame->durable = $durable;
}
if (null !== $autoDelete) {
$frame->autoDelete = $autoDelete;
}
if (null !== $internal) {
$frame->internal = $internal;
}
if (null !== $nowait) {
$frame->nowait = $nowait;
}
if (null !== $arguments) {
$frame->arguments = $arguments;
}
return $frame;
} | php | public static function create(
$exchange = null, $type = null, $passive = null, $durable = null, $autoDelete = null, $internal = null, $nowait = null, $arguments = null
)
{
$frame = new self();
if (null !== $exchange) {
$frame->exchange = $exchange;
}
if (null !== $type) {
$frame->type = $type;
}
if (null !== $passive) {
$frame->passive = $passive;
}
if (null !== $durable) {
$frame->durable = $durable;
}
if (null !== $autoDelete) {
$frame->autoDelete = $autoDelete;
}
if (null !== $internal) {
$frame->internal = $internal;
}
if (null !== $nowait) {
$frame->nowait = $nowait;
}
if (null !== $arguments) {
$frame->arguments = $arguments;
}
return $frame;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"exchange",
"=",
"null",
",",
"$",
"type",
"=",
"null",
",",
"$",
"passive",
"=",
"null",
",",
"$",
"durable",
"=",
"null",
",",
"$",
"autoDelete",
"=",
"null",
",",
"$",
"internal",
"=",
"null",
... | table | [
"table"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Exchange/ExchangeDeclareFrame.php#L28-L60 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Serializer/Table.php | Table.serialize | public function serialize(array $table)
{
$buffer = '';
foreach ($table as $key => $value) {
$buffer .= $this->serializeShortString($key);
$buffer .= $this->serializeField($value);
}
return $this->serializeByteArray($buffer);
} | php | public function serialize(array $table)
{
$buffer = '';
foreach ($table as $key => $value) {
$buffer .= $this->serializeShortString($key);
$buffer .= $this->serializeField($value);
}
return $this->serializeByteArray($buffer);
} | [
"public",
"function",
"serialize",
"(",
"array",
"$",
"table",
")",
"{",
"$",
"buffer",
"=",
"''",
";",
"foreach",
"(",
"$",
"table",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"buffer",
".=",
"$",
"this",
"->",
"serializeShortString",
"(",... | Serialize an AMQP table.
@param array $table The table.
@return string The binary serialized table.
@throws InvalidArgumentException if the table contains unserializable
values. | [
"Serialize",
"an",
"AMQP",
"table",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Serializer/Table.php#L31-L41 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Serializer/Table.php | Table.serializeField | private function serializeField($value)
{
if (is_string($value)) {
// @todo Could be decimal (D) or byte array (x)
// @see https://github.com/recoilphp/amqp/issues/25
return 'S' . $this->serializeLongString($value);
}
if (is_int($value)) {
// @todo Could be timestamp (T)
// @see https://github.com/recoilphp/amqp/issues/25
if ($value >= 0) {
if ($value < 0x80) {
return 'b' . $this->serializeSignedInt8($value);
}
if ($value < 0x8000) {
return 's' . $this->serializeSignedInt16($value);
}
if ($value < 0x80000000) {
return 'I' . $this->serializeSignedInt32($value);
}
} else {
if ($value >= -0x80) {
return 'b' . $this->serializeSignedInt8($value);
}
if ($value >= -0x8000) {
return 's' . $this->serializeSignedInt16($value);
}
if ($value >= -0x80000000) {
return 'I' . $this->serializeSignedInt32($value);
}
}
return 'l' . $this->serializeSignedInt64($value);
}
if (true === $value) {
return "t\x01";
}
if (false === $value) {
return "t\x00";
}
if (null === $value) {
return 'V';
}
if (is_float($value)) {
return 'd' . $this->serializeDouble($value);
}
if (is_array($value)) {
return $this->serializeArrayOrTable($value);
}
throw new InvalidArgumentException(
'Could not serialize value (' . chr($value) . ').'
);
} | php | private function serializeField($value)
{
if (is_string($value)) {
// @todo Could be decimal (D) or byte array (x)
// @see https://github.com/recoilphp/amqp/issues/25
return 'S' . $this->serializeLongString($value);
}
if (is_int($value)) {
// @todo Could be timestamp (T)
// @see https://github.com/recoilphp/amqp/issues/25
if ($value >= 0) {
if ($value < 0x80) {
return 'b' . $this->serializeSignedInt8($value);
}
if ($value < 0x8000) {
return 's' . $this->serializeSignedInt16($value);
}
if ($value < 0x80000000) {
return 'I' . $this->serializeSignedInt32($value);
}
} else {
if ($value >= -0x80) {
return 'b' . $this->serializeSignedInt8($value);
}
if ($value >= -0x8000) {
return 's' . $this->serializeSignedInt16($value);
}
if ($value >= -0x80000000) {
return 'I' . $this->serializeSignedInt32($value);
}
}
return 'l' . $this->serializeSignedInt64($value);
}
if (true === $value) {
return "t\x01";
}
if (false === $value) {
return "t\x00";
}
if (null === $value) {
return 'V';
}
if (is_float($value)) {
return 'd' . $this->serializeDouble($value);
}
if (is_array($value)) {
return $this->serializeArrayOrTable($value);
}
throw new InvalidArgumentException(
'Could not serialize value (' . chr($value) . ').'
);
} | [
"private",
"function",
"serializeField",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
")",
"{",
"// @todo Could be decimal (D) or byte array (x)",
"// @see https://github.com/recoilphp/amqp/issues/25",
"return",
"'S'",
".",
"$",
"this",
... | Serialize a table or array field.
@param mixed $value
@return string The serialized value.
@throws \InvalidArgumentException | [
"Serialize",
"a",
"table",
"or",
"array",
"field",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Serializer/Table.php#L51-L103 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Serializer/Table.php | Table.serializeArrayOrTable | private function serializeArrayOrTable(array $array)
{
$assoc = false;
$index = 0;
$values = [];
foreach ($array as $key => $value) {
// We already know the array is associative, serialize both the key
// and the value ...
if ($assoc) {
$values[] = $this->serializeShortString($key)
. $this->serializeField($value);
// Otherwise, if the key matches the index counter it is sequential,
// only serialize the value ...
} elseif ($key === $index++) {
$values[] = $this->serializeField($value);
// Otherwise, we've just discovered the array is NOT sequential,
// Go back through the existing values and add the keys ...
} else {
foreach ($values as $k => $v) {
$values[$k] = $this->serializeShortString($k) . $v;
}
$values[] = $this->serializeShortString($key)
. $this->serializeField($value);
$assoc = true;
}
}
return ($assoc ? 'F' : 'A') . $this->serializeByteArray(
implode('', $values)
);
} | php | private function serializeArrayOrTable(array $array)
{
$assoc = false;
$index = 0;
$values = [];
foreach ($array as $key => $value) {
// We already know the array is associative, serialize both the key
// and the value ...
if ($assoc) {
$values[] = $this->serializeShortString($key)
. $this->serializeField($value);
// Otherwise, if the key matches the index counter it is sequential,
// only serialize the value ...
} elseif ($key === $index++) {
$values[] = $this->serializeField($value);
// Otherwise, we've just discovered the array is NOT sequential,
// Go back through the existing values and add the keys ...
} else {
foreach ($values as $k => $v) {
$values[$k] = $this->serializeShortString($k) . $v;
}
$values[] = $this->serializeShortString($key)
. $this->serializeField($value);
$assoc = true;
}
}
return ($assoc ? 'F' : 'A') . $this->serializeByteArray(
implode('', $values)
);
} | [
"private",
"function",
"serializeArrayOrTable",
"(",
"array",
"$",
"array",
")",
"{",
"$",
"assoc",
"=",
"false",
";",
"$",
"index",
"=",
"0",
";",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"value... | Serialize a PHP array.
If the array contains sequential integer keys, it is serialized as an AMQP
array, otherwise it is serialized as an AMQP table.
@param array $array
@return string The binary serialized table.
@throws \InvalidArgumentException | [
"Serialize",
"a",
"PHP",
"array",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Serializer/Table.php#L116-L151 |
kakserpom/phpdaemon | PHPDaemon/Servers/Socks/Connection.php | Connection.onRead | public function onRead()
{
if ($this->state === self::STATE_DATAFLOW) {
// Data exchange
if ($this->slave) {
do {
$this->slave->writeFromBuffer($this->bev->input, $this->bev->input->length);
} while ($this->bev->input->length > 0);
}
return;
}
start:
$l = $this->bev->input->length;
if ($this->state === self::STATE_ROOT) {
// Start
if ($l < 2) {
// Not enough data yet
return;
}
$n = ord($this->look(1, 1));
if ($l < $n + 2) {
// Not enough data yet
return;
}
$this->ver = $this->look(1);
$this->drain(2);
$methods = $this->read($n);
if (!$this->pool->config->auth->value) {
// No auth
$m = "\x00";
$this->state = self::STATE_AUTHORIZED;
} elseif (mb_orig_strpos($methods, "\x02") !== false) {
// Username/Password authentication
$m = "\x02";
$this->state = self::STATE_HANDSHAKED;
} else {
// No allowed methods
$m = "\xFF";
$this->state = self::STATE_ABORTED;
}
$this->write($this->ver . $m);
if ($this->state === self::STATE_ABORTED) {
$this->finish();
} else {
goto start;
}
} elseif ($this->state === self::STATE_HANDSHAKED) {
// Handshaked
if ($l < 3) {
// Not enough data yet
return;
}
$ver = $this->look(1);
if ($ver !== $this->ver) {
$this->finish();
return;
}
$ulen = ord($this->look(1, 1));
if ($l < 3 + $ulen) {
// Not enough data yet
return;
}
$username = $this->look(2, $ulen);
$plen = ord($this->look(2 + $ulen, 1));
if ($l < 3 + $ulen + $plen) {
// Not enough data yet
return;
}
$this->drain(3 + $ulen);
$password = $this->read($plen);
if (($username !== $this->pool->config->username->value)
|| ($password !== $this->pool->config->password->value)
) {
$this->state = self::STATE_ABORTED;
$m = "\x01";
} else {
$this->state = self::STATE_AUTHORIZED;
$m = "\x00";
}
$this->write($this->ver . $m);
if ($this->state === self::STATE_ABORTED) {
$this->finish();
} else {
goto start;
}
} elseif ($this->state === self::STATE_AUTHORIZED) {
// Ready for query
if ($l < 4) {
// Not enough data yet
return;
}
$ver = $this->read(1);
if ($ver !== $this->ver) {
$this->finish();
return;
}
$cmd = $this->read(1);
$this->drain(1);
$atype = $this->read(1);
if ($atype === "\x01") {
$address = inet_ntop($this->read(4));
} elseif ($atype === "\x03") {
$len = ord($this->read(1));
$address = $this->read($len);
} elseif ($atype === "\x04") {
$address = inet_ntop($this->read(16));
} else {
$this->finish();
return;
}
$u = unpack('nport', $this->read(2));
$port = $u['port'];
$this->destAddr = $address;
$this->destPort = $port;
$this->pool->connect('tcp://' . $this->destAddr . ':' . $this->destPort, function ($conn) {
if (!$conn) {
// Early connection error
$this->write($this->ver . "\x05");
$this->finish();
} else {
$conn->setClient($this);
$this->state = self::STATE_DATAFLOW;
$conn->getSocketName($addr, $port);
$this->slave = $conn;
$this->onSlaveReady(0x00, $addr, $port);
$this->onReadEv(null);
}
}, 'SocksServerSlaveConnection');
}
} | php | public function onRead()
{
if ($this->state === self::STATE_DATAFLOW) {
// Data exchange
if ($this->slave) {
do {
$this->slave->writeFromBuffer($this->bev->input, $this->bev->input->length);
} while ($this->bev->input->length > 0);
}
return;
}
start:
$l = $this->bev->input->length;
if ($this->state === self::STATE_ROOT) {
// Start
if ($l < 2) {
// Not enough data yet
return;
}
$n = ord($this->look(1, 1));
if ($l < $n + 2) {
// Not enough data yet
return;
}
$this->ver = $this->look(1);
$this->drain(2);
$methods = $this->read($n);
if (!$this->pool->config->auth->value) {
// No auth
$m = "\x00";
$this->state = self::STATE_AUTHORIZED;
} elseif (mb_orig_strpos($methods, "\x02") !== false) {
// Username/Password authentication
$m = "\x02";
$this->state = self::STATE_HANDSHAKED;
} else {
// No allowed methods
$m = "\xFF";
$this->state = self::STATE_ABORTED;
}
$this->write($this->ver . $m);
if ($this->state === self::STATE_ABORTED) {
$this->finish();
} else {
goto start;
}
} elseif ($this->state === self::STATE_HANDSHAKED) {
// Handshaked
if ($l < 3) {
// Not enough data yet
return;
}
$ver = $this->look(1);
if ($ver !== $this->ver) {
$this->finish();
return;
}
$ulen = ord($this->look(1, 1));
if ($l < 3 + $ulen) {
// Not enough data yet
return;
}
$username = $this->look(2, $ulen);
$plen = ord($this->look(2 + $ulen, 1));
if ($l < 3 + $ulen + $plen) {
// Not enough data yet
return;
}
$this->drain(3 + $ulen);
$password = $this->read($plen);
if (($username !== $this->pool->config->username->value)
|| ($password !== $this->pool->config->password->value)
) {
$this->state = self::STATE_ABORTED;
$m = "\x01";
} else {
$this->state = self::STATE_AUTHORIZED;
$m = "\x00";
}
$this->write($this->ver . $m);
if ($this->state === self::STATE_ABORTED) {
$this->finish();
} else {
goto start;
}
} elseif ($this->state === self::STATE_AUTHORIZED) {
// Ready for query
if ($l < 4) {
// Not enough data yet
return;
}
$ver = $this->read(1);
if ($ver !== $this->ver) {
$this->finish();
return;
}
$cmd = $this->read(1);
$this->drain(1);
$atype = $this->read(1);
if ($atype === "\x01") {
$address = inet_ntop($this->read(4));
} elseif ($atype === "\x03") {
$len = ord($this->read(1));
$address = $this->read($len);
} elseif ($atype === "\x04") {
$address = inet_ntop($this->read(16));
} else {
$this->finish();
return;
}
$u = unpack('nport', $this->read(2));
$port = $u['port'];
$this->destAddr = $address;
$this->destPort = $port;
$this->pool->connect('tcp://' . $this->destAddr . ':' . $this->destPort, function ($conn) {
if (!$conn) {
// Early connection error
$this->write($this->ver . "\x05");
$this->finish();
} else {
$conn->setClient($this);
$this->state = self::STATE_DATAFLOW;
$conn->getSocketName($addr, $port);
$this->slave = $conn;
$this->onSlaveReady(0x00, $addr, $port);
$this->onReadEv(null);
}
}, 'SocksServerSlaveConnection');
}
} | [
"public",
"function",
"onRead",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"state",
"===",
"self",
"::",
"STATE_DATAFLOW",
")",
"{",
"// Data exchange",
"if",
"(",
"$",
"this",
"->",
"slave",
")",
"{",
"do",
"{",
"$",
"this",
"->",
"slave",
"->",
... | Called when new data received.
@return void | [
"Called",
"when",
"new",
"data",
"received",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Servers/Socks/Connection.php#L43-L189 |
kakserpom/phpdaemon | PHPDaemon/SockJS/Methods/Generic.php | Generic.init | public function init()
{
$this->sessId = $this->attrs->sessId;
$this->serverId = $this->attrs->serverId;
$this->path = $this->attrs->path;
// @TODO: revert timeout after request
$this->upstream->setTimeouts($this->appInstance->config->networktimeoutread->value,
$this->appInstance->config->networktimeoutwrite->value);
$this->opts = $this->appInstance->getRouteOptions($this->attrs->path);
$this->CORS();
if ($this->isFinished()) {
return;
}
if ($this->opts['cookie_needed'] && !$this instanceof Info) {
if (isset($_COOKIE['JSESSIONID'])) {
$val = $_COOKIE['JSESSIONID'];
if (!is_string($val) || $val === '') {
$val = 'dummy';
}
} else {
$val = 'dummy';
}
$this->setcookie('JSESSIONID', $val, 0, '/');
}
$this->contentType($this->contentType);
if (!$this->cacheable) {
$this->noncache();
$this->header('X-Accel-Buffering: no');
}
if ($this->callbackParamEnabled) {
if (!isset($_GET['c']) || !is_string($_GET['c']) || preg_match('~[^_\.a-zA-Z0-9]~', $_GET['c'])) {
$this->header('500 Internal Server Error');
$this->out('"callback" parameter required');
$this->finish();
return;
}
}
if (($f = $this->appInstance->config->heartbeatinterval->value) > 0) {
$this->heartbeatTimer = setTimeout(function ($timer) {
if (in_array('one-by-one', $this->pollMode)) {
$this->heartbeatOnFinish = true;
$this->stop();
return;
}
$this->sendFrame('h');
if ($this->gcEnabled) {
$this->gcCheck();
}
}, $f * 1e6);
}
$this->afterHeaders();
if ($this->poll) {
$this->acquire(function () {
$this->poll();
});
}
} | php | public function init()
{
$this->sessId = $this->attrs->sessId;
$this->serverId = $this->attrs->serverId;
$this->path = $this->attrs->path;
// @TODO: revert timeout after request
$this->upstream->setTimeouts($this->appInstance->config->networktimeoutread->value,
$this->appInstance->config->networktimeoutwrite->value);
$this->opts = $this->appInstance->getRouteOptions($this->attrs->path);
$this->CORS();
if ($this->isFinished()) {
return;
}
if ($this->opts['cookie_needed'] && !$this instanceof Info) {
if (isset($_COOKIE['JSESSIONID'])) {
$val = $_COOKIE['JSESSIONID'];
if (!is_string($val) || $val === '') {
$val = 'dummy';
}
} else {
$val = 'dummy';
}
$this->setcookie('JSESSIONID', $val, 0, '/');
}
$this->contentType($this->contentType);
if (!$this->cacheable) {
$this->noncache();
$this->header('X-Accel-Buffering: no');
}
if ($this->callbackParamEnabled) {
if (!isset($_GET['c']) || !is_string($_GET['c']) || preg_match('~[^_\.a-zA-Z0-9]~', $_GET['c'])) {
$this->header('500 Internal Server Error');
$this->out('"callback" parameter required');
$this->finish();
return;
}
}
if (($f = $this->appInstance->config->heartbeatinterval->value) > 0) {
$this->heartbeatTimer = setTimeout(function ($timer) {
if (in_array('one-by-one', $this->pollMode)) {
$this->heartbeatOnFinish = true;
$this->stop();
return;
}
$this->sendFrame('h');
if ($this->gcEnabled) {
$this->gcCheck();
}
}, $f * 1e6);
}
$this->afterHeaders();
if ($this->poll) {
$this->acquire(function () {
$this->poll();
});
}
} | [
"public",
"function",
"init",
"(",
")",
"{",
"$",
"this",
"->",
"sessId",
"=",
"$",
"this",
"->",
"attrs",
"->",
"sessId",
";",
"$",
"this",
"->",
"serverId",
"=",
"$",
"this",
"->",
"attrs",
"->",
"serverId",
";",
"$",
"this",
"->",
"path",
"=",
... | Constructor
@return void | [
"Constructor"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/Generic.php#L51-L109 |
kakserpom/phpdaemon | PHPDaemon/SockJS/Methods/Generic.php | Generic.CORS | protected function CORS()
{
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
$this->header('Access-Control-Allow-Headers: ' . $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
}
if (isset($_SERVER['HTTP_ORIGIN']) && $_SERVER['HTTP_ORIGIN'] !== 'null') {
$this->header('Access-Control-Allow-Origin:' . $_SERVER['HTTP_ORIGIN']);
} else {
$this->header('Access-Control-Allow-Origin: *');
}
$this->header('Access-Control-Allow-Credentials: true');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
$this->header('204 No Content');
$this->header('Cache-Control: max-age=31536000, public, pre-check=0, post-check=0');
$this->header('Access-Control-Max-Age: 31536000');
$this->header('Access-Control-Allow-Methods: OPTIONS, ' . $this->allowedMethods);
$this->header('Expires: ' . date('r', strtotime('+1 year')));
$this->finish();
} elseif (!in_array($_SERVER['REQUEST_METHOD'], explode(', ', $this->allowedMethods), true)) {
$this->header('405 Method Not Allowed');
$this->finish();
}
} | php | protected function CORS()
{
if (isset($_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS'])) {
$this->header('Access-Control-Allow-Headers: ' . $_SERVER['HTTP_ACCESS_CONTROL_REQUEST_HEADERS']);
}
if (isset($_SERVER['HTTP_ORIGIN']) && $_SERVER['HTTP_ORIGIN'] !== 'null') {
$this->header('Access-Control-Allow-Origin:' . $_SERVER['HTTP_ORIGIN']);
} else {
$this->header('Access-Control-Allow-Origin: *');
}
$this->header('Access-Control-Allow-Credentials: true');
if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
$this->header('204 No Content');
$this->header('Cache-Control: max-age=31536000, public, pre-check=0, post-check=0');
$this->header('Access-Control-Max-Age: 31536000');
$this->header('Access-Control-Allow-Methods: OPTIONS, ' . $this->allowedMethods);
$this->header('Expires: ' . date('r', strtotime('+1 year')));
$this->finish();
} elseif (!in_array($_SERVER['REQUEST_METHOD'], explode(', ', $this->allowedMethods), true)) {
$this->header('405 Method Not Allowed');
$this->finish();
}
} | [
"protected",
"function",
"CORS",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCESS_CONTROL_REQUEST_HEADERS'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"header",
"(",
"'Access-Control-Allow-Headers: '",
".",
"$",
"_SERVER",
"[",
"'HTTP_AC... | CORS
@return void | [
"CORS"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/Generic.php#L115-L137 |
kakserpom/phpdaemon | PHPDaemon/SockJS/Methods/Generic.php | Generic.out | public function out($s, $flush = true)
{
if ($this->heartbeatTimer !== null) {
Timer::setTimeout($this->heartbeatTimer);
}
return parent::out($s, $flush);;
} | php | public function out($s, $flush = true)
{
if ($this->heartbeatTimer !== null) {
Timer::setTimeout($this->heartbeatTimer);
}
return parent::out($s, $flush);;
} | [
"public",
"function",
"out",
"(",
"$",
"s",
",",
"$",
"flush",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"heartbeatTimer",
"!==",
"null",
")",
"{",
"Timer",
"::",
"setTimeout",
"(",
"$",
"this",
"->",
"heartbeatTimer",
")",
";",
"}",
"re... | Output some data
@param string $s String to out
@param boolean $flush
@return boolean Success | [
"Output",
"some",
"data"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/Generic.php#L165-L171 |
kakserpom/phpdaemon | PHPDaemon/SockJS/Methods/Generic.php | Generic.stop | public function stop()
{
if ($this->stopped) {
return;
}
$this->stopped = true;
if (in_array('one-by-one', $this->pollMode)) {
$this->finish();
return;
}
$this->appInstance->unsubscribeReal('s2c:' . $this->sessId, function ($redis) {
$this->finish();
});
} | php | public function stop()
{
if ($this->stopped) {
return;
}
$this->stopped = true;
if (in_array('one-by-one', $this->pollMode)) {
$this->finish();
return;
}
$this->appInstance->unsubscribeReal('s2c:' . $this->sessId, function ($redis) {
$this->finish();
});
} | [
"public",
"function",
"stop",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"stopped",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"stopped",
"=",
"true",
";",
"if",
"(",
"in_array",
"(",
"'one-by-one'",
",",
"$",
"this",
"->",
"pollMode",
")",... | Stop
@return void | [
"Stop"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/Generic.php#L177-L190 |
kakserpom/phpdaemon | PHPDaemon/SockJS/Methods/Generic.php | Generic.gcCheck | public function gcCheck()
{
if ($this->stopped) {
return;
}
$max = $this->appInstance->config->gcmaxresponsesize->value;
if ($max > 0 && $this->bytesSent > $max) {
$this->stop();
}
} | php | public function gcCheck()
{
if ($this->stopped) {
return;
}
$max = $this->appInstance->config->gcmaxresponsesize->value;
if ($max > 0 && $this->bytesSent > $max) {
$this->stop();
}
} | [
"public",
"function",
"gcCheck",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"stopped",
")",
"{",
"return",
";",
"}",
"$",
"max",
"=",
"$",
"this",
"->",
"appInstance",
"->",
"config",
"->",
"gcmaxresponsesize",
"->",
"value",
";",
"if",
"(",
"$",
... | gcCheck
@return void | [
"gcCheck"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/Generic.php#L208-L217 |
kakserpom/phpdaemon | PHPDaemon/SockJS/Methods/Generic.php | Generic.acquire | protected function acquire($cb)
{
$this->appInstance->getkey('error:' . $this->sessId, function ($redis) use ($cb) {
if (!$redis) {
$this->internalServerError();
return;
}
if ($redis->result !== null) {
$this->error((int)$redis->result);
return;
}
if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 0) {
$this->anotherConnectionStillOpen();
return;
}
$this->appInstance->publish('w8in:' . $this->sessId, '', function ($redis) use ($cb) {
if (!$redis) {
$this->internalServerError();
return;
}
if ($redis->result > 0) {
$this->anotherConnectionStillOpen();
return;
}
$this->appInstance->subscribe('w8in:' . $this->sessId, [$this, 'w8in'], function ($redis) use ($cb) {
if (!$redis) {
$this->internalServerError();
return;
}
if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 1) {
$this->anotherConnectionStillOpen();
return;
}
$this->appInstance->publish('w8in:' . $this->sessId, '', function ($redis) use ($cb) {
if (!$redis) {
$this->internalServerError();
return;
}
if ($redis->result > 1) {
$this->anotherConnectionStillOpen();
return;
}
if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 1) {
$this->anotherConnectionStillOpen();
return;
}
$cb === null || $cb();
});
});
});
});
} | php | protected function acquire($cb)
{
$this->appInstance->getkey('error:' . $this->sessId, function ($redis) use ($cb) {
if (!$redis) {
$this->internalServerError();
return;
}
if ($redis->result !== null) {
$this->error((int)$redis->result);
return;
}
if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 0) {
$this->anotherConnectionStillOpen();
return;
}
$this->appInstance->publish('w8in:' . $this->sessId, '', function ($redis) use ($cb) {
if (!$redis) {
$this->internalServerError();
return;
}
if ($redis->result > 0) {
$this->anotherConnectionStillOpen();
return;
}
$this->appInstance->subscribe('w8in:' . $this->sessId, [$this, 'w8in'], function ($redis) use ($cb) {
if (!$redis) {
$this->internalServerError();
return;
}
if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 1) {
$this->anotherConnectionStillOpen();
return;
}
$this->appInstance->publish('w8in:' . $this->sessId, '', function ($redis) use ($cb) {
if (!$redis) {
$this->internalServerError();
return;
}
if ($redis->result > 1) {
$this->anotherConnectionStillOpen();
return;
}
if ($this->appInstance->getLocalSubscribersCount('w8in:' . $this->sessId) > 1) {
$this->anotherConnectionStillOpen();
return;
}
$cb === null || $cb();
});
});
});
});
} | [
"protected",
"function",
"acquire",
"(",
"$",
"cb",
")",
"{",
"$",
"this",
"->",
"appInstance",
"->",
"getkey",
"(",
"'error:'",
".",
"$",
"this",
"->",
"sessId",
",",
"function",
"(",
"$",
"redis",
")",
"use",
"(",
"$",
"cb",
")",
"{",
"if",
"(",
... | acquire
@param callable $cb
@callback $cb ( )
@return void | [
"acquire"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/Generic.php#L233-L284 |
kakserpom/phpdaemon | PHPDaemon/SockJS/Methods/Generic.php | Generic.error | protected function error($code)
{
$this->sendFrame('c' . json_encode([$code, isset($this->errors[$code]) ? $this->errors[$code] : null]));
} | php | protected function error($code)
{
$this->sendFrame('c' . json_encode([$code, isset($this->errors[$code]) ? $this->errors[$code] : null]));
} | [
"protected",
"function",
"error",
"(",
"$",
"code",
")",
"{",
"$",
"this",
"->",
"sendFrame",
"(",
"'c'",
".",
"json_encode",
"(",
"[",
"$",
"code",
",",
"isset",
"(",
"$",
"this",
"->",
"errors",
"[",
"$",
"code",
"]",
")",
"?",
"$",
"this",
"->... | error
@param integer $code
@return void | [
"error"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/Generic.php#L302-L305 |
kakserpom/phpdaemon | PHPDaemon/SockJS/Methods/Generic.php | Generic.anotherConnectionStillOpen | protected function anotherConnectionStillOpen()
{
$this->appInstance->setkey('error:' . $this->sessId, 1002, function () {
$this->appInstance->expire('error:' . $this->sessId, $this->appInstance->config->deadsessiontimeout->value,
function () {
$this->error(2010);
});
});
} | php | protected function anotherConnectionStillOpen()
{
$this->appInstance->setkey('error:' . $this->sessId, 1002, function () {
$this->appInstance->expire('error:' . $this->sessId, $this->appInstance->config->deadsessiontimeout->value,
function () {
$this->error(2010);
});
});
} | [
"protected",
"function",
"anotherConnectionStillOpen",
"(",
")",
"{",
"$",
"this",
"->",
"appInstance",
"->",
"setkey",
"(",
"'error:'",
".",
"$",
"this",
"->",
"sessId",
",",
"1002",
",",
"function",
"(",
")",
"{",
"$",
"this",
"->",
"appInstance",
"->",
... | anotherConnectionStillOpen
@return void | [
"anotherConnectionStillOpen"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/Generic.php#L311-L319 |
kakserpom/phpdaemon | PHPDaemon/SockJS/Methods/Generic.php | Generic.poll | protected function poll($cb = null)
{
$this->appInstance->subscribe('s2c:' . $this->sessId, [$this, 's2c'], function ($redis) use ($cb) {
$this->appInstance->publish('poll:' . $this->sessId, json_encode($this->pollMode),
function ($redis) use ($cb) {
if (!$redis) {
$cb === null || $cb();
return;
}
if ($redis->result > 0) {
$cb === null || $cb();
return;
}
$this->appInstance->setnx('sess:' . $this->sessId, $this->attrs->server['REQUEST_URI'],
function ($redis) use ($cb) {
if (!$redis || $redis->result === 0) {
$this->error(3000);
$cb === null || $cb();
return;
}
$this->appInstance->expire('sess:' . $this->sessId,
$this->appInstance->config->deadsessiontimeout->value, function ($redis) use ($cb) {
if (!$redis || $redis->result === 0) {
$this->error(3000);
$cb === null || $cb();
return;
}
$this->appInstance->subscribe('state:' . $this->sessId,
function ($redis) use ($cb) {
if (!$redis) {
return;
}
list(, $chan, $state) = $redis->result;
if ($state === 'started') {
$this->sendFrame('o');
if (!in_array('stream', $this->pollMode)) {
$this->finish();
return;
}
}
$this->appInstance->publish('poll:' . $this->sessId,
json_encode($this->pollMode), function ($redis) use ($cb) {
if (!$redis || $redis->result === 0) {
$this->error(3000);
$cb === null || $cb();
return;
}
$cb === null || $cb();
});
}, function ($redis) use ($cb) {
if (!$this->appInstance->beginSession($this->path, $this->sessId,
$this->attrs->server)
) {
$this->header('404 Not Found');
$this->finish();
$this->unsubscribeReal('state:' . $this->sessId);
}
$cb === null || $cb();
});
});
});
});
});
} | php | protected function poll($cb = null)
{
$this->appInstance->subscribe('s2c:' . $this->sessId, [$this, 's2c'], function ($redis) use ($cb) {
$this->appInstance->publish('poll:' . $this->sessId, json_encode($this->pollMode),
function ($redis) use ($cb) {
if (!$redis) {
$cb === null || $cb();
return;
}
if ($redis->result > 0) {
$cb === null || $cb();
return;
}
$this->appInstance->setnx('sess:' . $this->sessId, $this->attrs->server['REQUEST_URI'],
function ($redis) use ($cb) {
if (!$redis || $redis->result === 0) {
$this->error(3000);
$cb === null || $cb();
return;
}
$this->appInstance->expire('sess:' . $this->sessId,
$this->appInstance->config->deadsessiontimeout->value, function ($redis) use ($cb) {
if (!$redis || $redis->result === 0) {
$this->error(3000);
$cb === null || $cb();
return;
}
$this->appInstance->subscribe('state:' . $this->sessId,
function ($redis) use ($cb) {
if (!$redis) {
return;
}
list(, $chan, $state) = $redis->result;
if ($state === 'started') {
$this->sendFrame('o');
if (!in_array('stream', $this->pollMode)) {
$this->finish();
return;
}
}
$this->appInstance->publish('poll:' . $this->sessId,
json_encode($this->pollMode), function ($redis) use ($cb) {
if (!$redis || $redis->result === 0) {
$this->error(3000);
$cb === null || $cb();
return;
}
$cb === null || $cb();
});
}, function ($redis) use ($cb) {
if (!$this->appInstance->beginSession($this->path, $this->sessId,
$this->attrs->server)
) {
$this->header('404 Not Found');
$this->finish();
$this->unsubscribeReal('state:' . $this->sessId);
}
$cb === null || $cb();
});
});
});
});
});
} | [
"protected",
"function",
"poll",
"(",
"$",
"cb",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"appInstance",
"->",
"subscribe",
"(",
"'s2c:'",
".",
"$",
"this",
"->",
"sessId",
",",
"[",
"$",
"this",
",",
"'s2c'",
"]",
",",
"function",
"(",
"$",
"redi... | Poll
@param callable $cb
@callback $cb ( )
@return void | [
"Poll"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/Generic.php#L327-L390 |
kakserpom/phpdaemon | PHPDaemon/SockJS/Methods/Generic.php | Generic.outputFrame | public function outputFrame($s, $flush = true)
{
$this->bytesSent += mb_orig_strlen($s);
return parent::out($s, $flush);
} | php | public function outputFrame($s, $flush = true)
{
$this->bytesSent += mb_orig_strlen($s);
return parent::out($s, $flush);
} | [
"public",
"function",
"outputFrame",
"(",
"$",
"s",
",",
"$",
"flush",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"bytesSent",
"+=",
"mb_orig_strlen",
"(",
"$",
"s",
")",
";",
"return",
"parent",
"::",
"out",
"(",
"$",
"s",
",",
"$",
"flush",
")",
... | Output some data
@param string $s String to out
@param boolean $flush
@return boolean Success | [
"Output",
"some",
"data"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/Generic.php#L398-L402 |
kakserpom/phpdaemon | PHPDaemon/SockJS/Methods/Generic.php | Generic.s2c | public function s2c($redis)
{
if (!$redis) {
return;
}
list(, $chan, $msg) = $redis->result;
$frames = json_decode($msg, true);
if (!is_array($frames) || !sizeof($frames)) {
return;
}
foreach ($frames as $frame) {
$this->sendFrame($frame);
}
if (!in_array('stream', $this->pollMode)) {
$this->heartbeatOnFinish = false;
$this->stop();
return;
}
if ($this->gcEnabled) {
$this->gcCheck();
}
} | php | public function s2c($redis)
{
if (!$redis) {
return;
}
list(, $chan, $msg) = $redis->result;
$frames = json_decode($msg, true);
if (!is_array($frames) || !sizeof($frames)) {
return;
}
foreach ($frames as $frame) {
$this->sendFrame($frame);
}
if (!in_array('stream', $this->pollMode)) {
$this->heartbeatOnFinish = false;
$this->stop();
return;
}
if ($this->gcEnabled) {
$this->gcCheck();
}
} | [
"public",
"function",
"s2c",
"(",
"$",
"redis",
")",
"{",
"if",
"(",
"!",
"$",
"redis",
")",
"{",
"return",
";",
"}",
"list",
"(",
",",
"$",
"chan",
",",
"$",
"msg",
")",
"=",
"$",
"redis",
"->",
"result",
";",
"$",
"frames",
"=",
"json_decode"... | s2c
@param object $redis
@return void | [
"s2c"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/Generic.php#L426-L447 |
kakserpom/phpdaemon | PHPDaemon/SockJS/Methods/Generic.php | Generic.onFinish | public function onFinish()
{
$this->appInstance->unsubscribe('s2c:' . $this->sessId, [$this, 's2c']);
$this->appInstance->unsubscribe('w8in:' . $this->sessId, [$this, 'w8in']);
Timer::remove($this->heartbeatTimer);
if ($this->heartbeatOnFinish) {
$this->sendFrame('h');
}
parent::onFinish();
} | php | public function onFinish()
{
$this->appInstance->unsubscribe('s2c:' . $this->sessId, [$this, 's2c']);
$this->appInstance->unsubscribe('w8in:' . $this->sessId, [$this, 'w8in']);
Timer::remove($this->heartbeatTimer);
if ($this->heartbeatOnFinish) {
$this->sendFrame('h');
}
parent::onFinish();
} | [
"public",
"function",
"onFinish",
"(",
")",
"{",
"$",
"this",
"->",
"appInstance",
"->",
"unsubscribe",
"(",
"'s2c:'",
".",
"$",
"this",
"->",
"sessId",
",",
"[",
"$",
"this",
",",
"'s2c'",
"]",
")",
";",
"$",
"this",
"->",
"appInstance",
"->",
"unsu... | On finish
@return void | [
"On",
"finish"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/SockJS/Methods/Generic.php#L453-L462 |
kakserpom/phpdaemon | PHPDaemon/Clients/HTTP/Connection.php | Connection.sendRequestHeaders | protected function sendRequestHeaders($type, $url, &$params)
{
if (!is_array($params)) {
$params = ['resultcb' => $params];
}
if (!isset($params['uri']) || !isset($params['host'])) {
$prepared = Pool::parseUrl($url);
if (!$prepared) {
if (isset($params['resultcb'])) {
$params['resultcb'](false);
}
return;
}
list($params['host'], $params['uri']) = $prepared;
}
if ($params['uri'] === '') {
$params['uri'] = '/';
}
$this->lastURL = 'http://' . $params['host'] . $params['uri'];
if (!isset($params['version'])) {
$params['version'] = '1.1';
}
$this->writeln($type . ' ' . $params['uri'] . ' HTTP/' . $params['version']);
if (isset($params['proxy'])) {
if (isset($params['proxy']['auth'])) {
$this->writeln('Proxy-Authorization: basic ' . base64_encode($params['proxy']['auth']['username'] . ':' . $params['proxy']['auth']['password']));
}
}
$this->writeln('Host: ' . $params['host']);
if ($this->pool->config->expose->value && !isset($params['headers']['User-Agent'])) {
$this->writeln('User-Agent: phpDaemon/' . Daemon::$version);
}
if (isset($params['cookie']) && sizeof($params['cookie'])) {
$this->writeln('Cookie: ' . http_build_query($params['cookie'], '', '; '));
}
if (isset($params['contentType'])) {
if (!isset($params['headers'])) {
$params['headers'] = [];
}
$params['headers']['Content-Type'] = $params['contentType'];
}
if (isset($params['headers'])) {
$this->customRequestHeaders($params['headers']);
}
if (isset($params['rawHeaders']) && $params['rawHeaders']) {
$this->rawHeaders = [];
}
if (isset($params['chunkcb']) && is_callable($params['chunkcb'])) {
$this->chunkcb = $params['chunkcb'];
}
$this->writeln('');
$this->requests->push($type);
$this->onResponse->push($params['resultcb']);
$this->checkFree();
} | php | protected function sendRequestHeaders($type, $url, &$params)
{
if (!is_array($params)) {
$params = ['resultcb' => $params];
}
if (!isset($params['uri']) || !isset($params['host'])) {
$prepared = Pool::parseUrl($url);
if (!$prepared) {
if (isset($params['resultcb'])) {
$params['resultcb'](false);
}
return;
}
list($params['host'], $params['uri']) = $prepared;
}
if ($params['uri'] === '') {
$params['uri'] = '/';
}
$this->lastURL = 'http://' . $params['host'] . $params['uri'];
if (!isset($params['version'])) {
$params['version'] = '1.1';
}
$this->writeln($type . ' ' . $params['uri'] . ' HTTP/' . $params['version']);
if (isset($params['proxy'])) {
if (isset($params['proxy']['auth'])) {
$this->writeln('Proxy-Authorization: basic ' . base64_encode($params['proxy']['auth']['username'] . ':' . $params['proxy']['auth']['password']));
}
}
$this->writeln('Host: ' . $params['host']);
if ($this->pool->config->expose->value && !isset($params['headers']['User-Agent'])) {
$this->writeln('User-Agent: phpDaemon/' . Daemon::$version);
}
if (isset($params['cookie']) && sizeof($params['cookie'])) {
$this->writeln('Cookie: ' . http_build_query($params['cookie'], '', '; '));
}
if (isset($params['contentType'])) {
if (!isset($params['headers'])) {
$params['headers'] = [];
}
$params['headers']['Content-Type'] = $params['contentType'];
}
if (isset($params['headers'])) {
$this->customRequestHeaders($params['headers']);
}
if (isset($params['rawHeaders']) && $params['rawHeaders']) {
$this->rawHeaders = [];
}
if (isset($params['chunkcb']) && is_callable($params['chunkcb'])) {
$this->chunkcb = $params['chunkcb'];
}
$this->writeln('');
$this->requests->push($type);
$this->onResponse->push($params['resultcb']);
$this->checkFree();
} | [
"protected",
"function",
"sendRequestHeaders",
"(",
"$",
"type",
",",
"$",
"url",
",",
"&",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"$",
"params",
"=",
"[",
"'resultcb'",
"=>",
"$",
"params",
"]",
";"... | Send request headers
@param $type
@param $url
@param &$params
@return void | [
"Send",
"request",
"headers"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/HTTP/Connection.php#L122-L176 |
kakserpom/phpdaemon | PHPDaemon/Clients/HTTP/Connection.php | Connection.post | public function post($url, $data = [], $params = null)
{
foreach ($data as $val) {
if ($val instanceof UploadFile) {
$params['contentType'] = 'multipart/form-data';
}
}
if (!isset($params['contentType'])) {
$params['contentType'] = 'application/x-www-form-urlencoded';
}
if ($params['contentType'] === 'application/x-www-form-urlencoded') {
$body = http_build_query($data, '', '&', PHP_QUERY_RFC3986);
} elseif ($params['contentType'] === 'application/x-json' || $params['contentType'] === 'application/json') {
$body = json_encode($data);
} else {
$body = 'Unsupported Content-Type';
}
if (!isset($params['headers'])) {
$params['headers'] = [];
}
$params['headers']['Content-Length'] = mb_orig_strlen($body);
$this->sendRequestHeaders('POST', $url, $params);
$this->write($body);
$this->writeln('');
} | php | public function post($url, $data = [], $params = null)
{
foreach ($data as $val) {
if ($val instanceof UploadFile) {
$params['contentType'] = 'multipart/form-data';
}
}
if (!isset($params['contentType'])) {
$params['contentType'] = 'application/x-www-form-urlencoded';
}
if ($params['contentType'] === 'application/x-www-form-urlencoded') {
$body = http_build_query($data, '', '&', PHP_QUERY_RFC3986);
} elseif ($params['contentType'] === 'application/x-json' || $params['contentType'] === 'application/json') {
$body = json_encode($data);
} else {
$body = 'Unsupported Content-Type';
}
if (!isset($params['headers'])) {
$params['headers'] = [];
}
$params['headers']['Content-Length'] = mb_orig_strlen($body);
$this->sendRequestHeaders('POST', $url, $params);
$this->write($body);
$this->writeln('');
} | [
"public",
"function",
"post",
"(",
"$",
"url",
",",
"$",
"data",
"=",
"[",
"]",
",",
"$",
"params",
"=",
"null",
")",
"{",
"foreach",
"(",
"$",
"data",
"as",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"val",
"instanceof",
"UploadFile",
")",
"{",
"$"... | Perform a POST request
@param string $url
@param array $data
@param array $params | [
"Perform",
"a",
"POST",
"request"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/HTTP/Connection.php#L222-L246 |
kakserpom/phpdaemon | PHPDaemon/Clients/HTTP/Connection.php | Connection.getHeader | public function getHeader($name)
{
$k = 'HTTP_' . strtoupper(strtr($name, Generic::$htr));
return isset($this->headers[$k]) ? $this->headers[$k] : null;
} | php | public function getHeader($name)
{
$k = 'HTTP_' . strtoupper(strtr($name, Generic::$htr));
return isset($this->headers[$k]) ? $this->headers[$k] : null;
} | [
"public",
"function",
"getHeader",
"(",
"$",
"name",
")",
"{",
"$",
"k",
"=",
"'HTTP_'",
".",
"strtoupper",
"(",
"strtr",
"(",
"$",
"name",
",",
"Generic",
"::",
"$",
"htr",
")",
")",
";",
"return",
"isset",
"(",
"$",
"this",
"->",
"headers",
"[",
... | Get header
@param string $name Header name
@return string | [
"Get",
"header"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/HTTP/Connection.php#L271-L275 |
kakserpom/phpdaemon | PHPDaemon/Clients/HTTP/Connection.php | Connection.onRead | public function onRead()
{
if ($this->state === self::STATE_BODY) {
goto body;
}
if ($this->reqType === null) {
if ($this->requests->isEmpty()) {
$this->finish();
return;
}
$this->reqType = $this->requests->shift();
}
while (($line = $this->readLine()) !== null) {
if ($line !== '') {
if ($this->rawHeaders !== null) {
$this->rawHeaders[] = $line;
}
} else {
if (isset($this->headers['HTTP_CONTENT_LENGTH'])) {
$this->contentLength = (int)$this->headers['HTTP_CONTENT_LENGTH'];
} else {
$this->contentLength = -1;
}
if (isset($this->headers['HTTP_TRANSFER_ENCODING'])) {
$e = explode(', ', strtolower($this->headers['HTTP_TRANSFER_ENCODING']));
$this->chunked = in_array('chunked', $e, true);
} else {
$this->chunked = false;
}
if (isset($this->headers['HTTP_CONNECTION'])) {
$e = explode(', ', strtolower($this->headers['HTTP_CONNECTION']));
$this->keepalive = in_array('keep-alive', $e, true);
}
if (isset($this->headers['HTTP_CONTENT_TYPE'])) {
parse_str('type=' . strtr($this->headers['HTTP_CONTENT_TYPE'], [';' => '&', ' ' => '']), $p);
$this->contentType = $p['type'];
if (isset($p['charset'])) {
$this->charset = strtolower($p['charset']);
}
}
if ($this->contentLength === -1 && !$this->chunked && !$this->keepalive) {
$this->eofTerminated = true;
}
if ($this->reqType === 'HEAD') {
$this->requestFinished();
} else {
$this->state = self::STATE_BODY;
}
break;
}
if ($this->state === self::STATE_ROOT) {
$this->headers['STATUS'] = $line;
$e = explode(' ', $this->headers['STATUS']);
$this->responseCode = isset($e[1]) ? (int)$e[1] : 0;
$this->state = self::STATE_HEADERS;
} elseif ($this->state === self::STATE_HEADERS) {
$e = explode(': ', $line);
if (isset($e[1])) {
$k = 'HTTP_' . strtoupper(strtr($e[0], Generic::$htr));
if ($k === 'HTTP_SET_COOKIE') {
parse_str(strtr($e[1], [';' => '&', ' ' => '']), $p);
if (sizeof($p)) {
$this->cookie[$k = key($p)] =& $p;
$p['value'] = $p[$k];
unset($p[$k], $p);
}
}
if (isset($this->headers[$k])) {
if (is_array($this->headers[$k])) {
$this->headers[$k][] = $e[1];
} else {
$this->headers[$k] = [$this->headers[$k], $e[1]];
}
} else {
$this->headers[$k] = $e[1];
}
}
}
}
if ($this->state !== self::STATE_BODY) {
return; // not enough data yet
}
body:
if ($this->eofTerminated) {
$body = $this->readUnlimited();
if ($this->chunkcb) {
$func = $this->chunkcb;
$func($body);
}
$this->body .= $body;
return;
}
if ($this->chunked) {
chunk:
if ($this->curChunkSize === null) { // outside of chunk
$l = $this->readLine();
if ($l === '') { // skip empty line
goto chunk;
}
if ($l === null) {
return; // not enough data yet
}
if (!ctype_xdigit($l)) {
$this->protocolError = __LINE__;
$this->finish(); // protocol error
return;
}
$this->curChunkSize = hexdec($l);
}
if ($this->curChunkSize !== null) {
if ($this->curChunkSize === 0) {
if ($this->readLine() === '') {
$this->requestFinished();
return;
} else { // protocol error
$this->protocolError = __LINE__;
$this->finish();
return;
}
}
$n = $this->curChunkSize - mb_orig_strlen($this->curChunk);
$this->curChunk .= $this->read($n);
if ($this->curChunkSize <= mb_orig_strlen($this->curChunk)) {
if ($this->chunkcb) {
$func = $this->chunkcb;
$func($this->curChunk);
}
$this->body .= $this->curChunk;
$this->curChunkSize = null;
$this->curChunk = '';
goto chunk;
}
}
} else {
$body = $this->read($this->contentLength - mb_orig_strlen($this->body));
if ($this->chunkcb) {
$func = $this->chunkcb;
$func($body);
}
$this->body .= $body;
if (($this->contentLength !== -1) && (mb_orig_strlen($this->body) >= $this->contentLength)) {
$this->requestFinished();
}
}
} | php | public function onRead()
{
if ($this->state === self::STATE_BODY) {
goto body;
}
if ($this->reqType === null) {
if ($this->requests->isEmpty()) {
$this->finish();
return;
}
$this->reqType = $this->requests->shift();
}
while (($line = $this->readLine()) !== null) {
if ($line !== '') {
if ($this->rawHeaders !== null) {
$this->rawHeaders[] = $line;
}
} else {
if (isset($this->headers['HTTP_CONTENT_LENGTH'])) {
$this->contentLength = (int)$this->headers['HTTP_CONTENT_LENGTH'];
} else {
$this->contentLength = -1;
}
if (isset($this->headers['HTTP_TRANSFER_ENCODING'])) {
$e = explode(', ', strtolower($this->headers['HTTP_TRANSFER_ENCODING']));
$this->chunked = in_array('chunked', $e, true);
} else {
$this->chunked = false;
}
if (isset($this->headers['HTTP_CONNECTION'])) {
$e = explode(', ', strtolower($this->headers['HTTP_CONNECTION']));
$this->keepalive = in_array('keep-alive', $e, true);
}
if (isset($this->headers['HTTP_CONTENT_TYPE'])) {
parse_str('type=' . strtr($this->headers['HTTP_CONTENT_TYPE'], [';' => '&', ' ' => '']), $p);
$this->contentType = $p['type'];
if (isset($p['charset'])) {
$this->charset = strtolower($p['charset']);
}
}
if ($this->contentLength === -1 && !$this->chunked && !$this->keepalive) {
$this->eofTerminated = true;
}
if ($this->reqType === 'HEAD') {
$this->requestFinished();
} else {
$this->state = self::STATE_BODY;
}
break;
}
if ($this->state === self::STATE_ROOT) {
$this->headers['STATUS'] = $line;
$e = explode(' ', $this->headers['STATUS']);
$this->responseCode = isset($e[1]) ? (int)$e[1] : 0;
$this->state = self::STATE_HEADERS;
} elseif ($this->state === self::STATE_HEADERS) {
$e = explode(': ', $line);
if (isset($e[1])) {
$k = 'HTTP_' . strtoupper(strtr($e[0], Generic::$htr));
if ($k === 'HTTP_SET_COOKIE') {
parse_str(strtr($e[1], [';' => '&', ' ' => '']), $p);
if (sizeof($p)) {
$this->cookie[$k = key($p)] =& $p;
$p['value'] = $p[$k];
unset($p[$k], $p);
}
}
if (isset($this->headers[$k])) {
if (is_array($this->headers[$k])) {
$this->headers[$k][] = $e[1];
} else {
$this->headers[$k] = [$this->headers[$k], $e[1]];
}
} else {
$this->headers[$k] = $e[1];
}
}
}
}
if ($this->state !== self::STATE_BODY) {
return; // not enough data yet
}
body:
if ($this->eofTerminated) {
$body = $this->readUnlimited();
if ($this->chunkcb) {
$func = $this->chunkcb;
$func($body);
}
$this->body .= $body;
return;
}
if ($this->chunked) {
chunk:
if ($this->curChunkSize === null) { // outside of chunk
$l = $this->readLine();
if ($l === '') { // skip empty line
goto chunk;
}
if ($l === null) {
return; // not enough data yet
}
if (!ctype_xdigit($l)) {
$this->protocolError = __LINE__;
$this->finish(); // protocol error
return;
}
$this->curChunkSize = hexdec($l);
}
if ($this->curChunkSize !== null) {
if ($this->curChunkSize === 0) {
if ($this->readLine() === '') {
$this->requestFinished();
return;
} else { // protocol error
$this->protocolError = __LINE__;
$this->finish();
return;
}
}
$n = $this->curChunkSize - mb_orig_strlen($this->curChunk);
$this->curChunk .= $this->read($n);
if ($this->curChunkSize <= mb_orig_strlen($this->curChunk)) {
if ($this->chunkcb) {
$func = $this->chunkcb;
$func($this->curChunk);
}
$this->body .= $this->curChunk;
$this->curChunkSize = null;
$this->curChunk = '';
goto chunk;
}
}
} else {
$body = $this->read($this->contentLength - mb_orig_strlen($this->body));
if ($this->chunkcb) {
$func = $this->chunkcb;
$func($body);
}
$this->body .= $body;
if (($this->contentLength !== -1) && (mb_orig_strlen($this->body) >= $this->contentLength)) {
$this->requestFinished();
}
}
} | [
"public",
"function",
"onRead",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"state",
"===",
"self",
"::",
"STATE_BODY",
")",
"{",
"goto",
"body",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"reqType",
"===",
"null",
")",
"{",
"if",
"(",
"$",
"this",... | Called when new data received | [
"Called",
"when",
"new",
"data",
"received"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/HTTP/Connection.php#L280-L425 |
kakserpom/phpdaemon | PHPDaemon/Clients/HTTP/Connection.php | Connection.onFinish | public function onFinish()
{
if ($this->eofTerminated) {
$this->requestFinished();
$this->onResponse->executeAll($this, false);
parent::onFinish();
return;
}
if ($this->protocolError) {
$this->onResponse->executeAll($this, false);
} else {
if (($this->state !== self::STATE_ROOT) && !$this->onResponse->isEmpty()) {
$this->requestFinished();
}
}
parent::onFinish();
} | php | public function onFinish()
{
if ($this->eofTerminated) {
$this->requestFinished();
$this->onResponse->executeAll($this, false);
parent::onFinish();
return;
}
if ($this->protocolError) {
$this->onResponse->executeAll($this, false);
} else {
if (($this->state !== self::STATE_ROOT) && !$this->onResponse->isEmpty()) {
$this->requestFinished();
}
}
parent::onFinish();
} | [
"public",
"function",
"onFinish",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"eofTerminated",
")",
"{",
"$",
"this",
"->",
"requestFinished",
"(",
")",
";",
"$",
"this",
"->",
"onResponse",
"->",
"executeAll",
"(",
"$",
"this",
",",
"false",
")",
"... | Called when connection finishes | [
"Called",
"when",
"connection",
"finishes"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/HTTP/Connection.php#L430-L446 |
kakserpom/phpdaemon | PHPDaemon/Clients/HTTP/Connection.php | Connection.requestFinished | protected function requestFinished()
{
$this->onResponse->executeOne($this, true);
$this->state = self::STATE_ROOT;
$this->contentLength = -1;
$this->curChunkSize = null;
$this->chunked = false;
$this->eofTerminated = false;
$this->headers = [];
$this->rawHeaders = null;
$this->contentType = null;
$this->charset = null;
$this->body = '';
$this->responseCode = 0;
$this->reqType = null;
if (!$this->keepalive) {
$this->finish();
}
$this->checkFree();
} | php | protected function requestFinished()
{
$this->onResponse->executeOne($this, true);
$this->state = self::STATE_ROOT;
$this->contentLength = -1;
$this->curChunkSize = null;
$this->chunked = false;
$this->eofTerminated = false;
$this->headers = [];
$this->rawHeaders = null;
$this->contentType = null;
$this->charset = null;
$this->body = '';
$this->responseCode = 0;
$this->reqType = null;
if (!$this->keepalive) {
$this->finish();
}
$this->checkFree();
} | [
"protected",
"function",
"requestFinished",
"(",
")",
"{",
"$",
"this",
"->",
"onResponse",
"->",
"executeOne",
"(",
"$",
"this",
",",
"true",
")",
";",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_ROOT",
";",
"$",
"this",
"->",
"contentLength",... | Called when request is finished | [
"Called",
"when",
"request",
"is",
"finished"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/HTTP/Connection.php#L451-L470 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Exception/AMQPConnectionException.php | AMQPConnectionException.couldNotConnect | public static function couldNotConnect(
ConnectionOptions $options,
$description,
\Exception $previous = null
)
{
return new self(
sprintf(
'Unable to connect to AMQP broker [%s:%d], check connection options and network connectivity (%s).',
$options->getHost(),
$options->getPort(),
rtrim($description, '.')
),
0,
$previous
);
} | php | public static function couldNotConnect(
ConnectionOptions $options,
$description,
\Exception $previous = null
)
{
return new self(
sprintf(
'Unable to connect to AMQP broker [%s:%d], check connection options and network connectivity (%s).',
$options->getHost(),
$options->getPort(),
rtrim($description, '.')
),
0,
$previous
);
} | [
"public",
"static",
"function",
"couldNotConnect",
"(",
"ConnectionOptions",
"$",
"options",
",",
"$",
"description",
",",
"\\",
"Exception",
"$",
"previous",
"=",
"null",
")",
"{",
"return",
"new",
"self",
"(",
"sprintf",
"(",
"'Unable to connect to AMQP broker [... | Create an exception that indicates a failure to establish a connection to
an AMQP broker.
@param ConnectionOptions $options The options used when establishing the connection.
@param string $description A description of the problem.
@param \Exception|null $previous The exception that caused this exception, if any.
@return AMQPConnectionException | [
"Create",
"an",
"exception",
"that",
"indicates",
"a",
"failure",
"to",
"establish",
"a",
"connection",
"to",
"an",
"AMQP",
"broker",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Exception/AMQPConnectionException.php#L25-L41 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Exception/AMQPConnectionException.php | AMQPConnectionException.notOpen | public static function notOpen(
ConnectionOptions $options,
\Exception $previous = null
)
{
return new self(
sprintf(
'Unable to use connection to AMQP broker [%s:%d] because it is closed.',
$options->getHost(),
$options->getPort()
),
0,
$previous
);
} | php | public static function notOpen(
ConnectionOptions $options,
\Exception $previous = null
)
{
return new self(
sprintf(
'Unable to use connection to AMQP broker [%s:%d] because it is closed.',
$options->getHost(),
$options->getPort()
),
0,
$previous
);
} | [
"public",
"static",
"function",
"notOpen",
"(",
"ConnectionOptions",
"$",
"options",
",",
"\\",
"Exception",
"$",
"previous",
"=",
"null",
")",
"{",
"return",
"new",
"self",
"(",
"sprintf",
"(",
"'Unable to use connection to AMQP broker [%s:%d] because it is closed.'",
... | Create an exception that indicates an attempt to use a connection that has
already been closed.
@param ConnectionOptions $options The options used when establishing the connection.
@param \Exception|null $previous The exception that caused this exception, if any.
@return AMQPConnectionException | [
"Create",
"an",
"exception",
"that",
"indicates",
"an",
"attempt",
"to",
"use",
"a",
"connection",
"that",
"has",
"already",
"been",
"closed",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Exception/AMQPConnectionException.php#L51-L65 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Exception/AMQPConnectionException.php | AMQPConnectionException.authenticationFailed | public static function authenticationFailed(
ConnectionOptions $options,
\Exception $previous = null
)
{
return new self(
sprintf(
'Unable to authenticate as "%s" on AMQP broker [%s:%d], check authentication credentials.',
$options->getUsername(),
$options->getHost(),
$options->getPort()
),
0,
$previous
);
} | php | public static function authenticationFailed(
ConnectionOptions $options,
\Exception $previous = null
)
{
return new self(
sprintf(
'Unable to authenticate as "%s" on AMQP broker [%s:%d], check authentication credentials.',
$options->getUsername(),
$options->getHost(),
$options->getPort()
),
0,
$previous
);
} | [
"public",
"static",
"function",
"authenticationFailed",
"(",
"ConnectionOptions",
"$",
"options",
",",
"\\",
"Exception",
"$",
"previous",
"=",
"null",
")",
"{",
"return",
"new",
"self",
"(",
"sprintf",
"(",
"'Unable to authenticate as \"%s\" on AMQP broker [%s:%d], che... | Create an exception that indicates that the credentials specified in the
connection options are incorrect.
@param ConnectionOptions $options The options used when establishing the connection.
@param \Exception|null $previous The exception that caused this exception, if any.
@return AMQPConnectionException | [
"Create",
"an",
"exception",
"that",
"indicates",
"that",
"the",
"credentials",
"specified",
"in",
"the",
"connection",
"options",
"are",
"incorrect",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Exception/AMQPConnectionException.php#L75-L90 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Exception/AMQPConnectionException.php | AMQPConnectionException.authorizationFailed | public static function authorizationFailed(
ConnectionOptions $options,
\Exception $previous = null
)
{
return new self(
sprintf(
'Unable to access vhost "%s" as "%s" on AMQP broker [%s:%d], check permissions.',
$options->getVhost(),
$options->getUsername(),
$options->getHost(),
$options->getPort()
),
0,
$previous
);
} | php | public static function authorizationFailed(
ConnectionOptions $options,
\Exception $previous = null
)
{
return new self(
sprintf(
'Unable to access vhost "%s" as "%s" on AMQP broker [%s:%d], check permissions.',
$options->getVhost(),
$options->getUsername(),
$options->getHost(),
$options->getPort()
),
0,
$previous
);
} | [
"public",
"static",
"function",
"authorizationFailed",
"(",
"ConnectionOptions",
"$",
"options",
",",
"\\",
"Exception",
"$",
"previous",
"=",
"null",
")",
"{",
"return",
"new",
"self",
"(",
"sprintf",
"(",
"'Unable to access vhost \"%s\" as \"%s\" on AMQP broker [%s:%d... | Create an exception that indicates that the credentials specified in the
connection options do not grant access to the requested AMQP virtual host.
@param ConnectionOptions $options The options used when establishing the connection.
@param \Exception|null $previous The exception that caused this exception, if any.
@return AMQPConnectionException | [
"Create",
"an",
"exception",
"that",
"indicates",
"that",
"the",
"credentials",
"specified",
"in",
"the",
"connection",
"options",
"do",
"not",
"grant",
"access",
"to",
"the",
"requested",
"AMQP",
"virtual",
"host",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Exception/AMQPConnectionException.php#L126-L142 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Exception/AMQPConnectionException.php | AMQPConnectionException.heartbeatTimedOut | public static function heartbeatTimedOut(
ConnectionOptions $options,
$heartbeatInterval,
\Exception $previous = null
)
{
return new self(
sprintf(
'The AMQP connection with broker [%s:%d] has timed out, '
. 'the last heartbeat was received over %d seconds ago.',
$options->getHost(),
$options->getPort(),
$heartbeatInterval
),
0,
$previous
);
} | php | public static function heartbeatTimedOut(
ConnectionOptions $options,
$heartbeatInterval,
\Exception $previous = null
)
{
return new self(
sprintf(
'The AMQP connection with broker [%s:%d] has timed out, '
. 'the last heartbeat was received over %d seconds ago.',
$options->getHost(),
$options->getPort(),
$heartbeatInterval
),
0,
$previous
);
} | [
"public",
"static",
"function",
"heartbeatTimedOut",
"(",
"ConnectionOptions",
"$",
"options",
",",
"$",
"heartbeatInterval",
",",
"\\",
"Exception",
"$",
"previous",
"=",
"null",
")",
"{",
"return",
"new",
"self",
"(",
"sprintf",
"(",
"'The AMQP connection with b... | Create an exception that indicates that the broker has failed to send
any data for a period longer than the heartbeat interval.
@param ConnectionOptions $options The options used when establishing the connection.
@param int $heartbeatInterval The heartbeat interval negotiated during the AMQP handshake.
@param \Exception|null $previous The exception that caused this exception, if any.
@return AMQPConnectionException | [
"Create",
"an",
"exception",
"that",
"indicates",
"that",
"the",
"broker",
"has",
"failed",
"to",
"send",
"any",
"data",
"for",
"a",
"period",
"longer",
"than",
"the",
"heartbeat",
"interval",
"."
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Exception/AMQPConnectionException.php#L153-L170 |
kakserpom/phpdaemon | PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Connection/ConnectionBlockedFrame.php | ConnectionBlockedFrame.create | public static function create(
$reason = null
)
{
$frame = new self();
if (null !== $reason) {
$frame->reason = $reason;
}
return $frame;
} | php | public static function create(
$reason = null
)
{
$frame = new self();
if (null !== $reason) {
$frame->reason = $reason;
}
return $frame;
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"reason",
"=",
"null",
")",
"{",
"$",
"frame",
"=",
"new",
"self",
"(",
")",
";",
"if",
"(",
"null",
"!==",
"$",
"reason",
")",
"{",
"$",
"frame",
"->",
"reason",
"=",
"$",
"reason",
";",
"}",
... | shortstr | [
"shortstr"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/AMQP/Driver/Protocol/v091/Protocol/Connection/ConnectionBlockedFrame.php#L20-L31 |
kakserpom/phpdaemon | PHPDaemon/Clients/IMAP/Connection.php | Connection.escapeList | protected function escapeList($list)
{
$result = [];
foreach ($list as $v) {
if (!is_array($v)) {
$result[] = $v;
continue;
}
$result[] = $this->escapeList($v);
}
return '(' . implode(' ', $result) . ')';
} | php | protected function escapeList($list)
{
$result = [];
foreach ($list as $v) {
if (!is_array($v)) {
$result[] = $v;
continue;
}
$result[] = $this->escapeList($v);
}
return '(' . implode(' ', $result) . ')';
} | [
"protected",
"function",
"escapeList",
"(",
"$",
"list",
")",
"{",
"$",
"result",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"v",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=... | escape a list with literals or lists
@param array $list list with literals or lists as PHP array
@return string escaped list for imap | [
"escape",
"a",
"list",
"with",
"literals",
"or",
"lists"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IMAP/Connection.php#L85-L96 |
kakserpom/phpdaemon | PHPDaemon/Clients/IMAP/Connection.php | Connection.decodeLine | protected function decodeLine($line)
{
$tokens = [];
$stack = [];
/*
We start to decode the response here. The understood tokens are:
literal
"literal" or also "lit\\er\"al"
(literals*)
All tokens are returned in an array. Literals in braces (the last understood
token in the list) are returned as an array of tokens. I.e. the following response:
"foo" baz bar ("f\\\"oo" bar)
would be returned as:
array('foo', 'baz', 'bar', array('f\\\"oo', 'bar'));
*/
// replace any trailing <NL> including spaces with a single space
$line = rtrim($line) . ' ';
while (($pos = strpos($line, ' ')) !== false) {
$token = substr($line, 0, $pos);
if (!strlen($token)) {
continue;
}
while ($token[0] === '(') {
array_push($stack, $tokens);
$tokens = [];
$token = substr($token, 1);
}
if ($token[0] === '"') {
if (preg_match('%^\(*"((.|\\\\|\\")*?)" *%', $line, $matches)) {
$tokens[] = $matches[1];
$line = substr($line, strlen($matches[0]));
continue;
}
}
if ($stack && $token[strlen($token) - 1] === ')') {
// closing braces are not separated by spaces, so we need to count them
$braces = strlen($token);
$token = rtrim($token, ')');
// only count braces if more than one
$braces -= strlen($token) + 1;
// only add if token had more than just closing braces
if (rtrim($token) != '') {
$tokens[] = rtrim($token);
}
$token = $tokens;
$tokens = array_pop($stack);
// special handline if more than one closing brace
while ($braces-- > 0) {
$tokens[] = $token;
$token = $tokens;
$tokens = array_pop($stack);
}
}
$tokens[] = $token;
$line = substr($line, $pos + 1);
}
// maybe the server forgot to send some closing braces
while ($stack) {
$child = $tokens;
$tokens = array_pop($stack);
$tokens[] = $child;
}
return $tokens;
} | php | protected function decodeLine($line)
{
$tokens = [];
$stack = [];
/*
We start to decode the response here. The understood tokens are:
literal
"literal" or also "lit\\er\"al"
(literals*)
All tokens are returned in an array. Literals in braces (the last understood
token in the list) are returned as an array of tokens. I.e. the following response:
"foo" baz bar ("f\\\"oo" bar)
would be returned as:
array('foo', 'baz', 'bar', array('f\\\"oo', 'bar'));
*/
// replace any trailing <NL> including spaces with a single space
$line = rtrim($line) . ' ';
while (($pos = strpos($line, ' ')) !== false) {
$token = substr($line, 0, $pos);
if (!strlen($token)) {
continue;
}
while ($token[0] === '(') {
array_push($stack, $tokens);
$tokens = [];
$token = substr($token, 1);
}
if ($token[0] === '"') {
if (preg_match('%^\(*"((.|\\\\|\\")*?)" *%', $line, $matches)) {
$tokens[] = $matches[1];
$line = substr($line, strlen($matches[0]));
continue;
}
}
if ($stack && $token[strlen($token) - 1] === ')') {
// closing braces are not separated by spaces, so we need to count them
$braces = strlen($token);
$token = rtrim($token, ')');
// only count braces if more than one
$braces -= strlen($token) + 1;
// only add if token had more than just closing braces
if (rtrim($token) != '') {
$tokens[] = rtrim($token);
}
$token = $tokens;
$tokens = array_pop($stack);
// special handline if more than one closing brace
while ($braces-- > 0) {
$tokens[] = $token;
$token = $tokens;
$tokens = array_pop($stack);
}
}
$tokens[] = $token;
$line = substr($line, $pos + 1);
}
// maybe the server forgot to send some closing braces
while ($stack) {
$child = $tokens;
$tokens = array_pop($stack);
$tokens[] = $child;
}
return $tokens;
} | [
"protected",
"function",
"decodeLine",
"(",
"$",
"line",
")",
"{",
"$",
"tokens",
"=",
"[",
"]",
";",
"$",
"stack",
"=",
"[",
"]",
";",
"/*\n We start to decode the response here. The understood tokens are:\n literal\n \"literal\" or a... | split a given line in tokens. a token is literal of any form or a list
@param string $line line to decode
@return array tokens, literals are returned as string, lists as array | [
"split",
"a",
"given",
"line",
"in",
"tokens",
".",
"a",
"token",
"is",
"literal",
"of",
"any",
"form",
"or",
"a",
"list"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IMAP/Connection.php#L104-L167 |
kakserpom/phpdaemon | PHPDaemon/Clients/IMAP/Connection.php | Connection.decodeSize | protected function decodeSize($lines)
{
$sizes = [];
foreach (array_map([$this, 'decodeLine'], $lines) as $tokens) {
if (!isset($tokens[1]) || $tokens[1] !== 'FETCH') {
continue;
}
if (!isset($tokens[2][0]) || $tokens[2][0] !== 'UID') {
continue;
}
if (!isset($tokens[2][2]) || $tokens[2][2] !== 'RFC822.SIZE') {
continue;
}
if (!isset($tokens[2][1]) || !isset($tokens[2][3])) {
continue;
}
$sizes[$tokens[2][1]] = $tokens[2][3];
}
return $sizes;
} | php | protected function decodeSize($lines)
{
$sizes = [];
foreach (array_map([$this, 'decodeLine'], $lines) as $tokens) {
if (!isset($tokens[1]) || $tokens[1] !== 'FETCH') {
continue;
}
if (!isset($tokens[2][0]) || $tokens[2][0] !== 'UID') {
continue;
}
if (!isset($tokens[2][2]) || $tokens[2][2] !== 'RFC822.SIZE') {
continue;
}
if (!isset($tokens[2][1]) || !isset($tokens[2][3])) {
continue;
}
$sizes[$tokens[2][1]] = $tokens[2][3];
}
return $sizes;
} | [
"protected",
"function",
"decodeSize",
"(",
"$",
"lines",
")",
"{",
"$",
"sizes",
"=",
"[",
"]",
";",
"foreach",
"(",
"array_map",
"(",
"[",
"$",
"this",
",",
"'decodeLine'",
"]",
",",
"$",
"lines",
")",
"as",
"$",
"tokens",
")",
"{",
"if",
"(",
... | /*
@param array $lines | [
"/",
"*"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IMAP/Connection.php#L336-L355 |
kakserpom/phpdaemon | PHPDaemon/Clients/IMAP/Connection.php | Connection.countMessages | public function countMessages($cb, $flags = null)
{
$this->onResponse->push($cb);
if ($flags === null) {
$this->searchMessages(['ALL'], self::TAG_COUNT);
return;
}
$params = [];
foreach ((array) $flags as $flag) {
if (isset($this->searchFlags[$flag])) {
$params[] = $this->searchFlags[$flag];
} else {
$params[] = 'KEYWORD';
$params[] = $this->escapeString($flag);
}
}
$this->searchMessages($params, self::TAG_COUNT);
} | php | public function countMessages($cb, $flags = null)
{
$this->onResponse->push($cb);
if ($flags === null) {
$this->searchMessages(['ALL'], self::TAG_COUNT);
return;
}
$params = [];
foreach ((array) $flags as $flag) {
if (isset($this->searchFlags[$flag])) {
$params[] = $this->searchFlags[$flag];
} else {
$params[] = 'KEYWORD';
$params[] = $this->escapeString($flag);
}
}
$this->searchMessages($params, self::TAG_COUNT);
} | [
"public",
"function",
"countMessages",
"(",
"$",
"cb",
",",
"$",
"flags",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"onResponse",
"->",
"push",
"(",
"$",
"cb",
")",
";",
"if",
"(",
"$",
"flags",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"search... | Count messages all messages in current box
@param null $flags | [
"Count",
"messages",
"all",
"messages",
"in",
"current",
"box"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IMAP/Connection.php#L475-L492 |
kakserpom/phpdaemon | PHPDaemon/Clients/IMAP/Connection.php | Connection.getSize | public function getSize($cb, $uid = null)
{
$this->onResponse->push($cb);
if ($uid) {
$this->fetch('RFC822.SIZE', $uid, null, true, self::TAG_SIZE);
} else {
$this->fetch('RFC822.SIZE', 1, INF, true, self::TAG_SIZE);
}
} | php | public function getSize($cb, $uid = null)
{
$this->onResponse->push($cb);
if ($uid) {
$this->fetch('RFC822.SIZE', $uid, null, true, self::TAG_SIZE);
} else {
$this->fetch('RFC822.SIZE', 1, INF, true, self::TAG_SIZE);
}
} | [
"public",
"function",
"getSize",
"(",
"$",
"cb",
",",
"$",
"uid",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"onResponse",
"->",
"push",
"(",
"$",
"cb",
")",
";",
"if",
"(",
"$",
"uid",
")",
"{",
"$",
"this",
"->",
"fetch",
"(",
"'RFC822.SIZE'",
... | get a list of messages with number and size
@param int $uid number of message | [
"get",
"a",
"list",
"of",
"messages",
"with",
"number",
"and",
"size"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IMAP/Connection.php#L498-L506 |
kakserpom/phpdaemon | PHPDaemon/Clients/IMAP/Connection.php | Connection.getRawMessage | public function getRawMessage($cb, $uid, $byUid = true)
{
$this->onResponse->push($cb);
$this->fetch(['FLAGS', 'BODY[]'], $uid, null, $byUid, self::TAG_GETRAWMESSAGE);
} | php | public function getRawMessage($cb, $uid, $byUid = true)
{
$this->onResponse->push($cb);
$this->fetch(['FLAGS', 'BODY[]'], $uid, null, $byUid, self::TAG_GETRAWMESSAGE);
} | [
"public",
"function",
"getRawMessage",
"(",
"$",
"cb",
",",
"$",
"uid",
",",
"$",
"byUid",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"onResponse",
"->",
"push",
"(",
"$",
"cb",
")",
";",
"$",
"this",
"->",
"fetch",
"(",
"[",
"'FLAGS'",
",",
"'BOD... | Fetch a message
@param int $uid unique number of message | [
"Fetch",
"a",
"message"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IMAP/Connection.php#L512-L516 |
kakserpom/phpdaemon | PHPDaemon/Clients/IMAP/Connection.php | Connection.getRawHeader | public function getRawHeader($cb, $uid, $byUid = true)
{
$this->onResponse->push($cb);
$this->fetch(['FLAGS', 'RFC822.HEADER'], $uid, null, $byUid, self::TAG_GETRAWHEADER);
} | php | public function getRawHeader($cb, $uid, $byUid = true)
{
$this->onResponse->push($cb);
$this->fetch(['FLAGS', 'RFC822.HEADER'], $uid, null, $byUid, self::TAG_GETRAWHEADER);
} | [
"public",
"function",
"getRawHeader",
"(",
"$",
"cb",
",",
"$",
"uid",
",",
"$",
"byUid",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"onResponse",
"->",
"push",
"(",
"$",
"cb",
")",
";",
"$",
"this",
"->",
"fetch",
"(",
"[",
"'FLAGS'",
",",
"'RFC8... | /*
Get raw header of message or part
@param int $uid unique number of message | [
"/",
"*",
"Get",
"raw",
"header",
"of",
"message",
"or",
"part"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IMAP/Connection.php#L522-L526 |
kakserpom/phpdaemon | PHPDaemon/Clients/IMAP/Connection.php | Connection.getRawContent | public function getRawContent($cb, $uid, $byUid = true)
{
$this->onResponse->push($cb);
$this->fetch(['FLAGS', 'RFC822.TEXT'], $uid, null, $byUid, self::TAG_GETRAWCONTENT);
} | php | public function getRawContent($cb, $uid, $byUid = true)
{
$this->onResponse->push($cb);
$this->fetch(['FLAGS', 'RFC822.TEXT'], $uid, null, $byUid, self::TAG_GETRAWCONTENT);
} | [
"public",
"function",
"getRawContent",
"(",
"$",
"cb",
",",
"$",
"uid",
",",
"$",
"byUid",
"=",
"true",
")",
"{",
"$",
"this",
"->",
"onResponse",
"->",
"push",
"(",
"$",
"cb",
")",
";",
"$",
"this",
"->",
"fetch",
"(",
"[",
"'FLAGS'",
",",
"'RFC... | /*
Get raw content of message or part
@param int $uid number of message | [
"/",
"*",
"Get",
"raw",
"content",
"of",
"message",
"or",
"part"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IMAP/Connection.php#L533-L537 |
kakserpom/phpdaemon | PHPDaemon/Clients/IMAP/Connection.php | Connection.getUniqueId | public function getUniqueId($cb, $id = null)
{
$this->onResponse->push($cb);
if ($id) {
$this->fetch('UID', $id, null, false, self::TAG_GETUID);
} else {
$this->fetch('UID', 1, INF, false, self::TAG_GETUID);
}
} | php | public function getUniqueId($cb, $id = null)
{
$this->onResponse->push($cb);
if ($id) {
$this->fetch('UID', $id, null, false, self::TAG_GETUID);
} else {
$this->fetch('UID', 1, INF, false, self::TAG_GETUID);
}
} | [
"public",
"function",
"getUniqueId",
"(",
"$",
"cb",
",",
"$",
"id",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"onResponse",
"->",
"push",
"(",
"$",
"cb",
")",
";",
"if",
"(",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"fetch",
"(",
"'UID'",
",",
... | get unique id for one or all messages
@param int|null $id message number | [
"get",
"unique",
"id",
"for",
"one",
"or",
"all",
"messages"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IMAP/Connection.php#L544-L552 |
kakserpom/phpdaemon | PHPDaemon/Clients/IMAP/Connection.php | Connection.createFolder | public function createFolder($cb, $folder, $parentFolder = null)
{
$this->onResponse->push($cb);
if ($parentFolder) {
$folder = $parentFolder . '/' . $folder ;
}
$this->writeln(self::TAG_CREATEFOLDER . " CREATE ".$this->escapeString($folder));
} | php | public function createFolder($cb, $folder, $parentFolder = null)
{
$this->onResponse->push($cb);
if ($parentFolder) {
$folder = $parentFolder . '/' . $folder ;
}
$this->writeln(self::TAG_CREATEFOLDER . " CREATE ".$this->escapeString($folder));
} | [
"public",
"function",
"createFolder",
"(",
"$",
"cb",
",",
"$",
"folder",
",",
"$",
"parentFolder",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"onResponse",
"->",
"push",
"(",
"$",
"cb",
")",
";",
"if",
"(",
"$",
"parentFolder",
")",
"{",
"$",
"fold... | create a new folder (and parent folders if needed)
@param string $folder folder name
@return bool success | [
"create",
"a",
"new",
"folder",
"(",
"and",
"parent",
"folders",
"if",
"needed",
")"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IMAP/Connection.php#L560-L567 |
kakserpom/phpdaemon | PHPDaemon/Clients/IMAP/Connection.php | Connection.removeFolder | public function removeFolder($cb, $folder)
{
$this->onResponse->push($cb);
$this->writeln(self::TAG_DELETEFOLDER . " DELETE ".$this->escapeString($folder));
} | php | public function removeFolder($cb, $folder)
{
$this->onResponse->push($cb);
$this->writeln(self::TAG_DELETEFOLDER . " DELETE ".$this->escapeString($folder));
} | [
"public",
"function",
"removeFolder",
"(",
"$",
"cb",
",",
"$",
"folder",
")",
"{",
"$",
"this",
"->",
"onResponse",
"->",
"push",
"(",
"$",
"cb",
")",
";",
"$",
"this",
"->",
"writeln",
"(",
"self",
"::",
"TAG_DELETEFOLDER",
".",
"\" DELETE \"",
".",
... | remove a folder
@param string $name name or instance of folder | [
"remove",
"a",
"folder"
] | train | https://github.com/kakserpom/phpdaemon/blob/cfbe02e60e162853747ea9484c12f15341e56833/PHPDaemon/Clients/IMAP/Connection.php#L574-L578 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.