repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
listlengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
listlengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatFunction | public function formatFunction(Func $func) {
$arguments = [];
foreach ($func->getArguments() as $arg) {
$type = $arg['type'];
$value = $arg['value'];
if ($value instanceof Func) {
$value = $this->formatFunction($value);
} else if ($value instanceof SubQuery) {
$value = $this->formatSubQuery($value);
} else if ($type === Func::FIELD) {
$value = $this->quote($value);
} else if ($type === Func::LITERAL) {
// Do nothing
} else if (is_string($value) || $value === null) {
$value = $this->getDriver()->escape($value);
}
$arguments[] = $value;
}
$output = sprintf($this->getClause(self::FUNC),
$func->getName(),
implode($func->getSeparator(), $arguments)
);
if ($alias = $func->getAlias()) {
$output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
}
return $output;
} | php | public function formatFunction(Func $func) {
$arguments = [];
foreach ($func->getArguments() as $arg) {
$type = $arg['type'];
$value = $arg['value'];
if ($value instanceof Func) {
$value = $this->formatFunction($value);
} else if ($value instanceof SubQuery) {
$value = $this->formatSubQuery($value);
} else if ($type === Func::FIELD) {
$value = $this->quote($value);
} else if ($type === Func::LITERAL) {
// Do nothing
} else if (is_string($value) || $value === null) {
$value = $this->getDriver()->escape($value);
}
$arguments[] = $value;
}
$output = sprintf($this->getClause(self::FUNC),
$func->getName(),
implode($func->getSeparator(), $arguments)
);
if ($alias = $func->getAlias()) {
$output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
}
return $output;
} | [
"public",
"function",
"formatFunction",
"(",
"Func",
"$",
"func",
")",
"{",
"$",
"arguments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"func",
"->",
"getArguments",
"(",
")",
"as",
"$",
"arg",
")",
"{",
"$",
"type",
"=",
"$",
"arg",
"[",
"'type'",
"]",
";",
"$",
"value",
"=",
"$",
"arg",
"[",
"'value'",
"]",
";",
"if",
"(",
"$",
"value",
"instanceof",
"Func",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"formatFunction",
"(",
"$",
"value",
")",
";",
"}",
"else",
"if",
"(",
"$",
"value",
"instanceof",
"SubQuery",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"formatSubQuery",
"(",
"$",
"value",
")",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"Func",
"::",
"FIELD",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"value",
")",
";",
"}",
"else",
"if",
"(",
"$",
"type",
"===",
"Func",
"::",
"LITERAL",
")",
"{",
"// Do nothing",
"}",
"else",
"if",
"(",
"is_string",
"(",
"$",
"value",
")",
"||",
"$",
"value",
"===",
"null",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getDriver",
"(",
")",
"->",
"escape",
"(",
"$",
"value",
")",
";",
"}",
"$",
"arguments",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"$",
"output",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"FUNC",
")",
",",
"$",
"func",
"->",
"getName",
"(",
")",
",",
"implode",
"(",
"$",
"func",
"->",
"getSeparator",
"(",
")",
",",
"$",
"arguments",
")",
")",
";",
"if",
"(",
"$",
"alias",
"=",
"$",
"func",
"->",
"getAlias",
"(",
")",
")",
"{",
"$",
"output",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"AS_ALIAS",
")",
",",
"$",
"output",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"alias",
")",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
]
| Format a database function.
@param \Titon\Db\Query\Func $func
@return string | [
"Format",
"a",
"database",
"function",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L624-L660 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatGroupBy | public function formatGroupBy(array $groupBy) {
if ($groupBy) {
return sprintf($this->getClause(self::GROUP_BY), $this->quoteList($groupBy));
}
return '';
} | php | public function formatGroupBy(array $groupBy) {
if ($groupBy) {
return sprintf($this->getClause(self::GROUP_BY), $this->quoteList($groupBy));
}
return '';
} | [
"public",
"function",
"formatGroupBy",
"(",
"array",
"$",
"groupBy",
")",
"{",
"if",
"(",
"$",
"groupBy",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"GROUP_BY",
")",
",",
"$",
"this",
"->",
"quoteList",
"(",
"$",
"groupBy",
")",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Format the group by.
@param array $groupBy
@return string | [
"Format",
"the",
"group",
"by",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L668-L674 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatHaving | public function formatHaving(Predicate $having) {
if ($having->getParams()) {
return sprintf($this->getClause(self::HAVING), $this->formatPredicate($having));
}
return '';
} | php | public function formatHaving(Predicate $having) {
if ($having->getParams()) {
return sprintf($this->getClause(self::HAVING), $this->formatPredicate($having));
}
return '';
} | [
"public",
"function",
"formatHaving",
"(",
"Predicate",
"$",
"having",
")",
"{",
"if",
"(",
"$",
"having",
"->",
"getParams",
"(",
")",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"HAVING",
")",
",",
"$",
"this",
"->",
"formatPredicate",
"(",
"$",
"having",
")",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Format the having clause.
@param \Titon\Db\Query\Predicate $having
@return string | [
"Format",
"the",
"having",
"clause",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L682-L688 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatJoins | public function formatJoins(array $joins) {
if ($joins) {
$output = [];
foreach ($joins as $join) {
$conditions = [];
foreach ($join->getOn() as $pfk => $rfk) {
$conditions[] = $this->quote($pfk) . ' = ' . $this->quote($rfk);
}
$output[] = sprintf($this->getClause($join->getType()),
$this->formatTable($join->getTable(), $join->getAlias()),
implode(' ' . $this->getKeyword(self::ALSO) . ' ', $conditions));
}
return implode(' ', $output);
}
return '';
} | php | public function formatJoins(array $joins) {
if ($joins) {
$output = [];
foreach ($joins as $join) {
$conditions = [];
foreach ($join->getOn() as $pfk => $rfk) {
$conditions[] = $this->quote($pfk) . ' = ' . $this->quote($rfk);
}
$output[] = sprintf($this->getClause($join->getType()),
$this->formatTable($join->getTable(), $join->getAlias()),
implode(' ' . $this->getKeyword(self::ALSO) . ' ', $conditions));
}
return implode(' ', $output);
}
return '';
} | [
"public",
"function",
"formatJoins",
"(",
"array",
"$",
"joins",
")",
"{",
"if",
"(",
"$",
"joins",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"joins",
"as",
"$",
"join",
")",
"{",
"$",
"conditions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"join",
"->",
"getOn",
"(",
")",
"as",
"$",
"pfk",
"=>",
"$",
"rfk",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"pfk",
")",
".",
"' = '",
".",
"$",
"this",
"->",
"quote",
"(",
"$",
"rfk",
")",
";",
"}",
"$",
"output",
"[",
"]",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"$",
"join",
"->",
"getType",
"(",
")",
")",
",",
"$",
"this",
"->",
"formatTable",
"(",
"$",
"join",
"->",
"getTable",
"(",
")",
",",
"$",
"join",
"->",
"getAlias",
"(",
")",
")",
",",
"implode",
"(",
"' '",
".",
"$",
"this",
"->",
"getKeyword",
"(",
"self",
"::",
"ALSO",
")",
".",
"' '",
",",
"$",
"conditions",
")",
")",
";",
"}",
"return",
"implode",
"(",
"' '",
",",
"$",
"output",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Format the list of joins.
@param \Titon\Db\Query\Join[] $joins
@return string | [
"Format",
"the",
"list",
"of",
"joins",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L696-L716 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatLimit | public function formatLimit($limit) {
if ($limit) {
return sprintf($this->getClause(self::LIMIT), (int) $limit);
}
return '';
} | php | public function formatLimit($limit) {
if ($limit) {
return sprintf($this->getClause(self::LIMIT), (int) $limit);
}
return '';
} | [
"public",
"function",
"formatLimit",
"(",
"$",
"limit",
")",
"{",
"if",
"(",
"$",
"limit",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"LIMIT",
")",
",",
"(",
"int",
")",
"$",
"limit",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Format the limit.
@param int $limit
@return string | [
"Format",
"the",
"limit",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L724-L730 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatLimitOffset | public function formatLimitOffset($limit, $offset = 0) {
if ($limit && $offset) {
return sprintf($this->getClause(self::LIMIT_OFFSET), (int) $limit, (int) $offset);
}
return $this->formatLimit($limit);
} | php | public function formatLimitOffset($limit, $offset = 0) {
if ($limit && $offset) {
return sprintf($this->getClause(self::LIMIT_OFFSET), (int) $limit, (int) $offset);
}
return $this->formatLimit($limit);
} | [
"public",
"function",
"formatLimitOffset",
"(",
"$",
"limit",
",",
"$",
"offset",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"limit",
"&&",
"$",
"offset",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"LIMIT_OFFSET",
")",
",",
"(",
"int",
")",
"$",
"limit",
",",
"(",
"int",
")",
"$",
"offset",
")",
";",
"}",
"return",
"$",
"this",
"->",
"formatLimit",
"(",
"$",
"limit",
")",
";",
"}"
]
| Format the limit and offset.
@param int $limit
@param int $offset
@return string | [
"Format",
"the",
"limit",
"and",
"offset",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L739-L745 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatOrderBy | public function formatOrderBy(array $orderBy) {
if ($orderBy) {
$output = [];
foreach ($orderBy as $field => $direction) {
if ($direction instanceof Func) {
$output[] = $this->formatFunction($direction);
} else {
$output[] = $this->quote($field) . ' ' . $this->getKeyword($direction);
}
}
return sprintf($this->getClause(self::ORDER_BY), implode(', ', $output));
}
return '';
} | php | public function formatOrderBy(array $orderBy) {
if ($orderBy) {
$output = [];
foreach ($orderBy as $field => $direction) {
if ($direction instanceof Func) {
$output[] = $this->formatFunction($direction);
} else {
$output[] = $this->quote($field) . ' ' . $this->getKeyword($direction);
}
}
return sprintf($this->getClause(self::ORDER_BY), implode(', ', $output));
}
return '';
} | [
"public",
"function",
"formatOrderBy",
"(",
"array",
"$",
"orderBy",
")",
"{",
"if",
"(",
"$",
"orderBy",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"orderBy",
"as",
"$",
"field",
"=>",
"$",
"direction",
")",
"{",
"if",
"(",
"$",
"direction",
"instanceof",
"Func",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"formatFunction",
"(",
"$",
"direction",
")",
";",
"}",
"else",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"field",
")",
".",
"' '",
".",
"$",
"this",
"->",
"getKeyword",
"(",
"$",
"direction",
")",
";",
"}",
"}",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"ORDER_BY",
")",
",",
"implode",
"(",
"', '",
",",
"$",
"output",
")",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Format the order by.
@param array $orderBy
@return string | [
"Format",
"the",
"order",
"by",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L753-L769 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatPredicate | public function formatPredicate(Predicate $predicate) {
$output = [];
foreach ($predicate->getParams() as $param) {
if ($param instanceof Predicate) {
$output[] = sprintf($this->getClause(self::GROUP), $this->formatPredicate($param));
} else if ($param instanceof Expr) {
$output[] = $this->formatExpression($param);
}
}
return implode(' ' . $this->getKeyword($predicate->getType()) . ' ', $output);
} | php | public function formatPredicate(Predicate $predicate) {
$output = [];
foreach ($predicate->getParams() as $param) {
if ($param instanceof Predicate) {
$output[] = sprintf($this->getClause(self::GROUP), $this->formatPredicate($param));
} else if ($param instanceof Expr) {
$output[] = $this->formatExpression($param);
}
}
return implode(' ' . $this->getKeyword($predicate->getType()) . ' ', $output);
} | [
"public",
"function",
"formatPredicate",
"(",
"Predicate",
"$",
"predicate",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"predicate",
"->",
"getParams",
"(",
")",
"as",
"$",
"param",
")",
"{",
"if",
"(",
"$",
"param",
"instanceof",
"Predicate",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"GROUP",
")",
",",
"$",
"this",
"->",
"formatPredicate",
"(",
"$",
"param",
")",
")",
";",
"}",
"else",
"if",
"(",
"$",
"param",
"instanceof",
"Expr",
")",
"{",
"$",
"output",
"[",
"]",
"=",
"$",
"this",
"->",
"formatExpression",
"(",
"$",
"param",
")",
";",
"}",
"}",
"return",
"implode",
"(",
"' '",
".",
"$",
"this",
"->",
"getKeyword",
"(",
"$",
"predicate",
"->",
"getType",
"(",
")",
")",
".",
"' '",
",",
"$",
"output",
")",
";",
"}"
]
| Format the predicate object by grouping nested predicates and parameters.
@param \Titon\Db\Query\Predicate $predicate
@return string | [
"Format",
"the",
"predicate",
"object",
"by",
"grouping",
"nested",
"predicates",
"and",
"parameters",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L777-L790 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatSubQuery | public function formatSubQuery(SubQuery $query) {
// Reset the alias since statement would have double aliasing
$alias = $query->getAlias();
$query->asAlias(null);
// @codeCoverageIgnoreStart
if (method_exists($this, 'buildSelect')) {
$output = sprintf($this->getClause(self::SUB_QUERY), trim($this->buildSelect($query), ';'));
} else {
throw new UnsupportedQueryStatementException('Sub-query building requires a buildSelect() method');
}
// @codeCoverageIgnoreEnd
if ($alias) {
$output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
}
if ($filter = $query->getFilter()) {
$output = $this->getKeyword($filter) . ' ' . $output;
}
return $output;
} | php | public function formatSubQuery(SubQuery $query) {
// Reset the alias since statement would have double aliasing
$alias = $query->getAlias();
$query->asAlias(null);
// @codeCoverageIgnoreStart
if (method_exists($this, 'buildSelect')) {
$output = sprintf($this->getClause(self::SUB_QUERY), trim($this->buildSelect($query), ';'));
} else {
throw new UnsupportedQueryStatementException('Sub-query building requires a buildSelect() method');
}
// @codeCoverageIgnoreEnd
if ($alias) {
$output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
}
if ($filter = $query->getFilter()) {
$output = $this->getKeyword($filter) . ' ' . $output;
}
return $output;
} | [
"public",
"function",
"formatSubQuery",
"(",
"SubQuery",
"$",
"query",
")",
"{",
"// Reset the alias since statement would have double aliasing",
"$",
"alias",
"=",
"$",
"query",
"->",
"getAlias",
"(",
")",
";",
"$",
"query",
"->",
"asAlias",
"(",
"null",
")",
";",
"// @codeCoverageIgnoreStart",
"if",
"(",
"method_exists",
"(",
"$",
"this",
",",
"'buildSelect'",
")",
")",
"{",
"$",
"output",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"SUB_QUERY",
")",
",",
"trim",
"(",
"$",
"this",
"->",
"buildSelect",
"(",
"$",
"query",
")",
",",
"';'",
")",
")",
";",
"}",
"else",
"{",
"throw",
"new",
"UnsupportedQueryStatementException",
"(",
"'Sub-query building requires a buildSelect() method'",
")",
";",
"}",
"// @codeCoverageIgnoreEnd",
"if",
"(",
"$",
"alias",
")",
"{",
"$",
"output",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"AS_ALIAS",
")",
",",
"$",
"output",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"alias",
")",
")",
";",
"}",
"if",
"(",
"$",
"filter",
"=",
"$",
"query",
"->",
"getFilter",
"(",
")",
")",
"{",
"$",
"output",
"=",
"$",
"this",
"->",
"getKeyword",
"(",
"$",
"filter",
")",
".",
"' '",
".",
"$",
"output",
";",
"}",
"return",
"$",
"output",
";",
"}"
]
| Format a sub-query.
@param \Titon\Db\Query\SubQuery $query
@return string
@throws \Titon\Db\Exception\UnsupportedQueryStatementException | [
"Format",
"a",
"sub",
"-",
"query",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L799-L822 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatTable | public function formatTable($table, $alias = null) {
if (!$table) {
throw new InvalidTableException('Missing table name for query');
}
$output = $this->quote($table);
if ($alias && $table !== $alias) {
$output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
}
return $output;
} | php | public function formatTable($table, $alias = null) {
if (!$table) {
throw new InvalidTableException('Missing table name for query');
}
$output = $this->quote($table);
if ($alias && $table !== $alias) {
$output = sprintf($this->getClause(self::AS_ALIAS), $output, $this->quote($alias));
}
return $output;
} | [
"public",
"function",
"formatTable",
"(",
"$",
"table",
",",
"$",
"alias",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"table",
")",
"{",
"throw",
"new",
"InvalidTableException",
"(",
"'Missing table name for query'",
")",
";",
"}",
"$",
"output",
"=",
"$",
"this",
"->",
"quote",
"(",
"$",
"table",
")",
";",
"if",
"(",
"$",
"alias",
"&&",
"$",
"table",
"!==",
"$",
"alias",
")",
"{",
"$",
"output",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"AS_ALIAS",
")",
",",
"$",
"output",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"alias",
")",
")",
";",
"}",
"return",
"$",
"output",
";",
"}"
]
| Format the table name and alias name.
@param string $table
@param string $alias
@return string
@throws \Titon\Db\Exception\InvalidTableException | [
"Format",
"the",
"table",
"name",
"and",
"alias",
"name",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L832-L844 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatTableForeign | public function formatTableForeign(array $data) {
$ref = explode('.', $data['references']);
$key = sprintf($this->getClause(self::FOREIGN_KEY), $this->quote($data['column']), $this->quote($ref[0]), $this->quote($ref[1]));
if ($data['constraint']) {
$key = sprintf($this->getClause(self::CONSTRAINT), $this->quote($data['constraint'])) . ' ' . $key;
}
$actions = $data;
unset($actions['references'], $actions['constraint'], $actions['column']);
foreach ($actions as $clause => $action) {
$value = '';
if ($this->hasKeyword($action)) {
$value = $this->getKeyword($action);
}
$key .= ' ' . sprintf($this->getClause($clause), $value);
}
return $key;
} | php | public function formatTableForeign(array $data) {
$ref = explode('.', $data['references']);
$key = sprintf($this->getClause(self::FOREIGN_KEY), $this->quote($data['column']), $this->quote($ref[0]), $this->quote($ref[1]));
if ($data['constraint']) {
$key = sprintf($this->getClause(self::CONSTRAINT), $this->quote($data['constraint'])) . ' ' . $key;
}
$actions = $data;
unset($actions['references'], $actions['constraint'], $actions['column']);
foreach ($actions as $clause => $action) {
$value = '';
if ($this->hasKeyword($action)) {
$value = $this->getKeyword($action);
}
$key .= ' ' . sprintf($this->getClause($clause), $value);
}
return $key;
} | [
"public",
"function",
"formatTableForeign",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"ref",
"=",
"explode",
"(",
"'.'",
",",
"$",
"data",
"[",
"'references'",
"]",
")",
";",
"$",
"key",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"FOREIGN_KEY",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"data",
"[",
"'column'",
"]",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"ref",
"[",
"0",
"]",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"ref",
"[",
"1",
"]",
")",
")",
";",
"if",
"(",
"$",
"data",
"[",
"'constraint'",
"]",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"CONSTRAINT",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"data",
"[",
"'constraint'",
"]",
")",
")",
".",
"' '",
".",
"$",
"key",
";",
"}",
"$",
"actions",
"=",
"$",
"data",
";",
"unset",
"(",
"$",
"actions",
"[",
"'references'",
"]",
",",
"$",
"actions",
"[",
"'constraint'",
"]",
",",
"$",
"actions",
"[",
"'column'",
"]",
")",
";",
"foreach",
"(",
"$",
"actions",
"as",
"$",
"clause",
"=>",
"$",
"action",
")",
"{",
"$",
"value",
"=",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"hasKeyword",
"(",
"$",
"action",
")",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"getKeyword",
"(",
"$",
"action",
")",
";",
"}",
"$",
"key",
".=",
"' '",
".",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"$",
"clause",
")",
",",
"$",
"value",
")",
";",
"}",
"return",
"$",
"key",
";",
"}"
]
| Format a table foreign key.
@param array $data
@return string | [
"Format",
"a",
"table",
"foreign",
"key",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L852-L874 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatTableIndex | public function formatTableIndex($index, array $columns) {
return sprintf($this->getClause(self::INDEX), $this->quote($index), $this->quoteList($columns));
} | php | public function formatTableIndex($index, array $columns) {
return sprintf($this->getClause(self::INDEX), $this->quote($index), $this->quoteList($columns));
} | [
"public",
"function",
"formatTableIndex",
"(",
"$",
"index",
",",
"array",
"$",
"columns",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"INDEX",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"index",
")",
",",
"$",
"this",
"->",
"quoteList",
"(",
"$",
"columns",
")",
")",
";",
"}"
]
| Format a table index key.
@param string $index
@param array $columns
@return string | [
"Format",
"a",
"table",
"index",
"key",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L883-L885 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatTableKeys | public function formatTableKeys(Schema $schema) {
$keys = [];
if ($primary = $schema->getPrimaryKey()) {
$keys[] = $this->formatTablePrimary($primary);
}
foreach ($schema->getUniqueKeys() as $unique) {
$keys[] = $this->formatTableUnique($unique);
}
foreach ($schema->getForeignKeys() as $foreign) {
$keys[] = $this->formatTableForeign($foreign);
}
$keys = array_filter($keys);
if ($keys) {
return ",\n" . implode(",\n", $keys);
}
return '';
} | php | public function formatTableKeys(Schema $schema) {
$keys = [];
if ($primary = $schema->getPrimaryKey()) {
$keys[] = $this->formatTablePrimary($primary);
}
foreach ($schema->getUniqueKeys() as $unique) {
$keys[] = $this->formatTableUnique($unique);
}
foreach ($schema->getForeignKeys() as $foreign) {
$keys[] = $this->formatTableForeign($foreign);
}
$keys = array_filter($keys);
if ($keys) {
return ",\n" . implode(",\n", $keys);
}
return '';
} | [
"public",
"function",
"formatTableKeys",
"(",
"Schema",
"$",
"schema",
")",
"{",
"$",
"keys",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"primary",
"=",
"$",
"schema",
"->",
"getPrimaryKey",
"(",
")",
")",
"{",
"$",
"keys",
"[",
"]",
"=",
"$",
"this",
"->",
"formatTablePrimary",
"(",
"$",
"primary",
")",
";",
"}",
"foreach",
"(",
"$",
"schema",
"->",
"getUniqueKeys",
"(",
")",
"as",
"$",
"unique",
")",
"{",
"$",
"keys",
"[",
"]",
"=",
"$",
"this",
"->",
"formatTableUnique",
"(",
"$",
"unique",
")",
";",
"}",
"foreach",
"(",
"$",
"schema",
"->",
"getForeignKeys",
"(",
")",
"as",
"$",
"foreign",
")",
"{",
"$",
"keys",
"[",
"]",
"=",
"$",
"this",
"->",
"formatTableForeign",
"(",
"$",
"foreign",
")",
";",
"}",
"$",
"keys",
"=",
"array_filter",
"(",
"$",
"keys",
")",
";",
"if",
"(",
"$",
"keys",
")",
"{",
"return",
"\",\\n\"",
".",
"implode",
"(",
"\",\\n\"",
",",
"$",
"keys",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Format table keys (primary, unique and foreign) and indexes.
@param \Titon\Db\Driver\Schema $schema
@return string | [
"Format",
"table",
"keys",
"(",
"primary",
"unique",
"and",
"foreign",
")",
"and",
"indexes",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L893-L915 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatTableOptions | public function formatTableOptions(array $options) {
$output = [];
foreach ($this->formatAttributes($options) as $key => $value) {
if ($this->hasClause($key)) {
$option = sprintf($this->getClause($key), $value);
} else {
$option = $this->getKeyword($key);
if ($value !== true) {
$option .= ' ' . $value;
}
}
$output[] = $option;
}
return implode(' ', $output);
} | php | public function formatTableOptions(array $options) {
$output = [];
foreach ($this->formatAttributes($options) as $key => $value) {
if ($this->hasClause($key)) {
$option = sprintf($this->getClause($key), $value);
} else {
$option = $this->getKeyword($key);
if ($value !== true) {
$option .= ' ' . $value;
}
}
$output[] = $option;
}
return implode(' ', $output);
} | [
"public",
"function",
"formatTableOptions",
"(",
"array",
"$",
"options",
")",
"{",
"$",
"output",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"formatAttributes",
"(",
"$",
"options",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasClause",
"(",
"$",
"key",
")",
")",
"{",
"$",
"option",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"$",
"key",
")",
",",
"$",
"value",
")",
";",
"}",
"else",
"{",
"$",
"option",
"=",
"$",
"this",
"->",
"getKeyword",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"value",
"!==",
"true",
")",
"{",
"$",
"option",
".=",
"' '",
".",
"$",
"value",
";",
"}",
"}",
"$",
"output",
"[",
"]",
"=",
"$",
"option",
";",
"}",
"return",
"implode",
"(",
"' '",
",",
"$",
"output",
")",
";",
"}"
]
| Format the table options for a create table statement.
@param array $options
@return string | [
"Format",
"the",
"table",
"options",
"for",
"a",
"create",
"table",
"statement",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L923-L942 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatTablePrimary | public function formatTablePrimary(array $data) {
$key = sprintf($this->getClause(self::PRIMARY_KEY), $this->quoteList($data['columns']));
if ($data['constraint']) {
$key = sprintf($this->getClause(self::CONSTRAINT), $this->quote($data['constraint'])) . ' ' . $key;
}
return $key;
} | php | public function formatTablePrimary(array $data) {
$key = sprintf($this->getClause(self::PRIMARY_KEY), $this->quoteList($data['columns']));
if ($data['constraint']) {
$key = sprintf($this->getClause(self::CONSTRAINT), $this->quote($data['constraint'])) . ' ' . $key;
}
return $key;
} | [
"public",
"function",
"formatTablePrimary",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"PRIMARY_KEY",
")",
",",
"$",
"this",
"->",
"quoteList",
"(",
"$",
"data",
"[",
"'columns'",
"]",
")",
")",
";",
"if",
"(",
"$",
"data",
"[",
"'constraint'",
"]",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"CONSTRAINT",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"data",
"[",
"'constraint'",
"]",
")",
")",
".",
"' '",
".",
"$",
"key",
";",
"}",
"return",
"$",
"key",
";",
"}"
]
| Format a table primary key.
@param array $data
@return string | [
"Format",
"a",
"table",
"primary",
"key",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L950-L958 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatTableUnique | public function formatTableUnique(array $data) {
$key = sprintf($this->getClause(self::UNIQUE_KEY), $this->quote($data['index']), $this->quoteList($data['columns']));
if ($data['constraint']) {
$key = sprintf($this->getClause(self::CONSTRAINT), $this->quote($data['constraint'])) . ' ' . $key;
}
return $key;
} | php | public function formatTableUnique(array $data) {
$key = sprintf($this->getClause(self::UNIQUE_KEY), $this->quote($data['index']), $this->quoteList($data['columns']));
if ($data['constraint']) {
$key = sprintf($this->getClause(self::CONSTRAINT), $this->quote($data['constraint'])) . ' ' . $key;
}
return $key;
} | [
"public",
"function",
"formatTableUnique",
"(",
"array",
"$",
"data",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"UNIQUE_KEY",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"data",
"[",
"'index'",
"]",
")",
",",
"$",
"this",
"->",
"quoteList",
"(",
"$",
"data",
"[",
"'columns'",
"]",
")",
")",
";",
"if",
"(",
"$",
"data",
"[",
"'constraint'",
"]",
")",
"{",
"$",
"key",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"CONSTRAINT",
")",
",",
"$",
"this",
"->",
"quote",
"(",
"$",
"data",
"[",
"'constraint'",
"]",
")",
")",
".",
"' '",
".",
"$",
"key",
";",
"}",
"return",
"$",
"key",
";",
"}"
]
| Format a table unique key.
@param array $data
@return string | [
"Format",
"a",
"table",
"unique",
"key",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L966-L974 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatValues | public function formatValues(Query $query) {
$fields = $query->getData();
switch ($query->getType()) {
case Query::INSERT:
return sprintf($this->getClause(self::GROUP), implode(', ', array_fill(0, count($fields), '?')));
break;
case Query::MULTI_INSERT:
$value = sprintf($this->getClause(self::GROUP), implode(', ', array_fill(0, count($fields[0]), '?')));
return implode(', ', array_fill(0, count($fields), $value));
break;
}
return '';
} | php | public function formatValues(Query $query) {
$fields = $query->getData();
switch ($query->getType()) {
case Query::INSERT:
return sprintf($this->getClause(self::GROUP), implode(', ', array_fill(0, count($fields), '?')));
break;
case Query::MULTI_INSERT:
$value = sprintf($this->getClause(self::GROUP), implode(', ', array_fill(0, count($fields[0]), '?')));
return implode(', ', array_fill(0, count($fields), $value));
break;
}
return '';
} | [
"public",
"function",
"formatValues",
"(",
"Query",
"$",
"query",
")",
"{",
"$",
"fields",
"=",
"$",
"query",
"->",
"getData",
"(",
")",
";",
"switch",
"(",
"$",
"query",
"->",
"getType",
"(",
")",
")",
"{",
"case",
"Query",
"::",
"INSERT",
":",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"GROUP",
")",
",",
"implode",
"(",
"', '",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"fields",
")",
",",
"'?'",
")",
")",
")",
";",
"break",
";",
"case",
"Query",
"::",
"MULTI_INSERT",
":",
"$",
"value",
"=",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"GROUP",
")",
",",
"implode",
"(",
"', '",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"fields",
"[",
"0",
"]",
")",
",",
"'?'",
")",
")",
")",
";",
"return",
"implode",
"(",
"', '",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"$",
"fields",
")",
",",
"$",
"value",
")",
")",
";",
"break",
";",
"}",
"return",
"''",
";",
"}"
]
| Format the fields values structure depending on the type of query.
@param \Titon\Db\Query $query
@return string | [
"Format",
"the",
"fields",
"values",
"structure",
"depending",
"on",
"the",
"type",
"of",
"query",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L982-L997 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.formatWhere | public function formatWhere(Predicate $where) {
if ($where->getParams()) {
return sprintf($this->getClause(self::WHERE), $this->formatPredicate($where));
}
return '';
} | php | public function formatWhere(Predicate $where) {
if ($where->getParams()) {
return sprintf($this->getClause(self::WHERE), $this->formatPredicate($where));
}
return '';
} | [
"public",
"function",
"formatWhere",
"(",
"Predicate",
"$",
"where",
")",
"{",
"if",
"(",
"$",
"where",
"->",
"getParams",
"(",
")",
")",
"{",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"getClause",
"(",
"self",
"::",
"WHERE",
")",
",",
"$",
"this",
"->",
"formatPredicate",
"(",
"$",
"where",
")",
")",
";",
"}",
"return",
"''",
";",
"}"
]
| Format the where clause.
@param \Titon\Db\Query\Predicate $where
@return string | [
"Format",
"the",
"where",
"clause",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L1005-L1011 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.getClause | public function getClause($key) {
if ($this->hasClause($key)) {
return $this->_clauses[$key];
}
throw new MissingClauseException(sprintf('Missing clause %s', $key));
} | php | public function getClause($key) {
if ($this->hasClause($key)) {
return $this->_clauses[$key];
}
throw new MissingClauseException(sprintf('Missing clause %s', $key));
} | [
"public",
"function",
"getClause",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasClause",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_clauses",
"[",
"$",
"key",
"]",
";",
"}",
"throw",
"new",
"MissingClauseException",
"(",
"sprintf",
"(",
"'Missing clause %s'",
",",
"$",
"key",
")",
")",
";",
"}"
]
| {@inheritdoc}
@throws \Titon\Db\Exception\MissingClauseException | [
"{",
"@inheritdoc",
"}"
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L1018-L1024 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.getKeyword | public function getKeyword($key) {
if ($this->hasKeyword($key)) {
return $this->_keywords[$key];
}
throw new MissingKeywordException(sprintf('Missing keyword %s', $key));
} | php | public function getKeyword($key) {
if ($this->hasKeyword($key)) {
return $this->_keywords[$key];
}
throw new MissingKeywordException(sprintf('Missing keyword %s', $key));
} | [
"public",
"function",
"getKeyword",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasKeyword",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_keywords",
"[",
"$",
"key",
"]",
";",
"}",
"throw",
"new",
"MissingKeywordException",
"(",
"sprintf",
"(",
"'Missing keyword %s'",
",",
"$",
"key",
")",
")",
";",
"}"
]
| {@inheritdoc}
@throws \Titon\Db\Exception\MissingKeywordException | [
"{",
"@inheritdoc",
"}"
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L1038-L1044 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.getStatement | public function getStatement($key) {
if ($this->hasStatement($key)) {
return $this->_statements[$key];
}
throw new MissingStatementException(sprintf('Missing statement %s', $key));
} | php | public function getStatement($key) {
if ($this->hasStatement($key)) {
return $this->_statements[$key];
}
throw new MissingStatementException(sprintf('Missing statement %s', $key));
} | [
"public",
"function",
"getStatement",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasStatement",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_statements",
"[",
"$",
"key",
"]",
";",
"}",
"throw",
"new",
"MissingStatementException",
"(",
"sprintf",
"(",
"'Missing statement %s'",
",",
"$",
"key",
")",
")",
";",
"}"
]
| {@inheritdoc}
@throws \Titon\Db\Exception\MissingStatementException | [
"{",
"@inheritdoc",
"}"
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L1058-L1064 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect.quote | public function quote($value) {
if ($value === '') {
return '';
} else if ($value === '*') {
return '*';
}
if (strpos($value, '.') !== false) {
list($table, $field) = explode('.', $value);
if ($field !== '*') {
$field = $this->_quote($field);
}
return $this->_quote($table) . '.' . $field;
}
return $this->_quote($value);
} | php | public function quote($value) {
if ($value === '') {
return '';
} else if ($value === '*') {
return '*';
}
if (strpos($value, '.') !== false) {
list($table, $field) = explode('.', $value);
if ($field !== '*') {
$field = $this->_quote($field);
}
return $this->_quote($table) . '.' . $field;
}
return $this->_quote($value);
} | [
"public",
"function",
"quote",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"''",
")",
"{",
"return",
"''",
";",
"}",
"else",
"if",
"(",
"$",
"value",
"===",
"'*'",
")",
"{",
"return",
"'*'",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"value",
",",
"'.'",
")",
"!==",
"false",
")",
"{",
"list",
"(",
"$",
"table",
",",
"$",
"field",
")",
"=",
"explode",
"(",
"'.'",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"field",
"!==",
"'*'",
")",
"{",
"$",
"field",
"=",
"$",
"this",
"->",
"_quote",
"(",
"$",
"field",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_quote",
"(",
"$",
"table",
")",
".",
"'.'",
".",
"$",
"field",
";",
"}",
"return",
"$",
"this",
"->",
"_quote",
"(",
"$",
"value",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L1097-L1115 |
titon/db | src/Titon/Db/Driver/Dialect/AbstractDialect.php | AbstractDialect._quote | protected function _quote($value) {
$char = $this->getConfig('quoteCharacter');
return $char . str_replace($char, '', $value) . $char;
} | php | protected function _quote($value) {
$char = $this->getConfig('quoteCharacter');
return $char . str_replace($char, '', $value) . $char;
} | [
"protected",
"function",
"_quote",
"(",
"$",
"value",
")",
"{",
"$",
"char",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'quoteCharacter'",
")",
";",
"return",
"$",
"char",
".",
"str_replace",
"(",
"$",
"char",
",",
"''",
",",
"$",
"value",
")",
".",
"$",
"char",
";",
"}"
]
| Place quoting in a protected method for speed improvements.
This reduces the amount of calls to `strpos()` and `explode()`.
@param string $value
@return string | [
"Place",
"quoting",
"in",
"a",
"protected",
"method",
"for",
"speed",
"improvements",
".",
"This",
"reduces",
"the",
"amount",
"of",
"calls",
"to",
"strpos",
"()",
"and",
"explode",
"()",
"."
]
| train | https://github.com/titon/db/blob/fbc5159d1ce9d2139759c9367565986981485604/src/Titon/Db/Driver/Dialect/AbstractDialect.php#L1143-L1147 |
lode/fem | src/request.php | request.redirect | public static function redirect($location, $stop_execution=true, $code=null) {
if (preg_match('{^(http(s)?:)?//}', $location) == false) {
$base_url = 'http';
$base_url .= !empty($_SERVER['HTTPS']) ? 's' : '';
$base_url .= '://'.$_SERVER['SERVER_NAME'];
if (strpos($location, '/') !== 0) {
$base_url .= '/';
}
$location = $base_url.$location;
}
header('Location: '.$location, $replace=true, $code);
if ($stop_execution == false) {
return;
}
exit;
} | php | public static function redirect($location, $stop_execution=true, $code=null) {
if (preg_match('{^(http(s)?:)?//}', $location) == false) {
$base_url = 'http';
$base_url .= !empty($_SERVER['HTTPS']) ? 's' : '';
$base_url .= '://'.$_SERVER['SERVER_NAME'];
if (strpos($location, '/') !== 0) {
$base_url .= '/';
}
$location = $base_url.$location;
}
header('Location: '.$location, $replace=true, $code);
if ($stop_execution == false) {
return;
}
exit;
} | [
"public",
"static",
"function",
"redirect",
"(",
"$",
"location",
",",
"$",
"stop_execution",
"=",
"true",
",",
"$",
"code",
"=",
"null",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'{^(http(s)?:)?//}'",
",",
"$",
"location",
")",
"==",
"false",
")",
"{",
"$",
"base_url",
"=",
"'http'",
";",
"$",
"base_url",
".=",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTPS'",
"]",
")",
"?",
"'s'",
":",
"''",
";",
"$",
"base_url",
".=",
"'://'",
".",
"$",
"_SERVER",
"[",
"'SERVER_NAME'",
"]",
";",
"if",
"(",
"strpos",
"(",
"$",
"location",
",",
"'/'",
")",
"!==",
"0",
")",
"{",
"$",
"base_url",
".=",
"'/'",
";",
"}",
"$",
"location",
"=",
"$",
"base_url",
".",
"$",
"location",
";",
"}",
"header",
"(",
"'Location: '",
".",
"$",
"location",
",",
"$",
"replace",
"=",
"true",
",",
"$",
"code",
")",
";",
"if",
"(",
"$",
"stop_execution",
"==",
"false",
")",
"{",
"return",
";",
"}",
"exit",
";",
"}"
]
| redirect a browser session to a new url
also exists flow
@param string $location relative to the host
@param boolean $stop_execution defaults to true
@param int $code optional, status code instead of default 302
@return void | [
"redirect",
"a",
"browser",
"session",
"to",
"a",
"new",
"url",
"also",
"exists",
"flow"
]
| train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/request.php#L16-L36 |
lode/fem | src/request.php | request.get_method | public static function get_method() {
if (empty($_SERVER['REQUEST_METHOD'])) {
return 'GET';
}
$allowed_methods = ['GET', 'PUT', 'POST', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'];
if (in_array($_SERVER['REQUEST_METHOD'], $allowed_methods) == false) {
return false;
}
return $_SERVER['REQUEST_METHOD'];
} | php | public static function get_method() {
if (empty($_SERVER['REQUEST_METHOD'])) {
return 'GET';
}
$allowed_methods = ['GET', 'PUT', 'POST', 'PATCH', 'DELETE', 'OPTIONS', 'HEAD'];
if (in_array($_SERVER['REQUEST_METHOD'], $allowed_methods) == false) {
return false;
}
return $_SERVER['REQUEST_METHOD'];
} | [
"public",
"static",
"function",
"get_method",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
")",
")",
"{",
"return",
"'GET'",
";",
"}",
"$",
"allowed_methods",
"=",
"[",
"'GET'",
",",
"'PUT'",
",",
"'POST'",
",",
"'PATCH'",
",",
"'DELETE'",
",",
"'OPTIONS'",
",",
"'HEAD'",
"]",
";",
"if",
"(",
"in_array",
"(",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
",",
"$",
"allowed_methods",
")",
"==",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"_SERVER",
"[",
"'REQUEST_METHOD'",
"]",
";",
"}"
]
| get the http method used for the current session
@return string|boolean one of GET|PUT|POST|PATCH|DELETE|OPTIONS|HEAD
or false for unknown types | [
"get",
"the",
"http",
"method",
"used",
"for",
"the",
"current",
"session"
]
| train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/request.php#L57-L68 |
lode/fem | src/request.php | request.get_data | public static function get_data() {
if (static::get_method() == 'POST' && !empty($_POST)) {
return $_POST;
}
$data_string = file_get_contents('php://input');
if (empty($data_string)) {
return [];
}
// convert from json or xml
$type = self::get_content_type();
if ($type == 'json') {
return json_decode($data_string, true);
}
if ($type == 'xml') {
$xml_options =
LIBXML_NOCDATA| // convert CDATA to strings
LIBXML_COMPACT| // speed optimalization
LIBXML_NONET| // disable network access
LIBXML_NOERROR|LIBXML_NOWARNING; // turn off error reporting
$xml_data = simplexml_load_string($data_string, $class='SimpleXMLElement', $xml_options);
return json_decode(json_encode($xml_data), true);
}
parse_str($data_string, $data_array);
return $data_array;
} | php | public static function get_data() {
if (static::get_method() == 'POST' && !empty($_POST)) {
return $_POST;
}
$data_string = file_get_contents('php://input');
if (empty($data_string)) {
return [];
}
// convert from json or xml
$type = self::get_content_type();
if ($type == 'json') {
return json_decode($data_string, true);
}
if ($type == 'xml') {
$xml_options =
LIBXML_NOCDATA| // convert CDATA to strings
LIBXML_COMPACT| // speed optimalization
LIBXML_NONET| // disable network access
LIBXML_NOERROR|LIBXML_NOWARNING; // turn off error reporting
$xml_data = simplexml_load_string($data_string, $class='SimpleXMLElement', $xml_options);
return json_decode(json_encode($xml_data), true);
}
parse_str($data_string, $data_array);
return $data_array;
} | [
"public",
"static",
"function",
"get_data",
"(",
")",
"{",
"if",
"(",
"static",
"::",
"get_method",
"(",
")",
"==",
"'POST'",
"&&",
"!",
"empty",
"(",
"$",
"_POST",
")",
")",
"{",
"return",
"$",
"_POST",
";",
"}",
"$",
"data_string",
"=",
"file_get_contents",
"(",
"'php://input'",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"data_string",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"// convert from json or xml",
"$",
"type",
"=",
"self",
"::",
"get_content_type",
"(",
")",
";",
"if",
"(",
"$",
"type",
"==",
"'json'",
")",
"{",
"return",
"json_decode",
"(",
"$",
"data_string",
",",
"true",
")",
";",
"}",
"if",
"(",
"$",
"type",
"==",
"'xml'",
")",
"{",
"$",
"xml_options",
"=",
"LIBXML_NOCDATA",
"|",
"// convert CDATA to strings",
"LIBXML_COMPACT",
"|",
"// speed optimalization",
"LIBXML_NONET",
"|",
"// disable network access",
"LIBXML_NOERROR",
"|",
"LIBXML_NOWARNING",
";",
"// turn off error reporting",
"$",
"xml_data",
"=",
"simplexml_load_string",
"(",
"$",
"data_string",
",",
"$",
"class",
"=",
"'SimpleXMLElement'",
",",
"$",
"xml_options",
")",
";",
"return",
"json_decode",
"(",
"json_encode",
"(",
"$",
"xml_data",
")",
",",
"true",
")",
";",
"}",
"parse_str",
"(",
"$",
"data_string",
",",
"$",
"data_array",
")",
";",
"return",
"$",
"data_array",
";",
"}"
]
| get the http ($_POST) data
mainly useful for data from non-POST requests like PUT/PATCH/DELETE
@note also converts json or xml to the array
@return array a like $_POST | [
"get",
"the",
"http",
"(",
"$_POST",
")",
"data",
"mainly",
"useful",
"for",
"data",
"from",
"non",
"-",
"POST",
"requests",
"like",
"PUT",
"/",
"PATCH",
"/",
"DELETE"
]
| train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/request.php#L78-L107 |
lode/fem | src/request.php | request.get_primary_accept | public static function get_primary_accept() {
if (empty($_SERVER['HTTP_ACCEPT'])) {
return '*';
}
// catch the most common formats
if (strpos($_SERVER['HTTP_ACCEPT'], 'text/html,') === 0) {
return 'html';
}
if (strpos($_SERVER['HTTP_ACCEPT'], 'application/json,') === 0) {
return 'json';
}
// use a generic method
return self::get_primary_mime_type($_SERVER['HTTP_ACCEPT']);
} | php | public static function get_primary_accept() {
if (empty($_SERVER['HTTP_ACCEPT'])) {
return '*';
}
// catch the most common formats
if (strpos($_SERVER['HTTP_ACCEPT'], 'text/html,') === 0) {
return 'html';
}
if (strpos($_SERVER['HTTP_ACCEPT'], 'application/json,') === 0) {
return 'json';
}
// use a generic method
return self::get_primary_mime_type($_SERVER['HTTP_ACCEPT']);
} | [
"public",
"static",
"function",
"get_primary_accept",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
")",
")",
"{",
"return",
"'*'",
";",
"}",
"// catch the most common formats",
"if",
"(",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
",",
"'text/html,'",
")",
"===",
"0",
")",
"{",
"return",
"'html'",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
",",
"'application/json,'",
")",
"===",
"0",
")",
"{",
"return",
"'json'",
";",
"}",
"// use a generic method",
"return",
"self",
"::",
"get_primary_mime_type",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
")",
";",
"}"
]
| get the primary http accepted output format for the current session
@return string @see ::get_primary_mime_type() | [
"get",
"the",
"primary",
"http",
"accepted",
"output",
"format",
"for",
"the",
"current",
"session"
]
| train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/request.php#L136-L151 |
lode/fem | src/request.php | request.get_basic_auth | public static function get_basic_auth() {
// normally it just works
if (!empty($_SERVER['PHP_AUTH_USER'])) {
return [
'USER' => $_SERVER['PHP_AUTH_USER'],
'PW' => $_SERVER['PHP_AUTH_PW'],
];
}
// php cgi mode requires a work around
if (!empty($_SERVER['REDIRECT_REMOTE_USER']) && strpos($_SERVER['REDIRECT_REMOTE_USER'], 'Basic ') === 0) {
$credentials = substr($_SERVER['REDIRECT_REMOTE_USER'], strlen('Basic '));
$credentials = base64_decode($credentials);
if (strpos($credentials, ':')) {
$credentials = explode(':', $credentials);
return [
'USER' => $credentials[0],
'PW' => $credentials[1],
];
}
}
return null;
} | php | public static function get_basic_auth() {
// normally it just works
if (!empty($_SERVER['PHP_AUTH_USER'])) {
return [
'USER' => $_SERVER['PHP_AUTH_USER'],
'PW' => $_SERVER['PHP_AUTH_PW'],
];
}
// php cgi mode requires a work around
if (!empty($_SERVER['REDIRECT_REMOTE_USER']) && strpos($_SERVER['REDIRECT_REMOTE_USER'], 'Basic ') === 0) {
$credentials = substr($_SERVER['REDIRECT_REMOTE_USER'], strlen('Basic '));
$credentials = base64_decode($credentials);
if (strpos($credentials, ':')) {
$credentials = explode(':', $credentials);
return [
'USER' => $credentials[0],
'PW' => $credentials[1],
];
}
}
return null;
} | [
"public",
"static",
"function",
"get_basic_auth",
"(",
")",
"{",
"// normally it just works",
"if",
"(",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'PHP_AUTH_USER'",
"]",
")",
")",
"{",
"return",
"[",
"'USER'",
"=>",
"$",
"_SERVER",
"[",
"'PHP_AUTH_USER'",
"]",
",",
"'PW'",
"=>",
"$",
"_SERVER",
"[",
"'PHP_AUTH_PW'",
"]",
",",
"]",
";",
"}",
"// php cgi mode requires a work around",
"if",
"(",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'REDIRECT_REMOTE_USER'",
"]",
")",
"&&",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'REDIRECT_REMOTE_USER'",
"]",
",",
"'Basic '",
")",
"===",
"0",
")",
"{",
"$",
"credentials",
"=",
"substr",
"(",
"$",
"_SERVER",
"[",
"'REDIRECT_REMOTE_USER'",
"]",
",",
"strlen",
"(",
"'Basic '",
")",
")",
";",
"$",
"credentials",
"=",
"base64_decode",
"(",
"$",
"credentials",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"credentials",
",",
"':'",
")",
")",
"{",
"$",
"credentials",
"=",
"explode",
"(",
"':'",
",",
"$",
"credentials",
")",
";",
"return",
"[",
"'USER'",
"=>",
"$",
"credentials",
"[",
"0",
"]",
",",
"'PW'",
"=>",
"$",
"credentials",
"[",
"1",
"]",
",",
"]",
";",
"}",
"}",
"return",
"null",
";",
"}"
]
| returns basic auth credentials
this works around php cgi mode not passing them directly
@note this requires a change in the htaccess as well
@see example-project/public_html/.htaccess
@return array|null with 'USER' and 'PW' keys | [
"returns",
"basic",
"auth",
"credentials",
"this",
"works",
"around",
"php",
"cgi",
"mode",
"not",
"passing",
"them",
"directly"
]
| train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/request.php#L162-L185 |
lode/fem | src/request.php | request.get_primary_mime_type | private static function get_primary_mime_type($type) {
if (strpos($type, ',')) {
$type = substr($type, 0, strpos($type, ','));
}
if (strpos($type, '/')) {
$type = substr($type, strpos($type, '/')+1);
}
if (strpos($type, ';')) {
$type = substr($type, 0, strpos($type, ';'));
}
if (strpos($type, '+')) {
$type = substr($type, strpos($type, '+')+1);
}
return $type;
} | php | private static function get_primary_mime_type($type) {
if (strpos($type, ',')) {
$type = substr($type, 0, strpos($type, ','));
}
if (strpos($type, '/')) {
$type = substr($type, strpos($type, '/')+1);
}
if (strpos($type, ';')) {
$type = substr($type, 0, strpos($type, ';'));
}
if (strpos($type, '+')) {
$type = substr($type, strpos($type, '+')+1);
}
return $type;
} | [
"private",
"static",
"function",
"get_primary_mime_type",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"type",
",",
"','",
")",
")",
"{",
"$",
"type",
"=",
"substr",
"(",
"$",
"type",
",",
"0",
",",
"strpos",
"(",
"$",
"type",
",",
"','",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"type",
",",
"'/'",
")",
")",
"{",
"$",
"type",
"=",
"substr",
"(",
"$",
"type",
",",
"strpos",
"(",
"$",
"type",
",",
"'/'",
")",
"+",
"1",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"type",
",",
"';'",
")",
")",
"{",
"$",
"type",
"=",
"substr",
"(",
"$",
"type",
",",
"0",
",",
"strpos",
"(",
"$",
"type",
",",
"';'",
")",
")",
";",
"}",
"if",
"(",
"strpos",
"(",
"$",
"type",
",",
"'+'",
")",
")",
"{",
"$",
"type",
"=",
"substr",
"(",
"$",
"type",
",",
"strpos",
"(",
"$",
"type",
",",
"'+'",
")",
"+",
"1",
")",
";",
"}",
"return",
"$",
"type",
";",
"}"
]
| gets a friendly version of a mime type
@param string $type
@return string the most interesting part of the mime type ..
.. only the first format, and only the most determinating part ..
i.e. 'text/html, ...' returns 'html'
i.e. 'application/json, ...' returns 'json' | [
"gets",
"a",
"friendly",
"version",
"of",
"a",
"mime",
"type"
]
| train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/request.php#L196-L211 |
lode/fem | src/request.php | request.get_fingerprint | public static function get_fingerprint() {
return [
'ip_address' => !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : false,
'user_agent' => !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : false,
'accept_content' => !empty($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : false,
'accept_charset' => !empty($_SERVER['HTTP_ACCEPT_CHARSET']) ? $_SERVER['HTTP_ACCEPT_CHARSET'] : false,
'accept_encoding' => !empty($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : false,
'accept_language' => !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : false,
];
} | php | public static function get_fingerprint() {
return [
'ip_address' => !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : false,
'user_agent' => !empty($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : false,
'accept_content' => !empty($_SERVER['HTTP_ACCEPT']) ? $_SERVER['HTTP_ACCEPT'] : false,
'accept_charset' => !empty($_SERVER['HTTP_ACCEPT_CHARSET']) ? $_SERVER['HTTP_ACCEPT_CHARSET'] : false,
'accept_encoding' => !empty($_SERVER['HTTP_ACCEPT_ENCODING']) ? $_SERVER['HTTP_ACCEPT_ENCODING'] : false,
'accept_language' => !empty($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : false,
];
} | [
"public",
"static",
"function",
"get_fingerprint",
"(",
")",
"{",
"return",
"[",
"'ip_address'",
"=>",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'REMOTE_ADDR'",
"]",
":",
"false",
",",
"'user_agent'",
"=>",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_USER_AGENT'",
"]",
":",
"false",
",",
"'accept_content'",
"=>",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT'",
"]",
":",
"false",
",",
"'accept_charset'",
"=>",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_CHARSET'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_CHARSET'",
"]",
":",
"false",
",",
"'accept_encoding'",
"=>",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_ENCODING'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_ENCODING'",
"]",
":",
"false",
",",
"'accept_language'",
"=>",
"!",
"empty",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_LANGUAGE'",
"]",
":",
"false",
",",
"]",
";",
"}"
]
| generates a fingerprint of the current request
it is based on: the users ip address, the user agent, and its accept properties
@return array | [
"generates",
"a",
"fingerprint",
"of",
"the",
"current",
"request",
"it",
"is",
"based",
"on",
":",
"the",
"users",
"ip",
"address",
"the",
"user",
"agent",
"and",
"its",
"accept",
"properties"
]
| train | https://github.com/lode/fem/blob/c1c466c1a904d99452b341c5ae7cbc3e22b106e1/src/request.php#L219-L228 |
JeanWolf/yii2-jrbac | src/RoleActionColumn.php | RoleActionColumn.initUserIndexButton | protected function initUserIndexButton()
{
if (!isset($this->buttons['userindex'])) {
$this->buttons['userindex'] = function ($url, $model, $key) {
return Html::a('<span class="glyphicon glyphicon-user"></span>', $url, array_merge([
'title' => \Yii::t('yii', '角色用户管理'),
'data-pjax' => '0',
], $this->buttonOptions));
};
}
} | php | protected function initUserIndexButton()
{
if (!isset($this->buttons['userindex'])) {
$this->buttons['userindex'] = function ($url, $model, $key) {
return Html::a('<span class="glyphicon glyphicon-user"></span>', $url, array_merge([
'title' => \Yii::t('yii', '角色用户管理'),
'data-pjax' => '0',
], $this->buttonOptions));
};
}
} | [
"protected",
"function",
"initUserIndexButton",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"buttons",
"[",
"'userindex'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"buttons",
"[",
"'userindex'",
"]",
"=",
"function",
"(",
"$",
"url",
",",
"$",
"model",
",",
"$",
"key",
")",
"{",
"return",
"Html",
"::",
"a",
"(",
"'<span class=\"glyphicon glyphicon-user\"></span>'",
",",
"$",
"url",
",",
"array_merge",
"(",
"[",
"'title'",
"=>",
"\\",
"Yii",
"::",
"t",
"(",
"'yii'",
",",
"'角色用户管理'),",
"",
"",
"'data-pjax'",
"=>",
"'0'",
",",
"]",
",",
"$",
"this",
"->",
"buttonOptions",
")",
")",
";",
"}",
";",
"}",
"}"
]
| Initializes the default button rendering callbacks. | [
"Initializes",
"the",
"default",
"button",
"rendering",
"callbacks",
"."
]
| train | https://github.com/JeanWolf/yii2-jrbac/blob/1e5c80038451bd5b385f83cb9344c3bd5edd85e0/src/RoleActionColumn.php#L28-L38 |
jfusion/org.jfusion.framework | src/Authentication/Cookies.php | Cookies.addCookie | function addCookie($cookie_name, $cookie_value = '', $cookie_expires_time = 0, $cookiepath = '', $cookiedomain = '', $cookie_secure = false, $cookie_httponly = false, $mask = false) {
if ($cookie_expires_time != 0) {
$cookie_expires_time = time() + intval($cookie_expires_time);
} else {
$cookie_expires_time = 0;
}
list ($url, $cookiedomain) = $this->getApiUrl($cookiedomain);
$cookie = new stdClass();
$cookie->name = $cookie_name;
$cookie->value = $cookie_value;
$cookie->expire = $cookie_expires_time;
$cookie->path = $cookiepath;
$cookie->domain = $cookiedomain;
$cookie->secure = $cookie_secure;
$cookie->httponly = $cookie_httponly;
if ($url) {
$this->cookies[$url][] = $cookie;
} else {
setcookie($cookie->name, $cookie->value, $cookie->expire, $cookie->path, $cookie->domain, $cookie->secure, $cookie->httponly);
}
$debug = array();
$debug[Text::_('COOKIE')][Text::_('JFUSION_CROSS_DOMAIN_URL')] = $url;
$debug[Text::_('COOKIE')][Text::_('COOKIE_DOMAIN')] = $cookiedomain;
$debug[Text::_('COOKIE')][Text::_('NAME')] = $cookie_name;
if ($mask) {
$debug[Text::_('COOKIE')][Text::_('VALUE')] = substr($cookie_value, 0, 6) . '********';
} else {
$debug[Text::_('COOKIE')][Text::_('VALUE')] = $cookie_value;
}
if (($cookie_expires_time) == 0) {
$cookie_expires_time = 'Session_cookie';
} else {
$cookie_expires_time = date('d-m-Y H:i:s', $cookie_expires_time);
}
$debug[Text::_('COOKIE')][Text::_('COOKIE_EXPIRES')] = $cookie_expires_time;
$debug[Text::_('COOKIE')][Text::_('COOKIE_PATH')] = $cookiepath;
$debug[Text::_('COOKIE')][Text::_('COOKIE_SECURE')] = $cookie_secure;
$debug[Text::_('COOKIE')][Text::_('COOKIE_HTTPONLY')] = $cookie_httponly;
return $debug;
} | php | function addCookie($cookie_name, $cookie_value = '', $cookie_expires_time = 0, $cookiepath = '', $cookiedomain = '', $cookie_secure = false, $cookie_httponly = false, $mask = false) {
if ($cookie_expires_time != 0) {
$cookie_expires_time = time() + intval($cookie_expires_time);
} else {
$cookie_expires_time = 0;
}
list ($url, $cookiedomain) = $this->getApiUrl($cookiedomain);
$cookie = new stdClass();
$cookie->name = $cookie_name;
$cookie->value = $cookie_value;
$cookie->expire = $cookie_expires_time;
$cookie->path = $cookiepath;
$cookie->domain = $cookiedomain;
$cookie->secure = $cookie_secure;
$cookie->httponly = $cookie_httponly;
if ($url) {
$this->cookies[$url][] = $cookie;
} else {
setcookie($cookie->name, $cookie->value, $cookie->expire, $cookie->path, $cookie->domain, $cookie->secure, $cookie->httponly);
}
$debug = array();
$debug[Text::_('COOKIE')][Text::_('JFUSION_CROSS_DOMAIN_URL')] = $url;
$debug[Text::_('COOKIE')][Text::_('COOKIE_DOMAIN')] = $cookiedomain;
$debug[Text::_('COOKIE')][Text::_('NAME')] = $cookie_name;
if ($mask) {
$debug[Text::_('COOKIE')][Text::_('VALUE')] = substr($cookie_value, 0, 6) . '********';
} else {
$debug[Text::_('COOKIE')][Text::_('VALUE')] = $cookie_value;
}
if (($cookie_expires_time) == 0) {
$cookie_expires_time = 'Session_cookie';
} else {
$cookie_expires_time = date('d-m-Y H:i:s', $cookie_expires_time);
}
$debug[Text::_('COOKIE')][Text::_('COOKIE_EXPIRES')] = $cookie_expires_time;
$debug[Text::_('COOKIE')][Text::_('COOKIE_PATH')] = $cookiepath;
$debug[Text::_('COOKIE')][Text::_('COOKIE_SECURE')] = $cookie_secure;
$debug[Text::_('COOKIE')][Text::_('COOKIE_HTTPONLY')] = $cookie_httponly;
return $debug;
} | [
"function",
"addCookie",
"(",
"$",
"cookie_name",
",",
"$",
"cookie_value",
"=",
"''",
",",
"$",
"cookie_expires_time",
"=",
"0",
",",
"$",
"cookiepath",
"=",
"''",
",",
"$",
"cookiedomain",
"=",
"''",
",",
"$",
"cookie_secure",
"=",
"false",
",",
"$",
"cookie_httponly",
"=",
"false",
",",
"$",
"mask",
"=",
"false",
")",
"{",
"if",
"(",
"$",
"cookie_expires_time",
"!=",
"0",
")",
"{",
"$",
"cookie_expires_time",
"=",
"time",
"(",
")",
"+",
"intval",
"(",
"$",
"cookie_expires_time",
")",
";",
"}",
"else",
"{",
"$",
"cookie_expires_time",
"=",
"0",
";",
"}",
"list",
"(",
"$",
"url",
",",
"$",
"cookiedomain",
")",
"=",
"$",
"this",
"->",
"getApiUrl",
"(",
"$",
"cookiedomain",
")",
";",
"$",
"cookie",
"=",
"new",
"stdClass",
"(",
")",
";",
"$",
"cookie",
"->",
"name",
"=",
"$",
"cookie_name",
";",
"$",
"cookie",
"->",
"value",
"=",
"$",
"cookie_value",
";",
"$",
"cookie",
"->",
"expire",
"=",
"$",
"cookie_expires_time",
";",
"$",
"cookie",
"->",
"path",
"=",
"$",
"cookiepath",
";",
"$",
"cookie",
"->",
"domain",
"=",
"$",
"cookiedomain",
";",
"$",
"cookie",
"->",
"secure",
"=",
"$",
"cookie_secure",
";",
"$",
"cookie",
"->",
"httponly",
"=",
"$",
"cookie_httponly",
";",
"if",
"(",
"$",
"url",
")",
"{",
"$",
"this",
"->",
"cookies",
"[",
"$",
"url",
"]",
"[",
"]",
"=",
"$",
"cookie",
";",
"}",
"else",
"{",
"setcookie",
"(",
"$",
"cookie",
"->",
"name",
",",
"$",
"cookie",
"->",
"value",
",",
"$",
"cookie",
"->",
"expire",
",",
"$",
"cookie",
"->",
"path",
",",
"$",
"cookie",
"->",
"domain",
",",
"$",
"cookie",
"->",
"secure",
",",
"$",
"cookie",
"->",
"httponly",
")",
";",
"}",
"$",
"debug",
"=",
"array",
"(",
")",
";",
"$",
"debug",
"[",
"Text",
"::",
"_",
"(",
"'COOKIE'",
")",
"]",
"[",
"Text",
"::",
"_",
"(",
"'JFUSION_CROSS_DOMAIN_URL'",
")",
"]",
"=",
"$",
"url",
";",
"$",
"debug",
"[",
"Text",
"::",
"_",
"(",
"'COOKIE'",
")",
"]",
"[",
"Text",
"::",
"_",
"(",
"'COOKIE_DOMAIN'",
")",
"]",
"=",
"$",
"cookiedomain",
";",
"$",
"debug",
"[",
"Text",
"::",
"_",
"(",
"'COOKIE'",
")",
"]",
"[",
"Text",
"::",
"_",
"(",
"'NAME'",
")",
"]",
"=",
"$",
"cookie_name",
";",
"if",
"(",
"$",
"mask",
")",
"{",
"$",
"debug",
"[",
"Text",
"::",
"_",
"(",
"'COOKIE'",
")",
"]",
"[",
"Text",
"::",
"_",
"(",
"'VALUE'",
")",
"]",
"=",
"substr",
"(",
"$",
"cookie_value",
",",
"0",
",",
"6",
")",
".",
"'********'",
";",
"}",
"else",
"{",
"$",
"debug",
"[",
"Text",
"::",
"_",
"(",
"'COOKIE'",
")",
"]",
"[",
"Text",
"::",
"_",
"(",
"'VALUE'",
")",
"]",
"=",
"$",
"cookie_value",
";",
"}",
"if",
"(",
"(",
"$",
"cookie_expires_time",
")",
"==",
"0",
")",
"{",
"$",
"cookie_expires_time",
"=",
"'Session_cookie'",
";",
"}",
"else",
"{",
"$",
"cookie_expires_time",
"=",
"date",
"(",
"'d-m-Y H:i:s'",
",",
"$",
"cookie_expires_time",
")",
";",
"}",
"$",
"debug",
"[",
"Text",
"::",
"_",
"(",
"'COOKIE'",
")",
"]",
"[",
"Text",
"::",
"_",
"(",
"'COOKIE_EXPIRES'",
")",
"]",
"=",
"$",
"cookie_expires_time",
";",
"$",
"debug",
"[",
"Text",
"::",
"_",
"(",
"'COOKIE'",
")",
"]",
"[",
"Text",
"::",
"_",
"(",
"'COOKIE_PATH'",
")",
"]",
"=",
"$",
"cookiepath",
";",
"$",
"debug",
"[",
"Text",
"::",
"_",
"(",
"'COOKIE'",
")",
"]",
"[",
"Text",
"::",
"_",
"(",
"'COOKIE_SECURE'",
")",
"]",
"=",
"$",
"cookie_secure",
";",
"$",
"debug",
"[",
"Text",
"::",
"_",
"(",
"'COOKIE'",
")",
"]",
"[",
"Text",
"::",
"_",
"(",
"'COOKIE_HTTPONLY'",
")",
"]",
"=",
"$",
"cookie_httponly",
";",
"return",
"$",
"debug",
";",
"}"
]
| addCookie
@param string $cookie_name
@param string $cookie_value
@param int $cookie_expires_time
@param string $cookiepath
@param string $cookiedomain
@param int $cookie_secure
@param int $cookie_httponly
@param boolean $mask
@return array Cookie debug info | [
"addCookie"
]
| train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Authentication/Cookies.php#L54-L96 |
jfusion/org.jfusion.framework | src/Authentication/Cookies.php | Cookies.executeRedirect | function executeRedirect($source_url = null, $return = null) {
if (!$this->secret) {
if(count($this->cookies)) {
if (empty($return)) {
$return = Application::getInstance()->input->getBase64('return', '');
if ($return) {
$return = base64_decode($return);
if( stripos($return, 'http://') === false && stripos($return, 'https://') === false ) {
$return = ltrim($return, '/');
$return = $source_url . $return;
}
}
}
$api = null;
$data = array();
foreach($this->cookies as $key => $cookies) {
$api = new Api($key, $this->secret);
if ($api->set('Cookie', 'Cookies', $cookies)) {
$data['url'][$api->url] = $api->sid;
}
}
if ($api) {
unset($data['url'][$api->url]);
$api->execute('cookie', 'cookies', $data, $return);
}
}
if (!empty($return)) {
Framework::redirect($return);
}
}
} | php | function executeRedirect($source_url = null, $return = null) {
if (!$this->secret) {
if(count($this->cookies)) {
if (empty($return)) {
$return = Application::getInstance()->input->getBase64('return', '');
if ($return) {
$return = base64_decode($return);
if( stripos($return, 'http://') === false && stripos($return, 'https://') === false ) {
$return = ltrim($return, '/');
$return = $source_url . $return;
}
}
}
$api = null;
$data = array();
foreach($this->cookies as $key => $cookies) {
$api = new Api($key, $this->secret);
if ($api->set('Cookie', 'Cookies', $cookies)) {
$data['url'][$api->url] = $api->sid;
}
}
if ($api) {
unset($data['url'][$api->url]);
$api->execute('cookie', 'cookies', $data, $return);
}
}
if (!empty($return)) {
Framework::redirect($return);
}
}
} | [
"function",
"executeRedirect",
"(",
"$",
"source_url",
"=",
"null",
",",
"$",
"return",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"secret",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"cookies",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"return",
")",
")",
"{",
"$",
"return",
"=",
"Application",
"::",
"getInstance",
"(",
")",
"->",
"input",
"->",
"getBase64",
"(",
"'return'",
",",
"''",
")",
";",
"if",
"(",
"$",
"return",
")",
"{",
"$",
"return",
"=",
"base64_decode",
"(",
"$",
"return",
")",
";",
"if",
"(",
"stripos",
"(",
"$",
"return",
",",
"'http://'",
")",
"===",
"false",
"&&",
"stripos",
"(",
"$",
"return",
",",
"'https://'",
")",
"===",
"false",
")",
"{",
"$",
"return",
"=",
"ltrim",
"(",
"$",
"return",
",",
"'/'",
")",
";",
"$",
"return",
"=",
"$",
"source_url",
".",
"$",
"return",
";",
"}",
"}",
"}",
"$",
"api",
"=",
"null",
";",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"cookies",
"as",
"$",
"key",
"=>",
"$",
"cookies",
")",
"{",
"$",
"api",
"=",
"new",
"Api",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"secret",
")",
";",
"if",
"(",
"$",
"api",
"->",
"set",
"(",
"'Cookie'",
",",
"'Cookies'",
",",
"$",
"cookies",
")",
")",
"{",
"$",
"data",
"[",
"'url'",
"]",
"[",
"$",
"api",
"->",
"url",
"]",
"=",
"$",
"api",
"->",
"sid",
";",
"}",
"}",
"if",
"(",
"$",
"api",
")",
"{",
"unset",
"(",
"$",
"data",
"[",
"'url'",
"]",
"[",
"$",
"api",
"->",
"url",
"]",
")",
";",
"$",
"api",
"->",
"execute",
"(",
"'cookie'",
",",
"'cookies'",
",",
"$",
"data",
",",
"$",
"return",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"return",
")",
")",
"{",
"Framework",
"::",
"redirect",
"(",
"$",
"return",
")",
";",
"}",
"}",
"}"
]
| Execute the cross domain login redirects
@param string $source_url
@param string $return | [
"Execute",
"the",
"cross",
"domain",
"login",
"redirects"
]
| train | https://github.com/jfusion/org.jfusion.framework/blob/65771963f23ccabcf1f867eb17c9452299cfe683/src/Authentication/Cookies.php#L104-L135 |
redaigbaria/oauth2 | src/Entity/AuthCodeEntity.php | AuthCodeEntity.generateRedirectUri | public function generateRedirectUri($state = null, $queryDelimeter = '?')
{
$uri = $this->getRedirectUri();
$uri .= (strstr($this->getRedirectUri(), $queryDelimeter) === false) ? $queryDelimeter : '&';
return $uri.http_build_query([
'code' => $this->getId(),
'state' => $state,
]);
} | php | public function generateRedirectUri($state = null, $queryDelimeter = '?')
{
$uri = $this->getRedirectUri();
$uri .= (strstr($this->getRedirectUri(), $queryDelimeter) === false) ? $queryDelimeter : '&';
return $uri.http_build_query([
'code' => $this->getId(),
'state' => $state,
]);
} | [
"public",
"function",
"generateRedirectUri",
"(",
"$",
"state",
"=",
"null",
",",
"$",
"queryDelimeter",
"=",
"'?'",
")",
"{",
"$",
"uri",
"=",
"$",
"this",
"->",
"getRedirectUri",
"(",
")",
";",
"$",
"uri",
".=",
"(",
"strstr",
"(",
"$",
"this",
"->",
"getRedirectUri",
"(",
")",
",",
"$",
"queryDelimeter",
")",
"===",
"false",
")",
"?",
"$",
"queryDelimeter",
":",
"'&'",
";",
"return",
"$",
"uri",
".",
"http_build_query",
"(",
"[",
"'code'",
"=>",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"'state'",
"=>",
"$",
"state",
",",
"]",
")",
";",
"}"
]
| Generate a redirect URI
@param string $state The state parameter if set by the client
@param string $queryDelimeter The query delimiter ('?' for auth code grant, '#' for implicit grant)
@return string | [
"Generate",
"a",
"redirect",
"URI"
]
| train | https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/Entity/AuthCodeEntity.php#L58-L67 |
redaigbaria/oauth2 | src/Entity/AuthCodeEntity.php | AuthCodeEntity.getSession | public function getSession()
{
if ($this->session instanceof SessionEntity) {
return $this->session;
}
$this->session = $this->server->getSessionStorage()->getByAuthCode($this);
return $this->session;
} | php | public function getSession()
{
if ($this->session instanceof SessionEntity) {
return $this->session;
}
$this->session = $this->server->getSessionStorage()->getByAuthCode($this);
return $this->session;
} | [
"public",
"function",
"getSession",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"session",
"instanceof",
"SessionEntity",
")",
"{",
"return",
"$",
"this",
"->",
"session",
";",
"}",
"$",
"this",
"->",
"session",
"=",
"$",
"this",
"->",
"server",
"->",
"getSessionStorage",
"(",
")",
"->",
"getByAuthCode",
"(",
"$",
"this",
")",
";",
"return",
"$",
"this",
"->",
"session",
";",
"}"
]
| Get session
@return \League\OAuth2\Server\Entity\SessionEntity | [
"Get",
"session"
]
| train | https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/Entity/AuthCodeEntity.php#L74-L83 |
redaigbaria/oauth2 | src/Entity/AuthCodeEntity.php | AuthCodeEntity.getScopes | public function getScopes()
{
if ($this->scopes === null) {
$this->scopes = $this->formatScopes(
$this->server->getAuthCodeStorage()->getScopes($this)
);
}
return $this->scopes;
} | php | public function getScopes()
{
if ($this->scopes === null) {
$this->scopes = $this->formatScopes(
$this->server->getAuthCodeStorage()->getScopes($this)
);
}
return $this->scopes;
} | [
"public",
"function",
"getScopes",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"scopes",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"scopes",
"=",
"$",
"this",
"->",
"formatScopes",
"(",
"$",
"this",
"->",
"server",
"->",
"getAuthCodeStorage",
"(",
")",
"->",
"getScopes",
"(",
"$",
"this",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"scopes",
";",
"}"
]
| Return all scopes associated with the session
@return \League\OAuth2\Server\Entity\ScopeEntity[] | [
"Return",
"all",
"scopes",
"associated",
"with",
"the",
"session"
]
| train | https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/Entity/AuthCodeEntity.php#L90-L99 |
redaigbaria/oauth2 | src/Entity/AuthCodeEntity.php | AuthCodeEntity.save | public function save()
{
$this->server->getAuthCodeStorage()->create(
$this->getId(),
$this->getExpireTime(),
$this->getSession()->getId(),
$this->getRedirectUri()
);
// Associate the scope with the token
foreach ($this->getScopes() as $scope) {
$this->server->getAuthCodeStorage()->associateScope($this, $scope);
}
return $this;
} | php | public function save()
{
$this->server->getAuthCodeStorage()->create(
$this->getId(),
$this->getExpireTime(),
$this->getSession()->getId(),
$this->getRedirectUri()
);
// Associate the scope with the token
foreach ($this->getScopes() as $scope) {
$this->server->getAuthCodeStorage()->associateScope($this, $scope);
}
return $this;
} | [
"public",
"function",
"save",
"(",
")",
"{",
"$",
"this",
"->",
"server",
"->",
"getAuthCodeStorage",
"(",
")",
"->",
"create",
"(",
"$",
"this",
"->",
"getId",
"(",
")",
",",
"$",
"this",
"->",
"getExpireTime",
"(",
")",
",",
"$",
"this",
"->",
"getSession",
"(",
")",
"->",
"getId",
"(",
")",
",",
"$",
"this",
"->",
"getRedirectUri",
"(",
")",
")",
";",
"// Associate the scope with the token",
"foreach",
"(",
"$",
"this",
"->",
"getScopes",
"(",
")",
"as",
"$",
"scope",
")",
"{",
"$",
"this",
"->",
"server",
"->",
"getAuthCodeStorage",
"(",
")",
"->",
"associateScope",
"(",
"$",
"this",
",",
"$",
"scope",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/redaigbaria/oauth2/blob/54cca4aaaff6a095cbf1c8010f2fe2cc7de4e45a/src/Entity/AuthCodeEntity.php#L104-L119 |
shrink0r/workflux | src/Transition/TransitionSet.php | TransitionSet.add | public function add(TransitionInterface $transition): self
{
$transitions = $this->internal_set->toArray();
$transitions[] = $transition;
return new static($transitions);
} | php | public function add(TransitionInterface $transition): self
{
$transitions = $this->internal_set->toArray();
$transitions[] = $transition;
return new static($transitions);
} | [
"public",
"function",
"add",
"(",
"TransitionInterface",
"$",
"transition",
")",
":",
"self",
"{",
"$",
"transitions",
"=",
"$",
"this",
"->",
"internal_set",
"->",
"toArray",
"(",
")",
";",
"$",
"transitions",
"[",
"]",
"=",
"$",
"transition",
";",
"return",
"new",
"static",
"(",
"$",
"transitions",
")",
";",
"}"
]
| @param TransitionInterface $transition
@return self | [
"@param",
"TransitionInterface",
"$transition"
]
| train | https://github.com/shrink0r/workflux/blob/008f45c64f52b1f795ab7f6ddbfc1a55580254d9/src/Transition/TransitionSet.php#L35-L41 |
shrink0r/workflux | src/Transition/TransitionSet.php | TransitionSet.contains | public function contains(TransitionInterface $transition): bool
{
foreach ($this->internal_set as $cur_transition) {
if ($cur_transition->getFrom() === $transition->getFrom()
&& $cur_transition->getTo() === $transition->getTo()
) {
return true;
}
}
return false;
} | php | public function contains(TransitionInterface $transition): bool
{
foreach ($this->internal_set as $cur_transition) {
if ($cur_transition->getFrom() === $transition->getFrom()
&& $cur_transition->getTo() === $transition->getTo()
) {
return true;
}
}
return false;
} | [
"public",
"function",
"contains",
"(",
"TransitionInterface",
"$",
"transition",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"internal_set",
"as",
"$",
"cur_transition",
")",
"{",
"if",
"(",
"$",
"cur_transition",
"->",
"getFrom",
"(",
")",
"===",
"$",
"transition",
"->",
"getFrom",
"(",
")",
"&&",
"$",
"cur_transition",
"->",
"getTo",
"(",
")",
"===",
"$",
"transition",
"->",
"getTo",
"(",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
]
| @param TransitionInterface $transition
@return bool | [
"@param",
"TransitionInterface",
"$transition"
]
| train | https://github.com/shrink0r/workflux/blob/008f45c64f52b1f795ab7f6ddbfc1a55580254d9/src/Transition/TransitionSet.php#L48-L58 |
shrink0r/workflux | src/Transition/TransitionSet.php | TransitionSet.filter | public function filter(callable $callback): self
{
$set = clone $this;
$set->internal_set = $this->internal_set->filter($callback);
return $set;
} | php | public function filter(callable $callback): self
{
$set = clone $this;
$set->internal_set = $this->internal_set->filter($callback);
return $set;
} | [
"public",
"function",
"filter",
"(",
"callable",
"$",
"callback",
")",
":",
"self",
"{",
"$",
"set",
"=",
"clone",
"$",
"this",
";",
"$",
"set",
"->",
"internal_set",
"=",
"$",
"this",
"->",
"internal_set",
"->",
"filter",
"(",
"$",
"callback",
")",
";",
"return",
"$",
"set",
";",
"}"
]
| @param callable $callback
@return self | [
"@param",
"callable",
"$callback"
]
| train | https://github.com/shrink0r/workflux/blob/008f45c64f52b1f795ab7f6ddbfc1a55580254d9/src/Transition/TransitionSet.php#L65-L71 |
vi-kon/laravel-auth | src/ViKon/Auth/AuthServiceProvider.php | AuthServiceProvider.boot | public function boot()
{
$this->publishes([__DIR__ . '/../../config/config.php' => config_path('vi-kon/auth.php')], 'config');
$this->publishes([__DIR__ . '/../../database/migrations/' => base_path('database/migrations')], 'migrations');
$this->app->make('router')->middleware('auth.has-access', HasAccessMiddleware::class);
$this->app->make('router')->middleware('auth.login-redirector', LoginRedirectorMiddleware::class);
$this->app->make('router')->middleware('auth.permission', PermissionMiddleware::class);
$this->app->make('auth')->extend('vi-kon.session', function (Container $app, $name, array $config) {
$provider = $app->make('auth')->createUserProvider($config['provider']);
return new Guard($name, $provider, $app->make('session.store'), $app->make('request'));
});
$this->app->bind(Keeper::class, function (Container $app) {
$guard = $app->make('auth')->guard();
if (!$guard instanceof Keeper) {
throw new InvalidKeeperGuardException();
}
return $guard;
});
} | php | public function boot()
{
$this->publishes([__DIR__ . '/../../config/config.php' => config_path('vi-kon/auth.php')], 'config');
$this->publishes([__DIR__ . '/../../database/migrations/' => base_path('database/migrations')], 'migrations');
$this->app->make('router')->middleware('auth.has-access', HasAccessMiddleware::class);
$this->app->make('router')->middleware('auth.login-redirector', LoginRedirectorMiddleware::class);
$this->app->make('router')->middleware('auth.permission', PermissionMiddleware::class);
$this->app->make('auth')->extend('vi-kon.session', function (Container $app, $name, array $config) {
$provider = $app->make('auth')->createUserProvider($config['provider']);
return new Guard($name, $provider, $app->make('session.store'), $app->make('request'));
});
$this->app->bind(Keeper::class, function (Container $app) {
$guard = $app->make('auth')->guard();
if (!$guard instanceof Keeper) {
throw new InvalidKeeperGuardException();
}
return $guard;
});
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../../config/config.php'",
"=>",
"config_path",
"(",
"'vi-kon/auth.php'",
")",
"]",
",",
"'config'",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"__DIR__",
".",
"'/../../database/migrations/'",
"=>",
"base_path",
"(",
"'database/migrations'",
")",
"]",
",",
"'migrations'",
")",
";",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'router'",
")",
"->",
"middleware",
"(",
"'auth.has-access'",
",",
"HasAccessMiddleware",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'router'",
")",
"->",
"middleware",
"(",
"'auth.login-redirector'",
",",
"LoginRedirectorMiddleware",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'router'",
")",
"->",
"middleware",
"(",
"'auth.permission'",
",",
"PermissionMiddleware",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'auth'",
")",
"->",
"extend",
"(",
"'vi-kon.session'",
",",
"function",
"(",
"Container",
"$",
"app",
",",
"$",
"name",
",",
"array",
"$",
"config",
")",
"{",
"$",
"provider",
"=",
"$",
"app",
"->",
"make",
"(",
"'auth'",
")",
"->",
"createUserProvider",
"(",
"$",
"config",
"[",
"'provider'",
"]",
")",
";",
"return",
"new",
"Guard",
"(",
"$",
"name",
",",
"$",
"provider",
",",
"$",
"app",
"->",
"make",
"(",
"'session.store'",
")",
",",
"$",
"app",
"->",
"make",
"(",
"'request'",
")",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"bind",
"(",
"Keeper",
"::",
"class",
",",
"function",
"(",
"Container",
"$",
"app",
")",
"{",
"$",
"guard",
"=",
"$",
"app",
"->",
"make",
"(",
"'auth'",
")",
"->",
"guard",
"(",
")",
";",
"if",
"(",
"!",
"$",
"guard",
"instanceof",
"Keeper",
")",
"{",
"throw",
"new",
"InvalidKeeperGuardException",
"(",
")",
";",
"}",
"return",
"$",
"guard",
";",
"}",
")",
";",
"}"
]
| Bootstrap the application events.
@return void | [
"Bootstrap",
"the",
"application",
"events",
"."
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/AuthServiceProvider.php#L41-L65 |
vi-kon/laravel-auth | src/ViKon/Auth/AuthServiceProvider.php | AuthServiceProvider.register | public function register()
{
$this->app->singleton(RouterAuth::class, RouterAuth::class);
$this->app->singleton(Guard::class, function (Application $app) {
return $app->make('auth')->guard();
});
$this->mergeConfigFrom(__DIR__ . '/../../config/config.php', 'vi-kon.auth');
} | php | public function register()
{
$this->app->singleton(RouterAuth::class, RouterAuth::class);
$this->app->singleton(Guard::class, function (Application $app) {
return $app->make('auth')->guard();
});
$this->mergeConfigFrom(__DIR__ . '/../../config/config.php', 'vi-kon.auth');
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"RouterAuth",
"::",
"class",
",",
"RouterAuth",
"::",
"class",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"Guard",
"::",
"class",
",",
"function",
"(",
"Application",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"->",
"make",
"(",
"'auth'",
")",
"->",
"guard",
"(",
")",
";",
"}",
")",
";",
"$",
"this",
"->",
"mergeConfigFrom",
"(",
"__DIR__",
".",
"'/../../config/config.php'",
",",
"'vi-kon.auth'",
")",
";",
"}"
]
| {@inheritDoc} | [
"{"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/AuthServiceProvider.php#L81-L89 |
meccado/acl-admin-control-panel | src/Http/Controllers/Auth/AuthController.php | AuthController.create | protected function create(array $data)
{
//Ceate User
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
//create Blank profile
$profile = Profile::create([
'user_id' => $user->id,
'bio' => '',
]);
$profile->save();
//Assign User Role
$user->assign('user');
return $user;
} | php | protected function create(array $data)
{
//Ceate User
$user = User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
//create Blank profile
$profile = Profile::create([
'user_id' => $user->id,
'bio' => '',
]);
$profile->save();
//Assign User Role
$user->assign('user');
return $user;
} | [
"protected",
"function",
"create",
"(",
"array",
"$",
"data",
")",
"{",
"//Ceate User",
"$",
"user",
"=",
"User",
"::",
"create",
"(",
"[",
"'name'",
"=>",
"$",
"data",
"[",
"'name'",
"]",
",",
"'email'",
"=>",
"$",
"data",
"[",
"'email'",
"]",
",",
"'password'",
"=>",
"bcrypt",
"(",
"$",
"data",
"[",
"'password'",
"]",
")",
",",
"]",
")",
";",
"//create Blank profile",
"$",
"profile",
"=",
"Profile",
"::",
"create",
"(",
"[",
"'user_id'",
"=>",
"$",
"user",
"->",
"id",
",",
"'bio'",
"=>",
"''",
",",
"]",
")",
";",
"$",
"profile",
"->",
"save",
"(",
")",
";",
"//Assign User Role",
"$",
"user",
"->",
"assign",
"(",
"'user'",
")",
";",
"return",
"$",
"user",
";",
"}"
]
| Create a new user instance after a valid registration.
@param array $data
@return User | [
"Create",
"a",
"new",
"user",
"instance",
"after",
"a",
"valid",
"registration",
"."
]
| train | https://github.com/meccado/acl-admin-control-panel/blob/50ac4c0dbf8bd49944ecad6a70708a70411b7378/src/Http/Controllers/Auth/AuthController.php#L65-L84 |
chubbyphp/chubbyphp-api-http | src/Serialization/ApiProblem/ClientError/RequestUriTooLongMapping.php | RequestUriTooLongMapping.getNormalizationFieldMappings | public function getNormalizationFieldMappings(string $path): array
{
$fieldMappings = parent::getNormalizationFieldMappings($path);
$fieldMappings[] = NormalizationFieldMappingBuilder::create('maxUriLength')->getMapping();
return $fieldMappings;
} | php | public function getNormalizationFieldMappings(string $path): array
{
$fieldMappings = parent::getNormalizationFieldMappings($path);
$fieldMappings[] = NormalizationFieldMappingBuilder::create('maxUriLength')->getMapping();
return $fieldMappings;
} | [
"public",
"function",
"getNormalizationFieldMappings",
"(",
"string",
"$",
"path",
")",
":",
"array",
"{",
"$",
"fieldMappings",
"=",
"parent",
"::",
"getNormalizationFieldMappings",
"(",
"$",
"path",
")",
";",
"$",
"fieldMappings",
"[",
"]",
"=",
"NormalizationFieldMappingBuilder",
"::",
"create",
"(",
"'maxUriLength'",
")",
"->",
"getMapping",
"(",
")",
";",
"return",
"$",
"fieldMappings",
";",
"}"
]
| @param string $path
@return NormalizationFieldMappingInterface[] | [
"@param",
"string",
"$path"
]
| train | https://github.com/chubbyphp/chubbyphp-api-http/blob/675d657b686e96aa16be56d0e9e07aaa844266ed/src/Serialization/ApiProblem/ClientError/RequestUriTooLongMapping.php#L27-L34 |
anime-db/app-bundle | src/Util/Filesystem.php | Filesystem.scandir | public static function scandir($path, $filter = 0, $order = SCANDIR_SORT_ASCENDING)
{
if (!$filter || (
($filter & self::FILE) != self::FILE &&
($filter & self::DIRECTORY) != self::DIRECTORY
)) {
$filter = self::FILE | self::DIRECTORY;
}
// add slash if need
$path = self::getRealPath($path);
// wrap path for current fs
$wrap = Utf8::wrapPath($path);
// scan directory
$folders = [];
foreach (new \DirectoryIterator($wrap) as $file) {
/* @var $file \SplFileInfo */
try {
if (
$file->getFilename()[0] != '.' &&
substr($file->getFilename(), -1) != '~' &&
$file->getFilename() != 'pagefile.sys' && // failed read C:\pagefile.sys
$file->isReadable() &&
(
(($filter & self::FILE) == self::FILE && $file->isFile()) ||
(($filter & self::DIRECTORY) == self::DIRECTORY && $file->isDir())
)
) {
$folders[$file->getFilename()] = [
'name' => $file->getFilename(),
'path' => $path.$file->getFilename().DIRECTORY_SEPARATOR,
];
}
} catch (\Exception $e) {
// ignore all errors
}
}
// order files
if ($order == SCANDIR_SORT_ASCENDING) {
ksort($folders);
} elseif ($order == SCANDIR_SORT_DESCENDING) {
ksort($folders);
$folders = array_reverse($folders);
}
// add link on parent folder
if (substr_count($path, DIRECTORY_SEPARATOR) > 1) {
$pos = strrpos(substr($path, 0, -1), DIRECTORY_SEPARATOR) + 1;
array_unshift($folders, [
'name' => '..',
'path' => substr($path, 0, $pos),
]);
}
return array_values($folders);
} | php | public static function scandir($path, $filter = 0, $order = SCANDIR_SORT_ASCENDING)
{
if (!$filter || (
($filter & self::FILE) != self::FILE &&
($filter & self::DIRECTORY) != self::DIRECTORY
)) {
$filter = self::FILE | self::DIRECTORY;
}
// add slash if need
$path = self::getRealPath($path);
// wrap path for current fs
$wrap = Utf8::wrapPath($path);
// scan directory
$folders = [];
foreach (new \DirectoryIterator($wrap) as $file) {
/* @var $file \SplFileInfo */
try {
if (
$file->getFilename()[0] != '.' &&
substr($file->getFilename(), -1) != '~' &&
$file->getFilename() != 'pagefile.sys' && // failed read C:\pagefile.sys
$file->isReadable() &&
(
(($filter & self::FILE) == self::FILE && $file->isFile()) ||
(($filter & self::DIRECTORY) == self::DIRECTORY && $file->isDir())
)
) {
$folders[$file->getFilename()] = [
'name' => $file->getFilename(),
'path' => $path.$file->getFilename().DIRECTORY_SEPARATOR,
];
}
} catch (\Exception $e) {
// ignore all errors
}
}
// order files
if ($order == SCANDIR_SORT_ASCENDING) {
ksort($folders);
} elseif ($order == SCANDIR_SORT_DESCENDING) {
ksort($folders);
$folders = array_reverse($folders);
}
// add link on parent folder
if (substr_count($path, DIRECTORY_SEPARATOR) > 1) {
$pos = strrpos(substr($path, 0, -1), DIRECTORY_SEPARATOR) + 1;
array_unshift($folders, [
'name' => '..',
'path' => substr($path, 0, $pos),
]);
}
return array_values($folders);
} | [
"public",
"static",
"function",
"scandir",
"(",
"$",
"path",
",",
"$",
"filter",
"=",
"0",
",",
"$",
"order",
"=",
"SCANDIR_SORT_ASCENDING",
")",
"{",
"if",
"(",
"!",
"$",
"filter",
"||",
"(",
"(",
"$",
"filter",
"&",
"self",
"::",
"FILE",
")",
"!=",
"self",
"::",
"FILE",
"&&",
"(",
"$",
"filter",
"&",
"self",
"::",
"DIRECTORY",
")",
"!=",
"self",
"::",
"DIRECTORY",
")",
")",
"{",
"$",
"filter",
"=",
"self",
"::",
"FILE",
"|",
"self",
"::",
"DIRECTORY",
";",
"}",
"// add slash if need",
"$",
"path",
"=",
"self",
"::",
"getRealPath",
"(",
"$",
"path",
")",
";",
"// wrap path for current fs",
"$",
"wrap",
"=",
"Utf8",
"::",
"wrapPath",
"(",
"$",
"path",
")",
";",
"// scan directory",
"$",
"folders",
"=",
"[",
"]",
";",
"foreach",
"(",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"wrap",
")",
"as",
"$",
"file",
")",
"{",
"/* @var $file \\SplFileInfo */",
"try",
"{",
"if",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
"[",
"0",
"]",
"!=",
"'.'",
"&&",
"substr",
"(",
"$",
"file",
"->",
"getFilename",
"(",
")",
",",
"-",
"1",
")",
"!=",
"'~'",
"&&",
"$",
"file",
"->",
"getFilename",
"(",
")",
"!=",
"'pagefile.sys'",
"&&",
"// failed read C:\\pagefile.sys",
"$",
"file",
"->",
"isReadable",
"(",
")",
"&&",
"(",
"(",
"(",
"$",
"filter",
"&",
"self",
"::",
"FILE",
")",
"==",
"self",
"::",
"FILE",
"&&",
"$",
"file",
"->",
"isFile",
"(",
")",
")",
"||",
"(",
"(",
"$",
"filter",
"&",
"self",
"::",
"DIRECTORY",
")",
"==",
"self",
"::",
"DIRECTORY",
"&&",
"$",
"file",
"->",
"isDir",
"(",
")",
")",
")",
")",
"{",
"$",
"folders",
"[",
"$",
"file",
"->",
"getFilename",
"(",
")",
"]",
"=",
"[",
"'name'",
"=>",
"$",
"file",
"->",
"getFilename",
"(",
")",
",",
"'path'",
"=>",
"$",
"path",
".",
"$",
"file",
"->",
"getFilename",
"(",
")",
".",
"DIRECTORY_SEPARATOR",
",",
"]",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// ignore all errors",
"}",
"}",
"// order files",
"if",
"(",
"$",
"order",
"==",
"SCANDIR_SORT_ASCENDING",
")",
"{",
"ksort",
"(",
"$",
"folders",
")",
";",
"}",
"elseif",
"(",
"$",
"order",
"==",
"SCANDIR_SORT_DESCENDING",
")",
"{",
"ksort",
"(",
"$",
"folders",
")",
";",
"$",
"folders",
"=",
"array_reverse",
"(",
"$",
"folders",
")",
";",
"}",
"// add link on parent folder",
"if",
"(",
"substr_count",
"(",
"$",
"path",
",",
"DIRECTORY_SEPARATOR",
")",
">",
"1",
")",
"{",
"$",
"pos",
"=",
"strrpos",
"(",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"-",
"1",
")",
",",
"DIRECTORY_SEPARATOR",
")",
"+",
"1",
";",
"array_unshift",
"(",
"$",
"folders",
",",
"[",
"'name'",
"=>",
"'..'",
",",
"'path'",
"=>",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"$",
"pos",
")",
",",
"]",
")",
";",
"}",
"return",
"array_values",
"(",
"$",
"folders",
")",
";",
"}"
]
| List files and directories inside the specified path.
@param string $path
@param int $filter
@param int $order
@return array | [
"List",
"files",
"and",
"directories",
"inside",
"the",
"specified",
"path",
"."
]
| train | https://github.com/anime-db/app-bundle/blob/ca3b342081719d41ba018792a75970cbb1f1fe22/src/Util/Filesystem.php#L93-L149 |
anime-db/app-bundle | src/Util/Filesystem.php | Filesystem.getRealPath | public static function getRealPath($path)
{
$path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path);
return rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
} | php | public static function getRealPath($path)
{
$path = str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path);
return rtrim($path, DIRECTORY_SEPARATOR).DIRECTORY_SEPARATOR;
} | [
"public",
"static",
"function",
"getRealPath",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"str_replace",
"(",
"[",
"'\\\\'",
",",
"'/'",
"]",
",",
"DIRECTORY_SEPARATOR",
",",
"$",
"path",
")",
";",
"return",
"rtrim",
"(",
"$",
"path",
",",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"}"
]
| @param string $path
@return string | [
"@param",
"string",
"$path"
]
| train | https://github.com/anime-db/app-bundle/blob/ca3b342081719d41ba018792a75970cbb1f1fe22/src/Util/Filesystem.php#L156-L161 |
aryelgois/yasql-php | src/Populator.php | Populator.load | public function load(string $file)
{
$this->data = Yaml::parse(file_get_contents($file));
$this->filename = basename($file);
} | php | public function load(string $file)
{
$this->data = Yaml::parse(file_get_contents($file));
$this->filename = basename($file);
} | [
"public",
"function",
"load",
"(",
"string",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"data",
"=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
")",
";",
"$",
"this",
"->",
"filename",
"=",
"basename",
"(",
"$",
"file",
")",
";",
"}"
]
| Loads a YAML file to be processed
@param string $file Path to YAML source file | [
"Loads",
"a",
"YAML",
"file",
"to",
"be",
"processed"
]
| train | https://github.com/aryelgois/yasql-php/blob/f428b180d35bfc1ddf1f9b3323f9b085fbc09ac7/src/Populator.php#L57-L61 |
silvercommerce/catalogue-frontend | src/extensions/ControllerExtension.php | ControllerExtension.CatalogueMenu | public function CatalogueMenu($ParentID = 0)
{
return $this
->owner
->CatalogueCategories()
->filterByCallback(function($item, $list) {
return $item->canView();
});
} | php | public function CatalogueMenu($ParentID = 0)
{
return $this
->owner
->CatalogueCategories()
->filterByCallback(function($item, $list) {
return $item->canView();
});
} | [
"public",
"function",
"CatalogueMenu",
"(",
"$",
"ParentID",
"=",
"0",
")",
"{",
"return",
"$",
"this",
"->",
"owner",
"->",
"CatalogueCategories",
"(",
")",
"->",
"filterByCallback",
"(",
"function",
"(",
"$",
"item",
",",
"$",
"list",
")",
"{",
"return",
"$",
"item",
"->",
"canView",
"(",
")",
";",
"}",
")",
";",
"}"
]
| Generate a list of categories that can be used in menus
(this means that) categories are checked for their
can view state before being returned
@param Parent the ID of a parent cetegory
@return SS_List | [
"Generate",
"a",
"list",
"of",
"categories",
"that",
"can",
"be",
"used",
"in",
"menus",
"(",
"this",
"means",
"that",
")",
"categories",
"are",
"checked",
"for",
"their",
"can",
"view",
"state",
"before",
"being",
"returned"
]
| train | https://github.com/silvercommerce/catalogue-frontend/blob/671f1e32bf6bc6eb193c6608ae904cd055540cc4/src/extensions/ControllerExtension.php#L44-L52 |
ruvents/ruwork-upload-bundle | Validator/AssertUploadValidator.php | AssertUploadValidator.validate | public function validate($value, Constraint $constraint): void
{
if (!$constraint instanceof AssertUpload) {
throw new UnexpectedTypeException($constraint, AssertUpload::class);
}
if (null === $value) {
return;
}
if (!\is_object($value)) {
throw new UnexpectedTypeException($value, 'object');
}
$file = null;
try {
$file = $this->manager->getResolvedSource($value)->getTmpPath();
} catch (NotRegisteredException $exception) {
try {
$file = $this->manager->locate($value);
} catch (EmptyPathException $exception) {
}
}
$this->context
->getValidator()
->inContext($this->context)
->atPath(UploadType::FILE)
->validate($file, $constraint->constraints);
} | php | public function validate($value, Constraint $constraint): void
{
if (!$constraint instanceof AssertUpload) {
throw new UnexpectedTypeException($constraint, AssertUpload::class);
}
if (null === $value) {
return;
}
if (!\is_object($value)) {
throw new UnexpectedTypeException($value, 'object');
}
$file = null;
try {
$file = $this->manager->getResolvedSource($value)->getTmpPath();
} catch (NotRegisteredException $exception) {
try {
$file = $this->manager->locate($value);
} catch (EmptyPathException $exception) {
}
}
$this->context
->getValidator()
->inContext($this->context)
->atPath(UploadType::FILE)
->validate($file, $constraint->constraints);
} | [
"public",
"function",
"validate",
"(",
"$",
"value",
",",
"Constraint",
"$",
"constraint",
")",
":",
"void",
"{",
"if",
"(",
"!",
"$",
"constraint",
"instanceof",
"AssertUpload",
")",
"{",
"throw",
"new",
"UnexpectedTypeException",
"(",
"$",
"constraint",
",",
"AssertUpload",
"::",
"class",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"\\",
"is_object",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"UnexpectedTypeException",
"(",
"$",
"value",
",",
"'object'",
")",
";",
"}",
"$",
"file",
"=",
"null",
";",
"try",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"manager",
"->",
"getResolvedSource",
"(",
"$",
"value",
")",
"->",
"getTmpPath",
"(",
")",
";",
"}",
"catch",
"(",
"NotRegisteredException",
"$",
"exception",
")",
"{",
"try",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"manager",
"->",
"locate",
"(",
"$",
"value",
")",
";",
"}",
"catch",
"(",
"EmptyPathException",
"$",
"exception",
")",
"{",
"}",
"}",
"$",
"this",
"->",
"context",
"->",
"getValidator",
"(",
")",
"->",
"inContext",
"(",
"$",
"this",
"->",
"context",
")",
"->",
"atPath",
"(",
"UploadType",
"::",
"FILE",
")",
"->",
"validate",
"(",
"$",
"file",
",",
"$",
"constraint",
"->",
"constraints",
")",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/ruvents/ruwork-upload-bundle/blob/8ad09cc2dce6ab389105c440d791346696da43af/Validator/AssertUploadValidator.php#L27-L57 |
left-right/center | src/libraries/Trail.php | Trail.manage | public static function manage() {
$back = (Session::has('back')) ? Session::get('back') : [];
if (URL::current() == end($back)) {
//going back down the stack
array_pop($back);
} elseif (URL::previous() != end($back)) {
//going up the stack
$back[] = URL::previous();
}
//persist
if (count($back)) {
Session::set('back', $back);
} elseif (Session::has('back')) {
Session::forget('back');
}
} | php | public static function manage() {
$back = (Session::has('back')) ? Session::get('back') : [];
if (URL::current() == end($back)) {
//going back down the stack
array_pop($back);
} elseif (URL::previous() != end($back)) {
//going up the stack
$back[] = URL::previous();
}
//persist
if (count($back)) {
Session::set('back', $back);
} elseif (Session::has('back')) {
Session::forget('back');
}
} | [
"public",
"static",
"function",
"manage",
"(",
")",
"{",
"$",
"back",
"=",
"(",
"Session",
"::",
"has",
"(",
"'back'",
")",
")",
"?",
"Session",
"::",
"get",
"(",
"'back'",
")",
":",
"[",
"]",
";",
"if",
"(",
"URL",
"::",
"current",
"(",
")",
"==",
"end",
"(",
"$",
"back",
")",
")",
"{",
"//going back down the stack",
"array_pop",
"(",
"$",
"back",
")",
";",
"}",
"elseif",
"(",
"URL",
"::",
"previous",
"(",
")",
"!=",
"end",
"(",
"$",
"back",
")",
")",
"{",
"//going up the stack",
"$",
"back",
"[",
"]",
"=",
"URL",
"::",
"previous",
"(",
")",
";",
"}",
"//persist",
"if",
"(",
"count",
"(",
"$",
"back",
")",
")",
"{",
"Session",
"::",
"set",
"(",
"'back'",
",",
"$",
"back",
")",
";",
"}",
"elseif",
"(",
"Session",
"::",
"has",
"(",
"'back'",
")",
")",
"{",
"Session",
"::",
"forget",
"(",
"'back'",
")",
";",
"}",
"}"
]
| manage the return stack | [
"manage",
"the",
"return",
"stack"
]
| train | https://github.com/left-right/center/blob/47c225538475ca3e87fa49f31a323b6e6bd4eff2/src/libraries/Trail.php#L9-L28 |
ppetermann/king23 | src/Settings/SettingsChain.php | SettingsChain.get | public function get($key, $default = null)
{
/** @var SettingsInterface[] $providers */
$providers = array_reverse($this->settingsProviders);
foreach ($providers as $provider) {
if (!is_null($setting = $provider->get($key, null))) {
return $setting;
}
}
return $default;
} | php | public function get($key, $default = null)
{
/** @var SettingsInterface[] $providers */
$providers = array_reverse($this->settingsProviders);
foreach ($providers as $provider) {
if (!is_null($setting = $provider->get($key, null))) {
return $setting;
}
}
return $default;
} | [
"public",
"function",
"get",
"(",
"$",
"key",
",",
"$",
"default",
"=",
"null",
")",
"{",
"/** @var SettingsInterface[] $providers */",
"$",
"providers",
"=",
"array_reverse",
"(",
"$",
"this",
"->",
"settingsProviders",
")",
";",
"foreach",
"(",
"$",
"providers",
"as",
"$",
"provider",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"setting",
"=",
"$",
"provider",
"->",
"get",
"(",
"$",
"key",
",",
"null",
")",
")",
")",
"{",
"return",
"$",
"setting",
";",
"}",
"}",
"return",
"$",
"default",
";",
"}"
]
| retrieve a settings value, will return $default if none is found
@param string $key
@param null|mixed $default
@return mixed | [
"retrieve",
"a",
"settings",
"value",
"will",
"return",
"$default",
"if",
"none",
"is",
"found"
]
| train | https://github.com/ppetermann/king23/blob/603896083ec89f5ac4d744abd3b1b4db3e914c95/src/Settings/SettingsChain.php#L57-L67 |
joomlatools/joomlatools-platform-legacy | code/response/response.php | JResponse.setHeader | public static function setHeader($name, $value, $replace = false)
{
JFactory::getApplication()->setHeader($name, $value, $replace);
} | php | public static function setHeader($name, $value, $replace = false)
{
JFactory::getApplication()->setHeader($name, $value, $replace);
} | [
"public",
"static",
"function",
"setHeader",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"replace",
"=",
"false",
")",
"{",
"JFactory",
"::",
"getApplication",
"(",
")",
"->",
"setHeader",
"(",
"$",
"name",
",",
"$",
"value",
",",
"$",
"replace",
")",
";",
"}"
]
| Set a header.
If $replace is true, replaces any headers already defined with that $name.
@param string $name The name of the header to set.
@param string $value The value of the header to set.
@param boolean $replace True to replace any existing headers by name.
@return void
@since 11.1
@deprecated 4.0 Use JApplicationWeb::setHeader() instead | [
"Set",
"a",
"header",
"."
]
| train | https://github.com/joomlatools/joomlatools-platform-legacy/blob/3a76944e2f2c415faa6504754c75321a3b478c06/code/response/response.php#L77-L80 |
joomlatools/joomlatools-platform-legacy | code/response/response.php | JResponse.compress | protected static function compress($data)
{
$encoding = self::clientEncoding();
if (!$encoding)
{
return $data;
}
if (!extension_loaded('zlib') || ini_get('zlib.output_compression'))
{
return $data;
}
if (headers_sent())
{
return $data;
}
if (connection_status() !== 0)
{
return $data;
}
// Ideal level
$level = 4;
/*
$size = strlen($data);
$crc = crc32($data);
$gzdata = "\x1f\x8b\x08\x00\x00\x00\x00\x00";
$gzdata .= gzcompress($data, $level);
$gzdata = substr($gzdata, 0, strlen($gzdata) - 4);
$gzdata .= pack("V",$crc) . pack("V", $size);
*/
$gzdata = gzencode($data, $level);
self::setHeader('Content-Encoding', $encoding);
// Header will be removed at 4.0
if (JFactory::getConfig()->get('MetaVersion', 0) && defined('JVERSION'))
{
self::setHeader('X-Content-Encoded-By', 'Joomla! ' . JVERSION);
}
return $gzdata;
} | php | protected static function compress($data)
{
$encoding = self::clientEncoding();
if (!$encoding)
{
return $data;
}
if (!extension_loaded('zlib') || ini_get('zlib.output_compression'))
{
return $data;
}
if (headers_sent())
{
return $data;
}
if (connection_status() !== 0)
{
return $data;
}
// Ideal level
$level = 4;
/*
$size = strlen($data);
$crc = crc32($data);
$gzdata = "\x1f\x8b\x08\x00\x00\x00\x00\x00";
$gzdata .= gzcompress($data, $level);
$gzdata = substr($gzdata, 0, strlen($gzdata) - 4);
$gzdata .= pack("V",$crc) . pack("V", $size);
*/
$gzdata = gzencode($data, $level);
self::setHeader('Content-Encoding', $encoding);
// Header will be removed at 4.0
if (JFactory::getConfig()->get('MetaVersion', 0) && defined('JVERSION'))
{
self::setHeader('X-Content-Encoded-By', 'Joomla! ' . JVERSION);
}
return $gzdata;
} | [
"protected",
"static",
"function",
"compress",
"(",
"$",
"data",
")",
"{",
"$",
"encoding",
"=",
"self",
"::",
"clientEncoding",
"(",
")",
";",
"if",
"(",
"!",
"$",
"encoding",
")",
"{",
"return",
"$",
"data",
";",
"}",
"if",
"(",
"!",
"extension_loaded",
"(",
"'zlib'",
")",
"||",
"ini_get",
"(",
"'zlib.output_compression'",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"if",
"(",
"headers_sent",
"(",
")",
")",
"{",
"return",
"$",
"data",
";",
"}",
"if",
"(",
"connection_status",
"(",
")",
"!==",
"0",
")",
"{",
"return",
"$",
"data",
";",
"}",
"// Ideal level",
"$",
"level",
"=",
"4",
";",
"/*\n\t\t$size = strlen($data);\n\t\t$crc = crc32($data);\n\t\t$gzdata = \"\\x1f\\x8b\\x08\\x00\\x00\\x00\\x00\\x00\";\n\t\t$gzdata .= gzcompress($data, $level);\n\t\t$gzdata = substr($gzdata, 0, strlen($gzdata) - 4);\n\t\t$gzdata .= pack(\"V\",$crc) . pack(\"V\", $size);\n\t\t*/",
"$",
"gzdata",
"=",
"gzencode",
"(",
"$",
"data",
",",
"$",
"level",
")",
";",
"self",
"::",
"setHeader",
"(",
"'Content-Encoding'",
",",
"$",
"encoding",
")",
";",
"// Header will be removed at 4.0",
"if",
"(",
"JFactory",
"::",
"getConfig",
"(",
")",
"->",
"get",
"(",
"'MetaVersion'",
",",
"0",
")",
"&&",
"defined",
"(",
"'JVERSION'",
")",
")",
"{",
"self",
"::",
"setHeader",
"(",
"'X-Content-Encoded-By'",
",",
"'Joomla! '",
".",
"JVERSION",
")",
";",
"}",
"return",
"$",
"gzdata",
";",
"}"
]
| Compress the data
Checks the accept encoding of the browser and compresses the data before
sending it to the client.
@param string $data Content to compress for output.
@return string compressed data
@note Replaces _compress method in 11.1
@since 11.1
@deprecated 4.0 Use JApplicationWeb::compress() instead | [
"Compress",
"the",
"data"
]
| train | https://github.com/joomlatools/joomlatools-platform-legacy/blob/3a76944e2f2c415faa6504754c75321a3b478c06/code/response/response.php#L212-L259 |
joomlatools/joomlatools-platform-legacy | code/response/response.php | JResponse.clientEncoding | protected static function clientEncoding()
{
if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']))
{
return false;
}
$encoding = false;
if (false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
{
$encoding = 'gzip';
}
if (false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip'))
{
$encoding = 'x-gzip';
}
return $encoding;
} | php | protected static function clientEncoding()
{
if (!isset($_SERVER['HTTP_ACCEPT_ENCODING']))
{
return false;
}
$encoding = false;
if (false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
{
$encoding = 'gzip';
}
if (false !== strpos($_SERVER['HTTP_ACCEPT_ENCODING'], 'x-gzip'))
{
$encoding = 'x-gzip';
}
return $encoding;
} | [
"protected",
"static",
"function",
"clientEncoding",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_ENCODING'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"encoding",
"=",
"false",
";",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_ENCODING'",
"]",
",",
"'gzip'",
")",
")",
"{",
"$",
"encoding",
"=",
"'gzip'",
";",
"}",
"if",
"(",
"false",
"!==",
"strpos",
"(",
"$",
"_SERVER",
"[",
"'HTTP_ACCEPT_ENCODING'",
"]",
",",
"'x-gzip'",
")",
")",
"{",
"$",
"encoding",
"=",
"'x-gzip'",
";",
"}",
"return",
"$",
"encoding",
";",
"}"
]
| Check, whether client supports compressed data
@return boolean
@since 11.1
@note Replaces _clientEncoding method from 11.1
@deprecated 4.0 Use JApplicationWebClient instead | [
"Check",
"whether",
"client",
"supports",
"compressed",
"data"
]
| train | https://github.com/joomlatools/joomlatools-platform-legacy/blob/3a76944e2f2c415faa6504754c75321a3b478c06/code/response/response.php#L270-L290 |
jungle-bay/telegram-bot-api | src/TelegramBotAPI/Core/GSON.php | GSON.jsonSerialize | public function jsonSerialize() {
$props = (array) $this;
$json = array();
foreach ($props as $key => $value) {
if (null === $value) continue;
if ('*' === substr($key, 1, 1)) $key = substr($key, 2);
$key = str_replace(get_called_class(), '', $key);
$key = str_replace(get_parent_class($this), '', $key);
$key = str_replace("\0", '', $key);
$json[$this->fromCamelCase($key)] = $value;
}
return $json;
} | php | public function jsonSerialize() {
$props = (array) $this;
$json = array();
foreach ($props as $key => $value) {
if (null === $value) continue;
if ('*' === substr($key, 1, 1)) $key = substr($key, 2);
$key = str_replace(get_called_class(), '', $key);
$key = str_replace(get_parent_class($this), '', $key);
$key = str_replace("\0", '', $key);
$json[$this->fromCamelCase($key)] = $value;
}
return $json;
} | [
"public",
"function",
"jsonSerialize",
"(",
")",
"{",
"$",
"props",
"=",
"(",
"array",
")",
"$",
"this",
";",
"$",
"json",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"props",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"value",
")",
"continue",
";",
"if",
"(",
"'*'",
"===",
"substr",
"(",
"$",
"key",
",",
"1",
",",
"1",
")",
")",
"$",
"key",
"=",
"substr",
"(",
"$",
"key",
",",
"2",
")",
";",
"$",
"key",
"=",
"str_replace",
"(",
"get_called_class",
"(",
")",
",",
"''",
",",
"$",
"key",
")",
";",
"$",
"key",
"=",
"str_replace",
"(",
"get_parent_class",
"(",
"$",
"this",
")",
",",
"''",
",",
"$",
"key",
")",
";",
"$",
"key",
"=",
"str_replace",
"(",
"\"\\0\"",
",",
"''",
",",
"$",
"key",
")",
";",
"$",
"json",
"[",
"$",
"this",
"->",
"fromCamelCase",
"(",
"$",
"key",
")",
"]",
"=",
"$",
"value",
";",
"}",
"return",
"$",
"json",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/jungle-bay/telegram-bot-api/blob/8847ad5ad1dbb83283f72f68acf715c4a5868186/src/TelegramBotAPI/Core/GSON.php#L288-L307 |
thienhungho/yii2-order-management | src/modules/OrderBase/OrderItem.php | OrderItem.beforeSave | public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
$this->coupon = null;
if ($this->isNewRecord) {
$this->product_price = $this->product0->promotional_price;
$this->product_unit = $this->product0->unit;
$this->currency_unit = $this->product0->currency_unit;
$orderItem = \thienhungho\OrderManagement\models\OrderItem::find()
->where(['product' => $this->product])
->andWhere(['order' => $this->order])
->one();
if (!empty($orderItem)) {
$this->quantity += $orderItem->quantity;
$orderItem->deleteWithRelated();
}
}
$this->real_value = $this->quantity * $this->product_price;
if ($this->coupon == null) {
$this->discount_value = 0;
}
$this->total_price = $this->real_value;
return true;
}
return false;
} | php | public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
$this->coupon = null;
if ($this->isNewRecord) {
$this->product_price = $this->product0->promotional_price;
$this->product_unit = $this->product0->unit;
$this->currency_unit = $this->product0->currency_unit;
$orderItem = \thienhungho\OrderManagement\models\OrderItem::find()
->where(['product' => $this->product])
->andWhere(['order' => $this->order])
->one();
if (!empty($orderItem)) {
$this->quantity += $orderItem->quantity;
$orderItem->deleteWithRelated();
}
}
$this->real_value = $this->quantity * $this->product_price;
if ($this->coupon == null) {
$this->discount_value = 0;
}
$this->total_price = $this->real_value;
return true;
}
return false;
} | [
"public",
"function",
"beforeSave",
"(",
"$",
"insert",
")",
"{",
"if",
"(",
"parent",
"::",
"beforeSave",
"(",
"$",
"insert",
")",
")",
"{",
"$",
"this",
"->",
"coupon",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"isNewRecord",
")",
"{",
"$",
"this",
"->",
"product_price",
"=",
"$",
"this",
"->",
"product0",
"->",
"promotional_price",
";",
"$",
"this",
"->",
"product_unit",
"=",
"$",
"this",
"->",
"product0",
"->",
"unit",
";",
"$",
"this",
"->",
"currency_unit",
"=",
"$",
"this",
"->",
"product0",
"->",
"currency_unit",
";",
"$",
"orderItem",
"=",
"\\",
"thienhungho",
"\\",
"OrderManagement",
"\\",
"models",
"\\",
"OrderItem",
"::",
"find",
"(",
")",
"->",
"where",
"(",
"[",
"'product'",
"=>",
"$",
"this",
"->",
"product",
"]",
")",
"->",
"andWhere",
"(",
"[",
"'order'",
"=>",
"$",
"this",
"->",
"order",
"]",
")",
"->",
"one",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"orderItem",
")",
")",
"{",
"$",
"this",
"->",
"quantity",
"+=",
"$",
"orderItem",
"->",
"quantity",
";",
"$",
"orderItem",
"->",
"deleteWithRelated",
"(",
")",
";",
"}",
"}",
"$",
"this",
"->",
"real_value",
"=",
"$",
"this",
"->",
"quantity",
"*",
"$",
"this",
"->",
"product_price",
";",
"if",
"(",
"$",
"this",
"->",
"coupon",
"==",
"null",
")",
"{",
"$",
"this",
"->",
"discount_value",
"=",
"0",
";",
"}",
"$",
"this",
"->",
"total_price",
"=",
"$",
"this",
"->",
"real_value",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
]
| @param bool $insert
@return bool
@throws \yii\base\Exception
@throws \yii\base\InvalidConfigException | [
"@param",
"bool",
"$insert"
]
| train | https://github.com/thienhungho/yii2-order-management/blob/f263f0b2168d6f5e99cee2e20a5878d09d4e81c0/src/modules/OrderBase/OrderItem.php#L36-L66 |
ClanCats/Core | src/classes/CCError/Handler.php | CCError_Handler.log | protected function log()
{
if ( class_exists( 'CCLog' ) )
{
try {
\CCLog::add(
$this->inspector->exception()->getMessage()." - ".
str_replace( CCROOT, '', $this->inspector->exception()->getFile() ).":".
$this->inspector->exception()->getLine(), 'exception'
);
\CCLog::write();
} catch( \Exception $e ) {}
}
} | php | protected function log()
{
if ( class_exists( 'CCLog' ) )
{
try {
\CCLog::add(
$this->inspector->exception()->getMessage()." - ".
str_replace( CCROOT, '', $this->inspector->exception()->getFile() ).":".
$this->inspector->exception()->getLine(), 'exception'
);
\CCLog::write();
} catch( \Exception $e ) {}
}
} | [
"protected",
"function",
"log",
"(",
")",
"{",
"if",
"(",
"class_exists",
"(",
"'CCLog'",
")",
")",
"{",
"try",
"{",
"\\",
"CCLog",
"::",
"add",
"(",
"$",
"this",
"->",
"inspector",
"->",
"exception",
"(",
")",
"->",
"getMessage",
"(",
")",
".",
"\" - \"",
".",
"str_replace",
"(",
"CCROOT",
",",
"''",
",",
"$",
"this",
"->",
"inspector",
"->",
"exception",
"(",
")",
"->",
"getFile",
"(",
")",
")",
".",
"\":\"",
".",
"$",
"this",
"->",
"inspector",
"->",
"exception",
"(",
")",
"->",
"getLine",
"(",
")",
",",
"'exception'",
")",
";",
"\\",
"CCLog",
"::",
"write",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"}",
"}",
"}"
]
| Try to log that something went wrong
@return void | [
"Try",
"to",
"log",
"that",
"something",
"went",
"wrong"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError/Handler.php#L39-L52 |
ClanCats/Core | src/classes/CCError/Handler.php | CCError_Handler.handle | public function handle()
{
$this->log();
// when not in development we respond using a route
if ( !ClanCats::in_development() && !ClanCats::is_cli() )
{
CCResponse::error(500)->send( true );
}
// when in development continue with the default responder
else
{
$this->respond();
}
} | php | public function handle()
{
$this->log();
// when not in development we respond using a route
if ( !ClanCats::in_development() && !ClanCats::is_cli() )
{
CCResponse::error(500)->send( true );
}
// when in development continue with the default responder
else
{
$this->respond();
}
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"this",
"->",
"log",
"(",
")",
";",
"// when not in development we respond using a route",
"if",
"(",
"!",
"ClanCats",
"::",
"in_development",
"(",
")",
"&&",
"!",
"ClanCats",
"::",
"is_cli",
"(",
")",
")",
"{",
"CCResponse",
"::",
"error",
"(",
"500",
")",
"->",
"send",
"(",
"true",
")",
";",
"}",
"// when in development continue with the default responder",
"else",
"{",
"$",
"this",
"->",
"respond",
"(",
")",
";",
"}",
"}"
]
| trigger the handler
@return void | [
"trigger",
"the",
"handler"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError/Handler.php#L59-L73 |
ClanCats/Core | src/classes/CCError/Handler.php | CCError_Handler.respond | public function respond()
{
echo "<h1>".$this->inspector->message()." <small>( ".$this->inspector->exception_name()." )</small></h1>";
echo "<pre>".$this->inspector->exception()->getTraceAsString()."</pre>";
} | php | public function respond()
{
echo "<h1>".$this->inspector->message()." <small>( ".$this->inspector->exception_name()." )</small></h1>";
echo "<pre>".$this->inspector->exception()->getTraceAsString()."</pre>";
} | [
"public",
"function",
"respond",
"(",
")",
"{",
"echo",
"\"<h1>\"",
".",
"$",
"this",
"->",
"inspector",
"->",
"message",
"(",
")",
".",
"\" <small>( \"",
".",
"$",
"this",
"->",
"inspector",
"->",
"exception_name",
"(",
")",
".",
"\" )</small></h1>\"",
";",
"echo",
"\"<pre>\"",
".",
"$",
"this",
"->",
"inspector",
"->",
"exception",
"(",
")",
"->",
"getTraceAsString",
"(",
")",
".",
"\"</pre>\"",
";",
"}"
]
| respond information to the user
@return void | [
"respond",
"information",
"to",
"the",
"user"
]
| train | https://github.com/ClanCats/Core/blob/9f6ec72c1a439de4b253d0223f1029f7f85b6ef8/src/classes/CCError/Handler.php#L80-L84 |
egeloen/IvorySerializerBundle | DependencyInjection/Compiler/RegisterTypePass.php | RegisterTypePass.process | public function process(ContainerBuilder $container)
{
$typeRegistry = $container->getDefinition('ivory.serializer.registry.type');
$types = [];
foreach ($container->findTaggedServiceIds($tag = 'ivory.serializer.type') as $id => $attributes) {
foreach ($attributes as $attribute) {
$priority = isset($attribute['priority']) ? $attribute['priority'] : 0;
if (!isset($attribute['alias'])) {
throw new \RuntimeException(sprintf(
'No "alias" attribute found for the tag "%s" on the service "%s".',
$tag,
$id
));
}
if (!isset($attribute['direction'])) {
$attribute['direction'] = 'all';
}
$mapping = [
'all' => [Direction::SERIALIZATION, Direction::DESERIALIZATION],
'serialization' => [Direction::SERIALIZATION],
'deserialization' => [Direction::DESERIALIZATION],
];
if (!isset($mapping[$attribute['direction']])) {
throw new \RuntimeException(sprintf(
'The "direction" attribute for the tag "%s" on the service "%s" is not valid (%s).',
$tag,
$id,
$attribute['direction']
));
}
if ($attribute['alias'] === '!null') {
$attribute['alias'] = 'null';
}
foreach ($mapping[$attribute['direction']] as $direction) {
$types[$direction][$priority][$id][] = $attribute;
}
}
}
foreach ($types as $direction => $sortedTypes) {
krsort($sortedTypes);
$sortedTypes = call_user_func_array('array_merge', $sortedTypes);
foreach ($sortedTypes as $id => $attributes) {
foreach ($attributes as $attribute) {
$typeRegistry->addMethodCall('registerType', [$attribute['alias'], $direction, new Reference($id)]);
}
}
}
} | php | public function process(ContainerBuilder $container)
{
$typeRegistry = $container->getDefinition('ivory.serializer.registry.type');
$types = [];
foreach ($container->findTaggedServiceIds($tag = 'ivory.serializer.type') as $id => $attributes) {
foreach ($attributes as $attribute) {
$priority = isset($attribute['priority']) ? $attribute['priority'] : 0;
if (!isset($attribute['alias'])) {
throw new \RuntimeException(sprintf(
'No "alias" attribute found for the tag "%s" on the service "%s".',
$tag,
$id
));
}
if (!isset($attribute['direction'])) {
$attribute['direction'] = 'all';
}
$mapping = [
'all' => [Direction::SERIALIZATION, Direction::DESERIALIZATION],
'serialization' => [Direction::SERIALIZATION],
'deserialization' => [Direction::DESERIALIZATION],
];
if (!isset($mapping[$attribute['direction']])) {
throw new \RuntimeException(sprintf(
'The "direction" attribute for the tag "%s" on the service "%s" is not valid (%s).',
$tag,
$id,
$attribute['direction']
));
}
if ($attribute['alias'] === '!null') {
$attribute['alias'] = 'null';
}
foreach ($mapping[$attribute['direction']] as $direction) {
$types[$direction][$priority][$id][] = $attribute;
}
}
}
foreach ($types as $direction => $sortedTypes) {
krsort($sortedTypes);
$sortedTypes = call_user_func_array('array_merge', $sortedTypes);
foreach ($sortedTypes as $id => $attributes) {
foreach ($attributes as $attribute) {
$typeRegistry->addMethodCall('registerType', [$attribute['alias'], $direction, new Reference($id)]);
}
}
}
} | [
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"$",
"typeRegistry",
"=",
"$",
"container",
"->",
"getDefinition",
"(",
"'ivory.serializer.registry.type'",
")",
";",
"$",
"types",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"container",
"->",
"findTaggedServiceIds",
"(",
"$",
"tag",
"=",
"'ivory.serializer.type'",
")",
"as",
"$",
"id",
"=>",
"$",
"attributes",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"$",
"priority",
"=",
"isset",
"(",
"$",
"attribute",
"[",
"'priority'",
"]",
")",
"?",
"$",
"attribute",
"[",
"'priority'",
"]",
":",
"0",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"attribute",
"[",
"'alias'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'No \"alias\" attribute found for the tag \"%s\" on the service \"%s\".'",
",",
"$",
"tag",
",",
"$",
"id",
")",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"attribute",
"[",
"'direction'",
"]",
")",
")",
"{",
"$",
"attribute",
"[",
"'direction'",
"]",
"=",
"'all'",
";",
"}",
"$",
"mapping",
"=",
"[",
"'all'",
"=>",
"[",
"Direction",
"::",
"SERIALIZATION",
",",
"Direction",
"::",
"DESERIALIZATION",
"]",
",",
"'serialization'",
"=>",
"[",
"Direction",
"::",
"SERIALIZATION",
"]",
",",
"'deserialization'",
"=>",
"[",
"Direction",
"::",
"DESERIALIZATION",
"]",
",",
"]",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"mapping",
"[",
"$",
"attribute",
"[",
"'direction'",
"]",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'The \"direction\" attribute for the tag \"%s\" on the service \"%s\" is not valid (%s).'",
",",
"$",
"tag",
",",
"$",
"id",
",",
"$",
"attribute",
"[",
"'direction'",
"]",
")",
")",
";",
"}",
"if",
"(",
"$",
"attribute",
"[",
"'alias'",
"]",
"===",
"'!null'",
")",
"{",
"$",
"attribute",
"[",
"'alias'",
"]",
"=",
"'null'",
";",
"}",
"foreach",
"(",
"$",
"mapping",
"[",
"$",
"attribute",
"[",
"'direction'",
"]",
"]",
"as",
"$",
"direction",
")",
"{",
"$",
"types",
"[",
"$",
"direction",
"]",
"[",
"$",
"priority",
"]",
"[",
"$",
"id",
"]",
"[",
"]",
"=",
"$",
"attribute",
";",
"}",
"}",
"}",
"foreach",
"(",
"$",
"types",
"as",
"$",
"direction",
"=>",
"$",
"sortedTypes",
")",
"{",
"krsort",
"(",
"$",
"sortedTypes",
")",
";",
"$",
"sortedTypes",
"=",
"call_user_func_array",
"(",
"'array_merge'",
",",
"$",
"sortedTypes",
")",
";",
"foreach",
"(",
"$",
"sortedTypes",
"as",
"$",
"id",
"=>",
"$",
"attributes",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
")",
"{",
"$",
"typeRegistry",
"->",
"addMethodCall",
"(",
"'registerType'",
",",
"[",
"$",
"attribute",
"[",
"'alias'",
"]",
",",
"$",
"direction",
",",
"new",
"Reference",
"(",
"$",
"id",
")",
"]",
")",
";",
"}",
"}",
"}",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/egeloen/IvorySerializerBundle/blob/a2bdd912bf715c61b823cf7257ee232d5c823dd3/DependencyInjection/Compiler/RegisterTypePass.php#L27-L83 |
picamator/CacheManager | src/Operation/Delete.php | Delete.delete | public function delete(SearchCriteriaInterface $searchCriteria) : bool
{
$cacheKeyList = $this->keyGenerator->generateList($searchCriteria);
try {
$result = $this->cacheItemPool->deleteItems($cacheKeyList);
} catch (PsrCacheInvalidArgumentException $e) {
throw new InvalidCacheKeyException($e->getMessage(), $e->getCode(), $e);
}
return $result;
} | php | public function delete(SearchCriteriaInterface $searchCriteria) : bool
{
$cacheKeyList = $this->keyGenerator->generateList($searchCriteria);
try {
$result = $this->cacheItemPool->deleteItems($cacheKeyList);
} catch (PsrCacheInvalidArgumentException $e) {
throw new InvalidCacheKeyException($e->getMessage(), $e->getCode(), $e);
}
return $result;
} | [
"public",
"function",
"delete",
"(",
"SearchCriteriaInterface",
"$",
"searchCriteria",
")",
":",
"bool",
"{",
"$",
"cacheKeyList",
"=",
"$",
"this",
"->",
"keyGenerator",
"->",
"generateList",
"(",
"$",
"searchCriteria",
")",
";",
"try",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"cacheItemPool",
"->",
"deleteItems",
"(",
"$",
"cacheKeyList",
")",
";",
"}",
"catch",
"(",
"PsrCacheInvalidArgumentException",
"$",
"e",
")",
"{",
"throw",
"new",
"InvalidCacheKeyException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"return",
"$",
"result",
";",
"}"
]
| {@inheritdoc} | [
"{"
]
| train | https://github.com/picamator/CacheManager/blob/5e5493910610b65ae31a362786d7963ba3e33806/src/Operation/Delete.php#L44-L54 |
lmammino/e-foundation | src/Product/Model/Variant.php | Variant.setObject | public function setObject(VariableInterface $object = null)
{
$this->object = $this->product = $object;
return $this;
} | php | public function setObject(VariableInterface $object = null)
{
$this->object = $this->product = $object;
return $this;
} | [
"public",
"function",
"setObject",
"(",
"VariableInterface",
"$",
"object",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"object",
"=",
"$",
"this",
"->",
"product",
"=",
"$",
"object",
";",
"return",
"$",
"this",
";",
"}"
]
| {@inheritDoc} | [
"{"
]
| train | https://github.com/lmammino/e-foundation/blob/198b7047d93eb11c9bc0c7ddf0bfa8229d42807a/src/Product/Model/Variant.php#L44-L49 |
forxer/tao | src/Tao/Templating/Helpers/SelectOption.php | SelectOption.render | public function render($default)
{
$attr = $this->html;
$attr .= $this->class_name ? ' class="' . $this->class_name . '"' : '';
if ($this->value == $default)
{
$attr .= ' selected="selected"';
}
return sprintf($this->option, $this->value, $this->name, $attr) . PHP_EOL;
} | php | public function render($default)
{
$attr = $this->html;
$attr .= $this->class_name ? ' class="' . $this->class_name . '"' : '';
if ($this->value == $default)
{
$attr .= ' selected="selected"';
}
return sprintf($this->option, $this->value, $this->name, $attr) . PHP_EOL;
} | [
"public",
"function",
"render",
"(",
"$",
"default",
")",
"{",
"$",
"attr",
"=",
"$",
"this",
"->",
"html",
";",
"$",
"attr",
".=",
"$",
"this",
"->",
"class_name",
"?",
"' class=\"'",
".",
"$",
"this",
"->",
"class_name",
".",
"'\"'",
":",
"''",
";",
"if",
"(",
"$",
"this",
"->",
"value",
"==",
"$",
"default",
")",
"{",
"$",
"attr",
".=",
"' selected=\"selected\"'",
";",
"}",
"return",
"sprintf",
"(",
"$",
"this",
"->",
"option",
",",
"$",
"this",
"->",
"value",
",",
"$",
"this",
"->",
"name",
",",
"$",
"attr",
")",
".",
"PHP_EOL",
";",
"}"
]
| Option renderer
Returns option HTML code
@param boolean $default
selected
@return string | [
"Option",
"renderer"
]
| train | https://github.com/forxer/tao/blob/b5e9109c244a29a72403ae6a58633ab96a67c660/src/Tao/Templating/Helpers/SelectOption.php#L47-L58 |
webforge-labs/psc-cms | lib/Psc/CMS/Item/TabButtonableValueObject.php | TabButtonableValueObject.copyFromTabButtonable | public static function copyFromTabButtonable(TabButtonable $tabButtonable) {
$valueObject = new static();
// ugly, but fast
$valueObject->setButtonLabel($tabButtonable->getButtonLabel());
$valueObject->setFullButtonLabel($tabButtonable->getFullButtonLabel());
$valueObject->setButtonLeftIcon($tabButtonable->getButtonLeftIcon());
$valueObject->setButtonRightIcon($tabButtonable->getButtonRightIcon());
$valueObject->setButtonMode($tabButtonable->getButtonMode());
$valueObject->setTabLabel($tabButtonable->getTabLabel());
$valueObject->setTabRequestMeta($tabButtonable->getTabRequestMeta());
return $valueObject;
} | php | public static function copyFromTabButtonable(TabButtonable $tabButtonable) {
$valueObject = new static();
// ugly, but fast
$valueObject->setButtonLabel($tabButtonable->getButtonLabel());
$valueObject->setFullButtonLabel($tabButtonable->getFullButtonLabel());
$valueObject->setButtonLeftIcon($tabButtonable->getButtonLeftIcon());
$valueObject->setButtonRightIcon($tabButtonable->getButtonRightIcon());
$valueObject->setButtonMode($tabButtonable->getButtonMode());
$valueObject->setTabLabel($tabButtonable->getTabLabel());
$valueObject->setTabRequestMeta($tabButtonable->getTabRequestMeta());
return $valueObject;
} | [
"public",
"static",
"function",
"copyFromTabButtonable",
"(",
"TabButtonable",
"$",
"tabButtonable",
")",
"{",
"$",
"valueObject",
"=",
"new",
"static",
"(",
")",
";",
"// ugly, but fast",
"$",
"valueObject",
"->",
"setButtonLabel",
"(",
"$",
"tabButtonable",
"->",
"getButtonLabel",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setFullButtonLabel",
"(",
"$",
"tabButtonable",
"->",
"getFullButtonLabel",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setButtonLeftIcon",
"(",
"$",
"tabButtonable",
"->",
"getButtonLeftIcon",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setButtonRightIcon",
"(",
"$",
"tabButtonable",
"->",
"getButtonRightIcon",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setButtonMode",
"(",
"$",
"tabButtonable",
"->",
"getButtonMode",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setTabLabel",
"(",
"$",
"tabButtonable",
"->",
"getTabLabel",
"(",
")",
")",
";",
"$",
"valueObject",
"->",
"setTabRequestMeta",
"(",
"$",
"tabButtonable",
"->",
"getTabRequestMeta",
"(",
")",
")",
";",
"return",
"$",
"valueObject",
";",
"}"
]
| Creates a copy of an tabButtonable
use this to have a modified Version of the interface
@return TabButtonableValueObject | [
"Creates",
"a",
"copy",
"of",
"an",
"tabButtonable"
]
| train | https://github.com/webforge-labs/psc-cms/blob/467bfa2547e6b4fa487d2d7f35fa6cc618dbc763/lib/Psc/CMS/Item/TabButtonableValueObject.php#L18-L31 |
discordier/justtextwidgets | src/Widgets/JustAnExplanation.php | JustAnExplanation.generateLabel | public function generateLabel()
{
if ($this->strLabel === '') {
return '';
}
return sprintf(
'<span %s>%s%s</span>',
('' !== $this->strClass ? ' class="' . $this->strClass . '"' : ''),
$this->strLabel,
($this->required ? '<span class="mandatory">*</span>' : '')
);
} | php | public function generateLabel()
{
if ($this->strLabel === '') {
return '';
}
return sprintf(
'<span %s>%s%s</span>',
('' !== $this->strClass ? ' class="' . $this->strClass . '"' : ''),
$this->strLabel,
($this->required ? '<span class="mandatory">*</span>' : '')
);
} | [
"public",
"function",
"generateLabel",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"strLabel",
"===",
"''",
")",
"{",
"return",
"''",
";",
"}",
"return",
"sprintf",
"(",
"'<span %s>%s%s</span>'",
",",
"(",
"''",
"!==",
"$",
"this",
"->",
"strClass",
"?",
"' class=\"'",
".",
"$",
"this",
"->",
"strClass",
".",
"'\"'",
":",
"''",
")",
",",
"$",
"this",
"->",
"strLabel",
",",
"(",
"$",
"this",
"->",
"required",
"?",
"'<span class=\"mandatory\">*</span>'",
":",
"''",
")",
")",
";",
"}"
]
| Generate the label and return it as string.
@return string | [
"Generate",
"the",
"label",
"and",
"return",
"it",
"as",
"string",
"."
]
| train | https://github.com/discordier/justtextwidgets/blob/585f20eec05d592bb13281ca8ef0972e956d3f06/src/Widgets/JustAnExplanation.php#L53-L65 |
dunkelfrosch/phpcoverfish | src/PHPCoverFish/Base/BaseCoverFishScanner.php | BaseCoverFishScanner.initCoverFishScanner | private function initCoverFishScanner(array $cliOptions)
{
// fetch all necessary coverfish parameter by optional given raw-data first
$this->testAutoloadPath = $cliOptions['raw_scan_autoload_file'];
$this->testSourcePath = $cliOptions['raw_scan_source'];
$this->testExcludePath = $cliOptions['raw_scan_exclude_path'];
// fetch additional system/app parameter
$this->phpUnitXMLFile = $cliOptions['sys_phpunit_config'];
$this->phpUnitTestSuite = $cliOptions['sys_phpunit_config_test_suite'];
$this->stopOnFailure = (bool) $cliOptions['sys_stop_on_failure'];
$this->stopOnError = (bool) $cliOptions['sys_stop_on_error'];
} | php | private function initCoverFishScanner(array $cliOptions)
{
// fetch all necessary coverfish parameter by optional given raw-data first
$this->testAutoloadPath = $cliOptions['raw_scan_autoload_file'];
$this->testSourcePath = $cliOptions['raw_scan_source'];
$this->testExcludePath = $cliOptions['raw_scan_exclude_path'];
// fetch additional system/app parameter
$this->phpUnitXMLFile = $cliOptions['sys_phpunit_config'];
$this->phpUnitTestSuite = $cliOptions['sys_phpunit_config_test_suite'];
$this->stopOnFailure = (bool) $cliOptions['sys_stop_on_failure'];
$this->stopOnError = (bool) $cliOptions['sys_stop_on_error'];
} | [
"private",
"function",
"initCoverFishScanner",
"(",
"array",
"$",
"cliOptions",
")",
"{",
"// fetch all necessary coverfish parameter by optional given raw-data first",
"$",
"this",
"->",
"testAutoloadPath",
"=",
"$",
"cliOptions",
"[",
"'raw_scan_autoload_file'",
"]",
";",
"$",
"this",
"->",
"testSourcePath",
"=",
"$",
"cliOptions",
"[",
"'raw_scan_source'",
"]",
";",
"$",
"this",
"->",
"testExcludePath",
"=",
"$",
"cliOptions",
"[",
"'raw_scan_exclude_path'",
"]",
";",
"// fetch additional system/app parameter",
"$",
"this",
"->",
"phpUnitXMLFile",
"=",
"$",
"cliOptions",
"[",
"'sys_phpunit_config'",
"]",
";",
"$",
"this",
"->",
"phpUnitTestSuite",
"=",
"$",
"cliOptions",
"[",
"'sys_phpunit_config_test_suite'",
"]",
";",
"$",
"this",
"->",
"stopOnFailure",
"=",
"(",
"bool",
")",
"$",
"cliOptions",
"[",
"'sys_stop_on_failure'",
"]",
";",
"$",
"this",
"->",
"stopOnError",
"=",
"(",
"bool",
")",
"$",
"cliOptions",
"[",
"'sys_stop_on_error'",
"]",
";",
"}"
]
| @param array $cliOptions
@codeCoverageIgnore | [
"@param",
"array",
"$cliOptions"
]
| train | https://github.com/dunkelfrosch/phpcoverfish/blob/779bd399ec8f4cadb3b7854200695c5eb3f5a8ad/src/PHPCoverFish/Base/BaseCoverFishScanner.php#L70-L82 |
dunkelfrosch/phpcoverfish | src/PHPCoverFish/Base/BaseCoverFishScanner.php | BaseCoverFishScanner.setConfigFromPHPUnitConfigFile | public function setConfigFromPHPUnitConfigFile()
{
try {
/** @var \SimpleXMLElement $xmlDocument */
$xmlDocument = simplexml_load_file($this->phpUnitXMLFile);
$this->phpUnitXMLPath = $this->coverFishHelper->getPathFromFileNameAndPath($this->phpUnitXMLFile);
$this->testAutoloadPath = sprintf('%s%s', $this->phpUnitXMLPath, $this->getAttributeFromXML('bootstrap', $xmlDocument));
$this->testSourcePath = sprintf('%s%s', $this->phpUnitXMLPath, $this->getTestSuitePropertyFromXML('directory', $xmlDocument));
$this->testExcludePath = sprintf('%s', $this->getTestSuitePropertyFromXML('exclude', $xmlDocument));
} catch (\Exception $e) {
echo (sprintf('parse error loading phpunit config file "%s"!', $this->phpUnitXMLFile));
echo (sprintf('-> message: %s', $e->getMessage()));
}
} | php | public function setConfigFromPHPUnitConfigFile()
{
try {
/** @var \SimpleXMLElement $xmlDocument */
$xmlDocument = simplexml_load_file($this->phpUnitXMLFile);
$this->phpUnitXMLPath = $this->coverFishHelper->getPathFromFileNameAndPath($this->phpUnitXMLFile);
$this->testAutoloadPath = sprintf('%s%s', $this->phpUnitXMLPath, $this->getAttributeFromXML('bootstrap', $xmlDocument));
$this->testSourcePath = sprintf('%s%s', $this->phpUnitXMLPath, $this->getTestSuitePropertyFromXML('directory', $xmlDocument));
$this->testExcludePath = sprintf('%s', $this->getTestSuitePropertyFromXML('exclude', $xmlDocument));
} catch (\Exception $e) {
echo (sprintf('parse error loading phpunit config file "%s"!', $this->phpUnitXMLFile));
echo (sprintf('-> message: %s', $e->getMessage()));
}
} | [
"public",
"function",
"setConfigFromPHPUnitConfigFile",
"(",
")",
"{",
"try",
"{",
"/** @var \\SimpleXMLElement $xmlDocument */",
"$",
"xmlDocument",
"=",
"simplexml_load_file",
"(",
"$",
"this",
"->",
"phpUnitXMLFile",
")",
";",
"$",
"this",
"->",
"phpUnitXMLPath",
"=",
"$",
"this",
"->",
"coverFishHelper",
"->",
"getPathFromFileNameAndPath",
"(",
"$",
"this",
"->",
"phpUnitXMLFile",
")",
";",
"$",
"this",
"->",
"testAutoloadPath",
"=",
"sprintf",
"(",
"'%s%s'",
",",
"$",
"this",
"->",
"phpUnitXMLPath",
",",
"$",
"this",
"->",
"getAttributeFromXML",
"(",
"'bootstrap'",
",",
"$",
"xmlDocument",
")",
")",
";",
"$",
"this",
"->",
"testSourcePath",
"=",
"sprintf",
"(",
"'%s%s'",
",",
"$",
"this",
"->",
"phpUnitXMLPath",
",",
"$",
"this",
"->",
"getTestSuitePropertyFromXML",
"(",
"'directory'",
",",
"$",
"xmlDocument",
")",
")",
";",
"$",
"this",
"->",
"testExcludePath",
"=",
"sprintf",
"(",
"'%s'",
",",
"$",
"this",
"->",
"getTestSuitePropertyFromXML",
"(",
"'exclude'",
",",
"$",
"xmlDocument",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"echo",
"(",
"sprintf",
"(",
"'parse error loading phpunit config file \"%s\"!'",
",",
"$",
"this",
"->",
"phpUnitXMLFile",
")",
")",
";",
"echo",
"(",
"sprintf",
"(",
"'-> message: %s'",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
")",
";",
"}",
"}"
]
| update/set configuration using phpunit xml file | [
"update",
"/",
"set",
"configuration",
"using",
"phpunit",
"xml",
"file"
]
| train | https://github.com/dunkelfrosch/phpcoverfish/blob/779bd399ec8f4cadb3b7854200695c5eb3f5a8ad/src/PHPCoverFish/Base/BaseCoverFishScanner.php#L87-L104 |
dunkelfrosch/phpcoverfish | src/PHPCoverFish/Base/BaseCoverFishScanner.php | BaseCoverFishScanner.validateAndReturnMapping | public function validateAndReturnMapping(CoverFishPHPUnitTest $phpUnitTest)
{
$phpUnitTest->clearCoverMappings();
/** @var BaseCoverFishValidatorInterface $validator */
foreach ($this->validatorCollection as $validator) {
if (false === $validator->validate()) {
continue;
}
$phpUnitTest->addCoverMapping($validator->getMapping($this->phpUnitFile));
}
return $phpUnitTest;
} | php | public function validateAndReturnMapping(CoverFishPHPUnitTest $phpUnitTest)
{
$phpUnitTest->clearCoverMappings();
/** @var BaseCoverFishValidatorInterface $validator */
foreach ($this->validatorCollection as $validator) {
if (false === $validator->validate()) {
continue;
}
$phpUnitTest->addCoverMapping($validator->getMapping($this->phpUnitFile));
}
return $phpUnitTest;
} | [
"public",
"function",
"validateAndReturnMapping",
"(",
"CoverFishPHPUnitTest",
"$",
"phpUnitTest",
")",
"{",
"$",
"phpUnitTest",
"->",
"clearCoverMappings",
"(",
")",
";",
"/** @var BaseCoverFishValidatorInterface $validator */",
"foreach",
"(",
"$",
"this",
"->",
"validatorCollection",
"as",
"$",
"validator",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"validator",
"->",
"validate",
"(",
")",
")",
"{",
"continue",
";",
"}",
"$",
"phpUnitTest",
"->",
"addCoverMapping",
"(",
"$",
"validator",
"->",
"getMapping",
"(",
"$",
"this",
"->",
"phpUnitFile",
")",
")",
";",
"}",
"return",
"$",
"phpUnitTest",
";",
"}"
]
| @param CoverFishPHPUnitTest $phpUnitTest
@return CoverFishPHPUnitTest | [
"@param",
"CoverFishPHPUnitTest",
"$phpUnitTest"
]
| train | https://github.com/dunkelfrosch/phpcoverfish/blob/779bd399ec8f4cadb3b7854200695c5eb3f5a8ad/src/PHPCoverFish/Base/BaseCoverFishScanner.php#L111-L125 |
iamapen/dbunit-ExcelFriendlyDataSet | src/lib/Iamapen/ExcelFriendlyDataSet/Database/DataSet/CommentableCsvDataSet.php | CommentableCsvDataSet.getCsvRow | protected function getCsvRow($fh)
{
if (version_compare(PHP_VERSION, '5.3.0', '>')) {
$rows = fgetcsv($fh, NULL, $this->delimiter, $this->enclosure, $this->escape);
} else {
$rows = fgetcsv($fh, NULL, $this->delimiter, $this->enclosure);
}
if ($rows === false) {
return false;
}
for ($i = 0; $i < $this->ignoreColumnCount; $i++) {
array_shift($rows);
}
return $rows;
} | php | protected function getCsvRow($fh)
{
if (version_compare(PHP_VERSION, '5.3.0', '>')) {
$rows = fgetcsv($fh, NULL, $this->delimiter, $this->enclosure, $this->escape);
} else {
$rows = fgetcsv($fh, NULL, $this->delimiter, $this->enclosure);
}
if ($rows === false) {
return false;
}
for ($i = 0; $i < $this->ignoreColumnCount; $i++) {
array_shift($rows);
}
return $rows;
} | [
"protected",
"function",
"getCsvRow",
"(",
"$",
"fh",
")",
"{",
"if",
"(",
"version_compare",
"(",
"PHP_VERSION",
",",
"'5.3.0'",
",",
"'>'",
")",
")",
"{",
"$",
"rows",
"=",
"fgetcsv",
"(",
"$",
"fh",
",",
"NULL",
",",
"$",
"this",
"->",
"delimiter",
",",
"$",
"this",
"->",
"enclosure",
",",
"$",
"this",
"->",
"escape",
")",
";",
"}",
"else",
"{",
"$",
"rows",
"=",
"fgetcsv",
"(",
"$",
"fh",
",",
"NULL",
",",
"$",
"this",
"->",
"delimiter",
",",
"$",
"this",
"->",
"enclosure",
")",
";",
"}",
"if",
"(",
"$",
"rows",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"ignoreColumnCount",
";",
"$",
"i",
"++",
")",
"{",
"array_shift",
"(",
"$",
"rows",
")",
";",
"}",
"return",
"$",
"rows",
";",
"}"
]
| Returns a row from the csv file in an indexed array.
@param resource $fh
@return array | [
"Returns",
"a",
"row",
"from",
"the",
"csv",
"file",
"in",
"an",
"indexed",
"array",
"."
]
| train | https://github.com/iamapen/dbunit-ExcelFriendlyDataSet/blob/036103cb2a2a75608f0a00448301cd3f4a5c4e19/src/lib/Iamapen/ExcelFriendlyDataSet/Database/DataSet/CommentableCsvDataSet.php#L37-L53 |
maximebf/events | src/Events/GenericEmitter.php | GenericEmitter.addListener | public function addListener(EventListener $listener, $priority = 0, $important = false)
{
$this->eventDispatcher->addListener($listener, $priority, $important);
return $this;
} | php | public function addListener(EventListener $listener, $priority = 0, $important = false)
{
$this->eventDispatcher->addListener($listener, $priority, $important);
return $this;
} | [
"public",
"function",
"addListener",
"(",
"EventListener",
"$",
"listener",
",",
"$",
"priority",
"=",
"0",
",",
"$",
"important",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"eventDispatcher",
"->",
"addListener",
"(",
"$",
"listener",
",",
"$",
"priority",
",",
"$",
"important",
")",
";",
"return",
"$",
"this",
";",
"}"
]
| {@inheritDoc} | [
"{"
]
| train | https://github.com/maximebf/events/blob/b9861c260ee9eaabb9aa986bab76a2e039eb871f/src/Events/GenericEmitter.php#L53-L57 |
iocaste/microservice-foundation | src/Exception/MicroserviceHandler.php | MicroserviceHandler.render | public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException || $e instanceof NotFoundHttpException) {
return $this->respondNotFound(
ApiResponse::CODE_NOT_FOUND,
$e->getMessage()
);
}
$data = [];
$status = 500;
if (env('APP_DEBUG')) {
$data = [
'exception' => \get_class($e),
'code' => $e->getCode(),
'message' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
];
}
if ($this->isHttpException($e)) {
// Grab the HTTP status code from the Exception
$status = $e->getStatusCode();
}
return $this->setStatusCode($status)
->respondWithError(
ApiResponse::CODE_API_ERROR,
'API internal error occurred. Please contact support for details.',
$data
);
} | php | public function render($request, Exception $e)
{
if ($e instanceof ModelNotFoundException || $e instanceof NotFoundHttpException) {
return $this->respondNotFound(
ApiResponse::CODE_NOT_FOUND,
$e->getMessage()
);
}
$data = [];
$status = 500;
if (env('APP_DEBUG')) {
$data = [
'exception' => \get_class($e),
'code' => $e->getCode(),
'message' => $e->getMessage(),
'trace' => $e->getTraceAsString(),
];
}
if ($this->isHttpException($e)) {
// Grab the HTTP status code from the Exception
$status = $e->getStatusCode();
}
return $this->setStatusCode($status)
->respondWithError(
ApiResponse::CODE_API_ERROR,
'API internal error occurred. Please contact support for details.',
$data
);
} | [
"public",
"function",
"render",
"(",
"$",
"request",
",",
"Exception",
"$",
"e",
")",
"{",
"if",
"(",
"$",
"e",
"instanceof",
"ModelNotFoundException",
"||",
"$",
"e",
"instanceof",
"NotFoundHttpException",
")",
"{",
"return",
"$",
"this",
"->",
"respondNotFound",
"(",
"ApiResponse",
"::",
"CODE_NOT_FOUND",
",",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"$",
"data",
"=",
"[",
"]",
";",
"$",
"status",
"=",
"500",
";",
"if",
"(",
"env",
"(",
"'APP_DEBUG'",
")",
")",
"{",
"$",
"data",
"=",
"[",
"'exception'",
"=>",
"\\",
"get_class",
"(",
"$",
"e",
")",
",",
"'code'",
"=>",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"'message'",
"=>",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"'trace'",
"=>",
"$",
"e",
"->",
"getTraceAsString",
"(",
")",
",",
"]",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"isHttpException",
"(",
"$",
"e",
")",
")",
"{",
"// Grab the HTTP status code from the Exception",
"$",
"status",
"=",
"$",
"e",
"->",
"getStatusCode",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"setStatusCode",
"(",
"$",
"status",
")",
"->",
"respondWithError",
"(",
"ApiResponse",
"::",
"CODE_API_ERROR",
",",
"'API internal error occurred. Please contact support for details.'",
",",
"$",
"data",
")",
";",
"}"
]
| Render an exception into an HTTP response.
@param \Illuminate\Http\Request $request
@param \Exception $e
@return \Illuminate\Http\Response|\Illuminate\Http\JsonResponse | [
"Render",
"an",
"exception",
"into",
"an",
"HTTP",
"response",
"."
]
| train | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Exception/MicroserviceHandler.php#L56-L89 |
iocaste/microservice-foundation | src/Transformer/Transformer.php | Transformer.isRequested | protected function isRequested($resource = null): bool
{
$requestKey = config('fractal.auto_includes.request_key');
if (! config('fractal.auto_includes.enabled')) {
return false;
}
if (! $includes = app('request')->get($requestKey)) {
return false;
}
$includes = explode(',', $includes);
if (! \is_array($includes)) {
return false;
}
if (! \in_array($resource, $includes, false)) {
return false;
}
return true;
} | php | protected function isRequested($resource = null): bool
{
$requestKey = config('fractal.auto_includes.request_key');
if (! config('fractal.auto_includes.enabled')) {
return false;
}
if (! $includes = app('request')->get($requestKey)) {
return false;
}
$includes = explode(',', $includes);
if (! \is_array($includes)) {
return false;
}
if (! \in_array($resource, $includes, false)) {
return false;
}
return true;
} | [
"protected",
"function",
"isRequested",
"(",
"$",
"resource",
"=",
"null",
")",
":",
"bool",
"{",
"$",
"requestKey",
"=",
"config",
"(",
"'fractal.auto_includes.request_key'",
")",
";",
"if",
"(",
"!",
"config",
"(",
"'fractal.auto_includes.enabled'",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"includes",
"=",
"app",
"(",
"'request'",
")",
"->",
"get",
"(",
"$",
"requestKey",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"includes",
"=",
"explode",
"(",
"','",
",",
"$",
"includes",
")",
";",
"if",
"(",
"!",
"\\",
"is_array",
"(",
"$",
"includes",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"resource",
",",
"$",
"includes",
",",
"false",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
]
| Checks if specified resource has been requested as query string parameter.
@param string $resource
@return bool | [
"Checks",
"if",
"specified",
"resource",
"has",
"been",
"requested",
"as",
"query",
"string",
"parameter",
".",
"@param",
"string",
"$resource"
]
| train | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Transformer/Transformer.php#L20-L43 |
iocaste/microservice-foundation | src/Transformer/Transformer.php | Transformer.getEntity | public function getEntity(): ?string
{
$reflection = new ReflectionMethod($this, 'transform');
if (! $reflection->getNumberOfParameters()) {
return null;
}
$parameter = $reflection->getParameters()[0];
if (! ($type = $parameter->getType())) {
return null;
}
return $type->getName();
} | php | public function getEntity(): ?string
{
$reflection = new ReflectionMethod($this, 'transform');
if (! $reflection->getNumberOfParameters()) {
return null;
}
$parameter = $reflection->getParameters()[0];
if (! ($type = $parameter->getType())) {
return null;
}
return $type->getName();
} | [
"public",
"function",
"getEntity",
"(",
")",
":",
"?",
"string",
"{",
"$",
"reflection",
"=",
"new",
"ReflectionMethod",
"(",
"$",
"this",
",",
"'transform'",
")",
";",
"if",
"(",
"!",
"$",
"reflection",
"->",
"getNumberOfParameters",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"parameter",
"=",
"$",
"reflection",
"->",
"getParameters",
"(",
")",
"[",
"0",
"]",
";",
"if",
"(",
"!",
"(",
"$",
"type",
"=",
"$",
"parameter",
"->",
"getType",
"(",
")",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"type",
"->",
"getName",
"(",
")",
";",
"}"
]
| @return null|string
@throws \ReflectionException | [
"@return",
"null|string"
]
| train | https://github.com/iocaste/microservice-foundation/blob/274a154de4299e8a57314bab972e09f6d8cdae9e/src/Transformer/Transformer.php#L64-L77 |
aedart/laravel-helpers | src/Traits/Database/DBTrait.php | DBTrait.getDb | public function getDb(): ?ConnectionInterface
{
if (!$this->hasDb()) {
$this->setDb($this->getDefaultDb());
}
return $this->db;
} | php | public function getDb(): ?ConnectionInterface
{
if (!$this->hasDb()) {
$this->setDb($this->getDefaultDb());
}
return $this->db;
} | [
"public",
"function",
"getDb",
"(",
")",
":",
"?",
"ConnectionInterface",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"hasDb",
"(",
")",
")",
"{",
"$",
"this",
"->",
"setDb",
"(",
"$",
"this",
"->",
"getDefaultDb",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"db",
";",
"}"
]
| Get db
If no db has been set, this method will
set and return a default db, if any such
value is available
@see getDefaultDb()
@return ConnectionInterface|null db or null if none db has been set | [
"Get",
"db"
]
| train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Database/DBTrait.php#L53-L59 |
aedart/laravel-helpers | src/Traits/Database/DBTrait.php | DBTrait.getDefaultDb | public function getDefaultDb(): ?ConnectionInterface
{
// By default, the DB Facade does not return the
// any actual database connection, but rather an
// instance of \Illuminate\Database\DatabaseManager.
// Therefore, we make sure only to obtain its
// "connection", to make sure that its only the connection
// instance that we obtain.
$manager = DB::getFacadeRoot();
if (isset($manager)) {
return $manager->connection();
}
return $manager;
} | php | public function getDefaultDb(): ?ConnectionInterface
{
// By default, the DB Facade does not return the
// any actual database connection, but rather an
// instance of \Illuminate\Database\DatabaseManager.
// Therefore, we make sure only to obtain its
// "connection", to make sure that its only the connection
// instance that we obtain.
$manager = DB::getFacadeRoot();
if (isset($manager)) {
return $manager->connection();
}
return $manager;
} | [
"public",
"function",
"getDefaultDb",
"(",
")",
":",
"?",
"ConnectionInterface",
"{",
"// By default, the DB Facade does not return the",
"// any actual database connection, but rather an",
"// instance of \\Illuminate\\Database\\DatabaseManager.",
"// Therefore, we make sure only to obtain its",
"// \"connection\", to make sure that its only the connection",
"// instance that we obtain.",
"$",
"manager",
"=",
"DB",
"::",
"getFacadeRoot",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"manager",
")",
")",
"{",
"return",
"$",
"manager",
"->",
"connection",
"(",
")",
";",
"}",
"return",
"$",
"manager",
";",
"}"
]
| Get a default db value, if any is available
@return ConnectionInterface|null A default db value or Null if no default value is available | [
"Get",
"a",
"default",
"db",
"value",
"if",
"any",
"is",
"available"
]
| train | https://github.com/aedart/laravel-helpers/blob/8b81a2d6658f3f8cb62b6be2c34773aaa2df219a/src/Traits/Database/DBTrait.php#L76-L89 |
ivory-php/fbi | src/Fbi.php | Fbi.showStatusBar | public function showStatusBar()
{
return $this;
/**
* In case the without status bar has been set, remove it first.
*/
if( array_key_exists('noverbose', $this->options) ) unset($this->options['noverbose']);
$this->options['v'] = '';
return $this;
} | php | public function showStatusBar()
{
return $this;
/**
* In case the without status bar has been set, remove it first.
*/
if( array_key_exists('noverbose', $this->options) ) unset($this->options['noverbose']);
$this->options['v'] = '';
return $this;
} | [
"public",
"function",
"showStatusBar",
"(",
")",
"{",
"return",
"$",
"this",
";",
"/**\n\t\t * In case the without status bar has been set, remove it first.\n\t\t */",
"if",
"(",
"array_key_exists",
"(",
"'noverbose'",
",",
"$",
"this",
"->",
"options",
")",
")",
"unset",
"(",
"$",
"this",
"->",
"options",
"[",
"'noverbose'",
"]",
")",
";",
"$",
"this",
"->",
"options",
"[",
"'v'",
"]",
"=",
"''",
";",
"return",
"$",
"this",
";",
"}"
]
| This shows the status bar at the bottom of the screen with image
about the file being displayed in it.
@return $this | [
"This",
"shows",
"the",
"status",
"bar",
"at",
"the",
"bottom",
"of",
"the",
"screen",
"with",
"image",
"about",
"the",
"file",
"being",
"displayed",
"in",
"it",
"."
]
| train | https://github.com/ivory-php/fbi/blob/fce0839ed4d5693bd161fe45260311cc27f46cef/src/Fbi.php#L88-L100 |
ivory-php/fbi | src/Fbi.php | Fbi.withoutStatusBar | public function withoutStatusBar()
{
return $this;
if( array_key_exists('v', $this->options) ) unset($this->options['v']);
$this->options['noverbose'] = '';
return $this;
} | php | public function withoutStatusBar()
{
return $this;
if( array_key_exists('v', $this->options) ) unset($this->options['v']);
$this->options['noverbose'] = '';
return $this;
} | [
"public",
"function",
"withoutStatusBar",
"(",
")",
"{",
"return",
"$",
"this",
";",
"if",
"(",
"array_key_exists",
"(",
"'v'",
",",
"$",
"this",
"->",
"options",
")",
")",
"unset",
"(",
"$",
"this",
"->",
"options",
"[",
"'v'",
"]",
")",
";",
"$",
"this",
"->",
"options",
"[",
"'noverbose'",
"]",
"=",
"''",
";",
"return",
"$",
"this",
";",
"}"
]
| Don't display the status bar at the bottom of the screen
@return $this | [
"Don",
"t",
"display",
"the",
"status",
"bar",
"at",
"the",
"bottom",
"of",
"the",
"screen"
]
| train | https://github.com/ivory-php/fbi/blob/fce0839ed4d5693bd161fe45260311cc27f46cef/src/Fbi.php#L106-L114 |
ivory-php/fbi | src/Fbi.php | Fbi.displayFor | public function displayFor(int $seconds)
{
$this->options['t'] = $seconds;
$this->displayFor = $seconds;
return $this;
} | php | public function displayFor(int $seconds)
{
$this->options['t'] = $seconds;
$this->displayFor = $seconds;
return $this;
} | [
"public",
"function",
"displayFor",
"(",
"int",
"$",
"seconds",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'t'",
"]",
"=",
"$",
"seconds",
";",
"$",
"this",
"->",
"displayFor",
"=",
"$",
"seconds",
";",
"return",
"$",
"this",
";",
"}"
]
| Load the next image after x number of seconds without
any keypress (eg, slideshow)
@return $this | [
"Load",
"the",
"next",
"image",
"after",
"x",
"number",
"of",
"seconds",
"without",
"any",
"keypress",
"(",
"eg",
"slideshow",
")"
]
| train | https://github.com/ivory-php/fbi/blob/fce0839ed4d5693bd161fe45260311cc27f46cef/src/Fbi.php#L147-L153 |
ivory-php/fbi | src/Fbi.php | Fbi.display | public function display()
{
$options = $this->_compileOptions();
$command = system('sudo fbi --noverbose ' . $this->_compileOptions() . ' ' .$this->file . ' > /dev/null 2>&1');
/**
* If $displayFor is set to 0, then the application doesn't need to be terminated. It's showing
* indefinetly.
*/
if( $this->displayFor > 0 )
{
sleep($this->displayFor);
$this->terminate();
}
} | php | public function display()
{
$options = $this->_compileOptions();
$command = system('sudo fbi --noverbose ' . $this->_compileOptions() . ' ' .$this->file . ' > /dev/null 2>&1');
/**
* If $displayFor is set to 0, then the application doesn't need to be terminated. It's showing
* indefinetly.
*/
if( $this->displayFor > 0 )
{
sleep($this->displayFor);
$this->terminate();
}
} | [
"public",
"function",
"display",
"(",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"_compileOptions",
"(",
")",
";",
"$",
"command",
"=",
"system",
"(",
"'sudo fbi --noverbose '",
".",
"$",
"this",
"->",
"_compileOptions",
"(",
")",
".",
"' '",
".",
"$",
"this",
"->",
"file",
".",
"' > /dev/null 2>&1'",
")",
";",
"/**\n\t\t * If $displayFor is set to 0, then the application doesn't need to be terminated. It's showing\n\t\t * indefinetly. \n\t\t */",
"if",
"(",
"$",
"this",
"->",
"displayFor",
">",
"0",
")",
"{",
"sleep",
"(",
"$",
"this",
"->",
"displayFor",
")",
";",
"$",
"this",
"->",
"terminate",
"(",
")",
";",
"}",
"}"
]
| Display The Image
@return | [
"Display",
"The",
"Image"
]
| train | https://github.com/ivory-php/fbi/blob/fce0839ed4d5693bd161fe45260311cc27f46cef/src/Fbi.php#L315-L329 |
ivory-php/fbi | src/Fbi.php | Fbi._compileOptions | public function _compileOptions()
{
$compiled = '';
/**
* We'll cycle through the options. If the option has only one
* character, it needs a hash, multiple characters needs two hashes.
*/
foreach( $this->options as $option => $value ) :
if( strlen($option) > 1 ) $compiled.= "--{$option} {$value} ";
else $compiled.= "-{$option} {$value}";
endforeach;
return $compiled;
} | php | public function _compileOptions()
{
$compiled = '';
/**
* We'll cycle through the options. If the option has only one
* character, it needs a hash, multiple characters needs two hashes.
*/
foreach( $this->options as $option => $value ) :
if( strlen($option) > 1 ) $compiled.= "--{$option} {$value} ";
else $compiled.= "-{$option} {$value}";
endforeach;
return $compiled;
} | [
"public",
"function",
"_compileOptions",
"(",
")",
"{",
"$",
"compiled",
"=",
"''",
";",
"/**\n\t\t * We'll cycle through the options. If the option has only one \n\t\t * character, it needs a hash, multiple characters needs two hashes. \n\t\t */",
"foreach",
"(",
"$",
"this",
"->",
"options",
"as",
"$",
"option",
"=>",
"$",
"value",
")",
":",
"if",
"(",
"strlen",
"(",
"$",
"option",
")",
">",
"1",
")",
"$",
"compiled",
".=",
"\"--{$option} {$value} \"",
";",
"else",
"$",
"compiled",
".=",
"\"-{$option} {$value}\"",
";",
"endforeach",
";",
"return",
"$",
"compiled",
";",
"}"
]
| Compile the options to a string passable to the command
@return string | [
"Compile",
"the",
"options",
"to",
"a",
"string",
"passable",
"to",
"the",
"command"
]
| train | https://github.com/ivory-php/fbi/blob/fce0839ed4d5693bd161fe45260311cc27f46cef/src/Fbi.php#L335-L349 |
mihai-stancu/serializer | Serializer/Normalizer/BinaryNormalizer.php | BinaryNormalizer.normalize | public function normalize($string, $format = null, array $context = array())
{
$mime = isset($context[static::CONTEXT_MIME]) ? $context[static::CONTEXT_MIME] : 'application/octet-stream';
$charset = isset($context[static::CONTEXT_CHARSET]) ? $context[static::CONTEXT_CHARSET] : null;
$gzip = isset($context[static::CONTEXT_GZIP]) ? $context[static::CONTEXT_GZIP] : null;
$base64 = isset($context[static::CONTEXT_BASE64]) ? $context[static::CONTEXT_BASE64] : null;
$base64 = ($base64 !== null) ? $base64 : strpos($mime, '/octet-stream') !== false;
$urlencode = isset($context[static::CONTEXT_URLENCODE]) ? $context[static::CONTEXT_URLENCODE] : null;
$urlencode = ($urlencode !== null) ? $urlencode : strpos($mime, 'text/') !== false;
if ($gzip) {
$string = gzencode($string);
$mime = 'application/x-gzip';
}
if ($urlencode and !$base64) {
$string = urlencode($string);
}
if ($base64 or !$urlencode) {
$string = base64_encode($string);
}
$options = $mime;
if ($charset and $mime) {
$options .= ';charset='.$charset;
}
if ($base64) {
$options .= ';base64';
}
return sprintf('data:%s,%s', $options, $string);
} | php | public function normalize($string, $format = null, array $context = array())
{
$mime = isset($context[static::CONTEXT_MIME]) ? $context[static::CONTEXT_MIME] : 'application/octet-stream';
$charset = isset($context[static::CONTEXT_CHARSET]) ? $context[static::CONTEXT_CHARSET] : null;
$gzip = isset($context[static::CONTEXT_GZIP]) ? $context[static::CONTEXT_GZIP] : null;
$base64 = isset($context[static::CONTEXT_BASE64]) ? $context[static::CONTEXT_BASE64] : null;
$base64 = ($base64 !== null) ? $base64 : strpos($mime, '/octet-stream') !== false;
$urlencode = isset($context[static::CONTEXT_URLENCODE]) ? $context[static::CONTEXT_URLENCODE] : null;
$urlencode = ($urlencode !== null) ? $urlencode : strpos($mime, 'text/') !== false;
if ($gzip) {
$string = gzencode($string);
$mime = 'application/x-gzip';
}
if ($urlencode and !$base64) {
$string = urlencode($string);
}
if ($base64 or !$urlencode) {
$string = base64_encode($string);
}
$options = $mime;
if ($charset and $mime) {
$options .= ';charset='.$charset;
}
if ($base64) {
$options .= ';base64';
}
return sprintf('data:%s,%s', $options, $string);
} | [
"public",
"function",
"normalize",
"(",
"$",
"string",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"$",
"mime",
"=",
"isset",
"(",
"$",
"context",
"[",
"static",
"::",
"CONTEXT_MIME",
"]",
")",
"?",
"$",
"context",
"[",
"static",
"::",
"CONTEXT_MIME",
"]",
":",
"'application/octet-stream'",
";",
"$",
"charset",
"=",
"isset",
"(",
"$",
"context",
"[",
"static",
"::",
"CONTEXT_CHARSET",
"]",
")",
"?",
"$",
"context",
"[",
"static",
"::",
"CONTEXT_CHARSET",
"]",
":",
"null",
";",
"$",
"gzip",
"=",
"isset",
"(",
"$",
"context",
"[",
"static",
"::",
"CONTEXT_GZIP",
"]",
")",
"?",
"$",
"context",
"[",
"static",
"::",
"CONTEXT_GZIP",
"]",
":",
"null",
";",
"$",
"base64",
"=",
"isset",
"(",
"$",
"context",
"[",
"static",
"::",
"CONTEXT_BASE64",
"]",
")",
"?",
"$",
"context",
"[",
"static",
"::",
"CONTEXT_BASE64",
"]",
":",
"null",
";",
"$",
"base64",
"=",
"(",
"$",
"base64",
"!==",
"null",
")",
"?",
"$",
"base64",
":",
"strpos",
"(",
"$",
"mime",
",",
"'/octet-stream'",
")",
"!==",
"false",
";",
"$",
"urlencode",
"=",
"isset",
"(",
"$",
"context",
"[",
"static",
"::",
"CONTEXT_URLENCODE",
"]",
")",
"?",
"$",
"context",
"[",
"static",
"::",
"CONTEXT_URLENCODE",
"]",
":",
"null",
";",
"$",
"urlencode",
"=",
"(",
"$",
"urlencode",
"!==",
"null",
")",
"?",
"$",
"urlencode",
":",
"strpos",
"(",
"$",
"mime",
",",
"'text/'",
")",
"!==",
"false",
";",
"if",
"(",
"$",
"gzip",
")",
"{",
"$",
"string",
"=",
"gzencode",
"(",
"$",
"string",
")",
";",
"$",
"mime",
"=",
"'application/x-gzip'",
";",
"}",
"if",
"(",
"$",
"urlencode",
"and",
"!",
"$",
"base64",
")",
"{",
"$",
"string",
"=",
"urlencode",
"(",
"$",
"string",
")",
";",
"}",
"if",
"(",
"$",
"base64",
"or",
"!",
"$",
"urlencode",
")",
"{",
"$",
"string",
"=",
"base64_encode",
"(",
"$",
"string",
")",
";",
"}",
"$",
"options",
"=",
"$",
"mime",
";",
"if",
"(",
"$",
"charset",
"and",
"$",
"mime",
")",
"{",
"$",
"options",
".=",
"';charset='",
".",
"$",
"charset",
";",
"}",
"if",
"(",
"$",
"base64",
")",
"{",
"$",
"options",
".=",
"';base64'",
";",
"}",
"return",
"sprintf",
"(",
"'data:%s,%s'",
",",
"$",
"options",
",",
"$",
"string",
")",
";",
"}"
]
| @param object|string $string
@param string $format
@param array $context
@return array|bool|float|int|null|string | [
"@param",
"object|string",
"$string",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/BinaryNormalizer.php#L86-L116 |
mihai-stancu/serializer | Serializer/Normalizer/BinaryNormalizer.php | BinaryNormalizer.denormalize | public function denormalize($string, $class, $format = null, array $context = array())
{
if (!preg_match(static::FULL_REGEX, $string, $matches)) {
throw new \InvalidArgumentException('The provided "data:" URI is not valid.');
}
$mime = !empty($matches[static::CONTEXT_MIME]) ? $matches[static::CONTEXT_MIME] : 'application/octet-stream';
$charset = !empty($matches[static::CONTEXT_CHARSET]) ? $matches[static::CONTEXT_CHARSET] : null;
$gzip = strpos($mime, 'gzip') !== false;
$base64 = !empty($matches[static::CONTEXT_BASE64]) ? $matches[static::CONTEXT_BASE64] : null;
$urldecode = strpos($mime, 'text/') !== false;
$string = $matches[static::CONTEXT_DATA];
if ($base64) {
$string = base64_decode($string);
}
if ($gzip) {
$string = gzdecode($string);
}
if ($urldecode or !$base64) {
$string = urldecode($string);
}
return $string;
} | php | public function denormalize($string, $class, $format = null, array $context = array())
{
if (!preg_match(static::FULL_REGEX, $string, $matches)) {
throw new \InvalidArgumentException('The provided "data:" URI is not valid.');
}
$mime = !empty($matches[static::CONTEXT_MIME]) ? $matches[static::CONTEXT_MIME] : 'application/octet-stream';
$charset = !empty($matches[static::CONTEXT_CHARSET]) ? $matches[static::CONTEXT_CHARSET] : null;
$gzip = strpos($mime, 'gzip') !== false;
$base64 = !empty($matches[static::CONTEXT_BASE64]) ? $matches[static::CONTEXT_BASE64] : null;
$urldecode = strpos($mime, 'text/') !== false;
$string = $matches[static::CONTEXT_DATA];
if ($base64) {
$string = base64_decode($string);
}
if ($gzip) {
$string = gzdecode($string);
}
if ($urldecode or !$base64) {
$string = urldecode($string);
}
return $string;
} | [
"public",
"function",
"denormalize",
"(",
"$",
"string",
",",
"$",
"class",
",",
"$",
"format",
"=",
"null",
",",
"array",
"$",
"context",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"preg_match",
"(",
"static",
"::",
"FULL_REGEX",
",",
"$",
"string",
",",
"$",
"matches",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'The provided \"data:\" URI is not valid.'",
")",
";",
"}",
"$",
"mime",
"=",
"!",
"empty",
"(",
"$",
"matches",
"[",
"static",
"::",
"CONTEXT_MIME",
"]",
")",
"?",
"$",
"matches",
"[",
"static",
"::",
"CONTEXT_MIME",
"]",
":",
"'application/octet-stream'",
";",
"$",
"charset",
"=",
"!",
"empty",
"(",
"$",
"matches",
"[",
"static",
"::",
"CONTEXT_CHARSET",
"]",
")",
"?",
"$",
"matches",
"[",
"static",
"::",
"CONTEXT_CHARSET",
"]",
":",
"null",
";",
"$",
"gzip",
"=",
"strpos",
"(",
"$",
"mime",
",",
"'gzip'",
")",
"!==",
"false",
";",
"$",
"base64",
"=",
"!",
"empty",
"(",
"$",
"matches",
"[",
"static",
"::",
"CONTEXT_BASE64",
"]",
")",
"?",
"$",
"matches",
"[",
"static",
"::",
"CONTEXT_BASE64",
"]",
":",
"null",
";",
"$",
"urldecode",
"=",
"strpos",
"(",
"$",
"mime",
",",
"'text/'",
")",
"!==",
"false",
";",
"$",
"string",
"=",
"$",
"matches",
"[",
"static",
"::",
"CONTEXT_DATA",
"]",
";",
"if",
"(",
"$",
"base64",
")",
"{",
"$",
"string",
"=",
"base64_decode",
"(",
"$",
"string",
")",
";",
"}",
"if",
"(",
"$",
"gzip",
")",
"{",
"$",
"string",
"=",
"gzdecode",
"(",
"$",
"string",
")",
";",
"}",
"if",
"(",
"$",
"urldecode",
"or",
"!",
"$",
"base64",
")",
"{",
"$",
"string",
"=",
"urldecode",
"(",
"$",
"string",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
]
| @param string $string
@param string $class
@param string $format
@param array $context
@return \SplFileObject | [
"@param",
"string",
"$string",
"@param",
"string",
"$class",
"@param",
"string",
"$format",
"@param",
"array",
"$context"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/BinaryNormalizer.php#L137-L162 |
mihai-stancu/serializer | Serializer/Normalizer/BinaryNormalizer.php | BinaryNormalizer.supportsDenormalization | public function supportsDenormalization($data, $type, $format = null)
{
return in_array($type, static::$types)
and is_string($data) and preg_match(static::SIMPLE_REGEX, $data) > 0;
} | php | public function supportsDenormalization($data, $type, $format = null)
{
return in_array($type, static::$types)
and is_string($data) and preg_match(static::SIMPLE_REGEX, $data) > 0;
} | [
"public",
"function",
"supportsDenormalization",
"(",
"$",
"data",
",",
"$",
"type",
",",
"$",
"format",
"=",
"null",
")",
"{",
"return",
"in_array",
"(",
"$",
"type",
",",
"static",
"::",
"$",
"types",
")",
"and",
"is_string",
"(",
"$",
"data",
")",
"and",
"preg_match",
"(",
"static",
"::",
"SIMPLE_REGEX",
",",
"$",
"data",
")",
">",
"0",
";",
"}"
]
| @param mixed $data
@param string $type
@param string $format
@return bool | [
"@param",
"mixed",
"$data",
"@param",
"string",
"$type",
"@param",
"string",
"$format"
]
| train | https://github.com/mihai-stancu/serializer/blob/4d96f942a3c44d5b5652868be726af656bf1baad/Serializer/Normalizer/BinaryNormalizer.php#L171-L175 |
vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.attempt | public function attempt(array $credentials = [], $remember = false, $login = true)
{
if (!array_key_exists('namespace', $credentials)) {
$credentials['namespace'] = '';
}
return parent::attempt($credentials, $remember, $login);
} | php | public function attempt(array $credentials = [], $remember = false, $login = true)
{
if (!array_key_exists('namespace', $credentials)) {
$credentials['namespace'] = '';
}
return parent::attempt($credentials, $remember, $login);
} | [
"public",
"function",
"attempt",
"(",
"array",
"$",
"credentials",
"=",
"[",
"]",
",",
"$",
"remember",
"=",
"false",
",",
"$",
"login",
"=",
"true",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'namespace'",
",",
"$",
"credentials",
")",
")",
"{",
"$",
"credentials",
"[",
"'namespace'",
"]",
"=",
"''",
";",
"}",
"return",
"parent",
"::",
"attempt",
"(",
"$",
"credentials",
",",
"$",
"remember",
",",
"$",
"login",
")",
";",
"}"
]
| {@inheritDoc} | [
"{"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L33-L40 |
vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.hasGroup | public function hasGroup($group)
{
if ($this->user() === null) {
return null;
}
return in_array($group, $this->groups, true);
} | php | public function hasGroup($group)
{
if ($this->user() === null) {
return null;
}
return in_array($group, $this->groups, true);
} | [
"public",
"function",
"hasGroup",
"(",
"$",
"group",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"in_array",
"(",
"$",
"group",
",",
"$",
"this",
"->",
"groups",
",",
"true",
")",
";",
"}"
]
| Check if authenticate user has group
@param string $group
@return bool|null return NULL if user is not authenticated | [
"Check",
"if",
"authenticate",
"user",
"has",
"group"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L49-L56 |
vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.hasGroups | public function hasGroups($groups)
{
if ($this->user() === null) {
return null;
}
if (!is_array($groups)) {
$groups = func_get_args();
}
// Count roles because user need user to have all roles passed as parameter
return count(array_intersect($groups, $this->groups)) === count($groups);
} | php | public function hasGroups($groups)
{
if ($this->user() === null) {
return null;
}
if (!is_array($groups)) {
$groups = func_get_args();
}
// Count roles because user need user to have all roles passed as parameter
return count(array_intersect($groups, $this->groups)) === count($groups);
} | [
"public",
"function",
"hasGroups",
"(",
"$",
"groups",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"groups",
")",
")",
"{",
"$",
"groups",
"=",
"func_get_args",
"(",
")",
";",
"}",
"// Count roles because user need user to have all roles passed as parameter",
"return",
"count",
"(",
"array_intersect",
"(",
"$",
"groups",
",",
"$",
"this",
"->",
"groups",
")",
")",
"===",
"count",
"(",
"$",
"groups",
")",
";",
"}"
]
| Check if authenticated user has all groups passed by parameter
@param string[] $groups
@return bool|null return NULL if user is not authenticated | [
"Check",
"if",
"authenticated",
"user",
"has",
"all",
"groups",
"passed",
"by",
"parameter"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L65-L77 |
vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.hasRole | public function hasRole($role)
{
if ($this->user() === null) {
return null;
}
return in_array($role, $this->roles, true);
} | php | public function hasRole($role)
{
if ($this->user() === null) {
return null;
}
return in_array($role, $this->roles, true);
} | [
"public",
"function",
"hasRole",
"(",
"$",
"role",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"in_array",
"(",
"$",
"role",
",",
"$",
"this",
"->",
"roles",
",",
"true",
")",
";",
"}"
]
| Check if authenticate user has role
@param string $role
@return bool|null return NULL if user is not authenticated | [
"Check",
"if",
"authenticate",
"user",
"has",
"role"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L86-L93 |
vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.hasRoles | public function hasRoles($roles)
{
if ($this->user() === null) {
return null;
}
if (!is_array($roles)) {
$roles = func_get_args();
}
// Count roles because user need user to have all roles passed as parameter
return count(array_intersect($roles, $this->roles)) === count($roles);
} | php | public function hasRoles($roles)
{
if ($this->user() === null) {
return null;
}
if (!is_array($roles)) {
$roles = func_get_args();
}
// Count roles because user need user to have all roles passed as parameter
return count(array_intersect($roles, $this->roles)) === count($roles);
} | [
"public",
"function",
"hasRoles",
"(",
"$",
"roles",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"roles",
")",
")",
"{",
"$",
"roles",
"=",
"func_get_args",
"(",
")",
";",
"}",
"// Count roles because user need user to have all roles passed as parameter",
"return",
"count",
"(",
"array_intersect",
"(",
"$",
"roles",
",",
"$",
"this",
"->",
"roles",
")",
")",
"===",
"count",
"(",
"$",
"roles",
")",
";",
"}"
]
| Check if authenticated user has all roles passed by parameter
@param string[] $roles
@return bool|null return NULL if user is not authenticated | [
"Check",
"if",
"authenticated",
"user",
"has",
"all",
"roles",
"passed",
"by",
"parameter"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L102-L114 |
vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.hasPermission | public function hasPermission($permission)
{
if ($this->user() === null) {
return null;
}
return in_array($permission, $this->permissions, true);
} | php | public function hasPermission($permission)
{
if ($this->user() === null) {
return null;
}
return in_array($permission, $this->permissions, true);
} | [
"public",
"function",
"hasPermission",
"(",
"$",
"permission",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"return",
"in_array",
"(",
"$",
"permission",
",",
"$",
"this",
"->",
"permissions",
",",
"true",
")",
";",
"}"
]
| Check if authenticated user has permission
@param string $permission
@return bool|null return NULL if user is not authenticated | [
"Check",
"if",
"authenticated",
"user",
"has",
"permission"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L123-L130 |
vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.hasPermissions | public function hasPermissions($permissions)
{
if ($this->user() === null) {
return null;
}
if (!is_array($permissions)) {
$permissions = func_get_args();
}
// Count permissions because user need user to have all permissions passed as parameter
return count(array_intersect($permissions, $this->permissions)) === count($permissions);
} | php | public function hasPermissions($permissions)
{
if ($this->user() === null) {
return null;
}
if (!is_array($permissions)) {
$permissions = func_get_args();
}
// Count permissions because user need user to have all permissions passed as parameter
return count(array_intersect($permissions, $this->permissions)) === count($permissions);
} | [
"public",
"function",
"hasPermissions",
"(",
"$",
"permissions",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"permissions",
")",
")",
"{",
"$",
"permissions",
"=",
"func_get_args",
"(",
")",
";",
"}",
"// Count permissions because user need user to have all permissions passed as parameter",
"return",
"count",
"(",
"array_intersect",
"(",
"$",
"permissions",
",",
"$",
"this",
"->",
"permissions",
")",
")",
"===",
"count",
"(",
"$",
"permissions",
")",
";",
"}"
]
| Check if authenticated user has all permission passed by parameter
@param string[] $permissions
@return bool|null return NULL if user is not authenticated | [
"Check",
"if",
"authenticated",
"user",
"has",
"all",
"permission",
"passed",
"by",
"parameter"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L139-L151 |
vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.user | public function user()
{
$user = parent::user();
// Load roles if user is set first time
if ($user !== null && ($this->roles === null || $this->permissions === null)) {
$this->groups = [];
$this->roles = [];
$this->permissions = [];
// Load roles only if User model is permission based user
if ($user instanceof User) {
$this->addGroups($user->groups);
$this->addRoles($user->roles);
$this->addPermissions($user->permissions);
$this->roles = array_unique($this->roles);
$this->permissions = array_unique($this->permissions);
}
}
return $user;
} | php | public function user()
{
$user = parent::user();
// Load roles if user is set first time
if ($user !== null && ($this->roles === null || $this->permissions === null)) {
$this->groups = [];
$this->roles = [];
$this->permissions = [];
// Load roles only if User model is permission based user
if ($user instanceof User) {
$this->addGroups($user->groups);
$this->addRoles($user->roles);
$this->addPermissions($user->permissions);
$this->roles = array_unique($this->roles);
$this->permissions = array_unique($this->permissions);
}
}
return $user;
} | [
"public",
"function",
"user",
"(",
")",
"{",
"$",
"user",
"=",
"parent",
"::",
"user",
"(",
")",
";",
"// Load roles if user is set first time",
"if",
"(",
"$",
"user",
"!==",
"null",
"&&",
"(",
"$",
"this",
"->",
"roles",
"===",
"null",
"||",
"$",
"this",
"->",
"permissions",
"===",
"null",
")",
")",
"{",
"$",
"this",
"->",
"groups",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"roles",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"permissions",
"=",
"[",
"]",
";",
"// Load roles only if User model is permission based user",
"if",
"(",
"$",
"user",
"instanceof",
"User",
")",
"{",
"$",
"this",
"->",
"addGroups",
"(",
"$",
"user",
"->",
"groups",
")",
";",
"$",
"this",
"->",
"addRoles",
"(",
"$",
"user",
"->",
"roles",
")",
";",
"$",
"this",
"->",
"addPermissions",
"(",
"$",
"user",
"->",
"permissions",
")",
";",
"$",
"this",
"->",
"roles",
"=",
"array_unique",
"(",
"$",
"this",
"->",
"roles",
")",
";",
"$",
"this",
"->",
"permissions",
"=",
"array_unique",
"(",
"$",
"this",
"->",
"permissions",
")",
";",
"}",
"}",
"return",
"$",
"user",
";",
"}"
]
| {@inheritDoc}
@return \ViKon\Auth\Model\User|null | [
"{",
"@inheritDoc",
"}"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L158-L180 |
vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.logout | public function logout()
{
parent::logout();
$this->groups = null;
$this->roles = null;
$this->permissions = null;
} | php | public function logout()
{
parent::logout();
$this->groups = null;
$this->roles = null;
$this->permissions = null;
} | [
"public",
"function",
"logout",
"(",
")",
"{",
"parent",
"::",
"logout",
"(",
")",
";",
"$",
"this",
"->",
"groups",
"=",
"null",
";",
"$",
"this",
"->",
"roles",
"=",
"null",
";",
"$",
"this",
"->",
"permissions",
"=",
"null",
";",
"}"
]
| {@inheritDoc} | [
"{"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L185-L192 |
vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.isBlocked | public function isBlocked()
{
if ($this->user() === null) {
return null;
}
// Check user blocking status only if User model is role based user
if ($this->user instanceof User) {
return $this->user->blocked;
}
return false;
} | php | public function isBlocked()
{
if ($this->user() === null) {
return null;
}
// Check user blocking status only if User model is role based user
if ($this->user instanceof User) {
return $this->user->blocked;
}
return false;
} | [
"public",
"function",
"isBlocked",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"user",
"(",
")",
"===",
"null",
")",
"{",
"return",
"null",
";",
"}",
"// Check user blocking status only if User model is role based user",
"if",
"(",
"$",
"this",
"->",
"user",
"instanceof",
"User",
")",
"{",
"return",
"$",
"this",
"->",
"user",
"->",
"blocked",
";",
"}",
"return",
"false",
";",
"}"
]
| Return if current user is blocked
If user is not role based user, then always return false
@return bool|null return NULL if user is not authenticated | [
"Return",
"if",
"current",
"user",
"is",
"blocked"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L201-L213 |
vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.addGroups | protected function addGroups(Collection $groups)
{
foreach ($groups as $group) {
$this->groups[] = $group->token;
$this->addRoles($group->roles);
$this->addPermissions($group->permissions);
}
} | php | protected function addGroups(Collection $groups)
{
foreach ($groups as $group) {
$this->groups[] = $group->token;
$this->addRoles($group->roles);
$this->addPermissions($group->permissions);
}
} | [
"protected",
"function",
"addGroups",
"(",
"Collection",
"$",
"groups",
")",
"{",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"group",
")",
"{",
"$",
"this",
"->",
"groups",
"[",
"]",
"=",
"$",
"group",
"->",
"token",
";",
"$",
"this",
"->",
"addRoles",
"(",
"$",
"group",
"->",
"roles",
")",
";",
"$",
"this",
"->",
"addPermissions",
"(",
"$",
"group",
"->",
"permissions",
")",
";",
"}",
"}"
]
| @param \Illuminate\Database\Eloquent\Collection|\ViKon\Auth\Model\Group[] $groups
@return void | [
"@param",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Eloquent",
"\\",
"Collection|",
"\\",
"ViKon",
"\\",
"Auth",
"\\",
"Model",
"\\",
"Group",
"[]",
"$groups"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L220-L227 |
vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.addRoles | protected function addRoles(Collection $roles)
{
foreach ($roles as $role) {
$this->roles[] = $role->token;
$this->addPermissions($role->permissions);
}
} | php | protected function addRoles(Collection $roles)
{
foreach ($roles as $role) {
$this->roles[] = $role->token;
$this->addPermissions($role->permissions);
}
} | [
"protected",
"function",
"addRoles",
"(",
"Collection",
"$",
"roles",
")",
"{",
"foreach",
"(",
"$",
"roles",
"as",
"$",
"role",
")",
"{",
"$",
"this",
"->",
"roles",
"[",
"]",
"=",
"$",
"role",
"->",
"token",
";",
"$",
"this",
"->",
"addPermissions",
"(",
"$",
"role",
"->",
"permissions",
")",
";",
"}",
"}"
]
| @param \Illuminate\Database\Eloquent\Collection|\ViKon\Auth\Model\Role[] $roles
@return void | [
"@param",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Eloquent",
"\\",
"Collection|",
"\\",
"ViKon",
"\\",
"Auth",
"\\",
"Model",
"\\",
"Role",
"[]",
"$roles"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L234-L240 |
vi-kon/laravel-auth | src/ViKon/Auth/Guard.php | Guard.addPermissions | protected function addPermissions(Collection $permissions)
{
foreach ($permissions as $permission) {
$this->permissions[] = $permission->token;
}
} | php | protected function addPermissions(Collection $permissions)
{
foreach ($permissions as $permission) {
$this->permissions[] = $permission->token;
}
} | [
"protected",
"function",
"addPermissions",
"(",
"Collection",
"$",
"permissions",
")",
"{",
"foreach",
"(",
"$",
"permissions",
"as",
"$",
"permission",
")",
"{",
"$",
"this",
"->",
"permissions",
"[",
"]",
"=",
"$",
"permission",
"->",
"token",
";",
"}",
"}"
]
| @param \Illuminate\Database\Eloquent\Collection|\ViKon\Auth\Model\Permission[] $permissions
@return void | [
"@param",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Eloquent",
"\\",
"Collection|",
"\\",
"ViKon",
"\\",
"Auth",
"\\",
"Model",
"\\",
"Permission",
"[]",
"$permissions"
]
| train | https://github.com/vi-kon/laravel-auth/blob/501c20128f43347a2ca271a53435297f9ef7f567/src/ViKon/Auth/Guard.php#L247-L252 |
tompedals/helpscout-dynamic-app | src/AppAction.php | AppAction.respondWithJson | private function respondWithJson(ResponseInterface $response, array $data, $status)
{
$body = $response->getBody();
$body->rewind();
$body->write(json_encode($data));
$response = $response->withStatus($status);
$response = $response->withHeader('Content-Type', 'application/json;charset=utf-8');
return $response;
} | php | private function respondWithJson(ResponseInterface $response, array $data, $status)
{
$body = $response->getBody();
$body->rewind();
$body->write(json_encode($data));
$response = $response->withStatus($status);
$response = $response->withHeader('Content-Type', 'application/json;charset=utf-8');
return $response;
} | [
"private",
"function",
"respondWithJson",
"(",
"ResponseInterface",
"$",
"response",
",",
"array",
"$",
"data",
",",
"$",
"status",
")",
"{",
"$",
"body",
"=",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"$",
"body",
"->",
"rewind",
"(",
")",
";",
"$",
"body",
"->",
"write",
"(",
"json_encode",
"(",
"$",
"data",
")",
")",
";",
"$",
"response",
"=",
"$",
"response",
"->",
"withStatus",
"(",
"$",
"status",
")",
";",
"$",
"response",
"=",
"$",
"response",
"->",
"withHeader",
"(",
"'Content-Type'",
",",
"'application/json;charset=utf-8'",
")",
";",
"return",
"$",
"response",
";",
"}"
]
| @param ResponseInterface $response
@param array $data
@param int $status
@return ResponseInterface | [
"@param",
"ResponseInterface",
"$response",
"@param",
"array",
"$data",
"@param",
"int",
"$status"
]
| train | https://github.com/tompedals/helpscout-dynamic-app/blob/450d660db402a6aced0f541b71b89a0fc44d303a/src/AppAction.php#L64-L74 |
nexusnetsoftgmbh/nexuscli | src/Nexus/DockerClient/DockerClientDependencyProvider.php | DockerClientDependencyProvider.handleDependencies | public function handleDependencies(DependencyContainerInterface $container): DependencyContainerInterface
{
$container = $this->addShellFacade($container);
$container = $this->addCommandList($container);
return $container;
} | php | public function handleDependencies(DependencyContainerInterface $container): DependencyContainerInterface
{
$container = $this->addShellFacade($container);
$container = $this->addCommandList($container);
return $container;
} | [
"public",
"function",
"handleDependencies",
"(",
"DependencyContainerInterface",
"$",
"container",
")",
":",
"DependencyContainerInterface",
"{",
"$",
"container",
"=",
"$",
"this",
"->",
"addShellFacade",
"(",
"$",
"container",
")",
";",
"$",
"container",
"=",
"$",
"this",
"->",
"addCommandList",
"(",
"$",
"container",
")",
";",
"return",
"$",
"container",
";",
"}"
]
| @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container
@return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface | [
"@param",
"\\",
"Xervice",
"\\",
"Core",
"\\",
"Business",
"\\",
"Model",
"\\",
"Dependency",
"\\",
"DependencyContainerInterface",
"$container"
]
| train | https://github.com/nexusnetsoftgmbh/nexuscli/blob/8416b43d31ad56ea379ae2b0bf85d456e78ba67a/src/Nexus/DockerClient/DockerClientDependencyProvider.php#L31-L37 |
nexusnetsoftgmbh/nexuscli | src/Nexus/DockerClient/DockerClientDependencyProvider.php | DockerClientDependencyProvider.addShellFacade | private function addShellFacade(DependencyContainerInterface $container): DependencyContainerInterface
{
$container[self::SHELL_FACADE] = function (DependencyContainerInterface $container) {
return $container->getLocator()->shell()->facade();
};
return $container;
} | php | private function addShellFacade(DependencyContainerInterface $container): DependencyContainerInterface
{
$container[self::SHELL_FACADE] = function (DependencyContainerInterface $container) {
return $container->getLocator()->shell()->facade();
};
return $container;
} | [
"private",
"function",
"addShellFacade",
"(",
"DependencyContainerInterface",
"$",
"container",
")",
":",
"DependencyContainerInterface",
"{",
"$",
"container",
"[",
"self",
"::",
"SHELL_FACADE",
"]",
"=",
"function",
"(",
"DependencyContainerInterface",
"$",
"container",
")",
"{",
"return",
"$",
"container",
"->",
"getLocator",
"(",
")",
"->",
"shell",
"(",
")",
"->",
"facade",
"(",
")",
";",
"}",
";",
"return",
"$",
"container",
";",
"}"
]
| @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container
@return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface | [
"@param",
"\\",
"Xervice",
"\\",
"Core",
"\\",
"Business",
"\\",
"Model",
"\\",
"Dependency",
"\\",
"DependencyContainerInterface",
"$container"
]
| train | https://github.com/nexusnetsoftgmbh/nexuscli/blob/8416b43d31ad56ea379ae2b0bf85d456e78ba67a/src/Nexus/DockerClient/DockerClientDependencyProvider.php#L66-L73 |
nexusnetsoftgmbh/nexuscli | src/Nexus/DockerClient/DockerClientDependencyProvider.php | DockerClientDependencyProvider.addCommandList | protected function addCommandList(
DependencyContainerInterface $container
): DependencyContainerInterface {
$container[self::COMMAND_LIST] = function (DependencyContainerInterface $container) {
return $this->getCommandList();
};
return $container;
} | php | protected function addCommandList(
DependencyContainerInterface $container
): DependencyContainerInterface {
$container[self::COMMAND_LIST] = function (DependencyContainerInterface $container) {
return $this->getCommandList();
};
return $container;
} | [
"protected",
"function",
"addCommandList",
"(",
"DependencyContainerInterface",
"$",
"container",
")",
":",
"DependencyContainerInterface",
"{",
"$",
"container",
"[",
"self",
"::",
"COMMAND_LIST",
"]",
"=",
"function",
"(",
"DependencyContainerInterface",
"$",
"container",
")",
"{",
"return",
"$",
"this",
"->",
"getCommandList",
"(",
")",
";",
"}",
";",
"return",
"$",
"container",
";",
"}"
]
| @param \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface $container
@return \Xervice\Core\Business\Model\Dependency\DependencyContainerInterface | [
"@param",
"\\",
"Xervice",
"\\",
"Core",
"\\",
"Business",
"\\",
"Model",
"\\",
"Dependency",
"\\",
"DependencyContainerInterface",
"$container"
]
| train | https://github.com/nexusnetsoftgmbh/nexuscli/blob/8416b43d31ad56ea379ae2b0bf85d456e78ba67a/src/Nexus/DockerClient/DockerClientDependencyProvider.php#L80-L88 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.