id int32 0 241k | repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1 value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 |
|---|---|---|---|---|---|---|---|---|---|---|---|
38,900 | mmoreram/symfony-bundle-dependencies | CachedBundleDependenciesResolver.php | CachedBundleDependenciesResolver.cacheBuiltBundleStack | protected function cacheBuiltBundleStack(
array $bundleStack,
string $cacheFile
) {
foreach ($bundleStack as $bundle) {
if (is_object($bundle)) {
$kernelNamespace = get_class($this);
$bundleNamespace = get_class($bundle);
throw new BundleStackNotCacheableException(
$kernelNamespace,
$bundleNamespace
);
}
}
file_put_contents(
$cacheFile,
'<?php return ' . var_export($bundleStack, true) . ';'
);
} | php | protected function cacheBuiltBundleStack(
array $bundleStack,
string $cacheFile
) {
foreach ($bundleStack as $bundle) {
if (is_object($bundle)) {
$kernelNamespace = get_class($this);
$bundleNamespace = get_class($bundle);
throw new BundleStackNotCacheableException(
$kernelNamespace,
$bundleNamespace
);
}
}
file_put_contents(
$cacheFile,
'<?php return ' . var_export($bundleStack, true) . ';'
);
} | [
"protected",
"function",
"cacheBuiltBundleStack",
"(",
"array",
"$",
"bundleStack",
",",
"string",
"$",
"cacheFile",
")",
"{",
"foreach",
"(",
"$",
"bundleStack",
"as",
"$",
"bundle",
")",
"{",
"if",
"(",
"is_object",
"(",
"$",
"bundle",
")",
")",
"{",
"... | Cache the built bundles stack.
Only bundles stack with string definitions are allowed to be cached.
Otherwise, will throw an exception.
@param Bundle[]|string[] $bundleStack
@param string $cacheFile
@throws BundleStackNotCacheableException Bundles not cacheable | [
"Cache",
"the",
"built",
"bundles",
"stack",
".",
"Only",
"bundles",
"stack",
"with",
"string",
"definitions",
"are",
"allowed",
"to",
"be",
"cached",
".",
"Otherwise",
"will",
"throw",
"an",
"exception",
"."
] | aed90cc4b91e08ce6b01506d5b36830041ceb18e | https://github.com/mmoreram/symfony-bundle-dependencies/blob/aed90cc4b91e08ce6b01506d5b36830041ceb18e/CachedBundleDependenciesResolver.php#L95-L114 |
38,901 | nilportugues/php-sql-query-formatter | src/Helper/NewLine.php | NewLine.addNewLineBreak | public function addNewLineBreak($tab)
{
$addedNewline = false;
if (true === $this->newline) {
$this->formatter->appendToFormattedSql("\n".str_repeat($tab, $this->indentation->getIndentLvl()));
$this->newline = false;
$addedNewline = true;
}
return $addedNewline;
} | php | public function addNewLineBreak($tab)
{
$addedNewline = false;
if (true === $this->newline) {
$this->formatter->appendToFormattedSql("\n".str_repeat($tab, $this->indentation->getIndentLvl()));
$this->newline = false;
$addedNewline = true;
}
return $addedNewline;
} | [
"public",
"function",
"addNewLineBreak",
"(",
"$",
"tab",
")",
"{",
"$",
"addedNewline",
"=",
"false",
";",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"newline",
")",
"{",
"$",
"this",
"->",
"formatter",
"->",
"appendToFormattedSql",
"(",
"\"\\n\"",
".... | Adds a new line break if needed.
@param string $tab
@return bool | [
"Adds",
"a",
"new",
"line",
"break",
"if",
"needed",
"."
] | 865e9c13ff78be6af03b2b259e28c6677f3d79aa | https://github.com/nilportugues/php-sql-query-formatter/blob/865e9c13ff78be6af03b2b259e28c6677f3d79aa/src/Helper/NewLine.php#L60-L71 |
38,902 | nilportugues/php-sql-query-formatter | src/Helper/NewLine.php | NewLine.addNewLineAfterOpeningParentheses | public function addNewLineAfterOpeningParentheses()
{
if (false === $this->parentheses->getInlineParentheses()) {
$this->indentation->setIncreaseBlockIndent(true);
$this->newline = true;
}
} | php | public function addNewLineAfterOpeningParentheses()
{
if (false === $this->parentheses->getInlineParentheses()) {
$this->indentation->setIncreaseBlockIndent(true);
$this->newline = true;
}
} | [
"public",
"function",
"addNewLineAfterOpeningParentheses",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"parentheses",
"->",
"getInlineParentheses",
"(",
")",
")",
"{",
"$",
"this",
"->",
"indentation",
"->",
"setIncreaseBlockIndent",
"(",
"true"... | Adds a new line break for an opening parentheses for a non-inline expression. | [
"Adds",
"a",
"new",
"line",
"break",
"for",
"an",
"opening",
"parentheses",
"for",
"a",
"non",
"-",
"inline",
"expression",
"."
] | 865e9c13ff78be6af03b2b259e28c6677f3d79aa | https://github.com/nilportugues/php-sql-query-formatter/blob/865e9c13ff78be6af03b2b259e28c6677f3d79aa/src/Helper/NewLine.php#L101-L107 |
38,903 | nilportugues/php-sql-query-formatter | src/Helper/NewLine.php | NewLine.writeNewLineBecauseOfTopLevelReservedWord | public function writeNewLineBecauseOfTopLevelReservedWord($addedNewline, $tab)
{
if (false === $addedNewline) {
$this->formatter->appendToFormattedSql("\n");
} else {
$this->formatter->setFormattedSql(\rtrim($this->formatter->getFormattedSql(), $tab));
}
$this->formatter->appendToFormattedSql(\str_repeat($tab, $this->indentation->getIndentLvl()));
$this->newline = true;
} | php | public function writeNewLineBecauseOfTopLevelReservedWord($addedNewline, $tab)
{
if (false === $addedNewline) {
$this->formatter->appendToFormattedSql("\n");
} else {
$this->formatter->setFormattedSql(\rtrim($this->formatter->getFormattedSql(), $tab));
}
$this->formatter->appendToFormattedSql(\str_repeat($tab, $this->indentation->getIndentLvl()));
$this->newline = true;
} | [
"public",
"function",
"writeNewLineBecauseOfTopLevelReservedWord",
"(",
"$",
"addedNewline",
",",
"$",
"tab",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"addedNewline",
")",
"{",
"$",
"this",
"->",
"formatter",
"->",
"appendToFormattedSql",
"(",
"\"\\n\"",
")",
... | Add a newline before the top level reserved word if necessary and indent.
@param bool $addedNewline
@param string $tab | [
"Add",
"a",
"newline",
"before",
"the",
"top",
"level",
"reserved",
"word",
"if",
"necessary",
"and",
"indent",
"."
] | 865e9c13ff78be6af03b2b259e28c6677f3d79aa | https://github.com/nilportugues/php-sql-query-formatter/blob/865e9c13ff78be6af03b2b259e28c6677f3d79aa/src/Helper/NewLine.php#L128-L138 |
38,904 | nilportugues/php-sql-query-formatter | src/Helper/NewLine.php | NewLine.writeNewLineBecauseOfComma | public function writeNewLineBecauseOfComma()
{
$this->newline = true;
if (true === $this->formatter->getClauseLimit()) {
$this->newline = false;
$this->formatter->setClauseLimit(false);
}
} | php | public function writeNewLineBecauseOfComma()
{
$this->newline = true;
if (true === $this->formatter->getClauseLimit()) {
$this->newline = false;
$this->formatter->setClauseLimit(false);
}
} | [
"public",
"function",
"writeNewLineBecauseOfComma",
"(",
")",
"{",
"$",
"this",
"->",
"newline",
"=",
"true",
";",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"formatter",
"->",
"getClauseLimit",
"(",
")",
")",
"{",
"$",
"this",
"->",
"newline",
"=",
... | Commas start a new line unless they are found within inline parentheses or SQL 'LIMIT' clause.
If the previous TOKEN_VALUE is 'LIMIT', undo new line. | [
"Commas",
"start",
"a",
"new",
"line",
"unless",
"they",
"are",
"found",
"within",
"inline",
"parentheses",
"or",
"SQL",
"LIMIT",
"clause",
".",
"If",
"the",
"previous",
"TOKEN_VALUE",
"is",
"LIMIT",
"undo",
"new",
"line",
"."
] | 865e9c13ff78be6af03b2b259e28c6677f3d79aa | https://github.com/nilportugues/php-sql-query-formatter/blob/865e9c13ff78be6af03b2b259e28c6677f3d79aa/src/Helper/NewLine.php#L144-L152 |
38,905 | nilportugues/php-sql-query-formatter | src/Formatter.php | Formatter.format | public function format($sql)
{
$this->reset();
$tab = "\t";
$originalTokens = $this->tokenizer->tokenize((string) $sql);
$tokens = WhiteSpace::removeTokenWhitespace($originalTokens);
foreach ($tokens as $i => $token) {
$queryValue = $token[Tokenizer::TOKEN_VALUE];
$this->indentation->increaseSpecialIndent()->increaseBlockIndent();
$addedNewline = $this->newLine->addNewLineBreak($tab);
if ($this->comment->stringHasCommentToken($token)) {
$this->formattedSql = $this->comment->writeCommentBlock($token, $tab, $queryValue);
continue;
}
if ($this->parentheses->getInlineParentheses()) {
if ($this->parentheses->stringIsClosingParentheses($token)) {
$this->parentheses->writeInlineParenthesesBlock($tab, $queryValue);
continue;
}
$this->newLine->writeNewLineForLongCommaInlineValues($token);
$this->inlineCount += \strlen($token[Tokenizer::TOKEN_VALUE]);
}
switch ($token) {
case $this->parentheses->stringIsOpeningParentheses($token):
$tokens = $this->formatOpeningParenthesis($token, $i, $tokens, $originalTokens);
break;
case $this->parentheses->stringIsClosingParentheses($token):
$this->indentation->decreaseIndentLevelUntilIndentTypeIsSpecial($this);
$this->newLine->addNewLineBeforeToken($addedNewline, $tab);
break;
case $this->stringIsEndOfLimitClause($token):
$this->clauseLimit = false;
break;
case $token[Tokenizer::TOKEN_VALUE] === ',' && false === $this->parentheses->getInlineParentheses():
$this->newLine->writeNewLineBecauseOfComma();
break;
case Token::isTokenTypeReservedTopLevel($token):
$queryValue = $this->formatTokenTypeReservedTopLevel($addedNewline, $tab, $token, $queryValue);
break;
case $this->newLine->isTokenTypeReservedNewLine($token):
$this->newLine->addNewLineBeforeToken($addedNewline, $tab);
if (WhiteSpace::tokenHasExtraWhiteSpaces($token)) {
$queryValue = \preg_replace('/\s+/', ' ', $queryValue);
}
break;
}
$this->formatBoundaryCharacterToken($token, $i, $tokens, $originalTokens);
$this->formatWhiteSpaceToken($token, $queryValue);
$this->formatDashToken($token, $i, $tokens);
}
return \trim(\str_replace(["\t", " \n"], [$this->tab, "\n"], $this->formattedSql))."\n";
} | php | public function format($sql)
{
$this->reset();
$tab = "\t";
$originalTokens = $this->tokenizer->tokenize((string) $sql);
$tokens = WhiteSpace::removeTokenWhitespace($originalTokens);
foreach ($tokens as $i => $token) {
$queryValue = $token[Tokenizer::TOKEN_VALUE];
$this->indentation->increaseSpecialIndent()->increaseBlockIndent();
$addedNewline = $this->newLine->addNewLineBreak($tab);
if ($this->comment->stringHasCommentToken($token)) {
$this->formattedSql = $this->comment->writeCommentBlock($token, $tab, $queryValue);
continue;
}
if ($this->parentheses->getInlineParentheses()) {
if ($this->parentheses->stringIsClosingParentheses($token)) {
$this->parentheses->writeInlineParenthesesBlock($tab, $queryValue);
continue;
}
$this->newLine->writeNewLineForLongCommaInlineValues($token);
$this->inlineCount += \strlen($token[Tokenizer::TOKEN_VALUE]);
}
switch ($token) {
case $this->parentheses->stringIsOpeningParentheses($token):
$tokens = $this->formatOpeningParenthesis($token, $i, $tokens, $originalTokens);
break;
case $this->parentheses->stringIsClosingParentheses($token):
$this->indentation->decreaseIndentLevelUntilIndentTypeIsSpecial($this);
$this->newLine->addNewLineBeforeToken($addedNewline, $tab);
break;
case $this->stringIsEndOfLimitClause($token):
$this->clauseLimit = false;
break;
case $token[Tokenizer::TOKEN_VALUE] === ',' && false === $this->parentheses->getInlineParentheses():
$this->newLine->writeNewLineBecauseOfComma();
break;
case Token::isTokenTypeReservedTopLevel($token):
$queryValue = $this->formatTokenTypeReservedTopLevel($addedNewline, $tab, $token, $queryValue);
break;
case $this->newLine->isTokenTypeReservedNewLine($token):
$this->newLine->addNewLineBeforeToken($addedNewline, $tab);
if (WhiteSpace::tokenHasExtraWhiteSpaces($token)) {
$queryValue = \preg_replace('/\s+/', ' ', $queryValue);
}
break;
}
$this->formatBoundaryCharacterToken($token, $i, $tokens, $originalTokens);
$this->formatWhiteSpaceToken($token, $queryValue);
$this->formatDashToken($token, $i, $tokens);
}
return \trim(\str_replace(["\t", " \n"], [$this->tab, "\n"], $this->formattedSql))."\n";
} | [
"public",
"function",
"format",
"(",
"$",
"sql",
")",
"{",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"$",
"tab",
"=",
"\"\\t\"",
";",
"$",
"originalTokens",
"=",
"$",
"this",
"->",
"tokenizer",
"->",
"tokenize",
"(",
"(",
"string",
")",
"$",
"sql"... | Returns a SQL string in a readable human-friendly format.
@param string $sql
@return string | [
"Returns",
"a",
"SQL",
"string",
"in",
"a",
"readable",
"human",
"-",
"friendly",
"format",
"."
] | 865e9c13ff78be6af03b2b259e28c6677f3d79aa | https://github.com/nilportugues/php-sql-query-formatter/blob/865e9c13ff78be6af03b2b259e28c6677f3d79aa/src/Formatter.php#L77-L141 |
38,906 | nilportugues/php-sql-query-formatter | src/Helper/Indent.php | Indent.increaseSpecialIndent | public function increaseSpecialIndent()
{
if ($this->increaseSpecialIndent) {
++$this->indentLvl;
$this->increaseSpecialIndent = false;
\array_unshift($this->indentTypes, 'special');
}
return $this;
} | php | public function increaseSpecialIndent()
{
if ($this->increaseSpecialIndent) {
++$this->indentLvl;
$this->increaseSpecialIndent = false;
\array_unshift($this->indentTypes, 'special');
}
return $this;
} | [
"public",
"function",
"increaseSpecialIndent",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"increaseSpecialIndent",
")",
"{",
"++",
"$",
"this",
"->",
"indentLvl",
";",
"$",
"this",
"->",
"increaseSpecialIndent",
"=",
"false",
";",
"\\",
"array_unshift",
"(... | Increase the Special Indent if increaseSpecialIndent is true after the current iteration.
@return $this | [
"Increase",
"the",
"Special",
"Indent",
"if",
"increaseSpecialIndent",
"is",
"true",
"after",
"the",
"current",
"iteration",
"."
] | 865e9c13ff78be6af03b2b259e28c6677f3d79aa | https://github.com/nilportugues/php-sql-query-formatter/blob/865e9c13ff78be6af03b2b259e28c6677f3d79aa/src/Helper/Indent.php#L50-L59 |
38,907 | nilportugues/php-sql-query-formatter | src/Helper/Indent.php | Indent.increaseBlockIndent | public function increaseBlockIndent()
{
if ($this->increaseBlockIndent) {
++$this->indentLvl;
$this->increaseBlockIndent = false;
\array_unshift($this->indentTypes, 'block');
}
return $this;
} | php | public function increaseBlockIndent()
{
if ($this->increaseBlockIndent) {
++$this->indentLvl;
$this->increaseBlockIndent = false;
\array_unshift($this->indentTypes, 'block');
}
return $this;
} | [
"public",
"function",
"increaseBlockIndent",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"increaseBlockIndent",
")",
"{",
"++",
"$",
"this",
"->",
"indentLvl",
";",
"$",
"this",
"->",
"increaseBlockIndent",
"=",
"false",
";",
"\\",
"array_unshift",
"(",
"... | Increase the Block Indent if increaseBlockIndent is true after the current iteration.
@return $this | [
"Increase",
"the",
"Block",
"Indent",
"if",
"increaseBlockIndent",
"is",
"true",
"after",
"the",
"current",
"iteration",
"."
] | 865e9c13ff78be6af03b2b259e28c6677f3d79aa | https://github.com/nilportugues/php-sql-query-formatter/blob/865e9c13ff78be6af03b2b259e28c6677f3d79aa/src/Helper/Indent.php#L66-L75 |
38,908 | nilportugues/php-sql-query-formatter | src/Helper/Indent.php | Indent.decreaseIndentLevelUntilIndentTypeIsSpecial | public function decreaseIndentLevelUntilIndentTypeIsSpecial(Formatter $formatter)
{
$formatter->setFormattedSql(\rtrim($formatter->getFormattedSql(), ' '));
--$this->indentLvl;
while ($j = \array_shift($this->indentTypes)) {
if ('special' !== $j) {
break;
}
--$this->indentLvl;
}
return $this;
} | php | public function decreaseIndentLevelUntilIndentTypeIsSpecial(Formatter $formatter)
{
$formatter->setFormattedSql(\rtrim($formatter->getFormattedSql(), ' '));
--$this->indentLvl;
while ($j = \array_shift($this->indentTypes)) {
if ('special' !== $j) {
break;
}
--$this->indentLvl;
}
return $this;
} | [
"public",
"function",
"decreaseIndentLevelUntilIndentTypeIsSpecial",
"(",
"Formatter",
"$",
"formatter",
")",
"{",
"$",
"formatter",
"->",
"setFormattedSql",
"(",
"\\",
"rtrim",
"(",
"$",
"formatter",
"->",
"getFormattedSql",
"(",
")",
",",
"' '",
")",
")",
";",... | Closing parentheses decrease the block indent level.
@param Formatter $formatter
@return $this | [
"Closing",
"parentheses",
"decrease",
"the",
"block",
"indent",
"level",
"."
] | 865e9c13ff78be6af03b2b259e28c6677f3d79aa | https://github.com/nilportugues/php-sql-query-formatter/blob/865e9c13ff78be6af03b2b259e28c6677f3d79aa/src/Helper/Indent.php#L84-L97 |
38,909 | nilportugues/php-sql-query-formatter | src/Tokenizer/Parser/Reserved.php | Reserved.isReservedPrecededByDotCharacter | protected static function isReservedPrecededByDotCharacter($previous)
{
return !$previous || !isset($previous[Tokenizer::TOKEN_VALUE]) || $previous[Tokenizer::TOKEN_VALUE] !== '.';
} | php | protected static function isReservedPrecededByDotCharacter($previous)
{
return !$previous || !isset($previous[Tokenizer::TOKEN_VALUE]) || $previous[Tokenizer::TOKEN_VALUE] !== '.';
} | [
"protected",
"static",
"function",
"isReservedPrecededByDotCharacter",
"(",
"$",
"previous",
")",
"{",
"return",
"!",
"$",
"previous",
"||",
"!",
"isset",
"(",
"$",
"previous",
"[",
"Tokenizer",
"::",
"TOKEN_VALUE",
"]",
")",
"||",
"$",
"previous",
"[",
"Tok... | A reserved word cannot be preceded by a "." in order to differentiate "mytable.from" from the token "from".
@param $previous
@return bool | [
"A",
"reserved",
"word",
"cannot",
"be",
"preceded",
"by",
"a",
".",
"in",
"order",
"to",
"differentiate",
"mytable",
".",
"from",
"from",
"the",
"token",
"from",
"."
] | 865e9c13ff78be6af03b2b259e28c6677f3d79aa | https://github.com/nilportugues/php-sql-query-formatter/blob/865e9c13ff78be6af03b2b259e28c6677f3d79aa/src/Tokenizer/Parser/Reserved.php#L58-L61 |
38,910 | nilportugues/php-sql-query-formatter | src/Tokenizer/Parser/UserDefined.php | UserDefined.getUserDefinedVariableString | protected static function getUserDefinedVariableString(&$string)
{
$returnData = [
Tokenizer::TOKEN_VALUE => null,
Tokenizer::TOKEN_TYPE => Tokenizer::TOKEN_TYPE_VARIABLE,
];
self::setTokenValueStartingWithAtSymbolAndWrapped($returnData, $string);
self::setTokenValueStartingWithAtSymbol($returnData, $string);
return $returnData;
} | php | protected static function getUserDefinedVariableString(&$string)
{
$returnData = [
Tokenizer::TOKEN_VALUE => null,
Tokenizer::TOKEN_TYPE => Tokenizer::TOKEN_TYPE_VARIABLE,
];
self::setTokenValueStartingWithAtSymbolAndWrapped($returnData, $string);
self::setTokenValueStartingWithAtSymbol($returnData, $string);
return $returnData;
} | [
"protected",
"static",
"function",
"getUserDefinedVariableString",
"(",
"&",
"$",
"string",
")",
"{",
"$",
"returnData",
"=",
"[",
"Tokenizer",
"::",
"TOKEN_VALUE",
"=>",
"null",
",",
"Tokenizer",
"::",
"TOKEN_TYPE",
"=>",
"Tokenizer",
"::",
"TOKEN_TYPE_VARIABLE",... | Gets the user defined variables for in quoted or non-quoted fashion.
@param string $string
@return array | [
"Gets",
"the",
"user",
"defined",
"variables",
"for",
"in",
"quoted",
"or",
"non",
"-",
"quoted",
"fashion",
"."
] | 865e9c13ff78be6af03b2b259e28c6677f3d79aa | https://github.com/nilportugues/php-sql-query-formatter/blob/865e9c13ff78be6af03b2b259e28c6677f3d79aa/src/Tokenizer/Parser/UserDefined.php#L50-L61 |
38,911 | nilportugues/php-sql-query-formatter | src/Tokenizer/Tokenizer.php | Tokenizer.getNextTokenFromString | protected function getNextTokenFromString($string, $token, $cacheKey)
{
$token = $this->parseNextToken($string, $token);
if ($cacheKey && \strlen($token[self::TOKEN_VALUE]) < $this->maxCacheKeySize) {
$this->tokenCache[$cacheKey] = $token;
}
return $token;
} | php | protected function getNextTokenFromString($string, $token, $cacheKey)
{
$token = $this->parseNextToken($string, $token);
if ($cacheKey && \strlen($token[self::TOKEN_VALUE]) < $this->maxCacheKeySize) {
$this->tokenCache[$cacheKey] = $token;
}
return $token;
} | [
"protected",
"function",
"getNextTokenFromString",
"(",
"$",
"string",
",",
"$",
"token",
",",
"$",
"cacheKey",
")",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"parseNextToken",
"(",
"$",
"string",
",",
"$",
"token",
")",
";",
"if",
"(",
"$",
"cacheKey... | Get the next token and the token type and store it in cache.
@param string $string
@param string $token
@param string $cacheKey
@return array | [
"Get",
"the",
"next",
"token",
"and",
"the",
"token",
"type",
"and",
"store",
"it",
"in",
"cache",
"."
] | 865e9c13ff78be6af03b2b259e28c6677f3d79aa | https://github.com/nilportugues/php-sql-query-formatter/blob/865e9c13ff78be6af03b2b259e28c6677f3d79aa/src/Tokenizer/Tokenizer.php#L241-L250 |
38,912 | megahertz/guzzle-tor | src/Middleware.php | Middleware.tor | public static function tor($proxy = '127.0.0.1:9050', $torControl = '127.0.0.1:9051')
{
return function (callable $handler) use ($proxy, $torControl) {
return function (
RequestInterface $request,
array $options
) use ($handler, $proxy, $torControl) {
$options = array_replace_recursive([
'proxy' => $proxy,
'curl' => [
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5_HOSTNAME
]
], $options);
if (array_key_exists('tor_new_identity', $options) && $options['tor_new_identity']) {
try {
self::requireNewTorIdentity($torControl, $options);
} catch (GuzzleException $e) {
if (@$options['tor_new_identity_exception']) {
throw $e;
}
}
}
return $handler($request, $options);
};
};
} | php | public static function tor($proxy = '127.0.0.1:9050', $torControl = '127.0.0.1:9051')
{
return function (callable $handler) use ($proxy, $torControl) {
return function (
RequestInterface $request,
array $options
) use ($handler, $proxy, $torControl) {
$options = array_replace_recursive([
'proxy' => $proxy,
'curl' => [
CURLOPT_PROXYTYPE => CURLPROXY_SOCKS5_HOSTNAME
]
], $options);
if (array_key_exists('tor_new_identity', $options) && $options['tor_new_identity']) {
try {
self::requireNewTorIdentity($torControl, $options);
} catch (GuzzleException $e) {
if (@$options['tor_new_identity_exception']) {
throw $e;
}
}
}
return $handler($request, $options);
};
};
} | [
"public",
"static",
"function",
"tor",
"(",
"$",
"proxy",
"=",
"'127.0.0.1:9050'",
",",
"$",
"torControl",
"=",
"'127.0.0.1:9051'",
")",
"{",
"return",
"function",
"(",
"callable",
"$",
"handler",
")",
"use",
"(",
"$",
"proxy",
",",
"$",
"torControl",
")",... | This middleware allows to use Tor client as a proxy
@param string $proxy Tor socks5 proxy host:port
@param string $torControl Tor control host:port
@return callable | [
"This",
"middleware",
"allows",
"to",
"use",
"Tor",
"client",
"as",
"a",
"proxy"
] | ce58a86b912d4aaf7ccd126e12ef1d9966a82367 | https://github.com/megahertz/guzzle-tor/blob/ce58a86b912d4aaf7ccd126e12ef1d9966a82367/src/Middleware.php#L20-L47 |
38,913 | stekycz/Cronner | src/Cronner/TimestampStorage/FileStorage.php | FileStorage.setTaskName | public function setTaskName(string $taskName = NULL)
{
if ($taskName !== NULL && Strings::length($taskName) <= 0) {
throw new InvalidTaskNameException('Given task name is not valid.');
}
$this->taskName = $taskName;
} | php | public function setTaskName(string $taskName = NULL)
{
if ($taskName !== NULL && Strings::length($taskName) <= 0) {
throw new InvalidTaskNameException('Given task name is not valid.');
}
$this->taskName = $taskName;
} | [
"public",
"function",
"setTaskName",
"(",
"string",
"$",
"taskName",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"taskName",
"!==",
"NULL",
"&&",
"Strings",
"::",
"length",
"(",
"$",
"taskName",
")",
"<=",
"0",
")",
"{",
"throw",
"new",
"InvalidTaskNameExcept... | Sets name of current task.
@param string|null $taskName | [
"Sets",
"name",
"of",
"current",
"task",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/TimestampStorage/FileStorage.php#L48-L54 |
38,914 | stekycz/Cronner | src/Cronner/TimestampStorage/FileStorage.php | FileStorage.saveRunTime | public function saveRunTime(DateTimeInterface $now)
{
$filepath = $this->buildFilePath();
file_put_contents($filepath, $now->format(self::DATETIME_FORMAT));
} | php | public function saveRunTime(DateTimeInterface $now)
{
$filepath = $this->buildFilePath();
file_put_contents($filepath, $now->format(self::DATETIME_FORMAT));
} | [
"public",
"function",
"saveRunTime",
"(",
"DateTimeInterface",
"$",
"now",
")",
"{",
"$",
"filepath",
"=",
"$",
"this",
"->",
"buildFilePath",
"(",
")",
";",
"file_put_contents",
"(",
"$",
"filepath",
",",
"$",
"now",
"->",
"format",
"(",
"self",
"::",
"... | Saves current date and time as last invocation time.
@param DateTimeInterface $now | [
"Saves",
"current",
"date",
"and",
"time",
"as",
"last",
"invocation",
"time",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/TimestampStorage/FileStorage.php#L61-L65 |
38,915 | stekycz/Cronner | src/Cronner/TimestampStorage/FileStorage.php | FileStorage.loadLastRunTime | public function loadLastRunTime()
{
$date = NULL;
$filepath = $this->buildFilePath();
if (file_exists($filepath)) {
$date = file_get_contents($filepath);
$date = DateTime::createFromFormat(self::DATETIME_FORMAT, $date);
}
return $date ? $date : NULL;
} | php | public function loadLastRunTime()
{
$date = NULL;
$filepath = $this->buildFilePath();
if (file_exists($filepath)) {
$date = file_get_contents($filepath);
$date = DateTime::createFromFormat(self::DATETIME_FORMAT, $date);
}
return $date ? $date : NULL;
} | [
"public",
"function",
"loadLastRunTime",
"(",
")",
"{",
"$",
"date",
"=",
"NULL",
";",
"$",
"filepath",
"=",
"$",
"this",
"->",
"buildFilePath",
"(",
")",
";",
"if",
"(",
"file_exists",
"(",
"$",
"filepath",
")",
")",
"{",
"$",
"date",
"=",
"file_get... | Returns date and time of last cron task invocation.
@return DateTimeInterface|null | [
"Returns",
"date",
"and",
"time",
"of",
"last",
"cron",
"task",
"invocation",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/TimestampStorage/FileStorage.php#L72-L82 |
38,916 | stekycz/Cronner | src/Cronner/TimestampStorage/FileStorage.php | FileStorage.buildFilePath | private function buildFilePath() : string
{
if ($this->taskName === NULL) {
throw new EmptyTaskNameException('Task name was not set.');
}
return SafeStream::PROTOCOL . '://' . $this->directory . '/' . sha1($this->taskName);
} | php | private function buildFilePath() : string
{
if ($this->taskName === NULL) {
throw new EmptyTaskNameException('Task name was not set.');
}
return SafeStream::PROTOCOL . '://' . $this->directory . '/' . sha1($this->taskName);
} | [
"private",
"function",
"buildFilePath",
"(",
")",
":",
"string",
"{",
"if",
"(",
"$",
"this",
"->",
"taskName",
"===",
"NULL",
")",
"{",
"throw",
"new",
"EmptyTaskNameException",
"(",
"'Task name was not set.'",
")",
";",
"}",
"return",
"SafeStream",
"::",
"... | Builds file path from directory and task name. | [
"Builds",
"file",
"path",
"from",
"directory",
"and",
"task",
"name",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/TimestampStorage/FileStorage.php#L87-L94 |
38,917 | stekycz/Cronner | src/Cronner/Tasks/Task.php | Task.shouldBeRun | public function shouldBeRun(DateTimeInterface $now = NULL) : bool
{
if ($now === NULL) {
$now = new DateTime();
}
$parameters = $this->getParameters();
if (!$parameters->isTask()) {
return FALSE;
}
$this->timestampStorage->setTaskName($parameters->getName());
return $parameters->isInDay($now)
&& $parameters->isInTime($now)
&& $parameters->isNextPeriod($now, $this->timestampStorage->loadLastRunTime());
} | php | public function shouldBeRun(DateTimeInterface $now = NULL) : bool
{
if ($now === NULL) {
$now = new DateTime();
}
$parameters = $this->getParameters();
if (!$parameters->isTask()) {
return FALSE;
}
$this->timestampStorage->setTaskName($parameters->getName());
return $parameters->isInDay($now)
&& $parameters->isInTime($now)
&& $parameters->isNextPeriod($now, $this->timestampStorage->loadLastRunTime());
} | [
"public",
"function",
"shouldBeRun",
"(",
"DateTimeInterface",
"$",
"now",
"=",
"NULL",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"now",
"===",
"NULL",
")",
"{",
"$",
"now",
"=",
"new",
"DateTime",
"(",
")",
";",
"}",
"$",
"parameters",
"=",
"$",
"thi... | Returns True if given parameters should be run. | [
"Returns",
"True",
"if",
"given",
"parameters",
"should",
"be",
"run",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Tasks/Task.php#L71-L86 |
38,918 | stekycz/Cronner | src/Cronner/Tasks/Task.php | Task.getParameters | private function getParameters() : Parameters
{
if ($this->parameters === NULL) {
$this->parameters = new Parameters(Parameters::parseParameters($this->method));
}
return $this->parameters;
} | php | private function getParameters() : Parameters
{
if ($this->parameters === NULL) {
$this->parameters = new Parameters(Parameters::parseParameters($this->method));
}
return $this->parameters;
} | [
"private",
"function",
"getParameters",
"(",
")",
":",
"Parameters",
"{",
"if",
"(",
"$",
"this",
"->",
"parameters",
"===",
"NULL",
")",
"{",
"$",
"this",
"->",
"parameters",
"=",
"new",
"Parameters",
"(",
"Parameters",
"::",
"parseParameters",
"(",
"$",
... | Returns instance of parsed parameters. | [
"Returns",
"instance",
"of",
"parsed",
"parameters",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Tasks/Task.php#L104-L111 |
38,919 | stekycz/Cronner | src/Cronner/Cronner.php | Cronner.setMaxExecutionTime | public function setMaxExecutionTime(int $maxExecutionTime = NULL) : self
{
if ($maxExecutionTime !== NULL && $maxExecutionTime <= 0) {
throw new InvalidArgumentException("Max execution time must be NULL or non negative number.");
}
$this->maxExecutionTime = $maxExecutionTime;
return $this;
} | php | public function setMaxExecutionTime(int $maxExecutionTime = NULL) : self
{
if ($maxExecutionTime !== NULL && $maxExecutionTime <= 0) {
throw new InvalidArgumentException("Max execution time must be NULL or non negative number.");
}
$this->maxExecutionTime = $maxExecutionTime;
return $this;
} | [
"public",
"function",
"setMaxExecutionTime",
"(",
"int",
"$",
"maxExecutionTime",
"=",
"NULL",
")",
":",
"self",
"{",
"if",
"(",
"$",
"maxExecutionTime",
"!==",
"NULL",
"&&",
"$",
"maxExecutionTime",
"<=",
"0",
")",
"{",
"throw",
"new",
"InvalidArgumentExcepti... | Sets max execution time for Cronner. It is used only when Cronner runs.
@param int|null $maxExecutionTime
@return Cronner
@throws InvalidArgumentException | [
"Sets",
"max",
"execution",
"time",
"for",
"Cronner",
".",
"It",
"is",
"used",
"only",
"when",
"Cronner",
"runs",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Cronner.php#L119-L127 |
38,920 | stekycz/Cronner | src/Cronner/Cronner.php | Cronner.addTasks | public function addTasks($tasks) : self
{
$tasksId = $this->createIdFromObject($tasks);
if (in_array($tasksId, $this->registeredTaskObjects)) {
throw new InvalidArgumentException("Tasks with ID '" . $tasksId . "' have been already added.");
}
$reflection = new ClassType($tasks);
$methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
if (!Strings::startsWith($method->getName(), '__') && $method->hasAnnotation(Parameters::TASK)) {
$task = new Task($tasks, $method, $this->timestampStorage);
if (array_key_exists($task->getName(), $this->tasks)) {
throw new DuplicateTaskNameException('Cannot use more tasks with the same name "' . $task->getName() . '".');
}
$this->tasks[$task->getName()] = $task;
}
}
$this->registeredTaskObjects[] = $tasksId;
return $this;
} | php | public function addTasks($tasks) : self
{
$tasksId = $this->createIdFromObject($tasks);
if (in_array($tasksId, $this->registeredTaskObjects)) {
throw new InvalidArgumentException("Tasks with ID '" . $tasksId . "' have been already added.");
}
$reflection = new ClassType($tasks);
$methods = $reflection->getMethods(ReflectionMethod::IS_PUBLIC);
foreach ($methods as $method) {
if (!Strings::startsWith($method->getName(), '__') && $method->hasAnnotation(Parameters::TASK)) {
$task = new Task($tasks, $method, $this->timestampStorage);
if (array_key_exists($task->getName(), $this->tasks)) {
throw new DuplicateTaskNameException('Cannot use more tasks with the same name "' . $task->getName() . '".');
}
$this->tasks[$task->getName()] = $task;
}
}
$this->registeredTaskObjects[] = $tasksId;
return $this;
} | [
"public",
"function",
"addTasks",
"(",
"$",
"tasks",
")",
":",
"self",
"{",
"$",
"tasksId",
"=",
"$",
"this",
"->",
"createIdFromObject",
"(",
"$",
"tasks",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"tasksId",
",",
"$",
"this",
"->",
"registeredTaskOb... | Adds task case to be processed when cronner runs. If tasks
with name which is already added are given then throws
an exception.
@param object $tasks
@return Cronner
@throws InvalidArgumentException | [
"Adds",
"task",
"case",
"to",
"be",
"processed",
"when",
"cronner",
"runs",
".",
"If",
"tasks",
"with",
"name",
"which",
"is",
"already",
"added",
"are",
"given",
"then",
"throws",
"an",
"exception",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Cronner.php#L158-L179 |
38,921 | stekycz/Cronner | src/Cronner/Cronner.php | Cronner.run | public function run(DateTimeInterface $now = NULL)
{
if ($now === NULL) {
$now = new DateTime();
}
if ($this->maxExecutionTime !== NULL) {
set_time_limit($this->maxExecutionTime);
}
foreach ($this->tasks as $task) {
try {
$name = $task->getName();
if ($task->shouldBeRun($now)) {
if ($this->criticalSection->enter($name)) {
$this->onTaskBegin($this, $task);
$task($now);
$this->onTaskFinished($this, $task);
$this->criticalSection->leave($name);
}
}
} catch (Exception $e) {
$this->onTaskError($this, $e, $task);
$name = $task->getName();
if ($this->criticalSection->isEntered($name)) {
$this->criticalSection->leave($name);
}
if ($e instanceof RuntimeException) {
throw $e; // Throw exception if it is Cronner Runtime exception
} elseif ($this->skipFailedTask === FALSE) {
throw $e; // Throw exception if failed task should not be skipped
}
}
}
} | php | public function run(DateTimeInterface $now = NULL)
{
if ($now === NULL) {
$now = new DateTime();
}
if ($this->maxExecutionTime !== NULL) {
set_time_limit($this->maxExecutionTime);
}
foreach ($this->tasks as $task) {
try {
$name = $task->getName();
if ($task->shouldBeRun($now)) {
if ($this->criticalSection->enter($name)) {
$this->onTaskBegin($this, $task);
$task($now);
$this->onTaskFinished($this, $task);
$this->criticalSection->leave($name);
}
}
} catch (Exception $e) {
$this->onTaskError($this, $e, $task);
$name = $task->getName();
if ($this->criticalSection->isEntered($name)) {
$this->criticalSection->leave($name);
}
if ($e instanceof RuntimeException) {
throw $e; // Throw exception if it is Cronner Runtime exception
} elseif ($this->skipFailedTask === FALSE) {
throw $e; // Throw exception if failed task should not be skipped
}
}
}
} | [
"public",
"function",
"run",
"(",
"DateTimeInterface",
"$",
"now",
"=",
"NULL",
")",
"{",
"if",
"(",
"$",
"now",
"===",
"NULL",
")",
"{",
"$",
"now",
"=",
"new",
"DateTime",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"maxExecutionTime",
"!==... | Runs all cron tasks. | [
"Runs",
"all",
"cron",
"tasks",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Cronner.php#L184-L217 |
38,922 | stekycz/Cronner | src/Cronner/Tasks/Parameters.php | Parameters.isInDay | public function isInDay(DateTimeInterface $now) : bool
{
if (($days = $this->values[static::DAYS]) !== NULL) {
return in_array($now->format('D'), $days);
}
return TRUE;
} | php | public function isInDay(DateTimeInterface $now) : bool
{
if (($days = $this->values[static::DAYS]) !== NULL) {
return in_array($now->format('D'), $days);
}
return TRUE;
} | [
"public",
"function",
"isInDay",
"(",
"DateTimeInterface",
"$",
"now",
")",
":",
"bool",
"{",
"if",
"(",
"(",
"$",
"days",
"=",
"$",
"this",
"->",
"values",
"[",
"static",
"::",
"DAYS",
"]",
")",
"!==",
"NULL",
")",
"{",
"return",
"in_array",
"(",
... | Returns true if today is allowed day of week. | [
"Returns",
"true",
"if",
"today",
"is",
"allowed",
"day",
"of",
"week",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Tasks/Parameters.php#L51-L58 |
38,923 | stekycz/Cronner | src/Cronner/Tasks/Parameters.php | Parameters.isInTime | public function isInTime(DateTimeInterface $now) : bool
{
if ($times = $this->values[static::TIME]) {
foreach ($times as $time) {
if ($time['to'] && $time['to'] >= $now->format('H:i') && $time['from'] <= $now->format('H:i')) {
// Is in range with precision to minutes
return TRUE;
} elseif ($time['from'] == $now->format('H:i')) {
// Is in specific minute
return TRUE;
}
}
return FALSE;
}
return TRUE;
} | php | public function isInTime(DateTimeInterface $now) : bool
{
if ($times = $this->values[static::TIME]) {
foreach ($times as $time) {
if ($time['to'] && $time['to'] >= $now->format('H:i') && $time['from'] <= $now->format('H:i')) {
// Is in range with precision to minutes
return TRUE;
} elseif ($time['from'] == $now->format('H:i')) {
// Is in specific minute
return TRUE;
}
}
return FALSE;
}
return TRUE;
} | [
"public",
"function",
"isInTime",
"(",
"DateTimeInterface",
"$",
"now",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"times",
"=",
"$",
"this",
"->",
"values",
"[",
"static",
"::",
"TIME",
"]",
")",
"{",
"foreach",
"(",
"$",
"times",
"as",
"$",
"time",
"... | Returns true if current time is in allowed range. | [
"Returns",
"true",
"if",
"current",
"time",
"is",
"in",
"allowed",
"range",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Tasks/Parameters.php#L63-L80 |
38,924 | stekycz/Cronner | src/Cronner/Tasks/Parameters.php | Parameters.isNextPeriod | public function isNextPeriod(DateTimeInterface $now, DateTimeInterface $lastRunTime = NULL) : bool
{
if (
$lastRunTime !== NULL
&& !$lastRunTime instanceof \DateTimeImmutable
&& !$lastRunTime instanceof \DateTime
) {
throw new InvalidArgumentException;
}
if (isset($this->values[static::PERIOD]) && $this->values[static::PERIOD]) {
// Prevent run task on next cronner run because of a few seconds shift
$now = Nette\Utils\DateTime::from($now)->modifyClone('+5 seconds');
return $lastRunTime === NULL || $lastRunTime->modify('+ ' . $this->values[static::PERIOD]) <= $now;
}
return TRUE;
} | php | public function isNextPeriod(DateTimeInterface $now, DateTimeInterface $lastRunTime = NULL) : bool
{
if (
$lastRunTime !== NULL
&& !$lastRunTime instanceof \DateTimeImmutable
&& !$lastRunTime instanceof \DateTime
) {
throw new InvalidArgumentException;
}
if (isset($this->values[static::PERIOD]) && $this->values[static::PERIOD]) {
// Prevent run task on next cronner run because of a few seconds shift
$now = Nette\Utils\DateTime::from($now)->modifyClone('+5 seconds');
return $lastRunTime === NULL || $lastRunTime->modify('+ ' . $this->values[static::PERIOD]) <= $now;
}
return TRUE;
} | [
"public",
"function",
"isNextPeriod",
"(",
"DateTimeInterface",
"$",
"now",
",",
"DateTimeInterface",
"$",
"lastRunTime",
"=",
"NULL",
")",
":",
"bool",
"{",
"if",
"(",
"$",
"lastRunTime",
"!==",
"NULL",
"&&",
"!",
"$",
"lastRunTime",
"instanceof",
"\\",
"Da... | Returns true if current time is next period of invocation. | [
"Returns",
"true",
"if",
"current",
"time",
"is",
"next",
"period",
"of",
"invocation",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Tasks/Parameters.php#L85-L103 |
38,925 | stekycz/Cronner | src/Cronner/Tasks/Parameters.php | Parameters.parseParameters | public static function parseParameters(Method $method) : array
{
$taskName = NULL;
if ($method->hasAnnotation(Parameters::TASK)) {
$className = $method->getDeclaringClass()->getName();
$methodName = $method->getName();
$taskName = $className . ' - ' . $methodName;
}
$taskAnnotation = $method->getAnnotation(Parameters::TASK);
$parameters = [
static::TASK => is_string($taskAnnotation)
? Parser::parseName($taskAnnotation)
: $taskName,
static::PERIOD => $method->hasAnnotation(Parameters::PERIOD)
? Parser::parsePeriod((string) $method->getAnnotation(Parameters::PERIOD))
: NULL,
static::DAYS => $method->hasAnnotation(Parameters::DAYS)
? Parser::parseDays((string) $method->getAnnotation(Parameters::DAYS))
: NULL,
static::TIME => $method->hasAnnotation(Parameters::TIME)
? Parser::parseTimes((string) $method->getAnnotation(Parameters::TIME))
: NULL,
];
return $parameters;
} | php | public static function parseParameters(Method $method) : array
{
$taskName = NULL;
if ($method->hasAnnotation(Parameters::TASK)) {
$className = $method->getDeclaringClass()->getName();
$methodName = $method->getName();
$taskName = $className . ' - ' . $methodName;
}
$taskAnnotation = $method->getAnnotation(Parameters::TASK);
$parameters = [
static::TASK => is_string($taskAnnotation)
? Parser::parseName($taskAnnotation)
: $taskName,
static::PERIOD => $method->hasAnnotation(Parameters::PERIOD)
? Parser::parsePeriod((string) $method->getAnnotation(Parameters::PERIOD))
: NULL,
static::DAYS => $method->hasAnnotation(Parameters::DAYS)
? Parser::parseDays((string) $method->getAnnotation(Parameters::DAYS))
: NULL,
static::TIME => $method->hasAnnotation(Parameters::TIME)
? Parser::parseTimes((string) $method->getAnnotation(Parameters::TIME))
: NULL,
];
return $parameters;
} | [
"public",
"static",
"function",
"parseParameters",
"(",
"Method",
"$",
"method",
")",
":",
"array",
"{",
"$",
"taskName",
"=",
"NULL",
";",
"if",
"(",
"$",
"method",
"->",
"hasAnnotation",
"(",
"Parameters",
"::",
"TASK",
")",
")",
"{",
"$",
"className",... | Parse cronner values from annotations. | [
"Parse",
"cronner",
"values",
"from",
"annotations",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Tasks/Parameters.php#L108-L135 |
38,926 | stekycz/Cronner | src/Cronner/Tasks/Parser.php | Parser.parseName | public static function parseName(string $annotation)
{
$name = Strings::trim($annotation);
$name = Strings::length($name) > 0 ? $name : NULL;
return $name;
} | php | public static function parseName(string $annotation)
{
$name = Strings::trim($annotation);
$name = Strings::length($name) > 0 ? $name : NULL;
return $name;
} | [
"public",
"static",
"function",
"parseName",
"(",
"string",
"$",
"annotation",
")",
"{",
"$",
"name",
"=",
"Strings",
"::",
"trim",
"(",
"$",
"annotation",
")",
";",
"$",
"name",
"=",
"Strings",
"::",
"length",
"(",
"$",
"name",
")",
">",
"0",
"?",
... | Parses name of cron task.
@param string $annotation
@return string|null | [
"Parses",
"name",
"of",
"cron",
"task",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Tasks/Parser.php#L20-L26 |
38,927 | stekycz/Cronner | src/Cronner/Tasks/Parser.php | Parser.parsePeriod | public static function parsePeriod(string $annotation)
{
$period = NULL;
$annotation = Strings::trim($annotation);
if (Strings::length($annotation)) {
if (strtotime('+ ' . $annotation) === FALSE) {
throw new InvalidParameterException(
"Given period parameter '" . $annotation . "' must be valid for strtotime() with '+' sign as its prefix (added by Cronner automatically)."
);
}
$period = $annotation;
}
return $period ?: NULL;
} | php | public static function parsePeriod(string $annotation)
{
$period = NULL;
$annotation = Strings::trim($annotation);
if (Strings::length($annotation)) {
if (strtotime('+ ' . $annotation) === FALSE) {
throw new InvalidParameterException(
"Given period parameter '" . $annotation . "' must be valid for strtotime() with '+' sign as its prefix (added by Cronner automatically)."
);
}
$period = $annotation;
}
return $period ?: NULL;
} | [
"public",
"static",
"function",
"parsePeriod",
"(",
"string",
"$",
"annotation",
")",
"{",
"$",
"period",
"=",
"NULL",
";",
"$",
"annotation",
"=",
"Strings",
"::",
"trim",
"(",
"$",
"annotation",
")",
";",
"if",
"(",
"Strings",
"::",
"length",
"(",
"$... | Parses period of cron task. If annotation is invalid throws exception.
@param string $annotation
@return string|null
@throws InvalidParameterException | [
"Parses",
"period",
"of",
"cron",
"task",
".",
"If",
"annotation",
"is",
"invalid",
"throws",
"exception",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Tasks/Parser.php#L35-L49 |
38,928 | stekycz/Cronner | src/Cronner/Tasks/Parser.php | Parser.parseDays | public static function parseDays(string $annotation)
{
static $validValues = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun',];
$days = NULL;
$annotation = Strings::trim($annotation);
if (Strings::length($annotation)) {
$days = static::translateToDayNames($annotation);
$days = static::expandDaysRange($days);
foreach ($days as $day) {
if (!in_array($day, $validValues)) {
throw new InvalidParameterException(
"Given day parameter '" . $day . "' must be one from " . implode(', ', $validValues) . "."
);
}
}
$days = array_values(array_intersect($validValues, $days));
}
return $days ?: NULL;
} | php | public static function parseDays(string $annotation)
{
static $validValues = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun',];
$days = NULL;
$annotation = Strings::trim($annotation);
if (Strings::length($annotation)) {
$days = static::translateToDayNames($annotation);
$days = static::expandDaysRange($days);
foreach ($days as $day) {
if (!in_array($day, $validValues)) {
throw new InvalidParameterException(
"Given day parameter '" . $day . "' must be one from " . implode(', ', $validValues) . "."
);
}
}
$days = array_values(array_intersect($validValues, $days));
}
return $days ?: NULL;
} | [
"public",
"static",
"function",
"parseDays",
"(",
"string",
"$",
"annotation",
")",
"{",
"static",
"$",
"validValues",
"=",
"[",
"'Mon'",
",",
"'Tue'",
",",
"'Wed'",
",",
"'Thu'",
",",
"'Fri'",
",",
"'Sat'",
",",
"'Sun'",
",",
"]",
";",
"$",
"days",
... | Parses allowed days for cron task. If annotation is invalid
throws exception.
@param string $annotation
@return string[]|null
@throws InvalidParameterException | [
"Parses",
"allowed",
"days",
"for",
"cron",
"task",
".",
"If",
"annotation",
"is",
"invalid",
"throws",
"exception",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Tasks/Parser.php#L59-L79 |
38,929 | stekycz/Cronner | src/Cronner/Tasks/Parser.php | Parser.parseTimes | public static function parseTimes(string $annotation)
{
$times = NULL;
$annotation = Strings::trim($annotation);
if (Strings::length($annotation)) {
if ($values = static::splitMultipleValues($annotation)) {
$times = [];
foreach ($values as $time) {
$times = array_merge($times, static::parseOneTime($time));
}
usort($times, function ($a, $b) {
return $a < $b ? -1 : ($a > $b ? 1 : 0);
});
}
}
return $times ?: NULL;
} | php | public static function parseTimes(string $annotation)
{
$times = NULL;
$annotation = Strings::trim($annotation);
if (Strings::length($annotation)) {
if ($values = static::splitMultipleValues($annotation)) {
$times = [];
foreach ($values as $time) {
$times = array_merge($times, static::parseOneTime($time));
}
usort($times, function ($a, $b) {
return $a < $b ? -1 : ($a > $b ? 1 : 0);
});
}
}
return $times ?: NULL;
} | [
"public",
"static",
"function",
"parseTimes",
"(",
"string",
"$",
"annotation",
")",
"{",
"$",
"times",
"=",
"NULL",
";",
"$",
"annotation",
"=",
"Strings",
"::",
"trim",
"(",
"$",
"annotation",
")",
";",
"if",
"(",
"Strings",
"::",
"length",
"(",
"$",... | Parses allowed time ranges for cron task. If annotation is invalid
throws exception.
@param string $annotation
@return string[][]|null
@throws InvalidParameterException | [
"Parses",
"allowed",
"time",
"ranges",
"for",
"cron",
"task",
".",
"If",
"annotation",
"is",
"invalid",
"throws",
"exception",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Tasks/Parser.php#L89-L106 |
38,930 | stekycz/Cronner | src/Cronner/Tasks/Parser.php | Parser.expandDaysRange | private static function expandDaysRange(array $days) : array
{
static $dayNames = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun',];
$expandedValues = [];
foreach ($days as $day) {
if (Strings::match($day, '~^\w{3}\s*-\s*\w{3}$~u')) {
list($begin, $end) = Strings::split($day, '~\s*-\s*~');
$started = FALSE;
foreach ($dayNames as $dayName) {
if ($dayName === $begin) {
$started = TRUE;
}
if ($started) {
$expandedValues[] = $dayName;
}
if ($dayName === $end) {
$started = FALSE;
}
}
} else {
$expandedValues[] = $day;
}
}
return array_unique($expandedValues);
} | php | private static function expandDaysRange(array $days) : array
{
static $dayNames = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun',];
$expandedValues = [];
foreach ($days as $day) {
if (Strings::match($day, '~^\w{3}\s*-\s*\w{3}$~u')) {
list($begin, $end) = Strings::split($day, '~\s*-\s*~');
$started = FALSE;
foreach ($dayNames as $dayName) {
if ($dayName === $begin) {
$started = TRUE;
}
if ($started) {
$expandedValues[] = $dayName;
}
if ($dayName === $end) {
$started = FALSE;
}
}
} else {
$expandedValues[] = $day;
}
}
return array_unique($expandedValues);
} | [
"private",
"static",
"function",
"expandDaysRange",
"(",
"array",
"$",
"days",
")",
":",
"array",
"{",
"static",
"$",
"dayNames",
"=",
"[",
"'Mon'",
",",
"'Tue'",
",",
"'Wed'",
",",
"'Thu'",
",",
"'Fri'",
",",
"'Sat'",
",",
"'Sun'",
",",
"]",
";",
"$... | Expands given day names and day ranges to day names only. The day range must be
in "Mon-Fri" format.
@param string[] $days
@return string[] | [
"Expands",
"given",
"day",
"names",
"and",
"day",
"ranges",
"to",
"day",
"names",
"only",
".",
"The",
"day",
"range",
"must",
"be",
"in",
"Mon",
"-",
"Fri",
"format",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Tasks/Parser.php#L144-L170 |
38,931 | stekycz/Cronner | src/Cronner/Tasks/Parser.php | Parser.parseOneTime | private static function parseOneTime(string $time) : array
{
$time = static::translateToTimes($time);
$parts = Strings::split($time, '/\s*-\s*/');
if (!static::isValidTime($parts[0]) || (isset($parts[1]) && !static::isValidTime($parts[1]))) {
throw new InvalidParameterException(
"Times annotation is not in valid format. It must looks like 'hh:mm[ - hh:mm]' but '" . $time . "' was given."
);
}
$times = [];
if (static::isTimeOverMidnight($parts[0], isset($parts[1]) ? $parts[1] : NULL)) {
$times[] = static::timePartsToArray('00:00', $parts[1]);
$times[] = static::timePartsToArray($parts[0], '23:59');
} else {
$times[] = static::timePartsToArray($parts[0], isset($parts[1]) ? $parts[1] : NULL);
}
return $times;
} | php | private static function parseOneTime(string $time) : array
{
$time = static::translateToTimes($time);
$parts = Strings::split($time, '/\s*-\s*/');
if (!static::isValidTime($parts[0]) || (isset($parts[1]) && !static::isValidTime($parts[1]))) {
throw new InvalidParameterException(
"Times annotation is not in valid format. It must looks like 'hh:mm[ - hh:mm]' but '" . $time . "' was given."
);
}
$times = [];
if (static::isTimeOverMidnight($parts[0], isset($parts[1]) ? $parts[1] : NULL)) {
$times[] = static::timePartsToArray('00:00', $parts[1]);
$times[] = static::timePartsToArray($parts[0], '23:59');
} else {
$times[] = static::timePartsToArray($parts[0], isset($parts[1]) ? $parts[1] : NULL);
}
return $times;
} | [
"private",
"static",
"function",
"parseOneTime",
"(",
"string",
"$",
"time",
")",
":",
"array",
"{",
"$",
"time",
"=",
"static",
"::",
"translateToTimes",
"(",
"$",
"time",
")",
";",
"$",
"parts",
"=",
"Strings",
"::",
"split",
"(",
"$",
"time",
",",
... | Parses one time annotation. If it is invalid throws exception.
@param string $time
@return string[][]
@throws InvalidParameterException | [
"Parses",
"one",
"time",
"annotation",
".",
"If",
"it",
"is",
"invalid",
"throws",
"exception",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Tasks/Parser.php#L198-L216 |
38,932 | stekycz/Cronner | src/Cronner/Tasks/Parser.php | Parser.isTimeOverMidnight | private static function isTimeOverMidnight(string $from, string $to = NULL) : bool
{
return $to !== NULL && $to < $from;
} | php | private static function isTimeOverMidnight(string $from, string $to = NULL) : bool
{
return $to !== NULL && $to < $from;
} | [
"private",
"static",
"function",
"isTimeOverMidnight",
"(",
"string",
"$",
"from",
",",
"string",
"$",
"to",
"=",
"NULL",
")",
":",
"bool",
"{",
"return",
"$",
"to",
"!==",
"NULL",
"&&",
"$",
"to",
"<",
"$",
"from",
";",
"}"
] | Returns True if given times includes midnight, False otherwise. | [
"Returns",
"True",
"if",
"given",
"times",
"includes",
"midnight",
"False",
"otherwise",
"."
] | 86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c | https://github.com/stekycz/Cronner/blob/86c0d54fd88f7f8ffe7a47e60b17d604cc25cd3c/src/Cronner/Tasks/Parser.php#L238-L241 |
38,933 | cartalyst/converter | src/Converter.php | Converter.format | public function format($measurement = null)
{
// Get the value
$value = $this->getValue();
// Do we have a negative value?
$negative = $value < 0;
// Switch to negative format
$format = $negative ? 'negative' : 'format';
// Get the measurement format
$measurement = $measurement ?: $this->getMeasurement("{$this->to}.{$format}");
// Value Regex
$valRegex = '/([0-9].*|)[0-9]/';
// Match decimal and thousand separators
preg_match_all('/[,.!]/', $measurement, $separators);
if ($thousand = array_get($separators, '0.0', null)) {
if ($thousand == '!') {
$thousand = '';
}
}
$decimal = array_get($separators, '0.1', null);
// Match format for decimals count
preg_match($valRegex, $measurement, $valFormat);
$valFormat = array_get($valFormat, 0, 0);
// Count decimals length
$decimals = $decimal ? strlen(substr(strrchr($valFormat, $decimal), 1)) : 0;
// Strip negative sign
if ($negative) {
$value *= -1;
}
// Format the value
$value = number_format($value, $decimals, $decimal, $thousand);
// Return the formatted measurement
return preg_replace($valRegex, $value, $measurement);
} | php | public function format($measurement = null)
{
// Get the value
$value = $this->getValue();
// Do we have a negative value?
$negative = $value < 0;
// Switch to negative format
$format = $negative ? 'negative' : 'format';
// Get the measurement format
$measurement = $measurement ?: $this->getMeasurement("{$this->to}.{$format}");
// Value Regex
$valRegex = '/([0-9].*|)[0-9]/';
// Match decimal and thousand separators
preg_match_all('/[,.!]/', $measurement, $separators);
if ($thousand = array_get($separators, '0.0', null)) {
if ($thousand == '!') {
$thousand = '';
}
}
$decimal = array_get($separators, '0.1', null);
// Match format for decimals count
preg_match($valRegex, $measurement, $valFormat);
$valFormat = array_get($valFormat, 0, 0);
// Count decimals length
$decimals = $decimal ? strlen(substr(strrchr($valFormat, $decimal), 1)) : 0;
// Strip negative sign
if ($negative) {
$value *= -1;
}
// Format the value
$value = number_format($value, $decimals, $decimal, $thousand);
// Return the formatted measurement
return preg_replace($valRegex, $value, $measurement);
} | [
"public",
"function",
"format",
"(",
"$",
"measurement",
"=",
"null",
")",
"{",
"// Get the value",
"$",
"value",
"=",
"$",
"this",
"->",
"getValue",
"(",
")",
";",
"// Do we have a negative value?",
"$",
"negative",
"=",
"$",
"value",
"<",
"0",
";",
"// S... | Format the value into the desired measurement.
@param string $measurement
@return string | [
"Format",
"the",
"value",
"into",
"the",
"desired",
"measurement",
"."
] | fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c | https://github.com/cartalyst/converter/blob/fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c/src/Converter.php#L174-L220 |
38,934 | cartalyst/converter | src/Converter.php | Converter.getMeasurement | public function getMeasurement($measurement, $default = null)
{
$measurements = $this->getMeasurements();
$measure = array_get($measurements, $measurement, $default);
if (is_null($measure)) {
if (str_contains($measurement, 'negative')) {
return '-' . $this->getMeasurement(str_replace('negative', 'format', $measurement));
}
if (str_contains($measurement, 'currency')) {
$currency = explode('.', $measurement);
return $this->exchanger->get($currency[1]);
}
throw new Exception("Measurement [{$measurement}] was not found.");
}
return $measure;
} | php | public function getMeasurement($measurement, $default = null)
{
$measurements = $this->getMeasurements();
$measure = array_get($measurements, $measurement, $default);
if (is_null($measure)) {
if (str_contains($measurement, 'negative')) {
return '-' . $this->getMeasurement(str_replace('negative', 'format', $measurement));
}
if (str_contains($measurement, 'currency')) {
$currency = explode('.', $measurement);
return $this->exchanger->get($currency[1]);
}
throw new Exception("Measurement [{$measurement}] was not found.");
}
return $measure;
} | [
"public",
"function",
"getMeasurement",
"(",
"$",
"measurement",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"measurements",
"=",
"$",
"this",
"->",
"getMeasurements",
"(",
")",
";",
"$",
"measure",
"=",
"array_get",
"(",
"$",
"measurements",
",",
"... | Returns information about the given measurement.
@param string $measurement
@param mixed $default
@return mixed
@throws \Exception | [
"Returns",
"information",
"about",
"the",
"given",
"measurement",
"."
] | fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c | https://github.com/cartalyst/converter/blob/fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c/src/Converter.php#L253-L274 |
38,935 | steos/php-quickcheck | src/QCheck/Random.php | Random.int_add | public static function int_add($x, $y)
{
if ($y == 0) {
return $x;
} else {
return self::int_add($x ^ $y, ($x & $y) << 1);
}
} | php | public static function int_add($x, $y)
{
if ($y == 0) {
return $x;
} else {
return self::int_add($x ^ $y, ($x & $y) << 1);
}
} | [
"public",
"static",
"function",
"int_add",
"(",
"$",
"x",
",",
"$",
"y",
")",
"{",
"if",
"(",
"$",
"y",
"==",
"0",
")",
"{",
"return",
"$",
"x",
";",
"}",
"else",
"{",
"return",
"self",
"::",
"int_add",
"(",
"$",
"x",
"^",
"$",
"y",
",",
"(... | addition with only shifts and ands | [
"addition",
"with",
"only",
"shifts",
"and",
"ands"
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Random.php#L80-L87 |
38,936 | steos/php-quickcheck | src/QCheck/Generator.php | Generator.sequence | private static function sequence($ms)
{
return FP::reduce(
function (Generator $acc, Generator $elem) {
return $acc->bindGen(function ($xs) use ($elem) {
return $elem->bindGen(function ($y) use ($xs) {
return self::pureGen(FP::push($xs, $y));
});
});
},
$ms,
self::pureGen([])
);
} | php | private static function sequence($ms)
{
return FP::reduce(
function (Generator $acc, Generator $elem) {
return $acc->bindGen(function ($xs) use ($elem) {
return $elem->bindGen(function ($y) use ($xs) {
return self::pureGen(FP::push($xs, $y));
});
});
},
$ms,
self::pureGen([])
);
} | [
"private",
"static",
"function",
"sequence",
"(",
"$",
"ms",
")",
"{",
"return",
"FP",
"::",
"reduce",
"(",
"function",
"(",
"Generator",
"$",
"acc",
",",
"Generator",
"$",
"elem",
")",
"{",
"return",
"$",
"acc",
"->",
"bindGen",
"(",
"function",
"(",
... | turns a list of generators into a generator of a list
@param Generator[]|\Iterator $ms
@return Generator | [
"turns",
"a",
"list",
"of",
"generators",
"into",
"a",
"generator",
"of",
"a",
"list"
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Generator.php#L60-L73 |
38,937 | steos/php-quickcheck | src/QCheck/Generator.php | Generator.fmap | public function fmap(callable $f)
{
return $this->fmapGen(function (RoseTree $rose) use ($f) {
return $rose->fmap($f);
});
} | php | public function fmap(callable $f)
{
return $this->fmapGen(function (RoseTree $rose) use ($f) {
return $rose->fmap($f);
});
} | [
"public",
"function",
"fmap",
"(",
"callable",
"$",
"f",
")",
"{",
"return",
"$",
"this",
"->",
"fmapGen",
"(",
"function",
"(",
"RoseTree",
"$",
"rose",
")",
"use",
"(",
"$",
"f",
")",
"{",
"return",
"$",
"rose",
"->",
"fmap",
"(",
"$",
"f",
")"... | maps function f over the values produced by this generator
@param callable $f
@return Generator | [
"maps",
"function",
"f",
"over",
"the",
"values",
"produced",
"by",
"this",
"generator"
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Generator.php#L81-L86 |
38,938 | steos/php-quickcheck | src/QCheck/Generator.php | Generator.tuples | public static function tuples()
{
$seq = self::sequence(self::getArgs(func_get_args()));
return $seq->bindGen(function ($roses) {
return self::pureGen(RoseTree::zip(FP::args(), $roses));
});
} | php | public static function tuples()
{
$seq = self::sequence(self::getArgs(func_get_args()));
return $seq->bindGen(function ($roses) {
return self::pureGen(RoseTree::zip(FP::args(), $roses));
});
} | [
"public",
"static",
"function",
"tuples",
"(",
")",
"{",
"$",
"seq",
"=",
"self",
"::",
"sequence",
"(",
"self",
"::",
"getArgs",
"(",
"func_get_args",
"(",
")",
")",
")",
";",
"return",
"$",
"seq",
"->",
"bindGen",
"(",
"function",
"(",
"$",
"roses"... | creates a new generator that returns an array whose elements are chosen
from the list of given generators. Individual elements shrink according to
their generator but the array will never shrink in count.
Accepts either a variadic number of args or a single array of generators.
Example:
Gen::tuples(Gen::booleans(), Gen::ints())
Gen::tuples([Gen::booleans(), Gen::ints()])
@return Generator | [
"creates",
"a",
"new",
"generator",
"that",
"returns",
"an",
"array",
"whose",
"elements",
"are",
"chosen",
"from",
"the",
"list",
"of",
"given",
"generators",
".",
"Individual",
"elements",
"shrink",
"according",
"to",
"their",
"generator",
"but",
"the",
"arr... | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Generator.php#L254-L260 |
38,939 | steos/php-quickcheck | src/QCheck/Generator.php | Generator.alphaNumChars | public static function alphaNumChars()
{
return self::oneOf(
self::choose(48, 57),
self::choose(65, 90),
self::choose(97, 122)
)->fmap('chr');
} | php | public static function alphaNumChars()
{
return self::oneOf(
self::choose(48, 57),
self::choose(65, 90),
self::choose(97, 122)
)->fmap('chr');
} | [
"public",
"static",
"function",
"alphaNumChars",
"(",
")",
"{",
"return",
"self",
"::",
"oneOf",
"(",
"self",
"::",
"choose",
"(",
"48",
",",
"57",
")",
",",
"self",
"::",
"choose",
"(",
"65",
",",
"90",
")",
",",
"self",
"::",
"choose",
"(",
"97",... | creates a generator that produces alphanumeric characters
@return Generator | [
"creates",
"a",
"generator",
"that",
"produces",
"alphanumeric",
"characters"
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Generator.php#L331-L338 |
38,940 | steos/php-quickcheck | src/QCheck/Generator.php | Generator.oneOf | public static function oneOf()
{
$generators = self::getArgs(func_get_args());
$num = count($generators);
if ($num < 2) {
throw new \InvalidArgumentException();
}
return self::choose(0, $num - 1)
->bind(function ($index) use ($generators) {
return $generators[$index];
});
} | php | public static function oneOf()
{
$generators = self::getArgs(func_get_args());
$num = count($generators);
if ($num < 2) {
throw new \InvalidArgumentException();
}
return self::choose(0, $num - 1)
->bind(function ($index) use ($generators) {
return $generators[$index];
});
} | [
"public",
"static",
"function",
"oneOf",
"(",
")",
"{",
"$",
"generators",
"=",
"self",
"::",
"getArgs",
"(",
"func_get_args",
"(",
")",
")",
";",
"$",
"num",
"=",
"count",
"(",
"$",
"generators",
")",
";",
"if",
"(",
"$",
"num",
"<",
"2",
")",
"... | creates a new generator that randomly chooses a value from the list
of provided generators. Shrinks toward earlier generators as well as shrinking
the generated value itself.
Accepts either a variadic number of args or a single array of generators.
Example:
Gen::oneOf(Gen::booleans(), Gen::ints())
Gen::oneOf([Gen::booleans(), Gen::ints()])
@return Generator | [
"creates",
"a",
"new",
"generator",
"that",
"randomly",
"chooses",
"a",
"value",
"from",
"the",
"list",
"of",
"provided",
"generators",
".",
"Shrinks",
"toward",
"earlier",
"generators",
"as",
"well",
"as",
"shrinking",
"the",
"generated",
"value",
"itself",
"... | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Generator.php#L473-L484 |
38,941 | steos/php-quickcheck | src/QCheck/Generator.php | Generator.elements | public static function elements()
{
$coll = self::getArgs(func_get_args());
if (empty($coll)) {
throw new \InvalidArgumentException();
}
return self::choose(0, count($coll) - 1)
->bindGen(function (RoseTree $rose) use ($coll) {
return self::pureGen($rose->fmap(
function ($index) use ($coll) {
return $coll[$index];
}
));
});
} | php | public static function elements()
{
$coll = self::getArgs(func_get_args());
if (empty($coll)) {
throw new \InvalidArgumentException();
}
return self::choose(0, count($coll) - 1)
->bindGen(function (RoseTree $rose) use ($coll) {
return self::pureGen($rose->fmap(
function ($index) use ($coll) {
return $coll[$index];
}
));
});
} | [
"public",
"static",
"function",
"elements",
"(",
")",
"{",
"$",
"coll",
"=",
"self",
"::",
"getArgs",
"(",
"func_get_args",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"coll",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
... | creates a generator that randomly chooses from the specified values
Accepts either a variadic number of args or a single array of values.
Example:
Gen::elements('foo', 'bar', 'baz')
Gen::elements(['foo', 'bar', 'baz'])
@return Generator | [
"creates",
"a",
"generator",
"that",
"randomly",
"chooses",
"from",
"the",
"specified",
"values"
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Generator.php#L497-L511 |
38,942 | steos/php-quickcheck | src/QCheck/Generator.php | Generator.frequency | public static function frequency()
{
$args = func_get_args();
$argc = count($args);
if ($argc < 2 || $argc % 2 != 0) {
throw new \InvalidArgumentException();
}
$total = array_sum(FP::realize(FP::takeNth(2, $args)));
$pairs = FP::realize(FP::partition(2, $args));
return self::choose(1, $total)->bindGen(
function (RoseTree $rose) use ($pairs) {
$n = $rose->getRoot();
foreach ($pairs as $pair) {
list($chance, $gen) = $pair;
if ($n <= $chance) {
return $gen;
}
$n = $n - $chance;
}
}
);
} | php | public static function frequency()
{
$args = func_get_args();
$argc = count($args);
if ($argc < 2 || $argc % 2 != 0) {
throw new \InvalidArgumentException();
}
$total = array_sum(FP::realize(FP::takeNth(2, $args)));
$pairs = FP::realize(FP::partition(2, $args));
return self::choose(1, $total)->bindGen(
function (RoseTree $rose) use ($pairs) {
$n = $rose->getRoot();
foreach ($pairs as $pair) {
list($chance, $gen) = $pair;
if ($n <= $chance) {
return $gen;
}
$n = $n - $chance;
}
}
);
} | [
"public",
"static",
"function",
"frequency",
"(",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"$",
"argc",
"=",
"count",
"(",
"$",
"args",
")",
";",
"if",
"(",
"$",
"argc",
"<",
"2",
"||",
"$",
"argc",
"%",
"2",
"!=",
"0",
")",
... | creates a generator that produces values from specified generators based on
likelihoods. The likelihood of a generator being chosen is its likelihood divided
by the sum of all likelihoods.
Example:
Gen::frequency(
5, Gen::ints(),
3, Gen::booleans(),
2, Gen::alphaStrings()
)
@return Generator | [
"creates",
"a",
"generator",
"that",
"produces",
"values",
"from",
"specified",
"generators",
"based",
"on",
"likelihoods",
".",
"The",
"likelihood",
"of",
"a",
"generator",
"being",
"chosen",
"is",
"its",
"likelihood",
"divided",
"by",
"the",
"sum",
"of",
"al... | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Generator.php#L624-L645 |
38,943 | cartalyst/converter | src/Laravel/ConverterServiceProvider.php | ConverterServiceProvider.registerExchangers | protected function registerExchangers()
{
$this->app->singleton('converter.native.exchanger', function ($app) {
return new NativeExchanger;
});
$this->app->singleton('converter.openexchangerates.exchanger', function ($app) {
$config = $app['config']->get('cartalyst.converter');
$appId = array_get($config, 'exchangers.openexchangerates.app_id');
$expires = array_get($config, 'expires');
$exchanger = new OpenExchangeRatesExchanger($app['cache']);
$exchanger->setAppId($appId);
$exchanger->setExpires($expires);
return $exchanger;
});
$this->app->singleton('converter.exchanger', function ($app) {
$default = $app['config']->get('cartalyst.converter.exchangers.default');
return $app["converter.{$default}.exchanger"];
});
} | php | protected function registerExchangers()
{
$this->app->singleton('converter.native.exchanger', function ($app) {
return new NativeExchanger;
});
$this->app->singleton('converter.openexchangerates.exchanger', function ($app) {
$config = $app['config']->get('cartalyst.converter');
$appId = array_get($config, 'exchangers.openexchangerates.app_id');
$expires = array_get($config, 'expires');
$exchanger = new OpenExchangeRatesExchanger($app['cache']);
$exchanger->setAppId($appId);
$exchanger->setExpires($expires);
return $exchanger;
});
$this->app->singleton('converter.exchanger', function ($app) {
$default = $app['config']->get('cartalyst.converter.exchangers.default');
return $app["converter.{$default}.exchanger"];
});
} | [
"protected",
"function",
"registerExchangers",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'converter.native.exchanger'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"new",
"NativeExchanger",
";",
"}",
")",
";",
"$",
"this",
... | Register all the available exchangers.
@return void | [
"Register",
"all",
"the",
"available",
"exchangers",
"."
] | fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c | https://github.com/cartalyst/converter/blob/fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c/src/Laravel/ConverterServiceProvider.php#L63-L88 |
38,944 | cartalyst/converter | src/Laravel/ConverterServiceProvider.php | ConverterServiceProvider.registerConverter | protected function registerConverter()
{
$this->app->singleton('converter', function ($app) {
$measurements = $app['config']->get('cartalyst.converter.measurements');
$converter = new Converter($app['converter.exchanger']);
$converter->setMeasurements($measurements);
return $converter;
});
} | php | protected function registerConverter()
{
$this->app->singleton('converter', function ($app) {
$measurements = $app['config']->get('cartalyst.converter.measurements');
$converter = new Converter($app['converter.exchanger']);
$converter->setMeasurements($measurements);
return $converter;
});
} | [
"protected",
"function",
"registerConverter",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'converter'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"measurements",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'ca... | Register the Converter.
@return void | [
"Register",
"the",
"Converter",
"."
] | fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c | https://github.com/cartalyst/converter/blob/fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c/src/Laravel/ConverterServiceProvider.php#L95-L105 |
38,945 | steos/php-quickcheck | src/QCheck/Annotation.php | Annotation.getReflection | public static function getReflection(callable $f)
{
if (is_string($f)) {
if (strpos($f, '::', 1) !== false) {
return new \ReflectionMethod($f);
} else {
return new \ReflectionFunction($f);
}
} elseif (is_array($f) && count($f) == 2) {
return new \ReflectionMethod($f[0], $f[1]);
} elseif ($f instanceof \Closure) {
return new \ReflectionFunction($f);
} elseif (is_object($f) && method_exists($f, '__invoke')) {
return new \ReflectionMethod($f, '__invoke');
}
// if the tests above are exhaustive, we should never hit the next line.
throw new AnnotationException("Unable to determine callable type.");
} | php | public static function getReflection(callable $f)
{
if (is_string($f)) {
if (strpos($f, '::', 1) !== false) {
return new \ReflectionMethod($f);
} else {
return new \ReflectionFunction($f);
}
} elseif (is_array($f) && count($f) == 2) {
return new \ReflectionMethod($f[0], $f[1]);
} elseif ($f instanceof \Closure) {
return new \ReflectionFunction($f);
} elseif (is_object($f) && method_exists($f, '__invoke')) {
return new \ReflectionMethod($f, '__invoke');
}
// if the tests above are exhaustive, we should never hit the next line.
throw new AnnotationException("Unable to determine callable type.");
} | [
"public",
"static",
"function",
"getReflection",
"(",
"callable",
"$",
"f",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"f",
")",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"f",
",",
"'::'",
",",
"1",
")",
"!==",
"false",
")",
"{",
"return",
"new",... | Return the correct reflection class for the given callable.
@param callable $f
@throws AnnotationException
@return \ReflectionFunction|\ReflectionMethod | [
"Return",
"the",
"correct",
"reflection",
"class",
"for",
"the",
"given",
"callable",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Annotation.php#L33-L50 |
38,946 | steos/php-quickcheck | src/QCheck/Annotation.php | Annotation.types | public static function types(callable $f)
{
$ref = self::getReflection($f);
$docs = $ref->getDocComment();
$proto = $ref->getParameters();
preg_match_all('/@param\s+(?P<type>.*?)\s+\$(?P<name>.*?)\s+/', $docs, $docs, PREG_SET_ORDER);
$params = array();
foreach ($proto as $p) {
$name = $p->getName();
$type = null;
foreach ($docs as $k => $d) {
if ($d['name'] === $name) {
$type = $d['type'];
unset($docs[$k]);
break;
}
}
if (is_null($type)) {
throw new MissingTypeAnnotationException("Cannot determine type for $name.");
}
if (count(explode('|', $type)) > 1) {
throw new AmbiguousTypeAnnotationException("Ambiguous type for $name : $type");
}
$params[$name] = $type;
}
return $params;
} | php | public static function types(callable $f)
{
$ref = self::getReflection($f);
$docs = $ref->getDocComment();
$proto = $ref->getParameters();
preg_match_all('/@param\s+(?P<type>.*?)\s+\$(?P<name>.*?)\s+/', $docs, $docs, PREG_SET_ORDER);
$params = array();
foreach ($proto as $p) {
$name = $p->getName();
$type = null;
foreach ($docs as $k => $d) {
if ($d['name'] === $name) {
$type = $d['type'];
unset($docs[$k]);
break;
}
}
if (is_null($type)) {
throw new MissingTypeAnnotationException("Cannot determine type for $name.");
}
if (count(explode('|', $type)) > 1) {
throw new AmbiguousTypeAnnotationException("Ambiguous type for $name : $type");
}
$params[$name] = $type;
}
return $params;
} | [
"public",
"static",
"function",
"types",
"(",
"callable",
"$",
"f",
")",
"{",
"$",
"ref",
"=",
"self",
"::",
"getReflection",
"(",
"$",
"f",
")",
";",
"$",
"docs",
"=",
"$",
"ref",
"->",
"getDocComment",
"(",
")",
";",
"$",
"proto",
"=",
"$",
"re... | Return the types for the given callable.
@param callable $f
@throws AnnotationException
@return array | [
"Return",
"the",
"types",
"for",
"the",
"given",
"callable",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Annotation.php#L59-L89 |
38,947 | steos/php-quickcheck | src/QCheck/Annotation.php | Annotation.register | public static function register($type, Generator $generator)
{
if (array_key_exists($type, self::$generators)) {
throw new DuplicateGeneratorException("A generator is already registred for $type.");
}
self::$generators[$type] = $generator;
} | php | public static function register($type, Generator $generator)
{
if (array_key_exists($type, self::$generators)) {
throw new DuplicateGeneratorException("A generator is already registred for $type.");
}
self::$generators[$type] = $generator;
} | [
"public",
"static",
"function",
"register",
"(",
"$",
"type",
",",
"Generator",
"$",
"generator",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"type",
",",
"self",
"::",
"$",
"generators",
")",
")",
"{",
"throw",
"new",
"DuplicateGeneratorException",
... | Associate a generator to a given type.
@param string $type
@param Generator $generator Tĥe generator associated with the type
@throws DuplicateGeneratorException | [
"Associate",
"a",
"generator",
"to",
"a",
"given",
"type",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/Annotation.php#L98-L105 |
38,948 | cartalyst/converter | src/Exchangers/OpenExchangeRatesExchanger.php | OpenExchangeRatesExchanger.get | public function get($code)
{
$rates = $this->getRates();
$code = strtoupper($code);
if (empty($rates[$code])) {
throw new Exception;
}
return $rates[$code];
} | php | public function get($code)
{
$rates = $this->getRates();
$code = strtoupper($code);
if (empty($rates[$code])) {
throw new Exception;
}
return $rates[$code];
} | [
"public",
"function",
"get",
"(",
"$",
"code",
")",
"{",
"$",
"rates",
"=",
"$",
"this",
"->",
"getRates",
"(",
")",
";",
"$",
"code",
"=",
"strtoupper",
"(",
"$",
"code",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"rates",
"[",
"$",
"code",
"]",
... | Return the exchange rate for the provided currency code.
@param string $code
@return float
@throws \Exception | [
"Return",
"the",
"exchange",
"rate",
"for",
"the",
"provided",
"currency",
"code",
"."
] | fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c | https://github.com/cartalyst/converter/blob/fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c/src/Exchangers/OpenExchangeRatesExchanger.php#L102-L113 |
38,949 | cartalyst/converter | src/Exchangers/OpenExchangeRatesExchanger.php | OpenExchangeRatesExchanger.setRates | public function setRates()
{
// Avoid instance issues
$self = $this;
// Cache the currencies
return $this->rates = $this->cache->remember('currencies', $this->getExpires(), function () use ($self) {
if (! $appId = $self->getAppId()) {
throw new Exception('OpenExchangeRates.org requires an app key.');
}
$client = new Client([ 'base_url' => $self->getUrl() ]);
$data = $client->get("latest.json?app_id={$appId}")->json();
return $data['rates'];
});
} | php | public function setRates()
{
// Avoid instance issues
$self = $this;
// Cache the currencies
return $this->rates = $this->cache->remember('currencies', $this->getExpires(), function () use ($self) {
if (! $appId = $self->getAppId()) {
throw new Exception('OpenExchangeRates.org requires an app key.');
}
$client = new Client([ 'base_url' => $self->getUrl() ]);
$data = $client->get("latest.json?app_id={$appId}")->json();
return $data['rates'];
});
} | [
"public",
"function",
"setRates",
"(",
")",
"{",
"// Avoid instance issues",
"$",
"self",
"=",
"$",
"this",
";",
"// Cache the currencies",
"return",
"$",
"this",
"->",
"rates",
"=",
"$",
"this",
"->",
"cache",
"->",
"remember",
"(",
"'currencies'",
",",
"$"... | Downloads the latest exchange rates file from openexchangerates.org
@return object | [
"Downloads",
"the",
"latest",
"exchange",
"rates",
"file",
"from",
"openexchangerates",
".",
"org"
] | fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c | https://github.com/cartalyst/converter/blob/fc4d047bf4f17a63470e0703a0f2ae8ef3f6345c/src/Exchangers/OpenExchangeRatesExchanger.php#L173-L190 |
38,950 | steos/php-quickcheck | src/QCheck/FP.php | FP.reduce | public static function reduce(callable $f, $xs, $initial = null)
{
if (is_array($xs)) {
$initial = $initial !== null ? $initial : array_shift($xs);
return array_reduce($xs, $f, $initial);
}
if ($xs instanceof \Iterator) {
$xs->rewind();
if (!$xs->valid()) {
return $initial;
}
$acc = $initial;
if ($acc === null) {
$acc = $xs->current();
$xs->next();
}
for (; $xs->valid(); $xs->next()) {
$acc = call_user_func($f, $acc, $xs->current());
}
return $acc;
}
throw new \InvalidArgumentException();
} | php | public static function reduce(callable $f, $xs, $initial = null)
{
if (is_array($xs)) {
$initial = $initial !== null ? $initial : array_shift($xs);
return array_reduce($xs, $f, $initial);
}
if ($xs instanceof \Iterator) {
$xs->rewind();
if (!$xs->valid()) {
return $initial;
}
$acc = $initial;
if ($acc === null) {
$acc = $xs->current();
$xs->next();
}
for (; $xs->valid(); $xs->next()) {
$acc = call_user_func($f, $acc, $xs->current());
}
return $acc;
}
throw new \InvalidArgumentException();
} | [
"public",
"static",
"function",
"reduce",
"(",
"callable",
"$",
"f",
",",
"$",
"xs",
",",
"$",
"initial",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"xs",
")",
")",
"{",
"$",
"initial",
"=",
"$",
"initial",
"!==",
"null",
"?",
"$",
... | Reduce any iterable collection using the callback. In case
of an array, array_reduce is used.
@param callable $f
@param $xs
@param null $initial
@return mixed|null
@throws \InvalidArgumentException | [
"Reduce",
"any",
"iterable",
"collection",
"using",
"the",
"callback",
".",
"In",
"case",
"of",
"an",
"array",
"array_reduce",
"is",
"used",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/FP.php#L37-L59 |
38,951 | steos/php-quickcheck | src/QCheck/FP.php | FP.comp | public static function comp(callable $f, callable $g)
{
return function () use ($f, $g) {
return call_user_func($f, call_user_func_array($g, func_get_args()));
};
} | php | public static function comp(callable $f, callable $g)
{
return function () use ($f, $g) {
return call_user_func($f, call_user_func_array($g, func_get_args()));
};
} | [
"public",
"static",
"function",
"comp",
"(",
"callable",
"$",
"f",
",",
"callable",
"$",
"g",
")",
"{",
"return",
"function",
"(",
")",
"use",
"(",
"$",
"f",
",",
"$",
"g",
")",
"{",
"return",
"call_user_func",
"(",
"$",
"f",
",",
"call_user_func_arr... | Compose the two functions
@param callable $f
@param callable $g
@return callable | [
"Compose",
"the",
"two",
"functions"
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/FP.php#L68-L73 |
38,952 | steos/php-quickcheck | src/QCheck/FP.php | FP.filter | public static function filter(callable $f, $coll)
{
foreach ($coll as $x) {
if (call_user_func($f, $x)) {
yield $x;
}
}
} | php | public static function filter(callable $f, $coll)
{
foreach ($coll as $x) {
if (call_user_func($f, $x)) {
yield $x;
}
}
} | [
"public",
"static",
"function",
"filter",
"(",
"callable",
"$",
"f",
",",
"$",
"coll",
")",
"{",
"foreach",
"(",
"$",
"coll",
"as",
"$",
"x",
")",
"{",
"if",
"(",
"call_user_func",
"(",
"$",
"f",
",",
"$",
"x",
")",
")",
"{",
"yield",
"$",
"x",... | Filter the given iterable collection using the callback in a
lazy way.
@param callable $f
@param $coll
@return \Generator | [
"Filter",
"the",
"given",
"iterable",
"collection",
"using",
"the",
"callback",
"in",
"a",
"lazy",
"way",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/FP.php#L98-L105 |
38,953 | steos/php-quickcheck | src/QCheck/FP.php | FP.iterator | public static function iterator($xs)
{
if (is_array($xs)) {
return new \ArrayIterator($xs);
}
if (!$xs instanceof \Iterator) {
throw new \InvalidArgumentException();
}
return $xs;
} | php | public static function iterator($xs)
{
if (is_array($xs)) {
return new \ArrayIterator($xs);
}
if (!$xs instanceof \Iterator) {
throw new \InvalidArgumentException();
}
return $xs;
} | [
"public",
"static",
"function",
"iterator",
"(",
"$",
"xs",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"xs",
")",
")",
"{",
"return",
"new",
"\\",
"ArrayIterator",
"(",
"$",
"xs",
")",
";",
"}",
"if",
"(",
"!",
"$",
"xs",
"instanceof",
"\\",
"Ite... | Return an iterator for the given collection if
possible.
@param $xs
@return \ArrayIterator
@throws \InvalidArgumentException | [
"Return",
"an",
"iterator",
"for",
"the",
"given",
"collection",
"if",
"possible",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/FP.php#L322-L331 |
38,954 | steos/php-quickcheck | src/QCheck/FP.php | FP.takeNth | public static function takeNth($n, $coll)
{
$coll = self::iterator($coll);
for ($coll->rewind(); $coll->valid(); $coll->valid() && $coll->next()) {
yield $coll->current();
for ($i = 0; $i < $n - 1 && $coll->valid(); ++$i) {
$coll->next();
}
}
} | php | public static function takeNth($n, $coll)
{
$coll = self::iterator($coll);
for ($coll->rewind(); $coll->valid(); $coll->valid() && $coll->next()) {
yield $coll->current();
for ($i = 0; $i < $n - 1 && $coll->valid(); ++$i) {
$coll->next();
}
}
} | [
"public",
"static",
"function",
"takeNth",
"(",
"$",
"n",
",",
"$",
"coll",
")",
"{",
"$",
"coll",
"=",
"self",
"::",
"iterator",
"(",
"$",
"coll",
")",
";",
"for",
"(",
"$",
"coll",
"->",
"rewind",
"(",
")",
";",
"$",
"coll",
"->",
"valid",
"(... | Return every Nth elements in the given collection in a lazy
fashion.
@param int $n
@param $coll
@return \Generator | [
"Return",
"every",
"Nth",
"elements",
"in",
"the",
"given",
"collection",
"in",
"a",
"lazy",
"fashion",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/FP.php#L341-L350 |
38,955 | steos/php-quickcheck | src/QCheck/FP.php | FP.partition | public static function partition($n, $coll)
{
$coll = self::iterator($coll);
for ($coll->rewind(); $coll->valid();) {
$partition = [];
for ($i = 0; $i < $n && $coll->valid(); ++$i, $coll->next()) {
$partition[] = $coll->current();
}
yield $partition;
}
} | php | public static function partition($n, $coll)
{
$coll = self::iterator($coll);
for ($coll->rewind(); $coll->valid();) {
$partition = [];
for ($i = 0; $i < $n && $coll->valid(); ++$i, $coll->next()) {
$partition[] = $coll->current();
}
yield $partition;
}
} | [
"public",
"static",
"function",
"partition",
"(",
"$",
"n",
",",
"$",
"coll",
")",
"{",
"$",
"coll",
"=",
"self",
"::",
"iterator",
"(",
"$",
"coll",
")",
";",
"for",
"(",
"$",
"coll",
"->",
"rewind",
"(",
")",
";",
"$",
"coll",
"->",
"valid",
... | Return the given collection partitioned in n sized segments
in a lazy fashion.
@param int $n
@param $coll
@return \Generator | [
"Return",
"the",
"given",
"collection",
"partitioned",
"in",
"n",
"sized",
"segments",
"in",
"a",
"lazy",
"fashion",
"."
] | 11f6f8e33f6d04452bca2ab510dc457fe8267773 | https://github.com/steos/php-quickcheck/blob/11f6f8e33f6d04452bca2ab510dc457fe8267773/src/QCheck/FP.php#L360-L370 |
38,956 | lampager/lampager | src/AbstractProcessor.php | AbstractProcessor.process | public function process(Query $query, $rows)
{
$meta = [
'hasPrevious' => false,
'previousCursor' => null,
'hasNext' => false,
'nextCursor' => null,
];
if ($this->shouldLtrim($query, $rows)) {
$type = $query->direction()->forward() ? 'previous' : 'next';
$meta['has' . ucfirst($type)] = true;
$meta[$type . 'Cursor'] = $this->makeCursor(
$query,
$this->offset($rows, (int)$query->exclusive())
);
$rows = $this->slice($rows, 1);
}
if ($this->shouldRtrim($query, $rows)) {
$type = $query->direction()->backward() ? 'previous' : 'next';
$meta['has' . ucfirst($type)] = true;
$meta[$type . 'Cursor'] = $this->makeCursor(
$query,
$this->offset($rows, $query->limit() - $query->exclusive())
);
$rows = $this->slice($rows, 0, $query->limit());
}
// If we are not using UNION ALL, boolean values are not defined.
if (!$query->selectOrUnionAll() instanceof UnionAll) {
$meta[$query->direction()->forward() ? 'hasPrevious' : 'hasNext'] = null;
}
return $this->invokeFormatter($this->shouldReverse($query) ? $this->reverse($rows) : $rows, $meta, $query);
} | php | public function process(Query $query, $rows)
{
$meta = [
'hasPrevious' => false,
'previousCursor' => null,
'hasNext' => false,
'nextCursor' => null,
];
if ($this->shouldLtrim($query, $rows)) {
$type = $query->direction()->forward() ? 'previous' : 'next';
$meta['has' . ucfirst($type)] = true;
$meta[$type . 'Cursor'] = $this->makeCursor(
$query,
$this->offset($rows, (int)$query->exclusive())
);
$rows = $this->slice($rows, 1);
}
if ($this->shouldRtrim($query, $rows)) {
$type = $query->direction()->backward() ? 'previous' : 'next';
$meta['has' . ucfirst($type)] = true;
$meta[$type . 'Cursor'] = $this->makeCursor(
$query,
$this->offset($rows, $query->limit() - $query->exclusive())
);
$rows = $this->slice($rows, 0, $query->limit());
}
// If we are not using UNION ALL, boolean values are not defined.
if (!$query->selectOrUnionAll() instanceof UnionAll) {
$meta[$query->direction()->forward() ? 'hasPrevious' : 'hasNext'] = null;
}
return $this->invokeFormatter($this->shouldReverse($query) ? $this->reverse($rows) : $rows, $meta, $query);
} | [
"public",
"function",
"process",
"(",
"Query",
"$",
"query",
",",
"$",
"rows",
")",
"{",
"$",
"meta",
"=",
"[",
"'hasPrevious'",
"=>",
"false",
",",
"'previousCursor'",
"=>",
"null",
",",
"'hasNext'",
"=>",
"false",
",",
"'nextCursor'",
"=>",
"null",
","... | Get result.
@param Query $query
@param mixed $rows
@return mixed | [
"Get",
"result",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/AbstractProcessor.php#L72-L106 |
38,957 | lampager/lampager | src/AbstractProcessor.php | AbstractProcessor.invokeFormatter | protected function invokeFormatter($rows, array $meta, Query $query)
{
$formatter = $this->formatter ?: static::$defaultFormatter ?: [$this, 'defaultFormat'];
return $formatter($rows, $meta, $query);
} | php | protected function invokeFormatter($rows, array $meta, Query $query)
{
$formatter = $this->formatter ?: static::$defaultFormatter ?: [$this, 'defaultFormat'];
return $formatter($rows, $meta, $query);
} | [
"protected",
"function",
"invokeFormatter",
"(",
"$",
"rows",
",",
"array",
"$",
"meta",
",",
"Query",
"$",
"query",
")",
"{",
"$",
"formatter",
"=",
"$",
"this",
"->",
"formatter",
"?",
":",
"static",
"::",
"$",
"defaultFormatter",
"?",
":",
"[",
"$",... | Invoke formatter.
@param mixed $rows
@param array $meta
@param Query $query
@return mixed | [
"Invoke",
"formatter",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/AbstractProcessor.php#L116-L120 |
38,958 | lampager/lampager | src/AbstractProcessor.php | AbstractProcessor.validateFormatter | protected static function validateFormatter($formatter)
{
if (is_subclass_of($formatter, Formatter::class)) {
return [is_string($formatter) ? new $formatter() : $formatter, 'format'];
}
if (is_callable($formatter)) {
return $formatter;
}
throw new InvalidArgumentException('Formatter must be an instanceof ' . Formatter::class . ' or callable.');
} | php | protected static function validateFormatter($formatter)
{
if (is_subclass_of($formatter, Formatter::class)) {
return [is_string($formatter) ? new $formatter() : $formatter, 'format'];
}
if (is_callable($formatter)) {
return $formatter;
}
throw new InvalidArgumentException('Formatter must be an instanceof ' . Formatter::class . ' or callable.');
} | [
"protected",
"static",
"function",
"validateFormatter",
"(",
"$",
"formatter",
")",
"{",
"if",
"(",
"is_subclass_of",
"(",
"$",
"formatter",
",",
"Formatter",
"::",
"class",
")",
")",
"{",
"return",
"[",
"is_string",
"(",
"$",
"formatter",
")",
"?",
"new",... | Validate formatter and return in normalized form.
@param mixed $formatter
@return callable | [
"Validate",
"formatter",
"and",
"return",
"in",
"normalized",
"form",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/AbstractProcessor.php#L128-L137 |
38,959 | lampager/lampager | src/AbstractProcessor.php | AbstractProcessor.shouldLtrim | protected function shouldLtrim(Query $query, $rows)
{
$first = $this->offset($rows, 0);
$selectOrUnionAll = $query->selectOrUnionAll();
// If we are not using UNION ALL or the elements are empty...
if (!$selectOrUnionAll instanceof UnionAll || !$first) {
return false;
}
foreach ($selectOrUnionAll->supportQuery()->orders() as $order) {
// Retrieve values
$field = $this->field($first, $order->column());
$cursor = $query->cursor()->get($order->column());
// Compare the first row and the cursor
if (!$diff = $this->compareField($field, $cursor)) {
continue;
}
//
// Drop the first row if ...
//
//
// - the support query is descending && $field < $cursor
//
// --------------------> Main query, ascending
// [4, <5>, 6, 7, 8, 9, 10]
// <----- Support query, descending
//
// ----> Support query, descending
// [10, 9, 8, 7, 6, <5>, 4]
// <--------------------- Main query, ascending
//
//
// - the support query is ascending && $field > $cursor
//
// -----> Support query, ascending
// [4, 5, 6, 7, 8, <9>, 10]
// <-------------------- Main query, descending
//
// --------------------> Main query, descending
// [10, <9>, 8, 7, 6, 5, 4]
// <---- Support query, ascending
//
return $diff === ($order->descending() ? -1 : 1);
}
// If the first row and the cursor are identical, we should drop the first row only if exclusive.
return $query->exclusive();
} | php | protected function shouldLtrim(Query $query, $rows)
{
$first = $this->offset($rows, 0);
$selectOrUnionAll = $query->selectOrUnionAll();
// If we are not using UNION ALL or the elements are empty...
if (!$selectOrUnionAll instanceof UnionAll || !$first) {
return false;
}
foreach ($selectOrUnionAll->supportQuery()->orders() as $order) {
// Retrieve values
$field = $this->field($first, $order->column());
$cursor = $query->cursor()->get($order->column());
// Compare the first row and the cursor
if (!$diff = $this->compareField($field, $cursor)) {
continue;
}
//
// Drop the first row if ...
//
//
// - the support query is descending && $field < $cursor
//
// --------------------> Main query, ascending
// [4, <5>, 6, 7, 8, 9, 10]
// <----- Support query, descending
//
// ----> Support query, descending
// [10, 9, 8, 7, 6, <5>, 4]
// <--------------------- Main query, ascending
//
//
// - the support query is ascending && $field > $cursor
//
// -----> Support query, ascending
// [4, 5, 6, 7, 8, <9>, 10]
// <-------------------- Main query, descending
//
// --------------------> Main query, descending
// [10, <9>, 8, 7, 6, 5, 4]
// <---- Support query, ascending
//
return $diff === ($order->descending() ? -1 : 1);
}
// If the first row and the cursor are identical, we should drop the first row only if exclusive.
return $query->exclusive();
} | [
"protected",
"function",
"shouldLtrim",
"(",
"Query",
"$",
"query",
",",
"$",
"rows",
")",
"{",
"$",
"first",
"=",
"$",
"this",
"->",
"offset",
"(",
"$",
"rows",
",",
"0",
")",
";",
"$",
"selectOrUnionAll",
"=",
"$",
"query",
"->",
"selectOrUnionAll",
... | Determine if the first row should be dropped.
@param Query $query
@param mixed $rows
@return bool | [
"Determine",
"if",
"the",
"first",
"row",
"should",
"be",
"dropped",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/AbstractProcessor.php#L170-L222 |
38,960 | lampager/lampager | src/AbstractProcessor.php | AbstractProcessor.makeCursor | protected function makeCursor(Query $query, $row)
{
$fields = [];
foreach ($query->orders() as $order) {
$fields[$order->column()] = $this->field($row, $order->column());
}
return $fields;
} | php | protected function makeCursor(Query $query, $row)
{
$fields = [];
foreach ($query->orders() as $order) {
$fields[$order->column()] = $this->field($row, $order->column());
}
return $fields;
} | [
"protected",
"function",
"makeCursor",
"(",
"Query",
"$",
"query",
",",
"$",
"row",
")",
"{",
"$",
"fields",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"query",
"->",
"orders",
"(",
")",
"as",
"$",
"order",
")",
"{",
"$",
"fields",
"[",
"$",
"order... | Make a cursor from the specific row.
@param Query $query
@param mixed $row
@return int[]|string[] | [
"Make",
"a",
"cursor",
"from",
"the",
"specific",
"row",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/AbstractProcessor.php#L243-L250 |
38,961 | lampager/lampager | src/ArrayProcessor.php | ArrayProcessor.field | protected function field($row, $column)
{
return is_object($row) && !$row instanceof \ArrayAccess ? $row->$column : $row[$column];
} | php | protected function field($row, $column)
{
return is_object($row) && !$row instanceof \ArrayAccess ? $row->$column : $row[$column];
} | [
"protected",
"function",
"field",
"(",
"$",
"row",
",",
"$",
"column",
")",
"{",
"return",
"is_object",
"(",
"$",
"row",
")",
"&&",
"!",
"$",
"row",
"instanceof",
"\\",
"ArrayAccess",
"?",
"$",
"row",
"->",
"$",
"column",
":",
"$",
"row",
"[",
"$",... | Return comparable value from a row.
@param mixed $row
@param string $column
@return int|string | [
"Return",
"comparable",
"value",
"from",
"a",
"row",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/ArrayProcessor.php#L14-L17 |
38,962 | lampager/lampager | src/Concerns/HasProcessor.php | HasProcessor.validateProcessor | protected static function validateProcessor($processor)
{
if (!is_subclass_of($processor, AbstractProcessor::class)) {
throw new InvalidArgumentException('Processor must be an instanceof ' . AbstractProcessor::class);
}
return is_string($processor) ? new $processor() : $processor;
} | php | protected static function validateProcessor($processor)
{
if (!is_subclass_of($processor, AbstractProcessor::class)) {
throw new InvalidArgumentException('Processor must be an instanceof ' . AbstractProcessor::class);
}
return is_string($processor) ? new $processor() : $processor;
} | [
"protected",
"static",
"function",
"validateProcessor",
"(",
"$",
"processor",
")",
"{",
"if",
"(",
"!",
"is_subclass_of",
"(",
"$",
"processor",
",",
"AbstractProcessor",
"::",
"class",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Processor... | Validate processor and return in normalized form.
@param mixed $processor
@return AbstractProcessor | [
"Validate",
"processor",
"and",
"return",
"in",
"normalized",
"form",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/Concerns/HasProcessor.php#L70-L76 |
38,963 | lampager/lampager | src/Paginator.php | Paginator.orderBy | public function orderBy($column, $order = Order::ASC)
{
$this->orders[] = [$column, $order];
return $this;
} | php | public function orderBy($column, $order = Order::ASC)
{
$this->orders[] = [$column, $order];
return $this;
} | [
"public",
"function",
"orderBy",
"(",
"$",
"column",
",",
"$",
"order",
"=",
"Order",
"::",
"ASC",
")",
"{",
"$",
"this",
"->",
"orders",
"[",
"]",
"=",
"[",
"$",
"column",
",",
"$",
"order",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Add cursor parameter name for ORDER BY statement.
IMPORTANT: Last parameter MUST be a primary key
e.g. $factory->orderBy('created_at')->orderBy('id') // <--- PRIMARY KEY
@param string $column
@param null|string $order
@return $this | [
"Add",
"cursor",
"parameter",
"name",
"for",
"ORDER",
"BY",
"statement",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/Paginator.php#L54-L58 |
38,964 | lampager/lampager | src/Paginator.php | Paginator.fromArray | public function fromArray(array $options)
{
static $configurables = [
'limit',
'forward',
'backward',
'exclusive',
'inclusive',
'seekable',
'unseekable',
];
if (isset($options['orders'])) {
foreach ($options['orders'] as $order) {
$this->orderBy(...$order);
}
}
foreach (array_intersect_key($options, array_flip($configurables)) as $key => $value) {
$this->$key($value);
}
return $this;
} | php | public function fromArray(array $options)
{
static $configurables = [
'limit',
'forward',
'backward',
'exclusive',
'inclusive',
'seekable',
'unseekable',
];
if (isset($options['orders'])) {
foreach ($options['orders'] as $order) {
$this->orderBy(...$order);
}
}
foreach (array_intersect_key($options, array_flip($configurables)) as $key => $value) {
$this->$key($value);
}
return $this;
} | [
"public",
"function",
"fromArray",
"(",
"array",
"$",
"options",
")",
"{",
"static",
"$",
"configurables",
"=",
"[",
"'limit'",
",",
"'forward'",
",",
"'backward'",
",",
"'exclusive'",
",",
"'inclusive'",
",",
"'seekable'",
",",
"'unseekable'",
",",
"]",
";"... | Define options from an associative array.
@param (bool|int|string[][])[] $options
@return $this | [
"Define",
"options",
"from",
"an",
"associative",
"array",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/Paginator.php#L172-L195 |
38,965 | lampager/lampager | src/Paginator.php | Paginator.configure | public function configure($cursor = [])
{
return Query::create($this->orders, $cursor, $this->limit, $this->backward, $this->exclusive, $this->seekable, $this->builder);
} | php | public function configure($cursor = [])
{
return Query::create($this->orders, $cursor, $this->limit, $this->backward, $this->exclusive, $this->seekable, $this->builder);
} | [
"public",
"function",
"configure",
"(",
"$",
"cursor",
"=",
"[",
"]",
")",
"{",
"return",
"Query",
"::",
"create",
"(",
"$",
"this",
"->",
"orders",
",",
"$",
"cursor",
",",
"$",
"this",
"->",
"limit",
",",
"$",
"this",
"->",
"backward",
",",
"$",
... | Build Query instance.
@param Cursor|int[]|string[] $cursor
@return Query | [
"Build",
"Query",
"instance",
"."
] | 9f111335ae6e74323d8d3f06497cce8abf6b55a6 | https://github.com/lampager/lampager/blob/9f111335ae6e74323d8d3f06497cce8abf6b55a6/src/Paginator.php#L203-L206 |
38,966 | fgheorghe/php3d-stl | src/STLFacetNormal.php | STLFacetNormal.fromString | public static function fromString(string $stlFacetNormalString) : STLFacetNormal
{
$class = new self();
preg_match("/facet normal +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*)/",
$stlFacetNormalString, $matches);
$class->setCoordinatesArray(array((float)$matches[1], (float)$matches[2], (float)$matches[3]));
$lines = explode("\n", $stlFacetNormalString);
$vertex = "";
for ($i = 1; $i < count($lines) - 1; $i++) {
$vertex .= $lines[$i];
}
$class->setVertex(STLVertex::fromString($vertex));
return $class;
} | php | public static function fromString(string $stlFacetNormalString) : STLFacetNormal
{
$class = new self();
preg_match("/facet normal +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*)/",
$stlFacetNormalString, $matches);
$class->setCoordinatesArray(array((float)$matches[1], (float)$matches[2], (float)$matches[3]));
$lines = explode("\n", $stlFacetNormalString);
$vertex = "";
for ($i = 1; $i < count($lines) - 1; $i++) {
$vertex .= $lines[$i];
}
$class->setVertex(STLVertex::fromString($vertex));
return $class;
} | [
"public",
"static",
"function",
"fromString",
"(",
"string",
"$",
"stlFacetNormalString",
")",
":",
"STLFacetNormal",
"{",
"$",
"class",
"=",
"new",
"self",
"(",
")",
";",
"preg_match",
"(",
"\"/facet normal +(\\-*\\d+\\.*\\d*e*\\-*\\+*\\d*) +(\\-*\\d+\\.*\\d*e*\\-*\\+*\\... | Class constructor from an STL facet normal string.
Example facet normal string:
facet normal 0.5651193 -0.07131607 0.8219211
outerloop
vertex -71.74323 47.70205 4.666243
vertex -72.13071 47.70205 4.932664
vertex -72.1506 47.2273 4.905148
endloop
endfacet
@param string $stlFacetNormalString
@return STLFacetNormal | [
"Class",
"constructor",
"from",
"an",
"STL",
"facet",
"normal",
"string",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STLFacetNormal.php#L86-L102 |
38,967 | fgheorghe/php3d-stl | src/STLFacetNormal.php | STLFacetNormal.fromArray | public static function fromArray(array $stlFacetNormalArray) : STLFacetNormal
{
$class = new self();
$class->setCoordinatesArray($stlFacetNormalArray["coordinates"]);
$class->setVertex(STLVertex::fromArray($stlFacetNormalArray["vertex"]));
return $class;
} | php | public static function fromArray(array $stlFacetNormalArray) : STLFacetNormal
{
$class = new self();
$class->setCoordinatesArray($stlFacetNormalArray["coordinates"]);
$class->setVertex(STLVertex::fromArray($stlFacetNormalArray["vertex"]));
return $class;
} | [
"public",
"static",
"function",
"fromArray",
"(",
"array",
"$",
"stlFacetNormalArray",
")",
":",
"STLFacetNormal",
"{",
"$",
"class",
"=",
"new",
"self",
"(",
")",
";",
"$",
"class",
"->",
"setCoordinatesArray",
"(",
"$",
"stlFacetNormalArray",
"[",
"\"coordin... | Class constructor from an STL facet normal array.
Example facet normal array:
array(
"coordinates" => array(0.5651193, -0.07131607, 0.8219211),
"vertex" => array(
array(
-71.74323, 47.70205, 4.666243
),
array(
-72.13071, 47.70205, 4.932664
),
array(
-72.1506, 47.2273, 4.905148
)
)
)
@param array $stlFacetNormalArray
@return STLFacetNormal | [
"Class",
"constructor",
"from",
"an",
"STL",
"facet",
"normal",
"array",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STLFacetNormal.php#L126-L132 |
38,968 | fgheorghe/php3d-stl | src/STLFacetNormal.php | STLFacetNormal.toString | public function toString() : string
{
$string = "facet normal " . implode(" ", $this->getCoordinatesArray()) . "\n";
$string .= $this->getVertex()->toString() . "\n";
$string .= "endfacet";
return $string;
} | php | public function toString() : string
{
$string = "facet normal " . implode(" ", $this->getCoordinatesArray()) . "\n";
$string .= $this->getVertex()->toString() . "\n";
$string .= "endfacet";
return $string;
} | [
"public",
"function",
"toString",
"(",
")",
":",
"string",
"{",
"$",
"string",
"=",
"\"facet normal \"",
".",
"implode",
"(",
"\" \"",
",",
"$",
"this",
"->",
"getCoordinatesArray",
"(",
")",
")",
".",
"\"\\n\"",
";",
"$",
"string",
".=",
"$",
"this",
... | Returns facet as string.
@return string | [
"Returns",
"facet",
"as",
"string",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STLFacetNormal.php#L152-L158 |
38,969 | fgheorghe/php3d-stl | src/STLSplit.php | STLSplit.split | public function split() : array
{
$stlArray = $this->getStl()->toArray();
$facets = $stlArray["facets"];
$objArray = array();
$vertex = $facets[0];
unset($facets[0]);
$current = 0;
$objArray[$current] = array($vertex);
while (count($facets) != 0) {
$this->findNeighbour(
$vertex,
$objArray[$current],
$facets
);
$vertex = array_pop($facets);
$current++;
if ($vertex) {
$objArray[$current] = array($vertex);
}
}
$stlObjects = array();
foreach ($objArray as $key => $object) {
$stlObjects[] = STL::fromArray(array(
"name" => $this->getStl()->getSolidName() . $key,
"facets" => $object
));
}
return $stlObjects;
} | php | public function split() : array
{
$stlArray = $this->getStl()->toArray();
$facets = $stlArray["facets"];
$objArray = array();
$vertex = $facets[0];
unset($facets[0]);
$current = 0;
$objArray[$current] = array($vertex);
while (count($facets) != 0) {
$this->findNeighbour(
$vertex,
$objArray[$current],
$facets
);
$vertex = array_pop($facets);
$current++;
if ($vertex) {
$objArray[$current] = array($vertex);
}
}
$stlObjects = array();
foreach ($objArray as $key => $object) {
$stlObjects[] = STL::fromArray(array(
"name" => $this->getStl()->getSolidName() . $key,
"facets" => $object
));
}
return $stlObjects;
} | [
"public",
"function",
"split",
"(",
")",
":",
"array",
"{",
"$",
"stlArray",
"=",
"$",
"this",
"->",
"getStl",
"(",
")",
"->",
"toArray",
"(",
")",
";",
"$",
"facets",
"=",
"$",
"stlArray",
"[",
"\"facets\"",
"]",
";",
"$",
"objArray",
"=",
"array"... | Splits an STL object and returns the new 3D objects in an array of STL files.
@return array | [
"Splits",
"an",
"STL",
"object",
"and",
"returns",
"the",
"new",
"3D",
"objects",
"in",
"an",
"array",
"of",
"STL",
"files",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STLSplit.php#L55-L88 |
38,970 | fgheorghe/php3d-stl | src/STLSplit.php | STLSplit.findNeighbour | private function findNeighbour(array $facet, array &$object, array &$facets)
{
foreach ($facets as $key => $_facet) {
for ($i = 0; $i < 3; $i++) {
if (in_array($_facet["vertex"][$i], $facet["vertex"])) {
unset($facets[$key]);
$object[] = $_facet;
$this->findNeighbour(
$_facet,
$object,
$facets
);
}
continue 2;
}
}
} | php | private function findNeighbour(array $facet, array &$object, array &$facets)
{
foreach ($facets as $key => $_facet) {
for ($i = 0; $i < 3; $i++) {
if (in_array($_facet["vertex"][$i], $facet["vertex"])) {
unset($facets[$key]);
$object[] = $_facet;
$this->findNeighbour(
$_facet,
$object,
$facets
);
}
continue 2;
}
}
} | [
"private",
"function",
"findNeighbour",
"(",
"array",
"$",
"facet",
",",
"array",
"&",
"$",
"object",
",",
"array",
"&",
"$",
"facets",
")",
"{",
"foreach",
"(",
"$",
"facets",
"as",
"$",
"key",
"=>",
"$",
"_facet",
")",
"{",
"for",
"(",
"$",
"i",
... | Finds the neighbouring facets of a facet.
@param array $facet
@param array $object
@param array $facets | [
"Finds",
"the",
"neighbouring",
"facets",
"of",
"a",
"facet",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STLSplit.php#L97-L113 |
38,971 | fgheorghe/php3d-stl | src/STLVertex.php | STLVertex.fromString | public static function fromString(string $stlVertexString) : STLVertex
{
$class = new self();
preg_match_all("/vertex +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*)/",
$stlVertexString, $matches);
$coordinates = array(
array((float)$matches[1][0], (float)$matches[2][0], (float)$matches[3][0]),
array((float)$matches[1][1], (float)$matches[2][1], (float)$matches[3][1]),
array((float)$matches[1][2], (float)$matches[2][2], (float)$matches[3][2])
);
$class->setCoordinatesArray($coordinates);
return $class;
} | php | public static function fromString(string $stlVertexString) : STLVertex
{
$class = new self();
preg_match_all("/vertex +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*) +(\-*\d+\.*\d*e*\-*\+*\d*)/",
$stlVertexString, $matches);
$coordinates = array(
array((float)$matches[1][0], (float)$matches[2][0], (float)$matches[3][0]),
array((float)$matches[1][1], (float)$matches[2][1], (float)$matches[3][1]),
array((float)$matches[1][2], (float)$matches[2][2], (float)$matches[3][2])
);
$class->setCoordinatesArray($coordinates);
return $class;
} | [
"public",
"static",
"function",
"fromString",
"(",
"string",
"$",
"stlVertexString",
")",
":",
"STLVertex",
"{",
"$",
"class",
"=",
"new",
"self",
"(",
")",
";",
"preg_match_all",
"(",
"\"/vertex +(\\-*\\d+\\.*\\d*e*\\-*\\+*\\d*) +(\\-*\\d+\\.*\\d*e*\\-*\\+*\\d*) +(\\-*\\... | Class constructor from an STL vertex string.
Example vertex string:
outerloop
vertex -71.74323 47.70205 4.666243
vertex -72.13071 47.70205 4.932664
vertex -72.1506 47.2273 4.905148
endloop
@param string $stlVertexString
@return STLVertex | [
"Class",
"constructor",
"from",
"an",
"STL",
"vertex",
"string",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STLVertex.php#L60-L76 |
38,972 | fgheorghe/php3d-stl | src/STLVertex.php | STLVertex.toString | public function toString() : string
{
$coordinates = $this->getCoordinatesArray();
$string = "outerloop\n";
foreach ($coordinates as $coordinate) {
$string .= " vertex " . implode(" ", $coordinate) . "\n";
}
$string .= "endloop";
return $string;
} | php | public function toString() : string
{
$coordinates = $this->getCoordinatesArray();
$string = "outerloop\n";
foreach ($coordinates as $coordinate) {
$string .= " vertex " . implode(" ", $coordinate) . "\n";
}
$string .= "endloop";
return $string;
} | [
"public",
"function",
"toString",
"(",
")",
":",
"string",
"{",
"$",
"coordinates",
"=",
"$",
"this",
"->",
"getCoordinatesArray",
"(",
")",
";",
"$",
"string",
"=",
"\"outerloop\\n\"",
";",
"foreach",
"(",
"$",
"coordinates",
"as",
"$",
"coordinate",
")",... | Returns a vertex outerloop.
@return string | [
"Returns",
"a",
"vertex",
"outerloop",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STLVertex.php#L120-L130 |
38,973 | fgheorghe/php3d-stl | src/STL.php | STL.fromString | public static function fromString(string $stlFileContentString) : STL
{
$class = new self();
// Extract name.
$lines = explode("\n", $stlFileContentString);
preg_match("/solid (.+)/", $lines[0], $matches);
$class->setSolidName($matches[1]);
// Extract facets.
foreach ($lines as $line) {
if (preg_match("/facet normal (.+)/", $line)) {
// Get this line and the following, making a block of facets.
$string = next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$class->addFacetNormal(STLFacetNormal::fromString($string));
}
}
return $class;
} | php | public static function fromString(string $stlFileContentString) : STL
{
$class = new self();
// Extract name.
$lines = explode("\n", $stlFileContentString);
preg_match("/solid (.+)/", $lines[0], $matches);
$class->setSolidName($matches[1]);
// Extract facets.
foreach ($lines as $line) {
if (preg_match("/facet normal (.+)/", $line)) {
// Get this line and the following, making a block of facets.
$string = next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$string .= next($lines) . "\n";
$class->addFacetNormal(STLFacetNormal::fromString($string));
}
}
return $class;
} | [
"public",
"static",
"function",
"fromString",
"(",
"string",
"$",
"stlFileContentString",
")",
":",
"STL",
"{",
"$",
"class",
"=",
"new",
"self",
"(",
")",
";",
"// Extract name.",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"stlFileContentString... | Class constructor from an STL string.
Example STL file string: see STLTest $stlFileString property.
@param string $stlFileContentString
@return STL | [
"Class",
"constructor",
"from",
"an",
"STL",
"string",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STL.php#L60-L85 |
38,974 | fgheorghe/php3d-stl | src/STL.php | STL.fromArray | public static function fromArray(array $stlFileArray) : STL
{
$class = new self();
$class->setSolidName($stlFileArray["name"]);
foreach ($stlFileArray["facets"] as $facet) {
$class->addFacetNormal(STLFacetNormal::fromArray($facet));
}
return $class;
} | php | public static function fromArray(array $stlFileArray) : STL
{
$class = new self();
$class->setSolidName($stlFileArray["name"]);
foreach ($stlFileArray["facets"] as $facet) {
$class->addFacetNormal(STLFacetNormal::fromArray($facet));
}
return $class;
} | [
"public",
"static",
"function",
"fromArray",
"(",
"array",
"$",
"stlFileArray",
")",
":",
"STL",
"{",
"$",
"class",
"=",
"new",
"self",
"(",
")",
";",
"$",
"class",
"->",
"setSolidName",
"(",
"$",
"stlFileArray",
"[",
"\"name\"",
"]",
")",
";",
"foreac... | Class constructor from an STL array.
Example STL file array: see STLTest $stlFileArray property.
@param array $stlFileArray
@return STL | [
"Class",
"constructor",
"from",
"an",
"STL",
"array",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STL.php#L95-L105 |
38,975 | fgheorghe/php3d-stl | src/STL.php | STL.setFacetNormal | public function setFacetNormal(int $position, STLFacetNormal $facetNormal) : STL
{
$this->facets[$position] = $facetNormal;
return $this;
} | php | public function setFacetNormal(int $position, STLFacetNormal $facetNormal) : STL
{
$this->facets[$position] = $facetNormal;
return $this;
} | [
"public",
"function",
"setFacetNormal",
"(",
"int",
"$",
"position",
",",
"STLFacetNormal",
"$",
"facetNormal",
")",
":",
"STL",
"{",
"$",
"this",
"->",
"facets",
"[",
"$",
"position",
"]",
"=",
"$",
"facetNormal",
";",
"return",
"$",
"this",
";",
"}"
] | Sets a facet normal at a given position.
@param int $position
@param STLFacetNormal $facetNormal
@return STL | [
"Sets",
"a",
"facet",
"normal",
"at",
"a",
"given",
"position",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STL.php#L147-L151 |
38,976 | fgheorghe/php3d-stl | src/STL.php | STL.deleteFacetNormal | public function deleteFacetNormal(int $position) : STL
{
$facets = $this->facets;
unset($facets[$position]);
$this->facets = array_values($facets);
return $this;
} | php | public function deleteFacetNormal(int $position) : STL
{
$facets = $this->facets;
unset($facets[$position]);
$this->facets = array_values($facets);
return $this;
} | [
"public",
"function",
"deleteFacetNormal",
"(",
"int",
"$",
"position",
")",
":",
"STL",
"{",
"$",
"facets",
"=",
"$",
"this",
"->",
"facets",
";",
"unset",
"(",
"$",
"facets",
"[",
"$",
"position",
"]",
")",
";",
"$",
"this",
"->",
"facets",
"=",
... | Deletes a facet normal at a given position.
@param int $position
@return STL | [
"Deletes",
"a",
"facet",
"normal",
"at",
"a",
"given",
"position",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STL.php#L159-L165 |
38,977 | fgheorghe/php3d-stl | src/STL.php | STL.toArray | public function toArray() : array
{
$facets = array();
$count = $this->getFacetNormalCount();
for ($i = 0; $i < $count; $i++) {
$facets[] = $this->getFacetNormal($i)->toArray();
}
return array(
"name" => $this->getSolidName(),
"facets" => $facets
);
} | php | public function toArray() : array
{
$facets = array();
$count = $this->getFacetNormalCount();
for ($i = 0; $i < $count; $i++) {
$facets[] = $this->getFacetNormal($i)->toArray();
}
return array(
"name" => $this->getSolidName(),
"facets" => $facets
);
} | [
"public",
"function",
"toArray",
"(",
")",
":",
"array",
"{",
"$",
"facets",
"=",
"array",
"(",
")",
";",
"$",
"count",
"=",
"$",
"this",
"->",
"getFacetNormalCount",
"(",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"coun... | Converts STL back to array.
@return array | [
"Converts",
"STL",
"back",
"to",
"array",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STL.php#L172-L185 |
38,978 | fgheorghe/php3d-stl | src/STL.php | STL.toString | public function toString() : string
{
$string = "solid " . $this->getSolidName() . "\n";
$count = $this->getFacetNormalCount();
for ($i = 0; $i < $count; $i++) {
$string .= $this->getFacetNormal($i)->toString() . "\n";
}
$string .= "endsolid";
return $string;
} | php | public function toString() : string
{
$string = "solid " . $this->getSolidName() . "\n";
$count = $this->getFacetNormalCount();
for ($i = 0; $i < $count; $i++) {
$string .= $this->getFacetNormal($i)->toString() . "\n";
}
$string .= "endsolid";
return $string;
} | [
"public",
"function",
"toString",
"(",
")",
":",
"string",
"{",
"$",
"string",
"=",
"\"solid \"",
".",
"$",
"this",
"->",
"getSolidName",
"(",
")",
".",
"\"\\n\"",
";",
"$",
"count",
"=",
"$",
"this",
"->",
"getFacetNormalCount",
"(",
")",
";",
"for",
... | Converts STL back to string.
@return string | [
"Converts",
"STL",
"back",
"to",
"string",
"."
] | 435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced | https://github.com/fgheorghe/php3d-stl/blob/435de2eb7f19c4c0b8aeb5dfffa5cd3ac4d65ced/src/STL.php#L192-L205 |
38,979 | ikkez/f3-fal | lib/fal/metafilestorage.php | MetaFileStorage.save | public function save($file, $data, $ttl)
{
$cacheHash = $this->getCacheHash($file);
if($this->fs->write($this->getMetaFilePath($file), json_encode($data))) {
if ($this->f3->get('CACHE')) {
$cache = \Cache::instance();
if ($ttl)
$cache->set($cacheHash, $data, $ttl);
elseif ($cache->exists($cacheHash))
$cache->clear($cacheHash);
}
$this->data = $data;
return true;
} else return false;
} | php | public function save($file, $data, $ttl)
{
$cacheHash = $this->getCacheHash($file);
if($this->fs->write($this->getMetaFilePath($file), json_encode($data))) {
if ($this->f3->get('CACHE')) {
$cache = \Cache::instance();
if ($ttl)
$cache->set($cacheHash, $data, $ttl);
elseif ($cache->exists($cacheHash))
$cache->clear($cacheHash);
}
$this->data = $data;
return true;
} else return false;
} | [
"public",
"function",
"save",
"(",
"$",
"file",
",",
"$",
"data",
",",
"$",
"ttl",
")",
"{",
"$",
"cacheHash",
"=",
"$",
"this",
"->",
"getCacheHash",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"this",
"->",
"fs",
"->",
"write",
"(",
"$",
"thi... | save meta data
@param $file
@param $data
@param $ttl
@return bool | [
"save",
"meta",
"data"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/metafilestorage.php#L44-L58 |
38,980 | ikkez/f3-fal | lib/fal/metafilestorage.php | MetaFileStorage.load | public function load($file,$ttl)
{
$cache = \Cache::instance();
$cacheHash = $this->getCacheHash($file);
if ($this->f3->get('CACHE') && $ttl && ($cached = $cache->exists(
$cacheHash, $content)) && $cached + $ttl > microtime(TRUE)
) {
$this->data = $content;
} elseif ($this->fs->exists($metaFile = $this->getMetaFilePath($file))) {
$this->data = json_decode($this->fs->read($metaFile), true);
if ($this->f3->get('CACHE') && $ttl)
$cache->set($cacheHash, $this->data, $ttl);
}
return $this->data;
} | php | public function load($file,$ttl)
{
$cache = \Cache::instance();
$cacheHash = $this->getCacheHash($file);
if ($this->f3->get('CACHE') && $ttl && ($cached = $cache->exists(
$cacheHash, $content)) && $cached + $ttl > microtime(TRUE)
) {
$this->data = $content;
} elseif ($this->fs->exists($metaFile = $this->getMetaFilePath($file))) {
$this->data = json_decode($this->fs->read($metaFile), true);
if ($this->f3->get('CACHE') && $ttl)
$cache->set($cacheHash, $this->data, $ttl);
}
return $this->data;
} | [
"public",
"function",
"load",
"(",
"$",
"file",
",",
"$",
"ttl",
")",
"{",
"$",
"cache",
"=",
"\\",
"Cache",
"::",
"instance",
"(",
")",
";",
"$",
"cacheHash",
"=",
"$",
"this",
"->",
"getCacheHash",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
... | return meta data
@param $file
@param $ttl
@return mixed | [
"return",
"meta",
"data"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/metafilestorage.php#L66-L80 |
38,981 | ikkez/f3-fal | lib/fal/metafilestorage.php | MetaFileStorage.delete | public function delete($file)
{
$metaFile = $this->getMetaFilePath($file);
if ($this->fs->exists($metaFile))
$this->fs->delete($metaFile);
if ($this->f3->get('CACHE')) {
$cache = \Cache::instance();
if ($cache->exists($cacheHash = $this->getCacheHash($file)))
$cache->clear($cacheHash);
}
} | php | public function delete($file)
{
$metaFile = $this->getMetaFilePath($file);
if ($this->fs->exists($metaFile))
$this->fs->delete($metaFile);
if ($this->f3->get('CACHE')) {
$cache = \Cache::instance();
if ($cache->exists($cacheHash = $this->getCacheHash($file)))
$cache->clear($cacheHash);
}
} | [
"public",
"function",
"delete",
"(",
"$",
"file",
")",
"{",
"$",
"metaFile",
"=",
"$",
"this",
"->",
"getMetaFilePath",
"(",
"$",
"file",
")",
";",
"if",
"(",
"$",
"this",
"->",
"fs",
"->",
"exists",
"(",
"$",
"metaFile",
")",
")",
"$",
"this",
"... | delete meta record
@param $file | [
"delete",
"meta",
"record"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/metafilestorage.php#L86-L96 |
38,982 | ikkez/f3-fal | lib/fal/metafilestorage.php | MetaFileStorage.move | public function move($current,$new)
{
$metaFile = $this->getMetaFilePath($current);
if ($this->fs->exists($metaFile)) {
$this->fs->move($metaFile,$this->getMetaFilePath($new));
if ($this->f3->get('CACHE')) {
$cache = \Cache::instance();
if ($cache->exists($cacheHash = $this->getCacheHash($current)))
$cache->clear($cacheHash);
}
}
} | php | public function move($current,$new)
{
$metaFile = $this->getMetaFilePath($current);
if ($this->fs->exists($metaFile)) {
$this->fs->move($metaFile,$this->getMetaFilePath($new));
if ($this->f3->get('CACHE')) {
$cache = \Cache::instance();
if ($cache->exists($cacheHash = $this->getCacheHash($current)))
$cache->clear($cacheHash);
}
}
} | [
"public",
"function",
"move",
"(",
"$",
"current",
",",
"$",
"new",
")",
"{",
"$",
"metaFile",
"=",
"$",
"this",
"->",
"getMetaFilePath",
"(",
"$",
"current",
")",
";",
"if",
"(",
"$",
"this",
"->",
"fs",
"->",
"exists",
"(",
"$",
"metaFile",
")",
... | rename meta file
@param $current
@param $new | [
"rename",
"meta",
"file"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/metafilestorage.php#L103-L114 |
38,983 | ikkez/f3-fal | lib/fal/metafilestorage.php | MetaFileStorage.getMetaFilePath | protected function getMetaFilePath($file)
{
$parts = pathinfo($file);
$metaFilename = sprintf($this->metaFileMask, $parts['basename']);
return str_replace($parts['basename'], $metaFilename, $file);
} | php | protected function getMetaFilePath($file)
{
$parts = pathinfo($file);
$metaFilename = sprintf($this->metaFileMask, $parts['basename']);
return str_replace($parts['basename'], $metaFilename, $file);
} | [
"protected",
"function",
"getMetaFilePath",
"(",
"$",
"file",
")",
"{",
"$",
"parts",
"=",
"pathinfo",
"(",
"$",
"file",
")",
";",
"$",
"metaFilename",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"metaFileMask",
",",
"$",
"parts",
"[",
"'basename'",
"]",
"... | compute meta file path
@param string $file
@return mixed | [
"compute",
"meta",
"file",
"path"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/metafilestorage.php#L121-L126 |
38,984 | ikkez/f3-fal | lib/fal/metafilestorage.php | MetaFileStorage.getCacheHash | protected function getCacheHash($file)
{
$fs_class = explode('\\', get_class($this->fs));
return $this->f3->hash($this->f3->stringify($file)).
'.'.strtolower(array_pop($fs_class)).'.meta';
} | php | protected function getCacheHash($file)
{
$fs_class = explode('\\', get_class($this->fs));
return $this->f3->hash($this->f3->stringify($file)).
'.'.strtolower(array_pop($fs_class)).'.meta';
} | [
"protected",
"function",
"getCacheHash",
"(",
"$",
"file",
")",
"{",
"$",
"fs_class",
"=",
"explode",
"(",
"'\\\\'",
",",
"get_class",
"(",
"$",
"this",
"->",
"fs",
")",
")",
";",
"return",
"$",
"this",
"->",
"f3",
"->",
"hash",
"(",
"$",
"this",
"... | return cache key
@param $file
@return string | [
"return",
"cache",
"key"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/metafilestorage.php#L133-L138 |
38,985 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.setAuthToken | public function setAuthToken($token, $secret) {
$this->authToken = $token;
$this->authSecret = $secret;
$this->f3->set('SESSION.dropbox.authToken', $this->authToken);
$this->f3->set('SESSION.dropbox.authSecret', $this->authSecret);
} | php | public function setAuthToken($token, $secret) {
$this->authToken = $token;
$this->authSecret = $secret;
$this->f3->set('SESSION.dropbox.authToken', $this->authToken);
$this->f3->set('SESSION.dropbox.authSecret', $this->authSecret);
} | [
"public",
"function",
"setAuthToken",
"(",
"$",
"token",
",",
"$",
"secret",
")",
"{",
"$",
"this",
"->",
"authToken",
"=",
"$",
"token",
";",
"$",
"this",
"->",
"authSecret",
"=",
"$",
"secret",
";",
"$",
"this",
"->",
"f3",
"->",
"set",
"(",
"'SE... | set auth tokens
@param $token
@param $secret | [
"set",
"auth",
"tokens"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L70-L75 |
38,986 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.login | public function login($callback_url=NULL) {
if (!$this->f3->exists('GET.oauth_token')) {
$tokens = $this->requestToken();
$this->setAuthToken($tokens['oauth_token'], $tokens['oauth_token_secret']);
if(is_null($callback_url))
$callback_url = $this->f3->get('SCHEME').'://'.$this->f3->get('HOST').
$this->f3->get('URI');
$this->authorize($callback_url);
} else {
return $this->accessToken();
}
} | php | public function login($callback_url=NULL) {
if (!$this->f3->exists('GET.oauth_token')) {
$tokens = $this->requestToken();
$this->setAuthToken($tokens['oauth_token'], $tokens['oauth_token_secret']);
if(is_null($callback_url))
$callback_url = $this->f3->get('SCHEME').'://'.$this->f3->get('HOST').
$this->f3->get('URI');
$this->authorize($callback_url);
} else {
return $this->accessToken();
}
} | [
"public",
"function",
"login",
"(",
"$",
"callback_url",
"=",
"NULL",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"f3",
"->",
"exists",
"(",
"'GET.oauth_token'",
")",
")",
"{",
"$",
"tokens",
"=",
"$",
"this",
"->",
"requestToken",
"(",
")",
";",
... | perform external authorisation, return access token
@param null $callback_url
@return array|bool | [
"perform",
"external",
"authorisation",
"return",
"access",
"token"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L82-L93 |
38,987 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.doOAuthCall | protected function doOAuthCall($url, $method, $params=null,
$type=NULL, $file=NULL, $content=NULL) {
if(is_null($params)) $params = array();
$method = strtoupper($method);
$options = array('method' => $method);
if ($method == 'GET') {
if($file)
$url .= $type.'/'.$file;
$url .= '?'.http_build_query($this->authParams + $params);
}
elseif ($method == 'POST') {
$params = $this->authParams + $params + array('root' => $type);
$options['content'] = http_build_query($params);
}
elseif ($method == 'PUT') {
$url .= $type.'/'.$file.'?'.http_build_query($this->authParams + $params);
$options['content'] = $content;
$options['header'] = array('Content-Type: application/octet-stream');
}
else {
trigger_error(sprintf(self::E_METHODNOTSUPPORTED,$method));
return false;
}
return $this->web->request($url, $options);
} | php | protected function doOAuthCall($url, $method, $params=null,
$type=NULL, $file=NULL, $content=NULL) {
if(is_null($params)) $params = array();
$method = strtoupper($method);
$options = array('method' => $method);
if ($method == 'GET') {
if($file)
$url .= $type.'/'.$file;
$url .= '?'.http_build_query($this->authParams + $params);
}
elseif ($method == 'POST') {
$params = $this->authParams + $params + array('root' => $type);
$options['content'] = http_build_query($params);
}
elseif ($method == 'PUT') {
$url .= $type.'/'.$file.'?'.http_build_query($this->authParams + $params);
$options['content'] = $content;
$options['header'] = array('Content-Type: application/octet-stream');
}
else {
trigger_error(sprintf(self::E_METHODNOTSUPPORTED,$method));
return false;
}
return $this->web->request($url, $options);
} | [
"protected",
"function",
"doOAuthCall",
"(",
"$",
"url",
",",
"$",
"method",
",",
"$",
"params",
"=",
"null",
",",
"$",
"type",
"=",
"NULL",
",",
"$",
"file",
"=",
"NULL",
",",
"$",
"content",
"=",
"NULL",
")",
"{",
"if",
"(",
"is_null",
"(",
"$"... | perform a signed oauth request
@param string $url request url
@param string $method method type
@param array $params additional params
@param null $type storage type [sandbox|dropbox]
@param null $file full file pathname
@param null $content file content
@return bool | [
"perform",
"a",
"signed",
"oauth",
"request"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L160-L184 |
38,988 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.getAccountInfo | public function getAccountInfo() {
$url = 'https://api.dropbox.com/1/account/info';
$result = $this->doOAuthCall($url,'POST');
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR,$result_body['error']));
return false;
}
} | php | public function getAccountInfo() {
$url = 'https://api.dropbox.com/1/account/info';
$result = $this->doOAuthCall($url,'POST');
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR,$result_body['error']));
return false;
}
} | [
"public",
"function",
"getAccountInfo",
"(",
")",
"{",
"$",
"url",
"=",
"'https://api.dropbox.com/1/account/info'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"doOAuthCall",
"(",
"$",
"url",
",",
"'POST'",
")",
";",
"$",
"result_body",
"=",
"json_decode",
"... | gather user account information
@return bool|mixed | [
"gather",
"user",
"account",
"information"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L190-L200 |
38,989 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.read | public function read($file, $rev=NUll, $type='sandbox')
{
$url = 'https://api-content.dropbox.com/1/files/';
$params = array();
if ($rev) $params['rev'] = $rev;
$result = $this->doOAuthCall($url,'GET',$params, $type, $file);
// if file not found, response is json, otherwise just file contents
if(!in_array('HTTP/1.1 404 Not Found', $result['headers']))
return $result['body'];
else {
$result_body = json_decode($result['body'], true);
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | php | public function read($file, $rev=NUll, $type='sandbox')
{
$url = 'https://api-content.dropbox.com/1/files/';
$params = array();
if ($rev) $params['rev'] = $rev;
$result = $this->doOAuthCall($url,'GET',$params, $type, $file);
// if file not found, response is json, otherwise just file contents
if(!in_array('HTTP/1.1 404 Not Found', $result['headers']))
return $result['body'];
else {
$result_body = json_decode($result['body'], true);
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | [
"public",
"function",
"read",
"(",
"$",
"file",
",",
"$",
"rev",
"=",
"NUll",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"url",
"=",
"'https://api-content.dropbox.com/1/files/'",
";",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
... | return file content
@param $file
@param null $rev
@param string $type
@return mixed | [
"return",
"file",
"content"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L209-L223 |
38,990 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.exists | public function exists($file, $hidden=false, $rev=NULL, $type='sandbox')
{
return $this->metadata($file, false, true, $hidden, $rev, $type);
} | php | public function exists($file, $hidden=false, $rev=NULL, $type='sandbox')
{
return $this->metadata($file, false, true, $hidden, $rev, $type);
} | [
"public",
"function",
"exists",
"(",
"$",
"file",
",",
"$",
"hidden",
"=",
"false",
",",
"$",
"rev",
"=",
"NULL",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"return",
"$",
"this",
"->",
"metadata",
"(",
"$",
"file",
",",
"false",
",",
"true",
... | determine if the file exists
@param $file
@param bool $hidden
@param null $rev
@param string $type
@return mixed | [
"determine",
"if",
"the",
"file",
"exists"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L233-L236 |
38,991 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.listDir | public function listDir($dir='/', $filter=NULL, $hidden=false, $rev=NUll, $type='sandbox')
{
$result = $this->metadata($dir, true, false, $hidden, $rev, $type);
$return = array();
foreach ($result['contents'] as $item) {
$exp = explode('/', $item['path']);
$ext = explode('.', $name = end($exp));
if (!$filter || preg_match($filter, $name))
$return[$name] = array(
'path' => $item['path'],
'filename' => $name,
'extension' => (count($ext) > 1) ? array_pop($ext) : null,
'basename' => implode('.', $ext),
'mtime'=>strtotime($item['modified']),
'size' => $item['bytes'],
'type' => $item['is_dir'] ? 'dir' : 'file',
);
}
return $return;
} | php | public function listDir($dir='/', $filter=NULL, $hidden=false, $rev=NUll, $type='sandbox')
{
$result = $this->metadata($dir, true, false, $hidden, $rev, $type);
$return = array();
foreach ($result['contents'] as $item) {
$exp = explode('/', $item['path']);
$ext = explode('.', $name = end($exp));
if (!$filter || preg_match($filter, $name))
$return[$name] = array(
'path' => $item['path'],
'filename' => $name,
'extension' => (count($ext) > 1) ? array_pop($ext) : null,
'basename' => implode('.', $ext),
'mtime'=>strtotime($item['modified']),
'size' => $item['bytes'],
'type' => $item['is_dir'] ? 'dir' : 'file',
);
}
return $return;
} | [
"public",
"function",
"listDir",
"(",
"$",
"dir",
"=",
"'/'",
",",
"$",
"filter",
"=",
"NULL",
",",
"$",
"hidden",
"=",
"false",
",",
"$",
"rev",
"=",
"NUll",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
... | list directory contents
@param string $dir
@param string $filter
@param bool $hidden
@param null $rev
@param string $type
@return bool|mixed | [
"list",
"directory",
"contents"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L247-L266 |
38,992 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.fileInfo | public function fileInfo($file, $rev=NUll, $type='sandbox')
{
return $this->metadata($file,false,false,true,$rev,$type);
} | php | public function fileInfo($file, $rev=NUll, $type='sandbox')
{
return $this->metadata($file,false,false,true,$rev,$type);
} | [
"public",
"function",
"fileInfo",
"(",
"$",
"file",
",",
"$",
"rev",
"=",
"NUll",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"return",
"$",
"this",
"->",
"metadata",
"(",
"$",
"file",
",",
"false",
",",
"false",
",",
"true",
",",
"$",
"rev",
"... | get file information
@param $file
@param null $rev
@param string $type
@return bool|mixed | [
"get",
"file",
"information"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L275-L278 |
38,993 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.metadata | public function metadata($file, $list=true, $existCheck=false,
$hidden=false, $rev=NULL, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/metadata/';
$params = array();
$params['list'] = $list;
if ($rev) $params['rev'] = $rev;
if ($list) $params['include_deleted'] = 'false';
$result = $this->doOAuthCall($url, 'GET', $params, $type,$file);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
if($existCheck) {
if(array_key_exists('is_deleted',$result_body) && $result_body['is_deleted'])
return ($hidden) ? true : false;
else return true;
}
else return $result_body;
} else {
if($existCheck) return false;
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | php | public function metadata($file, $list=true, $existCheck=false,
$hidden=false, $rev=NULL, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/metadata/';
$params = array();
$params['list'] = $list;
if ($rev) $params['rev'] = $rev;
if ($list) $params['include_deleted'] = 'false';
$result = $this->doOAuthCall($url, 'GET', $params, $type,$file);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
if($existCheck) {
if(array_key_exists('is_deleted',$result_body) && $result_body['is_deleted'])
return ($hidden) ? true : false;
else return true;
}
else return $result_body;
} else {
if($existCheck) return false;
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | [
"public",
"function",
"metadata",
"(",
"$",
"file",
",",
"$",
"list",
"=",
"true",
",",
"$",
"existCheck",
"=",
"false",
",",
"$",
"hidden",
"=",
"false",
",",
"$",
"rev",
"=",
"NULL",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"url",
"="... | perform meta request
@param string $file full file pathname
@param bool $list include file list, if $file is a dir
@param bool $existCheck return bool instead of json or error
@param bool $hidden include deleted files
@param null $rev select file version
@param string $type storage type [sandbox|dropbox]
@return bool|mixed | [
"perform",
"meta",
"request"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L290-L312 |
38,994 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.write | public function write($file, $content, $type='sandbox')
{
$url = 'https://api-content.dropbox.com/1/files_put/';
$result = $this->doOAuthCall($url,'PUT',null,$type,$file,$content);
$result_body = json_decode($result['body'],true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | php | public function write($file, $content, $type='sandbox')
{
$url = 'https://api-content.dropbox.com/1/files_put/';
$result = $this->doOAuthCall($url,'PUT',null,$type,$file,$content);
$result_body = json_decode($result['body'],true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | [
"public",
"function",
"write",
"(",
"$",
"file",
",",
"$",
"content",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"url",
"=",
"'https://api-content.dropbox.com/1/files_put/'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"doOAuthCall",
"(",
"$",
"url... | write file content
@param $file file path
@param $content file content
@param string $type sandbox or dropbox
@return mixed | [
"write",
"file",
"content"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L321-L332 |
38,995 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.delete | public function delete($file, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/fileops/delete';
$result = $this->doOAuthCall($url,'POST',array('path' => $file),$type);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | php | public function delete($file, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/fileops/delete';
$result = $this->doOAuthCall($url,'POST',array('path' => $file),$type);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | [
"public",
"function",
"delete",
"(",
"$",
"file",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"url",
"=",
"'https://api.dropbox.com/1/fileops/delete'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"doOAuthCall",
"(",
"$",
"url",
",",
"'POST'",
",",
... | delete a file or dir
@param $file
@param string $type
@return mixed | [
"delete",
"a",
"file",
"or",
"dir"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L340-L351 |
38,996 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.move | public function move($from, $to, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/fileops/move';
$params = array('from_path' => $from,'to_path'=>$to);
$result = $this->doOAuthCall($url, 'POST', $params, $type);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | php | public function move($from, $to, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/fileops/move';
$params = array('from_path' => $from,'to_path'=>$to);
$result = $this->doOAuthCall($url, 'POST', $params, $type);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | [
"public",
"function",
"move",
"(",
"$",
"from",
",",
"$",
"to",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"url",
"=",
"'https://api.dropbox.com/1/fileops/move'",
";",
"$",
"params",
"=",
"array",
"(",
"'from_path'",
"=>",
"$",
"from",
",",
"'to_... | rename a file or directory
@param $from
@param $to
@param string $type
@return mixed | [
"rename",
"a",
"file",
"or",
"directory"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L360-L372 |
38,997 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.modified | public function modified($file, $rev=NULL, $type='sandbox')
{
$result = $this->metadata($file, false, false, true, $rev, $type);
return strtotime($result['modified']);
} | php | public function modified($file, $rev=NULL, $type='sandbox')
{
$result = $this->metadata($file, false, false, true, $rev, $type);
return strtotime($result['modified']);
} | [
"public",
"function",
"modified",
"(",
"$",
"file",
",",
"$",
"rev",
"=",
"NULL",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"metadata",
"(",
"$",
"file",
",",
"false",
",",
"false",
",",
"true",
",",
"$"... | get last modified date
@param $file
@param null $rev
@param string $type
@return mixed | [
"get",
"last",
"modified",
"date"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L381-L385 |
38,998 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.isDir | public function isDir($dir, $rev=NULL, $type='sandbox')
{
$result = $this->metadata($dir, false, true, false, $rev, $type);
return (bool)$result;
} | php | public function isDir($dir, $rev=NULL, $type='sandbox')
{
$result = $this->metadata($dir, false, true, false, $rev, $type);
return (bool)$result;
} | [
"public",
"function",
"isDir",
"(",
"$",
"dir",
",",
"$",
"rev",
"=",
"NULL",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"metadata",
"(",
"$",
"dir",
",",
"false",
",",
"true",
",",
"false",
",",
"$",
"... | return whether the item is a directory
@param $dir
@param null $rev
@param string $type
@return mixed | [
"return",
"whether",
"the",
"item",
"is",
"a",
"directory"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L407-L411 |
38,999 | ikkez/f3-fal | lib/fal/dropbox.php | Dropbox.createDir | public function createDir($dir, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/fileops/create_folder';
$result = $this->doOAuthCall($url, 'POST', array('path'=>$dir), $type);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | php | public function createDir($dir, $type='sandbox')
{
$url = 'https://api.dropbox.com/1/fileops/create_folder';
$result = $this->doOAuthCall($url, 'POST', array('path'=>$dir), $type);
$result_body = json_decode($result['body'], true);
if (!array_key_exists('error', $result_body)) {
return $result_body;
} else {
trigger_error(sprintf(self::E_APIERROR, $result_body['error']));
return false;
}
} | [
"public",
"function",
"createDir",
"(",
"$",
"dir",
",",
"$",
"type",
"=",
"'sandbox'",
")",
"{",
"$",
"url",
"=",
"'https://api.dropbox.com/1/fileops/create_folder'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"doOAuthCall",
"(",
"$",
"url",
",",
"'POST'",... | create new directory
@param $dir
@param string $type
@return mixed | [
"create",
"new",
"directory"
] | ebd593306bab008210b2d16ffffca599c667d7fe | https://github.com/ikkez/f3-fal/blob/ebd593306bab008210b2d16ffffca599c667d7fe/lib/fal/dropbox.php#L419-L430 |
Subsets and Splits
Yii Code Samples
Gathers all records from test, train, and validation sets that contain the word 'yii', providing a basic filtered view of the dataset relevant to Yii-related content.