repo
stringlengths 6
63
| path
stringlengths 5
140
| func_name
stringlengths 3
151
| original_string
stringlengths 84
13k
| language
stringclasses 1
value | code
stringlengths 84
13k
| code_tokens
list | docstring
stringlengths 3
47.2k
| docstring_tokens
list | sha
stringlengths 40
40
| url
stringlengths 91
247
| partition
stringclasses 1
value |
---|---|---|---|---|---|---|---|---|---|---|---|
SysCodeSoft/Sofi-Router | src/Route.php | Route.route | function route($path = '/', array $actions = [], $method = Router::ANY_METHOD, $name = '')
{
$this->path($path);
$this->actions[$method] = $actions;
$this->name = $name;
return $this;
} | php | function route($path = '/', array $actions = [], $method = Router::ANY_METHOD, $name = '')
{
$this->path($path);
$this->actions[$method] = $actions;
$this->name = $name;
return $this;
} | [
"function",
"route",
"(",
"$",
"path",
"=",
"'/'",
",",
"array",
"$",
"actions",
"=",
"[",
"]",
",",
"$",
"method",
"=",
"Router",
"::",
"ANY_METHOD",
",",
"$",
"name",
"=",
"''",
")",
"{",
"$",
"this",
"->",
"path",
"(",
"$",
"path",
")",
";",
"$",
"this",
"->",
"actions",
"[",
"$",
"method",
"]",
"=",
"$",
"actions",
";",
"$",
"this",
"->",
"name",
"=",
"$",
"name",
";",
"return",
"$",
"this",
";",
"}"
] | Set route params
@param string $path Path for parse
@param array $actions Array actions for route
@param int|string $method Request method
@param string $name Alias for route | [
"Set",
"route",
"params"
] | a2fc580d2561a0b18f6ac74e9e0b2a8c68e6559c | https://github.com/SysCodeSoft/Sofi-Router/blob/a2fc580d2561a0b18f6ac74e9e0b2a8c68e6559c/src/Route.php#L46-L53 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Database.php | Database.connect | public function connect() {
if(false === $this -> connection instanceof \mysqli) {
$this -> connection = new \mysqli($this -> data -> host, $this -> data -> username, $this -> data -> password, $this -> data -> db, $this -> data -> port);
if($this -> data -> charset) {
$this -> connection -> set_charset($this -> data -> charset);
}
}
} | php | public function connect() {
if(false === $this -> connection instanceof \mysqli) {
$this -> connection = new \mysqli($this -> data -> host, $this -> data -> username, $this -> data -> password, $this -> data -> db, $this -> data -> port);
if($this -> data -> charset) {
$this -> connection -> set_charset($this -> data -> charset);
}
}
} | [
"public",
"function",
"connect",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"connection",
"instanceof",
"\\",
"mysqli",
")",
"{",
"$",
"this",
"->",
"connection",
"=",
"new",
"\\",
"mysqli",
"(",
"$",
"this",
"->",
"data",
"->",
"host",
",",
"$",
"this",
"->",
"data",
"->",
"username",
",",
"$",
"this",
"->",
"data",
"->",
"password",
",",
"$",
"this",
"->",
"data",
"->",
"db",
",",
"$",
"this",
"->",
"data",
"->",
"port",
")",
";",
"if",
"(",
"$",
"this",
"->",
"data",
"->",
"charset",
")",
"{",
"$",
"this",
"->",
"connection",
"->",
"set_charset",
"(",
"$",
"this",
"->",
"data",
"->",
"charset",
")",
";",
"}",
"}",
"}"
] | Connect to Mysql server and set charset | [
"Connect",
"to",
"Mysql",
"server",
"and",
"set",
"charset"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Database.php#L119-L129 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Database.php | Database.fetch | public function fetch($type = null) {
if(null !== $type && false === is_string($type)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($query)), E_USER_ERROR);
}
$results = new ResultSet([], $type);
//Returns a copy of a value
$copy = function($a) { return $a; };
$amount = count($this -> stmt);
foreach($this -> stmt as $stmt) {
//Execute statement and store results
$stmt = $this -> executeStatement($stmt);
$result = [];
if(false !== $stmt && 0 !== $stmt -> field_count && 0 === $stmt -> errno) {
$vars = $this -> bind($stmt);
while($stmt -> fetch()) {
if($amount === 1) {
$results -> append(array_map($copy, $vars));
}
else {
$result[] = array_map($copy, $vars);
}
}
}
if($amount > 1) {
$results -> append($result);
}
}
$this -> shadow = $this -> stmt;
$this -> reset();
return $results;
} | php | public function fetch($type = null) {
if(null !== $type && false === is_string($type)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($query)), E_USER_ERROR);
}
$results = new ResultSet([], $type);
//Returns a copy of a value
$copy = function($a) { return $a; };
$amount = count($this -> stmt);
foreach($this -> stmt as $stmt) {
//Execute statement and store results
$stmt = $this -> executeStatement($stmt);
$result = [];
if(false !== $stmt && 0 !== $stmt -> field_count && 0 === $stmt -> errno) {
$vars = $this -> bind($stmt);
while($stmt -> fetch()) {
if($amount === 1) {
$results -> append(array_map($copy, $vars));
}
else {
$result[] = array_map($copy, $vars);
}
}
}
if($amount > 1) {
$results -> append($result);
}
}
$this -> shadow = $this -> stmt;
$this -> reset();
return $results;
} | [
"public",
"function",
"fetch",
"(",
"$",
"type",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"type",
"&&",
"false",
"===",
"is_string",
"(",
"$",
"type",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"query",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"results",
"=",
"new",
"ResultSet",
"(",
"[",
"]",
",",
"$",
"type",
")",
";",
"//Returns a copy of a value\r",
"$",
"copy",
"=",
"function",
"(",
"$",
"a",
")",
"{",
"return",
"$",
"a",
";",
"}",
";",
"$",
"amount",
"=",
"count",
"(",
"$",
"this",
"->",
"stmt",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"stmt",
"as",
"$",
"stmt",
")",
"{",
"//Execute statement and store results\r",
"$",
"stmt",
"=",
"$",
"this",
"->",
"executeStatement",
"(",
"$",
"stmt",
")",
";",
"$",
"result",
"=",
"[",
"]",
";",
"if",
"(",
"false",
"!==",
"$",
"stmt",
"&&",
"0",
"!==",
"$",
"stmt",
"->",
"field_count",
"&&",
"0",
"===",
"$",
"stmt",
"->",
"errno",
")",
"{",
"$",
"vars",
"=",
"$",
"this",
"->",
"bind",
"(",
"$",
"stmt",
")",
";",
"while",
"(",
"$",
"stmt",
"->",
"fetch",
"(",
")",
")",
"{",
"if",
"(",
"$",
"amount",
"===",
"1",
")",
"{",
"$",
"results",
"->",
"append",
"(",
"array_map",
"(",
"$",
"copy",
",",
"$",
"vars",
")",
")",
";",
"}",
"else",
"{",
"$",
"result",
"[",
"]",
"=",
"array_map",
"(",
"$",
"copy",
",",
"$",
"vars",
")",
";",
"}",
"}",
"}",
"if",
"(",
"$",
"amount",
">",
"1",
")",
"{",
"$",
"results",
"->",
"append",
"(",
"$",
"result",
")",
";",
"}",
"}",
"$",
"this",
"->",
"shadow",
"=",
"$",
"this",
"->",
"stmt",
";",
"$",
"this",
"->",
"reset",
"(",
")",
";",
"return",
"$",
"results",
";",
"}"
] | Returns results from statement as an result set
@param string $type
@return sFire\Adapter\ResultSet | [
"Returns",
"results",
"from",
"statement",
"as",
"an",
"result",
"set"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Database.php#L227-L269 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Database.php | Database.query | public function query($query, $params = []) {
if(false === is_string($query)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($query)), E_USER_ERROR);
}
if(null !== $params && false === is_array($params)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($params)), E_USER_ERROR);
}
if(null === $this -> connection) {
$this -> connect();
}
$bind = $this -> parse($params, $query);
//Write time for debugging
if(null === $this -> trace) {
$this -> trace = microtime(true);
}
//Prepare statement
$stmt = $this -> connection -> prepare($query);
if(false === $stmt) {
return trigger_error($this -> connection -> error, E_USER_ERROR);
}
if(count($bind) > 0) {
if(false === ($stmt -> param_count == count($bind) - 1)) {
return trigger_error('Number of variable elements query string does not match number of bind variables');
}
call_user_func_array([$stmt, 'bind_param'], $bind);
}
$this -> stmt[] = $stmt;
$this -> shadow = $this -> stmt;
return $this;
} | php | public function query($query, $params = []) {
if(false === is_string($query)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($query)), E_USER_ERROR);
}
if(null !== $params && false === is_array($params)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($params)), E_USER_ERROR);
}
if(null === $this -> connection) {
$this -> connect();
}
$bind = $this -> parse($params, $query);
//Write time for debugging
if(null === $this -> trace) {
$this -> trace = microtime(true);
}
//Prepare statement
$stmt = $this -> connection -> prepare($query);
if(false === $stmt) {
return trigger_error($this -> connection -> error, E_USER_ERROR);
}
if(count($bind) > 0) {
if(false === ($stmt -> param_count == count($bind) - 1)) {
return trigger_error('Number of variable elements query string does not match number of bind variables');
}
call_user_func_array([$stmt, 'bind_param'], $bind);
}
$this -> stmt[] = $stmt;
$this -> shadow = $this -> stmt;
return $this;
} | [
"public",
"function",
"query",
"(",
"$",
"query",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"query",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"query",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"params",
"&&",
"false",
"===",
"is_array",
"(",
"$",
"params",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"params",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"connection",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"$",
"bind",
"=",
"$",
"this",
"->",
"parse",
"(",
"$",
"params",
",",
"$",
"query",
")",
";",
"//Write time for debugging\r",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"trace",
")",
"{",
"$",
"this",
"->",
"trace",
"=",
"microtime",
"(",
"true",
")",
";",
"}",
"//Prepare statement\r",
"$",
"stmt",
"=",
"$",
"this",
"->",
"connection",
"->",
"prepare",
"(",
"$",
"query",
")",
";",
"if",
"(",
"false",
"===",
"$",
"stmt",
")",
"{",
"return",
"trigger_error",
"(",
"$",
"this",
"->",
"connection",
"->",
"error",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"bind",
")",
">",
"0",
")",
"{",
"if",
"(",
"false",
"===",
"(",
"$",
"stmt",
"->",
"param_count",
"==",
"count",
"(",
"$",
"bind",
")",
"-",
"1",
")",
")",
"{",
"return",
"trigger_error",
"(",
"'Number of variable elements query string does not match number of bind variables'",
")",
";",
"}",
"call_user_func_array",
"(",
"[",
"$",
"stmt",
",",
"'bind_param'",
"]",
",",
"$",
"bind",
")",
";",
"}",
"$",
"this",
"->",
"stmt",
"[",
"]",
"=",
"$",
"stmt",
";",
"$",
"this",
"->",
"shadow",
"=",
"$",
"this",
"->",
"stmt",
";",
"return",
"$",
"this",
";",
"}"
] | Prepare a raw query
@param string $query
@param array $params
@return $this | [
"Prepare",
"a",
"raw",
"query"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Database.php#L278-L319 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Database.php | Database.multiquery | public function multiquery($query, $params = []) {
if(true === is_array($query)) {
$query = implode(";\n", $query);
}
if(false === is_string($query)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($query)), E_USER_ERROR);
}
$results = new ResultSet([], 'array');
if(null === $this -> connection) {
$this -> connect();
}
//Escape paramaters
$query = $this -> escapeSql($query, $params);
if($this -> connection -> multi_query($query)) {
$array = [];
do {
if($result = $this -> connection -> use_result()) {
while($row = $result -> fetch_array(MYSQLI_ASSOC)) {
$array[] = $row;
}
$result -> close();
$results -> append($array);
$array = [];
}
}
while($this -> connection -> more_results() && $this -> connection -> next_result());
}
return $results;
} | php | public function multiquery($query, $params = []) {
if(true === is_array($query)) {
$query = implode(";\n", $query);
}
if(false === is_string($query)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string or array, "%s" given', __METHOD__, gettype($query)), E_USER_ERROR);
}
$results = new ResultSet([], 'array');
if(null === $this -> connection) {
$this -> connect();
}
//Escape paramaters
$query = $this -> escapeSql($query, $params);
if($this -> connection -> multi_query($query)) {
$array = [];
do {
if($result = $this -> connection -> use_result()) {
while($row = $result -> fetch_array(MYSQLI_ASSOC)) {
$array[] = $row;
}
$result -> close();
$results -> append($array);
$array = [];
}
}
while($this -> connection -> more_results() && $this -> connection -> next_result());
}
return $results;
} | [
"public",
"function",
"multiquery",
"(",
"$",
"query",
",",
"$",
"params",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"true",
"===",
"is_array",
"(",
"$",
"query",
")",
")",
"{",
"$",
"query",
"=",
"implode",
"(",
"\";\\n\"",
",",
"$",
"query",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"query",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string or array, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"query",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"results",
"=",
"new",
"ResultSet",
"(",
"[",
"]",
",",
"'array'",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"connection",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"//Escape paramaters\r",
"$",
"query",
"=",
"$",
"this",
"->",
"escapeSql",
"(",
"$",
"query",
",",
"$",
"params",
")",
";",
"if",
"(",
"$",
"this",
"->",
"connection",
"->",
"multi_query",
"(",
"$",
"query",
")",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"do",
"{",
"if",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"connection",
"->",
"use_result",
"(",
")",
")",
"{",
"while",
"(",
"$",
"row",
"=",
"$",
"result",
"->",
"fetch_array",
"(",
"MYSQLI_ASSOC",
")",
")",
"{",
"$",
"array",
"[",
"]",
"=",
"$",
"row",
";",
"}",
"$",
"result",
"->",
"close",
"(",
")",
";",
"$",
"results",
"->",
"append",
"(",
"$",
"array",
")",
";",
"$",
"array",
"=",
"[",
"]",
";",
"}",
"}",
"while",
"(",
"$",
"this",
"->",
"connection",
"->",
"more_results",
"(",
")",
"&&",
"$",
"this",
"->",
"connection",
"->",
"next_result",
"(",
")",
")",
";",
"}",
"return",
"$",
"results",
";",
"}"
] | Execute a multiquery
@param string $query
@param array $params
@return sFire\Adapter\ResultSet | [
"Execute",
"a",
"multiquery"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Database.php#L328-L369 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Database.php | Database.escape | public function escape($data) {
if(null === $data) {
return $data;
}
if(false === is_string($data) && false === is_numeric($data)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, float or int, "%s" given', __METHOD__, gettype($data)), E_USER_ERROR);
}
if(null === $this -> connection) {
$this -> connect();
}
return $this -> connection -> real_escape_string($data);
} | php | public function escape($data) {
if(null === $data) {
return $data;
}
if(false === is_string($data) && false === is_numeric($data)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, float or int, "%s" given', __METHOD__, gettype($data)), E_USER_ERROR);
}
if(null === $this -> connection) {
$this -> connect();
}
return $this -> connection -> real_escape_string($data);
} | [
"public",
"function",
"escape",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"data",
")",
"{",
"return",
"$",
"data",
";",
"}",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"data",
")",
"&&",
"false",
"===",
"is_numeric",
"(",
"$",
"data",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, float or int, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"data",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"connection",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"connection",
"->",
"real_escape_string",
"(",
"$",
"data",
")",
";",
"}"
] | Escapes string for statement usage
@param string $data
@return string | [
"Escapes",
"string",
"for",
"statement",
"usage"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Database.php#L397-L412 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Database.php | Database.close | public function close() {
if(false === $this -> connection instanceof \mysqli) {
return trigger_error('Connection already closed');
}
$this -> connection -> close();
return $this;
} | php | public function close() {
if(false === $this -> connection instanceof \mysqli) {
return trigger_error('Connection already closed');
}
$this -> connection -> close();
return $this;
} | [
"public",
"function",
"close",
"(",
")",
"{",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"connection",
"instanceof",
"\\",
"mysqli",
")",
"{",
"return",
"trigger_error",
"(",
"'Connection already closed'",
")",
";",
"}",
"$",
"this",
"->",
"connection",
"->",
"close",
"(",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Closes the database connection
@return $this | [
"Closes",
"the",
"database",
"connection"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Database.php#L470-L479 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Database.php | Database.getLastErrno | public function getLastErrno() {
if(true === $this -> connection instanceof \mysqli) {
$this -> connect();
}
return $this -> connection -> errno;
} | php | public function getLastErrno() {
if(true === $this -> connection instanceof \mysqli) {
$this -> connect();
}
return $this -> connection -> errno;
} | [
"public",
"function",
"getLastErrno",
"(",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"connection",
"instanceof",
"\\",
"mysqli",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"connection",
"->",
"errno",
";",
"}"
] | Returns the last error number
@return int | [
"Returns",
"the",
"last",
"error",
"number"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Database.php#L486-L493 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Database.php | Database.getLastError | public function getLastError() {
if(true === $this -> connection instanceof \mysqli) {
$this -> connect();
}
return $this -> connection -> error;
} | php | public function getLastError() {
if(true === $this -> connection instanceof \mysqli) {
$this -> connect();
}
return $this -> connection -> error;
} | [
"public",
"function",
"getLastError",
"(",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"this",
"->",
"connection",
"instanceof",
"\\",
"mysqli",
")",
"{",
"$",
"this",
"->",
"connect",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"connection",
"->",
"error",
";",
"}"
] | Returns the last error message
@return string | [
"Returns",
"the",
"last",
"error",
"message"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Database.php#L500-L507 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Database.php | Database.escapeSemicolon | private function escapeSemicolon($query, $params) {
preg_match_all('#:((?:[a-zA-Z_])(?:[a-zA-Z0-9-_]+)?)#', $query, $variables);
if(true === isset($variables[0])) {
foreach($variables[0] as $index => $variable) {
if(false === array_key_exists($variables[1][$index], $params)) {
return trigger_error(sprintf('Parameter "%s" missing from parameters', $params[1][$index]), E_USER_ERROR);
}
$var = $params[$variables[1][$index]];
switch(gettype($var)) {
case 'string' : $var = '"' . $this -> escape($var) . '"'; break;
case 'NULL' : $var = 'NULL'; break;
default : $var = $this -> escape($var); break;
}
$query = str_replace($variables[0][$index], $var, $query);
}
}
return $query;
} | php | private function escapeSemicolon($query, $params) {
preg_match_all('#:((?:[a-zA-Z_])(?:[a-zA-Z0-9-_]+)?)#', $query, $variables);
if(true === isset($variables[0])) {
foreach($variables[0] as $index => $variable) {
if(false === array_key_exists($variables[1][$index], $params)) {
return trigger_error(sprintf('Parameter "%s" missing from parameters', $params[1][$index]), E_USER_ERROR);
}
$var = $params[$variables[1][$index]];
switch(gettype($var)) {
case 'string' : $var = '"' . $this -> escape($var) . '"'; break;
case 'NULL' : $var = 'NULL'; break;
default : $var = $this -> escape($var); break;
}
$query = str_replace($variables[0][$index], $var, $query);
}
}
return $query;
} | [
"private",
"function",
"escapeSemicolon",
"(",
"$",
"query",
",",
"$",
"params",
")",
"{",
"preg_match_all",
"(",
"'#:((?:[a-zA-Z_])(?:[a-zA-Z0-9-_]+)?)#'",
",",
"$",
"query",
",",
"$",
"variables",
")",
";",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"variables",
"[",
"0",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"variables",
"[",
"0",
"]",
"as",
"$",
"index",
"=>",
"$",
"variable",
")",
"{",
"if",
"(",
"false",
"===",
"array_key_exists",
"(",
"$",
"variables",
"[",
"1",
"]",
"[",
"$",
"index",
"]",
",",
"$",
"params",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Parameter \"%s\" missing from parameters'",
",",
"$",
"params",
"[",
"1",
"]",
"[",
"$",
"index",
"]",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"var",
"=",
"$",
"params",
"[",
"$",
"variables",
"[",
"1",
"]",
"[",
"$",
"index",
"]",
"]",
";",
"switch",
"(",
"gettype",
"(",
"$",
"var",
")",
")",
"{",
"case",
"'string'",
":",
"$",
"var",
"=",
"'\"'",
".",
"$",
"this",
"->",
"escape",
"(",
"$",
"var",
")",
".",
"'\"'",
";",
"break",
";",
"case",
"'NULL'",
":",
"$",
"var",
"=",
"'NULL'",
";",
"break",
";",
"default",
":",
"$",
"var",
"=",
"$",
"this",
"->",
"escape",
"(",
"$",
"var",
")",
";",
"break",
";",
"}",
"$",
"query",
"=",
"str_replace",
"(",
"$",
"variables",
"[",
"0",
"]",
"[",
"$",
"index",
"]",
",",
"$",
"var",
",",
"$",
"query",
")",
";",
"}",
"}",
"return",
"$",
"query",
";",
"}"
] | Escape variables bind with a semicolon
@param string $query
@param array $params
@return string | [
"Escape",
"variables",
"bind",
"with",
"a",
"semicolon"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Database.php#L563-L589 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Database.php | Database.escapeQuestionmark | private function escapeQuestionmark($query, $params) {
preg_match_all('#([\\\]{0,})(\?)#', $query, $variables);
if(true === isset($variables[0])) {
foreach($variables[0] as $index => $variable) {
//Check if ? sign is escaped or not
if(strlen($variables[1][$index]) % 2 !== 0) {
continue;
}
if(false === isset($params[$index])) {
return trigger_error('Number of variable elements query string does not match number of bind variables');
}
$var = $params[$index];
switch(gettype($var)) {
case 'string' : $var = '"' . $this -> escape($var) . '"'; break;
case 'NULL' : $var = 'NULL'; break;
default : $var = $this -> escape($var); break;
}
$query = preg_replace('#' . preg_quote($variable, '/') . '#', $var, $query, 1);
}
}
return $query;
} | php | private function escapeQuestionmark($query, $params) {
preg_match_all('#([\\\]{0,})(\?)#', $query, $variables);
if(true === isset($variables[0])) {
foreach($variables[0] as $index => $variable) {
//Check if ? sign is escaped or not
if(strlen($variables[1][$index]) % 2 !== 0) {
continue;
}
if(false === isset($params[$index])) {
return trigger_error('Number of variable elements query string does not match number of bind variables');
}
$var = $params[$index];
switch(gettype($var)) {
case 'string' : $var = '"' . $this -> escape($var) . '"'; break;
case 'NULL' : $var = 'NULL'; break;
default : $var = $this -> escape($var); break;
}
$query = preg_replace('#' . preg_quote($variable, '/') . '#', $var, $query, 1);
}
}
return $query;
} | [
"private",
"function",
"escapeQuestionmark",
"(",
"$",
"query",
",",
"$",
"params",
")",
"{",
"preg_match_all",
"(",
"'#([\\\\\\]{0,})(\\?)#'",
",",
"$",
"query",
",",
"$",
"variables",
")",
";",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"variables",
"[",
"0",
"]",
")",
")",
"{",
"foreach",
"(",
"$",
"variables",
"[",
"0",
"]",
"as",
"$",
"index",
"=>",
"$",
"variable",
")",
"{",
"//Check if ? sign is escaped or not\r",
"if",
"(",
"strlen",
"(",
"$",
"variables",
"[",
"1",
"]",
"[",
"$",
"index",
"]",
")",
"%",
"2",
"!==",
"0",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"false",
"===",
"isset",
"(",
"$",
"params",
"[",
"$",
"index",
"]",
")",
")",
"{",
"return",
"trigger_error",
"(",
"'Number of variable elements query string does not match number of bind variables'",
")",
";",
"}",
"$",
"var",
"=",
"$",
"params",
"[",
"$",
"index",
"]",
";",
"switch",
"(",
"gettype",
"(",
"$",
"var",
")",
")",
"{",
"case",
"'string'",
":",
"$",
"var",
"=",
"'\"'",
".",
"$",
"this",
"->",
"escape",
"(",
"$",
"var",
")",
".",
"'\"'",
";",
"break",
";",
"case",
"'NULL'",
":",
"$",
"var",
"=",
"'NULL'",
";",
"break",
";",
"default",
":",
"$",
"var",
"=",
"$",
"this",
"->",
"escape",
"(",
"$",
"var",
")",
";",
"break",
";",
"}",
"$",
"query",
"=",
"preg_replace",
"(",
"'#'",
".",
"preg_quote",
"(",
"$",
"variable",
",",
"'/'",
")",
".",
"'#'",
",",
"$",
"var",
",",
"$",
"query",
",",
"1",
")",
";",
"}",
"}",
"return",
"$",
"query",
";",
"}"
] | Escape variables bind with a question mark
@param string $query
@param array $params
@return string | [
"Escape",
"variables",
"bind",
"with",
"a",
"question",
"mark"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Database.php#L598-L629 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Database.php | Database.executeStatement | private function executeStatement($stmt) {
if(true !== $stmt -> execute()) {
if($this -> getLastErrno() > 0) {
return trigger_error(sprintf('A database error occured with error number "%s" and message: "%s"', $this -> getLastErrno(), $this -> getLastError()), E_USER_ERROR);
}
return false;
}
$stmt -> store_result();
return $stmt;
} | php | private function executeStatement($stmt) {
if(true !== $stmt -> execute()) {
if($this -> getLastErrno() > 0) {
return trigger_error(sprintf('A database error occured with error number "%s" and message: "%s"', $this -> getLastErrno(), $this -> getLastError()), E_USER_ERROR);
}
return false;
}
$stmt -> store_result();
return $stmt;
} | [
"private",
"function",
"executeStatement",
"(",
"$",
"stmt",
")",
"{",
"if",
"(",
"true",
"!==",
"$",
"stmt",
"->",
"execute",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getLastErrno",
"(",
")",
">",
"0",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'A database error occured with error number \"%s\" and message: \"%s\"'",
",",
"$",
"this",
"->",
"getLastErrno",
"(",
")",
",",
"$",
"this",
"->",
"getLastError",
"(",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"return",
"false",
";",
"}",
"$",
"stmt",
"->",
"store_result",
"(",
")",
";",
"return",
"$",
"stmt",
";",
"}"
] | Executes one statement
@param mysqli_stmt
@return mysqli_stmt | [
"Executes",
"one",
"statement"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Database.php#L637-L651 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Database.php | Database.parse | private function parse(&$params, &$query) {
//Check the type of param binding ("?" = all keys are numeric or ":" = all keys are strings)
if(0 !== count(array_filter(array_keys($params), 'is_string'))) {
preg_match_all('#:((?:[a-zA-Z_])(?:[a-zA-Z0-9-_]+)?)#', $query, $variables);
if(true === isset($variables[0])) {
$parameters = [];
foreach($variables[0] as $index => $variable) {
if(false === array_key_exists($variables[1][$index], $params)) {
return trigger_error(sprintf('Parameter "%s" missing from bind parameters', $variables[1][$index]), E_USER_ERROR);
}
$parameters[] =& $params[$variables[1][$index]];
$query = str_replace($variables[0][$index], '?', $query);
}
$params = $parameters;
}
}
$bind = [];
if(count($params) > 0) {
$types = '';
foreach($params as $param => $value) {
switch(gettype($value)) {
case 'NULL' :
case 'string' : $types .= 's'; break;
case 'boolean' :
case 'integer' : $types .= 'i'; break;
case 'blob' : $types .= 'b'; break;
case 'double' : $types .= 'd'; break;
}
}
$bind[] =& $types;
foreach($params as $param => $value) {
$bind[] =& $params[$param];
}
}
return $bind;
} | php | private function parse(&$params, &$query) {
//Check the type of param binding ("?" = all keys are numeric or ":" = all keys are strings)
if(0 !== count(array_filter(array_keys($params), 'is_string'))) {
preg_match_all('#:((?:[a-zA-Z_])(?:[a-zA-Z0-9-_]+)?)#', $query, $variables);
if(true === isset($variables[0])) {
$parameters = [];
foreach($variables[0] as $index => $variable) {
if(false === array_key_exists($variables[1][$index], $params)) {
return trigger_error(sprintf('Parameter "%s" missing from bind parameters', $variables[1][$index]), E_USER_ERROR);
}
$parameters[] =& $params[$variables[1][$index]];
$query = str_replace($variables[0][$index], '?', $query);
}
$params = $parameters;
}
}
$bind = [];
if(count($params) > 0) {
$types = '';
foreach($params as $param => $value) {
switch(gettype($value)) {
case 'NULL' :
case 'string' : $types .= 's'; break;
case 'boolean' :
case 'integer' : $types .= 'i'; break;
case 'blob' : $types .= 'b'; break;
case 'double' : $types .= 'd'; break;
}
}
$bind[] =& $types;
foreach($params as $param => $value) {
$bind[] =& $params[$param];
}
}
return $bind;
} | [
"private",
"function",
"parse",
"(",
"&",
"$",
"params",
",",
"&",
"$",
"query",
")",
"{",
"//Check the type of param binding (\"?\" = all keys are numeric or \":\" = all keys are strings)\r",
"if",
"(",
"0",
"!==",
"count",
"(",
"array_filter",
"(",
"array_keys",
"(",
"$",
"params",
")",
",",
"'is_string'",
")",
")",
")",
"{",
"preg_match_all",
"(",
"'#:((?:[a-zA-Z_])(?:[a-zA-Z0-9-_]+)?)#'",
",",
"$",
"query",
",",
"$",
"variables",
")",
";",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"variables",
"[",
"0",
"]",
")",
")",
"{",
"$",
"parameters",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"variables",
"[",
"0",
"]",
"as",
"$",
"index",
"=>",
"$",
"variable",
")",
"{",
"if",
"(",
"false",
"===",
"array_key_exists",
"(",
"$",
"variables",
"[",
"1",
"]",
"[",
"$",
"index",
"]",
",",
"$",
"params",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Parameter \"%s\" missing from bind parameters'",
",",
"$",
"variables",
"[",
"1",
"]",
"[",
"$",
"index",
"]",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"parameters",
"[",
"]",
"=",
"&",
"$",
"params",
"[",
"$",
"variables",
"[",
"1",
"]",
"[",
"$",
"index",
"]",
"]",
";",
"$",
"query",
"=",
"str_replace",
"(",
"$",
"variables",
"[",
"0",
"]",
"[",
"$",
"index",
"]",
",",
"'?'",
",",
"$",
"query",
")",
";",
"}",
"$",
"params",
"=",
"$",
"parameters",
";",
"}",
"}",
"$",
"bind",
"=",
"[",
"]",
";",
"if",
"(",
"count",
"(",
"$",
"params",
")",
">",
"0",
")",
"{",
"$",
"types",
"=",
"''",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
"=>",
"$",
"value",
")",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"value",
")",
")",
"{",
"case",
"'NULL'",
":",
"case",
"'string'",
":",
"$",
"types",
".=",
"'s'",
";",
"break",
";",
"case",
"'boolean'",
":",
"case",
"'integer'",
":",
"$",
"types",
".=",
"'i'",
";",
"break",
";",
"case",
"'blob'",
":",
"$",
"types",
".=",
"'b'",
";",
"break",
";",
"case",
"'double'",
":",
"$",
"types",
".=",
"'d'",
";",
"break",
";",
"}",
"}",
"$",
"bind",
"[",
"]",
"=",
"&",
"$",
"types",
";",
"foreach",
"(",
"$",
"params",
"as",
"$",
"param",
"=>",
"$",
"value",
")",
"{",
"$",
"bind",
"[",
"]",
"=",
"&",
"$",
"params",
"[",
"$",
"param",
"]",
";",
"}",
"}",
"return",
"$",
"bind",
";",
"}"
] | Parse parameters and return it with types
@param array $params
@param string $query
@return array | [
"Parse",
"parameters",
"and",
"return",
"it",
"with",
"types"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Database.php#L660-L715 | train |
Kris-Kuiper/sFire-Framework | src/DB/Driver/MySQLi/Database.php | Database.bind | private function bind($stmt) {
$meta = $stmt -> result_metadata();
$double = [];
$vars = [];
if($stmt -> field_count > 0) {
while($field = $meta -> fetch_field()) {
$columnname = $field -> name;
${$columnname} = null;
if(true === array_key_exists($columnname, $vars)) {
$double[] = $columnname;
}
else {
$vars[$columnname] = &${$columnname};
}
}
}
if(count($double) > 0) {
return trigger_error(sprintf('Column %s in field list is ambiguous', implode(', ', array_unique($double))));
}
call_user_func_array([$stmt, 'bind_result'], $vars);
return $vars;
} | php | private function bind($stmt) {
$meta = $stmt -> result_metadata();
$double = [];
$vars = [];
if($stmt -> field_count > 0) {
while($field = $meta -> fetch_field()) {
$columnname = $field -> name;
${$columnname} = null;
if(true === array_key_exists($columnname, $vars)) {
$double[] = $columnname;
}
else {
$vars[$columnname] = &${$columnname};
}
}
}
if(count($double) > 0) {
return trigger_error(sprintf('Column %s in field list is ambiguous', implode(', ', array_unique($double))));
}
call_user_func_array([$stmt, 'bind_result'], $vars);
return $vars;
} | [
"private",
"function",
"bind",
"(",
"$",
"stmt",
")",
"{",
"$",
"meta",
"=",
"$",
"stmt",
"->",
"result_metadata",
"(",
")",
";",
"$",
"double",
"=",
"[",
"]",
";",
"$",
"vars",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"stmt",
"->",
"field_count",
">",
"0",
")",
"{",
"while",
"(",
"$",
"field",
"=",
"$",
"meta",
"->",
"fetch_field",
"(",
")",
")",
"{",
"$",
"columnname",
"=",
"$",
"field",
"->",
"name",
";",
"$",
"{",
"$",
"columnname",
"}",
"=",
"null",
";",
"if",
"(",
"true",
"===",
"array_key_exists",
"(",
"$",
"columnname",
",",
"$",
"vars",
")",
")",
"{",
"$",
"double",
"[",
"]",
"=",
"$",
"columnname",
";",
"}",
"else",
"{",
"$",
"vars",
"[",
"$",
"columnname",
"]",
"=",
"&",
"$",
"{",
"$",
"columnname",
"}",
";",
"}",
"}",
"}",
"if",
"(",
"count",
"(",
"$",
"double",
")",
">",
"0",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Column %s in field list is ambiguous'",
",",
"implode",
"(",
"', '",
",",
"array_unique",
"(",
"$",
"double",
")",
")",
")",
")",
";",
"}",
"call_user_func_array",
"(",
"[",
"$",
"stmt",
",",
"'bind_result'",
"]",
",",
"$",
"vars",
")",
";",
"return",
"$",
"vars",
";",
"}"
] | Bind the result to the variables and returns it
@return array | [
"Bind",
"the",
"result",
"to",
"the",
"variables",
"and",
"returns",
"it"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/DB/Driver/MySQLi/Database.php#L722-L751 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Loader/Bridge/InMemory/InMemoryLoaderTrait.php | InMemoryLoaderTrait.registerData | public function registerData(array $entityData)
{
foreach ($entityData as $data) {
$this->registerEntity($this->normalizer->denormalize(
$data,
$this->entityCollection->getEntityClass()
));
}
} | php | public function registerData(array $entityData)
{
foreach ($entityData as $data) {
$this->registerEntity($this->normalizer->denormalize(
$data,
$this->entityCollection->getEntityClass()
));
}
} | [
"public",
"function",
"registerData",
"(",
"array",
"$",
"entityData",
")",
"{",
"foreach",
"(",
"$",
"entityData",
"as",
"$",
"data",
")",
"{",
"$",
"this",
"->",
"registerEntity",
"(",
"$",
"this",
"->",
"normalizer",
"->",
"denormalize",
"(",
"$",
"data",
",",
"$",
"this",
"->",
"entityCollection",
"->",
"getEntityClass",
"(",
")",
")",
")",
";",
"}",
"}"
] | Register given set of data into datastore.
@param array $entityData | [
"Register",
"given",
"set",
"of",
"data",
"into",
"datastore",
"."
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Loader/Bridge/InMemory/InMemoryLoaderTrait.php#L68-L76 | train |
Linkvalue-Interne/MajoraFrameworkExtraBundle | src/Majora/Framework/Loader/Bridge/InMemory/InMemoryLoaderTrait.php | InMemoryLoaderTrait.registerEntity | public function registerEntity(CollectionableInterface $entity)
{
if (!is_a($entity, $this->entityCollection->getEntityClass())) {
throw new \InvalidArgumentException(sprintf('Only "%s" object allowed into "%s" store, "%s" given.',
$this->entityCollection->getEntityClass(),
get_class($this),
get_class($entity)
));
}
$this->entityCollection->set(
$entity->getId(),
$this->loadDelegates($entity)
);
} | php | public function registerEntity(CollectionableInterface $entity)
{
if (!is_a($entity, $this->entityCollection->getEntityClass())) {
throw new \InvalidArgumentException(sprintf('Only "%s" object allowed into "%s" store, "%s" given.',
$this->entityCollection->getEntityClass(),
get_class($this),
get_class($entity)
));
}
$this->entityCollection->set(
$entity->getId(),
$this->loadDelegates($entity)
);
} | [
"public",
"function",
"registerEntity",
"(",
"CollectionableInterface",
"$",
"entity",
")",
"{",
"if",
"(",
"!",
"is_a",
"(",
"$",
"entity",
",",
"$",
"this",
"->",
"entityCollection",
"->",
"getEntityClass",
"(",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Only \"%s\" object allowed into \"%s\" store, \"%s\" given.'",
",",
"$",
"this",
"->",
"entityCollection",
"->",
"getEntityClass",
"(",
")",
",",
"get_class",
"(",
"$",
"this",
")",
",",
"get_class",
"(",
"$",
"entity",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"entityCollection",
"->",
"set",
"(",
"$",
"entity",
"->",
"getId",
"(",
")",
",",
"$",
"this",
"->",
"loadDelegates",
"(",
"$",
"entity",
")",
")",
";",
"}"
] | Register a new Collectionable entity into datastore.
@param CollectionableInterface $entity
@throws \InvalidArgumentException If given object is not a supported type | [
"Register",
"a",
"new",
"Collectionable",
"entity",
"into",
"datastore",
"."
] | 6f368380cfc39d27fafb0844e9a53b4d86d7c034 | https://github.com/Linkvalue-Interne/MajoraFrameworkExtraBundle/blob/6f368380cfc39d27fafb0844e9a53b4d86d7c034/src/Majora/Framework/Loader/Bridge/InMemory/InMemoryLoaderTrait.php#L85-L99 | train |
kitpages/KitpagesStepBundle | Proxy/CacheWarmer/ProxyCacheWarmer.php | ProxyCacheWarmer.warmUp | public function warmUp($cacheDir)
{
$stepList = $this->stepManager->getStepList();
if (null === $stepList) {
return;
}
foreach ($stepList as $stepName => $step) {
$stepFinalConfig = $this->stepManager->getResultingConfig($stepName);
$stepFinalConfig = $this->stepManager->normalizeStepConfig($stepFinalConfig);
// step name is only defined in config given in parameters
if (!isset($stepFinalConfig['class'])) {
throw new StepException('unknown stepName and class undefined in config');
}
$className = $stepFinalConfig['class'];
if (!class_exists($className)) {
throw new StepException('class '.$className." doesn't exists");
}
$proxyGenerator = new ProxyGenerator($className, true, $cacheDir);
$proxyGenerator->writeProxyClassCache();
}
} | php | public function warmUp($cacheDir)
{
$stepList = $this->stepManager->getStepList();
if (null === $stepList) {
return;
}
foreach ($stepList as $stepName => $step) {
$stepFinalConfig = $this->stepManager->getResultingConfig($stepName);
$stepFinalConfig = $this->stepManager->normalizeStepConfig($stepFinalConfig);
// step name is only defined in config given in parameters
if (!isset($stepFinalConfig['class'])) {
throw new StepException('unknown stepName and class undefined in config');
}
$className = $stepFinalConfig['class'];
if (!class_exists($className)) {
throw new StepException('class '.$className." doesn't exists");
}
$proxyGenerator = new ProxyGenerator($className, true, $cacheDir);
$proxyGenerator->writeProxyClassCache();
}
} | [
"public",
"function",
"warmUp",
"(",
"$",
"cacheDir",
")",
"{",
"$",
"stepList",
"=",
"$",
"this",
"->",
"stepManager",
"->",
"getStepList",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"stepList",
")",
"{",
"return",
";",
"}",
"foreach",
"(",
"$",
"stepList",
"as",
"$",
"stepName",
"=>",
"$",
"step",
")",
"{",
"$",
"stepFinalConfig",
"=",
"$",
"this",
"->",
"stepManager",
"->",
"getResultingConfig",
"(",
"$",
"stepName",
")",
";",
"$",
"stepFinalConfig",
"=",
"$",
"this",
"->",
"stepManager",
"->",
"normalizeStepConfig",
"(",
"$",
"stepFinalConfig",
")",
";",
"// step name is only defined in config given in parameters",
"if",
"(",
"!",
"isset",
"(",
"$",
"stepFinalConfig",
"[",
"'class'",
"]",
")",
")",
"{",
"throw",
"new",
"StepException",
"(",
"'unknown stepName and class undefined in config'",
")",
";",
"}",
"$",
"className",
"=",
"$",
"stepFinalConfig",
"[",
"'class'",
"]",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"throw",
"new",
"StepException",
"(",
"'class '",
".",
"$",
"className",
".",
"\" doesn't exists\"",
")",
";",
"}",
"$",
"proxyGenerator",
"=",
"new",
"ProxyGenerator",
"(",
"$",
"className",
",",
"true",
",",
"$",
"cacheDir",
")",
";",
"$",
"proxyGenerator",
"->",
"writeProxyClassCache",
"(",
")",
";",
"}",
"}"
] | Writes the workflow proxy cache file.
@param string $cacheDir The cache directory | [
"Writes",
"the",
"workflow",
"proxy",
"cache",
"file",
"."
] | 2ac421c8364d41b87b515a91a94513f3d1ab20c1 | https://github.com/kitpages/KitpagesStepBundle/blob/2ac421c8364d41b87b515a91a94513f3d1ab20c1/Proxy/CacheWarmer/ProxyCacheWarmer.php#L47-L72 | train |
lasallecms/lasallecms-l5-lasallecmsemail-pkg | src/Repositories/Email_messageRepository.php | Email_messageRepository.markEmailAsRead | public function markEmailAsRead($id) {
$emailMessage = $this->model->find($id);
$emailMessage->read = 1;
return $emailMessage->save();
} | php | public function markEmailAsRead($id) {
$emailMessage = $this->model->find($id);
$emailMessage->read = 1;
return $emailMessage->save();
} | [
"public",
"function",
"markEmailAsRead",
"(",
"$",
"id",
")",
"{",
"$",
"emailMessage",
"=",
"$",
"this",
"->",
"model",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"emailMessage",
"->",
"read",
"=",
"1",
";",
"return",
"$",
"emailMessage",
"->",
"save",
"(",
")",
";",
"}"
] | Mark an email as read by setting the "read" field to true
@param int $id The "email_messages" table's ID field
@return void | [
"Mark",
"an",
"email",
"as",
"read",
"by",
"setting",
"the",
"read",
"field",
"to",
"true"
] | 95db5a59ab322105b9d3681cf9ab1f829c9fdb9f | https://github.com/lasallecms/lasallecms-l5-lasallecmsemail-pkg/blob/95db5a59ab322105b9d3681cf9ab1f829c9fdb9f/src/Repositories/Email_messageRepository.php#L81-L88 | train |
lasallecms/lasallecms-l5-lasallecmsemail-pkg | src/Repositories/Email_messageRepository.php | Email_messageRepository.markEmailAsSent | public function markEmailAsSent($id) {
$emailMessage = $this->model->find($id);
$emailMessage->sent = 1;
return $emailMessage->save();
} | php | public function markEmailAsSent($id) {
$emailMessage = $this->model->find($id);
$emailMessage->sent = 1;
return $emailMessage->save();
} | [
"public",
"function",
"markEmailAsSent",
"(",
"$",
"id",
")",
"{",
"$",
"emailMessage",
"=",
"$",
"this",
"->",
"model",
"->",
"find",
"(",
"$",
"id",
")",
";",
"$",
"emailMessage",
"->",
"sent",
"=",
"1",
";",
"return",
"$",
"emailMessage",
"->",
"save",
"(",
")",
";",
"}"
] | Mark an email as sent by setting the "sent" field to true
@param int $id The "email_messages" table's ID field
@return void | [
"Mark",
"an",
"email",
"as",
"sent",
"by",
"setting",
"the",
"sent",
"field",
"to",
"true"
] | 95db5a59ab322105b9d3681cf9ab1f829c9fdb9f | https://github.com/lasallecms/lasallecms-l5-lasallecmsemail-pkg/blob/95db5a59ab322105b9d3681cf9ab1f829c9fdb9f/src/Repositories/Email_messageRepository.php#L96-L103 | train |
modulusphp/support | File.php | File.disc | public function disc(string $storage)
{
if (isset($this->storage[$storage])) {
$this->disc = strtolower($storage);
return $this;
}
throw new UnknownStorageException;
} | php | public function disc(string $storage)
{
if (isset($this->storage[$storage])) {
$this->disc = strtolower($storage);
return $this;
}
throw new UnknownStorageException;
} | [
"public",
"function",
"disc",
"(",
"string",
"$",
"storage",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"storage",
"[",
"$",
"storage",
"]",
")",
")",
"{",
"$",
"this",
"->",
"disc",
"=",
"strtolower",
"(",
"$",
"storage",
")",
";",
"return",
"$",
"this",
";",
"}",
"throw",
"new",
"UnknownStorageException",
";",
"}"
] | Set default disc storage
@param string $storage
@return void | [
"Set",
"default",
"disc",
"storage"
] | b5c5b48dcbeb379e6cd1f29159dc8cdacef3adab | https://github.com/modulusphp/support/blob/b5c5b48dcbeb379e6cd1f29159dc8cdacef3adab/File.php#L106-L114 | train |
Dhii/iterator-abstract | src/RecursiveIteratorTrait.php | RecursiveIteratorTrait._loop | protected function _loop()
{
// Ensure that there are items on the stack
if (!$this->_hasParents()) {
return $this->_createIteration(null, null);
}
// Get current top item on the stack and its current iteration entry
$parent = &$this->_getCurrentIterable();
$current = $this->_createCurrentIteration($parent);
// Reached end of current iterable
if ($current->getKey() === null) {
return $this->_backtrackLoop();
}
// Element is a leaf
if (!$this->_isElementHasChildren($current->getValue())) {
next($parent);
return $current;
}
// Element is not a leaf; push to stack
$children = $current->getValue();
$this->_pushParent($children);
if ($this->_isMode(R::MODE_SELF_FIRST)) {
return $current;
}
return $this->_loop();
} | php | protected function _loop()
{
// Ensure that there are items on the stack
if (!$this->_hasParents()) {
return $this->_createIteration(null, null);
}
// Get current top item on the stack and its current iteration entry
$parent = &$this->_getCurrentIterable();
$current = $this->_createCurrentIteration($parent);
// Reached end of current iterable
if ($current->getKey() === null) {
return $this->_backtrackLoop();
}
// Element is a leaf
if (!$this->_isElementHasChildren($current->getValue())) {
next($parent);
return $current;
}
// Element is not a leaf; push to stack
$children = $current->getValue();
$this->_pushParent($children);
if ($this->_isMode(R::MODE_SELF_FIRST)) {
return $current;
}
return $this->_loop();
} | [
"protected",
"function",
"_loop",
"(",
")",
"{",
"// Ensure that there are items on the stack",
"if",
"(",
"!",
"$",
"this",
"->",
"_hasParents",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_createIteration",
"(",
"null",
",",
"null",
")",
";",
"}",
"// Get current top item on the stack and its current iteration entry",
"$",
"parent",
"=",
"&",
"$",
"this",
"->",
"_getCurrentIterable",
"(",
")",
";",
"$",
"current",
"=",
"$",
"this",
"->",
"_createCurrentIteration",
"(",
"$",
"parent",
")",
";",
"// Reached end of current iterable",
"if",
"(",
"$",
"current",
"->",
"getKey",
"(",
")",
"===",
"null",
")",
"{",
"return",
"$",
"this",
"->",
"_backtrackLoop",
"(",
")",
";",
"}",
"// Element is a leaf",
"if",
"(",
"!",
"$",
"this",
"->",
"_isElementHasChildren",
"(",
"$",
"current",
"->",
"getValue",
"(",
")",
")",
")",
"{",
"next",
"(",
"$",
"parent",
")",
";",
"return",
"$",
"current",
";",
"}",
"// Element is not a leaf; push to stack",
"$",
"children",
"=",
"$",
"current",
"->",
"getValue",
"(",
")",
";",
"$",
"this",
"->",
"_pushParent",
"(",
"$",
"children",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_isMode",
"(",
"R",
"::",
"MODE_SELF_FIRST",
")",
")",
"{",
"return",
"$",
"current",
";",
"}",
"return",
"$",
"this",
"->",
"_loop",
"(",
")",
";",
"}"
] | Advances the iterator and computes the new state.
@since [*next-version*]
@return IterationInterface The iteration that represents the new state. | [
"Advances",
"the",
"iterator",
"and",
"computes",
"the",
"new",
"state",
"."
] | 576484183865575ffc2a0d586132741329626fb8 | https://github.com/Dhii/iterator-abstract/blob/576484183865575ffc2a0d586132741329626fb8/src/RecursiveIteratorTrait.php#L57-L89 | train |
Dhii/iterator-abstract | src/RecursiveIteratorTrait.php | RecursiveIteratorTrait._backtrackLoop | protected function _backtrackLoop()
{
$this->_popParent();
if (!$this->_hasParents()) {
return $this->_createIteration(null, null);
}
$parent = &$this->_getCurrentIterable();
$current = $this->_createCurrentIteration($parent);
next($parent);
if ($this->_isMode(R::MODE_CHILD_FIRST)) {
return $current;
}
return $this->_loop();
} | php | protected function _backtrackLoop()
{
$this->_popParent();
if (!$this->_hasParents()) {
return $this->_createIteration(null, null);
}
$parent = &$this->_getCurrentIterable();
$current = $this->_createCurrentIteration($parent);
next($parent);
if ($this->_isMode(R::MODE_CHILD_FIRST)) {
return $current;
}
return $this->_loop();
} | [
"protected",
"function",
"_backtrackLoop",
"(",
")",
"{",
"$",
"this",
"->",
"_popParent",
"(",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"_hasParents",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_createIteration",
"(",
"null",
",",
"null",
")",
";",
"}",
"$",
"parent",
"=",
"&",
"$",
"this",
"->",
"_getCurrentIterable",
"(",
")",
";",
"$",
"current",
"=",
"$",
"this",
"->",
"_createCurrentIteration",
"(",
"$",
"parent",
")",
";",
"next",
"(",
"$",
"parent",
")",
";",
"if",
"(",
"$",
"this",
"->",
"_isMode",
"(",
"R",
"::",
"MODE_CHILD_FIRST",
")",
")",
"{",
"return",
"$",
"current",
";",
"}",
"return",
"$",
"this",
"->",
"_loop",
"(",
")",
";",
"}"
] | Backtracks up one parent, yielding the parent or resuming the loop, whichever is appropriate.
@since [*next-version*]
@return IterationInterface | [
"Backtracks",
"up",
"one",
"parent",
"yielding",
"the",
"parent",
"or",
"resuming",
"the",
"loop",
"whichever",
"is",
"appropriate",
"."
] | 576484183865575ffc2a0d586132741329626fb8 | https://github.com/Dhii/iterator-abstract/blob/576484183865575ffc2a0d586132741329626fb8/src/RecursiveIteratorTrait.php#L98-L115 | train |
Dhii/iterator-abstract | src/RecursiveIteratorTrait.php | RecursiveIteratorTrait._pushParent | protected function _pushParent(&$parent)
{
$children = &$this->_getElementChildren($parent);
$pathSegment = $this->_getElementPathSegment(null, $parent);
$this->_pushPathSegment($pathSegment);
reset($children);
array_unshift($this->parents, $children);
} | php | protected function _pushParent(&$parent)
{
$children = &$this->_getElementChildren($parent);
$pathSegment = $this->_getElementPathSegment(null, $parent);
$this->_pushPathSegment($pathSegment);
reset($children);
array_unshift($this->parents, $children);
} | [
"protected",
"function",
"_pushParent",
"(",
"&",
"$",
"parent",
")",
"{",
"$",
"children",
"=",
"&",
"$",
"this",
"->",
"_getElementChildren",
"(",
"$",
"parent",
")",
";",
"$",
"pathSegment",
"=",
"$",
"this",
"->",
"_getElementPathSegment",
"(",
"null",
",",
"$",
"parent",
")",
";",
"$",
"this",
"->",
"_pushPathSegment",
"(",
"$",
"pathSegment",
")",
";",
"reset",
"(",
"$",
"children",
")",
";",
"array_unshift",
"(",
"$",
"this",
"->",
"parents",
",",
"$",
"children",
")",
";",
"}"
] | Adds an iterable parent onto the stack.
The stack is there to maintain a trace of hierarchy.
@since [*next-version*]
@param Iterator|array $parent The parent. | [
"Adds",
"an",
"iterable",
"parent",
"onto",
"the",
"stack",
"."
] | 576484183865575ffc2a0d586132741329626fb8 | https://github.com/Dhii/iterator-abstract/blob/576484183865575ffc2a0d586132741329626fb8/src/RecursiveIteratorTrait.php#L139-L148 | train |
Dhii/iterator-abstract | src/RecursiveIteratorTrait.php | RecursiveIteratorTrait._createCurrentIteration | protected function _createCurrentIteration(&$iterable)
{
$key = $this->_getCurrentIterableKey($iterable);
$val = $this->_getCurrentIterableValue($iterable);
$path = $this->_getCurrentPath($key, $val);
return $this->_createIteration($key, $val, $path);
} | php | protected function _createCurrentIteration(&$iterable)
{
$key = $this->_getCurrentIterableKey($iterable);
$val = $this->_getCurrentIterableValue($iterable);
$path = $this->_getCurrentPath($key, $val);
return $this->_createIteration($key, $val, $path);
} | [
"protected",
"function",
"_createCurrentIteration",
"(",
"&",
"$",
"iterable",
")",
"{",
"$",
"key",
"=",
"$",
"this",
"->",
"_getCurrentIterableKey",
"(",
"$",
"iterable",
")",
";",
"$",
"val",
"=",
"$",
"this",
"->",
"_getCurrentIterableValue",
"(",
"$",
"iterable",
")",
";",
"$",
"path",
"=",
"$",
"this",
"->",
"_getCurrentPath",
"(",
"$",
"key",
",",
"$",
"val",
")",
";",
"return",
"$",
"this",
"->",
"_createIteration",
"(",
"$",
"key",
",",
"$",
"val",
",",
"$",
"path",
")",
";",
"}"
] | Creates an iteration instance for the current state of a given iterable.
@since [*next-version*]
@param array|Traversable $iterable The iterable.
@return IterationInterface | [
"Creates",
"an",
"iteration",
"instance",
"for",
"the",
"current",
"state",
"of",
"a",
"given",
"iterable",
"."
] | 576484183865575ffc2a0d586132741329626fb8 | https://github.com/Dhii/iterator-abstract/blob/576484183865575ffc2a0d586132741329626fb8/src/RecursiveIteratorTrait.php#L267-L274 | train |
Dhii/iterator-abstract | src/RecursiveIteratorTrait.php | RecursiveIteratorTrait._getCurrentPath | protected function _getCurrentPath($key, $value)
{
$path = $this->_getPathSegments();
$path[] = $this->_getElementPathSegment($key, $value);
return array_filter($path);
} | php | protected function _getCurrentPath($key, $value)
{
$path = $this->_getPathSegments();
$path[] = $this->_getElementPathSegment($key, $value);
return array_filter($path);
} | [
"protected",
"function",
"_getCurrentPath",
"(",
"$",
"key",
",",
"$",
"value",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"_getPathSegments",
"(",
")",
";",
"$",
"path",
"[",
"]",
"=",
"$",
"this",
"->",
"_getElementPathSegment",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"return",
"array_filter",
"(",
"$",
"path",
")",
";",
"}"
] | Retrieves the current path.
@since [*next-version*]
@param string|int $key The current element key.
@param mixed $value The current element value.
@return array | [
"Retrieves",
"the",
"current",
"path",
"."
] | 576484183865575ffc2a0d586132741329626fb8 | https://github.com/Dhii/iterator-abstract/blob/576484183865575ffc2a0d586132741329626fb8/src/RecursiveIteratorTrait.php#L286-L292 | train |
fiiSoft/fiisoft-logger | src/Logger/Reader/LogConsumer/InMemoryLogsCollector.php | InMemoryLogsCollector.sendLogsTo | public function sendLogsTo(LogConsumer $logConsumer)
{
if ($logConsumer === $this) {
throw new LogicException('Operation not allowed');
}
while (!empty($this->collectedLogs)) {
$log = array_shift($this->collectedLogs);
$logConsumer->consumeLog($log['message'], $log['context']);
}
} | php | public function sendLogsTo(LogConsumer $logConsumer)
{
if ($logConsumer === $this) {
throw new LogicException('Operation not allowed');
}
while (!empty($this->collectedLogs)) {
$log = array_shift($this->collectedLogs);
$logConsumer->consumeLog($log['message'], $log['context']);
}
} | [
"public",
"function",
"sendLogsTo",
"(",
"LogConsumer",
"$",
"logConsumer",
")",
"{",
"if",
"(",
"$",
"logConsumer",
"===",
"$",
"this",
")",
"{",
"throw",
"new",
"LogicException",
"(",
"'Operation not allowed'",
")",
";",
"}",
"while",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"collectedLogs",
")",
")",
"{",
"$",
"log",
"=",
"array_shift",
"(",
"$",
"this",
"->",
"collectedLogs",
")",
";",
"$",
"logConsumer",
"->",
"consumeLog",
"(",
"$",
"log",
"[",
"'message'",
"]",
",",
"$",
"log",
"[",
"'context'",
"]",
")",
";",
"}",
"}"
] | Send all logs to other LogConsumer.
Be aware that logs are removed during this process.
@param LogConsumer $logConsumer
@throws LogicException
@return void | [
"Send",
"all",
"logs",
"to",
"other",
"LogConsumer",
".",
"Be",
"aware",
"that",
"logs",
"are",
"removed",
"during",
"this",
"process",
"."
] | 3d2eb9d18a785ec119d2fbeb9d34b74265e7dcf5 | https://github.com/fiiSoft/fiisoft-logger/blob/3d2eb9d18a785ec119d2fbeb9d34b74265e7dcf5/src/Logger/Reader/LogConsumer/InMemoryLogsCollector.php#L71-L81 | train |
romm/configuration_object | Classes/Legacy/Reflection/DocCommentParser.php | DocCommentParser.parseTag | protected function parseTag($line)
{
$tagAndValue = preg_split('/\\s/', $line, 2);
$tag = substr($tagAndValue[0], 1);
if (count($tagAndValue) > 1) {
$this->tags[$tag][] = trim($tagAndValue[1]);
} else {
$this->tags[$tag] = [];
}
} | php | protected function parseTag($line)
{
$tagAndValue = preg_split('/\\s/', $line, 2);
$tag = substr($tagAndValue[0], 1);
if (count($tagAndValue) > 1) {
$this->tags[$tag][] = trim($tagAndValue[1]);
} else {
$this->tags[$tag] = [];
}
} | [
"protected",
"function",
"parseTag",
"(",
"$",
"line",
")",
"{",
"$",
"tagAndValue",
"=",
"preg_split",
"(",
"'/\\\\s/'",
",",
"$",
"line",
",",
"2",
")",
";",
"$",
"tag",
"=",
"substr",
"(",
"$",
"tagAndValue",
"[",
"0",
"]",
",",
"1",
")",
";",
"if",
"(",
"count",
"(",
"$",
"tagAndValue",
")",
">",
"1",
")",
"{",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"]",
"[",
"]",
"=",
"trim",
"(",
"$",
"tagAndValue",
"[",
"1",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"tags",
"[",
"$",
"tag",
"]",
"=",
"[",
"]",
";",
"}",
"}"
] | Parses a line of a doc comment for a tag and its value.
The result is stored in the interal tags array.
@param string $line A line of a doc comment which starts with an @-sign | [
"Parses",
"a",
"line",
"of",
"a",
"doc",
"comment",
"for",
"a",
"tag",
"and",
"its",
"value",
".",
"The",
"result",
"is",
"stored",
"in",
"the",
"interal",
"tags",
"array",
"."
] | d3a40903386c2e0766bd8279337fe6da45cf5ce3 | https://github.com/romm/configuration_object/blob/d3a40903386c2e0766bd8279337fe6da45cf5ce3/Classes/Legacy/Reflection/DocCommentParser.php#L108-L117 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Message/MessageParser.php | MessageParser.parseRequest | public function parseRequest($message)
{
if (!($parts = $this->parseMessage($message))) {
return false;
}
// Parse the protocol and protocol version
if (isset($parts['start_line'][2])) {
$startParts = explode('/', $parts['start_line'][2]);
$protocol = strtoupper($startParts[0]);
$version = isset($startParts[1]) ? $startParts[1] : '1.1';
} else {
$protocol = 'HTTP';
$version = '1.1';
}
$parsed = [
'method' => strtoupper($parts['start_line'][0]),
'protocol' => $protocol,
'protocol_version' => $version,
'headers' => $parts['headers'],
'body' => $parts['body']
];
$parsed['request_url'] = $this->getUrlPartsFromMessage(
(isset($parts['start_line'][1]) ? $parts['start_line'][1] : ''), $parsed);
return $parsed;
} | php | public function parseRequest($message)
{
if (!($parts = $this->parseMessage($message))) {
return false;
}
// Parse the protocol and protocol version
if (isset($parts['start_line'][2])) {
$startParts = explode('/', $parts['start_line'][2]);
$protocol = strtoupper($startParts[0]);
$version = isset($startParts[1]) ? $startParts[1] : '1.1';
} else {
$protocol = 'HTTP';
$version = '1.1';
}
$parsed = [
'method' => strtoupper($parts['start_line'][0]),
'protocol' => $protocol,
'protocol_version' => $version,
'headers' => $parts['headers'],
'body' => $parts['body']
];
$parsed['request_url'] = $this->getUrlPartsFromMessage(
(isset($parts['start_line'][1]) ? $parts['start_line'][1] : ''), $parsed);
return $parsed;
} | [
"public",
"function",
"parseRequest",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"parts",
"=",
"$",
"this",
"->",
"parseMessage",
"(",
"$",
"message",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"// Parse the protocol and protocol version",
"if",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'start_line'",
"]",
"[",
"2",
"]",
")",
")",
"{",
"$",
"startParts",
"=",
"explode",
"(",
"'/'",
",",
"$",
"parts",
"[",
"'start_line'",
"]",
"[",
"2",
"]",
")",
";",
"$",
"protocol",
"=",
"strtoupper",
"(",
"$",
"startParts",
"[",
"0",
"]",
")",
";",
"$",
"version",
"=",
"isset",
"(",
"$",
"startParts",
"[",
"1",
"]",
")",
"?",
"$",
"startParts",
"[",
"1",
"]",
":",
"'1.1'",
";",
"}",
"else",
"{",
"$",
"protocol",
"=",
"'HTTP'",
";",
"$",
"version",
"=",
"'1.1'",
";",
"}",
"$",
"parsed",
"=",
"[",
"'method'",
"=>",
"strtoupper",
"(",
"$",
"parts",
"[",
"'start_line'",
"]",
"[",
"0",
"]",
")",
",",
"'protocol'",
"=>",
"$",
"protocol",
",",
"'protocol_version'",
"=>",
"$",
"version",
",",
"'headers'",
"=>",
"$",
"parts",
"[",
"'headers'",
"]",
",",
"'body'",
"=>",
"$",
"parts",
"[",
"'body'",
"]",
"]",
";",
"$",
"parsed",
"[",
"'request_url'",
"]",
"=",
"$",
"this",
"->",
"getUrlPartsFromMessage",
"(",
"(",
"isset",
"(",
"$",
"parts",
"[",
"'start_line'",
"]",
"[",
"1",
"]",
")",
"?",
"$",
"parts",
"[",
"'start_line'",
"]",
"[",
"1",
"]",
":",
"''",
")",
",",
"$",
"parsed",
")",
";",
"return",
"$",
"parsed",
";",
"}"
] | Parse an HTTP request message into an associative array of parts.
@param string $message HTTP request to parse
@return array|bool Returns false if the message is invalid | [
"Parse",
"an",
"HTTP",
"request",
"message",
"into",
"an",
"associative",
"array",
"of",
"parts",
"."
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Message/MessageParser.php#L17-L45 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Message/MessageParser.php | MessageParser.parseResponse | public function parseResponse($message)
{
if (!($parts = $this->parseMessage($message))) {
return false;
}
list($protocol, $version) = explode('/', trim($parts['start_line'][0]));
return [
'protocol' => $protocol,
'protocol_version' => $version,
'code' => $parts['start_line'][1],
'reason_phrase' => isset($parts['start_line'][2]) ? $parts['start_line'][2] : '',
'headers' => $parts['headers'],
'body' => $parts['body']
];
} | php | public function parseResponse($message)
{
if (!($parts = $this->parseMessage($message))) {
return false;
}
list($protocol, $version) = explode('/', trim($parts['start_line'][0]));
return [
'protocol' => $protocol,
'protocol_version' => $version,
'code' => $parts['start_line'][1],
'reason_phrase' => isset($parts['start_line'][2]) ? $parts['start_line'][2] : '',
'headers' => $parts['headers'],
'body' => $parts['body']
];
} | [
"public",
"function",
"parseResponse",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"(",
"$",
"parts",
"=",
"$",
"this",
"->",
"parseMessage",
"(",
"$",
"message",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"list",
"(",
"$",
"protocol",
",",
"$",
"version",
")",
"=",
"explode",
"(",
"'/'",
",",
"trim",
"(",
"$",
"parts",
"[",
"'start_line'",
"]",
"[",
"0",
"]",
")",
")",
";",
"return",
"[",
"'protocol'",
"=>",
"$",
"protocol",
",",
"'protocol_version'",
"=>",
"$",
"version",
",",
"'code'",
"=>",
"$",
"parts",
"[",
"'start_line'",
"]",
"[",
"1",
"]",
",",
"'reason_phrase'",
"=>",
"isset",
"(",
"$",
"parts",
"[",
"'start_line'",
"]",
"[",
"2",
"]",
")",
"?",
"$",
"parts",
"[",
"'start_line'",
"]",
"[",
"2",
"]",
":",
"''",
",",
"'headers'",
"=>",
"$",
"parts",
"[",
"'headers'",
"]",
",",
"'body'",
"=>",
"$",
"parts",
"[",
"'body'",
"]",
"]",
";",
"}"
] | Parse an HTTP response message into an associative array of parts.
@param string $message HTTP response to parse
@return array|bool Returns false if the message is invalid | [
"Parse",
"an",
"HTTP",
"response",
"message",
"into",
"an",
"associative",
"array",
"of",
"parts",
"."
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Message/MessageParser.php#L54-L70 | train |
horntell/php-sdk | lib/guzzle/GuzzleHttp/Message/MessageParser.php | MessageParser.parseMessage | private function parseMessage($message)
{
if (!$message) {
return false;
}
$startLine = null;
$headers = [];
$body = '';
// Iterate over each line in the message, accounting for line endings
$lines = preg_split('/(\\r?\\n)/', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
for ($i = 0, $totalLines = count($lines); $i < $totalLines; $i += 2) {
$line = $lines[$i];
// If two line breaks were encountered, then this is the end of body
if (empty($line)) {
if ($i < $totalLines - 1) {
$body = implode('', array_slice($lines, $i + 2));
}
break;
}
// Parse message headers
if (!$startLine) {
$startLine = explode(' ', $line, 3);
} elseif (strpos($line, ':')) {
$parts = explode(':', $line, 2);
$key = trim($parts[0]);
$value = isset($parts[1]) ? trim($parts[1]) : '';
if (!isset($headers[$key])) {
$headers[$key] = $value;
} elseif (!is_array($headers[$key])) {
$headers[$key] = [$headers[$key], $value];
} else {
$headers[$key][] = $value;
}
}
}
return [
'start_line' => $startLine,
'headers' => $headers,
'body' => $body
];
} | php | private function parseMessage($message)
{
if (!$message) {
return false;
}
$startLine = null;
$headers = [];
$body = '';
// Iterate over each line in the message, accounting for line endings
$lines = preg_split('/(\\r?\\n)/', $message, -1, PREG_SPLIT_DELIM_CAPTURE);
for ($i = 0, $totalLines = count($lines); $i < $totalLines; $i += 2) {
$line = $lines[$i];
// If two line breaks were encountered, then this is the end of body
if (empty($line)) {
if ($i < $totalLines - 1) {
$body = implode('', array_slice($lines, $i + 2));
}
break;
}
// Parse message headers
if (!$startLine) {
$startLine = explode(' ', $line, 3);
} elseif (strpos($line, ':')) {
$parts = explode(':', $line, 2);
$key = trim($parts[0]);
$value = isset($parts[1]) ? trim($parts[1]) : '';
if (!isset($headers[$key])) {
$headers[$key] = $value;
} elseif (!is_array($headers[$key])) {
$headers[$key] = [$headers[$key], $value];
} else {
$headers[$key][] = $value;
}
}
}
return [
'start_line' => $startLine,
'headers' => $headers,
'body' => $body
];
} | [
"private",
"function",
"parseMessage",
"(",
"$",
"message",
")",
"{",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"return",
"false",
";",
"}",
"$",
"startLine",
"=",
"null",
";",
"$",
"headers",
"=",
"[",
"]",
";",
"$",
"body",
"=",
"''",
";",
"// Iterate over each line in the message, accounting for line endings",
"$",
"lines",
"=",
"preg_split",
"(",
"'/(\\\\r?\\\\n)/'",
",",
"$",
"message",
",",
"-",
"1",
",",
"PREG_SPLIT_DELIM_CAPTURE",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
",",
"$",
"totalLines",
"=",
"count",
"(",
"$",
"lines",
")",
";",
"$",
"i",
"<",
"$",
"totalLines",
";",
"$",
"i",
"+=",
"2",
")",
"{",
"$",
"line",
"=",
"$",
"lines",
"[",
"$",
"i",
"]",
";",
"// If two line breaks were encountered, then this is the end of body",
"if",
"(",
"empty",
"(",
"$",
"line",
")",
")",
"{",
"if",
"(",
"$",
"i",
"<",
"$",
"totalLines",
"-",
"1",
")",
"{",
"$",
"body",
"=",
"implode",
"(",
"''",
",",
"array_slice",
"(",
"$",
"lines",
",",
"$",
"i",
"+",
"2",
")",
")",
";",
"}",
"break",
";",
"}",
"// Parse message headers",
"if",
"(",
"!",
"$",
"startLine",
")",
"{",
"$",
"startLine",
"=",
"explode",
"(",
"' '",
",",
"$",
"line",
",",
"3",
")",
";",
"}",
"elseif",
"(",
"strpos",
"(",
"$",
"line",
",",
"':'",
")",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"':'",
",",
"$",
"line",
",",
"2",
")",
";",
"$",
"key",
"=",
"trim",
"(",
"$",
"parts",
"[",
"0",
"]",
")",
";",
"$",
"value",
"=",
"isset",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
"?",
"trim",
"(",
"$",
"parts",
"[",
"1",
"]",
")",
":",
"''",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"headers",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"headers",
"[",
"$",
"key",
"]",
"=",
"$",
"value",
";",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"headers",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"headers",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"headers",
"[",
"$",
"key",
"]",
",",
"$",
"value",
"]",
";",
"}",
"else",
"{",
"$",
"headers",
"[",
"$",
"key",
"]",
"[",
"]",
"=",
"$",
"value",
";",
"}",
"}",
"}",
"return",
"[",
"'start_line'",
"=>",
"$",
"startLine",
",",
"'headers'",
"=>",
"$",
"headers",
",",
"'body'",
"=>",
"$",
"body",
"]",
";",
"}"
] | Parse a message into parts
@param string $message Message to parse
@return array|bool | [
"Parse",
"a",
"message",
"into",
"parts"
] | e5205e9396a21b754d5651a8aa5898da5922a1b7 | https://github.com/horntell/php-sdk/blob/e5205e9396a21b754d5651a8aa5898da5922a1b7/lib/guzzle/GuzzleHttp/Message/MessageParser.php#L79-L125 | train |
infusephp/cron | src/Libs/CronDate.php | CronDate.calculate | private function calculate()
{
$this->second = 0;
$iters = 0;
$maxIters = 100;
while ($iters < $maxIters && !$this->satisfied()) {
if ($this->params->minute !== '*' && ($this->minute != $this->params->minute)) {
if ($this->minute > $this->params->minute) {
$this->modify('+1 hour');
}
$this->minute = $this->params->minute;
}
if ($this->params->hour !== '*' && ($this->hour != $this->params->hour)) {
if ($this->hour > $this->params->hour) {
$this->modify('+1 day');
}
$this->hour = $this->params->hour;
$this->minute = 0;
}
if ($this->params->week !== '*' && ($this->week != $this->params->week)) {
$this->week = $this->params->week;
$this->hour = 0;
$this->minute = 0;
}
if ($this->params->day !== '*' && ($this->day != $this->params->day)) {
if ($this->day > $this->params->day) {
$this->modify('+1 month');
}
$this->day = $this->params->day;
$this->hour = 0;
$this->minute = 0;
}
if ($this->params->month !== '*' && ($this->month != $this->params->month)) {
if ($this->month > $this->params->month) {
$this->modify('+1 year');
}
$this->month = $this->params->month;
$this->day = 1;
$this->hour = 0;
$this->minute = 0;
}
++$iters;
}
} | php | private function calculate()
{
$this->second = 0;
$iters = 0;
$maxIters = 100;
while ($iters < $maxIters && !$this->satisfied()) {
if ($this->params->minute !== '*' && ($this->minute != $this->params->minute)) {
if ($this->minute > $this->params->minute) {
$this->modify('+1 hour');
}
$this->minute = $this->params->minute;
}
if ($this->params->hour !== '*' && ($this->hour != $this->params->hour)) {
if ($this->hour > $this->params->hour) {
$this->modify('+1 day');
}
$this->hour = $this->params->hour;
$this->minute = 0;
}
if ($this->params->week !== '*' && ($this->week != $this->params->week)) {
$this->week = $this->params->week;
$this->hour = 0;
$this->minute = 0;
}
if ($this->params->day !== '*' && ($this->day != $this->params->day)) {
if ($this->day > $this->params->day) {
$this->modify('+1 month');
}
$this->day = $this->params->day;
$this->hour = 0;
$this->minute = 0;
}
if ($this->params->month !== '*' && ($this->month != $this->params->month)) {
if ($this->month > $this->params->month) {
$this->modify('+1 year');
}
$this->month = $this->params->month;
$this->day = 1;
$this->hour = 0;
$this->minute = 0;
}
++$iters;
}
} | [
"private",
"function",
"calculate",
"(",
")",
"{",
"$",
"this",
"->",
"second",
"=",
"0",
";",
"$",
"iters",
"=",
"0",
";",
"$",
"maxIters",
"=",
"100",
";",
"while",
"(",
"$",
"iters",
"<",
"$",
"maxIters",
"&&",
"!",
"$",
"this",
"->",
"satisfied",
"(",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"params",
"->",
"minute",
"!==",
"'*'",
"&&",
"(",
"$",
"this",
"->",
"minute",
"!=",
"$",
"this",
"->",
"params",
"->",
"minute",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"minute",
">",
"$",
"this",
"->",
"params",
"->",
"minute",
")",
"{",
"$",
"this",
"->",
"modify",
"(",
"'+1 hour'",
")",
";",
"}",
"$",
"this",
"->",
"minute",
"=",
"$",
"this",
"->",
"params",
"->",
"minute",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"params",
"->",
"hour",
"!==",
"'*'",
"&&",
"(",
"$",
"this",
"->",
"hour",
"!=",
"$",
"this",
"->",
"params",
"->",
"hour",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hour",
">",
"$",
"this",
"->",
"params",
"->",
"hour",
")",
"{",
"$",
"this",
"->",
"modify",
"(",
"'+1 day'",
")",
";",
"}",
"$",
"this",
"->",
"hour",
"=",
"$",
"this",
"->",
"params",
"->",
"hour",
";",
"$",
"this",
"->",
"minute",
"=",
"0",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"params",
"->",
"week",
"!==",
"'*'",
"&&",
"(",
"$",
"this",
"->",
"week",
"!=",
"$",
"this",
"->",
"params",
"->",
"week",
")",
")",
"{",
"$",
"this",
"->",
"week",
"=",
"$",
"this",
"->",
"params",
"->",
"week",
";",
"$",
"this",
"->",
"hour",
"=",
"0",
";",
"$",
"this",
"->",
"minute",
"=",
"0",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"params",
"->",
"day",
"!==",
"'*'",
"&&",
"(",
"$",
"this",
"->",
"day",
"!=",
"$",
"this",
"->",
"params",
"->",
"day",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"day",
">",
"$",
"this",
"->",
"params",
"->",
"day",
")",
"{",
"$",
"this",
"->",
"modify",
"(",
"'+1 month'",
")",
";",
"}",
"$",
"this",
"->",
"day",
"=",
"$",
"this",
"->",
"params",
"->",
"day",
";",
"$",
"this",
"->",
"hour",
"=",
"0",
";",
"$",
"this",
"->",
"minute",
"=",
"0",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"params",
"->",
"month",
"!==",
"'*'",
"&&",
"(",
"$",
"this",
"->",
"month",
"!=",
"$",
"this",
"->",
"params",
"->",
"month",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"month",
">",
"$",
"this",
"->",
"params",
"->",
"month",
")",
"{",
"$",
"this",
"->",
"modify",
"(",
"'+1 year'",
")",
";",
"}",
"$",
"this",
"->",
"month",
"=",
"$",
"this",
"->",
"params",
"->",
"month",
";",
"$",
"this",
"->",
"day",
"=",
"1",
";",
"$",
"this",
"->",
"hour",
"=",
"0",
";",
"$",
"this",
"->",
"minute",
"=",
"0",
";",
"}",
"++",
"$",
"iters",
";",
"}",
"}"
] | Calculates the next run timestamp. | [
"Calculates",
"the",
"next",
"run",
"timestamp",
"."
] | 783f6078b455a48415efeba0a6ee97ab17a3a903 | https://github.com/infusephp/cron/blob/783f6078b455a48415efeba0a6ee97ab17a3a903/src/Libs/CronDate.php#L103-L156 | train |
infusephp/cron | src/Libs/CronDate.php | CronDate.satisfied | private function satisfied()
{
return ($this->params->minute === '*' || $this->params->minute == $this->minute) &&
($this->params->hour === '*' || $this->params->hour == $this->hour) &&
($this->params->day === '*' || $this->params->day == $this->day) &&
($this->params->month === '*' || $this->params->month == $this->month) &&
($this->params->week === '*' || $this->params->week == $this->week);
} | php | private function satisfied()
{
return ($this->params->minute === '*' || $this->params->minute == $this->minute) &&
($this->params->hour === '*' || $this->params->hour == $this->hour) &&
($this->params->day === '*' || $this->params->day == $this->day) &&
($this->params->month === '*' || $this->params->month == $this->month) &&
($this->params->week === '*' || $this->params->week == $this->week);
} | [
"private",
"function",
"satisfied",
"(",
")",
"{",
"return",
"(",
"$",
"this",
"->",
"params",
"->",
"minute",
"===",
"'*'",
"||",
"$",
"this",
"->",
"params",
"->",
"minute",
"==",
"$",
"this",
"->",
"minute",
")",
"&&",
"(",
"$",
"this",
"->",
"params",
"->",
"hour",
"===",
"'*'",
"||",
"$",
"this",
"->",
"params",
"->",
"hour",
"==",
"$",
"this",
"->",
"hour",
")",
"&&",
"(",
"$",
"this",
"->",
"params",
"->",
"day",
"===",
"'*'",
"||",
"$",
"this",
"->",
"params",
"->",
"day",
"==",
"$",
"this",
"->",
"day",
")",
"&&",
"(",
"$",
"this",
"->",
"params",
"->",
"month",
"===",
"'*'",
"||",
"$",
"this",
"->",
"params",
"->",
"month",
"==",
"$",
"this",
"->",
"month",
")",
"&&",
"(",
"$",
"this",
"->",
"params",
"->",
"week",
"===",
"'*'",
"||",
"$",
"this",
"->",
"params",
"->",
"week",
"==",
"$",
"this",
"->",
"week",
")",
";",
"}"
] | Checks if the calculated next run timestamp
satisfies the date parameters.
@return bool | [
"Checks",
"if",
"the",
"calculated",
"next",
"run",
"timestamp",
"satisfies",
"the",
"date",
"parameters",
"."
] | 783f6078b455a48415efeba0a6ee97ab17a3a903 | https://github.com/infusephp/cron/blob/783f6078b455a48415efeba0a6ee97ab17a3a903/src/Libs/CronDate.php#L164-L171 | train |
codeblanche/Web | src/Web/Route/Abstraction/AbstractRule.php | AbstractRule.matchFilters | protected function matchFilters($params)
{
foreach ($this->filters as $key => $expression) {
if (!isset($params[$key])) {
return false;
}
if (!preg_match($expression, $params[$key])) {
return false;
}
}
return true;
} | php | protected function matchFilters($params)
{
foreach ($this->filters as $key => $expression) {
if (!isset($params[$key])) {
return false;
}
if (!preg_match($expression, $params[$key])) {
return false;
}
}
return true;
} | [
"protected",
"function",
"matchFilters",
"(",
"$",
"params",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"as",
"$",
"key",
"=>",
"$",
"expression",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"preg_match",
"(",
"$",
"expression",
",",
"$",
"params",
"[",
"$",
"key",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Validate params against given expressions.
@param $params
@return bool | [
"Validate",
"params",
"against",
"given",
"expressions",
"."
] | 3e9ebf1943d3ea468f619ba99f7cc10714cb16e9 | https://github.com/codeblanche/Web/blob/3e9ebf1943d3ea468f619ba99f7cc10714cb16e9/src/Web/Route/Abstraction/AbstractRule.php#L133-L146 | train |
freialib/ran.tools | src/Field/Select.php | SelectField.liefhierarchy_parse_options | protected function liefhierarchy_parse_options(array $options) {
foreach ($options as $key => $label) {
if (is_array($label)) {
$option = \ran\HTMLTag::i($this->confs, 'option', $key)
->set('disabled', '');
$this->appendtagbody($option->render());
$this->liefhierarchy_parse_options($label);
}
else { # $value not array
$option = \ran\HTMLTag::i($this->confs, 'option', $label)
->set('value', $key);
if ($this->values !== null && in_array(strval($key), $this->values, false)) {
$option->set('selected', '');
}
$this->appendtagbody($option->render());
}
}
} | php | protected function liefhierarchy_parse_options(array $options) {
foreach ($options as $key => $label) {
if (is_array($label)) {
$option = \ran\HTMLTag::i($this->confs, 'option', $key)
->set('disabled', '');
$this->appendtagbody($option->render());
$this->liefhierarchy_parse_options($label);
}
else { # $value not array
$option = \ran\HTMLTag::i($this->confs, 'option', $label)
->set('value', $key);
if ($this->values !== null && in_array(strval($key), $this->values, false)) {
$option->set('selected', '');
}
$this->appendtagbody($option->render());
}
}
} | [
"protected",
"function",
"liefhierarchy_parse_options",
"(",
"array",
"$",
"options",
")",
"{",
"foreach",
"(",
"$",
"options",
"as",
"$",
"key",
"=>",
"$",
"label",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"label",
")",
")",
"{",
"$",
"option",
"=",
"\\",
"ran",
"\\",
"HTMLTag",
"::",
"i",
"(",
"$",
"this",
"->",
"confs",
",",
"'option'",
",",
"$",
"key",
")",
"->",
"set",
"(",
"'disabled'",
",",
"''",
")",
";",
"$",
"this",
"->",
"appendtagbody",
"(",
"$",
"option",
"->",
"render",
"(",
")",
")",
";",
"$",
"this",
"->",
"liefhierarchy_parse_options",
"(",
"$",
"label",
")",
";",
"}",
"else",
"{",
"# $value not array",
"$",
"option",
"=",
"\\",
"ran",
"\\",
"HTMLTag",
"::",
"i",
"(",
"$",
"this",
"->",
"confs",
",",
"'option'",
",",
"$",
"label",
")",
"->",
"set",
"(",
"'value'",
",",
"$",
"key",
")",
";",
"if",
"(",
"$",
"this",
"->",
"values",
"!==",
"null",
"&&",
"in_array",
"(",
"strval",
"(",
"$",
"key",
")",
",",
"$",
"this",
"->",
"values",
",",
"false",
")",
")",
"{",
"$",
"option",
"->",
"set",
"(",
"'selected'",
",",
"''",
")",
";",
"}",
"$",
"this",
"->",
"appendtagbody",
"(",
"$",
"option",
"->",
"render",
"(",
")",
")",
";",
"}",
"}",
"}"
] | Parses hierarchy input array. | [
"Parses",
"hierarchy",
"input",
"array",
"."
] | f4cbb926ef54da357b102cbfa4b6ce273be6ce63 | https://github.com/freialib/ran.tools/blob/f4cbb926ef54da357b102cbfa4b6ce273be6ce63/src/Field/Select.php#L169-L189 | train |
freialib/ran.tools | src/Field/Select.php | SelectField.options_table | function options_table(array $table, $valuekey = null, $labelkey = null, $groupkey = null) {
$optgroups = [];
$options = [];
if ($groupkey === null) {
$options = static::associativeFrom($table, $valuekey, $labelkey);
}
else { # got group key
foreach ($table as $row) {
if ($row[$groupkey] !== null) {
isset($optgroups[$row[$groupkey]]) or $optgroups[$row[$groupkey]] = [];
$optgroups[$row[$groupkey]][$row[$valuekey]] = $row[$labelkey];
}
else { # null group
$options[$row[$valuekey]] = $row[$labelkey];
}
}
}
$this->options_array($options);
$this->optgroups_array($optgroups);
return $this;
} | php | function options_table(array $table, $valuekey = null, $labelkey = null, $groupkey = null) {
$optgroups = [];
$options = [];
if ($groupkey === null) {
$options = static::associativeFrom($table, $valuekey, $labelkey);
}
else { # got group key
foreach ($table as $row) {
if ($row[$groupkey] !== null) {
isset($optgroups[$row[$groupkey]]) or $optgroups[$row[$groupkey]] = [];
$optgroups[$row[$groupkey]][$row[$valuekey]] = $row[$labelkey];
}
else { # null group
$options[$row[$valuekey]] = $row[$labelkey];
}
}
}
$this->options_array($options);
$this->optgroups_array($optgroups);
return $this;
} | [
"function",
"options_table",
"(",
"array",
"$",
"table",
",",
"$",
"valuekey",
"=",
"null",
",",
"$",
"labelkey",
"=",
"null",
",",
"$",
"groupkey",
"=",
"null",
")",
"{",
"$",
"optgroups",
"=",
"[",
"]",
";",
"$",
"options",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"groupkey",
"===",
"null",
")",
"{",
"$",
"options",
"=",
"static",
"::",
"associativeFrom",
"(",
"$",
"table",
",",
"$",
"valuekey",
",",
"$",
"labelkey",
")",
";",
"}",
"else",
"{",
"# got group key",
"foreach",
"(",
"$",
"table",
"as",
"$",
"row",
")",
"{",
"if",
"(",
"$",
"row",
"[",
"$",
"groupkey",
"]",
"!==",
"null",
")",
"{",
"isset",
"(",
"$",
"optgroups",
"[",
"$",
"row",
"[",
"$",
"groupkey",
"]",
"]",
")",
"or",
"$",
"optgroups",
"[",
"$",
"row",
"[",
"$",
"groupkey",
"]",
"]",
"=",
"[",
"]",
";",
"$",
"optgroups",
"[",
"$",
"row",
"[",
"$",
"groupkey",
"]",
"]",
"[",
"$",
"row",
"[",
"$",
"valuekey",
"]",
"]",
"=",
"$",
"row",
"[",
"$",
"labelkey",
"]",
";",
"}",
"else",
"{",
"# null group",
"$",
"options",
"[",
"$",
"row",
"[",
"$",
"valuekey",
"]",
"]",
"=",
"$",
"row",
"[",
"$",
"labelkey",
"]",
";",
"}",
"}",
"}",
"$",
"this",
"->",
"options_array",
"(",
"$",
"options",
")",
";",
"$",
"this",
"->",
"optgroups_array",
"(",
"$",
"optgroups",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Inserts values by interpreting tablular array as is typically the result
of a SQL call. If the table is nonstandard you can provide an idkey and
titlekey to help the function retrieve the correct values.
Typically defaults for idkey and title key are "id" and "title."
If groupkey is provided the method will insert optgroups instead of
normal options, unless the value for the group is null.
@return static $this | [
"Inserts",
"values",
"by",
"interpreting",
"tablular",
"array",
"as",
"is",
"typically",
"the",
"result",
"of",
"a",
"SQL",
"call",
".",
"If",
"the",
"table",
"is",
"nonstandard",
"you",
"can",
"provide",
"an",
"idkey",
"and",
"titlekey",
"to",
"help",
"the",
"function",
"retrieve",
"the",
"correct",
"values",
"."
] | f4cbb926ef54da357b102cbfa4b6ce273be6ce63 | https://github.com/freialib/ran.tools/blob/f4cbb926ef54da357b102cbfa4b6ce273be6ce63/src/Field/Select.php#L208-L231 | train |
freialib/ran.tools | src/Field/Select.php | SelectField.associativeFrom | protected static function associativeFrom(array &$table, $key_ref = 'id', $value_ref = 'title') {
$assoc = [];
foreach ($table as $row) {
$assoc[$row[$key_ref]] = $row[$value_ref];
}
return $assoc;
} | php | protected static function associativeFrom(array &$table, $key_ref = 'id', $value_ref = 'title') {
$assoc = [];
foreach ($table as $row) {
$assoc[$row[$key_ref]] = $row[$value_ref];
}
return $assoc;
} | [
"protected",
"static",
"function",
"associativeFrom",
"(",
"array",
"&",
"$",
"table",
",",
"$",
"key_ref",
"=",
"'id'",
",",
"$",
"value_ref",
"=",
"'title'",
")",
"{",
"$",
"assoc",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"table",
"as",
"$",
"row",
")",
"{",
"$",
"assoc",
"[",
"$",
"row",
"[",
"$",
"key_ref",
"]",
"]",
"=",
"$",
"row",
"[",
"$",
"value_ref",
"]",
";",
"}",
"return",
"$",
"assoc",
";",
"}"
] | Given an array converts it to an associative array based on the key
and value reference provided.
@param array array
@param string key reference
@param string value reference
@return array | [
"Given",
"an",
"array",
"converts",
"it",
"to",
"an",
"associative",
"array",
"based",
"on",
"the",
"key",
"and",
"value",
"reference",
"provided",
"."
] | f4cbb926ef54da357b102cbfa4b6ce273be6ce63 | https://github.com/freialib/ran.tools/blob/f4cbb926ef54da357b102cbfa4b6ce273be6ce63/src/Field/Select.php#L271-L277 | train |
SlaxWeb/Router | src/Container.php | Container.add | public function add(Route $route): self
{
if ($route->uri === ""
|| $route->method === 0b0
|| $route->action === null) {
$this->logger->error("Route incomplete. Unable to add");
$this->logger->debug("Incomplete Route", [$route]);
throw new Exception\RouteIncompleteException(
"Retrieved Route is not complete and can not be stored"
);
}
// store default route
if ($route->isDefault) {
if ($this->defaultRoute === null) {
$this->defaultRoute = $route;
} else {
$this->logger->debug(
"Default route already added to container, skipping add.",
["route" => $route, "storedDefault" => $this->defaultRoute]
);
}
}
// store 404 route
if ($route->is404) {
if ($this->e404Route === null) {
$this->e404Route = $route;
$this->logger->info("404 route added to Route Container");
} else {
$this->logger->debug(
"404 route already added to container, skipping add.",
["route" => $route, "stored404" => $this->e404Route]
);
}
return $this;
}
// store route to regular container
$this->routes[] = $route;
$this->logger->info(
"Route successfully added to Container",
["uri" => $route->uri]
);
return $this;
} | php | public function add(Route $route): self
{
if ($route->uri === ""
|| $route->method === 0b0
|| $route->action === null) {
$this->logger->error("Route incomplete. Unable to add");
$this->logger->debug("Incomplete Route", [$route]);
throw new Exception\RouteIncompleteException(
"Retrieved Route is not complete and can not be stored"
);
}
// store default route
if ($route->isDefault) {
if ($this->defaultRoute === null) {
$this->defaultRoute = $route;
} else {
$this->logger->debug(
"Default route already added to container, skipping add.",
["route" => $route, "storedDefault" => $this->defaultRoute]
);
}
}
// store 404 route
if ($route->is404) {
if ($this->e404Route === null) {
$this->e404Route = $route;
$this->logger->info("404 route added to Route Container");
} else {
$this->logger->debug(
"404 route already added to container, skipping add.",
["route" => $route, "stored404" => $this->e404Route]
);
}
return $this;
}
// store route to regular container
$this->routes[] = $route;
$this->logger->info(
"Route successfully added to Container",
["uri" => $route->uri]
);
return $this;
} | [
"public",
"function",
"add",
"(",
"Route",
"$",
"route",
")",
":",
"self",
"{",
"if",
"(",
"$",
"route",
"->",
"uri",
"===",
"\"\"",
"||",
"$",
"route",
"->",
"method",
"===",
"0b0",
"||",
"$",
"route",
"->",
"action",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"error",
"(",
"\"Route incomplete. Unable to add\"",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"Incomplete Route\"",
",",
"[",
"$",
"route",
"]",
")",
";",
"throw",
"new",
"Exception",
"\\",
"RouteIncompleteException",
"(",
"\"Retrieved Route is not complete and can not be stored\"",
")",
";",
"}",
"// store default route",
"if",
"(",
"$",
"route",
"->",
"isDefault",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"defaultRoute",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"defaultRoute",
"=",
"$",
"route",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"Default route already added to container, skipping add.\"",
",",
"[",
"\"route\"",
"=>",
"$",
"route",
",",
"\"storedDefault\"",
"=>",
"$",
"this",
"->",
"defaultRoute",
"]",
")",
";",
"}",
"}",
"// store 404 route",
"if",
"(",
"$",
"route",
"->",
"is404",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"e404Route",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"e404Route",
"=",
"$",
"route",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"\"404 route added to Route Container\"",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"\"404 route already added to container, skipping add.\"",
",",
"[",
"\"route\"",
"=>",
"$",
"route",
",",
"\"stored404\"",
"=>",
"$",
"this",
"->",
"e404Route",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}",
"// store route to regular container",
"$",
"this",
"->",
"routes",
"[",
"]",
"=",
"$",
"route",
";",
"$",
"this",
"->",
"logger",
"->",
"info",
"(",
"\"Route successfully added to Container\"",
",",
"[",
"\"uri\"",
"=>",
"$",
"route",
"->",
"uri",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Add Route definition
Add the retrieved Route to the internal Routes container array. If the
retrieved Route is not complete, throw the 'RouteIncompleteException'.
@param \SlaxWeb\Router\Route $route Route definition object
@return self | [
"Add",
"Route",
"definition"
] | b4a25655710638c71787a8498d267a663ef2e819 | https://github.com/SlaxWeb/Router/blob/b4a25655710638c71787a8498d267a663ef2e819/src/Container.php#L78-L126 | train |
SlaxWeb/Router | src/Container.php | Container.iterateRoutes | protected function iterateRoutes(string $function)
{
if (($route = $function($this->routes)) !== false) {
$this->currentRoute = $route;
return $this->currentRoute;
}
return false;
} | php | protected function iterateRoutes(string $function)
{
if (($route = $function($this->routes)) !== false) {
$this->currentRoute = $route;
return $this->currentRoute;
}
return false;
} | [
"protected",
"function",
"iterateRoutes",
"(",
"string",
"$",
"function",
")",
"{",
"if",
"(",
"(",
"$",
"route",
"=",
"$",
"function",
"(",
"$",
"this",
"->",
"routes",
")",
")",
"!==",
"false",
")",
"{",
"$",
"this",
"->",
"currentRoute",
"=",
"$",
"route",
";",
"return",
"$",
"this",
"->",
"currentRoute",
";",
"}",
"return",
"false",
";",
"}"
] | Iterate internal Routes array
Provides a unified method for iterating the Routes array with PHP
functions, 'next', 'prev', 'current', and 'end'. Returns the Route on the
position that is desired, if no Route is found, false is returned.
@param string $function Function name for array iteration
@return \SlaxWeb\Router\Route|bool | [
"Iterate",
"internal",
"Routes",
"array"
] | b4a25655710638c71787a8498d267a663ef2e819 | https://github.com/SlaxWeb/Router/blob/b4a25655710638c71787a8498d267a663ef2e819/src/Container.php#L210-L217 | train |
ManifestWebDesign/dabl-orm | src/Model.php | Model.getColumnNames | static function getColumnNames() {
$class = get_called_class();
if (!isset(self::$_columnNames[$class])) {
self::$_columnNames[$class] = array_keys(static::$_columns);
}
return self::$_columnNames[$class];
} | php | static function getColumnNames() {
$class = get_called_class();
if (!isset(self::$_columnNames[$class])) {
self::$_columnNames[$class] = array_keys(static::$_columns);
}
return self::$_columnNames[$class];
} | [
"static",
"function",
"getColumnNames",
"(",
")",
"{",
"$",
"class",
"=",
"get_called_class",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"_columnNames",
"[",
"$",
"class",
"]",
")",
")",
"{",
"self",
"::",
"$",
"_columnNames",
"[",
"$",
"class",
"]",
"=",
"array_keys",
"(",
"static",
"::",
"$",
"_columns",
")",
";",
"}",
"return",
"self",
"::",
"$",
"_columnNames",
"[",
"$",
"class",
"]",
";",
"}"
] | Access to array of column names
@return array | [
"Access",
"to",
"array",
"of",
"column",
"names"
] | f216513e4b16251db7901c1773d00e13e3a49421 | https://github.com/ManifestWebDesign/dabl-orm/blob/f216513e4b16251db7901c1773d00e13e3a49421/src/Model.php#L291-L298 | train |
ManifestWebDesign/dabl-orm | src/Model.php | Model.getQuery | static function getQuery(array $params = array(), Query $q = null) {
$model_class = get_called_class();
$query_class = class_exists($model_class . 'Query') ? $model_class . 'Query' : 'Dabl\\Query\\Query';
$q = $q ? clone $q : new $query_class;
$tablename = $q->getTable();
if (!$tablename) {
$tablename = static::getTableName();
$q->setTable($tablename);
}
// If an alias has been set, use that for fully-qualified names, otherwise use the table name
$alias = $q->getAlias();
if (!$alias) {
$alias = $tablename;
}
// filters
foreach ($params as $key => &$param) {
if (static::hasColumn($key)) {
$column = static::normalizeColumnName($key);
$q->add("$alias.$column", strtolower($param) === 'null' ? null : $param);
}
}
// SortBy (alias of sort_by, deprecated)
if (isset($params['SortBy']) && !isset($params['order_by'])) {
$params['order_by'] = $params['SortBy'];
}
// order_by
if (isset($params['order_by']) && static::hasColumn($params['order_by'])) {
$q->orderBy($params['order_by'], isset($params['dir']) ? Query::DESC : Query::ASC);
}
// limit
if (isset($params['limit'])) {
$q->setLimit($params['limit']);
}
return $q;
} | php | static function getQuery(array $params = array(), Query $q = null) {
$model_class = get_called_class();
$query_class = class_exists($model_class . 'Query') ? $model_class . 'Query' : 'Dabl\\Query\\Query';
$q = $q ? clone $q : new $query_class;
$tablename = $q->getTable();
if (!$tablename) {
$tablename = static::getTableName();
$q->setTable($tablename);
}
// If an alias has been set, use that for fully-qualified names, otherwise use the table name
$alias = $q->getAlias();
if (!$alias) {
$alias = $tablename;
}
// filters
foreach ($params as $key => &$param) {
if (static::hasColumn($key)) {
$column = static::normalizeColumnName($key);
$q->add("$alias.$column", strtolower($param) === 'null' ? null : $param);
}
}
// SortBy (alias of sort_by, deprecated)
if (isset($params['SortBy']) && !isset($params['order_by'])) {
$params['order_by'] = $params['SortBy'];
}
// order_by
if (isset($params['order_by']) && static::hasColumn($params['order_by'])) {
$q->orderBy($params['order_by'], isset($params['dir']) ? Query::DESC : Query::ASC);
}
// limit
if (isset($params['limit'])) {
$q->setLimit($params['limit']);
}
return $q;
} | [
"static",
"function",
"getQuery",
"(",
"array",
"$",
"params",
"=",
"array",
"(",
")",
",",
"Query",
"$",
"q",
"=",
"null",
")",
"{",
"$",
"model_class",
"=",
"get_called_class",
"(",
")",
";",
"$",
"query_class",
"=",
"class_exists",
"(",
"$",
"model_class",
".",
"'Query'",
")",
"?",
"$",
"model_class",
".",
"'Query'",
":",
"'Dabl\\\\Query\\\\Query'",
";",
"$",
"q",
"=",
"$",
"q",
"?",
"clone",
"$",
"q",
":",
"new",
"$",
"query_class",
";",
"$",
"tablename",
"=",
"$",
"q",
"->",
"getTable",
"(",
")",
";",
"if",
"(",
"!",
"$",
"tablename",
")",
"{",
"$",
"tablename",
"=",
"static",
"::",
"getTableName",
"(",
")",
";",
"$",
"q",
"->",
"setTable",
"(",
"$",
"tablename",
")",
";",
"}",
"// If an alias has been set, use that for fully-qualified names, otherwise use the table name",
"$",
"alias",
"=",
"$",
"q",
"->",
"getAlias",
"(",
")",
";",
"if",
"(",
"!",
"$",
"alias",
")",
"{",
"$",
"alias",
"=",
"$",
"tablename",
";",
"}",
"// filters",
"foreach",
"(",
"$",
"params",
"as",
"$",
"key",
"=>",
"&",
"$",
"param",
")",
"{",
"if",
"(",
"static",
"::",
"hasColumn",
"(",
"$",
"key",
")",
")",
"{",
"$",
"column",
"=",
"static",
"::",
"normalizeColumnName",
"(",
"$",
"key",
")",
";",
"$",
"q",
"->",
"add",
"(",
"\"$alias.$column\"",
",",
"strtolower",
"(",
"$",
"param",
")",
"===",
"'null'",
"?",
"null",
":",
"$",
"param",
")",
";",
"}",
"}",
"// SortBy (alias of sort_by, deprecated)",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'SortBy'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"params",
"[",
"'order_by'",
"]",
")",
")",
"{",
"$",
"params",
"[",
"'order_by'",
"]",
"=",
"$",
"params",
"[",
"'SortBy'",
"]",
";",
"}",
"// order_by",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'order_by'",
"]",
")",
"&&",
"static",
"::",
"hasColumn",
"(",
"$",
"params",
"[",
"'order_by'",
"]",
")",
")",
"{",
"$",
"q",
"->",
"orderBy",
"(",
"$",
"params",
"[",
"'order_by'",
"]",
",",
"isset",
"(",
"$",
"params",
"[",
"'dir'",
"]",
")",
"?",
"Query",
"::",
"DESC",
":",
"Query",
"::",
"ASC",
")",
";",
"}",
"// limit",
"if",
"(",
"isset",
"(",
"$",
"params",
"[",
"'limit'",
"]",
")",
")",
"{",
"$",
"q",
"->",
"setLimit",
"(",
"$",
"params",
"[",
"'limit'",
"]",
")",
";",
"}",
"return",
"$",
"q",
";",
"}"
] | Given an array of params, construct a query where the keys are used as column names
and values as query parameters. Will try to do fully-qualified names.
@return Query | [
"Given",
"an",
"array",
"of",
"params",
"construct",
"a",
"query",
"where",
"the",
"keys",
"are",
"used",
"as",
"column",
"names",
"and",
"values",
"as",
"query",
"parameters",
".",
"Will",
"try",
"to",
"do",
"fully",
"-",
"qualified",
"names",
"."
] | f216513e4b16251db7901c1773d00e13e3a49421 | https://github.com/ManifestWebDesign/dabl-orm/blob/f216513e4b16251db7901c1773d00e13e3a49421/src/Model.php#L479-L521 | train |
ManifestWebDesign/dabl-orm | src/Model.php | Model.retrieveFromPool | static function retrieveFromPool($pk_value) {
if (!static::$_poolEnabled || null === $pk_value) {
return null;
}
$pk_value = (string) $pk_value;
if (isset(static::$_instancePool[$pk_value])) {
return static::$_instancePool[$pk_value];
}
return null;
} | php | static function retrieveFromPool($pk_value) {
if (!static::$_poolEnabled || null === $pk_value) {
return null;
}
$pk_value = (string) $pk_value;
if (isset(static::$_instancePool[$pk_value])) {
return static::$_instancePool[$pk_value];
}
return null;
} | [
"static",
"function",
"retrieveFromPool",
"(",
"$",
"pk_value",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"$",
"_poolEnabled",
"||",
"null",
"===",
"$",
"pk_value",
")",
"{",
"return",
"null",
";",
"}",
"$",
"pk_value",
"=",
"(",
"string",
")",
"$",
"pk_value",
";",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"_instancePool",
"[",
"$",
"pk_value",
"]",
")",
")",
"{",
"return",
"static",
"::",
"$",
"_instancePool",
"[",
"$",
"pk_value",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | Return the cached instance from the pool.
@param mixed $pk_value Primary Key
@return static | [
"Return",
"the",
"cached",
"instance",
"from",
"the",
"pool",
"."
] | f216513e4b16251db7901c1773d00e13e3a49421 | https://github.com/ManifestWebDesign/dabl-orm/blob/f216513e4b16251db7901c1773d00e13e3a49421/src/Model.php#L555-L566 | train |
ManifestWebDesign/dabl-orm | src/Model.php | Model.removeFromPool | static function removeFromPool($object_or_pk) {
$pool_key = $object_or_pk instanceof Model ? implode('-', $object_or_pk->getPrimaryKeyValues()) : $object_or_pk;
if (isset(static::$_instancePool[$pool_key])) {
unset(static::$_instancePool[$pool_key]);
--static::$_instancePoolCount;
}
} | php | static function removeFromPool($object_or_pk) {
$pool_key = $object_or_pk instanceof Model ? implode('-', $object_or_pk->getPrimaryKeyValues()) : $object_or_pk;
if (isset(static::$_instancePool[$pool_key])) {
unset(static::$_instancePool[$pool_key]);
--static::$_instancePoolCount;
}
} | [
"static",
"function",
"removeFromPool",
"(",
"$",
"object_or_pk",
")",
"{",
"$",
"pool_key",
"=",
"$",
"object_or_pk",
"instanceof",
"Model",
"?",
"implode",
"(",
"'-'",
",",
"$",
"object_or_pk",
"->",
"getPrimaryKeyValues",
"(",
")",
")",
":",
"$",
"object_or_pk",
";",
"if",
"(",
"isset",
"(",
"static",
"::",
"$",
"_instancePool",
"[",
"$",
"pool_key",
"]",
")",
")",
"{",
"unset",
"(",
"static",
"::",
"$",
"_instancePool",
"[",
"$",
"pool_key",
"]",
")",
";",
"--",
"static",
"::",
"$",
"_instancePoolCount",
";",
"}",
"}"
] | Remove the object from the instance pool.
@param mixed $object_or_pk Object or PK to remove
@return void | [
"Remove",
"the",
"object",
"from",
"the",
"instance",
"pool",
"."
] | f216513e4b16251db7901c1773d00e13e3a49421 | https://github.com/ManifestWebDesign/dabl-orm/blob/f216513e4b16251db7901c1773d00e13e3a49421/src/Model.php#L574-L581 | train |
ManifestWebDesign/dabl-orm | src/Model.php | Model.doSelectRS | static function doSelectRS(Query $q = null) {
$q = $q ? clone $q : static::getQuery();
if (!$q->getTable()) {
$q->setTable(static::getTableName());
}
return $q->doSelect(static::getConnection());
} | php | static function doSelectRS(Query $q = null) {
$q = $q ? clone $q : static::getQuery();
if (!$q->getTable()) {
$q->setTable(static::getTableName());
}
return $q->doSelect(static::getConnection());
} | [
"static",
"function",
"doSelectRS",
"(",
"Query",
"$",
"q",
"=",
"null",
")",
"{",
"$",
"q",
"=",
"$",
"q",
"?",
"clone",
"$",
"q",
":",
"static",
"::",
"getQuery",
"(",
")",
";",
"if",
"(",
"!",
"$",
"q",
"->",
"getTable",
"(",
")",
")",
"{",
"$",
"q",
"->",
"setTable",
"(",
"static",
"::",
"getTableName",
"(",
")",
")",
";",
"}",
"return",
"$",
"q",
"->",
"doSelect",
"(",
"static",
"::",
"getConnection",
"(",
")",
")",
";",
"}"
] | Executes a select query and returns the PDO result
@return PDOStatement | [
"Executes",
"a",
"select",
"query",
"and",
"returns",
"the",
"PDO",
"result"
] | f216513e4b16251db7901c1773d00e13e3a49421 | https://github.com/ManifestWebDesign/dabl-orm/blob/f216513e4b16251db7901c1773d00e13e3a49421/src/Model.php#L662-L670 | train |
ManifestWebDesign/dabl-orm | src/Model.php | Model.doSelectIterator | static function doSelectIterator(Query $q = null) {
$q = $q ? clone $q : static::getQuery();
if (!$q->getTable()) {
$q->setTable(static::getTableName());
}
return new QueryModelIterator($q, get_called_class());
} | php | static function doSelectIterator(Query $q = null) {
$q = $q ? clone $q : static::getQuery();
if (!$q->getTable()) {
$q->setTable(static::getTableName());
}
return new QueryModelIterator($q, get_called_class());
} | [
"static",
"function",
"doSelectIterator",
"(",
"Query",
"$",
"q",
"=",
"null",
")",
"{",
"$",
"q",
"=",
"$",
"q",
"?",
"clone",
"$",
"q",
":",
"static",
"::",
"getQuery",
"(",
")",
";",
"if",
"(",
"!",
"$",
"q",
"->",
"getTable",
"(",
")",
")",
"{",
"$",
"q",
"->",
"setTable",
"(",
"static",
"::",
"getTableName",
"(",
")",
")",
";",
"}",
"return",
"new",
"QueryModelIterator",
"(",
"$",
"q",
",",
"get_called_class",
"(",
")",
")",
";",
"}"
] | Returns a simple Iterator that wraps PDOStatement for lightweight foreach
@param Query $q
@return QueryModelIterator | [
"Returns",
"a",
"simple",
"Iterator",
"that",
"wraps",
"PDOStatement",
"for",
"lightweight",
"foreach"
] | f216513e4b16251db7901c1773d00e13e3a49421 | https://github.com/ManifestWebDesign/dabl-orm/blob/f216513e4b16251db7901c1773d00e13e3a49421/src/Model.php#L678-L686 | train |
ManifestWebDesign/dabl-orm | src/Model.php | Model.hasPrimaryKeyValues | function hasPrimaryKeyValues() {
$pks = static::$_primaryKeys;
if (!$pks)
return false;
foreach ($pks as &$pk)
if ($this->$pk === null)
return false;
return true;
} | php | function hasPrimaryKeyValues() {
$pks = static::$_primaryKeys;
if (!$pks)
return false;
foreach ($pks as &$pk)
if ($this->$pk === null)
return false;
return true;
} | [
"function",
"hasPrimaryKeyValues",
"(",
")",
"{",
"$",
"pks",
"=",
"static",
"::",
"$",
"_primaryKeys",
";",
"if",
"(",
"!",
"$",
"pks",
")",
"return",
"false",
";",
"foreach",
"(",
"$",
"pks",
"as",
"&",
"$",
"pk",
")",
"if",
"(",
"$",
"this",
"->",
"$",
"pk",
"===",
"null",
")",
"return",
"false",
";",
"return",
"true",
";",
"}"
] | Returns true if this table has primary keys and if all of the primary values are not null
@return bool | [
"Returns",
"true",
"if",
"this",
"table",
"has",
"primary",
"keys",
"and",
"if",
"all",
"of",
"the",
"primary",
"values",
"are",
"not",
"null"
] | f216513e4b16251db7901c1773d00e13e3a49421 | https://github.com/ManifestWebDesign/dabl-orm/blob/f216513e4b16251db7901c1773d00e13e3a49421/src/Model.php#L1169-L1178 | train |
ManifestWebDesign/dabl-orm | src/Model.php | Model.getPrimaryKeyValues | function getPrimaryKeyValues() {
$arr = array();
$pks = static::$_primaryKeys;
foreach ($pks as &$pk) {
$arr[] = $this->{"get$pk"}();
}
return $arr;
} | php | function getPrimaryKeyValues() {
$arr = array();
$pks = static::$_primaryKeys;
foreach ($pks as &$pk) {
$arr[] = $this->{"get$pk"}();
}
return $arr;
} | [
"function",
"getPrimaryKeyValues",
"(",
")",
"{",
"$",
"arr",
"=",
"array",
"(",
")",
";",
"$",
"pks",
"=",
"static",
"::",
"$",
"_primaryKeys",
";",
"foreach",
"(",
"$",
"pks",
"as",
"&",
"$",
"pk",
")",
"{",
"$",
"arr",
"[",
"]",
"=",
"$",
"this",
"->",
"{",
"\"get$pk\"",
"}",
"(",
")",
";",
"}",
"return",
"$",
"arr",
";",
"}"
] | Returns an array of all primary key values.
@return mixed[] | [
"Returns",
"an",
"array",
"of",
"all",
"primary",
"key",
"values",
"."
] | f216513e4b16251db7901c1773d00e13e3a49421 | https://github.com/ManifestWebDesign/dabl-orm/blob/f216513e4b16251db7901c1773d00e13e3a49421/src/Model.php#L1185-L1194 | train |
ManifestWebDesign/dabl-orm | src/Model.php | Model.castInts | function castInts() {
foreach (static::$_columns as $column_name => &$type) {
if ($this->{$column_name} === null || !static::isIntegerType($type)) {
continue;
}
if ('' === $this->{$column_name}) {
$this->{$column_name} = null;
continue;
}
$this->{$column_name} = (int) $this->{$column_name};
}
return $this;
} | php | function castInts() {
foreach (static::$_columns as $column_name => &$type) {
if ($this->{$column_name} === null || !static::isIntegerType($type)) {
continue;
}
if ('' === $this->{$column_name}) {
$this->{$column_name} = null;
continue;
}
$this->{$column_name} = (int) $this->{$column_name};
}
return $this;
} | [
"function",
"castInts",
"(",
")",
"{",
"foreach",
"(",
"static",
"::",
"$",
"_columns",
"as",
"$",
"column_name",
"=>",
"&",
"$",
"type",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"{",
"$",
"column_name",
"}",
"===",
"null",
"||",
"!",
"static",
"::",
"isIntegerType",
"(",
"$",
"type",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"''",
"===",
"$",
"this",
"->",
"{",
"$",
"column_name",
"}",
")",
"{",
"$",
"this",
"->",
"{",
"$",
"column_name",
"}",
"=",
"null",
";",
"continue",
";",
"}",
"$",
"this",
"->",
"{",
"$",
"column_name",
"}",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"{",
"$",
"column_name",
"}",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Cast returned values from the database into integers where appropriate.
@return static | [
"Cast",
"returned",
"values",
"from",
"the",
"database",
"into",
"integers",
"where",
"appropriate",
"."
] | f216513e4b16251db7901c1773d00e13e3a49421 | https://github.com/ManifestWebDesign/dabl-orm/blob/f216513e4b16251db7901c1773d00e13e3a49421/src/Model.php#L1337-L1349 | train |
ManifestWebDesign/dabl-orm | src/Model.php | Model.insert | protected function insert() {
$conn = static::getConnection();
$pk = static::getPrimaryKey();
$fields = array();
$values = array();
$placeholders = array();
foreach (static::$_columns as $column_name => &$type) {
$value = $this->$column_name;
if ($value === null && !$this->isColumnModified($column_name))
continue;
$fields[] = $conn->quoteIdentifier($column_name, true);
$values[] = $value;
$placeholders[] = '?';
}
$quoted_table = $conn->quoteIdentifier(static::getTableName(), true);
$query_s = 'INSERT INTO ' . $quoted_table . ' (' . implode(', ', $fields) . ')';
if ($pk && $this->isAutoIncrement() && $conn instanceof DBMSSQL) {
$query_s .= " OUTPUT inserted.$pk";
}
$query_s .= ' VALUES (' . implode(', ', $placeholders) . ') ';
if ($pk && $this->isAutoIncrement() && $conn instanceof DBPostgres) {
$query_s .= ' RETURNING ' . $conn->quoteIdentifier($pk, true);
}
$statement = new QueryStatement($conn);
$statement->setString($query_s);
$statement->setParams($values);
$result = $statement->bindAndExecute();
$count = $result->rowCount();
if ($pk && $this->isAutoIncrement()) {
$id = null;
if (($conn instanceof DBPostgres) || ($conn instanceof DBMSSQL)) {
$id = $result->fetchColumn(0);
} elseif ($conn->isGetIdAfterInsert()) {
$id = $conn->lastInsertId();
if (empty($id) && $conn instanceof DBRedshift) {
$id = $conn->query('SELECT MAX(' . $conn->quoteIdentifier($pk) . ") FROM $quoted_table")->fetchColumn();
}
}
if (null !== $id) {
$this->{"set$pk"}($id);
}
}
$this->resetModified();
$this->setNew(false);
$this->insertIntoPool($this);
return $count;
} | php | protected function insert() {
$conn = static::getConnection();
$pk = static::getPrimaryKey();
$fields = array();
$values = array();
$placeholders = array();
foreach (static::$_columns as $column_name => &$type) {
$value = $this->$column_name;
if ($value === null && !$this->isColumnModified($column_name))
continue;
$fields[] = $conn->quoteIdentifier($column_name, true);
$values[] = $value;
$placeholders[] = '?';
}
$quoted_table = $conn->quoteIdentifier(static::getTableName(), true);
$query_s = 'INSERT INTO ' . $quoted_table . ' (' . implode(', ', $fields) . ')';
if ($pk && $this->isAutoIncrement() && $conn instanceof DBMSSQL) {
$query_s .= " OUTPUT inserted.$pk";
}
$query_s .= ' VALUES (' . implode(', ', $placeholders) . ') ';
if ($pk && $this->isAutoIncrement() && $conn instanceof DBPostgres) {
$query_s .= ' RETURNING ' . $conn->quoteIdentifier($pk, true);
}
$statement = new QueryStatement($conn);
$statement->setString($query_s);
$statement->setParams($values);
$result = $statement->bindAndExecute();
$count = $result->rowCount();
if ($pk && $this->isAutoIncrement()) {
$id = null;
if (($conn instanceof DBPostgres) || ($conn instanceof DBMSSQL)) {
$id = $result->fetchColumn(0);
} elseif ($conn->isGetIdAfterInsert()) {
$id = $conn->lastInsertId();
if (empty($id) && $conn instanceof DBRedshift) {
$id = $conn->query('SELECT MAX(' . $conn->quoteIdentifier($pk) . ") FROM $quoted_table")->fetchColumn();
}
}
if (null !== $id) {
$this->{"set$pk"}($id);
}
}
$this->resetModified();
$this->setNew(false);
$this->insertIntoPool($this);
return $count;
} | [
"protected",
"function",
"insert",
"(",
")",
"{",
"$",
"conn",
"=",
"static",
"::",
"getConnection",
"(",
")",
";",
"$",
"pk",
"=",
"static",
"::",
"getPrimaryKey",
"(",
")",
";",
"$",
"fields",
"=",
"array",
"(",
")",
";",
"$",
"values",
"=",
"array",
"(",
")",
";",
"$",
"placeholders",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"static",
"::",
"$",
"_columns",
"as",
"$",
"column_name",
"=>",
"&",
"$",
"type",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"$",
"column_name",
";",
"if",
"(",
"$",
"value",
"===",
"null",
"&&",
"!",
"$",
"this",
"->",
"isColumnModified",
"(",
"$",
"column_name",
")",
")",
"continue",
";",
"$",
"fields",
"[",
"]",
"=",
"$",
"conn",
"->",
"quoteIdentifier",
"(",
"$",
"column_name",
",",
"true",
")",
";",
"$",
"values",
"[",
"]",
"=",
"$",
"value",
";",
"$",
"placeholders",
"[",
"]",
"=",
"'?'",
";",
"}",
"$",
"quoted_table",
"=",
"$",
"conn",
"->",
"quoteIdentifier",
"(",
"static",
"::",
"getTableName",
"(",
")",
",",
"true",
")",
";",
"$",
"query_s",
"=",
"'INSERT INTO '",
".",
"$",
"quoted_table",
".",
"' ('",
".",
"implode",
"(",
"', '",
",",
"$",
"fields",
")",
".",
"')'",
";",
"if",
"(",
"$",
"pk",
"&&",
"$",
"this",
"->",
"isAutoIncrement",
"(",
")",
"&&",
"$",
"conn",
"instanceof",
"DBMSSQL",
")",
"{",
"$",
"query_s",
".=",
"\" OUTPUT inserted.$pk\"",
";",
"}",
"$",
"query_s",
".=",
"' VALUES ('",
".",
"implode",
"(",
"', '",
",",
"$",
"placeholders",
")",
".",
"') '",
";",
"if",
"(",
"$",
"pk",
"&&",
"$",
"this",
"->",
"isAutoIncrement",
"(",
")",
"&&",
"$",
"conn",
"instanceof",
"DBPostgres",
")",
"{",
"$",
"query_s",
".=",
"' RETURNING '",
".",
"$",
"conn",
"->",
"quoteIdentifier",
"(",
"$",
"pk",
",",
"true",
")",
";",
"}",
"$",
"statement",
"=",
"new",
"QueryStatement",
"(",
"$",
"conn",
")",
";",
"$",
"statement",
"->",
"setString",
"(",
"$",
"query_s",
")",
";",
"$",
"statement",
"->",
"setParams",
"(",
"$",
"values",
")",
";",
"$",
"result",
"=",
"$",
"statement",
"->",
"bindAndExecute",
"(",
")",
";",
"$",
"count",
"=",
"$",
"result",
"->",
"rowCount",
"(",
")",
";",
"if",
"(",
"$",
"pk",
"&&",
"$",
"this",
"->",
"isAutoIncrement",
"(",
")",
")",
"{",
"$",
"id",
"=",
"null",
";",
"if",
"(",
"(",
"$",
"conn",
"instanceof",
"DBPostgres",
")",
"||",
"(",
"$",
"conn",
"instanceof",
"DBMSSQL",
")",
")",
"{",
"$",
"id",
"=",
"$",
"result",
"->",
"fetchColumn",
"(",
"0",
")",
";",
"}",
"elseif",
"(",
"$",
"conn",
"->",
"isGetIdAfterInsert",
"(",
")",
")",
"{",
"$",
"id",
"=",
"$",
"conn",
"->",
"lastInsertId",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"id",
")",
"&&",
"$",
"conn",
"instanceof",
"DBRedshift",
")",
"{",
"$",
"id",
"=",
"$",
"conn",
"->",
"query",
"(",
"'SELECT MAX('",
".",
"$",
"conn",
"->",
"quoteIdentifier",
"(",
"$",
"pk",
")",
".",
"\") FROM $quoted_table\"",
")",
"->",
"fetchColumn",
"(",
")",
";",
"}",
"}",
"if",
"(",
"null",
"!==",
"$",
"id",
")",
"{",
"$",
"this",
"->",
"{",
"\"set$pk\"",
"}",
"(",
"$",
"id",
")",
";",
"}",
"}",
"$",
"this",
"->",
"resetModified",
"(",
")",
";",
"$",
"this",
"->",
"setNew",
"(",
"false",
")",
";",
"$",
"this",
"->",
"insertIntoPool",
"(",
"$",
"this",
")",
";",
"return",
"$",
"count",
";",
"}"
] | Creates and executes INSERT query string for this object
@return int | [
"Creates",
"and",
"executes",
"INSERT",
"query",
"string",
"for",
"this",
"object"
] | f216513e4b16251db7901c1773d00e13e3a49421 | https://github.com/ManifestWebDesign/dabl-orm/blob/f216513e4b16251db7901c1773d00e13e3a49421/src/Model.php#L1355-L1412 | train |
ManifestWebDesign/dabl-orm | src/Model.php | Model.update | protected function update() {
if (!static::$_primaryKeys) {
throw new RuntimeException('This table has no primary keys');
}
$column_values = array();
foreach ($this->getModifiedColumns() as $column) {
$column_values[$column] = $this->$column;
}
// If array is empty there is nothing to update
if (empty($column_values)) {
return 0;
}
$q = static::getQuery();
foreach (static::$_primaryKeys as $pk) {
if ($this->$pk === null) {
throw new RuntimeException('Cannot update with NULL primary key.');
}
$q->add($pk, $this->$pk);
}
$row_count = $this->doUpdate($column_values, $q);
$this->resetModified();
return $row_count;
} | php | protected function update() {
if (!static::$_primaryKeys) {
throw new RuntimeException('This table has no primary keys');
}
$column_values = array();
foreach ($this->getModifiedColumns() as $column) {
$column_values[$column] = $this->$column;
}
// If array is empty there is nothing to update
if (empty($column_values)) {
return 0;
}
$q = static::getQuery();
foreach (static::$_primaryKeys as $pk) {
if ($this->$pk === null) {
throw new RuntimeException('Cannot update with NULL primary key.');
}
$q->add($pk, $this->$pk);
}
$row_count = $this->doUpdate($column_values, $q);
$this->resetModified();
return $row_count;
} | [
"protected",
"function",
"update",
"(",
")",
"{",
"if",
"(",
"!",
"static",
"::",
"$",
"_primaryKeys",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'This table has no primary keys'",
")",
";",
"}",
"$",
"column_values",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"getModifiedColumns",
"(",
")",
"as",
"$",
"column",
")",
"{",
"$",
"column_values",
"[",
"$",
"column",
"]",
"=",
"$",
"this",
"->",
"$",
"column",
";",
"}",
"// If array is empty there is nothing to update",
"if",
"(",
"empty",
"(",
"$",
"column_values",
")",
")",
"{",
"return",
"0",
";",
"}",
"$",
"q",
"=",
"static",
"::",
"getQuery",
"(",
")",
";",
"foreach",
"(",
"static",
"::",
"$",
"_primaryKeys",
"as",
"$",
"pk",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"$",
"pk",
"===",
"null",
")",
"{",
"throw",
"new",
"RuntimeException",
"(",
"'Cannot update with NULL primary key.'",
")",
";",
"}",
"$",
"q",
"->",
"add",
"(",
"$",
"pk",
",",
"$",
"this",
"->",
"$",
"pk",
")",
";",
"}",
"$",
"row_count",
"=",
"$",
"this",
"->",
"doUpdate",
"(",
"$",
"column_values",
",",
"$",
"q",
")",
";",
"$",
"this",
"->",
"resetModified",
"(",
")",
";",
"return",
"$",
"row_count",
";",
"}"
] | Creates and executes UPDATE query string for this object. Returns
the number of affected rows.
@return Int | [
"Creates",
"and",
"executes",
"UPDATE",
"query",
"string",
"for",
"this",
"object",
".",
"Returns",
"the",
"number",
"of",
"affected",
"rows",
"."
] | f216513e4b16251db7901c1773d00e13e3a49421 | https://github.com/ManifestWebDesign/dabl-orm/blob/f216513e4b16251db7901c1773d00e13e3a49421/src/Model.php#L1419-L1446 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.move | public function move($directory) {
if(false === is_string($directory)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($directory)), E_USER_ERROR);
}
if(false === is_dir($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s() is not an existing directory', $directory, __METHOD__), E_USER_ERROR);
}
if(false === is_writable($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s() is not writable', $directory, __METHOD__), E_USER_ERROR);
}
//Add directory seperator to directory
$directory = rtrim($directory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
if(false !== $this -> file -> getExists()) {
if(rename($this -> file -> getBasepath(), $directory . $this -> file -> getBasename())) {
$this -> file -> setPath($directory);
$this -> file -> setBasepath($directory . $this -> file -> getBasename());
$this -> refresh();
}
}
return $this;
} | php | public function move($directory) {
if(false === is_string($directory)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($directory)), E_USER_ERROR);
}
if(false === is_dir($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s() is not an existing directory', $directory, __METHOD__), E_USER_ERROR);
}
if(false === is_writable($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s() is not writable', $directory, __METHOD__), E_USER_ERROR);
}
//Add directory seperator to directory
$directory = rtrim($directory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
if(false !== $this -> file -> getExists()) {
if(rename($this -> file -> getBasepath(), $directory . $this -> file -> getBasename())) {
$this -> file -> setPath($directory);
$this -> file -> setBasepath($directory . $this -> file -> getBasename());
$this -> refresh();
}
}
return $this;
} | [
"public",
"function",
"move",
"(",
"$",
"directory",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"directory",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"directory",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_dir",
"(",
"$",
"directory",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Directory \"%s\" passed to %s() is not an existing directory'",
",",
"$",
"directory",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_writable",
"(",
"$",
"directory",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Directory \"%s\" passed to %s() is not writable'",
",",
"$",
"directory",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"//Add directory seperator to directory\r",
"$",
"directory",
"=",
"rtrim",
"(",
"$",
"directory",
",",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"if",
"(",
"rename",
"(",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
",",
"$",
"directory",
".",
"$",
"this",
"->",
"file",
"->",
"getBasename",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setPath",
"(",
"$",
"directory",
")",
";",
"$",
"this",
"->",
"file",
"->",
"setBasepath",
"(",
"$",
"directory",
".",
"$",
"this",
"->",
"file",
"->",
"getBasename",
"(",
")",
")",
";",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Moves the current file to given directory
@param string $directory
@return sFire\System\File | [
"Moves",
"the",
"current",
"file",
"to",
"given",
"directory"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L100-L129 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.delete | public function delete() {
if(false !== $this -> file -> getExists()) {
if(unlink($this -> file -> getBasepath())) {
$this -> refresh();
}
}
return $this;
} | php | public function delete() {
if(false !== $this -> file -> getExists()) {
if(unlink($this -> file -> getBasepath())) {
$this -> refresh();
}
}
return $this;
} | [
"public",
"function",
"delete",
"(",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"if",
"(",
"unlink",
"(",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
")",
")",
"{",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Deletes current file
@return sFire\System\File | [
"Deletes",
"current",
"file"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L136-L146 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.touch | public function touch($time = null, $accesstime = null) {
if(null !== $time && false === ('-' . intval($time) == '-' . $time)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($time)), E_USER_ERROR);
}
if(null !== $accesstime && false === ('-' . intval($accesstime) == '-' . $accesstime)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($accesstime)), E_USER_ERROR);
}
if(false !== $this -> file -> getExists()) {
touch($this -> file -> getBasepath(), $time, $accesstime);
}
return $this;
} | php | public function touch($time = null, $accesstime = null) {
if(null !== $time && false === ('-' . intval($time) == '-' . $time)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($time)), E_USER_ERROR);
}
if(null !== $accesstime && false === ('-' . intval($accesstime) == '-' . $accesstime)) {
return trigger_error(sprintf('Argument 2 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($accesstime)), E_USER_ERROR);
}
if(false !== $this -> file -> getExists()) {
touch($this -> file -> getBasepath(), $time, $accesstime);
}
return $this;
} | [
"public",
"function",
"touch",
"(",
"$",
"time",
"=",
"null",
",",
"$",
"accesstime",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"time",
"&&",
"false",
"===",
"(",
"'-'",
".",
"intval",
"(",
"$",
"time",
")",
"==",
"'-'",
".",
"$",
"time",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"time",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"null",
"!==",
"$",
"accesstime",
"&&",
"false",
"===",
"(",
"'-'",
".",
"intval",
"(",
"$",
"accesstime",
")",
"==",
"'-'",
".",
"$",
"accesstime",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 2 passed to %s() must be of the type integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"accesstime",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"touch",
"(",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
",",
"$",
"time",
",",
"$",
"accesstime",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets access and modification time of file. If the file does not exist, it will be created
@param int $time
@param accesstime $time
@return sFire\System\File | [
"Sets",
"access",
"and",
"modification",
"time",
"of",
"file",
".",
"If",
"the",
"file",
"does",
"not",
"exist",
"it",
"will",
"be",
"created"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L155-L170 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.copy | public function copy($directory) {
if(false === is_string($directory)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($directory)), E_USER_ERROR);
}
if(false === is_dir($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s() is not an existing directory', $directory, __METHOD__), E_USER_ERROR);
}
if(false === is_writable($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s() is not writable', $directory, __METHOD__), E_USER_ERROR);
}
if(false !== $this -> file -> getExists()) {
//Add directory seperator to directory
$directory = rtrim($directory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
copy($this -> file -> getBasepath(), $directory . $this -> file -> getBasename());
}
return $this;
} | php | public function copy($directory) {
if(false === is_string($directory)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($directory)), E_USER_ERROR);
}
if(false === is_dir($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s() is not an existing directory', $directory, __METHOD__), E_USER_ERROR);
}
if(false === is_writable($directory)) {
return trigger_error(sprintf('Directory "%s" passed to %s() is not writable', $directory, __METHOD__), E_USER_ERROR);
}
if(false !== $this -> file -> getExists()) {
//Add directory seperator to directory
$directory = rtrim($directory, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
copy($this -> file -> getBasepath(), $directory . $this -> file -> getBasename());
}
return $this;
} | [
"public",
"function",
"copy",
"(",
"$",
"directory",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"directory",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"directory",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_dir",
"(",
"$",
"directory",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Directory \"%s\" passed to %s() is not an existing directory'",
",",
"$",
"directory",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"===",
"is_writable",
"(",
"$",
"directory",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Directory \"%s\" passed to %s() is not writable'",
",",
"$",
"directory",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"//Add directory seperator to directory\r",
"$",
"directory",
"=",
"rtrim",
"(",
"$",
"directory",
",",
"DIRECTORY_SEPARATOR",
")",
".",
"DIRECTORY_SEPARATOR",
";",
"copy",
"(",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
",",
"$",
"directory",
".",
"$",
"this",
"->",
"file",
"->",
"getBasename",
"(",
")",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Makes a copy of the file to the destination directory
@param string $directory
@return sFire\System\File | [
"Makes",
"a",
"copy",
"of",
"the",
"file",
"to",
"the",
"destination",
"directory"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L195-L218 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.rename | public function rename($name) {
if(false === is_string($name)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
}
if(false !== $this -> file -> getExists()) {
if(rename($this -> file -> getBasepath(), $this -> file -> getPath() . $name)) {
$info = (object) pathinfo($this -> file -> getPath() . $name);
$this -> file -> setName($info -> filename);
$this -> file -> setBasename($info -> basename);
$this -> file -> setBasepath($this -> file -> getPath() . $this -> file -> getBasename());
if(true === isset($info -> extension)) {
$this -> file -> setExtension($info -> extension);
}
$this -> refresh();
}
}
return $this;
} | php | public function rename($name) {
if(false === is_string($name)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($name)), E_USER_ERROR);
}
if(false !== $this -> file -> getExists()) {
if(rename($this -> file -> getBasepath(), $this -> file -> getPath() . $name)) {
$info = (object) pathinfo($this -> file -> getPath() . $name);
$this -> file -> setName($info -> filename);
$this -> file -> setBasename($info -> basename);
$this -> file -> setBasepath($this -> file -> getPath() . $this -> file -> getBasename());
if(true === isset($info -> extension)) {
$this -> file -> setExtension($info -> extension);
}
$this -> refresh();
}
}
return $this;
} | [
"public",
"function",
"rename",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"name",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"name",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"if",
"(",
"rename",
"(",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
",",
"$",
"this",
"->",
"file",
"->",
"getPath",
"(",
")",
".",
"$",
"name",
")",
")",
"{",
"$",
"info",
"=",
"(",
"object",
")",
"pathinfo",
"(",
"$",
"this",
"->",
"file",
"->",
"getPath",
"(",
")",
".",
"$",
"name",
")",
";",
"$",
"this",
"->",
"file",
"->",
"setName",
"(",
"$",
"info",
"->",
"filename",
")",
";",
"$",
"this",
"->",
"file",
"->",
"setBasename",
"(",
"$",
"info",
"->",
"basename",
")",
";",
"$",
"this",
"->",
"file",
"->",
"setBasepath",
"(",
"$",
"this",
"->",
"file",
"->",
"getPath",
"(",
")",
".",
"$",
"this",
"->",
"file",
"->",
"getBasename",
"(",
")",
")",
";",
"if",
"(",
"true",
"===",
"isset",
"(",
"$",
"info",
"->",
"extension",
")",
")",
"{",
"$",
"this",
"->",
"file",
"->",
"setExtension",
"(",
"$",
"info",
"->",
"extension",
")",
";",
"}",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Attempts to rename oldname to newname. If newname exists, it will be overwritten
@param string $name
@return sFire\System\File | [
"Attempts",
"to",
"rename",
"oldname",
"to",
"newname",
".",
"If",
"newname",
"exists",
"it",
"will",
"be",
"overwritten"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L226-L251 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.getContent | public function getContent() {
if(false !== $this -> file -> getExists()) {
$this -> refresh();
if(false === $this -> file -> getReadable()) {
trigger_error(sprintf('File "%s" is not readable', $this -> file -> getBasepath()), E_USER_ERROR);
}
return file_get_contents($this -> file -> getBasepath());
}
} | php | public function getContent() {
if(false !== $this -> file -> getExists()) {
$this -> refresh();
if(false === $this -> file -> getReadable()) {
trigger_error(sprintf('File "%s" is not readable', $this -> file -> getBasepath()), E_USER_ERROR);
}
return file_get_contents($this -> file -> getBasepath());
}
} | [
"public",
"function",
"getContent",
"(",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"file",
"->",
"getReadable",
"(",
")",
")",
"{",
"trigger_error",
"(",
"sprintf",
"(",
"'File \"%s\" is not readable'",
",",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"return",
"file_get_contents",
"(",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
")",
";",
"}",
"}"
] | Returns the content of current file
@return string | [
"Returns",
"the",
"content",
"of",
"current",
"file"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L258-L270 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.append | public function append($data) {
if(false === is_string($data)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($data)), E_USER_ERROR);
}
if(false !== $this -> file -> getExists()) {
if(false === is_writable($this -> file -> getBasepath())) {
trigger_error(sprintf('File "%s" is not writable', $this -> file -> getBasepath()), E_USER_ERROR);
}
$handle = fopen($this -> file -> getBasepath(), 'a');
fwrite($handle, $data);
fclose($handle);
}
return $this;
} | php | public function append($data) {
if(false === is_string($data)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($data)), E_USER_ERROR);
}
if(false !== $this -> file -> getExists()) {
if(false === is_writable($this -> file -> getBasepath())) {
trigger_error(sprintf('File "%s" is not writable', $this -> file -> getBasepath()), E_USER_ERROR);
}
$handle = fopen($this -> file -> getBasepath(), 'a');
fwrite($handle, $data);
fclose($handle);
}
return $this;
} | [
"public",
"function",
"append",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"data",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"data",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"if",
"(",
"false",
"===",
"is_writable",
"(",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
")",
")",
"{",
"trigger_error",
"(",
"sprintf",
"(",
"'File \"%s\" is not writable'",
",",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
",",
"'a'",
")",
";",
"fwrite",
"(",
"$",
"handle",
",",
"$",
"data",
")",
";",
"fclose",
"(",
"$",
"handle",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Appends data to current file
@param string $data
@return sFire\System\File | [
"Appends",
"data",
"to",
"current",
"file"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L278-L297 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.prepend | public function prepend($data) {
if(false === is_string($data)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($data)), E_USER_ERROR);
}
if(false !== $this -> file -> getExists()) {
$this -> refresh();
if(false === $this -> file -> getWritable()) {
trigger_error(sprintf('File "%s" is not writable', $this -> file -> getBasepath()), E_USER_ERROR);
}
$handle = fopen($this -> file -> getBasepath(), 'r+');
$len = strlen($data);
$final_len = filesize($this -> file -> getBasepath()) + $len;
$cache_old = fread($handle, $len);
rewind($handle);
$i = 1;
while(ftell($handle) < $final_len) {
fwrite($handle, $data);
$data = $cache_old;
$cache_old = fread($handle, $len);
fseek($handle, $i * $len);
$i++;
}
}
return $this;
} | php | public function prepend($data) {
if(false === is_string($data)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($data)), E_USER_ERROR);
}
if(false !== $this -> file -> getExists()) {
$this -> refresh();
if(false === $this -> file -> getWritable()) {
trigger_error(sprintf('File "%s" is not writable', $this -> file -> getBasepath()), E_USER_ERROR);
}
$handle = fopen($this -> file -> getBasepath(), 'r+');
$len = strlen($data);
$final_len = filesize($this -> file -> getBasepath()) + $len;
$cache_old = fread($handle, $len);
rewind($handle);
$i = 1;
while(ftell($handle) < $final_len) {
fwrite($handle, $data);
$data = $cache_old;
$cache_old = fread($handle, $len);
fseek($handle, $i * $len);
$i++;
}
}
return $this;
} | [
"public",
"function",
"prepend",
"(",
"$",
"data",
")",
"{",
"if",
"(",
"false",
"===",
"is_string",
"(",
"$",
"data",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type string, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"data",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"if",
"(",
"false",
"===",
"$",
"this",
"->",
"file",
"->",
"getWritable",
"(",
")",
")",
"{",
"trigger_error",
"(",
"sprintf",
"(",
"'File \"%s\" is not writable'",
",",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"handle",
"=",
"fopen",
"(",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
",",
"'r+'",
")",
";",
"$",
"len",
"=",
"strlen",
"(",
"$",
"data",
")",
";",
"$",
"final_len",
"=",
"filesize",
"(",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
")",
"+",
"$",
"len",
";",
"$",
"cache_old",
"=",
"fread",
"(",
"$",
"handle",
",",
"$",
"len",
")",
";",
"rewind",
"(",
"$",
"handle",
")",
";",
"$",
"i",
"=",
"1",
";",
"while",
"(",
"ftell",
"(",
"$",
"handle",
")",
"<",
"$",
"final_len",
")",
"{",
"fwrite",
"(",
"$",
"handle",
",",
"$",
"data",
")",
";",
"$",
"data",
"=",
"$",
"cache_old",
";",
"$",
"cache_old",
"=",
"fread",
"(",
"$",
"handle",
",",
"$",
"len",
")",
";",
"fseek",
"(",
"$",
"handle",
",",
"$",
"i",
"*",
"$",
"len",
")",
";",
"$",
"i",
"++",
";",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Prepends data to current file
@param string $data
@return sFire\System\File | [
"Prepends",
"data",
"to",
"current",
"file"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L305-L342 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.flush | public function flush() {
if(false !== $this -> file -> getExists()) {
if(false === is_writable($this -> file -> getBasepath())) {
return trigger_error(sprintf('File "%s" passed to %s() is not writable', $this -> file -> getBasepath(), __METHOD__), E_USER_ERROR);
}
$fh = fopen($this -> file -> getBasepath(), 'w');
if(flock($fh, LOCK_EX)) {
ftruncate($fh, 0);
fflush($fh);
flock($fh, LOCK_UN);
}
fclose($fh);
$this -> refresh();
}
return $this;
} | php | public function flush() {
if(false !== $this -> file -> getExists()) {
if(false === is_writable($this -> file -> getBasepath())) {
return trigger_error(sprintf('File "%s" passed to %s() is not writable', $this -> file -> getBasepath(), __METHOD__), E_USER_ERROR);
}
$fh = fopen($this -> file -> getBasepath(), 'w');
if(flock($fh, LOCK_EX)) {
ftruncate($fh, 0);
fflush($fh);
flock($fh, LOCK_UN);
}
fclose($fh);
$this -> refresh();
}
return $this;
} | [
"public",
"function",
"flush",
"(",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"if",
"(",
"false",
"===",
"is_writable",
"(",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'File \"%s\" passed to %s() is not writable'",
",",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
",",
"__METHOD__",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"$",
"fh",
"=",
"fopen",
"(",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
",",
"'w'",
")",
";",
"if",
"(",
"flock",
"(",
"$",
"fh",
",",
"LOCK_EX",
")",
")",
"{",
"ftruncate",
"(",
"$",
"fh",
",",
"0",
")",
";",
"fflush",
"(",
"$",
"fh",
")",
";",
"flock",
"(",
"$",
"fh",
",",
"LOCK_UN",
")",
";",
"}",
"fclose",
"(",
"$",
"fh",
")",
";",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Empty the current file content
@return sFire\System\File | [
"Empty",
"the",
"current",
"file",
"content"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L360-L383 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.chmod | public function chmod($type) {
if(null !== $type && false === ('-' . intval($type) == '-' . $type)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($type)), E_USER_ERROR);
}
if(false !== $this -> file -> getExists()) {
return chmod($this -> file -> getBasepath(), $type);
}
return false;
} | php | public function chmod($type) {
if(null !== $type && false === ('-' . intval($type) == '-' . $type)) {
return trigger_error(sprintf('Argument 1 passed to %s() must be of the type integer, "%s" given', __METHOD__, gettype($type)), E_USER_ERROR);
}
if(false !== $this -> file -> getExists()) {
return chmod($this -> file -> getBasepath(), $type);
}
return false;
} | [
"public",
"function",
"chmod",
"(",
"$",
"type",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"type",
"&&",
"false",
"===",
"(",
"'-'",
".",
"intval",
"(",
"$",
"type",
")",
"==",
"'-'",
".",
"$",
"type",
")",
")",
"{",
"return",
"trigger_error",
"(",
"sprintf",
"(",
"'Argument 1 passed to %s() must be of the type integer, \"%s\" given'",
",",
"__METHOD__",
",",
"gettype",
"(",
"$",
"type",
")",
")",
",",
"E_USER_ERROR",
")",
";",
"}",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"return",
"chmod",
"(",
"$",
"this",
"->",
"file",
"->",
"getBasepath",
"(",
")",
",",
"$",
"type",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Changes current file mode
@param int $type
@return boolean | [
"Changes",
"current",
"file",
"mode"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L391-L402 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.getAccessTime | public function getAccessTime() {
if(false !== $this -> file -> getExists()) {
$this -> refresh();
return $this -> file -> getAccessTime();
}
} | php | public function getAccessTime() {
if(false !== $this -> file -> getExists()) {
$this -> refresh();
return $this -> file -> getAccessTime();
}
} | [
"public",
"function",
"getAccessTime",
"(",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"return",
"$",
"this",
"->",
"file",
"->",
"getAccessTime",
"(",
")",
";",
"}",
"}"
] | Returns the access time of current file
@return int | [
"Returns",
"the",
"access",
"time",
"of",
"current",
"file"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L424-L432 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.getGroup | public function getGroup() {
if(false !== $this -> file -> getExists()) {
$this -> refresh();
return $this -> file -> getGroup();
}
} | php | public function getGroup() {
if(false !== $this -> file -> getExists()) {
$this -> refresh();
return $this -> file -> getGroup();
}
} | [
"public",
"function",
"getGroup",
"(",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"return",
"$",
"this",
"->",
"file",
"->",
"getGroup",
"(",
")",
";",
"}",
"}"
] | Returns group name of current file
@return string | [
"Returns",
"group",
"name",
"of",
"current",
"file"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L439-L447 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.getModificationTime | public function getModificationTime() {
if(false !== $this -> file -> getExists()) {
$this -> refresh();
return $this -> file -> getModificationTime();
}
} | php | public function getModificationTime() {
if(false !== $this -> file -> getExists()) {
$this -> refresh();
return $this -> file -> getModificationTime();
}
} | [
"public",
"function",
"getModificationTime",
"(",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"return",
"$",
"this",
"->",
"file",
"->",
"getModificationTime",
"(",
")",
";",
"}",
"}"
] | Returns the modification time of current file
@return int | [
"Returns",
"the",
"modification",
"time",
"of",
"current",
"file"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L454-L462 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.getOwner | public function getOwner() {
if(false !== $this -> file -> getExists()) {
$this -> refresh();
return $this -> file -> getOwner();
}
} | php | public function getOwner() {
if(false !== $this -> file -> getExists()) {
$this -> refresh();
return $this -> file -> getOwner();
}
} | [
"public",
"function",
"getOwner",
"(",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"return",
"$",
"this",
"->",
"file",
"->",
"getOwner",
"(",
")",
";",
"}",
"}"
] | Returns the owner of current file
@return string | [
"Returns",
"the",
"owner",
"of",
"current",
"file"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L469-L477 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.isReadable | public function isReadable() {
if(false !== $this -> file -> getExists()) {
$this -> refresh();
return $this -> file -> getReadable();
}
return false;
} | php | public function isReadable() {
if(false !== $this -> file -> getExists()) {
$this -> refresh();
return $this -> file -> getReadable();
}
return false;
} | [
"public",
"function",
"isReadable",
"(",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"return",
"$",
"this",
"->",
"file",
"->",
"getReadable",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Returns if the current file is readable
@return boolean | [
"Returns",
"if",
"the",
"current",
"file",
"is",
"readable"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L508-L518 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.isWritable | public function isWritable() {
if(false !== $this -> file -> getExists()) {
$this -> refresh();
return $this -> file -> getWritable();
}
return false;
} | php | public function isWritable() {
if(false !== $this -> file -> getExists()) {
$this -> refresh();
return $this -> file -> getWritable();
}
return false;
} | [
"public",
"function",
"isWritable",
"(",
")",
"{",
"if",
"(",
"false",
"!==",
"$",
"this",
"->",
"file",
"->",
"getExists",
"(",
")",
")",
"{",
"$",
"this",
"->",
"refresh",
"(",
")",
";",
"return",
"$",
"this",
"->",
"file",
"->",
"getWritable",
"(",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Returns if the current file is writable
@return boolean | [
"Returns",
"if",
"the",
"current",
"file",
"is",
"writable"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L525-L535 | train |
Kris-Kuiper/sFire-Framework | src/System/File.php | File.getMime | public function getMime() {
if(null === $this -> mime) {
$this -> mime = new Mime();
}
return Mime :: get($this -> file -> getExtension());
} | php | public function getMime() {
if(null === $this -> mime) {
$this -> mime = new Mime();
}
return Mime :: get($this -> file -> getExtension());
} | [
"public",
"function",
"getMime",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"mime",
")",
"{",
"$",
"this",
"->",
"mime",
"=",
"new",
"Mime",
"(",
")",
";",
"}",
"return",
"Mime",
"::",
"get",
"(",
"$",
"this",
"->",
"file",
"->",
"getExtension",
"(",
")",
")",
";",
"}"
] | Returns mime type of current file
@return string | [
"Returns",
"mime",
"type",
"of",
"current",
"file"
] | deefe1d9d2b40e7326381e8dcd4f01f9aa61885c | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/System/File.php#L542-L549 | train |
modulusphp/request | Headers.php | Headers.has | public function has(string $name) : bool
{
if (isset($this->all[$name])) return true;
return false;
} | php | public function has(string $name) : bool
{
if (isset($this->all[$name])) return true;
return false;
} | [
"public",
"function",
"has",
"(",
"string",
"$",
"name",
")",
":",
"bool",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"all",
"[",
"$",
"name",
"]",
")",
")",
"return",
"true",
";",
"return",
"false",
";",
"}"
] | Check if header is present
@param string $name
@return bool | [
"Check",
"if",
"header",
"is",
"present"
] | 9328d81e71994e2944636ad5aed70f7a32f3fb87 | https://github.com/modulusphp/request/blob/9328d81e71994e2944636ad5aed70f7a32f3fb87/Headers.php#L19-L23 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Config.php | Config.rebuildConnectionString | protected function rebuildConnectionString()
{
foreach ($this->availableDrivers as $driverName) {
if (array_key_exists($driverName, $this->connectionStrings)) {
continue;
}
$ConnStringInterface = __NAMESPACE__.'\\ConnectionString\\'.ucfirst($driverName).'ConnectionString';
if (class_exists($ConnStringInterface)) {
$ConnString = new $ConnStringInterface();
$this->registerConnectionString($ConnString, $driverName);
}
}
} | php | protected function rebuildConnectionString()
{
foreach ($this->availableDrivers as $driverName) {
if (array_key_exists($driverName, $this->connectionStrings)) {
continue;
}
$ConnStringInterface = __NAMESPACE__.'\\ConnectionString\\'.ucfirst($driverName).'ConnectionString';
if (class_exists($ConnStringInterface)) {
$ConnString = new $ConnStringInterface();
$this->registerConnectionString($ConnString, $driverName);
}
}
} | [
"protected",
"function",
"rebuildConnectionString",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"availableDrivers",
"as",
"$",
"driverName",
")",
"{",
"if",
"(",
"array_key_exists",
"(",
"$",
"driverName",
",",
"$",
"this",
"->",
"connectionStrings",
")",
")",
"{",
"continue",
";",
"}",
"$",
"ConnStringInterface",
"=",
"__NAMESPACE__",
".",
"'\\\\ConnectionString\\\\'",
".",
"ucfirst",
"(",
"$",
"driverName",
")",
".",
"'ConnectionString'",
";",
"if",
"(",
"class_exists",
"(",
"$",
"ConnStringInterface",
")",
")",
"{",
"$",
"ConnString",
"=",
"new",
"$",
"ConnStringInterface",
"(",
")",
";",
"$",
"this",
"->",
"registerConnectionString",
"(",
"$",
"ConnString",
",",
"$",
"driverName",
")",
";",
"}",
"}",
"}"
] | Rebuild ConnectionString. | [
"Rebuild",
"ConnectionString",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Config.php#L93-L105 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Config.php | Config.registerConnectionString | public function registerConnectionString(ConnectionStringInterface $connString, $driverName)
{
$this->connectionStrings[$driverName] = $connString;
if (!in_array($driverName, $this->availableDrivers)) {
$this->availableDrivers[] = $driverName;
}
$this->error->setMessage(null);
$this->__buildConfig($this->rawConfig);
$connString->setConfig($this);
} | php | public function registerConnectionString(ConnectionStringInterface $connString, $driverName)
{
$this->connectionStrings[$driverName] = $connString;
if (!in_array($driverName, $this->availableDrivers)) {
$this->availableDrivers[] = $driverName;
}
$this->error->setMessage(null);
$this->__buildConfig($this->rawConfig);
$connString->setConfig($this);
} | [
"public",
"function",
"registerConnectionString",
"(",
"ConnectionStringInterface",
"$",
"connString",
",",
"$",
"driverName",
")",
"{",
"$",
"this",
"->",
"connectionStrings",
"[",
"$",
"driverName",
"]",
"=",
"$",
"connString",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"driverName",
",",
"$",
"this",
"->",
"availableDrivers",
")",
")",
"{",
"$",
"this",
"->",
"availableDrivers",
"[",
"]",
"=",
"$",
"driverName",
";",
"}",
"$",
"this",
"->",
"error",
"->",
"setMessage",
"(",
"null",
")",
";",
"$",
"this",
"->",
"__buildConfig",
"(",
"$",
"this",
"->",
"rawConfig",
")",
";",
"$",
"connString",
"->",
"setConfig",
"(",
"$",
"this",
")",
";",
"}"
] | Register new Connection String.
@param \Realboard\Component\Database\DBInstance\DBInterface\ConnectionStringInterface $connString Connection String Class
@param string $driverName Driver Alias eg (mysql, oci, pgsql, sqlite, firebird etc)
@return self | [
"Register",
"new",
"Connection",
"String",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Config.php#L115-L124 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Config.php | Config.getAttr | public function getAttr($key = null)
{
if (null !== $key) {
return isset($this->attr[$attribute]) ? $this->attr[$attribute] : null;
}
return $this->attr;
} | php | public function getAttr($key = null)
{
if (null !== $key) {
return isset($this->attr[$attribute]) ? $this->attr[$attribute] : null;
}
return $this->attr;
} | [
"public",
"function",
"getAttr",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"key",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"attr",
"[",
"$",
"attribute",
"]",
")",
"?",
"$",
"this",
"->",
"attr",
"[",
"$",
"attribute",
"]",
":",
"null",
";",
"}",
"return",
"$",
"this",
"->",
"attr",
";",
"}"
] | Get Current Attribute.
@param mixed $key Pdo Attribute
@return mixed Pdo Attr Value | [
"Get",
"Current",
"Attribute",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Config.php#L144-L151 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Config.php | Config.setAttrArray | public function setAttrArray(array $attributes)
{
foreach ($attributes as $attribute => $value) {
$this->setAttr($attribute, $value);
}
} | php | public function setAttrArray(array $attributes)
{
foreach ($attributes as $attribute => $value) {
$this->setAttr($attribute, $value);
}
} | [
"public",
"function",
"setAttrArray",
"(",
"array",
"$",
"attributes",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"$",
"this",
"->",
"setAttr",
"(",
"$",
"attribute",
",",
"$",
"value",
")",
";",
"}",
"}"
] | Batch Setup Attribute.
@param array $attributes | [
"Batch",
"Setup",
"Attribute",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Config.php#L158-L163 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Config.php | Config.__buildConfig | private function __buildConfig(array $config)
{
foreach ($config as $key => $conf) {
if ($key == 'driver') {
$this->rawConfig['type'] = strtolower($conf);
continue;
}
if (!array_key_exists($key, $this->rawConfig)) {
$this->error->setMessage(sprintf(
"invalid config '%s', allowed config are: %s",
$key, implode(', ', array_keys($this->rawConfig))
));
break;
}
$this->rawConfig[$key] = $conf;
}
if (!$this->error->hasError() && !$this->hasDriver($this->getType()) && !$this->preventNoLocalDriver) {
$this->error->setMessage(sprintf(
"Driver '%s' not available. Please choose one of: '%s'. ".
'Or register new ConnectionString class by implements %s.',
$this->getType(),
implode("', '", $this->getAvailableDrivers()),
ConnectionStringInterface::class
));
}
} | php | private function __buildConfig(array $config)
{
foreach ($config as $key => $conf) {
if ($key == 'driver') {
$this->rawConfig['type'] = strtolower($conf);
continue;
}
if (!array_key_exists($key, $this->rawConfig)) {
$this->error->setMessage(sprintf(
"invalid config '%s', allowed config are: %s",
$key, implode(', ', array_keys($this->rawConfig))
));
break;
}
$this->rawConfig[$key] = $conf;
}
if (!$this->error->hasError() && !$this->hasDriver($this->getType()) && !$this->preventNoLocalDriver) {
$this->error->setMessage(sprintf(
"Driver '%s' not available. Please choose one of: '%s'. ".
'Or register new ConnectionString class by implements %s.',
$this->getType(),
implode("', '", $this->getAvailableDrivers()),
ConnectionStringInterface::class
));
}
} | [
"private",
"function",
"__buildConfig",
"(",
"array",
"$",
"config",
")",
"{",
"foreach",
"(",
"$",
"config",
"as",
"$",
"key",
"=>",
"$",
"conf",
")",
"{",
"if",
"(",
"$",
"key",
"==",
"'driver'",
")",
"{",
"$",
"this",
"->",
"rawConfig",
"[",
"'type'",
"]",
"=",
"strtolower",
"(",
"$",
"conf",
")",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"rawConfig",
")",
")",
"{",
"$",
"this",
"->",
"error",
"->",
"setMessage",
"(",
"sprintf",
"(",
"\"invalid config '%s', allowed config are: %s\"",
",",
"$",
"key",
",",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"$",
"this",
"->",
"rawConfig",
")",
")",
")",
")",
";",
"break",
";",
"}",
"$",
"this",
"->",
"rawConfig",
"[",
"$",
"key",
"]",
"=",
"$",
"conf",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"error",
"->",
"hasError",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"hasDriver",
"(",
"$",
"this",
"->",
"getType",
"(",
")",
")",
"&&",
"!",
"$",
"this",
"->",
"preventNoLocalDriver",
")",
"{",
"$",
"this",
"->",
"error",
"->",
"setMessage",
"(",
"sprintf",
"(",
"\"Driver '%s' not available. Please choose one of: '%s'. \"",
".",
"'Or register new ConnectionString class by implements %s.'",
",",
"$",
"this",
"->",
"getType",
"(",
")",
",",
"implode",
"(",
"\"', '\"",
",",
"$",
"this",
"->",
"getAvailableDrivers",
"(",
")",
")",
",",
"ConnectionStringInterface",
"::",
"class",
")",
")",
";",
"}",
"}"
] | Build Self Config.
@param array $config | [
"Build",
"Self",
"Config",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Config.php#L170-L198 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Config.php | Config.getRawConfig | public function getRawConfig()
{
$raw = array();
foreach ($this->rawConfig as $key => $conf) {
$raw[$key] = call_user_func_array(array($this, 'get'.ucfirst($key)), array());
}
return $raw;
} | php | public function getRawConfig()
{
$raw = array();
foreach ($this->rawConfig as $key => $conf) {
$raw[$key] = call_user_func_array(array($this, 'get'.ucfirst($key)), array());
}
return $raw;
} | [
"public",
"function",
"getRawConfig",
"(",
")",
"{",
"$",
"raw",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"rawConfig",
"as",
"$",
"key",
"=>",
"$",
"conf",
")",
"{",
"$",
"raw",
"[",
"$",
"key",
"]",
"=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"this",
",",
"'get'",
".",
"ucfirst",
"(",
"$",
"key",
")",
")",
",",
"array",
"(",
")",
")",
";",
"}",
"return",
"$",
"raw",
";",
"}"
] | Get Raw Config.
@return array | [
"Get",
"Raw",
"Config",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Config.php#L205-L213 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Config.php | Config.getPort | public function getPort()
{
$defaultPorts = array(
'mysql' => '3306',
'pgsql' => '5432',
'oci' => '1521',
);
if (!$this->rawConfig['port'] && isset($defaultPorts[$this->getType()])) {
$this->rawConfig['port'] = $defaultPorts[$this->getType()];
}
return intval($this->rawConfig['port']);
} | php | public function getPort()
{
$defaultPorts = array(
'mysql' => '3306',
'pgsql' => '5432',
'oci' => '1521',
);
if (!$this->rawConfig['port'] && isset($defaultPorts[$this->getType()])) {
$this->rawConfig['port'] = $defaultPorts[$this->getType()];
}
return intval($this->rawConfig['port']);
} | [
"public",
"function",
"getPort",
"(",
")",
"{",
"$",
"defaultPorts",
"=",
"array",
"(",
"'mysql'",
"=>",
"'3306'",
",",
"'pgsql'",
"=>",
"'5432'",
",",
"'oci'",
"=>",
"'1521'",
",",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"rawConfig",
"[",
"'port'",
"]",
"&&",
"isset",
"(",
"$",
"defaultPorts",
"[",
"$",
"this",
"->",
"getType",
"(",
")",
"]",
")",
")",
"{",
"$",
"this",
"->",
"rawConfig",
"[",
"'port'",
"]",
"=",
"$",
"defaultPorts",
"[",
"$",
"this",
"->",
"getType",
"(",
")",
"]",
";",
"}",
"return",
"intval",
"(",
"$",
"this",
"->",
"rawConfig",
"[",
"'port'",
"]",
")",
";",
"}"
] | Get Database Port.
@return int|null Port | [
"Get",
"Database",
"Port",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Config.php#L270-L282 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Config.php | Config.getDsn | public function getDsn()
{
if ($this->rawConfig['dsn']) {
return $this->rawConfig['dsn'];
}
if (isset($this->connectionStrings[$this->getType()])) {
return $this->connectionStrings[$this->getType()]->getDsn();
}
} | php | public function getDsn()
{
if ($this->rawConfig['dsn']) {
return $this->rawConfig['dsn'];
}
if (isset($this->connectionStrings[$this->getType()])) {
return $this->connectionStrings[$this->getType()]->getDsn();
}
} | [
"public",
"function",
"getDsn",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"rawConfig",
"[",
"'dsn'",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"rawConfig",
"[",
"'dsn'",
"]",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"connectionStrings",
"[",
"$",
"this",
"->",
"getType",
"(",
")",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"connectionStrings",
"[",
"$",
"this",
"->",
"getType",
"(",
")",
"]",
"->",
"getDsn",
"(",
")",
";",
"}",
"}"
] | Get Database DSN.
@return string DSN | [
"Get",
"Database",
"DSN",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Config.php#L329-L338 | train |
realboard/DBInstance | src/Realboard/Component/Database/DBInstance/Config.php | Config.preventNoLocalDriver | public function preventNoLocalDriver($prevented = true)
{
if ($prevented && !array_key_exists($this->getType(), $this->connectionStrings)) {
$this->availableDrivers[] = $this->getType();
$this->rebuildConnectionString();
}
$this->preventNoLocalDriver = $prevented;
} | php | public function preventNoLocalDriver($prevented = true)
{
if ($prevented && !array_key_exists($this->getType(), $this->connectionStrings)) {
$this->availableDrivers[] = $this->getType();
$this->rebuildConnectionString();
}
$this->preventNoLocalDriver = $prevented;
} | [
"public",
"function",
"preventNoLocalDriver",
"(",
"$",
"prevented",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"prevented",
"&&",
"!",
"array_key_exists",
"(",
"$",
"this",
"->",
"getType",
"(",
")",
",",
"$",
"this",
"->",
"connectionStrings",
")",
")",
"{",
"$",
"this",
"->",
"availableDrivers",
"[",
"]",
"=",
"$",
"this",
"->",
"getType",
"(",
")",
";",
"$",
"this",
"->",
"rebuildConnectionString",
"(",
")",
";",
"}",
"$",
"this",
"->",
"preventNoLocalDriver",
"=",
"$",
"prevented",
";",
"}"
] | Prevent error if driver is not available.
@param bool $prevented | [
"Prevent",
"error",
"if",
"driver",
"is",
"not",
"available",
"."
] | f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35 | https://github.com/realboard/DBInstance/blob/f2cde7fdf480d5eb5a491a5cf81ff7f4b3be0a35/src/Realboard/Component/Database/DBInstance/Config.php#L377-L385 | train |
Xsaven/laravel-intelect-admin | src/Addons/JWTAuth/Providers/JWTAuthServiceProvider.php | JWTAuthServiceProvider.bootBindings | protected function bootBindings()
{
$this->app->singleton('Lia\Addons\JWTAuth\JWTAuth', function ($app) {
return $app['lia.jwt.auth'];
});
$this->app->singleton('Lia\Addons\JWTAuth\Providers\User\UserInterface', function ($app) {
return $app['lia.jwt.provider.user'];
});
$this->app->singleton('Lia\Addons\JWTAuth\Providers\JWT\JWTInterface', function ($app) {
return $app['lia.jwt.provider.jwt'];
});
$this->app->singleton('Lia\Addons\JWTAuth\Providers\Auth\AuthInterface', function ($app) {
return $app['lia.jwt.provider.auth'];
});
$this->app->singleton('Lia\Addons\JWTAuth\Providers\Storage\StorageInterface', function ($app) {
return $app['lia.jwt.provider.storage'];
});
$this->app->singleton('Lia\Addons\JWTAuth\JWTManager', function ($app) {
return $app['lia.jwt.manager'];
});
$this->app->singleton('Lia\Addons\JWTAuth\Blacklist', function ($app) {
return $app['lia.jwt.blacklist'];
});
$this->app->singleton('Lia\Addons\JWTAuth\PayloadFactory', function ($app) {
return $app['lia.jwt.payload.factory'];
});
$this->app->singleton('Lia\Addons\JWTAuth\Claims\Factory', function ($app) {
return $app['lia.jwt.claim.factory'];
});
$this->app->singleton('Lia\Addons\JWTAuth\Validators\PayloadValidator', function ($app) {
return $app['lia.jwt.validators.payload'];
});
} | php | protected function bootBindings()
{
$this->app->singleton('Lia\Addons\JWTAuth\JWTAuth', function ($app) {
return $app['lia.jwt.auth'];
});
$this->app->singleton('Lia\Addons\JWTAuth\Providers\User\UserInterface', function ($app) {
return $app['lia.jwt.provider.user'];
});
$this->app->singleton('Lia\Addons\JWTAuth\Providers\JWT\JWTInterface', function ($app) {
return $app['lia.jwt.provider.jwt'];
});
$this->app->singleton('Lia\Addons\JWTAuth\Providers\Auth\AuthInterface', function ($app) {
return $app['lia.jwt.provider.auth'];
});
$this->app->singleton('Lia\Addons\JWTAuth\Providers\Storage\StorageInterface', function ($app) {
return $app['lia.jwt.provider.storage'];
});
$this->app->singleton('Lia\Addons\JWTAuth\JWTManager', function ($app) {
return $app['lia.jwt.manager'];
});
$this->app->singleton('Lia\Addons\JWTAuth\Blacklist', function ($app) {
return $app['lia.jwt.blacklist'];
});
$this->app->singleton('Lia\Addons\JWTAuth\PayloadFactory', function ($app) {
return $app['lia.jwt.payload.factory'];
});
$this->app->singleton('Lia\Addons\JWTAuth\Claims\Factory', function ($app) {
return $app['lia.jwt.claim.factory'];
});
$this->app->singleton('Lia\Addons\JWTAuth\Validators\PayloadValidator', function ($app) {
return $app['lia.jwt.validators.payload'];
});
} | [
"protected",
"function",
"bootBindings",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'Lia\\Addons\\JWTAuth\\JWTAuth'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"[",
"'lia.jwt.auth'",
"]",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'Lia\\Addons\\JWTAuth\\Providers\\User\\UserInterface'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"[",
"'lia.jwt.provider.user'",
"]",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'Lia\\Addons\\JWTAuth\\Providers\\JWT\\JWTInterface'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"[",
"'lia.jwt.provider.jwt'",
"]",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'Lia\\Addons\\JWTAuth\\Providers\\Auth\\AuthInterface'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"[",
"'lia.jwt.provider.auth'",
"]",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'Lia\\Addons\\JWTAuth\\Providers\\Storage\\StorageInterface'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"[",
"'lia.jwt.provider.storage'",
"]",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'Lia\\Addons\\JWTAuth\\JWTManager'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"[",
"'lia.jwt.manager'",
"]",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'Lia\\Addons\\JWTAuth\\Blacklist'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"[",
"'lia.jwt.blacklist'",
"]",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'Lia\\Addons\\JWTAuth\\PayloadFactory'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"[",
"'lia.jwt.payload.factory'",
"]",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'Lia\\Addons\\JWTAuth\\Claims\\Factory'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"[",
"'lia.jwt.claim.factory'",
"]",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'Lia\\Addons\\JWTAuth\\Validators\\PayloadValidator'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"return",
"$",
"app",
"[",
"'lia.jwt.validators.payload'",
"]",
";",
"}",
")",
";",
"}"
] | Bind some Interfaces and implementations. | [
"Bind",
"some",
"Interfaces",
"and",
"implementations",
"."
] | 592574633d12c74cf25b43dd6694fee496abefcb | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/JWTAuth/Providers/JWTAuthServiceProvider.php#L40-L81 | train |
Xsaven/laravel-intelect-admin | src/Addons/JWTAuth/Providers/JWTAuthServiceProvider.php | JWTAuthServiceProvider.registerUserProvider | protected function registerUserProvider()
{
$this->app->singleton('lia.jwt.provider.user', function ($app) {
$provider = $this->config('providers.user');
$model = $app->make($this->config('user'));
return new $provider($model);
});
} | php | protected function registerUserProvider()
{
$this->app->singleton('lia.jwt.provider.user', function ($app) {
$provider = $this->config('providers.user');
$model = $app->make($this->config('user'));
return new $provider($model);
});
} | [
"protected",
"function",
"registerUserProvider",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'lia.jwt.provider.user'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"provider",
"=",
"$",
"this",
"->",
"config",
"(",
"'providers.user'",
")",
";",
"$",
"model",
"=",
"$",
"app",
"->",
"make",
"(",
"$",
"this",
"->",
"config",
"(",
"'user'",
")",
")",
";",
"return",
"new",
"$",
"provider",
"(",
"$",
"model",
")",
";",
"}",
")",
";",
"}"
] | Register the bindings for the User provider. | [
"Register",
"the",
"bindings",
"for",
"the",
"User",
"provider",
"."
] | 592574633d12c74cf25b43dd6694fee496abefcb | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/JWTAuth/Providers/JWTAuthServiceProvider.php#L111-L119 | train |
Xsaven/laravel-intelect-admin | src/Addons/JWTAuth/Providers/JWTAuthServiceProvider.php | JWTAuthServiceProvider.registerJWTManager | protected function registerJWTManager()
{
$this->app->singleton('lia.jwt.manager', function ($app) {
$instance = new JWTManager(
$app['lia.jwt.provider.jwt'],
$app['lia.jwt.blacklist'],
$app['lia.jwt.payload.factory']
);
return $instance->setBlacklistEnabled((bool) $this->config('blacklist_enabled'));
});
} | php | protected function registerJWTManager()
{
$this->app->singleton('lia.jwt.manager', function ($app) {
$instance = new JWTManager(
$app['lia.jwt.provider.jwt'],
$app['lia.jwt.blacklist'],
$app['lia.jwt.payload.factory']
);
return $instance->setBlacklistEnabled((bool) $this->config('blacklist_enabled'));
});
} | [
"protected",
"function",
"registerJWTManager",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'lia.jwt.manager'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"instance",
"=",
"new",
"JWTManager",
"(",
"$",
"app",
"[",
"'lia.jwt.provider.jwt'",
"]",
",",
"$",
"app",
"[",
"'lia.jwt.blacklist'",
"]",
",",
"$",
"app",
"[",
"'lia.jwt.payload.factory'",
"]",
")",
";",
"return",
"$",
"instance",
"->",
"setBlacklistEnabled",
"(",
"(",
"bool",
")",
"$",
"this",
"->",
"config",
"(",
"'blacklist_enabled'",
")",
")",
";",
"}",
")",
";",
"}"
] | Register the bindings for the JWT Manager. | [
"Register",
"the",
"bindings",
"for",
"the",
"JWT",
"Manager",
"."
] | 592574633d12c74cf25b43dd6694fee496abefcb | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/JWTAuth/Providers/JWTAuthServiceProvider.php#L168-L179 | train |
Xsaven/laravel-intelect-admin | src/Addons/JWTAuth/Providers/JWTAuthServiceProvider.php | JWTAuthServiceProvider.registerPayloadFactory | protected function registerPayloadFactory()
{
$this->app->singleton('lia.jwt.payload.factory', function ($app) {
$factory = new PayloadFactory($app['lia.jwt.claim.factory'], $app['request'], $app['lia.jwt.validators.payload']);
return $factory->setTTL($this->config('ttl'));
});
} | php | protected function registerPayloadFactory()
{
$this->app->singleton('lia.jwt.payload.factory', function ($app) {
$factory = new PayloadFactory($app['lia.jwt.claim.factory'], $app['request'], $app['lia.jwt.validators.payload']);
return $factory->setTTL($this->config('ttl'));
});
} | [
"protected",
"function",
"registerPayloadFactory",
"(",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'lia.jwt.payload.factory'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"factory",
"=",
"new",
"PayloadFactory",
"(",
"$",
"app",
"[",
"'lia.jwt.claim.factory'",
"]",
",",
"$",
"app",
"[",
"'request'",
"]",
",",
"$",
"app",
"[",
"'lia.jwt.validators.payload'",
"]",
")",
";",
"return",
"$",
"factory",
"->",
"setTTL",
"(",
"$",
"this",
"->",
"config",
"(",
"'ttl'",
")",
")",
";",
"}",
")",
";",
"}"
] | Register the bindings for the Payload Factory. | [
"Register",
"the",
"bindings",
"for",
"the",
"Payload",
"Factory",
"."
] | 592574633d12c74cf25b43dd6694fee496abefcb | https://github.com/Xsaven/laravel-intelect-admin/blob/592574633d12c74cf25b43dd6694fee496abefcb/src/Addons/JWTAuth/Providers/JWTAuthServiceProvider.php#L223-L230 | train |
polusphp/polus-middleware | src/ClientIp.php | ClientIp.determineClientIpAddress | protected function determineClientIpAddress($request)
{
$ipAddress = null;
$serverParams = $request->getServerParams();
if (isset($serverParams['REMOTE_ADDR']) && $this->isValidIpAddress($serverParams['REMOTE_ADDR'])) {
$ipAddress = $serverParams['REMOTE_ADDR'];
}
$checkProxyHeaders = $this->checkProxyHeaders;
if ($checkProxyHeaders && !empty($this->trustedProxies)) {
if (!in_array($ipAddress, $this->trustedProxies)) {
$checkProxyHeaders = false;
}
}
if ($checkProxyHeaders) {
foreach ($this->headersToInspect as $header) {
if ($request->hasHeader($header)) {
$ip = trim(current(explode(',', $request->getHeaderLine($header))));
if ($this->isValidIpAddress($ip)) {
$ipAddress = $ip;
break;
}
}
}
}
return $ipAddress;
} | php | protected function determineClientIpAddress($request)
{
$ipAddress = null;
$serverParams = $request->getServerParams();
if (isset($serverParams['REMOTE_ADDR']) && $this->isValidIpAddress($serverParams['REMOTE_ADDR'])) {
$ipAddress = $serverParams['REMOTE_ADDR'];
}
$checkProxyHeaders = $this->checkProxyHeaders;
if ($checkProxyHeaders && !empty($this->trustedProxies)) {
if (!in_array($ipAddress, $this->trustedProxies)) {
$checkProxyHeaders = false;
}
}
if ($checkProxyHeaders) {
foreach ($this->headersToInspect as $header) {
if ($request->hasHeader($header)) {
$ip = trim(current(explode(',', $request->getHeaderLine($header))));
if ($this->isValidIpAddress($ip)) {
$ipAddress = $ip;
break;
}
}
}
}
return $ipAddress;
} | [
"protected",
"function",
"determineClientIpAddress",
"(",
"$",
"request",
")",
"{",
"$",
"ipAddress",
"=",
"null",
";",
"$",
"serverParams",
"=",
"$",
"request",
"->",
"getServerParams",
"(",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"serverParams",
"[",
"'REMOTE_ADDR'",
"]",
")",
"&&",
"$",
"this",
"->",
"isValidIpAddress",
"(",
"$",
"serverParams",
"[",
"'REMOTE_ADDR'",
"]",
")",
")",
"{",
"$",
"ipAddress",
"=",
"$",
"serverParams",
"[",
"'REMOTE_ADDR'",
"]",
";",
"}",
"$",
"checkProxyHeaders",
"=",
"$",
"this",
"->",
"checkProxyHeaders",
";",
"if",
"(",
"$",
"checkProxyHeaders",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"trustedProxies",
")",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"ipAddress",
",",
"$",
"this",
"->",
"trustedProxies",
")",
")",
"{",
"$",
"checkProxyHeaders",
"=",
"false",
";",
"}",
"}",
"if",
"(",
"$",
"checkProxyHeaders",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"headersToInspect",
"as",
"$",
"header",
")",
"{",
"if",
"(",
"$",
"request",
"->",
"hasHeader",
"(",
"$",
"header",
")",
")",
"{",
"$",
"ip",
"=",
"trim",
"(",
"current",
"(",
"explode",
"(",
"','",
",",
"$",
"request",
"->",
"getHeaderLine",
"(",
"$",
"header",
")",
")",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"isValidIpAddress",
"(",
"$",
"ip",
")",
")",
"{",
"$",
"ipAddress",
"=",
"$",
"ip",
";",
"break",
";",
"}",
"}",
"}",
"}",
"return",
"$",
"ipAddress",
";",
"}"
] | Find out the client's IP address from the headers available to us
@param ServerRequestInterface $request PSR-7 Request
@return string | [
"Find",
"out",
"the",
"client",
"s",
"IP",
"address",
"from",
"the",
"headers",
"available",
"to",
"us"
] | c265c51fbdf6b2c5ed85686415b47a1fbf720c57 | https://github.com/polusphp/polus-middleware/blob/c265c51fbdf6b2c5ed85686415b47a1fbf720c57/src/ClientIp.php#L88-L117 | train |
polusphp/polus-middleware | src/ClientIp.php | ClientIp.isValidIpAddress | protected function isValidIpAddress($ip)
{
$flags = FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6;
if (filter_var($ip, FILTER_VALIDATE_IP, $flags) === false) {
return false;
}
return true;
} | php | protected function isValidIpAddress($ip)
{
$flags = FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6;
if (filter_var($ip, FILTER_VALIDATE_IP, $flags) === false) {
return false;
}
return true;
} | [
"protected",
"function",
"isValidIpAddress",
"(",
"$",
"ip",
")",
"{",
"$",
"flags",
"=",
"FILTER_FLAG_IPV4",
"|",
"FILTER_FLAG_IPV6",
";",
"if",
"(",
"filter_var",
"(",
"$",
"ip",
",",
"FILTER_VALIDATE_IP",
",",
"$",
"flags",
")",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | Check that a given string is a valid IP address
@param string $ip
@return boolean | [
"Check",
"that",
"a",
"given",
"string",
"is",
"a",
"valid",
"IP",
"address"
] | c265c51fbdf6b2c5ed85686415b47a1fbf720c57 | https://github.com/polusphp/polus-middleware/blob/c265c51fbdf6b2c5ed85686415b47a1fbf720c57/src/ClientIp.php#L125-L132 | train |
stubbles/stubbles-date | src/main/php/TimeZone.php | TimeZone.offset | public function offset($date = null): string
{
$offset = $this->offsetInSeconds($date);
$hours = intval(abs($offset) / 3600);
$minutes = (abs($offset)- ($hours * 3600)) / 60;
return sprintf('%s%02d%02d', ($offset < 0 ? '-' : '+'), $hours, $minutes);
} | php | public function offset($date = null): string
{
$offset = $this->offsetInSeconds($date);
$hours = intval(abs($offset) / 3600);
$minutes = (abs($offset)- ($hours * 3600)) / 60;
return sprintf('%s%02d%02d', ($offset < 0 ? '-' : '+'), $hours, $minutes);
} | [
"public",
"function",
"offset",
"(",
"$",
"date",
"=",
"null",
")",
":",
"string",
"{",
"$",
"offset",
"=",
"$",
"this",
"->",
"offsetInSeconds",
"(",
"$",
"date",
")",
";",
"$",
"hours",
"=",
"intval",
"(",
"abs",
"(",
"$",
"offset",
")",
"/",
"3600",
")",
";",
"$",
"minutes",
"=",
"(",
"abs",
"(",
"$",
"offset",
")",
"-",
"(",
"$",
"hours",
"*",
"3600",
")",
")",
"/",
"60",
";",
"return",
"sprintf",
"(",
"'%s%02d%02d'",
",",
"(",
"$",
"offset",
"<",
"0",
"?",
"'-'",
":",
"'+'",
")",
",",
"$",
"hours",
",",
"$",
"minutes",
")",
";",
"}"
] | returns offset of the time zone
@param int|string|\DateTime|\stubbles\date\Date $date defaults to current date
@return string | [
"returns",
"offset",
"of",
"the",
"time",
"zone"
] | 98553392bec03affc53a6e3eb7f88408c2720d1c | https://github.com/stubbles/stubbles-date/blob/98553392bec03affc53a6e3eb7f88408c2720d1c/src/main/php/TimeZone.php#L81-L87 | train |
stubbles/stubbles-date | src/main/php/TimeZone.php | TimeZone.offsetInSeconds | public function offsetInSeconds($date = null): int
{
if (null === $date) {
return $this->timeZone->getOffset(new \DateTime('now'));
}
return $this->timeZone->getOffset(Date::castFrom($date)->handle());
} | php | public function offsetInSeconds($date = null): int
{
if (null === $date) {
return $this->timeZone->getOffset(new \DateTime('now'));
}
return $this->timeZone->getOffset(Date::castFrom($date)->handle());
} | [
"public",
"function",
"offsetInSeconds",
"(",
"$",
"date",
"=",
"null",
")",
":",
"int",
"{",
"if",
"(",
"null",
"===",
"$",
"date",
")",
"{",
"return",
"$",
"this",
"->",
"timeZone",
"->",
"getOffset",
"(",
"new",
"\\",
"DateTime",
"(",
"'now'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"timeZone",
"->",
"getOffset",
"(",
"Date",
"::",
"castFrom",
"(",
"$",
"date",
")",
"->",
"handle",
"(",
")",
")",
";",
"}"
] | returns offset to given date in seconds
Because a timezone may have different offsets when its in DST or non-DST
mode, a date object must be given which is used to determine whether DST
or non-DST offset should be returned.
@param int|string|\DateTime|\stubbles\date\Date $date defaults to current date
@return int | [
"returns",
"offset",
"to",
"given",
"date",
"in",
"seconds"
] | 98553392bec03affc53a6e3eb7f88408c2720d1c | https://github.com/stubbles/stubbles-date/blob/98553392bec03affc53a6e3eb7f88408c2720d1c/src/main/php/TimeZone.php#L99-L106 | train |
stubbles/stubbles-date | src/main/php/TimeZone.php | TimeZone.translate | public function translate($date): Date
{
$handle = Date::castFrom($date)->handle();
$handle->setTimezone($this->timeZone);
return new Date($handle);
} | php | public function translate($date): Date
{
$handle = Date::castFrom($date)->handle();
$handle->setTimezone($this->timeZone);
return new Date($handle);
} | [
"public",
"function",
"translate",
"(",
"$",
"date",
")",
":",
"Date",
"{",
"$",
"handle",
"=",
"Date",
"::",
"castFrom",
"(",
"$",
"date",
")",
"->",
"handle",
"(",
")",
";",
"$",
"handle",
"->",
"setTimezone",
"(",
"$",
"this",
"->",
"timeZone",
")",
";",
"return",
"new",
"Date",
"(",
"$",
"handle",
")",
";",
"}"
] | translates a date from one timezone to a date of this timezone
A new date instance will be returned while the given date is not changed.
@param int|string|\DateTime|\stubbles\date\Date $date
@return \stubbles\date\Date | [
"translates",
"a",
"date",
"from",
"one",
"timezone",
"to",
"a",
"date",
"of",
"this",
"timezone"
] | 98553392bec03affc53a6e3eb7f88408c2720d1c | https://github.com/stubbles/stubbles-date/blob/98553392bec03affc53a6e3eb7f88408c2720d1c/src/main/php/TimeZone.php#L127-L132 | train |
pixelpolishers/makedocs | src/MakeDocs/Builder/Html/HtmlBuilder.php | HtmlBuilder.getElementRegister | public function getElementRegister()
{
if ($this->elementRegister === null) {
$this->elementRegister = new ElementRegister();
$this->initializeElementRegister($this->elementRegister);
}
return $this->elementRegister;
} | php | public function getElementRegister()
{
if ($this->elementRegister === null) {
$this->elementRegister = new ElementRegister();
$this->initializeElementRegister($this->elementRegister);
}
return $this->elementRegister;
} | [
"public",
"function",
"getElementRegister",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"elementRegister",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"elementRegister",
"=",
"new",
"ElementRegister",
"(",
")",
";",
"$",
"this",
"->",
"initializeElementRegister",
"(",
"$",
"this",
"->",
"elementRegister",
")",
";",
"}",
"return",
"$",
"this",
"->",
"elementRegister",
";",
"}"
] | Gets the element register.
@return ElementRegister | [
"Gets",
"the",
"element",
"register",
"."
] | 1fa243b52565b5de417ef2dbdfbcae9896b6b483 | https://github.com/pixelpolishers/makedocs/blob/1fa243b52565b5de417ef2dbdfbcae9896b6b483/src/MakeDocs/Builder/Html/HtmlBuilder.php#L65-L72 | train |
pixelpolishers/makedocs | src/MakeDocs/Builder/Html/HtmlBuilder.php | HtmlBuilder.initializeElementRegister | protected function initializeElementRegister(ElementRegister $register)
{
$register->set('a', new AnchorElement());
$register->set('admonition', new AdmonitionElement());
$register->set('br', new BreakElement());
$register->set('code', new CodeElement());
$register->set('em', new EmphasisElement());
$register->set('error', new AdmonitionElement('error'));
$register->set('header', new HeaderElement());
$register->set('h1', new HeaderElement(1));
$register->set('h2', new HeaderElement(2));
$register->set('h3', new HeaderElement(3));
$register->set('h4', new HeaderElement(4));
$register->set('h5', new HeaderElement(5));
$register->set('h6', new HeaderElement(6));
$register->set('hint', new AdmonitionElement('hint'));
$register->set('img', new ImageElement());
$register->set('include', new IncludeElement());
$register->set('list', new ListElement());
$register->set('note', new AdmonitionElement('note'));
$register->set('p', new ParagraphElement());
$register->set('spoiler', new AdmonitionElement('spoiler'));
$register->set('strong', new StrongElement());
$register->set('table', new TableElement());
$register->set('td', new TableColumnElement());
$register->set('th', new TableHeaderElement());
$register->set('tr', new TableRowElement());
$register->set('tip', new AdmonitionElement('tip'));
$register->set('warning', new AdmonitionElement('warning'));
} | php | protected function initializeElementRegister(ElementRegister $register)
{
$register->set('a', new AnchorElement());
$register->set('admonition', new AdmonitionElement());
$register->set('br', new BreakElement());
$register->set('code', new CodeElement());
$register->set('em', new EmphasisElement());
$register->set('error', new AdmonitionElement('error'));
$register->set('header', new HeaderElement());
$register->set('h1', new HeaderElement(1));
$register->set('h2', new HeaderElement(2));
$register->set('h3', new HeaderElement(3));
$register->set('h4', new HeaderElement(4));
$register->set('h5', new HeaderElement(5));
$register->set('h6', new HeaderElement(6));
$register->set('hint', new AdmonitionElement('hint'));
$register->set('img', new ImageElement());
$register->set('include', new IncludeElement());
$register->set('list', new ListElement());
$register->set('note', new AdmonitionElement('note'));
$register->set('p', new ParagraphElement());
$register->set('spoiler', new AdmonitionElement('spoiler'));
$register->set('strong', new StrongElement());
$register->set('table', new TableElement());
$register->set('td', new TableColumnElement());
$register->set('th', new TableHeaderElement());
$register->set('tr', new TableRowElement());
$register->set('tip', new AdmonitionElement('tip'));
$register->set('warning', new AdmonitionElement('warning'));
} | [
"protected",
"function",
"initializeElementRegister",
"(",
"ElementRegister",
"$",
"register",
")",
"{",
"$",
"register",
"->",
"set",
"(",
"'a'",
",",
"new",
"AnchorElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'admonition'",
",",
"new",
"AdmonitionElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'br'",
",",
"new",
"BreakElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'code'",
",",
"new",
"CodeElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'em'",
",",
"new",
"EmphasisElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'error'",
",",
"new",
"AdmonitionElement",
"(",
"'error'",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'header'",
",",
"new",
"HeaderElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'h1'",
",",
"new",
"HeaderElement",
"(",
"1",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'h2'",
",",
"new",
"HeaderElement",
"(",
"2",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'h3'",
",",
"new",
"HeaderElement",
"(",
"3",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'h4'",
",",
"new",
"HeaderElement",
"(",
"4",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'h5'",
",",
"new",
"HeaderElement",
"(",
"5",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'h6'",
",",
"new",
"HeaderElement",
"(",
"6",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'hint'",
",",
"new",
"AdmonitionElement",
"(",
"'hint'",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'img'",
",",
"new",
"ImageElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'include'",
",",
"new",
"IncludeElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'list'",
",",
"new",
"ListElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'note'",
",",
"new",
"AdmonitionElement",
"(",
"'note'",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'p'",
",",
"new",
"ParagraphElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'spoiler'",
",",
"new",
"AdmonitionElement",
"(",
"'spoiler'",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'strong'",
",",
"new",
"StrongElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'table'",
",",
"new",
"TableElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'td'",
",",
"new",
"TableColumnElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'th'",
",",
"new",
"TableHeaderElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'tr'",
",",
"new",
"TableRowElement",
"(",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'tip'",
",",
"new",
"AdmonitionElement",
"(",
"'tip'",
")",
")",
";",
"$",
"register",
"->",
"set",
"(",
"'warning'",
",",
"new",
"AdmonitionElement",
"(",
"'warning'",
")",
")",
";",
"}"
] | Initializes athe element register.
@param ElementRegister $register The register to initialize. | [
"Initializes",
"athe",
"element",
"register",
"."
] | 1fa243b52565b5de417ef2dbdfbcae9896b6b483 | https://github.com/pixelpolishers/makedocs/blob/1fa243b52565b5de417ef2dbdfbcae9896b6b483/src/MakeDocs/Builder/Html/HtmlBuilder.php#L79-L108 | train |
pixelpolishers/makedocs | src/MakeDocs/Builder/Html/HtmlBuilder.php | HtmlBuilder.getLink | public function getLink($page, $header = null)
{
$id = preg_replace('/[^a-z0-9\/]+/i', '', $page);
$link = $this->getBaseUrl() . '/' . $id;
if ($header !== null) {
$link .= '#' . $this->createId($header);
} else if ($id == 'index') {
$link = $this->getBaseUrl();
}
return $link;
} | php | public function getLink($page, $header = null)
{
$id = preg_replace('/[^a-z0-9\/]+/i', '', $page);
$link = $this->getBaseUrl() . '/' . $id;
if ($header !== null) {
$link .= '#' . $this->createId($header);
} else if ($id == 'index') {
$link = $this->getBaseUrl();
}
return $link;
} | [
"public",
"function",
"getLink",
"(",
"$",
"page",
",",
"$",
"header",
"=",
"null",
")",
"{",
"$",
"id",
"=",
"preg_replace",
"(",
"'/[^a-z0-9\\/]+/i'",
",",
"''",
",",
"$",
"page",
")",
";",
"$",
"link",
"=",
"$",
"this",
"->",
"getBaseUrl",
"(",
")",
".",
"'/'",
".",
"$",
"id",
";",
"if",
"(",
"$",
"header",
"!==",
"null",
")",
"{",
"$",
"link",
".=",
"'#'",
".",
"$",
"this",
"->",
"createId",
"(",
"$",
"header",
")",
";",
"}",
"else",
"if",
"(",
"$",
"id",
"==",
"'index'",
")",
"{",
"$",
"link",
"=",
"$",
"this",
"->",
"getBaseUrl",
"(",
")",
";",
"}",
"return",
"$",
"link",
";",
"}"
] | Gets the link for the given source file.
@param SourceFile $page The page to get the link for.
@param string $header An optional header to link to.
@return string | [
"Gets",
"the",
"link",
"for",
"the",
"given",
"source",
"file",
"."
] | 1fa243b52565b5de417ef2dbdfbcae9896b6b483 | https://github.com/pixelpolishers/makedocs/blob/1fa243b52565b5de417ef2dbdfbcae9896b6b483/src/MakeDocs/Builder/Html/HtmlBuilder.php#L188-L200 | train |
pixelpolishers/makedocs | src/MakeDocs/Builder/Html/HtmlBuilder.php | HtmlBuilder.build | public function build(Generator $generator)
{
$renderer = new DOMRenderer($generator, $this);
$publisher = new Publisher($generator, $this);
$pageManager = $this->loadPageManager($generator);
while (!$pageManager->getQueue()->isEmpty()) {
$page = $pageManager->getQueue()->dequeue();
if ($pageManager->hasPage($page)) {
continue;
}
// Parse the source file:
$sourceFile = $pageManager->getSourceFile($page);
// Register the page:
$pageManager->addPage($page, $sourceFile);
// Parse the content:
$content = $renderer->renderContentElement($sourceFile->getContent());
// And add the content to the publisher:
$publisher->add($page, $content);
}
$publisher->publish();
} | php | public function build(Generator $generator)
{
$renderer = new DOMRenderer($generator, $this);
$publisher = new Publisher($generator, $this);
$pageManager = $this->loadPageManager($generator);
while (!$pageManager->getQueue()->isEmpty()) {
$page = $pageManager->getQueue()->dequeue();
if ($pageManager->hasPage($page)) {
continue;
}
// Parse the source file:
$sourceFile = $pageManager->getSourceFile($page);
// Register the page:
$pageManager->addPage($page, $sourceFile);
// Parse the content:
$content = $renderer->renderContentElement($sourceFile->getContent());
// And add the content to the publisher:
$publisher->add($page, $content);
}
$publisher->publish();
} | [
"public",
"function",
"build",
"(",
"Generator",
"$",
"generator",
")",
"{",
"$",
"renderer",
"=",
"new",
"DOMRenderer",
"(",
"$",
"generator",
",",
"$",
"this",
")",
";",
"$",
"publisher",
"=",
"new",
"Publisher",
"(",
"$",
"generator",
",",
"$",
"this",
")",
";",
"$",
"pageManager",
"=",
"$",
"this",
"->",
"loadPageManager",
"(",
"$",
"generator",
")",
";",
"while",
"(",
"!",
"$",
"pageManager",
"->",
"getQueue",
"(",
")",
"->",
"isEmpty",
"(",
")",
")",
"{",
"$",
"page",
"=",
"$",
"pageManager",
"->",
"getQueue",
"(",
")",
"->",
"dequeue",
"(",
")",
";",
"if",
"(",
"$",
"pageManager",
"->",
"hasPage",
"(",
"$",
"page",
")",
")",
"{",
"continue",
";",
"}",
"// Parse the source file:",
"$",
"sourceFile",
"=",
"$",
"pageManager",
"->",
"getSourceFile",
"(",
"$",
"page",
")",
";",
"// Register the page:",
"$",
"pageManager",
"->",
"addPage",
"(",
"$",
"page",
",",
"$",
"sourceFile",
")",
";",
"// Parse the content:",
"$",
"content",
"=",
"$",
"renderer",
"->",
"renderContentElement",
"(",
"$",
"sourceFile",
"->",
"getContent",
"(",
")",
")",
";",
"// And add the content to the publisher:",
"$",
"publisher",
"->",
"add",
"(",
"$",
"page",
",",
"$",
"content",
")",
";",
"}",
"$",
"publisher",
"->",
"publish",
"(",
")",
";",
"}"
] | Builds the source files.
@param Generator $generator The generator to build for. | [
"Builds",
"the",
"source",
"files",
"."
] | 1fa243b52565b5de417ef2dbdfbcae9896b6b483 | https://github.com/pixelpolishers/makedocs/blob/1fa243b52565b5de417ef2dbdfbcae9896b6b483/src/MakeDocs/Builder/Html/HtmlBuilder.php#L207-L234 | train |
AnonymPHP/Anonym-Route | Router.php | Router.run | public function run()
{
$method = strtoupper($this->getRequest()->getMethod());
$collections = $this->resolveGroupAndWhen(RouteCollector::getRoutes());
if (!$this->hasAnyRouteInRequestMethod($collections, $method)) {
$this->callRouteNotFoundCommand();
}
$collections = $collections[$method];
if (false === $return = $this->isThereEquealUrl($collections)) {
$return = $this->isThereMatchUrl($collections);
}
$this->callRouteNotFoundCommand();
return $return;
} | php | public function run()
{
$method = strtoupper($this->getRequest()->getMethod());
$collections = $this->resolveGroupAndWhen(RouteCollector::getRoutes());
if (!$this->hasAnyRouteInRequestMethod($collections, $method)) {
$this->callRouteNotFoundCommand();
}
$collections = $collections[$method];
if (false === $return = $this->isThereEquealUrl($collections)) {
$return = $this->isThereMatchUrl($collections);
}
$this->callRouteNotFoundCommand();
return $return;
} | [
"public",
"function",
"run",
"(",
")",
"{",
"$",
"method",
"=",
"strtoupper",
"(",
"$",
"this",
"->",
"getRequest",
"(",
")",
"->",
"getMethod",
"(",
")",
")",
";",
"$",
"collections",
"=",
"$",
"this",
"->",
"resolveGroupAndWhen",
"(",
"RouteCollector",
"::",
"getRoutes",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"hasAnyRouteInRequestMethod",
"(",
"$",
"collections",
",",
"$",
"method",
")",
")",
"{",
"$",
"this",
"->",
"callRouteNotFoundCommand",
"(",
")",
";",
"}",
"$",
"collections",
"=",
"$",
"collections",
"[",
"$",
"method",
"]",
";",
"if",
"(",
"false",
"===",
"$",
"return",
"=",
"$",
"this",
"->",
"isThereEquealUrl",
"(",
"$",
"collections",
")",
")",
"{",
"$",
"return",
"=",
"$",
"this",
"->",
"isThereMatchUrl",
"(",
"$",
"collections",
")",
";",
"}",
"$",
"this",
"->",
"callRouteNotFoundCommand",
"(",
")",
";",
"return",
"$",
"return",
";",
"}"
] | Run the router and check requested uri
@throws RouteMatchException
@return bool | [
"Run",
"the",
"router",
"and",
"check",
"requested",
"uri"
] | bb7f8004fbbd2998af8b0061f404f026f11466ab | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/Router.php#L197-L217 | train |
AnonymPHP/Anonym-Route | Router.php | Router.dispatchCollection | protected function dispatchCollection($collection)
{
// find and send group variables
$group = isset($collection['group']) ? $collection['group'] : null;
// dispatch action dispatcher
$content = $this->getActionDispatcher()->dispatch($collection['action'], $group);
if (is_string($content)) {
$this->sendContentString($content, $this->getRequest());
}
} | php | protected function dispatchCollection($collection)
{
// find and send group variables
$group = isset($collection['group']) ? $collection['group'] : null;
// dispatch action dispatcher
$content = $this->getActionDispatcher()->dispatch($collection['action'], $group);
if (is_string($content)) {
$this->sendContentString($content, $this->getRequest());
}
} | [
"protected",
"function",
"dispatchCollection",
"(",
"$",
"collection",
")",
"{",
"// find and send group variables",
"$",
"group",
"=",
"isset",
"(",
"$",
"collection",
"[",
"'group'",
"]",
")",
"?",
"$",
"collection",
"[",
"'group'",
"]",
":",
"null",
";",
"// dispatch action dispatcher",
"$",
"content",
"=",
"$",
"this",
"->",
"getActionDispatcher",
"(",
")",
"->",
"dispatch",
"(",
"$",
"collection",
"[",
"'action'",
"]",
",",
"$",
"group",
")",
";",
"if",
"(",
"is_string",
"(",
"$",
"content",
")",
")",
"{",
"$",
"this",
"->",
"sendContentString",
"(",
"$",
"content",
",",
"$",
"this",
"->",
"getRequest",
"(",
")",
")",
";",
"}",
"}"
] | dispatch matched collection
@param mixed $collection | [
"dispatch",
"matched",
"collection"
] | bb7f8004fbbd2998af8b0061f404f026f11466ab | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/Router.php#L263-L272 | train |
AnonymPHP/Anonym-Route | Router.php | Router.resolveGroupAndWhen | protected function resolveGroupAndWhen($collections)
{
if (count(RouteCollector::getGroups())) {
$collections = $this->resolveGroupCollections($collections);
}
if (isset($collections['WHEN'])) {
$collections = $this->resolveWhenCollections($collections['WHEN']);
}
if (count($groups = RouteCollector::getGroups())) {
$collections = $this->resolveGroupCollections($groups);
}
return $collections;
} | php | protected function resolveGroupAndWhen($collections)
{
if (count(RouteCollector::getGroups())) {
$collections = $this->resolveGroupCollections($collections);
}
if (isset($collections['WHEN'])) {
$collections = $this->resolveWhenCollections($collections['WHEN']);
}
if (count($groups = RouteCollector::getGroups())) {
$collections = $this->resolveGroupCollections($groups);
}
return $collections;
} | [
"protected",
"function",
"resolveGroupAndWhen",
"(",
"$",
"collections",
")",
"{",
"if",
"(",
"count",
"(",
"RouteCollector",
"::",
"getGroups",
"(",
")",
")",
")",
"{",
"$",
"collections",
"=",
"$",
"this",
"->",
"resolveGroupCollections",
"(",
"$",
"collections",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"collections",
"[",
"'WHEN'",
"]",
")",
")",
"{",
"$",
"collections",
"=",
"$",
"this",
"->",
"resolveWhenCollections",
"(",
"$",
"collections",
"[",
"'WHEN'",
"]",
")",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"groups",
"=",
"RouteCollector",
"::",
"getGroups",
"(",
")",
")",
")",
"{",
"$",
"collections",
"=",
"$",
"this",
"->",
"resolveGroupCollections",
"(",
"$",
"groups",
")",
";",
"}",
"return",
"$",
"collections",
";",
"}"
] | resolve group and when collections
@param array $collections
@return array | [
"resolve",
"group",
"and",
"when",
"collections"
] | bb7f8004fbbd2998af8b0061f404f026f11466ab | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/Router.php#L300-L315 | train |
AnonymPHP/Anonym-Route | Router.php | Router.resolveWhenCollections | protected function resolveWhenCollections(array $collections = [])
{
foreach ($collections as $index => $collection) {
if ($this->getMatcher()->matchWhen($collection['uri'])) {
// registering when tag
RouteCollector::$firing['when'] = $collection['uri'];
app()->call($collection['action'], [app('route')]);
RouteCollector::removeWhen($index);
break;
}
}
return RouteCollector::getRoutes();
} | php | protected function resolveWhenCollections(array $collections = [])
{
foreach ($collections as $index => $collection) {
if ($this->getMatcher()->matchWhen($collection['uri'])) {
// registering when tag
RouteCollector::$firing['when'] = $collection['uri'];
app()->call($collection['action'], [app('route')]);
RouteCollector::removeWhen($index);
break;
}
}
return RouteCollector::getRoutes();
} | [
"protected",
"function",
"resolveWhenCollections",
"(",
"array",
"$",
"collections",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"collections",
"as",
"$",
"index",
"=>",
"$",
"collection",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"getMatcher",
"(",
")",
"->",
"matchWhen",
"(",
"$",
"collection",
"[",
"'uri'",
"]",
")",
")",
"{",
"// registering when tag",
"RouteCollector",
"::",
"$",
"firing",
"[",
"'when'",
"]",
"=",
"$",
"collection",
"[",
"'uri'",
"]",
";",
"app",
"(",
")",
"->",
"call",
"(",
"$",
"collection",
"[",
"'action'",
"]",
",",
"[",
"app",
"(",
"'route'",
")",
"]",
")",
";",
"RouteCollector",
"::",
"removeWhen",
"(",
"$",
"index",
")",
";",
"break",
";",
"}",
"}",
"return",
"RouteCollector",
"::",
"getRoutes",
"(",
")",
";",
"}"
] | resolve when collections
@param array $collections
@return array | [
"resolve",
"when",
"collections"
] | bb7f8004fbbd2998af8b0061f404f026f11466ab | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/Router.php#L324-L339 | train |
AnonymPHP/Anonym-Route | Router.php | Router.resolveGroupCollections | private function resolveGroupCollections(array $groups = [])
{
foreach ($groups as $index => $group) {
// register group
RouteCollector::$firing['group'] = $group;
app()->call($group['callback'], [app('route')]);
// unregister the route
unset(RouteCollector::$firing['group']);
RouteCollector::removeGroup($index);
}
return RouteCollector::getRoutes();
} | php | private function resolveGroupCollections(array $groups = [])
{
foreach ($groups as $index => $group) {
// register group
RouteCollector::$firing['group'] = $group;
app()->call($group['callback'], [app('route')]);
// unregister the route
unset(RouteCollector::$firing['group']);
RouteCollector::removeGroup($index);
}
return RouteCollector::getRoutes();
} | [
"private",
"function",
"resolveGroupCollections",
"(",
"array",
"$",
"groups",
"=",
"[",
"]",
")",
"{",
"foreach",
"(",
"$",
"groups",
"as",
"$",
"index",
"=>",
"$",
"group",
")",
"{",
"// register group",
"RouteCollector",
"::",
"$",
"firing",
"[",
"'group'",
"]",
"=",
"$",
"group",
";",
"app",
"(",
")",
"->",
"call",
"(",
"$",
"group",
"[",
"'callback'",
"]",
",",
"[",
"app",
"(",
"'route'",
")",
"]",
")",
";",
"// unregister the route",
"unset",
"(",
"RouteCollector",
"::",
"$",
"firing",
"[",
"'group'",
"]",
")",
";",
"RouteCollector",
"::",
"removeGroup",
"(",
"$",
"index",
")",
";",
"}",
"return",
"RouteCollector",
"::",
"getRoutes",
"(",
")",
";",
"}"
] | resolve the when collections
@param array $groups
@return array return the new collections | [
"resolve",
"the",
"when",
"collections"
] | bb7f8004fbbd2998af8b0061f404f026f11466ab | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/Router.php#L347-L361 | train |
AnonymPHP/Anonym-Route | Router.php | Router.sendContentString | private function sendContentString($content = '', Request $request)
{
$response = $request->getResponse();
$response->setContent($content);
$response->send();
} | php | private function sendContentString($content = '', Request $request)
{
$response = $request->getResponse();
$response->setContent($content);
$response->send();
} | [
"private",
"function",
"sendContentString",
"(",
"$",
"content",
"=",
"''",
",",
"Request",
"$",
"request",
")",
"{",
"$",
"response",
"=",
"$",
"request",
"->",
"getResponse",
"(",
")",
";",
"$",
"response",
"->",
"setContent",
"(",
"$",
"content",
")",
";",
"$",
"response",
"->",
"send",
"(",
")",
";",
"}"
] | send the content
@param string $content
@param Request $request | [
"send",
"the",
"content"
] | bb7f8004fbbd2998af8b0061f404f026f11466ab | https://github.com/AnonymPHP/Anonym-Route/blob/bb7f8004fbbd2998af8b0061f404f026f11466ab/Router.php#L369-L374 | train |
jonesiscoding/device | src/DetectByUserAgent.php | DetectByUserAgent.detect | public function detect()
{
$detected = true;
if ( empty( $this->ua ) )
{
$detected = false;
}
else
{
// If it's not any of the common browsers, perhaps it's something mobile.
if ( !$this->isMSIE() && !$this->isChrome() && !$this->isFirefox() && !$this->isSafari() && !$this->isEdge() && !$this->isOpera() )
{
if ( !$this->isOtherMobile() )
{
$detected = false;
}
}
else
{
// If it's one of the default browsers, check to see if it's the mobile version.
if ( !$this->isChromeMobile() && !$this->isSafariMobile() && !$this->isFirefoxMobile() && !$this->isOperaMobile() )
{
// If not, check for other mobile conditions, otherwise mark as definitely not mobile.
if ( !$this->isOtherMobile() )
{
$this->mobile = false;
$this->touch = false;
$this->android = false;
$this->ios = false;
$this->tablet = false;
$this->phone = false;
}
}
}
}
if ( $detected )
{
// Deal with Width/Height
if ( !$this->width )
{
$this->width = ( $this->phone ) ? $this->defaultSize[ 'phone' ][ 'width' ] : $this->defaultSize['tablet']['width'];
$this->height = ( $this->phone ) ? $this->defaultSize[ 'phone' ][ 'height' ] : $this->defaultSize['tablet']['height'];
}
// Deal with Browser
if ( $this->isModern() )
{
$browser = 'modern';
}
elseif($this->isFallback())
{
$browser = 'fallback';
}
else
{
$browser = 'baseline';
}
// Return the array that DeviceFeatureInfo expects.
return array(
'hidpi' => false,
'width' => $this->width,
'height' => $this->height,
'low_speed' => false,
'low_battery' => false,
'metered' => $this->metered,
'browser' => $browser,
'touch' => $this->touch,
'android' => $this->android,
'ios' => $this->ios,
'user-agent' => $this->ua
);
}
return null;
} | php | public function detect()
{
$detected = true;
if ( empty( $this->ua ) )
{
$detected = false;
}
else
{
// If it's not any of the common browsers, perhaps it's something mobile.
if ( !$this->isMSIE() && !$this->isChrome() && !$this->isFirefox() && !$this->isSafari() && !$this->isEdge() && !$this->isOpera() )
{
if ( !$this->isOtherMobile() )
{
$detected = false;
}
}
else
{
// If it's one of the default browsers, check to see if it's the mobile version.
if ( !$this->isChromeMobile() && !$this->isSafariMobile() && !$this->isFirefoxMobile() && !$this->isOperaMobile() )
{
// If not, check for other mobile conditions, otherwise mark as definitely not mobile.
if ( !$this->isOtherMobile() )
{
$this->mobile = false;
$this->touch = false;
$this->android = false;
$this->ios = false;
$this->tablet = false;
$this->phone = false;
}
}
}
}
if ( $detected )
{
// Deal with Width/Height
if ( !$this->width )
{
$this->width = ( $this->phone ) ? $this->defaultSize[ 'phone' ][ 'width' ] : $this->defaultSize['tablet']['width'];
$this->height = ( $this->phone ) ? $this->defaultSize[ 'phone' ][ 'height' ] : $this->defaultSize['tablet']['height'];
}
// Deal with Browser
if ( $this->isModern() )
{
$browser = 'modern';
}
elseif($this->isFallback())
{
$browser = 'fallback';
}
else
{
$browser = 'baseline';
}
// Return the array that DeviceFeatureInfo expects.
return array(
'hidpi' => false,
'width' => $this->width,
'height' => $this->height,
'low_speed' => false,
'low_battery' => false,
'metered' => $this->metered,
'browser' => $browser,
'touch' => $this->touch,
'android' => $this->android,
'ios' => $this->ios,
'user-agent' => $this->ua
);
}
return null;
} | [
"public",
"function",
"detect",
"(",
")",
"{",
"$",
"detected",
"=",
"true",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"ua",
")",
")",
"{",
"$",
"detected",
"=",
"false",
";",
"}",
"else",
"{",
"// If it's not any of the common browsers, perhaps it's something mobile.",
"if",
"(",
"!",
"$",
"this",
"->",
"isMSIE",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isChrome",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isFirefox",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isSafari",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isEdge",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isOpera",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isOtherMobile",
"(",
")",
")",
"{",
"$",
"detected",
"=",
"false",
";",
"}",
"}",
"else",
"{",
"// If it's one of the default browsers, check to see if it's the mobile version.",
"if",
"(",
"!",
"$",
"this",
"->",
"isChromeMobile",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isSafariMobile",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isFirefoxMobile",
"(",
")",
"&&",
"!",
"$",
"this",
"->",
"isOperaMobile",
"(",
")",
")",
"{",
"// If not, check for other mobile conditions, otherwise mark as definitely not mobile.",
"if",
"(",
"!",
"$",
"this",
"->",
"isOtherMobile",
"(",
")",
")",
"{",
"$",
"this",
"->",
"mobile",
"=",
"false",
";",
"$",
"this",
"->",
"touch",
"=",
"false",
";",
"$",
"this",
"->",
"android",
"=",
"false",
";",
"$",
"this",
"->",
"ios",
"=",
"false",
";",
"$",
"this",
"->",
"tablet",
"=",
"false",
";",
"$",
"this",
"->",
"phone",
"=",
"false",
";",
"}",
"}",
"}",
"}",
"if",
"(",
"$",
"detected",
")",
"{",
"// Deal with Width/Height",
"if",
"(",
"!",
"$",
"this",
"->",
"width",
")",
"{",
"$",
"this",
"->",
"width",
"=",
"(",
"$",
"this",
"->",
"phone",
")",
"?",
"$",
"this",
"->",
"defaultSize",
"[",
"'phone'",
"]",
"[",
"'width'",
"]",
":",
"$",
"this",
"->",
"defaultSize",
"[",
"'tablet'",
"]",
"[",
"'width'",
"]",
";",
"$",
"this",
"->",
"height",
"=",
"(",
"$",
"this",
"->",
"phone",
")",
"?",
"$",
"this",
"->",
"defaultSize",
"[",
"'phone'",
"]",
"[",
"'height'",
"]",
":",
"$",
"this",
"->",
"defaultSize",
"[",
"'tablet'",
"]",
"[",
"'height'",
"]",
";",
"}",
"// Deal with Browser",
"if",
"(",
"$",
"this",
"->",
"isModern",
"(",
")",
")",
"{",
"$",
"browser",
"=",
"'modern'",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isFallback",
"(",
")",
")",
"{",
"$",
"browser",
"=",
"'fallback'",
";",
"}",
"else",
"{",
"$",
"browser",
"=",
"'baseline'",
";",
"}",
"// Return the array that DeviceFeatureInfo expects.",
"return",
"array",
"(",
"'hidpi'",
"=>",
"false",
",",
"'width'",
"=>",
"$",
"this",
"->",
"width",
",",
"'height'",
"=>",
"$",
"this",
"->",
"height",
",",
"'low_speed'",
"=>",
"false",
",",
"'low_battery'",
"=>",
"false",
",",
"'metered'",
"=>",
"$",
"this",
"->",
"metered",
",",
"'browser'",
"=>",
"$",
"browser",
",",
"'touch'",
"=>",
"$",
"this",
"->",
"touch",
",",
"'android'",
"=>",
"$",
"this",
"->",
"android",
",",
"'ios'",
"=>",
"$",
"this",
"->",
"ios",
",",
"'user-agent'",
"=>",
"$",
"this",
"->",
"ua",
")",
";",
"}",
"return",
"null",
";",
"}"
] | Detects the various items from the user agent, and returns what it can in the the array format desired by
DeviceFeatureInfo. If nothing can be detected, returns null.
@return array|null | [
"Detects",
"the",
"various",
"items",
"from",
"the",
"user",
"agent",
"and",
"returns",
"what",
"it",
"can",
"in",
"the",
"the",
"array",
"format",
"desired",
"by",
"DeviceFeatureInfo",
".",
"If",
"nothing",
"can",
"be",
"detected",
"returns",
"null",
"."
] | d3c66f934bcaa8e5e0424cf684c995b1c80cee29 | https://github.com/jonesiscoding/device/blob/d3c66f934bcaa8e5e0424cf684c995b1c80cee29/src/DetectByUserAgent.php#L84-L160 | train |
jonesiscoding/device | src/DetectByUserAgent.php | DetectByUserAgent.isSafari | private function isSafari()
{
$is = false;
if ( preg_match( "/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//", $this->ua, $matches ) )
{
// These things sometimes surf around acting like they're Safari.
if ( !preg_match( "/(PhantomJS|Silk|rekonq|OPR|Chrome|Android|Edge|bot)/", $this->ua ) )
{
$is = true;
$major = ( isset( $matches[ 2 ] ) ) ? $matches[ 2 ] : null;
$minor = ( isset( $matches[ 3 ] ) ) ? $matches[ 3 ] : null;
$rev = ( isset( $matches[ 4 ] ) ) ? $matches[ 4 ] : null;
$version = ( isset( $major ) ) ? $major : null;
$version .= ( isset( $minor ) ) ? '.' . $minor : null;
$version .= ( isset( $rev ) ) ? '.' . $rev : null;
}
}
// Versions below 3.x doe not have the Version/ in the UA. Since we can't get the version number, we go with the
// highest version that didn't have the version number in the UA. It doesn't really matter, since this would be
// a 'baseline' browser anyway.
elseif ( preg_match("/(Safari)\/\d+/", $this->ua, $matches) )
{
// These things sometimes surf around acting like they're Safari.
if ( !preg_match( "/(PhantomJS|Silk|rekonq|OPR|Chrome|Android|Edge|bot)/", $this->ua ) )
{
$is = true;
$version = 2;
$major = 2;
$minor = 0;
$rev = 4;
}
}
if ( $is && isset( $version, $major, $minor ) )
{
$this->browser = 'safari';
$this->version = $version;
$this->major = $major;
$this->minor = $minor;
$this->rev = ( isset( $rev ) ) ? $rev : null;
return true;
}
return false;
} | php | private function isSafari()
{
$is = false;
if ( preg_match( "/(Version)\/(\d+)\.(\d+)(?:\.(\d+))?.*Safari\//", $this->ua, $matches ) )
{
// These things sometimes surf around acting like they're Safari.
if ( !preg_match( "/(PhantomJS|Silk|rekonq|OPR|Chrome|Android|Edge|bot)/", $this->ua ) )
{
$is = true;
$major = ( isset( $matches[ 2 ] ) ) ? $matches[ 2 ] : null;
$minor = ( isset( $matches[ 3 ] ) ) ? $matches[ 3 ] : null;
$rev = ( isset( $matches[ 4 ] ) ) ? $matches[ 4 ] : null;
$version = ( isset( $major ) ) ? $major : null;
$version .= ( isset( $minor ) ) ? '.' . $minor : null;
$version .= ( isset( $rev ) ) ? '.' . $rev : null;
}
}
// Versions below 3.x doe not have the Version/ in the UA. Since we can't get the version number, we go with the
// highest version that didn't have the version number in the UA. It doesn't really matter, since this would be
// a 'baseline' browser anyway.
elseif ( preg_match("/(Safari)\/\d+/", $this->ua, $matches) )
{
// These things sometimes surf around acting like they're Safari.
if ( !preg_match( "/(PhantomJS|Silk|rekonq|OPR|Chrome|Android|Edge|bot)/", $this->ua ) )
{
$is = true;
$version = 2;
$major = 2;
$minor = 0;
$rev = 4;
}
}
if ( $is && isset( $version, $major, $minor ) )
{
$this->browser = 'safari';
$this->version = $version;
$this->major = $major;
$this->minor = $minor;
$this->rev = ( isset( $rev ) ) ? $rev : null;
return true;
}
return false;
} | [
"private",
"function",
"isSafari",
"(",
")",
"{",
"$",
"is",
"=",
"false",
";",
"if",
"(",
"preg_match",
"(",
"\"/(Version)\\/(\\d+)\\.(\\d+)(?:\\.(\\d+))?.*Safari\\//\"",
",",
"$",
"this",
"->",
"ua",
",",
"$",
"matches",
")",
")",
"{",
"// These things sometimes surf around acting like they're Safari.",
"if",
"(",
"!",
"preg_match",
"(",
"\"/(PhantomJS|Silk|rekonq|OPR|Chrome|Android|Edge|bot)/\"",
",",
"$",
"this",
"->",
"ua",
")",
")",
"{",
"$",
"is",
"=",
"true",
";",
"$",
"major",
"=",
"(",
"isset",
"(",
"$",
"matches",
"[",
"2",
"]",
")",
")",
"?",
"$",
"matches",
"[",
"2",
"]",
":",
"null",
";",
"$",
"minor",
"=",
"(",
"isset",
"(",
"$",
"matches",
"[",
"3",
"]",
")",
")",
"?",
"$",
"matches",
"[",
"3",
"]",
":",
"null",
";",
"$",
"rev",
"=",
"(",
"isset",
"(",
"$",
"matches",
"[",
"4",
"]",
")",
")",
"?",
"$",
"matches",
"[",
"4",
"]",
":",
"null",
";",
"$",
"version",
"=",
"(",
"isset",
"(",
"$",
"major",
")",
")",
"?",
"$",
"major",
":",
"null",
";",
"$",
"version",
".=",
"(",
"isset",
"(",
"$",
"minor",
")",
")",
"?",
"'.'",
".",
"$",
"minor",
":",
"null",
";",
"$",
"version",
".=",
"(",
"isset",
"(",
"$",
"rev",
")",
")",
"?",
"'.'",
".",
"$",
"rev",
":",
"null",
";",
"}",
"}",
"// Versions below 3.x doe not have the Version/ in the UA. Since we can't get the version number, we go with the",
"// highest version that didn't have the version number in the UA. It doesn't really matter, since this would be",
"// a 'baseline' browser anyway.",
"elseif",
"(",
"preg_match",
"(",
"\"/(Safari)\\/\\d+/\"",
",",
"$",
"this",
"->",
"ua",
",",
"$",
"matches",
")",
")",
"{",
"// These things sometimes surf around acting like they're Safari.",
"if",
"(",
"!",
"preg_match",
"(",
"\"/(PhantomJS|Silk|rekonq|OPR|Chrome|Android|Edge|bot)/\"",
",",
"$",
"this",
"->",
"ua",
")",
")",
"{",
"$",
"is",
"=",
"true",
";",
"$",
"version",
"=",
"2",
";",
"$",
"major",
"=",
"2",
";",
"$",
"minor",
"=",
"0",
";",
"$",
"rev",
"=",
"4",
";",
"}",
"}",
"if",
"(",
"$",
"is",
"&&",
"isset",
"(",
"$",
"version",
",",
"$",
"major",
",",
"$",
"minor",
")",
")",
"{",
"$",
"this",
"->",
"browser",
"=",
"'safari'",
";",
"$",
"this",
"->",
"version",
"=",
"$",
"version",
";",
"$",
"this",
"->",
"major",
"=",
"$",
"major",
";",
"$",
"this",
"->",
"minor",
"=",
"$",
"minor",
";",
"$",
"this",
"->",
"rev",
"=",
"(",
"isset",
"(",
"$",
"rev",
")",
")",
"?",
"$",
"rev",
":",
"null",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Determines if a browser is Safari by the user agent string.
@return bool | [
"Determines",
"if",
"a",
"browser",
"is",
"Safari",
"by",
"the",
"user",
"agent",
"string",
"."
] | d3c66f934bcaa8e5e0424cf684c995b1c80cee29 | https://github.com/jonesiscoding/device/blob/d3c66f934bcaa8e5e0424cf684c995b1c80cee29/src/DetectByUserAgent.php#L273-L318 | train |
jonesiscoding/device | src/DetectByUserAgent.php | DetectByUserAgent.isChrome | private function isChrome()
{
$is = false;
// For our purposes, Chrome and Chromium are the same.
if ( preg_match( "/(Chrome|Chromium)\/([0-9\.]+)/", $this->ua, $matches ) )
{
// These things go around acting like they are chrome, but they aren't.
if ( !preg_match( "/(MRCHROME|FlyFlow|baidubrowser|bot|Edge)/i", $this->ua ) )
{
$is = true;
$version = $matches[ 2 ];
$parts = explode( '.', $matches[ 2 ] );
$major = array_shift($parts);
$minor = array_shift($parts);
$rev = implode( '.', $parts );
}
}
if ( $is && isset($version,$major,$minor,$rev) )
{
$this->browser = 'chrome';
$this->version = $version;
$this->major = $major;
$this->minor = $minor;
$this->rev = $rev;
return true;
}
return false;
} | php | private function isChrome()
{
$is = false;
// For our purposes, Chrome and Chromium are the same.
if ( preg_match( "/(Chrome|Chromium)\/([0-9\.]+)/", $this->ua, $matches ) )
{
// These things go around acting like they are chrome, but they aren't.
if ( !preg_match( "/(MRCHROME|FlyFlow|baidubrowser|bot|Edge)/i", $this->ua ) )
{
$is = true;
$version = $matches[ 2 ];
$parts = explode( '.', $matches[ 2 ] );
$major = array_shift($parts);
$minor = array_shift($parts);
$rev = implode( '.', $parts );
}
}
if ( $is && isset($version,$major,$minor,$rev) )
{
$this->browser = 'chrome';
$this->version = $version;
$this->major = $major;
$this->minor = $minor;
$this->rev = $rev;
return true;
}
return false;
} | [
"private",
"function",
"isChrome",
"(",
")",
"{",
"$",
"is",
"=",
"false",
";",
"// For our purposes, Chrome and Chromium are the same.",
"if",
"(",
"preg_match",
"(",
"\"/(Chrome|Chromium)\\/([0-9\\.]+)/\"",
",",
"$",
"this",
"->",
"ua",
",",
"$",
"matches",
")",
")",
"{",
"// These things go around acting like they are chrome, but they aren't.",
"if",
"(",
"!",
"preg_match",
"(",
"\"/(MRCHROME|FlyFlow|baidubrowser|bot|Edge)/i\"",
",",
"$",
"this",
"->",
"ua",
")",
")",
"{",
"$",
"is",
"=",
"true",
";",
"$",
"version",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"$",
"parts",
"=",
"explode",
"(",
"'.'",
",",
"$",
"matches",
"[",
"2",
"]",
")",
";",
"$",
"major",
"=",
"array_shift",
"(",
"$",
"parts",
")",
";",
"$",
"minor",
"=",
"array_shift",
"(",
"$",
"parts",
")",
";",
"$",
"rev",
"=",
"implode",
"(",
"'.'",
",",
"$",
"parts",
")",
";",
"}",
"}",
"if",
"(",
"$",
"is",
"&&",
"isset",
"(",
"$",
"version",
",",
"$",
"major",
",",
"$",
"minor",
",",
"$",
"rev",
")",
")",
"{",
"$",
"this",
"->",
"browser",
"=",
"'chrome'",
";",
"$",
"this",
"->",
"version",
"=",
"$",
"version",
";",
"$",
"this",
"->",
"major",
"=",
"$",
"major",
";",
"$",
"this",
"->",
"minor",
"=",
"$",
"minor",
";",
"$",
"this",
"->",
"rev",
"=",
"$",
"rev",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Determines if a browser is chrome by the user agent string.
@return bool | [
"Determines",
"if",
"a",
"browser",
"is",
"chrome",
"by",
"the",
"user",
"agent",
"string",
"."
] | d3c66f934bcaa8e5e0424cf684c995b1c80cee29 | https://github.com/jonesiscoding/device/blob/d3c66f934bcaa8e5e0424cf684c995b1c80cee29/src/DetectByUserAgent.php#L324-L354 | train |
jonesiscoding/device | src/DetectByUserAgent.php | DetectByUserAgent.isEdge | private function isEdge()
{
if ( preg_match("/Edge (([0-9]+)\.?([0-9]*))/", $this->ua, $matches) )
{
// Nothing is known to try to look like a faux Edge, but we'll still exclude 'bots'
if( stripos( $this->ua, 'bot' ) === false )
{
$this->browser = "edge";
$this->version = $matches[ 1 ];
$this->major = $matches[ 2 ];
$this->minor = $matches[ 3 ];
}
}
return false;
} | php | private function isEdge()
{
if ( preg_match("/Edge (([0-9]+)\.?([0-9]*))/", $this->ua, $matches) )
{
// Nothing is known to try to look like a faux Edge, but we'll still exclude 'bots'
if( stripos( $this->ua, 'bot' ) === false )
{
$this->browser = "edge";
$this->version = $matches[ 1 ];
$this->major = $matches[ 2 ];
$this->minor = $matches[ 3 ];
}
}
return false;
} | [
"private",
"function",
"isEdge",
"(",
")",
"{",
"if",
"(",
"preg_match",
"(",
"\"/Edge (([0-9]+)\\.?([0-9]*))/\"",
",",
"$",
"this",
"->",
"ua",
",",
"$",
"matches",
")",
")",
"{",
"// Nothing is known to try to look like a faux Edge, but we'll still exclude 'bots'",
"if",
"(",
"stripos",
"(",
"$",
"this",
"->",
"ua",
",",
"'bot'",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"browser",
"=",
"\"edge\"",
";",
"$",
"this",
"->",
"version",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"this",
"->",
"major",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"$",
"this",
"->",
"minor",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Determines if a browser is Microsoft Edge by the user agent string.
@return bool | [
"Determines",
"if",
"a",
"browser",
"is",
"Microsoft",
"Edge",
"by",
"the",
"user",
"agent",
"string",
"."
] | d3c66f934bcaa8e5e0424cf684c995b1c80cee29 | https://github.com/jonesiscoding/device/blob/d3c66f934bcaa8e5e0424cf684c995b1c80cee29/src/DetectByUserAgent.php#L361-L376 | train |
jonesiscoding/device | src/DetectByUserAgent.php | DetectByUserAgent.isMSIE | private function isMSIE()
{
$is = false;
// Versions prior to IE11 follow this format
if ( preg_match("/MSIE (([0-9]+)\.?([0-9]*))/", $this->ua, $matches) )
{
$is = true;
$version = $matches[ 1 ];
$major = $matches[ 2 ];
$minor = $matches[ 3 ];
}
// This one is for IE11 only.
elseif ( preg_match( "/Trident\/[0-9]\.[0-9]; [^;]*[;\s]*rv:(([0-9]+)\.?([0-9]*))/", $this->ua, $matches ) )
{
$is = true;
$version = $matches[ 1 ];
$major = $matches[ 2 ];
$minor = $matches[ 3 ];
}
// Excludes 'bots' that might be acting like MSIE.
if ( $is && isset($version,$major,$minor) && stripos($this->ua,'bot') === false)
{
$this->browser = "msie";
$this->version = $version;
$this->major = $major;
$this->minor = $minor;
return true;
}
return false;
} | php | private function isMSIE()
{
$is = false;
// Versions prior to IE11 follow this format
if ( preg_match("/MSIE (([0-9]+)\.?([0-9]*))/", $this->ua, $matches) )
{
$is = true;
$version = $matches[ 1 ];
$major = $matches[ 2 ];
$minor = $matches[ 3 ];
}
// This one is for IE11 only.
elseif ( preg_match( "/Trident\/[0-9]\.[0-9]; [^;]*[;\s]*rv:(([0-9]+)\.?([0-9]*))/", $this->ua, $matches ) )
{
$is = true;
$version = $matches[ 1 ];
$major = $matches[ 2 ];
$minor = $matches[ 3 ];
}
// Excludes 'bots' that might be acting like MSIE.
if ( $is && isset($version,$major,$minor) && stripos($this->ua,'bot') === false)
{
$this->browser = "msie";
$this->version = $version;
$this->major = $major;
$this->minor = $minor;
return true;
}
return false;
} | [
"private",
"function",
"isMSIE",
"(",
")",
"{",
"$",
"is",
"=",
"false",
";",
"// Versions prior to IE11 follow this format",
"if",
"(",
"preg_match",
"(",
"\"/MSIE (([0-9]+)\\.?([0-9]*))/\"",
",",
"$",
"this",
"->",
"ua",
",",
"$",
"matches",
")",
")",
"{",
"$",
"is",
"=",
"true",
";",
"$",
"version",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"major",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"$",
"minor",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"}",
"// This one is for IE11 only.",
"elseif",
"(",
"preg_match",
"(",
"\"/Trident\\/[0-9]\\.[0-9]; [^;]*[;\\s]*rv:(([0-9]+)\\.?([0-9]*))/\"",
",",
"$",
"this",
"->",
"ua",
",",
"$",
"matches",
")",
")",
"{",
"$",
"is",
"=",
"true",
";",
"$",
"version",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"major",
"=",
"$",
"matches",
"[",
"2",
"]",
";",
"$",
"minor",
"=",
"$",
"matches",
"[",
"3",
"]",
";",
"}",
"// Excludes 'bots' that might be acting like MSIE.",
"if",
"(",
"$",
"is",
"&&",
"isset",
"(",
"$",
"version",
",",
"$",
"major",
",",
"$",
"minor",
")",
"&&",
"stripos",
"(",
"$",
"this",
"->",
"ua",
",",
"'bot'",
")",
"===",
"false",
")",
"{",
"$",
"this",
"->",
"browser",
"=",
"\"msie\"",
";",
"$",
"this",
"->",
"version",
"=",
"$",
"version",
";",
"$",
"this",
"->",
"major",
"=",
"$",
"major",
";",
"$",
"this",
"->",
"minor",
"=",
"$",
"minor",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | Determines if a browser is Internet Explorer by the user agent string.
@return bool | [
"Determines",
"if",
"a",
"browser",
"is",
"Internet",
"Explorer",
"by",
"the",
"user",
"agent",
"string",
"."
] | d3c66f934bcaa8e5e0424cf684c995b1c80cee29 | https://github.com/jonesiscoding/device/blob/d3c66f934bcaa8e5e0424cf684c995b1c80cee29/src/DetectByUserAgent.php#L383-L415 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.