repo stringlengths 6 63 | path stringlengths 5 140 | func_name stringlengths 3 151 | original_string stringlengths 84 13k | language stringclasses 1
value | code stringlengths 84 13k | code_tokens list | docstring stringlengths 3 47.2k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 91 247 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
hail-framework/framework | src/Application.php | Application.param | public function param(string $name, $value = null)
{
if ($value === null) {
return $this->params[$name] ?? null;
}
return $this->params[$name] = $value;
} | php | public function param(string $name, $value = null)
{
if ($value === null) {
return $this->params[$name] ?? null;
}
return $this->params[$name] = $value;
} | [
"public",
"function",
"param",
"(",
"string",
"$",
"name",
",",
"$",
"value",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"value",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"params",
"[",
"$",
"name",
"]",
"??",
"null",
";",
"}",
"return",... | Get param from router
@param string $name
@param mixed $value
@return mixed|null | [
"Get",
"param",
"from",
"router"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Application.php#L258-L265 | train |
hail-framework/framework | src/Util/Closure/Serializer.php | Serializer.serialize | public static function serialize(\Closure $closure, string $type = null): string
{
self::$serializeType = $type;
$serialized = Serialize::encode(new SerializableClosure($closure), $type);
if ($serialized === null) {
throw new \RuntimeException('The closure could not be serialized.');
}
return $serialized;
} | php | public static function serialize(\Closure $closure, string $type = null): string
{
self::$serializeType = $type;
$serialized = Serialize::encode(new SerializableClosure($closure), $type);
if ($serialized === null) {
throw new \RuntimeException('The closure could not be serialized.');
}
return $serialized;
} | [
"public",
"static",
"function",
"serialize",
"(",
"\\",
"Closure",
"$",
"closure",
",",
"string",
"$",
"type",
"=",
"null",
")",
":",
"string",
"{",
"self",
"::",
"$",
"serializeType",
"=",
"$",
"type",
";",
"$",
"serialized",
"=",
"Serialize",
"::",
"... | Takes a Closure object, decorates it with a SerializableClosure object,
then performs the serialization.
@param \Closure $closure Closure to serialize.
@param string|null $type
@return string Serialized closure.
@throws \RuntimeException | [
"Takes",
"a",
"Closure",
"object",
"decorates",
"it",
"with",
"a",
"SerializableClosure",
"object",
"then",
"performs",
"the",
"serialization",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Closure/Serializer.php#L55-L66 | train |
hail-framework/framework | src/Util/Closure/Serializer.php | Serializer.unserialize | public static function unserialize($serialized, string $type = null): \Closure
{
self::$serializeType = $type;
$unserialized = Serialize::decode($serialized, $type);
if (!$unserialized instanceof SerializableClosure) {
throw new \RuntimeException(
'The closure did not unserialize to a SuperClosure.'
);
}
return $unserialized->getClosure();
} | php | public static function unserialize($serialized, string $type = null): \Closure
{
self::$serializeType = $type;
$unserialized = Serialize::decode($serialized, $type);
if (!$unserialized instanceof SerializableClosure) {
throw new \RuntimeException(
'The closure did not unserialize to a SuperClosure.'
);
}
return $unserialized->getClosure();
} | [
"public",
"static",
"function",
"unserialize",
"(",
"$",
"serialized",
",",
"string",
"$",
"type",
"=",
"null",
")",
":",
"\\",
"Closure",
"{",
"self",
"::",
"$",
"serializeType",
"=",
"$",
"type",
";",
"$",
"unserialized",
"=",
"Serialize",
"::",
"decod... | Takes a serialized closure, performs the unserialization, and then
extracts and returns a the Closure object.
@param string $serialized Serialized closure.
@param string|null $type
@throws \RuntimeException if unserialization fails.
@return \Closure Unserialized closure. | [
"Takes",
"a",
"serialized",
"closure",
"performs",
"the",
"unserialization",
"and",
"then",
"extracts",
"and",
"returns",
"a",
"the",
"Closure",
"object",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Closure/Serializer.php#L78-L90 | train |
hail-framework/framework | src/Util/Closure/Serializer.php | Serializer.analyze | private static function analyze(\Closure $closure)
{
$reflection = new ReflectionClosure($closure);
$scope = $reflection->getClosureScopeClass();
$data = [
'reflection' => $reflection,
'code' => $reflection->getCode(),
'hasThis' => $reflection->isBindingRequired(),
'context' => $reflection->getUseVariables(),
'hasRefs' => false,
'binding' => $reflection->getClosureThis(),
'scope' => $scope ? $scope->getName() : null,
'isStatic' => $reflection->isStatic(),
];
return $data;
} | php | private static function analyze(\Closure $closure)
{
$reflection = new ReflectionClosure($closure);
$scope = $reflection->getClosureScopeClass();
$data = [
'reflection' => $reflection,
'code' => $reflection->getCode(),
'hasThis' => $reflection->isBindingRequired(),
'context' => $reflection->getUseVariables(),
'hasRefs' => false,
'binding' => $reflection->getClosureThis(),
'scope' => $scope ? $scope->getName() : null,
'isStatic' => $reflection->isStatic(),
];
return $data;
} | [
"private",
"static",
"function",
"analyze",
"(",
"\\",
"Closure",
"$",
"closure",
")",
"{",
"$",
"reflection",
"=",
"new",
"ReflectionClosure",
"(",
"$",
"closure",
")",
";",
"$",
"scope",
"=",
"$",
"reflection",
"->",
"getClosureScopeClass",
"(",
")",
";"... | Analyzer a given closure.
@param \Closure $closure
@return array | [
"Analyzer",
"a",
"given",
"closure",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Closure/Serializer.php#L184-L201 | train |
hail-framework/framework | src/I18n/I18n.php | I18n.translator | public function translator(string $locale, string $domain, string $directory): ?TranslatorInterface
{
$class = GETTEXT_EXTENSION ? GettextTranslator::class : Translator::class;
$previous = self::$translator;
self::$translator = new $class($locale, $domain, $directory);
if ($previous === null) {
require __DIR__ . DIRECTORY_SEPARATOR . 'helpers.php';
}
$this->locale = $locale;
return $previous;
} | php | public function translator(string $locale, string $domain, string $directory): ?TranslatorInterface
{
$class = GETTEXT_EXTENSION ? GettextTranslator::class : Translator::class;
$previous = self::$translator;
self::$translator = new $class($locale, $domain, $directory);
if ($previous === null) {
require __DIR__ . DIRECTORY_SEPARATOR . 'helpers.php';
}
$this->locale = $locale;
return $previous;
} | [
"public",
"function",
"translator",
"(",
"string",
"$",
"locale",
",",
"string",
"$",
"domain",
",",
"string",
"$",
"directory",
")",
":",
"?",
"TranslatorInterface",
"{",
"$",
"class",
"=",
"GETTEXT_EXTENSION",
"?",
"GettextTranslator",
"::",
"class",
":",
... | Initialize a new gettext class
@param string $directory
@param string $domain
@param string $locale
@return TranslatorInterface|null | [
"Initialize",
"a",
"new",
"gettext",
"class"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/I18n/I18n.php#L44-L58 | train |
Kajna/K-Core | Core/Database/MSSqlDatabase.php | MSSqlDatabase.query | public function query($query, array $params = [])
{
// Execute query
$stmt = $this->connection->prepare($query);
$stmt->execute($params);
// Return result resource variable
return $stmt;
} | php | public function query($query, array $params = [])
{
// Execute query
$stmt = $this->connection->prepare($query);
$stmt->execute($params);
// Return result resource variable
return $stmt;
} | [
"public",
"function",
"query",
"(",
"$",
"query",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"// Execute query",
"$",
"stmt",
"=",
"$",
"this",
"->",
"connection",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"stmt",
"->",
"execute",... | Classic query method using prepared statements.
@param string $query
@param array $params
@return \PDOStatement|resource | [
"Classic",
"query",
"method",
"using",
"prepared",
"statements",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Database/MSSqlDatabase.php#L71-L78 | train |
Kajna/K-Core | Core/Database/MSSqlDatabase.php | MSSqlDatabase.delete | public function delete($query, array $params = [])
{
$stmt = $this->connection->prepare($query);
$stmt->execute($params);
return $stmt->rowCount();
} | php | public function delete($query, array $params = [])
{
$stmt = $this->connection->prepare($query);
$stmt->execute($params);
return $stmt->rowCount();
} | [
"public",
"function",
"delete",
"(",
"$",
"query",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"connection",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"$",
"par... | Delete query.
@param string $query
@param array $params
@return int | [
"Delete",
"query",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Database/MSSqlDatabase.php#L156-L161 | train |
Kajna/K-Core | Core/Database/MSSqlDatabase.php | MSSqlDatabase.count | public function count($query, array $params = [])
{
$stmt = $this->connection->prepare($query);
$stmt->execute($params);
return $stmt->fetchColumn();
} | php | public function count($query, array $params = [])
{
$stmt = $this->connection->prepare($query);
$stmt->execute($params);
return $stmt->fetchColumn();
} | [
"public",
"function",
"count",
"(",
"$",
"query",
",",
"array",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"$",
"stmt",
"=",
"$",
"this",
"->",
"connection",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"$",
"stmt",
"->",
"execute",
"(",
"$",
"para... | Count query.
@param string $query
@param array $params
@return int | [
"Count",
"query",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Database/MSSqlDatabase.php#L170-L175 | train |
Kajna/K-Core | Core/Database/MSSqlDatabase.php | MSSqlDatabase.addIndex | public function addIndex($table, $column, $name)
{
$sql = sprintf('ALTER TABLE %s ADD INDEX %s(%s)', $table, $name, $column);
// Execute query
$stmt = $this->connection->prepare($sql);
return $stmt->execute();
} | php | public function addIndex($table, $column, $name)
{
$sql = sprintf('ALTER TABLE %s ADD INDEX %s(%s)', $table, $name, $column);
// Execute query
$stmt = $this->connection->prepare($sql);
return $stmt->execute();
} | [
"public",
"function",
"addIndex",
"(",
"$",
"table",
",",
"$",
"column",
",",
"$",
"name",
")",
"{",
"$",
"sql",
"=",
"sprintf",
"(",
"'ALTER TABLE %s ADD INDEX %s(%s)'",
",",
"$",
"table",
",",
"$",
"name",
",",
"$",
"column",
")",
";",
"// Execute quer... | Add index to table column.
@param string $table
@param string $column
@param string $name
@return bool | [
"Add",
"index",
"to",
"table",
"column",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Database/MSSqlDatabase.php#L220-L227 | train |
hail-framework/framework | src/Template/Template.php | Template.start | public function start($name)
{
if ($name === 'content') {
throw new \LogicException('The section name "content" is reserved.');
}
if ($this->sectionName) {
throw new \LogicException('You cannot nest sections within other sections.');
}
$this->sectionName = $name;
ob_start();
} | php | public function start($name)
{
if ($name === 'content') {
throw new \LogicException('The section name "content" is reserved.');
}
if ($this->sectionName) {
throw new \LogicException('You cannot nest sections within other sections.');
}
$this->sectionName = $name;
ob_start();
} | [
"public",
"function",
"start",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"name",
"===",
"'content'",
")",
"{",
"throw",
"new",
"\\",
"LogicException",
"(",
"'The section name \"content\" is reserved.'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"secti... | Start a new section block.
@param string $name
@throws \LogicException | [
"Start",
"a",
"new",
"section",
"block",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Template/Template.php#L208-L221 | train |
systemson/collection | src/Base/Statements.php | Statements.where | public function where(string $column, $value): CollectionInterface
{
return $this->filter(
function ($item) use ($column, $value) {
if (isset($item[$column])) {
return $item[$column] === $value;
}
}
);
} | php | public function where(string $column, $value): CollectionInterface
{
return $this->filter(
function ($item) use ($column, $value) {
if (isset($item[$column])) {
return $item[$column] === $value;
}
}
);
} | [
"public",
"function",
"where",
"(",
"string",
"$",
"column",
",",
"$",
"value",
")",
":",
"CollectionInterface",
"{",
"return",
"$",
"this",
"->",
"filter",
"(",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"column",
",",
"$",
"value",
")",
"{... | Returns a new Collection containing the items in the specified column that are equal to the especified value.
@param string $column The columns to filter by.
@param mixed $value The value to compare each item.
@return Collection A new collection instance. | [
"Returns",
"a",
"new",
"Collection",
"containing",
"the",
"items",
"in",
"the",
"specified",
"column",
"that",
"are",
"equal",
"to",
"the",
"especified",
"value",
"."
] | fb3ae1a78806aafabc0562db96822e8b99dc2a64 | https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/Statements.php#L52-L61 | train |
systemson/collection | src/Base/Statements.php | Statements.orderBy | public function orderBy(string $column, string $order = 'ASC'): CollectionInterface
{
return $this->sort(
function ($a, $b) use ($column, $order) {
if (strtoupper($order) == 'ASC') {
return $a[$column] <=> $b[$column];
} elseif (strtoupper($order) == 'DESC') {
return $b[$column] <=> $a[$column];
}
// Must throw exception if item column does not exists
}
);
} | php | public function orderBy(string $column, string $order = 'ASC'): CollectionInterface
{
return $this->sort(
function ($a, $b) use ($column, $order) {
if (strtoupper($order) == 'ASC') {
return $a[$column] <=> $b[$column];
} elseif (strtoupper($order) == 'DESC') {
return $b[$column] <=> $a[$column];
}
// Must throw exception if item column does not exists
}
);
} | [
"public",
"function",
"orderBy",
"(",
"string",
"$",
"column",
",",
"string",
"$",
"order",
"=",
"'ASC'",
")",
":",
"CollectionInterface",
"{",
"return",
"$",
"this",
"->",
"sort",
"(",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
... | Returns a new Collection containing the items ordered by the especified column.
@todo MUST throw exception if the column does not exists
@param string $column The column to order by.
@param string $order The order to sort the items.
@return Collection A new collection instance. | [
"Returns",
"a",
"new",
"Collection",
"containing",
"the",
"items",
"ordered",
"by",
"the",
"especified",
"column",
"."
] | fb3ae1a78806aafabc0562db96822e8b99dc2a64 | https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/Statements.php#L131-L143 | train |
systemson/collection | src/Base/Statements.php | Statements.join | public function join(array $array, string $pkey, string $fkey): CollectionInterface
{
return $this->map(
function ($item) use ($array, $pkey, $fkey) {
foreach ($array as $value) {
if ($item[$pkey] == $value[$fkey]) {
return array_merge($item, $value);
}
}
}
);
} | php | public function join(array $array, string $pkey, string $fkey): CollectionInterface
{
return $this->map(
function ($item) use ($array, $pkey, $fkey) {
foreach ($array as $value) {
if ($item[$pkey] == $value[$fkey]) {
return array_merge($item, $value);
}
}
}
);
} | [
"public",
"function",
"join",
"(",
"array",
"$",
"array",
",",
"string",
"$",
"pkey",
",",
"string",
"$",
"fkey",
")",
":",
"CollectionInterface",
"{",
"return",
"$",
"this",
"->",
"map",
"(",
"function",
"(",
"$",
"item",
")",
"use",
"(",
"$",
"arra... | Returns a new Collection joined by the specified column.
@param array $array The array to merge
@param string $pkey The key to compare on the current collection.
@param string $fkey The key to compare on the provided array.
@return Collection A new collection instance. | [
"Returns",
"a",
"new",
"Collection",
"joined",
"by",
"the",
"specified",
"column",
"."
] | fb3ae1a78806aafabc0562db96822e8b99dc2a64 | https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/Statements.php#L178-L189 | train |
systemson/collection | src/Base/Statements.php | Statements.sum | public function sum(string $column = null): int
{
if (!is_null($column)) {
return $this->column($column)->sum();
}
return array_sum($this->toArray());
} | php | public function sum(string $column = null): int
{
if (!is_null($column)) {
return $this->column($column)->sum();
}
return array_sum($this->toArray());
} | [
"public",
"function",
"sum",
"(",
"string",
"$",
"column",
"=",
"null",
")",
":",
"int",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"column",
")",
")",
"{",
"return",
"$",
"this",
"->",
"column",
"(",
"$",
"column",
")",
"->",
"sum",
"(",
")",
"... | Calculates the sum of values in the collection.
@param string $column The column.
@return int The collection sum. | [
"Calculates",
"the",
"sum",
"of",
"values",
"in",
"the",
"collection",
"."
] | fb3ae1a78806aafabc0562db96822e8b99dc2a64 | https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/Statements.php#L198-L205 | train |
railken/amethyst-common | src/CommonServiceProvider.php | CommonServiceProvider.loadTranslations | public function loadTranslations()
{
$directory = $this->getDirectory().'/../../resources/lang';
$this->loadTranslationsFrom($directory, 'amethyst-'.$this->getPackageName());
$this->publishes([
$directory => resource_path('lang/vendor/amethyst'),
], 'resources');
} | php | public function loadTranslations()
{
$directory = $this->getDirectory().'/../../resources/lang';
$this->loadTranslationsFrom($directory, 'amethyst-'.$this->getPackageName());
$this->publishes([
$directory => resource_path('lang/vendor/amethyst'),
], 'resources');
} | [
"public",
"function",
"loadTranslations",
"(",
")",
"{",
"$",
"directory",
"=",
"$",
"this",
"->",
"getDirectory",
"(",
")",
".",
"'/../../resources/lang'",
";",
"$",
"this",
"->",
"loadTranslationsFrom",
"(",
"$",
"directory",
",",
"'amethyst-'",
".",
"$",
... | Load translations. | [
"Load",
"translations",
"."
] | ee89a31531e267d454352e2caf02fd73be5babfe | https://github.com/railken/amethyst-common/blob/ee89a31531e267d454352e2caf02fd73be5babfe/src/CommonServiceProvider.php#L58-L67 | train |
railken/amethyst-common | src/CommonServiceProvider.php | CommonServiceProvider.loadConfigs | public function loadConfigs()
{
$directory = $this->getDirectory().'/../../config/*';
foreach (glob($directory) as $file) {
$this->publishes([$file => config_path(basename($file))], 'config');
$this->mergeConfigFrom($file, basename($file, '.php'));
}
} | php | public function loadConfigs()
{
$directory = $this->getDirectory().'/../../config/*';
foreach (glob($directory) as $file) {
$this->publishes([$file => config_path(basename($file))], 'config');
$this->mergeConfigFrom($file, basename($file, '.php'));
}
} | [
"public",
"function",
"loadConfigs",
"(",
")",
"{",
"$",
"directory",
"=",
"$",
"this",
"->",
"getDirectory",
"(",
")",
".",
"'/../../config/*'",
";",
"foreach",
"(",
"glob",
"(",
"$",
"directory",
")",
"as",
"$",
"file",
")",
"{",
"$",
"this",
"->",
... | Load configs-. | [
"Load",
"configs",
"-",
"."
] | ee89a31531e267d454352e2caf02fd73be5babfe | https://github.com/railken/amethyst-common/blob/ee89a31531e267d454352e2caf02fd73be5babfe/src/CommonServiceProvider.php#L84-L92 | train |
railken/amethyst-common | src/CommonServiceProvider.php | CommonServiceProvider.getPackageName | public function getPackageName()
{
$reflection = new \ReflectionClass($this);
$inflector = new Inflector();
return str_replace('_', '-', $inflector->tableize(str_replace('ServiceProvider', '', $reflection->getShortName())));
} | php | public function getPackageName()
{
$reflection = new \ReflectionClass($this);
$inflector = new Inflector();
return str_replace('_', '-', $inflector->tableize(str_replace('ServiceProvider', '', $reflection->getShortName())));
} | [
"public",
"function",
"getPackageName",
"(",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
")",
";",
"$",
"inflector",
"=",
"new",
"Inflector",
"(",
")",
";",
"return",
"str_replace",
"(",
"'_'",
",",
"'-'",
",",
"... | Return package name. | [
"Return",
"package",
"name",
"."
] | ee89a31531e267d454352e2caf02fd73be5babfe | https://github.com/railken/amethyst-common/blob/ee89a31531e267d454352e2caf02fd73be5babfe/src/CommonServiceProvider.php#L97-L103 | train |
railken/amethyst-common | src/CommonServiceProvider.php | CommonServiceProvider.loadRoutes | public function loadRoutes()
{
$packageName = $this->getPackageName();
foreach (Config::get('amethyst.'.$packageName.'.http') as $groupName => $group) {
foreach ($group as $configName => $config) {
if (Arr::get($config, 'enabled')) {
Router::group($groupName, Arr::get($config, 'router'), function ($router) use ($config) {
$controller = Arr::get($config, 'controller');
$reflection = new \ReflectionClass($controller);
if ($reflection->hasMethod('index')) {
$router->get('/', ['as' => 'index', 'uses' => $controller.'@index']);
}
if ($reflection->hasMethod('store')) {
$router->put('/', ['as' => 'store', 'uses' => $controller.'@store']);
}
if ($reflection->hasMethod('erase')) {
$router->delete('/', ['as' => 'erase', 'uses' => $controller.'@erase']);
}
if ($reflection->hasMethod('create')) {
$router->post('/', ['as' => 'create', 'uses' => $controller.'@create']);
}
if ($reflection->hasMethod('update')) {
$router->put('/{id}', ['as' => 'update', 'uses' => $controller.'@update']);
}
if ($reflection->hasMethod('remove')) {
$router->delete('/{id}', ['as' => 'remove', 'uses' => $controller.'@remove']);
}
if ($reflection->hasMethod('show')) {
$router->get('/{id}', ['as' => 'show', 'uses' => $controller.'@show']);
}
});
}
}
}
} | php | public function loadRoutes()
{
$packageName = $this->getPackageName();
foreach (Config::get('amethyst.'.$packageName.'.http') as $groupName => $group) {
foreach ($group as $configName => $config) {
if (Arr::get($config, 'enabled')) {
Router::group($groupName, Arr::get($config, 'router'), function ($router) use ($config) {
$controller = Arr::get($config, 'controller');
$reflection = new \ReflectionClass($controller);
if ($reflection->hasMethod('index')) {
$router->get('/', ['as' => 'index', 'uses' => $controller.'@index']);
}
if ($reflection->hasMethod('store')) {
$router->put('/', ['as' => 'store', 'uses' => $controller.'@store']);
}
if ($reflection->hasMethod('erase')) {
$router->delete('/', ['as' => 'erase', 'uses' => $controller.'@erase']);
}
if ($reflection->hasMethod('create')) {
$router->post('/', ['as' => 'create', 'uses' => $controller.'@create']);
}
if ($reflection->hasMethod('update')) {
$router->put('/{id}', ['as' => 'update', 'uses' => $controller.'@update']);
}
if ($reflection->hasMethod('remove')) {
$router->delete('/{id}', ['as' => 'remove', 'uses' => $controller.'@remove']);
}
if ($reflection->hasMethod('show')) {
$router->get('/{id}', ['as' => 'show', 'uses' => $controller.'@show']);
}
});
}
}
}
} | [
"public",
"function",
"loadRoutes",
"(",
")",
"{",
"$",
"packageName",
"=",
"$",
"this",
"->",
"getPackageName",
"(",
")",
";",
"foreach",
"(",
"Config",
"::",
"get",
"(",
"'amethyst.'",
".",
"$",
"packageName",
".",
"'.http'",
")",
"as",
"$",
"groupName... | Load routes based on configs. | [
"Load",
"routes",
"based",
"on",
"configs",
"."
] | ee89a31531e267d454352e2caf02fd73be5babfe | https://github.com/railken/amethyst-common/blob/ee89a31531e267d454352e2caf02fd73be5babfe/src/CommonServiceProvider.php#L108-L151 | train |
DoSomething/gateway | src/Common/HasAttributes.php | HasAttributes.hasGetMutator | public function hasGetMutator($key)
{
$TitleCase = ucwords(str_replace(['-', '_'], ' ', $key));
$StudlyCase = str_replace(' ', '', $TitleCase);
return method_exists($this, 'get'.$StudlyCase.'Attribute');
} | php | public function hasGetMutator($key)
{
$TitleCase = ucwords(str_replace(['-', '_'], ' ', $key));
$StudlyCase = str_replace(' ', '', $TitleCase);
return method_exists($this, 'get'.$StudlyCase.'Attribute');
} | [
"public",
"function",
"hasGetMutator",
"(",
"$",
"key",
")",
"{",
"$",
"TitleCase",
"=",
"ucwords",
"(",
"str_replace",
"(",
"[",
"'-'",
",",
"'_'",
"]",
",",
"' '",
",",
"$",
"key",
")",
")",
";",
"$",
"StudlyCase",
"=",
"str_replace",
"(",
"' '",
... | Determine if a get mutator exists for an attribute.
@param string $key
@return bool | [
"Determine",
"if",
"a",
"get",
"mutator",
"exists",
"for",
"an",
"attribute",
"."
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Common/HasAttributes.php#L99-L105 | train |
hail-framework/framework | src/Image/AbstractDecoder.php | AbstractDecoder.isStream | public function isStream()
{
if ($this->data instanceof StreamInterface) {
return true;
}
if (!is_resource($this->data)) {
return false;
}
if (get_resource_type($this->data) !== 'stream') {
return false;
}
return true;
} | php | public function isStream()
{
if ($this->data instanceof StreamInterface) {
return true;
}
if (!is_resource($this->data)) {
return false;
}
if (get_resource_type($this->data) !== 'stream') {
return false;
}
return true;
} | [
"public",
"function",
"isStream",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"data",
"instanceof",
"StreamInterface",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"!",
"is_resource",
"(",
"$",
"this",
"->",
"data",
")",
")",
"{",
"return",
"fal... | Determines if current source data is a stream resource
@return bool | [
"Determines",
"if",
"current",
"source",
"data",
"is",
"a",
"stream",
"resource"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Image/AbstractDecoder.php#L209-L224 | train |
DoSomething/gateway | src/Laravel/LaravelOAuthBridge.php | LaravelOAuthBridge.persistUserToken | public function persistUserToken(AccessToken $token)
{
$northstarId = $token->getResourceOwnerId();
/** @var NorthstarUserContract $user */
$user = $this->getUser($northstarId);
// If user hasn't tried to log in before, make them a local record.
if (! $user) {
$user = $this->createModel();
$user->setNorthstarIdentifier($northstarId);
}
// And then update their token details.
$user->setOAuthToken($token);
$user->save();
// Finally, tell the guard about the new token if this is the currently
// logged-in user. (Otherwise, they wouldn't get the new token until
// the following page load.)
if (auth()->user() && auth()->user()->getNorthstarIdentifier() === $northstarId) {
auth()->setUser($user);
}
} | php | public function persistUserToken(AccessToken $token)
{
$northstarId = $token->getResourceOwnerId();
/** @var NorthstarUserContract $user */
$user = $this->getUser($northstarId);
// If user hasn't tried to log in before, make them a local record.
if (! $user) {
$user = $this->createModel();
$user->setNorthstarIdentifier($northstarId);
}
// And then update their token details.
$user->setOAuthToken($token);
$user->save();
// Finally, tell the guard about the new token if this is the currently
// logged-in user. (Otherwise, they wouldn't get the new token until
// the following page load.)
if (auth()->user() && auth()->user()->getNorthstarIdentifier() === $northstarId) {
auth()->setUser($user);
}
} | [
"public",
"function",
"persistUserToken",
"(",
"AccessToken",
"$",
"token",
")",
"{",
"$",
"northstarId",
"=",
"$",
"token",
"->",
"getResourceOwnerId",
"(",
")",
";",
"/** @var NorthstarUserContract $user */",
"$",
"user",
"=",
"$",
"this",
"->",
"getUser",
"("... | Save the access & refresh tokens for an authorized user.
@param \League\OAuth2\Client\Token\AccessToken $token
@return void | [
"Save",
"the",
"access",
"&",
"refresh",
"tokens",
"for",
"an",
"authorized",
"user",
"."
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Laravel/LaravelOAuthBridge.php#L68-L91 | train |
DoSomething/gateway | src/Laravel/LaravelOAuthBridge.php | LaravelOAuthBridge.getClientToken | public function getClientToken()
{
$client = app('db')->connection()->table('clients')
->where('client_id', config('services.northstar.client_credentials.client_id'))
->first();
// If any of the required fields are empty, return null.
if (empty($client->access_token) || empty($client->access_token_expiration)) {
return null;
}
return new AccessToken([
'access_token' => $client->access_token,
'expires' => $client->access_token_expiration,
]);
} | php | public function getClientToken()
{
$client = app('db')->connection()->table('clients')
->where('client_id', config('services.northstar.client_credentials.client_id'))
->first();
// If any of the required fields are empty, return null.
if (empty($client->access_token) || empty($client->access_token_expiration)) {
return null;
}
return new AccessToken([
'access_token' => $client->access_token,
'expires' => $client->access_token_expiration,
]);
} | [
"public",
"function",
"getClientToken",
"(",
")",
"{",
"$",
"client",
"=",
"app",
"(",
"'db'",
")",
"->",
"connection",
"(",
")",
"->",
"table",
"(",
"'clients'",
")",
"->",
"where",
"(",
"'client_id'",
",",
"config",
"(",
"'services.northstar.client_credent... | Get the OAuth client's token. | [
"Get",
"the",
"OAuth",
"client",
"s",
"token",
"."
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Laravel/LaravelOAuthBridge.php#L114-L129 | train |
DoSomething/gateway | src/Laravel/LaravelOAuthBridge.php | LaravelOAuthBridge.persistClientToken | public function persistClientToken($clientId, $accessToken, $expiration, $role)
{
/** @var \Illuminate\Database\Query\Builder $table */
$table = app('db')->connection()->table('clients');
// If the record doesn't already exist, add it.
if (! $table->where(['client_id' => $clientId])->exists()) {
$table->insert(['client_id' => $clientId]);
}
// Update record with the new access token & expiration.
$table->where(['client_id' => $clientId])->update([
'access_token' => $accessToken,
'access_token_expiration' => $expiration,
]);
} | php | public function persistClientToken($clientId, $accessToken, $expiration, $role)
{
/** @var \Illuminate\Database\Query\Builder $table */
$table = app('db')->connection()->table('clients');
// If the record doesn't already exist, add it.
if (! $table->where(['client_id' => $clientId])->exists()) {
$table->insert(['client_id' => $clientId]);
}
// Update record with the new access token & expiration.
$table->where(['client_id' => $clientId])->update([
'access_token' => $accessToken,
'access_token_expiration' => $expiration,
]);
} | [
"public",
"function",
"persistClientToken",
"(",
"$",
"clientId",
",",
"$",
"accessToken",
",",
"$",
"expiration",
",",
"$",
"role",
")",
"{",
"/** @var \\Illuminate\\Database\\Query\\Builder $table */",
"$",
"table",
"=",
"app",
"(",
"'db'",
")",
"->",
"connectio... | Save the access token for an authorized client.
@param $clientId - OAuth client ID
@param $accessToken - Encoded OAuth access token
@param $expiration - Access token expiration as UNIX timestamp
@return void | [
"Save",
"the",
"access",
"token",
"for",
"an",
"authorized",
"client",
"."
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Laravel/LaravelOAuthBridge.php#L139-L154 | train |
DoSomething/gateway | src/Laravel/LaravelOAuthBridge.php | LaravelOAuthBridge.login | public function login(NorthstarUserContract $user, AccessToken $token)
{
// Save the user's role to their local account (for easy permission checking).
$user->setRole($token->getValues()['role']);
$user->save();
auth()->login($user, true);
} | php | public function login(NorthstarUserContract $user, AccessToken $token)
{
// Save the user's role to their local account (for easy permission checking).
$user->setRole($token->getValues()['role']);
$user->save();
auth()->login($user, true);
} | [
"public",
"function",
"login",
"(",
"NorthstarUserContract",
"$",
"user",
",",
"AccessToken",
"$",
"token",
")",
"{",
"// Save the user's role to their local account (for easy permission checking).",
"$",
"user",
"->",
"setRole",
"(",
"$",
"token",
"->",
"getValues",
"(... | Log a user in to the application & update their locally cached role.
@param NorthstarUserContract|\Illuminate\Contracts\Auth\Authenticatable $user
@param AccessToken $token
@return void | [
"Log",
"a",
"user",
"in",
"to",
"the",
"application",
"&",
"update",
"their",
"locally",
"cached",
"role",
"."
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/Laravel/LaravelOAuthBridge.php#L184-L191 | train |
hail-framework/framework | src/Database/Migration/Adapter/SQLiteAdapter.php | SQLiteAdapter.getColumnSqlDefinition | protected function getColumnSqlDefinition(Column $column)
{
$sqlType = $this->getSqlType($column->getType());
$def = '';
$def .= strtoupper($sqlType['name']);
if ($column->getPrecision() && $column->getScale()) {
$def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')';
}
$limitable = in_array(strtoupper($sqlType['name']), $this->definitionsWithLimits);
if (($column->getLimit() || isset($sqlType['limit'])) && $limitable) {
$def .= '(' . ($column->getLimit() ?: $sqlType['limit']) . ')';
}
if (($values = $column->getValues()) && is_array($values)) {
$def .= " CHECK({$column->getName()} IN ('" . implode("', '", $values) . "'))";
}
$default = $column->getDefault();
$def .= ($column->isNull() || is_null($default)) ? ' NULL' : ' NOT NULL';
$def .= $this->getDefaultValueDefinition($default);
$def .= ($column->isIdentity()) ? ' PRIMARY KEY AUTOINCREMENT' : '';
if ($column->getUpdate()) {
$def .= ' ON UPDATE ' . $column->getUpdate();
}
$def .= $this->getCommentDefinition($column);
return $def;
} | php | protected function getColumnSqlDefinition(Column $column)
{
$sqlType = $this->getSqlType($column->getType());
$def = '';
$def .= strtoupper($sqlType['name']);
if ($column->getPrecision() && $column->getScale()) {
$def .= '(' . $column->getPrecision() . ',' . $column->getScale() . ')';
}
$limitable = in_array(strtoupper($sqlType['name']), $this->definitionsWithLimits);
if (($column->getLimit() || isset($sqlType['limit'])) && $limitable) {
$def .= '(' . ($column->getLimit() ?: $sqlType['limit']) . ')';
}
if (($values = $column->getValues()) && is_array($values)) {
$def .= " CHECK({$column->getName()} IN ('" . implode("', '", $values) . "'))";
}
$default = $column->getDefault();
$def .= ($column->isNull() || is_null($default)) ? ' NULL' : ' NOT NULL';
$def .= $this->getDefaultValueDefinition($default);
$def .= ($column->isIdentity()) ? ' PRIMARY KEY AUTOINCREMENT' : '';
if ($column->getUpdate()) {
$def .= ' ON UPDATE ' . $column->getUpdate();
}
$def .= $this->getCommentDefinition($column);
return $def;
} | [
"protected",
"function",
"getColumnSqlDefinition",
"(",
"Column",
"$",
"column",
")",
"{",
"$",
"sqlType",
"=",
"$",
"this",
"->",
"getSqlType",
"(",
"$",
"column",
"->",
"getType",
"(",
")",
")",
";",
"$",
"def",
"=",
"''",
";",
"$",
"def",
".=",
"s... | Gets the SQLite Column Definition for a Column object.
@param Column $column Column
@return string | [
"Gets",
"the",
"SQLite",
"Column",
"Definition",
"for",
"a",
"Column",
"object",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Adapter/SQLiteAdapter.php#L985-L1014 | train |
systemson/collection | src/Base/EssentialTrait.php | EssentialTrait.max | public function max(string $column = null)
{
if ($this->isNotEmpty()) {
return max($this->toArray());
}
return false;
} | php | public function max(string $column = null)
{
if ($this->isNotEmpty()) {
return max($this->toArray());
}
return false;
} | [
"public",
"function",
"max",
"(",
"string",
"$",
"column",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNotEmpty",
"(",
")",
")",
"{",
"return",
"max",
"(",
"$",
"this",
"->",
"toArray",
"(",
")",
")",
";",
"}",
"return",
"false",
";",... | Returns the max value of the collection.
@param string $column The column to get the max value.
@return mixed | [
"Returns",
"the",
"max",
"value",
"of",
"the",
"collection",
"."
] | fb3ae1a78806aafabc0562db96822e8b99dc2a64 | https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/EssentialTrait.php#L91-L98 | train |
systemson/collection | src/Base/EssentialTrait.php | EssentialTrait.min | public function min(string $column = null)
{
if ($this->isNotEmpty()) {
return min($this->toArray());
}
return false;
} | php | public function min(string $column = null)
{
if ($this->isNotEmpty()) {
return min($this->toArray());
}
return false;
} | [
"public",
"function",
"min",
"(",
"string",
"$",
"column",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isNotEmpty",
"(",
")",
")",
"{",
"return",
"min",
"(",
"$",
"this",
"->",
"toArray",
"(",
")",
")",
";",
"}",
"return",
"false",
";",... | Returns the min value of the collection.
@param string $column The column to get the min value.
@return mixed | [
"Returns",
"the",
"min",
"value",
"of",
"the",
"collection",
"."
] | fb3ae1a78806aafabc0562db96822e8b99dc2a64 | https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/EssentialTrait.php#L107-L114 | train |
systemson/collection | src/Base/EssentialTrait.php | EssentialTrait.only | public function only(array $values): self
{
return $this->filter(function ($value) use ($values) {
return in_array($value, $values);
});
} | php | public function only(array $values): self
{
return $this->filter(function ($value) use ($values) {
return in_array($value, $values);
});
} | [
"public",
"function",
"only",
"(",
"array",
"$",
"values",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"filter",
"(",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"values",
")",
"{",
"return",
"in_array",
"(",
"$",
"value",
",",
"$"... | Returns the items of the collection that match the specified array.
@param array $values
@return self | [
"Returns",
"the",
"items",
"of",
"the",
"collection",
"that",
"match",
"the",
"specified",
"array",
"."
] | fb3ae1a78806aafabc0562db96822e8b99dc2a64 | https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/EssentialTrait.php#L148-L153 | train |
systemson/collection | src/Base/EssentialTrait.php | EssentialTrait.except | public function except(array $values): self
{
return $this->filter(function ($value) use ($values) {
return !in_array($value, $values);
});
} | php | public function except(array $values): self
{
return $this->filter(function ($value) use ($values) {
return !in_array($value, $values);
});
} | [
"public",
"function",
"except",
"(",
"array",
"$",
"values",
")",
":",
"self",
"{",
"return",
"$",
"this",
"->",
"filter",
"(",
"function",
"(",
"$",
"value",
")",
"use",
"(",
"$",
"values",
")",
"{",
"return",
"!",
"in_array",
"(",
"$",
"value",
"... | Returns the items of the collections that do not match the specified array.
@param array $values
@return self | [
"Returns",
"the",
"items",
"of",
"the",
"collections",
"that",
"do",
"not",
"match",
"the",
"specified",
"array",
"."
] | fb3ae1a78806aafabc0562db96822e8b99dc2a64 | https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/Base/EssentialTrait.php#L162-L167 | train |
hail-framework/framework | src/Util/Closure/SerializableClosure.php | SerializableClosure.serialize | public function serialize()
{
try {
$this->data = $this->data ?: Serializer::getData($this->closure, true);
return Serialize::encode($this->data, Serializer::getSerializeType());
} catch (\Exception $e) {
\trigger_error('Serialization of closure failed: ' . $e->getMessage());
// Note: The serialize() method of Serializable must return a string
// or null and cannot throw exceptions.
return null;
}
} | php | public function serialize()
{
try {
$this->data = $this->data ?: Serializer::getData($this->closure, true);
return Serialize::encode($this->data, Serializer::getSerializeType());
} catch (\Exception $e) {
\trigger_error('Serialization of closure failed: ' . $e->getMessage());
// Note: The serialize() method of Serializable must return a string
// or null and cannot throw exceptions.
return null;
}
} | [
"public",
"function",
"serialize",
"(",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"data",
"=",
"$",
"this",
"->",
"data",
"?",
":",
"Serializer",
"::",
"getData",
"(",
"$",
"this",
"->",
"closure",
",",
"true",
")",
";",
"return",
"Serialize",
"::",
... | Serializes the code, context, and binding of the closure.
@return string|null
@link http://php.net/manual/en/serializable.serialize.php | [
"Serializes",
"the",
"code",
"context",
"and",
"binding",
"of",
"the",
"closure",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Closure/SerializableClosure.php#L99-L111 | train |
hail-framework/framework | src/Util/Closure/SerializableClosure.php | SerializableClosure.unserialize | public function unserialize($serialized)
{
// Unserialize the closure data and reconstruct the closure object.
$this->data = Serialize::decode($serialized, Serializer::getSerializeType());
$this->closure = __reconstruct_closure($this->data);
// Throw an exception if the closure could not be reconstructed.
if (!$this->closure instanceof \Closure) {
throw new \RuntimeException(
'The closure is corrupted and cannot be unserialized.'
);
}
// Rebind the closure to its former binding and scope.
if ($this->data['binding'] || $this->data['isStatic']) {
$this->closure = $this->closure->bindTo(
$this->data['binding'],
$this->data['scope']
);
}
} | php | public function unserialize($serialized)
{
// Unserialize the closure data and reconstruct the closure object.
$this->data = Serialize::decode($serialized, Serializer::getSerializeType());
$this->closure = __reconstruct_closure($this->data);
// Throw an exception if the closure could not be reconstructed.
if (!$this->closure instanceof \Closure) {
throw new \RuntimeException(
'The closure is corrupted and cannot be unserialized.'
);
}
// Rebind the closure to its former binding and scope.
if ($this->data['binding'] || $this->data['isStatic']) {
$this->closure = $this->closure->bindTo(
$this->data['binding'],
$this->data['scope']
);
}
} | [
"public",
"function",
"unserialize",
"(",
"$",
"serialized",
")",
"{",
"// Unserialize the closure data and reconstruct the closure object.",
"$",
"this",
"->",
"data",
"=",
"Serialize",
"::",
"decode",
"(",
"$",
"serialized",
",",
"Serializer",
"::",
"getSerializeType"... | Unserializes the closure.
Unserializes the closure's data and recreates the closure using a
simulation of its original context. The used variables (context) are
extracted into a fresh scope prior to redefining the closure. The
closure is also rebound to its former object and scope.
@param string $serialized
@throws \RuntimeException
@link http://php.net/manual/en/serializable.unserialize.php | [
"Unserializes",
"the",
"closure",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Closure/SerializableClosure.php#L126-L146 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.enableStatistics | public function enableStatistics($enable = true, $sortBy = 'averageTime')
{
if (!\in_array($sortBy, ['count', 'deltaTime', 'averageTime'], true)) {
throw new \InvalidArgumentException("Cannot sort statistics by '$sortBy' column.");
}
$this->performStatistics = (bool) $enable;
$this->sortBy = $sortBy;
return $this;
} | php | public function enableStatistics($enable = true, $sortBy = 'averageTime')
{
if (!\in_array($sortBy, ['count', 'deltaTime', 'averageTime'], true)) {
throw new \InvalidArgumentException("Cannot sort statistics by '$sortBy' column.");
}
$this->performStatistics = (bool) $enable;
$this->sortBy = $sortBy;
return $this;
} | [
"public",
"function",
"enableStatistics",
"(",
"$",
"enable",
"=",
"true",
",",
"$",
"sortBy",
"=",
"'averageTime'",
")",
"{",
"if",
"(",
"!",
"\\",
"in_array",
"(",
"$",
"sortBy",
",",
"[",
"'count'",
",",
"'deltaTime'",
",",
"'averageTime'",
"]",
",",
... | Enable or disable function time statistics.
@param bool enable statistics
@param string sort by column 'count', 'deltaTime' or 'averageTime'
@return TracePanel
@throws \InvalidArgumentException | [
"Enable",
"or",
"disable",
"function",
"time",
"statistics",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L193-L203 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.start | public function start($title = null)
{
if (!$this->isError) {
if ($this->state === self::STATE_RUN) {
$this->pause();
}
if ($this->state === self::STATE_STOP) {
$this->titles = [$title];
\xdebug_start_trace($this->traceFile, XDEBUG_TRACE_COMPUTERIZED);
} elseif ($this->state === self::STATE_PAUSE) {
$this->titles[] = $title;
\xdebug_start_trace($this->traceFile, XDEBUG_TRACE_COMPUTERIZED | XDEBUG_TRACE_APPEND);
}
$this->state = self::STATE_RUN;
}
} | php | public function start($title = null)
{
if (!$this->isError) {
if ($this->state === self::STATE_RUN) {
$this->pause();
}
if ($this->state === self::STATE_STOP) {
$this->titles = [$title];
\xdebug_start_trace($this->traceFile, XDEBUG_TRACE_COMPUTERIZED);
} elseif ($this->state === self::STATE_PAUSE) {
$this->titles[] = $title;
\xdebug_start_trace($this->traceFile, XDEBUG_TRACE_COMPUTERIZED | XDEBUG_TRACE_APPEND);
}
$this->state = self::STATE_RUN;
}
} | [
"public",
"function",
"start",
"(",
"$",
"title",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isError",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"state",
"===",
"self",
"::",
"STATE_RUN",
")",
"{",
"$",
"this",
"->",
"pause",
"(",
... | Start or continue tracing.
@param string|NULL trace title | [
"Start",
"or",
"continue",
"tracing",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L213-L230 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.pause | public function pause()
{
if ($this->state === self::STATE_RUN) {
\xdebug_stop_trace();
$this->state = self::STATE_PAUSE;
}
} | php | public function pause()
{
if ($this->state === self::STATE_RUN) {
\xdebug_stop_trace();
$this->state = self::STATE_PAUSE;
}
} | [
"public",
"function",
"pause",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"state",
"===",
"self",
"::",
"STATE_RUN",
")",
"{",
"\\",
"xdebug_stop_trace",
"(",
")",
";",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_PAUSE",
";",
"}",
"}"
] | Pause tracing. | [
"Pause",
"tracing",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L236-L242 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.stop | public function stop()
{
if ($this->state === self::STATE_RUN) {
\xdebug_stop_trace();
}
$this->state = self::STATE_STOP;
} | php | public function stop()
{
if ($this->state === self::STATE_RUN) {
\xdebug_stop_trace();
}
$this->state = self::STATE_STOP;
} | [
"public",
"function",
"stop",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"state",
"===",
"self",
"::",
"STATE_RUN",
")",
"{",
"\\",
"xdebug_stop_trace",
"(",
")",
";",
"}",
"$",
"this",
"->",
"state",
"=",
"self",
"::",
"STATE_STOP",
";",
"}"
] | Stop tracing. | [
"Stop",
"tracing",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L248-L255 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.time | public function time($time, $precision = 0)
{
$units = 's';
if ($time < 1e-6) { // <1us
$units = 'ns';
$time *= 1e9;
} elseif ($time < 1e-3) { // <1ms
$units = "\xc2\xb5s";
$time *= 1e6;
} elseif ($time < 1) { // <1s
$units = 'ms';
$time *= 1e3;
}
return \round($time, $precision) . ' ' . $units;
} | php | public function time($time, $precision = 0)
{
$units = 's';
if ($time < 1e-6) { // <1us
$units = 'ns';
$time *= 1e9;
} elseif ($time < 1e-3) { // <1ms
$units = "\xc2\xb5s";
$time *= 1e6;
} elseif ($time < 1) { // <1s
$units = 'ms';
$time *= 1e3;
}
return \round($time, $precision) . ' ' . $units;
} | [
"public",
"function",
"time",
"(",
"$",
"time",
",",
"$",
"precision",
"=",
"0",
")",
"{",
"$",
"units",
"=",
"'s'",
";",
"if",
"(",
"$",
"time",
"<",
"1e-6",
")",
"{",
"// <1us",
"$",
"units",
"=",
"'ns'",
";",
"$",
"time",
"*=",
"1e9",
";",
... | Template helper converts seconds to ns, us, ms, s.
@param float $time time interval in seconds
@param int $precision part precision
@return string formated time | [
"Template",
"helper",
"converts",
"seconds",
"to",
"ns",
"us",
"ms",
"s",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L269-L286 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.timeClass | public function timeClass($time, $slow = null, $fast = null)
{
$slow = $slow ?: 0.02; // 20ms
$fast = $fast ?: 1e-3; // 1ms
if ($time <= $fast) {
return 'timeFast';
}
if ($time <= $slow) {
return 'timeMedian';
}
return 'timeSlow';
} | php | public function timeClass($time, $slow = null, $fast = null)
{
$slow = $slow ?: 0.02; // 20ms
$fast = $fast ?: 1e-3; // 1ms
if ($time <= $fast) {
return 'timeFast';
}
if ($time <= $slow) {
return 'timeMedian';
}
return 'timeSlow';
} | [
"public",
"function",
"timeClass",
"(",
"$",
"time",
",",
"$",
"slow",
"=",
"null",
",",
"$",
"fast",
"=",
"null",
")",
"{",
"$",
"slow",
"=",
"$",
"slow",
"?",
":",
"0.02",
";",
"// 20ms",
"$",
"fast",
"=",
"$",
"fast",
"?",
":",
"1e-3",
";",
... | Template helper converts seconds to HTML class string.
@param float $time time interval in seconds
@param float $slow over this value is interval classified as slow
@param float $fast under this value is interval classified as fast
@return string | [
"Template",
"helper",
"converts",
"seconds",
"to",
"HTML",
"class",
"string",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L298-L312 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.bytes | public function bytes($bytes, $precision = 2)
{
$bytes = \round($bytes);
$units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB'];
foreach ($units as $unit) {
if (\abs($bytes) < 1024 || $unit === \end($units)) {
break;
}
$bytes = $bytes / 1024;
}
return \round($bytes, $precision) . ' ' . $unit;
} | php | public function bytes($bytes, $precision = 2)
{
$bytes = \round($bytes);
$units = ['B', 'kB', 'MB', 'GB', 'TB', 'PB'];
foreach ($units as $unit) {
if (\abs($bytes) < 1024 || $unit === \end($units)) {
break;
}
$bytes = $bytes / 1024;
}
return \round($bytes, $precision) . ' ' . $unit;
} | [
"public",
"function",
"bytes",
"(",
"$",
"bytes",
",",
"$",
"precision",
"=",
"2",
")",
"{",
"$",
"bytes",
"=",
"\\",
"round",
"(",
"$",
"bytes",
")",
";",
"$",
"units",
"=",
"[",
"'B'",
",",
"'kB'",
",",
"'MB'",
",",
"'GB'",
",",
"'TB'",
",",
... | Converts to human readable file size.
@param int
@param int
@return string | [
"Converts",
"to",
"human",
"readable",
"file",
"size",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L322-L334 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.setError | protected function setError($message, array $lastError = null)
{
$this->isError = true;
$this->errMessage = $message;
if ($lastError !== null) {
$this->errMessage .= ': ' . $lastError['message'];
$this->errFile = $lastError['file'];
$this->errLine = $lastError['line'];
}
} | php | protected function setError($message, array $lastError = null)
{
$this->isError = true;
$this->errMessage = $message;
if ($lastError !== null) {
$this->errMessage .= ': ' . $lastError['message'];
$this->errFile = $lastError['file'];
$this->errLine = $lastError['line'];
}
} | [
"protected",
"function",
"setError",
"(",
"$",
"message",
",",
"array",
"$",
"lastError",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"isError",
"=",
"true",
";",
"$",
"this",
"->",
"errMessage",
"=",
"$",
"message",
";",
"if",
"(",
"$",
"lastError",
"... | Sets internal error variables.
@param string $message error message
@param array $lastError error_get_last() | [
"Sets",
"internal",
"error",
"variables",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L343-L353 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.renderError | protected function renderError()
{
$errMessage = $this->errMessage;
$errFile = $this->errFile;
$errLine = $this->errLine;
\ob_start();
require __DIR__ . '/templates/trace.error.phtml';
return \ob_get_clean();
} | php | protected function renderError()
{
$errMessage = $this->errMessage;
$errFile = $this->errFile;
$errLine = $this->errLine;
\ob_start();
require __DIR__ . '/templates/trace.error.phtml';
return \ob_get_clean();
} | [
"protected",
"function",
"renderError",
"(",
")",
"{",
"$",
"errMessage",
"=",
"$",
"this",
"->",
"errMessage",
";",
"$",
"errFile",
"=",
"$",
"this",
"->",
"errFile",
";",
"$",
"errLine",
"=",
"$",
"this",
"->",
"errLine",
";",
"\\",
"ob_start",
"(",
... | Render error message.
@return string rendered error template | [
"Render",
"error",
"message",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L361-L371 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.openTrace | protected function openTrace()
{
$index = \count($this->traces);
$this->traces[$index] = [];
$this->trace =& $this->traces[$index];
$this->indents[$index] = [];
$this->indent =& $this->indents[$index];
if ($this->performStatistics) {
$this->statistics[$index] = [];
$this->statistic =& $this->statistics[$index];
}
} | php | protected function openTrace()
{
$index = \count($this->traces);
$this->traces[$index] = [];
$this->trace =& $this->traces[$index];
$this->indents[$index] = [];
$this->indent =& $this->indents[$index];
if ($this->performStatistics) {
$this->statistics[$index] = [];
$this->statistic =& $this->statistics[$index];
}
} | [
"protected",
"function",
"openTrace",
"(",
")",
"{",
"$",
"index",
"=",
"\\",
"count",
"(",
"$",
"this",
"->",
"traces",
")",
";",
"$",
"this",
"->",
"traces",
"[",
"$",
"index",
"]",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"trace",
"=",
"&",
"$... | Sets trace and indent references. | [
"Sets",
"trace",
"and",
"indent",
"references",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L488-L502 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.closeTrace | protected function closeTrace()
{
if ($this->trace !== null) {
foreach ($this->trace as $id => $record) {
if (!$record->exited) { // last chance to filter non-exited records by FILTER_EXIT callback
$remove = false;
foreach ($this->filterExitCallbacks as $callback) {
$result = (int) $callback($record, false, $this);
if ($result & self::SKIP) {
$remove = true;
}
if ($result & self::STOP) {
break;
}
}
if ($remove) {
unset($this->trace[$id]);
continue;
}
}
$this->indent[$record->level] = 1;
}
if (null !== $this->indent) {
\ksort($this->indent);
$keys = \array_keys($this->indent);
$this->indent = \array_combine($keys, \array_keys($keys));
}
$null = null;
$this->trace =& $null;
$this->indent =& $null;
if ($this->performStatistics) {
foreach ($this->statistic as $statistic) {
$statistic->averageTime = $statistic->deltaTime / $statistic->count;
}
$sortBy = $this->sortBy;
\uasort($this->statistic, function ($a, $b) use ($sortBy) {
return $a->{$sortBy} < $b->{$sortBy};
});
$this->statistic =& $null;
}
}
} | php | protected function closeTrace()
{
if ($this->trace !== null) {
foreach ($this->trace as $id => $record) {
if (!$record->exited) { // last chance to filter non-exited records by FILTER_EXIT callback
$remove = false;
foreach ($this->filterExitCallbacks as $callback) {
$result = (int) $callback($record, false, $this);
if ($result & self::SKIP) {
$remove = true;
}
if ($result & self::STOP) {
break;
}
}
if ($remove) {
unset($this->trace[$id]);
continue;
}
}
$this->indent[$record->level] = 1;
}
if (null !== $this->indent) {
\ksort($this->indent);
$keys = \array_keys($this->indent);
$this->indent = \array_combine($keys, \array_keys($keys));
}
$null = null;
$this->trace =& $null;
$this->indent =& $null;
if ($this->performStatistics) {
foreach ($this->statistic as $statistic) {
$statistic->averageTime = $statistic->deltaTime / $statistic->count;
}
$sortBy = $this->sortBy;
\uasort($this->statistic, function ($a, $b) use ($sortBy) {
return $a->{$sortBy} < $b->{$sortBy};
});
$this->statistic =& $null;
}
}
} | [
"protected",
"function",
"closeTrace",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"trace",
"!==",
"null",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"trace",
"as",
"$",
"id",
"=>",
"$",
"record",
")",
"{",
"if",
"(",
"!",
"$",
"record",
"->",... | Unset trace and indent references and compute indents. | [
"Unset",
"trace",
"and",
"indent",
"references",
"and",
"compute",
"indents",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L508-L557 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.addRecord | protected function addRecord(\stdClass $record)
{
if ($record->isEntry) {
$add = true;
foreach ($this->filterEntryCallbacks as $callback) {
$result = (int) $callback($record, true, $this);
if ($result & self::SKIP) {
$add = false;
}
if ($result & self::STOP) {
break;
}
}
if ($add) {
$this->trace[$record->id] = $record;
}
} elseif (isset($this->trace[$record->id])) {
$entryRecord = $this->trace[$record->id];
$entryRecord->exited = true;
$entryRecord->exitTime = $record->time;
$entryRecord->deltaTime = $record->time - $entryRecord->time;
$entryRecord->exitMemory = $record->memory;
$entryRecord->deltaMemory = $record->memory - $entryRecord->memory;
$remove = false;
foreach ($this->filterExitCallbacks as $callback) {
$result = (int) $callback($entryRecord, false, $this);
if ($result & self::SKIP) {
$remove = true;
}
if ($result & self::STOP) {
break;
}
}
if ($remove) {
unset($this->trace[$record->id]);
} elseif ($this->performStatistics) {
if (!isset($this->statistic[$entryRecord->function])) {
$this->statistic[$entryRecord->function] = (object) [
'count' => 1,
'deltaTime' => $entryRecord->deltaTime,
];
} else {
$this->statistic[$entryRecord->function]->count += 1;
$this->statistic[$entryRecord->function]->deltaTime += $entryRecord->deltaTime;
}
}
}
} | php | protected function addRecord(\stdClass $record)
{
if ($record->isEntry) {
$add = true;
foreach ($this->filterEntryCallbacks as $callback) {
$result = (int) $callback($record, true, $this);
if ($result & self::SKIP) {
$add = false;
}
if ($result & self::STOP) {
break;
}
}
if ($add) {
$this->trace[$record->id] = $record;
}
} elseif (isset($this->trace[$record->id])) {
$entryRecord = $this->trace[$record->id];
$entryRecord->exited = true;
$entryRecord->exitTime = $record->time;
$entryRecord->deltaTime = $record->time - $entryRecord->time;
$entryRecord->exitMemory = $record->memory;
$entryRecord->deltaMemory = $record->memory - $entryRecord->memory;
$remove = false;
foreach ($this->filterExitCallbacks as $callback) {
$result = (int) $callback($entryRecord, false, $this);
if ($result & self::SKIP) {
$remove = true;
}
if ($result & self::STOP) {
break;
}
}
if ($remove) {
unset($this->trace[$record->id]);
} elseif ($this->performStatistics) {
if (!isset($this->statistic[$entryRecord->function])) {
$this->statistic[$entryRecord->function] = (object) [
'count' => 1,
'deltaTime' => $entryRecord->deltaTime,
];
} else {
$this->statistic[$entryRecord->function]->count += 1;
$this->statistic[$entryRecord->function]->deltaTime += $entryRecord->deltaTime;
}
}
}
} | [
"protected",
"function",
"addRecord",
"(",
"\\",
"stdClass",
"$",
"record",
")",
"{",
"if",
"(",
"$",
"record",
"->",
"isEntry",
")",
"{",
"$",
"add",
"=",
"true",
";",
"foreach",
"(",
"$",
"this",
"->",
"filterEntryCallbacks",
"as",
"$",
"callback",
"... | Push parsed trace file line into trace stack.
@param \stdClass parsed trace file line | [
"Push",
"parsed",
"trace",
"file",
"line",
"into",
"trace",
"stack",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L576-L632 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.defaultFilterCb | protected function defaultFilterCb(\stdClass $record)
{
if ($this->skipOver['phpInternals'] && $record->isInternal) {
return self::SKIP;
}
if ($this->skipOver['XDebugTrace']) {
if ($record->filename === __FILE__) {
return self::SKIP;
}
if (\strpos($record->function, 'XDebug::') === 0) {
return self::SKIP;
}
}
if ($this->skipOver['Hail'] && \strpos($record->function, 'Hail\\') === 0) {
return self::SKIP;
}
if ($this->skipOver['Composer'] && \strpos($record->function, 'Composer\\') === 0) {
return self::SKIP;
}
if ($this->skipOver['callbacks'] && ($record->function === 'callback' || $record->function === '{closure}')) {
return self::SKIP;
}
if ($this->skipOver['includes'] && $record->includeFile !== null) {
return self::SKIP;
}
return 0;
} | php | protected function defaultFilterCb(\stdClass $record)
{
if ($this->skipOver['phpInternals'] && $record->isInternal) {
return self::SKIP;
}
if ($this->skipOver['XDebugTrace']) {
if ($record->filename === __FILE__) {
return self::SKIP;
}
if (\strpos($record->function, 'XDebug::') === 0) {
return self::SKIP;
}
}
if ($this->skipOver['Hail'] && \strpos($record->function, 'Hail\\') === 0) {
return self::SKIP;
}
if ($this->skipOver['Composer'] && \strpos($record->function, 'Composer\\') === 0) {
return self::SKIP;
}
if ($this->skipOver['callbacks'] && ($record->function === 'callback' || $record->function === '{closure}')) {
return self::SKIP;
}
if ($this->skipOver['includes'] && $record->includeFile !== null) {
return self::SKIP;
}
return 0;
} | [
"protected",
"function",
"defaultFilterCb",
"(",
"\\",
"stdClass",
"$",
"record",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"skipOver",
"[",
"'phpInternals'",
"]",
"&&",
"$",
"record",
"->",
"isInternal",
")",
"{",
"return",
"self",
"::",
"SKIP",
";",
"}",... | Default filtering callback.
@param \stdClass trace file record
@return int bitmask of self::SKIP, self::STOP | [
"Default",
"filtering",
"callback",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L680-L713 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.addFilterCallback | public function addFilterCallback($callback, $flags = null)
{
$flags = (int) $flags;
if ($flags & self::FILTER_REPLACE_ENTRY) {
$this->filterEntryCallbacks = [];
}
if ($flags & self::FILTER_REPLACE_EXIT) {
$this->filterExitCallbacks = [];
}
// Called when entry records came
if (($flags & self::FILTER_ENTRY) || !($flags & self::FILTER_EXIT)) {
if ($flags & self::FILTER_APPEND_ENTRY) {
$this->filterEntryCallbacks[] = $callback;
} else {
\array_unshift($this->filterEntryCallbacks, $callback);
}
}
// Called when exit records came
if ($flags & self::FILTER_EXIT) {
if ($flags & self::FILTER_APPEND_EXIT) {
$this->filterExitCallbacks[] = $callback;
} else {
\array_unshift($this->filterExitCallbacks, $callback);
}
}
} | php | public function addFilterCallback($callback, $flags = null)
{
$flags = (int) $flags;
if ($flags & self::FILTER_REPLACE_ENTRY) {
$this->filterEntryCallbacks = [];
}
if ($flags & self::FILTER_REPLACE_EXIT) {
$this->filterExitCallbacks = [];
}
// Called when entry records came
if (($flags & self::FILTER_ENTRY) || !($flags & self::FILTER_EXIT)) {
if ($flags & self::FILTER_APPEND_ENTRY) {
$this->filterEntryCallbacks[] = $callback;
} else {
\array_unshift($this->filterEntryCallbacks, $callback);
}
}
// Called when exit records came
if ($flags & self::FILTER_EXIT) {
if ($flags & self::FILTER_APPEND_EXIT) {
$this->filterExitCallbacks[] = $callback;
} else {
\array_unshift($this->filterExitCallbacks, $callback);
}
}
} | [
"public",
"function",
"addFilterCallback",
"(",
"$",
"callback",
",",
"$",
"flags",
"=",
"null",
")",
"{",
"$",
"flags",
"=",
"(",
"int",
")",
"$",
"flags",
";",
"if",
"(",
"$",
"flags",
"&",
"self",
"::",
"FILTER_REPLACE_ENTRY",
")",
"{",
"$",
"this... | Register own filter callback.
@param callback (\stdClass $record, bool $isEntry, XDebugPanel $this)
@param int $flags bitmask of self::FILTER_* | [
"Register",
"own",
"filter",
"callback",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L722-L753 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.setFilterCallback | public function setFilterCallback($callback, $flags = null)
{
$flags = ((int) $flags) | self::FILTER_REPLACE;
$this->addFilterCallback($callback, $flags);
} | php | public function setFilterCallback($callback, $flags = null)
{
$flags = ((int) $flags) | self::FILTER_REPLACE;
$this->addFilterCallback($callback, $flags);
} | [
"public",
"function",
"setFilterCallback",
"(",
"$",
"callback",
",",
"$",
"flags",
"=",
"null",
")",
"{",
"$",
"flags",
"=",
"(",
"(",
"int",
")",
"$",
"flags",
")",
"|",
"self",
"::",
"FILTER_REPLACE",
";",
"$",
"this",
"->",
"addFilterCallback",
"("... | Replace all filter callbacks by this one.
@param callback (\stdClass $record, bool $isEntry, XDebugPanel $this)
@param int $flags bitmask of self::FILTER_* | [
"Replace",
"all",
"filter",
"callbacks",
"by",
"this",
"one",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L762-L766 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.traceFunction | public function traceFunction($name, $deep = false, $showInternals = false)
{
if (\is_array($name)) {
$name1 = \implode('::', $name);
$name2 = \implode('->', $name);
} else {
$name1 = $name2 = (string) $name;
}
$cb = function (\stdClass $record, $isEntry) use ($name1, $name2, $deep, $showInternals) {
static $cnt = 0;
if ($record->function === $name1 || $record->function === $name2) {
$cnt += $isEntry ? 1 : -1;
return null;
}
return ($deep && $cnt && ($showInternals || !$record->isInternal)) ? null : self::SKIP;
};
$this->setFilterCallback($cb, self::FILTER_BOTH);
} | php | public function traceFunction($name, $deep = false, $showInternals = false)
{
if (\is_array($name)) {
$name1 = \implode('::', $name);
$name2 = \implode('->', $name);
} else {
$name1 = $name2 = (string) $name;
}
$cb = function (\stdClass $record, $isEntry) use ($name1, $name2, $deep, $showInternals) {
static $cnt = 0;
if ($record->function === $name1 || $record->function === $name2) {
$cnt += $isEntry ? 1 : -1;
return null;
}
return ($deep && $cnt && ($showInternals || !$record->isInternal)) ? null : self::SKIP;
};
$this->setFilterCallback($cb, self::FILTER_BOTH);
} | [
"public",
"function",
"traceFunction",
"(",
"$",
"name",
",",
"$",
"deep",
"=",
"false",
",",
"$",
"showInternals",
"=",
"false",
")",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"$",
"name1",
"=",
"\\",
"implode",
"(",
"'::'... | Trace function by name.
@param string|array $name name of function or pair [class, method]
@param bool $deep show inside function trace too
@param bool $showInternals show internals in inside function trace | [
"Trace",
"function",
"by",
"name",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L788-L810 | train |
hail-framework/framework | src/Debugger/Bar/TracePanel.php | TracePanel.traceFunctionRe | public function traceFunctionRe($re, $deep = false, $showInternals = false)
{
$cb = function (\stdClass $record, $isEntry) use ($re, $deep, $showInternals) {
static $cnt = 0;
if (\preg_match($re, $record->function)) {
$cnt += $isEntry ? 1 : -1;
return null;
}
return ($deep && $cnt && ($showInternals || !$record->isInternal)) ? null : self::SKIP;
};
$this->setFilterCallback($cb, self::FILTER_BOTH);
} | php | public function traceFunctionRe($re, $deep = false, $showInternals = false)
{
$cb = function (\stdClass $record, $isEntry) use ($re, $deep, $showInternals) {
static $cnt = 0;
if (\preg_match($re, $record->function)) {
$cnt += $isEntry ? 1 : -1;
return null;
}
return ($deep && $cnt && ($showInternals || !$record->isInternal)) ? null : self::SKIP;
};
$this->setFilterCallback($cb, self::FILTER_BOTH);
} | [
"public",
"function",
"traceFunctionRe",
"(",
"$",
"re",
",",
"$",
"deep",
"=",
"false",
",",
"$",
"showInternals",
"=",
"false",
")",
"{",
"$",
"cb",
"=",
"function",
"(",
"\\",
"stdClass",
"$",
"record",
",",
"$",
"isEntry",
")",
"use",
"(",
"$",
... | Trace function which name is expressed by PCRE reqular expression.
@param string $re regular expression
@param bool $deep show inside function trace too
@param bool $showInternals show internals in inside function trace | [
"Trace",
"function",
"which",
"name",
"is",
"expressed",
"by",
"PCRE",
"reqular",
"expression",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Debugger/Bar/TracePanel.php#L820-L835 | train |
hail-framework/framework | src/Console/Formatter.php | Formatter.format | public function format($text = '', string $style = 'none')
{
return $this->getStartMark($style) . $text . $this->getClearMark();
} | php | public function format($text = '', string $style = 'none')
{
return $this->getStartMark($style) . $text . $this->getClearMark();
} | [
"public",
"function",
"format",
"(",
"$",
"text",
"=",
"''",
",",
"string",
"$",
"style",
"=",
"'none'",
")",
"{",
"return",
"$",
"this",
"->",
"getStartMark",
"(",
"$",
"style",
")",
".",
"$",
"text",
".",
"$",
"this",
"->",
"getClearMark",
"(",
"... | Formats a text according to the given style or parameters.
@param string $text The text to style
@param string $style A style name
@return string The styled text | [
"Formats",
"a",
"text",
"according",
"to",
"the",
"given",
"style",
"or",
"parameters",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Formatter.php#L171-L174 | train |
hiqdev/hipanel-module-dns | src/widgets/DnsZoneEditWidget.php | DnsZoneEditWidget.registerClientScript | public function registerClientScript()
{
$id = $this->pjaxOptions['id'];
$url = Json::encode($this->buildUrl());
$js = "
$.pjax({
url: $url,
push: false,
replace: false,
container: '#$id',
});
$('#$id').on('pjax:error', function (event, xhr, textStatus, error, options) {
$(this).text(xhr.responseText);
});
";
if ($this->clientScriptWrap instanceof Closure) {
$js = call_user_func($this->clientScriptWrap, $js);
}
Yii::$app->view->registerJs($js);
} | php | public function registerClientScript()
{
$id = $this->pjaxOptions['id'];
$url = Json::encode($this->buildUrl());
$js = "
$.pjax({
url: $url,
push: false,
replace: false,
container: '#$id',
});
$('#$id').on('pjax:error', function (event, xhr, textStatus, error, options) {
$(this).text(xhr.responseText);
});
";
if ($this->clientScriptWrap instanceof Closure) {
$js = call_user_func($this->clientScriptWrap, $js);
}
Yii::$app->view->registerJs($js);
} | [
"public",
"function",
"registerClientScript",
"(",
")",
"{",
"$",
"id",
"=",
"$",
"this",
"->",
"pjaxOptions",
"[",
"'id'",
"]",
";",
"$",
"url",
"=",
"Json",
"::",
"encode",
"(",
"$",
"this",
"->",
"buildUrl",
"(",
")",
")",
";",
"$",
"js",
"=",
... | Registers JS. | [
"Registers",
"JS",
"."
] | 7e9199c95d91a979b7bd4fd07fe801dbe9e69183 | https://github.com/hiqdev/hipanel-module-dns/blob/7e9199c95d91a979b7bd4fd07fe801dbe9e69183/src/widgets/DnsZoneEditWidget.php#L76-L96 | train |
hail-framework/framework | src/Util/Arrays.php | Arrays.searchKey | public static function searchKey(array $arr, $key)
{
$foo = [$key => null];
return ($tmp = \array_search(\key($foo), \array_keys($arr), true)) === false ? null : $tmp;
} | php | public static function searchKey(array $arr, $key)
{
$foo = [$key => null];
return ($tmp = \array_search(\key($foo), \array_keys($arr), true)) === false ? null : $tmp;
} | [
"public",
"static",
"function",
"searchKey",
"(",
"array",
"$",
"arr",
",",
"$",
"key",
")",
"{",
"$",
"foo",
"=",
"[",
"$",
"key",
"=>",
"null",
"]",
";",
"return",
"(",
"$",
"tmp",
"=",
"\\",
"array_search",
"(",
"\\",
"key",
"(",
"$",
"foo",
... | Searches the array for a given key and returns the offset if successful.
@param array $arr
@param int|string $key
@return int|null|string offset if it is found, null otherwise | [
"Searches",
"the",
"array",
"for",
"a",
"given",
"key",
"and",
"returns",
"the",
"offset",
"if",
"successful",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Arrays.php#L208-L213 | train |
hail-framework/framework | src/Util/Arrays.php | Arrays.insertBefore | public static function insertBefore(array &$arr, $key, array $inserted): void
{
$offset = (int) self::searchKey($arr, $key);
$arr = \array_slice($arr, 0, $offset, true) + $inserted + \array_slice($arr, $offset, null, true);
} | php | public static function insertBefore(array &$arr, $key, array $inserted): void
{
$offset = (int) self::searchKey($arr, $key);
$arr = \array_slice($arr, 0, $offset, true) + $inserted + \array_slice($arr, $offset, null, true);
} | [
"public",
"static",
"function",
"insertBefore",
"(",
"array",
"&",
"$",
"arr",
",",
"$",
"key",
",",
"array",
"$",
"inserted",
")",
":",
"void",
"{",
"$",
"offset",
"=",
"(",
"int",
")",
"self",
"::",
"searchKey",
"(",
"$",
"arr",
",",
"$",
"key",
... | Inserts new array before item specified by key.
@param array $arr
@param int|string $key
@param array $inserted | [
"Inserts",
"new",
"array",
"before",
"item",
"specified",
"by",
"key",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Arrays.php#L222-L226 | train |
hail-framework/framework | src/Util/Arrays.php | Arrays.insertAfter | public static function insertAfter(array &$arr, $key, array $inserted): void
{
$offset = self::searchKey($arr, $key);
if ($offset === null) {
$arr += $inserted;
} else {
++$offset;
$arr = \array_slice($arr, 0, $offset, true) + $inserted + \array_slice($arr, $offset, null, true);
}
} | php | public static function insertAfter(array &$arr, $key, array $inserted): void
{
$offset = self::searchKey($arr, $key);
if ($offset === null) {
$arr += $inserted;
} else {
++$offset;
$arr = \array_slice($arr, 0, $offset, true) + $inserted + \array_slice($arr, $offset, null, true);
}
} | [
"public",
"static",
"function",
"insertAfter",
"(",
"array",
"&",
"$",
"arr",
",",
"$",
"key",
",",
"array",
"$",
"inserted",
")",
":",
"void",
"{",
"$",
"offset",
"=",
"self",
"::",
"searchKey",
"(",
"$",
"arr",
",",
"$",
"key",
")",
";",
"if",
... | Inserts new array after item specified by key.
@param array $arr
@param int|string $key
@param array $inserted | [
"Inserts",
"new",
"array",
"after",
"item",
"specified",
"by",
"key",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Arrays.php#L236-L245 | train |
hail-framework/framework | src/Util/Arrays.php | Arrays.renameKey | public static function renameKey(array &$arr, $oldKey, $newKey): void
{
$offset = self::searchKey($arr, $oldKey);
if ($offset !== null) {
$keys = \array_keys($arr);
$keys[$offset] = $newKey;
$arr = \array_combine($keys, $arr);
}
} | php | public static function renameKey(array &$arr, $oldKey, $newKey): void
{
$offset = self::searchKey($arr, $oldKey);
if ($offset !== null) {
$keys = \array_keys($arr);
$keys[$offset] = $newKey;
$arr = \array_combine($keys, $arr);
}
} | [
"public",
"static",
"function",
"renameKey",
"(",
"array",
"&",
"$",
"arr",
",",
"$",
"oldKey",
",",
"$",
"newKey",
")",
":",
"void",
"{",
"$",
"offset",
"=",
"self",
"::",
"searchKey",
"(",
"$",
"arr",
",",
"$",
"oldKey",
")",
";",
"if",
"(",
"$... | Renames key in array.
@param array $arr
@param int|string $oldKey
@param int|string $newKey | [
"Renames",
"key",
"in",
"array",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Arrays.php#L254-L262 | train |
hail-framework/framework | src/Util/Arrays.php | Arrays.grep | public static function grep(array $arr, string $pattern, int $flags = 0): array
{
return Strings::pcre('\preg_grep', [$pattern, $arr, $flags]);
} | php | public static function grep(array $arr, string $pattern, int $flags = 0): array
{
return Strings::pcre('\preg_grep', [$pattern, $arr, $flags]);
} | [
"public",
"static",
"function",
"grep",
"(",
"array",
"$",
"arr",
",",
"string",
"$",
"pattern",
",",
"int",
"$",
"flags",
"=",
"0",
")",
":",
"array",
"{",
"return",
"Strings",
"::",
"pcre",
"(",
"'\\preg_grep'",
",",
"[",
"$",
"pattern",
",",
"$",
... | Returns array entries that match the pattern.
@param array $arr
@param string $pattern
@param int $flags
@return array | [
"Returns",
"array",
"entries",
"that",
"match",
"the",
"pattern",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Arrays.php#L273-L276 | train |
hail-framework/framework | src/Util/Arrays.php | Arrays.pick | public static function pick(array &$arr, $key)
{
if (\array_key_exists($key, $arr)) {
$value = $arr[$key];
unset($arr[$key]);
return $value;
}
return null;
} | php | public static function pick(array &$arr, $key)
{
if (\array_key_exists($key, $arr)) {
$value = $arr[$key];
unset($arr[$key]);
return $value;
}
return null;
} | [
"public",
"static",
"function",
"pick",
"(",
"array",
"&",
"$",
"arr",
",",
"$",
"key",
")",
"{",
"if",
"(",
"\\",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"arr",
")",
")",
"{",
"$",
"value",
"=",
"$",
"arr",
"[",
"$",
"key",
"]",
";",
... | Picks element from the array by key and return its value.
@param array $arr
@param string|int $key array key
@return mixed | [
"Picks",
"element",
"from",
"the",
"array",
"by",
"key",
"and",
"return",
"its",
"value",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Arrays.php#L286-L296 | train |
systemson/collection | src/MultilevelCollection.php | MultilevelCollection.has | public function has(string $key): bool
{
$slug = $this->splitKey($key);
if (is_string($slug)) {
return isset($this[$slug]);
}
$collection = $this->all();
foreach ($this->splitKey($key) as $search) {
if (!isset($collection[$search])) {
return false;
}
$collection = $collection[$search];
}
return true;
} | php | public function has(string $key): bool
{
$slug = $this->splitKey($key);
if (is_string($slug)) {
return isset($this[$slug]);
}
$collection = $this->all();
foreach ($this->splitKey($key) as $search) {
if (!isset($collection[$search])) {
return false;
}
$collection = $collection[$search];
}
return true;
} | [
"public",
"function",
"has",
"(",
"string",
"$",
"key",
")",
":",
"bool",
"{",
"$",
"slug",
"=",
"$",
"this",
"->",
"splitKey",
"(",
"$",
"key",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"slug",
")",
")",
"{",
"return",
"isset",
"(",
"$",
"th... | Whether an item is present it the collection
@param string $key The item's key
@return bool | [
"Whether",
"an",
"item",
"is",
"present",
"it",
"the",
"collection"
] | fb3ae1a78806aafabc0562db96822e8b99dc2a64 | https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/MultilevelCollection.php#L106-L125 | train |
systemson/collection | src/MultilevelCollection.php | MultilevelCollection.get | public function get(string $key)
{
$slug = $this->splitKey($key);
if (is_string($slug)) {
if (isset($this[$slug])) {
return $this[$slug];
}
return null;
}
$array = $this->toArray();
foreach ($slug as $search) {
if (isset($array[$search])) {
$array = $array[$search];
} else {
return;
}
}
return $array;
} | php | public function get(string $key)
{
$slug = $this->splitKey($key);
if (is_string($slug)) {
if (isset($this[$slug])) {
return $this[$slug];
}
return null;
}
$array = $this->toArray();
foreach ($slug as $search) {
if (isset($array[$search])) {
$array = $array[$search];
} else {
return;
}
}
return $array;
} | [
"public",
"function",
"get",
"(",
"string",
"$",
"key",
")",
"{",
"$",
"slug",
"=",
"$",
"this",
"->",
"splitKey",
"(",
"$",
"key",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"slug",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"[",
... | Gets an item from collection.
@param string $key The item's key
@return mixed|void The item's value or void if the key doesn't exists. | [
"Gets",
"an",
"item",
"from",
"collection",
"."
] | fb3ae1a78806aafabc0562db96822e8b99dc2a64 | https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/MultilevelCollection.php#L134-L156 | train |
systemson/collection | src/MultilevelCollection.php | MultilevelCollection.unset | public function unset(string $key): void
{
$slug = $this->splitKey($key);
if (is_string($slug)) {
if (isset($this[$slug])) {
unset($this[$slug]);
}
} else {
if ($this->has($key)) {
$this->set($key, null);
}
}
} | php | public function unset(string $key): void
{
$slug = $this->splitKey($key);
if (is_string($slug)) {
if (isset($this[$slug])) {
unset($this[$slug]);
}
} else {
if ($this->has($key)) {
$this->set($key, null);
}
}
} | [
"public",
"function",
"unset",
"(",
"string",
"$",
"key",
")",
":",
"void",
"{",
"$",
"slug",
"=",
"$",
"this",
"->",
"splitKey",
"(",
"$",
"key",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"slug",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
... | Unsets an item from collection.
@param string $key The item's key
@return void | [
"Unsets",
"an",
"item",
"from",
"collection",
"."
] | fb3ae1a78806aafabc0562db96822e8b99dc2a64 | https://github.com/systemson/collection/blob/fb3ae1a78806aafabc0562db96822e8b99dc2a64/src/MultilevelCollection.php#L165-L178 | train |
hail-framework/framework | src/Database/Migration/Table.php | Table.insert | public function insert($data)
{
// handle array of array situations
if (isset($data[0]) && is_array($data[0])) {
foreach ($data as $row) {
$this->data[] = $row;
}
return $this;
}
$this->data[] = $data;
return $this;
} | php | public function insert($data)
{
// handle array of array situations
if (isset($data[0]) && is_array($data[0])) {
foreach ($data as $row) {
$this->data[] = $row;
}
return $this;
}
$this->data[] = $data;
return $this;
} | [
"public",
"function",
"insert",
"(",
"$",
"data",
")",
"{",
"// handle array of array situations",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"0",
"]",
")",
"&&",
"is_array",
"(",
"$",
"data",
"[",
"0",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"data"... | Insert data into the table.
@param array $data array of data in the form:
array(
array("col1" => "value1", "col2" => "anotherValue1"),
array("col2" => "value2", "col2" => "anotherValue2"),
)
or array("col1" => "value1", "col2" => "anotherValue1")
@return Table | [
"Insert",
"data",
"into",
"the",
"table",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Table.php#L629-L642 | train |
hail-framework/framework | src/Database/Migration/Table.php | Table.update | public function update()
{
if (!$this->exists()) {
throw new \RuntimeException('Cannot update a table that doesn\'t exist!');
}
// update table
foreach ($this->getPendingColumns() as $column) {
$this->getAdapter()->addColumn($this, $column);
}
foreach ($this->getIndexes() as $index) {
$this->getAdapter()->addIndex($this, $index);
}
foreach ($this->getForeignKeys() as $foreignKey) {
$this->getAdapter()->addForeignKey($this, $foreignKey);
}
$this->saveData();
$this->reset(); // reset pending changes
} | php | public function update()
{
if (!$this->exists()) {
throw new \RuntimeException('Cannot update a table that doesn\'t exist!');
}
// update table
foreach ($this->getPendingColumns() as $column) {
$this->getAdapter()->addColumn($this, $column);
}
foreach ($this->getIndexes() as $index) {
$this->getAdapter()->addIndex($this, $index);
}
foreach ($this->getForeignKeys() as $foreignKey) {
$this->getAdapter()->addForeignKey($this, $foreignKey);
}
$this->saveData();
$this->reset(); // reset pending changes
} | [
"public",
"function",
"update",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"exists",
"(",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Cannot update a table that doesn\\'t exist!'",
")",
";",
"}",
"// update table",
"foreach",
"(",
... | Updates a table from the object instance.
@throws \RuntimeException
@return void | [
"Updates",
"a",
"table",
"from",
"the",
"object",
"instance",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Table.php#L662-L683 | train |
hail-framework/framework | src/Database/Migration/Table.php | Table.saveData | public function saveData()
{
$rows = $this->getData();
if (empty($rows)) {
return;
}
$bulk = true;
$row = current($rows);
$c = array_keys($row);
foreach ($this->getData() as $row) {
$k = array_keys($row);
if ($k != $c) {
$bulk = false;
break;
}
}
if ($bulk) {
$this->getAdapter()->bulkinsert($this, $this->getData());
} else {
foreach ($this->getData() as $row) {
$this->getAdapter()->insert($this, $row);
}
}
} | php | public function saveData()
{
$rows = $this->getData();
if (empty($rows)) {
return;
}
$bulk = true;
$row = current($rows);
$c = array_keys($row);
foreach ($this->getData() as $row) {
$k = array_keys($row);
if ($k != $c) {
$bulk = false;
break;
}
}
if ($bulk) {
$this->getAdapter()->bulkinsert($this, $this->getData());
} else {
foreach ($this->getData() as $row) {
$this->getAdapter()->insert($this, $row);
}
}
} | [
"public",
"function",
"saveData",
"(",
")",
"{",
"$",
"rows",
"=",
"$",
"this",
"->",
"getData",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"rows",
")",
")",
"{",
"return",
";",
"}",
"$",
"bulk",
"=",
"true",
";",
"$",
"row",
"=",
"current",
... | Commit the pending data waiting for insertion.
@return void | [
"Commit",
"the",
"pending",
"data",
"waiting",
"for",
"insertion",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Table.php#L690-L715 | train |
hail-framework/framework | src/Http/Message/Response.php | Response.setStatusCode | private function setStatusCode($code, $reasonPhrase = ''): void
{
if (
!\is_numeric($code) || \is_float($code) ||
$code < static::MIN_STATUS_CODE_VALUE ||
$code > static::MAX_STATUS_CODE_VALUE
) {
throw new \InvalidArgumentException(sprintf(
'Invalid status code "%s"; must be an integer between %d and %d, inclusive',
\is_scalar($code) ? $code : \gettype($code),
static::MIN_STATUS_CODE_VALUE,
static::MAX_STATUS_CODE_VALUE
));
}
if (!\is_string($reasonPhrase)) {
throw new \InvalidArgumentException(\sprintf(
'Unsupported response reason phrase; must be a string, received %s',
\is_object($reasonPhrase) ? \get_class($reasonPhrase) : \gettype($reasonPhrase)
));
}
if ($reasonPhrase === '' && isset($this->phrases[$code])) {
$reasonPhrase = self::$phrases[$code];
}
$this->reasonPhrase = $reasonPhrase;
$this->statusCode = (int) $code;
} | php | private function setStatusCode($code, $reasonPhrase = ''): void
{
if (
!\is_numeric($code) || \is_float($code) ||
$code < static::MIN_STATUS_CODE_VALUE ||
$code > static::MAX_STATUS_CODE_VALUE
) {
throw new \InvalidArgumentException(sprintf(
'Invalid status code "%s"; must be an integer between %d and %d, inclusive',
\is_scalar($code) ? $code : \gettype($code),
static::MIN_STATUS_CODE_VALUE,
static::MAX_STATUS_CODE_VALUE
));
}
if (!\is_string($reasonPhrase)) {
throw new \InvalidArgumentException(\sprintf(
'Unsupported response reason phrase; must be a string, received %s',
\is_object($reasonPhrase) ? \get_class($reasonPhrase) : \gettype($reasonPhrase)
));
}
if ($reasonPhrase === '' && isset($this->phrases[$code])) {
$reasonPhrase = self::$phrases[$code];
}
$this->reasonPhrase = $reasonPhrase;
$this->statusCode = (int) $code;
} | [
"private",
"function",
"setStatusCode",
"(",
"$",
"code",
",",
"$",
"reasonPhrase",
"=",
"''",
")",
":",
"void",
"{",
"if",
"(",
"!",
"\\",
"is_numeric",
"(",
"$",
"code",
")",
"||",
"\\",
"is_float",
"(",
"$",
"code",
")",
"||",
"$",
"code",
"<",
... | Set a valid status code.
@param int $code
@param string $reasonPhrase
@throws \InvalidArgumentException on an invalid status code. | [
"Set",
"a",
"valid",
"status",
"code",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Message/Response.php#L159-L187 | train |
DoSomething/gateway | src/AuthorizesWithBasicAuth.php | AuthorizesWithBasicAuth.getCredentials | protected function getCredentials()
{
if (empty($this->username) || empty($this->password)) {
throw new \Exception('Basic authentication requires a $username & $password property.');
}
return [$this->username, $this->password];
} | php | protected function getCredentials()
{
if (empty($this->username) || empty($this->password)) {
throw new \Exception('Basic authentication requires a $username & $password property.');
}
return [$this->username, $this->password];
} | [
"protected",
"function",
"getCredentials",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"username",
")",
"||",
"empty",
"(",
"$",
"this",
"->",
"password",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Basic authentication requires... | Get the authorization credentials for a request
@return null|array
@throws \Exception | [
"Get",
"the",
"authorization",
"credentials",
"for",
"a",
"request"
] | 89c1c59c6af038dff790df6d5aaa9fc703246568 | https://github.com/DoSomething/gateway/blob/89c1c59c6af038dff790df6d5aaa9fc703246568/src/AuthorizesWithBasicAuth.php#L40-L47 | train |
hail-framework/framework | src/Console/Application.php | Application.runWithTry | public function runWithTry(array $argv)
{
try {
return $this->run($argv);
} catch (CommandArgumentNotEnoughException $e) {
$this->logger->error($e->getMessage());
$this->logger->writeln('Expected argument prototypes:');
foreach ($e->getCommand()->getAllCommandPrototype() as $p) {
$this->logger->writeln("\t" . $p);
}
$this->logger->newline();
} catch (CommandNotFoundException $e) {
$this->logger->error($e->getMessage() . ' available commands are: ' .
implode(', ', $e->getCommand()->getVisibleCommandList())
);
$this->logger->newline();
$this->logger->writeln('Please try the command below to see the details:');
$this->logger->newline();
$this->logger->writeln("\t" . $this->getProgramName() . ' help ');
$this->logger->newline();
} catch (BadMethodCallException $e) {
$this->logger->error($e->getMessage());
$this->logger->error('Seems like an application logic error, please contact the developer.');
} catch (Exception $e) {
ExceptionPrinter::dump($e, $this->getOption('debug'));
}
return false;
} | php | public function runWithTry(array $argv)
{
try {
return $this->run($argv);
} catch (CommandArgumentNotEnoughException $e) {
$this->logger->error($e->getMessage());
$this->logger->writeln('Expected argument prototypes:');
foreach ($e->getCommand()->getAllCommandPrototype() as $p) {
$this->logger->writeln("\t" . $p);
}
$this->logger->newline();
} catch (CommandNotFoundException $e) {
$this->logger->error($e->getMessage() . ' available commands are: ' .
implode(', ', $e->getCommand()->getVisibleCommandList())
);
$this->logger->newline();
$this->logger->writeln('Please try the command below to see the details:');
$this->logger->newline();
$this->logger->writeln("\t" . $this->getProgramName() . ' help ');
$this->logger->newline();
} catch (BadMethodCallException $e) {
$this->logger->error($e->getMessage());
$this->logger->error('Seems like an application logic error, please contact the developer.');
} catch (Exception $e) {
ExceptionPrinter::dump($e, $this->getOption('debug'));
}
return false;
} | [
"public",
"function",
"runWithTry",
"(",
"array",
"$",
"argv",
")",
"{",
"try",
"{",
"return",
"$",
"this",
"->",
"run",
"(",
"$",
"argv",
")",
";",
"}",
"catch",
"(",
"CommandArgumentNotEnoughException",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"logger"... | Execute `run` method with a default try & catch block to catch the exception.
@param array $argv
@return bool return true for success, false for failure. the returned
state will be reflected to the exit code of the process. | [
"Execute",
"run",
"method",
"with",
"a",
"default",
"try",
"&",
"catch",
"block",
"to",
"catch",
"the",
"exception",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Application.php#L117-L146 | train |
hail-framework/framework | src/Console/Application.php | Application.run | public function run(array $argv)
{
$this->setProgramName($argv[0]);
$currentCommand = $this;
// init application,
// before parsing options, we have to known the registered commands.
$currentCommand->init();
// use getoption kit to parse application options
$parser = new ContinuousOptionParser($currentCommand->getOptionCollection());
// parse the first part options (options after script name)
// option parser should stop before next command name.
//
// $ app.php -v -d next
// |
// |->> parser
//
//
$currentCommand->setOptions(
$parser->parse($argv)
);
if (false === $currentCommand->prepare()) {
return false;
}
$commandStack = [];
$arguments = [];
// build the command list from command line arguments
while (!$parser->isEnd()) {
$a = $parser->getCurrentArgument();
// if current command is in subcommand list.
if ($currentCommand->hasCommands()) {
if (!$currentCommand->hasCommand($a)) {
if (!$this->getOption('no-interact') && ($guess = $currentCommand->guessCommand($a)) !== null) {
$a = $guess;
} else {
throw new CommandNotFoundException($currentCommand, $a);
}
}
$parser->advance(); // advance position
// get command object of "$a"
/** @var Command $nextCommand */
$nextCommand = $currentCommand->getCommand($a);
$parser->setSpecs($nextCommand->getOptionCollection());
// parse the option result for command.
$nextCommand->setOptions(
$parser->continueParse()
);
$commandStack[] = $currentCommand = $nextCommand; // save command object into the stack
} else {
$r = $parser->continueParse();
if (count($r)) {
// get the option result and merge the new result
$currentCommand->getOptions()->merge($r);
} else {
$a = $parser->advance();
$arguments[] = $a;
}
}
}
foreach ($commandStack as $cmd) {
if (false === $cmd->prepare()) {
return false;
}
}
// get last command and run
if ($lastCommand = array_pop($commandStack)) {
$lastCommand->executeWrapper($arguments);
$lastCommand->finish();
while ($cmd = array_pop($commandStack)) {
// call finish stage.. of every command.
$cmd->finish();
}
} else {
// no command specified.
$this->executeWrapper($arguments);
return true;
}
$currentCommand->finish();
$this->finish();
return true;
} | php | public function run(array $argv)
{
$this->setProgramName($argv[0]);
$currentCommand = $this;
// init application,
// before parsing options, we have to known the registered commands.
$currentCommand->init();
// use getoption kit to parse application options
$parser = new ContinuousOptionParser($currentCommand->getOptionCollection());
// parse the first part options (options after script name)
// option parser should stop before next command name.
//
// $ app.php -v -d next
// |
// |->> parser
//
//
$currentCommand->setOptions(
$parser->parse($argv)
);
if (false === $currentCommand->prepare()) {
return false;
}
$commandStack = [];
$arguments = [];
// build the command list from command line arguments
while (!$parser->isEnd()) {
$a = $parser->getCurrentArgument();
// if current command is in subcommand list.
if ($currentCommand->hasCommands()) {
if (!$currentCommand->hasCommand($a)) {
if (!$this->getOption('no-interact') && ($guess = $currentCommand->guessCommand($a)) !== null) {
$a = $guess;
} else {
throw new CommandNotFoundException($currentCommand, $a);
}
}
$parser->advance(); // advance position
// get command object of "$a"
/** @var Command $nextCommand */
$nextCommand = $currentCommand->getCommand($a);
$parser->setSpecs($nextCommand->getOptionCollection());
// parse the option result for command.
$nextCommand->setOptions(
$parser->continueParse()
);
$commandStack[] = $currentCommand = $nextCommand; // save command object into the stack
} else {
$r = $parser->continueParse();
if (count($r)) {
// get the option result and merge the new result
$currentCommand->getOptions()->merge($r);
} else {
$a = $parser->advance();
$arguments[] = $a;
}
}
}
foreach ($commandStack as $cmd) {
if (false === $cmd->prepare()) {
return false;
}
}
// get last command and run
if ($lastCommand = array_pop($commandStack)) {
$lastCommand->executeWrapper($arguments);
$lastCommand->finish();
while ($cmd = array_pop($commandStack)) {
// call finish stage.. of every command.
$cmd->finish();
}
} else {
// no command specified.
$this->executeWrapper($arguments);
return true;
}
$currentCommand->finish();
$this->finish();
return true;
} | [
"public",
"function",
"run",
"(",
"array",
"$",
"argv",
")",
"{",
"$",
"this",
"->",
"setProgramName",
"(",
"$",
"argv",
"[",
"0",
"]",
")",
";",
"$",
"currentCommand",
"=",
"$",
"this",
";",
"// init application,",
"// before parsing options, we have to known... | Run application with
list argv
@param array $argv
@return bool return true for success, false for failure. the returned
state will be reflected to the exit code of the process.
@throws CommandNotFoundException | [
"Run",
"application",
"with",
"list",
"argv"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Application.php#L159-L261 | train |
hail-framework/framework | src/Console/Application.php | Application.prepare | public function prepare()
{
$this->startedAt = microtime(true);
if ($this->getOption('debug')) {
$this->logger->setLevel(LogLevel::DEBUG);
} elseif ($this->getOption('verbose')) {
$this->logger->setLevel(LogLevel::INFO);
} elseif ($this->getOption('quiet')) {
$this->logger->setLevel(LogLevel::ERROR);
} elseif ($this->config('debug', false)) {
$this->logger->setLevel(LogLevel::DEBUG);
} elseif ($this->config('verbose', false)) {
$this->logger->setLevel(LogLevel::INFO);
}
return true;
} | php | public function prepare()
{
$this->startedAt = microtime(true);
if ($this->getOption('debug')) {
$this->logger->setLevel(LogLevel::DEBUG);
} elseif ($this->getOption('verbose')) {
$this->logger->setLevel(LogLevel::INFO);
} elseif ($this->getOption('quiet')) {
$this->logger->setLevel(LogLevel::ERROR);
} elseif ($this->config('debug', false)) {
$this->logger->setLevel(LogLevel::DEBUG);
} elseif ($this->config('verbose', false)) {
$this->logger->setLevel(LogLevel::INFO);
}
return true;
} | [
"public",
"function",
"prepare",
"(",
")",
"{",
"$",
"this",
"->",
"startedAt",
"=",
"microtime",
"(",
"true",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getOption",
"(",
"'debug'",
")",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"setLevel",
"(",
"... | This is a `before` trigger of an app. when the application is getting
started, we run `prepare` method to prepare the settings. | [
"This",
"is",
"a",
"before",
"trigger",
"of",
"an",
"app",
".",
"when",
"the",
"application",
"is",
"getting",
"started",
"we",
"run",
"prepare",
"method",
"to",
"prepare",
"the",
"settings",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Application.php#L267-L284 | train |
hail-framework/framework | src/Console/Application.php | Application.execute | public function execute(...$arguments)
{
$options = $this->getOptions();
if ($options->version) {
$this->logger->writeln($this->name() . ' - ' . static::VERSION);
$this->logger->writeln('console core: ' . static::CORE_VERSION);
return;
}
// show list and help by default
$help = $this->getCommand('help');
$help->setOptions($options);
if ($help || $options->help) {
$help->executeWrapper($arguments);
return;
}
throw new CommandNotFoundException($this, 'help');
} | php | public function execute(...$arguments)
{
$options = $this->getOptions();
if ($options->version) {
$this->logger->writeln($this->name() . ' - ' . static::VERSION);
$this->logger->writeln('console core: ' . static::CORE_VERSION);
return;
}
// show list and help by default
$help = $this->getCommand('help');
$help->setOptions($options);
if ($help || $options->help) {
$help->executeWrapper($arguments);
return;
}
throw new CommandNotFoundException($this, 'help');
} | [
"public",
"function",
"execute",
"(",
"...",
"$",
"arguments",
")",
"{",
"$",
"options",
"=",
"$",
"this",
"->",
"getOptions",
"(",
")",
";",
"if",
"(",
"$",
"options",
"->",
"version",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"writeln",
"(",
"... | This method is the top logic of an application. when there is no
argument provided, we show help content by default.
@param array ...$arguments
@throws CommandNotFoundException | [
"This",
"method",
"is",
"the",
"top",
"logic",
"of",
"an",
"application",
".",
"when",
"there",
"is",
"no",
"argument",
"provided",
"we",
"show",
"help",
"content",
"by",
"default",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Application.php#L322-L342 | train |
hail-framework/framework | src/Image/Size.php | Size.getConstraint | private function getConstraint(Closure $callback = null)
{
$constraint = new Constraint(clone $this);
if ($callback !== null) {
$callback($constraint);
}
return $constraint;
} | php | private function getConstraint(Closure $callback = null)
{
$constraint = new Constraint(clone $this);
if ($callback !== null) {
$callback($constraint);
}
return $constraint;
} | [
"private",
"function",
"getConstraint",
"(",
"Closure",
"$",
"callback",
"=",
"null",
")",
"{",
"$",
"constraint",
"=",
"new",
"Constraint",
"(",
"clone",
"$",
"this",
")",
";",
"if",
"(",
"$",
"callback",
"!==",
"null",
")",
"{",
"$",
"callback",
"(",... | Runs constraints on current size
@param Closure|null $callback
@return \Hail\Image\Constraint | [
"Runs",
"constraints",
"on",
"current",
"size"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Image/Size.php#L370-L379 | train |
hail-framework/framework | src/Http/Helpers.php | Helpers.getMethod | public static function getMethod(array $server): string
{
$method = $server['REQUEST_METHOD'] ?? 'GET';
if ($method === 'POST' &&
isset(
$server['HTTP_X_HTTP_METHOD_OVERRIDE'],
self::$methods[$server['HTTP_X_HTTP_METHOD_OVERRIDE']]
)
) {
$method = $server['HTTP_X_HTTP_METHOD_OVERRIDE'];
}
return $method;
} | php | public static function getMethod(array $server): string
{
$method = $server['REQUEST_METHOD'] ?? 'GET';
if ($method === 'POST' &&
isset(
$server['HTTP_X_HTTP_METHOD_OVERRIDE'],
self::$methods[$server['HTTP_X_HTTP_METHOD_OVERRIDE']]
)
) {
$method = $server['HTTP_X_HTTP_METHOD_OVERRIDE'];
}
return $method;
} | [
"public",
"static",
"function",
"getMethod",
"(",
"array",
"$",
"server",
")",
":",
"string",
"{",
"$",
"method",
"=",
"$",
"server",
"[",
"'REQUEST_METHOD'",
"]",
"??",
"'GET'",
";",
"if",
"(",
"$",
"method",
"===",
"'POST'",
"&&",
"isset",
"(",
"$",
... | Get method from server variables.
@param array $server Typically $_SERVER or similar structure.
@return string | [
"Get",
"method",
"from",
"server",
"variables",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Helpers.php#L244-L257 | train |
hail-framework/framework | src/Http/Helpers.php | Helpers.getProtocol | public static function getProtocol(array $server): string
{
if (!isset($server['SERVER_PROTOCOL'])) {
return '1.1';
}
if (!\preg_match('#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#', $server['SERVER_PROTOCOL'], $matches)) {
throw new \UnexpectedValueException("Unrecognized protocol version ({$server['SERVER_PROTOCOL']})");
}
return $matches['version'];
} | php | public static function getProtocol(array $server): string
{
if (!isset($server['SERVER_PROTOCOL'])) {
return '1.1';
}
if (!\preg_match('#^(HTTP/)?(?P<version>[1-9]\d*(?:\.\d)?)$#', $server['SERVER_PROTOCOL'], $matches)) {
throw new \UnexpectedValueException("Unrecognized protocol version ({$server['SERVER_PROTOCOL']})");
}
return $matches['version'];
} | [
"public",
"static",
"function",
"getProtocol",
"(",
"array",
"$",
"server",
")",
":",
"string",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"server",
"[",
"'SERVER_PROTOCOL'",
"]",
")",
")",
"{",
"return",
"'1.1'",
";",
"}",
"if",
"(",
"!",
"\\",
"preg_m... | Get protocol from server variables.
@param array $server Typically $_SERVER or similar structure.
@return string
@throws \UnexpectedValueException | [
"Get",
"protocol",
"from",
"server",
"variables",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Helpers.php#L267-L278 | train |
hail-framework/framework | src/Http/Helpers.php | Helpers.fixContentLength | public static function fixContentLength(MessageInterface $response): MessageInterface
{
$size = $response->getBody()->getSize();
if ($size !== null) {
return $response->withHeader('Content-Length', (string) $size);
}
return $response->withoutHeader('Content-Length');
} | php | public static function fixContentLength(MessageInterface $response): MessageInterface
{
$size = $response->getBody()->getSize();
if ($size !== null) {
return $response->withHeader('Content-Length', (string) $size);
}
return $response->withoutHeader('Content-Length');
} | [
"public",
"static",
"function",
"fixContentLength",
"(",
"MessageInterface",
"$",
"response",
")",
":",
"MessageInterface",
"{",
"$",
"size",
"=",
"$",
"response",
"->",
"getBody",
"(",
")",
"->",
"getSize",
"(",
")",
";",
"if",
"(",
"$",
"size",
"!==",
... | Add or remove the Content-Length header
Used by middlewares that modify the body content
@param MessageInterface $response
@return MessageInterface | [
"Add",
"or",
"remove",
"the",
"Content",
"-",
"Length",
"header",
"Used",
"by",
"middlewares",
"that",
"modify",
"the",
"body",
"content"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Http/Helpers.php#L327-L335 | train |
hail-framework/framework | src/Database/Migration/Config.php | Config.getEnvironments | public function getEnvironments()
{
if (isset($this->values['environments'])) {
$environments = [];
foreach ($this->values['environments'] as $key => $value) {
if (is_array($value)) {
$environments[$key] = $value;
}
}
return $environments;
}
return null;
} | php | public function getEnvironments()
{
if (isset($this->values['environments'])) {
$environments = [];
foreach ($this->values['environments'] as $key => $value) {
if (is_array($value)) {
$environments[$key] = $value;
}
}
return $environments;
}
return null;
} | [
"public",
"function",
"getEnvironments",
"(",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"'environments'",
"]",
")",
")",
"{",
"$",
"environments",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"values",
"[",
"'envi... | Returns the configuration for each environment.
This method returns <code>null</code> if no environments exist.
@return array|null | [
"Returns",
"the",
"configuration",
"for",
"each",
"environment",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Config.php#L71-L85 | train |
hail-framework/framework | src/Database/Migration/Config.php | Config.getDefaultEnvironment | public function getDefaultEnvironment()
{
// if the user has configured a default database then use it,
// providing it actually exists!
if (isset($this->values['environments']['default_database'])) {
if ($this->getEnvironment($this->values['environments']['default_database'])) {
return $this->values['environments']['default_database'];
}
throw new \RuntimeException(sprintf(
'The environment configuration for \'%s\' is missing',
$this->values['environments']['default_database']
));
}
// else default to the first available one
if (is_array($this->getEnvironments()) && count($this->getEnvironments()) > 0) {
$names = array_keys($this->getEnvironments());
return $names[0];
}
throw new \RuntimeException('Could not find a default environment');
} | php | public function getDefaultEnvironment()
{
// if the user has configured a default database then use it,
// providing it actually exists!
if (isset($this->values['environments']['default_database'])) {
if ($this->getEnvironment($this->values['environments']['default_database'])) {
return $this->values['environments']['default_database'];
}
throw new \RuntimeException(sprintf(
'The environment configuration for \'%s\' is missing',
$this->values['environments']['default_database']
));
}
// else default to the first available one
if (is_array($this->getEnvironments()) && count($this->getEnvironments()) > 0) {
$names = array_keys($this->getEnvironments());
return $names[0];
}
throw new \RuntimeException('Could not find a default environment');
} | [
"public",
"function",
"getDefaultEnvironment",
"(",
")",
"{",
"// if the user has configured a default database then use it,",
"// providing it actually exists!",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"'environments'",
"]",
"[",
"'default_database'",
"]... | Gets the default environment name.
@throws \RuntimeException
@return string | [
"Gets",
"the",
"default",
"environment",
"name",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Config.php#L129-L152 | train |
hail-framework/framework | src/Database/Migration/Config.php | Config.getMigrationBaseClassName | public function getMigrationBaseClassName($dropNamespace = true)
{
$className = $this->values['migration_base_class'] ?? AbstractMigration::class;
if ($dropNamespace) {
return substr(strrchr($className, '\\'), 1) ?: $className;
}
return $className;
} | php | public function getMigrationBaseClassName($dropNamespace = true)
{
$className = $this->values['migration_base_class'] ?? AbstractMigration::class;
if ($dropNamespace) {
return substr(strrchr($className, '\\'), 1) ?: $className;
}
return $className;
} | [
"public",
"function",
"getMigrationBaseClassName",
"(",
"$",
"dropNamespace",
"=",
"true",
")",
"{",
"$",
"className",
"=",
"$",
"this",
"->",
"values",
"[",
"'migration_base_class'",
"]",
"??",
"AbstractMigration",
"::",
"class",
";",
"if",
"(",
"$",
"dropNam... | Gets the base class name for migrations.
@param bool $dropNamespace Return the base migration class name without the namespace.
@return string | [
"Gets",
"the",
"base",
"class",
"name",
"for",
"migrations",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Database/Migration/Config.php#L191-L200 | train |
hail-framework/framework | src/Console/Command/Help.php | Help.execute | public function execute(...$commandNames)
{
$logger = $this->logger;
$app = $this->getApplication();
$progname = basename($app->getProgramName());
// if there is no subcommand to render help, show all available commands.
$count = count($commandNames);
if ($count) {
$cmd = $app;
for ($i = 0; $cmd && $i < $count; ++$i) {
$cmd = $cmd->getCommand($commandNames[$i]);
}
if (!$cmd) {
throw new \Exception('Command entry ' . implode(' ', $commandNames) . ' not found');
}
if ($brief = $cmd->brief()) {
$logger->writeln('NAME', 'yellow');
$logger->writeln("\t<strong_white>" . $cmd->name() . '</strong_white> - ' . $brief);
$logger->newline();
}
if ($aliases = $cmd->aliases()) {
$logger->writeln('ALIASES', 'yellow');
$logger->writeln("\t<strong_white>" . implode(', ', $aliases) . '</strong_white>');
$logger->newline();
}
$this->printUsage($cmd);
$logger->writeln('SYNOPSIS', 'yellow');
$prototypes = $cmd->getAllCommandPrototype();
foreach ($prototypes as $prototype) {
$logger->writeln("\t" . ' ' . $prototype);
}
$logger->newline();
$this->printOptions($cmd);
$this->printCommand($cmd);
$this->printHelp($cmd);
} else {
// print application
$cmd = $this->parent;
$logger->writeln(ucfirst($cmd->brief()), 'strong_white');
$logger->newline();
$this->printUsage($cmd);
$logger->writeln('SYNOPSIS', 'yellow');
$logger->write("\t" . $progname);
if (!empty($cmd->getOptionCollection()->options)) {
$logger->write(' [options]');
}
if ($cmd->hasCommands()) {
$logger->write(' <command>');
} else {
foreach ($cmd->getArguments() as $argument) {
$logger->write(' <' . $argument->name() . '>');
}
}
$logger->newline();
$logger->newline();
$this->printOptions($cmd);
$this->printCommand($cmd);
$this->printHelp($cmd);
}
} | php | public function execute(...$commandNames)
{
$logger = $this->logger;
$app = $this->getApplication();
$progname = basename($app->getProgramName());
// if there is no subcommand to render help, show all available commands.
$count = count($commandNames);
if ($count) {
$cmd = $app;
for ($i = 0; $cmd && $i < $count; ++$i) {
$cmd = $cmd->getCommand($commandNames[$i]);
}
if (!$cmd) {
throw new \Exception('Command entry ' . implode(' ', $commandNames) . ' not found');
}
if ($brief = $cmd->brief()) {
$logger->writeln('NAME', 'yellow');
$logger->writeln("\t<strong_white>" . $cmd->name() . '</strong_white> - ' . $brief);
$logger->newline();
}
if ($aliases = $cmd->aliases()) {
$logger->writeln('ALIASES', 'yellow');
$logger->writeln("\t<strong_white>" . implode(', ', $aliases) . '</strong_white>');
$logger->newline();
}
$this->printUsage($cmd);
$logger->writeln('SYNOPSIS', 'yellow');
$prototypes = $cmd->getAllCommandPrototype();
foreach ($prototypes as $prototype) {
$logger->writeln("\t" . ' ' . $prototype);
}
$logger->newline();
$this->printOptions($cmd);
$this->printCommand($cmd);
$this->printHelp($cmd);
} else {
// print application
$cmd = $this->parent;
$logger->writeln(ucfirst($cmd->brief()), 'strong_white');
$logger->newline();
$this->printUsage($cmd);
$logger->writeln('SYNOPSIS', 'yellow');
$logger->write("\t" . $progname);
if (!empty($cmd->getOptionCollection()->options)) {
$logger->write(' [options]');
}
if ($cmd->hasCommands()) {
$logger->write(' <command>');
} else {
foreach ($cmd->getArguments() as $argument) {
$logger->write(' <' . $argument->name() . '>');
}
}
$logger->newline();
$logger->newline();
$this->printOptions($cmd);
$this->printCommand($cmd);
$this->printHelp($cmd);
}
} | [
"public",
"function",
"execute",
"(",
"...",
"$",
"commandNames",
")",
"{",
"$",
"logger",
"=",
"$",
"this",
"->",
"logger",
";",
"$",
"app",
"=",
"$",
"this",
"->",
"getApplication",
"(",
")",
";",
"$",
"progname",
"=",
"basename",
"(",
"$",
"app",
... | Show command help message.
@param array ...$commandNames command name
@throws \Exception | [
"Show",
"command",
"help",
"message",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Command/Help.php#L74-L146 | train |
cfxmarkets/php-public-models | src/Exchange/Order.php | Order.validateStatusActive | protected function validateStatusActive($field) {
if (!$this->initializing) {
$passedStates = [
'active' => ["Order Active", "This order is currently active and cannot be altered"],
'cancelled' => ["Item Cancelled", "This order has been cancelled and cannot be altered"],
'matched' => ["Item Sold", "This order has already been successfully executed and sold and cannot be altered"],
'expired' => ["Item Expired", "This intent has expired and cannot be altered"],
];
if (in_array($this->getStatus(), array_keys($passedStates), true)) {
$e = $passedStates[$this->getStatus()];
$this->setError($field, 'immutableStatus', [
"title" => "Order Not Alterable",
"detail" => $e[1],
]);
return false;
} else {
$this->clearError($field, 'immutableStatus');
return true;
}
}
} | php | protected function validateStatusActive($field) {
if (!$this->initializing) {
$passedStates = [
'active' => ["Order Active", "This order is currently active and cannot be altered"],
'cancelled' => ["Item Cancelled", "This order has been cancelled and cannot be altered"],
'matched' => ["Item Sold", "This order has already been successfully executed and sold and cannot be altered"],
'expired' => ["Item Expired", "This intent has expired and cannot be altered"],
];
if (in_array($this->getStatus(), array_keys($passedStates), true)) {
$e = $passedStates[$this->getStatus()];
$this->setError($field, 'immutableStatus', [
"title" => "Order Not Alterable",
"detail" => $e[1],
]);
return false;
} else {
$this->clearError($field, 'immutableStatus');
return true;
}
}
} | [
"protected",
"function",
"validateStatusActive",
"(",
"$",
"field",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"initializing",
")",
"{",
"$",
"passedStates",
"=",
"[",
"'active'",
"=>",
"[",
"\"Order Active\"",
",",
"\"This order is currently active and cannot b... | Validates that the current status permits edits
If the order is actively listed, certain fields should not be editable. This checks the status and
sets an error if the user is trying to edit fields that are not editable for the given status.
@param string $field The name of the field being validated
@return bool Whether or not the validation has passed | [
"Validates",
"that",
"the",
"current",
"status",
"permits",
"edits"
] | b91a58f7d9519b98b29c58f0911e976e361a5f65 | https://github.com/cfxmarkets/php-public-models/blob/b91a58f7d9519b98b29c58f0911e976e361a5f65/src/Exchange/Order.php#L294-L315 | train |
hail-framework/framework | src/Console/CommandLoader.php | CommandLoader.autoload | public static function autoload(Command $parent)
{
$reflector = new \ReflectionObject($parent);
$dir = \dirname($reflector->getFileName()) . '/';
/*
* Commands to be autoloaded must located at specific directory.
* If parent is Application, commands must be whthin App/Command/ directory.
* If parent is another command named Foo or FooCommand, sub-commands must
* within App/Command/Foo/ directory, if App/Command/Foo/ directory
* not exists found in App/Command/Command/ directory.
*/
if ($parent->isApplication()) {
$subNamespace = 'Command';
} else {
$subNamespace = static::clearSuffix(
$reflector->getShortName()
);
if (!\is_dir($dir . $subNamespace)) {
$subNamespace = 'Command';
}
}
$dir .= $subNamespace;
if (!\is_dir($dir)) {
return;
}
$classes = static::scanPhp($dir);
$namespace = '\\' . $reflector->getNamespaceName() . '\\' . $subNamespace;
foreach ($classes as $class) {
$class = $namespace . '\\' . $class;
$reflection = new \ReflectionClass($class);
if ($reflection->isInstantiable()) {
$parent->addCommand($class);
}
}
} | php | public static function autoload(Command $parent)
{
$reflector = new \ReflectionObject($parent);
$dir = \dirname($reflector->getFileName()) . '/';
/*
* Commands to be autoloaded must located at specific directory.
* If parent is Application, commands must be whthin App/Command/ directory.
* If parent is another command named Foo or FooCommand, sub-commands must
* within App/Command/Foo/ directory, if App/Command/Foo/ directory
* not exists found in App/Command/Command/ directory.
*/
if ($parent->isApplication()) {
$subNamespace = 'Command';
} else {
$subNamespace = static::clearSuffix(
$reflector->getShortName()
);
if (!\is_dir($dir . $subNamespace)) {
$subNamespace = 'Command';
}
}
$dir .= $subNamespace;
if (!\is_dir($dir)) {
return;
}
$classes = static::scanPhp($dir);
$namespace = '\\' . $reflector->getNamespaceName() . '\\' . $subNamespace;
foreach ($classes as $class) {
$class = $namespace . '\\' . $class;
$reflection = new \ReflectionClass($class);
if ($reflection->isInstantiable()) {
$parent->addCommand($class);
}
}
} | [
"public",
"static",
"function",
"autoload",
"(",
"Command",
"$",
"parent",
")",
"{",
"$",
"reflector",
"=",
"new",
"\\",
"ReflectionObject",
"(",
"$",
"parent",
")",
";",
"$",
"dir",
"=",
"\\",
"dirname",
"(",
"$",
"reflector",
"->",
"getFileName",
"(",
... | Add all commands in a directory to parent command
@param Command $parent object we want to load its commands/subcommands
@return void
@throws CommandClassNotFoundException
@throws \ReflectionException | [
"Add",
"all",
"commands",
"in",
"a",
"directory",
"to",
"parent",
"command"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/CommandLoader.php#L62-L102 | train |
hail-framework/framework | src/Console/CommandLoader.php | CommandLoader.inverseTranslate | public static function inverseTranslate(string $className): string
{
// remove the suffix 'Command', then lower case the first letter
$className = \lcfirst(static::clearSuffix($className));
return \strtolower(
\preg_replace('/([A-Z])/', ':\1', $className)
);
} | php | public static function inverseTranslate(string $className): string
{
// remove the suffix 'Command', then lower case the first letter
$className = \lcfirst(static::clearSuffix($className));
return \strtolower(
\preg_replace('/([A-Z])/', ':\1', $className)
);
} | [
"public",
"static",
"function",
"inverseTranslate",
"(",
"string",
"$",
"className",
")",
":",
"string",
"{",
"// remove the suffix 'Command', then lower case the first letter",
"$",
"className",
"=",
"\\",
"lcfirst",
"(",
"static",
"::",
"clearSuffix",
"(",
"$",
"cla... | Translate class name to command name
This method is inverse of self::translate()
HelpCommand => help
SuchALongCommand => such:a:long
@param string $className class name.
@return string translated command name. | [
"Translate",
"class",
"name",
"to",
"command",
"name"
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/CommandLoader.php#L136-L144 | train |
hail-framework/framework | src/Redis/Cluster/Native.php | Native.getConnectionBySlot | public function getConnectionBySlot($slot)
{
if ($slot < 0x0000 || $slot > 0x3FFF) {
throw new \OutOfBoundsException("Invalid slot [$slot].");
}
if (isset($this->slots[$slot])) {
return $this->slots[$slot];
}
$connectionID = $this->guessNode($slot);
if (!$connection = $this->getConnectionById($connectionID)) {
$connection = $this->createConnection($connectionID);
}
return $this->slots[$slot] = $connection;
} | php | public function getConnectionBySlot($slot)
{
if ($slot < 0x0000 || $slot > 0x3FFF) {
throw new \OutOfBoundsException("Invalid slot [$slot].");
}
if (isset($this->slots[$slot])) {
return $this->slots[$slot];
}
$connectionID = $this->guessNode($slot);
if (!$connection = $this->getConnectionById($connectionID)) {
$connection = $this->createConnection($connectionID);
}
return $this->slots[$slot] = $connection;
} | [
"public",
"function",
"getConnectionBySlot",
"(",
"$",
"slot",
")",
"{",
"if",
"(",
"$",
"slot",
"<",
"0x0000",
"||",
"$",
"slot",
">",
"0x3FFF",
")",
"{",
"throw",
"new",
"\\",
"OutOfBoundsException",
"(",
"\"Invalid slot [$slot].\"",
")",
";",
"}",
"if",... | Returns the connection currently associated to a given slot.
@param int $slot Slot index.
@return Client|mixed|null
@throws RedisException | [
"Returns",
"the",
"connection",
"currently",
"associated",
"to",
"a",
"given",
"slot",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Redis/Cluster/Native.php#L325-L341 | train |
hail-framework/framework | src/Redis/Cluster/Native.php | Native.getRandomConnection | protected function getRandomConnection(): ?Client
{
if ($this->pool) {
return $this->pool[\array_rand($this->pool)];
}
if ($this->hosts) {
$key = \array_rand($this->hosts);
$connectionID = $this->hosts[$key];
unset($key);
return $this->createConnection($connectionID);
}
return null;
} | php | protected function getRandomConnection(): ?Client
{
if ($this->pool) {
return $this->pool[\array_rand($this->pool)];
}
if ($this->hosts) {
$key = \array_rand($this->hosts);
$connectionID = $this->hosts[$key];
unset($key);
return $this->createConnection($connectionID);
}
return null;
} | [
"protected",
"function",
"getRandomConnection",
"(",
")",
":",
"?",
"Client",
"{",
"if",
"(",
"$",
"this",
"->",
"pool",
")",
"{",
"return",
"$",
"this",
"->",
"pool",
"[",
"\\",
"array_rand",
"(",
"$",
"this",
"->",
"pool",
")",
"]",
";",
"}",
"if... | Returns a random connection from the pool.
@return Client|null | [
"Returns",
"a",
"random",
"connection",
"from",
"the",
"pool",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Redis/Cluster/Native.php#L357-L372 | train |
hail-framework/framework | src/Redis/Cluster/Native.php | Native.onMovedResponse | protected function onMovedResponse(string $command, array $args, string $details)
{
[$slot, $connectionID] = \explode(' ', $details, 2);
if (!$connection = $this->getConnectionById($connectionID)) {
$connection = $this->createConnection($connectionID);
}
$this->askSlotsMap($connection);
$this->move($connection, $slot);
return $this->execute($command, $args);
} | php | protected function onMovedResponse(string $command, array $args, string $details)
{
[$slot, $connectionID] = \explode(' ', $details, 2);
if (!$connection = $this->getConnectionById($connectionID)) {
$connection = $this->createConnection($connectionID);
}
$this->askSlotsMap($connection);
$this->move($connection, $slot);
return $this->execute($command, $args);
} | [
"protected",
"function",
"onMovedResponse",
"(",
"string",
"$",
"command",
",",
"array",
"$",
"args",
",",
"string",
"$",
"details",
")",
"{",
"[",
"$",
"slot",
",",
"$",
"connectionID",
"]",
"=",
"\\",
"explode",
"(",
"' '",
",",
"$",
"details",
",",
... | Handles -MOVED responses by executing again the command against the node
indicated by the Redis response.
@param string $command Command that generated the -MOVED response.
@param array $args
@param string $details Parameters of the -MOVED response.
@return mixed
@throws RedisException | [
"Handles",
"-",
"MOVED",
"responses",
"by",
"executing",
"again",
"the",
"command",
"against",
"the",
"node",
"indicated",
"by",
"the",
"Redis",
"response",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Redis/Cluster/Native.php#L421-L432 | train |
hail-framework/framework | src/Redis/Cluster/Native.php | Native.getSlot | public function getSlot($command, $args): ?int
{
$id = \strtoupper($command);
$slot = null;
if (isset($this->commands[$id])) {
$key = $this->commands[$id]($id, $args);
if (null !== $key) {
$slot = $this->getSlotByKey($key);
}
}
return $slot;
} | php | public function getSlot($command, $args): ?int
{
$id = \strtoupper($command);
$slot = null;
if (isset($this->commands[$id])) {
$key = $this->commands[$id]($id, $args);
if (null !== $key) {
$slot = $this->getSlotByKey($key);
}
}
return $slot;
} | [
"public",
"function",
"getSlot",
"(",
"$",
"command",
",",
"$",
"args",
")",
":",
"?",
"int",
"{",
"$",
"id",
"=",
"\\",
"strtoupper",
"(",
"$",
"command",
")",
";",
"$",
"slot",
"=",
"null",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"co... | Returns a slot for the given command used for clustering distribution or
NULL when this is not possible.
@param string $command Command name.
@param array $args
@return int|null | [
"Returns",
"a",
"slot",
"for",
"the",
"given",
"command",
"used",
"for",
"clustering",
"distribution",
"or",
"NULL",
"when",
"this",
"is",
"not",
"possible",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Redis/Cluster/Native.php#L899-L914 | train |
Kajna/K-Core | Core/Routing/Route.php | Route.matches | public function matches($uri, $method)
{
// Check if request method matches.
if (in_array($method, $this->methods)) {
$paramValues = [];
// Replace parameters with proper regex patterns.
$urlRegex = preg_replace_callback(self::MATCHES_REGEX, [$this, 'regexUrl'], $this->url);
// Check if URI matches and if it matches put results in values array.
$pattern = '@^' . $urlRegex . '/?$@' . ($this->matchUnicode?'u':'');
if (preg_match($pattern, $uri, $paramValues) === 1) {// There is a match.
// Extract parameter names.
$paramNames = [];
preg_match_all(self::MATCHES_REGEX, $this->url, $paramNames, PREG_PATTERN_ORDER);
// Put parameters to array to be passed to controller/function later.
foreach ($paramNames[0] as $index => $value) {
$this->params[substr($value, 1)] = urldecode($paramValues[$index + 1]);
}
// Append passed params to executable
$this->executable->addParams($this->params);
// Everything is done return true.
return true;
}
}
// No match found return false.
return false;
} | php | public function matches($uri, $method)
{
// Check if request method matches.
if (in_array($method, $this->methods)) {
$paramValues = [];
// Replace parameters with proper regex patterns.
$urlRegex = preg_replace_callback(self::MATCHES_REGEX, [$this, 'regexUrl'], $this->url);
// Check if URI matches and if it matches put results in values array.
$pattern = '@^' . $urlRegex . '/?$@' . ($this->matchUnicode?'u':'');
if (preg_match($pattern, $uri, $paramValues) === 1) {// There is a match.
// Extract parameter names.
$paramNames = [];
preg_match_all(self::MATCHES_REGEX, $this->url, $paramNames, PREG_PATTERN_ORDER);
// Put parameters to array to be passed to controller/function later.
foreach ($paramNames[0] as $index => $value) {
$this->params[substr($value, 1)] = urldecode($paramValues[$index + 1]);
}
// Append passed params to executable
$this->executable->addParams($this->params);
// Everything is done return true.
return true;
}
}
// No match found return false.
return false;
} | [
"public",
"function",
"matches",
"(",
"$",
"uri",
",",
"$",
"method",
")",
"{",
"// Check if request method matches.",
"if",
"(",
"in_array",
"(",
"$",
"method",
",",
"$",
"this",
"->",
"methods",
")",
")",
"{",
"$",
"paramValues",
"=",
"[",
"]",
";",
... | Check if requested URI and method matches this route.
@param string $uri
@param string $method
@return bool | [
"Check",
"if",
"requested",
"URI",
"and",
"method",
"matches",
"this",
"route",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Routing/Route.php#L128-L158 | train |
Kajna/K-Core | Core/Routing/Route.php | Route.regexUrl | protected function regexUrl($matches)
{
$key = substr($matches[0], 1);
if (isset($this->conditions[$key])) {
return '(' . $this->conditions[$key] . ')';
} else {
return '(' . self::$conditionRegex['default'] . ')';
}
} | php | protected function regexUrl($matches)
{
$key = substr($matches[0], 1);
if (isset($this->conditions[$key])) {
return '(' . $this->conditions[$key] . ')';
} else {
return '(' . self::$conditionRegex['default'] . ')';
}
} | [
"protected",
"function",
"regexUrl",
"(",
"$",
"matches",
")",
"{",
"$",
"key",
"=",
"substr",
"(",
"$",
"matches",
"[",
"0",
"]",
",",
"1",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"conditions",
"[",
"$",
"key",
"]",
")",
")",
"{"... | Helper regex for matches function.
@param string $matches
@return string | [
"Helper",
"regex",
"for",
"matches",
"function",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Routing/Route.php#L166-L174 | train |
Kajna/K-Core | Core/Routing/Route.php | Route.where | public function where($key, $condition)
{
$this->conditions[$key] = self::$conditionRegex[$condition];
return $this;
} | php | public function where($key, $condition)
{
$this->conditions[$key] = self::$conditionRegex[$condition];
return $this;
} | [
"public",
"function",
"where",
"(",
"$",
"key",
",",
"$",
"condition",
")",
"{",
"$",
"this",
"->",
"conditions",
"[",
"$",
"key",
"]",
"=",
"self",
"::",
"$",
"conditionRegex",
"[",
"$",
"condition",
"]",
";",
"return",
"$",
"this",
";",
"}"
] | Set route parameter condition.
@param string $key
@param string $condition
@return self | [
"Set",
"route",
"parameter",
"condition",
"."
] | 6a354056cf95e471b9b1eb372c5626123fd77df2 | https://github.com/Kajna/K-Core/blob/6a354056cf95e471b9b1eb372c5626123fd77df2/Core/Routing/Route.php#L193-L197 | train |
hail-framework/framework | src/Console/Corrector.php | Corrector.correct | public static function correct(string $input, array $possibleTokens = []): string
{
$guess = static::match($input, $possibleTokens);
if ($guess === $input) {
return $guess;
}
return static::askForGuess($guess) ? $guess : $input;
} | php | public static function correct(string $input, array $possibleTokens = []): string
{
$guess = static::match($input, $possibleTokens);
if ($guess === $input) {
return $guess;
}
return static::askForGuess($guess) ? $guess : $input;
} | [
"public",
"static",
"function",
"correct",
"(",
"string",
"$",
"input",
",",
"array",
"$",
"possibleTokens",
"=",
"[",
"]",
")",
":",
"string",
"{",
"$",
"guess",
"=",
"static",
"::",
"match",
"(",
"$",
"input",
",",
"$",
"possibleTokens",
")",
";",
... | Given user's input, ask user to correct it.
@param string $input user's input
@param string[] $possibleTokens candidates of the suggestion
@return string corrected input | [
"Given",
"user",
"s",
"input",
"ask",
"user",
"to",
"correct",
"it",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Corrector.php#L18-L26 | train |
hail-framework/framework | src/Console/Corrector.php | Corrector.match | public static function match(string $input, array $possibleTokens = []): string
{
if (empty($possibleTokens)) {
return $input;
}
$bestSimilarity = -1;
$bestGuess = $input;
foreach ($possibleTokens as $possibleToken) {
similar_text($input, $possibleToken, $similarity);
if ($similarity > $bestSimilarity) {
$bestSimilarity = $similarity;
$bestGuess = $possibleToken;
}
}
return $bestGuess;
} | php | public static function match(string $input, array $possibleTokens = []): string
{
if (empty($possibleTokens)) {
return $input;
}
$bestSimilarity = -1;
$bestGuess = $input;
foreach ($possibleTokens as $possibleToken) {
similar_text($input, $possibleToken, $similarity);
if ($similarity > $bestSimilarity) {
$bestSimilarity = $similarity;
$bestGuess = $possibleToken;
}
}
return $bestGuess;
} | [
"public",
"static",
"function",
"match",
"(",
"string",
"$",
"input",
",",
"array",
"$",
"possibleTokens",
"=",
"[",
"]",
")",
":",
"string",
"{",
"if",
"(",
"empty",
"(",
"$",
"possibleTokens",
")",
")",
"{",
"return",
"$",
"input",
";",
"}",
"$",
... | Given user's input, return the best match among candidates.
@param string $input @see self::correct()
@param string[] $possibleTokens @see self::correct()
@return string best matched string or raw input if no candidates provided | [
"Given",
"user",
"s",
"input",
"return",
"the",
"best",
"match",
"among",
"candidates",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Console/Corrector.php#L36-L53 | train |
hail-framework/framework | src/Util/Strings.php | Strings.fixEncoding | public static function fixEncoding(string $s): string
{
// removes xD800-xDFFF, x110000 and higher
return \htmlspecialchars_decode(\htmlspecialchars($s, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'), ENT_NOQUOTES);
} | php | public static function fixEncoding(string $s): string
{
// removes xD800-xDFFF, x110000 and higher
return \htmlspecialchars_decode(\htmlspecialchars($s, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'), ENT_NOQUOTES);
} | [
"public",
"static",
"function",
"fixEncoding",
"(",
"string",
"$",
"s",
")",
":",
"string",
"{",
"// removes xD800-xDFFF, x110000 and higher",
"return",
"\\",
"htmlspecialchars_decode",
"(",
"\\",
"htmlspecialchars",
"(",
"$",
"s",
",",
"ENT_NOQUOTES",
"|",
"ENT_IGN... | Removes invalid code unit sequences from UTF-8 string.
@param string $s byte stream to fix
@return string | [
"Removes",
"invalid",
"code",
"unit",
"sequences",
"from",
"UTF",
"-",
"8",
"string",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L38-L42 | train |
hail-framework/framework | src/Util/Strings.php | Strings.ord | public static function ord(string $char): int
{
if (\function_exists('\mb_ord')) {
return \mb_ord($char);
}
$code = ($c = \unpack('C*', \substr($char, 0, 4))) ? $c[1] : 0;
if (0xF0 <= $code) {
return (($code - 0xF0) << 18) + (($c[2] - 0x80) << 12) + (($c[3] - 0x80) << 6) + $c[4] - 0x80;
}
if (0xE0 <= $code) {
return (($code - 0xE0) << 12) + (($c[2] - 0x80) << 6) + $c[3] - 0x80;
}
if (0xC0 <= $code) {
return (($code - 0xC0) << 6) + $c[2] - 0x80;
}
return $code;
} | php | public static function ord(string $char): int
{
if (\function_exists('\mb_ord')) {
return \mb_ord($char);
}
$code = ($c = \unpack('C*', \substr($char, 0, 4))) ? $c[1] : 0;
if (0xF0 <= $code) {
return (($code - 0xF0) << 18) + (($c[2] - 0x80) << 12) + (($c[3] - 0x80) << 6) + $c[4] - 0x80;
}
if (0xE0 <= $code) {
return (($code - 0xE0) << 12) + (($c[2] - 0x80) << 6) + $c[3] - 0x80;
}
if (0xC0 <= $code) {
return (($code - 0xC0) << 6) + $c[2] - 0x80;
}
return $code;
} | [
"public",
"static",
"function",
"ord",
"(",
"string",
"$",
"char",
")",
":",
"int",
"{",
"if",
"(",
"\\",
"function_exists",
"(",
"'\\mb_ord'",
")",
")",
"{",
"return",
"\\",
"mb_ord",
"(",
"$",
"char",
")",
";",
"}",
"$",
"code",
"=",
"(",
"$",
... | Get a decimal code representation of a specific character.
@param string $char Character.
@return int | [
"Get",
"a",
"decimal",
"code",
"representation",
"of",
"a",
"specific",
"character",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L51-L69 | train |
hail-framework/framework | src/Util/Strings.php | Strings.chr | public static function chr(int $code): string
{
if ($code < 0 || ($code >= 0xD800 && $code <= 0xDFFF) || $code > 0x10FFFF) {
throw new \InvalidArgumentException('Code point must be in range 0x0 to 0xD7FF or 0xE000 to 0x10FFFF.');
}
if (\function_exists('\mb_chr')) {
return \mb_chr($code);
}
if (\function_exists('\iconv')) {
return \iconv('UTF-32BE', 'UTF-8//IGNORE', \pack('N', $code));
}
if (0x80 > $code %= 0x200000) {
return \chr($code);
}
if (0x800 > $code) {
return \chr(0xC0 | $code >> 6) . \chr(0x80 | $code & 0x3F);
}
if (0x10000 > $code) {
return \chr(0xE0 | $code >> 12) . \chr(0x80 | $code >> 6 & 0x3F) . \chr(0x80 | $code & 0x3F);
}
return \chr(0xF0 | $code >> 18) . \chr(0x80 | $code >> 12 & 0x3F) . \chr(0x80 | $code >> 6 & 0x3F) . \chr(0x80 | $code & 0x3F);
} | php | public static function chr(int $code): string
{
if ($code < 0 || ($code >= 0xD800 && $code <= 0xDFFF) || $code > 0x10FFFF) {
throw new \InvalidArgumentException('Code point must be in range 0x0 to 0xD7FF or 0xE000 to 0x10FFFF.');
}
if (\function_exists('\mb_chr')) {
return \mb_chr($code);
}
if (\function_exists('\iconv')) {
return \iconv('UTF-32BE', 'UTF-8//IGNORE', \pack('N', $code));
}
if (0x80 > $code %= 0x200000) {
return \chr($code);
}
if (0x800 > $code) {
return \chr(0xC0 | $code >> 6) . \chr(0x80 | $code & 0x3F);
}
if (0x10000 > $code) {
return \chr(0xE0 | $code >> 12) . \chr(0x80 | $code >> 6 & 0x3F) . \chr(0x80 | $code & 0x3F);
}
return \chr(0xF0 | $code >> 18) . \chr(0x80 | $code >> 12 & 0x3F) . \chr(0x80 | $code >> 6 & 0x3F) . \chr(0x80 | $code & 0x3F);
} | [
"public",
"static",
"function",
"chr",
"(",
"int",
"$",
"code",
")",
":",
"string",
"{",
"if",
"(",
"$",
"code",
"<",
"0",
"||",
"(",
"$",
"code",
">=",
"0xD800",
"&&",
"$",
"code",
"<=",
"0xDFFF",
")",
"||",
"$",
"code",
">",
"0x10FFFF",
")",
... | Returns a specific character in UTF-8.
@param int $code code point (0x0 to 0xD7FF or 0xE000 to 0x10FFFF)
@return string
@throws \InvalidArgumentException if code point is not in valid range | [
"Returns",
"a",
"specific",
"character",
"in",
"UTF",
"-",
"8",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L79-L104 | train |
hail-framework/framework | src/Util/Strings.php | Strings.normalizeNewLines | public static function normalizeNewLines(string $s): string
{
if (\strpos($s, "\r") === false) {
return $s;
}
return \str_replace(["\r\n", "\r"], "\n", $s);
} | php | public static function normalizeNewLines(string $s): string
{
if (\strpos($s, "\r") === false) {
return $s;
}
return \str_replace(["\r\n", "\r"], "\n", $s);
} | [
"public",
"static",
"function",
"normalizeNewLines",
"(",
"string",
"$",
"s",
")",
":",
"string",
"{",
"if",
"(",
"\\",
"strpos",
"(",
"$",
"s",
",",
"\"\\r\"",
")",
"===",
"false",
")",
"{",
"return",
"$",
"s",
";",
"}",
"return",
"\\",
"str_replace... | Standardize line endings to unix-like.
@param string $s UTF-8 encoding or 8-bit
@return string | [
"Standardize",
"line",
"endings",
"to",
"unix",
"-",
"like",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L190-L197 | train |
hail-framework/framework | src/Util/Strings.php | Strings.truncate | public static function truncate(string $s, int $maxLen, string $append = "\xE2\x80\xA6"): string
{
if (\mb_strlen($s) > $maxLen) {
$maxLen -= \mb_strlen($append);
if ($maxLen < 1) {
return $append;
}
if ($matches = static::match($s, '#^.{1,' . $maxLen . '}(?=[\s\x00-/:-@\[-`{-~])#us')) {
return $matches[0] . $append;
}
return \mb_substr($s, 0, $maxLen) . $append;
}
return $s;
} | php | public static function truncate(string $s, int $maxLen, string $append = "\xE2\x80\xA6"): string
{
if (\mb_strlen($s) > $maxLen) {
$maxLen -= \mb_strlen($append);
if ($maxLen < 1) {
return $append;
}
if ($matches = static::match($s, '#^.{1,' . $maxLen . '}(?=[\s\x00-/:-@\[-`{-~])#us')) {
return $matches[0] . $append;
}
return \mb_substr($s, 0, $maxLen) . $append;
}
return $s;
} | [
"public",
"static",
"function",
"truncate",
"(",
"string",
"$",
"s",
",",
"int",
"$",
"maxLen",
",",
"string",
"$",
"append",
"=",
"\"\\xE2\\x80\\xA6\"",
")",
":",
"string",
"{",
"if",
"(",
"\\",
"mb_strlen",
"(",
"$",
"s",
")",
">",
"$",
"maxLen",
"... | Truncates string to maximal length.
@param string $s UTF-8 encoding
@param int $maxLen
@param string $append UTF-8 encoding
@return string | [
"Truncates",
"string",
"to",
"maximal",
"length",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L277-L293 | train |
hail-framework/framework | src/Util/Strings.php | Strings.indent | public static function indent(string $s, int $level = 1, string $chars = "\t"): string
{
if ($level > 0) {
$s = static::replace($s, '#(?:^|[\r\n]+)(?=[^\r\n])#', '$0' . \str_repeat($chars, $level));
}
return $s;
} | php | public static function indent(string $s, int $level = 1, string $chars = "\t"): string
{
if ($level > 0) {
$s = static::replace($s, '#(?:^|[\r\n]+)(?=[^\r\n])#', '$0' . \str_repeat($chars, $level));
}
return $s;
} | [
"public",
"static",
"function",
"indent",
"(",
"string",
"$",
"s",
",",
"int",
"$",
"level",
"=",
"1",
",",
"string",
"$",
"chars",
"=",
"\"\\t\"",
")",
":",
"string",
"{",
"if",
"(",
"$",
"level",
">",
"0",
")",
"{",
"$",
"s",
"=",
"static",
"... | Indents the content from the left.
@param string $s UTF-8 encoding or 8-bit
@param int $level
@param string $chars
@return string | [
"Indents",
"the",
"content",
"from",
"the",
"left",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L305-L312 | train |
hail-framework/framework | src/Util/Strings.php | Strings.compare | public static function compare(string $left, string $right, int $len = null): bool
{
if (\class_exists('\Normalizer', false)) {
$left = \Normalizer::normalize($left, \Normalizer::FORM_D); // form NFD is faster
$right = \Normalizer::normalize($right, \Normalizer::FORM_D); // form NFD is faster
}
if ($len < 0) {
$left = \mb_substr($left, $len, -$len);
$right = \mb_substr($right, $len, -$len);
} elseif ($len !== null) {
$left = \mb_substr($left, 0, $len);
$right = \mb_substr($right, 0, $len);
}
return \mb_strtolower($left) === \mb_strtolower($right);
} | php | public static function compare(string $left, string $right, int $len = null): bool
{
if (\class_exists('\Normalizer', false)) {
$left = \Normalizer::normalize($left, \Normalizer::FORM_D); // form NFD is faster
$right = \Normalizer::normalize($right, \Normalizer::FORM_D); // form NFD is faster
}
if ($len < 0) {
$left = \mb_substr($left, $len, -$len);
$right = \mb_substr($right, $len, -$len);
} elseif ($len !== null) {
$left = \mb_substr($left, 0, $len);
$right = \mb_substr($right, 0, $len);
}
return \mb_strtolower($left) === \mb_strtolower($right);
} | [
"public",
"static",
"function",
"compare",
"(",
"string",
"$",
"left",
",",
"string",
"$",
"right",
",",
"int",
"$",
"len",
"=",
"null",
")",
":",
"bool",
"{",
"if",
"(",
"\\",
"class_exists",
"(",
"'\\Normalizer'",
",",
"false",
")",
")",
"{",
"$",
... | Case-insensitive compares UTF-8 strings.
@param string
@param string
@param int
@return bool | [
"Case",
"-",
"insensitive",
"compares",
"UTF",
"-",
"8",
"strings",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L349-L365 | train |
hail-framework/framework | src/Util/Strings.php | Strings.findPrefix | public static function findPrefix($first, ...$strings): string
{
if (\is_array($first)) {
$strings = $first;
$first = $strings[0];
unset($strings[0]);
}
for ($i = 0, $n = \strlen($first); $i < $n; $i++) {
foreach ($strings as $s) {
if (!isset($s[$i]) || $first[$i] !== $s[$i]) {
while ($i && $first[$i - 1] >= "\x80" && $first[$i] >= "\x80" && $first[$i] < "\xC0") {
$i--;
}
return \substr($first, 0, $i);
}
}
}
return $first;
} | php | public static function findPrefix($first, ...$strings): string
{
if (\is_array($first)) {
$strings = $first;
$first = $strings[0];
unset($strings[0]);
}
for ($i = 0, $n = \strlen($first); $i < $n; $i++) {
foreach ($strings as $s) {
if (!isset($s[$i]) || $first[$i] !== $s[$i]) {
while ($i && $first[$i - 1] >= "\x80" && $first[$i] >= "\x80" && $first[$i] < "\xC0") {
$i--;
}
return \substr($first, 0, $i);
}
}
}
return $first;
} | [
"public",
"static",
"function",
"findPrefix",
"(",
"$",
"first",
",",
"...",
"$",
"strings",
")",
":",
"string",
"{",
"if",
"(",
"\\",
"is_array",
"(",
"$",
"first",
")",
")",
"{",
"$",
"strings",
"=",
"$",
"first",
";",
"$",
"first",
"=",
"$",
"... | Finds the length of common prefix of strings.
@param string|array $first
@param array ...$strings
@return string | [
"Finds",
"the",
"length",
"of",
"common",
"prefix",
"of",
"strings",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L376-L397 | train |
hail-framework/framework | src/Util/Strings.php | Strings.trim | public static function trim(string $s, string $charList = self::TRIM_CHARACTERS): string
{
$charList = \preg_quote($charList, '#');
return static::replace($s, '#^[' . $charList . ']+|[' . $charList . ']+\z#u', '');
} | php | public static function trim(string $s, string $charList = self::TRIM_CHARACTERS): string
{
$charList = \preg_quote($charList, '#');
return static::replace($s, '#^[' . $charList . ']+|[' . $charList . ']+\z#u', '');
} | [
"public",
"static",
"function",
"trim",
"(",
"string",
"$",
"s",
",",
"string",
"$",
"charList",
"=",
"self",
"::",
"TRIM_CHARACTERS",
")",
":",
"string",
"{",
"$",
"charList",
"=",
"\\",
"preg_quote",
"(",
"$",
"charList",
",",
"'#'",
")",
";",
"retur... | Strips whitespace.
@param string $s UTF-8 encoding
@param string $charList
@return string
@throws RegexpException | [
"Strips",
"whitespace",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L408-L413 | train |
hail-framework/framework | src/Util/Strings.php | Strings.ltrim | public static function ltrim(string $s, string $charList = self::TRIM_CHARACTERS): string
{
$charList = \preg_quote($charList, '#');
return static::replace($s, '#^[' . $charList . ']+#u', '');
} | php | public static function ltrim(string $s, string $charList = self::TRIM_CHARACTERS): string
{
$charList = \preg_quote($charList, '#');
return static::replace($s, '#^[' . $charList . ']+#u', '');
} | [
"public",
"static",
"function",
"ltrim",
"(",
"string",
"$",
"s",
",",
"string",
"$",
"charList",
"=",
"self",
"::",
"TRIM_CHARACTERS",
")",
":",
"string",
"{",
"$",
"charList",
"=",
"\\",
"preg_quote",
"(",
"$",
"charList",
",",
"'#'",
")",
";",
"retu... | Strips whitespace from the beginning of a string.
@param string $s UTF-8 encoding
@param string $charList
@return string
@throws RegexpException | [
"Strips",
"whitespace",
"from",
"the",
"beginning",
"of",
"a",
"string",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L424-L429 | train |
hail-framework/framework | src/Util/Strings.php | Strings.rtrim | public static function rtrim(string $s, string $charList = self::TRIM_CHARACTERS): string
{
$charList = \preg_quote($charList, '#');
return static::replace($s, '#[' . $charList . ']+\z#u', '');
} | php | public static function rtrim(string $s, string $charList = self::TRIM_CHARACTERS): string
{
$charList = \preg_quote($charList, '#');
return static::replace($s, '#[' . $charList . ']+\z#u', '');
} | [
"public",
"static",
"function",
"rtrim",
"(",
"string",
"$",
"s",
",",
"string",
"$",
"charList",
"=",
"self",
"::",
"TRIM_CHARACTERS",
")",
":",
"string",
"{",
"$",
"charList",
"=",
"\\",
"preg_quote",
"(",
"$",
"charList",
",",
"'#'",
")",
";",
"retu... | Strips whitespace from the end of a string.
@param string $s UTF-8 encoding
@param string $charList
@return string
@throws RegexpException | [
"Strips",
"whitespace",
"from",
"the",
"end",
"of",
"a",
"string",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L440-L445 | train |
hail-framework/framework | src/Util/Strings.php | Strings.padLeft | public static function padLeft(string $s, int $length, string $pad = ' '): string
{
$length -= \mb_strlen($s);
if ($length <= 0) {
return $s;
}
$padLen = \mb_strlen($pad);
return \str_repeat($pad, (int) ($length / $padLen)) . \mb_substr($pad, 0, $length % $padLen) . $s;
} | php | public static function padLeft(string $s, int $length, string $pad = ' '): string
{
$length -= \mb_strlen($s);
if ($length <= 0) {
return $s;
}
$padLen = \mb_strlen($pad);
return \str_repeat($pad, (int) ($length / $padLen)) . \mb_substr($pad, 0, $length % $padLen) . $s;
} | [
"public",
"static",
"function",
"padLeft",
"(",
"string",
"$",
"s",
",",
"int",
"$",
"length",
",",
"string",
"$",
"pad",
"=",
"' '",
")",
":",
"string",
"{",
"$",
"length",
"-=",
"\\",
"mb_strlen",
"(",
"$",
"s",
")",
";",
"if",
"(",
"$",
"lengt... | Pad a UTF-8 string to a certain length with another string.
@param string $s UTF-8 encoding
@param int $length
@param string $pad
@return string | [
"Pad",
"a",
"UTF",
"-",
"8",
"string",
"to",
"a",
"certain",
"length",
"with",
"another",
"string",
"."
] | d419e6c098d29ef9b62192b74050e51985b94f90 | https://github.com/hail-framework/framework/blob/d419e6c098d29ef9b62192b74050e51985b94f90/src/Util/Strings.php#L457-L467 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.