repository_name
stringlengths 5
67
| func_path_in_repository
stringlengths 4
234
| func_name
stringlengths 0
314
| whole_func_string
stringlengths 52
3.87M
| language
stringclasses 6
values | func_code_string
stringlengths 52
3.87M
| func_code_tokens
sequencelengths 15
672k
| func_documentation_string
stringlengths 1
47.2k
| func_documentation_tokens
sequencelengths 1
3.92k
| split_name
stringclasses 1
value | func_code_url
stringlengths 85
339
|
---|---|---|---|---|---|---|---|---|---|---|
meta-tech/pws-auth | src/MetaTech/Util/Tool.php | Tool.concat | public static function concat($sep, $list)
{
$value = array_shift($list);
foreach ($list as $item) {
$value .= $sep . $item;
}
return $value;
} | php | public static function concat($sep, $list)
{
$value = array_shift($list);
foreach ($list as $item) {
$value .= $sep . $item;
}
return $value;
} | [
"public",
"static",
"function",
"concat",
"(",
"$",
"sep",
",",
"$",
"list",
")",
"{",
"$",
"value",
"=",
"array_shift",
"(",
"$",
"list",
")",
";",
"foreach",
"(",
"$",
"list",
"as",
"$",
"item",
")",
"{",
"$",
"value",
".=",
"$",
"sep",
".",
"$",
"item",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | /*!
concatenate various items in $list separate with specifyed separator $sep
@method concat
@public
@param str $sep the used separator to concatenate items in $list
@param [str] $list the list of items to concatenate
@return str | [
"/",
"*",
"!",
"concatenate",
"various",
"items",
"in",
"$list",
"separate",
"with",
"specifyed",
"separator",
"$sep"
] | train | https://github.com/meta-tech/pws-auth/blob/6ba2727cf82470ffbda65925b077fadcd64a77ee/src/MetaTech/Util/Tool.php#L84-L91 |
meta-tech/pws-auth | src/MetaTech/Util/Tool.php | Tool.compact | public static function compact($source, $fields)
{
$data = array();
foreach ($fields as $field) {
if (isset($source[$field])) $data[$field] = $source[$field];
}
return $data;
} | php | public static function compact($source, $fields)
{
$data = array();
foreach ($fields as $field) {
if (isset($source[$field])) $data[$field] = $source[$field];
}
return $data;
} | [
"public",
"static",
"function",
"compact",
"(",
"$",
"source",
",",
"$",
"fields",
")",
"{",
"$",
"data",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"fields",
"as",
"$",
"field",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"source",
"[",
"$",
"field",
"]",
")",
")",
"$",
"data",
"[",
"$",
"field",
"]",
"=",
"$",
"source",
"[",
"$",
"field",
"]",
";",
"}",
"return",
"$",
"data",
";",
"}"
] | /*!
desc
@method compact
@public
@param [str] $source
@param [str] $fields
@return str | [
"/",
"*",
"!",
"desc"
] | train | https://github.com/meta-tech/pws-auth/blob/6ba2727cf82470ffbda65925b077fadcd64a77ee/src/MetaTech/Util/Tool.php#L102-L109 |
NuclearCMS/Hierarchy | src/NodeBag.php | NodeBag.getOrFind | public function getOrFind($id, $published = true)
{
$node = $this->get($id);
if (is_null($node))
{
$node = $published ?
PublishedNode::find($id) :
Node::find($id);
$this->put($id, $node);
}
return $node;
} | php | public function getOrFind($id, $published = true)
{
$node = $this->get($id);
if (is_null($node))
{
$node = $published ?
PublishedNode::find($id) :
Node::find($id);
$this->put($id, $node);
}
return $node;
} | [
"public",
"function",
"getOrFind",
"(",
"$",
"id",
",",
"$",
"published",
"=",
"true",
")",
"{",
"$",
"node",
"=",
"$",
"this",
"->",
"get",
"(",
"$",
"id",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"node",
")",
")",
"{",
"$",
"node",
"=",
"$",
"published",
"?",
"PublishedNode",
"::",
"find",
"(",
"$",
"id",
")",
":",
"Node",
"::",
"find",
"(",
"$",
"id",
")",
";",
"$",
"this",
"->",
"put",
"(",
"$",
"id",
",",
"$",
"node",
")",
";",
"}",
"return",
"$",
"node",
";",
"}"
] | Gets or finds the node and sets by id
@param int $id
@param bool $published
@return Node | [
"Gets",
"or",
"finds",
"the",
"node",
"and",
"sets",
"by",
"id"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/NodeBag.php#L18-L32 |
hametuha/wpametu | src/WPametu/DB/Model.php | Model.get | public function get($id, $ignore_cache = false){
if( empty($this->primary_key) ){
return null;
}
$row = $this->where("{$this->table}.{$this->primary_key} = %d", $id)->get_row('', $ignore_cache);
if( $row && $this->result_class ){
return new $this->result_class($row);
}else{
return $row;
}
} | php | public function get($id, $ignore_cache = false){
if( empty($this->primary_key) ){
return null;
}
$row = $this->where("{$this->table}.{$this->primary_key} = %d", $id)->get_row('', $ignore_cache);
if( $row && $this->result_class ){
return new $this->result_class($row);
}else{
return $row;
}
} | [
"public",
"function",
"get",
"(",
"$",
"id",
",",
"$",
"ignore_cache",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"primary_key",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"row",
"=",
"$",
"this",
"->",
"where",
"(",
"\"{$this->table}.{$this->primary_key} = %d\"",
",",
"$",
"id",
")",
"->",
"get_row",
"(",
"''",
",",
"$",
"ignore_cache",
")",
";",
"if",
"(",
"$",
"row",
"&&",
"$",
"this",
"->",
"result_class",
")",
"{",
"return",
"new",
"$",
"this",
"->",
"result_class",
"(",
"$",
"row",
")",
";",
"}",
"else",
"{",
"return",
"$",
"row",
";",
"}",
"}"
] | Get object with primary key
@param int $id
@param bool $ignore_cache
@return mixed|null | [
"Get",
"object",
"with",
"primary",
"key"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/Model.php#L69-L79 |
hametuha/wpametu | src/WPametu/DB/Model.php | Model.get_var | public function get_var($query = ''){
if( !$query ){
$query = $this->build_query();
}
$this->clear();
return $this->db->get_var($query);
} | php | public function get_var($query = ''){
if( !$query ){
$query = $this->build_query();
}
$this->clear();
return $this->db->get_var($query);
} | [
"public",
"function",
"get_var",
"(",
"$",
"query",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"$",
"query",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"build_query",
"(",
")",
";",
"}",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"return",
"$",
"this",
"->",
"db",
"->",
"get_var",
"(",
"$",
"query",
")",
";",
"}"
] | Get var
@param string $query
@return null|string | [
"Get",
"var"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/Model.php#L100-L106 |
hametuha/wpametu | src/WPametu/DB/Model.php | Model.get_col | public function get_col($x = 0, $query = ''){
if( !$query ){
$query = $this->build_query();
}
$this->clear();
return $this->db->get_col($query, $x);
} | php | public function get_col($x = 0, $query = ''){
if( !$query ){
$query = $this->build_query();
}
$this->clear();
return $this->db->get_col($query, $x);
} | [
"public",
"function",
"get_col",
"(",
"$",
"x",
"=",
"0",
",",
"$",
"query",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"$",
"query",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"build_query",
"(",
")",
";",
"}",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"return",
"$",
"this",
"->",
"db",
"->",
"get_col",
"(",
"$",
"query",
",",
"$",
"x",
")",
";",
"}"
] | Returns specified column as array
@param int $x
@param string $query
@return array | [
"Returns",
"specified",
"column",
"as",
"array"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/Model.php#L115-L121 |
hametuha/wpametu | src/WPametu/DB/Model.php | Model.get_row | public function get_row($query = '', $ignore_cache = false){
if( empty($query) ){
$query = $this->build_query();
$this->clear();
}
if( $this->cache_exist($query) && !$ignore_cache ){
return $this->get_cache($query);
}else{
return $this->db->get_row($query);
}
} | php | public function get_row($query = '', $ignore_cache = false){
if( empty($query) ){
$query = $this->build_query();
$this->clear();
}
if( $this->cache_exist($query) && !$ignore_cache ){
return $this->get_cache($query);
}else{
return $this->db->get_row($query);
}
} | [
"public",
"function",
"get_row",
"(",
"$",
"query",
"=",
"''",
",",
"$",
"ignore_cache",
"=",
"false",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"query",
")",
")",
"{",
"$",
"query",
"=",
"$",
"this",
"->",
"build_query",
"(",
")",
";",
"$",
"this",
"->",
"clear",
"(",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"cache_exist",
"(",
"$",
"query",
")",
"&&",
"!",
"$",
"ignore_cache",
")",
"{",
"return",
"$",
"this",
"->",
"get_cache",
"(",
"$",
"query",
")",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"db",
"->",
"get_row",
"(",
"$",
"query",
")",
";",
"}",
"}"
] | Returns row object
@param string $query
@param bool $ignore_cache
@return mixed|null | [
"Returns",
"row",
"object"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/Model.php#L130-L140 |
hametuha/wpametu | src/WPametu/DB/Model.php | Model.result | public function result($query = '', $ignore_cache = false){
$result = $this->raw_result($query, $ignore_cache);
if( $result && $this->has_result_class() ){
$new_results = [];
foreach($result as $key => $obj){
$new_results[$key] = new $this->result_class($obj);
}
return $new_results;
}else{
return $result;
}
} | php | public function result($query = '', $ignore_cache = false){
$result = $this->raw_result($query, $ignore_cache);
if( $result && $this->has_result_class() ){
$new_results = [];
foreach($result as $key => $obj){
$new_results[$key] = new $this->result_class($obj);
}
return $new_results;
}else{
return $result;
}
} | [
"public",
"function",
"result",
"(",
"$",
"query",
"=",
"''",
",",
"$",
"ignore_cache",
"=",
"false",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"raw_result",
"(",
"$",
"query",
",",
"$",
"ignore_cache",
")",
";",
"if",
"(",
"$",
"result",
"&&",
"$",
"this",
"->",
"has_result_class",
"(",
")",
")",
"{",
"$",
"new_results",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"result",
"as",
"$",
"key",
"=>",
"$",
"obj",
")",
"{",
"$",
"new_results",
"[",
"$",
"key",
"]",
"=",
"new",
"$",
"this",
"->",
"result_class",
"(",
"$",
"obj",
")",
";",
"}",
"return",
"$",
"new_results",
";",
"}",
"else",
"{",
"return",
"$",
"result",
";",
"}",
"}"
] | Get results
@param string $query
@param bool $ignore_cache
@return array|mixed|null | [
"Get",
"results"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/Model.php#L149-L160 |
hametuha/wpametu | src/WPametu/DB/Model.php | Model.insert | protected function insert(array $values, array $place_holders = [], $table = ''){
if( empty($table) ){
extract($this->get_default_values($values, $table, $place_holders));
}
return $this->db->insert($table, $values, $place_holders);
} | php | protected function insert(array $values, array $place_holders = [], $table = ''){
if( empty($table) ){
extract($this->get_default_values($values, $table, $place_holders));
}
return $this->db->insert($table, $values, $place_holders);
} | [
"protected",
"function",
"insert",
"(",
"array",
"$",
"values",
",",
"array",
"$",
"place_holders",
"=",
"[",
"]",
",",
"$",
"table",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"table",
")",
")",
"{",
"extract",
"(",
"$",
"this",
"->",
"get_default_values",
"(",
"$",
"values",
",",
"$",
"table",
",",
"$",
"place_holders",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"db",
"->",
"insert",
"(",
"$",
"table",
",",
"$",
"values",
",",
"$",
"place_holders",
")",
";",
"}"
] | Insert row
@param array $values Array with 'column' => 'value'
@param array $place_holders Array of '%s', '%d', '%f'
@param string $table
@return false|int number of rows or false on failure | [
"Insert",
"row"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/Model.php#L196-L201 |
hametuha/wpametu | src/WPametu/DB/Model.php | Model.update | protected function update(array $values, array $wheres = [], array $place_holders = [], array $where_format = [], $table = ''){
if( empty($table) ){
extract($this->get_default_values($values, $table, $place_holders));
}
if( empty($where_format) && !empty($this->default_placeholder) ){
foreach($wheres as $column => $valud){
if( isset($this->default_placeholder[$column]) ){
$where_format[] = $this->default_placeholder[$column];
}
}
}
return $this->db->update($table, $values, $wheres, $place_holders, $where_format);
} | php | protected function update(array $values, array $wheres = [], array $place_holders = [], array $where_format = [], $table = ''){
if( empty($table) ){
extract($this->get_default_values($values, $table, $place_holders));
}
if( empty($where_format) && !empty($this->default_placeholder) ){
foreach($wheres as $column => $valud){
if( isset($this->default_placeholder[$column]) ){
$where_format[] = $this->default_placeholder[$column];
}
}
}
return $this->db->update($table, $values, $wheres, $place_holders, $where_format);
} | [
"protected",
"function",
"update",
"(",
"array",
"$",
"values",
",",
"array",
"$",
"wheres",
"=",
"[",
"]",
",",
"array",
"$",
"place_holders",
"=",
"[",
"]",
",",
"array",
"$",
"where_format",
"=",
"[",
"]",
",",
"$",
"table",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"table",
")",
")",
"{",
"extract",
"(",
"$",
"this",
"->",
"get_default_values",
"(",
"$",
"values",
",",
"$",
"table",
",",
"$",
"place_holders",
")",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"where_format",
")",
"&&",
"!",
"empty",
"(",
"$",
"this",
"->",
"default_placeholder",
")",
")",
"{",
"foreach",
"(",
"$",
"wheres",
"as",
"$",
"column",
"=>",
"$",
"valud",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"default_placeholder",
"[",
"$",
"column",
"]",
")",
")",
"{",
"$",
"where_format",
"[",
"]",
"=",
"$",
"this",
"->",
"default_placeholder",
"[",
"$",
"column",
"]",
";",
"}",
"}",
"}",
"return",
"$",
"this",
"->",
"db",
"->",
"update",
"(",
"$",
"table",
",",
"$",
"values",
",",
"$",
"wheres",
",",
"$",
"place_holders",
",",
"$",
"where_format",
")",
";",
"}"
] | Update table
@param array $values
@param array $wheres ['column' => 'value'] format.
@param array $place_holders
@param array $where_format
@param string $table
@return false|int | [
"Update",
"table"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/Model.php#L213-L225 |
hametuha/wpametu | src/WPametu/DB/Model.php | Model.get_default_values | protected function get_default_values(array $values = [], $table = '', array $place_holders = [] ){
if( empty($table) ){
$table = $this->table;
}
if( $table == $this->table ){
// Overwrite place holder
if( $this->default_placeholder ){
$default_place_holder = [];
foreach( $values as $column => $value ){
$default_place_holder[] = $this->default_placeholder[$column];
}
if( empty($place_holders) ){
$place_holders = $default_place_holder;
}
}
// Add updated column
if( $this->updated_column ){
if( !isset($values[$this->updated_column]) ){
$values[$this->updated_column] = current_time('mysql');
$place_holders[] = '%s';
}
}
}
return compact('table', 'place_holders', 'values');
} | php | protected function get_default_values(array $values = [], $table = '', array $place_holders = [] ){
if( empty($table) ){
$table = $this->table;
}
if( $table == $this->table ){
// Overwrite place holder
if( $this->default_placeholder ){
$default_place_holder = [];
foreach( $values as $column => $value ){
$default_place_holder[] = $this->default_placeholder[$column];
}
if( empty($place_holders) ){
$place_holders = $default_place_holder;
}
}
// Add updated column
if( $this->updated_column ){
if( !isset($values[$this->updated_column]) ){
$values[$this->updated_column] = current_time('mysql');
$place_holders[] = '%s';
}
}
}
return compact('table', 'place_holders', 'values');
} | [
"protected",
"function",
"get_default_values",
"(",
"array",
"$",
"values",
"=",
"[",
"]",
",",
"$",
"table",
"=",
"''",
",",
"array",
"$",
"place_holders",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"table",
")",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"table",
";",
"}",
"if",
"(",
"$",
"table",
"==",
"$",
"this",
"->",
"table",
")",
"{",
"// Overwrite place holder",
"if",
"(",
"$",
"this",
"->",
"default_placeholder",
")",
"{",
"$",
"default_place_holder",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"values",
"as",
"$",
"column",
"=>",
"$",
"value",
")",
"{",
"$",
"default_place_holder",
"[",
"]",
"=",
"$",
"this",
"->",
"default_placeholder",
"[",
"$",
"column",
"]",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"place_holders",
")",
")",
"{",
"$",
"place_holders",
"=",
"$",
"default_place_holder",
";",
"}",
"}",
"// Add updated column",
"if",
"(",
"$",
"this",
"->",
"updated_column",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"values",
"[",
"$",
"this",
"->",
"updated_column",
"]",
")",
")",
"{",
"$",
"values",
"[",
"$",
"this",
"->",
"updated_column",
"]",
"=",
"current_time",
"(",
"'mysql'",
")",
";",
"$",
"place_holders",
"[",
"]",
"=",
"'%s'",
";",
"}",
"}",
"}",
"return",
"compact",
"(",
"'table'",
",",
"'place_holders'",
",",
"'values'",
")",
";",
"}"
] | Get default value
@param array $values
@param string $table
@param array $place_holders
@return array | [
"Get",
"default",
"value"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/Model.php#L235-L259 |
hametuha/wpametu | src/WPametu/DB/Model.php | Model.delete_where | protected function delete_where(array $wheres, $table_name = ''){
if( empty($table_name) ){
$table_name = $this->table;
}
if( !empty($wheres) ){
$where_clause = [];
foreach( $wheres as $condition ){
if( count($condition) != 4 ){
throw new \Exception('Where section of delete query has 4 parameters(column, operand, value, placeholder)', 500);
}
list($column, $operand, $value, $replace) = $condition;
if( is_array($value) ){
$where_clause[] = "{$column} {$operand} (".implode(', ', array_map(function($val) use ($replace) {
return $this->db->prepare($replace, $val);
}, $value)).")";
}else{
$where_clause[] = $this->db->prepare("{$column} {$operand} {$replace}", $value);
}
}
$where_clause = implode(' AND ', $where_clause);
$query = <<<SQL
DELETE FROM {$table_name}
WHERE {$where_clause}
SQL;
return $this->db->query($query);
}
return 0;
} | php | protected function delete_where(array $wheres, $table_name = ''){
if( empty($table_name) ){
$table_name = $this->table;
}
if( !empty($wheres) ){
$where_clause = [];
foreach( $wheres as $condition ){
if( count($condition) != 4 ){
throw new \Exception('Where section of delete query has 4 parameters(column, operand, value, placeholder)', 500);
}
list($column, $operand, $value, $replace) = $condition;
if( is_array($value) ){
$where_clause[] = "{$column} {$operand} (".implode(', ', array_map(function($val) use ($replace) {
return $this->db->prepare($replace, $val);
}, $value)).")";
}else{
$where_clause[] = $this->db->prepare("{$column} {$operand} {$replace}", $value);
}
}
$where_clause = implode(' AND ', $where_clause);
$query = <<<SQL
DELETE FROM {$table_name}
WHERE {$where_clause}
SQL;
return $this->db->query($query);
}
return 0;
} | [
"protected",
"function",
"delete_where",
"(",
"array",
"$",
"wheres",
",",
"$",
"table_name",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"table_name",
")",
")",
"{",
"$",
"table_name",
"=",
"$",
"this",
"->",
"table",
";",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"wheres",
")",
")",
"{",
"$",
"where_clause",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"wheres",
"as",
"$",
"condition",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"condition",
")",
"!=",
"4",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Where section of delete query has 4 parameters(column, operand, value, placeholder)'",
",",
"500",
")",
";",
"}",
"list",
"(",
"$",
"column",
",",
"$",
"operand",
",",
"$",
"value",
",",
"$",
"replace",
")",
"=",
"$",
"condition",
";",
"if",
"(",
"is_array",
"(",
"$",
"value",
")",
")",
"{",
"$",
"where_clause",
"[",
"]",
"=",
"\"{$column} {$operand} (\"",
".",
"implode",
"(",
"', '",
",",
"array_map",
"(",
"function",
"(",
"$",
"val",
")",
"use",
"(",
"$",
"replace",
")",
"{",
"return",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"$",
"replace",
",",
"$",
"val",
")",
";",
"}",
",",
"$",
"value",
")",
")",
".",
"\")\"",
";",
"}",
"else",
"{",
"$",
"where_clause",
"[",
"]",
"=",
"$",
"this",
"->",
"db",
"->",
"prepare",
"(",
"\"{$column} {$operand} {$replace}\"",
",",
"$",
"value",
")",
";",
"}",
"}",
"$",
"where_clause",
"=",
"implode",
"(",
"' AND '",
",",
"$",
"where_clause",
")",
";",
"$",
"query",
"=",
" <<<SQL\n DELETE FROM {$table_name}\n WHERE {$where_clause}\nSQL",
";",
"return",
"$",
"this",
"->",
"db",
"->",
"query",
"(",
"$",
"query",
")",
";",
"}",
"return",
"0",
";",
"}"
] | Delete record
@param array $wheres
@param string $table_name If not specified, <code>$this->table</code> will be used.
@return false|int
@throws \Exception | [
"Delete",
"record"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/Model.php#L269-L296 |
gedex/php-janrain-api | lib/Janrain/Api/Capture/Clients.php | Clients.clearWhitelist | public function clearWhitelist($clientId = null)
{
$params = array();
if ($clientId) {
$params['for_client_id'] = $clientId;
}
return $this->post('clients/clear_whitelist', $params);
} | php | public function clearWhitelist($clientId = null)
{
$params = array();
if ($clientId) {
$params['for_client_id'] = $clientId;
}
return $this->post('clients/clear_whitelist', $params);
} | [
"public",
"function",
"clearWhitelist",
"(",
"$",
"clientId",
"=",
"null",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"$",
"clientId",
")",
"{",
"$",
"params",
"[",
"'for_client_id'",
"]",
"=",
"$",
"clientId",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"'clients/clear_whitelist'",
",",
"$",
"params",
")",
";",
"}"
] | Clear the IP whitelist for a target client, resetting it to the default
value that allows all IP addresses. Only the 'owner' client may make this
API call. The default whitelist is `["0.0.0.0/0"]`, which means that all IP
addresses are allowed.
@param string $clientId The `client_id` whose whitelist will be cleared. If
you don't use this parameter, the whitelist will be
cleared for the 'owner' client | [
"Clear",
"the",
"IP",
"whitelist",
"for",
"a",
"target",
"client",
"resetting",
"it",
"to",
"the",
"default",
"value",
"that",
"allows",
"all",
"IP",
"addresses",
".",
"Only",
"the",
"owner",
"client",
"may",
"make",
"this",
"API",
"call",
".",
"The",
"default",
"whitelist",
"is",
"[",
"0",
".",
"0",
".",
"0",
".",
"0",
"/",
"0",
"]",
"which",
"means",
"that",
"all",
"IP",
"addresses",
"are",
"allowed",
"."
] | train | https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Capture/Clients.php#L42-L50 |
gedex/php-janrain-api | lib/Janrain/Api/Capture/Clients.php | Clients.getList | public function getList(array $hasFeatures = array())
{
$params = array();
if (!empty($hasFeatures)) {
$params['features'] = json_encode(array_values($hasFeatures));
}
return $this->post('clients/list', $params);
} | php | public function getList(array $hasFeatures = array())
{
$params = array();
if (!empty($hasFeatures)) {
$params['features'] = json_encode(array_values($hasFeatures));
}
return $this->post('clients/list', $params);
} | [
"public",
"function",
"getList",
"(",
"array",
"$",
"hasFeatures",
"=",
"array",
"(",
")",
")",
"{",
"$",
"params",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"hasFeatures",
")",
")",
"{",
"$",
"params",
"[",
"'features'",
"]",
"=",
"json_encode",
"(",
"array_values",
"(",
"$",
"hasFeatures",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"'clients/list'",
",",
"$",
"params",
")",
";",
"}"
] | Since `list` is reserved keyword in PHP.
Get a list of the clients in your Capture application, optionally filtered
by client feature. Only the 'owner' client can make this API call.
@param array $hasFeatures Array features names; only clients which have at
least one of the features in the array will be
displayed | [
"Since",
"list",
"is",
"reserved",
"keyword",
"in",
"PHP",
"."
] | train | https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Capture/Clients.php#L75-L83 |
gedex/php-janrain-api | lib/Janrain/Api/Capture/Clients.php | Clients.setDescription | public function setDescription($clientId, $description)
{
$params = array(
'for_client_id' => $clientId,
'description' => $description,
);
// If empty, description is set for the owner client.
if (!$params['for_client_id']) {
unset($params['for_client_id']);
}
return $this->post('clients/set_description', $params);
} | php | public function setDescription($clientId, $description)
{
$params = array(
'for_client_id' => $clientId,
'description' => $description,
);
// If empty, description is set for the owner client.
if (!$params['for_client_id']) {
unset($params['for_client_id']);
}
return $this->post('clients/set_description', $params);
} | [
"public",
"function",
"setDescription",
"(",
"$",
"clientId",
",",
"$",
"description",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'for_client_id'",
"=>",
"$",
"clientId",
",",
"'description'",
"=>",
"$",
"description",
",",
")",
";",
"// If empty, description is set for the owner client.",
"if",
"(",
"!",
"$",
"params",
"[",
"'for_client_id'",
"]",
")",
"{",
"unset",
"(",
"$",
"params",
"[",
"'for_client_id'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"'clients/set_description'",
",",
"$",
"params",
")",
";",
"}"
] | Change the description of a client. This can also be thought of as the
'name' of the client. This API call may only be made by the owner client.
@param string $clientId The client id of the client having it's
description changed
@param string $description The new description for the target client | [
"Change",
"the",
"description",
"of",
"a",
"client",
".",
"This",
"can",
"also",
"be",
"thought",
"of",
"as",
"the",
"name",
"of",
"the",
"client",
".",
"This",
"API",
"call",
"may",
"only",
"be",
"made",
"by",
"the",
"owner",
"client",
"."
] | train | https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Capture/Clients.php#L119-L132 |
gedex/php-janrain-api | lib/Janrain/Api/Capture/Clients.php | Clients.setFeatures | public function setFeatures($clientId, array $features)
{
$params = array(
'for_client_id' => $clientId,
'features' => json_encode($features),
);
// If empty, features are set for the owner client.
if (!$params['for_client_id']) {
unset($params['for_client_id']);
}
return $this->post('clients/set_features', $params);
} | php | public function setFeatures($clientId, array $features)
{
$params = array(
'for_client_id' => $clientId,
'features' => json_encode($features),
);
// If empty, features are set for the owner client.
if (!$params['for_client_id']) {
unset($params['for_client_id']);
}
return $this->post('clients/set_features', $params);
} | [
"public",
"function",
"setFeatures",
"(",
"$",
"clientId",
",",
"array",
"$",
"features",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'for_client_id'",
"=>",
"$",
"clientId",
",",
"'features'",
"=>",
"json_encode",
"(",
"$",
"features",
")",
",",
")",
";",
"// If empty, features are set for the owner client.",
"if",
"(",
"!",
"$",
"params",
"[",
"'for_client_id'",
"]",
")",
"{",
"unset",
"(",
"$",
"params",
"[",
"'for_client_id'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"'clients/set_features'",
",",
"$",
"params",
")",
";",
"}"
] | Change the features that a target client has by overwriting the old feature
list. This API call may only be made by the 'owner' client. The owner client
may not remove the 'owner' feature from itself.
@param string $clientId The client id for which to set features
@param array $features Array of feature names to assign to the client | [
"Change",
"the",
"features",
"that",
"a",
"target",
"client",
"has",
"by",
"overwriting",
"the",
"old",
"feature",
"list",
".",
"This",
"API",
"call",
"may",
"only",
"be",
"made",
"by",
"the",
"owner",
"client",
".",
"The",
"owner",
"client",
"may",
"not",
"remove",
"the",
"owner",
"feature",
"from",
"itself",
"."
] | train | https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Capture/Clients.php#L142-L155 |
gedex/php-janrain-api | lib/Janrain/Api/Capture/Clients.php | Clients.setWhiteList | public function setWhiteList($clientId, array $addresses)
{
$params = array(
'for_client_id' => $clientId,
'whitelist' => json_encode($addresses),
);
// If empty, features are set for the owner client.
if (!$params['for_client_id']) {
unset($params['for_client_id']);
}
return $this->post('clients/set_whitelist', $params);
} | php | public function setWhiteList($clientId, array $addresses)
{
$params = array(
'for_client_id' => $clientId,
'whitelist' => json_encode($addresses),
);
// If empty, features are set for the owner client.
if (!$params['for_client_id']) {
unset($params['for_client_id']);
}
return $this->post('clients/set_whitelist', $params);
} | [
"public",
"function",
"setWhiteList",
"(",
"$",
"clientId",
",",
"array",
"$",
"addresses",
")",
"{",
"$",
"params",
"=",
"array",
"(",
"'for_client_id'",
"=>",
"$",
"clientId",
",",
"'whitelist'",
"=>",
"json_encode",
"(",
"$",
"addresses",
")",
",",
")",
";",
"// If empty, features are set for the owner client.",
"if",
"(",
"!",
"$",
"params",
"[",
"'for_client_id'",
"]",
")",
"{",
"unset",
"(",
"$",
"params",
"[",
"'for_client_id'",
"]",
")",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"'clients/set_whitelist'",
",",
"$",
"params",
")",
";",
"}"
] | Change the IP whitelist for a target client, overwriting the previous whitelist.
@param string $clientId Client ID
@param array $addresses Array of CIDR addresses | [
"Change",
"the",
"IP",
"whitelist",
"for",
"a",
"target",
"client",
"overwriting",
"the",
"previous",
"whitelist",
"."
] | train | https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Capture/Clients.php#L163-L176 |
blast-project/BaseEntitiesBundle | src/Loggable/Mapping/Event/Adapter/ORM.php | ORM.getNewVersion | public function getNewVersion($meta, $object)
{
$em = $this->getObjectManager();
$objectMeta = $em->getClassMetadata(get_class($object));
$identifierField = $this->getSingleIdentifierFieldName($objectMeta);
$objectId = $objectMeta->getReflectionProperty($identifierField)->getValue($object);
$dql = "SELECT MAX(log.version) FROM {$meta->name} log";
$dql .= ' WHERE log.objectId = :objectId';
$dql .= ' AND log.objectClass = :objectClass';
$q = $em->createQuery($dql);
$q->setParameters(array(
'objectId' => $objectId,
'objectClass' => $objectMeta->name,
));
return $q->getSingleScalarResult() + 1;
} | php | public function getNewVersion($meta, $object)
{
$em = $this->getObjectManager();
$objectMeta = $em->getClassMetadata(get_class($object));
$identifierField = $this->getSingleIdentifierFieldName($objectMeta);
$objectId = $objectMeta->getReflectionProperty($identifierField)->getValue($object);
$dql = "SELECT MAX(log.version) FROM {$meta->name} log";
$dql .= ' WHERE log.objectId = :objectId';
$dql .= ' AND log.objectClass = :objectClass';
$q = $em->createQuery($dql);
$q->setParameters(array(
'objectId' => $objectId,
'objectClass' => $objectMeta->name,
));
return $q->getSingleScalarResult() + 1;
} | [
"public",
"function",
"getNewVersion",
"(",
"$",
"meta",
",",
"$",
"object",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getObjectManager",
"(",
")",
";",
"$",
"objectMeta",
"=",
"$",
"em",
"->",
"getClassMetadata",
"(",
"get_class",
"(",
"$",
"object",
")",
")",
";",
"$",
"identifierField",
"=",
"$",
"this",
"->",
"getSingleIdentifierFieldName",
"(",
"$",
"objectMeta",
")",
";",
"$",
"objectId",
"=",
"$",
"objectMeta",
"->",
"getReflectionProperty",
"(",
"$",
"identifierField",
")",
"->",
"getValue",
"(",
"$",
"object",
")",
";",
"$",
"dql",
"=",
"\"SELECT MAX(log.version) FROM {$meta->name} log\"",
";",
"$",
"dql",
".=",
"' WHERE log.objectId = :objectId'",
";",
"$",
"dql",
".=",
"' AND log.objectClass = :objectClass'",
";",
"$",
"q",
"=",
"$",
"em",
"->",
"createQuery",
"(",
"$",
"dql",
")",
";",
"$",
"q",
"->",
"setParameters",
"(",
"array",
"(",
"'objectId'",
"=>",
"$",
"objectId",
",",
"'objectClass'",
"=>",
"$",
"objectMeta",
"->",
"name",
",",
")",
")",
";",
"return",
"$",
"q",
"->",
"getSingleScalarResult",
"(",
")",
"+",
"1",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/blast-project/BaseEntitiesBundle/blob/abd06891fc38922225ab7e4fcb437a286ba2c0c4/src/Loggable/Mapping/Event/Adapter/ORM.php#L46-L64 |
heidelpay/PhpDoc | src/phpDocumentor/Command/Helper/LoggerHelper.php | LoggerHelper.connectOutputToLogging | public function connectOutputToLogging(OutputInterface $output, $command)
{
static $alreadyConnected = false;
$helper = $this;
// ignore any second or later invocations of this method
if ($alreadyConnected) {
return;
}
/** @var Dispatcher $eventDispatcher */
$eventDispatcher = $command->getService('event_dispatcher');
$eventDispatcher->addListener(
'parser.file.pre',
function (PreFileEvent $event) use ($output) {
$output->writeln('Parsing <info>'.$event->getFile().'</info>');
}
);
$eventDispatcher->addListener(
'system.log',
function (LogEvent $event) use ($command, $helper, $output) {
$helper->logEvent($output, $event, $command);
}
);
$alreadyConnected = true;
} | php | public function connectOutputToLogging(OutputInterface $output, $command)
{
static $alreadyConnected = false;
$helper = $this;
// ignore any second or later invocations of this method
if ($alreadyConnected) {
return;
}
/** @var Dispatcher $eventDispatcher */
$eventDispatcher = $command->getService('event_dispatcher');
$eventDispatcher->addListener(
'parser.file.pre',
function (PreFileEvent $event) use ($output) {
$output->writeln('Parsing <info>'.$event->getFile().'</info>');
}
);
$eventDispatcher->addListener(
'system.log',
function (LogEvent $event) use ($command, $helper, $output) {
$helper->logEvent($output, $event, $command);
}
);
$alreadyConnected = true;
} | [
"public",
"function",
"connectOutputToLogging",
"(",
"OutputInterface",
"$",
"output",
",",
"$",
"command",
")",
"{",
"static",
"$",
"alreadyConnected",
"=",
"false",
";",
"$",
"helper",
"=",
"$",
"this",
";",
"// ignore any second or later invocations of this method",
"if",
"(",
"$",
"alreadyConnected",
")",
"{",
"return",
";",
"}",
"/** @var Dispatcher $eventDispatcher */",
"$",
"eventDispatcher",
"=",
"$",
"command",
"->",
"getService",
"(",
"'event_dispatcher'",
")",
";",
"$",
"eventDispatcher",
"->",
"addListener",
"(",
"'parser.file.pre'",
",",
"function",
"(",
"PreFileEvent",
"$",
"event",
")",
"use",
"(",
"$",
"output",
")",
"{",
"$",
"output",
"->",
"writeln",
"(",
"'Parsing <info>'",
".",
"$",
"event",
"->",
"getFile",
"(",
")",
".",
"'</info>'",
")",
";",
"}",
")",
";",
"$",
"eventDispatcher",
"->",
"addListener",
"(",
"'system.log'",
",",
"function",
"(",
"LogEvent",
"$",
"event",
")",
"use",
"(",
"$",
"command",
",",
"$",
"helper",
",",
"$",
"output",
")",
"{",
"$",
"helper",
"->",
"logEvent",
"(",
"$",
"output",
",",
"$",
"event",
",",
"$",
"command",
")",
";",
"}",
")",
";",
"$",
"alreadyConnected",
"=",
"true",
";",
"}"
] | Connect the logging events to the output object of Symfony Console.
@param OutputInterface $output
@param Command $command
@return void | [
"Connect",
"the",
"logging",
"events",
"to",
"the",
"output",
"object",
"of",
"Symfony",
"Console",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Command/Helper/LoggerHelper.php#L64-L92 |
heidelpay/PhpDoc | src/phpDocumentor/Command/Helper/LoggerHelper.php | LoggerHelper.logEvent | public function logEvent(OutputInterface $output, LogEvent $event, Command $command)
{
$numericErrors = array(
LogLevel::DEBUG => 0,
LogLevel::NOTICE => 1,
LogLevel::INFO => 2,
LogLevel::WARNING => 3,
LogLevel::ERROR => 4,
LogLevel::ALERT => 5,
LogLevel::CRITICAL => 6,
LogLevel::EMERGENCY => 7,
);
$threshold = LogLevel::ERROR;
if ($output->getVerbosity() === OutputInterface::VERBOSITY_DEBUG) {
$threshold = LogLevel::DEBUG;
}
if ($numericErrors[$event->getPriority()] >= $numericErrors[$threshold]) {
/** @var Translator $translator */
$translator = $command->getContainer()->offsetGet('translator');
$message = vsprintf($translator->translate($event->getMessage()), $event->getContext());
switch ($event->getPriority()) {
case LogLevel::WARNING:
$message = '<comment>' . $message . '</comment>';
break;
case LogLevel::EMERGENCY:
case LogLevel::ALERT:
case LogLevel::CRITICAL:
case LogLevel::ERROR:
$message = '<error>' . $message . '</error>';
break;
}
$output->writeln(' ' . $message);
}
} | php | public function logEvent(OutputInterface $output, LogEvent $event, Command $command)
{
$numericErrors = array(
LogLevel::DEBUG => 0,
LogLevel::NOTICE => 1,
LogLevel::INFO => 2,
LogLevel::WARNING => 3,
LogLevel::ERROR => 4,
LogLevel::ALERT => 5,
LogLevel::CRITICAL => 6,
LogLevel::EMERGENCY => 7,
);
$threshold = LogLevel::ERROR;
if ($output->getVerbosity() === OutputInterface::VERBOSITY_DEBUG) {
$threshold = LogLevel::DEBUG;
}
if ($numericErrors[$event->getPriority()] >= $numericErrors[$threshold]) {
/** @var Translator $translator */
$translator = $command->getContainer()->offsetGet('translator');
$message = vsprintf($translator->translate($event->getMessage()), $event->getContext());
switch ($event->getPriority()) {
case LogLevel::WARNING:
$message = '<comment>' . $message . '</comment>';
break;
case LogLevel::EMERGENCY:
case LogLevel::ALERT:
case LogLevel::CRITICAL:
case LogLevel::ERROR:
$message = '<error>' . $message . '</error>';
break;
}
$output->writeln(' ' . $message);
}
} | [
"public",
"function",
"logEvent",
"(",
"OutputInterface",
"$",
"output",
",",
"LogEvent",
"$",
"event",
",",
"Command",
"$",
"command",
")",
"{",
"$",
"numericErrors",
"=",
"array",
"(",
"LogLevel",
"::",
"DEBUG",
"=>",
"0",
",",
"LogLevel",
"::",
"NOTICE",
"=>",
"1",
",",
"LogLevel",
"::",
"INFO",
"=>",
"2",
",",
"LogLevel",
"::",
"WARNING",
"=>",
"3",
",",
"LogLevel",
"::",
"ERROR",
"=>",
"4",
",",
"LogLevel",
"::",
"ALERT",
"=>",
"5",
",",
"LogLevel",
"::",
"CRITICAL",
"=>",
"6",
",",
"LogLevel",
"::",
"EMERGENCY",
"=>",
"7",
",",
")",
";",
"$",
"threshold",
"=",
"LogLevel",
"::",
"ERROR",
";",
"if",
"(",
"$",
"output",
"->",
"getVerbosity",
"(",
")",
"===",
"OutputInterface",
"::",
"VERBOSITY_DEBUG",
")",
"{",
"$",
"threshold",
"=",
"LogLevel",
"::",
"DEBUG",
";",
"}",
"if",
"(",
"$",
"numericErrors",
"[",
"$",
"event",
"->",
"getPriority",
"(",
")",
"]",
">=",
"$",
"numericErrors",
"[",
"$",
"threshold",
"]",
")",
"{",
"/** @var Translator $translator */",
"$",
"translator",
"=",
"$",
"command",
"->",
"getContainer",
"(",
")",
"->",
"offsetGet",
"(",
"'translator'",
")",
";",
"$",
"message",
"=",
"vsprintf",
"(",
"$",
"translator",
"->",
"translate",
"(",
"$",
"event",
"->",
"getMessage",
"(",
")",
")",
",",
"$",
"event",
"->",
"getContext",
"(",
")",
")",
";",
"switch",
"(",
"$",
"event",
"->",
"getPriority",
"(",
")",
")",
"{",
"case",
"LogLevel",
"::",
"WARNING",
":",
"$",
"message",
"=",
"'<comment>'",
".",
"$",
"message",
".",
"'</comment>'",
";",
"break",
";",
"case",
"LogLevel",
"::",
"EMERGENCY",
":",
"case",
"LogLevel",
"::",
"ALERT",
":",
"case",
"LogLevel",
"::",
"CRITICAL",
":",
"case",
"LogLevel",
"::",
"ERROR",
":",
"$",
"message",
"=",
"'<error>'",
".",
"$",
"message",
".",
"'</error>'",
";",
"break",
";",
"}",
"$",
"output",
"->",
"writeln",
"(",
"' '",
".",
"$",
"message",
")",
";",
"}",
"}"
] | Logs an event with the output.
This method will also colorize the message based on priority and withhold
certain logging in case of verbosity or not.
@param OutputInterface $output
@param LogEvent $event
@param Command $command
@return void | [
"Logs",
"an",
"event",
"with",
"the",
"output",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Command/Helper/LoggerHelper.php#L106-L142 |
codezero-be/curl | src/Request.php | Request.get | public function get($url, array $data = [], array $headers = [])
{
$url = $this->optionParser->parseUrl($url, $data);
$this->unsetOption(CURLOPT_POST);
$this->setOptions([
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPGET => true
]);
return $this->send($url, [], $headers);
} | php | public function get($url, array $data = [], array $headers = [])
{
$url = $this->optionParser->parseUrl($url, $data);
$this->unsetOption(CURLOPT_POST);
$this->setOptions([
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPGET => true
]);
return $this->send($url, [], $headers);
} | [
"public",
"function",
"get",
"(",
"$",
"url",
",",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"$",
"url",
"=",
"$",
"this",
"->",
"optionParser",
"->",
"parseUrl",
"(",
"$",
"url",
",",
"$",
"data",
")",
";",
"$",
"this",
"->",
"unsetOption",
"(",
"CURLOPT_POST",
")",
";",
"$",
"this",
"->",
"setOptions",
"(",
"[",
"CURLOPT_CUSTOMREQUEST",
"=>",
"'GET'",
",",
"CURLOPT_HTTPGET",
"=>",
"true",
"]",
")",
";",
"return",
"$",
"this",
"->",
"send",
"(",
"$",
"url",
",",
"[",
"]",
",",
"$",
"headers",
")",
";",
"}"
] | Send GET request
@param string $url
@param array $data
@param array $headers
@return Response | [
"Send",
"GET",
"request"
] | train | https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Request.php#L58-L70 |
codezero-be/curl | src/Request.php | Request.post | public function post($url, array $data = [], array $headers = [])
{
$this->unsetOption(CURLOPT_HTTPGET);
$this->setOptions([
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POST => true
]);
return $this->send($url, $data, $headers);
} | php | public function post($url, array $data = [], array $headers = [])
{
$this->unsetOption(CURLOPT_HTTPGET);
$this->setOptions([
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POST => true
]);
return $this->send($url, $data, $headers);
} | [
"public",
"function",
"post",
"(",
"$",
"url",
",",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"unsetOption",
"(",
"CURLOPT_HTTPGET",
")",
";",
"$",
"this",
"->",
"setOptions",
"(",
"[",
"CURLOPT_CUSTOMREQUEST",
"=>",
"'POST'",
",",
"CURLOPT_POST",
"=>",
"true",
"]",
")",
";",
"return",
"$",
"this",
"->",
"send",
"(",
"$",
"url",
",",
"$",
"data",
",",
"$",
"headers",
")",
";",
"}"
] | Send POST request
@param string $url
@param array $data
@param array $headers
@return Response | [
"Send",
"POST",
"request"
] | train | https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Request.php#L81-L91 |
codezero-be/curl | src/Request.php | Request.put | public function put($url, array $data = [], array $headers = [])
{
$this->unsetOptions([CURLOPT_HTTPGET, CURLOPT_POST]);
$this->setOption(CURLOPT_CUSTOMREQUEST, 'PUT');
return $this->send($url, $data, $headers);
} | php | public function put($url, array $data = [], array $headers = [])
{
$this->unsetOptions([CURLOPT_HTTPGET, CURLOPT_POST]);
$this->setOption(CURLOPT_CUSTOMREQUEST, 'PUT');
return $this->send($url, $data, $headers);
} | [
"public",
"function",
"put",
"(",
"$",
"url",
",",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"$",
"this",
"->",
"unsetOptions",
"(",
"[",
"CURLOPT_HTTPGET",
",",
"CURLOPT_POST",
"]",
")",
";",
"$",
"this",
"->",
"setOption",
"(",
"CURLOPT_CUSTOMREQUEST",
",",
"'PUT'",
")",
";",
"return",
"$",
"this",
"->",
"send",
"(",
"$",
"url",
",",
"$",
"data",
",",
"$",
"headers",
")",
";",
"}"
] | Send PUT request
@param string $url
@param array $data
@param array $headers
@return Response | [
"Send",
"PUT",
"request"
] | train | https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Request.php#L102-L109 |
codezero-be/curl | src/Request.php | Request.setDefaultOptions | private function setDefaultOptions()
{
$this->setOptions([
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true, //=> return response instead of boolean
CURLOPT_FAILONERROR => false //=> also return an error when there is a http error >= 400
]);
} | php | private function setDefaultOptions()
{
$this->setOptions([
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_HEADER => false,
CURLOPT_RETURNTRANSFER => true, //=> return response instead of boolean
CURLOPT_FAILONERROR => false //=> also return an error when there is a http error >= 400
]);
} | [
"private",
"function",
"setDefaultOptions",
"(",
")",
"{",
"$",
"this",
"->",
"setOptions",
"(",
"[",
"CURLOPT_SSL_VERIFYPEER",
"=>",
"true",
",",
"CURLOPT_HEADER",
"=>",
"false",
",",
"CURLOPT_RETURNTRANSFER",
"=>",
"true",
",",
"//=> return response instead of boolean",
"CURLOPT_FAILONERROR",
"=>",
"false",
"//=> also return an error when there is a http error >= 400",
"]",
")",
";",
"}"
] | Set default cURL options
@return void | [
"Set",
"default",
"cURL",
"options"
] | train | https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Request.php#L265-L273 |
codezero-be/curl | src/Request.php | Request.setData | private function setData(array $data)
{
if ( ! empty($data))
{
$this->setOption(CURLOPT_POSTFIELDS, $this->optionParser->parseData($data));
}
else
{
$this->unsetOption(CURLOPT_POSTFIELDS);
}
} | php | private function setData(array $data)
{
if ( ! empty($data))
{
$this->setOption(CURLOPT_POSTFIELDS, $this->optionParser->parseData($data));
}
else
{
$this->unsetOption(CURLOPT_POSTFIELDS);
}
} | [
"private",
"function",
"setData",
"(",
"array",
"$",
"data",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"$",
"this",
"->",
"setOption",
"(",
"CURLOPT_POSTFIELDS",
",",
"$",
"this",
"->",
"optionParser",
"->",
"parseData",
"(",
"$",
"data",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"unsetOption",
"(",
"CURLOPT_POSTFIELDS",
")",
";",
"}",
"}"
] | Set request post fields
@param array $data
@return void | [
"Set",
"request",
"post",
"fields"
] | train | https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Request.php#L294-L304 |
codezero-be/curl | src/Request.php | Request.setHeaders | private function setHeaders(array $headers)
{
if ( ! empty($headers))
{
$this->setOption(CURLOPT_HTTPHEADER, $this->optionParser->parseHeaders($headers));
}
else
{
$this->unsetOption(CURLOPT_HTTPHEADER);
}
} | php | private function setHeaders(array $headers)
{
if ( ! empty($headers))
{
$this->setOption(CURLOPT_HTTPHEADER, $this->optionParser->parseHeaders($headers));
}
else
{
$this->unsetOption(CURLOPT_HTTPHEADER);
}
} | [
"private",
"function",
"setHeaders",
"(",
"array",
"$",
"headers",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"headers",
")",
")",
"{",
"$",
"this",
"->",
"setOption",
"(",
"CURLOPT_HTTPHEADER",
",",
"$",
"this",
"->",
"optionParser",
"->",
"parseHeaders",
"(",
"$",
"headers",
")",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"unsetOption",
"(",
"CURLOPT_HTTPHEADER",
")",
";",
"}",
"}"
] | Set request headers
@param array $headers
@return void | [
"Set",
"request",
"headers"
] | train | https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Request.php#L313-L323 |
codezero-be/curl | src/Request.php | Request.send | private function send($url, array $data = [], array $headers = [])
{
// Set incoming parameters as cURL options
$this->setUrl($url);
$this->setData($data);
$this->setHeaders($headers);
return $this->executeCurlRequest();
} | php | private function send($url, array $data = [], array $headers = [])
{
// Set incoming parameters as cURL options
$this->setUrl($url);
$this->setData($data);
$this->setHeaders($headers);
return $this->executeCurlRequest();
} | [
"private",
"function",
"send",
"(",
"$",
"url",
",",
"array",
"$",
"data",
"=",
"[",
"]",
",",
"array",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"// Set incoming parameters as cURL options",
"$",
"this",
"->",
"setUrl",
"(",
"$",
"url",
")",
";",
"$",
"this",
"->",
"setData",
"(",
"$",
"data",
")",
";",
"$",
"this",
"->",
"setHeaders",
"(",
"$",
"headers",
")",
";",
"return",
"$",
"this",
"->",
"executeCurlRequest",
"(",
")",
";",
"}"
] | Send a request
@param string $url
@param array $data
@param array $headers
@return Response
@throws RequestException | [
"Send",
"a",
"request"
] | train | https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Request.php#L335-L343 |
codezero-be/curl | src/Request.php | Request.executeCurlRequest | private function executeCurlRequest()
{
// Send the request and capture the response
$rawResponse = $this->curl->sendRequest($this->options);
// Fetch additional information about the request
$responseInfo = $this->curl->getRequestInfo();
if ( ! is_array($responseInfo))
{
throw new RequestException('Unable to retrieve request info array!');
}
// Get the error (if any)
$errorCode = $this->curl->getErrorCode();
$errorDescription = $this->curl->getErrorDescription();
// Close Curl
$this->curl->close();
if ($errorCode > 0)
{
// There was a cURL error...
throw new RequestException($errorDescription, $errorCode);
}
// Generate a response with the collected information
return $this->responseFactory->make($rawResponse, $responseInfo);
} | php | private function executeCurlRequest()
{
// Send the request and capture the response
$rawResponse = $this->curl->sendRequest($this->options);
// Fetch additional information about the request
$responseInfo = $this->curl->getRequestInfo();
if ( ! is_array($responseInfo))
{
throw new RequestException('Unable to retrieve request info array!');
}
// Get the error (if any)
$errorCode = $this->curl->getErrorCode();
$errorDescription = $this->curl->getErrorDescription();
// Close Curl
$this->curl->close();
if ($errorCode > 0)
{
// There was a cURL error...
throw new RequestException($errorDescription, $errorCode);
}
// Generate a response with the collected information
return $this->responseFactory->make($rawResponse, $responseInfo);
} | [
"private",
"function",
"executeCurlRequest",
"(",
")",
"{",
"// Send the request and capture the response",
"$",
"rawResponse",
"=",
"$",
"this",
"->",
"curl",
"->",
"sendRequest",
"(",
"$",
"this",
"->",
"options",
")",
";",
"// Fetch additional information about the request",
"$",
"responseInfo",
"=",
"$",
"this",
"->",
"curl",
"->",
"getRequestInfo",
"(",
")",
";",
"if",
"(",
"!",
"is_array",
"(",
"$",
"responseInfo",
")",
")",
"{",
"throw",
"new",
"RequestException",
"(",
"'Unable to retrieve request info array!'",
")",
";",
"}",
"// Get the error (if any)",
"$",
"errorCode",
"=",
"$",
"this",
"->",
"curl",
"->",
"getErrorCode",
"(",
")",
";",
"$",
"errorDescription",
"=",
"$",
"this",
"->",
"curl",
"->",
"getErrorDescription",
"(",
")",
";",
"// Close Curl",
"$",
"this",
"->",
"curl",
"->",
"close",
"(",
")",
";",
"if",
"(",
"$",
"errorCode",
">",
"0",
")",
"{",
"// There was a cURL error...",
"throw",
"new",
"RequestException",
"(",
"$",
"errorDescription",
",",
"$",
"errorCode",
")",
";",
"}",
"// Generate a response with the collected information",
"return",
"$",
"this",
"->",
"responseFactory",
"->",
"make",
"(",
"$",
"rawResponse",
",",
"$",
"responseInfo",
")",
";",
"}"
] | Execute the cURL request
@return Response
@throws RequestException | [
"Execute",
"the",
"cURL",
"request"
] | train | https://github.com/codezero-be/curl/blob/c1385479886662b6276c18dd9140df529959d95c/src/Request.php#L351-L379 |
php-lug/lug | src/Component/Grid/Column/Type/Formatter/NumberFormatter.php | NumberFormatter.format | public function format($value, array $options = [])
{
if (!is_numeric($value)) {
throw new InvalidTypeException(sprintf(
'The number formatter expects a numeric value, got "%s".',
is_object($value) ? get_class($value) : gettype($value)
));
}
$scale = isset($options['scale']) ? $options['scale'] : 2;
$rounding = isset($options['rounding']) ? $options['rounding'] : \NumberFormatter::ROUND_HALFUP;
$grouping = isset($options['grouping']) ? $options['grouping'] : false;
$formatter = new \NumberFormatter($this->localeContext->getLocale(), \NumberFormatter::DECIMAL);
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $scale);
$formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $rounding);
$formatter->setAttribute(\NumberFormatter::GROUPING_USED, $grouping);
return str_replace("\xc2\xa0", ' ', $formatter->format($value));
} | php | public function format($value, array $options = [])
{
if (!is_numeric($value)) {
throw new InvalidTypeException(sprintf(
'The number formatter expects a numeric value, got "%s".',
is_object($value) ? get_class($value) : gettype($value)
));
}
$scale = isset($options['scale']) ? $options['scale'] : 2;
$rounding = isset($options['rounding']) ? $options['rounding'] : \NumberFormatter::ROUND_HALFUP;
$grouping = isset($options['grouping']) ? $options['grouping'] : false;
$formatter = new \NumberFormatter($this->localeContext->getLocale(), \NumberFormatter::DECIMAL);
$formatter->setAttribute(\NumberFormatter::FRACTION_DIGITS, $scale);
$formatter->setAttribute(\NumberFormatter::ROUNDING_MODE, $rounding);
$formatter->setAttribute(\NumberFormatter::GROUPING_USED, $grouping);
return str_replace("\xc2\xa0", ' ', $formatter->format($value));
} | [
"public",
"function",
"format",
"(",
"$",
"value",
",",
"array",
"$",
"options",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"value",
")",
")",
"{",
"throw",
"new",
"InvalidTypeException",
"(",
"sprintf",
"(",
"'The number formatter expects a numeric value, got \"%s\".'",
",",
"is_object",
"(",
"$",
"value",
")",
"?",
"get_class",
"(",
"$",
"value",
")",
":",
"gettype",
"(",
"$",
"value",
")",
")",
")",
";",
"}",
"$",
"scale",
"=",
"isset",
"(",
"$",
"options",
"[",
"'scale'",
"]",
")",
"?",
"$",
"options",
"[",
"'scale'",
"]",
":",
"2",
";",
"$",
"rounding",
"=",
"isset",
"(",
"$",
"options",
"[",
"'rounding'",
"]",
")",
"?",
"$",
"options",
"[",
"'rounding'",
"]",
":",
"\\",
"NumberFormatter",
"::",
"ROUND_HALFUP",
";",
"$",
"grouping",
"=",
"isset",
"(",
"$",
"options",
"[",
"'grouping'",
"]",
")",
"?",
"$",
"options",
"[",
"'grouping'",
"]",
":",
"false",
";",
"$",
"formatter",
"=",
"new",
"\\",
"NumberFormatter",
"(",
"$",
"this",
"->",
"localeContext",
"->",
"getLocale",
"(",
")",
",",
"\\",
"NumberFormatter",
"::",
"DECIMAL",
")",
";",
"$",
"formatter",
"->",
"setAttribute",
"(",
"\\",
"NumberFormatter",
"::",
"FRACTION_DIGITS",
",",
"$",
"scale",
")",
";",
"$",
"formatter",
"->",
"setAttribute",
"(",
"\\",
"NumberFormatter",
"::",
"ROUNDING_MODE",
",",
"$",
"rounding",
")",
";",
"$",
"formatter",
"->",
"setAttribute",
"(",
"\\",
"NumberFormatter",
"::",
"GROUPING_USED",
",",
"$",
"grouping",
")",
";",
"return",
"str_replace",
"(",
"\"\\xc2\\xa0\"",
",",
"' '",
",",
"$",
"formatter",
"->",
"format",
"(",
"$",
"value",
")",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Component/Grid/Column/Type/Formatter/NumberFormatter.php#L38-L57 |
juskiewicz/Geolocation | src/Http/Exception/InvalidServerResponse.php | InvalidServerResponse.create | public static function create(string $query, int $code = 0) : self
{
return new self(sprintf('Server returned an invalid response (%d) for query "%s". We could not parse it.', $code, $query));
} | php | public static function create(string $query, int $code = 0) : self
{
return new self(sprintf('Server returned an invalid response (%d) for query "%s". We could not parse it.', $code, $query));
} | [
"public",
"static",
"function",
"create",
"(",
"string",
"$",
"query",
",",
"int",
"$",
"code",
"=",
"0",
")",
":",
"self",
"{",
"return",
"new",
"self",
"(",
"sprintf",
"(",
"'Server returned an invalid response (%d) for query \"%s\". We could not parse it.'",
",",
"$",
"code",
",",
"$",
"query",
")",
")",
";",
"}"
] | @param string $query
@param int $code
@return InvalidServerResponse | [
"@param",
"string",
"$query",
"@param",
"int",
"$code"
] | train | https://github.com/juskiewicz/Geolocation/blob/5d3cd393961b92bdfbe2dfe631fbfb62c72dc36d/src/Http/Exception/InvalidServerResponse.php#L13-L16 |
Duffleman/json-client | src/JSONClient.php | JSONClient.get | public function get($url, $query = [], $headers = [])
{
$headers = array_merge($this->global_headers, $headers);
return $this->request('GET', $url, [], $query, $headers);
} | php | public function get($url, $query = [], $headers = [])
{
$headers = array_merge($this->global_headers, $headers);
return $this->request('GET', $url, [], $query, $headers);
} | [
"public",
"function",
"get",
"(",
"$",
"url",
",",
"$",
"query",
"=",
"[",
"]",
",",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"$",
"headers",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"global_headers",
",",
"$",
"headers",
")",
";",
"return",
"$",
"this",
"->",
"request",
"(",
"'GET'",
",",
"$",
"url",
",",
"[",
"]",
",",
"$",
"query",
",",
"$",
"headers",
")",
";",
"}"
] | Special method for GET because we never pass in a body.
@param string $url
@param array $query
@param array $headers
@return Collections\Generic|\Illuminate\Support\Collection|void | [
"Special",
"method",
"for",
"GET",
"because",
"we",
"never",
"pass",
"in",
"a",
"body",
"."
] | train | https://github.com/Duffleman/json-client/blob/83432875a000e79243424a1e8676acb9969d0c18/src/JSONClient.php#L85-L90 |
Duffleman/json-client | src/JSONClient.php | JSONClient.request | public function request($method, $url, $body = [], $query = [], $headers = [])
{
list($body, $query, $headers) = $this->setupVariables($body, $query, $headers);
if (!empty($body)) {
$body = encode($body);
$headers['Content-Type'] = 'application/json';
} else {
$body = null;
}
$headers = array_merge($this->global_headers, $headers);
try {
$response = $this->client->request($method, $url, [
'query' => $query,
'body' => $body,
'headers' => $headers,
]);
$response_body = (string) $response->getBody();
} catch (BadResponseException $exception) {
self::handleError($exception);
}
switch ($this->mode) {
case -1:
return $response;
case 0:
return $response_body;
case 1:
if (!empty($response_body)) {
return decode($response_body);
}
return;
case 2:
if (!empty($response_body)) {
return CollectionManager::build(decode($response_body));
}
return;
default:
throw new JSONLibraryException('unknown_mode_set');
}
} | php | public function request($method, $url, $body = [], $query = [], $headers = [])
{
list($body, $query, $headers) = $this->setupVariables($body, $query, $headers);
if (!empty($body)) {
$body = encode($body);
$headers['Content-Type'] = 'application/json';
} else {
$body = null;
}
$headers = array_merge($this->global_headers, $headers);
try {
$response = $this->client->request($method, $url, [
'query' => $query,
'body' => $body,
'headers' => $headers,
]);
$response_body = (string) $response->getBody();
} catch (BadResponseException $exception) {
self::handleError($exception);
}
switch ($this->mode) {
case -1:
return $response;
case 0:
return $response_body;
case 1:
if (!empty($response_body)) {
return decode($response_body);
}
return;
case 2:
if (!empty($response_body)) {
return CollectionManager::build(decode($response_body));
}
return;
default:
throw new JSONLibraryException('unknown_mode_set');
}
} | [
"public",
"function",
"request",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"body",
"=",
"[",
"]",
",",
"$",
"query",
"=",
"[",
"]",
",",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"list",
"(",
"$",
"body",
",",
"$",
"query",
",",
"$",
"headers",
")",
"=",
"$",
"this",
"->",
"setupVariables",
"(",
"$",
"body",
",",
"$",
"query",
",",
"$",
"headers",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"body",
")",
")",
"{",
"$",
"body",
"=",
"encode",
"(",
"$",
"body",
")",
";",
"$",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/json'",
";",
"}",
"else",
"{",
"$",
"body",
"=",
"null",
";",
"}",
"$",
"headers",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"global_headers",
",",
"$",
"headers",
")",
";",
"try",
"{",
"$",
"response",
"=",
"$",
"this",
"->",
"client",
"->",
"request",
"(",
"$",
"method",
",",
"$",
"url",
",",
"[",
"'query'",
"=>",
"$",
"query",
",",
"'body'",
"=>",
"$",
"body",
",",
"'headers'",
"=>",
"$",
"headers",
",",
"]",
")",
";",
"$",
"response_body",
"=",
"(",
"string",
")",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"}",
"catch",
"(",
"BadResponseException",
"$",
"exception",
")",
"{",
"self",
"::",
"handleError",
"(",
"$",
"exception",
")",
";",
"}",
"switch",
"(",
"$",
"this",
"->",
"mode",
")",
"{",
"case",
"-",
"1",
":",
"return",
"$",
"response",
";",
"case",
"0",
":",
"return",
"$",
"response_body",
";",
"case",
"1",
":",
"if",
"(",
"!",
"empty",
"(",
"$",
"response_body",
")",
")",
"{",
"return",
"decode",
"(",
"$",
"response_body",
")",
";",
"}",
"return",
";",
"case",
"2",
":",
"if",
"(",
"!",
"empty",
"(",
"$",
"response_body",
")",
")",
"{",
"return",
"CollectionManager",
"::",
"build",
"(",
"decode",
"(",
"$",
"response_body",
")",
")",
";",
"}",
"return",
";",
"default",
":",
"throw",
"new",
"JSONLibraryException",
"(",
"'unknown_mode_set'",
")",
";",
"}",
"}"
] | The main meaty request method, handles
all outgoing requests and deals with responses.
@param string $method
@param string $url
@param array $body
@param array $query
@param array $headers
@throws JSONError
@throws JSONLibraryException
@return Collections\Generic|\Illuminate\Support\Collection|null|void | [
"The",
"main",
"meaty",
"request",
"method",
"handles",
"all",
"outgoing",
"requests",
"and",
"deals",
"with",
"responses",
"."
] | train | https://github.com/Duffleman/json-client/blob/83432875a000e79243424a1e8676acb9969d0c18/src/JSONClient.php#L107-L151 |
Duffleman/json-client | src/JSONClient.php | JSONClient.requestAsync | public function requestAsync($method, $url, $body = [], $query = [], $headers = [])
{
if (!empty($body)) {
$body = encode($body);
$headers['Content-Type'] = 'application/json';
} else {
$body = null;
}
$headers = array_merge($this->global_headers, $headers);
return $this->client->requestAsync($method, $url, [
'query' => $query,
'body' => $body,
'headers' => $headers,
]);
} | php | public function requestAsync($method, $url, $body = [], $query = [], $headers = [])
{
if (!empty($body)) {
$body = encode($body);
$headers['Content-Type'] = 'application/json';
} else {
$body = null;
}
$headers = array_merge($this->global_headers, $headers);
return $this->client->requestAsync($method, $url, [
'query' => $query,
'body' => $body,
'headers' => $headers,
]);
} | [
"public",
"function",
"requestAsync",
"(",
"$",
"method",
",",
"$",
"url",
",",
"$",
"body",
"=",
"[",
"]",
",",
"$",
"query",
"=",
"[",
"]",
",",
"$",
"headers",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"body",
")",
")",
"{",
"$",
"body",
"=",
"encode",
"(",
"$",
"body",
")",
";",
"$",
"headers",
"[",
"'Content-Type'",
"]",
"=",
"'application/json'",
";",
"}",
"else",
"{",
"$",
"body",
"=",
"null",
";",
"}",
"$",
"headers",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"global_headers",
",",
"$",
"headers",
")",
";",
"return",
"$",
"this",
"->",
"client",
"->",
"requestAsync",
"(",
"$",
"method",
",",
"$",
"url",
",",
"[",
"'query'",
"=>",
"$",
"query",
",",
"'body'",
"=>",
"$",
"body",
",",
"'headers'",
"=>",
"$",
"headers",
",",
"]",
")",
";",
"}"
] | Return a promise for async requests.
@param string $method
@param string $url
@param array $body
@param array $query
@param array $headers
@return \GuzzleHttp\Promise\PromiseInterface | [
"Return",
"a",
"promise",
"for",
"async",
"requests",
"."
] | train | https://github.com/Duffleman/json-client/blob/83432875a000e79243424a1e8676acb9969d0c18/src/JSONClient.php#L164-L180 |
Duffleman/json-client | src/JSONClient.php | JSONClient.handleError | public static function handleError(BadResponseException $exception)
{
$response_body = (string) $exception->getResponse()->getBody();
$array_body = decode($response_body);
$code = $exception->getResponse()->getStatusCode();
$lookForKeys = ['message', 'code', 'error'];
foreach ($lookForKeys as $key) {
if (isset($array_body[$key])) {
$message = $array_body[$key];
}
}
if (!$message) {
$message = 'unknown_error';
}
throw new JSONError($message, $code, $array_body);
} | php | public static function handleError(BadResponseException $exception)
{
$response_body = (string) $exception->getResponse()->getBody();
$array_body = decode($response_body);
$code = $exception->getResponse()->getStatusCode();
$lookForKeys = ['message', 'code', 'error'];
foreach ($lookForKeys as $key) {
if (isset($array_body[$key])) {
$message = $array_body[$key];
}
}
if (!$message) {
$message = 'unknown_error';
}
throw new JSONError($message, $code, $array_body);
} | [
"public",
"static",
"function",
"handleError",
"(",
"BadResponseException",
"$",
"exception",
")",
"{",
"$",
"response_body",
"=",
"(",
"string",
")",
"$",
"exception",
"->",
"getResponse",
"(",
")",
"->",
"getBody",
"(",
")",
";",
"$",
"array_body",
"=",
"decode",
"(",
"$",
"response_body",
")",
";",
"$",
"code",
"=",
"$",
"exception",
"->",
"getResponse",
"(",
")",
"->",
"getStatusCode",
"(",
")",
";",
"$",
"lookForKeys",
"=",
"[",
"'message'",
",",
"'code'",
",",
"'error'",
"]",
";",
"foreach",
"(",
"$",
"lookForKeys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"array_body",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"message",
"=",
"$",
"array_body",
"[",
"$",
"key",
"]",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"message",
")",
"{",
"$",
"message",
"=",
"'unknown_error'",
";",
"}",
"throw",
"new",
"JSONError",
"(",
"$",
"message",
",",
"$",
"code",
",",
"$",
"array_body",
")",
";",
"}"
] | Handles the error for us, just a bit of code abstraction.
@param BadResponseException $exception
@throws JSONError | [
"Handles",
"the",
"error",
"for",
"us",
"just",
"a",
"bit",
"of",
"code",
"abstraction",
"."
] | train | https://github.com/Duffleman/json-client/blob/83432875a000e79243424a1e8676acb9969d0c18/src/JSONClient.php#L189-L209 |
Duffleman/json-client | src/JSONClient.php | JSONClient.mode | public function mode($mode)
{
$acceptable_modes = [-1, 0, 1, 2];
if (!in_array($mode, $acceptable_modes)) {
throw new JSONLibraryException('bad_mode_set');
}
$this->mode = $mode;
return $this;
} | php | public function mode($mode)
{
$acceptable_modes = [-1, 0, 1, 2];
if (!in_array($mode, $acceptable_modes)) {
throw new JSONLibraryException('bad_mode_set');
}
$this->mode = $mode;
return $this;
} | [
"public",
"function",
"mode",
"(",
"$",
"mode",
")",
"{",
"$",
"acceptable_modes",
"=",
"[",
"-",
"1",
",",
"0",
",",
"1",
",",
"2",
"]",
";",
"if",
"(",
"!",
"in_array",
"(",
"$",
"mode",
",",
"$",
"acceptable_modes",
")",
")",
"{",
"throw",
"new",
"JSONLibraryException",
"(",
"'bad_mode_set'",
")",
";",
"}",
"$",
"this",
"->",
"mode",
"=",
"$",
"mode",
";",
"return",
"$",
"this",
";",
"}"
] | Set the mode fluently.
@param int $mode
@throws JSONLibraryException
@return $this | [
"Set",
"the",
"mode",
"fluently",
"."
] | train | https://github.com/Duffleman/json-client/blob/83432875a000e79243424a1e8676acb9969d0c18/src/JSONClient.php#L220-L229 |
Duffleman/json-client | src/JSONClient.php | JSONClient.setupVariables | private function setupVariables($body, $query, $headers)
{
if (is_null($headers)) {
$headers = [];
}
if (is_null($query)) {
$query = [];
}
if (is_null($body)) {
$body = [];
}
return [$body, $query, $headers];
} | php | private function setupVariables($body, $query, $headers)
{
if (is_null($headers)) {
$headers = [];
}
if (is_null($query)) {
$query = [];
}
if (is_null($body)) {
$body = [];
}
return [$body, $query, $headers];
} | [
"private",
"function",
"setupVariables",
"(",
"$",
"body",
",",
"$",
"query",
",",
"$",
"headers",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"headers",
")",
")",
"{",
"$",
"headers",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"query",
")",
")",
"{",
"$",
"query",
"=",
"[",
"]",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"body",
")",
")",
"{",
"$",
"body",
"=",
"[",
"]",
";",
"}",
"return",
"[",
"$",
"body",
",",
"$",
"query",
",",
"$",
"headers",
"]",
";",
"}"
] | Setup empty arrays if null given.
@param $body
@param $query
@param $headers
@return array | [
"Setup",
"empty",
"arrays",
"if",
"null",
"given",
"."
] | train | https://github.com/Duffleman/json-client/blob/83432875a000e79243424a1e8676acb9969d0c18/src/JSONClient.php#L280-L293 |
heidelpay/PhpDoc | src/phpDocumentor/Bootstrap.php | Bootstrap.initialize | public function initialize()
{
$vendorPath = $this->findVendorPath();
$autoloader = $this->createAutoloader($vendorPath);
return new Application($autoloader, array('composer.vendor_path' => $vendorPath));
} | php | public function initialize()
{
$vendorPath = $this->findVendorPath();
$autoloader = $this->createAutoloader($vendorPath);
return new Application($autoloader, array('composer.vendor_path' => $vendorPath));
} | [
"public",
"function",
"initialize",
"(",
")",
"{",
"$",
"vendorPath",
"=",
"$",
"this",
"->",
"findVendorPath",
"(",
")",
";",
"$",
"autoloader",
"=",
"$",
"this",
"->",
"createAutoloader",
"(",
"$",
"vendorPath",
")",
";",
"return",
"new",
"Application",
"(",
"$",
"autoloader",
",",
"array",
"(",
"'composer.vendor_path'",
"=>",
"$",
"vendorPath",
")",
")",
";",
"}"
] | Convenience method that does the complete initialization for phpDocumentor.
@return Application | [
"Convenience",
"method",
"that",
"does",
"the",
"complete",
"initialization",
"for",
"phpDocumentor",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Bootstrap.php#L56-L63 |
heidelpay/PhpDoc | src/phpDocumentor/Bootstrap.php | Bootstrap.registerProfiler | public function registerProfiler()
{
// check whether xhprof is loaded
$profile = (bool) (getenv('PHPDOC_PROFILE') === 'on');
$xhguiPath = getenv('XHGUI_PATH');
if ($profile && $xhguiPath && extension_loaded('xhprof')) {
echo 'PROFILING ENABLED' . PHP_EOL;
include($xhguiPath . '/external/header.php');
}
return $this;
} | php | public function registerProfiler()
{
// check whether xhprof is loaded
$profile = (bool) (getenv('PHPDOC_PROFILE') === 'on');
$xhguiPath = getenv('XHGUI_PATH');
if ($profile && $xhguiPath && extension_loaded('xhprof')) {
echo 'PROFILING ENABLED' . PHP_EOL;
include($xhguiPath . '/external/header.php');
}
return $this;
} | [
"public",
"function",
"registerProfiler",
"(",
")",
"{",
"// check whether xhprof is loaded",
"$",
"profile",
"=",
"(",
"bool",
")",
"(",
"getenv",
"(",
"'PHPDOC_PROFILE'",
")",
"===",
"'on'",
")",
";",
"$",
"xhguiPath",
"=",
"getenv",
"(",
"'XHGUI_PATH'",
")",
";",
"if",
"(",
"$",
"profile",
"&&",
"$",
"xhguiPath",
"&&",
"extension_loaded",
"(",
"'xhprof'",
")",
")",
"{",
"echo",
"'PROFILING ENABLED'",
".",
"PHP_EOL",
";",
"include",
"(",
"$",
"xhguiPath",
".",
"'/external/header.php'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sets up XHProf so that we can profile phpDocumentor using XHGUI.
@return self | [
"Sets",
"up",
"XHProf",
"so",
"that",
"we",
"can",
"profile",
"phpDocumentor",
"using",
"XHGUI",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Bootstrap.php#L70-L81 |
heidelpay/PhpDoc | src/phpDocumentor/Bootstrap.php | Bootstrap.createAutoloader | public function createAutoloader($vendorDir = null)
{
if (! $vendorDir) {
$vendorDir = __DIR__ . '/../../vendor';
}
$autoloader_location = $vendorDir . '/autoload.php';
if (! file_exists($autoloader_location) || ! is_readable($autoloader_location)) {
throw new \RuntimeException(
'phpDocumentor expected to find an autoloader at "' . $autoloader_location . '" but it was not there. '
. 'Usually this is because the "composer install" command has not been ran yet. If this is not the '
. 'case, please open an issue at http://github.com/phpDocumentor/phpDocumentor2 detailing what '
. 'installation method you used, which path is mentioned in this error message and any other relevant '
. 'information.'
);
}
return require $autoloader_location;
} | php | public function createAutoloader($vendorDir = null)
{
if (! $vendorDir) {
$vendorDir = __DIR__ . '/../../vendor';
}
$autoloader_location = $vendorDir . '/autoload.php';
if (! file_exists($autoloader_location) || ! is_readable($autoloader_location)) {
throw new \RuntimeException(
'phpDocumentor expected to find an autoloader at "' . $autoloader_location . '" but it was not there. '
. 'Usually this is because the "composer install" command has not been ran yet. If this is not the '
. 'case, please open an issue at http://github.com/phpDocumentor/phpDocumentor2 detailing what '
. 'installation method you used, which path is mentioned in this error message and any other relevant '
. 'information.'
);
}
return require $autoloader_location;
} | [
"public",
"function",
"createAutoloader",
"(",
"$",
"vendorDir",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"$",
"vendorDir",
")",
"{",
"$",
"vendorDir",
"=",
"__DIR__",
".",
"'/../../vendor'",
";",
"}",
"$",
"autoloader_location",
"=",
"$",
"vendorDir",
".",
"'/autoload.php'",
";",
"if",
"(",
"!",
"file_exists",
"(",
"$",
"autoloader_location",
")",
"||",
"!",
"is_readable",
"(",
"$",
"autoloader_location",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'phpDocumentor expected to find an autoloader at \"'",
".",
"$",
"autoloader_location",
".",
"'\" but it was not there. '",
".",
"'Usually this is because the \"composer install\" command has not been ran yet. If this is not the '",
".",
"'case, please open an issue at http://github.com/phpDocumentor/phpDocumentor2 detailing what '",
".",
"'installation method you used, which path is mentioned in this error message and any other relevant '",
".",
"'information.'",
")",
";",
"}",
"return",
"require",
"$",
"autoloader_location",
";",
"}"
] | Initializes and returns the autoloader.
@param string|null $vendorDir A path (either absolute or relative to the current working directory) leading to
the vendor folder where composer installed the dependencies.
@throws \RuntimeException if no autoloader could be found.
@return ClassLoader | [
"Initializes",
"and",
"returns",
"the",
"autoloader",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Bootstrap.php#L93-L111 |
heidelpay/PhpDoc | src/phpDocumentor/Bootstrap.php | Bootstrap.findVendorPath | public function findVendorPath($baseDir = __DIR__)
{
// default installation
$vendorDir = $baseDir . '/../../vendor';
// Composerised installation, vendor/phpdocumentor/phpdocumentor/src/phpDocumentor is __DIR__
$rootFolderWhenInstalledWithComposer = $baseDir . '/../../../../../';
$composerConfigurationPath = $rootFolderWhenInstalledWithComposer .'composer.json';
if (file_exists($composerConfigurationPath)) {
$vendorDir = $rootFolderWhenInstalledWithComposer
. $this->getCustomVendorPathFromComposer($composerConfigurationPath);
}
return file_exists($vendorDir) ? $vendorDir : null;
} | php | public function findVendorPath($baseDir = __DIR__)
{
// default installation
$vendorDir = $baseDir . '/../../vendor';
// Composerised installation, vendor/phpdocumentor/phpdocumentor/src/phpDocumentor is __DIR__
$rootFolderWhenInstalledWithComposer = $baseDir . '/../../../../../';
$composerConfigurationPath = $rootFolderWhenInstalledWithComposer .'composer.json';
if (file_exists($composerConfigurationPath)) {
$vendorDir = $rootFolderWhenInstalledWithComposer
. $this->getCustomVendorPathFromComposer($composerConfigurationPath);
}
return file_exists($vendorDir) ? $vendorDir : null;
} | [
"public",
"function",
"findVendorPath",
"(",
"$",
"baseDir",
"=",
"__DIR__",
")",
"{",
"// default installation",
"$",
"vendorDir",
"=",
"$",
"baseDir",
".",
"'/../../vendor'",
";",
"// Composerised installation, vendor/phpdocumentor/phpdocumentor/src/phpDocumentor is __DIR__",
"$",
"rootFolderWhenInstalledWithComposer",
"=",
"$",
"baseDir",
".",
"'/../../../../../'",
";",
"$",
"composerConfigurationPath",
"=",
"$",
"rootFolderWhenInstalledWithComposer",
".",
"'composer.json'",
";",
"if",
"(",
"file_exists",
"(",
"$",
"composerConfigurationPath",
")",
")",
"{",
"$",
"vendorDir",
"=",
"$",
"rootFolderWhenInstalledWithComposer",
".",
"$",
"this",
"->",
"getCustomVendorPathFromComposer",
"(",
"$",
"composerConfigurationPath",
")",
";",
"}",
"return",
"file_exists",
"(",
"$",
"vendorDir",
")",
"?",
"$",
"vendorDir",
":",
"null",
";",
"}"
] | Attempts to find the location of the vendor folder.
This method tries to check for a composer.json in a directory 5 levels below the folder of this Bootstrap file.
This is the expected location if phpDocumentor is installed using composer because the current directory for
this file is expected to be 'vendor/phpdocumentor/phpdocumentor/src/phpDocumentor'.
If a composer.json is found we will try to extract the vendor folder name using the 'vendor-dir' configuration
option of composer or assume it is vendor if that option is not set.
If no custom composer.json can be found, then we assume that the vendor folder is that of phpDocumentor itself,
which is `../../vendor` starting from this folder.
If neither locations exist, then this method returns null because no vendor path could be found.
@param $baseDir parameter for test purposes only.
@return string|null | [
"Attempts",
"to",
"find",
"the",
"location",
"of",
"the",
"vendor",
"folder",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Bootstrap.php#L132-L146 |
heidelpay/PhpDoc | src/phpDocumentor/Bootstrap.php | Bootstrap.getCustomVendorPathFromComposer | protected function getCustomVendorPathFromComposer($composerConfigurationPath)
{
$composerFile = file_get_contents($composerConfigurationPath);
$composerJson = json_decode($composerFile, true);
return isset($composerJson['config']['vendor-dir']) ? $composerJson['config']['vendor-dir'] : 'vendor';
} | php | protected function getCustomVendorPathFromComposer($composerConfigurationPath)
{
$composerFile = file_get_contents($composerConfigurationPath);
$composerJson = json_decode($composerFile, true);
return isset($composerJson['config']['vendor-dir']) ? $composerJson['config']['vendor-dir'] : 'vendor';
} | [
"protected",
"function",
"getCustomVendorPathFromComposer",
"(",
"$",
"composerConfigurationPath",
")",
"{",
"$",
"composerFile",
"=",
"file_get_contents",
"(",
"$",
"composerConfigurationPath",
")",
";",
"$",
"composerJson",
"=",
"json_decode",
"(",
"$",
"composerFile",
",",
"true",
")",
";",
"return",
"isset",
"(",
"$",
"composerJson",
"[",
"'config'",
"]",
"[",
"'vendor-dir'",
"]",
")",
"?",
"$",
"composerJson",
"[",
"'config'",
"]",
"[",
"'vendor-dir'",
"]",
":",
"'vendor'",
";",
"}"
] | Retrieves the custom vendor-dir from the given composer.json or returns 'vendor'.
@param string $composerConfigurationPath the path pointing to the composer.json
@return string | [
"Retrieves",
"the",
"custom",
"vendor",
"-",
"dir",
"from",
"the",
"given",
"composer",
".",
"json",
"or",
"returns",
"vendor",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Bootstrap.php#L155-L161 |
technote-space/wordpress-plugin-base | src/classes/models/lib/device.php | Device.is_robot | public function is_robot( $cache = true ) {
if ( $cache && isset( $this->_is_robot ) ) {
return $this->_is_robot;
}
$this->_is_robot = $this->apply_filters( 'pre_check_bot', null );
if ( is_bool( $this->_is_robot ) ) {
return $this->_is_robot;
}
$bot_list = explode( ',', $this->apply_filters( 'bot_list', implode( ',', [
'facebookexternalhit',
'Googlebot',
'Baiduspider',
'bingbot',
'Yeti',
'NaverBot',
'Yahoo! Slurp',
'Y!J-BRI',
'Y!J-BRJ/YATS crawler',
'Tumblr',
// 'livedoor',
// 'Hatena',
'Twitterbot',
'Page Speed',
'Google Web Preview',
'msnbot/',
'proodleBot',
'psbot/',
'ScSpider/',
'TutorGigBot/',
'YottaShopping_Bot/',
'Faxobot/',
'Gigabot/',
'MJ12bot/',
'Ask Jeeves/Teoma; ',
] ) ) );
$this->_is_robot = false;
$ua = $this->app->input->user_agent();
foreach ( $bot_list as $value ) {
$value = trim( $value );
if ( preg_match( '/' . str_replace( '/', '\\/', $value ) . '/i', $ua ) ) {
$this->_is_robot = true;
break;
}
}
return $this->_is_robot;
} | php | public function is_robot( $cache = true ) {
if ( $cache && isset( $this->_is_robot ) ) {
return $this->_is_robot;
}
$this->_is_robot = $this->apply_filters( 'pre_check_bot', null );
if ( is_bool( $this->_is_robot ) ) {
return $this->_is_robot;
}
$bot_list = explode( ',', $this->apply_filters( 'bot_list', implode( ',', [
'facebookexternalhit',
'Googlebot',
'Baiduspider',
'bingbot',
'Yeti',
'NaverBot',
'Yahoo! Slurp',
'Y!J-BRI',
'Y!J-BRJ/YATS crawler',
'Tumblr',
// 'livedoor',
// 'Hatena',
'Twitterbot',
'Page Speed',
'Google Web Preview',
'msnbot/',
'proodleBot',
'psbot/',
'ScSpider/',
'TutorGigBot/',
'YottaShopping_Bot/',
'Faxobot/',
'Gigabot/',
'MJ12bot/',
'Ask Jeeves/Teoma; ',
] ) ) );
$this->_is_robot = false;
$ua = $this->app->input->user_agent();
foreach ( $bot_list as $value ) {
$value = trim( $value );
if ( preg_match( '/' . str_replace( '/', '\\/', $value ) . '/i', $ua ) ) {
$this->_is_robot = true;
break;
}
}
return $this->_is_robot;
} | [
"public",
"function",
"is_robot",
"(",
"$",
"cache",
"=",
"true",
")",
"{",
"if",
"(",
"$",
"cache",
"&&",
"isset",
"(",
"$",
"this",
"->",
"_is_robot",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_is_robot",
";",
"}",
"$",
"this",
"->",
"_is_robot",
"=",
"$",
"this",
"->",
"apply_filters",
"(",
"'pre_check_bot'",
",",
"null",
")",
";",
"if",
"(",
"is_bool",
"(",
"$",
"this",
"->",
"_is_robot",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_is_robot",
";",
"}",
"$",
"bot_list",
"=",
"explode",
"(",
"','",
",",
"$",
"this",
"->",
"apply_filters",
"(",
"'bot_list'",
",",
"implode",
"(",
"','",
",",
"[",
"'facebookexternalhit'",
",",
"'Googlebot'",
",",
"'Baiduspider'",
",",
"'bingbot'",
",",
"'Yeti'",
",",
"'NaverBot'",
",",
"'Yahoo! Slurp'",
",",
"'Y!J-BRI'",
",",
"'Y!J-BRJ/YATS crawler'",
",",
"'Tumblr'",
",",
"//\t\t'livedoor',",
"//\t\t'Hatena',",
"'Twitterbot'",
",",
"'Page Speed'",
",",
"'Google Web Preview'",
",",
"'msnbot/'",
",",
"'proodleBot'",
",",
"'psbot/'",
",",
"'ScSpider/'",
",",
"'TutorGigBot/'",
",",
"'YottaShopping_Bot/'",
",",
"'Faxobot/'",
",",
"'Gigabot/'",
",",
"'MJ12bot/'",
",",
"'Ask Jeeves/Teoma; '",
",",
"]",
")",
")",
")",
";",
"$",
"this",
"->",
"_is_robot",
"=",
"false",
";",
"$",
"ua",
"=",
"$",
"this",
"->",
"app",
"->",
"input",
"->",
"user_agent",
"(",
")",
";",
"foreach",
"(",
"$",
"bot_list",
"as",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"trim",
"(",
"$",
"value",
")",
";",
"if",
"(",
"preg_match",
"(",
"'/'",
".",
"str_replace",
"(",
"'/'",
",",
"'\\\\/'",
",",
"$",
"value",
")",
".",
"'/i'",
",",
"$",
"ua",
")",
")",
"{",
"$",
"this",
"->",
"_is_robot",
"=",
"true",
";",
"break",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_is_robot",
";",
"}"
] | @param bool $cache
@return bool | [
"@param",
"bool",
"$cache"
] | train | https://github.com/technote-space/wordpress-plugin-base/blob/02cfcba358432a2539af07a69d9db00ff7c14eac/src/classes/models/lib/device.php#L62-L111 |
everest-php/framework | src/Social/FacebookAuth.php | FacebookAuth.collectResponse | public static function collectResponse(){
self::init();
$fb = self::$fbInstance;
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (isset($accessToken)) {
$oAuth2Client = $fb->getOAuth2Client();
$longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
Cookie::setItem("fb_token",$longLivedAccessToken);
self::redirectToRedirectURL();
}
} | php | public static function collectResponse(){
self::init();
$fb = self::$fbInstance;
$helper = $fb->getRedirectLoginHelper();
try {
$accessToken = $helper->getAccessToken();
} catch(FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
if (isset($accessToken)) {
$oAuth2Client = $fb->getOAuth2Client();
$longLivedAccessToken = $oAuth2Client->getLongLivedAccessToken($accessToken);
Cookie::setItem("fb_token",$longLivedAccessToken);
self::redirectToRedirectURL();
}
} | [
"public",
"static",
"function",
"collectResponse",
"(",
")",
"{",
"self",
"::",
"init",
"(",
")",
";",
"$",
"fb",
"=",
"self",
"::",
"$",
"fbInstance",
";",
"$",
"helper",
"=",
"$",
"fb",
"->",
"getRedirectLoginHelper",
"(",
")",
";",
"try",
"{",
"$",
"accessToken",
"=",
"$",
"helper",
"->",
"getAccessToken",
"(",
")",
";",
"}",
"catch",
"(",
"FacebookResponseException",
"$",
"e",
")",
"{",
"echo",
"'Graph returned an error: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"exit",
";",
"}",
"catch",
"(",
"FacebookSDKException",
"$",
"e",
")",
"{",
"echo",
"'Facebook SDK returned an error: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
";",
"exit",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"accessToken",
")",
")",
"{",
"$",
"oAuth2Client",
"=",
"$",
"fb",
"->",
"getOAuth2Client",
"(",
")",
";",
"$",
"longLivedAccessToken",
"=",
"$",
"oAuth2Client",
"->",
"getLongLivedAccessToken",
"(",
"$",
"accessToken",
")",
";",
"Cookie",
"::",
"setItem",
"(",
"\"fb_token\"",
",",
"$",
"longLivedAccessToken",
")",
";",
"self",
"::",
"redirectToRedirectURL",
"(",
")",
";",
"}",
"}"
] | Part 2: When Authorise Response comes back from facebook | [
"Part",
"2",
":",
"When",
"Authorise",
"Response",
"comes",
"back",
"from",
"facebook"
] | train | https://github.com/everest-php/framework/blob/f5c402dd7dbd7622074d2aa4835bcee133f398a7/src/Social/FacebookAuth.php#L67-L89 |
songshenzong/log | src/LaravelDebugbar.php | LaravelDebugbar.boot | public function boot()
{
if ($this->booted) {
return;
}
/** @var \Songshenzong\Log\LaravelDebugbar $debugbar */
$debugbar = $this;
/** @var Application $app */
$app = $this->app;
// Set custom error handler
set_error_handler([$this, 'handleError']);
/**---------------------------------------------------------
* phpinfo
*---------------------------------------------------------*/
if ($this->shouldCollect('phpinfo', true)) {
$this->addCollector(new PhpInfoCollector());
}
/**---------------------------------------------------------
* Messages
*---------------------------------------------------------*/
if ($this->shouldCollect('messages', true)) {
$this->addCollector(new MessagesCollector());
}
/**---------------------------------------------------------
* time
*---------------------------------------------------------*/
if ($this->shouldCollect('time', true)) {
$this->addCollector(new TimeDataCollector());
if (!$this->isLumen()) {
$this->app->booted(
function () use ($debugbar) {
$startTime = $this->app['request']->server('REQUEST_TIME_FLOAT');
if ($startTime) {
$debugbar['time']->addMeasure('Booting', $startTime, microtime(true));
}
}
);
}
$debugbar->startMeasure('application', 'Application');
}
/**---------------------------------------------------------
* memory
*---------------------------------------------------------*/
if ($this->shouldCollect('memory', true)) {
$this->addCollector(new MemoryCollector());
}
/**---------------------------------------------------------
* exceptions
*---------------------------------------------------------*/
if ($this->shouldCollect('exceptions', true)) {
try {
$exceptionCollector = new ExceptionsCollector();
$exceptionCollector->setChainExceptions(
$this->app['config']->get('songshenzong-log.options.exceptions.chain', true)
);
$this->addCollector($exceptionCollector);
} catch (\Exception $e) {
}
}
/**---------------------------------------------------------
* laravel
*---------------------------------------------------------*/
if ($this->shouldCollect('laravel', false)) {
$this->addCollector(new LaravelCollector($this->app));
}
/**---------------------------------------------------------
* All events fired
*---------------------------------------------------------*/
if ($this->shouldCollect('events', false) && isset($this->app['events'])) {
try {
$startTime = $this->app['request']->server('REQUEST_TIME_FLOAT');
$eventCollector = new EventCollector($startTime);
$this->addCollector($eventCollector);
$this->app['events']->subscribe($eventCollector);
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add EventCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Views with their data
*---------------------------------------------------------*/
if ($this->shouldCollect('views', true) && isset($this->app['events'])) {
try {
$collectData = $this->app['config']->get('songshenzong-log.options.views.data', true);
$this->addCollector(new ViewCollector($collectData));
$this->app['events']->listen(
'composing:*',
function ($view, $data = []) use ($debugbar) {
if ($data) {
$view = $data[0]; // For Laravel >= 5.4
}
$debugbar['views']->addView($view);
}
);
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add ViewCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Current route information
*---------------------------------------------------------*/
if (!$this->isLumen() && $this->shouldCollect('route')) {
try {
$this->addCollector($this->app->make('Songshenzong\Log\DataCollector\IlluminateRouteCollector'));
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add RouteCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Logs from Mongolog (merged in messages if enabled)
*---------------------------------------------------------*/
if (!$this->isLumen() && $this->shouldCollect('log', true)) {
try {
if ($this->hasCollector('messages')) {
$logger = new MessagesCollector('log');
$this['messages']->aggregate($logger);
$this->app['log']->listen(
function ($level, $message = null, $context = null) use ($logger) {
// Laravel 5.4 changed how the global log listeners are called. We must account for
// the first argument being an "event object", where arguments are passed
// via object properties, instead of individual arguments.
if ($level instanceof \Illuminate\Log\Events\MessageLogged) {
$message = $level->message;
$context = $level->context;
$level = $level->level;
}
try {
$logMessage = (string) $message;
if (mb_check_encoding($logMessage, 'UTF-8')) {
$logMessage .= (!empty($context) ? ' ' . json_encode($context) : '');
} else {
$logMessage = '[INVALID UTF-8 DATA]';
}
} catch (\Exception $e) {
$logMessage = '[Exception: ' . $e->getMessage() . ']';
}
$logger->addMessage(
'[' . date('H:i:s') . '] ' . "LOG.$level: " . $logMessage,
$level,
false
);
}
);
} else {
$this->addCollector(new MonologCollector($this->app['log']->getMonolog()));
}
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add LogsCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Show database (PDO) queries and bindings
*---------------------------------------------------------*/
if ($this->shouldCollect('db', true) && isset($this->app['db'])) {
$db = $this->app['db'];
if ($debugbar->hasCollector('time') && $this->app['config']->get(
'songshenzong-log.options.db.timeline',
false
)
) {
$timeCollector = $debugbar->getCollector('time');
} else {
$timeCollector = null;
}
$queryCollector = new QueryCollector($timeCollector);
$queryCollector->setDataFormatter(new QueryFormatter());
if ($this->app['config']->get('songshenzong-log.options.db.with_params')) {
$queryCollector->setRenderSqlWithParams(true);
}
if ($this->app['config']->get('songshenzong-log.options.db.backtrace')) {
$middleware = !$this->is_lumen ? $this->app['router']->getMiddleware() : [];
$queryCollector->setFindSource(true, $middleware);
}
if ($this->app['config']->get('songshenzong-log.options.db.explain.enabled')) {
$types = $this->app['config']->get('songshenzong-log.options.db.explain.types');
$queryCollector->setExplainSource(true, $types);
}
if ($this->app['config']->get('songshenzong-log.options.db.hints', true)) {
$queryCollector->setShowHints(true);
}
$this->addCollector($queryCollector);
try {
$db->listen(
function ($query, $bindings = null, $time = null, $connectionName = null) use ($db, $queryCollector) {
// Laravel 5.2 changed the way some core events worked. We must account for
// the first argument being an "event object", where arguments are passed
// via object properties, instead of individual arguments.
if ($query instanceof \Illuminate\Database\Events\QueryExecuted) {
$bindings = $query->bindings;
$time = $query->time;
$connection = $query->connection;
$query = $query->sql;
} else {
$connection = $db->connection($connectionName);
}
$queryCollector->addQuery((string) $query, $bindings, $time, $connection);
}
);
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add listen to Queries for Songshenzong: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
try {
$db->getEventDispatcher()->listen([
\Illuminate\Database\Events\TransactionBeginning::class,
'connection.*.beganTransaction',
], function ($transaction) use ($queryCollector) {
$queryCollector->collectTransactionEvent('Begin Transaction', $transaction->connection);
});
$db->getEventDispatcher()->listen([
\Illuminate\Database\Events\TransactionCommitted::class,
'connection.*.committed',
], function ($transaction) use ($queryCollector) {
$queryCollector->collectTransactionEvent('Commit Transaction', $transaction->connection);
});
$db->getEventDispatcher()->listen([
\Illuminate\Database\Events\TransactionRolledBack::class,
'connection.*.rollingBack',
], function ($transaction) use ($queryCollector) {
$queryCollector->collectTransactionEvent('Rollback Transaction', $transaction->connection);
});
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add listen transactions to Queries for Songshenzong: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Catch mail messages
*---------------------------------------------------------*/
if ($this->shouldCollect('mail', true) && class_exists('Illuminate\Mail\MailServiceProvider')) {
try {
$mailer = $this->app['mailer']->getSwiftMailer();
$this->addCollector(new SwiftMailCollector($mailer));
if ($this->app['config']->get('songshenzong-log.options.mail.full_log') && $this->hasCollector(
'messages'
)
) {
$this['messages']->aggregate(new SwiftLogCollector($mailer));
}
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add MailCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Add the latest log messages
*---------------------------------------------------------*/
if ($this->shouldCollect('logs', false)) {
try {
$file = $this->app['config']->get('songshenzong-log.options.logs.file');
$this->addCollector(new LogsCollector($file));
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add LogsCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Show the included files
*---------------------------------------------------------*/
if ($this->shouldCollect('files', false)) {
$this->addCollector(new FilesCollector($app));
}
/**---------------------------------------------------------
* Display Laravel authentication status
*---------------------------------------------------------*/
if ($this->shouldCollect('auth', false)) {
try {
if ($this->checkVersion('5.2')) {
// fix for compatibility with Laravel 5.2.*
$guards = array_keys($this->app['config']->get('auth.guards'));
$authCollector = new MultiAuthCollector($app['auth'], $guards);
} else {
$authCollector = new AuthCollector($app['auth']);
}
$authCollector->setShowName(
$this->app['config']->get('songshenzong-log.options.auth.show_name')
);
$this->addCollector($authCollector);
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add AuthCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Display Laravel Gate checks
*---------------------------------------------------------*/
if ($this->shouldCollect('gate', false)) {
try {
$gateCollector = $this->app->make('Songshenzong\Log\DataCollector\GateCollector');
$this->addCollector($gateCollector);
} catch (\Exception $e) {
// No Gate collector
}
}
$this->booted = true;
} | php | public function boot()
{
if ($this->booted) {
return;
}
/** @var \Songshenzong\Log\LaravelDebugbar $debugbar */
$debugbar = $this;
/** @var Application $app */
$app = $this->app;
// Set custom error handler
set_error_handler([$this, 'handleError']);
/**---------------------------------------------------------
* phpinfo
*---------------------------------------------------------*/
if ($this->shouldCollect('phpinfo', true)) {
$this->addCollector(new PhpInfoCollector());
}
/**---------------------------------------------------------
* Messages
*---------------------------------------------------------*/
if ($this->shouldCollect('messages', true)) {
$this->addCollector(new MessagesCollector());
}
/**---------------------------------------------------------
* time
*---------------------------------------------------------*/
if ($this->shouldCollect('time', true)) {
$this->addCollector(new TimeDataCollector());
if (!$this->isLumen()) {
$this->app->booted(
function () use ($debugbar) {
$startTime = $this->app['request']->server('REQUEST_TIME_FLOAT');
if ($startTime) {
$debugbar['time']->addMeasure('Booting', $startTime, microtime(true));
}
}
);
}
$debugbar->startMeasure('application', 'Application');
}
/**---------------------------------------------------------
* memory
*---------------------------------------------------------*/
if ($this->shouldCollect('memory', true)) {
$this->addCollector(new MemoryCollector());
}
/**---------------------------------------------------------
* exceptions
*---------------------------------------------------------*/
if ($this->shouldCollect('exceptions', true)) {
try {
$exceptionCollector = new ExceptionsCollector();
$exceptionCollector->setChainExceptions(
$this->app['config']->get('songshenzong-log.options.exceptions.chain', true)
);
$this->addCollector($exceptionCollector);
} catch (\Exception $e) {
}
}
/**---------------------------------------------------------
* laravel
*---------------------------------------------------------*/
if ($this->shouldCollect('laravel', false)) {
$this->addCollector(new LaravelCollector($this->app));
}
/**---------------------------------------------------------
* All events fired
*---------------------------------------------------------*/
if ($this->shouldCollect('events', false) && isset($this->app['events'])) {
try {
$startTime = $this->app['request']->server('REQUEST_TIME_FLOAT');
$eventCollector = new EventCollector($startTime);
$this->addCollector($eventCollector);
$this->app['events']->subscribe($eventCollector);
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add EventCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Views with their data
*---------------------------------------------------------*/
if ($this->shouldCollect('views', true) && isset($this->app['events'])) {
try {
$collectData = $this->app['config']->get('songshenzong-log.options.views.data', true);
$this->addCollector(new ViewCollector($collectData));
$this->app['events']->listen(
'composing:*',
function ($view, $data = []) use ($debugbar) {
if ($data) {
$view = $data[0]; // For Laravel >= 5.4
}
$debugbar['views']->addView($view);
}
);
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add ViewCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Current route information
*---------------------------------------------------------*/
if (!$this->isLumen() && $this->shouldCollect('route')) {
try {
$this->addCollector($this->app->make('Songshenzong\Log\DataCollector\IlluminateRouteCollector'));
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add RouteCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Logs from Mongolog (merged in messages if enabled)
*---------------------------------------------------------*/
if (!$this->isLumen() && $this->shouldCollect('log', true)) {
try {
if ($this->hasCollector('messages')) {
$logger = new MessagesCollector('log');
$this['messages']->aggregate($logger);
$this->app['log']->listen(
function ($level, $message = null, $context = null) use ($logger) {
// Laravel 5.4 changed how the global log listeners are called. We must account for
// the first argument being an "event object", where arguments are passed
// via object properties, instead of individual arguments.
if ($level instanceof \Illuminate\Log\Events\MessageLogged) {
$message = $level->message;
$context = $level->context;
$level = $level->level;
}
try {
$logMessage = (string) $message;
if (mb_check_encoding($logMessage, 'UTF-8')) {
$logMessage .= (!empty($context) ? ' ' . json_encode($context) : '');
} else {
$logMessage = '[INVALID UTF-8 DATA]';
}
} catch (\Exception $e) {
$logMessage = '[Exception: ' . $e->getMessage() . ']';
}
$logger->addMessage(
'[' . date('H:i:s') . '] ' . "LOG.$level: " . $logMessage,
$level,
false
);
}
);
} else {
$this->addCollector(new MonologCollector($this->app['log']->getMonolog()));
}
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add LogsCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Show database (PDO) queries and bindings
*---------------------------------------------------------*/
if ($this->shouldCollect('db', true) && isset($this->app['db'])) {
$db = $this->app['db'];
if ($debugbar->hasCollector('time') && $this->app['config']->get(
'songshenzong-log.options.db.timeline',
false
)
) {
$timeCollector = $debugbar->getCollector('time');
} else {
$timeCollector = null;
}
$queryCollector = new QueryCollector($timeCollector);
$queryCollector->setDataFormatter(new QueryFormatter());
if ($this->app['config']->get('songshenzong-log.options.db.with_params')) {
$queryCollector->setRenderSqlWithParams(true);
}
if ($this->app['config']->get('songshenzong-log.options.db.backtrace')) {
$middleware = !$this->is_lumen ? $this->app['router']->getMiddleware() : [];
$queryCollector->setFindSource(true, $middleware);
}
if ($this->app['config']->get('songshenzong-log.options.db.explain.enabled')) {
$types = $this->app['config']->get('songshenzong-log.options.db.explain.types');
$queryCollector->setExplainSource(true, $types);
}
if ($this->app['config']->get('songshenzong-log.options.db.hints', true)) {
$queryCollector->setShowHints(true);
}
$this->addCollector($queryCollector);
try {
$db->listen(
function ($query, $bindings = null, $time = null, $connectionName = null) use ($db, $queryCollector) {
// Laravel 5.2 changed the way some core events worked. We must account for
// the first argument being an "event object", where arguments are passed
// via object properties, instead of individual arguments.
if ($query instanceof \Illuminate\Database\Events\QueryExecuted) {
$bindings = $query->bindings;
$time = $query->time;
$connection = $query->connection;
$query = $query->sql;
} else {
$connection = $db->connection($connectionName);
}
$queryCollector->addQuery((string) $query, $bindings, $time, $connection);
}
);
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add listen to Queries for Songshenzong: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
try {
$db->getEventDispatcher()->listen([
\Illuminate\Database\Events\TransactionBeginning::class,
'connection.*.beganTransaction',
], function ($transaction) use ($queryCollector) {
$queryCollector->collectTransactionEvent('Begin Transaction', $transaction->connection);
});
$db->getEventDispatcher()->listen([
\Illuminate\Database\Events\TransactionCommitted::class,
'connection.*.committed',
], function ($transaction) use ($queryCollector) {
$queryCollector->collectTransactionEvent('Commit Transaction', $transaction->connection);
});
$db->getEventDispatcher()->listen([
\Illuminate\Database\Events\TransactionRolledBack::class,
'connection.*.rollingBack',
], function ($transaction) use ($queryCollector) {
$queryCollector->collectTransactionEvent('Rollback Transaction', $transaction->connection);
});
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add listen transactions to Queries for Songshenzong: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Catch mail messages
*---------------------------------------------------------*/
if ($this->shouldCollect('mail', true) && class_exists('Illuminate\Mail\MailServiceProvider')) {
try {
$mailer = $this->app['mailer']->getSwiftMailer();
$this->addCollector(new SwiftMailCollector($mailer));
if ($this->app['config']->get('songshenzong-log.options.mail.full_log') && $this->hasCollector(
'messages'
)
) {
$this['messages']->aggregate(new SwiftLogCollector($mailer));
}
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add MailCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Add the latest log messages
*---------------------------------------------------------*/
if ($this->shouldCollect('logs', false)) {
try {
$file = $this->app['config']->get('songshenzong-log.options.logs.file');
$this->addCollector(new LogsCollector($file));
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add LogsCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Show the included files
*---------------------------------------------------------*/
if ($this->shouldCollect('files', false)) {
$this->addCollector(new FilesCollector($app));
}
/**---------------------------------------------------------
* Display Laravel authentication status
*---------------------------------------------------------*/
if ($this->shouldCollect('auth', false)) {
try {
if ($this->checkVersion('5.2')) {
// fix for compatibility with Laravel 5.2.*
$guards = array_keys($this->app['config']->get('auth.guards'));
$authCollector = new MultiAuthCollector($app['auth'], $guards);
} else {
$authCollector = new AuthCollector($app['auth']);
}
$authCollector->setShowName(
$this->app['config']->get('songshenzong-log.options.auth.show_name')
);
$this->addCollector($authCollector);
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add AuthCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Display Laravel Gate checks
*---------------------------------------------------------*/
if ($this->shouldCollect('gate', false)) {
try {
$gateCollector = $this->app->make('Songshenzong\Log\DataCollector\GateCollector');
$this->addCollector($gateCollector);
} catch (\Exception $e) {
// No Gate collector
}
}
$this->booted = true;
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"booted",
")",
"{",
"return",
";",
"}",
"/** @var \\Songshenzong\\Log\\LaravelDebugbar $debugbar */",
"$",
"debugbar",
"=",
"$",
"this",
";",
"/** @var Application $app */",
"$",
"app",
"=",
"$",
"this",
"->",
"app",
";",
"// Set custom error handler",
"set_error_handler",
"(",
"[",
"$",
"this",
",",
"'handleError'",
"]",
")",
";",
"/**---------------------------------------------------------\n * phpinfo\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'phpinfo'",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"addCollector",
"(",
"new",
"PhpInfoCollector",
"(",
")",
")",
";",
"}",
"/**---------------------------------------------------------\n * Messages\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'messages'",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"addCollector",
"(",
"new",
"MessagesCollector",
"(",
")",
")",
";",
"}",
"/**---------------------------------------------------------\n * time\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'time'",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"addCollector",
"(",
"new",
"TimeDataCollector",
"(",
")",
")",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isLumen",
"(",
")",
")",
"{",
"$",
"this",
"->",
"app",
"->",
"booted",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"debugbar",
")",
"{",
"$",
"startTime",
"=",
"$",
"this",
"->",
"app",
"[",
"'request'",
"]",
"->",
"server",
"(",
"'REQUEST_TIME_FLOAT'",
")",
";",
"if",
"(",
"$",
"startTime",
")",
"{",
"$",
"debugbar",
"[",
"'time'",
"]",
"->",
"addMeasure",
"(",
"'Booting'",
",",
"$",
"startTime",
",",
"microtime",
"(",
"true",
")",
")",
";",
"}",
"}",
")",
";",
"}",
"$",
"debugbar",
"->",
"startMeasure",
"(",
"'application'",
",",
"'Application'",
")",
";",
"}",
"/**---------------------------------------------------------\n * memory\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'memory'",
",",
"true",
")",
")",
"{",
"$",
"this",
"->",
"addCollector",
"(",
"new",
"MemoryCollector",
"(",
")",
")",
";",
"}",
"/**---------------------------------------------------------\n * exceptions\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'exceptions'",
",",
"true",
")",
")",
"{",
"try",
"{",
"$",
"exceptionCollector",
"=",
"new",
"ExceptionsCollector",
"(",
")",
";",
"$",
"exceptionCollector",
"->",
"setChainExceptions",
"(",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'songshenzong-log.options.exceptions.chain'",
",",
"true",
")",
")",
";",
"$",
"this",
"->",
"addCollector",
"(",
"$",
"exceptionCollector",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"}",
"}",
"/**---------------------------------------------------------\n * laravel\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'laravel'",
",",
"false",
")",
")",
"{",
"$",
"this",
"->",
"addCollector",
"(",
"new",
"LaravelCollector",
"(",
"$",
"this",
"->",
"app",
")",
")",
";",
"}",
"/**---------------------------------------------------------\n * All events fired\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'events'",
",",
"false",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"app",
"[",
"'events'",
"]",
")",
")",
"{",
"try",
"{",
"$",
"startTime",
"=",
"$",
"this",
"->",
"app",
"[",
"'request'",
"]",
"->",
"server",
"(",
"'REQUEST_TIME_FLOAT'",
")",
";",
"$",
"eventCollector",
"=",
"new",
"EventCollector",
"(",
"$",
"startTime",
")",
";",
"$",
"this",
"->",
"addCollector",
"(",
"$",
"eventCollector",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'events'",
"]",
"->",
"subscribe",
"(",
"$",
"eventCollector",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addThrowable",
"(",
"new",
"Exception",
"(",
"'Cannot add EventCollector to SongshenzongLog: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
")",
";",
"}",
"}",
"/**---------------------------------------------------------\n * Views with their data\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'views'",
",",
"true",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"app",
"[",
"'events'",
"]",
")",
")",
"{",
"try",
"{",
"$",
"collectData",
"=",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'songshenzong-log.options.views.data'",
",",
"true",
")",
";",
"$",
"this",
"->",
"addCollector",
"(",
"new",
"ViewCollector",
"(",
"$",
"collectData",
")",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'events'",
"]",
"->",
"listen",
"(",
"'composing:*'",
",",
"function",
"(",
"$",
"view",
",",
"$",
"data",
"=",
"[",
"]",
")",
"use",
"(",
"$",
"debugbar",
")",
"{",
"if",
"(",
"$",
"data",
")",
"{",
"$",
"view",
"=",
"$",
"data",
"[",
"0",
"]",
";",
"// For Laravel >= 5.4",
"}",
"$",
"debugbar",
"[",
"'views'",
"]",
"->",
"addView",
"(",
"$",
"view",
")",
";",
"}",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addThrowable",
"(",
"new",
"Exception",
"(",
"'Cannot add ViewCollector to SongshenzongLog: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
")",
";",
"}",
"}",
"/**---------------------------------------------------------\n * Current route information\n *---------------------------------------------------------*/",
"if",
"(",
"!",
"$",
"this",
"->",
"isLumen",
"(",
")",
"&&",
"$",
"this",
"->",
"shouldCollect",
"(",
"'route'",
")",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"addCollector",
"(",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'Songshenzong\\Log\\DataCollector\\IlluminateRouteCollector'",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addThrowable",
"(",
"new",
"Exception",
"(",
"'Cannot add RouteCollector to SongshenzongLog: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
")",
";",
"}",
"}",
"/**---------------------------------------------------------\n * Logs from Mongolog (merged in messages if enabled)\n *---------------------------------------------------------*/",
"if",
"(",
"!",
"$",
"this",
"->",
"isLumen",
"(",
")",
"&&",
"$",
"this",
"->",
"shouldCollect",
"(",
"'log'",
",",
"true",
")",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"hasCollector",
"(",
"'messages'",
")",
")",
"{",
"$",
"logger",
"=",
"new",
"MessagesCollector",
"(",
"'log'",
")",
";",
"$",
"this",
"[",
"'messages'",
"]",
"->",
"aggregate",
"(",
"$",
"logger",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'log'",
"]",
"->",
"listen",
"(",
"function",
"(",
"$",
"level",
",",
"$",
"message",
"=",
"null",
",",
"$",
"context",
"=",
"null",
")",
"use",
"(",
"$",
"logger",
")",
"{",
"// Laravel 5.4 changed how the global log listeners are called. We must account for",
"// the first argument being an \"event object\", where arguments are passed",
"// via object properties, instead of individual arguments.",
"if",
"(",
"$",
"level",
"instanceof",
"\\",
"Illuminate",
"\\",
"Log",
"\\",
"Events",
"\\",
"MessageLogged",
")",
"{",
"$",
"message",
"=",
"$",
"level",
"->",
"message",
";",
"$",
"context",
"=",
"$",
"level",
"->",
"context",
";",
"$",
"level",
"=",
"$",
"level",
"->",
"level",
";",
"}",
"try",
"{",
"$",
"logMessage",
"=",
"(",
"string",
")",
"$",
"message",
";",
"if",
"(",
"mb_check_encoding",
"(",
"$",
"logMessage",
",",
"'UTF-8'",
")",
")",
"{",
"$",
"logMessage",
".=",
"(",
"!",
"empty",
"(",
"$",
"context",
")",
"?",
"' '",
".",
"json_encode",
"(",
"$",
"context",
")",
":",
"''",
")",
";",
"}",
"else",
"{",
"$",
"logMessage",
"=",
"'[INVALID UTF-8 DATA]'",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"logMessage",
"=",
"'[Exception: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
".",
"']'",
";",
"}",
"$",
"logger",
"->",
"addMessage",
"(",
"'['",
".",
"date",
"(",
"'H:i:s'",
")",
".",
"'] '",
".",
"\"LOG.$level: \"",
".",
"$",
"logMessage",
",",
"$",
"level",
",",
"false",
")",
";",
"}",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"addCollector",
"(",
"new",
"MonologCollector",
"(",
"$",
"this",
"->",
"app",
"[",
"'log'",
"]",
"->",
"getMonolog",
"(",
")",
")",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addThrowable",
"(",
"new",
"Exception",
"(",
"'Cannot add LogsCollector to SongshenzongLog: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
")",
";",
"}",
"}",
"/**---------------------------------------------------------\n * Show database (PDO) queries and bindings\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'db'",
",",
"true",
")",
"&&",
"isset",
"(",
"$",
"this",
"->",
"app",
"[",
"'db'",
"]",
")",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"app",
"[",
"'db'",
"]",
";",
"if",
"(",
"$",
"debugbar",
"->",
"hasCollector",
"(",
"'time'",
")",
"&&",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'songshenzong-log.options.db.timeline'",
",",
"false",
")",
")",
"{",
"$",
"timeCollector",
"=",
"$",
"debugbar",
"->",
"getCollector",
"(",
"'time'",
")",
";",
"}",
"else",
"{",
"$",
"timeCollector",
"=",
"null",
";",
"}",
"$",
"queryCollector",
"=",
"new",
"QueryCollector",
"(",
"$",
"timeCollector",
")",
";",
"$",
"queryCollector",
"->",
"setDataFormatter",
"(",
"new",
"QueryFormatter",
"(",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'songshenzong-log.options.db.with_params'",
")",
")",
"{",
"$",
"queryCollector",
"->",
"setRenderSqlWithParams",
"(",
"true",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'songshenzong-log.options.db.backtrace'",
")",
")",
"{",
"$",
"middleware",
"=",
"!",
"$",
"this",
"->",
"is_lumen",
"?",
"$",
"this",
"->",
"app",
"[",
"'router'",
"]",
"->",
"getMiddleware",
"(",
")",
":",
"[",
"]",
";",
"$",
"queryCollector",
"->",
"setFindSource",
"(",
"true",
",",
"$",
"middleware",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'songshenzong-log.options.db.explain.enabled'",
")",
")",
"{",
"$",
"types",
"=",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'songshenzong-log.options.db.explain.types'",
")",
";",
"$",
"queryCollector",
"->",
"setExplainSource",
"(",
"true",
",",
"$",
"types",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'songshenzong-log.options.db.hints'",
",",
"true",
")",
")",
"{",
"$",
"queryCollector",
"->",
"setShowHints",
"(",
"true",
")",
";",
"}",
"$",
"this",
"->",
"addCollector",
"(",
"$",
"queryCollector",
")",
";",
"try",
"{",
"$",
"db",
"->",
"listen",
"(",
"function",
"(",
"$",
"query",
",",
"$",
"bindings",
"=",
"null",
",",
"$",
"time",
"=",
"null",
",",
"$",
"connectionName",
"=",
"null",
")",
"use",
"(",
"$",
"db",
",",
"$",
"queryCollector",
")",
"{",
"// Laravel 5.2 changed the way some core events worked. We must account for",
"// the first argument being an \"event object\", where arguments are passed",
"// via object properties, instead of individual arguments.",
"if",
"(",
"$",
"query",
"instanceof",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Events",
"\\",
"QueryExecuted",
")",
"{",
"$",
"bindings",
"=",
"$",
"query",
"->",
"bindings",
";",
"$",
"time",
"=",
"$",
"query",
"->",
"time",
";",
"$",
"connection",
"=",
"$",
"query",
"->",
"connection",
";",
"$",
"query",
"=",
"$",
"query",
"->",
"sql",
";",
"}",
"else",
"{",
"$",
"connection",
"=",
"$",
"db",
"->",
"connection",
"(",
"$",
"connectionName",
")",
";",
"}",
"$",
"queryCollector",
"->",
"addQuery",
"(",
"(",
"string",
")",
"$",
"query",
",",
"$",
"bindings",
",",
"$",
"time",
",",
"$",
"connection",
")",
";",
"}",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addThrowable",
"(",
"new",
"Exception",
"(",
"'Cannot add listen to Queries for Songshenzong: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
")",
";",
"}",
"try",
"{",
"$",
"db",
"->",
"getEventDispatcher",
"(",
")",
"->",
"listen",
"(",
"[",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Events",
"\\",
"TransactionBeginning",
"::",
"class",
",",
"'connection.*.beganTransaction'",
",",
"]",
",",
"function",
"(",
"$",
"transaction",
")",
"use",
"(",
"$",
"queryCollector",
")",
"{",
"$",
"queryCollector",
"->",
"collectTransactionEvent",
"(",
"'Begin Transaction'",
",",
"$",
"transaction",
"->",
"connection",
")",
";",
"}",
")",
";",
"$",
"db",
"->",
"getEventDispatcher",
"(",
")",
"->",
"listen",
"(",
"[",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Events",
"\\",
"TransactionCommitted",
"::",
"class",
",",
"'connection.*.committed'",
",",
"]",
",",
"function",
"(",
"$",
"transaction",
")",
"use",
"(",
"$",
"queryCollector",
")",
"{",
"$",
"queryCollector",
"->",
"collectTransactionEvent",
"(",
"'Commit Transaction'",
",",
"$",
"transaction",
"->",
"connection",
")",
";",
"}",
")",
";",
"$",
"db",
"->",
"getEventDispatcher",
"(",
")",
"->",
"listen",
"(",
"[",
"\\",
"Illuminate",
"\\",
"Database",
"\\",
"Events",
"\\",
"TransactionRolledBack",
"::",
"class",
",",
"'connection.*.rollingBack'",
",",
"]",
",",
"function",
"(",
"$",
"transaction",
")",
"use",
"(",
"$",
"queryCollector",
")",
"{",
"$",
"queryCollector",
"->",
"collectTransactionEvent",
"(",
"'Rollback Transaction'",
",",
"$",
"transaction",
"->",
"connection",
")",
";",
"}",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addThrowable",
"(",
"new",
"Exception",
"(",
"'Cannot add listen transactions to Queries for Songshenzong: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
")",
";",
"}",
"}",
"/**---------------------------------------------------------\n * Catch mail messages\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'mail'",
",",
"true",
")",
"&&",
"class_exists",
"(",
"'Illuminate\\Mail\\MailServiceProvider'",
")",
")",
"{",
"try",
"{",
"$",
"mailer",
"=",
"$",
"this",
"->",
"app",
"[",
"'mailer'",
"]",
"->",
"getSwiftMailer",
"(",
")",
";",
"$",
"this",
"->",
"addCollector",
"(",
"new",
"SwiftMailCollector",
"(",
"$",
"mailer",
")",
")",
";",
"if",
"(",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'songshenzong-log.options.mail.full_log'",
")",
"&&",
"$",
"this",
"->",
"hasCollector",
"(",
"'messages'",
")",
")",
"{",
"$",
"this",
"[",
"'messages'",
"]",
"->",
"aggregate",
"(",
"new",
"SwiftLogCollector",
"(",
"$",
"mailer",
")",
")",
";",
"}",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addThrowable",
"(",
"new",
"Exception",
"(",
"'Cannot add MailCollector to SongshenzongLog: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
")",
";",
"}",
"}",
"/**---------------------------------------------------------\n * Add the latest log messages\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'logs'",
",",
"false",
")",
")",
"{",
"try",
"{",
"$",
"file",
"=",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'songshenzong-log.options.logs.file'",
")",
";",
"$",
"this",
"->",
"addCollector",
"(",
"new",
"LogsCollector",
"(",
"$",
"file",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addThrowable",
"(",
"new",
"Exception",
"(",
"'Cannot add LogsCollector to SongshenzongLog: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
")",
";",
"}",
"}",
"/**---------------------------------------------------------\n * Show the included files\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'files'",
",",
"false",
")",
")",
"{",
"$",
"this",
"->",
"addCollector",
"(",
"new",
"FilesCollector",
"(",
"$",
"app",
")",
")",
";",
"}",
"/**---------------------------------------------------------\n * Display Laravel authentication status\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'auth'",
",",
"false",
")",
")",
"{",
"try",
"{",
"if",
"(",
"$",
"this",
"->",
"checkVersion",
"(",
"'5.2'",
")",
")",
"{",
"// fix for compatibility with Laravel 5.2.*",
"$",
"guards",
"=",
"array_keys",
"(",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'auth.guards'",
")",
")",
";",
"$",
"authCollector",
"=",
"new",
"MultiAuthCollector",
"(",
"$",
"app",
"[",
"'auth'",
"]",
",",
"$",
"guards",
")",
";",
"}",
"else",
"{",
"$",
"authCollector",
"=",
"new",
"AuthCollector",
"(",
"$",
"app",
"[",
"'auth'",
"]",
")",
";",
"}",
"$",
"authCollector",
"->",
"setShowName",
"(",
"$",
"this",
"->",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'songshenzong-log.options.auth.show_name'",
")",
")",
";",
"$",
"this",
"->",
"addCollector",
"(",
"$",
"authCollector",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addThrowable",
"(",
"new",
"Exception",
"(",
"'Cannot add AuthCollector to SongshenzongLog: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
")",
";",
"}",
"}",
"/**---------------------------------------------------------\n * Display Laravel Gate checks\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'gate'",
",",
"false",
")",
")",
"{",
"try",
"{",
"$",
"gateCollector",
"=",
"$",
"this",
"->",
"app",
"->",
"make",
"(",
"'Songshenzong\\Log\\DataCollector\\GateCollector'",
")",
";",
"$",
"this",
"->",
"addCollector",
"(",
"$",
"gateCollector",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// No Gate collector",
"}",
"}",
"$",
"this",
"->",
"booted",
"=",
"true",
";",
"}"
] | Boot (add collectors, renderer and listener) | [
"Boot",
"(",
"add",
"collectors",
"renderer",
"and",
"listener",
")"
] | train | https://github.com/songshenzong/log/blob/b1e01f7994da47737866eabf82367490eab17c46/src/LaravelDebugbar.php#L125-L517 |
songshenzong/log | src/LaravelDebugbar.php | LaravelDebugbar.startMeasure | public function startMeasure($name, $label = null)
{
if ($this->hasCollector('time')) {
/** @var \Songshenzong\Log\DataCollector\TimeDataCollector $collector */
$collector = $this->getCollector('time');
$collector->startMeasure($name, $label);
}
} | php | public function startMeasure($name, $label = null)
{
if ($this->hasCollector('time')) {
/** @var \Songshenzong\Log\DataCollector\TimeDataCollector $collector */
$collector = $this->getCollector('time');
$collector->startMeasure($name, $label);
}
} | [
"public",
"function",
"startMeasure",
"(",
"$",
"name",
",",
"$",
"label",
"=",
"null",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasCollector",
"(",
"'time'",
")",
")",
"{",
"/** @var \\Songshenzong\\Log\\DataCollector\\TimeDataCollector $collector */",
"$",
"collector",
"=",
"$",
"this",
"->",
"getCollector",
"(",
"'time'",
")",
";",
"$",
"collector",
"->",
"startMeasure",
"(",
"$",
"name",
",",
"$",
"label",
")",
";",
"}",
"}"
] | Starts a measure
@param string $name Internal name, used to stop the measure
@param string $label Public name
@throws DebugBarException | [
"Starts",
"a",
"measure"
] | train | https://github.com/songshenzong/log/blob/b1e01f7994da47737866eabf82367490eab17c46/src/LaravelDebugbar.php#L559-L566 |
songshenzong/log | src/LaravelDebugbar.php | LaravelDebugbar.stopMeasure | public function stopMeasure($name)
{
if ($this->hasCollector('time')) {
/** @var \Songshenzong\Log\DataCollector\TimeDataCollector $collector */
$collector = $this->getCollector('time');
try {
$collector->stopMeasure($name);
} catch (\Exception $e) {
// $this->addThrowable($e);
}
}
} | php | public function stopMeasure($name)
{
if ($this->hasCollector('time')) {
/** @var \Songshenzong\Log\DataCollector\TimeDataCollector $collector */
$collector = $this->getCollector('time');
try {
$collector->stopMeasure($name);
} catch (\Exception $e) {
// $this->addThrowable($e);
}
}
} | [
"public",
"function",
"stopMeasure",
"(",
"$",
"name",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"hasCollector",
"(",
"'time'",
")",
")",
"{",
"/** @var \\Songshenzong\\Log\\DataCollector\\TimeDataCollector $collector */",
"$",
"collector",
"=",
"$",
"this",
"->",
"getCollector",
"(",
"'time'",
")",
";",
"try",
"{",
"$",
"collector",
"->",
"stopMeasure",
"(",
"$",
"name",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"// $this->addThrowable($e);",
"}",
"}",
"}"
] | Stops a measure
@param string $name
@throws DebugBarException | [
"Stops",
"a",
"measure"
] | train | https://github.com/songshenzong/log/blob/b1e01f7994da47737866eabf82367490eab17c46/src/LaravelDebugbar.php#L575-L586 |
songshenzong/log | src/LaravelDebugbar.php | LaravelDebugbar.modifyResponse | public function modifyResponse(Request $request, Response $response)
{
if ($this->isCollect() === false) {
return;
}
// if ($this -> created) {
// return;
// }
$app = $this->app;
if ($app->runningInConsole() || !$this->isEnabled() || $this->isMyselfRequest()) {
return $response;
}
// Show the Http Response Exception, when available
if (isset($response->exception)) {
$this->addThrowable($response->exception);
}
/**---------------------------------------------------------
* Display config settings
*---------------------------------------------------------*/
if ($this->shouldCollect('config', false)) {
try {
$configCollector = new ConfigCollector();
$configCollector->setData($app['config']->all());
$this->addCollector($configCollector);
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add ConfigCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
if ($this->app->bound(SessionManager::class)) {
/** @var \Illuminate\Session\SessionManager $sessionManager */
$sessionManager = $app->make(SessionManager::class);
$httpDriver = new SymfonyHttpDriver($sessionManager, $response);
$this->setHttpDriver($httpDriver);
if ($this->shouldCollect('session') && !$this->hasCollector('session')) {
try {
$this->addCollector(new SessionCollector($sessionManager));
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add SessionCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
} else {
$sessionManager = null;
}
/**---------------------------------------------------------
* Only one can be enabled.
*---------------------------------------------------------*/
if ($this->shouldCollect('request', true) && !$this->hasCollector('request')) {
try {
$this->addCollector(new RequestCollector($request, $response, $sessionManager));
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add RequestCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Just collect + store data
*---------------------------------------------------------*/
try {
$this->collect();
} catch (\Exception $e) {
$app['log']->error('Songshenzong exception: ' . $e->getMessage());
}
return $response;
} | php | public function modifyResponse(Request $request, Response $response)
{
if ($this->isCollect() === false) {
return;
}
// if ($this -> created) {
// return;
// }
$app = $this->app;
if ($app->runningInConsole() || !$this->isEnabled() || $this->isMyselfRequest()) {
return $response;
}
// Show the Http Response Exception, when available
if (isset($response->exception)) {
$this->addThrowable($response->exception);
}
/**---------------------------------------------------------
* Display config settings
*---------------------------------------------------------*/
if ($this->shouldCollect('config', false)) {
try {
$configCollector = new ConfigCollector();
$configCollector->setData($app['config']->all());
$this->addCollector($configCollector);
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add ConfigCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
if ($this->app->bound(SessionManager::class)) {
/** @var \Illuminate\Session\SessionManager $sessionManager */
$sessionManager = $app->make(SessionManager::class);
$httpDriver = new SymfonyHttpDriver($sessionManager, $response);
$this->setHttpDriver($httpDriver);
if ($this->shouldCollect('session') && !$this->hasCollector('session')) {
try {
$this->addCollector(new SessionCollector($sessionManager));
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add SessionCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
} else {
$sessionManager = null;
}
/**---------------------------------------------------------
* Only one can be enabled.
*---------------------------------------------------------*/
if ($this->shouldCollect('request', true) && !$this->hasCollector('request')) {
try {
$this->addCollector(new RequestCollector($request, $response, $sessionManager));
} catch (\Exception $e) {
$this->addThrowable(
new Exception(
'Cannot add RequestCollector to SongshenzongLog: ' . $e->getMessage(),
$e->getCode(),
$e
)
);
}
}
/**---------------------------------------------------------
* Just collect + store data
*---------------------------------------------------------*/
try {
$this->collect();
} catch (\Exception $e) {
$app['log']->error('Songshenzong exception: ' . $e->getMessage());
}
return $response;
} | [
"public",
"function",
"modifyResponse",
"(",
"Request",
"$",
"request",
",",
"Response",
"$",
"response",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isCollect",
"(",
")",
"===",
"false",
")",
"{",
"return",
";",
"}",
"// if ($this -> created) {",
"// return;",
"// }",
"$",
"app",
"=",
"$",
"this",
"->",
"app",
";",
"if",
"(",
"$",
"app",
"->",
"runningInConsole",
"(",
")",
"||",
"!",
"$",
"this",
"->",
"isEnabled",
"(",
")",
"||",
"$",
"this",
"->",
"isMyselfRequest",
"(",
")",
")",
"{",
"return",
"$",
"response",
";",
"}",
"// Show the Http Response Exception, when available",
"if",
"(",
"isset",
"(",
"$",
"response",
"->",
"exception",
")",
")",
"{",
"$",
"this",
"->",
"addThrowable",
"(",
"$",
"response",
"->",
"exception",
")",
";",
"}",
"/**---------------------------------------------------------\n * Display config settings\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'config'",
",",
"false",
")",
")",
"{",
"try",
"{",
"$",
"configCollector",
"=",
"new",
"ConfigCollector",
"(",
")",
";",
"$",
"configCollector",
"->",
"setData",
"(",
"$",
"app",
"[",
"'config'",
"]",
"->",
"all",
"(",
")",
")",
";",
"$",
"this",
"->",
"addCollector",
"(",
"$",
"configCollector",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addThrowable",
"(",
"new",
"Exception",
"(",
"'Cannot add ConfigCollector to SongshenzongLog: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"app",
"->",
"bound",
"(",
"SessionManager",
"::",
"class",
")",
")",
"{",
"/** @var \\Illuminate\\Session\\SessionManager $sessionManager */",
"$",
"sessionManager",
"=",
"$",
"app",
"->",
"make",
"(",
"SessionManager",
"::",
"class",
")",
";",
"$",
"httpDriver",
"=",
"new",
"SymfonyHttpDriver",
"(",
"$",
"sessionManager",
",",
"$",
"response",
")",
";",
"$",
"this",
"->",
"setHttpDriver",
"(",
"$",
"httpDriver",
")",
";",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'session'",
")",
"&&",
"!",
"$",
"this",
"->",
"hasCollector",
"(",
"'session'",
")",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"addCollector",
"(",
"new",
"SessionCollector",
"(",
"$",
"sessionManager",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addThrowable",
"(",
"new",
"Exception",
"(",
"'Cannot add SessionCollector to SongshenzongLog: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
")",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"sessionManager",
"=",
"null",
";",
"}",
"/**---------------------------------------------------------\n * Only one can be enabled.\n *---------------------------------------------------------*/",
"if",
"(",
"$",
"this",
"->",
"shouldCollect",
"(",
"'request'",
",",
"true",
")",
"&&",
"!",
"$",
"this",
"->",
"hasCollector",
"(",
"'request'",
")",
")",
"{",
"try",
"{",
"$",
"this",
"->",
"addCollector",
"(",
"new",
"RequestCollector",
"(",
"$",
"request",
",",
"$",
"response",
",",
"$",
"sessionManager",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"addThrowable",
"(",
"new",
"Exception",
"(",
"'Cannot add RequestCollector to SongshenzongLog: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
")",
";",
"}",
"}",
"/**---------------------------------------------------------\n * Just collect + store data\n *---------------------------------------------------------*/",
"try",
"{",
"$",
"this",
"->",
"collect",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"app",
"[",
"'log'",
"]",
"->",
"error",
"(",
"'Songshenzong exception: '",
".",
"$",
"e",
"->",
"getMessage",
"(",
")",
")",
";",
"}",
"return",
"$",
"response",
";",
"}"
] | Modify the response and inject (or data in headers)
@param \Symfony\Component\HttpFoundation\Request $request
@param \Symfony\Component\HttpFoundation\Response $response
@return Response
@throws DebugBarException | [
"Modify",
"the",
"response",
"and",
"inject",
"(",
"or",
"data",
"in",
"headers",
")"
] | train | https://github.com/songshenzong/log/blob/b1e01f7994da47737866eabf82367490eab17c46/src/LaravelDebugbar.php#L627-L724 |
songshenzong/log | src/LaravelDebugbar.php | LaravelDebugbar.collect | public function collect()
{
$request = app('request');
$this->meta = [
'time' => microtime(true),
'method' => $request->getMethod(),
'uri' => $request->getRequestUri(),
'ip' => $request->getClientIp(),
];
foreach ($this->collectors as $name => $collector) {
$this->data[$name] = $collector->collect();
}
// Remove all invalid (non UTF-8) characters
array_walk_recursive(
$this->data,
function (&$item) {
if (is_string($item) && !mb_check_encoding($item, 'UTF-8')) {
$item = mb_convert_encoding($item, 'UTF-8', 'UTF-8');
}
}
);
$this->persistData();
return $this->data;
} | php | public function collect()
{
$request = app('request');
$this->meta = [
'time' => microtime(true),
'method' => $request->getMethod(),
'uri' => $request->getRequestUri(),
'ip' => $request->getClientIp(),
];
foreach ($this->collectors as $name => $collector) {
$this->data[$name] = $collector->collect();
}
// Remove all invalid (non UTF-8) characters
array_walk_recursive(
$this->data,
function (&$item) {
if (is_string($item) && !mb_check_encoding($item, 'UTF-8')) {
$item = mb_convert_encoding($item, 'UTF-8', 'UTF-8');
}
}
);
$this->persistData();
return $this->data;
} | [
"public",
"function",
"collect",
"(",
")",
"{",
"$",
"request",
"=",
"app",
"(",
"'request'",
")",
";",
"$",
"this",
"->",
"meta",
"=",
"[",
"'time'",
"=>",
"microtime",
"(",
"true",
")",
",",
"'method'",
"=>",
"$",
"request",
"->",
"getMethod",
"(",
")",
",",
"'uri'",
"=>",
"$",
"request",
"->",
"getRequestUri",
"(",
")",
",",
"'ip'",
"=>",
"$",
"request",
"->",
"getClientIp",
"(",
")",
",",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"collectors",
"as",
"$",
"name",
"=>",
"$",
"collector",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
"=",
"$",
"collector",
"->",
"collect",
"(",
")",
";",
"}",
"// Remove all invalid (non UTF-8) characters",
"array_walk_recursive",
"(",
"$",
"this",
"->",
"data",
",",
"function",
"(",
"&",
"$",
"item",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"item",
")",
"&&",
"!",
"mb_check_encoding",
"(",
"$",
"item",
",",
"'UTF-8'",
")",
")",
"{",
"$",
"item",
"=",
"mb_convert_encoding",
"(",
"$",
"item",
",",
"'UTF-8'",
",",
"'UTF-8'",
")",
";",
"}",
"}",
")",
";",
"$",
"this",
"->",
"persistData",
"(",
")",
";",
"return",
"$",
"this",
"->",
"data",
";",
"}"
] | Collects the data from the collectors
@return array | [
"Collects",
"the",
"data",
"from",
"the",
"collectors"
] | train | https://github.com/songshenzong/log/blob/b1e01f7994da47737866eabf82367490eab17c46/src/LaravelDebugbar.php#L759-L789 |
songshenzong/log | src/LaravelDebugbar.php | LaravelDebugbar.collectConsole | public function collectConsole()
{
if (!$this->isEnabled()) {
return;
}
$this->meta = [
'time' => microtime(true),
'method' => 'CLI',
'uri' => isset($_SERVER['argv']) ? implode(' ', $_SERVER['argv']) : null,
'ip' => isset($_SERVER['SSH_CLIENT']) ? $_SERVER['SSH_CLIENT'] : null,
];
foreach ($this->collectors as $name => $collector) {
$this->data[$name] = $collector->collect();
}
// Remove all invalid (non UTF-8) characters
array_walk_recursive(
$this->data,
function (&$item) {
if (is_string($item) && !mb_check_encoding($item, 'UTF-8')) {
$item = mb_convert_encoding($item, 'UTF-8', 'UTF-8');
}
}
);
$this->persistData();
return $this->data;
} | php | public function collectConsole()
{
if (!$this->isEnabled()) {
return;
}
$this->meta = [
'time' => microtime(true),
'method' => 'CLI',
'uri' => isset($_SERVER['argv']) ? implode(' ', $_SERVER['argv']) : null,
'ip' => isset($_SERVER['SSH_CLIENT']) ? $_SERVER['SSH_CLIENT'] : null,
];
foreach ($this->collectors as $name => $collector) {
$this->data[$name] = $collector->collect();
}
// Remove all invalid (non UTF-8) characters
array_walk_recursive(
$this->data,
function (&$item) {
if (is_string($item) && !mb_check_encoding($item, 'UTF-8')) {
$item = mb_convert_encoding($item, 'UTF-8', 'UTF-8');
}
}
);
$this->persistData();
return $this->data;
} | [
"public",
"function",
"collectConsole",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"isEnabled",
"(",
")",
")",
"{",
"return",
";",
"}",
"$",
"this",
"->",
"meta",
"=",
"[",
"'time'",
"=>",
"microtime",
"(",
"true",
")",
",",
"'method'",
"=>",
"'CLI'",
",",
"'uri'",
"=>",
"isset",
"(",
"$",
"_SERVER",
"[",
"'argv'",
"]",
")",
"?",
"implode",
"(",
"' '",
",",
"$",
"_SERVER",
"[",
"'argv'",
"]",
")",
":",
"null",
",",
"'ip'",
"=>",
"isset",
"(",
"$",
"_SERVER",
"[",
"'SSH_CLIENT'",
"]",
")",
"?",
"$",
"_SERVER",
"[",
"'SSH_CLIENT'",
"]",
":",
"null",
",",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"collectors",
"as",
"$",
"name",
"=>",
"$",
"collector",
")",
"{",
"$",
"this",
"->",
"data",
"[",
"$",
"name",
"]",
"=",
"$",
"collector",
"->",
"collect",
"(",
")",
";",
"}",
"// Remove all invalid (non UTF-8) characters",
"array_walk_recursive",
"(",
"$",
"this",
"->",
"data",
",",
"function",
"(",
"&",
"$",
"item",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"item",
")",
"&&",
"!",
"mb_check_encoding",
"(",
"$",
"item",
",",
"'UTF-8'",
")",
")",
"{",
"$",
"item",
"=",
"mb_convert_encoding",
"(",
"$",
"item",
",",
"'UTF-8'",
",",
"'UTF-8'",
")",
";",
"}",
"}",
")",
";",
"$",
"this",
"->",
"persistData",
"(",
")",
";",
"return",
"$",
"this",
"->",
"data",
";",
"}"
] | Collect data in a CLI request
@return array | [
"Collect",
"data",
"in",
"a",
"CLI",
"request"
] | train | https://github.com/songshenzong/log/blob/b1e01f7994da47737866eabf82367490eab17c46/src/LaravelDebugbar.php#L797-L830 |
songshenzong/log | src/LaravelDebugbar.php | LaravelDebugbar.json | public function json($status_code, $message, $data = null)
{
return response()->json([
'status_code' => $status_code,
'message' => $message,
'data' => $data,
'request' => \request()->all(),
]);
} | php | public function json($status_code, $message, $data = null)
{
return response()->json([
'status_code' => $status_code,
'message' => $message,
'data' => $data,
'request' => \request()->all(),
]);
} | [
"public",
"function",
"json",
"(",
"$",
"status_code",
",",
"$",
"message",
",",
"$",
"data",
"=",
"null",
")",
"{",
"return",
"response",
"(",
")",
"->",
"json",
"(",
"[",
"'status_code'",
"=>",
"$",
"status_code",
",",
"'message'",
"=>",
"$",
"message",
",",
"'data'",
"=>",
"$",
"data",
",",
"'request'",
"=>",
"\\",
"request",
"(",
")",
"->",
"all",
"(",
")",
",",
"]",
")",
";",
"}"
] | Basic Json method.
@param $status_code
@param $message
@param null $data
@return mixed | [
"Basic",
"Json",
"method",
"."
] | train | https://github.com/songshenzong/log/blob/b1e01f7994da47737866eabf82367490eab17c46/src/LaravelDebugbar.php#L969-L977 |
old-town/workflow-designer-server | src/View/WorkflowDescriptorApiModel.php | WorkflowDescriptorApiModel.__isset | public function __isset($name)
{
$variables = $this->getVariables();
$method = 'get' . ucfirst($name);
$flag = method_exists($variables, $method);
return $flag;
} | php | public function __isset($name)
{
$variables = $this->getVariables();
$method = 'get' . ucfirst($name);
$flag = method_exists($variables, $method);
return $flag;
} | [
"public",
"function",
"__isset",
"(",
"$",
"name",
")",
"{",
"$",
"variables",
"=",
"$",
"this",
"->",
"getVariables",
"(",
")",
";",
"$",
"method",
"=",
"'get'",
".",
"ucfirst",
"(",
"$",
"name",
")",
";",
"$",
"flag",
"=",
"method_exists",
"(",
"$",
"variables",
",",
"$",
"method",
")",
";",
"return",
"$",
"flag",
";",
"}"
] | Property overloading: do we have the requested variable value?
@param string $name
@return bool | [
"Property",
"overloading",
":",
"do",
"we",
"have",
"the",
"requested",
"variable",
"value?"
] | train | https://github.com/old-town/workflow-designer-server/blob/6389c5a515861cc8e0b769f1ca7be12c6b78c611/src/View/WorkflowDescriptorApiModel.php#L68-L76 |
tequila/mongodb-odm | src/BulkWriteBuilderFactory.php | BulkWriteBuilderFactory.getBulkWriteBuilder | public function getBulkWriteBuilder(DocumentManager $documentManager, string $collectionName)
{
if (!array_key_exists($collectionName, $this->builders)) {
$this->builders[$collectionName] = new BulkWriteBuilder($documentManager, $collectionName);
}
return $this->builders[$collectionName];
} | php | public function getBulkWriteBuilder(DocumentManager $documentManager, string $collectionName)
{
if (!array_key_exists($collectionName, $this->builders)) {
$this->builders[$collectionName] = new BulkWriteBuilder($documentManager, $collectionName);
}
return $this->builders[$collectionName];
} | [
"public",
"function",
"getBulkWriteBuilder",
"(",
"DocumentManager",
"$",
"documentManager",
",",
"string",
"$",
"collectionName",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"collectionName",
",",
"$",
"this",
"->",
"builders",
")",
")",
"{",
"$",
"this",
"->",
"builders",
"[",
"$",
"collectionName",
"]",
"=",
"new",
"BulkWriteBuilder",
"(",
"$",
"documentManager",
",",
"$",
"collectionName",
")",
";",
"}",
"return",
"$",
"this",
"->",
"builders",
"[",
"$",
"collectionName",
"]",
";",
"}"
] | @param DocumentManager $documentManager
@param string $collectionName
@return BulkWriteBuilder | [
"@param",
"DocumentManager",
"$documentManager",
"@param",
"string",
"$collectionName"
] | train | https://github.com/tequila/mongodb-odm/blob/501d58529bbcb23ad7839680462f62d5c3466d23/src/BulkWriteBuilderFactory.php#L18-L25 |
novaway/open-graph | src/Metadata/Driver/YamlDriver.php | YamlDriver.loadMetadataFromFile | protected function loadMetadataFromFile(\ReflectionClass $class, $file)
{
$name = $class->name;
$config = Yaml::parse(file_get_contents($file));
if (!isset($config[$name])) {
throw new \RuntimeException(sprintf('Expected metadata for class %s to be defined in %s.', $class->name, $file));
}
$config = $config[$name];
$classMetadata = new ClassMetadata($name);
$this->parseNamespaces($classMetadata, $config);
$this->parseNodes($class, $classMetadata, $config);
return $classMetadata;
} | php | protected function loadMetadataFromFile(\ReflectionClass $class, $file)
{
$name = $class->name;
$config = Yaml::parse(file_get_contents($file));
if (!isset($config[$name])) {
throw new \RuntimeException(sprintf('Expected metadata for class %s to be defined in %s.', $class->name, $file));
}
$config = $config[$name];
$classMetadata = new ClassMetadata($name);
$this->parseNamespaces($classMetadata, $config);
$this->parseNodes($class, $classMetadata, $config);
return $classMetadata;
} | [
"protected",
"function",
"loadMetadataFromFile",
"(",
"\\",
"ReflectionClass",
"$",
"class",
",",
"$",
"file",
")",
"{",
"$",
"name",
"=",
"$",
"class",
"->",
"name",
";",
"$",
"config",
"=",
"Yaml",
"::",
"parse",
"(",
"file_get_contents",
"(",
"$",
"file",
")",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"$",
"name",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Expected metadata for class %s to be defined in %s.'",
",",
"$",
"class",
"->",
"name",
",",
"$",
"file",
")",
")",
";",
"}",
"$",
"config",
"=",
"$",
"config",
"[",
"$",
"name",
"]",
";",
"$",
"classMetadata",
"=",
"new",
"ClassMetadata",
"(",
"$",
"name",
")",
";",
"$",
"this",
"->",
"parseNamespaces",
"(",
"$",
"classMetadata",
",",
"$",
"config",
")",
";",
"$",
"this",
"->",
"parseNodes",
"(",
"$",
"class",
",",
"$",
"classMetadata",
",",
"$",
"config",
")",
";",
"return",
"$",
"classMetadata",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/novaway/open-graph/blob/19817bee4b91cf26ca3fe44883ad58b32328e464/src/Metadata/Driver/YamlDriver.php#L18-L35 |
novaway/open-graph | src/Metadata/Driver/YamlDriver.php | YamlDriver.parseNamespaces | protected function parseNamespaces(ClassMetadata $metadata, $config)
{
if (!isset($config['namespaces'])) {
return;
}
if (!is_array($config)) {
throw new \RuntimeException(sprintf('Invalid YAML configuration for "%s" : "namespaces" property need to be an array.', $metadata->name));
}
foreach ($config['namespaces'] as $prefix => $uri) {
$metadata->addGraphNamespace(new NamespaceNode([
'prefix' => $prefix,
'uri' => $uri,
]));
}
} | php | protected function parseNamespaces(ClassMetadata $metadata, $config)
{
if (!isset($config['namespaces'])) {
return;
}
if (!is_array($config)) {
throw new \RuntimeException(sprintf('Invalid YAML configuration for "%s" : "namespaces" property need to be an array.', $metadata->name));
}
foreach ($config['namespaces'] as $prefix => $uri) {
$metadata->addGraphNamespace(new NamespaceNode([
'prefix' => $prefix,
'uri' => $uri,
]));
}
} | [
"protected",
"function",
"parseNamespaces",
"(",
"ClassMetadata",
"$",
"metadata",
",",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'namespaces'",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Invalid YAML configuration for \"%s\" : \"namespaces\" property need to be an array.'",
",",
"$",
"metadata",
"->",
"name",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"config",
"[",
"'namespaces'",
"]",
"as",
"$",
"prefix",
"=>",
"$",
"uri",
")",
"{",
"$",
"metadata",
"->",
"addGraphNamespace",
"(",
"new",
"NamespaceNode",
"(",
"[",
"'prefix'",
"=>",
"$",
"prefix",
",",
"'uri'",
"=>",
"$",
"uri",
",",
"]",
")",
")",
";",
"}",
"}"
] | Parse namespaces configuration
@param ClassMetadata $metadata
@param mixed $config | [
"Parse",
"namespaces",
"configuration"
] | train | https://github.com/novaway/open-graph/blob/19817bee4b91cf26ca3fe44883ad58b32328e464/src/Metadata/Driver/YamlDriver.php#L51-L67 |
novaway/open-graph | src/Metadata/Driver/YamlDriver.php | YamlDriver.parseNodes | protected function parseNodes(\ReflectionClass $class, ClassMetadata $metadata, $config)
{
if (!isset($config['nodes'])) {
return;
}
if (!is_array($config)) {
throw new \RuntimeException(sprintf('Invalid YAML configuration for "%s" : "properties" property need to be an array.', $metadata->name));
}
foreach ($config['nodes'] as $property => $nodeProperties) {
foreach ($nodeProperties as $nodeProperty) {
if (!isset($nodeProperty['namespace']) || !isset($nodeProperty['tag'])) {
throw new \RuntimeException(sprintf('Invalid YAML configuration for "%s" : "namespace" and "tag" are required.', $metadata->name));
}
$node = new Node([
'namespace' => $nodeProperty['namespace'],
'tag' => $nodeProperty['tag'],
]);
if ($class->hasProperty($property)) {
$metadata->addGraphMetadata($node, new PropertyMetadata($class->name, $property));
}
if ($class->hasMethod($property)) {
$metadata->addGraphMetadata($node, new MethodMetadata($class->name, $property));
}
}
}
} | php | protected function parseNodes(\ReflectionClass $class, ClassMetadata $metadata, $config)
{
if (!isset($config['nodes'])) {
return;
}
if (!is_array($config)) {
throw new \RuntimeException(sprintf('Invalid YAML configuration for "%s" : "properties" property need to be an array.', $metadata->name));
}
foreach ($config['nodes'] as $property => $nodeProperties) {
foreach ($nodeProperties as $nodeProperty) {
if (!isset($nodeProperty['namespace']) || !isset($nodeProperty['tag'])) {
throw new \RuntimeException(sprintf('Invalid YAML configuration for "%s" : "namespace" and "tag" are required.', $metadata->name));
}
$node = new Node([
'namespace' => $nodeProperty['namespace'],
'tag' => $nodeProperty['tag'],
]);
if ($class->hasProperty($property)) {
$metadata->addGraphMetadata($node, new PropertyMetadata($class->name, $property));
}
if ($class->hasMethod($property)) {
$metadata->addGraphMetadata($node, new MethodMetadata($class->name, $property));
}
}
}
} | [
"protected",
"function",
"parseNodes",
"(",
"\\",
"ReflectionClass",
"$",
"class",
",",
"ClassMetadata",
"$",
"metadata",
",",
"$",
"config",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'nodes'",
"]",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"config",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Invalid YAML configuration for \"%s\" : \"properties\" property need to be an array.'",
",",
"$",
"metadata",
"->",
"name",
")",
")",
";",
"}",
"foreach",
"(",
"$",
"config",
"[",
"'nodes'",
"]",
"as",
"$",
"property",
"=>",
"$",
"nodeProperties",
")",
"{",
"foreach",
"(",
"$",
"nodeProperties",
"as",
"$",
"nodeProperty",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"nodeProperty",
"[",
"'namespace'",
"]",
")",
"||",
"!",
"isset",
"(",
"$",
"nodeProperty",
"[",
"'tag'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Invalid YAML configuration for \"%s\" : \"namespace\" and \"tag\" are required.'",
",",
"$",
"metadata",
"->",
"name",
")",
")",
";",
"}",
"$",
"node",
"=",
"new",
"Node",
"(",
"[",
"'namespace'",
"=>",
"$",
"nodeProperty",
"[",
"'namespace'",
"]",
",",
"'tag'",
"=>",
"$",
"nodeProperty",
"[",
"'tag'",
"]",
",",
"]",
")",
";",
"if",
"(",
"$",
"class",
"->",
"hasProperty",
"(",
"$",
"property",
")",
")",
"{",
"$",
"metadata",
"->",
"addGraphMetadata",
"(",
"$",
"node",
",",
"new",
"PropertyMetadata",
"(",
"$",
"class",
"->",
"name",
",",
"$",
"property",
")",
")",
";",
"}",
"if",
"(",
"$",
"class",
"->",
"hasMethod",
"(",
"$",
"property",
")",
")",
"{",
"$",
"metadata",
"->",
"addGraphMetadata",
"(",
"$",
"node",
",",
"new",
"MethodMetadata",
"(",
"$",
"class",
"->",
"name",
",",
"$",
"property",
")",
")",
";",
"}",
"}",
"}",
"}"
] | Parse OpenGraph node properties
@param \ReflectionClass $class
@param ClassMetadata $metadata
@param mixed $config | [
"Parse",
"OpenGraph",
"node",
"properties"
] | train | https://github.com/novaway/open-graph/blob/19817bee4b91cf26ca3fe44883ad58b32328e464/src/Metadata/Driver/YamlDriver.php#L76-L106 |
42mate/towel | src/Towel/Towel.php | Towel.getApps | static public function getApps() {
static $applications = array();
if (!empty($applications)) {
return $applications;
}
$appsDir = APP_ROOT_DIR . '/Application';
$content = scandir($appsDir);
foreach ($content as $item) {
if (is_dir($appsDir . '/' . $item) && $item != '.' && $item != '..') {
$application = array();
$application['name'] = $item;
$application['path'] = $appsDir . '/' . $item;
$applications[$item] = $application;
}
}
$application = array();
$application['name'] = basename(APP_FW_DIR);
$application['path'] = APP_FW_DIR;
$applications['Towel'] = $application;
return $applications;
} | php | static public function getApps() {
static $applications = array();
if (!empty($applications)) {
return $applications;
}
$appsDir = APP_ROOT_DIR . '/Application';
$content = scandir($appsDir);
foreach ($content as $item) {
if (is_dir($appsDir . '/' . $item) && $item != '.' && $item != '..') {
$application = array();
$application['name'] = $item;
$application['path'] = $appsDir . '/' . $item;
$applications[$item] = $application;
}
}
$application = array();
$application['name'] = basename(APP_FW_DIR);
$application['path'] = APP_FW_DIR;
$applications['Towel'] = $application;
return $applications;
} | [
"static",
"public",
"function",
"getApps",
"(",
")",
"{",
"static",
"$",
"applications",
"=",
"array",
"(",
")",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"applications",
")",
")",
"{",
"return",
"$",
"applications",
";",
"}",
"$",
"appsDir",
"=",
"APP_ROOT_DIR",
".",
"'/Application'",
";",
"$",
"content",
"=",
"scandir",
"(",
"$",
"appsDir",
")",
";",
"foreach",
"(",
"$",
"content",
"as",
"$",
"item",
")",
"{",
"if",
"(",
"is_dir",
"(",
"$",
"appsDir",
".",
"'/'",
".",
"$",
"item",
")",
"&&",
"$",
"item",
"!=",
"'.'",
"&&",
"$",
"item",
"!=",
"'..'",
")",
"{",
"$",
"application",
"=",
"array",
"(",
")",
";",
"$",
"application",
"[",
"'name'",
"]",
"=",
"$",
"item",
";",
"$",
"application",
"[",
"'path'",
"]",
"=",
"$",
"appsDir",
".",
"'/'",
".",
"$",
"item",
";",
"$",
"applications",
"[",
"$",
"item",
"]",
"=",
"$",
"application",
";",
"}",
"}",
"$",
"application",
"=",
"array",
"(",
")",
";",
"$",
"application",
"[",
"'name'",
"]",
"=",
"basename",
"(",
"APP_FW_DIR",
")",
";",
"$",
"application",
"[",
"'path'",
"]",
"=",
"APP_FW_DIR",
";",
"$",
"applications",
"[",
"'Towel'",
"]",
"=",
"$",
"application",
";",
"return",
"$",
"applications",
";",
"}"
] | Gets Available applications
return Array : Applications names. | [
"Gets",
"Available",
"applications"
] | train | https://github.com/42mate/towel/blob/5316c3075fc844e8a5cbae113712b26556227dff/src/Towel/Towel.php#L12-L37 |
ronaldborla/chikka | src/Borla/Chikka/Models/Config.php | Config.setShortcodeAttribute | protected function setShortcodeAttribute($value) {
// Extract numerics only
$shortcode = Utilities::extractNumerics($value);
// If shortcode doesn't begin with 29290
if (substr($shortcode, 0, 5) != '29290') {
// Throw error
throw new InvalidConfig('Shortcode must start with `29290`. `' . $shortcode . '` is given');
}
// Set shortcode
return $shortcode;
} | php | protected function setShortcodeAttribute($value) {
// Extract numerics only
$shortcode = Utilities::extractNumerics($value);
// If shortcode doesn't begin with 29290
if (substr($shortcode, 0, 5) != '29290') {
// Throw error
throw new InvalidConfig('Shortcode must start with `29290`. `' . $shortcode . '` is given');
}
// Set shortcode
return $shortcode;
} | [
"protected",
"function",
"setShortcodeAttribute",
"(",
"$",
"value",
")",
"{",
"// Extract numerics only",
"$",
"shortcode",
"=",
"Utilities",
"::",
"extractNumerics",
"(",
"$",
"value",
")",
";",
"// If shortcode doesn't begin with 29290",
"if",
"(",
"substr",
"(",
"$",
"shortcode",
",",
"0",
",",
"5",
")",
"!=",
"'29290'",
")",
"{",
"// Throw error",
"throw",
"new",
"InvalidConfig",
"(",
"'Shortcode must start with `29290`. `'",
".",
"$",
"shortcode",
".",
"'` is given'",
")",
";",
"}",
"// Set shortcode",
"return",
"$",
"shortcode",
";",
"}"
] | When setting shortcode | [
"When",
"setting",
"shortcode"
] | train | https://github.com/ronaldborla/chikka/blob/446987706f81d5a0efbc8bd6b7d3b259d0527719/src/Borla/Chikka/Models/Config.php#L40-L50 |
zicht/z | src/Zicht/Tool/Util.php | Util.toPhp | public static function toPhp($var)
{
switch (gettype($var)) {
case 'array':
$skipKeys = (range(0, count($var) - 1) === array_keys($var));
$ret = 'array(';
$i = 0;
foreach ($var as $key => $value) {
if ($i++ > 0) {
$ret .= ', ';
}
if (!$skipKeys) {
$ret .= self::toPhp($key) . ' => ';
}
$ret .= self::toPhp($value);
}
$ret .= ')';
break;
default:
$ret = var_export($var, true);
}
return $ret;
} | php | public static function toPhp($var)
{
switch (gettype($var)) {
case 'array':
$skipKeys = (range(0, count($var) - 1) === array_keys($var));
$ret = 'array(';
$i = 0;
foreach ($var as $key => $value) {
if ($i++ > 0) {
$ret .= ', ';
}
if (!$skipKeys) {
$ret .= self::toPhp($key) . ' => ';
}
$ret .= self::toPhp($value);
}
$ret .= ')';
break;
default:
$ret = var_export($var, true);
}
return $ret;
} | [
"public",
"static",
"function",
"toPhp",
"(",
"$",
"var",
")",
"{",
"switch",
"(",
"gettype",
"(",
"$",
"var",
")",
")",
"{",
"case",
"'array'",
":",
"$",
"skipKeys",
"=",
"(",
"range",
"(",
"0",
",",
"count",
"(",
"$",
"var",
")",
"-",
"1",
")",
"===",
"array_keys",
"(",
"$",
"var",
")",
")",
";",
"$",
"ret",
"=",
"'array('",
";",
"$",
"i",
"=",
"0",
";",
"foreach",
"(",
"$",
"var",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"i",
"++",
">",
"0",
")",
"{",
"$",
"ret",
".=",
"', '",
";",
"}",
"if",
"(",
"!",
"$",
"skipKeys",
")",
"{",
"$",
"ret",
".=",
"self",
"::",
"toPhp",
"(",
"$",
"key",
")",
".",
"' => '",
";",
"}",
"$",
"ret",
".=",
"self",
"::",
"toPhp",
"(",
"$",
"value",
")",
";",
"}",
"$",
"ret",
".=",
"')'",
";",
"break",
";",
"default",
":",
"$",
"ret",
"=",
"var_export",
"(",
"$",
"var",
",",
"true",
")",
";",
"}",
"return",
"$",
"ret",
";",
"}"
] | A wrapper for var_export, having list-style arrays (0-indexed incremental keys) compile without the keys in
the code.
@param mixed $var
@return string | [
"A",
"wrapper",
"for",
"var_export",
"having",
"list",
"-",
"style",
"arrays",
"(",
"0",
"-",
"indexed",
"incremental",
"keys",
")",
"compile",
"without",
"the",
"keys",
"in",
"the",
"code",
"."
] | train | https://github.com/zicht/z/blob/6a1731dad20b018555a96b726a61d4bf8ec8c886/src/Zicht/Tool/Util.php#L24-L46 |
InactiveProjects/limoncello-illuminate | app/Database/Models/Role.php | Role.getRoleId | public static function getRoleId($role)
{
$map = [
self::ENUM_ROLE_ADMIN => self::ENUM_ROLE_ADMIN_ID,
self::ENUM_ROLE_USER => self::ENUM_ROLE_USER_ID,
];
// do not check if key exist deliberately. If wrong role is given it will cause an error.
return $map[$role];
} | php | public static function getRoleId($role)
{
$map = [
self::ENUM_ROLE_ADMIN => self::ENUM_ROLE_ADMIN_ID,
self::ENUM_ROLE_USER => self::ENUM_ROLE_USER_ID,
];
// do not check if key exist deliberately. If wrong role is given it will cause an error.
return $map[$role];
} | [
"public",
"static",
"function",
"getRoleId",
"(",
"$",
"role",
")",
"{",
"$",
"map",
"=",
"[",
"self",
"::",
"ENUM_ROLE_ADMIN",
"=>",
"self",
"::",
"ENUM_ROLE_ADMIN_ID",
",",
"self",
"::",
"ENUM_ROLE_USER",
"=>",
"self",
"::",
"ENUM_ROLE_USER_ID",
",",
"]",
";",
"// do not check if key exist deliberately. If wrong role is given it will cause an error.",
"return",
"$",
"map",
"[",
"$",
"role",
"]",
";",
"}"
] | @param string $role
@return int | [
"@param",
"string",
"$role"
] | train | https://github.com/InactiveProjects/limoncello-illuminate/blob/cae6fc26190efcf090495a5c3582c10fa2430897/app/Database/Models/Role.php#L68-L77 |
tylernathanreed/flash | src/FlashServiceProvider.php | FlashServiceProvider.boot | public function boot()
{
$path = __DIR__ . '/../resources/views';
$this->loadViewsFrom($path, 'flash');
$this->publishes([
$path => base_path('resources/views/vendor/flash'),
], 'flash');
} | php | public function boot()
{
$path = __DIR__ . '/../resources/views';
$this->loadViewsFrom($path, 'flash');
$this->publishes([
$path => base_path('resources/views/vendor/flash'),
], 'flash');
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"$",
"path",
"=",
"__DIR__",
".",
"'/../resources/views'",
";",
"$",
"this",
"->",
"loadViewsFrom",
"(",
"$",
"path",
",",
"'flash'",
")",
";",
"$",
"this",
"->",
"publishes",
"(",
"[",
"$",
"path",
"=>",
"base_path",
"(",
"'resources/views/vendor/flash'",
")",
",",
"]",
",",
"'flash'",
")",
";",
"}"
] | Perform post-registration booting of services.
@return void | [
"Perform",
"post",
"-",
"registration",
"booting",
"of",
"services",
"."
] | train | https://github.com/tylernathanreed/flash/blob/6ca4b361493e7e48e3c3cf6b1ed95f8a1b2b724c/src/FlashServiceProvider.php#L41-L50 |
inhere/php-librarys | src/Traits/FixedEventStaticTrait.php | FixedEventStaticTrait.fire | public static function fire($event, array $args = [])
{
if (!isset(self::$events[$event])) {
return false;
}
// call event handlers of the event.
foreach ((array)self::$eventHandlers[$event] as $cb) {
// return FALSE to stop go on handle.
if (false === PhpHelper::call($cb, ...$args)) {
break;
}
}
// is a once event, remove it
if (self::$events[$event]) {
return self::off($event);
}
return true;
} | php | public static function fire($event, array $args = [])
{
if (!isset(self::$events[$event])) {
return false;
}
// call event handlers of the event.
foreach ((array)self::$eventHandlers[$event] as $cb) {
// return FALSE to stop go on handle.
if (false === PhpHelper::call($cb, ...$args)) {
break;
}
}
// is a once event, remove it
if (self::$events[$event]) {
return self::off($event);
}
return true;
} | [
"public",
"static",
"function",
"fire",
"(",
"$",
"event",
",",
"array",
"$",
"args",
"=",
"[",
"]",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"self",
"::",
"$",
"events",
"[",
"$",
"event",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"// call event handlers of the event.",
"foreach",
"(",
"(",
"array",
")",
"self",
"::",
"$",
"eventHandlers",
"[",
"$",
"event",
"]",
"as",
"$",
"cb",
")",
"{",
"// return FALSE to stop go on handle.",
"if",
"(",
"false",
"===",
"PhpHelper",
"::",
"call",
"(",
"$",
"cb",
",",
"...",
"$",
"args",
")",
")",
"{",
"break",
";",
"}",
"}",
"// is a once event, remove it",
"if",
"(",
"self",
"::",
"$",
"events",
"[",
"$",
"event",
"]",
")",
"{",
"return",
"self",
"::",
"off",
"(",
"$",
"event",
")",
";",
"}",
"return",
"true",
";",
"}"
] | trigger event
@param $event
@param array $args
@return bool | [
"trigger",
"event"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Traits/FixedEventStaticTrait.php#L74-L94 |
inhere/php-librarys | src/Traits/FixedEventStaticTrait.php | FixedEventStaticTrait.off | public static function off($event)
{
if (self::hasEvent($event)) {
unset(self::$events[$event], self::$eventHandlers[$event]);
return true;
}
return false;
} | php | public static function off($event)
{
if (self::hasEvent($event)) {
unset(self::$events[$event], self::$eventHandlers[$event]);
return true;
}
return false;
} | [
"public",
"static",
"function",
"off",
"(",
"$",
"event",
")",
"{",
"if",
"(",
"self",
"::",
"hasEvent",
"(",
"$",
"event",
")",
")",
"{",
"unset",
"(",
"self",
"::",
"$",
"events",
"[",
"$",
"event",
"]",
",",
"self",
"::",
"$",
"eventHandlers",
"[",
"$",
"event",
"]",
")",
";",
"return",
"true",
";",
"}",
"return",
"false",
";",
"}"
] | remove event and it's handlers
@param $event
@return bool | [
"remove",
"event",
"and",
"it",
"s",
"handlers"
] | train | https://github.com/inhere/php-librarys/blob/e6ca598685469794f310e3ab0e2bc19519cd0ae6/src/Traits/FixedEventStaticTrait.php#L101-L110 |
wplibs/rules | src/Operator/In.php | In.evaluate | public function evaluate( Context $context ) {
/**
* Extracts variables.
*
* @var \Ruler\Variable $left
* @var \Ruler\Variable $right
*/
list( $left, $right ) = $this->getOperands();
$left = $left->prepareValue( $context )->getValue();
$right = $right->prepareValue( $context )->getValue();
return in_array( $left, is_array( $right ) ? $right : [ $right ] );
} | php | public function evaluate( Context $context ) {
/**
* Extracts variables.
*
* @var \Ruler\Variable $left
* @var \Ruler\Variable $right
*/
list( $left, $right ) = $this->getOperands();
$left = $left->prepareValue( $context )->getValue();
$right = $right->prepareValue( $context )->getValue();
return in_array( $left, is_array( $right ) ? $right : [ $right ] );
} | [
"public",
"function",
"evaluate",
"(",
"Context",
"$",
"context",
")",
"{",
"/**\n\t\t * Extracts variables.\n\t\t *\n\t\t * @var \\Ruler\\Variable $left\n\t\t * @var \\Ruler\\Variable $right\n\t\t */",
"list",
"(",
"$",
"left",
",",
"$",
"right",
")",
"=",
"$",
"this",
"->",
"getOperands",
"(",
")",
";",
"$",
"left",
"=",
"$",
"left",
"->",
"prepareValue",
"(",
"$",
"context",
")",
"->",
"getValue",
"(",
")",
";",
"$",
"right",
"=",
"$",
"right",
"->",
"prepareValue",
"(",
"$",
"context",
")",
"->",
"getValue",
"(",
")",
";",
"return",
"in_array",
"(",
"$",
"left",
",",
"is_array",
"(",
"$",
"right",
")",
"?",
"$",
"right",
":",
"[",
"$",
"right",
"]",
")",
";",
"}"
] | Evaluate the operands.
@param Context $context Context with which to evaluate this Proposition.
@return boolean | [
"Evaluate",
"the",
"operands",
"."
] | train | https://github.com/wplibs/rules/blob/29b4495e2ae87349fd64fcd844f3ba96cc268e3d/src/Operator/In.php#L16-L29 |
zhouyl/mellivora | Mellivora/Config/Ini.php | Ini.parseIniString | protected function parseIniString($path, $value)
{
$value = $this->cast($value);
$pos = strpos($path, '.');
if ($pos === false) {
return [$path => $value];
}
$key = substr($path, 0, $pos);
$path = substr($path, $pos + 1);
return [$key => $this->parseIniString($path, $value)];
} | php | protected function parseIniString($path, $value)
{
$value = $this->cast($value);
$pos = strpos($path, '.');
if ($pos === false) {
return [$path => $value];
}
$key = substr($path, 0, $pos);
$path = substr($path, $pos + 1);
return [$key => $this->parseIniString($path, $value)];
} | [
"protected",
"function",
"parseIniString",
"(",
"$",
"path",
",",
"$",
"value",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"cast",
"(",
"$",
"value",
")",
";",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"path",
",",
"'.'",
")",
";",
"if",
"(",
"$",
"pos",
"===",
"false",
")",
"{",
"return",
"[",
"$",
"path",
"=>",
"$",
"value",
"]",
";",
"}",
"$",
"key",
"=",
"substr",
"(",
"$",
"path",
",",
"0",
",",
"$",
"pos",
")",
";",
"$",
"path",
"=",
"substr",
"(",
"$",
"path",
",",
"$",
"pos",
"+",
"1",
")",
";",
"return",
"[",
"$",
"key",
"=>",
"$",
"this",
"->",
"parseIniString",
"(",
"$",
"path",
",",
"$",
"value",
")",
"]",
";",
"}"
] | 将 ini 的 . 分隔符构建的数据,解析为多维数组
<code>
$this->parseIniString("path.hello.world", "value for last key");
// result
[
"path" => [
"hello" => [
"world" => "value for last key",
],
],
];
</code>
@param mixed $path
@param mixed $value | [
"将",
"ini",
"的",
".",
"分隔符构建的数据,解析为多维数组"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Config/Ini.php#L67-L80 |
zhouyl/mellivora | Mellivora/Config/Ini.php | Ini.cast | protected function cast($ini)
{
if (is_array($ini)) {
foreach ($ini as $key => $val) {
$ini[$key] = $this->cast($val);
}
}
if (is_string($ini)) {
if (in_array(strtolower($ini), ['true', 'yes', 'on'])) {
return true;
}
if (in_array(strtolower($ini), ['false', 'no', 'off'])) {
return false;
}
if (in_array(strtolower($ini), ['', 'null'])) {
return null;
}
if (is_numeric($ini)) {
if (preg_match('/[.]+/', $ini)) {
return (float) $ini;
}
return (int) $ini;
}
}
return $ini;
} | php | protected function cast($ini)
{
if (is_array($ini)) {
foreach ($ini as $key => $val) {
$ini[$key] = $this->cast($val);
}
}
if (is_string($ini)) {
if (in_array(strtolower($ini), ['true', 'yes', 'on'])) {
return true;
}
if (in_array(strtolower($ini), ['false', 'no', 'off'])) {
return false;
}
if (in_array(strtolower($ini), ['', 'null'])) {
return null;
}
if (is_numeric($ini)) {
if (preg_match('/[.]+/', $ini)) {
return (float) $ini;
}
return (int) $ini;
}
}
return $ini;
} | [
"protected",
"function",
"cast",
"(",
"$",
"ini",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"ini",
")",
")",
"{",
"foreach",
"(",
"$",
"ini",
"as",
"$",
"key",
"=>",
"$",
"val",
")",
"{",
"$",
"ini",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"cast",
"(",
"$",
"val",
")",
";",
"}",
"}",
"if",
"(",
"is_string",
"(",
"$",
"ini",
")",
")",
"{",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"ini",
")",
",",
"[",
"'true'",
",",
"'yes'",
",",
"'on'",
"]",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"ini",
")",
",",
"[",
"'false'",
",",
"'no'",
",",
"'off'",
"]",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"in_array",
"(",
"strtolower",
"(",
"$",
"ini",
")",
",",
"[",
"''",
",",
"'null'",
"]",
")",
")",
"{",
"return",
"null",
";",
"}",
"if",
"(",
"is_numeric",
"(",
"$",
"ini",
")",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/[.]+/'",
",",
"$",
"ini",
")",
")",
"{",
"return",
"(",
"float",
")",
"$",
"ini",
";",
"}",
"return",
"(",
"int",
")",
"$",
"ini",
";",
"}",
"}",
"return",
"$",
"ini",
";",
"}"
] | php 对 ini 的解释有不到位的地方,部分值转换需要手动处理
@param mixed $ini
@return mixed | [
"php",
"对",
"ini",
"的解释有不到位的地方,部分值转换需要手动处理"
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Config/Ini.php#L89-L117 |
SergioMadness/query-builder | src/adapters/MySQL/SelectBuilder.php | SelectBuilder.buildOrder | protected function buildOrder()
{
$result = '';
$orders = (array) $this->getOrder();
foreach ($orders as $field => $direction) {
if ($result != '') {
$result.=',';
}
$result.=$field.' '.($direction === SORT_DESC ? 'DESC' : 'ASC');
}
if ($result != '') {
$result = 'ORDER BY '.$result;
}
return $result;
} | php | protected function buildOrder()
{
$result = '';
$orders = (array) $this->getOrder();
foreach ($orders as $field => $direction) {
if ($result != '') {
$result.=',';
}
$result.=$field.' '.($direction === SORT_DESC ? 'DESC' : 'ASC');
}
if ($result != '') {
$result = 'ORDER BY '.$result;
}
return $result;
} | [
"protected",
"function",
"buildOrder",
"(",
")",
"{",
"$",
"result",
"=",
"''",
";",
"$",
"orders",
"=",
"(",
"array",
")",
"$",
"this",
"->",
"getOrder",
"(",
")",
";",
"foreach",
"(",
"$",
"orders",
"as",
"$",
"field",
"=>",
"$",
"direction",
")",
"{",
"if",
"(",
"$",
"result",
"!=",
"''",
")",
"{",
"$",
"result",
".=",
"','",
";",
"}",
"$",
"result",
".=",
"$",
"field",
".",
"' '",
".",
"(",
"$",
"direction",
"===",
"SORT_DESC",
"?",
"'DESC'",
":",
"'ASC'",
")",
";",
"}",
"if",
"(",
"$",
"result",
"!=",
"''",
")",
"{",
"$",
"result",
"=",
"'ORDER BY '",
".",
"$",
"result",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Build order
@return string | [
"Build",
"order"
] | train | https://github.com/SergioMadness/query-builder/blob/95b7a46bba4c4d369101c6f0d37f133fecb3956d/src/adapters/MySQL/SelectBuilder.php#L172-L188 |
jetfirephp/http | src/Request.php | Request.isEmptyString | protected function isEmptyString($key)
{
$value = $this->input($key);
$boolOrArray = is_bool($value) || is_array($value);
return ! $boolOrArray && trim((string) $value) === '';
} | php | protected function isEmptyString($key)
{
$value = $this->input($key);
$boolOrArray = is_bool($value) || is_array($value);
return ! $boolOrArray && trim((string) $value) === '';
} | [
"protected",
"function",
"isEmptyString",
"(",
"$",
"key",
")",
"{",
"$",
"value",
"=",
"$",
"this",
"->",
"input",
"(",
"$",
"key",
")",
";",
"$",
"boolOrArray",
"=",
"is_bool",
"(",
"$",
"value",
")",
"||",
"is_array",
"(",
"$",
"value",
")",
";",
"return",
"!",
"$",
"boolOrArray",
"&&",
"trim",
"(",
"(",
"string",
")",
"$",
"value",
")",
"===",
"''",
";",
"}"
] | Determine if the given input key is an empty string for "has".
@param string $key
@return bool | [
"Determine",
"if",
"the",
"given",
"input",
"key",
"is",
"an",
"empty",
"string",
"for",
"has",
"."
] | train | https://github.com/jetfirephp/http/blob/b00cfd930edb48621d694cdb91fd1e931ad3f529/src/Request.php#L197-L202 |
jetfirephp/http | src/Request.php | Request.flash | public function flash($filter = null, $keys = [])
{
$flash = (! is_null($filter)) ? $this->$filter($keys) : $this->all();
$this->session()->getFlashBag()->set($flash);
} | php | public function flash($filter = null, $keys = [])
{
$flash = (! is_null($filter)) ? $this->$filter($keys) : $this->all();
$this->session()->getFlashBag()->set($flash);
} | [
"public",
"function",
"flash",
"(",
"$",
"filter",
"=",
"null",
",",
"$",
"keys",
"=",
"[",
"]",
")",
"{",
"$",
"flash",
"=",
"(",
"!",
"is_null",
"(",
"$",
"filter",
")",
")",
"?",
"$",
"this",
"->",
"$",
"filter",
"(",
"$",
"keys",
")",
":",
"$",
"this",
"->",
"all",
"(",
")",
";",
"$",
"this",
"->",
"session",
"(",
")",
"->",
"getFlashBag",
"(",
")",
"->",
"set",
"(",
"$",
"flash",
")",
";",
"}"
] | Flash the input for the current request to the session.
@param string $filter
@param array $keys
@return void | [
"Flash",
"the",
"input",
"for",
"the",
"current",
"request",
"to",
"the",
"session",
"."
] | train | https://github.com/jetfirephp/http/blob/b00cfd930edb48621d694cdb91fd1e931ad3f529/src/Request.php#L314-L318 |
jetfirephp/http | src/Request.php | Request.json | public function json($key = null, $default = null)
{
if (! isset($this->json)) {
$this->json = new ParameterBag((array) json_decode($this->getContent(), true));
}
if (is_null($key)) {
return $this->json;
}
return $this->json->get($key,$default);
} | php | public function json($key = null, $default = null)
{
if (! isset($this->json)) {
$this->json = new ParameterBag((array) json_decode($this->getContent(), true));
}
if (is_null($key)) {
return $this->json;
}
return $this->json->get($key,$default);
} | [
"public",
"function",
"json",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"json",
")",
")",
"{",
"$",
"this",
"->",
"json",
"=",
"new",
"ParameterBag",
"(",
"(",
"array",
")",
"json_decode",
"(",
"$",
"this",
"->",
"getContent",
"(",
")",
",",
"true",
")",
")",
";",
"}",
"if",
"(",
"is_null",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"json",
";",
"}",
"return",
"$",
"this",
"->",
"json",
"->",
"get",
"(",
"$",
"key",
",",
"$",
"default",
")",
";",
"}"
] | Get the JSON payload for the request.
@param string $key
@param mixed $default
@return mixed | [
"Get",
"the",
"JSON",
"payload",
"for",
"the",
"request",
"."
] | train | https://github.com/jetfirephp/http/blob/b00cfd930edb48621d694cdb91fd1e931ad3f529/src/Request.php#L393-L402 |
jetfirephp/http | src/Request.php | Request.wantsJson | public function wantsJson()
{
$acceptable = $this->getAcceptableContentTypes();
return (isset($acceptable[0]) && (strpos($acceptable[0], '/json') !== false || strpos($acceptable[0], '+json') !== false));
} | php | public function wantsJson()
{
$acceptable = $this->getAcceptableContentTypes();
return (isset($acceptable[0]) && (strpos($acceptable[0], '/json') !== false || strpos($acceptable[0], '+json') !== false));
} | [
"public",
"function",
"wantsJson",
"(",
")",
"{",
"$",
"acceptable",
"=",
"$",
"this",
"->",
"getAcceptableContentTypes",
"(",
")",
";",
"return",
"(",
"isset",
"(",
"$",
"acceptable",
"[",
"0",
"]",
")",
"&&",
"(",
"strpos",
"(",
"$",
"acceptable",
"[",
"0",
"]",
",",
"'/json'",
")",
"!==",
"false",
"||",
"strpos",
"(",
"$",
"acceptable",
"[",
"0",
"]",
",",
"'+json'",
")",
"!==",
"false",
")",
")",
";",
"}"
] | Determine if the current request is asking for JSON in return.
@return bool | [
"Determine",
"if",
"the",
"current",
"request",
"is",
"asking",
"for",
"JSON",
"in",
"return",
"."
] | train | https://github.com/jetfirephp/http/blob/b00cfd930edb48621d694cdb91fd1e931ad3f529/src/Request.php#L447-L451 |
jetfirephp/http | src/Request.php | Request.input | public function input($key = null, $default = null)
{
$input = array_merge($this->getInputSource()->all(),$this->query->all());
return isset($input[$key])?$input[$key]:$default;
} | php | public function input($key = null, $default = null)
{
$input = array_merge($this->getInputSource()->all(),$this->query->all());
return isset($input[$key])?$input[$key]:$default;
} | [
"public",
"function",
"input",
"(",
"$",
"key",
"=",
"null",
",",
"$",
"default",
"=",
"null",
")",
"{",
"$",
"input",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"getInputSource",
"(",
")",
"->",
"all",
"(",
")",
",",
"$",
"this",
"->",
"query",
"->",
"all",
"(",
")",
")",
";",
"return",
"isset",
"(",
"$",
"input",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"input",
"[",
"$",
"key",
"]",
":",
"$",
"default",
";",
"}"
] | Retrieve an input item from the request.
@param string $key
@param string|array|null $default
@return string|array | [
"Retrieve",
"an",
"input",
"item",
"from",
"the",
"request",
"."
] | train | https://github.com/jetfirephp/http/blob/b00cfd930edb48621d694cdb91fd1e931ad3f529/src/Request.php#L519-L523 |
jetfirephp/http | src/Request.php | Request.except | public function except($keys)
{
$keys = is_array($keys) ? $keys : func_get_args();
$results = [];
$inputs = $this->all();
foreach ($inputs as $key => $input) {
if(!in_array($key,$keys))
$results[$key] = $input[$key];
}
return $results;
} | php | public function except($keys)
{
$keys = is_array($keys) ? $keys : func_get_args();
$results = [];
$inputs = $this->all();
foreach ($inputs as $key => $input) {
if(!in_array($key,$keys))
$results[$key] = $input[$key];
}
return $results;
} | [
"public",
"function",
"except",
"(",
"$",
"keys",
")",
"{",
"$",
"keys",
"=",
"is_array",
"(",
"$",
"keys",
")",
"?",
"$",
"keys",
":",
"func_get_args",
"(",
")",
";",
"$",
"results",
"=",
"[",
"]",
";",
"$",
"inputs",
"=",
"$",
"this",
"->",
"all",
"(",
")",
";",
"foreach",
"(",
"$",
"inputs",
"as",
"$",
"key",
"=>",
"$",
"input",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"key",
",",
"$",
"keys",
")",
")",
"$",
"results",
"[",
"$",
"key",
"]",
"=",
"$",
"input",
"[",
"$",
"key",
"]",
";",
"}",
"return",
"$",
"results",
";",
"}"
] | Get all of the input except for a specified array of items.
@param array|mixed $keys
@return array | [
"Get",
"all",
"of",
"the",
"input",
"except",
"for",
"a",
"specified",
"array",
"of",
"items",
"."
] | train | https://github.com/jetfirephp/http/blob/b00cfd930edb48621d694cdb91fd1e931ad3f529/src/Request.php#L546-L556 |
InactiveProjects/limoncello-illuminate | app/Database/Factories/CommentFactory.php | CommentFactory.getRandomPost | private function getRandomPost()
{
if ($this->posts === null) {
$this->posts = Post::all();
}
return $this->posts->random();
} | php | private function getRandomPost()
{
if ($this->posts === null) {
$this->posts = Post::all();
}
return $this->posts->random();
} | [
"private",
"function",
"getRandomPost",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"posts",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"posts",
"=",
"Post",
"::",
"all",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"posts",
"->",
"random",
"(",
")",
";",
"}"
] | @return Post
@SuppressWarnings(PHPMD.StaticAccess) | [
"@return",
"Post"
] | train | https://github.com/InactiveProjects/limoncello-illuminate/blob/cae6fc26190efcf090495a5c3582c10fa2430897/app/Database/Factories/CommentFactory.php#L37-L44 |
Root-XS/SudoBible | src/SudoBiblePassage.php | SudoBiblePassage.getReference | public function getReference($bAbbreviate = false)
{
$oFirstVerse = $this->getFirstVerse();
$oLastVerse = $this->getLastVerse();
// John 3
$strRef = ($bAbbreviate ? $oFirstVerse->book_abbr : $oFirstVerse->book_name)
. ' ' . $oFirstVerse->chapter;
if (!$this->isFullChapter()) {
// John 3:16
$strRef .= ':' . $oFirstVerse->verse;
if (count($this->aVerses) > 1) {
if ($oFirstVerse->book_id == $oLastVerse->book_id && $oFirstVerse->chapter == $oLastVerse->chapter) {
// John 3:16-17
$strRef .= '-' . $oLastVerse->verse;
} else {
$strRef .= ' - ';
// John 3:16 - Acts 1:1
if ($oFirstVerse->book_id !== $oLastVerse->book_id)
$strRef .= ($bAbbreviate ? $oLastVerse->book_abbr : $oLastVerse->book_name) . ' ';
// John 3:16 - 4:2
$strRef .= $oLastVerse->chapter . ':' . $oLastVerse->verse;
}
}
}
// Add styling
$strRef = $this->bHTML
? '<i>(' . $strRef . ')</i>'
: '(' . $strRef .')';
return $strRef;
} | php | public function getReference($bAbbreviate = false)
{
$oFirstVerse = $this->getFirstVerse();
$oLastVerse = $this->getLastVerse();
// John 3
$strRef = ($bAbbreviate ? $oFirstVerse->book_abbr : $oFirstVerse->book_name)
. ' ' . $oFirstVerse->chapter;
if (!$this->isFullChapter()) {
// John 3:16
$strRef .= ':' . $oFirstVerse->verse;
if (count($this->aVerses) > 1) {
if ($oFirstVerse->book_id == $oLastVerse->book_id && $oFirstVerse->chapter == $oLastVerse->chapter) {
// John 3:16-17
$strRef .= '-' . $oLastVerse->verse;
} else {
$strRef .= ' - ';
// John 3:16 - Acts 1:1
if ($oFirstVerse->book_id !== $oLastVerse->book_id)
$strRef .= ($bAbbreviate ? $oLastVerse->book_abbr : $oLastVerse->book_name) . ' ';
// John 3:16 - 4:2
$strRef .= $oLastVerse->chapter . ':' . $oLastVerse->verse;
}
}
}
// Add styling
$strRef = $this->bHTML
? '<i>(' . $strRef . ')</i>'
: '(' . $strRef .')';
return $strRef;
} | [
"public",
"function",
"getReference",
"(",
"$",
"bAbbreviate",
"=",
"false",
")",
"{",
"$",
"oFirstVerse",
"=",
"$",
"this",
"->",
"getFirstVerse",
"(",
")",
";",
"$",
"oLastVerse",
"=",
"$",
"this",
"->",
"getLastVerse",
"(",
")",
";",
"// John 3",
"$",
"strRef",
"=",
"(",
"$",
"bAbbreviate",
"?",
"$",
"oFirstVerse",
"->",
"book_abbr",
":",
"$",
"oFirstVerse",
"->",
"book_name",
")",
".",
"' '",
".",
"$",
"oFirstVerse",
"->",
"chapter",
";",
"if",
"(",
"!",
"$",
"this",
"->",
"isFullChapter",
"(",
")",
")",
"{",
"// John 3:16",
"$",
"strRef",
".=",
"':'",
".",
"$",
"oFirstVerse",
"->",
"verse",
";",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"aVerses",
")",
">",
"1",
")",
"{",
"if",
"(",
"$",
"oFirstVerse",
"->",
"book_id",
"==",
"$",
"oLastVerse",
"->",
"book_id",
"&&",
"$",
"oFirstVerse",
"->",
"chapter",
"==",
"$",
"oLastVerse",
"->",
"chapter",
")",
"{",
"// John 3:16-17",
"$",
"strRef",
".=",
"'-'",
".",
"$",
"oLastVerse",
"->",
"verse",
";",
"}",
"else",
"{",
"$",
"strRef",
".=",
"' - '",
";",
"// John 3:16 - Acts 1:1",
"if",
"(",
"$",
"oFirstVerse",
"->",
"book_id",
"!==",
"$",
"oLastVerse",
"->",
"book_id",
")",
"$",
"strRef",
".=",
"(",
"$",
"bAbbreviate",
"?",
"$",
"oLastVerse",
"->",
"book_abbr",
":",
"$",
"oLastVerse",
"->",
"book_name",
")",
".",
"' '",
";",
"// John 3:16 - 4:2",
"$",
"strRef",
".=",
"$",
"oLastVerse",
"->",
"chapter",
".",
"':'",
".",
"$",
"oLastVerse",
"->",
"verse",
";",
"}",
"}",
"}",
"// Add styling",
"$",
"strRef",
"=",
"$",
"this",
"->",
"bHTML",
"?",
"'<i>('",
".",
"$",
"strRef",
".",
"')</i>'",
":",
"'('",
".",
"$",
"strRef",
".",
"')'",
";",
"return",
"$",
"strRef",
";",
"}"
] | Get the reference location, like "John 3:16"
@param bool $bAbbreviate Use the book's abbreviation instead of full name?
@return string | [
"Get",
"the",
"reference",
"location",
"like",
"John",
"3",
":",
"16"
] | train | https://github.com/Root-XS/SudoBible/blob/562462e92e1b2c019bdd48ed83414502ca0bdb0c/src/SudoBiblePassage.php#L165-L207 |
Root-XS/SudoBible | src/SudoBiblePassage.php | SudoBiblePassage.nextVerse | public function nextVerse()
{
if ($this->isEmpty())
throw new Exception(__METHOD__ . ': Can\'t find next - current passage is invalid.');
$oLastVerse = $this->getLastVerse();
return $this->oBible->nextVerse(
$oLastVerse->book_id,
$oLastVerse->chapter,
$oLastVerse->verse
);
} | php | public function nextVerse()
{
if ($this->isEmpty())
throw new Exception(__METHOD__ . ': Can\'t find next - current passage is invalid.');
$oLastVerse = $this->getLastVerse();
return $this->oBible->nextVerse(
$oLastVerse->book_id,
$oLastVerse->chapter,
$oLastVerse->verse
);
} | [
"public",
"function",
"nextVerse",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"isEmpty",
"(",
")",
")",
"throw",
"new",
"Exception",
"(",
"__METHOD__",
".",
"': Can\\'t find next - current passage is invalid.'",
")",
";",
"$",
"oLastVerse",
"=",
"$",
"this",
"->",
"getLastVerse",
"(",
")",
";",
"return",
"$",
"this",
"->",
"oBible",
"->",
"nextVerse",
"(",
"$",
"oLastVerse",
"->",
"book_id",
",",
"$",
"oLastVerse",
"->",
"chapter",
",",
"$",
"oLastVerse",
"->",
"verse",
")",
";",
"}"
] | Return the next Bible verse after the current passage.
@return SudoBiblePassage | [
"Return",
"the",
"next",
"Bible",
"verse",
"after",
"the",
"current",
"passage",
"."
] | train | https://github.com/Root-XS/SudoBible/blob/562462e92e1b2c019bdd48ed83414502ca0bdb0c/src/SudoBiblePassage.php#L214-L225 |
gruzilla/hydra | src/Hydra/Workers/MappedSerialWorker.php | MappedSerialWorker.run | public function run(JobInterface $job)
{
parent::run($job);
if (!($job instanceof MappedJob)) {
return $this;
}
$job->setResult(
$this->mapper->map(
$job->getEntityRepository(),
$job->getMappedClass(),
$job->getResult()
)
);
// allow chaining
return $this;
} | php | public function run(JobInterface $job)
{
parent::run($job);
if (!($job instanceof MappedJob)) {
return $this;
}
$job->setResult(
$this->mapper->map(
$job->getEntityRepository(),
$job->getMappedClass(),
$job->getResult()
)
);
// allow chaining
return $this;
} | [
"public",
"function",
"run",
"(",
"JobInterface",
"$",
"job",
")",
"{",
"parent",
"::",
"run",
"(",
"$",
"job",
")",
";",
"if",
"(",
"!",
"(",
"$",
"job",
"instanceof",
"MappedJob",
")",
")",
"{",
"return",
"$",
"this",
";",
"}",
"$",
"job",
"->",
"setResult",
"(",
"$",
"this",
"->",
"mapper",
"->",
"map",
"(",
"$",
"job",
"->",
"getEntityRepository",
"(",
")",
",",
"$",
"job",
"->",
"getMappedClass",
"(",
")",
",",
"$",
"job",
"->",
"getResult",
"(",
")",
")",
")",
";",
"// allow chaining",
"return",
"$",
"this",
";",
"}"
] | runs the parent job and then maps the result
@param JobInterface $job the job to execute
@return self | [
"runs",
"the",
"parent",
"job",
"and",
"then",
"maps",
"the",
"result"
] | train | https://github.com/gruzilla/hydra/blob/47f381cc48e1a26bfe2e211d8dcb54c787ea0478/src/Hydra/Workers/MappedSerialWorker.php#L28-L47 |
heidelpay/PhpDoc | src/phpDocumentor/Plugin/Scrybe/Converter/RestructuredText/ToHtml.php | ToHtml.discover | protected function discover()
{
/** @var File $file */
foreach ($this->fileset as $file) {
$rst = new Document($this, $file);
$rst->options->xhtmlVisitor = 'phpDocumentor\Plugin\Scrybe\Converter\RestructuredText\Visitors\Discover';
if ($this->getLogger()) {
$this->getLogger()->info('Scanning file "' . $file->getRealPath() . '"');
}
try {
$rst->getAsXhtml();
} catch (\Exception $e) {
continue;
}
}
} | php | protected function discover()
{
/** @var File $file */
foreach ($this->fileset as $file) {
$rst = new Document($this, $file);
$rst->options->xhtmlVisitor = 'phpDocumentor\Plugin\Scrybe\Converter\RestructuredText\Visitors\Discover';
if ($this->getLogger()) {
$this->getLogger()->info('Scanning file "' . $file->getRealPath() . '"');
}
try {
$rst->getAsXhtml();
} catch (\Exception $e) {
continue;
}
}
} | [
"protected",
"function",
"discover",
"(",
")",
"{",
"/** @var File $file */",
"foreach",
"(",
"$",
"this",
"->",
"fileset",
"as",
"$",
"file",
")",
"{",
"$",
"rst",
"=",
"new",
"Document",
"(",
"$",
"this",
",",
"$",
"file",
")",
";",
"$",
"rst",
"->",
"options",
"->",
"xhtmlVisitor",
"=",
"'phpDocumentor\\Plugin\\Scrybe\\Converter\\RestructuredText\\Visitors\\Discover'",
";",
"if",
"(",
"$",
"this",
"->",
"getLogger",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"info",
"(",
"'Scanning file \"'",
".",
"$",
"file",
"->",
"getRealPath",
"(",
")",
".",
"'\"'",
")",
";",
"}",
"try",
"{",
"$",
"rst",
"->",
"getAsXhtml",
"(",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"continue",
";",
"}",
"}",
"}"
] | Discovers the data that is spanning all files.
This method tries to find any data that needs to be collected before the actual creation and substitution
phase begins.
Examples of data that needs to be collected during an initial phase is a table of contents, list of document
titles for references, assets and more.
@see manual://internals#build_cycle for more information regarding the build process.
@return void | [
"Discovers",
"the",
"data",
"that",
"is",
"spanning",
"all",
"files",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Scrybe/Converter/RestructuredText/ToHtml.php#L42-L59 |
heidelpay/PhpDoc | src/phpDocumentor/Plugin/Scrybe/Converter/RestructuredText/ToHtml.php | ToHtml.create | protected function create(TemplateInterface $template)
{
$result = array();
/** @var File $file */
foreach ($this->fileset as $file) {
$rst = new Document($this, $file);
$destination = $this->getDestinationFilenameRelativeToProjectRoot($file);
$this->setDestinationRoot($destination);
if ($this->getLogger()) {
$this->getLogger()->info('Parsing file "' . $file->getRealPath() . '"');
}
try {
$xhtml_document = $rst->getAsXhtml();
$converted_contents = $template->decorate($xhtml_document->save(), $this->options);
$rst->logStats(null, $this->getLogger());
} catch (\Exception $e) {
$rst->logStats($e, $this->getLogger());
continue;
}
$result[$destination] = $converted_contents;
}
return $result;
} | php | protected function create(TemplateInterface $template)
{
$result = array();
/** @var File $file */
foreach ($this->fileset as $file) {
$rst = new Document($this, $file);
$destination = $this->getDestinationFilenameRelativeToProjectRoot($file);
$this->setDestinationRoot($destination);
if ($this->getLogger()) {
$this->getLogger()->info('Parsing file "' . $file->getRealPath() . '"');
}
try {
$xhtml_document = $rst->getAsXhtml();
$converted_contents = $template->decorate($xhtml_document->save(), $this->options);
$rst->logStats(null, $this->getLogger());
} catch (\Exception $e) {
$rst->logStats($e, $this->getLogger());
continue;
}
$result[$destination] = $converted_contents;
}
return $result;
} | [
"protected",
"function",
"create",
"(",
"TemplateInterface",
"$",
"template",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"/** @var File $file */",
"foreach",
"(",
"$",
"this",
"->",
"fileset",
"as",
"$",
"file",
")",
"{",
"$",
"rst",
"=",
"new",
"Document",
"(",
"$",
"this",
",",
"$",
"file",
")",
";",
"$",
"destination",
"=",
"$",
"this",
"->",
"getDestinationFilenameRelativeToProjectRoot",
"(",
"$",
"file",
")",
";",
"$",
"this",
"->",
"setDestinationRoot",
"(",
"$",
"destination",
")",
";",
"if",
"(",
"$",
"this",
"->",
"getLogger",
"(",
")",
")",
"{",
"$",
"this",
"->",
"getLogger",
"(",
")",
"->",
"info",
"(",
"'Parsing file \"'",
".",
"$",
"file",
"->",
"getRealPath",
"(",
")",
".",
"'\"'",
")",
";",
"}",
"try",
"{",
"$",
"xhtml_document",
"=",
"$",
"rst",
"->",
"getAsXhtml",
"(",
")",
";",
"$",
"converted_contents",
"=",
"$",
"template",
"->",
"decorate",
"(",
"$",
"xhtml_document",
"->",
"save",
"(",
")",
",",
"$",
"this",
"->",
"options",
")",
";",
"$",
"rst",
"->",
"logStats",
"(",
"null",
",",
"$",
"this",
"->",
"getLogger",
"(",
")",
")",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"rst",
"->",
"logStats",
"(",
"$",
"e",
",",
"$",
"this",
"->",
"getLogger",
"(",
")",
")",
";",
"continue",
";",
"}",
"$",
"result",
"[",
"$",
"destination",
"]",
"=",
"$",
"converted_contents",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | Converts the input files into one or more output files in the intended format.
This method reads the files, converts them into the correct format and returns the contents of the conversion.
The template is provided using the $template parameter and is used to decorate the individual files. It can be
obtained using the `\phpDocumentor\Plugin\Scrybe\Template\Factory` class.
@param TemplateInterface $template
@see manual://internals#build_cycle for more information regarding the build process.
@return string[]|null The contents of the resulting file(s) or null if the files are written directly to file. | [
"Converts",
"the",
"input",
"files",
"into",
"one",
"or",
"more",
"output",
"files",
"in",
"the",
"intended",
"format",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Scrybe/Converter/RestructuredText/ToHtml.php#L75-L102 |
heidelpay/PhpDoc | src/phpDocumentor/Plugin/Scrybe/Converter/RestructuredText/ToHtml.php | ToHtml.setDestinationRoot | protected function setDestinationRoot($destination)
{
$this->options['root'] = dirname($destination) != '.'
? implode('/', array_fill(0, count(explode('/', dirname($destination))), '..')) . '/'
: './';
} | php | protected function setDestinationRoot($destination)
{
$this->options['root'] = dirname($destination) != '.'
? implode('/', array_fill(0, count(explode('/', dirname($destination))), '..')) . '/'
: './';
} | [
"protected",
"function",
"setDestinationRoot",
"(",
"$",
"destination",
")",
"{",
"$",
"this",
"->",
"options",
"[",
"'root'",
"]",
"=",
"dirname",
"(",
"$",
"destination",
")",
"!=",
"'.'",
"?",
"implode",
"(",
"'/'",
",",
"array_fill",
"(",
"0",
",",
"count",
"(",
"explode",
"(",
"'/'",
",",
"dirname",
"(",
"$",
"destination",
")",
")",
")",
",",
"'..'",
")",
")",
".",
"'/'",
":",
"'./'",
";",
"}"
] | Sets the relative path to the root of the generated contents.
Basically this method takes the depth of the given destination and replaces it with `..` unless the destination
directory name is `.`.
@param string $destination The destination path relative to the target folder.
@see $options for where the 'root' variable is set.
@return void | [
"Sets",
"the",
"relative",
"path",
"to",
"the",
"root",
"of",
"the",
"generated",
"contents",
"."
] | train | https://github.com/heidelpay/PhpDoc/blob/5ac9e842cbd4cbb70900533b240c131f3515ee02/src/phpDocumentor/Plugin/Scrybe/Converter/RestructuredText/ToHtml.php#L116-L121 |
interactivesolutions/honeycomb-core | src/providers/HCRollbarServiceProvider.php | HCRollbarServiceProvider.boot | public function boot()
{
$app = $this->app;
// Listen to log messages.
$app['log']->listen(function ($level, $message, $context) use ($app) {
$app['rollbar.handler']->log($level, $message, $context);
});
} | php | public function boot()
{
$app = $this->app;
// Listen to log messages.
$app['log']->listen(function ($level, $message, $context) use ($app) {
$app['rollbar.handler']->log($level, $message, $context);
});
} | [
"public",
"function",
"boot",
"(",
")",
"{",
"$",
"app",
"=",
"$",
"this",
"->",
"app",
";",
"// Listen to log messages.",
"$",
"app",
"[",
"'log'",
"]",
"->",
"listen",
"(",
"function",
"(",
"$",
"level",
",",
"$",
"message",
",",
"$",
"context",
")",
"use",
"(",
"$",
"app",
")",
"{",
"$",
"app",
"[",
"'rollbar.handler'",
"]",
"->",
"log",
"(",
"$",
"level",
",",
"$",
"message",
",",
"$",
"context",
")",
";",
"}",
")",
";",
"}"
] | Bootstrap the application events.
@return void | [
"Bootstrap",
"the",
"application",
"events",
"."
] | train | https://github.com/interactivesolutions/honeycomb-core/blob/06b8d88bb285e73a1a286e60411ca5f41863f39f/src/providers/HCRollbarServiceProvider.php#L23-L31 |
interactivesolutions/honeycomb-core | src/providers/HCRollbarServiceProvider.php | HCRollbarServiceProvider.register | public function register()
{
$app = $this->app;
$this->app['rollbar.client'] = $this->app->share(function ($app) {
$config = $app['config']->get('services.rollbar');
Rollbar::$instance = $rollbar = new RollbarNotifier($config);
return $rollbar;
});
$this->app['rollbar.handler'] = $this->app->share(function ($app) {
$client = $app['rollbar.client'];
$level = $app['config']->get('services.rollbar.level', 'debug');
return new RollbarLogHandler($client, $app, $level);
});
// If the Rollbar client was resolved, then there is a possibility that there
// are unsent error messages in the internal queue, so let's flush them.
register_shutdown_function(function () use ($app) {
if (isset($app['rollbar.client'])) {
$app['rollbar.client']->flush();
}
});
// Register the fatal error handler.
register_shutdown_function(function () use ($app) {
if (isset($app['rollbar.client'])) {
$app->make('rollbar.client');
Rollbar::report_fatal_error();
}
});
} | php | public function register()
{
$app = $this->app;
$this->app['rollbar.client'] = $this->app->share(function ($app) {
$config = $app['config']->get('services.rollbar');
Rollbar::$instance = $rollbar = new RollbarNotifier($config);
return $rollbar;
});
$this->app['rollbar.handler'] = $this->app->share(function ($app) {
$client = $app['rollbar.client'];
$level = $app['config']->get('services.rollbar.level', 'debug');
return new RollbarLogHandler($client, $app, $level);
});
// If the Rollbar client was resolved, then there is a possibility that there
// are unsent error messages in the internal queue, so let's flush them.
register_shutdown_function(function () use ($app) {
if (isset($app['rollbar.client'])) {
$app['rollbar.client']->flush();
}
});
// Register the fatal error handler.
register_shutdown_function(function () use ($app) {
if (isset($app['rollbar.client'])) {
$app->make('rollbar.client');
Rollbar::report_fatal_error();
}
});
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"app",
"=",
"$",
"this",
"->",
"app",
";",
"$",
"this",
"->",
"app",
"[",
"'rollbar.client'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"config",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'services.rollbar'",
")",
";",
"Rollbar",
"::",
"$",
"instance",
"=",
"$",
"rollbar",
"=",
"new",
"RollbarNotifier",
"(",
"$",
"config",
")",
";",
"return",
"$",
"rollbar",
";",
"}",
")",
";",
"$",
"this",
"->",
"app",
"[",
"'rollbar.handler'",
"]",
"=",
"$",
"this",
"->",
"app",
"->",
"share",
"(",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"client",
"=",
"$",
"app",
"[",
"'rollbar.client'",
"]",
";",
"$",
"level",
"=",
"$",
"app",
"[",
"'config'",
"]",
"->",
"get",
"(",
"'services.rollbar.level'",
",",
"'debug'",
")",
";",
"return",
"new",
"RollbarLogHandler",
"(",
"$",
"client",
",",
"$",
"app",
",",
"$",
"level",
")",
";",
"}",
")",
";",
"// If the Rollbar client was resolved, then there is a possibility that there",
"// are unsent error messages in the internal queue, so let's flush them.",
"register_shutdown_function",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"app",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"app",
"[",
"'rollbar.client'",
"]",
")",
")",
"{",
"$",
"app",
"[",
"'rollbar.client'",
"]",
"->",
"flush",
"(",
")",
";",
"}",
"}",
")",
";",
"// Register the fatal error handler.",
"register_shutdown_function",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"app",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"app",
"[",
"'rollbar.client'",
"]",
")",
")",
"{",
"$",
"app",
"->",
"make",
"(",
"'rollbar.client'",
")",
";",
"Rollbar",
"::",
"report_fatal_error",
"(",
")",
";",
"}",
"}",
")",
";",
"}"
] | Register the service provider.
@return void | [
"Register",
"the",
"service",
"provider",
"."
] | train | https://github.com/interactivesolutions/honeycomb-core/blob/06b8d88bb285e73a1a286e60411ca5f41863f39f/src/providers/HCRollbarServiceProvider.php#L38-L75 |
interactivesolutions/honeycomb-core | src/models/traits/Encryptable.php | Encryptable.setAttribute | public function setAttribute(string $key, string $value)
{
if ($this->valid($key, $value)) {
$value = encrypt($value);
}
return parent::setAttribute($key, $value);
} | php | public function setAttribute(string $key, string $value)
{
if ($this->valid($key, $value)) {
$value = encrypt($value);
}
return parent::setAttribute($key, $value);
} | [
"public",
"function",
"setAttribute",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"valid",
"(",
"$",
"key",
",",
"$",
"value",
")",
")",
"{",
"$",
"value",
"=",
"encrypt",
"(",
"$",
"value",
")",
";",
"}",
"return",
"parent",
"::",
"setAttribute",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}"
] | Encrypt field value before inserting into database
@param string $key
@param string $value
@return mixed | [
"Encrypt",
"field",
"value",
"before",
"inserting",
"into",
"database"
] | train | https://github.com/interactivesolutions/honeycomb-core/blob/06b8d88bb285e73a1a286e60411ca5f41863f39f/src/models/traits/Encryptable.php#L21-L28 |
interactivesolutions/honeycomb-core | src/models/traits/Encryptable.php | Encryptable.getAttribute | public function getAttribute(string $key)
{
$value = parent::getAttribute($key);
if ($this->valid($key, $value)) {
return decrypt($value);
}
return $value;
} | php | public function getAttribute(string $key)
{
$value = parent::getAttribute($key);
if ($this->valid($key, $value)) {
return decrypt($value);
}
return $value;
} | [
"public",
"function",
"getAttribute",
"(",
"string",
"$",
"key",
")",
"{",
"$",
"value",
"=",
"parent",
"::",
"getAttribute",
"(",
"$",
"key",
")",
";",
"if",
"(",
"$",
"this",
"->",
"valid",
"(",
"$",
"key",
",",
"$",
"value",
")",
")",
"{",
"return",
"decrypt",
"(",
"$",
"value",
")",
";",
"}",
"return",
"$",
"value",
";",
"}"
] | Get decrypted field values after getting from database
@param string $key
@return mixed | [
"Get",
"decrypted",
"field",
"values",
"after",
"getting",
"from",
"database"
] | train | https://github.com/interactivesolutions/honeycomb-core/blob/06b8d88bb285e73a1a286e60411ca5f41863f39f/src/models/traits/Encryptable.php#L36-L45 |
interactivesolutions/honeycomb-core | src/models/traits/Encryptable.php | Encryptable.attributesToArray | public function attributesToArray()
{
$attributes = parent::attributesToArray();
foreach ($attributes as $key => $value) {
if ($this->valid($key, $value)) {
$attributes[$key] = decrypt($value);
}
}
return $attributes;
} | php | public function attributesToArray()
{
$attributes = parent::attributesToArray();
foreach ($attributes as $key => $value) {
if ($this->valid($key, $value)) {
$attributes[$key] = decrypt($value);
}
}
return $attributes;
} | [
"public",
"function",
"attributesToArray",
"(",
")",
"{",
"$",
"attributes",
"=",
"parent",
"::",
"attributesToArray",
"(",
")",
";",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"valid",
"(",
"$",
"key",
",",
"$",
"value",
")",
")",
"{",
"$",
"attributes",
"[",
"$",
"key",
"]",
"=",
"decrypt",
"(",
"$",
"value",
")",
";",
"}",
"}",
"return",
"$",
"attributes",
";",
"}"
] | Decrypt given attributes
@return mixed | [
"Decrypt",
"given",
"attributes"
] | train | https://github.com/interactivesolutions/honeycomb-core/blob/06b8d88bb285e73a1a286e60411ca5f41863f39f/src/models/traits/Encryptable.php#L52-L63 |
interactivesolutions/honeycomb-core | src/models/traits/Encryptable.php | Encryptable.valid | protected function valid(string $key, string $value)
{
return in_array($key, $this->encryptable) && !is_null($value) && !empty($value);
} | php | protected function valid(string $key, string $value)
{
return in_array($key, $this->encryptable) && !is_null($value) && !empty($value);
} | [
"protected",
"function",
"valid",
"(",
"string",
"$",
"key",
",",
"string",
"$",
"value",
")",
"{",
"return",
"in_array",
"(",
"$",
"key",
",",
"$",
"this",
"->",
"encryptable",
")",
"&&",
"!",
"is_null",
"(",
"$",
"value",
")",
"&&",
"!",
"empty",
"(",
"$",
"value",
")",
";",
"}"
] | Check if key and value is valid and able to crypt or decrypt
@param string $key
@param string $value
@return bool | [
"Check",
"if",
"key",
"and",
"value",
"is",
"valid",
"and",
"able",
"to",
"crypt",
"or",
"decrypt"
] | train | https://github.com/interactivesolutions/honeycomb-core/blob/06b8d88bb285e73a1a286e60411ca5f41863f39f/src/models/traits/Encryptable.php#L72-L75 |
expectation-php/expect | src/Expect.php | Expect.configure | public static function configure(Configurator $configurator = null)
{
$useConfigurator = $configurator;
if ($useConfigurator === null) {
$useConfigurator = new DefaultConfigurator();
}
self::$contextFactory = $useConfigurator->configure();
} | php | public static function configure(Configurator $configurator = null)
{
$useConfigurator = $configurator;
if ($useConfigurator === null) {
$useConfigurator = new DefaultConfigurator();
}
self::$contextFactory = $useConfigurator->configure();
} | [
"public",
"static",
"function",
"configure",
"(",
"Configurator",
"$",
"configurator",
"=",
"null",
")",
"{",
"$",
"useConfigurator",
"=",
"$",
"configurator",
";",
"if",
"(",
"$",
"useConfigurator",
"===",
"null",
")",
"{",
"$",
"useConfigurator",
"=",
"new",
"DefaultConfigurator",
"(",
")",
";",
"}",
"self",
"::",
"$",
"contextFactory",
"=",
"$",
"useConfigurator",
"->",
"configure",
"(",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/expectation-php/expect/blob/1a32c5af37f3dc8dabe4e8eedeeb21aea16ce139/src/Expect.php#L31-L39 |
hametuha/wpametu | src/WPametu/Utility/CronBase.php | CronBase.register_cron | public function register_cron() {
if ( ! wp_next_scheduled( $this->event ) ) {
wp_schedule_event( $this->start_at(), $this->schedule, $this->event, $this->args() );
}
add_action( $this->event, [ $this, 'process' ] );
} | php | public function register_cron() {
if ( ! wp_next_scheduled( $this->event ) ) {
wp_schedule_event( $this->start_at(), $this->schedule, $this->event, $this->args() );
}
add_action( $this->event, [ $this, 'process' ] );
} | [
"public",
"function",
"register_cron",
"(",
")",
"{",
"if",
"(",
"!",
"wp_next_scheduled",
"(",
"$",
"this",
"->",
"event",
")",
")",
"{",
"wp_schedule_event",
"(",
"$",
"this",
"->",
"start_at",
"(",
")",
",",
"$",
"this",
"->",
"schedule",
",",
"$",
"this",
"->",
"event",
",",
"$",
"this",
"->",
"args",
"(",
")",
")",
";",
"}",
"add_action",
"(",
"$",
"this",
"->",
"event",
",",
"[",
"$",
"this",
",",
"'process'",
"]",
")",
";",
"}"
] | Register cron event | [
"Register",
"cron",
"event"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/Utility/CronBase.php#L63-L68 |
php-lug/lug | src/Bundle/GridBundle/Form/Type/Filter/AbstractFilterType.php | AbstractFilterType.configureOptions | public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults([
'label' => function (Options $options) {
return $options['filter']->getLabel();
},
'label_prefix' => function (Options $options) {
return 'lug.filter.'.$options['filter']->getType();
},
])
->setRequired('filter')
->setAllowedTypes('filter', FilterInterface::class);
} | php | public function configureOptions(OptionsResolver $resolver)
{
$resolver
->setDefaults([
'label' => function (Options $options) {
return $options['filter']->getLabel();
},
'label_prefix' => function (Options $options) {
return 'lug.filter.'.$options['filter']->getType();
},
])
->setRequired('filter')
->setAllowedTypes('filter', FilterInterface::class);
} | [
"public",
"function",
"configureOptions",
"(",
"OptionsResolver",
"$",
"resolver",
")",
"{",
"$",
"resolver",
"->",
"setDefaults",
"(",
"[",
"'label'",
"=>",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"$",
"options",
"[",
"'filter'",
"]",
"->",
"getLabel",
"(",
")",
";",
"}",
",",
"'label_prefix'",
"=>",
"function",
"(",
"Options",
"$",
"options",
")",
"{",
"return",
"'lug.filter.'",
".",
"$",
"options",
"[",
"'filter'",
"]",
"->",
"getType",
"(",
")",
";",
"}",
",",
"]",
")",
"->",
"setRequired",
"(",
"'filter'",
")",
"->",
"setAllowedTypes",
"(",
"'filter'",
",",
"FilterInterface",
"::",
"class",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/php-lug/lug/blob/81c109f187eba0a60f17e8cc59984ebb31841db7/src/Bundle/GridBundle/Form/Type/Filter/AbstractFilterType.php#L27-L40 |
stk2k/net-driver | src/Util/CharsetUtil.php | CharsetUtil.convertEncoding | public static function convertEncoding( $str, $html_charset, $to_encoding = 'UTF-8' )
{
if (empty($html_charset)){
return $str;
}
$php_encoding = self::getPhpEncoding($html_charset);
$from_encoding = $php_encoding ? $php_encoding : 'auto';
$str = ( $from_encoding == $to_encoding ) ? $str : mb_convert_encoding( $str, $to_encoding, $from_encoding );
return $str;
} | php | public static function convertEncoding( $str, $html_charset, $to_encoding = 'UTF-8' )
{
if (empty($html_charset)){
return $str;
}
$php_encoding = self::getPhpEncoding($html_charset);
$from_encoding = $php_encoding ? $php_encoding : 'auto';
$str = ( $from_encoding == $to_encoding ) ? $str : mb_convert_encoding( $str, $to_encoding, $from_encoding );
return $str;
} | [
"public",
"static",
"function",
"convertEncoding",
"(",
"$",
"str",
",",
"$",
"html_charset",
",",
"$",
"to_encoding",
"=",
"'UTF-8'",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"html_charset",
")",
")",
"{",
"return",
"$",
"str",
";",
"}",
"$",
"php_encoding",
"=",
"self",
"::",
"getPhpEncoding",
"(",
"$",
"html_charset",
")",
";",
"$",
"from_encoding",
"=",
"$",
"php_encoding",
"?",
"$",
"php_encoding",
":",
"'auto'",
";",
"$",
"str",
"=",
"(",
"$",
"from_encoding",
"==",
"$",
"to_encoding",
")",
"?",
"$",
"str",
":",
"mb_convert_encoding",
"(",
"$",
"str",
",",
"$",
"to_encoding",
",",
"$",
"from_encoding",
")",
";",
"return",
"$",
"str",
";",
"}"
] | Convert encoding
@param string $str
@param string $html_charset
@param string $to_encoding
@return string | [
"Convert",
"encoding"
] | train | https://github.com/stk2k/net-driver/blob/75e0bc1a95ba430dd9ed9e69f6a0a5dd8f2e7b1c/src/Util/CharsetUtil.php#L13-L25 |
stk2k/net-driver | src/Util/CharsetUtil.php | CharsetUtil.detectCharset | public static function detectCharset( $body, $content_type, $default_charset )
{
// get character encoding from Content-Type header
preg_match( '@([\w/+]+)(;\s+charset=(\S+))?@i', $content_type, $matches );
$charset = isset($matches[3]) ? $matches[3] : $default_charset;
$php_encoding = $charset ? self::getPhpEncoding($charset) : null;
if ( !$php_encoding ){
$html_encoded = mb_convert_encoding( strtolower($body), 'HTML-ENTITIES', 'UTF-8' );
$doc = new \DOMDocument();
@$doc->loadHTML( $html_encoded );
$elements = $doc->getElementsByTagName( "meta" );
for($i = 0; $i < $elements->length; $i++) {
$e = $elements->item($i);
// find like: <meta charset="utf-8"/>
$node = $e->attributes->getNamedItem("charset");
if($node){
$charset = $node->nodeValue;
$php_encoding = self::getPhpEncoding($charset);
break;
}
// find like: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
$node = $e->attributes->getNamedItem("http-equiv");
if ( $node ){
if ( strcasecmp($node->nodeValue, 'content-type') == 0 ){
$node = $e->attributes->getNamedItem("content");
if( $node ){
if ( preg_match('/[\; ]charset ?\= ?([A-Za-z0-9\-\_]+)/', $node->nodeValue, $m) ){
$charset = $m[1];
$php_encoding = self::getPhpEncoding($charset);
break;
}
}
}
}
}
}
return $php_encoding;
} | php | public static function detectCharset( $body, $content_type, $default_charset )
{
// get character encoding from Content-Type header
preg_match( '@([\w/+]+)(;\s+charset=(\S+))?@i', $content_type, $matches );
$charset = isset($matches[3]) ? $matches[3] : $default_charset;
$php_encoding = $charset ? self::getPhpEncoding($charset) : null;
if ( !$php_encoding ){
$html_encoded = mb_convert_encoding( strtolower($body), 'HTML-ENTITIES', 'UTF-8' );
$doc = new \DOMDocument();
@$doc->loadHTML( $html_encoded );
$elements = $doc->getElementsByTagName( "meta" );
for($i = 0; $i < $elements->length; $i++) {
$e = $elements->item($i);
// find like: <meta charset="utf-8"/>
$node = $e->attributes->getNamedItem("charset");
if($node){
$charset = $node->nodeValue;
$php_encoding = self::getPhpEncoding($charset);
break;
}
// find like: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
$node = $e->attributes->getNamedItem("http-equiv");
if ( $node ){
if ( strcasecmp($node->nodeValue, 'content-type') == 0 ){
$node = $e->attributes->getNamedItem("content");
if( $node ){
if ( preg_match('/[\; ]charset ?\= ?([A-Za-z0-9\-\_]+)/', $node->nodeValue, $m) ){
$charset = $m[1];
$php_encoding = self::getPhpEncoding($charset);
break;
}
}
}
}
}
}
return $php_encoding;
} | [
"public",
"static",
"function",
"detectCharset",
"(",
"$",
"body",
",",
"$",
"content_type",
",",
"$",
"default_charset",
")",
"{",
"// get character encoding from Content-Type header",
"preg_match",
"(",
"'@([\\w/+]+)(;\\s+charset=(\\S+))?@i'",
",",
"$",
"content_type",
",",
"$",
"matches",
")",
";",
"$",
"charset",
"=",
"isset",
"(",
"$",
"matches",
"[",
"3",
"]",
")",
"?",
"$",
"matches",
"[",
"3",
"]",
":",
"$",
"default_charset",
";",
"$",
"php_encoding",
"=",
"$",
"charset",
"?",
"self",
"::",
"getPhpEncoding",
"(",
"$",
"charset",
")",
":",
"null",
";",
"if",
"(",
"!",
"$",
"php_encoding",
")",
"{",
"$",
"html_encoded",
"=",
"mb_convert_encoding",
"(",
"strtolower",
"(",
"$",
"body",
")",
",",
"'HTML-ENTITIES'",
",",
"'UTF-8'",
")",
";",
"$",
"doc",
"=",
"new",
"\\",
"DOMDocument",
"(",
")",
";",
"@",
"$",
"doc",
"->",
"loadHTML",
"(",
"$",
"html_encoded",
")",
";",
"$",
"elements",
"=",
"$",
"doc",
"->",
"getElementsByTagName",
"(",
"\"meta\"",
")",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"elements",
"->",
"length",
";",
"$",
"i",
"++",
")",
"{",
"$",
"e",
"=",
"$",
"elements",
"->",
"item",
"(",
"$",
"i",
")",
";",
"// find like: <meta charset=\"utf-8\"/>",
"$",
"node",
"=",
"$",
"e",
"->",
"attributes",
"->",
"getNamedItem",
"(",
"\"charset\"",
")",
";",
"if",
"(",
"$",
"node",
")",
"{",
"$",
"charset",
"=",
"$",
"node",
"->",
"nodeValue",
";",
"$",
"php_encoding",
"=",
"self",
"::",
"getPhpEncoding",
"(",
"$",
"charset",
")",
";",
"break",
";",
"}",
"// find like: <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />",
"$",
"node",
"=",
"$",
"e",
"->",
"attributes",
"->",
"getNamedItem",
"(",
"\"http-equiv\"",
")",
";",
"if",
"(",
"$",
"node",
")",
"{",
"if",
"(",
"strcasecmp",
"(",
"$",
"node",
"->",
"nodeValue",
",",
"'content-type'",
")",
"==",
"0",
")",
"{",
"$",
"node",
"=",
"$",
"e",
"->",
"attributes",
"->",
"getNamedItem",
"(",
"\"content\"",
")",
";",
"if",
"(",
"$",
"node",
")",
"{",
"if",
"(",
"preg_match",
"(",
"'/[\\; ]charset ?\\= ?([A-Za-z0-9\\-\\_]+)/'",
",",
"$",
"node",
"->",
"nodeValue",
",",
"$",
"m",
")",
")",
"{",
"$",
"charset",
"=",
"$",
"m",
"[",
"1",
"]",
";",
"$",
"php_encoding",
"=",
"self",
"::",
"getPhpEncoding",
"(",
"$",
"charset",
")",
";",
"break",
";",
"}",
"}",
"}",
"}",
"}",
"}",
"return",
"$",
"php_encoding",
";",
"}"
] | detect charset
@param string $body
@param string $content_type
@param string $default_charset
@return string | [
"detect",
"charset"
] | train | https://github.com/stk2k/net-driver/blob/75e0bc1a95ba430dd9ed9e69f6a0a5dd8f2e7b1c/src/Util/CharsetUtil.php#L36-L78 |
stk2k/net-driver | src/Util/CharsetUtil.php | CharsetUtil.getPhpEncoding | private static function getPhpEncoding( $html_charset )
{
$php_encoding = null;
switch( strtolower($html_charset) ){
case 'sjis':
case 'sjis-win':
case 'shift_jis':
case 'shift-jis':
case 'ms_kanji':
case 'csshiftjis':
case 'x-sjis':
$php_encoding = 'sjis-win';
break;
case 'euc-jp':
case 'cseucpkdfmtjapanese':
$php_encoding = 'EUC-JP';
break;
case 'jis':
$php_encoding = 'jis';
break;
case 'iso-2022-jp':
case 'csiso2022jp':
$php_encoding = 'ISO-2022-JP';
break;
case 'iso-2022-jp-2':
case 'csiso2022jp2':
$php_encoding = 'ISO-2022-JP-2';
break;
case 'utf-8':
case 'csutf8':
$php_encoding = 'UTF-8';
break;
case 'utf-16':
case 'csutf16':
$php_encoding = 'UTF-16';
break;
default:
if ( strpos($html_charset,'sjis') ){
$php_encoding = 'SJIS';
}
break;
}
return $php_encoding;
} | php | private static function getPhpEncoding( $html_charset )
{
$php_encoding = null;
switch( strtolower($html_charset) ){
case 'sjis':
case 'sjis-win':
case 'shift_jis':
case 'shift-jis':
case 'ms_kanji':
case 'csshiftjis':
case 'x-sjis':
$php_encoding = 'sjis-win';
break;
case 'euc-jp':
case 'cseucpkdfmtjapanese':
$php_encoding = 'EUC-JP';
break;
case 'jis':
$php_encoding = 'jis';
break;
case 'iso-2022-jp':
case 'csiso2022jp':
$php_encoding = 'ISO-2022-JP';
break;
case 'iso-2022-jp-2':
case 'csiso2022jp2':
$php_encoding = 'ISO-2022-JP-2';
break;
case 'utf-8':
case 'csutf8':
$php_encoding = 'UTF-8';
break;
case 'utf-16':
case 'csutf16':
$php_encoding = 'UTF-16';
break;
default:
if ( strpos($html_charset,'sjis') ){
$php_encoding = 'SJIS';
}
break;
}
return $php_encoding;
} | [
"private",
"static",
"function",
"getPhpEncoding",
"(",
"$",
"html_charset",
")",
"{",
"$",
"php_encoding",
"=",
"null",
";",
"switch",
"(",
"strtolower",
"(",
"$",
"html_charset",
")",
")",
"{",
"case",
"'sjis'",
":",
"case",
"'sjis-win'",
":",
"case",
"'shift_jis'",
":",
"case",
"'shift-jis'",
":",
"case",
"'ms_kanji'",
":",
"case",
"'csshiftjis'",
":",
"case",
"'x-sjis'",
":",
"$",
"php_encoding",
"=",
"'sjis-win'",
";",
"break",
";",
"case",
"'euc-jp'",
":",
"case",
"'cseucpkdfmtjapanese'",
":",
"$",
"php_encoding",
"=",
"'EUC-JP'",
";",
"break",
";",
"case",
"'jis'",
":",
"$",
"php_encoding",
"=",
"'jis'",
";",
"break",
";",
"case",
"'iso-2022-jp'",
":",
"case",
"'csiso2022jp'",
":",
"$",
"php_encoding",
"=",
"'ISO-2022-JP'",
";",
"break",
";",
"case",
"'iso-2022-jp-2'",
":",
"case",
"'csiso2022jp2'",
":",
"$",
"php_encoding",
"=",
"'ISO-2022-JP-2'",
";",
"break",
";",
"case",
"'utf-8'",
":",
"case",
"'csutf8'",
":",
"$",
"php_encoding",
"=",
"'UTF-8'",
";",
"break",
";",
"case",
"'utf-16'",
":",
"case",
"'csutf16'",
":",
"$",
"php_encoding",
"=",
"'UTF-16'",
";",
"break",
";",
"default",
":",
"if",
"(",
"strpos",
"(",
"$",
"html_charset",
",",
"'sjis'",
")",
")",
"{",
"$",
"php_encoding",
"=",
"'SJIS'",
";",
"}",
"break",
";",
"}",
"return",
"$",
"php_encoding",
";",
"}"
] | Get PHP character encoding
@param $html_charset
@return string | [
"Get",
"PHP",
"character",
"encoding"
] | train | https://github.com/stk2k/net-driver/blob/75e0bc1a95ba430dd9ed9e69f6a0a5dd8f2e7b1c/src/Util/CharsetUtil.php#L87-L132 |
jasny/controller | src/Controller/CheckRequest.php | CheckRequest.getLocalReferer | public function getLocalReferer()
{
$request = $this->getRequest();
$referer = $request->getHeaderLine('HTTP_REFERER');
$host = $request->getHeaderLine('HTTP_HOST');
return $referer && parse_url($referer, PHP_URL_HOST) === $host ? $referer : '';
} | php | public function getLocalReferer()
{
$request = $this->getRequest();
$referer = $request->getHeaderLine('HTTP_REFERER');
$host = $request->getHeaderLine('HTTP_HOST');
return $referer && parse_url($referer, PHP_URL_HOST) === $host ? $referer : '';
} | [
"public",
"function",
"getLocalReferer",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"getRequest",
"(",
")",
";",
"$",
"referer",
"=",
"$",
"request",
"->",
"getHeaderLine",
"(",
"'HTTP_REFERER'",
")",
";",
"$",
"host",
"=",
"$",
"request",
"->",
"getHeaderLine",
"(",
"'HTTP_HOST'",
")",
";",
"return",
"$",
"referer",
"&&",
"parse_url",
"(",
"$",
"referer",
",",
"PHP_URL_HOST",
")",
"===",
"$",
"host",
"?",
"$",
"referer",
":",
"''",
";",
"}"
] | Returns the HTTP referer if it is on the current host
@return string | [
"Returns",
"the",
"HTTP",
"referer",
"if",
"it",
"is",
"on",
"the",
"current",
"host"
] | train | https://github.com/jasny/controller/blob/28edf64343f1d8218c166c0c570128e1ee6153d8/src/Controller/CheckRequest.php#L78-L85 |
endorphin-studio/browser-detector-data | src/Storage/YamlStorage.php | YamlStorage.getConfig | public function getConfig(): array
{
if (empty($this->config)) {
$yamlParser = new Parser();
$files = $this->getFileNames();
$config = [];
foreach ($files as $file) {
$fileConfig = $yamlParser->parseFile($file);
$config = \array_merge($config, $fileConfig);
}
$this->config = $config;
}
return $this->config;
} | php | public function getConfig(): array
{
if (empty($this->config)) {
$yamlParser = new Parser();
$files = $this->getFileNames();
$config = [];
foreach ($files as $file) {
$fileConfig = $yamlParser->parseFile($file);
$config = \array_merge($config, $fileConfig);
}
$this->config = $config;
}
return $this->config;
} | [
"public",
"function",
"getConfig",
"(",
")",
":",
"array",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"config",
")",
")",
"{",
"$",
"yamlParser",
"=",
"new",
"Parser",
"(",
")",
";",
"$",
"files",
"=",
"$",
"this",
"->",
"getFileNames",
"(",
")",
";",
"$",
"config",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"files",
"as",
"$",
"file",
")",
"{",
"$",
"fileConfig",
"=",
"$",
"yamlParser",
"->",
"parseFile",
"(",
"$",
"file",
")",
";",
"$",
"config",
"=",
"\\",
"array_merge",
"(",
"$",
"config",
",",
"$",
"fileConfig",
")",
";",
"}",
"$",
"this",
"->",
"config",
"=",
"$",
"config",
";",
"}",
"return",
"$",
"this",
"->",
"config",
";",
"}"
] | Get array of Data (patterns and etc.)
@return array array of data | [
"Get",
"array",
"of",
"Data",
"(",
"patterns",
"and",
"etc",
".",
")"
] | train | https://github.com/endorphin-studio/browser-detector-data/blob/cb1ace9f52f9677616c89f3b80c5148936d47b82/src/Storage/YamlStorage.php#L27-L40 |
yawik/composer-plugin | src/Plugin.php | Plugin.getApplication | public function getApplication()
{
if (!is_object($this->application)) {
$this->application = Application::init();
}
return $this->application;
} | php | public function getApplication()
{
if (!is_object($this->application)) {
$this->application = Application::init();
}
return $this->application;
} | [
"public",
"function",
"getApplication",
"(",
")",
"{",
"if",
"(",
"!",
"is_object",
"(",
"$",
"this",
"->",
"application",
")",
")",
"{",
"$",
"this",
"->",
"application",
"=",
"Application",
"::",
"init",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"application",
";",
"}"
] | Get Yawik Application to use
@return Application|\Zend\Mvc\Application | [
"Get",
"Yawik",
"Application",
"to",
"use"
] | train | https://github.com/yawik/composer-plugin/blob/d3a45d2ab342fc0eb21e1126e8637fb7752464e4/src/Plugin.php#L127-L133 |
shabbyrobe/amiss | src/Sql/Query/Criteria.php | Criteria.setParams | public function setParams(array $args)
{
// the class name / meta has already been eaten from the args by this point
if (!isset($args[1]) && is_array($args[0])) {
// Array criteria: func(..., ['where'=>'', 'params'=>'']);
$this->populate($args[0]);
}
elseif (!is_array($args[0])) {
// Args criteria: func(..., 'a=? AND b=?', ['a', 'b']);
// Args criteria: func(..., 'a=:a AND b=:a', ['a'=>'a', 'b'=>'b']);
$this->where = $args[0];
if (isset($args[1])) {
if (!is_array($args[1])) {
throw new \InvalidArgumentException("This is no longer variadic");
}
$this->params = $args[1];
}
}
else {
throw new \InvalidArgumentException("Couldn't parse arguments");
}
} | php | public function setParams(array $args)
{
// the class name / meta has already been eaten from the args by this point
if (!isset($args[1]) && is_array($args[0])) {
// Array criteria: func(..., ['where'=>'', 'params'=>'']);
$this->populate($args[0]);
}
elseif (!is_array($args[0])) {
// Args criteria: func(..., 'a=? AND b=?', ['a', 'b']);
// Args criteria: func(..., 'a=:a AND b=:a', ['a'=>'a', 'b'=>'b']);
$this->where = $args[0];
if (isset($args[1])) {
if (!is_array($args[1])) {
throw new \InvalidArgumentException("This is no longer variadic");
}
$this->params = $args[1];
}
}
else {
throw new \InvalidArgumentException("Couldn't parse arguments");
}
} | [
"public",
"function",
"setParams",
"(",
"array",
"$",
"args",
")",
"{",
"// the class name / meta has already been eaten from the args by this point",
"if",
"(",
"!",
"isset",
"(",
"$",
"args",
"[",
"1",
"]",
")",
"&&",
"is_array",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"{",
"// Array criteria: func(..., ['where'=>'', 'params'=>'']);",
"$",
"this",
"->",
"populate",
"(",
"$",
"args",
"[",
"0",
"]",
")",
";",
"}",
"elseif",
"(",
"!",
"is_array",
"(",
"$",
"args",
"[",
"0",
"]",
")",
")",
"{",
"// Args criteria: func(..., 'a=? AND b=?', ['a', 'b']);",
"// Args criteria: func(..., 'a=:a AND b=:a', ['a'=>'a', 'b'=>'b']);",
"$",
"this",
"->",
"where",
"=",
"$",
"args",
"[",
"0",
"]",
";",
"if",
"(",
"isset",
"(",
"$",
"args",
"[",
"1",
"]",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"args",
"[",
"1",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"This is no longer variadic\"",
")",
";",
"}",
"$",
"this",
"->",
"params",
"=",
"$",
"args",
"[",
"1",
"]",
";",
"}",
"}",
"else",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Couldn't parse arguments\"",
")",
";",
"}",
"}"
] | Allows functions to have different query syntaxes:
func(..., 'pants=? AND foo=?', ['pants', 'foo'])
func(..., 'pants=:pants AND foo=:foo', array('pants'=>'pants', 'foo'=>'foo'))
func(..., array('where'=>'pants=:pants AND foo=:foo', 'params'=>array('pants'=>'pants', 'foo'=>'foo'))) | [
"Allows",
"functions",
"to",
"have",
"different",
"query",
"syntaxes",
":",
"func",
"(",
"...",
"pants",
"=",
"?",
"AND",
"foo",
"=",
"?",
"[",
"pants",
"foo",
"]",
")",
"func",
"(",
"...",
"pants",
"=",
":",
"pants",
"AND",
"foo",
"=",
":",
"foo",
"array",
"(",
"pants",
"=",
">",
"pants",
"foo",
"=",
">",
"foo",
"))",
"func",
"(",
"...",
"array",
"(",
"where",
"=",
">",
"pants",
"=",
":",
"pants",
"AND",
"foo",
"=",
":",
"foo",
"params",
"=",
">",
"array",
"(",
"pants",
"=",
">",
"pants",
"foo",
"=",
">",
"foo",
")))"
] | train | https://github.com/shabbyrobe/amiss/blob/ba261f0d1f985ed36e9fd2903ac0df86c5b9498d/src/Sql/Query/Criteria.php#L37-L60 |
fortis/silex-graphite | src/Graphite/Silex/Provider/GraphiteServiceProvider.php | GraphiteServiceProvider.register | public function register(Container $app)
{
$app['graphite'] = function (Application $app) {
$client = new GraphiteClient($app['graphite.options']);
return $client;
};
} | php | public function register(Container $app)
{
$app['graphite'] = function (Application $app) {
$client = new GraphiteClient($app['graphite.options']);
return $client;
};
} | [
"public",
"function",
"register",
"(",
"Container",
"$",
"app",
")",
"{",
"$",
"app",
"[",
"'graphite'",
"]",
"=",
"function",
"(",
"Application",
"$",
"app",
")",
"{",
"$",
"client",
"=",
"new",
"GraphiteClient",
"(",
"$",
"app",
"[",
"'graphite.options'",
"]",
")",
";",
"return",
"$",
"client",
";",
"}",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/fortis/silex-graphite/blob/1faf4b53531c62d19b281b736a1dda326e127c7f/src/Graphite/Silex/Provider/GraphiteServiceProvider.php#L22-L28 |
vaibhavpandeyvpz/sandesh | src/Stream.php | Stream.getMetadata | public function getMetadata($key = null)
{
$metadata = stream_get_meta_data($this->resource);
if ($key) {
$metadata = isset($metadata[$key]) ? $metadata[$key] : null;
}
return $metadata;
} | php | public function getMetadata($key = null)
{
$metadata = stream_get_meta_data($this->resource);
if ($key) {
$metadata = isset($metadata[$key]) ? $metadata[$key] : null;
}
return $metadata;
} | [
"public",
"function",
"getMetadata",
"(",
"$",
"key",
"=",
"null",
")",
"{",
"$",
"metadata",
"=",
"stream_get_meta_data",
"(",
"$",
"this",
"->",
"resource",
")",
";",
"if",
"(",
"$",
"key",
")",
"{",
"$",
"metadata",
"=",
"isset",
"(",
"$",
"metadata",
"[",
"$",
"key",
"]",
")",
"?",
"$",
"metadata",
"[",
"$",
"key",
"]",
":",
"null",
";",
"}",
"return",
"$",
"metadata",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/vaibhavpandeyvpz/sandesh/blob/bea2d06c7cac099ed82da973c922859de4158de0/src/Stream.php#L113-L120 |
vaibhavpandeyvpz/sandesh | src/Stream.php | Stream.getSize | public function getSize()
{
$stats = fstat($this->resource);
return isset($stats['size']) ? (int)$stats['size'] : null;
} | php | public function getSize()
{
$stats = fstat($this->resource);
return isset($stats['size']) ? (int)$stats['size'] : null;
} | [
"public",
"function",
"getSize",
"(",
")",
"{",
"$",
"stats",
"=",
"fstat",
"(",
"$",
"this",
"->",
"resource",
")",
";",
"return",
"isset",
"(",
"$",
"stats",
"[",
"'size'",
"]",
")",
"?",
"(",
"int",
")",
"$",
"stats",
"[",
"'size'",
"]",
":",
"null",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/vaibhavpandeyvpz/sandesh/blob/bea2d06c7cac099ed82da973c922859de4158de0/src/Stream.php#L125-L129 |
vaibhavpandeyvpz/sandesh | src/Stream.php | Stream.isReadable | public function isReadable()
{
if (!isset($this->resource)) {
return false;
}
$mode = $this->getMetadata('mode');
return strstr($mode, 'r') || strstr($mode, '+');
} | php | public function isReadable()
{
if (!isset($this->resource)) {
return false;
}
$mode = $this->getMetadata('mode');
return strstr($mode, 'r') || strstr($mode, '+');
} | [
"public",
"function",
"isReadable",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"resource",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"mode",
"=",
"$",
"this",
"->",
"getMetadata",
"(",
"'mode'",
")",
";",
"return",
"strstr",
"(",
"$",
"mode",
",",
"'r'",
")",
"||",
"strstr",
"(",
"$",
"mode",
",",
"'+'",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/vaibhavpandeyvpz/sandesh/blob/bea2d06c7cac099ed82da973c922859de4158de0/src/Stream.php#L134-L141 |
vaibhavpandeyvpz/sandesh | src/Stream.php | Stream.isWritable | public function isWritable()
{
if (!isset($this->resource)) {
return false;
}
$mode = $this->getMetadata('mode');
return strstr($mode, 'x')
|| strstr($mode, 'w')
|| strstr($mode, 'c')
|| strstr($mode, 'a')
|| strstr($mode, '+');
} | php | public function isWritable()
{
if (!isset($this->resource)) {
return false;
}
$mode = $this->getMetadata('mode');
return strstr($mode, 'x')
|| strstr($mode, 'w')
|| strstr($mode, 'c')
|| strstr($mode, 'a')
|| strstr($mode, '+');
} | [
"public",
"function",
"isWritable",
"(",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"resource",
")",
")",
"{",
"return",
"false",
";",
"}",
"$",
"mode",
"=",
"$",
"this",
"->",
"getMetadata",
"(",
"'mode'",
")",
";",
"return",
"strstr",
"(",
"$",
"mode",
",",
"'x'",
")",
"||",
"strstr",
"(",
"$",
"mode",
",",
"'w'",
")",
"||",
"strstr",
"(",
"$",
"mode",
",",
"'c'",
")",
"||",
"strstr",
"(",
"$",
"mode",
",",
"'a'",
")",
"||",
"strstr",
"(",
"$",
"mode",
",",
"'+'",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/vaibhavpandeyvpz/sandesh/blob/bea2d06c7cac099ed82da973c922859de4158de0/src/Stream.php#L157-L168 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.