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
sequence | docstring
stringlengths 3
47.2k
| docstring_tokens
sequence | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
bartonlp/site-class | includes/database-engines/dbMysql.class.php | dbMysql.maketbodyrows | public function maketbodyrows($query, $rowdesc, $callback=null, &$retresult=false, $delim=false) {
// $rowdesc is the <tr>...</tr> for this row
// <tr><td>fieldname</td>...</tr>
list($result, $num) = $this->query($query, true);
if(!$num) {
return false;
}
if($retresult !== false) $retresult = $result;
// Set up delimiters
$rdelimlft = $rdelimrit = "";
if(!$delim) {
$sdelimlft = $rdelimlft = ">";
$sdelimrit = $rdelimrit = "<";
} else {
if(is_array($delim)) {
$sdelimlft = $delim[0];
$sdelimrit = $delim[1];
} else {
$sdelimlft = $sdelimrit = $delim;
}
}
$table = ""; // return tbody
while($row = mysql_fetch_assoc($result)) {
// If $callback then do the callback function. If the callback function returns true (continue) skip row.
$desc = $rowdesc;
if($callback) {
// Callback function can modify $row and/or $desc if the callback function has them passed by reference
// NOTE that $desc does not have the keys replaced with the values yet!!
if($callback($row, $desc)) {
continue;
}
}
// Replace the key in the $desc with the value.
foreach($row as $k=>$v) {
$desc = preg_replace("/{$sdelimlft}{$k}{$sdelimrit}/", "{$rdelimlft}{$v}{$rdelimrit}", $desc);
}
$table .= "$desc\n";
}
return $table; // on success return the tbody rows
} | php | public function maketbodyrows($query, $rowdesc, $callback=null, &$retresult=false, $delim=false) {
// $rowdesc is the <tr>...</tr> for this row
// <tr><td>fieldname</td>...</tr>
list($result, $num) = $this->query($query, true);
if(!$num) {
return false;
}
if($retresult !== false) $retresult = $result;
// Set up delimiters
$rdelimlft = $rdelimrit = "";
if(!$delim) {
$sdelimlft = $rdelimlft = ">";
$sdelimrit = $rdelimrit = "<";
} else {
if(is_array($delim)) {
$sdelimlft = $delim[0];
$sdelimrit = $delim[1];
} else {
$sdelimlft = $sdelimrit = $delim;
}
}
$table = ""; // return tbody
while($row = mysql_fetch_assoc($result)) {
// If $callback then do the callback function. If the callback function returns true (continue) skip row.
$desc = $rowdesc;
if($callback) {
// Callback function can modify $row and/or $desc if the callback function has them passed by reference
// NOTE that $desc does not have the keys replaced with the values yet!!
if($callback($row, $desc)) {
continue;
}
}
// Replace the key in the $desc with the value.
foreach($row as $k=>$v) {
$desc = preg_replace("/{$sdelimlft}{$k}{$sdelimrit}/", "{$rdelimlft}{$v}{$rdelimrit}", $desc);
}
$table .= "$desc\n";
}
return $table; // on success return the tbody rows
} | [
"public",
"function",
"maketbodyrows",
"(",
"$",
"query",
",",
"$",
"rowdesc",
",",
"$",
"callback",
"=",
"null",
",",
"&",
"$",
"retresult",
"=",
"false",
",",
"$",
"delim",
"=",
"false",
")",
"{",
"// $rowdesc is the <tr>...</tr> for this row",
"// <tr><td>fieldname</td>...</tr>",
"list",
"(",
"$",
"result",
",",
"$",
"num",
")",
"=",
"$",
"this",
"->",
"query",
"(",
"$",
"query",
",",
"true",
")",
";",
"if",
"(",
"!",
"$",
"num",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"$",
"retresult",
"!==",
"false",
")",
"$",
"retresult",
"=",
"$",
"result",
";",
"// Set up delimiters",
"$",
"rdelimlft",
"=",
"$",
"rdelimrit",
"=",
"\"\"",
";",
"if",
"(",
"!",
"$",
"delim",
")",
"{",
"$",
"sdelimlft",
"=",
"$",
"rdelimlft",
"=",
"\">\"",
";",
"$",
"sdelimrit",
"=",
"$",
"rdelimrit",
"=",
"\"<\"",
";",
"}",
"else",
"{",
"if",
"(",
"is_array",
"(",
"$",
"delim",
")",
")",
"{",
"$",
"sdelimlft",
"=",
"$",
"delim",
"[",
"0",
"]",
";",
"$",
"sdelimrit",
"=",
"$",
"delim",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"sdelimlft",
"=",
"$",
"sdelimrit",
"=",
"$",
"delim",
";",
"}",
"}",
"$",
"table",
"=",
"\"\"",
";",
"// return tbody",
"while",
"(",
"$",
"row",
"=",
"mysql_fetch_assoc",
"(",
"$",
"result",
")",
")",
"{",
"// If $callback then do the callback function. If the callback function returns true (continue) skip row.",
"$",
"desc",
"=",
"$",
"rowdesc",
";",
"if",
"(",
"$",
"callback",
")",
"{",
"// Callback function can modify $row and/or $desc if the callback function has them passed by reference",
"// NOTE that $desc does not have the keys replaced with the values yet!!",
"if",
"(",
"$",
"callback",
"(",
"$",
"row",
",",
"$",
"desc",
")",
")",
"{",
"continue",
";",
"}",
"}",
"// Replace the key in the $desc with the value.",
"foreach",
"(",
"$",
"row",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"desc",
"=",
"preg_replace",
"(",
"\"/{$sdelimlft}{$k}{$sdelimrit}/\"",
",",
"\"{$rdelimlft}{$v}{$rdelimrit}\"",
",",
"$",
"desc",
")",
";",
"}",
"$",
"table",
".=",
"\"$desc\\n\"",
";",
"}",
"return",
"$",
"table",
";",
"// on success return the tbody rows",
"}"
] | Make Tbody Row
Make a table row given the query and a template of the row
Call back function looks like: callback(&$row, &$rowdesc) it can modify $row and $rowdesc and
returns true if we should skip (continue) or false to process.
@param string $query the mysql query
@param string $rowdesc the tbody row description
@param function $callback an optional callback function like callback(&$row, &$rowdesc)
@param resouce &$retresult an optional return of resource id if $retresult === true
@param string|array $delimiter
@return string tbody or false if mysql_num_rows() == 0. Should check return === false for no rows. | [
"Make",
"Tbody",
"Row"
] | 9095b101701ef0ae12ea9a2b4587a18072d04438 | https://github.com/bartonlp/site-class/blob/9095b101701ef0ae12ea9a2b4587a18072d04438/includes/database-engines/dbMysql.class.php#L209-L259 | train |
bartonlp/site-class | includes/database-engines/dbMysql.class.php | dbMysql.maketable | public function maketable($query, array $extra=null) {
$table = "<table";
if($extra['attr']) {
$attr = $extra['attr'];
foreach($attr as $k=>$v) {
$table .= " $k='$v'";
}
}
$table .= ">\n<thead>\n<tr>%<th>*</th>%</tr>\n</thead>";
$rowdesc = "<tr><td>*</td></tr>";
$delim = array("<td>", "</td>");
$callback = $extra['callback']; // Before
$callback2 = $extra['callback2']; // After
$tbl = $this->makeresultrows($query, $rowdesc,
array('return'=>true, callback=>$callback,
callback2=>$callback2, header=>$table, delim=>$delim));
if($tbl === false) {
return false;
}
extract($tbl);
$ftr = $extra['footer'] ? "<tfoot>\n{$extra['footer']}\n</tfoot>\n" : null;
$ret = <<<EOF
$header
<tbody>
$rows</tbody>
$ftr
</table>
EOF;
return array($ret, $result, $num, $header, table=>$ret, result=>$result, num=>$num, header=>$header);
} | php | public function maketable($query, array $extra=null) {
$table = "<table";
if($extra['attr']) {
$attr = $extra['attr'];
foreach($attr as $k=>$v) {
$table .= " $k='$v'";
}
}
$table .= ">\n<thead>\n<tr>%<th>*</th>%</tr>\n</thead>";
$rowdesc = "<tr><td>*</td></tr>";
$delim = array("<td>", "</td>");
$callback = $extra['callback']; // Before
$callback2 = $extra['callback2']; // After
$tbl = $this->makeresultrows($query, $rowdesc,
array('return'=>true, callback=>$callback,
callback2=>$callback2, header=>$table, delim=>$delim));
if($tbl === false) {
return false;
}
extract($tbl);
$ftr = $extra['footer'] ? "<tfoot>\n{$extra['footer']}\n</tfoot>\n" : null;
$ret = <<<EOF
$header
<tbody>
$rows</tbody>
$ftr
</table>
EOF;
return array($ret, $result, $num, $header, table=>$ret, result=>$result, num=>$num, header=>$header);
} | [
"public",
"function",
"maketable",
"(",
"$",
"query",
",",
"array",
"$",
"extra",
"=",
"null",
")",
"{",
"$",
"table",
"=",
"\"<table\"",
";",
"if",
"(",
"$",
"extra",
"[",
"'attr'",
"]",
")",
"{",
"$",
"attr",
"=",
"$",
"extra",
"[",
"'attr'",
"]",
";",
"foreach",
"(",
"$",
"attr",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"table",
".=",
"\" $k='$v'\"",
";",
"}",
"}",
"$",
"table",
".=",
"\">\\n<thead>\\n<tr>%<th>*</th>%</tr>\\n</thead>\"",
";",
"$",
"rowdesc",
"=",
"\"<tr><td>*</td></tr>\"",
";",
"$",
"delim",
"=",
"array",
"(",
"\"<td>\"",
",",
"\"</td>\"",
")",
";",
"$",
"callback",
"=",
"$",
"extra",
"[",
"'callback'",
"]",
";",
"// Before",
"$",
"callback2",
"=",
"$",
"extra",
"[",
"'callback2'",
"]",
";",
"// After",
"$",
"tbl",
"=",
"$",
"this",
"->",
"makeresultrows",
"(",
"$",
"query",
",",
"$",
"rowdesc",
",",
"array",
"(",
"'return'",
"=>",
"true",
",",
"callback",
"=>",
"$",
"callback",
",",
"callback2",
"=>",
"$",
"callback2",
",",
"header",
"=>",
"$",
"table",
",",
"delim",
"=>",
"$",
"delim",
")",
")",
";",
"if",
"(",
"$",
"tbl",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"extract",
"(",
"$",
"tbl",
")",
";",
"$",
"ftr",
"=",
"$",
"extra",
"[",
"'footer'",
"]",
"?",
"\"<tfoot>\\n{$extra['footer']}\\n</tfoot>\\n\"",
":",
"null",
";",
"$",
"ret",
"=",
" <<<EOF\n$header\n<tbody>\n$rows</tbody>\n$ftr\n</table>\n\nEOF",
";",
"return",
"array",
"(",
"$",
"ret",
",",
"$",
"result",
",",
"$",
"num",
",",
"$",
"header",
",",
"table",
"=>",
"$",
"ret",
",",
"result",
"=>",
"$",
"result",
",",
"num",
"=>",
"$",
"num",
",",
"header",
"=>",
"$",
"header",
")",
";",
"}"
] | Make a full table
@param string $query : the table query
@param array $extra : optional.
$extra is an optional assoc array: $extra['callback'], $extra['callback2'], $extra['footer'] and $extra['attr'].
$extra['attr'] is an assoc array that can have attributes for the <table> tag, like 'id', 'title', 'class', 'style' etc.
$extra['callback'] function that can modify the header after it is filled in.
$extra['footer'] a footer string
@return array [{string table}, {result}, {num}, {hdr}, table=>{string}, result=>{result}, num=>{num rows}, header=>{hdr}]
or === false | [
"Make",
"a",
"full",
"table"
] | 9095b101701ef0ae12ea9a2b4587a18072d04438 | https://github.com/bartonlp/site-class/blob/9095b101701ef0ae12ea9a2b4587a18072d04438/includes/database-engines/dbMysql.class.php#L436-L472 | train |
Dhii/validation-base | src/Exception/ValidationFailedException.php | ValidationFailedException._initParent | protected function _initParent($message = '', $code = 0, RootException $previous = null)
{
parent::__construct($message, $code, $previous);
} | php | protected function _initParent($message = '', $code = 0, RootException $previous = null)
{
parent::__construct($message, $code, $previous);
} | [
"protected",
"function",
"_initParent",
"(",
"$",
"message",
"=",
"''",
",",
"$",
"code",
"=",
"0",
",",
"RootException",
"$",
"previous",
"=",
"null",
")",
"{",
"parent",
"::",
"__construct",
"(",
"$",
"message",
",",
"$",
"code",
",",
"$",
"previous",
")",
";",
"}"
] | Calls the parent constructor.
@param string $message The error message.
@param int $code The error code.
@param RootException $previous The inner exception, if any.
@since [*next-version*] | [
"Calls",
"the",
"parent",
"constructor",
"."
] | 9e75c5f886a2403c6989c36c2d4ffcfae158172e | https://github.com/Dhii/validation-base/blob/9e75c5f886a2403c6989c36c2d4ffcfae158172e/src/Exception/ValidationFailedException.php#L97-L100 | train |
danielgp/common-lib | source/CommonPermissions.php | CommonPermissions.explainPerms | public function explainPerms($permissionNumber)
{
$firstFlag = $this->matchFirstFlagSingle($permissionNumber);
$permissionsString = substr(sprintf('%o', $permissionNumber), -4);
$numericalPermissions = $this->numericalPermissionsArray();
return [
'Permissions' => $permissionNumber,
'Code' => $permissionsString,
'First' => $firstFlag,
'Overall' => implode('', [
$firstFlag['code'],
$numericalPermissions[substr($permissionsString, 1, 1)]['code'],
$numericalPermissions[substr($permissionsString, 2, 1)]['code'],
$numericalPermissions[substr($permissionsString, 3, 1)]['code'],
]),
'First' => $firstFlag,
'Owner' => $numericalPermissions[substr($permissionsString, 1, 1)],
'Group' => $numericalPermissions[substr($permissionsString, 2, 1)],
'World/Other' => $numericalPermissions[substr($permissionsString, 3, 1)],
];
} | php | public function explainPerms($permissionNumber)
{
$firstFlag = $this->matchFirstFlagSingle($permissionNumber);
$permissionsString = substr(sprintf('%o', $permissionNumber), -4);
$numericalPermissions = $this->numericalPermissionsArray();
return [
'Permissions' => $permissionNumber,
'Code' => $permissionsString,
'First' => $firstFlag,
'Overall' => implode('', [
$firstFlag['code'],
$numericalPermissions[substr($permissionsString, 1, 1)]['code'],
$numericalPermissions[substr($permissionsString, 2, 1)]['code'],
$numericalPermissions[substr($permissionsString, 3, 1)]['code'],
]),
'First' => $firstFlag,
'Owner' => $numericalPermissions[substr($permissionsString, 1, 1)],
'Group' => $numericalPermissions[substr($permissionsString, 2, 1)],
'World/Other' => $numericalPermissions[substr($permissionsString, 3, 1)],
];
} | [
"public",
"function",
"explainPerms",
"(",
"$",
"permissionNumber",
")",
"{",
"$",
"firstFlag",
"=",
"$",
"this",
"->",
"matchFirstFlagSingle",
"(",
"$",
"permissionNumber",
")",
";",
"$",
"permissionsString",
"=",
"substr",
"(",
"sprintf",
"(",
"'%o'",
",",
"$",
"permissionNumber",
")",
",",
"-",
"4",
")",
";",
"$",
"numericalPermissions",
"=",
"$",
"this",
"->",
"numericalPermissionsArray",
"(",
")",
";",
"return",
"[",
"'Permissions'",
"=>",
"$",
"permissionNumber",
",",
"'Code'",
"=>",
"$",
"permissionsString",
",",
"'First'",
"=>",
"$",
"firstFlag",
",",
"'Overall'",
"=>",
"implode",
"(",
"''",
",",
"[",
"$",
"firstFlag",
"[",
"'code'",
"]",
",",
"$",
"numericalPermissions",
"[",
"substr",
"(",
"$",
"permissionsString",
",",
"1",
",",
"1",
")",
"]",
"[",
"'code'",
"]",
",",
"$",
"numericalPermissions",
"[",
"substr",
"(",
"$",
"permissionsString",
",",
"2",
",",
"1",
")",
"]",
"[",
"'code'",
"]",
",",
"$",
"numericalPermissions",
"[",
"substr",
"(",
"$",
"permissionsString",
",",
"3",
",",
"1",
")",
"]",
"[",
"'code'",
"]",
",",
"]",
")",
",",
"'First'",
"=>",
"$",
"firstFlag",
",",
"'Owner'",
"=>",
"$",
"numericalPermissions",
"[",
"substr",
"(",
"$",
"permissionsString",
",",
"1",
",",
"1",
")",
"]",
",",
"'Group'",
"=>",
"$",
"numericalPermissions",
"[",
"substr",
"(",
"$",
"permissionsString",
",",
"2",
",",
"1",
")",
"]",
",",
"'World/Other'",
"=>",
"$",
"numericalPermissions",
"[",
"substr",
"(",
"$",
"permissionsString",
",",
"3",
",",
"1",
")",
"]",
",",
"]",
";",
"}"
] | Returns an array with meaningfull content of permissions
@param int $permissionNumber
@return array | [
"Returns",
"an",
"array",
"with",
"meaningfull",
"content",
"of",
"permissions"
] | 627b99b4408414c7cd21a6c8016f6468dc9216b2 | https://github.com/danielgp/common-lib/blob/627b99b4408414c7cd21a6c8016f6468dc9216b2/source/CommonPermissions.php#L45-L65 | train |
jitesoft/php-container | src/Injector.php | Injector.create | public function create(string $className, array $bindings = []) {
try {
$class = new ReflectionClass($className);
} catch (ReflectionException $ex) {
throw new ContainerException('Failed to create reflection class from given class name.');
}
$out = null;
if ($class->getConstructor() !== null) {
$ctr = $class->getConstructor();
$params = $ctr->getParameters();
$inParam = [];
foreach ($params as $param) {
$type = $this->getTypeHint($param);
if (array_key_exists($type, $bindings)) {
$get = $bindings[$type];
} else {
if ($this->container->has($type)) {
$get = $this->container->get($type);
} else {
$get = $this->create($type, $bindings);
}
}
$inParam[] = $get;
}
$out = $class->newInstanceArgs($inParam);
} else {
$out = $class->newInstanceWithoutConstructor();
}
return $out;
} | php | public function create(string $className, array $bindings = []) {
try {
$class = new ReflectionClass($className);
} catch (ReflectionException $ex) {
throw new ContainerException('Failed to create reflection class from given class name.');
}
$out = null;
if ($class->getConstructor() !== null) {
$ctr = $class->getConstructor();
$params = $ctr->getParameters();
$inParam = [];
foreach ($params as $param) {
$type = $this->getTypeHint($param);
if (array_key_exists($type, $bindings)) {
$get = $bindings[$type];
} else {
if ($this->container->has($type)) {
$get = $this->container->get($type);
} else {
$get = $this->create($type, $bindings);
}
}
$inParam[] = $get;
}
$out = $class->newInstanceArgs($inParam);
} else {
$out = $class->newInstanceWithoutConstructor();
}
return $out;
} | [
"public",
"function",
"create",
"(",
"string",
"$",
"className",
",",
"array",
"$",
"bindings",
"=",
"[",
"]",
")",
"{",
"try",
"{",
"$",
"class",
"=",
"new",
"ReflectionClass",
"(",
"$",
"className",
")",
";",
"}",
"catch",
"(",
"ReflectionException",
"$",
"ex",
")",
"{",
"throw",
"new",
"ContainerException",
"(",
"'Failed to create reflection class from given class name.'",
")",
";",
"}",
"$",
"out",
"=",
"null",
";",
"if",
"(",
"$",
"class",
"->",
"getConstructor",
"(",
")",
"!==",
"null",
")",
"{",
"$",
"ctr",
"=",
"$",
"class",
"->",
"getConstructor",
"(",
")",
";",
"$",
"params",
"=",
"$",
"ctr",
"->",
"getParameters",
"(",
")",
";",
"$",
"inParam",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
")",
"{",
"$",
"type",
"=",
"$",
"this",
"->",
"getTypeHint",
"(",
"$",
"param",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"type",
",",
"$",
"bindings",
")",
")",
"{",
"$",
"get",
"=",
"$",
"bindings",
"[",
"$",
"type",
"]",
";",
"}",
"else",
"{",
"if",
"(",
"$",
"this",
"->",
"container",
"->",
"has",
"(",
"$",
"type",
")",
")",
"{",
"$",
"get",
"=",
"$",
"this",
"->",
"container",
"->",
"get",
"(",
"$",
"type",
")",
";",
"}",
"else",
"{",
"$",
"get",
"=",
"$",
"this",
"->",
"create",
"(",
"$",
"type",
",",
"$",
"bindings",
")",
";",
"}",
"}",
"$",
"inParam",
"[",
"]",
"=",
"$",
"get",
";",
"}",
"$",
"out",
"=",
"$",
"class",
"->",
"newInstanceArgs",
"(",
"$",
"inParam",
")",
";",
"}",
"else",
"{",
"$",
"out",
"=",
"$",
"class",
"->",
"newInstanceWithoutConstructor",
"(",
")",
";",
"}",
"return",
"$",
"out",
";",
"}"
] | Create a instance of given class name.
The injector will try to handle constructor injection, if it fails, it will throw an exception.
If a binding array is passed through this method and a container already exists, the bindings will take
precedence over the container.
@param string $className
@param array $bindings Key value bindings list. Not required if a container exists.
@return null|object
@throws NotFoundExceptionInterface
@throws ContainerExceptionInterface
@internal | [
"Create",
"a",
"instance",
"of",
"given",
"class",
"name",
".",
"The",
"injector",
"will",
"try",
"to",
"handle",
"constructor",
"injection",
"if",
"it",
"fails",
"it",
"will",
"throw",
"an",
"exception",
"."
] | e24af8e089f5b46219316f9a9c0e0b2193c256b7 | https://github.com/jitesoft/php-container/blob/e24af8e089f5b46219316f9a9c0e0b2193c256b7/src/Injector.php#L56-L90 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PrepareForPersist.php | PrepareForPersist.prepareTitleForPersist | public function prepareTitleForPersist($title)
{
// Strip whitespace (or other characters) from the beginning and end of a string
$transformedTitle = trim($title);
// Strip HTML and PHP tags from a string
$transformedTitle = strip_tags($transformedTitle);
// Strip tags, optionally strip or encode special characters
// http://php.net/manual/en/filter.filters.sanitize.php
$transformedTitle = filter_var($transformedTitle, FILTER_SANITIZE_STRING);
// Uppercase the first character of each word in a string
$transformedTitle = ucwords($transformedTitle);
return $transformedTitle;
} | php | public function prepareTitleForPersist($title)
{
// Strip whitespace (or other characters) from the beginning and end of a string
$transformedTitle = trim($title);
// Strip HTML and PHP tags from a string
$transformedTitle = strip_tags($transformedTitle);
// Strip tags, optionally strip or encode special characters
// http://php.net/manual/en/filter.filters.sanitize.php
$transformedTitle = filter_var($transformedTitle, FILTER_SANITIZE_STRING);
// Uppercase the first character of each word in a string
$transformedTitle = ucwords($transformedTitle);
return $transformedTitle;
} | [
"public",
"function",
"prepareTitleForPersist",
"(",
"$",
"title",
")",
"{",
"// Strip whitespace (or other characters) from the beginning and end of a string",
"$",
"transformedTitle",
"=",
"trim",
"(",
"$",
"title",
")",
";",
"// Strip HTML and PHP tags from a string",
"$",
"transformedTitle",
"=",
"strip_tags",
"(",
"$",
"transformedTitle",
")",
";",
"// Strip tags, optionally strip or encode special characters",
"// http://php.net/manual/en/filter.filters.sanitize.php",
"$",
"transformedTitle",
"=",
"filter_var",
"(",
"$",
"transformedTitle",
",",
"FILTER_SANITIZE_STRING",
")",
";",
"// Uppercase the first character of each word in a string",
"$",
"transformedTitle",
"=",
"ucwords",
"(",
"$",
"transformedTitle",
")",
";",
"return",
"$",
"transformedTitle",
";",
"}"
] | Transform title for persist.
@param text $title
@return text | [
"Transform",
"title",
"for",
"persist",
"."
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PrepareForPersist.php#L188-L204 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PrepareForPersist.php | PrepareForPersist.prepareDescriptionForPersist | public function prepareDescriptionForPersist($description)
{
$description = html_entity_decode($description);
$description = strip_tags($description);
$description = filter_var($description, FILTER_SANITIZE_STRING);
// remove the encoded blank chars
$description = str_replace("\xc2\xa0",'',$description);
$description = trim($description);
return $description;
} | php | public function prepareDescriptionForPersist($description)
{
$description = html_entity_decode($description);
$description = strip_tags($description);
$description = filter_var($description, FILTER_SANITIZE_STRING);
// remove the encoded blank chars
$description = str_replace("\xc2\xa0",'',$description);
$description = trim($description);
return $description;
} | [
"public",
"function",
"prepareDescriptionForPersist",
"(",
"$",
"description",
")",
"{",
"$",
"description",
"=",
"html_entity_decode",
"(",
"$",
"description",
")",
";",
"$",
"description",
"=",
"strip_tags",
"(",
"$",
"description",
")",
";",
"$",
"description",
"=",
"filter_var",
"(",
"$",
"description",
",",
"FILTER_SANITIZE_STRING",
")",
";",
"// remove the encoded blank chars",
"$",
"description",
"=",
"str_replace",
"(",
"\"\\xc2\\xa0\"",
",",
"''",
",",
"$",
"description",
")",
";",
"$",
"description",
"=",
"trim",
"(",
"$",
"description",
")",
";",
"return",
"$",
"description",
";",
"}"
] | Transform description for persist.
@param string $descriptions
@return text | [
"Transform",
"description",
"for",
"persist",
"."
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PrepareForPersist.php#L213-L224 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PrepareForPersist.php | PrepareForPersist.prepareSlugForPersist | public function prepareSlugForPersist($title, $slug, $id=false)
{
$separator = '-';
if ($slug == "")
{
// No slug.. so this is a "create" form; or, the slug was deleted accidentally and so needs to be regenerated
// Convert all dashes/underscores into separator
$flip = $separator == '-' ? '_' : '-';
// wash the title
$title = html_entity_decode($title);
$title = strip_tags($title);
$title = filter_var($title, FILTER_SANITIZE_STRING);
// remove the encoded blank chars
$title = str_replace("\xc2\xa0",'',$title);
// remove encoded apostrophe
$title = str_replace("'",'',$title);
$title = trim($title);
$slug = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);
// Remove all characters that are not the separator, letters, numbers, or whitespace.
$slug = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($slug));
// Replace all separator characters and whitespace by a single separator
$slug = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $slug);
// well, is another record using this slug already? Let's return a record count, so we can use the count number...
$rowCount = $this->doesSlugAlreadyExist($slug);
if ($rowCount > 0)
{
// yes, this slug does exist already, so let's append this slug to make it different from what already exists.
++$rowCount;
return $slug.$rowCount;
}
// no, this slug does not yet exist, so let's use it as-is...
return $slug;
}
// Ah, so a slug was entered. So coming from an "edit" form...
// remove the encoded blank chars
$slug = str_replace("\xc2\xa0",'',$slug);
// remove encoded apostrophe
$slug = str_replace("'",'',$slug);
$slug = trim($slug);
$slug = strtolower($slug);
$slug = strip_tags($slug);
$slug = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $slug);
// if this slug is a different slug manually entered into the edit form, then process it further
if (!$this->isManuallyChangedSlugInEditForm($slug, $id)) {
return $slug;
}
// so this slug does belong to the existing ID, but is different than the slug in the database...
// well, is another record using this slug already? Let's return a record count, so we can use the count number...
$rowCount = $this->doesSlugAlreadyExist($slug);
if ($rowCount > 0)
{
// yes, this slug does exist already, so let's append this slug to make it different from what already exists.
++$rowCount;
return $slug.$rowCount;
}
// no, this slug does not yet exist, so let's use it as-is...
return $slug;
} | php | public function prepareSlugForPersist($title, $slug, $id=false)
{
$separator = '-';
if ($slug == "")
{
// No slug.. so this is a "create" form; or, the slug was deleted accidentally and so needs to be regenerated
// Convert all dashes/underscores into separator
$flip = $separator == '-' ? '_' : '-';
// wash the title
$title = html_entity_decode($title);
$title = strip_tags($title);
$title = filter_var($title, FILTER_SANITIZE_STRING);
// remove the encoded blank chars
$title = str_replace("\xc2\xa0",'',$title);
// remove encoded apostrophe
$title = str_replace("'",'',$title);
$title = trim($title);
$slug = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);
// Remove all characters that are not the separator, letters, numbers, or whitespace.
$slug = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($slug));
// Replace all separator characters and whitespace by a single separator
$slug = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $slug);
// well, is another record using this slug already? Let's return a record count, so we can use the count number...
$rowCount = $this->doesSlugAlreadyExist($slug);
if ($rowCount > 0)
{
// yes, this slug does exist already, so let's append this slug to make it different from what already exists.
++$rowCount;
return $slug.$rowCount;
}
// no, this slug does not yet exist, so let's use it as-is...
return $slug;
}
// Ah, so a slug was entered. So coming from an "edit" form...
// remove the encoded blank chars
$slug = str_replace("\xc2\xa0",'',$slug);
// remove encoded apostrophe
$slug = str_replace("'",'',$slug);
$slug = trim($slug);
$slug = strtolower($slug);
$slug = strip_tags($slug);
$slug = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $slug);
// if this slug is a different slug manually entered into the edit form, then process it further
if (!$this->isManuallyChangedSlugInEditForm($slug, $id)) {
return $slug;
}
// so this slug does belong to the existing ID, but is different than the slug in the database...
// well, is another record using this slug already? Let's return a record count, so we can use the count number...
$rowCount = $this->doesSlugAlreadyExist($slug);
if ($rowCount > 0)
{
// yes, this slug does exist already, so let's append this slug to make it different from what already exists.
++$rowCount;
return $slug.$rowCount;
}
// no, this slug does not yet exist, so let's use it as-is...
return $slug;
} | [
"public",
"function",
"prepareSlugForPersist",
"(",
"$",
"title",
",",
"$",
"slug",
",",
"$",
"id",
"=",
"false",
")",
"{",
"$",
"separator",
"=",
"'-'",
";",
"if",
"(",
"$",
"slug",
"==",
"\"\"",
")",
"{",
"// No slug.. so this is a \"create\" form; or, the slug was deleted accidentally and so needs to be regenerated",
"// Convert all dashes/underscores into separator",
"$",
"flip",
"=",
"$",
"separator",
"==",
"'-'",
"?",
"'_'",
":",
"'-'",
";",
"// wash the title",
"$",
"title",
"=",
"html_entity_decode",
"(",
"$",
"title",
")",
";",
"$",
"title",
"=",
"strip_tags",
"(",
"$",
"title",
")",
";",
"$",
"title",
"=",
"filter_var",
"(",
"$",
"title",
",",
"FILTER_SANITIZE_STRING",
")",
";",
"// remove the encoded blank chars",
"$",
"title",
"=",
"str_replace",
"(",
"\"\\xc2\\xa0\"",
",",
"''",
",",
"$",
"title",
")",
";",
"// remove encoded apostrophe",
"$",
"title",
"=",
"str_replace",
"(",
"\"'\"",
",",
"''",
",",
"$",
"title",
")",
";",
"$",
"title",
"=",
"trim",
"(",
"$",
"title",
")",
";",
"$",
"slug",
"=",
"preg_replace",
"(",
"'!['",
".",
"preg_quote",
"(",
"$",
"flip",
")",
".",
"']+!u'",
",",
"$",
"separator",
",",
"$",
"title",
")",
";",
"// Remove all characters that are not the separator, letters, numbers, or whitespace.",
"$",
"slug",
"=",
"preg_replace",
"(",
"'![^'",
".",
"preg_quote",
"(",
"$",
"separator",
")",
".",
"'\\pL\\pN\\s]+!u'",
",",
"''",
",",
"mb_strtolower",
"(",
"$",
"slug",
")",
")",
";",
"// Replace all separator characters and whitespace by a single separator",
"$",
"slug",
"=",
"preg_replace",
"(",
"'!['",
".",
"preg_quote",
"(",
"$",
"separator",
")",
".",
"'\\s]+!u'",
",",
"$",
"separator",
",",
"$",
"slug",
")",
";",
"// well, is another record using this slug already? Let's return a record count, so we can use the count number...",
"$",
"rowCount",
"=",
"$",
"this",
"->",
"doesSlugAlreadyExist",
"(",
"$",
"slug",
")",
";",
"if",
"(",
"$",
"rowCount",
">",
"0",
")",
"{",
"// yes, this slug does exist already, so let's append this slug to make it different from what already exists.",
"++",
"$",
"rowCount",
";",
"return",
"$",
"slug",
".",
"$",
"rowCount",
";",
"}",
"// no, this slug does not yet exist, so let's use it as-is...",
"return",
"$",
"slug",
";",
"}",
"// Ah, so a slug was entered. So coming from an \"edit\" form...",
"// remove the encoded blank chars",
"$",
"slug",
"=",
"str_replace",
"(",
"\"\\xc2\\xa0\"",
",",
"''",
",",
"$",
"slug",
")",
";",
"// remove encoded apostrophe",
"$",
"slug",
"=",
"str_replace",
"(",
"\"'\"",
",",
"''",
",",
"$",
"slug",
")",
";",
"$",
"slug",
"=",
"trim",
"(",
"$",
"slug",
")",
";",
"$",
"slug",
"=",
"strtolower",
"(",
"$",
"slug",
")",
";",
"$",
"slug",
"=",
"strip_tags",
"(",
"$",
"slug",
")",
";",
"$",
"slug",
"=",
"preg_replace",
"(",
"'!['",
".",
"preg_quote",
"(",
"$",
"separator",
")",
".",
"'\\s]+!u'",
",",
"$",
"separator",
",",
"$",
"slug",
")",
";",
"// if this slug is a different slug manually entered into the edit form, then process it further",
"if",
"(",
"!",
"$",
"this",
"->",
"isManuallyChangedSlugInEditForm",
"(",
"$",
"slug",
",",
"$",
"id",
")",
")",
"{",
"return",
"$",
"slug",
";",
"}",
"// so this slug does belong to the existing ID, but is different than the slug in the database...",
"// well, is another record using this slug already? Let's return a record count, so we can use the count number...",
"$",
"rowCount",
"=",
"$",
"this",
"->",
"doesSlugAlreadyExist",
"(",
"$",
"slug",
")",
";",
"if",
"(",
"$",
"rowCount",
">",
"0",
")",
"{",
"// yes, this slug does exist already, so let's append this slug to make it different from what already exists.",
"++",
"$",
"rowCount",
";",
"return",
"$",
"slug",
".",
"$",
"rowCount",
";",
"}",
"// no, this slug does not yet exist, so let's use it as-is...",
"return",
"$",
"slug",
";",
"}"
] | Prepare slug for persist.
@param text $title
@param text $slug
@param int $id The id of the record (eg, of the posts table) that is currently being edited
@return text | [
"Prepare",
"slug",
"for",
"persist",
"."
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PrepareForPersist.php#L235-L312 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PrepareForPersist.php | PrepareForPersist.isManuallyChangedSlugInEditForm | public function isManuallyChangedSlugInEditForm($slug, $id=false)
{
// If there is no $id, then there's nothing to figure out!
if (!$id) return false;
$record = DB::table($this->model->table)
->where('id', $id)
->first()
;
if ($record->slug == $slug) {
// The slug entered into the form is the same slug that is already in the database, so no change...
return false;
} else {
// The slug entered into the form is different than the slug in the database, so yes it has changed...
return true;
}
} | php | public function isManuallyChangedSlugInEditForm($slug, $id=false)
{
// If there is no $id, then there's nothing to figure out!
if (!$id) return false;
$record = DB::table($this->model->table)
->where('id', $id)
->first()
;
if ($record->slug == $slug) {
// The slug entered into the form is the same slug that is already in the database, so no change...
return false;
} else {
// The slug entered into the form is different than the slug in the database, so yes it has changed...
return true;
}
} | [
"public",
"function",
"isManuallyChangedSlugInEditForm",
"(",
"$",
"slug",
",",
"$",
"id",
"=",
"false",
")",
"{",
"// If there is no $id, then there's nothing to figure out!",
"if",
"(",
"!",
"$",
"id",
")",
"return",
"false",
";",
"$",
"record",
"=",
"DB",
"::",
"table",
"(",
"$",
"this",
"->",
"model",
"->",
"table",
")",
"->",
"where",
"(",
"'id'",
",",
"$",
"id",
")",
"->",
"first",
"(",
")",
";",
"if",
"(",
"$",
"record",
"->",
"slug",
"==",
"$",
"slug",
")",
"{",
"// The slug entered into the form is the same slug that is already in the database, so no change...",
"return",
"false",
";",
"}",
"else",
"{",
"// The slug entered into the form is different than the slug in the database, so yes it has changed...",
"return",
"true",
";",
"}",
"}"
] | Was the slug changed in the edit form?
@param text $slug
@param int $id The id of the record (eg, of the posts table) that is currently being edited
@return bool | [
"Was",
"the",
"slug",
"changed",
"in",
"the",
"edit",
"form?"
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PrepareForPersist.php#L322-L342 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PrepareForPersist.php | PrepareForPersist.doesSlugAlreadyExist | public function doesSlugAlreadyExist($slug)
{
$rowCount = DB::table($this->model->table)
->where('slug', $slug)
->count();
if ($rowCount > 0) return $rowCount;
return 0;
} | php | public function doesSlugAlreadyExist($slug)
{
$rowCount = DB::table($this->model->table)
->where('slug', $slug)
->count();
if ($rowCount > 0) return $rowCount;
return 0;
} | [
"public",
"function",
"doesSlugAlreadyExist",
"(",
"$",
"slug",
")",
"{",
"$",
"rowCount",
"=",
"DB",
"::",
"table",
"(",
"$",
"this",
"->",
"model",
"->",
"table",
")",
"->",
"where",
"(",
"'slug'",
",",
"$",
"slug",
")",
"->",
"count",
"(",
")",
";",
"if",
"(",
"$",
"rowCount",
">",
"0",
")",
"return",
"$",
"rowCount",
";",
"return",
"0",
";",
"}"
] | Does the slug already exist in the table?
@param text $slug
@return int | [
"Does",
"the",
"slug",
"already",
"exist",
"in",
"the",
"table?"
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PrepareForPersist.php#L351-L359 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PrepareForPersist.php | PrepareForPersist.prepareCanonicalURLForPersist | public function prepareCanonicalURLForPersist($slug)
{
$baseURL = rtrim(config('app.url'), "/");
if ($this->model->table == "posts") $type = "blog";
// July 15, 2015: do *NOT* want type!
//return $baseURL.'/'.$type.'/'.$slug;
return $baseURL.'/'.$slug;
} | php | public function prepareCanonicalURLForPersist($slug)
{
$baseURL = rtrim(config('app.url'), "/");
if ($this->model->table == "posts") $type = "blog";
// July 15, 2015: do *NOT* want type!
//return $baseURL.'/'.$type.'/'.$slug;
return $baseURL.'/'.$slug;
} | [
"public",
"function",
"prepareCanonicalURLForPersist",
"(",
"$",
"slug",
")",
"{",
"$",
"baseURL",
"=",
"rtrim",
"(",
"config",
"(",
"'app.url'",
")",
",",
"\"/\"",
")",
";",
"if",
"(",
"$",
"this",
"->",
"model",
"->",
"table",
"==",
"\"posts\"",
")",
"$",
"type",
"=",
"\"blog\"",
";",
"// July 15, 2015: do *NOT* want type!",
"//return $baseURL.'/'.$type.'/'.$slug;",
"return",
"$",
"baseURL",
".",
"'/'",
".",
"$",
"slug",
";",
"}"
] | Transform canonical_url for persist.
@param text $slug
@return text | [
"Transform",
"canonical_url",
"for",
"persist",
"."
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PrepareForPersist.php#L368-L379 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PrepareForPersist.php | PrepareForPersist.prepareURLForPersist | public function prepareURLForPersist($url)
{
if (substr($url, 0, 7 ) == "http://") return $url;
if (substr($url, 0, 8 ) == "https://") return $url;
$washedUrl = "http://";
$washedUrl .= $url;
return $url;
} | php | public function prepareURLForPersist($url)
{
if (substr($url, 0, 7 ) == "http://") return $url;
if (substr($url, 0, 8 ) == "https://") return $url;
$washedUrl = "http://";
$washedUrl .= $url;
return $url;
} | [
"public",
"function",
"prepareURLForPersist",
"(",
"$",
"url",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"7",
")",
"==",
"\"http://\"",
")",
"return",
"$",
"url",
";",
"if",
"(",
"substr",
"(",
"$",
"url",
",",
"0",
",",
"8",
")",
"==",
"\"https://\"",
")",
"return",
"$",
"url",
";",
"$",
"washedUrl",
"=",
"\"http://\"",
";",
"$",
"washedUrl",
".=",
"$",
"url",
";",
"return",
"$",
"url",
";",
"}"
] | Wash URL for persist.
Does *not* test for a .com or .ca or other TLD
@param text $url
@return text | [
"Wash",
"URL",
"for",
"persist",
"."
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PrepareForPersist.php#L390-L400 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PrepareForPersist.php | PrepareForPersist.prepareExcerptForPersist | public function prepareExcerptForPersist($excerpt="", $content)
{
$chars_to_excerpt = config('lasallecmsapi.how_many_initial_chars_of_content_field_for_excerpt');
if ($excerpt == "")
{
$excerpt = $content;
$excerpt = html_entity_decode($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = filter_var($excerpt, FILTER_SANITIZE_STRING);
// remove the encoded blank chars
$excerpt = str_replace("\xc2\xa0",'',$excerpt);
$excerpt = trim($excerpt);
$excerpt = mb_substr($excerpt, 0, $chars_to_excerpt).config('lasallecmsapi.append_excerpt_with_this_string');
return $excerpt;
}
$excerpt = html_entity_decode($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = filter_var($excerpt, FILTER_SANITIZE_STRING);
// remove the encoded blank chars
$excerpt = str_replace("\xc2\xa0",'',$excerpt);
$excerpt = trim($excerpt);
$excerpt.config('lasallecmsapi.append_excerpt_with_this_string');
return $excerpt;
} | php | public function prepareExcerptForPersist($excerpt="", $content)
{
$chars_to_excerpt = config('lasallecmsapi.how_many_initial_chars_of_content_field_for_excerpt');
if ($excerpt == "")
{
$excerpt = $content;
$excerpt = html_entity_decode($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = filter_var($excerpt, FILTER_SANITIZE_STRING);
// remove the encoded blank chars
$excerpt = str_replace("\xc2\xa0",'',$excerpt);
$excerpt = trim($excerpt);
$excerpt = mb_substr($excerpt, 0, $chars_to_excerpt).config('lasallecmsapi.append_excerpt_with_this_string');
return $excerpt;
}
$excerpt = html_entity_decode($excerpt);
$excerpt = strip_tags($excerpt);
$excerpt = filter_var($excerpt, FILTER_SANITIZE_STRING);
// remove the encoded blank chars
$excerpt = str_replace("\xc2\xa0",'',$excerpt);
$excerpt = trim($excerpt);
$excerpt.config('lasallecmsapi.append_excerpt_with_this_string');
return $excerpt;
} | [
"public",
"function",
"prepareExcerptForPersist",
"(",
"$",
"excerpt",
"=",
"\"\"",
",",
"$",
"content",
")",
"{",
"$",
"chars_to_excerpt",
"=",
"config",
"(",
"'lasallecmsapi.how_many_initial_chars_of_content_field_for_excerpt'",
")",
";",
"if",
"(",
"$",
"excerpt",
"==",
"\"\"",
")",
"{",
"$",
"excerpt",
"=",
"$",
"content",
";",
"$",
"excerpt",
"=",
"html_entity_decode",
"(",
"$",
"excerpt",
")",
";",
"$",
"excerpt",
"=",
"strip_tags",
"(",
"$",
"excerpt",
")",
";",
"$",
"excerpt",
"=",
"filter_var",
"(",
"$",
"excerpt",
",",
"FILTER_SANITIZE_STRING",
")",
";",
"// remove the encoded blank chars",
"$",
"excerpt",
"=",
"str_replace",
"(",
"\"\\xc2\\xa0\"",
",",
"''",
",",
"$",
"excerpt",
")",
";",
"$",
"excerpt",
"=",
"trim",
"(",
"$",
"excerpt",
")",
";",
"$",
"excerpt",
"=",
"mb_substr",
"(",
"$",
"excerpt",
",",
"0",
",",
"$",
"chars_to_excerpt",
")",
".",
"config",
"(",
"'lasallecmsapi.append_excerpt_with_this_string'",
")",
";",
"return",
"$",
"excerpt",
";",
"}",
"$",
"excerpt",
"=",
"html_entity_decode",
"(",
"$",
"excerpt",
")",
";",
"$",
"excerpt",
"=",
"strip_tags",
"(",
"$",
"excerpt",
")",
";",
"$",
"excerpt",
"=",
"filter_var",
"(",
"$",
"excerpt",
",",
"FILTER_SANITIZE_STRING",
")",
";",
"// remove the encoded blank chars",
"$",
"excerpt",
"=",
"str_replace",
"(",
"\"\\xc2\\xa0\"",
",",
"''",
",",
"$",
"excerpt",
")",
";",
"$",
"excerpt",
"=",
"trim",
"(",
"$",
"excerpt",
")",
";",
"$",
"excerpt",
".",
"config",
"(",
"'lasallecmsapi.append_excerpt_with_this_string'",
")",
";",
"return",
"$",
"excerpt",
";",
"}"
] | Transform excerpt for persist.
@param text $excerpt
@return text | [
"Transform",
"excerpt",
"for",
"persist",
"."
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PrepareForPersist.php#L422-L453 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PrepareForPersist.php | PrepareForPersist.prepareMetaDescriptionForPersist | public function prepareMetaDescriptionForPersist($meta_description="", $excerpt)
{
if ($meta_description == "") return $excerpt;
$meta_description = html_entity_decode($meta_description);
$meta_description = strip_tags($meta_description);
$meta_description = filter_var($meta_description, FILTER_SANITIZE_STRING);
// remove the encoded blank chars
$meta_description = str_replace("\xc2\xa0",'',$meta_description);
$meta_description = trim($meta_description);
return $meta_description;
} | php | public function prepareMetaDescriptionForPersist($meta_description="", $excerpt)
{
if ($meta_description == "") return $excerpt;
$meta_description = html_entity_decode($meta_description);
$meta_description = strip_tags($meta_description);
$meta_description = filter_var($meta_description, FILTER_SANITIZE_STRING);
// remove the encoded blank chars
$meta_description = str_replace("\xc2\xa0",'',$meta_description);
$meta_description = trim($meta_description);
return $meta_description;
} | [
"public",
"function",
"prepareMetaDescriptionForPersist",
"(",
"$",
"meta_description",
"=",
"\"\"",
",",
"$",
"excerpt",
")",
"{",
"if",
"(",
"$",
"meta_description",
"==",
"\"\"",
")",
"return",
"$",
"excerpt",
";",
"$",
"meta_description",
"=",
"html_entity_decode",
"(",
"$",
"meta_description",
")",
";",
"$",
"meta_description",
"=",
"strip_tags",
"(",
"$",
"meta_description",
")",
";",
"$",
"meta_description",
"=",
"filter_var",
"(",
"$",
"meta_description",
",",
"FILTER_SANITIZE_STRING",
")",
";",
"// remove the encoded blank chars",
"$",
"meta_description",
"=",
"str_replace",
"(",
"\"\\xc2\\xa0\"",
",",
"''",
",",
"$",
"meta_description",
")",
";",
"$",
"meta_description",
"=",
"trim",
"(",
"$",
"meta_description",
")",
";",
"return",
"$",
"meta_description",
";",
"}"
] | Transform meta_description for persist.
@param text $meta_description
@param text $excerpt
@return text | [
"Transform",
"meta_description",
"for",
"persist",
"."
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PrepareForPersist.php#L463-L476 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PrepareForPersist.php | PrepareForPersist.prepareCompositeTitleForPersist | public function prepareCompositeTitleForPersist($fieldsToConcatenate, $data)
{
$composite_title = "";
// count to determine spacing between fields
$count = count($fieldsToConcatenate);
$i = 1;
foreach ($fieldsToConcatenate as $fieldToConcatenate)
{
// If the field is blank, then skip the concatenation.
// Eg: The field "street2" is blank
if (($data[$fieldToConcatenate] == "") || (!$data[$fieldToConcatenate]) || (empty($data[$fieldToConcatenate])))
{
// blank on purpose --> yeah, I'm leaving it this way 'cause three months from now I'll actually
// understand what I was thinking on the wrong side of midnight on May 27th, 2015!
} else {
$composite_title .= $data[$fieldToConcatenate];
if ($i < $count) $composite_title .= " ";
}
}
return $composite_title;
} | php | public function prepareCompositeTitleForPersist($fieldsToConcatenate, $data)
{
$composite_title = "";
// count to determine spacing between fields
$count = count($fieldsToConcatenate);
$i = 1;
foreach ($fieldsToConcatenate as $fieldToConcatenate)
{
// If the field is blank, then skip the concatenation.
// Eg: The field "street2" is blank
if (($data[$fieldToConcatenate] == "") || (!$data[$fieldToConcatenate]) || (empty($data[$fieldToConcatenate])))
{
// blank on purpose --> yeah, I'm leaving it this way 'cause three months from now I'll actually
// understand what I was thinking on the wrong side of midnight on May 27th, 2015!
} else {
$composite_title .= $data[$fieldToConcatenate];
if ($i < $count) $composite_title .= " ";
}
}
return $composite_title;
} | [
"public",
"function",
"prepareCompositeTitleForPersist",
"(",
"$",
"fieldsToConcatenate",
",",
"$",
"data",
")",
"{",
"$",
"composite_title",
"=",
"\"\"",
";",
"// count to determine spacing between fields",
"$",
"count",
"=",
"count",
"(",
"$",
"fieldsToConcatenate",
")",
";",
"$",
"i",
"=",
"1",
";",
"foreach",
"(",
"$",
"fieldsToConcatenate",
"as",
"$",
"fieldToConcatenate",
")",
"{",
"// If the field is blank, then skip the concatenation.",
"// Eg: The field \"street2\" is blank",
"if",
"(",
"(",
"$",
"data",
"[",
"$",
"fieldToConcatenate",
"]",
"==",
"\"\"",
")",
"||",
"(",
"!",
"$",
"data",
"[",
"$",
"fieldToConcatenate",
"]",
")",
"||",
"(",
"empty",
"(",
"$",
"data",
"[",
"$",
"fieldToConcatenate",
"]",
")",
")",
")",
"{",
"// blank on purpose --> yeah, I'm leaving it this way 'cause three months from now I'll actually",
"// understand what I was thinking on the wrong side of midnight on May 27th, 2015!",
"}",
"else",
"{",
"$",
"composite_title",
".=",
"$",
"data",
"[",
"$",
"fieldToConcatenate",
"]",
";",
"if",
"(",
"$",
"i",
"<",
"$",
"count",
")",
"$",
"composite_title",
".=",
"\" \"",
";",
"}",
"}",
"return",
"$",
"composite_title",
";",
"}"
] | Concatenate fields for the composite Title field
@param array $fieldsToConcatenate
@param array $data
@return string | [
"Concatenate",
"fields",
"for",
"the",
"composite",
"Title",
"field"
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PrepareForPersist.php#L593-L619 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PrepareForPersist.php | PrepareForPersist.prepareRelatedTableForPersist | public function prepareRelatedTableForPersist($field, $data)
{
// If the field is nullable, then having associated records is optional.
if (
( ($data == "") ||
($data == null) ||
(!$data) ||
(empty($data)) )
&&
($field['nullable'])
)
{
$data = null;
}
return $data;
} | php | public function prepareRelatedTableForPersist($field, $data)
{
// If the field is nullable, then having associated records is optional.
if (
( ($data == "") ||
($data == null) ||
(!$data) ||
(empty($data)) )
&&
($field['nullable'])
)
{
$data = null;
}
return $data;
} | [
"public",
"function",
"prepareRelatedTableForPersist",
"(",
"$",
"field",
",",
"$",
"data",
")",
"{",
"// If the field is nullable, then having associated records is optional.",
"if",
"(",
"(",
"(",
"$",
"data",
"==",
"\"\"",
")",
"||",
"(",
"$",
"data",
"==",
"null",
")",
"||",
"(",
"!",
"$",
"data",
")",
"||",
"(",
"empty",
"(",
"$",
"data",
")",
")",
")",
"&&",
"(",
"$",
"field",
"[",
"'nullable'",
"]",
")",
")",
"{",
"$",
"data",
"=",
"null",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Prepare foreign key field for persist.
This is for "one" relationships only, where there is an actual field for the
related table's ID in the primary table.
Basically, the purpose here is to set the data to "null" when there is no value, and
the field is nullable.
@param array $fields
@param array $data
@return mixed | [
"Prepare",
"foreign",
"key",
"field",
"for",
"persist",
"."
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PrepareForPersist.php#L635-L651 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PrepareForPersist.php | PrepareForPersist.genericWashText | public function genericWashText($text) {
// http://php.net/manual/en/function.strip-tags.php
$text = strip_tags($text);
// http://php.net/manual/en/filter.filters.sanitize.php
$text = filter_var($text, FILTER_SANITIZE_STRING);
// remove the encoded blank chars
$text = str_replace("\xc2\xa0",'',$text);
// remove encoded apostrophe
$text = str_replace("'",'',$text);
// final trim
$text = trim($text);
return $text;
} | php | public function genericWashText($text) {
// http://php.net/manual/en/function.strip-tags.php
$text = strip_tags($text);
// http://php.net/manual/en/filter.filters.sanitize.php
$text = filter_var($text, FILTER_SANITIZE_STRING);
// remove the encoded blank chars
$text = str_replace("\xc2\xa0",'',$text);
// remove encoded apostrophe
$text = str_replace("'",'',$text);
// final trim
$text = trim($text);
return $text;
} | [
"public",
"function",
"genericWashText",
"(",
"$",
"text",
")",
"{",
"// http://php.net/manual/en/function.strip-tags.php",
"$",
"text",
"=",
"strip_tags",
"(",
"$",
"text",
")",
";",
"// http://php.net/manual/en/filter.filters.sanitize.php",
"$",
"text",
"=",
"filter_var",
"(",
"$",
"text",
",",
"FILTER_SANITIZE_STRING",
")",
";",
"// remove the encoded blank chars",
"$",
"text",
"=",
"str_replace",
"(",
"\"\\xc2\\xa0\"",
",",
"''",
",",
"$",
"text",
")",
";",
"// remove encoded apostrophe",
"$",
"text",
"=",
"str_replace",
"(",
"\"'\"",
",",
"''",
",",
"$",
"text",
")",
";",
"// final trim",
"$",
"text",
"=",
"trim",
"(",
"$",
"text",
")",
";",
"return",
"$",
"text",
";",
"}"
] | A generic wash of plain ol' text.
The hope is to rid a string of HTML tags and PHP tags
My admin form automation does not call this method, but I concocted it for my email package, and thought, gee,
it would be nice to have it in this class for other custom form field processing.
@param string $text
@return string | [
"A",
"generic",
"wash",
"of",
"plain",
"ol",
"text",
"."
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PrepareForPersist.php#L665-L683 | train |
lasallecms/lasallecms-l5-lasallecmsapi-pkg | src/Repositories/Traits/PrepareForPersist.php | PrepareForPersist.genericCreateSlug | public function genericCreateSlug($text) {
// Define a separator
$separator = '-';
// Convert all dashes/underscores into separator
$flip = $separator == '-' ? '_' : '-';
// Wash the $text, although it should already be washed
$slug = $this->genericWashText($text);
$slug = preg_replace('!['.preg_quote($flip).']+!u', $separator, $slug);
// Remove all characters that are not the separator, letters, numbers, or whitespace.
$slug = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($slug));
// Replace all separator characters and whitespace by a single separator
$slug = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $slug);
return $slug;
} | php | public function genericCreateSlug($text) {
// Define a separator
$separator = '-';
// Convert all dashes/underscores into separator
$flip = $separator == '-' ? '_' : '-';
// Wash the $text, although it should already be washed
$slug = $this->genericWashText($text);
$slug = preg_replace('!['.preg_quote($flip).']+!u', $separator, $slug);
// Remove all characters that are not the separator, letters, numbers, or whitespace.
$slug = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($slug));
// Replace all separator characters and whitespace by a single separator
$slug = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $slug);
return $slug;
} | [
"public",
"function",
"genericCreateSlug",
"(",
"$",
"text",
")",
"{",
"// Define a separator",
"$",
"separator",
"=",
"'-'",
";",
"// Convert all dashes/underscores into separator",
"$",
"flip",
"=",
"$",
"separator",
"==",
"'-'",
"?",
"'_'",
":",
"'-'",
";",
"// Wash the $text, although it should already be washed",
"$",
"slug",
"=",
"$",
"this",
"->",
"genericWashText",
"(",
"$",
"text",
")",
";",
"$",
"slug",
"=",
"preg_replace",
"(",
"'!['",
".",
"preg_quote",
"(",
"$",
"flip",
")",
".",
"']+!u'",
",",
"$",
"separator",
",",
"$",
"slug",
")",
";",
"// Remove all characters that are not the separator, letters, numbers, or whitespace.",
"$",
"slug",
"=",
"preg_replace",
"(",
"'![^'",
".",
"preg_quote",
"(",
"$",
"separator",
")",
".",
"'\\pL\\pN\\s]+!u'",
",",
"''",
",",
"mb_strtolower",
"(",
"$",
"slug",
")",
")",
";",
"// Replace all separator characters and whitespace by a single separator",
"$",
"slug",
"=",
"preg_replace",
"(",
"'!['",
".",
"preg_quote",
"(",
"$",
"separator",
")",
".",
"'\\s]+!u'",
",",
"$",
"separator",
",",
"$",
"slug",
")",
";",
"return",
"$",
"slug",
";",
"}"
] | A generic method to create a slug based on any string.
The prepareSlugForPersis() method creates a slug from the "title" field. This method
let's you create a slug from any string, not just from the "title" field.
My admin form automation does not call this method, but I concocted it for my email package, and thought, gee,
it would be nice to have it in this class for other custom form field processing.
@param string $text
@return string | [
"A",
"generic",
"method",
"to",
"create",
"a",
"slug",
"based",
"on",
"any",
"string",
"."
] | 05083be19645d52be86d8ba4f322773db348a11d | https://github.com/lasallecms/lasallecms-l5-lasallecmsapi-pkg/blob/05083be19645d52be86d8ba4f322773db348a11d/src/Repositories/Traits/PrepareForPersist.php#L697-L717 | train |
nattreid/tracking | src/Model/Tracking/TrackingMapper.php | TrackingMapper.onlineUsers | public function onlineUsers(): int
{
$builder = $this->builder()
->addSelect('COUNT(DISTINCT([uid])) count')
->andWhere('[inserted] > %dt', (new \DateTime)->modify('-' . $this->onlineTime . ' minute'))
->andWhere('[timeOnPage] IS NOT null');
return $this->execute($builder)->fetch()->count;
} | php | public function onlineUsers(): int
{
$builder = $this->builder()
->addSelect('COUNT(DISTINCT([uid])) count')
->andWhere('[inserted] > %dt', (new \DateTime)->modify('-' . $this->onlineTime . ' minute'))
->andWhere('[timeOnPage] IS NOT null');
return $this->execute($builder)->fetch()->count;
} | [
"public",
"function",
"onlineUsers",
"(",
")",
":",
"int",
"{",
"$",
"builder",
"=",
"$",
"this",
"->",
"builder",
"(",
")",
"->",
"addSelect",
"(",
"'COUNT(DISTINCT([uid])) count'",
")",
"->",
"andWhere",
"(",
"'[inserted] > %dt'",
",",
"(",
"new",
"\\",
"DateTime",
")",
"->",
"modify",
"(",
"'-'",
".",
"$",
"this",
"->",
"onlineTime",
".",
"' minute'",
")",
")",
"->",
"andWhere",
"(",
"'[timeOnPage] IS NOT null'",
")",
";",
"return",
"$",
"this",
"->",
"execute",
"(",
"$",
"builder",
")",
"->",
"fetch",
"(",
")",
"->",
"count",
";",
"}"
] | Vrati online uzivatele
@return int
@throws QueryException | [
"Vrati",
"online",
"uzivatele"
] | 5fc7c993c08774945405c79a393584ef2ed589f7 | https://github.com/nattreid/tracking/blob/5fc7c993c08774945405c79a393584ef2ed589f7/src/Model/Tracking/TrackingMapper.php#L105-L112 | train |
nattreid/tracking | src/Model/Tracking/TrackingMapper.php | TrackingMapper.findVisitsHours | public function findVisitsHours(Range $interval, bool $useTime = false): ?Result
{
$date = $useTime ? '%dt' : 'DATE(%dt)';
$subQuery = 'SELECT '
. 'DATE_FORMAT([inserted], "%%Y-%%m-%%d %%H:00:00") datefield, '
. 'COUNT([uid]) visits '
. 'FROM %table '
. 'WHERE ' . ($useTime ? '[inserted]' : 'DATE([inserted])') . ' BETWEEN ' . $date . ' AND ' . $date . ' '
. 'GROUP BY [uid], ROUND(UNIX_TIMESTAMP([inserted]) / %i)';
return $this->connection->query('SELECT [datefield], COUNT([visits]) visits FROM (' . $subQuery . ') sub GROUP BY HOUR([datefield]), DAY([datefield])', $this->getTableName(), $interval->from, $interval->to, $this->minTimeBetweenVisits * 60);
} | php | public function findVisitsHours(Range $interval, bool $useTime = false): ?Result
{
$date = $useTime ? '%dt' : 'DATE(%dt)';
$subQuery = 'SELECT '
. 'DATE_FORMAT([inserted], "%%Y-%%m-%%d %%H:00:00") datefield, '
. 'COUNT([uid]) visits '
. 'FROM %table '
. 'WHERE ' . ($useTime ? '[inserted]' : 'DATE([inserted])') . ' BETWEEN ' . $date . ' AND ' . $date . ' '
. 'GROUP BY [uid], ROUND(UNIX_TIMESTAMP([inserted]) / %i)';
return $this->connection->query('SELECT [datefield], COUNT([visits]) visits FROM (' . $subQuery . ') sub GROUP BY HOUR([datefield]), DAY([datefield])', $this->getTableName(), $interval->from, $interval->to, $this->minTimeBetweenVisits * 60);
} | [
"public",
"function",
"findVisitsHours",
"(",
"Range",
"$",
"interval",
",",
"bool",
"$",
"useTime",
"=",
"false",
")",
":",
"?",
"Result",
"{",
"$",
"date",
"=",
"$",
"useTime",
"?",
"'%dt'",
":",
"'DATE(%dt)'",
";",
"$",
"subQuery",
"=",
"'SELECT '",
".",
"'DATE_FORMAT([inserted], \"%%Y-%%m-%%d %%H:00:00\") datefield, '",
".",
"'COUNT([uid]) visits '",
".",
"'FROM %table '",
".",
"'WHERE '",
".",
"(",
"$",
"useTime",
"?",
"'[inserted]'",
":",
"'DATE([inserted])'",
")",
".",
"' BETWEEN '",
".",
"$",
"date",
".",
"' AND '",
".",
"$",
"date",
".",
"' '",
".",
"'GROUP BY [uid], ROUND(UNIX_TIMESTAMP([inserted]) / %i)'",
";",
"return",
"$",
"this",
"->",
"connection",
"->",
"query",
"(",
"'SELECT [datefield], COUNT([visits]) visits FROM ('",
".",
"$",
"subQuery",
".",
"') sub GROUP BY HOUR([datefield]), DAY([datefield])'",
",",
"$",
"this",
"->",
"getTableName",
"(",
")",
",",
"$",
"interval",
"->",
"from",
",",
"$",
"interval",
"->",
"to",
",",
"$",
"this",
"->",
"minTimeBetweenVisits",
"*",
"60",
")",
";",
"}"
] | Vrati navstevy po hodinach
@param Range $interval
@param bool $useTime ma se pouzit cas v intervalu
@return Result|null
@throws QueryException | [
"Vrati",
"navstevy",
"po",
"hodinach"
] | 5fc7c993c08774945405c79a393584ef2ed589f7 | https://github.com/nattreid/tracking/blob/5fc7c993c08774945405c79a393584ef2ed589f7/src/Model/Tracking/TrackingMapper.php#L121-L132 | train |
mwyatt/core | src/Iterator/Model/User.php | User.getByNameFirst | public function getByNameFirst($value)
{
$users = [];
foreach ($this as $user) {
if ($user->get('nameFirst')) {
$users[] = $user;
}
}
return new $this($users);
} | php | public function getByNameFirst($value)
{
$users = [];
foreach ($this as $user) {
if ($user->get('nameFirst')) {
$users[] = $user;
}
}
return new $this($users);
} | [
"public",
"function",
"getByNameFirst",
"(",
"$",
"value",
")",
"{",
"$",
"users",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"as",
"$",
"user",
")",
"{",
"if",
"(",
"$",
"user",
"->",
"get",
"(",
"'nameFirst'",
")",
")",
"{",
"$",
"users",
"[",
"]",
"=",
"$",
"user",
";",
"}",
"}",
"return",
"new",
"$",
"this",
"(",
"$",
"users",
")",
";",
"}"
] | example usage of more specific iterator
will tidy the controllers even further
@param string $value
@return array users | [
"example",
"usage",
"of",
"more",
"specific",
"iterator",
"will",
"tidy",
"the",
"controllers",
"even",
"further"
] | 8ea9d67cc84fe6aff17a469c703d5492dbcd93ed | https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/Iterator/Model/User.php#L15-L24 | train |
RhubarbPHP/Module.Leaf.Table | src/Leaves/Table.php | Table.inflateColumns | protected function inflateColumns($columns)
{
$inflatedColumns = [];
foreach ($columns as $key => $value) {
$tableColumn = $value;
$label = !is_numeric($key) ? $key : null;
if (is_string($tableColumn)) {
$value = (string)$value;
$tableColumn = $this->createColumnFromString($value, $label);
} elseif (is_callable($tableColumn)) {
$tableColumn = new ClosureColumn($label, $tableColumn);
} elseif (!($tableColumn instanceof TableColumn)) {
$tableColumn = $this->createColumnFromObject($tableColumn, $label);
}
if ($tableColumn && $tableColumn instanceof TableColumn) {
if ($tableColumn instanceof LeafColumn) {
$leaf = $tableColumn->getLeaf();
if ($leaf instanceof BindableLeafTrait) {
$event = $leaf->getBindingValueRequestedEvent();
$event->clearHandlers();
$event->attachHandler(function ($dataKey, $viewIndex = false) {
return $this->getDataForPresenter($dataKey, $viewIndex);
});
}
}
$inflatedColumns[] = $tableColumn;
}
}
return $inflatedColumns;
} | php | protected function inflateColumns($columns)
{
$inflatedColumns = [];
foreach ($columns as $key => $value) {
$tableColumn = $value;
$label = !is_numeric($key) ? $key : null;
if (is_string($tableColumn)) {
$value = (string)$value;
$tableColumn = $this->createColumnFromString($value, $label);
} elseif (is_callable($tableColumn)) {
$tableColumn = new ClosureColumn($label, $tableColumn);
} elseif (!($tableColumn instanceof TableColumn)) {
$tableColumn = $this->createColumnFromObject($tableColumn, $label);
}
if ($tableColumn && $tableColumn instanceof TableColumn) {
if ($tableColumn instanceof LeafColumn) {
$leaf = $tableColumn->getLeaf();
if ($leaf instanceof BindableLeafTrait) {
$event = $leaf->getBindingValueRequestedEvent();
$event->clearHandlers();
$event->attachHandler(function ($dataKey, $viewIndex = false) {
return $this->getDataForPresenter($dataKey, $viewIndex);
});
}
}
$inflatedColumns[] = $tableColumn;
}
}
return $inflatedColumns;
} | [
"protected",
"function",
"inflateColumns",
"(",
"$",
"columns",
")",
"{",
"$",
"inflatedColumns",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"columns",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"tableColumn",
"=",
"$",
"value",
";",
"$",
"label",
"=",
"!",
"is_numeric",
"(",
"$",
"key",
")",
"?",
"$",
"key",
":",
"null",
";",
"if",
"(",
"is_string",
"(",
"$",
"tableColumn",
")",
")",
"{",
"$",
"value",
"=",
"(",
"string",
")",
"$",
"value",
";",
"$",
"tableColumn",
"=",
"$",
"this",
"->",
"createColumnFromString",
"(",
"$",
"value",
",",
"$",
"label",
")",
";",
"}",
"elseif",
"(",
"is_callable",
"(",
"$",
"tableColumn",
")",
")",
"{",
"$",
"tableColumn",
"=",
"new",
"ClosureColumn",
"(",
"$",
"label",
",",
"$",
"tableColumn",
")",
";",
"}",
"elseif",
"(",
"!",
"(",
"$",
"tableColumn",
"instanceof",
"TableColumn",
")",
")",
"{",
"$",
"tableColumn",
"=",
"$",
"this",
"->",
"createColumnFromObject",
"(",
"$",
"tableColumn",
",",
"$",
"label",
")",
";",
"}",
"if",
"(",
"$",
"tableColumn",
"&&",
"$",
"tableColumn",
"instanceof",
"TableColumn",
")",
"{",
"if",
"(",
"$",
"tableColumn",
"instanceof",
"LeafColumn",
")",
"{",
"$",
"leaf",
"=",
"$",
"tableColumn",
"->",
"getLeaf",
"(",
")",
";",
"if",
"(",
"$",
"leaf",
"instanceof",
"BindableLeafTrait",
")",
"{",
"$",
"event",
"=",
"$",
"leaf",
"->",
"getBindingValueRequestedEvent",
"(",
")",
";",
"$",
"event",
"->",
"clearHandlers",
"(",
")",
";",
"$",
"event",
"->",
"attachHandler",
"(",
"function",
"(",
"$",
"dataKey",
",",
"$",
"viewIndex",
"=",
"false",
")",
"{",
"return",
"$",
"this",
"->",
"getDataForPresenter",
"(",
"$",
"dataKey",
",",
"$",
"viewIndex",
")",
";",
"}",
")",
";",
"}",
"}",
"$",
"inflatedColumns",
"[",
"]",
"=",
"$",
"tableColumn",
";",
"}",
"}",
"return",
"$",
"inflatedColumns",
";",
"}"
] | Expands the columns array, creating TableColumn objects where needed.
@param array $columns
@return TableColumn[] | [
"Expands",
"the",
"columns",
"array",
"creating",
"TableColumn",
"objects",
"where",
"needed",
"."
] | 1de09307177cc809ca6b2a50093ccad06ab49e45 | https://github.com/RhubarbPHP/Module.Leaf.Table/blob/1de09307177cc809ca6b2a50093ccad06ab49e45/src/Leaves/Table.php#L343-L378 | train |
RhubarbPHP/Module.Leaf.Table | src/Leaves/Table.php | Table.getDataForPresenter | protected function getDataForPresenter($dataKey, $viewIndex = false)
{
if (!isset($this->currentRow[$dataKey])) {
return $this->model->getBoundValue($dataKey, $viewIndex);
}
$value = $this->currentRow[$dataKey];
if ($value instanceof Model) {
return $value->UniqueIdentifier;
}
return $value;
} | php | protected function getDataForPresenter($dataKey, $viewIndex = false)
{
if (!isset($this->currentRow[$dataKey])) {
return $this->model->getBoundValue($dataKey, $viewIndex);
}
$value = $this->currentRow[$dataKey];
if ($value instanceof Model) {
return $value->UniqueIdentifier;
}
return $value;
} | [
"protected",
"function",
"getDataForPresenter",
"(",
"$",
"dataKey",
",",
"$",
"viewIndex",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"currentRow",
"[",
"$",
"dataKey",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"model",
"->",
"getBoundValue",
"(",
"$",
"dataKey",
",",
"$",
"viewIndex",
")",
";",
"}",
"$",
"value",
"=",
"$",
"this",
"->",
"currentRow",
"[",
"$",
"dataKey",
"]",
";",
"if",
"(",
"$",
"value",
"instanceof",
"Model",
")",
"{",
"return",
"$",
"value",
"->",
"UniqueIdentifier",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Provides model data to the requesting presenter.
This implementation ensures the LeafColumns are able to receive data from the row's model
@param string $dataKey
@param bool|int $viewIndex
@return mixed | [
"Provides",
"model",
"data",
"to",
"the",
"requesting",
"presenter",
"."
] | 1de09307177cc809ca6b2a50093ccad06ab49e45 | https://github.com/RhubarbPHP/Module.Leaf.Table/blob/1de09307177cc809ca6b2a50093ccad06ab49e45/src/Leaves/Table.php#L389-L402 | train |
mwyatt/core | src/AbstractView.php | AbstractView.getTemplate | public function getTemplate($templatePath)
{
$absoluteTemplateFilePath = $this->getTemplateFilePath($templatePath);
if (!$absoluteTemplateFilePath) {
return;
}
extract($this->getArrayCopy());
ob_start();
include $absoluteTemplateFilePath;
$content = ob_get_contents();
ob_end_clean();
return $content;
} | php | public function getTemplate($templatePath)
{
$absoluteTemplateFilePath = $this->getTemplateFilePath($templatePath);
if (!$absoluteTemplateFilePath) {
return;
}
extract($this->getArrayCopy());
ob_start();
include $absoluteTemplateFilePath;
$content = ob_get_contents();
ob_end_clean();
return $content;
} | [
"public",
"function",
"getTemplate",
"(",
"$",
"templatePath",
")",
"{",
"$",
"absoluteTemplateFilePath",
"=",
"$",
"this",
"->",
"getTemplateFilePath",
"(",
"$",
"templatePath",
")",
";",
"if",
"(",
"!",
"$",
"absoluteTemplateFilePath",
")",
"{",
"return",
";",
"}",
"extract",
"(",
"$",
"this",
"->",
"getArrayCopy",
"(",
")",
")",
";",
"ob_start",
"(",
")",
";",
"include",
"$",
"absoluteTemplateFilePath",
";",
"$",
"content",
"=",
"ob_get_contents",
"(",
")",
";",
"ob_end_clean",
"(",
")",
";",
"return",
"$",
"content",
";",
"}"
] | converts stored key values in iterator to output from
template path requested
@param string $templatePath
@return string | [
"converts",
"stored",
"key",
"values",
"in",
"iterator",
"to",
"output",
"from",
"template",
"path",
"requested"
] | 8ea9d67cc84fe6aff17a469c703d5492dbcd93ed | https://github.com/mwyatt/core/blob/8ea9d67cc84fe6aff17a469c703d5492dbcd93ed/src/AbstractView.php#L47-L59 | train |
praxigento/mobi_mod_downline | Block/Adminhtml/Customer/Edit/Tabs/Mobi/Info.php | Info.loadCustomerData | private function loadCustomerData()
{
$custId = $this->registry->registry(\Magento\Customer\Controller\RegistryConstants::CURRENT_CUSTOMER_ID);
if ($custId) {
$query = $this->qLoad->build();
$conn = $query->getConnection();
$bind = [
QLoad::BND_CUST_ID => $custId
];
$rs = $conn->fetchAll($query, $bind);
$this->cacheCustData = reset($rs);
}
} | php | private function loadCustomerData()
{
$custId = $this->registry->registry(\Magento\Customer\Controller\RegistryConstants::CURRENT_CUSTOMER_ID);
if ($custId) {
$query = $this->qLoad->build();
$conn = $query->getConnection();
$bind = [
QLoad::BND_CUST_ID => $custId
];
$rs = $conn->fetchAll($query, $bind);
$this->cacheCustData = reset($rs);
}
} | [
"private",
"function",
"loadCustomerData",
"(",
")",
"{",
"$",
"custId",
"=",
"$",
"this",
"->",
"registry",
"->",
"registry",
"(",
"\\",
"Magento",
"\\",
"Customer",
"\\",
"Controller",
"\\",
"RegistryConstants",
"::",
"CURRENT_CUSTOMER_ID",
")",
";",
"if",
"(",
"$",
"custId",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"qLoad",
"->",
"build",
"(",
")",
";",
"$",
"conn",
"=",
"$",
"query",
"->",
"getConnection",
"(",
")",
";",
"$",
"bind",
"=",
"[",
"QLoad",
"::",
"BND_CUST_ID",
"=>",
"$",
"custId",
"]",
";",
"$",
"rs",
"=",
"$",
"conn",
"->",
"fetchAll",
"(",
"$",
"query",
",",
"$",
"bind",
")",
";",
"$",
"this",
"->",
"cacheCustData",
"=",
"reset",
"(",
"$",
"rs",
")",
";",
"}",
"}"
] | Load block's working data before rendering. | [
"Load",
"block",
"s",
"working",
"data",
"before",
"rendering",
"."
] | 0f3c276dfff1aa029f9fd205ccfc56f207a2e75b | https://github.com/praxigento/mobi_mod_downline/blob/0f3c276dfff1aa029f9fd205ccfc56f207a2e75b/Block/Adminhtml/Customer/Edit/Tabs/Mobi/Info.php#L146-L158 | train |
pixelpolishers/makedocs | src/MakeDocs/Generator/SourceFile.php | SourceFile.getContent | public function getContent()
{
foreach ($this->dom->documentElement->childNodes as $node) {
if ($node->nodeName == 'content') {
return $node;
}
}
return null;
} | php | public function getContent()
{
foreach ($this->dom->documentElement->childNodes as $node) {
if ($node->nodeName == 'content') {
return $node;
}
}
return null;
} | [
"public",
"function",
"getContent",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"dom",
"->",
"documentElement",
"->",
"childNodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"nodeName",
"==",
"'content'",
")",
"{",
"return",
"$",
"node",
";",
"}",
"}",
"return",
"null",
";",
"}"
] | Gets the content section.
@return DOMElement | [
"Gets",
"the",
"content",
"section",
"."
] | 1fa243b52565b5de417ef2dbdfbcae9896b6b483 | https://github.com/pixelpolishers/makedocs/blob/1fa243b52565b5de417ef2dbdfbcae9896b6b483/src/MakeDocs/Generator/SourceFile.php#L63-L72 | train |
freialib/hlin.tools | src/Logger/File.php | FileLogger.log | function log($message, $type = null, $explicit = false) {
try {
$time = date('Y-m-d|H:i:s');
if ($type === null) {
$this->appendToFile(date('Y/m/d'), "[$time] $message", $explicit);
}
else { // type !== null
$this->appendToFile($type, "[$time] $message", $explicit);
}
}
catch (\Exception $e) {
$this->failedLogging($e, $message);
}
} | php | function log($message, $type = null, $explicit = false) {
try {
$time = date('Y-m-d|H:i:s');
if ($type === null) {
$this->appendToFile(date('Y/m/d'), "[$time] $message", $explicit);
}
else { // type !== null
$this->appendToFile($type, "[$time] $message", $explicit);
}
}
catch (\Exception $e) {
$this->failedLogging($e, $message);
}
} | [
"function",
"log",
"(",
"$",
"message",
",",
"$",
"type",
"=",
"null",
",",
"$",
"explicit",
"=",
"false",
")",
"{",
"try",
"{",
"$",
"time",
"=",
"date",
"(",
"'Y-m-d|H:i:s'",
")",
";",
"if",
"(",
"$",
"type",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"appendToFile",
"(",
"date",
"(",
"'Y/m/d'",
")",
",",
"\"[$time] $message\"",
",",
"$",
"explicit",
")",
";",
"}",
"else",
"{",
"// type !== null",
"$",
"this",
"->",
"appendToFile",
"(",
"$",
"type",
",",
"\"[$time] $message\"",
",",
"$",
"explicit",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"failedLogging",
"(",
"$",
"e",
",",
"$",
"message",
")",
";",
"}",
"}"
] | Logs a message. The type can be used as a hint to the logger on how to
log the message. If the logger doesn't understand the type a file with
the type name will be created as default behavior.
Types should not use illegal file characters. | [
"Logs",
"a",
"message",
".",
"The",
"type",
"can",
"be",
"used",
"as",
"a",
"hint",
"to",
"the",
"logger",
"on",
"how",
"to",
"log",
"the",
"message",
".",
"If",
"the",
"logger",
"doesn",
"t",
"understand",
"the",
"type",
"a",
"file",
"with",
"the",
"type",
"name",
"will",
"be",
"created",
"as",
"default",
"behavior",
"."
] | 42ad9e9fe081918d2ee5d52b72d174ccdcf7cbe7 | https://github.com/freialib/hlin.tools/blob/42ad9e9fe081918d2ee5d52b72d174ccdcf7cbe7/src/Logger/File.php#L56-L69 | train |
freialib/hlin.tools | src/Logger/File.php | FileLogger.appendToFile | protected function appendToFile($logfile, $logstring, $explicit = false) {
$class = \hlin\PHP::unn(__CLASS__);
# logging signatures are intended to prevent duplication PER REQUEST
# on a per logger instance basis, not cull duplicate messages per log
$sig = crc32($logstring);
$filesig = crc32($sig.$logfile);
// have we already logged the message?
if ( ! in_array($filesig, $this->filesigs)) {
$fs = $this->fs;
$filepath = $this->logspath.'/'.$logfile.'.log';
$dir = $fs->dirname($filepath);
if ( ! $fs->file_exists($dir)) {
if ( ! $fs->mkdir($dir, $this->dirPermission(), true)) {
$this->failedLogging(null, "[$class] Failed to create directories: $dir");
return;
}
}
// does the file exist?
if ( ! $fs->file_exists($filepath)) {
// ensure the file exists
if ( ! $fs->touch($filepath)) {
$this->failedLogging(null, "[$class] Failed to create log file: $filepath");
return;
}
// ensure the permissions are right
if ( ! $fs->chmod($filepath, $this->filePermission())) {
$this->failedLogging(null, "[$class] Failed to set permissions on log file: $filepath");
return;
}
}
if ( ! $fs->file_append_contents($filepath, "$logstring\n")) {
$this->failedLogging(null, "[$class] Failed to append to log: $filepath");
}
// intentionally recording signature only after success
$this->filesigs[] = $filesig;
// have we stored the summary report?
if ( ! $explicit && ! in_array($sig, $this->sigs)) {
$filepath = $this->logspath.'/summary.log';
# we don't need to ensure directory structure; it's already
# been ensured by previous operations of recording the long
# term complete log message
// we only record the first line in the summary log
if (($ptr = stripos($logstring, "\n")) !== false) {
$summary = trim(substr($logstring, 0, $ptr));
}
else { // no end of line detected
$summary = trim($logstring);
}
if ( ! $fs->file_append_contents($filepath, "$summary\n")) {
$this->failedLogging(null, "[$class] Failed to append to log: $filepath");
}
// intentionally recording signature only after success
$this->sigs[] = $sig;
}
}
} | php | protected function appendToFile($logfile, $logstring, $explicit = false) {
$class = \hlin\PHP::unn(__CLASS__);
# logging signatures are intended to prevent duplication PER REQUEST
# on a per logger instance basis, not cull duplicate messages per log
$sig = crc32($logstring);
$filesig = crc32($sig.$logfile);
// have we already logged the message?
if ( ! in_array($filesig, $this->filesigs)) {
$fs = $this->fs;
$filepath = $this->logspath.'/'.$logfile.'.log';
$dir = $fs->dirname($filepath);
if ( ! $fs->file_exists($dir)) {
if ( ! $fs->mkdir($dir, $this->dirPermission(), true)) {
$this->failedLogging(null, "[$class] Failed to create directories: $dir");
return;
}
}
// does the file exist?
if ( ! $fs->file_exists($filepath)) {
// ensure the file exists
if ( ! $fs->touch($filepath)) {
$this->failedLogging(null, "[$class] Failed to create log file: $filepath");
return;
}
// ensure the permissions are right
if ( ! $fs->chmod($filepath, $this->filePermission())) {
$this->failedLogging(null, "[$class] Failed to set permissions on log file: $filepath");
return;
}
}
if ( ! $fs->file_append_contents($filepath, "$logstring\n")) {
$this->failedLogging(null, "[$class] Failed to append to log: $filepath");
}
// intentionally recording signature only after success
$this->filesigs[] = $filesig;
// have we stored the summary report?
if ( ! $explicit && ! in_array($sig, $this->sigs)) {
$filepath = $this->logspath.'/summary.log';
# we don't need to ensure directory structure; it's already
# been ensured by previous operations of recording the long
# term complete log message
// we only record the first line in the summary log
if (($ptr = stripos($logstring, "\n")) !== false) {
$summary = trim(substr($logstring, 0, $ptr));
}
else { // no end of line detected
$summary = trim($logstring);
}
if ( ! $fs->file_append_contents($filepath, "$summary\n")) {
$this->failedLogging(null, "[$class] Failed to append to log: $filepath");
}
// intentionally recording signature only after success
$this->sigs[] = $sig;
}
}
} | [
"protected",
"function",
"appendToFile",
"(",
"$",
"logfile",
",",
"$",
"logstring",
",",
"$",
"explicit",
"=",
"false",
")",
"{",
"$",
"class",
"=",
"\\",
"hlin",
"\\",
"PHP",
"::",
"unn",
"(",
"__CLASS__",
")",
";",
"# logging signatures are intended to prevent duplication PER REQUEST",
"# on a per logger instance basis, not cull duplicate messages per log",
"$",
"sig",
"=",
"crc32",
"(",
"$",
"logstring",
")",
";",
"$",
"filesig",
"=",
"crc32",
"(",
"$",
"sig",
".",
"$",
"logfile",
")",
";",
"// have we already logged the message?",
"if",
"(",
"!",
"in_array",
"(",
"$",
"filesig",
",",
"$",
"this",
"->",
"filesigs",
")",
")",
"{",
"$",
"fs",
"=",
"$",
"this",
"->",
"fs",
";",
"$",
"filepath",
"=",
"$",
"this",
"->",
"logspath",
".",
"'/'",
".",
"$",
"logfile",
".",
"'.log'",
";",
"$",
"dir",
"=",
"$",
"fs",
"->",
"dirname",
"(",
"$",
"filepath",
")",
";",
"if",
"(",
"!",
"$",
"fs",
"->",
"file_exists",
"(",
"$",
"dir",
")",
")",
"{",
"if",
"(",
"!",
"$",
"fs",
"->",
"mkdir",
"(",
"$",
"dir",
",",
"$",
"this",
"->",
"dirPermission",
"(",
")",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"failedLogging",
"(",
"null",
",",
"\"[$class] Failed to create directories: $dir\"",
")",
";",
"return",
";",
"}",
"}",
"// does the file exist?",
"if",
"(",
"!",
"$",
"fs",
"->",
"file_exists",
"(",
"$",
"filepath",
")",
")",
"{",
"// ensure the file exists",
"if",
"(",
"!",
"$",
"fs",
"->",
"touch",
"(",
"$",
"filepath",
")",
")",
"{",
"$",
"this",
"->",
"failedLogging",
"(",
"null",
",",
"\"[$class] Failed to create log file: $filepath\"",
")",
";",
"return",
";",
"}",
"// ensure the permissions are right",
"if",
"(",
"!",
"$",
"fs",
"->",
"chmod",
"(",
"$",
"filepath",
",",
"$",
"this",
"->",
"filePermission",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"failedLogging",
"(",
"null",
",",
"\"[$class] Failed to set permissions on log file: $filepath\"",
")",
";",
"return",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"fs",
"->",
"file_append_contents",
"(",
"$",
"filepath",
",",
"\"$logstring\\n\"",
")",
")",
"{",
"$",
"this",
"->",
"failedLogging",
"(",
"null",
",",
"\"[$class] Failed to append to log: $filepath\"",
")",
";",
"}",
"// intentionally recording signature only after success",
"$",
"this",
"->",
"filesigs",
"[",
"]",
"=",
"$",
"filesig",
";",
"// have we stored the summary report?",
"if",
"(",
"!",
"$",
"explicit",
"&&",
"!",
"in_array",
"(",
"$",
"sig",
",",
"$",
"this",
"->",
"sigs",
")",
")",
"{",
"$",
"filepath",
"=",
"$",
"this",
"->",
"logspath",
".",
"'/summary.log'",
";",
"# we don't need to ensure directory structure; it's already",
"# been ensured by previous operations of recording the long",
"# term complete log message",
"// we only record the first line in the summary log",
"if",
"(",
"(",
"$",
"ptr",
"=",
"stripos",
"(",
"$",
"logstring",
",",
"\"\\n\"",
")",
")",
"!==",
"false",
")",
"{",
"$",
"summary",
"=",
"trim",
"(",
"substr",
"(",
"$",
"logstring",
",",
"0",
",",
"$",
"ptr",
")",
")",
";",
"}",
"else",
"{",
"// no end of line detected",
"$",
"summary",
"=",
"trim",
"(",
"$",
"logstring",
")",
";",
"}",
"if",
"(",
"!",
"$",
"fs",
"->",
"file_append_contents",
"(",
"$",
"filepath",
",",
"\"$summary\\n\"",
")",
")",
"{",
"$",
"this",
"->",
"failedLogging",
"(",
"null",
",",
"\"[$class] Failed to append to log: $filepath\"",
")",
";",
"}",
"// intentionally recording signature only after success",
"$",
"this",
"->",
"sigs",
"[",
"]",
"=",
"$",
"sig",
";",
"}",
"}",
"}"
] | Appeds to the logfile. The logfile is relative to the logs directory.
If the logfile doesn't exist yet the system will create it. The '.log'
extention is automatically appended, along with a single
newline character. | [
"Appeds",
"to",
"the",
"logfile",
".",
"The",
"logfile",
"is",
"relative",
"to",
"the",
"logs",
"directory",
".",
"If",
"the",
"logfile",
"doesn",
"t",
"exist",
"yet",
"the",
"system",
"will",
"create",
"it",
".",
"The",
".",
"log",
"extention",
"is",
"automatically",
"appended",
"along",
"with",
"a",
"single",
"newline",
"character",
"."
] | 42ad9e9fe081918d2ee5d52b72d174ccdcf7cbe7 | https://github.com/freialib/hlin.tools/blob/42ad9e9fe081918d2ee5d52b72d174ccdcf7cbe7/src/Logger/File.php#L89-L159 | train |
RocketPropelledTortoise/Core | src/Entities/Field.php | Field.setValueAttribute | public function setValueAttribute($value)
{
if (!$this->isValid($value)) {
throw new InvalidValueException("The value in the field '" . get_class($this) . "' is invalid");
}
$this->attributes['value'] = $this->prepareValue($value);
} | php | public function setValueAttribute($value)
{
if (!$this->isValid($value)) {
throw new InvalidValueException("The value in the field '" . get_class($this) . "' is invalid");
}
$this->attributes['value'] = $this->prepareValue($value);
} | [
"public",
"function",
"setValueAttribute",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isValid",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"InvalidValueException",
"(",
"\"The value in the field '\"",
".",
"get_class",
"(",
"$",
"this",
")",
".",
"\"' is invalid\"",
")",
";",
"}",
"$",
"this",
"->",
"attributes",
"[",
"'value'",
"]",
"=",
"$",
"this",
"->",
"prepareValue",
"(",
"$",
"value",
")",
";",
"}"
] | Validate and set the value
@param mixed $value | [
"Validate",
"and",
"set",
"the",
"value"
] | 78b65663fc463e21e494257140ddbed0a9ccb3c3 | https://github.com/RocketPropelledTortoise/Core/blob/78b65663fc463e21e494257140ddbed0a9ccb3c3/src/Entities/Field.php#L50-L57 | train |
danielgp/browser-agent-info | source/BrowserAgentInfosByDanielGP.php | BrowserAgentInfosByDanielGP.getArchitectureFromUserAgent | public function getArchitectureFromUserAgent($userAgent, $targetToAnalyze = 'os')
{
switch ($targetToAnalyze) {
case 'browser':
$aReturn = $this->getArchitectureFromUserAgentBrowser($userAgent);
break;
case 'os':
$aReturn = $this->getArchitectureFromUserAgentOperatingSystem($userAgent);
break;
default:
$aReturn = ['name' => '---'];
break;
}
return $aReturn;
} | php | public function getArchitectureFromUserAgent($userAgent, $targetToAnalyze = 'os')
{
switch ($targetToAnalyze) {
case 'browser':
$aReturn = $this->getArchitectureFromUserAgentBrowser($userAgent);
break;
case 'os':
$aReturn = $this->getArchitectureFromUserAgentOperatingSystem($userAgent);
break;
default:
$aReturn = ['name' => '---'];
break;
}
return $aReturn;
} | [
"public",
"function",
"getArchitectureFromUserAgent",
"(",
"$",
"userAgent",
",",
"$",
"targetToAnalyze",
"=",
"'os'",
")",
"{",
"switch",
"(",
"$",
"targetToAnalyze",
")",
"{",
"case",
"'browser'",
":",
"$",
"aReturn",
"=",
"$",
"this",
"->",
"getArchitectureFromUserAgentBrowser",
"(",
"$",
"userAgent",
")",
";",
"break",
";",
"case",
"'os'",
":",
"$",
"aReturn",
"=",
"$",
"this",
"->",
"getArchitectureFromUserAgentOperatingSystem",
"(",
"$",
"userAgent",
")",
";",
"break",
";",
"default",
":",
"$",
"aReturn",
"=",
"[",
"'name'",
"=>",
"'---'",
"]",
";",
"break",
";",
"}",
"return",
"$",
"aReturn",
";",
"}"
] | Return CPU architecture details from given user agent
@param string $userAgent
@param string $targetToAnalyze
@return array | [
"Return",
"CPU",
"architecture",
"details",
"from",
"given",
"user",
"agent"
] | 5e4b2c01793ee47ce517be2c799d64abe78d7f8a | https://github.com/danielgp/browser-agent-info/blob/5e4b2c01793ee47ce517be2c799d64abe78d7f8a/source/BrowserAgentInfosByDanielGP.php#L59-L73 | train |
danielgp/browser-agent-info | source/BrowserAgentInfosByDanielGP.php | BrowserAgentInfosByDanielGP.getClientBrowser | private function getClientBrowser(\DeviceDetector\DeviceDetector $deviceDetectorClass, $userAgent)
{
$this->autoPopulateSuperGlobals();
$browserInfoArray = [
'architecture' => $this->getArchitectureFromUserAgent($userAgent, 'browser'),
'connection' => $this->brServerGlobals->server->get('HTTP_CONNECTION'),
'family' => $this->getClientBrowserFamily($deviceDetectorClass),
'host' => $this->brServerGlobals->server->get('HTTP_HOST'),
'referrer' => $this->brServerGlobals->headers->get('referer'),
'user_agent' => $this->getUserAgentByCommonLib(),
];
$vrs = $this->getClientBrowserVersion($deviceDetectorClass);
$browserInformation = array_merge($browserInfoArray, $this->getClientBrowserAccepted(), $vrs);
ksort($browserInformation);
return $browserInformation;
} | php | private function getClientBrowser(\DeviceDetector\DeviceDetector $deviceDetectorClass, $userAgent)
{
$this->autoPopulateSuperGlobals();
$browserInfoArray = [
'architecture' => $this->getArchitectureFromUserAgent($userAgent, 'browser'),
'connection' => $this->brServerGlobals->server->get('HTTP_CONNECTION'),
'family' => $this->getClientBrowserFamily($deviceDetectorClass),
'host' => $this->brServerGlobals->server->get('HTTP_HOST'),
'referrer' => $this->brServerGlobals->headers->get('referer'),
'user_agent' => $this->getUserAgentByCommonLib(),
];
$vrs = $this->getClientBrowserVersion($deviceDetectorClass);
$browserInformation = array_merge($browserInfoArray, $this->getClientBrowserAccepted(), $vrs);
ksort($browserInformation);
return $browserInformation;
} | [
"private",
"function",
"getClientBrowser",
"(",
"\\",
"DeviceDetector",
"\\",
"DeviceDetector",
"$",
"deviceDetectorClass",
",",
"$",
"userAgent",
")",
"{",
"$",
"this",
"->",
"autoPopulateSuperGlobals",
"(",
")",
";",
"$",
"browserInfoArray",
"=",
"[",
"'architecture'",
"=>",
"$",
"this",
"->",
"getArchitectureFromUserAgent",
"(",
"$",
"userAgent",
",",
"'browser'",
")",
",",
"'connection'",
"=>",
"$",
"this",
"->",
"brServerGlobals",
"->",
"server",
"->",
"get",
"(",
"'HTTP_CONNECTION'",
")",
",",
"'family'",
"=>",
"$",
"this",
"->",
"getClientBrowserFamily",
"(",
"$",
"deviceDetectorClass",
")",
",",
"'host'",
"=>",
"$",
"this",
"->",
"brServerGlobals",
"->",
"server",
"->",
"get",
"(",
"'HTTP_HOST'",
")",
",",
"'referrer'",
"=>",
"$",
"this",
"->",
"brServerGlobals",
"->",
"headers",
"->",
"get",
"(",
"'referer'",
")",
",",
"'user_agent'",
"=>",
"$",
"this",
"->",
"getUserAgentByCommonLib",
"(",
")",
",",
"]",
";",
"$",
"vrs",
"=",
"$",
"this",
"->",
"getClientBrowserVersion",
"(",
"$",
"deviceDetectorClass",
")",
";",
"$",
"browserInformation",
"=",
"array_merge",
"(",
"$",
"browserInfoArray",
",",
"$",
"this",
"->",
"getClientBrowserAccepted",
"(",
")",
",",
"$",
"vrs",
")",
";",
"ksort",
"(",
"$",
"browserInformation",
")",
";",
"return",
"$",
"browserInformation",
";",
"}"
] | Provides details about browser
@param \DeviceDetector\DeviceDetector $deviceDetectorClass
@param string $userAgent
@return array | [
"Provides",
"details",
"about",
"browser"
] | 5e4b2c01793ee47ce517be2c799d64abe78d7f8a | https://github.com/danielgp/browser-agent-info/blob/5e4b2c01793ee47ce517be2c799d64abe78d7f8a/source/BrowserAgentInfosByDanielGP.php#L82-L97 | train |
danielgp/browser-agent-info | source/BrowserAgentInfosByDanielGP.php | BrowserAgentInfosByDanielGP.getClientBrowserAccepted | private function getClientBrowserAccepted()
{
$this->autoPopulateSuperGlobals();
$sReturn = [
'accept' => $this->brServerGlobals->server->get('HTTP_ACCEPT'),
'accept_encoding' => $this->brServerGlobals->server->get('HTTP_ACCEPT_ENCODING'),
];
if (!is_null($this->brServerGlobals->server->get('HTTP_ACCEPT_LANGUAGE'))) {
$sReturn['accept_language'] = $this->brServerGlobals->server->get('HTTP_ACCEPT_LANGUAGE');
$prfd = null;
preg_match_all('/([a-z]{2})(?:-[a-zA-Z]{2})?/', $sReturn['accept_language'], $prfd);
$sReturn['preferred locale'] = $prfd[0];
$sReturn['preferred languages'] = array_values(array_unique(array_values($prfd[1])));
}
return $sReturn;
} | php | private function getClientBrowserAccepted()
{
$this->autoPopulateSuperGlobals();
$sReturn = [
'accept' => $this->brServerGlobals->server->get('HTTP_ACCEPT'),
'accept_encoding' => $this->brServerGlobals->server->get('HTTP_ACCEPT_ENCODING'),
];
if (!is_null($this->brServerGlobals->server->get('HTTP_ACCEPT_LANGUAGE'))) {
$sReturn['accept_language'] = $this->brServerGlobals->server->get('HTTP_ACCEPT_LANGUAGE');
$prfd = null;
preg_match_all('/([a-z]{2})(?:-[a-zA-Z]{2})?/', $sReturn['accept_language'], $prfd);
$sReturn['preferred locale'] = $prfd[0];
$sReturn['preferred languages'] = array_values(array_unique(array_values($prfd[1])));
}
return $sReturn;
} | [
"private",
"function",
"getClientBrowserAccepted",
"(",
")",
"{",
"$",
"this",
"->",
"autoPopulateSuperGlobals",
"(",
")",
";",
"$",
"sReturn",
"=",
"[",
"'accept'",
"=>",
"$",
"this",
"->",
"brServerGlobals",
"->",
"server",
"->",
"get",
"(",
"'HTTP_ACCEPT'",
")",
",",
"'accept_encoding'",
"=>",
"$",
"this",
"->",
"brServerGlobals",
"->",
"server",
"->",
"get",
"(",
"'HTTP_ACCEPT_ENCODING'",
")",
",",
"]",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"brServerGlobals",
"->",
"server",
"->",
"get",
"(",
"'HTTP_ACCEPT_LANGUAGE'",
")",
")",
")",
"{",
"$",
"sReturn",
"[",
"'accept_language'",
"]",
"=",
"$",
"this",
"->",
"brServerGlobals",
"->",
"server",
"->",
"get",
"(",
"'HTTP_ACCEPT_LANGUAGE'",
")",
";",
"$",
"prfd",
"=",
"null",
";",
"preg_match_all",
"(",
"'/([a-z]{2})(?:-[a-zA-Z]{2})?/'",
",",
"$",
"sReturn",
"[",
"'accept_language'",
"]",
",",
"$",
"prfd",
")",
";",
"$",
"sReturn",
"[",
"'preferred locale'",
"]",
"=",
"$",
"prfd",
"[",
"0",
"]",
";",
"$",
"sReturn",
"[",
"'preferred languages'",
"]",
"=",
"array_values",
"(",
"array_unique",
"(",
"array_values",
"(",
"$",
"prfd",
"[",
"1",
"]",
")",
")",
")",
";",
"}",
"return",
"$",
"sReturn",
";",
"}"
] | Returns accepted things setting from the client browser
@return array | [
"Returns",
"accepted",
"things",
"setting",
"from",
"the",
"client",
"browser"
] | 5e4b2c01793ee47ce517be2c799d64abe78d7f8a | https://github.com/danielgp/browser-agent-info/blob/5e4b2c01793ee47ce517be2c799d64abe78d7f8a/source/BrowserAgentInfosByDanielGP.php#L104-L119 | train |
danielgp/browser-agent-info | source/BrowserAgentInfosByDanielGP.php | BrowserAgentInfosByDanielGP.getClientBrowserDetails | public function getClientBrowserDetails($returnType = ['Browser', 'Device', 'OS'], $tmpFolder = null)
{
$userAgent = $this->getUserAgentByCommonLib();
$devDetectClass = new \DeviceDetector\DeviceDetector($userAgent);
if (is_null($tmpFolder)) {
$tmpFolder = '../../tmp/DoctrineCache/';
}
$devDetectClass->setCache(new \Doctrine\Common\Cache\PhpFileCache($tmpFolder));
$devDetectClass->discardBotInformation();
$devDetectClass->parse();
if ($devDetectClass->isBot()) {
return [
'Bot' => $devDetectClass->getBot(),
];
}
return $this->getClientBrowserDetailsNonBot($devDetectClass, $userAgent, $returnType);
} | php | public function getClientBrowserDetails($returnType = ['Browser', 'Device', 'OS'], $tmpFolder = null)
{
$userAgent = $this->getUserAgentByCommonLib();
$devDetectClass = new \DeviceDetector\DeviceDetector($userAgent);
if (is_null($tmpFolder)) {
$tmpFolder = '../../tmp/DoctrineCache/';
}
$devDetectClass->setCache(new \Doctrine\Common\Cache\PhpFileCache($tmpFolder));
$devDetectClass->discardBotInformation();
$devDetectClass->parse();
if ($devDetectClass->isBot()) {
return [
'Bot' => $devDetectClass->getBot(),
];
}
return $this->getClientBrowserDetailsNonBot($devDetectClass, $userAgent, $returnType);
} | [
"public",
"function",
"getClientBrowserDetails",
"(",
"$",
"returnType",
"=",
"[",
"'Browser'",
",",
"'Device'",
",",
"'OS'",
"]",
",",
"$",
"tmpFolder",
"=",
"null",
")",
"{",
"$",
"userAgent",
"=",
"$",
"this",
"->",
"getUserAgentByCommonLib",
"(",
")",
";",
"$",
"devDetectClass",
"=",
"new",
"\\",
"DeviceDetector",
"\\",
"DeviceDetector",
"(",
"$",
"userAgent",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"tmpFolder",
")",
")",
"{",
"$",
"tmpFolder",
"=",
"'../../tmp/DoctrineCache/'",
";",
"}",
"$",
"devDetectClass",
"->",
"setCache",
"(",
"new",
"\\",
"Doctrine",
"\\",
"Common",
"\\",
"Cache",
"\\",
"PhpFileCache",
"(",
"$",
"tmpFolder",
")",
")",
";",
"$",
"devDetectClass",
"->",
"discardBotInformation",
"(",
")",
";",
"$",
"devDetectClass",
"->",
"parse",
"(",
")",
";",
"if",
"(",
"$",
"devDetectClass",
"->",
"isBot",
"(",
")",
")",
"{",
"return",
"[",
"'Bot'",
"=>",
"$",
"devDetectClass",
"->",
"getBot",
"(",
")",
",",
"]",
";",
"}",
"return",
"$",
"this",
"->",
"getClientBrowserDetailsNonBot",
"(",
"$",
"devDetectClass",
",",
"$",
"userAgent",
",",
"$",
"returnType",
")",
";",
"}"
] | Provides various details about browser based on user agent
@param array $returnType
@return array | [
"Provides",
"various",
"details",
"about",
"browser",
"based",
"on",
"user",
"agent"
] | 5e4b2c01793ee47ce517be2c799d64abe78d7f8a | https://github.com/danielgp/browser-agent-info/blob/5e4b2c01793ee47ce517be2c799d64abe78d7f8a/source/BrowserAgentInfosByDanielGP.php#L127-L143 | train |
danielgp/browser-agent-info | source/BrowserAgentInfosByDanielGP.php | BrowserAgentInfosByDanielGP.getClientBrowserDevice | private function getClientBrowserDevice(\DeviceDetector\DeviceDetector $deviceDetectorClass)
{
$this->autoPopulateSuperGlobals();
$clientIp = $this->brServerGlobals->getClientIp();
return [
'brand' => $deviceDetectorClass->getDeviceName(),
'ip' => $clientIp,
'ip direct' => $this->brServerGlobals->server->get('REMOTE_ADDR'),
'ip type' => $this->checkIpIsPrivate($clientIp),
'ip v4/v6' => $this->checkIpIsV4OrV6($clientIp),
'model' => $deviceDetectorClass->getModel(),
'name' => $deviceDetectorClass->getBrandName(),
];
} | php | private function getClientBrowserDevice(\DeviceDetector\DeviceDetector $deviceDetectorClass)
{
$this->autoPopulateSuperGlobals();
$clientIp = $this->brServerGlobals->getClientIp();
return [
'brand' => $deviceDetectorClass->getDeviceName(),
'ip' => $clientIp,
'ip direct' => $this->brServerGlobals->server->get('REMOTE_ADDR'),
'ip type' => $this->checkIpIsPrivate($clientIp),
'ip v4/v6' => $this->checkIpIsV4OrV6($clientIp),
'model' => $deviceDetectorClass->getModel(),
'name' => $deviceDetectorClass->getBrandName(),
];
} | [
"private",
"function",
"getClientBrowserDevice",
"(",
"\\",
"DeviceDetector",
"\\",
"DeviceDetector",
"$",
"deviceDetectorClass",
")",
"{",
"$",
"this",
"->",
"autoPopulateSuperGlobals",
"(",
")",
";",
"$",
"clientIp",
"=",
"$",
"this",
"->",
"brServerGlobals",
"->",
"getClientIp",
"(",
")",
";",
"return",
"[",
"'brand'",
"=>",
"$",
"deviceDetectorClass",
"->",
"getDeviceName",
"(",
")",
",",
"'ip'",
"=>",
"$",
"clientIp",
",",
"'ip direct'",
"=>",
"$",
"this",
"->",
"brServerGlobals",
"->",
"server",
"->",
"get",
"(",
"'REMOTE_ADDR'",
")",
",",
"'ip type'",
"=>",
"$",
"this",
"->",
"checkIpIsPrivate",
"(",
"$",
"clientIp",
")",
",",
"'ip v4/v6'",
"=>",
"$",
"this",
"->",
"checkIpIsV4OrV6",
"(",
"$",
"clientIp",
")",
",",
"'model'",
"=>",
"$",
"deviceDetectorClass",
"->",
"getModel",
"(",
")",
",",
"'name'",
"=>",
"$",
"deviceDetectorClass",
"->",
"getBrandName",
"(",
")",
",",
"]",
";",
"}"
] | Returns client device details from client browser
@param class $deviceDetectorClass
@return array | [
"Returns",
"client",
"device",
"details",
"from",
"client",
"browser"
] | 5e4b2c01793ee47ce517be2c799d64abe78d7f8a | https://github.com/danielgp/browser-agent-info/blob/5e4b2c01793ee47ce517be2c799d64abe78d7f8a/source/BrowserAgentInfosByDanielGP.php#L175-L188 | train |
danielgp/browser-agent-info | source/BrowserAgentInfosByDanielGP.php | BrowserAgentInfosByDanielGP.getClientBrowserOperatingSystem | private function getClientBrowserOperatingSystem(\DeviceDetector\DeviceDetector $deviceDetectorClass, $userAgent)
{
$aReturn = $deviceDetectorClass->getOs();
$aReturn['architecture'] = $this->getArchitectureFromUserAgent($userAgent, 'os');
$operatingSystem = new \DeviceDetector\Parser\OperatingSystem();
$osFamily = $operatingSystem->getOsFamily($deviceDetectorClass->getOs('short_name'));
$aReturn['family'] = ($osFamily !== false ? $osFamily : 'Unknown');
ksort($aReturn);
return $aReturn;
} | php | private function getClientBrowserOperatingSystem(\DeviceDetector\DeviceDetector $deviceDetectorClass, $userAgent)
{
$aReturn = $deviceDetectorClass->getOs();
$aReturn['architecture'] = $this->getArchitectureFromUserAgent($userAgent, 'os');
$operatingSystem = new \DeviceDetector\Parser\OperatingSystem();
$osFamily = $operatingSystem->getOsFamily($deviceDetectorClass->getOs('short_name'));
$aReturn['family'] = ($osFamily !== false ? $osFamily : 'Unknown');
ksort($aReturn);
return $aReturn;
} | [
"private",
"function",
"getClientBrowserOperatingSystem",
"(",
"\\",
"DeviceDetector",
"\\",
"DeviceDetector",
"$",
"deviceDetectorClass",
",",
"$",
"userAgent",
")",
"{",
"$",
"aReturn",
"=",
"$",
"deviceDetectorClass",
"->",
"getOs",
"(",
")",
";",
"$",
"aReturn",
"[",
"'architecture'",
"]",
"=",
"$",
"this",
"->",
"getArchitectureFromUserAgent",
"(",
"$",
"userAgent",
",",
"'os'",
")",
";",
"$",
"operatingSystem",
"=",
"new",
"\\",
"DeviceDetector",
"\\",
"Parser",
"\\",
"OperatingSystem",
"(",
")",
";",
"$",
"osFamily",
"=",
"$",
"operatingSystem",
"->",
"getOsFamily",
"(",
"$",
"deviceDetectorClass",
"->",
"getOs",
"(",
"'short_name'",
")",
")",
";",
"$",
"aReturn",
"[",
"'family'",
"]",
"=",
"(",
"$",
"osFamily",
"!==",
"false",
"?",
"$",
"osFamily",
":",
"'Unknown'",
")",
";",
"ksort",
"(",
"$",
"aReturn",
")",
";",
"return",
"$",
"aReturn",
";",
"}"
] | Returns client operating system details from client browser
@param class $deviceDetectorClass
@param string $userAgent
@return array | [
"Returns",
"client",
"operating",
"system",
"details",
"from",
"client",
"browser"
] | 5e4b2c01793ee47ce517be2c799d64abe78d7f8a | https://github.com/danielgp/browser-agent-info/blob/5e4b2c01793ee47ce517be2c799d64abe78d7f8a/source/BrowserAgentInfosByDanielGP.php#L204-L213 | train |
danielgp/browser-agent-info | source/BrowserAgentInfosByDanielGP.php | BrowserAgentInfosByDanielGP.getUserAgentByCommonLib | public function getUserAgentByCommonLib()
{
$this->autoPopulateSuperGlobals();
if (!is_null($this->brServerGlobals->get('ua'))) {
return $this->brServerGlobals->get('ua');
}
return $this->getUserAgentByCommonLibDetection();
} | php | public function getUserAgentByCommonLib()
{
$this->autoPopulateSuperGlobals();
if (!is_null($this->brServerGlobals->get('ua'))) {
return $this->brServerGlobals->get('ua');
}
return $this->getUserAgentByCommonLibDetection();
} | [
"public",
"function",
"getUserAgentByCommonLib",
"(",
")",
"{",
"$",
"this",
"->",
"autoPopulateSuperGlobals",
"(",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"brServerGlobals",
"->",
"get",
"(",
"'ua'",
")",
")",
")",
"{",
"return",
"$",
"this",
"->",
"brServerGlobals",
"->",
"get",
"(",
"'ua'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getUserAgentByCommonLibDetection",
"(",
")",
";",
"}"
] | Captures the user agent
@return string | [
"Captures",
"the",
"user",
"agent"
] | 5e4b2c01793ee47ce517be2c799d64abe78d7f8a | https://github.com/danielgp/browser-agent-info/blob/5e4b2c01793ee47ce517be2c799d64abe78d7f8a/source/BrowserAgentInfosByDanielGP.php#L231-L238 | train |
mosbth/phpmvc-comment | src/Comment/CommentController.php | CommentController.viewAction | public function viewAction()
{
$comments = new \Phpmvc\Comment\CommentsInSession();
$comments->setDI($this->di);
$all = $comments->findAll();
$this->views->add('comment/comments', [
'comments' => $all,
]);
} | php | public function viewAction()
{
$comments = new \Phpmvc\Comment\CommentsInSession();
$comments->setDI($this->di);
$all = $comments->findAll();
$this->views->add('comment/comments', [
'comments' => $all,
]);
} | [
"public",
"function",
"viewAction",
"(",
")",
"{",
"$",
"comments",
"=",
"new",
"\\",
"Phpmvc",
"\\",
"Comment",
"\\",
"CommentsInSession",
"(",
")",
";",
"$",
"comments",
"->",
"setDI",
"(",
"$",
"this",
"->",
"di",
")",
";",
"$",
"all",
"=",
"$",
"comments",
"->",
"findAll",
"(",
")",
";",
"$",
"this",
"->",
"views",
"->",
"add",
"(",
"'comment/comments'",
",",
"[",
"'comments'",
"=>",
"$",
"all",
",",
"]",
")",
";",
"}"
] | View all comments.
@return void | [
"View",
"all",
"comments",
"."
] | ea5c43e8bb3f723d6fb69c892500d26c7390eb37 | https://github.com/mosbth/phpmvc-comment/blob/ea5c43e8bb3f723d6fb69c892500d26c7390eb37/src/Comment/CommentController.php#L20-L30 | train |
mosbth/phpmvc-comment | src/Comment/CommentController.php | CommentController.removeAllAction | public function removeAllAction()
{
$isPosted = $this->request->getPost('doRemoveAll');
if (!$isPosted) {
$this->response->redirect($this->request->getPost('redirect'));
}
$comments = new \Phpmvc\Comment\CommentsInSession();
$comments->setDI($this->di);
$comments->deleteAll();
$this->response->redirect($this->request->getPost('redirect'));
} | php | public function removeAllAction()
{
$isPosted = $this->request->getPost('doRemoveAll');
if (!$isPosted) {
$this->response->redirect($this->request->getPost('redirect'));
}
$comments = new \Phpmvc\Comment\CommentsInSession();
$comments->setDI($this->di);
$comments->deleteAll();
$this->response->redirect($this->request->getPost('redirect'));
} | [
"public",
"function",
"removeAllAction",
"(",
")",
"{",
"$",
"isPosted",
"=",
"$",
"this",
"->",
"request",
"->",
"getPost",
"(",
"'doRemoveAll'",
")",
";",
"if",
"(",
"!",
"$",
"isPosted",
")",
"{",
"$",
"this",
"->",
"response",
"->",
"redirect",
"(",
"$",
"this",
"->",
"request",
"->",
"getPost",
"(",
"'redirect'",
")",
")",
";",
"}",
"$",
"comments",
"=",
"new",
"\\",
"Phpmvc",
"\\",
"Comment",
"\\",
"CommentsInSession",
"(",
")",
";",
"$",
"comments",
"->",
"setDI",
"(",
"$",
"this",
"->",
"di",
")",
";",
"$",
"comments",
"->",
"deleteAll",
"(",
")",
";",
"$",
"this",
"->",
"response",
"->",
"redirect",
"(",
"$",
"this",
"->",
"request",
"->",
"getPost",
"(",
"'redirect'",
")",
")",
";",
"}"
] | Remove all comments.
@return void | [
"Remove",
"all",
"comments",
"."
] | ea5c43e8bb3f723d6fb69c892500d26c7390eb37 | https://github.com/mosbth/phpmvc-comment/blob/ea5c43e8bb3f723d6fb69c892500d26c7390eb37/src/Comment/CommentController.php#L71-L85 | train |
PenoaksDev/Milky-Framework | src/Milky/Http/Routing/UrlGenerator.php | UrlGenerator.addQueryString | protected function addQueryString( $uri, array $parameters )
{
// If the URI has a fragment, we will move it to the end of this URI since it will
// need to come after any query string that may be added to the URL else it is
// not going to be available. We will remove it then append it back on here.
if ( !is_null( $fragment = parse_url( $uri, PHP_URL_FRAGMENT ) ) )
{
$uri = preg_replace( '/#.*/', '', $uri );
}
$uri .= $this->getRouteQueryString( $parameters );
return is_null( $fragment ) ? $uri : $uri . "#{$fragment}";
} | php | protected function addQueryString( $uri, array $parameters )
{
// If the URI has a fragment, we will move it to the end of this URI since it will
// need to come after any query string that may be added to the URL else it is
// not going to be available. We will remove it then append it back on here.
if ( !is_null( $fragment = parse_url( $uri, PHP_URL_FRAGMENT ) ) )
{
$uri = preg_replace( '/#.*/', '', $uri );
}
$uri .= $this->getRouteQueryString( $parameters );
return is_null( $fragment ) ? $uri : $uri . "#{$fragment}";
} | [
"protected",
"function",
"addQueryString",
"(",
"$",
"uri",
",",
"array",
"$",
"parameters",
")",
"{",
"// If the URI has a fragment, we will move it to the end of this URI since it will",
"// need to come after any query string that may be added to the URL else it is",
"// not going to be available. We will remove it then append it back on here.",
"if",
"(",
"!",
"is_null",
"(",
"$",
"fragment",
"=",
"parse_url",
"(",
"$",
"uri",
",",
"PHP_URL_FRAGMENT",
")",
")",
")",
"{",
"$",
"uri",
"=",
"preg_replace",
"(",
"'/#.*/'",
",",
"''",
",",
"$",
"uri",
")",
";",
"}",
"$",
"uri",
".=",
"$",
"this",
"->",
"getRouteQueryString",
"(",
"$",
"parameters",
")",
";",
"return",
"is_null",
"(",
"$",
"fragment",
")",
"?",
"$",
"uri",
":",
"$",
"uri",
".",
"\"#{$fragment}\"",
";",
"}"
] | Add a query string to the URI.
@param string $uri
@param array $parameters
@return mixed|string | [
"Add",
"a",
"query",
"string",
"to",
"the",
"URI",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Http/Routing/UrlGenerator.php#L435-L448 | train |
PenoaksDev/Milky-Framework | src/Milky/Http/Routing/UrlGenerator.php | UrlGenerator.getRouteScheme | protected function getRouteScheme( $route )
{
if ( $route->httpOnly() )
{
return $this->getScheme( false );
}
elseif ( $route->httpsOnly() )
{
return $this->getScheme( true );
}
return $this->getScheme( null );
} | php | protected function getRouteScheme( $route )
{
if ( $route->httpOnly() )
{
return $this->getScheme( false );
}
elseif ( $route->httpsOnly() )
{
return $this->getScheme( true );
}
return $this->getScheme( null );
} | [
"protected",
"function",
"getRouteScheme",
"(",
"$",
"route",
")",
"{",
"if",
"(",
"$",
"route",
"->",
"httpOnly",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getScheme",
"(",
"false",
")",
";",
"}",
"elseif",
"(",
"$",
"route",
"->",
"httpsOnly",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getScheme",
"(",
"true",
")",
";",
"}",
"return",
"$",
"this",
"->",
"getScheme",
"(",
"null",
")",
";",
"}"
] | Get the scheme for the given route.
@param Route $route
@return string | [
"Get",
"the",
"scheme",
"for",
"the",
"given",
"route",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Http/Routing/UrlGenerator.php#L608-L620 | train |
PenoaksDev/Milky-Framework | src/Milky/Http/Routing/UrlGenerator.php | UrlGenerator.isValidUrl | public function isValidUrl( $path )
{
if ( Str::startsWith( $path, ['#', '//', 'mailto:', 'tel:', 'http://', 'https://'] ) )
return true;
return filter_var( $path, FILTER_VALIDATE_URL ) !== false;
} | php | public function isValidUrl( $path )
{
if ( Str::startsWith( $path, ['#', '//', 'mailto:', 'tel:', 'http://', 'https://'] ) )
return true;
return filter_var( $path, FILTER_VALIDATE_URL ) !== false;
} | [
"public",
"function",
"isValidUrl",
"(",
"$",
"path",
")",
"{",
"if",
"(",
"Str",
"::",
"startsWith",
"(",
"$",
"path",
",",
"[",
"'#'",
",",
"'//'",
",",
"'mailto:'",
",",
"'tel:'",
",",
"'http://'",
",",
"'https://'",
"]",
")",
")",
"return",
"true",
";",
"return",
"filter_var",
"(",
"$",
"path",
",",
"FILTER_VALIDATE_URL",
")",
"!==",
"false",
";",
"}"
] | Determine if the given path is a valid URL.
@param string $path
@return bool | [
"Determine",
"if",
"the",
"given",
"path",
"is",
"a",
"valid",
"URL",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Http/Routing/UrlGenerator.php#L693-L699 | train |
xelax90/learning-context-client | src/LearningContextClient/ContextData.php | ContextData.genNonce | protected function genNonce() {
$chars = '1234567890abcdefghijklmnopqrstuvwxyz';
$rnd_string = '';
$num_chars = strlen($chars);
$size = mt_rand(41, 59);
for($i=0; $i<$size; $i++) {
$rnd_string .= $chars[mt_rand(0, $num_chars - 1)];
}
return $rnd_string;
} | php | protected function genNonce() {
$chars = '1234567890abcdefghijklmnopqrstuvwxyz';
$rnd_string = '';
$num_chars = strlen($chars);
$size = mt_rand(41, 59);
for($i=0; $i<$size; $i++) {
$rnd_string .= $chars[mt_rand(0, $num_chars - 1)];
}
return $rnd_string;
} | [
"protected",
"function",
"genNonce",
"(",
")",
"{",
"$",
"chars",
"=",
"'1234567890abcdefghijklmnopqrstuvwxyz'",
";",
"$",
"rnd_string",
"=",
"''",
";",
"$",
"num_chars",
"=",
"strlen",
"(",
"$",
"chars",
")",
";",
"$",
"size",
"=",
"mt_rand",
"(",
"41",
",",
"59",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"size",
";",
"$",
"i",
"++",
")",
"{",
"$",
"rnd_string",
".=",
"$",
"chars",
"[",
"mt_rand",
"(",
"0",
",",
"$",
"num_chars",
"-",
"1",
")",
"]",
";",
"}",
"return",
"$",
"rnd_string",
";",
"}"
] | Generating a random string which will be used as nonce
@return string | [
"Generating",
"a",
"random",
"string",
"which",
"will",
"be",
"used",
"as",
"nonce"
] | f167584eaa3dcfd6f1a48497fcc9c4b98411c601 | https://github.com/xelax90/learning-context-client/blob/f167584eaa3dcfd6f1a48497fcc9c4b98411c601/src/LearningContextClient/ContextData.php#L49-L58 | train |
xelax90/learning-context-client | src/LearningContextClient/ContextData.php | ContextData.genHash | protected function genHash($data, $nonce) {
$token = $this->getConfig()->getStorage()->getAccessToken()->getAccessToken();
return sha1(urlencode($data) . $this->getConfig()->getAppId() . urlencode(sha1($token)) . urlencode($nonce) . $this->getConfig()->getAppSecret() . $token);
} | php | protected function genHash($data, $nonce) {
$token = $this->getConfig()->getStorage()->getAccessToken()->getAccessToken();
return sha1(urlencode($data) . $this->getConfig()->getAppId() . urlencode(sha1($token)) . urlencode($nonce) . $this->getConfig()->getAppSecret() . $token);
} | [
"protected",
"function",
"genHash",
"(",
"$",
"data",
",",
"$",
"nonce",
")",
"{",
"$",
"token",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getStorage",
"(",
")",
"->",
"getAccessToken",
"(",
")",
"->",
"getAccessToken",
"(",
")",
";",
"return",
"sha1",
"(",
"urlencode",
"(",
"$",
"data",
")",
".",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getAppId",
"(",
")",
".",
"urlencode",
"(",
"sha1",
"(",
"$",
"token",
")",
")",
".",
"urlencode",
"(",
"$",
"nonce",
")",
".",
"$",
"this",
"->",
"getConfig",
"(",
")",
"->",
"getAppSecret",
"(",
")",
".",
"$",
"token",
")",
";",
"}"
] | Generating the required hash value from the data, nonce and the other information that is nearly static
@param string $data
@param string $nonce
@return string | [
"Generating",
"the",
"required",
"hash",
"value",
"from",
"the",
"data",
"nonce",
"and",
"the",
"other",
"information",
"that",
"is",
"nearly",
"static"
] | f167584eaa3dcfd6f1a48497fcc9c4b98411c601 | https://github.com/xelax90/learning-context-client/blob/f167584eaa3dcfd6f1a48497fcc9c4b98411c601/src/LearningContextClient/ContextData.php#L66-L69 | train |
smalldb/smalldb-rest | class/Router.php | Router.handle | public function handle($server, $get, $post)
{
$smalldb = null;
// Convert current path to array and to string (result: $path is array, $path_str is string)
$path = trim(isset($server['PATH_INFO']) ? $server['PATH_INFO'] : '', '/');
$path = ($path == '' ? array() : explode('/', $path));
// Get '!action'
$path_tail = end($path);
if (strpos($path_tail, '!') !== FALSE) {
list($path_tail, $action, ) = explode('!', $path_tail, 3); // drop extra '!'
if ($path_tail != '') {
$path[key($path)] = $path_tail;
} else {
unset($path[key($path)]);
}
} else {
$action = null;
}
$id = $path;
// Do something useful
if (!empty($path)) {
if ($action !== null) {
if ($server['REQUEST_METHOD'] == 'POST') {
// Invoke transition
$args = isset($post['args']) ? $post['args'] : [];
return $this->handler->invokeTransition($id, $action, $args);
} else {
// Show transition
return $this->handler->checkTransition($id, $action);
}
} else if (!empty($get)) {
// Get view(s)
return $this->handler->readViews($id, array_keys($get));
} else {
// Get properties
return $this->handler->readState($id);
}
} else if (!empty($get)) {
// Listing
return $this->handler->listing($get);
} else {
// Nothing, just list known types
return $this->handler->getKnownTypes();
}
} | php | public function handle($server, $get, $post)
{
$smalldb = null;
// Convert current path to array and to string (result: $path is array, $path_str is string)
$path = trim(isset($server['PATH_INFO']) ? $server['PATH_INFO'] : '', '/');
$path = ($path == '' ? array() : explode('/', $path));
// Get '!action'
$path_tail = end($path);
if (strpos($path_tail, '!') !== FALSE) {
list($path_tail, $action, ) = explode('!', $path_tail, 3); // drop extra '!'
if ($path_tail != '') {
$path[key($path)] = $path_tail;
} else {
unset($path[key($path)]);
}
} else {
$action = null;
}
$id = $path;
// Do something useful
if (!empty($path)) {
if ($action !== null) {
if ($server['REQUEST_METHOD'] == 'POST') {
// Invoke transition
$args = isset($post['args']) ? $post['args'] : [];
return $this->handler->invokeTransition($id, $action, $args);
} else {
// Show transition
return $this->handler->checkTransition($id, $action);
}
} else if (!empty($get)) {
// Get view(s)
return $this->handler->readViews($id, array_keys($get));
} else {
// Get properties
return $this->handler->readState($id);
}
} else if (!empty($get)) {
// Listing
return $this->handler->listing($get);
} else {
// Nothing, just list known types
return $this->handler->getKnownTypes();
}
} | [
"public",
"function",
"handle",
"(",
"$",
"server",
",",
"$",
"get",
",",
"$",
"post",
")",
"{",
"$",
"smalldb",
"=",
"null",
";",
"// Convert current path to array and to string (result: $path is array, $path_str is string)",
"$",
"path",
"=",
"trim",
"(",
"isset",
"(",
"$",
"server",
"[",
"'PATH_INFO'",
"]",
")",
"?",
"$",
"server",
"[",
"'PATH_INFO'",
"]",
":",
"''",
",",
"'/'",
")",
";",
"$",
"path",
"=",
"(",
"$",
"path",
"==",
"''",
"?",
"array",
"(",
")",
":",
"explode",
"(",
"'/'",
",",
"$",
"path",
")",
")",
";",
"// Get '!action'",
"$",
"path_tail",
"=",
"end",
"(",
"$",
"path",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"path_tail",
",",
"'!'",
")",
"!==",
"FALSE",
")",
"{",
"list",
"(",
"$",
"path_tail",
",",
"$",
"action",
",",
")",
"=",
"explode",
"(",
"'!'",
",",
"$",
"path_tail",
",",
"3",
")",
";",
"// drop extra '!'",
"if",
"(",
"$",
"path_tail",
"!=",
"''",
")",
"{",
"$",
"path",
"[",
"key",
"(",
"$",
"path",
")",
"]",
"=",
"$",
"path_tail",
";",
"}",
"else",
"{",
"unset",
"(",
"$",
"path",
"[",
"key",
"(",
"$",
"path",
")",
"]",
")",
";",
"}",
"}",
"else",
"{",
"$",
"action",
"=",
"null",
";",
"}",
"$",
"id",
"=",
"$",
"path",
";",
"// Do something useful",
"if",
"(",
"!",
"empty",
"(",
"$",
"path",
")",
")",
"{",
"if",
"(",
"$",
"action",
"!==",
"null",
")",
"{",
"if",
"(",
"$",
"server",
"[",
"'REQUEST_METHOD'",
"]",
"==",
"'POST'",
")",
"{",
"// Invoke transition",
"$",
"args",
"=",
"isset",
"(",
"$",
"post",
"[",
"'args'",
"]",
")",
"?",
"$",
"post",
"[",
"'args'",
"]",
":",
"[",
"]",
";",
"return",
"$",
"this",
"->",
"handler",
"->",
"invokeTransition",
"(",
"$",
"id",
",",
"$",
"action",
",",
"$",
"args",
")",
";",
"}",
"else",
"{",
"// Show transition",
"return",
"$",
"this",
"->",
"handler",
"->",
"checkTransition",
"(",
"$",
"id",
",",
"$",
"action",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"get",
")",
")",
"{",
"// Get view(s)",
"return",
"$",
"this",
"->",
"handler",
"->",
"readViews",
"(",
"$",
"id",
",",
"array_keys",
"(",
"$",
"get",
")",
")",
";",
"}",
"else",
"{",
"// Get properties",
"return",
"$",
"this",
"->",
"handler",
"->",
"readState",
"(",
"$",
"id",
")",
";",
"}",
"}",
"else",
"if",
"(",
"!",
"empty",
"(",
"$",
"get",
")",
")",
"{",
"// Listing",
"return",
"$",
"this",
"->",
"handler",
"->",
"listing",
"(",
"$",
"get",
")",
";",
"}",
"else",
"{",
"// Nothing, just list known types",
"return",
"$",
"this",
"->",
"handler",
"->",
"getKnownTypes",
"(",
")",
";",
"}",
"}"
] | Interpret the HTTP request | [
"Interpret",
"the",
"HTTP",
"request"
] | ff393ee39060b4524d41835921e86ed40af006fe | https://github.com/smalldb/smalldb-rest/blob/ff393ee39060b4524d41835921e86ed40af006fe/class/Router.php#L42-L89 | train |
BapCat/Remodel | src/GrammarWrapper.php | GrammarWrapper.compileSelect | public function compileSelect(Builder $query) {
$this->beforeGet($query);
return $this->grammar->compileSelect($query);
} | php | public function compileSelect(Builder $query) {
$this->beforeGet($query);
return $this->grammar->compileSelect($query);
} | [
"public",
"function",
"compileSelect",
"(",
"Builder",
"$",
"query",
")",
"{",
"$",
"this",
"->",
"beforeGet",
"(",
"$",
"query",
")",
";",
"return",
"$",
"this",
"->",
"grammar",
"->",
"compileSelect",
"(",
"$",
"query",
")",
";",
"}"
] | Compile a select query into SQL
@param Builder $query
@return string | [
"Compile",
"a",
"select",
"query",
"into",
"SQL"
] | 80fcdec8bca22b88c5af9a0a93622c796cf3e7b1 | https://github.com/BapCat/Remodel/blob/80fcdec8bca22b88c5af9a0a93622c796cf3e7b1/src/GrammarWrapper.php#L64-L67 | train |
BapCat/Remodel | src/GrammarWrapper.php | GrammarWrapper.compileInsert | public function compileInsert(Builder $query, array $values) {
foreach($values as &$row) {
$this->beforePut($row);
}
unset($row);
$this->remapWheres($query);
$sql = $this->grammar->compileInsert($query, $values);
if($this->replace_into) {
$sql = preg_replace('/^insert into/i', 'replace into', $sql);
$this->replace_into = false;
}
return $sql;
} | php | public function compileInsert(Builder $query, array $values) {
foreach($values as &$row) {
$this->beforePut($row);
}
unset($row);
$this->remapWheres($query);
$sql = $this->grammar->compileInsert($query, $values);
if($this->replace_into) {
$sql = preg_replace('/^insert into/i', 'replace into', $sql);
$this->replace_into = false;
}
return $sql;
} | [
"public",
"function",
"compileInsert",
"(",
"Builder",
"$",
"query",
",",
"array",
"$",
"values",
")",
"{",
"foreach",
"(",
"$",
"values",
"as",
"&",
"$",
"row",
")",
"{",
"$",
"this",
"->",
"beforePut",
"(",
"$",
"row",
")",
";",
"}",
"unset",
"(",
"$",
"row",
")",
";",
"$",
"this",
"->",
"remapWheres",
"(",
"$",
"query",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"grammar",
"->",
"compileInsert",
"(",
"$",
"query",
",",
"$",
"values",
")",
";",
"if",
"(",
"$",
"this",
"->",
"replace_into",
")",
"{",
"$",
"sql",
"=",
"preg_replace",
"(",
"'/^insert into/i'",
",",
"'replace into'",
",",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"replace_into",
"=",
"false",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] | Compile an insert statement into SQL
@param Builder $query
@param mixed[] $values
@return string | [
"Compile",
"an",
"insert",
"statement",
"into",
"SQL"
] | 80fcdec8bca22b88c5af9a0a93622c796cf3e7b1 | https://github.com/BapCat/Remodel/blob/80fcdec8bca22b88c5af9a0a93622c796cf3e7b1/src/GrammarWrapper.php#L88-L104 | train |
BapCat/Remodel | src/GrammarWrapper.php | GrammarWrapper.compileInsertGetId | public function compileInsertGetId(Builder $query, $values, $sequence) {
$this->beforePut($values);
$this->remapWheres($query);
$sql = $this->grammar->compileInsertGetId($query, $values, $sequence);
if($this->replace_into) {
$sql = preg_replace('/^insert into/i', 'replace into', $sql);
$this->replace_into = false;
}
return $sql;
} | php | public function compileInsertGetId(Builder $query, $values, $sequence) {
$this->beforePut($values);
$this->remapWheres($query);
$sql = $this->grammar->compileInsertGetId($query, $values, $sequence);
if($this->replace_into) {
$sql = preg_replace('/^insert into/i', 'replace into', $sql);
$this->replace_into = false;
}
return $sql;
} | [
"public",
"function",
"compileInsertGetId",
"(",
"Builder",
"$",
"query",
",",
"$",
"values",
",",
"$",
"sequence",
")",
"{",
"$",
"this",
"->",
"beforePut",
"(",
"$",
"values",
")",
";",
"$",
"this",
"->",
"remapWheres",
"(",
"$",
"query",
")",
";",
"$",
"sql",
"=",
"$",
"this",
"->",
"grammar",
"->",
"compileInsertGetId",
"(",
"$",
"query",
",",
"$",
"values",
",",
"$",
"sequence",
")",
";",
"if",
"(",
"$",
"this",
"->",
"replace_into",
")",
"{",
"$",
"sql",
"=",
"preg_replace",
"(",
"'/^insert into/i'",
",",
"'replace into'",
",",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"replace_into",
"=",
"false",
";",
"}",
"return",
"$",
"sql",
";",
"}"
] | Compile an insert and get ID statement into SQL
@param Builder $query
@param mixed[] $values
@param string $sequence
@return string | [
"Compile",
"an",
"insert",
"and",
"get",
"ID",
"statement",
"into",
"SQL"
] | 80fcdec8bca22b88c5af9a0a93622c796cf3e7b1 | https://github.com/BapCat/Remodel/blob/80fcdec8bca22b88c5af9a0a93622c796cf3e7b1/src/GrammarWrapper.php#L115-L126 | train |
BapCat/Remodel | src/GrammarWrapper.php | GrammarWrapper.compileUpdate | public function compileUpdate(Builder $query, $values) {
$this->beforePut($values);
$this->remapWheres($query);
return $this->grammar->compileUpdate($query, $values);
} | php | public function compileUpdate(Builder $query, $values) {
$this->beforePut($values);
$this->remapWheres($query);
return $this->grammar->compileUpdate($query, $values);
} | [
"public",
"function",
"compileUpdate",
"(",
"Builder",
"$",
"query",
",",
"$",
"values",
")",
"{",
"$",
"this",
"->",
"beforePut",
"(",
"$",
"values",
")",
";",
"$",
"this",
"->",
"remapWheres",
"(",
"$",
"query",
")",
";",
"return",
"$",
"this",
"->",
"grammar",
"->",
"compileUpdate",
"(",
"$",
"query",
",",
"$",
"values",
")",
";",
"}"
] | Compile an update statement into SQL
@param Builder $query
@param array $values
@return string | [
"Compile",
"an",
"update",
"statement",
"into",
"SQL"
] | 80fcdec8bca22b88c5af9a0a93622c796cf3e7b1 | https://github.com/BapCat/Remodel/blob/80fcdec8bca22b88c5af9a0a93622c796cf3e7b1/src/GrammarWrapper.php#L136-L140 | train |
BapCat/Remodel | src/GrammarWrapper.php | GrammarWrapper.compileDelete | public function compileDelete(Builder $query) {
$this->remapWheres($query);
return $this->grammar->compileDelete($query);
} | php | public function compileDelete(Builder $query) {
$this->remapWheres($query);
return $this->grammar->compileDelete($query);
} | [
"public",
"function",
"compileDelete",
"(",
"Builder",
"$",
"query",
")",
"{",
"$",
"this",
"->",
"remapWheres",
"(",
"$",
"query",
")",
";",
"return",
"$",
"this",
"->",
"grammar",
"->",
"compileDelete",
"(",
"$",
"query",
")",
";",
"}"
] | Compile a delete statement into SQL
@param Builder $query
@return string | [
"Compile",
"a",
"delete",
"statement",
"into",
"SQL"
] | 80fcdec8bca22b88c5af9a0a93622c796cf3e7b1 | https://github.com/BapCat/Remodel/blob/80fcdec8bca22b88c5af9a0a93622c796cf3e7b1/src/GrammarWrapper.php#L149-L152 | train |
Torann/skosh-generator | src/Console/Application.php | Application.registerEvents | private function registerEvents()
{
foreach ($this->getSetting('events', []) as $event => $listeners) {
foreach ($listeners as $listener) {
Event::bind($event, $listener);
}
}
} | php | private function registerEvents()
{
foreach ($this->getSetting('events', []) as $event => $listeners) {
foreach ($listeners as $listener) {
Event::bind($event, $listener);
}
}
} | [
"private",
"function",
"registerEvents",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"getSetting",
"(",
"'events'",
",",
"[",
"]",
")",
"as",
"$",
"event",
"=>",
"$",
"listeners",
")",
"{",
"foreach",
"(",
"$",
"listeners",
"as",
"$",
"listener",
")",
"{",
"Event",
"::",
"bind",
"(",
"$",
"event",
",",
"$",
"listener",
")",
";",
"}",
"}",
"}"
] | Register custom events. | [
"Register",
"custom",
"events",
"."
] | ea60e037d92398d7c146eb2349735d5692e3c48c | https://github.com/Torann/skosh-generator/blob/ea60e037d92398d7c146eb2349735d5692e3c48c/src/Console/Application.php#L87-L94 | train |
mossphp/moss-storage | Moss/Storage/Query/AbstractQuery.php | AbstractQuery.resetBinds | protected function resetBinds($prefix = null)
{
if ($prefix === null) {
$this->builder->setParameters([]);
return;
}
$params = (array) $this->builder->getParameters();
$types = (array) $this->builder->getParameterTypes();
foreach (array_keys($params) as $key) {
if (strpos($key, $prefix) === 1) {
unset($params[$key], $types[$key]);
}
}
$this->builder->setParameters($params, $types);
} | php | protected function resetBinds($prefix = null)
{
if ($prefix === null) {
$this->builder->setParameters([]);
return;
}
$params = (array) $this->builder->getParameters();
$types = (array) $this->builder->getParameterTypes();
foreach (array_keys($params) as $key) {
if (strpos($key, $prefix) === 1) {
unset($params[$key], $types[$key]);
}
}
$this->builder->setParameters($params, $types);
} | [
"protected",
"function",
"resetBinds",
"(",
"$",
"prefix",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"prefix",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"builder",
"->",
"setParameters",
"(",
"[",
"]",
")",
";",
"return",
";",
"}",
"$",
"params",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"builder",
"->",
"getParameters",
"(",
")",
";",
"$",
"types",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"builder",
"->",
"getParameterTypes",
"(",
")",
";",
"foreach",
"(",
"array_keys",
"(",
"$",
"params",
")",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"key",
",",
"$",
"prefix",
")",
"===",
"1",
")",
"{",
"unset",
"(",
"$",
"params",
"[",
"$",
"key",
"]",
",",
"$",
"types",
"[",
"$",
"key",
"]",
")",
";",
"}",
"}",
"$",
"this",
"->",
"builder",
"->",
"setParameters",
"(",
"$",
"params",
",",
"$",
"types",
")",
";",
"}"
] | Removes bound values by their prefix
If prefix is null - clears all bound values
@param null|string $prefix | [
"Removes",
"bound",
"values",
"by",
"their",
"prefix",
"If",
"prefix",
"is",
"null",
"-",
"clears",
"all",
"bound",
"values"
] | 0d123e7ae6bbfce1e2a18e73bf70997277b430c1 | https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/AbstractQuery.php#L127-L145 | train |
PenoaksDev/Milky-Framework | src/Milky/Database/Schema/Blueprint.php | Blueprint.addFluentIndexes | protected function addFluentIndexes()
{
foreach ( $this->columns as $column )
{
foreach ( ['primary', 'unique', 'index'] as $index )
{
// If the index has been specified on the given column, but is simply
// equal to "true" (boolean), no name has been specified for this
// index, so we will simply call the index methods without one.
if ( $column->$index === true )
{
$this->$index( $column->name );
continue 2;
}
// If the index has been specified on the column and it is something
// other than boolean true, we will assume a name was provided on
// the index specification, and pass in the name to the method.
elseif ( isset( $column->$index ) )
{
$this->$index( $column->name, $column->$index );
continue 2;
}
}
}
} | php | protected function addFluentIndexes()
{
foreach ( $this->columns as $column )
{
foreach ( ['primary', 'unique', 'index'] as $index )
{
// If the index has been specified on the given column, but is simply
// equal to "true" (boolean), no name has been specified for this
// index, so we will simply call the index methods without one.
if ( $column->$index === true )
{
$this->$index( $column->name );
continue 2;
}
// If the index has been specified on the column and it is something
// other than boolean true, we will assume a name was provided on
// the index specification, and pass in the name to the method.
elseif ( isset( $column->$index ) )
{
$this->$index( $column->name, $column->$index );
continue 2;
}
}
}
} | [
"protected",
"function",
"addFluentIndexes",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"columns",
"as",
"$",
"column",
")",
"{",
"foreach",
"(",
"[",
"'primary'",
",",
"'unique'",
",",
"'index'",
"]",
"as",
"$",
"index",
")",
"{",
"// If the index has been specified on the given column, but is simply",
"// equal to \"true\" (boolean), no name has been specified for this",
"// index, so we will simply call the index methods without one.",
"if",
"(",
"$",
"column",
"->",
"$",
"index",
"===",
"true",
")",
"{",
"$",
"this",
"->",
"$",
"index",
"(",
"$",
"column",
"->",
"name",
")",
";",
"continue",
"2",
";",
"}",
"// If the index has been specified on the column and it is something",
"// other than boolean true, we will assume a name was provided on",
"// the index specification, and pass in the name to the method.",
"elseif",
"(",
"isset",
"(",
"$",
"column",
"->",
"$",
"index",
")",
")",
"{",
"$",
"this",
"->",
"$",
"index",
"(",
"$",
"column",
"->",
"name",
",",
"$",
"column",
"->",
"$",
"index",
")",
";",
"continue",
"2",
";",
"}",
"}",
"}",
"}"
] | Add the index commands fluently specified on columns.
@return void | [
"Add",
"the",
"index",
"commands",
"fluently",
"specified",
"on",
"columns",
"."
] | 8afd7156610a70371aa5b1df50b8a212bf7b142c | https://github.com/PenoaksDev/Milky-Framework/blob/8afd7156610a70371aa5b1df50b8a212bf7b142c/src/Milky/Database/Schema/Blueprint.php#L144-L171 | train |
DreadLabs/VantomasWebsite | src/CodeSnippet/SyntaxHighlighterBrush.php | SyntaxHighlighterBrush.fromIdentifierOrAlias | public static function fromIdentifierOrAlias($identifierOrAlias)
{
$alias = $identifierOrAlias;
$identifier = 'Plain';
if (isset(self::$aliasToIdentifierMap[$identifierOrAlias])) {
$identifier = self::$aliasToIdentifierMap[$identifierOrAlias];
}
return new static($alias, $identifier);
} | php | public static function fromIdentifierOrAlias($identifierOrAlias)
{
$alias = $identifierOrAlias;
$identifier = 'Plain';
if (isset(self::$aliasToIdentifierMap[$identifierOrAlias])) {
$identifier = self::$aliasToIdentifierMap[$identifierOrAlias];
}
return new static($alias, $identifier);
} | [
"public",
"static",
"function",
"fromIdentifierOrAlias",
"(",
"$",
"identifierOrAlias",
")",
"{",
"$",
"alias",
"=",
"$",
"identifierOrAlias",
";",
"$",
"identifier",
"=",
"'Plain'",
";",
"if",
"(",
"isset",
"(",
"self",
"::",
"$",
"aliasToIdentifierMap",
"[",
"$",
"identifierOrAlias",
"]",
")",
")",
"{",
"$",
"identifier",
"=",
"self",
"::",
"$",
"aliasToIdentifierMap",
"[",
"$",
"identifierOrAlias",
"]",
";",
"}",
"return",
"new",
"static",
"(",
"$",
"alias",
",",
"$",
"identifier",
")",
";",
"}"
] | Instantiates the brush by identifier or alias.
@param string $identifierOrAlias
@return BrushInterface | [
"Instantiates",
"the",
"brush",
"by",
"identifier",
"or",
"alias",
"."
] | 7f85f2b45bdf5ed9fa9d320c805c416bf99cd668 | https://github.com/DreadLabs/VantomasWebsite/blob/7f85f2b45bdf5ed9fa9d320c805c416bf99cd668/src/CodeSnippet/SyntaxHighlighterBrush.php#L74-L84 | train |
nails/module-blog | admin/controllers/Settings.php | Settings.permissions | public static function permissions(): array
{
$permissions = parent::permissions();
// Fetch the blogs, each blog should have its own permission
$ci =& get_instance();
$ci->load->model('blog/blog_model');
$blogs = $ci->blog_model->getAll();
$out = array();
if (!empty($blogs)) {
foreach ($blogs as $blog) {
$permissions[$blog->id . ':update'] = $blog->label . ': Can update settings';
}
}
return $permissions;
} | php | public static function permissions(): array
{
$permissions = parent::permissions();
// Fetch the blogs, each blog should have its own permission
$ci =& get_instance();
$ci->load->model('blog/blog_model');
$blogs = $ci->blog_model->getAll();
$out = array();
if (!empty($blogs)) {
foreach ($blogs as $blog) {
$permissions[$blog->id . ':update'] = $blog->label . ': Can update settings';
}
}
return $permissions;
} | [
"public",
"static",
"function",
"permissions",
"(",
")",
":",
"array",
"{",
"$",
"permissions",
"=",
"parent",
"::",
"permissions",
"(",
")",
";",
"// Fetch the blogs, each blog should have its own permission",
"$",
"ci",
"=",
"&",
"get_instance",
"(",
")",
";",
"$",
"ci",
"->",
"load",
"->",
"model",
"(",
"'blog/blog_model'",
")",
";",
"$",
"blogs",
"=",
"$",
"ci",
"->",
"blog_model",
"->",
"getAll",
"(",
")",
";",
"$",
"out",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"blogs",
")",
")",
"{",
"foreach",
"(",
"$",
"blogs",
"as",
"$",
"blog",
")",
"{",
"$",
"permissions",
"[",
"$",
"blog",
"->",
"id",
".",
"':update'",
"]",
"=",
"$",
"blog",
"->",
"label",
".",
"': Can update settings'",
";",
"}",
"}",
"return",
"$",
"permissions",
";",
"}"
] | Returns an array of permissions which can be configured for the user
@return array | [
"Returns",
"an",
"array",
"of",
"permissions",
"which",
"can",
"be",
"configured",
"for",
"the",
"user"
] | 7b369c5209f4343fff7c7e2a22c237d5a95c8c24 | https://github.com/nails/module-blog/blob/7b369c5209f4343fff7c7e2a22c237d5a95c8c24/admin/controllers/Settings.php#L52-L70 | train |
porkchopsandwiches/doctrine-utilities | lib/src/PorkChopSandwiches/Doctrine/Utilities/EntityManager/Generator.php | Generator.manufacture | static public function manufacture ($conn, Cache $cache_driver, Reader $annotation_reader, array $entity_paths, $autogenerate_strategy = false, $ensure_production_settings = false, $doctrine_annotations_file_path = self::DOCTRINE_ANNOTATIONS_FILE_PATH, $proxy_namespace = "Doctrine\\Proxies", $proxy_dir = "/lib/src/Doctrine/Proxies") {
# Let the IDE know that the annotation reader is of the expected type
/** @var AnnotationReader $annotation_reader */
$config = new Configuration();
# Set up the Metadata Cache implementation -- this caches the scraped Metadata Configuration (i.e. the Annotations/XML/YAML) values
# !!!WARNING!!! If using MemCache - Doctrine does NOT throw an error if it can't connect to MemCache, it just silently goes on without a cache.
# Always check to see if the cache is being populated ($cache_driver -> getStats())
$config -> setMetadataCacheImpl($cache_driver);
# Register the Annotation handle file
# See http://doctrine-common.readthedocs.org/en/latest/reference/annotations.html for details
AnnotationRegistry::registerFile($doctrine_annotations_file_path);
# Set up the Metadata Driver implementation -- this tells Doctrine where to find the Annotated PHP classes to form Entities
$config -> setMetadataDriverImpl(new AnnotationDriver($annotation_reader, $entity_paths));
# Set up the Query Cache implementation -- this caches DQL query transformations into plain SQL
$config -> setQueryCacheImpl($cache_driver);
# Set up the Proxy directory where Doctrine will store Proxy classes, and the namespace they will have
$config -> setProxyDir($proxy_dir);
$config -> setProxyNamespace($proxy_namespace);
# Configure proxy generation
$config -> setAutoGenerateProxyClasses($autogenerate_strategy);
# Test production settings if desired
if ($ensure_production_settings) {
$config -> ensureProductionSettings();
}
# If connection is just the raw details for the moment, generate the real deal now
if (is_array($conn)) {
$conn = DriverManager::getConnection($conn, $config);
}
# Create the Entity Manager with the DB config details and ORM Config values
$em = EntityManager::create($conn, $config);
# Define our handy-dandy UTC Date Time column type
if (!Type::hasType("utcdatetime")) {
Type::addType("utcdatetime", "PorkChopSandwiches\\Doctrine\\Utilities\\Types\\UTCDateTimeType");
$em -> getConnection() -> getDatabasePlatform() -> registerDoctrineTypeMapping("datetime", "utcdatetime");
}
return $em;
} | php | static public function manufacture ($conn, Cache $cache_driver, Reader $annotation_reader, array $entity_paths, $autogenerate_strategy = false, $ensure_production_settings = false, $doctrine_annotations_file_path = self::DOCTRINE_ANNOTATIONS_FILE_PATH, $proxy_namespace = "Doctrine\\Proxies", $proxy_dir = "/lib/src/Doctrine/Proxies") {
# Let the IDE know that the annotation reader is of the expected type
/** @var AnnotationReader $annotation_reader */
$config = new Configuration();
# Set up the Metadata Cache implementation -- this caches the scraped Metadata Configuration (i.e. the Annotations/XML/YAML) values
# !!!WARNING!!! If using MemCache - Doctrine does NOT throw an error if it can't connect to MemCache, it just silently goes on without a cache.
# Always check to see if the cache is being populated ($cache_driver -> getStats())
$config -> setMetadataCacheImpl($cache_driver);
# Register the Annotation handle file
# See http://doctrine-common.readthedocs.org/en/latest/reference/annotations.html for details
AnnotationRegistry::registerFile($doctrine_annotations_file_path);
# Set up the Metadata Driver implementation -- this tells Doctrine where to find the Annotated PHP classes to form Entities
$config -> setMetadataDriverImpl(new AnnotationDriver($annotation_reader, $entity_paths));
# Set up the Query Cache implementation -- this caches DQL query transformations into plain SQL
$config -> setQueryCacheImpl($cache_driver);
# Set up the Proxy directory where Doctrine will store Proxy classes, and the namespace they will have
$config -> setProxyDir($proxy_dir);
$config -> setProxyNamespace($proxy_namespace);
# Configure proxy generation
$config -> setAutoGenerateProxyClasses($autogenerate_strategy);
# Test production settings if desired
if ($ensure_production_settings) {
$config -> ensureProductionSettings();
}
# If connection is just the raw details for the moment, generate the real deal now
if (is_array($conn)) {
$conn = DriverManager::getConnection($conn, $config);
}
# Create the Entity Manager with the DB config details and ORM Config values
$em = EntityManager::create($conn, $config);
# Define our handy-dandy UTC Date Time column type
if (!Type::hasType("utcdatetime")) {
Type::addType("utcdatetime", "PorkChopSandwiches\\Doctrine\\Utilities\\Types\\UTCDateTimeType");
$em -> getConnection() -> getDatabasePlatform() -> registerDoctrineTypeMapping("datetime", "utcdatetime");
}
return $em;
} | [
"static",
"public",
"function",
"manufacture",
"(",
"$",
"conn",
",",
"Cache",
"$",
"cache_driver",
",",
"Reader",
"$",
"annotation_reader",
",",
"array",
"$",
"entity_paths",
",",
"$",
"autogenerate_strategy",
"=",
"false",
",",
"$",
"ensure_production_settings",
"=",
"false",
",",
"$",
"doctrine_annotations_file_path",
"=",
"self",
"::",
"DOCTRINE_ANNOTATIONS_FILE_PATH",
",",
"$",
"proxy_namespace",
"=",
"\"Doctrine\\\\Proxies\"",
",",
"$",
"proxy_dir",
"=",
"\"/lib/src/Doctrine/Proxies\"",
")",
"{",
"# Let the IDE know that the annotation reader is of the expected type",
"/** @var AnnotationReader $annotation_reader */",
"$",
"config",
"=",
"new",
"Configuration",
"(",
")",
";",
"# Set up the Metadata Cache implementation -- this caches the scraped Metadata Configuration (i.e. the Annotations/XML/YAML) values",
"# !!!WARNING!!! If using MemCache - Doctrine does NOT throw an error if it can't connect to MemCache, it just silently goes on without a cache.",
"# Always check to see if the cache is being populated ($cache_driver -> getStats())",
"$",
"config",
"->",
"setMetadataCacheImpl",
"(",
"$",
"cache_driver",
")",
";",
"# Register the Annotation handle file",
"# See http://doctrine-common.readthedocs.org/en/latest/reference/annotations.html for details",
"AnnotationRegistry",
"::",
"registerFile",
"(",
"$",
"doctrine_annotations_file_path",
")",
";",
"# Set up the Metadata Driver implementation -- this tells Doctrine where to find the Annotated PHP classes to form Entities",
"$",
"config",
"->",
"setMetadataDriverImpl",
"(",
"new",
"AnnotationDriver",
"(",
"$",
"annotation_reader",
",",
"$",
"entity_paths",
")",
")",
";",
"# Set up the Query Cache implementation -- this caches DQL query transformations into plain SQL",
"$",
"config",
"->",
"setQueryCacheImpl",
"(",
"$",
"cache_driver",
")",
";",
"# Set up the Proxy directory where Doctrine will store Proxy classes, and the namespace they will have",
"$",
"config",
"->",
"setProxyDir",
"(",
"$",
"proxy_dir",
")",
";",
"$",
"config",
"->",
"setProxyNamespace",
"(",
"$",
"proxy_namespace",
")",
";",
"# Configure proxy generation",
"$",
"config",
"->",
"setAutoGenerateProxyClasses",
"(",
"$",
"autogenerate_strategy",
")",
";",
"# Test production settings if desired",
"if",
"(",
"$",
"ensure_production_settings",
")",
"{",
"$",
"config",
"->",
"ensureProductionSettings",
"(",
")",
";",
"}",
"# If connection is just the raw details for the moment, generate the real deal now",
"if",
"(",
"is_array",
"(",
"$",
"conn",
")",
")",
"{",
"$",
"conn",
"=",
"DriverManager",
"::",
"getConnection",
"(",
"$",
"conn",
",",
"$",
"config",
")",
";",
"}",
"# Create the Entity Manager with the DB config details and ORM Config values",
"$",
"em",
"=",
"EntityManager",
"::",
"create",
"(",
"$",
"conn",
",",
"$",
"config",
")",
";",
"# Define our handy-dandy UTC Date Time column type",
"if",
"(",
"!",
"Type",
"::",
"hasType",
"(",
"\"utcdatetime\"",
")",
")",
"{",
"Type",
"::",
"addType",
"(",
"\"utcdatetime\"",
",",
"\"PorkChopSandwiches\\\\Doctrine\\\\Utilities\\\\Types\\\\UTCDateTimeType\"",
")",
";",
"$",
"em",
"->",
"getConnection",
"(",
")",
"->",
"getDatabasePlatform",
"(",
")",
"->",
"registerDoctrineTypeMapping",
"(",
"\"datetime\"",
",",
"\"utcdatetime\"",
")",
";",
"}",
"return",
"$",
"em",
";",
"}"
] | Manufactures an EntityManager instance using the passed configuration.
@param array|Connection $conn
@param Cache $cache_driver
@param Reader $annotation_reader
@param array $entity_paths
@param boolean [$autogenerate_strategy]
@param boolean [$ensure_production_settings]
@param string [$doctrine_annotations_file_path]
@param string [$proxy_namespace]
@param string [$proxy_dir]
@throws Exception
@return EntityManager | [
"Manufactures",
"an",
"EntityManager",
"instance",
"using",
"the",
"passed",
"configuration",
"."
] | cc5e4268bac36c68af62d69d9512a0dd01ee310f | https://github.com/porkchopsandwiches/doctrine-utilities/blob/cc5e4268bac36c68af62d69d9512a0dd01ee310f/lib/src/PorkChopSandwiches/Doctrine/Utilities/EntityManager/Generator.php#L45-L93 | train |
azhai/code-refactor | src/CodeRefactor/CodeBlock.php | CodeBlock.insertStmts | public function insertStmts(array $stmts, $offset = 0, $remove = 0)
{
if (false === $offset) {
$offset = count($this->stmts);
} elseif (false === $remove) {
$remove = count($this->stmts);
}
array_splice($this->stmts, $offset, $remove, $stmts);
return $this;
} | php | public function insertStmts(array $stmts, $offset = 0, $remove = 0)
{
if (false === $offset) {
$offset = count($this->stmts);
} elseif (false === $remove) {
$remove = count($this->stmts);
}
array_splice($this->stmts, $offset, $remove, $stmts);
return $this;
} | [
"public",
"function",
"insertStmts",
"(",
"array",
"$",
"stmts",
",",
"$",
"offset",
"=",
"0",
",",
"$",
"remove",
"=",
"0",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"offset",
")",
"{",
"$",
"offset",
"=",
"count",
"(",
"$",
"this",
"->",
"stmts",
")",
";",
"}",
"elseif",
"(",
"false",
"===",
"$",
"remove",
")",
"{",
"$",
"remove",
"=",
"count",
"(",
"$",
"this",
"->",
"stmts",
")",
";",
"}",
"array_splice",
"(",
"$",
"this",
"->",
"stmts",
",",
"$",
"offset",
",",
"$",
"remove",
",",
"$",
"stmts",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Insert or replace some statements. | [
"Insert",
"or",
"replace",
"some",
"statements",
"."
] | cddb437d72f8239957daeba8211dda5e9366d6ca | https://github.com/azhai/code-refactor/blob/cddb437d72f8239957daeba8211dda5e9366d6ca/src/CodeRefactor/CodeBlock.php#L42-L51 | train |
bseddon/XPath20 | XPath2NodeIterator/XPath2NodeIteratorDebugView.php | XPath2NodeIteratorDebugView.getItems | public function getItems()
{
/**
* @var array $res
*/
$res = array();
foreach ( $this->iter as /** @var XPathItem $item */ $item )
{
if ( count( $res ) == 10)
break;
$res[] = $item->CloneInstance();
}
return $res;
} | php | public function getItems()
{
/**
* @var array $res
*/
$res = array();
foreach ( $this->iter as /** @var XPathItem $item */ $item )
{
if ( count( $res ) == 10)
break;
$res[] = $item->CloneInstance();
}
return $res;
} | [
"public",
"function",
"getItems",
"(",
")",
"{",
"/**\r\n\t\t * @var array $res\r\n\t\t */",
"$",
"res",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"iter",
"as",
"/** @var XPathItem $item */",
"$",
"item",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"res",
")",
"==",
"10",
")",
"break",
";",
"$",
"res",
"[",
"]",
"=",
"$",
"item",
"->",
"CloneInstance",
"(",
")",
";",
"}",
"return",
"$",
"res",
";",
"}"
] | Return the first 10 items of the iterator
@var XPathItem[] $Items | [
"Return",
"the",
"first",
"10",
"items",
"of",
"the",
"iterator"
] | 69882b6efffaa5470a819d5fdd2f6473ddeb046d | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/XPath2NodeIterator/XPath2NodeIteratorDebugView.php#L60-L75 | train |
CroudTech/laravel-repositories | src/BaseRepository.php | BaseRepository.findBy | public function findBy($field, $value)
{
$model_class = $this->getModelName();
return $model_class::where($field, $value)->first();
} | php | public function findBy($field, $value)
{
$model_class = $this->getModelName();
return $model_class::where($field, $value)->first();
} | [
"public",
"function",
"findBy",
"(",
"$",
"field",
",",
"$",
"value",
")",
"{",
"$",
"model_class",
"=",
"$",
"this",
"->",
"getModelName",
"(",
")",
";",
"return",
"$",
"model_class",
"::",
"where",
"(",
"$",
"field",
",",
"$",
"value",
")",
"->",
"first",
"(",
")",
";",
"}"
] | Find a record by a custom field
@method findBy
@param string $field The field to search by
@param mixed $value The field value
@return Model | null | [
"Find",
"a",
"record",
"by",
"a",
"custom",
"field"
] | 3146285be911728fe7b00cf27d2494ad22b773dc | https://github.com/CroudTech/laravel-repositories/blob/3146285be911728fe7b00cf27d2494ad22b773dc/src/BaseRepository.php#L115-L119 | train |
CroudTech/laravel-repositories | src/BaseRepository.php | BaseRepository.create | public function create(array $data) : Model
{
$model_class = $this->getModelName();
return $this->postCreate($data, $model_class::create($this->preCreate($this->parseData($data))));
} | php | public function create(array $data) : Model
{
$model_class = $this->getModelName();
return $this->postCreate($data, $model_class::create($this->preCreate($this->parseData($data))));
} | [
"public",
"function",
"create",
"(",
"array",
"$",
"data",
")",
":",
"Model",
"{",
"$",
"model_class",
"=",
"$",
"this",
"->",
"getModelName",
"(",
")",
";",
"return",
"$",
"this",
"->",
"postCreate",
"(",
"$",
"data",
",",
"$",
"model_class",
"::",
"create",
"(",
"$",
"this",
"->",
"preCreate",
"(",
"$",
"this",
"->",
"parseData",
"(",
"$",
"data",
")",
")",
")",
")",
";",
"}"
] | Create and return the model object
@method create
@param array $data array
@return Model | [
"Create",
"and",
"return",
"the",
"model",
"object"
] | 3146285be911728fe7b00cf27d2494ad22b773dc | https://github.com/CroudTech/laravel-repositories/blob/3146285be911728fe7b00cf27d2494ad22b773dc/src/BaseRepository.php#L128-L132 | train |
CroudTech/laravel-repositories | src/BaseRepository.php | BaseRepository.delete | public function delete($id)
{
if ($record = $this->find($id)) {
if ($this->preDelete($id, $record)) {
return $this->postDelete($id, $record->delete(), $record);
}
} else {
$this->throwModelNotFoundException($id);
}
} | php | public function delete($id)
{
if ($record = $this->find($id)) {
if ($this->preDelete($id, $record)) {
return $this->postDelete($id, $record->delete(), $record);
}
} else {
$this->throwModelNotFoundException($id);
}
} | [
"public",
"function",
"delete",
"(",
"$",
"id",
")",
"{",
"if",
"(",
"$",
"record",
"=",
"$",
"this",
"->",
"find",
"(",
"$",
"id",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"preDelete",
"(",
"$",
"id",
",",
"$",
"record",
")",
")",
"{",
"return",
"$",
"this",
"->",
"postDelete",
"(",
"$",
"id",
",",
"$",
"record",
"->",
"delete",
"(",
")",
",",
"$",
"record",
")",
";",
"}",
"}",
"else",
"{",
"$",
"this",
"->",
"throwModelNotFoundException",
"(",
"$",
"id",
")",
";",
"}",
"}"
] | Delete a record by ID
@method delete
@param integer $id The ID of the record
@return boolean | [
"Delete",
"a",
"record",
"by",
"ID"
] | 3146285be911728fe7b00cf27d2494ad22b773dc | https://github.com/CroudTech/laravel-repositories/blob/3146285be911728fe7b00cf27d2494ad22b773dc/src/BaseRepository.php#L208-L217 | train |
CroudTech/laravel-repositories | src/BaseRepository.php | BaseRepository.parseData | public function parseData(array $data) : array
{
if ($this->getTransformer() instanceof RequestTransformerContract) {
return $this->getTransformer()->transformRequestData($data);
}
return $data;
} | php | public function parseData(array $data) : array
{
if ($this->getTransformer() instanceof RequestTransformerContract) {
return $this->getTransformer()->transformRequestData($data);
}
return $data;
} | [
"public",
"function",
"parseData",
"(",
"array",
"$",
"data",
")",
":",
"array",
"{",
"if",
"(",
"$",
"this",
"->",
"getTransformer",
"(",
")",
"instanceof",
"RequestTransformerContract",
")",
"{",
"return",
"$",
"this",
"->",
"getTransformer",
"(",
")",
"->",
"transformRequestData",
"(",
"$",
"data",
")",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | Parse the data using the 'request' method of the transformer if it exists
@method parseData
@param array $data The data to parse
@return array The parsed data | [
"Parse",
"the",
"data",
"using",
"the",
"request",
"method",
"of",
"the",
"transformer",
"if",
"it",
"exists"
] | 3146285be911728fe7b00cf27d2494ad22b773dc | https://github.com/CroudTech/laravel-repositories/blob/3146285be911728fe7b00cf27d2494ad22b773dc/src/BaseRepository.php#L290-L297 | train |
CroudTech/laravel-repositories | src/BaseRepository.php | BaseRepository.transformItem | public function transformItem(Model $item, $includes = [], TransformerContract $transformer = null)
{
$this->fractal_manager->parseIncludes($includes);
$transformer = is_null($transformer) ? $this->getTransformer() : $transformer;
$resource = new Item($item, $transformer, $this->getModelName());
return $this->fractal_manager->createData($resource)->toArray();
} | php | public function transformItem(Model $item, $includes = [], TransformerContract $transformer = null)
{
$this->fractal_manager->parseIncludes($includes);
$transformer = is_null($transformer) ? $this->getTransformer() : $transformer;
$resource = new Item($item, $transformer, $this->getModelName());
return $this->fractal_manager->createData($resource)->toArray();
} | [
"public",
"function",
"transformItem",
"(",
"Model",
"$",
"item",
",",
"$",
"includes",
"=",
"[",
"]",
",",
"TransformerContract",
"$",
"transformer",
"=",
"null",
")",
"{",
"$",
"this",
"->",
"fractal_manager",
"->",
"parseIncludes",
"(",
"$",
"includes",
")",
";",
"$",
"transformer",
"=",
"is_null",
"(",
"$",
"transformer",
")",
"?",
"$",
"this",
"->",
"getTransformer",
"(",
")",
":",
"$",
"transformer",
";",
"$",
"resource",
"=",
"new",
"Item",
"(",
"$",
"item",
",",
"$",
"transformer",
",",
"$",
"this",
"->",
"getModelName",
"(",
")",
")",
";",
"return",
"$",
"this",
"->",
"fractal_manager",
"->",
"createData",
"(",
"$",
"resource",
")",
"->",
"toArray",
"(",
")",
";",
"}"
] | Pass a model through the transformer
@method transformItem
@param Model $item The model to transform
@param array $includes Any transformer includes to use
@param TransformerContract $transformer Override the transformer
@return array | [
"Pass",
"a",
"model",
"through",
"the",
"transformer"
] | 3146285be911728fe7b00cf27d2494ad22b773dc | https://github.com/CroudTech/laravel-repositories/blob/3146285be911728fe7b00cf27d2494ad22b773dc/src/BaseRepository.php#L340-L346 | train |
CroudTech/laravel-repositories | src/BaseRepository.php | BaseRepository.newQuery | public function newQuery() : QueryBuilder
{
$model = $this->container->make($this->getModelName());
if (!$model instanceof Model) {
throw new RepositoryException("Class {$this->model()} must be an instance of " . Model::class);
}
return $model->newQuery();
} | php | public function newQuery() : QueryBuilder
{
$model = $this->container->make($this->getModelName());
if (!$model instanceof Model) {
throw new RepositoryException("Class {$this->model()} must be an instance of " . Model::class);
}
return $model->newQuery();
} | [
"public",
"function",
"newQuery",
"(",
")",
":",
"QueryBuilder",
"{",
"$",
"model",
"=",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"$",
"this",
"->",
"getModelName",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"model",
"instanceof",
"Model",
")",
"{",
"throw",
"new",
"RepositoryException",
"(",
"\"Class {$this->model()} must be an instance of \"",
".",
"Model",
"::",
"class",
")",
";",
"}",
"return",
"$",
"model",
"->",
"newQuery",
"(",
")",
";",
"}"
] | Create a new query instance
@method newQuery
@return QueryBuilder [description] | [
"Create",
"a",
"new",
"query",
"instance"
] | 3146285be911728fe7b00cf27d2494ad22b773dc | https://github.com/CroudTech/laravel-repositories/blob/3146285be911728fe7b00cf27d2494ad22b773dc/src/BaseRepository.php#L387-L396 | train |
CroudTech/laravel-repositories | src/BaseRepository.php | BaseRepository.throwModelNotFoundException | protected function throwModelNotFoundException($id)
{
throw new ModelNotFoundException('Model not found for ID ' . $id . ' on table ' . $this->container->make($this->getModelName())->getTable());
} | php | protected function throwModelNotFoundException($id)
{
throw new ModelNotFoundException('Model not found for ID ' . $id . ' on table ' . $this->container->make($this->getModelName())->getTable());
} | [
"protected",
"function",
"throwModelNotFoundException",
"(",
"$",
"id",
")",
"{",
"throw",
"new",
"ModelNotFoundException",
"(",
"'Model not found for ID '",
".",
"$",
"id",
".",
"' on table '",
".",
"$",
"this",
"->",
"container",
"->",
"make",
"(",
"$",
"this",
"->",
"getModelName",
"(",
")",
")",
"->",
"getTable",
"(",
")",
")",
";",
"}"
] | Throw an exception when a model is not found
@method throwModelNotFoundException
@param integer $id | [
"Throw",
"an",
"exception",
"when",
"a",
"model",
"is",
"not",
"found"
] | 3146285be911728fe7b00cf27d2494ad22b773dc | https://github.com/CroudTech/laravel-repositories/blob/3146285be911728fe7b00cf27d2494ad22b773dc/src/BaseRepository.php#L404-L407 | train |
MindyPHP/OrmNestedSet | TreeQuerySet.php | TreeQuerySet.parent | public function parent()
{
return $this->filter([
'lft__lt' => $this->getModel()->lft,
'rgt__gt' => $this->getModel()->rgt,
'level' => $this->getModel()->level - 1,
'root' => $this->getModel()->root,
]);
} | php | public function parent()
{
return $this->filter([
'lft__lt' => $this->getModel()->lft,
'rgt__gt' => $this->getModel()->rgt,
'level' => $this->getModel()->level - 1,
'root' => $this->getModel()->root,
]);
} | [
"public",
"function",
"parent",
"(",
")",
"{",
"return",
"$",
"this",
"->",
"filter",
"(",
"[",
"'lft__lt'",
"=>",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"lft",
",",
"'rgt__gt'",
"=>",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"rgt",
",",
"'level'",
"=>",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"level",
"-",
"1",
",",
"'root'",
"=>",
"$",
"this",
"->",
"getModel",
"(",
")",
"->",
"root",
",",
"]",
")",
";",
"}"
] | Named scope. Gets parent of node.
@return QuerySet | [
"Named",
"scope",
".",
"Gets",
"parent",
"of",
"node",
"."
] | 8231c55f9b95314789983c0b0ec83a9eb70adf79 | https://github.com/MindyPHP/OrmNestedSet/blob/8231c55f9b95314789983c0b0ec83a9eb70adf79/TreeQuerySet.php#L125-L133 | train |
MindyPHP/OrmNestedSet | TreeQuerySet.php | TreeQuerySet.rebuildLftRgt | protected function rebuildLftRgt(string $table)
{
$builder = QueryBuilderFactory::getQueryBuilder($this->getConnection());
$subQuerySql = (clone $builder)
->clear()
->select('tt.parent_id')
->table($table, 'tt')
->where('tt.parent_id=t.id')
->toSQL();
$sql = (clone $builder)
->clear()
->table($table, 't')
->select('t.id, t.root, t.lft, t.rgt, t.rgt-t.lft-1 AS move')
->where('NOT t.lft=(t.rgt-1) AND NOT t.id IN ('.$subQuerySql.')')
->order('rgt ASC')
->toSQL();
$rows = $this
->getConnection()
->query($sql)
->fetchAll();
foreach ($rows as $row) {
/*
$sql = strtr(
'UPDATE {table} SET lft=lft-{move}, rgt=rgt-{move} WHERE root={root} AND lft>{rgt}',
[
'{table}' => $table,
'{move}' => $row['move'],
'{root}' => $row['root'],
'{lft}' => $row['rgt'],
]
);
*/
$sql = (clone $builder)
->clear()
->update()
->table($table)
->values([
'lft' => new Expression(sprintf('lft-%s', $row['move'])),
'rgt' => new Expression(sprintf('rgt-%s', $row['move'])),
])
->where([
'root' => $row['root'],
'lft__gt' => $row['rgt'],
])
->toSQL();
$this
->getConnection()
->query($sql)
->execute();
/*
$sql = strtr(
'UPDATE {table} SET rgt=rgt-{move} WHERE root={root} AND lft<{rgt} AND rgt>={rgt}',
[
'{table}' => $table,
'{move}' => $row['move'],
'{root}' => $row['root'],
'{lft}' => $row['rgt'],
]
);
*/
$sql = (clone $builder)
->clear()
->update()
->table($table)
->values([
'rgt' => new Expression(sprintf('rgt-%s', $row['move'])),
])
->where([
'root' => $row['root'],
'lft__lt' => $row['rgt'],
'rgt__gte' => $row['rgt'],
])
->toSQL();
$this
->getConnection()
->query($sql)
->execute();
}
return $this;
} | php | protected function rebuildLftRgt(string $table)
{
$builder = QueryBuilderFactory::getQueryBuilder($this->getConnection());
$subQuerySql = (clone $builder)
->clear()
->select('tt.parent_id')
->table($table, 'tt')
->where('tt.parent_id=t.id')
->toSQL();
$sql = (clone $builder)
->clear()
->table($table, 't')
->select('t.id, t.root, t.lft, t.rgt, t.rgt-t.lft-1 AS move')
->where('NOT t.lft=(t.rgt-1) AND NOT t.id IN ('.$subQuerySql.')')
->order('rgt ASC')
->toSQL();
$rows = $this
->getConnection()
->query($sql)
->fetchAll();
foreach ($rows as $row) {
/*
$sql = strtr(
'UPDATE {table} SET lft=lft-{move}, rgt=rgt-{move} WHERE root={root} AND lft>{rgt}',
[
'{table}' => $table,
'{move}' => $row['move'],
'{root}' => $row['root'],
'{lft}' => $row['rgt'],
]
);
*/
$sql = (clone $builder)
->clear()
->update()
->table($table)
->values([
'lft' => new Expression(sprintf('lft-%s', $row['move'])),
'rgt' => new Expression(sprintf('rgt-%s', $row['move'])),
])
->where([
'root' => $row['root'],
'lft__gt' => $row['rgt'],
])
->toSQL();
$this
->getConnection()
->query($sql)
->execute();
/*
$sql = strtr(
'UPDATE {table} SET rgt=rgt-{move} WHERE root={root} AND lft<{rgt} AND rgt>={rgt}',
[
'{table}' => $table,
'{move}' => $row['move'],
'{root}' => $row['root'],
'{lft}' => $row['rgt'],
]
);
*/
$sql = (clone $builder)
->clear()
->update()
->table($table)
->values([
'rgt' => new Expression(sprintf('rgt-%s', $row['move'])),
])
->where([
'root' => $row['root'],
'lft__lt' => $row['rgt'],
'rgt__gte' => $row['rgt'],
])
->toSQL();
$this
->getConnection()
->query($sql)
->execute();
}
return $this;
} | [
"protected",
"function",
"rebuildLftRgt",
"(",
"string",
"$",
"table",
")",
"{",
"$",
"builder",
"=",
"QueryBuilderFactory",
"::",
"getQueryBuilder",
"(",
"$",
"this",
"->",
"getConnection",
"(",
")",
")",
";",
"$",
"subQuerySql",
"=",
"(",
"clone",
"$",
"builder",
")",
"->",
"clear",
"(",
")",
"->",
"select",
"(",
"'tt.parent_id'",
")",
"->",
"table",
"(",
"$",
"table",
",",
"'tt'",
")",
"->",
"where",
"(",
"'tt.parent_id=t.id'",
")",
"->",
"toSQL",
"(",
")",
";",
"$",
"sql",
"=",
"(",
"clone",
"$",
"builder",
")",
"->",
"clear",
"(",
")",
"->",
"table",
"(",
"$",
"table",
",",
"'t'",
")",
"->",
"select",
"(",
"'t.id, t.root, t.lft, t.rgt, t.rgt-t.lft-1 AS move'",
")",
"->",
"where",
"(",
"'NOT t.lft=(t.rgt-1) AND NOT t.id IN ('",
".",
"$",
"subQuerySql",
".",
"')'",
")",
"->",
"order",
"(",
"'rgt ASC'",
")",
"->",
"toSQL",
"(",
")",
";",
"$",
"rows",
"=",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"query",
"(",
"$",
"sql",
")",
"->",
"fetchAll",
"(",
")",
";",
"foreach",
"(",
"$",
"rows",
"as",
"$",
"row",
")",
"{",
"/*\n $sql = strtr(\n 'UPDATE {table} SET lft=lft-{move}, rgt=rgt-{move} WHERE root={root} AND lft>{rgt}',\n [\n '{table}' => $table,\n '{move}' => $row['move'],\n '{root}' => $row['root'],\n '{lft}' => $row['rgt'],\n ]\n );\n */",
"$",
"sql",
"=",
"(",
"clone",
"$",
"builder",
")",
"->",
"clear",
"(",
")",
"->",
"update",
"(",
")",
"->",
"table",
"(",
"$",
"table",
")",
"->",
"values",
"(",
"[",
"'lft'",
"=>",
"new",
"Expression",
"(",
"sprintf",
"(",
"'lft-%s'",
",",
"$",
"row",
"[",
"'move'",
"]",
")",
")",
",",
"'rgt'",
"=>",
"new",
"Expression",
"(",
"sprintf",
"(",
"'rgt-%s'",
",",
"$",
"row",
"[",
"'move'",
"]",
")",
")",
",",
"]",
")",
"->",
"where",
"(",
"[",
"'root'",
"=>",
"$",
"row",
"[",
"'root'",
"]",
",",
"'lft__gt'",
"=>",
"$",
"row",
"[",
"'rgt'",
"]",
",",
"]",
")",
"->",
"toSQL",
"(",
")",
";",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"query",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
")",
";",
"/*\n $sql = strtr(\n 'UPDATE {table} SET rgt=rgt-{move} WHERE root={root} AND lft<{rgt} AND rgt>={rgt}',\n [\n '{table}' => $table,\n '{move}' => $row['move'],\n '{root}' => $row['root'],\n '{lft}' => $row['rgt'],\n ]\n );\n */",
"$",
"sql",
"=",
"(",
"clone",
"$",
"builder",
")",
"->",
"clear",
"(",
")",
"->",
"update",
"(",
")",
"->",
"table",
"(",
"$",
"table",
")",
"->",
"values",
"(",
"[",
"'rgt'",
"=>",
"new",
"Expression",
"(",
"sprintf",
"(",
"'rgt-%s'",
",",
"$",
"row",
"[",
"'move'",
"]",
")",
")",
",",
"]",
")",
"->",
"where",
"(",
"[",
"'root'",
"=>",
"$",
"row",
"[",
"'root'",
"]",
",",
"'lft__lt'",
"=>",
"$",
"row",
"[",
"'rgt'",
"]",
",",
"'rgt__gte'",
"=>",
"$",
"row",
"[",
"'rgt'",
"]",
",",
"]",
")",
"->",
"toSQL",
"(",
")",
";",
"$",
"this",
"->",
"getConnection",
"(",
")",
"->",
"query",
"(",
"$",
"sql",
")",
"->",
"execute",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Find and delete broken branches without root, parent
and with incorrect lft, rgt.
sql:
SELECT id, root, lft, rgt, (rgt-lft-1) AS move
FROM tbl t
WHERE NOT t.lft = (t.rgt-1)
AND NOT id IN (
SELECT tc.parent_id
FROM tbl tc
WHERE tc.parent_id = t.id
)
ORDER BY rgt DESC
@param $table
@throws \Doctrine\DBAL\DBALException
@throws \Mindy\QueryBuilder\Exception\NotSupportedException
@return TreeQuerySet | [
"Find",
"and",
"delete",
"broken",
"branches",
"without",
"root",
"parent",
"and",
"with",
"incorrect",
"lft",
"rgt",
"."
] | 8231c55f9b95314789983c0b0ec83a9eb70adf79 | https://github.com/MindyPHP/OrmNestedSet/blob/8231c55f9b95314789983c0b0ec83a9eb70adf79/TreeQuerySet.php#L347-L434 | train |
MindyPHP/OrmNestedSet | TreeQuerySet.php | TreeQuerySet.toHierarchy | public function toHierarchy($collection): array
{
// Trees mapped
$trees = [];
if (count($collection) > 0) {
// Node Stack. Used to help building the hierarchy
$stack = [];
foreach ($collection as $item) {
$item[$this->treeKey] = [];
// Number of stack items
$l = count($stack);
// Check if we're dealing with different levels
while ($l > 0 && $stack[$l - 1]['level'] >= $item['level']) {
array_pop($stack);
--$l;
}
// Stack is empty (we are inspecting the root)
if (0 == $l) {
// Assigning the root node
$i = count($trees);
$trees[$i] = $item;
$stack[] = &$trees[$i];
} else {
// Add node to parent
$i = count($stack[$l - 1][$this->treeKey]);
$stack[$l - 1][$this->treeKey][$i] = $item;
$stack[] = &$stack[$l - 1][$this->treeKey][$i];
}
}
}
return $trees;
} | php | public function toHierarchy($collection): array
{
// Trees mapped
$trees = [];
if (count($collection) > 0) {
// Node Stack. Used to help building the hierarchy
$stack = [];
foreach ($collection as $item) {
$item[$this->treeKey] = [];
// Number of stack items
$l = count($stack);
// Check if we're dealing with different levels
while ($l > 0 && $stack[$l - 1]['level'] >= $item['level']) {
array_pop($stack);
--$l;
}
// Stack is empty (we are inspecting the root)
if (0 == $l) {
// Assigning the root node
$i = count($trees);
$trees[$i] = $item;
$stack[] = &$trees[$i];
} else {
// Add node to parent
$i = count($stack[$l - 1][$this->treeKey]);
$stack[$l - 1][$this->treeKey][$i] = $item;
$stack[] = &$stack[$l - 1][$this->treeKey][$i];
}
}
}
return $trees;
} | [
"public",
"function",
"toHierarchy",
"(",
"$",
"collection",
")",
":",
"array",
"{",
"// Trees mapped",
"$",
"trees",
"=",
"[",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"collection",
")",
">",
"0",
")",
"{",
"// Node Stack. Used to help building the hierarchy",
"$",
"stack",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"collection",
"as",
"$",
"item",
")",
"{",
"$",
"item",
"[",
"$",
"this",
"->",
"treeKey",
"]",
"=",
"[",
"]",
";",
"// Number of stack items",
"$",
"l",
"=",
"count",
"(",
"$",
"stack",
")",
";",
"// Check if we're dealing with different levels",
"while",
"(",
"$",
"l",
">",
"0",
"&&",
"$",
"stack",
"[",
"$",
"l",
"-",
"1",
"]",
"[",
"'level'",
"]",
">=",
"$",
"item",
"[",
"'level'",
"]",
")",
"{",
"array_pop",
"(",
"$",
"stack",
")",
";",
"--",
"$",
"l",
";",
"}",
"// Stack is empty (we are inspecting the root)",
"if",
"(",
"0",
"==",
"$",
"l",
")",
"{",
"// Assigning the root node",
"$",
"i",
"=",
"count",
"(",
"$",
"trees",
")",
";",
"$",
"trees",
"[",
"$",
"i",
"]",
"=",
"$",
"item",
";",
"$",
"stack",
"[",
"]",
"=",
"&",
"$",
"trees",
"[",
"$",
"i",
"]",
";",
"}",
"else",
"{",
"// Add node to parent",
"$",
"i",
"=",
"count",
"(",
"$",
"stack",
"[",
"$",
"l",
"-",
"1",
"]",
"[",
"$",
"this",
"->",
"treeKey",
"]",
")",
";",
"$",
"stack",
"[",
"$",
"l",
"-",
"1",
"]",
"[",
"$",
"this",
"->",
"treeKey",
"]",
"[",
"$",
"i",
"]",
"=",
"$",
"item",
";",
"$",
"stack",
"[",
"]",
"=",
"&",
"$",
"stack",
"[",
"$",
"l",
"-",
"1",
"]",
"[",
"$",
"this",
"->",
"treeKey",
"]",
"[",
"$",
"i",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"trees",
";",
"}"
] | Make hierarchy array by level.
@param $collection Model[]
@return array | [
"Make",
"hierarchy",
"array",
"by",
"level",
"."
] | 8231c55f9b95314789983c0b0ec83a9eb70adf79 | https://github.com/MindyPHP/OrmNestedSet/blob/8231c55f9b95314789983c0b0ec83a9eb70adf79/TreeQuerySet.php#L505-L537 | train |
phpffcms/ffcms-core | src/Helper/FileSystem/Directory.php | Directory.writable | public static function writable($path)
{
$path = Normalize::diskFullPath($path);
if (!self::exist($path)) {
return false;
}
return (is_dir($path) && is_writable($path));
} | php | public static function writable($path)
{
$path = Normalize::diskFullPath($path);
if (!self::exist($path)) {
return false;
}
return (is_dir($path) && is_writable($path));
} | [
"public",
"static",
"function",
"writable",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"Normalize",
"::",
"diskFullPath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"self",
"::",
"exist",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"(",
"is_dir",
"(",
"$",
"path",
")",
"&&",
"is_writable",
"(",
"$",
"path",
")",
")",
";",
"}"
] | Check if directory is writable
@param string $path
@return bool | [
"Check",
"if",
"directory",
"is",
"writable"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/FileSystem/Directory.php#L32-L41 | train |
phpffcms/ffcms-core | src/Helper/FileSystem/Directory.php | Directory.create | public static function create($path, $chmod = 0755)
{
$path = Normalize::diskFullPath($path);
if (self::exist($path)) {
return false;
}
return @mkdir($path, $chmod, true);
} | php | public static function create($path, $chmod = 0755)
{
$path = Normalize::diskFullPath($path);
if (self::exist($path)) {
return false;
}
return @mkdir($path, $chmod, true);
} | [
"public",
"static",
"function",
"create",
"(",
"$",
"path",
",",
"$",
"chmod",
"=",
"0755",
")",
"{",
"$",
"path",
"=",
"Normalize",
"::",
"diskFullPath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"self",
"::",
"exist",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"@",
"mkdir",
"(",
"$",
"path",
",",
"$",
"chmod",
",",
"true",
")",
";",
"}"
] | Create directory with recursive support.
@param string $path
@param int $chmod
@return bool | [
"Create",
"directory",
"with",
"recursive",
"support",
"."
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/FileSystem/Directory.php#L49-L58 | train |
phpffcms/ffcms-core | src/Helper/FileSystem/Directory.php | Directory.remove | public static function remove($path)
{
$path = Normalize::diskFullPath($path);
if (!self::exist($path)) {
return false;
}
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $dir) {
$dir->isFile() ? @unlink($dir->getPathname()) : @rmdir($dir->getPathname());
}
return @rmdir($path);
} | php | public static function remove($path)
{
$path = Normalize::diskFullPath($path);
if (!self::exist($path)) {
return false;
}
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $dir) {
$dir->isFile() ? @unlink($dir->getPathname()) : @rmdir($dir->getPathname());
}
return @rmdir($path);
} | [
"public",
"static",
"function",
"remove",
"(",
"$",
"path",
")",
"{",
"$",
"path",
"=",
"Normalize",
"::",
"diskFullPath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"self",
"::",
"exist",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"foreach",
"(",
"new",
"RecursiveIteratorIterator",
"(",
"new",
"RecursiveDirectoryIterator",
"(",
"$",
"path",
",",
"FilesystemIterator",
"::",
"SKIP_DOTS",
")",
",",
"RecursiveIteratorIterator",
"::",
"CHILD_FIRST",
")",
"as",
"$",
"dir",
")",
"{",
"$",
"dir",
"->",
"isFile",
"(",
")",
"?",
"@",
"unlink",
"(",
"$",
"dir",
"->",
"getPathname",
"(",
")",
")",
":",
"@",
"rmdir",
"(",
"$",
"dir",
"->",
"getPathname",
"(",
")",
")",
";",
"}",
"return",
"@",
"rmdir",
"(",
"$",
"path",
")",
";",
"}"
] | Remove directory recursive.
@param string $path
@return bool | [
"Remove",
"directory",
"recursive",
"."
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/FileSystem/Directory.php#L65-L77 | train |
phpffcms/ffcms-core | src/Helper/FileSystem/Directory.php | Directory.scan | public static function scan($path, $mod = GLOB_ONLYDIR, $returnRelative = false)
{
$path = Normalize::diskFullPath($path);
if (!self::exist($path)) {
return false;
}
$pattern = rtrim($path, '/') . '/*';
$entry = glob($pattern, $mod);
if ($returnRelative === true) {
foreach ($entry as $key => $value) {
$entry[$key] = trim(str_replace($path, null, $value), '/');
}
}
return $entry;
} | php | public static function scan($path, $mod = GLOB_ONLYDIR, $returnRelative = false)
{
$path = Normalize::diskFullPath($path);
if (!self::exist($path)) {
return false;
}
$pattern = rtrim($path, '/') . '/*';
$entry = glob($pattern, $mod);
if ($returnRelative === true) {
foreach ($entry as $key => $value) {
$entry[$key] = trim(str_replace($path, null, $value), '/');
}
}
return $entry;
} | [
"public",
"static",
"function",
"scan",
"(",
"$",
"path",
",",
"$",
"mod",
"=",
"GLOB_ONLYDIR",
",",
"$",
"returnRelative",
"=",
"false",
")",
"{",
"$",
"path",
"=",
"Normalize",
"::",
"diskFullPath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"self",
"::",
"exist",
"(",
"$",
"path",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"pattern",
"=",
"rtrim",
"(",
"$",
"path",
",",
"'/'",
")",
".",
"'/*'",
";",
"$",
"entry",
"=",
"glob",
"(",
"$",
"pattern",
",",
"$",
"mod",
")",
";",
"if",
"(",
"$",
"returnRelative",
"===",
"true",
")",
"{",
"foreach",
"(",
"$",
"entry",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"entry",
"[",
"$",
"key",
"]",
"=",
"trim",
"(",
"str_replace",
"(",
"$",
"path",
",",
"null",
",",
"$",
"value",
")",
",",
"'/'",
")",
";",
"}",
"}",
"return",
"$",
"entry",
";",
"}"
] | Scan files in directory and return full or relative path
@param string $path
@param int $mod
@param bool|false $returnRelative
@return array|bool | [
"Scan",
"files",
"in",
"directory",
"and",
"return",
"full",
"or",
"relative",
"path"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/FileSystem/Directory.php#L86-L104 | train |
phpffcms/ffcms-core | src/Helper/FileSystem/Directory.php | Directory.recursiveChmod | public static function recursiveChmod($path, $mod = 0777)
{
$path = Normalize::diskFullPath($path);
if (!self::exist($path)) {
return;
}
$dir = new \DirectoryIterator($path);
foreach ($dir as $item) {
// change chmod for folders and files
if ($item->isDir() || $item->isFile()) {
chmod($item->getPathname(), 0777);
}
// try to recursive chmod folders
if ($item->isDir() && !$item->isDot()) {
self::recursiveChmod($item->getPathname(), $mod);
}
}
} | php | public static function recursiveChmod($path, $mod = 0777)
{
$path = Normalize::diskFullPath($path);
if (!self::exist($path)) {
return;
}
$dir = new \DirectoryIterator($path);
foreach ($dir as $item) {
// change chmod for folders and files
if ($item->isDir() || $item->isFile()) {
chmod($item->getPathname(), 0777);
}
// try to recursive chmod folders
if ($item->isDir() && !$item->isDot()) {
self::recursiveChmod($item->getPathname(), $mod);
}
}
} | [
"public",
"static",
"function",
"recursiveChmod",
"(",
"$",
"path",
",",
"$",
"mod",
"=",
"0777",
")",
"{",
"$",
"path",
"=",
"Normalize",
"::",
"diskFullPath",
"(",
"$",
"path",
")",
";",
"if",
"(",
"!",
"self",
"::",
"exist",
"(",
"$",
"path",
")",
")",
"{",
"return",
";",
"}",
"$",
"dir",
"=",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"path",
")",
";",
"foreach",
"(",
"$",
"dir",
"as",
"$",
"item",
")",
"{",
"// change chmod for folders and files",
"if",
"(",
"$",
"item",
"->",
"isDir",
"(",
")",
"||",
"$",
"item",
"->",
"isFile",
"(",
")",
")",
"{",
"chmod",
"(",
"$",
"item",
"->",
"getPathname",
"(",
")",
",",
"0777",
")",
";",
"}",
"// try to recursive chmod folders",
"if",
"(",
"$",
"item",
"->",
"isDir",
"(",
")",
"&&",
"!",
"$",
"item",
"->",
"isDot",
"(",
")",
")",
"{",
"self",
"::",
"recursiveChmod",
"(",
"$",
"item",
"->",
"getPathname",
"(",
")",
",",
"$",
"mod",
")",
";",
"}",
"}",
"}"
] | Change chmod recursive inside defined folder
@param string $path
@param int $mod | [
"Change",
"chmod",
"recursive",
"inside",
"defined",
"folder"
] | 44a309553ef9f115ccfcfd71f2ac6e381c612082 | https://github.com/phpffcms/ffcms-core/blob/44a309553ef9f115ccfcfd71f2ac6e381c612082/src/Helper/FileSystem/Directory.php#L135-L153 | train |
eureka-framework/component-response | src/Response/Json/Api.php | Api.getContent | public function getContent()
{
$json = new \stdClass();
$json->isSuccess = $this->isSuccess();
$json->errorCode = $this->getErrorCode();
$json->errorMessage = $this->getErrorMessage();
$json->data = $this->content;
return $json;
} | php | public function getContent()
{
$json = new \stdClass();
$json->isSuccess = $this->isSuccess();
$json->errorCode = $this->getErrorCode();
$json->errorMessage = $this->getErrorMessage();
$json->data = $this->content;
return $json;
} | [
"public",
"function",
"getContent",
"(",
")",
"{",
"$",
"json",
"=",
"new",
"\\",
"stdClass",
"(",
")",
";",
"$",
"json",
"->",
"isSuccess",
"=",
"$",
"this",
"->",
"isSuccess",
"(",
")",
";",
"$",
"json",
"->",
"errorCode",
"=",
"$",
"this",
"->",
"getErrorCode",
"(",
")",
";",
"$",
"json",
"->",
"errorMessage",
"=",
"$",
"this",
"->",
"getErrorMessage",
"(",
")",
";",
"$",
"json",
"->",
"data",
"=",
"$",
"this",
"->",
"content",
";",
"return",
"$",
"json",
";",
"}"
] | Over getContent response. Add specific content to the response.
@return string | [
"Over",
"getContent",
"response",
".",
"Add",
"specific",
"content",
"to",
"the",
"response",
"."
] | f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a | https://github.com/eureka-framework/component-response/blob/f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a/src/Response/Json/Api.php#L39-L49 | train |
eureka-framework/component-response | src/Response/Json/Api.php | Api.setErrorMessage | final public function setErrorMessage($message)
{
$this->errorMessage = (string) $message;
if (empty($this->errorMessage)) {
throw new \RuntimeException('Error message cannot be empty !');
}
return $this;
} | php | final public function setErrorMessage($message)
{
$this->errorMessage = (string) $message;
if (empty($this->errorMessage)) {
throw new \RuntimeException('Error message cannot be empty !');
}
return $this;
} | [
"final",
"public",
"function",
"setErrorMessage",
"(",
"$",
"message",
")",
"{",
"$",
"this",
"->",
"errorMessage",
"=",
"(",
"string",
")",
"$",
"message",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"errorMessage",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Error message cannot be empty !'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Set error message.
@param string $message
@return self
@throws \RuntimeException | [
"Set",
"error",
"message",
"."
] | f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a | https://github.com/eureka-framework/component-response/blob/f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a/src/Response/Json/Api.php#L114-L123 | train |
eureka-framework/component-response | src/Response/Json/Api.php | Api.appendContent | public function appendContent($key, $value)
{
if ($this->content === null) {
$this->content = array();
}
if (!is_array($this->content)) {
throw new \InvalidArgumentException('Cannot append response content: Current content is not an array !');
}
$this->content[(string) $key] = $value;
return $this;
} | php | public function appendContent($key, $value)
{
if ($this->content === null) {
$this->content = array();
}
if (!is_array($this->content)) {
throw new \InvalidArgumentException('Cannot append response content: Current content is not an array !');
}
$this->content[(string) $key] = $value;
return $this;
} | [
"public",
"function",
"appendContent",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"content",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"content",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"this",
"->",
"content",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"'Cannot append response content: Current content is not an array !'",
")",
";",
"}",
"$",
"this",
"->",
"content",
"[",
"(",
"string",
")",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"return",
"$",
"this",
";",
"}"
] | Append content for the response.
@param string $key
@param mixed $value
@return self
@throws \InvalidArgumentException | [
"Append",
"content",
"for",
"the",
"response",
"."
] | f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a | https://github.com/eureka-framework/component-response/blob/f34aea3a0aa67b88c5e7f8a3b86af29c550fa99a/src/Response/Json/Api.php#L133-L146 | train |
nativgames-old/pegase | src/Pegase/Core/Router/Service/Router.php | Router.get | public function get($route_name) {
$route = null;
if(!array_key_exists($route_name, $this->routes))
echo "Router: error: the array key $route_name doesn't exists.<br />";
else {
$route_infos = $this->routes[$route_name];
if($route_controller = $this->instancy_controller($route_infos[1])) {
$route = array($route_controller, $route_infos[2]);
}
}
return $route;
} | php | public function get($route_name) {
$route = null;
if(!array_key_exists($route_name, $this->routes))
echo "Router: error: the array key $route_name doesn't exists.<br />";
else {
$route_infos = $this->routes[$route_name];
if($route_controller = $this->instancy_controller($route_infos[1])) {
$route = array($route_controller, $route_infos[2]);
}
}
return $route;
} | [
"public",
"function",
"get",
"(",
"$",
"route_name",
")",
"{",
"$",
"route",
"=",
"null",
";",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"route_name",
",",
"$",
"this",
"->",
"routes",
")",
")",
"echo",
"\"Router: error: the array key $route_name doesn't exists.<br />\"",
";",
"else",
"{",
"$",
"route_infos",
"=",
"$",
"this",
"->",
"routes",
"[",
"$",
"route_name",
"]",
";",
"if",
"(",
"$",
"route_controller",
"=",
"$",
"this",
"->",
"instancy_controller",
"(",
"$",
"route_infos",
"[",
"1",
"]",
")",
")",
"{",
"$",
"route",
"=",
"array",
"(",
"$",
"route_controller",
",",
"$",
"route_infos",
"[",
"2",
"]",
")",
";",
"}",
"}",
"return",
"$",
"route",
";",
"}"
] | returns the controller with 'route_name' | [
"returns",
"the",
"controller",
"with",
"route_name"
] | 9a00e09a26f391c988aadecd7640c72316eaa521 | https://github.com/nativgames-old/pegase/blob/9a00e09a26f391c988aadecd7640c72316eaa521/src/Pegase/Core/Router/Service/Router.php#L49-L63 | train |
afroware/jwtauth | src/JwT.php | JwT.check | public function check($getPayload = false)
{
try {
$payload = $this->checkOrFail();
} catch (JwTException $e) {
return false;
}
return $getPayload ? $payload : true;
} | php | public function check($getPayload = false)
{
try {
$payload = $this->checkOrFail();
} catch (JwTException $e) {
return false;
}
return $getPayload ? $payload : true;
} | [
"public",
"function",
"check",
"(",
"$",
"getPayload",
"=",
"false",
")",
"{",
"try",
"{",
"$",
"payload",
"=",
"$",
"this",
"->",
"checkOrFail",
"(",
")",
";",
"}",
"catch",
"(",
"JwTException",
"$",
"e",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"getPayload",
"?",
"$",
"payload",
":",
"true",
";",
"}"
] | Check that the token is valid.
@param bool $getPayload
@return \Afroware\JwTauth\Payload|bool | [
"Check",
"that",
"the",
"token",
"is",
"valid",
"."
] | 54a0aebd811d87bfdd2b3668696fd53f50490cc1 | https://github.com/afroware/jwtauth/blob/54a0aebd811d87bfdd2b3668696fd53f50490cc1/src/JwT.php#L139-L148 | train |
brightnucleus/options-store | src/OptionRepository/AggregateOptionRepository.php | AggregateOptionRepository.has | public function has(string $key): bool
{
foreach ($this->repositories as $repository) {
if ($repository->has($key)) {
return true;
}
}
return false;
} | php | public function has(string $key): bool
{
foreach ($this->repositories as $repository) {
if ($repository->has($key)) {
return true;
}
}
return false;
} | [
"public",
"function",
"has",
"(",
"string",
"$",
"key",
")",
":",
"bool",
"{",
"foreach",
"(",
"$",
"this",
"->",
"repositories",
"as",
"$",
"repository",
")",
"{",
"if",
"(",
"$",
"repository",
"->",
"has",
"(",
"$",
"key",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Check whether the repository contains a given key.
@since 0.1.0
@param string $key Key to check for.
@return bool Whether the repository contained the requested key. | [
"Check",
"whether",
"the",
"repository",
"contains",
"a",
"given",
"key",
"."
] | 9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1 | https://github.com/brightnucleus/options-store/blob/9a9ef2a160bbacd69fe3e9db0be8ed89e6905ef1/src/OptionRepository/AggregateOptionRepository.php#L72-L81 | train |
koolkode/security | src/Authentication/Token/HttpDigestToken.php | HttpDigestToken.isValidResponse | public function isValidResponse($ha1)
{
if($this->opaque === NULL)
{
return false;
}
if(!SecurityUtil::timingSafeEquals($this->auth->getOpaque(), $this->opaque))
{
return false;
}
$args = [
$ha1,
$this->nonce,
$this->nc,
$this->cnonce,
$this->auth->getQualityOfProtection(),
$this->ha2
];
return SecurityUtil::timingSafeEquals(md5(vsprintf('%s:%s:%s:%s:%s:%s', $args)), $this->response);
} | php | public function isValidResponse($ha1)
{
if($this->opaque === NULL)
{
return false;
}
if(!SecurityUtil::timingSafeEquals($this->auth->getOpaque(), $this->opaque))
{
return false;
}
$args = [
$ha1,
$this->nonce,
$this->nc,
$this->cnonce,
$this->auth->getQualityOfProtection(),
$this->ha2
];
return SecurityUtil::timingSafeEquals(md5(vsprintf('%s:%s:%s:%s:%s:%s', $args)), $this->response);
} | [
"public",
"function",
"isValidResponse",
"(",
"$",
"ha1",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"opaque",
"===",
"NULL",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"SecurityUtil",
"::",
"timingSafeEquals",
"(",
"$",
"this",
"->",
"auth",
"->",
"getOpaque",
"(",
")",
",",
"$",
"this",
"->",
"opaque",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"args",
"=",
"[",
"$",
"ha1",
",",
"$",
"this",
"->",
"nonce",
",",
"$",
"this",
"->",
"nc",
",",
"$",
"this",
"->",
"cnonce",
",",
"$",
"this",
"->",
"auth",
"->",
"getQualityOfProtection",
"(",
")",
",",
"$",
"this",
"->",
"ha2",
"]",
";",
"return",
"SecurityUtil",
"::",
"timingSafeEquals",
"(",
"md5",
"(",
"vsprintf",
"(",
"'%s:%s:%s:%s:%s:%s'",
",",
"$",
"args",
")",
")",
",",
"$",
"this",
"->",
"response",
")",
";",
"}"
] | Check if the response is valid using the given HA1 value.
@param string $ha1
@return boolean | [
"Check",
"if",
"the",
"response",
"is",
"valid",
"using",
"the",
"given",
"HA1",
"value",
"."
] | d3d8d42392f520754847d29b6df19aaa38c79e8e | https://github.com/koolkode/security/blob/d3d8d42392f520754847d29b6df19aaa38c79e8e/src/Authentication/Token/HttpDigestToken.php#L235-L257 | train |
theopera/framework | src/Component/WebApplication/RouteCollection.php | RouteCollection.addRoute | public function addRoute(string $path, string $controller, string $action = 'index', string $method = Request::METHOD_GET) : self
{
$endPoint = new RouteEndpoint($this->namespace, $controller, $action, $method);
$this->routes[] = new Route($path, $endPoint);
return $this;
} | php | public function addRoute(string $path, string $controller, string $action = 'index', string $method = Request::METHOD_GET) : self
{
$endPoint = new RouteEndpoint($this->namespace, $controller, $action, $method);
$this->routes[] = new Route($path, $endPoint);
return $this;
} | [
"public",
"function",
"addRoute",
"(",
"string",
"$",
"path",
",",
"string",
"$",
"controller",
",",
"string",
"$",
"action",
"=",
"'index'",
",",
"string",
"$",
"method",
"=",
"Request",
"::",
"METHOD_GET",
")",
":",
"self",
"{",
"$",
"endPoint",
"=",
"new",
"RouteEndpoint",
"(",
"$",
"this",
"->",
"namespace",
",",
"$",
"controller",
",",
"$",
"action",
",",
"$",
"method",
")",
";",
"$",
"this",
"->",
"routes",
"[",
"]",
"=",
"new",
"Route",
"(",
"$",
"path",
",",
"$",
"endPoint",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add a new route to the collection
@param string $path
@param string $controller
@param string $action
@param string $method
@return $this | [
"Add",
"a",
"new",
"route",
"to",
"the",
"collection"
] | fa6165d3891a310faa580c81dee49a63c150c711 | https://github.com/theopera/framework/blob/fa6165d3891a310faa580c81dee49a63c150c711/src/Component/WebApplication/RouteCollection.php#L50-L56 | train |
pluf/tenant | src/Tenant/Views/SpaRun.php | Tenant_Views_SpaRun.defaultSpa | public function defaultSpa($request, $match)
{
$name = Tenant_Service::setting('spa.default', 'not-found');
$spa = Tenant_SPA::getSpaByName($name);
if (! isset($spa)) {
$spa = Tenant_SpaService::getNotfoundSpa();
}
// $resPath = $spa->getMainPagePath();
// return new Tenant_HTTP_Response_SpaMain($resPath, Pluf_FileUtil::getMimeType($resPath));
$host = ($request->https ? 'https://' : 'http://') . $request->SERVER['HTTP_HOST'];
$url = $host . '/' . $spa->name . '/';
return new Pluf_HTTP_Response_Redirect($url);
} | php | public function defaultSpa($request, $match)
{
$name = Tenant_Service::setting('spa.default', 'not-found');
$spa = Tenant_SPA::getSpaByName($name);
if (! isset($spa)) {
$spa = Tenant_SpaService::getNotfoundSpa();
}
// $resPath = $spa->getMainPagePath();
// return new Tenant_HTTP_Response_SpaMain($resPath, Pluf_FileUtil::getMimeType($resPath));
$host = ($request->https ? 'https://' : 'http://') . $request->SERVER['HTTP_HOST'];
$url = $host . '/' . $spa->name . '/';
return new Pluf_HTTP_Response_Redirect($url);
} | [
"public",
"function",
"defaultSpa",
"(",
"$",
"request",
",",
"$",
"match",
")",
"{",
"$",
"name",
"=",
"Tenant_Service",
"::",
"setting",
"(",
"'spa.default'",
",",
"'not-found'",
")",
";",
"$",
"spa",
"=",
"Tenant_SPA",
"::",
"getSpaByName",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"spa",
")",
")",
"{",
"$",
"spa",
"=",
"Tenant_SpaService",
"::",
"getNotfoundSpa",
"(",
")",
";",
"}",
"// $resPath = $spa->getMainPagePath();",
"// return new Tenant_HTTP_Response_SpaMain($resPath, Pluf_FileUtil::getMimeType($resPath));",
"$",
"host",
"=",
"(",
"$",
"request",
"->",
"https",
"?",
"'https://'",
":",
"'http://'",
")",
".",
"$",
"request",
"->",
"SERVER",
"[",
"'HTTP_HOST'",
"]",
";",
"$",
"url",
"=",
"$",
"host",
".",
"'/'",
".",
"$",
"spa",
"->",
"name",
".",
"'/'",
";",
"return",
"new",
"Pluf_HTTP_Response_Redirect",
"(",
"$",
"url",
")",
";",
"}"
] | Load default spa
@param Pluf_HTTP_Request $request
@param array $match
@return Pluf_HTTP_Response_File|Pluf_HTTP_Response | [
"Load",
"default",
"spa"
] | a06359c52b9a257b5a0a186264e8770acfc54b73 | https://github.com/pluf/tenant/blob/a06359c52b9a257b5a0a186264e8770acfc54b73/src/Tenant/Views/SpaRun.php#L41-L53 | train |
pluf/tenant | src/Tenant/Views/SpaRun.php | Tenant_Views_SpaRun.defaultSpaRobotsTxt | public function defaultSpaRobotsTxt($request, $match)
{
$name = Tenant_Service::setting('spa.default', 'not-found');
$spa = Tenant_SPA::getSpaByName($name);
if (! isset($spa)) {
$spa = Tenant_SpaService::getNotfoundSpa();
}
$resourcePath = $spa->getResourcePath('robots.txt');
$host = ($request->https ? 'https://' : 'http://') . $request->SERVER['HTTP_HOST'];
return new Tenant_HTTP_Response_RobotsTxt($host, $resourcePath);
} | php | public function defaultSpaRobotsTxt($request, $match)
{
$name = Tenant_Service::setting('spa.default', 'not-found');
$spa = Tenant_SPA::getSpaByName($name);
if (! isset($spa)) {
$spa = Tenant_SpaService::getNotfoundSpa();
}
$resourcePath = $spa->getResourcePath('robots.txt');
$host = ($request->https ? 'https://' : 'http://') . $request->SERVER['HTTP_HOST'];
return new Tenant_HTTP_Response_RobotsTxt($host, $resourcePath);
} | [
"public",
"function",
"defaultSpaRobotsTxt",
"(",
"$",
"request",
",",
"$",
"match",
")",
"{",
"$",
"name",
"=",
"Tenant_Service",
"::",
"setting",
"(",
"'spa.default'",
",",
"'not-found'",
")",
";",
"$",
"spa",
"=",
"Tenant_SPA",
"::",
"getSpaByName",
"(",
"$",
"name",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"spa",
")",
")",
"{",
"$",
"spa",
"=",
"Tenant_SpaService",
"::",
"getNotfoundSpa",
"(",
")",
";",
"}",
"$",
"resourcePath",
"=",
"$",
"spa",
"->",
"getResourcePath",
"(",
"'robots.txt'",
")",
";",
"$",
"host",
"=",
"(",
"$",
"request",
"->",
"https",
"?",
"'https://'",
":",
"'http://'",
")",
".",
"$",
"request",
"->",
"SERVER",
"[",
"'HTTP_HOST'",
"]",
";",
"return",
"new",
"Tenant_HTTP_Response_RobotsTxt",
"(",
"$",
"host",
",",
"$",
"resourcePath",
")",
";",
"}"
] | Load robots.txt of default spa
@param Pluf_HTTP_Request $request
@param array $match
@return Pluf_HTTP_Response_File|Pluf_HTTP_Response | [
"Load",
"robots",
".",
"txt",
"of",
"default",
"spa"
] | a06359c52b9a257b5a0a186264e8770acfc54b73 | https://github.com/pluf/tenant/blob/a06359c52b9a257b5a0a186264e8770acfc54b73/src/Tenant/Views/SpaRun.php#L62-L72 | train |
pluf/tenant | src/Tenant/Views/SpaRun.php | Tenant_Views_SpaRun.loadResource | public function loadResource($request, $match)
{
// First part of path
$firstPart = $match['firstPart'];
// Remain part of path
$remainPart = '';
if (array_key_exists('remainPart', $match)) {
$remainPart = $match['remainPart'];
}
$spa = Tenant_SPA::getSpaByName($firstPart);
if (isset($spa)) { // SPA is valid
$path = $remainPart;
$spaName = $firstPart;
} else {
// first part is not an SPA so use default SPA
$path = isset($remainPart) && ! empty($remainPart) ? $firstPart . '/' . $remainPart : $firstPart;
// find a resource
$tenantResource = $this->findTenantResource('/' . $path);
if ($tenantResource) {
return new Pluf_HTTP_Response_File($tenantResource->getAbsloutPath(), $tenantResource->mime_type);
}
// [OR] check for default spa
$name = Tenant_Service::setting('spa.default', 'not-found');
$spa = Tenant_SPA::getSpaByName($name);
if ($spa === null) {
$spa = Tenant_SpaService::getNotfoundSpa();
$spaName = 'not-found';
} else {
$spaName = null;
}
}
if (preg_match('/.+\.[a-zA-Z0-9]+$/', $path)) {
// Looking for file in SPA
$resPath = $spa->getResourcePath($path);
$isMain = false;
} else {
// [OR]Request is for main file (path is an internal state)
$resPath = $spa->getMainPagePath();
$isMain = true;
}
if ($isMain) {
return new Tenant_HTTP_Response_SpaMain($resPath, Pluf_FileUtil::getMimeType($resPath), $spaName);
} else {
return new Pluf_HTTP_Response_File($resPath, Pluf_FileUtil::getMimeType($resPath));
}
} | php | public function loadResource($request, $match)
{
// First part of path
$firstPart = $match['firstPart'];
// Remain part of path
$remainPart = '';
if (array_key_exists('remainPart', $match)) {
$remainPart = $match['remainPart'];
}
$spa = Tenant_SPA::getSpaByName($firstPart);
if (isset($spa)) { // SPA is valid
$path = $remainPart;
$spaName = $firstPart;
} else {
// first part is not an SPA so use default SPA
$path = isset($remainPart) && ! empty($remainPart) ? $firstPart . '/' . $remainPart : $firstPart;
// find a resource
$tenantResource = $this->findTenantResource('/' . $path);
if ($tenantResource) {
return new Pluf_HTTP_Response_File($tenantResource->getAbsloutPath(), $tenantResource->mime_type);
}
// [OR] check for default spa
$name = Tenant_Service::setting('spa.default', 'not-found');
$spa = Tenant_SPA::getSpaByName($name);
if ($spa === null) {
$spa = Tenant_SpaService::getNotfoundSpa();
$spaName = 'not-found';
} else {
$spaName = null;
}
}
if (preg_match('/.+\.[a-zA-Z0-9]+$/', $path)) {
// Looking for file in SPA
$resPath = $spa->getResourcePath($path);
$isMain = false;
} else {
// [OR]Request is for main file (path is an internal state)
$resPath = $spa->getMainPagePath();
$isMain = true;
}
if ($isMain) {
return new Tenant_HTTP_Response_SpaMain($resPath, Pluf_FileUtil::getMimeType($resPath), $spaName);
} else {
return new Pluf_HTTP_Response_File($resPath, Pluf_FileUtil::getMimeType($resPath));
}
} | [
"public",
"function",
"loadResource",
"(",
"$",
"request",
",",
"$",
"match",
")",
"{",
"// First part of path",
"$",
"firstPart",
"=",
"$",
"match",
"[",
"'firstPart'",
"]",
";",
"// Remain part of path",
"$",
"remainPart",
"=",
"''",
";",
"if",
"(",
"array_key_exists",
"(",
"'remainPart'",
",",
"$",
"match",
")",
")",
"{",
"$",
"remainPart",
"=",
"$",
"match",
"[",
"'remainPart'",
"]",
";",
"}",
"$",
"spa",
"=",
"Tenant_SPA",
"::",
"getSpaByName",
"(",
"$",
"firstPart",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"spa",
")",
")",
"{",
"// SPA is valid",
"$",
"path",
"=",
"$",
"remainPart",
";",
"$",
"spaName",
"=",
"$",
"firstPart",
";",
"}",
"else",
"{",
"// first part is not an SPA so use default SPA",
"$",
"path",
"=",
"isset",
"(",
"$",
"remainPart",
")",
"&&",
"!",
"empty",
"(",
"$",
"remainPart",
")",
"?",
"$",
"firstPart",
".",
"'/'",
".",
"$",
"remainPart",
":",
"$",
"firstPart",
";",
"// find a resource",
"$",
"tenantResource",
"=",
"$",
"this",
"->",
"findTenantResource",
"(",
"'/'",
".",
"$",
"path",
")",
";",
"if",
"(",
"$",
"tenantResource",
")",
"{",
"return",
"new",
"Pluf_HTTP_Response_File",
"(",
"$",
"tenantResource",
"->",
"getAbsloutPath",
"(",
")",
",",
"$",
"tenantResource",
"->",
"mime_type",
")",
";",
"}",
"// [OR] check for default spa",
"$",
"name",
"=",
"Tenant_Service",
"::",
"setting",
"(",
"'spa.default'",
",",
"'not-found'",
")",
";",
"$",
"spa",
"=",
"Tenant_SPA",
"::",
"getSpaByName",
"(",
"$",
"name",
")",
";",
"if",
"(",
"$",
"spa",
"===",
"null",
")",
"{",
"$",
"spa",
"=",
"Tenant_SpaService",
"::",
"getNotfoundSpa",
"(",
")",
";",
"$",
"spaName",
"=",
"'not-found'",
";",
"}",
"else",
"{",
"$",
"spaName",
"=",
"null",
";",
"}",
"}",
"if",
"(",
"preg_match",
"(",
"'/.+\\.[a-zA-Z0-9]+$/'",
",",
"$",
"path",
")",
")",
"{",
"// Looking for file in SPA",
"$",
"resPath",
"=",
"$",
"spa",
"->",
"getResourcePath",
"(",
"$",
"path",
")",
";",
"$",
"isMain",
"=",
"false",
";",
"}",
"else",
"{",
"// [OR]Request is for main file (path is an internal state)",
"$",
"resPath",
"=",
"$",
"spa",
"->",
"getMainPagePath",
"(",
")",
";",
"$",
"isMain",
"=",
"true",
";",
"}",
"if",
"(",
"$",
"isMain",
")",
"{",
"return",
"new",
"Tenant_HTTP_Response_SpaMain",
"(",
"$",
"resPath",
",",
"Pluf_FileUtil",
"::",
"getMimeType",
"(",
"$",
"resPath",
")",
",",
"$",
"spaName",
")",
";",
"}",
"else",
"{",
"return",
"new",
"Pluf_HTTP_Response_File",
"(",
"$",
"resPath",
",",
"Pluf_FileUtil",
"::",
"getMimeType",
"(",
"$",
"resPath",
")",
")",
";",
"}",
"}"
] | Load a resource from SPA
@param Pluf_HTTP_Request $request
@param array $match
@return Pluf_HTTP_Response_File|Pluf_HTTP_Response | [
"Load",
"a",
"resource",
"from",
"SPA"
] | a06359c52b9a257b5a0a186264e8770acfc54b73 | https://github.com/pluf/tenant/blob/a06359c52b9a257b5a0a186264e8770acfc54b73/src/Tenant/Views/SpaRun.php#L81-L130 | train |
pluf/tenant | src/Tenant/Views/SpaRun.php | Tenant_Views_SpaRun.findTenantResource | private function findTenantResource($path)
{
$q = new Pluf_SQL('path=%s', array(
$path
));
$item = new Tenant_Resource();
$item = $item->getList(array(
'filter' => $q->gen()
));
if (isset($item) && $item->count() == 1) {
return $item[0];
}
return null;
} | php | private function findTenantResource($path)
{
$q = new Pluf_SQL('path=%s', array(
$path
));
$item = new Tenant_Resource();
$item = $item->getList(array(
'filter' => $q->gen()
));
if (isset($item) && $item->count() == 1) {
return $item[0];
}
return null;
} | [
"private",
"function",
"findTenantResource",
"(",
"$",
"path",
")",
"{",
"$",
"q",
"=",
"new",
"Pluf_SQL",
"(",
"'path=%s'",
",",
"array",
"(",
"$",
"path",
")",
")",
";",
"$",
"item",
"=",
"new",
"Tenant_Resource",
"(",
")",
";",
"$",
"item",
"=",
"$",
"item",
"->",
"getList",
"(",
"array",
"(",
"'filter'",
"=>",
"$",
"q",
"->",
"gen",
"(",
")",
")",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"item",
")",
"&&",
"$",
"item",
"->",
"count",
"(",
")",
"==",
"1",
")",
"{",
"return",
"$",
"item",
"[",
"0",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Finds tenant resource with path
@param string $path
of the resource
@return Tenant_Resource the resource | [
"Finds",
"tenant",
"resource",
"with",
"path"
] | a06359c52b9a257b5a0a186264e8770acfc54b73 | https://github.com/pluf/tenant/blob/a06359c52b9a257b5a0a186264e8770acfc54b73/src/Tenant/Views/SpaRun.php#L139-L152 | train |
balintsera/evista-perform | src/Form/TranspiledForm.php | TranspiledForm.transpile | public function transpile()
{
// Form
/**
* @var Form form
*/
$this->form = $this->transpiler->instantiateFormObject();
// Fields
$fields = $this->transpiler->findFields();
if (!is_array($fields)) {
throw new \Exception("No fields found");
}
$this->form->addFields($fields);
// Populate
$this->form->populateFields();
// Validate
$this->form->validate();
return $this->form;
} | php | public function transpile()
{
// Form
/**
* @var Form form
*/
$this->form = $this->transpiler->instantiateFormObject();
// Fields
$fields = $this->transpiler->findFields();
if (!is_array($fields)) {
throw new \Exception("No fields found");
}
$this->form->addFields($fields);
// Populate
$this->form->populateFields();
// Validate
$this->form->validate();
return $this->form;
} | [
"public",
"function",
"transpile",
"(",
")",
"{",
"// Form",
"/**\n * @var Form form\n*/",
"$",
"this",
"->",
"form",
"=",
"$",
"this",
"->",
"transpiler",
"->",
"instantiateFormObject",
"(",
")",
";",
"// Fields",
"$",
"fields",
"=",
"$",
"this",
"->",
"transpiler",
"->",
"findFields",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"fields",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"No fields found\"",
")",
";",
"}",
"$",
"this",
"->",
"form",
"->",
"addFields",
"(",
"$",
"fields",
")",
";",
"// Populate",
"$",
"this",
"->",
"form",
"->",
"populateFields",
"(",
")",
";",
"// Validate",
"$",
"this",
"->",
"form",
"->",
"validate",
"(",
")",
";",
"return",
"$",
"this",
"->",
"form",
";",
"}"
] | Convert a markup to a BaseForm objet
@return mixed | [
"Convert",
"a",
"markup",
"to",
"a",
"BaseForm",
"objet"
] | 2b8723852ebe824ed721f30293e1e0d2c14f4b21 | https://github.com/balintsera/evista-perform/blob/2b8723852ebe824ed721f30293e1e0d2c14f4b21/src/Form/TranspiledForm.php#L38-L62 | train |
larakit/lk-validatebuilder | src/ValidateBuilder.php | ValidateBuilder.ruleBefore | function ruleBefore($date, $error_message = null) {
if (!strtotime($date)) {
throw new \Exception('Incorrect date');
}
return $this->_rule('before:' . $date, $error_message);
} | php | function ruleBefore($date, $error_message = null) {
if (!strtotime($date)) {
throw new \Exception('Incorrect date');
}
return $this->_rule('before:' . $date, $error_message);
} | [
"function",
"ruleBefore",
"(",
"$",
"date",
",",
"$",
"error_message",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"strtotime",
"(",
"$",
"date",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Incorrect date'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_rule",
"(",
"'before:'",
".",
"$",
"date",
",",
"$",
"error_message",
")",
";",
"}"
] | The field under validation must be a value preceding the given date. The dates will be passed into the PHP strtotime function.
@param $date
@param null $error_message
@return ValidateBuilder
@throws \Exception | [
"The",
"field",
"under",
"validation",
"must",
"be",
"a",
"value",
"preceding",
"the",
"given",
"date",
".",
"The",
"dates",
"will",
"be",
"passed",
"into",
"the",
"PHP",
"strtotime",
"function",
"."
] | 6cee7ccd3df570e9b043975859aad7ee501e5ab9 | https://github.com/larakit/lk-validatebuilder/blob/6cee7ccd3df570e9b043975859aad7ee501e5ab9/src/ValidateBuilder.php#L409-L415 | train |
larakit/lk-validatebuilder | src/ValidateBuilder.php | ValidateBuilder.ruleBetween | function ruleBetween($min, $max, $error_message = null) {
if (!is_numeric($min)) {
throw new \Exception('Incorrect parameter MIN in rule between');
}
if (!is_numeric($max)) {
throw new \Exception('Incorrect parameter MAX in rule between');
}
return $this->_rule('between:' . $min . ',' . $max, $error_message);
} | php | function ruleBetween($min, $max, $error_message = null) {
if (!is_numeric($min)) {
throw new \Exception('Incorrect parameter MIN in rule between');
}
if (!is_numeric($max)) {
throw new \Exception('Incorrect parameter MAX in rule between');
}
return $this->_rule('between:' . $min . ',' . $max, $error_message);
} | [
"function",
"ruleBetween",
"(",
"$",
"min",
",",
"$",
"max",
",",
"$",
"error_message",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"min",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Incorrect parameter MIN in rule between'",
")",
";",
"}",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"max",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Incorrect parameter MAX in rule between'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_rule",
"(",
"'between:'",
".",
"$",
"min",
".",
"','",
".",
"$",
"max",
",",
"$",
"error_message",
")",
";",
"}"
] | The field under validation must have a size between the given min and max. Strings, numerics, and files are evaluated in the same fashion as the size rule.
@param int $min
@param int $max
@param null $error_message
@return ValidateBuilder
@throws \Exception | [
"The",
"field",
"under",
"validation",
"must",
"have",
"a",
"size",
"between",
"the",
"given",
"min",
"and",
"max",
".",
"Strings",
"numerics",
"and",
"files",
"are",
"evaluated",
"in",
"the",
"same",
"fashion",
"as",
"the",
"size",
"rule",
"."
] | 6cee7ccd3df570e9b043975859aad7ee501e5ab9 | https://github.com/larakit/lk-validatebuilder/blob/6cee7ccd3df570e9b043975859aad7ee501e5ab9/src/ValidateBuilder.php#L457-L466 | train |
larakit/lk-validatebuilder | src/ValidateBuilder.php | ValidateBuilder.ruleMin | function ruleMin($min, $error_message = null) {
if (!is_numeric($min)) {
throw new \Exception('Incorrect parameter MIN in rule min');
}
return $this->_rule('min:' . $min, $error_message);
} | php | function ruleMin($min, $error_message = null) {
if (!is_numeric($min)) {
throw new \Exception('Incorrect parameter MIN in rule min');
}
return $this->_rule('min:' . $min, $error_message);
} | [
"function",
"ruleMin",
"(",
"$",
"min",
",",
"$",
"error_message",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"min",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Incorrect parameter MIN in rule min'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_rule",
"(",
"'min:'",
".",
"$",
"min",
",",
"$",
"error_message",
")",
";",
"}"
] | The field under validation must have a minimum value. Strings, numerics, and files are evaluated in the same fashion as the size rule.
@param $min
@param null $error_message
@return ValidateBuilder
@throws \Exception | [
"The",
"field",
"under",
"validation",
"must",
"have",
"a",
"minimum",
"value",
".",
"Strings",
"numerics",
"and",
"files",
"are",
"evaluated",
"in",
"the",
"same",
"fashion",
"as",
"the",
"size",
"rule",
"."
] | 6cee7ccd3df570e9b043975859aad7ee501e5ab9 | https://github.com/larakit/lk-validatebuilder/blob/6cee7ccd3df570e9b043975859aad7ee501e5ab9/src/ValidateBuilder.php#L1075-L1081 | train |
larakit/lk-validatebuilder | src/ValidateBuilder.php | ValidateBuilder.ruleRequiredIf | function ruleRequiredIf($anotherfield, $value, $error_message = null) {
return $this->_rule('required_if:' . $anotherfield . ',' . $value, $error_message);
} | php | function ruleRequiredIf($anotherfield, $value, $error_message = null) {
return $this->_rule('required_if:' . $anotherfield . ',' . $value, $error_message);
} | [
"function",
"ruleRequiredIf",
"(",
"$",
"anotherfield",
",",
"$",
"value",
",",
"$",
"error_message",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_rule",
"(",
"'required_if:'",
".",
"$",
"anotherfield",
".",
"','",
".",
"$",
"value",
",",
"$",
"error_message",
")",
";",
"}"
] | The field under validation must be present if the anotherfield field is equal to any value.
@param $anotherfield
@param $value
@param null $error_message
@return ValidateBuilder
@throws \Exception | [
"The",
"field",
"under",
"validation",
"must",
"be",
"present",
"if",
"the",
"anotherfield",
"field",
"is",
"equal",
"to",
"any",
"value",
"."
] | 6cee7ccd3df570e9b043975859aad7ee501e5ab9 | https://github.com/larakit/lk-validatebuilder/blob/6cee7ccd3df570e9b043975859aad7ee501e5ab9/src/ValidateBuilder.php#L1217-L1219 | train |
larakit/lk-validatebuilder | src/ValidateBuilder.php | ValidateBuilder.ruleRequiredUnless | function ruleRequiredUnless($anotherfield, $value, $error_message = null) {
return $this->_rule('required_unless:' . $anotherfield . ',' . $value, $error_message);
} | php | function ruleRequiredUnless($anotherfield, $value, $error_message = null) {
return $this->_rule('required_unless:' . $anotherfield . ',' . $value, $error_message);
} | [
"function",
"ruleRequiredUnless",
"(",
"$",
"anotherfield",
",",
"$",
"value",
",",
"$",
"error_message",
"=",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_rule",
"(",
"'required_unless:'",
".",
"$",
"anotherfield",
".",
"','",
".",
"$",
"value",
",",
"$",
"error_message",
")",
";",
"}"
] | The field under validation must be present unless the anotherfield field is equal to any value.
@param $anotherfield
@param $value
@param null $error_message
@return ValidateBuilder
@throws \Exception | [
"The",
"field",
"under",
"validation",
"must",
"be",
"present",
"unless",
"the",
"anotherfield",
"field",
"is",
"equal",
"to",
"any",
"value",
"."
] | 6cee7ccd3df570e9b043975859aad7ee501e5ab9 | https://github.com/larakit/lk-validatebuilder/blob/6cee7ccd3df570e9b043975859aad7ee501e5ab9/src/ValidateBuilder.php#L1241-L1243 | train |
larakit/lk-validatebuilder | src/ValidateBuilder.php | ValidateBuilder.ruleRequiredWith | function ruleRequiredWith($anotherfields, $error_message = null) {
if (is_array($anotherfields)) {
$anotherfields = implode(',', $anotherfields);
}
return $this->_rule('required_with:' . $anotherfields, $error_message);
} | php | function ruleRequiredWith($anotherfields, $error_message = null) {
if (is_array($anotherfields)) {
$anotherfields = implode(',', $anotherfields);
}
return $this->_rule('required_with:' . $anotherfields, $error_message);
} | [
"function",
"ruleRequiredWith",
"(",
"$",
"anotherfields",
",",
"$",
"error_message",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"anotherfields",
")",
")",
"{",
"$",
"anotherfields",
"=",
"implode",
"(",
"','",
",",
"$",
"anotherfields",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_rule",
"(",
"'required_with:'",
".",
"$",
"anotherfields",
",",
"$",
"error_message",
")",
";",
"}"
] | The field under validation must be present only if any of the other specified fields are present.
@param $anotherfield
@param $value
@param null $error_message
@return ValidateBuilder
@throws \Exception | [
"The",
"field",
"under",
"validation",
"must",
"be",
"present",
"only",
"if",
"any",
"of",
"the",
"other",
"specified",
"fields",
"are",
"present",
"."
] | 6cee7ccd3df570e9b043975859aad7ee501e5ab9 | https://github.com/larakit/lk-validatebuilder/blob/6cee7ccd3df570e9b043975859aad7ee501e5ab9/src/ValidateBuilder.php#L1265-L1271 | train |
larakit/lk-validatebuilder | src/ValidateBuilder.php | ValidateBuilder.ruleRequiredWithout | function ruleRequiredWithout($anotherfields, $error_message = null) {
if (is_array($anotherfields)) {
$anotherfields = implode(',', $anotherfields);
}
return $this->_rule('required_without:' . $anotherfields, $error_message);
} | php | function ruleRequiredWithout($anotherfields, $error_message = null) {
if (is_array($anotherfields)) {
$anotherfields = implode(',', $anotherfields);
}
return $this->_rule('required_without:' . $anotherfields, $error_message);
} | [
"function",
"ruleRequiredWithout",
"(",
"$",
"anotherfields",
",",
"$",
"error_message",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"anotherfields",
")",
")",
"{",
"$",
"anotherfields",
"=",
"implode",
"(",
"','",
",",
"$",
"anotherfields",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_rule",
"(",
"'required_without:'",
".",
"$",
"anotherfields",
",",
"$",
"error_message",
")",
";",
"}"
] | The field under validation must be present only when any of the other specified fields are not present.
@param $anotherfields
@param null $error_message
@return ValidateBuilder
@throws \Exception | [
"The",
"field",
"under",
"validation",
"must",
"be",
"present",
"only",
"when",
"any",
"of",
"the",
"other",
"specified",
"fields",
"are",
"not",
"present",
"."
] | 6cee7ccd3df570e9b043975859aad7ee501e5ab9 | https://github.com/larakit/lk-validatebuilder/blob/6cee7ccd3df570e9b043975859aad7ee501e5ab9/src/ValidateBuilder.php#L1315-L1321 | train |
larakit/lk-validatebuilder | src/ValidateBuilder.php | ValidateBuilder.ruleRequiredWithoutAll | function ruleRequiredWithoutAll($anotherfields, $error_message = null) {
if (is_array($anotherfields)) {
$anotherfields = implode(',', $anotherfields);
}
return $this->_rule('required_without_all:' . $anotherfields, $error_message);
} | php | function ruleRequiredWithoutAll($anotherfields, $error_message = null) {
if (is_array($anotherfields)) {
$anotherfields = implode(',', $anotherfields);
}
return $this->_rule('required_without_all:' . $anotherfields, $error_message);
} | [
"function",
"ruleRequiredWithoutAll",
"(",
"$",
"anotherfields",
",",
"$",
"error_message",
"=",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"anotherfields",
")",
")",
"{",
"$",
"anotherfields",
"=",
"implode",
"(",
"','",
",",
"$",
"anotherfields",
")",
";",
"}",
"return",
"$",
"this",
"->",
"_rule",
"(",
"'required_without_all:'",
".",
"$",
"anotherfields",
",",
"$",
"error_message",
")",
";",
"}"
] | The field under validation must be present only when all of the other specified fields are not present.
@param $anotherfields
@param null $error_message
@return ValidateBuilder
@throws \Exception | [
"The",
"field",
"under",
"validation",
"must",
"be",
"present",
"only",
"when",
"all",
"of",
"the",
"other",
"specified",
"fields",
"are",
"not",
"present",
"."
] | 6cee7ccd3df570e9b043975859aad7ee501e5ab9 | https://github.com/larakit/lk-validatebuilder/blob/6cee7ccd3df570e9b043975859aad7ee501e5ab9/src/ValidateBuilder.php#L1342-L1348 | train |
LartTyler/PHP-DaybreakCommons | src/DaybreakStudios/Common/DateTime/AbstractDateTimeAwareComparator.php | AbstractDateTimeAwareComparator.copyAndNormalize | protected function copyAndNormalize(/* ... $args */) {
if ($this->utcTimezone === null)
$this->utcTimezone = new DateTimeZone('UTC');
$args = func_get_args();
foreach ($args as $i => $dt)
if ($dt instanceof DateTime) {
$dt = clone $dt;
$dt->setTimezone($this->utcTimezone);
$args[$i] = $dt;
} else
throw new InvalidArgumentException('All arguments must be DateTime objects');
return $args;
} | php | protected function copyAndNormalize(/* ... $args */) {
if ($this->utcTimezone === null)
$this->utcTimezone = new DateTimeZone('UTC');
$args = func_get_args();
foreach ($args as $i => $dt)
if ($dt instanceof DateTime) {
$dt = clone $dt;
$dt->setTimezone($this->utcTimezone);
$args[$i] = $dt;
} else
throw new InvalidArgumentException('All arguments must be DateTime objects');
return $args;
} | [
"protected",
"function",
"copyAndNormalize",
"(",
"/* ... $args */",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"utcTimezone",
"===",
"null",
")",
"$",
"this",
"->",
"utcTimezone",
"=",
"new",
"DateTimeZone",
"(",
"'UTC'",
")",
";",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"args",
"as",
"$",
"i",
"=>",
"$",
"dt",
")",
"if",
"(",
"$",
"dt",
"instanceof",
"DateTime",
")",
"{",
"$",
"dt",
"=",
"clone",
"$",
"dt",
";",
"$",
"dt",
"->",
"setTimezone",
"(",
"$",
"this",
"->",
"utcTimezone",
")",
";",
"$",
"args",
"[",
"$",
"i",
"]",
"=",
"$",
"dt",
";",
"}",
"else",
"throw",
"new",
"InvalidArgumentException",
"(",
"'All arguments must be DateTime objects'",
")",
";",
"return",
"$",
"args",
";",
"}"
] | Copies any number of DateTime objects and normalizes their timezones.
@param DateTime $args,... a varargs list of DateTime objects
@return array an array containing the cloned and normalized DateTime objects | [
"Copies",
"any",
"number",
"of",
"DateTime",
"objects",
"and",
"normalizes",
"their",
"timezones",
"."
] | db25b5d6cea9b5a1d5afc4c5548a2cbc3018bc0d | https://github.com/LartTyler/PHP-DaybreakCommons/blob/db25b5d6cea9b5a1d5afc4c5548a2cbc3018bc0d/src/DaybreakStudios/Common/DateTime/AbstractDateTimeAwareComparator.php#L34-L51 | train |
AuronConsultingOSS/PhpConsoleLogger | src/Console.php | Console.log | public function log($level, $message, array $context = [])
{
// Do not allow users to supply nonsense on the log level
if (array_key_exists($level, $this->logPrefixesPerLevel) === false) {
throw new InvalidArgumentException('Console method not recognised');
}
// Parse message into a string we can use
$parsedMessage = $this->parseMessage($message);
// Examine context, and alter the message accordingly
$parsedMessage .= $this->parseContext($context);
// Speak!
$this->output($this->format($level, $parsedMessage));
} | php | public function log($level, $message, array $context = [])
{
// Do not allow users to supply nonsense on the log level
if (array_key_exists($level, $this->logPrefixesPerLevel) === false) {
throw new InvalidArgumentException('Console method not recognised');
}
// Parse message into a string we can use
$parsedMessage = $this->parseMessage($message);
// Examine context, and alter the message accordingly
$parsedMessage .= $this->parseContext($context);
// Speak!
$this->output($this->format($level, $parsedMessage));
} | [
"public",
"function",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"array",
"$",
"context",
"=",
"[",
"]",
")",
"{",
"// Do not allow users to supply nonsense on the log level",
"if",
"(",
"array_key_exists",
"(",
"$",
"level",
",",
"$",
"this",
"->",
"logPrefixesPerLevel",
")",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Console method not recognised'",
")",
";",
"}",
"// Parse message into a string we can use",
"$",
"parsedMessage",
"=",
"$",
"this",
"->",
"parseMessage",
"(",
"$",
"message",
")",
";",
"// Examine context, and alter the message accordingly",
"$",
"parsedMessage",
".=",
"$",
"this",
"->",
"parseContext",
"(",
"$",
"context",
")",
";",
"// Speak!",
"$",
"this",
"->",
"output",
"(",
"$",
"this",
"->",
"format",
"(",
"$",
"level",
",",
"$",
"parsedMessage",
")",
")",
";",
"}"
] | Logs to an arbitrary log level.
We only recognise info/notice/debug/warning/alert/error/emergency/critical levels, anything else will
throw an InvalidArgumentException. Please provide log level via Psr\Log\LogLevel constants to ensure goodness.
Message must be a string-able value.
Context is optional and can contain any arbitrary data as an array. If providing an exception, you MUST provide
it within a key of 'exception'.
@see: http://www.php-fig.org/psr/psr-3/#1-2-message
@see: http://www.php-fig.org/psr/psr-3/#1-3-context
@param mixed $level
@param string $message
@param array $context
@return void
@throws InvalidArgumentException | [
"Logs",
"to",
"an",
"arbitrary",
"log",
"level",
"."
] | 312fae19b9cf8dfa3237f9ca24d18b8da85043ef | https://github.com/AuronConsultingOSS/PhpConsoleLogger/blob/312fae19b9cf8dfa3237f9ca24d18b8da85043ef/src/Console.php#L63-L78 | train |
AuronConsultingOSS/PhpConsoleLogger | src/Console.php | Console.parseMessage | private function parseMessage($message)
{
$parsedMessage = null;
/**
* According to PSR-3 we can accept string-like values (eg stuff we can parse easily into a string, such as obviously
* strings and numbers, and objects that can be cast to strings).
*/
switch (gettype($message)) {
case 'boolean':
case 'integer':
case 'double':
case 'string':
case 'NULL':
$parsedMessage = (string) $message;
break;
case 'object':
if (method_exists($message, '__toString') !== false) {
$parsedMessage = (string) $message;
break;
}
// Otherwise, go on to default below
default:
throw new InvalidArgumentException('Message can only be a string, number or an object which can be cast to a string');
}
return $parsedMessage;
} | php | private function parseMessage($message)
{
$parsedMessage = null;
/**
* According to PSR-3 we can accept string-like values (eg stuff we can parse easily into a string, such as obviously
* strings and numbers, and objects that can be cast to strings).
*/
switch (gettype($message)) {
case 'boolean':
case 'integer':
case 'double':
case 'string':
case 'NULL':
$parsedMessage = (string) $message;
break;
case 'object':
if (method_exists($message, '__toString') !== false) {
$parsedMessage = (string) $message;
break;
}
// Otherwise, go on to default below
default:
throw new InvalidArgumentException('Message can only be a string, number or an object which can be cast to a string');
}
return $parsedMessage;
} | [
"private",
"function",
"parseMessage",
"(",
"$",
"message",
")",
"{",
"$",
"parsedMessage",
"=",
"null",
";",
"/**\n * According to PSR-3 we can accept string-like values (eg stuff we can parse easily into a string, such as obviously\n * strings and numbers, and objects that can be cast to strings).\n */",
"switch",
"(",
"gettype",
"(",
"$",
"message",
")",
")",
"{",
"case",
"'boolean'",
":",
"case",
"'integer'",
":",
"case",
"'double'",
":",
"case",
"'string'",
":",
"case",
"'NULL'",
":",
"$",
"parsedMessage",
"=",
"(",
"string",
")",
"$",
"message",
";",
"break",
";",
"case",
"'object'",
":",
"if",
"(",
"method_exists",
"(",
"$",
"message",
",",
"'__toString'",
")",
"!==",
"false",
")",
"{",
"$",
"parsedMessage",
"=",
"(",
"string",
")",
"$",
"message",
";",
"break",
";",
"}",
"// Otherwise, go on to default below",
"default",
":",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Message can only be a string, number or an object which can be cast to a string'",
")",
";",
"}",
"return",
"$",
"parsedMessage",
";",
"}"
] | Parses the log message and returns as a useable string, or Psr\Log\InvalidArgumentException if non parseable.
We only recognise info/notice/debug/warning/alert/error/emergency/critical levels, anything else will
throw an InvalidArgumentException.
@param mixed $message
@return string
@throws InvalidArgumentException
@see: http://www.php-fig.org/psr/psr-3/#1-2-message | [
"Parses",
"the",
"log",
"message",
"and",
"returns",
"as",
"a",
"useable",
"string",
"or",
"Psr",
"\\",
"Log",
"\\",
"InvalidArgumentException",
"if",
"non",
"parseable",
"."
] | 312fae19b9cf8dfa3237f9ca24d18b8da85043ef | https://github.com/AuronConsultingOSS/PhpConsoleLogger/blob/312fae19b9cf8dfa3237f9ca24d18b8da85043ef/src/Console.php#L94-L123 | train |
cubicmushroom/routing-annotations | src/Parser/DocumentationAnnotationParser.php | DocumentationAnnotationParser.parse | public function parse(array $classes)
{
$APIAnnotations = [];
foreach ($classes as $class) {
$reflectionClass = new \ReflectionClass($class);
foreach ($reflectionClass->getMethods() as $reflectionMethod) {
$annotations = $this->getReader()->getMethodAnnotations($reflectionMethod);
if (!empty($annotations)) {
foreach ($annotations as $annotation) {
switch (true) {
case ($annotation instanceof Route):
$APIAnnotations[$class][$reflectionMethod->getName()]['routes'][] = $annotation;
break;
case ($annotation instanceof ResponseBody):
$APIAnnotations[$class][$reflectionMethod->getName()]['requestBody'][] = $annotation;
break;
case ($annotation instanceof RequestBody):
$APIAnnotations[$class][$reflectionMethod->getName()]['responseBody'][] = $annotation;
break;
default:
// Do nothing
}
}
}
}
}
return $APIAnnotations;
} | php | public function parse(array $classes)
{
$APIAnnotations = [];
foreach ($classes as $class) {
$reflectionClass = new \ReflectionClass($class);
foreach ($reflectionClass->getMethods() as $reflectionMethod) {
$annotations = $this->getReader()->getMethodAnnotations($reflectionMethod);
if (!empty($annotations)) {
foreach ($annotations as $annotation) {
switch (true) {
case ($annotation instanceof Route):
$APIAnnotations[$class][$reflectionMethod->getName()]['routes'][] = $annotation;
break;
case ($annotation instanceof ResponseBody):
$APIAnnotations[$class][$reflectionMethod->getName()]['requestBody'][] = $annotation;
break;
case ($annotation instanceof RequestBody):
$APIAnnotations[$class][$reflectionMethod->getName()]['responseBody'][] = $annotation;
break;
default:
// Do nothing
}
}
}
}
}
return $APIAnnotations;
} | [
"public",
"function",
"parse",
"(",
"array",
"$",
"classes",
")",
"{",
"$",
"APIAnnotations",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"classes",
"as",
"$",
"class",
")",
"{",
"$",
"reflectionClass",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"class",
")",
";",
"foreach",
"(",
"$",
"reflectionClass",
"->",
"getMethods",
"(",
")",
"as",
"$",
"reflectionMethod",
")",
"{",
"$",
"annotations",
"=",
"$",
"this",
"->",
"getReader",
"(",
")",
"->",
"getMethodAnnotations",
"(",
"$",
"reflectionMethod",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"annotations",
")",
")",
"{",
"foreach",
"(",
"$",
"annotations",
"as",
"$",
"annotation",
")",
"{",
"switch",
"(",
"true",
")",
"{",
"case",
"(",
"$",
"annotation",
"instanceof",
"Route",
")",
":",
"$",
"APIAnnotations",
"[",
"$",
"class",
"]",
"[",
"$",
"reflectionMethod",
"->",
"getName",
"(",
")",
"]",
"[",
"'routes'",
"]",
"[",
"]",
"=",
"$",
"annotation",
";",
"break",
";",
"case",
"(",
"$",
"annotation",
"instanceof",
"ResponseBody",
")",
":",
"$",
"APIAnnotations",
"[",
"$",
"class",
"]",
"[",
"$",
"reflectionMethod",
"->",
"getName",
"(",
")",
"]",
"[",
"'requestBody'",
"]",
"[",
"]",
"=",
"$",
"annotation",
";",
"break",
";",
"case",
"(",
"$",
"annotation",
"instanceof",
"RequestBody",
")",
":",
"$",
"APIAnnotations",
"[",
"$",
"class",
"]",
"[",
"$",
"reflectionMethod",
"->",
"getName",
"(",
")",
"]",
"[",
"'responseBody'",
"]",
"[",
"]",
"=",
"$",
"annotation",
";",
"break",
";",
"default",
":",
"// Do nothing",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"APIAnnotations",
";",
"}"
] | Parses the files provided by the SeekableIterator
@param array $classes Array of classes to parse
@return array | [
"Parses",
"the",
"files",
"provided",
"by",
"the",
"SeekableIterator"
] | e8ea0b8c55b7d4ca42baeca64302e8d8ae573408 | https://github.com/cubicmushroom/routing-annotations/blob/e8ea0b8c55b7d4ca42baeca64302e8d8ae573408/src/Parser/DocumentationAnnotationParser.php#L60-L94 | train |
fridge-project/dbal | src/Fridge/DBAL/Query/Rewriter/AbstractQueryRewriter.php | AbstractQueryRewriter.extractType | protected static function extractType($type)
{
if (substr($type, -2) === Connection::PARAM_ARRAY) {
return substr($type, 0, strlen($type) - 2);
}
return false;
} | php | protected static function extractType($type)
{
if (substr($type, -2) === Connection::PARAM_ARRAY) {
return substr($type, 0, strlen($type) - 2);
}
return false;
} | [
"protected",
"static",
"function",
"extractType",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"substr",
"(",
"$",
"type",
",",
"-",
"2",
")",
"===",
"Connection",
"::",
"PARAM_ARRAY",
")",
"{",
"return",
"substr",
"(",
"$",
"type",
",",
"0",
",",
"strlen",
"(",
"$",
"type",
")",
"-",
"2",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Extracts the fridge type from the expanded type.
@param string $type The type.
@return string|boolean The fridge type or false if the type is not an expanded one. | [
"Extracts",
"the",
"fridge",
"type",
"from",
"the",
"expanded",
"type",
"."
] | d0b8c3551922d696836487aa0eb1bd74014edcd4 | https://github.com/fridge-project/dbal/blob/d0b8c3551922d696836487aa0eb1bd74014edcd4/src/Fridge/DBAL/Query/Rewriter/AbstractQueryRewriter.php#L30-L37 | train |
sourceboxio/sdk | src/Register/Register.php | Register.autoload | public static function autoload()
{
// Vendor path
$dir_base = realpath(__DIR__ . '/../../../../');
$finder = new Finder();
$finder->files()
->ignoreVCS(true)
->ignoreDotFiles(false)
->name('service.yml')
->exclude('Tests')
->exclude('tests')
->in($dir_base);
foreach ($finder as $file) {
self::autoloadFile($file);
}
} | php | public static function autoload()
{
// Vendor path
$dir_base = realpath(__DIR__ . '/../../../../');
$finder = new Finder();
$finder->files()
->ignoreVCS(true)
->ignoreDotFiles(false)
->name('service.yml')
->exclude('Tests')
->exclude('tests')
->in($dir_base);
foreach ($finder as $file) {
self::autoloadFile($file);
}
} | [
"public",
"static",
"function",
"autoload",
"(",
")",
"{",
"// Vendor path",
"$",
"dir_base",
"=",
"realpath",
"(",
"__DIR__",
".",
"'/../../../../'",
")",
";",
"$",
"finder",
"=",
"new",
"Finder",
"(",
")",
";",
"$",
"finder",
"->",
"files",
"(",
")",
"->",
"ignoreVCS",
"(",
"true",
")",
"->",
"ignoreDotFiles",
"(",
"false",
")",
"->",
"name",
"(",
"'service.yml'",
")",
"->",
"exclude",
"(",
"'Tests'",
")",
"->",
"exclude",
"(",
"'tests'",
")",
"->",
"in",
"(",
"$",
"dir_base",
")",
";",
"foreach",
"(",
"$",
"finder",
"as",
"$",
"file",
")",
"{",
"self",
"::",
"autoloadFile",
"(",
"$",
"file",
")",
";",
"}",
"}"
] | Auto register services.
@return void | [
"Auto",
"register",
"services",
"."
] | e16e9e92580d48c2a348d119c2829a8d38528681 | https://github.com/sourceboxio/sdk/blob/e16e9e92580d48c2a348d119c2829a8d38528681/src/Register/Register.php#L42-L59 | train |
sourceboxio/sdk | src/Register/Register.php | Register.autoloadFile | protected static function autoloadFile(SplFileInfo $file)
{
$yml = Yaml::parse(file_get_contents($file->getRealPath()), true);
$service = Arr::get($yml, 'micro-service');
if (is_null($service)) {
return;
}
sbox()->add(new MicroService($service, $yml));
} | php | protected static function autoloadFile(SplFileInfo $file)
{
$yml = Yaml::parse(file_get_contents($file->getRealPath()), true);
$service = Arr::get($yml, 'micro-service');
if (is_null($service)) {
return;
}
sbox()->add(new MicroService($service, $yml));
} | [
"protected",
"static",
"function",
"autoloadFile",
"(",
"SplFileInfo",
"$",
"file",
")",
"{",
"$",
"yml",
"=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"file",
"->",
"getRealPath",
"(",
")",
")",
",",
"true",
")",
";",
"$",
"service",
"=",
"Arr",
"::",
"get",
"(",
"$",
"yml",
",",
"'micro-service'",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"service",
")",
")",
"{",
"return",
";",
"}",
"sbox",
"(",
")",
"->",
"add",
"(",
"new",
"MicroService",
"(",
"$",
"service",
",",
"$",
"yml",
")",
")",
";",
"}"
] | Carregar arquivo.
@param SplFileInfo $file
@return void | [
"Carregar",
"arquivo",
"."
] | e16e9e92580d48c2a348d119c2829a8d38528681 | https://github.com/sourceboxio/sdk/blob/e16e9e92580d48c2a348d119c2829a8d38528681/src/Register/Register.php#L66-L76 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.