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
|
---|---|---|---|---|---|---|---|---|---|---|
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.makeArrayOfWhere | protected function makeArrayOfWhere($array, $type)
{
$self = self::getInstance();
if (array_key_exists(0, $array)) :
foreach ($array as $a):
$make = [
'parameter' => str_replace(".", "_", $a[0]),
'column' => $a[0],
'operator' => $a[1],
'value' => (isset($a[2])) ? $a[2] : null,
];
$where = $self->makeWhere(
$make['parameter'], $make['column'], $make['operator'], $make['value']
);
$whereData = $self->makeOptionWhere(
$make['parameter'], $make['column'], $make['operator'], $make['value']
);
array_push($self->optionWhere, $type.$where);
$self->optionWhereData = array_merge(
$self->optionWhereData, [":where_{$make['parameter']}" => $whereData]
);
endforeach; else:
foreach ($array as $a => $v):
$param = str_replace(".", "_", $a);
$where = $self->makeWhere($param, $a, '=', $v);
$whereData = $self->makeOptionWhere($param, $a, '=', $v);
array_push($self->optionWhere, $type.$where);
$self->optionWhereData = array_merge($self->optionWhereData, [":where_{$param}" => $whereData]);
endforeach;
endif;
return $self;
} | php | protected function makeArrayOfWhere($array, $type)
{
$self = self::getInstance();
if (array_key_exists(0, $array)) :
foreach ($array as $a):
$make = [
'parameter' => str_replace(".", "_", $a[0]),
'column' => $a[0],
'operator' => $a[1],
'value' => (isset($a[2])) ? $a[2] : null,
];
$where = $self->makeWhere(
$make['parameter'], $make['column'], $make['operator'], $make['value']
);
$whereData = $self->makeOptionWhere(
$make['parameter'], $make['column'], $make['operator'], $make['value']
);
array_push($self->optionWhere, $type.$where);
$self->optionWhereData = array_merge(
$self->optionWhereData, [":where_{$make['parameter']}" => $whereData]
);
endforeach; else:
foreach ($array as $a => $v):
$param = str_replace(".", "_", $a);
$where = $self->makeWhere($param, $a, '=', $v);
$whereData = $self->makeOptionWhere($param, $a, '=', $v);
array_push($self->optionWhere, $type.$where);
$self->optionWhereData = array_merge($self->optionWhereData, [":where_{$param}" => $whereData]);
endforeach;
endif;
return $self;
} | [
"protected",
"function",
"makeArrayOfWhere",
"(",
"$",
"array",
",",
"$",
"type",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"if",
"(",
"array_key_exists",
"(",
"0",
",",
"$",
"array",
")",
")",
":",
"foreach",
"(",
"$",
"array",
"as",
"$",
"a",
")",
":",
"$",
"make",
"=",
"[",
"'parameter'",
"=>",
"str_replace",
"(",
"\".\"",
",",
"\"_\"",
",",
"$",
"a",
"[",
"0",
"]",
")",
",",
"'column'",
"=>",
"$",
"a",
"[",
"0",
"]",
",",
"'operator'",
"=>",
"$",
"a",
"[",
"1",
"]",
",",
"'value'",
"=>",
"(",
"isset",
"(",
"$",
"a",
"[",
"2",
"]",
")",
")",
"?",
"$",
"a",
"[",
"2",
"]",
":",
"null",
",",
"]",
";",
"$",
"where",
"=",
"$",
"self",
"->",
"makeWhere",
"(",
"$",
"make",
"[",
"'parameter'",
"]",
",",
"$",
"make",
"[",
"'column'",
"]",
",",
"$",
"make",
"[",
"'operator'",
"]",
",",
"$",
"make",
"[",
"'value'",
"]",
")",
";",
"$",
"whereData",
"=",
"$",
"self",
"->",
"makeOptionWhere",
"(",
"$",
"make",
"[",
"'parameter'",
"]",
",",
"$",
"make",
"[",
"'column'",
"]",
",",
"$",
"make",
"[",
"'operator'",
"]",
",",
"$",
"make",
"[",
"'value'",
"]",
")",
";",
"array_push",
"(",
"$",
"self",
"->",
"optionWhere",
",",
"$",
"type",
".",
"$",
"where",
")",
";",
"$",
"self",
"->",
"optionWhereData",
"=",
"array_merge",
"(",
"$",
"self",
"->",
"optionWhereData",
",",
"[",
"\":where_{$make['parameter']}\"",
"=>",
"$",
"whereData",
"]",
")",
";",
"endforeach",
";",
"else",
":",
"foreach",
"(",
"$",
"array",
"as",
"$",
"a",
"=>",
"$",
"v",
")",
":",
"$",
"param",
"=",
"str_replace",
"(",
"\".\"",
",",
"\"_\"",
",",
"$",
"a",
")",
";",
"$",
"where",
"=",
"$",
"self",
"->",
"makeWhere",
"(",
"$",
"param",
",",
"$",
"a",
",",
"'='",
",",
"$",
"v",
")",
";",
"$",
"whereData",
"=",
"$",
"self",
"->",
"makeOptionWhere",
"(",
"$",
"param",
",",
"$",
"a",
",",
"'='",
",",
"$",
"v",
")",
";",
"array_push",
"(",
"$",
"self",
"->",
"optionWhere",
",",
"$",
"type",
".",
"$",
"where",
")",
";",
"$",
"self",
"->",
"optionWhereData",
"=",
"array_merge",
"(",
"$",
"self",
"->",
"optionWhereData",
",",
"[",
"\":where_{$param}\"",
"=>",
"$",
"whereData",
"]",
")",
";",
"endforeach",
";",
"endif",
";",
"return",
"$",
"self",
";",
"}"
] | Make Where Array
@param array $array
@param string $type
@return Instance | [
"Make",
"Where",
"Array"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L264-L306 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.makeStringOfWhere | protected function makeStringOfWhere($column, $operator = null, $value = null, $type)
{
$self = self::getInstance();
$param = str_replace(".", "_", $column); // remove table seperator for parameter
$where = $self->makeWhere($param, $column, $operator, $value);
$whereData = $self->makeOptionWhere($param, $column, $operator, $value);
array_push($self->optionWhere, $type.$where);
$self->optionWhereData = array_merge($self->optionWhereData, [":where_{$param}" => $whereData]);
return $self;
} | php | protected function makeStringOfWhere($column, $operator = null, $value = null, $type)
{
$self = self::getInstance();
$param = str_replace(".", "_", $column); // remove table seperator for parameter
$where = $self->makeWhere($param, $column, $operator, $value);
$whereData = $self->makeOptionWhere($param, $column, $operator, $value);
array_push($self->optionWhere, $type.$where);
$self->optionWhereData = array_merge($self->optionWhereData, [":where_{$param}" => $whereData]);
return $self;
} | [
"protected",
"function",
"makeStringOfWhere",
"(",
"$",
"column",
",",
"$",
"operator",
"=",
"null",
",",
"$",
"value",
"=",
"null",
",",
"$",
"type",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"param",
"=",
"str_replace",
"(",
"\".\"",
",",
"\"_\"",
",",
"$",
"column",
")",
";",
"// remove table seperator for parameter",
"$",
"where",
"=",
"$",
"self",
"->",
"makeWhere",
"(",
"$",
"param",
",",
"$",
"column",
",",
"$",
"operator",
",",
"$",
"value",
")",
";",
"$",
"whereData",
"=",
"$",
"self",
"->",
"makeOptionWhere",
"(",
"$",
"param",
",",
"$",
"column",
",",
"$",
"operator",
",",
"$",
"value",
")",
";",
"array_push",
"(",
"$",
"self",
"->",
"optionWhere",
",",
"$",
"type",
".",
"$",
"where",
")",
";",
"$",
"self",
"->",
"optionWhereData",
"=",
"array_merge",
"(",
"$",
"self",
"->",
"optionWhereData",
",",
"[",
"\":where_{$param}\"",
"=>",
"$",
"whereData",
"]",
")",
";",
"return",
"$",
"self",
";",
"}"
] | Make String Where
@return Instance | [
"Make",
"String",
"Where"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L313-L325 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.whereExecute | protected static function whereExecute($column, $operator, $value, $type)
{
$self = self::getInstance();
if (is_array($column)) {
return $self->makeArrayOfWhere($column, $type);
} else {
return $self->makeStringOfWhere($column, $operator, $value, $type);
}
return $self;
} | php | protected static function whereExecute($column, $operator, $value, $type)
{
$self = self::getInstance();
if (is_array($column)) {
return $self->makeArrayOfWhere($column, $type);
} else {
return $self->makeStringOfWhere($column, $operator, $value, $type);
}
return $self;
} | [
"protected",
"static",
"function",
"whereExecute",
"(",
"$",
"column",
",",
"$",
"operator",
",",
"$",
"value",
",",
"$",
"type",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"if",
"(",
"is_array",
"(",
"$",
"column",
")",
")",
"{",
"return",
"$",
"self",
"->",
"makeArrayOfWhere",
"(",
"$",
"column",
",",
"$",
"type",
")",
";",
"}",
"else",
"{",
"return",
"$",
"self",
"->",
"makeStringOfWhere",
"(",
"$",
"column",
",",
"$",
"operator",
",",
"$",
"value",
",",
"$",
"type",
")",
";",
"}",
"return",
"$",
"self",
";",
"}"
] | Check Where
@return Instance | [
"Check",
"Where"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L332-L343 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.makeIncreDecrement | protected function makeIncreDecrement($column, $value = null, $where = [], $operator)
{
$self = self::getInstance();
$table = $self->table_name;
$val = (!empty($value)) ? (int) $value : 1;
if (!empty($where)) {
$self = $self->where($where);
}
$statement = "UPDATE {$table} SET {$column} = {$column} {$operator} {$val}";
return $self->exec($statement, []);
} | php | protected function makeIncreDecrement($column, $value = null, $where = [], $operator)
{
$self = self::getInstance();
$table = $self->table_name;
$val = (!empty($value)) ? (int) $value : 1;
if (!empty($where)) {
$self = $self->where($where);
}
$statement = "UPDATE {$table} SET {$column} = {$column} {$operator} {$val}";
return $self->exec($statement, []);
} | [
"protected",
"function",
"makeIncreDecrement",
"(",
"$",
"column",
",",
"$",
"value",
"=",
"null",
",",
"$",
"where",
"=",
"[",
"]",
",",
"$",
"operator",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"table",
"=",
"$",
"self",
"->",
"table_name",
";",
"$",
"val",
"=",
"(",
"!",
"empty",
"(",
"$",
"value",
")",
")",
"?",
"(",
"int",
")",
"$",
"value",
":",
"1",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"where",
")",
")",
"{",
"$",
"self",
"=",
"$",
"self",
"->",
"where",
"(",
"$",
"where",
")",
";",
"}",
"$",
"statement",
"=",
"\"UPDATE {$table} SET {$column} = {$column} {$operator} {$val}\"",
";",
"return",
"$",
"self",
"->",
"exec",
"(",
"$",
"statement",
",",
"[",
"]",
")",
";",
"}"
] | Check Where
@return Boolean | [
"Check",
"Where"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L350-L365 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.insert | public static function insert($data)
{
$self = self::getInstance();
$table = $self->table_name;
if (isset($data[0])) {
$make = $self->makeMultipleInsert($table, $data);
$statement = $make[0];
$value = $make[1];
} else {
$newData = $self->makeInsertParameter($data);
$column = implode(",", array_keys($data));
$paramValue = implode(",", array_keys($newData));
$statement = "INSERT INTO {$table} ({$column}) VALUES({$paramValue});";
$value = $newData;
}
$execute = $self->exec($statement, $value);
return $execute;
} | php | public static function insert($data)
{
$self = self::getInstance();
$table = $self->table_name;
if (isset($data[0])) {
$make = $self->makeMultipleInsert($table, $data);
$statement = $make[0];
$value = $make[1];
} else {
$newData = $self->makeInsertParameter($data);
$column = implode(",", array_keys($data));
$paramValue = implode(",", array_keys($newData));
$statement = "INSERT INTO {$table} ({$column}) VALUES({$paramValue});";
$value = $newData;
}
$execute = $self->exec($statement, $value);
return $execute;
} | [
"public",
"static",
"function",
"insert",
"(",
"$",
"data",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"table",
"=",
"$",
"self",
"->",
"table_name",
";",
"if",
"(",
"isset",
"(",
"$",
"data",
"[",
"0",
"]",
")",
")",
"{",
"$",
"make",
"=",
"$",
"self",
"->",
"makeMultipleInsert",
"(",
"$",
"table",
",",
"$",
"data",
")",
";",
"$",
"statement",
"=",
"$",
"make",
"[",
"0",
"]",
";",
"$",
"value",
"=",
"$",
"make",
"[",
"1",
"]",
";",
"}",
"else",
"{",
"$",
"newData",
"=",
"$",
"self",
"->",
"makeInsertParameter",
"(",
"$",
"data",
")",
";",
"$",
"column",
"=",
"implode",
"(",
"\",\"",
",",
"array_keys",
"(",
"$",
"data",
")",
")",
";",
"$",
"paramValue",
"=",
"implode",
"(",
"\",\"",
",",
"array_keys",
"(",
"$",
"newData",
")",
")",
";",
"$",
"statement",
"=",
"\"INSERT INTO {$table} ({$column}) VALUES({$paramValue});\"",
";",
"$",
"value",
"=",
"$",
"newData",
";",
"}",
"$",
"execute",
"=",
"$",
"self",
"->",
"exec",
"(",
"$",
"statement",
",",
"$",
"value",
")",
";",
"return",
"$",
"execute",
";",
"}"
] | Insert & Multiple Insert
@param array $data
@return boolean | [
"Insert",
"&",
"Multiple",
"Insert"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L389-L409 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.update | public static function update($data)
{
$self = self::getInstance();
$table = $self->table_name;
$param = $self->makeUpdateParameter($data);
$value = $self->makeInsertParameter($data);
$statement = "UPDATE {$table} SET {$param} ";
$execute = $self->exec($statement, $value);
return $execute;
} | php | public static function update($data)
{
$self = self::getInstance();
$table = $self->table_name;
$param = $self->makeUpdateParameter($data);
$value = $self->makeInsertParameter($data);
$statement = "UPDATE {$table} SET {$param} ";
$execute = $self->exec($statement, $value);
return $execute;
} | [
"public",
"static",
"function",
"update",
"(",
"$",
"data",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"table",
"=",
"$",
"self",
"->",
"table_name",
";",
"$",
"param",
"=",
"$",
"self",
"->",
"makeUpdateParameter",
"(",
"$",
"data",
")",
";",
"$",
"value",
"=",
"$",
"self",
"->",
"makeInsertParameter",
"(",
"$",
"data",
")",
";",
"$",
"statement",
"=",
"\"UPDATE {$table} SET {$param} \"",
";",
"$",
"execute",
"=",
"$",
"self",
"->",
"exec",
"(",
"$",
"statement",
",",
"$",
"value",
")",
";",
"return",
"$",
"execute",
";",
"}"
] | Update Record
@param array $data
@return boolean | [
"Update",
"Record"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L417-L429 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.delete | public static function delete()
{
$self = self::getInstance();
$table = $self->table_name;
$query = "DELETE FROM {$table} ";
return $self->exec($query, []);
} | php | public static function delete()
{
$self = self::getInstance();
$table = $self->table_name;
$query = "DELETE FROM {$table} ";
return $self->exec($query, []);
} | [
"public",
"static",
"function",
"delete",
"(",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"table",
"=",
"$",
"self",
"->",
"table_name",
";",
"$",
"query",
"=",
"\"DELETE FROM {$table} \"",
";",
"return",
"$",
"self",
"->",
"exec",
"(",
"$",
"query",
",",
"[",
"]",
")",
";",
"}"
] | Delete Record
@return boolean | [
"Delete",
"Record"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L436-L444 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.join | public function join($table, $foreignKey1, $operator, $foreignKey2, $relation = "INNER")
{
$self = self::getInstance();
$self->optionJoin[] = " {$relation} JOIN {$table} ON {$foreignKey1}{$operator}{$foreignKey2}";
return $self;
} | php | public function join($table, $foreignKey1, $operator, $foreignKey2, $relation = "INNER")
{
$self = self::getInstance();
$self->optionJoin[] = " {$relation} JOIN {$table} ON {$foreignKey1}{$operator}{$foreignKey2}";
return $self;
} | [
"public",
"function",
"join",
"(",
"$",
"table",
",",
"$",
"foreignKey1",
",",
"$",
"operator",
",",
"$",
"foreignKey2",
",",
"$",
"relation",
"=",
"\"INNER\"",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"self",
"->",
"optionJoin",
"[",
"]",
"=",
"\" {$relation} JOIN {$table} ON {$foreignKey1}{$operator}{$foreignKey2}\"",
";",
"return",
"$",
"self",
";",
"}"
] | Join Option
@param string $table
@param string $foreignKey1
@param string $foreignKey2
@param string $relation
@return boolean | [
"Join",
"Option"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L455-L460 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.where | public static function where($column, $operator = null, $value = null, $type = " AND ")
{
return self::getInstance()->whereExecute($column, $operator, $value, $type);
} | php | public static function where($column, $operator = null, $value = null, $type = " AND ")
{
return self::getInstance()->whereExecute($column, $operator, $value, $type);
} | [
"public",
"static",
"function",
"where",
"(",
"$",
"column",
",",
"$",
"operator",
"=",
"null",
",",
"$",
"value",
"=",
"null",
",",
"$",
"type",
"=",
"\" AND \"",
")",
"{",
"return",
"self",
"::",
"getInstance",
"(",
")",
"->",
"whereExecute",
"(",
"$",
"column",
",",
"$",
"operator",
",",
"$",
"value",
",",
"$",
"type",
")",
";",
"}"
] | Where Option
@param string $column
@param string $operator
@param string $value
@param string $type
@return Instance | [
"Where",
"Option"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L486-L489 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.increment | public function increment($column, $value = null, $where = [], $operator = "+")
{
return self::getInstance()->makeIncreDecrement($column, $value, $where, $operator);
} | php | public function increment($column, $value = null, $where = [], $operator = "+")
{
return self::getInstance()->makeIncreDecrement($column, $value, $where, $operator);
} | [
"public",
"function",
"increment",
"(",
"$",
"column",
",",
"$",
"value",
"=",
"null",
",",
"$",
"where",
"=",
"[",
"]",
",",
"$",
"operator",
"=",
"\"+\"",
")",
"{",
"return",
"self",
"::",
"getInstance",
"(",
")",
"->",
"makeIncreDecrement",
"(",
"$",
"column",
",",
"$",
"value",
",",
"$",
"where",
",",
"$",
"operator",
")",
";",
"}"
] | Increment & Decrement
@param string $column
@param string/integer $value
@param array $where
@param string $operator
@return Instance | [
"Increment",
"&",
"Decrement"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L516-L519 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.limit | public function limit($limit, $offset = null)
{
$self = self::getInstance();
$offset = (!empty($offset)) ? 'OFFSET '.$offset : null;
$self->optionLimit = " LIMIT {$limit} ".$offset;
return $self;
} | php | public function limit($limit, $offset = null)
{
$self = self::getInstance();
$offset = (!empty($offset)) ? 'OFFSET '.$offset : null;
$self->optionLimit = " LIMIT {$limit} ".$offset;
return $self;
} | [
"public",
"function",
"limit",
"(",
"$",
"limit",
",",
"$",
"offset",
"=",
"null",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"offset",
"=",
"(",
"!",
"empty",
"(",
"$",
"offset",
")",
")",
"?",
"'OFFSET '",
".",
"$",
"offset",
":",
"null",
";",
"$",
"self",
"->",
"optionLimit",
"=",
"\" LIMIT {$limit} \"",
".",
"$",
"offset",
";",
"return",
"$",
"self",
";",
"}"
] | Limit Option
@param string || integer $limit
@param string || integer $offset
@return Instance | [
"Limit",
"Option"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L532-L539 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.get | public static function get()
{
$self = self::getInstance();
$statement = $self->makeSelect();
$execute = $self->exec($statement, []);
return $execute->fetchAll(\PDO::FETCH_CLASS);
} | php | public static function get()
{
$self = self::getInstance();
$statement = $self->makeSelect();
$execute = $self->exec($statement, []);
return $execute->fetchAll(\PDO::FETCH_CLASS);
} | [
"public",
"static",
"function",
"get",
"(",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"statement",
"=",
"$",
"self",
"->",
"makeSelect",
"(",
")",
";",
"$",
"execute",
"=",
"$",
"self",
"->",
"exec",
"(",
"$",
"statement",
",",
"[",
"]",
")",
";",
"return",
"$",
"execute",
"->",
"fetchAll",
"(",
"\\",
"PDO",
"::",
"FETCH_CLASS",
")",
";",
"}"
] | Get All Record
@return Array | [
"Get",
"All",
"Record"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L584-L592 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.first | public static function first()
{
$self = self::getInstance();
$statement = $self->makeSelect();
$execute = $self->exec($statement, []);
return $execute->fetchObject();
} | php | public static function first()
{
$self = self::getInstance();
$statement = $self->makeSelect();
$execute = $self->exec($statement, []);
return $execute->fetchObject();
} | [
"public",
"static",
"function",
"first",
"(",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"statement",
"=",
"$",
"self",
"->",
"makeSelect",
"(",
")",
";",
"$",
"execute",
"=",
"$",
"self",
"->",
"exec",
"(",
"$",
"statement",
",",
"[",
"]",
")",
";",
"return",
"$",
"execute",
"->",
"fetchObject",
"(",
")",
";",
"}"
] | Get First Record
@return Array | [
"Get",
"First",
"Record"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L607-L615 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.count | public static function count()
{
$self = self::getInstance();
$statement = $self->makeSelect();
$execute = $self->exec($statement, []);
return $execute->rowCount();
} | php | public static function count()
{
$self = self::getInstance();
$statement = $self->makeSelect();
$execute = $self->exec($statement, []);
return $execute->rowCount();
} | [
"public",
"static",
"function",
"count",
"(",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"$",
"statement",
"=",
"$",
"self",
"->",
"makeSelect",
"(",
")",
";",
"$",
"execute",
"=",
"$",
"self",
"->",
"exec",
"(",
"$",
"statement",
",",
"[",
"]",
")",
";",
"return",
"$",
"execute",
"->",
"rowCount",
"(",
")",
";",
"}"
] | Count Record
@return Array | [
"Count",
"Record"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L621-L629 |
ammarfaizi2/icetea-framework | src/System/Crayner/Database/DB.php | DB.max | public static function max($column)
{
$self = self::getInstance();
if (empty($self->optionSelect)) {
$self->optionSelect = "MAX({$column})";
} else {
$self->optionSelect .= ",MAX({$column})";
}
$statement = $self->makeSelect();
$execute = $self->exec($statement, []);
return $execute->fetchObject();
} | php | public static function max($column)
{
$self = self::getInstance();
if (empty($self->optionSelect)) {
$self->optionSelect = "MAX({$column})";
} else {
$self->optionSelect .= ",MAX({$column})";
}
$statement = $self->makeSelect();
$execute = $self->exec($statement, []);
return $execute->fetchObject();
} | [
"public",
"static",
"function",
"max",
"(",
"$",
"column",
")",
"{",
"$",
"self",
"=",
"self",
"::",
"getInstance",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"self",
"->",
"optionSelect",
")",
")",
"{",
"$",
"self",
"->",
"optionSelect",
"=",
"\"MAX({$column})\"",
";",
"}",
"else",
"{",
"$",
"self",
"->",
"optionSelect",
".=",
"\",MAX({$column})\"",
";",
"}",
"$",
"statement",
"=",
"$",
"self",
"->",
"makeSelect",
"(",
")",
";",
"$",
"execute",
"=",
"$",
"self",
"->",
"exec",
"(",
"$",
"statement",
",",
"[",
"]",
")",
";",
"return",
"$",
"execute",
"->",
"fetchObject",
"(",
")",
";",
"}"
] | Max Record
@return StdClass | [
"Max",
"Record"
] | train | https://github.com/ammarfaizi2/icetea-framework/blob/dedd832846c3e69b429b18b8612fae50881af180/src/System/Crayner/Database/DB.php#L635-L650 |
zodream/database | src/Engine/Mysqli.php | Mysqli.connect | protected function connect() {
if (empty($this->configs)) {
die ('Mysql host is not set');
}
$host = $this->configs['host'];
if ($this->configs['persistent'] === true) {
$host = 'p:'.$host;
}
$this->driver = new \mysqli(
$host,
$this->configs['user'],
$this->configs['password'],
$this->configs['database'],
$this->configs['port']
)
or die('There was a problem connecting to the database');
/* check connection */
/*if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}*/
if (isset($this->configs['encoding'])) {
$this->driver->set_charset($this->configs['encoding']);
}
} | php | protected function connect() {
if (empty($this->configs)) {
die ('Mysql host is not set');
}
$host = $this->configs['host'];
if ($this->configs['persistent'] === true) {
$host = 'p:'.$host;
}
$this->driver = new \mysqli(
$host,
$this->configs['user'],
$this->configs['password'],
$this->configs['database'],
$this->configs['port']
)
or die('There was a problem connecting to the database');
/* check connection */
/*if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}*/
if (isset($this->configs['encoding'])) {
$this->driver->set_charset($this->configs['encoding']);
}
} | [
"protected",
"function",
"connect",
"(",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"configs",
")",
")",
"{",
"die",
"(",
"'Mysql host is not set'",
")",
";",
"}",
"$",
"host",
"=",
"$",
"this",
"->",
"configs",
"[",
"'host'",
"]",
";",
"if",
"(",
"$",
"this",
"->",
"configs",
"[",
"'persistent'",
"]",
"===",
"true",
")",
"{",
"$",
"host",
"=",
"'p:'",
".",
"$",
"host",
";",
"}",
"$",
"this",
"->",
"driver",
"=",
"new",
"\\",
"mysqli",
"(",
"$",
"host",
",",
"$",
"this",
"->",
"configs",
"[",
"'user'",
"]",
",",
"$",
"this",
"->",
"configs",
"[",
"'password'",
"]",
",",
"$",
"this",
"->",
"configs",
"[",
"'database'",
"]",
",",
"$",
"this",
"->",
"configs",
"[",
"'port'",
"]",
")",
"or",
"die",
"(",
"'There was a problem connecting to the database'",
")",
";",
"/* check connection */",
"/*if (mysqli_connect_errno()) {\n\t\t printf(\"Connect failed: %s\\n\", mysqli_connect_error());\n\t\t exit();\n\t\t}*/",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"configs",
"[",
"'encoding'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"driver",
"->",
"set_charset",
"(",
"$",
"this",
"->",
"configs",
"[",
"'encoding'",
"]",
")",
";",
"}",
"}"
] | 连接数据库 | [
"连接数据库"
] | train | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Engine/Mysqli.php#L27-L51 |
zodream/database | src/Engine/Mysqli.php | Mysqli.bind | public function bind(array $param) {
$ref = new \ReflectionClass('mysqli_stmt');
$method = $ref->getMethod("bind_param");
$method->invokeArgs($this->result, $param);
} | php | public function bind(array $param) {
$ref = new \ReflectionClass('mysqli_stmt');
$method = $ref->getMethod("bind_param");
$method->invokeArgs($this->result, $param);
} | [
"public",
"function",
"bind",
"(",
"array",
"$",
"param",
")",
"{",
"$",
"ref",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"'mysqli_stmt'",
")",
";",
"$",
"method",
"=",
"$",
"ref",
"->",
"getMethod",
"(",
"\"bind_param\"",
")",
";",
"$",
"method",
"->",
"invokeArgs",
"(",
"$",
"this",
"->",
"result",
",",
"$",
"param",
")",
";",
"}"
] | 绑定值 只支持 ? 绑定
@param array $param | [
"绑定值",
"只支持",
"?",
"绑定"
] | train | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Engine/Mysqli.php#L65-L69 |
zodream/database | src/Engine/Mysqli.php | Mysqli.getObject | public function getObject($sql = null, $parameters = array()) {
$this->execute($sql);
$result = array();
while (!!$objs = mysqli_fetch_object($this->result) ) {
$result[] = $objs;
}
return $result;
} | php | public function getObject($sql = null, $parameters = array()) {
$this->execute($sql);
$result = array();
while (!!$objs = mysqli_fetch_object($this->result) ) {
$result[] = $objs;
}
return $result;
} | [
"public",
"function",
"getObject",
"(",
"$",
"sql",
"=",
"null",
",",
"$",
"parameters",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"execute",
"(",
"$",
"sql",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"while",
"(",
"!",
"!",
"$",
"objs",
"=",
"mysqli_fetch_object",
"(",
"$",
"this",
"->",
"result",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"objs",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | 获取Object结果集
@param string $sql
@param array $parameters
@return object | [
"获取Object结果集"
] | train | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Engine/Mysqli.php#L77-L84 |
zodream/database | src/Engine/Mysqli.php | Mysqli.getArray | public function getArray($sql = null, $parameters = array()) {
$this->execute($sql);
$result = array();
while (!!$objs = mysqli_fetch_assoc($this->result) ) {
$result[] = $objs;
}
return $result;
} | php | public function getArray($sql = null, $parameters = array()) {
$this->execute($sql);
$result = array();
while (!!$objs = mysqli_fetch_assoc($this->result) ) {
$result[] = $objs;
}
return $result;
} | [
"public",
"function",
"getArray",
"(",
"$",
"sql",
"=",
"null",
",",
"$",
"parameters",
"=",
"array",
"(",
")",
")",
"{",
"$",
"this",
"->",
"execute",
"(",
"$",
"sql",
")",
";",
"$",
"result",
"=",
"array",
"(",
")",
";",
"while",
"(",
"!",
"!",
"$",
"objs",
"=",
"mysqli_fetch_assoc",
"(",
"$",
"this",
"->",
"result",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"objs",
";",
"}",
"return",
"$",
"result",
";",
"}"
] | 获取关联数组
@param string $sql
@param array $parameters
@return array | [
"获取关联数组"
] | train | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Engine/Mysqli.php#L92-L99 |
zodream/database | src/Engine/Mysqli.php | Mysqli.execute | public function execute($sql = null, $parameters = array()) {
if (empty($sql)) {
return null;
}
$this->prepare($sql);
$this->bind($parameters);
Factory::log()->info(sprintf('MYSQLI: %s => %s', $sql,
$this->getError()));
return $this->result->execute();
} | php | public function execute($sql = null, $parameters = array()) {
if (empty($sql)) {
return null;
}
$this->prepare($sql);
$this->bind($parameters);
Factory::log()->info(sprintf('MYSQLI: %s => %s', $sql,
$this->getError()));
return $this->result->execute();
} | [
"public",
"function",
"execute",
"(",
"$",
"sql",
"=",
"null",
",",
"$",
"parameters",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"sql",
")",
")",
"{",
"return",
"null",
";",
"}",
"$",
"this",
"->",
"prepare",
"(",
"$",
"sql",
")",
";",
"$",
"this",
"->",
"bind",
"(",
"$",
"parameters",
")",
";",
"Factory",
"::",
"log",
"(",
")",
"->",
"info",
"(",
"sprintf",
"(",
"'MYSQLI: %s => %s'",
",",
"$",
"sql",
",",
"$",
"this",
"->",
"getError",
"(",
")",
")",
")",
";",
"return",
"$",
"this",
"->",
"result",
"->",
"execute",
"(",
")",
";",
"}"
] | 执行SQL语句
@access public
@param string $sql 多行查询语句
@param array $parameters
@return bool|null | [
"执行SQL语句"
] | train | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Engine/Mysqli.php#L130-L139 |
zodream/database | src/Engine/Mysqli.php | Mysqli.multi_query | public function multi_query($query) {
$result = array();
if (mysqli_multi_query($this->driver, $query)) { //执行多个查询
do {
if ($this->result = mysqli_store_result($this->driver)) {
$result[] = $this->getList();
mysqli_free_result($this->result);
}
/*if (mysqli_more_results($this_mysqli)) {
echo ("-----------------<br>"); //连个查询之间的分割线
}*/
} while (mysqli_next_result($this->driver));
}
$this->close();
return $result;
} | php | public function multi_query($query) {
$result = array();
if (mysqli_multi_query($this->driver, $query)) { //执行多个查询
do {
if ($this->result = mysqli_store_result($this->driver)) {
$result[] = $this->getList();
mysqli_free_result($this->result);
}
/*if (mysqli_more_results($this_mysqli)) {
echo ("-----------------<br>"); //连个查询之间的分割线
}*/
} while (mysqli_next_result($this->driver));
}
$this->close();
return $result;
} | [
"public",
"function",
"multi_query",
"(",
"$",
"query",
")",
"{",
"$",
"result",
"=",
"array",
"(",
")",
";",
"if",
"(",
"mysqli_multi_query",
"(",
"$",
"this",
"->",
"driver",
",",
"$",
"query",
")",
")",
"{",
"//执行多个查询",
"do",
"{",
"if",
"(",
"$",
"this",
"->",
"result",
"=",
"mysqli_store_result",
"(",
"$",
"this",
"->",
"driver",
")",
")",
"{",
"$",
"result",
"[",
"]",
"=",
"$",
"this",
"->",
"getList",
"(",
")",
";",
"mysqli_free_result",
"(",
"$",
"this",
"->",
"result",
")",
";",
"}",
"/*if (mysqli_more_results($this_mysqli)) {\n\t\t\t\t echo (\"-----------------<br>\"); //连个查询之间的分割线\n\t\t\t\t }*/",
"}",
"while",
"(",
"mysqli_next_result",
"(",
"$",
"this",
"->",
"driver",
")",
")",
";",
"}",
"$",
"this",
"->",
"close",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | 执行多行SQL语句
@access public
@param string $query 多行查询语句
@return array | [
"执行多行SQL语句"
] | train | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Engine/Mysqli.php#L149-L164 |
zodream/database | src/Engine/Mysqli.php | Mysqli.close | public function close() {
if (!empty($this->result) && !is_bool($this->result)) {
mysqli_free_result($this->result);
}
mysqli_close($this->driver);
parent::close();
} | php | public function close() {
if (!empty($this->result) && !is_bool($this->result)) {
mysqli_free_result($this->result);
}
mysqli_close($this->driver);
parent::close();
} | [
"public",
"function",
"close",
"(",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"result",
")",
"&&",
"!",
"is_bool",
"(",
"$",
"this",
"->",
"result",
")",
")",
"{",
"mysqli_free_result",
"(",
"$",
"this",
"->",
"result",
")",
";",
"}",
"mysqli_close",
"(",
"$",
"this",
"->",
"driver",
")",
";",
"parent",
"::",
"close",
"(",
")",
";",
"}"
] | 关闭和清理
@access public | [
"关闭和清理"
] | train | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Engine/Mysqli.php#L173-L179 |
zodream/database | src/Engine/Mysqli.php | Mysqli.commit | public function commit($args = array()) {
foreach ($args as $item) {
$this->driver->query($item);
}
if ($this->driver->errno > 0) {
throw new \Exception('事务执行失败!');
}
return $this->driver->commit();
} | php | public function commit($args = array()) {
foreach ($args as $item) {
$this->driver->query($item);
}
if ($this->driver->errno > 0) {
throw new \Exception('事务执行失败!');
}
return $this->driver->commit();
} | [
"public",
"function",
"commit",
"(",
"$",
"args",
"=",
"array",
"(",
")",
")",
"{",
"foreach",
"(",
"$",
"args",
"as",
"$",
"item",
")",
"{",
"$",
"this",
"->",
"driver",
"->",
"query",
"(",
"$",
"item",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"driver",
"->",
"errno",
">",
"0",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'事务执行失败!');",
"",
"",
"}",
"return",
"$",
"this",
"->",
"driver",
"->",
"commit",
"(",
")",
";",
"}"
] | 执行事务
@param array $args
@return bool
@throws \Exception | [
"执行事务"
] | train | https://github.com/zodream/database/blob/03712219c057799d07350a3a2650c55bcc92c28e/src/Engine/Mysqli.php#L203-L211 |
mossphp/moss-storage | Moss/Storage/Query/Relation/OneRelation.php | OneRelation.write | public function write(&$result)
{
$entity = $this->accessor->getPropertyValue($result, $this->definition->container());
if (empty($entity)) {
$conditions = [];
foreach ($this->definition->keys() as $local => $foreign) {
$conditions[$foreign][] = $this->accessor->getPropertyValue($result, $local);
}
$this->cleanup($this->definition->entity(), [], $conditions);
return $result;
}
$this->assertInstance($entity);
foreach ($this->definition->keys() as $local => $foreign) {
$this->accessor->setPropertyValue($entity, $foreign, $this->accessor->getPropertyValue($result, $local));
}
$this->storage->write($entity, $this->definition->entity())->execute();
$this->accessor->setPropertyValue($result, $this->definition->container(), $entity);
return $result;
} | php | public function write(&$result)
{
$entity = $this->accessor->getPropertyValue($result, $this->definition->container());
if (empty($entity)) {
$conditions = [];
foreach ($this->definition->keys() as $local => $foreign) {
$conditions[$foreign][] = $this->accessor->getPropertyValue($result, $local);
}
$this->cleanup($this->definition->entity(), [], $conditions);
return $result;
}
$this->assertInstance($entity);
foreach ($this->definition->keys() as $local => $foreign) {
$this->accessor->setPropertyValue($entity, $foreign, $this->accessor->getPropertyValue($result, $local));
}
$this->storage->write($entity, $this->definition->entity())->execute();
$this->accessor->setPropertyValue($result, $this->definition->container(), $entity);
return $result;
} | [
"public",
"function",
"write",
"(",
"&",
"$",
"result",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"accessor",
"->",
"getPropertyValue",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"definition",
"->",
"container",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"entity",
")",
")",
"{",
"$",
"conditions",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"definition",
"->",
"keys",
"(",
")",
"as",
"$",
"local",
"=>",
"$",
"foreign",
")",
"{",
"$",
"conditions",
"[",
"$",
"foreign",
"]",
"[",
"]",
"=",
"$",
"this",
"->",
"accessor",
"->",
"getPropertyValue",
"(",
"$",
"result",
",",
"$",
"local",
")",
";",
"}",
"$",
"this",
"->",
"cleanup",
"(",
"$",
"this",
"->",
"definition",
"->",
"entity",
"(",
")",
",",
"[",
"]",
",",
"$",
"conditions",
")",
";",
"return",
"$",
"result",
";",
"}",
"$",
"this",
"->",
"assertInstance",
"(",
"$",
"entity",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"definition",
"->",
"keys",
"(",
")",
"as",
"$",
"local",
"=>",
"$",
"foreign",
")",
"{",
"$",
"this",
"->",
"accessor",
"->",
"setPropertyValue",
"(",
"$",
"entity",
",",
"$",
"foreign",
",",
"$",
"this",
"->",
"accessor",
"->",
"getPropertyValue",
"(",
"$",
"result",
",",
"$",
"local",
")",
")",
";",
"}",
"$",
"this",
"->",
"storage",
"->",
"write",
"(",
"$",
"entity",
",",
"$",
"this",
"->",
"definition",
"->",
"entity",
"(",
")",
")",
"->",
"execute",
"(",
")",
";",
"$",
"this",
"->",
"accessor",
"->",
"setPropertyValue",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"definition",
"->",
"container",
"(",
")",
",",
"$",
"entity",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Executes write fro one-to-one relation
@param array|\ArrayAccess $result
@return array|\ArrayAccess
@throws RelationException | [
"Executes",
"write",
"fro",
"one",
"-",
"to",
"-",
"one",
"relation"
] | train | https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Relation/OneRelation.php#L68-L91 |
mossphp/moss-storage | Moss/Storage/Query/Relation/OneRelation.php | OneRelation.delete | public function delete(&$result)
{
$entity = $this->accessor->getPropertyValue($result, $this->definition->container());
if (empty($entity)) {
return $result;
}
$this->assertInstance($entity);
$this->storage->delete($entity, $this->definition->entity())->execute();
return $result;
} | php | public function delete(&$result)
{
$entity = $this->accessor->getPropertyValue($result, $this->definition->container());
if (empty($entity)) {
return $result;
}
$this->assertInstance($entity);
$this->storage->delete($entity, $this->definition->entity())->execute();
return $result;
} | [
"public",
"function",
"delete",
"(",
"&",
"$",
"result",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"accessor",
"->",
"getPropertyValue",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"definition",
"->",
"container",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"entity",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"this",
"->",
"assertInstance",
"(",
"$",
"entity",
")",
";",
"$",
"this",
"->",
"storage",
"->",
"delete",
"(",
"$",
"entity",
",",
"$",
"this",
"->",
"definition",
"->",
"entity",
"(",
")",
")",
"->",
"execute",
"(",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Executes delete for one-to-one relation
@param array|\ArrayAccess $result
@return array|\ArrayAccess
@throws RelationException | [
"Executes",
"delete",
"for",
"one",
"-",
"to",
"-",
"one",
"relation"
] | train | https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Relation/OneRelation.php#L101-L113 |
fuelphp-storage/session | src/Driver/Cookie.php | Cookie.read | public function read()
{
// bail out if we don't have an active session
if ($this->started)
{
// fetch the session data (is in the session cookie too)
if ($session = $this->findSessionId())
{
// and fetch the payload
$payload = $this->decrypt($session);
// make sure we got something meaningful
if (is_string($payload) and substr($payload,0,2) == 'a:')
{
// unserialize it
$payload = unserialize($payload);
// restore the session id if needed
if (isset($payload['security']['id']))
{
$this->sessionId = $payload['security']['id'];
}
// verify and process the payload
return $this->processPayload($payload);
}
}
}
// no session started, or no valid session data present
return false;
} | php | public function read()
{
// bail out if we don't have an active session
if ($this->started)
{
// fetch the session data (is in the session cookie too)
if ($session = $this->findSessionId())
{
// and fetch the payload
$payload = $this->decrypt($session);
// make sure we got something meaningful
if (is_string($payload) and substr($payload,0,2) == 'a:')
{
// unserialize it
$payload = unserialize($payload);
// restore the session id if needed
if (isset($payload['security']['id']))
{
$this->sessionId = $payload['security']['id'];
}
// verify and process the payload
return $this->processPayload($payload);
}
}
}
// no session started, or no valid session data present
return false;
} | [
"public",
"function",
"read",
"(",
")",
"{",
"// bail out if we don't have an active session",
"if",
"(",
"$",
"this",
"->",
"started",
")",
"{",
"// fetch the session data (is in the session cookie too)",
"if",
"(",
"$",
"session",
"=",
"$",
"this",
"->",
"findSessionId",
"(",
")",
")",
"{",
"// and fetch the payload",
"$",
"payload",
"=",
"$",
"this",
"->",
"decrypt",
"(",
"$",
"session",
")",
";",
"// make sure we got something meaningful",
"if",
"(",
"is_string",
"(",
"$",
"payload",
")",
"and",
"substr",
"(",
"$",
"payload",
",",
"0",
",",
"2",
")",
"==",
"'a:'",
")",
"{",
"// unserialize it",
"$",
"payload",
"=",
"unserialize",
"(",
"$",
"payload",
")",
";",
"// restore the session id if needed",
"if",
"(",
"isset",
"(",
"$",
"payload",
"[",
"'security'",
"]",
"[",
"'id'",
"]",
")",
")",
"{",
"$",
"this",
"->",
"sessionId",
"=",
"$",
"payload",
"[",
"'security'",
"]",
"[",
"'id'",
"]",
";",
"}",
"// verify and process the payload",
"return",
"$",
"this",
"->",
"processPayload",
"(",
"$",
"payload",
")",
";",
"}",
"}",
"}",
"// no session started, or no valid session data present",
"return",
"false",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Driver/Cookie.php#L84-L115 |
fuelphp-storage/session | src/Driver/Cookie.php | Cookie.stop | public function stop()
{
// bail out if we don't have an active session
if ( ! $this->started)
{
return false;
}
// construct the payload
$payload = $this->encrypt(serialize($this->assemblePayload()));
// make sure it's within cookie specs
if (strlen($payload) > 4096)
{
throw new \RuntimeException('The payload of the session cookie exceeds the maximum size of 4Kb. Use a different storage driver or reduce the size of your session.');
}
// mark the session as stopped
$this->started = false;
// and set the session cookie
return $this->setCookie(
$this->name,
$payload
);
} | php | public function stop()
{
// bail out if we don't have an active session
if ( ! $this->started)
{
return false;
}
// construct the payload
$payload = $this->encrypt(serialize($this->assemblePayload()));
// make sure it's within cookie specs
if (strlen($payload) > 4096)
{
throw new \RuntimeException('The payload of the session cookie exceeds the maximum size of 4Kb. Use a different storage driver or reduce the size of your session.');
}
// mark the session as stopped
$this->started = false;
// and set the session cookie
return $this->setCookie(
$this->name,
$payload
);
} | [
"public",
"function",
"stop",
"(",
")",
"{",
"// bail out if we don't have an active session",
"if",
"(",
"!",
"$",
"this",
"->",
"started",
")",
"{",
"return",
"false",
";",
"}",
"// construct the payload",
"$",
"payload",
"=",
"$",
"this",
"->",
"encrypt",
"(",
"serialize",
"(",
"$",
"this",
"->",
"assemblePayload",
"(",
")",
")",
")",
";",
"// make sure it's within cookie specs",
"if",
"(",
"strlen",
"(",
"$",
"payload",
")",
">",
"4096",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'The payload of the session cookie exceeds the maximum size of 4Kb. Use a different storage driver or reduce the size of your session.'",
")",
";",
"}",
"// mark the session as stopped",
"$",
"this",
"->",
"started",
"=",
"false",
";",
"// and set the session cookie",
"return",
"$",
"this",
"->",
"setCookie",
"(",
"$",
"this",
"->",
"name",
",",
"$",
"payload",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Driver/Cookie.php#L133-L158 |
fuelphp-storage/session | src/Driver/Cookie.php | Cookie.destroy | public function destroy()
{
// we need to have a session started
if ($this->started)
{
// mark the session as stopped
$this->started = false;
// reset the session containers
$this->manager->reset();
// delete the session cookie
return $this->deleteCookie($this->name);
}
// session was not started
return false;
} | php | public function destroy()
{
// we need to have a session started
if ($this->started)
{
// mark the session as stopped
$this->started = false;
// reset the session containers
$this->manager->reset();
// delete the session cookie
return $this->deleteCookie($this->name);
}
// session was not started
return false;
} | [
"public",
"function",
"destroy",
"(",
")",
"{",
"// we need to have a session started",
"if",
"(",
"$",
"this",
"->",
"started",
")",
"{",
"// mark the session as stopped",
"$",
"this",
"->",
"started",
"=",
"false",
";",
"// reset the session containers",
"$",
"this",
"->",
"manager",
"->",
"reset",
"(",
")",
";",
"// delete the session cookie",
"return",
"$",
"this",
"->",
"deleteCookie",
"(",
"$",
"this",
"->",
"name",
")",
";",
"}",
"// session was not started",
"return",
"false",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Driver/Cookie.php#L171-L188 |
fuelphp-storage/session | src/Driver/Cookie.php | Cookie.encrypt | protected function encrypt($string)
{
// only if we want the cookie to be encrypted
if ($this->config['cookie']['encrypt_cookie'])
{
// we require the mcrypt PECL extension for this
if ( ! function_exists('mcrypt_encrypt'))
{
throw new \BadMethodCallException('The Session Cookie driver requires the PHP mcrypt extension to be installed.');
}
// create the encyption key
$key = hash('SHA256', $this->config['cookie']['crypt_key'], true);
// create the IV
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
if (strlen($iv_base64 = rtrim(base64_encode($iv), '=')) != 22)
{
// invalid IV
return false;
}
// construct the encrypted payload
$string = $iv_base64.base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $string.md5($string), MCRYPT_MODE_CBC, $iv));
}
return $string;
} | php | protected function encrypt($string)
{
// only if we want the cookie to be encrypted
if ($this->config['cookie']['encrypt_cookie'])
{
// we require the mcrypt PECL extension for this
if ( ! function_exists('mcrypt_encrypt'))
{
throw new \BadMethodCallException('The Session Cookie driver requires the PHP mcrypt extension to be installed.');
}
// create the encyption key
$key = hash('SHA256', $this->config['cookie']['crypt_key'], true);
// create the IV
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC), MCRYPT_RAND);
if (strlen($iv_base64 = rtrim(base64_encode($iv), '=')) != 22)
{
// invalid IV
return false;
}
// construct the encrypted payload
$string = $iv_base64.base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $string.md5($string), MCRYPT_MODE_CBC, $iv));
}
return $string;
} | [
"protected",
"function",
"encrypt",
"(",
"$",
"string",
")",
"{",
"// only if we want the cookie to be encrypted",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'cookie'",
"]",
"[",
"'encrypt_cookie'",
"]",
")",
"{",
"// we require the mcrypt PECL extension for this",
"if",
"(",
"!",
"function_exists",
"(",
"'mcrypt_encrypt'",
")",
")",
"{",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"'The Session Cookie driver requires the PHP mcrypt extension to be installed.'",
")",
";",
"}",
"// create the encyption key",
"$",
"key",
"=",
"hash",
"(",
"'SHA256'",
",",
"$",
"this",
"->",
"config",
"[",
"'cookie'",
"]",
"[",
"'crypt_key'",
"]",
",",
"true",
")",
";",
"// create the IV",
"$",
"iv",
"=",
"mcrypt_create_iv",
"(",
"mcrypt_get_iv_size",
"(",
"MCRYPT_RIJNDAEL_128",
",",
"MCRYPT_MODE_CBC",
")",
",",
"MCRYPT_RAND",
")",
";",
"if",
"(",
"strlen",
"(",
"$",
"iv_base64",
"=",
"rtrim",
"(",
"base64_encode",
"(",
"$",
"iv",
")",
",",
"'='",
")",
")",
"!=",
"22",
")",
"{",
"// invalid IV",
"return",
"false",
";",
"}",
"// construct the encrypted payload",
"$",
"string",
"=",
"$",
"iv_base64",
".",
"base64_encode",
"(",
"mcrypt_encrypt",
"(",
"MCRYPT_RIJNDAEL_128",
",",
"$",
"key",
",",
"$",
"string",
".",
"md5",
"(",
"$",
"string",
")",
",",
"MCRYPT_MODE_CBC",
",",
"$",
"iv",
")",
")",
";",
"}",
"return",
"$",
"string",
";",
"}"
] | Encrypts a string using the crypt_key configured in the config
@param string $string
@return string
@throws \BadMethodCallException if the required mcrypt extension is not installed | [
"Encrypts",
"a",
"string",
"using",
"the",
"crypt_key",
"configured",
"in",
"the",
"config"
] | train | https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Driver/Cookie.php#L199-L226 |
fuelphp-storage/session | src/Driver/Cookie.php | Cookie.decrypt | protected function decrypt($string)
{
// only if we want the cookie to be encrypted
if ($this->config['cookie']['encrypt_cookie'])
{
// we require the mcrypt PECL extension for this
if ( ! function_exists('mcrypt_decrypt'))
{
throw new \BadMethodCallException('The Session Cookie driver requires the PHP mcrypt extension to be installed.');
}
// create the encyption key
$key = hash('SHA256', $this->config['cookie']['crypt_key'], true);
// key the IV from the payload
$iv = base64_decode(substr($string, 0, 22) . '==');
$string = substr($string, 22);
// decrypt the payload
$string = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($string), MCRYPT_MODE_CBC, $iv), "\0\4");
// split the hash from the payload
$hash = substr($string, -32);
$string = substr($string, 0, -32);
// double-check it wasn't tampered with
if (md5($string) != $hash)
{
return false;
}
}
return $string;
} | php | protected function decrypt($string)
{
// only if we want the cookie to be encrypted
if ($this->config['cookie']['encrypt_cookie'])
{
// we require the mcrypt PECL extension for this
if ( ! function_exists('mcrypt_decrypt'))
{
throw new \BadMethodCallException('The Session Cookie driver requires the PHP mcrypt extension to be installed.');
}
// create the encyption key
$key = hash('SHA256', $this->config['cookie']['crypt_key'], true);
// key the IV from the payload
$iv = base64_decode(substr($string, 0, 22) . '==');
$string = substr($string, 22);
// decrypt the payload
$string = rtrim(mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, base64_decode($string), MCRYPT_MODE_CBC, $iv), "\0\4");
// split the hash from the payload
$hash = substr($string, -32);
$string = substr($string, 0, -32);
// double-check it wasn't tampered with
if (md5($string) != $hash)
{
return false;
}
}
return $string;
} | [
"protected",
"function",
"decrypt",
"(",
"$",
"string",
")",
"{",
"// only if we want the cookie to be encrypted",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'cookie'",
"]",
"[",
"'encrypt_cookie'",
"]",
")",
"{",
"// we require the mcrypt PECL extension for this",
"if",
"(",
"!",
"function_exists",
"(",
"'mcrypt_decrypt'",
")",
")",
"{",
"throw",
"new",
"\\",
"BadMethodCallException",
"(",
"'The Session Cookie driver requires the PHP mcrypt extension to be installed.'",
")",
";",
"}",
"// create the encyption key",
"$",
"key",
"=",
"hash",
"(",
"'SHA256'",
",",
"$",
"this",
"->",
"config",
"[",
"'cookie'",
"]",
"[",
"'crypt_key'",
"]",
",",
"true",
")",
";",
"// key the IV from the payload",
"$",
"iv",
"=",
"base64_decode",
"(",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"22",
")",
".",
"'=='",
")",
";",
"$",
"string",
"=",
"substr",
"(",
"$",
"string",
",",
"22",
")",
";",
"// decrypt the payload",
"$",
"string",
"=",
"rtrim",
"(",
"mcrypt_decrypt",
"(",
"MCRYPT_RIJNDAEL_128",
",",
"$",
"key",
",",
"base64_decode",
"(",
"$",
"string",
")",
",",
"MCRYPT_MODE_CBC",
",",
"$",
"iv",
")",
",",
"\"\\0\\4\"",
")",
";",
"// split the hash from the payload",
"$",
"hash",
"=",
"substr",
"(",
"$",
"string",
",",
"-",
"32",
")",
";",
"$",
"string",
"=",
"substr",
"(",
"$",
"string",
",",
"0",
",",
"-",
"32",
")",
";",
"// double-check it wasn't tampered with",
"if",
"(",
"md5",
"(",
"$",
"string",
")",
"!=",
"$",
"hash",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"$",
"string",
";",
"}"
] | Decrypts a string using the crypt_key configured in the config
@param string $string
@return string
@throws \BadMethodCallException if the required mcrypt extension is not installed | [
"Decrypts",
"a",
"string",
"using",
"the",
"crypt_key",
"configured",
"in",
"the",
"config"
] | train | https://github.com/fuelphp-storage/session/blob/948fd2b45286e65e7fababf65de89ca6aaca3c4a/src/Driver/Cookie.php#L237-L270 |
joegreen88/zf1-component-validate | src/Zend/Validate/Db/Abstract.php | Zend_Validate_Db_Abstract.getAdapter | public function getAdapter()
{
/**
* Check for an adapter being defined. if not, fetch the default adapter.
*/
if ($this->_adapter === null) {
$this->_adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
if (null === $this->_adapter) {
throw new Zend_Validate_Exception('No database adapter present');
}
}
return $this->_adapter;
} | php | public function getAdapter()
{
/**
* Check for an adapter being defined. if not, fetch the default adapter.
*/
if ($this->_adapter === null) {
$this->_adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
if (null === $this->_adapter) {
throw new Zend_Validate_Exception('No database adapter present');
}
}
return $this->_adapter;
} | [
"public",
"function",
"getAdapter",
"(",
")",
"{",
"/**\n * Check for an adapter being defined. if not, fetch the default adapter.\n */",
"if",
"(",
"$",
"this",
"->",
"_adapter",
"===",
"null",
")",
"{",
"$",
"this",
"->",
"_adapter",
"=",
"Zend_Db_Table_Abstract",
"::",
"getDefaultAdapter",
"(",
")",
";",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"_adapter",
")",
"{",
"throw",
"new",
"Zend_Validate_Exception",
"(",
"'No database adapter present'",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_adapter",
";",
"}"
] | Returns the set adapter
@return Zend_Db_Adapter | [
"Returns",
"the",
"set",
"adapter"
] | train | https://github.com/joegreen88/zf1-component-validate/blob/88d9ea016f73d48ff0ba7d06ecbbf28951fd279e/src/Zend/Validate/Db/Abstract.php#L156-L169 |
joegreen88/zf1-component-validate | src/Zend/Validate/Db/Abstract.php | Zend_Validate_Db_Abstract.getSelect | public function getSelect()
{
if (null === $this->_select) {
$db = $this->getAdapter();
/**
* Build select object
*/
$select = new Zend_Db_Select($db);
$select->from($this->_table, array($this->_field), $this->_schema);
if ($db->supportsParameters('named')) {
$select->where($db->quoteIdentifier($this->_field, true).' = :value'); // named
} else {
$select->where($db->quoteIdentifier($this->_field, true).' = ?'); // positional
}
if ($this->_exclude !== null) {
if (is_array($this->_exclude)) {
$select->where(
$db->quoteIdentifier($this->_exclude['field'], true) .
' != ?', $this->_exclude['value']
);
} else {
$select->where($this->_exclude);
}
}
$select->limit(1);
$this->_select = $select;
}
return $this->_select;
} | php | public function getSelect()
{
if (null === $this->_select) {
$db = $this->getAdapter();
/**
* Build select object
*/
$select = new Zend_Db_Select($db);
$select->from($this->_table, array($this->_field), $this->_schema);
if ($db->supportsParameters('named')) {
$select->where($db->quoteIdentifier($this->_field, true).' = :value'); // named
} else {
$select->where($db->quoteIdentifier($this->_field, true).' = ?'); // positional
}
if ($this->_exclude !== null) {
if (is_array($this->_exclude)) {
$select->where(
$db->quoteIdentifier($this->_exclude['field'], true) .
' != ?', $this->_exclude['value']
);
} else {
$select->where($this->_exclude);
}
}
$select->limit(1);
$this->_select = $select;
}
return $this->_select;
} | [
"public",
"function",
"getSelect",
"(",
")",
"{",
"if",
"(",
"null",
"===",
"$",
"this",
"->",
"_select",
")",
"{",
"$",
"db",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
";",
"/**\n * Build select object\n */",
"$",
"select",
"=",
"new",
"Zend_Db_Select",
"(",
"$",
"db",
")",
";",
"$",
"select",
"->",
"from",
"(",
"$",
"this",
"->",
"_table",
",",
"array",
"(",
"$",
"this",
"->",
"_field",
")",
",",
"$",
"this",
"->",
"_schema",
")",
";",
"if",
"(",
"$",
"db",
"->",
"supportsParameters",
"(",
"'named'",
")",
")",
"{",
"$",
"select",
"->",
"where",
"(",
"$",
"db",
"->",
"quoteIdentifier",
"(",
"$",
"this",
"->",
"_field",
",",
"true",
")",
".",
"' = :value'",
")",
";",
"// named",
"}",
"else",
"{",
"$",
"select",
"->",
"where",
"(",
"$",
"db",
"->",
"quoteIdentifier",
"(",
"$",
"this",
"->",
"_field",
",",
"true",
")",
".",
"' = ?'",
")",
";",
"// positional",
"}",
"if",
"(",
"$",
"this",
"->",
"_exclude",
"!==",
"null",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"this",
"->",
"_exclude",
")",
")",
"{",
"$",
"select",
"->",
"where",
"(",
"$",
"db",
"->",
"quoteIdentifier",
"(",
"$",
"this",
"->",
"_exclude",
"[",
"'field'",
"]",
",",
"true",
")",
".",
"' != ?'",
",",
"$",
"this",
"->",
"_exclude",
"[",
"'value'",
"]",
")",
";",
"}",
"else",
"{",
"$",
"select",
"->",
"where",
"(",
"$",
"this",
"->",
"_exclude",
")",
";",
"}",
"}",
"$",
"select",
"->",
"limit",
"(",
"1",
")",
";",
"$",
"this",
"->",
"_select",
"=",
"$",
"select",
";",
"}",
"return",
"$",
"this",
"->",
"_select",
";",
"}"
] | Gets the select object to be used by the validator.
If no select object was supplied to the constructor,
then it will auto-generate one from the given table,
schema, field, and adapter options.
@return Zend_Db_Select The Select object which will be used | [
"Gets",
"the",
"select",
"object",
"to",
"be",
"used",
"by",
"the",
"validator",
".",
"If",
"no",
"select",
"object",
"was",
"supplied",
"to",
"the",
"constructor",
"then",
"it",
"will",
"auto",
"-",
"generate",
"one",
"from",
"the",
"given",
"table",
"schema",
"field",
"and",
"adapter",
"options",
"."
] | train | https://github.com/joegreen88/zf1-component-validate/blob/88d9ea016f73d48ff0ba7d06ecbbf28951fd279e/src/Zend/Validate/Db/Abstract.php#L300-L328 |
joegreen88/zf1-component-validate | src/Zend/Validate/Db/Abstract.php | Zend_Validate_Db_Abstract._query | protected function _query($value)
{
$select = $this->getSelect();
/**
* Run query
*/
$result = $select->getAdapter()->fetchRow(
$select,
array('value' => $value), // this should work whether db supports positional or named params
Zend_Db::FETCH_ASSOC
);
return $result;
} | php | protected function _query($value)
{
$select = $this->getSelect();
/**
* Run query
*/
$result = $select->getAdapter()->fetchRow(
$select,
array('value' => $value), // this should work whether db supports positional or named params
Zend_Db::FETCH_ASSOC
);
return $result;
} | [
"protected",
"function",
"_query",
"(",
"$",
"value",
")",
"{",
"$",
"select",
"=",
"$",
"this",
"->",
"getSelect",
"(",
")",
";",
"/**\n * Run query\n */",
"$",
"result",
"=",
"$",
"select",
"->",
"getAdapter",
"(",
")",
"->",
"fetchRow",
"(",
"$",
"select",
",",
"array",
"(",
"'value'",
"=>",
"$",
"value",
")",
",",
"// this should work whether db supports positional or named params",
"Zend_Db",
"::",
"FETCH_ASSOC",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Run query and returns matches, or null if no matches are found.
@param String $value
@return Array when matches are found. | [
"Run",
"query",
"and",
"returns",
"matches",
"or",
"null",
"if",
"no",
"matches",
"are",
"found",
"."
] | train | https://github.com/joegreen88/zf1-component-validate/blob/88d9ea016f73d48ff0ba7d06ecbbf28951fd279e/src/Zend/Validate/Db/Abstract.php#L336-L349 |
bytic/http | src/Request/RequestAwareTrait.php | RequestAwareTrait.getRequest | public function getRequest($autoInit = false)
{
$this->setAutoInitRequest($autoInit);
if ($this->request == null && $this->isAutoInitRequest()) {
$this->initRequest();
}
return $this->request;
} | php | public function getRequest($autoInit = false)
{
$this->setAutoInitRequest($autoInit);
if ($this->request == null && $this->isAutoInitRequest()) {
$this->initRequest();
}
return $this->request;
} | [
"public",
"function",
"getRequest",
"(",
"$",
"autoInit",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"setAutoInitRequest",
"(",
"$",
"autoInit",
")",
";",
"if",
"(",
"$",
"this",
"->",
"request",
"==",
"null",
"&&",
"$",
"this",
"->",
"isAutoInitRequest",
"(",
")",
")",
"{",
"$",
"this",
"->",
"initRequest",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"request",
";",
"}"
] | Get the Request.
@param bool $autoInit
@return Request | [
"Get",
"the",
"Request",
"."
] | train | https://github.com/bytic/http/blob/0d22507a8bcf05575d3d1d6c6a87c2026778c47c/src/Request/RequestAwareTrait.php#L30-L38 |
bkstg/schedule-bundle | EventSubscriber/UserMenuSubscriber.php | UserMenuSubscriber.addScheduleMenuItem | public function addScheduleMenuItem(UserMenuCollectionEvent $event): void
{
// Get the menu from the event.
$menu = $event->getMenu();
// Create a separator first.
$separator = $this->factory->createItem('schedule_separator', [
'extras' => [
'separator' => true,
'translation_domain' => false,
],
]);
$menu->addChild($separator);
// Add link to user's calendar.
$schedule = $this->factory->createItem('menu_item.my_schedule', [
'route' => 'bkstg_calendar_personal',
'extras' => [
'icon' => 'calendar',
'translation_domain' => BkstgScheduleBundle::TRANSLATION_DOMAIN,
],
]);
$menu->addChild($schedule);
} | php | public function addScheduleMenuItem(UserMenuCollectionEvent $event): void
{
// Get the menu from the event.
$menu = $event->getMenu();
// Create a separator first.
$separator = $this->factory->createItem('schedule_separator', [
'extras' => [
'separator' => true,
'translation_domain' => false,
],
]);
$menu->addChild($separator);
// Add link to user's calendar.
$schedule = $this->factory->createItem('menu_item.my_schedule', [
'route' => 'bkstg_calendar_personal',
'extras' => [
'icon' => 'calendar',
'translation_domain' => BkstgScheduleBundle::TRANSLATION_DOMAIN,
],
]);
$menu->addChild($schedule);
} | [
"public",
"function",
"addScheduleMenuItem",
"(",
"UserMenuCollectionEvent",
"$",
"event",
")",
":",
"void",
"{",
"// Get the menu from the event.",
"$",
"menu",
"=",
"$",
"event",
"->",
"getMenu",
"(",
")",
";",
"// Create a separator first.",
"$",
"separator",
"=",
"$",
"this",
"->",
"factory",
"->",
"createItem",
"(",
"'schedule_separator'",
",",
"[",
"'extras'",
"=>",
"[",
"'separator'",
"=>",
"true",
",",
"'translation_domain'",
"=>",
"false",
",",
"]",
",",
"]",
")",
";",
"$",
"menu",
"->",
"addChild",
"(",
"$",
"separator",
")",
";",
"// Add link to user's calendar.",
"$",
"schedule",
"=",
"$",
"this",
"->",
"factory",
"->",
"createItem",
"(",
"'menu_item.my_schedule'",
",",
"[",
"'route'",
"=>",
"'bkstg_calendar_personal'",
",",
"'extras'",
"=>",
"[",
"'icon'",
"=>",
"'calendar'",
",",
"'translation_domain'",
"=>",
"BkstgScheduleBundle",
"::",
"TRANSLATION_DOMAIN",
",",
"]",
",",
"]",
")",
";",
"$",
"menu",
"->",
"addChild",
"(",
"$",
"schedule",
")",
";",
"}"
] | Add the schedule items to the user menu.
@param UserMenuCollectionEvent $event The menu collection event.
@return void | [
"Add",
"the",
"schedule",
"items",
"to",
"the",
"user",
"menu",
"."
] | train | https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/EventSubscriber/UserMenuSubscriber.php#L67-L90 |
bkstg/schedule-bundle | EventSubscriber/UserMenuSubscriber.php | UserMenuSubscriber.addInvitationsMenuItem | public function addInvitationsMenuItem(UserMenuCollectionEvent $event): void
{
// Get the menu from the event.
$menu = $event->getMenu();
// Lookup and count pending invitations.
$repo = $this->em->getRepository(Invitation::class);
$user = $this->token_storage->getToken()->getUser();
$invitations = $repo->findPendingInvitations($user);
// Create the pending invitations menu link.
$invitations = $this->factory->createItem('menu_item.pending_invitations', [
'route' => 'bkstg_invitation_index',
'extras' => [
'badge_count' => count($invitations),
'translation_domain' => BkstgScheduleBundle::TRANSLATION_DOMAIN,
],
]);
$menu->addChild($invitations);
} | php | public function addInvitationsMenuItem(UserMenuCollectionEvent $event): void
{
// Get the menu from the event.
$menu = $event->getMenu();
// Lookup and count pending invitations.
$repo = $this->em->getRepository(Invitation::class);
$user = $this->token_storage->getToken()->getUser();
$invitations = $repo->findPendingInvitations($user);
// Create the pending invitations menu link.
$invitations = $this->factory->createItem('menu_item.pending_invitations', [
'route' => 'bkstg_invitation_index',
'extras' => [
'badge_count' => count($invitations),
'translation_domain' => BkstgScheduleBundle::TRANSLATION_DOMAIN,
],
]);
$menu->addChild($invitations);
} | [
"public",
"function",
"addInvitationsMenuItem",
"(",
"UserMenuCollectionEvent",
"$",
"event",
")",
":",
"void",
"{",
"// Get the menu from the event.",
"$",
"menu",
"=",
"$",
"event",
"->",
"getMenu",
"(",
")",
";",
"// Lookup and count pending invitations.",
"$",
"repo",
"=",
"$",
"this",
"->",
"em",
"->",
"getRepository",
"(",
"Invitation",
"::",
"class",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"token_storage",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"$",
"invitations",
"=",
"$",
"repo",
"->",
"findPendingInvitations",
"(",
"$",
"user",
")",
";",
"// Create the pending invitations menu link.",
"$",
"invitations",
"=",
"$",
"this",
"->",
"factory",
"->",
"createItem",
"(",
"'menu_item.pending_invitations'",
",",
"[",
"'route'",
"=>",
"'bkstg_invitation_index'",
",",
"'extras'",
"=>",
"[",
"'badge_count'",
"=>",
"count",
"(",
"$",
"invitations",
")",
",",
"'translation_domain'",
"=>",
"BkstgScheduleBundle",
"::",
"TRANSLATION_DOMAIN",
",",
"]",
",",
"]",
")",
";",
"$",
"menu",
"->",
"addChild",
"(",
"$",
"invitations",
")",
";",
"}"
] | Add invitations menu item.
@param UserMenuCollectionEvent $event The menu collection event.
@return void | [
"Add",
"invitations",
"menu",
"item",
"."
] | train | https://github.com/bkstg/schedule-bundle/blob/e64ac897aa7b28bc48319470d65de13cd4788afe/EventSubscriber/UserMenuSubscriber.php#L99-L118 |
ekyna/SettingBundle | DependencyInjection/Compiler/RegisterSchemasPass.php | RegisterSchemasPass.process | public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('ekyna_setting.schema_registry')) {
return;
}
$schemas = [];
foreach ($container->findTaggedServiceIds('ekyna_setting.schema') as $id => $attributes) {
if (!array_key_exists('namespace', $attributes[0])) {
throw new \InvalidArgumentException(sprintf('Service "%s" must define the "namespace" attribute on "ekyna_setting.schema" tags.', $id));
}
$namespace = $attributes[0]['namespace'];
$position = array_key_exists('position', $attributes[0]) ? $attributes[0]['position'] : 1;
$schemas[] = [$position, $namespace, $id];
}
usort($schemas, function($a, $b) {
if ($a[0] == $b[0]) {
return 0;
}
return ($a[0] < $b[0]) ? -1 : 1;
});
$schemaRegistry = $container->getDefinition('ekyna_setting.schema_registry');
foreach($schemas as $schema) {
$schemaRegistry->addMethodCall('registerSchema', [$schema[1], new Reference($schema[2])]);
}
} | php | public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('ekyna_setting.schema_registry')) {
return;
}
$schemas = [];
foreach ($container->findTaggedServiceIds('ekyna_setting.schema') as $id => $attributes) {
if (!array_key_exists('namespace', $attributes[0])) {
throw new \InvalidArgumentException(sprintf('Service "%s" must define the "namespace" attribute on "ekyna_setting.schema" tags.', $id));
}
$namespace = $attributes[0]['namespace'];
$position = array_key_exists('position', $attributes[0]) ? $attributes[0]['position'] : 1;
$schemas[] = [$position, $namespace, $id];
}
usort($schemas, function($a, $b) {
if ($a[0] == $b[0]) {
return 0;
}
return ($a[0] < $b[0]) ? -1 : 1;
});
$schemaRegistry = $container->getDefinition('ekyna_setting.schema_registry');
foreach($schemas as $schema) {
$schemaRegistry->addMethodCall('registerSchema', [$schema[1], new Reference($schema[2])]);
}
} | [
"public",
"function",
"process",
"(",
"ContainerBuilder",
"$",
"container",
")",
"{",
"if",
"(",
"!",
"$",
"container",
"->",
"hasDefinition",
"(",
"'ekyna_setting.schema_registry'",
")",
")",
"{",
"return",
";",
"}",
"$",
"schemas",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"container",
"->",
"findTaggedServiceIds",
"(",
"'ekyna_setting.schema'",
")",
"as",
"$",
"id",
"=>",
"$",
"attributes",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"'namespace'",
",",
"$",
"attributes",
"[",
"0",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Service \"%s\" must define the \"namespace\" attribute on \"ekyna_setting.schema\" tags.'",
",",
"$",
"id",
")",
")",
";",
"}",
"$",
"namespace",
"=",
"$",
"attributes",
"[",
"0",
"]",
"[",
"'namespace'",
"]",
";",
"$",
"position",
"=",
"array_key_exists",
"(",
"'position'",
",",
"$",
"attributes",
"[",
"0",
"]",
")",
"?",
"$",
"attributes",
"[",
"0",
"]",
"[",
"'position'",
"]",
":",
"1",
";",
"$",
"schemas",
"[",
"]",
"=",
"[",
"$",
"position",
",",
"$",
"namespace",
",",
"$",
"id",
"]",
";",
"}",
"usort",
"(",
"$",
"schemas",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"a",
"[",
"0",
"]",
"==",
"$",
"b",
"[",
"0",
"]",
")",
"{",
"return",
"0",
";",
"}",
"return",
"(",
"$",
"a",
"[",
"0",
"]",
"<",
"$",
"b",
"[",
"0",
"]",
")",
"?",
"-",
"1",
":",
"1",
";",
"}",
")",
";",
"$",
"schemaRegistry",
"=",
"$",
"container",
"->",
"getDefinition",
"(",
"'ekyna_setting.schema_registry'",
")",
";",
"foreach",
"(",
"$",
"schemas",
"as",
"$",
"schema",
")",
"{",
"$",
"schemaRegistry",
"->",
"addMethodCall",
"(",
"'registerSchema'",
",",
"[",
"$",
"schema",
"[",
"1",
"]",
",",
"new",
"Reference",
"(",
"$",
"schema",
"[",
"2",
"]",
")",
"]",
")",
";",
"}",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/ekyna/SettingBundle/blob/df58f83eb3a01ef56cd76ea73639322c581e75c1/DependencyInjection/Compiler/RegisterSchemasPass.php#L19-L48 |
foxslider/cmg-plugin | common/services/entities/SliderService.php | SliderService.delete | public function delete( $model, $config = [] ) {
// Clear all related slides
$this->slideService->deleteBySliderId( $model->id );
// Delete Slider
return parent::delete( $model, $config );
} | php | public function delete( $model, $config = [] ) {
// Clear all related slides
$this->slideService->deleteBySliderId( $model->id );
// Delete Slider
return parent::delete( $model, $config );
} | [
"public",
"function",
"delete",
"(",
"$",
"model",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"// Clear all related slides",
"$",
"this",
"->",
"slideService",
"->",
"deleteBySliderId",
"(",
"$",
"model",
"->",
"id",
")",
";",
"// Delete Slider",
"return",
"parent",
"::",
"delete",
"(",
"$",
"model",
",",
"$",
"config",
")",
";",
"}"
] | Delete ------------- | [
"Delete",
"-------------"
] | train | https://github.com/foxslider/cmg-plugin/blob/843f723ebb512ab833feff581beb9714df4e41bd/common/services/entities/SliderService.php#L257-L264 |
foxslider/cmg-plugin | common/services/entities/SliderService.php | SliderService.applyBulk | protected function applyBulk( $model, $column, $action, $target, $config = [] ) {
switch( $column ) {
case 'status': {
switch( $action ) {
case 'confirmed': {
$this->confirm( $model );
break;
}
case 'rejected': {
$this->reject( $model );
break;
}
case 'active': {
$this->approve( $model );
break;
}
case 'frozen': {
$this->freeze( $model );
break;
}
case 'blocked': {
$this->block( $model );
break;
}
}
break;
}
case 'model': {
switch( $action ) {
case 'fpage': {
$model->fullPage = true;
$model->update();
break;
}
case 'circular': {
$model->circular = true;
$model->update();
break;
}
case 'delete': {
$this->delete( $model );
break;
}
}
break;
}
}
} | php | protected function applyBulk( $model, $column, $action, $target, $config = [] ) {
switch( $column ) {
case 'status': {
switch( $action ) {
case 'confirmed': {
$this->confirm( $model );
break;
}
case 'rejected': {
$this->reject( $model );
break;
}
case 'active': {
$this->approve( $model );
break;
}
case 'frozen': {
$this->freeze( $model );
break;
}
case 'blocked': {
$this->block( $model );
break;
}
}
break;
}
case 'model': {
switch( $action ) {
case 'fpage': {
$model->fullPage = true;
$model->update();
break;
}
case 'circular': {
$model->circular = true;
$model->update();
break;
}
case 'delete': {
$this->delete( $model );
break;
}
}
break;
}
}
} | [
"protected",
"function",
"applyBulk",
"(",
"$",
"model",
",",
"$",
"column",
",",
"$",
"action",
",",
"$",
"target",
",",
"$",
"config",
"=",
"[",
"]",
")",
"{",
"switch",
"(",
"$",
"column",
")",
"{",
"case",
"'status'",
":",
"{",
"switch",
"(",
"$",
"action",
")",
"{",
"case",
"'confirmed'",
":",
"{",
"$",
"this",
"->",
"confirm",
"(",
"$",
"model",
")",
";",
"break",
";",
"}",
"case",
"'rejected'",
":",
"{",
"$",
"this",
"->",
"reject",
"(",
"$",
"model",
")",
";",
"break",
";",
"}",
"case",
"'active'",
":",
"{",
"$",
"this",
"->",
"approve",
"(",
"$",
"model",
")",
";",
"break",
";",
"}",
"case",
"'frozen'",
":",
"{",
"$",
"this",
"->",
"freeze",
"(",
"$",
"model",
")",
";",
"break",
";",
"}",
"case",
"'blocked'",
":",
"{",
"$",
"this",
"->",
"block",
"(",
"$",
"model",
")",
";",
"break",
";",
"}",
"}",
"break",
";",
"}",
"case",
"'model'",
":",
"{",
"switch",
"(",
"$",
"action",
")",
"{",
"case",
"'fpage'",
":",
"{",
"$",
"model",
"->",
"fullPage",
"=",
"true",
";",
"$",
"model",
"->",
"update",
"(",
")",
";",
"break",
";",
"}",
"case",
"'circular'",
":",
"{",
"$",
"model",
"->",
"circular",
"=",
"true",
";",
"$",
"model",
"->",
"update",
"(",
")",
";",
"break",
";",
"}",
"case",
"'delete'",
":",
"{",
"$",
"this",
"->",
"delete",
"(",
"$",
"model",
")",
";",
"break",
";",
"}",
"}",
"break",
";",
"}",
"}",
"}"
] | Bulk --------------- | [
"Bulk",
"---------------"
] | train | https://github.com/foxslider/cmg-plugin/blob/843f723ebb512ab833feff581beb9714df4e41bd/common/services/entities/SliderService.php#L268-L341 |
bseddon/XPath20 | Value/DayTimeDurationValue.php | DayTimeDurationValue.FromDuration | public static function FromDuration( $duration )
{
if ( $duration instanceof DurationValue )
$duration = $duration->getValue();
$duration->y = 0;
$duration->m = 0;
$duration->days = 0;
$dt = new \DateTimeImmutable();
$diff = $dt->add( $duration )->diff( $dt );
$diff->invert = $duration->invert;
$diff->microseconds = $duration->microseconds;
return new DayTimeDurationValue( $diff );
} | php | public static function FromDuration( $duration )
{
if ( $duration instanceof DurationValue )
$duration = $duration->getValue();
$duration->y = 0;
$duration->m = 0;
$duration->days = 0;
$dt = new \DateTimeImmutable();
$diff = $dt->add( $duration )->diff( $dt );
$diff->invert = $duration->invert;
$diff->microseconds = $duration->microseconds;
return new DayTimeDurationValue( $diff );
} | [
"public",
"static",
"function",
"FromDuration",
"(",
"$",
"duration",
")",
"{",
"if",
"(",
"$",
"duration",
"instanceof",
"DurationValue",
")",
"$",
"duration",
"=",
"$",
"duration",
"->",
"getValue",
"(",
")",
";",
"$",
"duration",
"->",
"y",
"=",
"0",
";",
"$",
"duration",
"->",
"m",
"=",
"0",
";",
"$",
"duration",
"->",
"days",
"=",
"0",
";",
"$",
"dt",
"=",
"new",
"\\",
"DateTimeImmutable",
"(",
")",
";",
"$",
"diff",
"=",
"$",
"dt",
"->",
"add",
"(",
"$",
"duration",
")",
"->",
"diff",
"(",
"$",
"dt",
")",
";",
"$",
"diff",
"->",
"invert",
"=",
"$",
"duration",
"->",
"invert",
";",
"$",
"diff",
"->",
"microseconds",
"=",
"$",
"duration",
"->",
"microseconds",
";",
"return",
"new",
"DayTimeDurationValue",
"(",
"$",
"diff",
")",
";",
"}"
] | Create a YearMonthDurationValue instance from a DurationValue or a DateInterval
@param unknown $duration | [
"Create",
"a",
"YearMonthDurationValue",
"instance",
"from",
"a",
"DurationValue",
"or",
"a",
"DateInterval"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DayTimeDurationValue.php#L73-L88 |
bseddon/XPath20 | Value/DayTimeDurationValue.php | DayTimeDurationValue.CompareTo | function CompareTo( $obj )
{
if ( ! $obj instanceof DayTimeDurationValue )
throw new ArgumentException("$obj");
/**
* @var DayTimeDurationValue $other
*/
$other = $obj;
/**
* @var DecimalValue $otherInterval
*/
$otherInterval = $other->getTotalSeconds();
/**
* @var DecimalValue $valueInterval
*/
$valueInterval = $this->getTotalSeconds();
return $valueInterval->CompareTo( $otherInterval );
} | php | function CompareTo( $obj )
{
if ( ! $obj instanceof DayTimeDurationValue )
throw new ArgumentException("$obj");
/**
* @var DayTimeDurationValue $other
*/
$other = $obj;
/**
* @var DecimalValue $otherInterval
*/
$otherInterval = $other->getTotalSeconds();
/**
* @var DecimalValue $valueInterval
*/
$valueInterval = $this->getTotalSeconds();
return $valueInterval->CompareTo( $otherInterval );
} | [
"function",
"CompareTo",
"(",
"$",
"obj",
")",
"{",
"if",
"(",
"!",
"$",
"obj",
"instanceof",
"DayTimeDurationValue",
")",
"throw",
"new",
"ArgumentException",
"(",
"\"$obj\"",
")",
";",
"/**\r\n\t\t * @var DayTimeDurationValue $other\r\n\t\t */",
"$",
"other",
"=",
"$",
"obj",
";",
"/**\r\n\t * @var DecimalValue $otherInterval\r\n\t */",
"$",
"otherInterval",
"=",
"$",
"other",
"->",
"getTotalSeconds",
"(",
")",
";",
"/**\r\n\t\t * @var DecimalValue $valueInterval\r\n\t\t */",
"$",
"valueInterval",
"=",
"$",
"this",
"->",
"getTotalSeconds",
"(",
")",
";",
"return",
"$",
"valueInterval",
"->",
"CompareTo",
"(",
"$",
"otherInterval",
")",
";",
"}"
] | CompareTo
@param object $obj
@return int | [
"CompareTo"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DayTimeDurationValue.php#L113-L132 |
bseddon/XPath20 | Value/DayTimeDurationValue.php | DayTimeDurationValue.getTotalSeconds | public function getTotalSeconds()
{
// Use the days value if it is available otherwise the months value will be used which gives
// nonsense results when the duration has been created from a day interval because the
// DateInterval assumes 30 days to every month!
// BMS 2018-03-20 Changed to look at the 'daysOnly' property and use the 'd' value if it is.
// On this date the parent::getTotalSeconds() function returns a value that is out by an hour
// when returning the interval of this expression:
// (xs:dateTime("1999-10-23T09:08:07Z") - xs:dateTime("1998-09-09T04:03:02Z"))
// which appears in test 'op-subtract-dateTimes-yielding-DTD-19' in 'dateTimesSubtract.xml'
// This interval is 408 days 22 hours 58 minutes and 59 seconds
if ( ! $this->Value->days && ( $this->Value->y || $this->Value->m ) ) return parent::getTotalSeconds();
// if ( ! $this->Value->days && ! $this->Value->daysOnly ) return parent::getTotalSeconds();
$seconds = new DecimalValue( ( $this->Value->days ? $this->Value->days : $this->Value->d ) * 86400 + $this->Value->h * 3600 + $this->Value->i * 60 + $this->Value->s );
$seconds = $seconds->Add( "0.{$this->Value->microseconds}" );
if ( $this->Value->invert )
{
$seconds = $seconds->Mul( -1 );
}
return $seconds;
} | php | public function getTotalSeconds()
{
// Use the days value if it is available otherwise the months value will be used which gives
// nonsense results when the duration has been created from a day interval because the
// DateInterval assumes 30 days to every month!
// BMS 2018-03-20 Changed to look at the 'daysOnly' property and use the 'd' value if it is.
// On this date the parent::getTotalSeconds() function returns a value that is out by an hour
// when returning the interval of this expression:
// (xs:dateTime("1999-10-23T09:08:07Z") - xs:dateTime("1998-09-09T04:03:02Z"))
// which appears in test 'op-subtract-dateTimes-yielding-DTD-19' in 'dateTimesSubtract.xml'
// This interval is 408 days 22 hours 58 minutes and 59 seconds
if ( ! $this->Value->days && ( $this->Value->y || $this->Value->m ) ) return parent::getTotalSeconds();
// if ( ! $this->Value->days && ! $this->Value->daysOnly ) return parent::getTotalSeconds();
$seconds = new DecimalValue( ( $this->Value->days ? $this->Value->days : $this->Value->d ) * 86400 + $this->Value->h * 3600 + $this->Value->i * 60 + $this->Value->s );
$seconds = $seconds->Add( "0.{$this->Value->microseconds}" );
if ( $this->Value->invert )
{
$seconds = $seconds->Mul( -1 );
}
return $seconds;
} | [
"public",
"function",
"getTotalSeconds",
"(",
")",
"{",
"// Use the days value if it is available otherwise the months value will be used which gives\r",
"// nonsense results when the duration has been created from a day interval because the\r",
"// DateInterval assumes 30 days to every month!\r",
"// BMS 2018-03-20 Changed to look at the 'daysOnly' property and use the 'd' value if it is.\r",
"//\t\t\t\t On this date the parent::getTotalSeconds() function returns a value that is out by an hour\r",
"//\t\t\t\t when returning the interval of this expression:\r",
"//\t\t\t\t (xs:dateTime(\"1999-10-23T09:08:07Z\") - xs:dateTime(\"1998-09-09T04:03:02Z\"))\r",
"//\t\t\t\t which appears in test 'op-subtract-dateTimes-yielding-DTD-19' in 'dateTimesSubtract.xml'\r",
"//\t\t\t\t This interval is 408 days 22 hours 58 minutes and 59 seconds\r",
"if",
"(",
"!",
"$",
"this",
"->",
"Value",
"->",
"days",
"&&",
"(",
"$",
"this",
"->",
"Value",
"->",
"y",
"||",
"$",
"this",
"->",
"Value",
"->",
"m",
")",
")",
"return",
"parent",
"::",
"getTotalSeconds",
"(",
")",
";",
"// if ( ! $this->Value->days && ! $this->Value->daysOnly ) return parent::getTotalSeconds();\r",
"$",
"seconds",
"=",
"new",
"DecimalValue",
"(",
"(",
"$",
"this",
"->",
"Value",
"->",
"days",
"?",
"$",
"this",
"->",
"Value",
"->",
"days",
":",
"$",
"this",
"->",
"Value",
"->",
"d",
")",
"*",
"86400",
"+",
"$",
"this",
"->",
"Value",
"->",
"h",
"*",
"3600",
"+",
"$",
"this",
"->",
"Value",
"->",
"i",
"*",
"60",
"+",
"$",
"this",
"->",
"Value",
"->",
"s",
")",
";",
"$",
"seconds",
"=",
"$",
"seconds",
"->",
"Add",
"(",
"\"0.{$this->Value->microseconds}\"",
")",
";",
"if",
"(",
"$",
"this",
"->",
"Value",
"->",
"invert",
")",
"{",
"$",
"seconds",
"=",
"$",
"seconds",
"->",
"Mul",
"(",
"-",
"1",
")",
";",
"}",
"return",
"$",
"seconds",
";",
"}"
] | Get the total number of seconds in the interval
@return DecimalValue | [
"Get",
"the",
"total",
"number",
"of",
"seconds",
"in",
"the",
"interval"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DayTimeDurationValue.php#L147-L170 |
bseddon/XPath20 | Value/DayTimeDurationValue.php | DayTimeDurationValue.Add | public function Add( $duration )
{
if ( ! $duration instanceof DurationValue )
{
throw new \InvalidArgumentException();
}
// $durationFactor = $duration->Value->invert ? -1 : 1;
// $thisFactor = $this->Value->invert ? -1 : 1;
// $thisSeconds = new DecimalValue( $this->Value->days * 86400 + $this->Value->h * 3600 + $this->Value->i * 60 + $this->Value->s );
// $thisSeconds = $thisSeconds->Add( "0." . $this->Value->microseconds );
// $thisSeconds = $thisSeconds->Mul( $thisFactor );
// $durationSeconds = new DecimalValue( $duration->Value->days * 86400 + $duration->Value->h * 3600 + $duration->Value->i * 60 + $duration->Value->s );
// $durationSeconds = $durationSeconds->Add( "0." . $duration->microseconds );
// $durationSeconds = $thisSeconds->Mul( $durationFactor );
$thisSeconds = $this->getTotalSeconds();
$durationSeconds = $duration->getTotalSeconds();
/**
* @var DecimalValue $interval
*/
$interval = $thisSeconds->Add( $durationSeconds );
$hasValue = $interval->CompareTo( 0 ) != 0;
$invert = 0 > $interval->CompareTo( 0 ) == -1;
$interval = $interval->getAbs();
$days = $interval->Div( 86400 )->getIntegerPart();
$interval = $interval->Sub( $days * 86400 );
$h = $interval->Div( 3600 )->getIntegerPart();
$interval = $interval->Sub( $h * 3600 );
$i = $interval->Div( 60 )->getIntegerPart();
$interval->Sub( $i * 60 );
$interval = $interval->Sub( $i * 60 );
$s = $interval->getIntegerPart();
$microseconds = $interval->getDecimalPart();
$specString = "P%02sDT%02sH%02sM%02sS";
$interval = sprintf( $specString, $days, $h, $i, $s );
$di = new \DateInterval( $interval );
$di->hasValue = $hasValue;
$di->invert = $invert;
$di->microseconds = $microseconds;
$this->Value = $di;
// if ( $hasValue )
// {
// $this->type = XPATH20_DURATION_TYPE_DAYTIME;
//
// }
} | php | public function Add( $duration )
{
if ( ! $duration instanceof DurationValue )
{
throw new \InvalidArgumentException();
}
// $durationFactor = $duration->Value->invert ? -1 : 1;
// $thisFactor = $this->Value->invert ? -1 : 1;
// $thisSeconds = new DecimalValue( $this->Value->days * 86400 + $this->Value->h * 3600 + $this->Value->i * 60 + $this->Value->s );
// $thisSeconds = $thisSeconds->Add( "0." . $this->Value->microseconds );
// $thisSeconds = $thisSeconds->Mul( $thisFactor );
// $durationSeconds = new DecimalValue( $duration->Value->days * 86400 + $duration->Value->h * 3600 + $duration->Value->i * 60 + $duration->Value->s );
// $durationSeconds = $durationSeconds->Add( "0." . $duration->microseconds );
// $durationSeconds = $thisSeconds->Mul( $durationFactor );
$thisSeconds = $this->getTotalSeconds();
$durationSeconds = $duration->getTotalSeconds();
/**
* @var DecimalValue $interval
*/
$interval = $thisSeconds->Add( $durationSeconds );
$hasValue = $interval->CompareTo( 0 ) != 0;
$invert = 0 > $interval->CompareTo( 0 ) == -1;
$interval = $interval->getAbs();
$days = $interval->Div( 86400 )->getIntegerPart();
$interval = $interval->Sub( $days * 86400 );
$h = $interval->Div( 3600 )->getIntegerPart();
$interval = $interval->Sub( $h * 3600 );
$i = $interval->Div( 60 )->getIntegerPart();
$interval->Sub( $i * 60 );
$interval = $interval->Sub( $i * 60 );
$s = $interval->getIntegerPart();
$microseconds = $interval->getDecimalPart();
$specString = "P%02sDT%02sH%02sM%02sS";
$interval = sprintf( $specString, $days, $h, $i, $s );
$di = new \DateInterval( $interval );
$di->hasValue = $hasValue;
$di->invert = $invert;
$di->microseconds = $microseconds;
$this->Value = $di;
// if ( $hasValue )
// {
// $this->type = XPATH20_DURATION_TYPE_DAYTIME;
//
// }
} | [
"public",
"function",
"Add",
"(",
"$",
"duration",
")",
"{",
"if",
"(",
"!",
"$",
"duration",
"instanceof",
"DurationValue",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
")",
";",
"}",
"// $durationFactor = $duration->Value->invert ? -1 : 1;\r",
"// $thisFactor = $this->Value->invert ? -1 : 1;\r",
"// $thisSeconds = new DecimalValue( $this->Value->days * 86400 + $this->Value->h * 3600 + $this->Value->i * 60 + $this->Value->s );\r",
"// $thisSeconds = $thisSeconds->Add( \"0.\" . $this->Value->microseconds );\r",
"// $thisSeconds = $thisSeconds->Mul( $thisFactor );\r",
"// $durationSeconds = new DecimalValue( $duration->Value->days * 86400 + $duration->Value->h * 3600 + $duration->Value->i * 60 + $duration->Value->s );\r",
"// $durationSeconds = $durationSeconds->Add( \"0.\" . $duration->microseconds );\r",
"// $durationSeconds = $thisSeconds->Mul( $durationFactor );\r",
"$",
"thisSeconds",
"=",
"$",
"this",
"->",
"getTotalSeconds",
"(",
")",
";",
"$",
"durationSeconds",
"=",
"$",
"duration",
"->",
"getTotalSeconds",
"(",
")",
";",
"/**\r\n\t\t * @var DecimalValue $interval\r\n\t\t */",
"$",
"interval",
"=",
"$",
"thisSeconds",
"->",
"Add",
"(",
"$",
"durationSeconds",
")",
";",
"$",
"hasValue",
"=",
"$",
"interval",
"->",
"CompareTo",
"(",
"0",
")",
"!=",
"0",
";",
"$",
"invert",
"=",
"0",
">",
"$",
"interval",
"->",
"CompareTo",
"(",
"0",
")",
"==",
"-",
"1",
";",
"$",
"interval",
"=",
"$",
"interval",
"->",
"getAbs",
"(",
")",
";",
"$",
"days",
"=",
"$",
"interval",
"->",
"Div",
"(",
"86400",
")",
"->",
"getIntegerPart",
"(",
")",
";",
"$",
"interval",
"=",
"$",
"interval",
"->",
"Sub",
"(",
"$",
"days",
"*",
"86400",
")",
";",
"$",
"h",
"=",
"$",
"interval",
"->",
"Div",
"(",
"3600",
")",
"->",
"getIntegerPart",
"(",
")",
";",
"$",
"interval",
"=",
"$",
"interval",
"->",
"Sub",
"(",
"$",
"h",
"*",
"3600",
")",
";",
"$",
"i",
"=",
"$",
"interval",
"->",
"Div",
"(",
"60",
")",
"->",
"getIntegerPart",
"(",
")",
";",
"$",
"interval",
"->",
"Sub",
"(",
"$",
"i",
"*",
"60",
")",
";",
"$",
"interval",
"=",
"$",
"interval",
"->",
"Sub",
"(",
"$",
"i",
"*",
"60",
")",
";",
"$",
"s",
"=",
"$",
"interval",
"->",
"getIntegerPart",
"(",
")",
";",
"$",
"microseconds",
"=",
"$",
"interval",
"->",
"getDecimalPart",
"(",
")",
";",
"$",
"specString",
"=",
"\"P%02sDT%02sH%02sM%02sS\"",
";",
"$",
"interval",
"=",
"sprintf",
"(",
"$",
"specString",
",",
"$",
"days",
",",
"$",
"h",
",",
"$",
"i",
",",
"$",
"s",
")",
";",
"$",
"di",
"=",
"new",
"\\",
"DateInterval",
"(",
"$",
"interval",
")",
";",
"$",
"di",
"->",
"hasValue",
"=",
"$",
"hasValue",
";",
"$",
"di",
"->",
"invert",
"=",
"$",
"invert",
";",
"$",
"di",
"->",
"microseconds",
"=",
"$",
"microseconds",
";",
"$",
"this",
"->",
"Value",
"=",
"$",
"di",
";",
"// if ( $hasValue )\r",
"// {\r",
"// \t$this->type = XPATH20_DURATION_TYPE_DAYTIME;\r",
"//\r",
"// }\r",
"}"
] | Subtract a duration from the current duration
@param DurationValue $duration | [
"Subtract",
"a",
"duration",
"from",
"the",
"current",
"duration"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DayTimeDurationValue.php#L186-L239 |
bseddon/XPath20 | Value/DayTimeDurationValue.php | DayTimeDurationValue.Multiply | public static function Multiply( $a, $b )
{
if ( ! is_numeric( $b ) )
throw new \InvalidArgumentException( "Division denominator is not a number" );
if ( is_nan( $b ) )
throw XPath2Exception::withErrorCode( "FOCA0005", Resources::FOCA0005 );
if ( $b == INF || $b == -INF )
throw XPath2Exception::withErrorCode( "FODT0002", Resources::FODT0002 );
if ( ! $a instanceof DayTimeDurationValue )
throw new ArgumentException("$a");
// Create a new interval with the multiplied days. ->days is created by the ->diff function to hold the total days.
$multipliedSeconds = $a->getTotalSeconds()->Mul( $b )->getRound(3);
$multipliedInterval = new \DateInterval("P0D");
$multipliedInterval->s = $multipliedSeconds->getIntegerPart();
$microseconds = $multipliedSeconds->getDecimalPart() + 0;
$sign = $multipliedSeconds->getIsNegative();
// Finally convert $multipliedInterval into a normalized interval
$dt = new \DateTimeImmutable();
$tz = new \DateTimeZone("Z");
$dt = $dt->setTimezone( $tz );
$diff = $dt->add( $multipliedInterval )->diff( $dt );
$diff->hasValue = $multipliedSeconds->getValue() != 0;
$diff->invert = ! $diff->invert;
$diff->microseconds = $microseconds;
// $diff->daysOnly = false;
return new DayTimeDurationValue( $diff );
} | php | public static function Multiply( $a, $b )
{
if ( ! is_numeric( $b ) )
throw new \InvalidArgumentException( "Division denominator is not a number" );
if ( is_nan( $b ) )
throw XPath2Exception::withErrorCode( "FOCA0005", Resources::FOCA0005 );
if ( $b == INF || $b == -INF )
throw XPath2Exception::withErrorCode( "FODT0002", Resources::FODT0002 );
if ( ! $a instanceof DayTimeDurationValue )
throw new ArgumentException("$a");
// Create a new interval with the multiplied days. ->days is created by the ->diff function to hold the total days.
$multipliedSeconds = $a->getTotalSeconds()->Mul( $b )->getRound(3);
$multipliedInterval = new \DateInterval("P0D");
$multipliedInterval->s = $multipliedSeconds->getIntegerPart();
$microseconds = $multipliedSeconds->getDecimalPart() + 0;
$sign = $multipliedSeconds->getIsNegative();
// Finally convert $multipliedInterval into a normalized interval
$dt = new \DateTimeImmutable();
$tz = new \DateTimeZone("Z");
$dt = $dt->setTimezone( $tz );
$diff = $dt->add( $multipliedInterval )->diff( $dt );
$diff->hasValue = $multipliedSeconds->getValue() != 0;
$diff->invert = ! $diff->invert;
$diff->microseconds = $microseconds;
// $diff->daysOnly = false;
return new DayTimeDurationValue( $diff );
} | [
"public",
"static",
"function",
"Multiply",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"b",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Division denominator is not a number\"",
")",
";",
"if",
"(",
"is_nan",
"(",
"$",
"b",
")",
")",
"throw",
"XPath2Exception",
"::",
"withErrorCode",
"(",
"\"FOCA0005\"",
",",
"Resources",
"::",
"FOCA0005",
")",
";",
"if",
"(",
"$",
"b",
"==",
"INF",
"||",
"$",
"b",
"==",
"-",
"INF",
")",
"throw",
"XPath2Exception",
"::",
"withErrorCode",
"(",
"\"FODT0002\"",
",",
"Resources",
"::",
"FODT0002",
")",
";",
"if",
"(",
"!",
"$",
"a",
"instanceof",
"DayTimeDurationValue",
")",
"throw",
"new",
"ArgumentException",
"(",
"\"$a\"",
")",
";",
"// Create a new interval with the multiplied days. ->days is created by the ->diff function to hold the total days.\r",
"$",
"multipliedSeconds",
"=",
"$",
"a",
"->",
"getTotalSeconds",
"(",
")",
"->",
"Mul",
"(",
"$",
"b",
")",
"->",
"getRound",
"(",
"3",
")",
";",
"$",
"multipliedInterval",
"=",
"new",
"\\",
"DateInterval",
"(",
"\"P0D\"",
")",
";",
"$",
"multipliedInterval",
"->",
"s",
"=",
"$",
"multipliedSeconds",
"->",
"getIntegerPart",
"(",
")",
";",
"$",
"microseconds",
"=",
"$",
"multipliedSeconds",
"->",
"getDecimalPart",
"(",
")",
"+",
"0",
";",
"$",
"sign",
"=",
"$",
"multipliedSeconds",
"->",
"getIsNegative",
"(",
")",
";",
"// Finally convert $multipliedInterval into a normalized interval\r",
"$",
"dt",
"=",
"new",
"\\",
"DateTimeImmutable",
"(",
")",
";",
"$",
"tz",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"\"Z\"",
")",
";",
"$",
"dt",
"=",
"$",
"dt",
"->",
"setTimezone",
"(",
"$",
"tz",
")",
";",
"$",
"diff",
"=",
"$",
"dt",
"->",
"add",
"(",
"$",
"multipliedInterval",
")",
"->",
"diff",
"(",
"$",
"dt",
")",
";",
"$",
"diff",
"->",
"hasValue",
"=",
"$",
"multipliedSeconds",
"->",
"getValue",
"(",
")",
"!=",
"0",
";",
"$",
"diff",
"->",
"invert",
"=",
"!",
"$",
"diff",
"->",
"invert",
";",
"$",
"diff",
"->",
"microseconds",
"=",
"$",
"microseconds",
";",
"// $diff->daysOnly = false;\r",
"return",
"new",
"DayTimeDurationValue",
"(",
"$",
"diff",
")",
";",
"}"
] | Multiply
@param DayTimeDurationValue $a
@param double $b
@return DayTimeDurationValue | [
"Multiply"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DayTimeDurationValue.php#L262-L294 |
bseddon/XPath20 | Value/DayTimeDurationValue.php | DayTimeDurationValue.Divide | public static function Divide( $a, $b )
{
if ( ! is_numeric( $b ) )
throw new \InvalidArgumentException( "Division denominator is not a number" );
if ( is_nan( $b ) )
throw XPath2Exception::withErrorCode( "FOCA0005", Resources::FOCA0005 );
// if ( $b == INF || $b == -INF )
// throw XPath2Exception::withErrorCode( "FOCA0005", Resources::FOCA0005 );
if ( $b == 0.0 )
throw XPath2Exception::withErrorCode( "FODT0002", Resources::FODT0002 );
if ( ! $a instanceof DayTimeDurationValue )
throw new ArgumentException("$a");
// Create a new interval with the multiplied days. ->days is created by the ->diff function to hold the total days.
$dividedSeconds = doubleval( $a->getTotalSeconds()->getValue() / $b );
$dividedInterval = new \DateInterval("P0D");
if ( round( $dividedSeconds ) == 0 )
{
$dividedInterval->hasValue = false;
$dividedInterval->microseconds = 0;
return new DayTimeDurationValue( $dividedInterval );
}
$dividedInterval->s = intval( $dividedSeconds );
$microseconds = round( $dividedSeconds - $dividedInterval->s, 3 ) * 1000;
// Finally convert $multipliedInterval into a normalized interval
$dt = new \DateTimeImmutable();
$tz = new \DateTimeZone("Z");
$dt = $dt->setTimezone( $tz );
$diff = $dt->add( $dividedInterval )->diff( $dt );
$diff->hasValue = $dividedSeconds != 0;
$diff->invert = ! $diff->invert;
$diff->microseconds = $microseconds;
return new DayTimeDurationValue( $diff );
} | php | public static function Divide( $a, $b )
{
if ( ! is_numeric( $b ) )
throw new \InvalidArgumentException( "Division denominator is not a number" );
if ( is_nan( $b ) )
throw XPath2Exception::withErrorCode( "FOCA0005", Resources::FOCA0005 );
// if ( $b == INF || $b == -INF )
// throw XPath2Exception::withErrorCode( "FOCA0005", Resources::FOCA0005 );
if ( $b == 0.0 )
throw XPath2Exception::withErrorCode( "FODT0002", Resources::FODT0002 );
if ( ! $a instanceof DayTimeDurationValue )
throw new ArgumentException("$a");
// Create a new interval with the multiplied days. ->days is created by the ->diff function to hold the total days.
$dividedSeconds = doubleval( $a->getTotalSeconds()->getValue() / $b );
$dividedInterval = new \DateInterval("P0D");
if ( round( $dividedSeconds ) == 0 )
{
$dividedInterval->hasValue = false;
$dividedInterval->microseconds = 0;
return new DayTimeDurationValue( $dividedInterval );
}
$dividedInterval->s = intval( $dividedSeconds );
$microseconds = round( $dividedSeconds - $dividedInterval->s, 3 ) * 1000;
// Finally convert $multipliedInterval into a normalized interval
$dt = new \DateTimeImmutable();
$tz = new \DateTimeZone("Z");
$dt = $dt->setTimezone( $tz );
$diff = $dt->add( $dividedInterval )->diff( $dt );
$diff->hasValue = $dividedSeconds != 0;
$diff->invert = ! $diff->invert;
$diff->microseconds = $microseconds;
return new DayTimeDurationValue( $diff );
} | [
"public",
"static",
"function",
"Divide",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"!",
"is_numeric",
"(",
"$",
"b",
")",
")",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"\"Division denominator is not a number\"",
")",
";",
"if",
"(",
"is_nan",
"(",
"$",
"b",
")",
")",
"throw",
"XPath2Exception",
"::",
"withErrorCode",
"(",
"\"FOCA0005\"",
",",
"Resources",
"::",
"FOCA0005",
")",
";",
"// if ( $b == INF || $b == -INF )\r",
"//\tthrow XPath2Exception::withErrorCode( \"FOCA0005\", Resources::FOCA0005 );\r",
"if",
"(",
"$",
"b",
"==",
"0.0",
")",
"throw",
"XPath2Exception",
"::",
"withErrorCode",
"(",
"\"FODT0002\"",
",",
"Resources",
"::",
"FODT0002",
")",
";",
"if",
"(",
"!",
"$",
"a",
"instanceof",
"DayTimeDurationValue",
")",
"throw",
"new",
"ArgumentException",
"(",
"\"$a\"",
")",
";",
"// Create a new interval with the multiplied days. ->days is created by the ->diff function to hold the total days.\r",
"$",
"dividedSeconds",
"=",
"doubleval",
"(",
"$",
"a",
"->",
"getTotalSeconds",
"(",
")",
"->",
"getValue",
"(",
")",
"/",
"$",
"b",
")",
";",
"$",
"dividedInterval",
"=",
"new",
"\\",
"DateInterval",
"(",
"\"P0D\"",
")",
";",
"if",
"(",
"round",
"(",
"$",
"dividedSeconds",
")",
"==",
"0",
")",
"{",
"$",
"dividedInterval",
"->",
"hasValue",
"=",
"false",
";",
"$",
"dividedInterval",
"->",
"microseconds",
"=",
"0",
";",
"return",
"new",
"DayTimeDurationValue",
"(",
"$",
"dividedInterval",
")",
";",
"}",
"$",
"dividedInterval",
"->",
"s",
"=",
"intval",
"(",
"$",
"dividedSeconds",
")",
";",
"$",
"microseconds",
"=",
"round",
"(",
"$",
"dividedSeconds",
"-",
"$",
"dividedInterval",
"->",
"s",
",",
"3",
")",
"*",
"1000",
";",
"// Finally convert $multipliedInterval into a normalized interval\r",
"$",
"dt",
"=",
"new",
"\\",
"DateTimeImmutable",
"(",
")",
";",
"$",
"tz",
"=",
"new",
"\\",
"DateTimeZone",
"(",
"\"Z\"",
")",
";",
"$",
"dt",
"=",
"$",
"dt",
"->",
"setTimezone",
"(",
"$",
"tz",
")",
";",
"$",
"diff",
"=",
"$",
"dt",
"->",
"add",
"(",
"$",
"dividedInterval",
")",
"->",
"diff",
"(",
"$",
"dt",
")",
";",
"$",
"diff",
"->",
"hasValue",
"=",
"$",
"dividedSeconds",
"!=",
"0",
";",
"$",
"diff",
"->",
"invert",
"=",
"!",
"$",
"diff",
"->",
"invert",
";",
"$",
"diff",
"->",
"microseconds",
"=",
"$",
"microseconds",
";",
"return",
"new",
"DayTimeDurationValue",
"(",
"$",
"diff",
")",
";",
"}"
] | Divide
@param DayTimeDurationValue $a
@param double $b
@return DayTimeDurationValue | [
"Divide"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DayTimeDurationValue.php#L302-L342 |
bseddon/XPath20 | Value/DayTimeDurationValue.php | DayTimeDurationValue.DivideDurations | public static function DivideDurations( $a, $b )
{
if ( ! $a instanceof DayTimeDurationValue )
throw new ArgumentException("$a");
if ( ! $b instanceof DayTimeDurationValue )
throw new ArgumentException("$b");
$numerator = $a->getTotalSeconds();
$denominator = $b->getTotalSeconds();
return $numerator->Div( $denominator, 21 );
} | php | public static function DivideDurations( $a, $b )
{
if ( ! $a instanceof DayTimeDurationValue )
throw new ArgumentException("$a");
if ( ! $b instanceof DayTimeDurationValue )
throw new ArgumentException("$b");
$numerator = $a->getTotalSeconds();
$denominator = $b->getTotalSeconds();
return $numerator->Div( $denominator, 21 );
} | [
"public",
"static",
"function",
"DivideDurations",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"!",
"$",
"a",
"instanceof",
"DayTimeDurationValue",
")",
"throw",
"new",
"ArgumentException",
"(",
"\"$a\"",
")",
";",
"if",
"(",
"!",
"$",
"b",
"instanceof",
"DayTimeDurationValue",
")",
"throw",
"new",
"ArgumentException",
"(",
"\"$b\"",
")",
";",
"$",
"numerator",
"=",
"$",
"a",
"->",
"getTotalSeconds",
"(",
")",
";",
"$",
"denominator",
"=",
"$",
"b",
"->",
"getTotalSeconds",
"(",
")",
";",
"return",
"$",
"numerator",
"->",
"Div",
"(",
"$",
"denominator",
",",
"21",
")",
";",
"}"
] | DivideDurations
@param DayTimeDurationValue $a
@param DayTimeDurationValue $b
@return DecimalValue | [
"DivideDurations"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DayTimeDurationValue.php#L350-L362 |
bseddon/XPath20 | Value/DayTimeDurationValue.php | DayTimeDurationValue.ToString | public function ToString()
{
// Reading all non-zero date parts.
$date = array_filter(array(
'D' => @isset( $this->Value->daysOnly ) && $this->Value->daysOnly && $this->Value->days ? $this->Value->days : $this->Value->d
// 'D' => $this->Value->days
));
$microseconds = "";
if ( ! @empty( $this->Value->microseconds ) && ! empty( rtrim( $this->Value->microseconds, "0" ) ) )
{
$microseconds = str_pad( substr( "." . $this->Value->microseconds, 0, 4 ), 4, "0", STR_PAD_RIGHT );
}
// Reading all non-zero time parts.
$time = array_filter(array
(
'H' => $this->Value->h,
'M' => $this->Value->i,
'S' => $this->Value->s . $microseconds,
));
$specString = 'P';
// Adding each part to the spec-string.
foreach ($date as $key => $value)
{
$specString .= $value . $key;
}
if ( count( $time ) > 0 )
{
$specString .= 'T';
foreach ( $time as $key => $value )
{
$specString .= $value . $key;
}
}
return $specString == "P"
? $this->ZeroStringValue()
: ( $this->Value->invert ? "-" : "" ) . $specString;
} | php | public function ToString()
{
// Reading all non-zero date parts.
$date = array_filter(array(
'D' => @isset( $this->Value->daysOnly ) && $this->Value->daysOnly && $this->Value->days ? $this->Value->days : $this->Value->d
// 'D' => $this->Value->days
));
$microseconds = "";
if ( ! @empty( $this->Value->microseconds ) && ! empty( rtrim( $this->Value->microseconds, "0" ) ) )
{
$microseconds = str_pad( substr( "." . $this->Value->microseconds, 0, 4 ), 4, "0", STR_PAD_RIGHT );
}
// Reading all non-zero time parts.
$time = array_filter(array
(
'H' => $this->Value->h,
'M' => $this->Value->i,
'S' => $this->Value->s . $microseconds,
));
$specString = 'P';
// Adding each part to the spec-string.
foreach ($date as $key => $value)
{
$specString .= $value . $key;
}
if ( count( $time ) > 0 )
{
$specString .= 'T';
foreach ( $time as $key => $value )
{
$specString .= $value . $key;
}
}
return $specString == "P"
? $this->ZeroStringValue()
: ( $this->Value->invert ? "-" : "" ) . $specString;
} | [
"public",
"function",
"ToString",
"(",
")",
"{",
"// Reading all non-zero date parts.\r",
"$",
"date",
"=",
"array_filter",
"(",
"array",
"(",
"'D'",
"=>",
"@",
"isset",
"(",
"$",
"this",
"->",
"Value",
"->",
"daysOnly",
")",
"&&",
"$",
"this",
"->",
"Value",
"->",
"daysOnly",
"&&",
"$",
"this",
"->",
"Value",
"->",
"days",
"?",
"$",
"this",
"->",
"Value",
"->",
"days",
":",
"$",
"this",
"->",
"Value",
"->",
"d",
"// 'D' => $this->Value->days\r",
")",
")",
";",
"$",
"microseconds",
"=",
"\"\"",
";",
"if",
"(",
"!",
"@",
"empty",
"(",
"$",
"this",
"->",
"Value",
"->",
"microseconds",
")",
"&&",
"!",
"empty",
"(",
"rtrim",
"(",
"$",
"this",
"->",
"Value",
"->",
"microseconds",
",",
"\"0\"",
")",
")",
")",
"{",
"$",
"microseconds",
"=",
"str_pad",
"(",
"substr",
"(",
"\".\"",
".",
"$",
"this",
"->",
"Value",
"->",
"microseconds",
",",
"0",
",",
"4",
")",
",",
"4",
",",
"\"0\"",
",",
"STR_PAD_RIGHT",
")",
";",
"}",
"// Reading all non-zero time parts.\r",
"$",
"time",
"=",
"array_filter",
"(",
"array",
"(",
"'H'",
"=>",
"$",
"this",
"->",
"Value",
"->",
"h",
",",
"'M'",
"=>",
"$",
"this",
"->",
"Value",
"->",
"i",
",",
"'S'",
"=>",
"$",
"this",
"->",
"Value",
"->",
"s",
".",
"$",
"microseconds",
",",
")",
")",
";",
"$",
"specString",
"=",
"'P'",
";",
"// Adding each part to the spec-string.\r",
"foreach",
"(",
"$",
"date",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"specString",
".=",
"$",
"value",
".",
"$",
"key",
";",
"}",
"if",
"(",
"count",
"(",
"$",
"time",
")",
">",
"0",
")",
"{",
"$",
"specString",
".=",
"'T'",
";",
"foreach",
"(",
"$",
"time",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"$",
"specString",
".=",
"$",
"value",
".",
"$",
"key",
";",
"}",
"}",
"return",
"$",
"specString",
"==",
"\"P\"",
"?",
"$",
"this",
"->",
"ZeroStringValue",
"(",
")",
":",
"(",
"$",
"this",
"->",
"Value",
"->",
"invert",
"?",
"\"-\"",
":",
"\"\"",
")",
".",
"$",
"specString",
";",
"}"
] | ToString
@return string | [
"ToString"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/Value/DayTimeDurationValue.php#L368-L410 |
mossphp/moss-storage | Moss/Storage/Query/Relation/OneTroughRelation.php | OneTroughRelation.delete | public function delete(&$result)
{
$entity = $this->accessor->getPropertyValue($result, $this->definition->container());
if (empty($entity)) {
return $result;
}
$mediator = [];
foreach ($this->definition->localKeys() as $entityField => $mediatorField) {
$mediator[$mediatorField] = $this->accessor->getPropertyValue($result, $entityField);
}
foreach ($this->definition->foreignKeys() as $mediatorField => $entityField) {
$mediator[$mediatorField] = $this->accessor->getPropertyValue($entity, $entityField);
}
$this->storage->delete($mediator, $this->definition->mediator())->execute();
$this->accessor->setPropertyValue($result, $this->definition->container(), $entity);
return $result;
} | php | public function delete(&$result)
{
$entity = $this->accessor->getPropertyValue($result, $this->definition->container());
if (empty($entity)) {
return $result;
}
$mediator = [];
foreach ($this->definition->localKeys() as $entityField => $mediatorField) {
$mediator[$mediatorField] = $this->accessor->getPropertyValue($result, $entityField);
}
foreach ($this->definition->foreignKeys() as $mediatorField => $entityField) {
$mediator[$mediatorField] = $this->accessor->getPropertyValue($entity, $entityField);
}
$this->storage->delete($mediator, $this->definition->mediator())->execute();
$this->accessor->setPropertyValue($result, $this->definition->container(), $entity);
return $result;
} | [
"public",
"function",
"delete",
"(",
"&",
"$",
"result",
")",
"{",
"$",
"entity",
"=",
"$",
"this",
"->",
"accessor",
"->",
"getPropertyValue",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"definition",
"->",
"container",
"(",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"entity",
")",
")",
"{",
"return",
"$",
"result",
";",
"}",
"$",
"mediator",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"definition",
"->",
"localKeys",
"(",
")",
"as",
"$",
"entityField",
"=>",
"$",
"mediatorField",
")",
"{",
"$",
"mediator",
"[",
"$",
"mediatorField",
"]",
"=",
"$",
"this",
"->",
"accessor",
"->",
"getPropertyValue",
"(",
"$",
"result",
",",
"$",
"entityField",
")",
";",
"}",
"foreach",
"(",
"$",
"this",
"->",
"definition",
"->",
"foreignKeys",
"(",
")",
"as",
"$",
"mediatorField",
"=>",
"$",
"entityField",
")",
"{",
"$",
"mediator",
"[",
"$",
"mediatorField",
"]",
"=",
"$",
"this",
"->",
"accessor",
"->",
"getPropertyValue",
"(",
"$",
"entity",
",",
"$",
"entityField",
")",
";",
"}",
"$",
"this",
"->",
"storage",
"->",
"delete",
"(",
"$",
"mediator",
",",
"$",
"this",
"->",
"definition",
"->",
"mediator",
"(",
")",
")",
"->",
"execute",
"(",
")",
";",
"$",
"this",
"->",
"accessor",
"->",
"setPropertyValue",
"(",
"$",
"result",
",",
"$",
"this",
"->",
"definition",
"->",
"container",
"(",
")",
",",
"$",
"entity",
")",
";",
"return",
"$",
"result",
";",
"}"
] | Executes delete for one-to-one relation
@param array|\ArrayAccess $result
@return array|\ArrayAccess | [
"Executes",
"delete",
"for",
"one",
"-",
"to",
"-",
"one",
"relation"
] | train | https://github.com/mossphp/moss-storage/blob/0d123e7ae6bbfce1e2a18e73bf70997277b430c1/Moss/Storage/Query/Relation/OneTroughRelation.php#L124-L145 |
locomotivemtl/charcoal-translator | src/Charcoal/Translator/Translation.php | Translation.sanitize | public function sanitize(callable $sanitizeCallback)
{
foreach ($this->val as $lang => $val) {
$this->val[$lang] = call_user_func($sanitizeCallback, $val);
}
return $this;
} | php | public function sanitize(callable $sanitizeCallback)
{
foreach ($this->val as $lang => $val) {
$this->val[$lang] = call_user_func($sanitizeCallback, $val);
}
return $this;
} | [
"public",
"function",
"sanitize",
"(",
"callable",
"$",
"sanitizeCallback",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"val",
"as",
"$",
"lang",
"=>",
"$",
"val",
")",
"{",
"$",
"this",
"->",
"val",
"[",
"$",
"lang",
"]",
"=",
"call_user_func",
"(",
"$",
"sanitizeCallback",
",",
"$",
"val",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Sanitize each language's string with a callback function.
The callback method signature is to take a string as parameter and return the sanitized string.
@param callable $sanitizeCallback The sanitizing function callback.
@return self | [
"Sanitize",
"each",
"language",
"s",
"string",
"with",
"a",
"callback",
"function",
"."
] | train | https://github.com/locomotivemtl/charcoal-translator/blob/0a64432baef223dcccbfecf057015440dfa76e49/src/Charcoal/Translator/Translation.php#L178-L184 |
locomotivemtl/charcoal-translator | src/Charcoal/Translator/Translation.php | Translation.setVal | private function setVal($val)
{
if ($val instanceof Translation) {
$this->val = $val->data();
} elseif (is_array($val)) {
$this->val = [];
foreach ($val as $lang => $l10n) {
if (!is_string($lang)) {
throw new InvalidArgumentException(sprintf(
'Invalid language; must be a string, received %s',
(is_object($lang) ? get_class($lang) : gettype($lang))
));
}
$this->val[$lang] = (string)$l10n;
}
} elseif (is_string($val)) {
$lang = $this->manager->currentLocale();
$this->val[$lang] = $val;
} else {
throw new InvalidArgumentException(
'Invalid localized value.'
);
}
return $this;
} | php | private function setVal($val)
{
if ($val instanceof Translation) {
$this->val = $val->data();
} elseif (is_array($val)) {
$this->val = [];
foreach ($val as $lang => $l10n) {
if (!is_string($lang)) {
throw new InvalidArgumentException(sprintf(
'Invalid language; must be a string, received %s',
(is_object($lang) ? get_class($lang) : gettype($lang))
));
}
$this->val[$lang] = (string)$l10n;
}
} elseif (is_string($val)) {
$lang = $this->manager->currentLocale();
$this->val[$lang] = $val;
} else {
throw new InvalidArgumentException(
'Invalid localized value.'
);
}
return $this;
} | [
"private",
"function",
"setVal",
"(",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"val",
"instanceof",
"Translation",
")",
"{",
"$",
"this",
"->",
"val",
"=",
"$",
"val",
"->",
"data",
"(",
")",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"val",
")",
")",
"{",
"$",
"this",
"->",
"val",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"val",
"as",
"$",
"lang",
"=>",
"$",
"l10n",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"lang",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'Invalid language; must be a string, received %s'",
",",
"(",
"is_object",
"(",
"$",
"lang",
")",
"?",
"get_class",
"(",
"$",
"lang",
")",
":",
"gettype",
"(",
"$",
"lang",
")",
")",
")",
")",
";",
"}",
"$",
"this",
"->",
"val",
"[",
"$",
"lang",
"]",
"=",
"(",
"string",
")",
"$",
"l10n",
";",
"}",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"val",
")",
")",
"{",
"$",
"lang",
"=",
"$",
"this",
"->",
"manager",
"->",
"currentLocale",
"(",
")",
";",
"$",
"this",
"->",
"val",
"[",
"$",
"lang",
"]",
"=",
"$",
"val",
";",
"}",
"else",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'Invalid localized value.'",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Assign the current translation value(s).
@param Translation|array|string $val The translation value(s).
Add one or more translation values.
Accept 3 types of arguments:
- object (TranslationInterface): The data will be copied from the object's.
- array: All languages available in the array. The format of the array should
be a hash in the `lang` => `string` format.
- string: The value will be assigned to the current language.
@return self
@throws InvalidArgumentException If language or value are invalid. | [
"Assign",
"the",
"current",
"translation",
"value",
"(",
"s",
")",
"."
] | train | https://github.com/locomotivemtl/charcoal-translator/blob/0a64432baef223dcccbfecf057015440dfa76e49/src/Charcoal/Translator/Translation.php#L200-L227 |
dms-org/common.structure | src/DateTime/DayOfWeek.php | DayOfWeek.weekdays | public static function weekdays() : array
{
$days = self::getAll();
$weekDays = [];
foreach ($days as $key => $day) {
if ($day->isWeekDay()) {
$weekDays[] = $day;
}
}
return $weekDays;
} | php | public static function weekdays() : array
{
$days = self::getAll();
$weekDays = [];
foreach ($days as $key => $day) {
if ($day->isWeekDay()) {
$weekDays[] = $day;
}
}
return $weekDays;
} | [
"public",
"static",
"function",
"weekdays",
"(",
")",
":",
"array",
"{",
"$",
"days",
"=",
"self",
"::",
"getAll",
"(",
")",
";",
"$",
"weekDays",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"days",
"as",
"$",
"key",
"=>",
"$",
"day",
")",
"{",
"if",
"(",
"$",
"day",
"->",
"isWeekDay",
"(",
")",
")",
"{",
"$",
"weekDays",
"[",
"]",
"=",
"$",
"day",
";",
"}",
"}",
"return",
"$",
"weekDays",
";",
"}"
] | Gets the weekdays.
@return DayOfWeek[] | [
"Gets",
"the",
"weekdays",
"."
] | train | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/DayOfWeek.php#L123-L135 |
dms-org/common.structure | src/DateTime/DayOfWeek.php | DayOfWeek.weekends | public static function weekends() : array
{
$days = self::getAll();
$weekEndDays = [];
foreach ($days as $key => $day) {
if ($day->isWeekEnd()) {
$weekEndDays[] = $day;
}
}
return $weekEndDays;
} | php | public static function weekends() : array
{
$days = self::getAll();
$weekEndDays = [];
foreach ($days as $key => $day) {
if ($day->isWeekEnd()) {
$weekEndDays[] = $day;
}
}
return $weekEndDays;
} | [
"public",
"static",
"function",
"weekends",
"(",
")",
":",
"array",
"{",
"$",
"days",
"=",
"self",
"::",
"getAll",
"(",
")",
";",
"$",
"weekEndDays",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"days",
"as",
"$",
"key",
"=>",
"$",
"day",
")",
"{",
"if",
"(",
"$",
"day",
"->",
"isWeekEnd",
"(",
")",
")",
"{",
"$",
"weekEndDays",
"[",
"]",
"=",
"$",
"day",
";",
"}",
"}",
"return",
"$",
"weekEndDays",
";",
"}"
] | Gets the weekend days.
@return DayOfWeek[] | [
"Gets",
"the",
"weekend",
"days",
"."
] | train | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/DayOfWeek.php#L142-L154 |
dms-org/common.structure | src/DateTime/DayOfWeek.php | DayOfWeek.fromShortName | public static function fromShortName(string $name) : DayOfWeek
{
return self::fromNameMap($name, self::$shortNames, __METHOD__);
} | php | public static function fromShortName(string $name) : DayOfWeek
{
return self::fromNameMap($name, self::$shortNames, __METHOD__);
} | [
"public",
"static",
"function",
"fromShortName",
"(",
"string",
"$",
"name",
")",
":",
"DayOfWeek",
"{",
"return",
"self",
"::",
"fromNameMap",
"(",
"$",
"name",
",",
"self",
"::",
"$",
"shortNames",
",",
"__METHOD__",
")",
";",
"}"
] | Gets the day of the week from the supplied name string.
NOTE: casing is ignored.
@param string $name
@return DayOfWeek
@throws InvalidEnumValueException | [
"Gets",
"the",
"day",
"of",
"the",
"week",
"from",
"the",
"supplied",
"name",
"string",
"."
] | train | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/DayOfWeek.php#L166-L169 |
dms-org/common.structure | src/DateTime/DayOfWeek.php | DayOfWeek.fromName | public static function fromName(string $name) : DayOfWeek
{
return self::fromNameMap($name, self::$fullNames, __METHOD__);
} | php | public static function fromName(string $name) : DayOfWeek
{
return self::fromNameMap($name, self::$fullNames, __METHOD__);
} | [
"public",
"static",
"function",
"fromName",
"(",
"string",
"$",
"name",
")",
":",
"DayOfWeek",
"{",
"return",
"self",
"::",
"fromNameMap",
"(",
"$",
"name",
",",
"self",
"::",
"$",
"fullNames",
",",
"__METHOD__",
")",
";",
"}"
] | Gets the day of the week from the supplied name string.
NOTE: casing is ignored.
@param string $name
@return DayOfWeek
@throws InvalidEnumValueException | [
"Gets",
"the",
"day",
"of",
"the",
"week",
"from",
"the",
"supplied",
"name",
"string",
"."
] | train | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/DayOfWeek.php#L181-L184 |
dms-org/common.structure | src/DateTime/DayOfWeek.php | DayOfWeek.fromNameMap | private static function fromNameMap(string $name, array $nameMap, string $method) : DayOfWeek
{
$name = ucfirst(strtolower($name));
$ordinal = array_search($name, $nameMap, true);
if ($ordinal === false) {
throw new InvalidEnumValueException($method, $nameMap, $name);
}
return new self($ordinal);
} | php | private static function fromNameMap(string $name, array $nameMap, string $method) : DayOfWeek
{
$name = ucfirst(strtolower($name));
$ordinal = array_search($name, $nameMap, true);
if ($ordinal === false) {
throw new InvalidEnumValueException($method, $nameMap, $name);
}
return new self($ordinal);
} | [
"private",
"static",
"function",
"fromNameMap",
"(",
"string",
"$",
"name",
",",
"array",
"$",
"nameMap",
",",
"string",
"$",
"method",
")",
":",
"DayOfWeek",
"{",
"$",
"name",
"=",
"ucfirst",
"(",
"strtolower",
"(",
"$",
"name",
")",
")",
";",
"$",
"ordinal",
"=",
"array_search",
"(",
"$",
"name",
",",
"$",
"nameMap",
",",
"true",
")",
";",
"if",
"(",
"$",
"ordinal",
"===",
"false",
")",
"{",
"throw",
"new",
"InvalidEnumValueException",
"(",
"$",
"method",
",",
"$",
"nameMap",
",",
"$",
"name",
")",
";",
"}",
"return",
"new",
"self",
"(",
"$",
"ordinal",
")",
";",
"}"
] | @param string $name
@param string[] $nameMap
@param string $method
@return DayOfWeek
@throws InvalidEnumValueException | [
"@param",
"string",
"$name",
"@param",
"string",
"[]",
"$nameMap",
"@param",
"string",
"$method"
] | train | https://github.com/dms-org/common.structure/blob/23f122182f60df5ec847047a81a39c8aab019ff1/src/DateTime/DayOfWeek.php#L194-L205 |
codeinchq/psr7-responses | src/HttpProxyResponse.php | HttpProxyResponse.getResponse | public function getResponse():ResponseInterface
{
if (!$this->response) {
$this->response = (new Client())->request('GET', $this->remoteUrl);
}
return $this->response;
} | php | public function getResponse():ResponseInterface
{
if (!$this->response) {
$this->response = (new Client())->request('GET', $this->remoteUrl);
}
return $this->response;
} | [
"public",
"function",
"getResponse",
"(",
")",
":",
"ResponseInterface",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"response",
")",
"{",
"$",
"this",
"->",
"response",
"=",
"(",
"new",
"Client",
"(",
")",
")",
"->",
"request",
"(",
"'GET'",
",",
"$",
"this",
"->",
"remoteUrl",
")",
";",
"}",
"return",
"$",
"this",
"->",
"response",
";",
"}"
] | Returns the HTTP response.
@return ResponseInterface
@throws \GuzzleHttp\Exception\GuzzleException | [
"Returns",
"the",
"HTTP",
"response",
"."
] | train | https://github.com/codeinchq/psr7-responses/blob/d4bb6bc9b4219694e7c1f5ee9b40b75b22362fce/src/HttpProxyResponse.php#L97-L103 |
codeinchq/psr7-responses | src/HttpProxyResponse.php | HttpProxyResponse.getResponseHeaders | public function getResponseHeaders():array
{
$headers = [];
foreach ($this->getResponse()->getHeaders() as $header => $values) {
if (preg_grep('/^'.preg_quote($header, '$/').'/ui', $this->acceptableProxyHeaders)) {
$headers[$header] = $values;
}
}
return $headers;
} | php | public function getResponseHeaders():array
{
$headers = [];
foreach ($this->getResponse()->getHeaders() as $header => $values) {
if (preg_grep('/^'.preg_quote($header, '$/').'/ui', $this->acceptableProxyHeaders)) {
$headers[$header] = $values;
}
}
return $headers;
} | [
"public",
"function",
"getResponseHeaders",
"(",
")",
":",
"array",
"{",
"$",
"headers",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"this",
"->",
"getResponse",
"(",
")",
"->",
"getHeaders",
"(",
")",
"as",
"$",
"header",
"=>",
"$",
"values",
")",
"{",
"if",
"(",
"preg_grep",
"(",
"'/^'",
".",
"preg_quote",
"(",
"$",
"header",
",",
"'$/'",
")",
".",
"'/ui'",
",",
"$",
"this",
"->",
"acceptableProxyHeaders",
")",
")",
"{",
"$",
"headers",
"[",
"$",
"header",
"]",
"=",
"$",
"values",
";",
"}",
"}",
"return",
"$",
"headers",
";",
"}"
] | Returns all the imported headers from the HTTP response.
@return array
@throws \GuzzleHttp\Exception\GuzzleException | [
"Returns",
"all",
"the",
"imported",
"headers",
"from",
"the",
"HTTP",
"response",
"."
] | train | https://github.com/codeinchq/psr7-responses/blob/d4bb6bc9b4219694e7c1f5ee9b40b75b22362fce/src/HttpProxyResponse.php#L111-L120 |
AmaraLiving/php-onehydra | src/Amara/OneHydra/ResultBuilder/PageResultBuilder.php | PageResultBuilder.build | public function build(RequestInterface $request, HttpResponseInterface $response)
{
$url = $request->getParams()['url'];
$json = $response->getBody();
$data = json_decode($json);
if (!isset($data->Page)) {
throw new ResultBuilderException("Required element was not present in response (Page)");
}
$rawPage = $data->Page;
// "Links" can be blank, so we don't check for it
$requiredProperties = [
"HeadContent",
"HeadInstructions",
"PageContent",
"ServerSide",
];
foreach ($requiredProperties as $expectedProperty) {
if (!isset($rawPage->{$expectedProperty})) {
throw new ResultBuilderException(
"Required element was not present in response (Page.{$expectedProperty})"
);
}
}
$page = new Page($rawPage);
$page->setPageUrl($url);
return new PageResult($response, $page);
} | php | public function build(RequestInterface $request, HttpResponseInterface $response)
{
$url = $request->getParams()['url'];
$json = $response->getBody();
$data = json_decode($json);
if (!isset($data->Page)) {
throw new ResultBuilderException("Required element was not present in response (Page)");
}
$rawPage = $data->Page;
// "Links" can be blank, so we don't check for it
$requiredProperties = [
"HeadContent",
"HeadInstructions",
"PageContent",
"ServerSide",
];
foreach ($requiredProperties as $expectedProperty) {
if (!isset($rawPage->{$expectedProperty})) {
throw new ResultBuilderException(
"Required element was not present in response (Page.{$expectedProperty})"
);
}
}
$page = new Page($rawPage);
$page->setPageUrl($url);
return new PageResult($response, $page);
} | [
"public",
"function",
"build",
"(",
"RequestInterface",
"$",
"request",
",",
"HttpResponseInterface",
"$",
"response",
")",
"{",
"$",
"url",
"=",
"$",
"request",
"->",
"getParams",
"(",
")",
"[",
"'url'",
"]",
";",
"$",
"json",
"=",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"$",
"data",
"=",
"json_decode",
"(",
"$",
"json",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"data",
"->",
"Page",
")",
")",
"{",
"throw",
"new",
"ResultBuilderException",
"(",
"\"Required element was not present in response (Page)\"",
")",
";",
"}",
"$",
"rawPage",
"=",
"$",
"data",
"->",
"Page",
";",
"// \"Links\" can be blank, so we don't check for it",
"$",
"requiredProperties",
"=",
"[",
"\"HeadContent\"",
",",
"\"HeadInstructions\"",
",",
"\"PageContent\"",
",",
"\"ServerSide\"",
",",
"]",
";",
"foreach",
"(",
"$",
"requiredProperties",
"as",
"$",
"expectedProperty",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"rawPage",
"->",
"{",
"$",
"expectedProperty",
"}",
")",
")",
"{",
"throw",
"new",
"ResultBuilderException",
"(",
"\"Required element was not present in response (Page.{$expectedProperty})\"",
")",
";",
"}",
"}",
"$",
"page",
"=",
"new",
"Page",
"(",
"$",
"rawPage",
")",
";",
"$",
"page",
"->",
"setPageUrl",
"(",
"$",
"url",
")",
";",
"return",
"new",
"PageResult",
"(",
"$",
"response",
",",
"$",
"page",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/AmaraLiving/php-onehydra/blob/f2c3155c42c8c0bec8c0246feb2a5959a15b2406/src/Amara/OneHydra/ResultBuilder/PageResultBuilder.php#L37-L71 |
yuncms/yii2-coin | frontend/controllers/CoinController.php | CoinController.actionRecharge | public function actionRecharge()
{
$model = new Recharge();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$payment = new Payment([
'currency' => $model->currency,
'money' => $model->money,
'name' => Yii::t('coin', 'Coin Recharge'),
'gateway' => $model->gateway,
'trade_type' => Payment::TYPE_NATIVE,
'model_id' => $model->id,
'model' => get_class($model),
'return_url' => Url::to(['/coin/coin/index'], true),
]);
if ($payment->save()) {
$model->link('payment', $payment);
return $this->redirect(['/payment/default/pay', 'id' => $payment->id]);
}
}
return $this->render('recharge', [
'model' => $model,
]);
} | php | public function actionRecharge()
{
$model = new Recharge();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$payment = new Payment([
'currency' => $model->currency,
'money' => $model->money,
'name' => Yii::t('coin', 'Coin Recharge'),
'gateway' => $model->gateway,
'trade_type' => Payment::TYPE_NATIVE,
'model_id' => $model->id,
'model' => get_class($model),
'return_url' => Url::to(['/coin/coin/index'], true),
]);
if ($payment->save()) {
$model->link('payment', $payment);
return $this->redirect(['/payment/default/pay', 'id' => $payment->id]);
}
}
return $this->render('recharge', [
'model' => $model,
]);
} | [
"public",
"function",
"actionRecharge",
"(",
")",
"{",
"$",
"model",
"=",
"new",
"Recharge",
"(",
")",
";",
"if",
"(",
"$",
"model",
"->",
"load",
"(",
"Yii",
"::",
"$",
"app",
"->",
"request",
"->",
"post",
"(",
")",
")",
"&&",
"$",
"model",
"->",
"save",
"(",
")",
")",
"{",
"$",
"payment",
"=",
"new",
"Payment",
"(",
"[",
"'currency'",
"=>",
"$",
"model",
"->",
"currency",
",",
"'money'",
"=>",
"$",
"model",
"->",
"money",
",",
"'name'",
"=>",
"Yii",
"::",
"t",
"(",
"'coin'",
",",
"'Coin Recharge'",
")",
",",
"'gateway'",
"=>",
"$",
"model",
"->",
"gateway",
",",
"'trade_type'",
"=>",
"Payment",
"::",
"TYPE_NATIVE",
",",
"'model_id'",
"=>",
"$",
"model",
"->",
"id",
",",
"'model'",
"=>",
"get_class",
"(",
"$",
"model",
")",
",",
"'return_url'",
"=>",
"Url",
"::",
"to",
"(",
"[",
"'/coin/coin/index'",
"]",
",",
"true",
")",
",",
"]",
")",
";",
"if",
"(",
"$",
"payment",
"->",
"save",
"(",
")",
")",
"{",
"$",
"model",
"->",
"link",
"(",
"'payment'",
",",
"$",
"payment",
")",
";",
"return",
"$",
"this",
"->",
"redirect",
"(",
"[",
"'/payment/default/pay'",
",",
"'id'",
"=>",
"$",
"payment",
"->",
"id",
"]",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'recharge'",
",",
"[",
"'model'",
"=>",
"$",
"model",
",",
"]",
")",
";",
"}"
] | 积分充值
@return array|string | [
"积分充值"
] | train | https://github.com/yuncms/yii2-coin/blob/0addecfec90972b5fb41e95ee3dbae78dfc4cfb2/frontend/controllers/CoinController.php#L63-L85 |
libreworks/caridea-container | src/Properties.php | Properties.typeof | protected static function typeof($v): string
{
if (is_bool($v)) {
return 'bool';
} elseif (is_int($v)) {
return 'int';
} elseif (is_float($v)) {
return 'float';
} elseif (is_string($v)) {
return 'string';
} elseif (is_array($v)) {
return 'array';
} elseif (is_resource($v)) {
return 'resource';
}
return get_class($v);
} | php | protected static function typeof($v): string
{
if (is_bool($v)) {
return 'bool';
} elseif (is_int($v)) {
return 'int';
} elseif (is_float($v)) {
return 'float';
} elseif (is_string($v)) {
return 'string';
} elseif (is_array($v)) {
return 'array';
} elseif (is_resource($v)) {
return 'resource';
}
return get_class($v);
} | [
"protected",
"static",
"function",
"typeof",
"(",
"$",
"v",
")",
":",
"string",
"{",
"if",
"(",
"is_bool",
"(",
"$",
"v",
")",
")",
"{",
"return",
"'bool'",
";",
"}",
"elseif",
"(",
"is_int",
"(",
"$",
"v",
")",
")",
"{",
"return",
"'int'",
";",
"}",
"elseif",
"(",
"is_float",
"(",
"$",
"v",
")",
")",
"{",
"return",
"'float'",
";",
"}",
"elseif",
"(",
"is_string",
"(",
"$",
"v",
")",
")",
"{",
"return",
"'string'",
";",
"}",
"elseif",
"(",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"return",
"'array'",
";",
"}",
"elseif",
"(",
"is_resource",
"(",
"$",
"v",
")",
")",
"{",
"return",
"'resource'",
";",
"}",
"return",
"get_class",
"(",
"$",
"v",
")",
";",
"}"
] | More predictable results than `gettype`.
@param mixed $v The value to evaluate | [
"More",
"predictable",
"results",
"than",
"gettype",
"."
] | train | https://github.com/libreworks/caridea-container/blob/b93087ff5bf49f5885025da691575093335bfe8f/src/Properties.php#L76-L92 |
libreworks/caridea-container | src/Properties.php | Properties.doGet | protected function doGet(string $name)
{
return isset($this->values[$name]) ? $this->values[$name] : null;
} | php | protected function doGet(string $name)
{
return isset($this->values[$name]) ? $this->values[$name] : null;
} | [
"protected",
"function",
"doGet",
"(",
"string",
"$",
"name",
")",
"{",
"return",
"isset",
"(",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
")",
"?",
"$",
"this",
"->",
"values",
"[",
"$",
"name",
"]",
":",
"null",
";",
"}"
] | Retrieves the value
@param string $name The value name | [
"Retrieves",
"the",
"value"
] | train | https://github.com/libreworks/caridea-container/blob/b93087ff5bf49f5885025da691575093335bfe8f/src/Properties.php#L99-L102 |
ARCANESOFT/Auth | src/Models/User.php | User.scopeProtectAdmins | public function scopeProtectAdmins(Builder $query)
{
/** @var self $user */
$user = auth()->user();
return ($user && $user->is_admin)
? $query
: $query->where('is_admin', false);
} | php | public function scopeProtectAdmins(Builder $query)
{
/** @var self $user */
$user = auth()->user();
return ($user && $user->is_admin)
? $query
: $query->where('is_admin', false);
} | [
"public",
"function",
"scopeProtectAdmins",
"(",
"Builder",
"$",
"query",
")",
"{",
"/** @var self $user */",
"$",
"user",
"=",
"auth",
"(",
")",
"->",
"user",
"(",
")",
";",
"return",
"(",
"$",
"user",
"&&",
"$",
"user",
"->",
"is_admin",
")",
"?",
"$",
"query",
":",
"$",
"query",
"->",
"where",
"(",
"'is_admin'",
",",
"false",
")",
";",
"}"
] | Protect admins.
@param \Illuminate\Database\Eloquent\Builder $query
@return \Illuminate\Database\Eloquent\Builder | [
"Protect",
"admins",
"."
] | train | https://github.com/ARCANESOFT/Auth/blob/b33ca82597a76b1e395071f71ae3e51f1ec67e62/src/Models/User.php#L53-L61 |
mrbase/Smesg | src/Smesg/Provider/UnwireProvider.php | UnwireProvider.getDefaultValues | public function getDefaultValues()
{
preg_match('/([0-9.]+)([A-Z]{3})/', $this->config['price'], $matches);
$this->defaults['price'] = array(
'currency' => (!empty($this->defaults['price']['currency']) ? $this->defaults['price']['currency'] : $matches[2]),
'amount' => (!empty($this->defaults['price']['amount']) ? $this->defaults['price']['amount'] : $matches[1]),
'vat' => (!empty($this->defaults['price']['vat']) ? $this->defaults['price']['vat'] : null),
);
return $this->defaults;
} | php | public function getDefaultValues()
{
preg_match('/([0-9.]+)([A-Z]{3})/', $this->config['price'], $matches);
$this->defaults['price'] = array(
'currency' => (!empty($this->defaults['price']['currency']) ? $this->defaults['price']['currency'] : $matches[2]),
'amount' => (!empty($this->defaults['price']['amount']) ? $this->defaults['price']['amount'] : $matches[1]),
'vat' => (!empty($this->defaults['price']['vat']) ? $this->defaults['price']['vat'] : null),
);
return $this->defaults;
} | [
"public",
"function",
"getDefaultValues",
"(",
")",
"{",
"preg_match",
"(",
"'/([0-9.]+)([A-Z]{3})/'",
",",
"$",
"this",
"->",
"config",
"[",
"'price'",
"]",
",",
"$",
"matches",
")",
";",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"=",
"array",
"(",
"'currency'",
"=>",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"[",
"'currency'",
"]",
")",
"?",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"[",
"'currency'",
"]",
":",
"$",
"matches",
"[",
"2",
"]",
")",
",",
"'amount'",
"=>",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"[",
"'amount'",
"]",
")",
"?",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"[",
"'amount'",
"]",
":",
"$",
"matches",
"[",
"1",
"]",
")",
",",
"'vat'",
"=>",
"(",
"!",
"empty",
"(",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"[",
"'vat'",
"]",
")",
"?",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"[",
"'vat'",
"]",
":",
"null",
")",
",",
")",
";",
"return",
"$",
"this",
"->",
"defaults",
";",
"}"
] | Return default values.
@return array | [
"Return",
"default",
"values",
"."
] | train | https://github.com/mrbase/Smesg/blob/e9692ed5915f5a9cd4dca0df875935a2c528e128/src/Smesg/Provider/UnwireProvider.php#L130-L141 |
mrbase/Smesg | src/Smesg/Provider/UnwireProvider.php | UnwireProvider.addMessage | public function addMessage($to, $message, array $options = array(), $autoSend = false)
{
if (count($this->messages) == self::BATCH_MAX_QUANTITY) {
throw new MaxMessagesReachedException('Unwire batch mode does not allow more than '.self::BATCH_MAX_QUANTITY.' pr. batch.');
}
if ($this->config['get_smsc']) {
$options['smsc'] = $this->getSmsc($to);
}
if (isset($options['price']) && !preg_match('/[0-9]+\.[0-9]{2}[A-Z]{3}/', $options['price'])) {
throw new InvalidArgumentException('The price must be in the format "00.00XXX" where XXX is the correct currency code for the destination country.');
}
return parent::addMessage($to, $message, $options, $autoSend);
} | php | public function addMessage($to, $message, array $options = array(), $autoSend = false)
{
if (count($this->messages) == self::BATCH_MAX_QUANTITY) {
throw new MaxMessagesReachedException('Unwire batch mode does not allow more than '.self::BATCH_MAX_QUANTITY.' pr. batch.');
}
if ($this->config['get_smsc']) {
$options['smsc'] = $this->getSmsc($to);
}
if (isset($options['price']) && !preg_match('/[0-9]+\.[0-9]{2}[A-Z]{3}/', $options['price'])) {
throw new InvalidArgumentException('The price must be in the format "00.00XXX" where XXX is the correct currency code for the destination country.');
}
return parent::addMessage($to, $message, $options, $autoSend);
} | [
"public",
"function",
"addMessage",
"(",
"$",
"to",
",",
"$",
"message",
",",
"array",
"$",
"options",
"=",
"array",
"(",
")",
",",
"$",
"autoSend",
"=",
"false",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"this",
"->",
"messages",
")",
"==",
"self",
"::",
"BATCH_MAX_QUANTITY",
")",
"{",
"throw",
"new",
"MaxMessagesReachedException",
"(",
"'Unwire batch mode does not allow more than '",
".",
"self",
"::",
"BATCH_MAX_QUANTITY",
".",
"' pr. batch.'",
")",
";",
"}",
"if",
"(",
"$",
"this",
"->",
"config",
"[",
"'get_smsc'",
"]",
")",
"{",
"$",
"options",
"[",
"'smsc'",
"]",
"=",
"$",
"this",
"->",
"getSmsc",
"(",
"$",
"to",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"options",
"[",
"'price'",
"]",
")",
"&&",
"!",
"preg_match",
"(",
"'/[0-9]+\\.[0-9]{2}[A-Z]{3}/'",
",",
"$",
"options",
"[",
"'price'",
"]",
")",
")",
"{",
"throw",
"new",
"InvalidArgumentException",
"(",
"'The price must be in the format \"00.00XXX\" where XXX is the correct currency code for the destination country.'",
")",
";",
"}",
"return",
"parent",
"::",
"addMessage",
"(",
"$",
"to",
",",
"$",
"message",
",",
"$",
"options",
",",
"$",
"autoSend",
")",
";",
"}"
] | {@inheritDoc}
@throws MaxMessagesReachedException
@throws InvalidArgumentException | [
"{",
"@inheritDoc",
"}"
] | train | https://github.com/mrbase/Smesg/blob/e9692ed5915f5a9cd4dca0df875935a2c528e128/src/Smesg/Provider/UnwireProvider.php#L150-L165 |
mrbase/Smesg | src/Smesg/Provider/UnwireProvider.php | UnwireProvider.send | public function send($dry_run = false)
{
switch (count($this->messages)) {
case 0:
throw new RuntimeException("No messages to send.");
case 1:
return $this->sendOne($dry_run);
}
$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="utf-8" ?><messages></messages>');
$xml->addAttribute('xmlns', 'http://www.unwire.com/UM/core/v1.3');
$xml->addAttribute('xsi:schemaLocation', 'http://www.unwire.com/UM/core/v1.3 https://gw.unwire.com/service/xmlinterface/core-1.3.xsd', 'http://www.w3.org/2001/XMLSchema-instance');
$xml->addAttribute('count', count($this->messages));
$xml->addAttribute('service', 'mt');
$xml->addAttribute('sessionid', (session_id() ?: time()));
$default = $xml->addChild('defaultvalues');
$default->addAttribute('type', 'text');
// set default values
foreach ($this->getDefaultValues() as $key => $value) {
if ($key == 'content') {
$content = $default->addChild($key);
$content->addChild('text', $value);
} else if ($key == 'price') {
$price = $default->addChild('price', $value['amount']);
$price->addAttribute('currency', $value['currency']);
if (!is_null($value['vat'])) {
$price->addAttribute('vat', $value['vat']);
}
} else {
if ($value) {
$default->addChild($key, $value);
}
}
}
$i=1;
// add messages
foreach ($this->messages as $message) {
$msg = $xml->addChild('sms');
$msg->addAttribute('id', $i);
$msg->addAttribute('type', 'text');
$msg->addChild('msisdn', $message->to);
if (empty($this->defaults['content'])) {
$content = $msg->addChild('content');
$content->addChild('text', $message->message);
}
if (empty($this->defaults['operator']) && isset($message->options['smsc'])) {
$msg->addChild('operator', $message->options['smsc']);
}
if (isset($message->options['shortcode'])) {
$msg->addChild('mediacode', $message->options['shortcode']);
} else if (empty($this->defaults['shortcode'])) {
$msg->addChild('shortcode', $this->config['appnr']);
}
if (isset($message->options['mediacode'])) {
$msg->addChild('mediacode', $message->options['mediacode']);
} else if (empty($this->defaults['mediacode'])) {
$msg->addChild('mediacode', $this->config['mediacode']);
}
if (isset($message->options['price'])) {
preg_match('/([0-9.]+)([A-Z]{3})/', $message->options['price'], $matches);
$price = $msg->addChild('price', $matches[1]);
$price->addAttribute('currency', $matches[2]);
if (!is_null($this->defaults['price']['vat'])) {
$price->addAttribute('vat', $this->defaults['price']['vat']);
}
}
$i++;
}
$endpoint = str_replace('://', '://'.$this->config['user'].':'.$this->config['password'].'@', self::BATCH_ENDPOINT);
$adapter = $this->getAdapter();
$adapter->setEndpoint($endpoint);
$adapter->setBody($xml->asXML());
if ($dry_run) {
$response = $adapter->dryRun();
} else {
$response = $adapter->post();
}
// empty query
$this->messages = array();
return $response;
} | php | public function send($dry_run = false)
{
switch (count($this->messages)) {
case 0:
throw new RuntimeException("No messages to send.");
case 1:
return $this->sendOne($dry_run);
}
$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="utf-8" ?><messages></messages>');
$xml->addAttribute('xmlns', 'http://www.unwire.com/UM/core/v1.3');
$xml->addAttribute('xsi:schemaLocation', 'http://www.unwire.com/UM/core/v1.3 https://gw.unwire.com/service/xmlinterface/core-1.3.xsd', 'http://www.w3.org/2001/XMLSchema-instance');
$xml->addAttribute('count', count($this->messages));
$xml->addAttribute('service', 'mt');
$xml->addAttribute('sessionid', (session_id() ?: time()));
$default = $xml->addChild('defaultvalues');
$default->addAttribute('type', 'text');
// set default values
foreach ($this->getDefaultValues() as $key => $value) {
if ($key == 'content') {
$content = $default->addChild($key);
$content->addChild('text', $value);
} else if ($key == 'price') {
$price = $default->addChild('price', $value['amount']);
$price->addAttribute('currency', $value['currency']);
if (!is_null($value['vat'])) {
$price->addAttribute('vat', $value['vat']);
}
} else {
if ($value) {
$default->addChild($key, $value);
}
}
}
$i=1;
// add messages
foreach ($this->messages as $message) {
$msg = $xml->addChild('sms');
$msg->addAttribute('id', $i);
$msg->addAttribute('type', 'text');
$msg->addChild('msisdn', $message->to);
if (empty($this->defaults['content'])) {
$content = $msg->addChild('content');
$content->addChild('text', $message->message);
}
if (empty($this->defaults['operator']) && isset($message->options['smsc'])) {
$msg->addChild('operator', $message->options['smsc']);
}
if (isset($message->options['shortcode'])) {
$msg->addChild('mediacode', $message->options['shortcode']);
} else if (empty($this->defaults['shortcode'])) {
$msg->addChild('shortcode', $this->config['appnr']);
}
if (isset($message->options['mediacode'])) {
$msg->addChild('mediacode', $message->options['mediacode']);
} else if (empty($this->defaults['mediacode'])) {
$msg->addChild('mediacode', $this->config['mediacode']);
}
if (isset($message->options['price'])) {
preg_match('/([0-9.]+)([A-Z]{3})/', $message->options['price'], $matches);
$price = $msg->addChild('price', $matches[1]);
$price->addAttribute('currency', $matches[2]);
if (!is_null($this->defaults['price']['vat'])) {
$price->addAttribute('vat', $this->defaults['price']['vat']);
}
}
$i++;
}
$endpoint = str_replace('://', '://'.$this->config['user'].':'.$this->config['password'].'@', self::BATCH_ENDPOINT);
$adapter = $this->getAdapter();
$adapter->setEndpoint($endpoint);
$adapter->setBody($xml->asXML());
if ($dry_run) {
$response = $adapter->dryRun();
} else {
$response = $adapter->post();
}
// empty query
$this->messages = array();
return $response;
} | [
"public",
"function",
"send",
"(",
"$",
"dry_run",
"=",
"false",
")",
"{",
"switch",
"(",
"count",
"(",
"$",
"this",
"->",
"messages",
")",
")",
"{",
"case",
"0",
":",
"throw",
"new",
"RuntimeException",
"(",
"\"No messages to send.\"",
")",
";",
"case",
"1",
":",
"return",
"$",
"this",
"->",
"sendOne",
"(",
"$",
"dry_run",
")",
";",
"}",
"$",
"xml",
"=",
"new",
"SimpleXMLExtended",
"(",
"'<?xml version=\"1.0\" encoding=\"utf-8\" ?><messages></messages>'",
")",
";",
"$",
"xml",
"->",
"addAttribute",
"(",
"'xmlns'",
",",
"'http://www.unwire.com/UM/core/v1.3'",
")",
";",
"$",
"xml",
"->",
"addAttribute",
"(",
"'xsi:schemaLocation'",
",",
"'http://www.unwire.com/UM/core/v1.3 https://gw.unwire.com/service/xmlinterface/core-1.3.xsd'",
",",
"'http://www.w3.org/2001/XMLSchema-instance'",
")",
";",
"$",
"xml",
"->",
"addAttribute",
"(",
"'count'",
",",
"count",
"(",
"$",
"this",
"->",
"messages",
")",
")",
";",
"$",
"xml",
"->",
"addAttribute",
"(",
"'service'",
",",
"'mt'",
")",
";",
"$",
"xml",
"->",
"addAttribute",
"(",
"'sessionid'",
",",
"(",
"session_id",
"(",
")",
"?",
":",
"time",
"(",
")",
")",
")",
";",
"$",
"default",
"=",
"$",
"xml",
"->",
"addChild",
"(",
"'defaultvalues'",
")",
";",
"$",
"default",
"->",
"addAttribute",
"(",
"'type'",
",",
"'text'",
")",
";",
"// set default values",
"foreach",
"(",
"$",
"this",
"->",
"getDefaultValues",
"(",
")",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"$",
"key",
"==",
"'content'",
")",
"{",
"$",
"content",
"=",
"$",
"default",
"->",
"addChild",
"(",
"$",
"key",
")",
";",
"$",
"content",
"->",
"addChild",
"(",
"'text'",
",",
"$",
"value",
")",
";",
"}",
"else",
"if",
"(",
"$",
"key",
"==",
"'price'",
")",
"{",
"$",
"price",
"=",
"$",
"default",
"->",
"addChild",
"(",
"'price'",
",",
"$",
"value",
"[",
"'amount'",
"]",
")",
";",
"$",
"price",
"->",
"addAttribute",
"(",
"'currency'",
",",
"$",
"value",
"[",
"'currency'",
"]",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"value",
"[",
"'vat'",
"]",
")",
")",
"{",
"$",
"price",
"->",
"addAttribute",
"(",
"'vat'",
",",
"$",
"value",
"[",
"'vat'",
"]",
")",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"$",
"value",
")",
"{",
"$",
"default",
"->",
"addChild",
"(",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"}",
"}",
"$",
"i",
"=",
"1",
";",
"// add messages",
"foreach",
"(",
"$",
"this",
"->",
"messages",
"as",
"$",
"message",
")",
"{",
"$",
"msg",
"=",
"$",
"xml",
"->",
"addChild",
"(",
"'sms'",
")",
";",
"$",
"msg",
"->",
"addAttribute",
"(",
"'id'",
",",
"$",
"i",
")",
";",
"$",
"msg",
"->",
"addAttribute",
"(",
"'type'",
",",
"'text'",
")",
";",
"$",
"msg",
"->",
"addChild",
"(",
"'msisdn'",
",",
"$",
"message",
"->",
"to",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"defaults",
"[",
"'content'",
"]",
")",
")",
"{",
"$",
"content",
"=",
"$",
"msg",
"->",
"addChild",
"(",
"'content'",
")",
";",
"$",
"content",
"->",
"addChild",
"(",
"'text'",
",",
"$",
"message",
"->",
"message",
")",
";",
"}",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"defaults",
"[",
"'operator'",
"]",
")",
"&&",
"isset",
"(",
"$",
"message",
"->",
"options",
"[",
"'smsc'",
"]",
")",
")",
"{",
"$",
"msg",
"->",
"addChild",
"(",
"'operator'",
",",
"$",
"message",
"->",
"options",
"[",
"'smsc'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"message",
"->",
"options",
"[",
"'shortcode'",
"]",
")",
")",
"{",
"$",
"msg",
"->",
"addChild",
"(",
"'mediacode'",
",",
"$",
"message",
"->",
"options",
"[",
"'shortcode'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"defaults",
"[",
"'shortcode'",
"]",
")",
")",
"{",
"$",
"msg",
"->",
"addChild",
"(",
"'shortcode'",
",",
"$",
"this",
"->",
"config",
"[",
"'appnr'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"message",
"->",
"options",
"[",
"'mediacode'",
"]",
")",
")",
"{",
"$",
"msg",
"->",
"addChild",
"(",
"'mediacode'",
",",
"$",
"message",
"->",
"options",
"[",
"'mediacode'",
"]",
")",
";",
"}",
"else",
"if",
"(",
"empty",
"(",
"$",
"this",
"->",
"defaults",
"[",
"'mediacode'",
"]",
")",
")",
"{",
"$",
"msg",
"->",
"addChild",
"(",
"'mediacode'",
",",
"$",
"this",
"->",
"config",
"[",
"'mediacode'",
"]",
")",
";",
"}",
"if",
"(",
"isset",
"(",
"$",
"message",
"->",
"options",
"[",
"'price'",
"]",
")",
")",
"{",
"preg_match",
"(",
"'/([0-9.]+)([A-Z]{3})/'",
",",
"$",
"message",
"->",
"options",
"[",
"'price'",
"]",
",",
"$",
"matches",
")",
";",
"$",
"price",
"=",
"$",
"msg",
"->",
"addChild",
"(",
"'price'",
",",
"$",
"matches",
"[",
"1",
"]",
")",
";",
"$",
"price",
"->",
"addAttribute",
"(",
"'currency'",
",",
"$",
"matches",
"[",
"2",
"]",
")",
";",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"[",
"'vat'",
"]",
")",
")",
"{",
"$",
"price",
"->",
"addAttribute",
"(",
"'vat'",
",",
"$",
"this",
"->",
"defaults",
"[",
"'price'",
"]",
"[",
"'vat'",
"]",
")",
";",
"}",
"}",
"$",
"i",
"++",
";",
"}",
"$",
"endpoint",
"=",
"str_replace",
"(",
"'://'",
",",
"'://'",
".",
"$",
"this",
"->",
"config",
"[",
"'user'",
"]",
".",
"':'",
".",
"$",
"this",
"->",
"config",
"[",
"'password'",
"]",
".",
"'@'",
",",
"self",
"::",
"BATCH_ENDPOINT",
")",
";",
"$",
"adapter",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
";",
"$",
"adapter",
"->",
"setEndpoint",
"(",
"$",
"endpoint",
")",
";",
"$",
"adapter",
"->",
"setBody",
"(",
"$",
"xml",
"->",
"asXML",
"(",
")",
")",
";",
"if",
"(",
"$",
"dry_run",
")",
"{",
"$",
"response",
"=",
"$",
"adapter",
"->",
"dryRun",
"(",
")",
";",
"}",
"else",
"{",
"$",
"response",
"=",
"$",
"adapter",
"->",
"post",
"(",
")",
";",
"}",
"// empty query",
"$",
"this",
"->",
"messages",
"=",
"array",
"(",
")",
";",
"return",
"$",
"response",
";",
"}"
] | {@inheritDoc}
@see UnwireProvider::sendOne() | [
"{",
"@inheritDoc",
"}"
] | train | https://github.com/mrbase/Smesg/blob/e9692ed5915f5a9cd4dca0df875935a2c528e128/src/Smesg/Provider/UnwireProvider.php#L173-L269 |
mrbase/Smesg | src/Smesg/Provider/UnwireProvider.php | UnwireProvider.getSmsc | protected function getSmsc($number)
{
$adapter = $this->getAdapter();
$adapter->setEndpoint(self::SMSC_ENDPOINT);
$adapter->setParameters(array(
'user' => $this->config['user'],
'password' => $this->config['password'],
'msisdn' => $number
));
$response = $adapter->get();
return $response->getBody();
} | php | protected function getSmsc($number)
{
$adapter = $this->getAdapter();
$adapter->setEndpoint(self::SMSC_ENDPOINT);
$adapter->setParameters(array(
'user' => $this->config['user'],
'password' => $this->config['password'],
'msisdn' => $number
));
$response = $adapter->get();
return $response->getBody();
} | [
"protected",
"function",
"getSmsc",
"(",
"$",
"number",
")",
"{",
"$",
"adapter",
"=",
"$",
"this",
"->",
"getAdapter",
"(",
")",
";",
"$",
"adapter",
"->",
"setEndpoint",
"(",
"self",
"::",
"SMSC_ENDPOINT",
")",
";",
"$",
"adapter",
"->",
"setParameters",
"(",
"array",
"(",
"'user'",
"=>",
"$",
"this",
"->",
"config",
"[",
"'user'",
"]",
",",
"'password'",
"=>",
"$",
"this",
"->",
"config",
"[",
"'password'",
"]",
",",
"'msisdn'",
"=>",
"$",
"number",
")",
")",
";",
"$",
"response",
"=",
"$",
"adapter",
"->",
"get",
"(",
")",
";",
"return",
"$",
"response",
"->",
"getBody",
"(",
")",
";",
"}"
] | Get smsc for a given mobile number.
TODO: implement some sort of caching here.
@param int $number the mobilenumber with countrycode prefix, not zero-padded tho
@return string | [
"Get",
"smsc",
"for",
"a",
"given",
"mobile",
"number",
"."
] | train | https://github.com/mrbase/Smesg/blob/e9692ed5915f5a9cd4dca0df875935a2c528e128/src/Smesg/Provider/UnwireProvider.php#L310-L322 |
wobblecode/WobbleCodeUserBundle | EventListener/RegistrationSubscriber.php | RegistrationSubscriber.getIpInfo | public function getIpInfo()
{
$request = $this->requestStack->getCurrentRequest();
$ipInfo = [];
$ipInfo['country'] = $request->server->get('GEOIP_COUNTRY_CODE', null);
$ipInfo['city'] = $request->server->get('GEOIP_CITY', null);
$ipInfo['region'] = $request->server->get('GEOIP_REGION_NAME', null);
$ipInfo['ip'] = $request->getClientIp();
return $ipInfo;
} | php | public function getIpInfo()
{
$request = $this->requestStack->getCurrentRequest();
$ipInfo = [];
$ipInfo['country'] = $request->server->get('GEOIP_COUNTRY_CODE', null);
$ipInfo['city'] = $request->server->get('GEOIP_CITY', null);
$ipInfo['region'] = $request->server->get('GEOIP_REGION_NAME', null);
$ipInfo['ip'] = $request->getClientIp();
return $ipInfo;
} | [
"public",
"function",
"getIpInfo",
"(",
")",
"{",
"$",
"request",
"=",
"$",
"this",
"->",
"requestStack",
"->",
"getCurrentRequest",
"(",
")",
";",
"$",
"ipInfo",
"=",
"[",
"]",
";",
"$",
"ipInfo",
"[",
"'country'",
"]",
"=",
"$",
"request",
"->",
"server",
"->",
"get",
"(",
"'GEOIP_COUNTRY_CODE'",
",",
"null",
")",
";",
"$",
"ipInfo",
"[",
"'city'",
"]",
"=",
"$",
"request",
"->",
"server",
"->",
"get",
"(",
"'GEOIP_CITY'",
",",
"null",
")",
";",
"$",
"ipInfo",
"[",
"'region'",
"]",
"=",
"$",
"request",
"->",
"server",
"->",
"get",
"(",
"'GEOIP_REGION_NAME'",
",",
"null",
")",
";",
"$",
"ipInfo",
"[",
"'ip'",
"]",
"=",
"$",
"request",
"->",
"getClientIp",
"(",
")",
";",
"return",
"$",
"ipInfo",
";",
"}"
] | Gets array with IP info and Geo Ip
@return array | [
"Gets",
"array",
"with",
"IP",
"info",
"and",
"Geo",
"Ip"
] | train | https://github.com/wobblecode/WobbleCodeUserBundle/blob/7b8206f8b4a50fbc61f7bfe4f83eb466cad96440/EventListener/RegistrationSubscriber.php#L159-L170 |
KDF5000/EasyThink | src/ThinkPHP/Mode/Lite/View.php | View.assign | public function assign($name,$value=''){
if(is_array($name)) {
$this->tVar = array_merge($this->tVar,$name);
}else {
$this->tVar[$name] = $value;
}
} | php | public function assign($name,$value=''){
if(is_array($name)) {
$this->tVar = array_merge($this->tVar,$name);
}else {
$this->tVar[$name] = $value;
}
} | [
"public",
"function",
"assign",
"(",
"$",
"name",
",",
"$",
"value",
"=",
"''",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"name",
")",
")",
"{",
"$",
"this",
"->",
"tVar",
"=",
"array_merge",
"(",
"$",
"this",
"->",
"tVar",
",",
"$",
"name",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"tVar",
"[",
"$",
"name",
"]",
"=",
"$",
"value",
";",
"}",
"}"
] | 模板变量赋值
@access public
@param mixed $name
@param mixed $value | [
"模板变量赋值"
] | train | https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Mode/Lite/View.php#L36-L42 |
KDF5000/EasyThink | src/ThinkPHP/Mode/Lite/View.php | View.fetch | public function fetch($templateFile='',$content='',$prefix='') {
if(empty($content)) {
$templateFile = $this->parseTemplate($templateFile);
// 模板文件不存在直接返回
if(!is_file($templateFile)) E(L('_TEMPLATE_NOT_EXIST_').':'.$templateFile);
}else{
defined('THEME_PATH') or define('THEME_PATH', $this->getThemePath());
}
// 页面缓存
ob_start();
ob_implicit_flush(0);
if('php' == strtolower(C('TMPL_ENGINE_TYPE'))) { // 使用PHP原生模板
$_content = $content;
// 模板阵列变量分解成为独立变量
extract($this->tVar, EXTR_OVERWRITE);
// 直接载入PHP模板
empty($_content)?include $templateFile:eval('?>'.$_content);
}else{
// 视图解析标签
$params = array('var'=>$this->tVar,'file'=>$templateFile,'content'=>$content,'prefix'=>$prefix);
$_content = !empty($content)?:$templateFile;
if((!empty($content) && $this->checkContentCache($content,$prefix)) || $this->checkCache($templateFile,$prefix)) { // 缓存有效
//载入模版缓存文件
Storage::load(C('CACHE_PATH').$prefix.md5($_content).C('TMPL_CACHFILE_SUFFIX'),$this->tVar);
}else{
$tpl = Think::instance('Think\\Template');
// 编译并加载模板文件
$tpl->fetch($_content,$this->tVar,$prefix);
}
}
// 获取并清空缓存
$content = ob_get_clean();
// 内容过滤标签
// 系统默认的特殊变量替换
$replace = array(
'__ROOT__' => __ROOT__, // 当前网站地址
'__APP__' => __APP__, // 当前应用地址
'__MODULE__' => __MODULE__,
'__ACTION__' => __ACTION__, // 当前操作地址
'__SELF__' => __SELF__, // 当前页面地址
'__CONTROLLER__'=> __CONTROLLER__,
'__URL__' => __CONTROLLER__,
'__PUBLIC__' => __ROOT__.'/Public',// 站点公共目录
);
// 允许用户自定义模板的字符串替换
if(is_array(C('TMPL_PARSE_STRING')) )
$replace = array_merge($replace,C('TMPL_PARSE_STRING'));
$content = str_replace(array_keys($replace),array_values($replace),$content);
// 输出模板文件
return $content;
} | php | public function fetch($templateFile='',$content='',$prefix='') {
if(empty($content)) {
$templateFile = $this->parseTemplate($templateFile);
// 模板文件不存在直接返回
if(!is_file($templateFile)) E(L('_TEMPLATE_NOT_EXIST_').':'.$templateFile);
}else{
defined('THEME_PATH') or define('THEME_PATH', $this->getThemePath());
}
// 页面缓存
ob_start();
ob_implicit_flush(0);
if('php' == strtolower(C('TMPL_ENGINE_TYPE'))) { // 使用PHP原生模板
$_content = $content;
// 模板阵列变量分解成为独立变量
extract($this->tVar, EXTR_OVERWRITE);
// 直接载入PHP模板
empty($_content)?include $templateFile:eval('?>'.$_content);
}else{
// 视图解析标签
$params = array('var'=>$this->tVar,'file'=>$templateFile,'content'=>$content,'prefix'=>$prefix);
$_content = !empty($content)?:$templateFile;
if((!empty($content) && $this->checkContentCache($content,$prefix)) || $this->checkCache($templateFile,$prefix)) { // 缓存有效
//载入模版缓存文件
Storage::load(C('CACHE_PATH').$prefix.md5($_content).C('TMPL_CACHFILE_SUFFIX'),$this->tVar);
}else{
$tpl = Think::instance('Think\\Template');
// 编译并加载模板文件
$tpl->fetch($_content,$this->tVar,$prefix);
}
}
// 获取并清空缓存
$content = ob_get_clean();
// 内容过滤标签
// 系统默认的特殊变量替换
$replace = array(
'__ROOT__' => __ROOT__, // 当前网站地址
'__APP__' => __APP__, // 当前应用地址
'__MODULE__' => __MODULE__,
'__ACTION__' => __ACTION__, // 当前操作地址
'__SELF__' => __SELF__, // 当前页面地址
'__CONTROLLER__'=> __CONTROLLER__,
'__URL__' => __CONTROLLER__,
'__PUBLIC__' => __ROOT__.'/Public',// 站点公共目录
);
// 允许用户自定义模板的字符串替换
if(is_array(C('TMPL_PARSE_STRING')) )
$replace = array_merge($replace,C('TMPL_PARSE_STRING'));
$content = str_replace(array_keys($replace),array_values($replace),$content);
// 输出模板文件
return $content;
} | [
"public",
"function",
"fetch",
"(",
"$",
"templateFile",
"=",
"''",
",",
"$",
"content",
"=",
"''",
",",
"$",
"prefix",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"content",
")",
")",
"{",
"$",
"templateFile",
"=",
"$",
"this",
"->",
"parseTemplate",
"(",
"$",
"templateFile",
")",
";",
"// 模板文件不存在直接返回",
"if",
"(",
"!",
"is_file",
"(",
"$",
"templateFile",
")",
")",
"E",
"(",
"L",
"(",
"'_TEMPLATE_NOT_EXIST_'",
")",
".",
"':'",
".",
"$",
"templateFile",
")",
";",
"}",
"else",
"{",
"defined",
"(",
"'THEME_PATH'",
")",
"or",
"define",
"(",
"'THEME_PATH'",
",",
"$",
"this",
"->",
"getThemePath",
"(",
")",
")",
";",
"}",
"// 页面缓存",
"ob_start",
"(",
")",
";",
"ob_implicit_flush",
"(",
"0",
")",
";",
"if",
"(",
"'php'",
"==",
"strtolower",
"(",
"C",
"(",
"'TMPL_ENGINE_TYPE'",
")",
")",
")",
"{",
"// 使用PHP原生模板",
"$",
"_content",
"=",
"$",
"content",
";",
"// 模板阵列变量分解成为独立变量",
"extract",
"(",
"$",
"this",
"->",
"tVar",
",",
"EXTR_OVERWRITE",
")",
";",
"// 直接载入PHP模板",
"empty",
"(",
"$",
"_content",
")",
"?",
"include",
"$",
"templateFile",
":",
"eval",
"(",
"'?>'",
".",
"$",
"_content",
")",
";",
"}",
"else",
"{",
"// 视图解析标签",
"$",
"params",
"=",
"array",
"(",
"'var'",
"=>",
"$",
"this",
"->",
"tVar",
",",
"'file'",
"=>",
"$",
"templateFile",
",",
"'content'",
"=>",
"$",
"content",
",",
"'prefix'",
"=>",
"$",
"prefix",
")",
";",
"$",
"_content",
"=",
"!",
"empty",
"(",
"$",
"content",
")",
"?",
":",
"$",
"templateFile",
";",
"if",
"(",
"(",
"!",
"empty",
"(",
"$",
"content",
")",
"&&",
"$",
"this",
"->",
"checkContentCache",
"(",
"$",
"content",
",",
"$",
"prefix",
")",
")",
"||",
"$",
"this",
"->",
"checkCache",
"(",
"$",
"templateFile",
",",
"$",
"prefix",
")",
")",
"{",
"// 缓存有效",
"//载入模版缓存文件",
"Storage",
"::",
"load",
"(",
"C",
"(",
"'CACHE_PATH'",
")",
".",
"$",
"prefix",
".",
"md5",
"(",
"$",
"_content",
")",
".",
"C",
"(",
"'TMPL_CACHFILE_SUFFIX'",
")",
",",
"$",
"this",
"->",
"tVar",
")",
";",
"}",
"else",
"{",
"$",
"tpl",
"=",
"Think",
"::",
"instance",
"(",
"'Think\\\\Template'",
")",
";",
"// 编译并加载模板文件",
"$",
"tpl",
"->",
"fetch",
"(",
"$",
"_content",
",",
"$",
"this",
"->",
"tVar",
",",
"$",
"prefix",
")",
";",
"}",
"}",
"// 获取并清空缓存",
"$",
"content",
"=",
"ob_get_clean",
"(",
")",
";",
"// 内容过滤标签",
"// 系统默认的特殊变量替换",
"$",
"replace",
"=",
"array",
"(",
"'__ROOT__'",
"=>",
"__ROOT__",
",",
"// 当前网站地址",
"'__APP__'",
"=>",
"__APP__",
",",
"// 当前应用地址",
"'__MODULE__'",
"=>",
"__MODULE__",
",",
"'__ACTION__'",
"=>",
"__ACTION__",
",",
"// 当前操作地址",
"'__SELF__'",
"=>",
"__SELF__",
",",
"// 当前页面地址",
"'__CONTROLLER__'",
"=>",
"__CONTROLLER__",
",",
"'__URL__'",
"=>",
"__CONTROLLER__",
",",
"'__PUBLIC__'",
"=>",
"__ROOT__",
".",
"'/Public'",
",",
"// 站点公共目录",
")",
";",
"// 允许用户自定义模板的字符串替换",
"if",
"(",
"is_array",
"(",
"C",
"(",
"'TMPL_PARSE_STRING'",
")",
")",
")",
"$",
"replace",
"=",
"array_merge",
"(",
"$",
"replace",
",",
"C",
"(",
"'TMPL_PARSE_STRING'",
")",
")",
";",
"$",
"content",
"=",
"str_replace",
"(",
"array_keys",
"(",
"$",
"replace",
")",
",",
"array_values",
"(",
"$",
"replace",
")",
",",
"$",
"content",
")",
";",
"// 输出模板文件",
"return",
"$",
"content",
";",
"}"
] | 解析和获取模板内容 用于输出
@access public
@param string $templateFile 模板文件名
@param string $content 模板输出内容
@param string $prefix 模板缓存前缀
@return string | [
"解析和获取模板内容",
"用于输出"
] | train | https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Mode/Lite/View.php#L102-L152 |
KDF5000/EasyThink | src/ThinkPHP/Mode/Lite/View.php | View.checkContentCache | protected function checkContentCache($tmplContent,$prefix='') {
if(Storage::has(C('CACHE_PATH').$prefix.md5($tmplContent).C('TMPL_CACHFILE_SUFFIX'))){
return true;
}else{
return false;
}
} | php | protected function checkContentCache($tmplContent,$prefix='') {
if(Storage::has(C('CACHE_PATH').$prefix.md5($tmplContent).C('TMPL_CACHFILE_SUFFIX'))){
return true;
}else{
return false;
}
} | [
"protected",
"function",
"checkContentCache",
"(",
"$",
"tmplContent",
",",
"$",
"prefix",
"=",
"''",
")",
"{",
"if",
"(",
"Storage",
"::",
"has",
"(",
"C",
"(",
"'CACHE_PATH'",
")",
".",
"$",
"prefix",
".",
"md5",
"(",
"$",
"tmplContent",
")",
".",
"C",
"(",
"'TMPL_CACHFILE_SUFFIX'",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"}"
] | 检查缓存内容是否有效
如果无效则需要重新编译
@access public
@param string $tmplContent 模板内容
@return boolean | [
"检查缓存内容是否有效",
"如果无效则需要重新编译"
] | train | https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Mode/Lite/View.php#L192-L198 |
KDF5000/EasyThink | src/ThinkPHP/Mode/Lite/View.php | View.parseTemplate | public function parseTemplate($template='') {
if(is_file($template)) {
return $template;
}
$depr = C('TMPL_FILE_DEPR');
$template = str_replace(':', $depr, $template);
// 获取当前模块
$module = MODULE_NAME;
if(strpos($template,'@')){ // 跨模块调用模版文件
list($module,$template) = explode('@',$template);
}
// 获取当前主题的模版路径
defined('THEME_PATH') or define('THEME_PATH', $this->getThemePath($module));
// 分析模板文件规则
if('' == $template) {
// 如果模板文件名为空 按照默认规则定位
$template = CONTROLLER_NAME . $depr . ACTION_NAME;
}elseif(false === strpos($template, $depr)){
$template = CONTROLLER_NAME . $depr . $template;
}
$file = THEME_PATH.$template.C('TMPL_TEMPLATE_SUFFIX');
if(C('TMPL_LOAD_DEFAULTTHEME') && THEME_NAME != C('DEFAULT_THEME') && !is_file($file)){
// 找不到当前主题模板的时候定位默认主题中的模板
$file = dirname(THEME_PATH).'/'.C('DEFAULT_THEME').'/'.$template.C('TMPL_TEMPLATE_SUFFIX');
}
return $file;
} | php | public function parseTemplate($template='') {
if(is_file($template)) {
return $template;
}
$depr = C('TMPL_FILE_DEPR');
$template = str_replace(':', $depr, $template);
// 获取当前模块
$module = MODULE_NAME;
if(strpos($template,'@')){ // 跨模块调用模版文件
list($module,$template) = explode('@',$template);
}
// 获取当前主题的模版路径
defined('THEME_PATH') or define('THEME_PATH', $this->getThemePath($module));
// 分析模板文件规则
if('' == $template) {
// 如果模板文件名为空 按照默认规则定位
$template = CONTROLLER_NAME . $depr . ACTION_NAME;
}elseif(false === strpos($template, $depr)){
$template = CONTROLLER_NAME . $depr . $template;
}
$file = THEME_PATH.$template.C('TMPL_TEMPLATE_SUFFIX');
if(C('TMPL_LOAD_DEFAULTTHEME') && THEME_NAME != C('DEFAULT_THEME') && !is_file($file)){
// 找不到当前主题模板的时候定位默认主题中的模板
$file = dirname(THEME_PATH).'/'.C('DEFAULT_THEME').'/'.$template.C('TMPL_TEMPLATE_SUFFIX');
}
return $file;
} | [
"public",
"function",
"parseTemplate",
"(",
"$",
"template",
"=",
"''",
")",
"{",
"if",
"(",
"is_file",
"(",
"$",
"template",
")",
")",
"{",
"return",
"$",
"template",
";",
"}",
"$",
"depr",
"=",
"C",
"(",
"'TMPL_FILE_DEPR'",
")",
";",
"$",
"template",
"=",
"str_replace",
"(",
"':'",
",",
"$",
"depr",
",",
"$",
"template",
")",
";",
"// 获取当前模块",
"$",
"module",
"=",
"MODULE_NAME",
";",
"if",
"(",
"strpos",
"(",
"$",
"template",
",",
"'@'",
")",
")",
"{",
"// 跨模块调用模版文件",
"list",
"(",
"$",
"module",
",",
"$",
"template",
")",
"=",
"explode",
"(",
"'@'",
",",
"$",
"template",
")",
";",
"}",
"// 获取当前主题的模版路径",
"defined",
"(",
"'THEME_PATH'",
")",
"or",
"define",
"(",
"'THEME_PATH'",
",",
"$",
"this",
"->",
"getThemePath",
"(",
"$",
"module",
")",
")",
";",
"// 分析模板文件规则",
"if",
"(",
"''",
"==",
"$",
"template",
")",
"{",
"// 如果模板文件名为空 按照默认规则定位",
"$",
"template",
"=",
"CONTROLLER_NAME",
".",
"$",
"depr",
".",
"ACTION_NAME",
";",
"}",
"elseif",
"(",
"false",
"===",
"strpos",
"(",
"$",
"template",
",",
"$",
"depr",
")",
")",
"{",
"$",
"template",
"=",
"CONTROLLER_NAME",
".",
"$",
"depr",
".",
"$",
"template",
";",
"}",
"$",
"file",
"=",
"THEME_PATH",
".",
"$",
"template",
".",
"C",
"(",
"'TMPL_TEMPLATE_SUFFIX'",
")",
";",
"if",
"(",
"C",
"(",
"'TMPL_LOAD_DEFAULTTHEME'",
")",
"&&",
"THEME_NAME",
"!=",
"C",
"(",
"'DEFAULT_THEME'",
")",
"&&",
"!",
"is_file",
"(",
"$",
"file",
")",
")",
"{",
"// 找不到当前主题模板的时候定位默认主题中的模板",
"$",
"file",
"=",
"dirname",
"(",
"THEME_PATH",
")",
".",
"'/'",
".",
"C",
"(",
"'DEFAULT_THEME'",
")",
".",
"'/'",
".",
"$",
"template",
".",
"C",
"(",
"'TMPL_TEMPLATE_SUFFIX'",
")",
";",
"}",
"return",
"$",
"file",
";",
"}"
] | 自动定位模板文件
@access protected
@param string $template 模板文件规则
@return string | [
"自动定位模板文件"
] | train | https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Mode/Lite/View.php#L206-L234 |
KDF5000/EasyThink | src/ThinkPHP/Mode/Lite/View.php | View.getThemePath | protected function getThemePath($module=MODULE_NAME){
// 获取当前主题名称
$theme = $this->getTemplateTheme();
// 获取当前主题的模版路径
$tmplPath = C('VIEW_PATH'); // 模块设置独立的视图目录
if(!$tmplPath){
// 定义TMPL_PATH 则改变全局的视图目录到模块之外
$tmplPath = defined('TMPL_PATH')? TMPL_PATH.$module.'/' : APP_PATH.$module.'/'.C('DEFAULT_V_LAYER').'/';
}
return $tmplPath.$theme;
} | php | protected function getThemePath($module=MODULE_NAME){
// 获取当前主题名称
$theme = $this->getTemplateTheme();
// 获取当前主题的模版路径
$tmplPath = C('VIEW_PATH'); // 模块设置独立的视图目录
if(!$tmplPath){
// 定义TMPL_PATH 则改变全局的视图目录到模块之外
$tmplPath = defined('TMPL_PATH')? TMPL_PATH.$module.'/' : APP_PATH.$module.'/'.C('DEFAULT_V_LAYER').'/';
}
return $tmplPath.$theme;
} | [
"protected",
"function",
"getThemePath",
"(",
"$",
"module",
"=",
"MODULE_NAME",
")",
"{",
"// 获取当前主题名称",
"$",
"theme",
"=",
"$",
"this",
"->",
"getTemplateTheme",
"(",
")",
";",
"// 获取当前主题的模版路径",
"$",
"tmplPath",
"=",
"C",
"(",
"'VIEW_PATH'",
")",
";",
"// 模块设置独立的视图目录",
"if",
"(",
"!",
"$",
"tmplPath",
")",
"{",
"// 定义TMPL_PATH 则改变全局的视图目录到模块之外",
"$",
"tmplPath",
"=",
"defined",
"(",
"'TMPL_PATH'",
")",
"?",
"TMPL_PATH",
".",
"$",
"module",
".",
"'/'",
":",
"APP_PATH",
".",
"$",
"module",
".",
"'/'",
".",
"C",
"(",
"'DEFAULT_V_LAYER'",
")",
".",
"'/'",
";",
"}",
"return",
"$",
"tmplPath",
".",
"$",
"theme",
";",
"}"
] | 获取当前的模板路径
@access protected
@param string $module 模块名
@return string | [
"获取当前的模板路径"
] | train | https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Mode/Lite/View.php#L242-L252 |
KDF5000/EasyThink | src/ThinkPHP/Mode/Lite/View.php | View.getTemplateTheme | private function getTemplateTheme() {
if($this->theme) { // 指定模板主题
$theme = $this->theme;
}else{
/* 获取模板主题名称 */
$theme = C('DEFAULT_THEME');
if(C('TMPL_DETECT_THEME')) {// 自动侦测模板主题
$t = C('VAR_TEMPLATE');
if (isset($_GET[$t])){
$theme = $_GET[$t];
}elseif(cookie('think_template')){
$theme = cookie('think_template');
}
if(!in_array($theme,explode(',',C('THEME_LIST')))){
$theme = C('DEFAULT_THEME');
}
cookie('think_template',$theme,864000);
}
}
defined('THEME_NAME') || define('THEME_NAME', $theme); // 当前模板主题名称
return $theme?$theme . '/':'';
} | php | private function getTemplateTheme() {
if($this->theme) { // 指定模板主题
$theme = $this->theme;
}else{
/* 获取模板主题名称 */
$theme = C('DEFAULT_THEME');
if(C('TMPL_DETECT_THEME')) {// 自动侦测模板主题
$t = C('VAR_TEMPLATE');
if (isset($_GET[$t])){
$theme = $_GET[$t];
}elseif(cookie('think_template')){
$theme = cookie('think_template');
}
if(!in_array($theme,explode(',',C('THEME_LIST')))){
$theme = C('DEFAULT_THEME');
}
cookie('think_template',$theme,864000);
}
}
defined('THEME_NAME') || define('THEME_NAME', $theme); // 当前模板主题名称
return $theme?$theme . '/':'';
} | [
"private",
"function",
"getTemplateTheme",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"theme",
")",
"{",
"// 指定模板主题",
"$",
"theme",
"=",
"$",
"this",
"->",
"theme",
";",
"}",
"else",
"{",
"/* 获取模板主题名称 */",
"$",
"theme",
"=",
"C",
"(",
"'DEFAULT_THEME'",
")",
";",
"if",
"(",
"C",
"(",
"'TMPL_DETECT_THEME'",
")",
")",
"{",
"// 自动侦测模板主题",
"$",
"t",
"=",
"C",
"(",
"'VAR_TEMPLATE'",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"_GET",
"[",
"$",
"t",
"]",
")",
")",
"{",
"$",
"theme",
"=",
"$",
"_GET",
"[",
"$",
"t",
"]",
";",
"}",
"elseif",
"(",
"cookie",
"(",
"'think_template'",
")",
")",
"{",
"$",
"theme",
"=",
"cookie",
"(",
"'think_template'",
")",
";",
"}",
"if",
"(",
"!",
"in_array",
"(",
"$",
"theme",
",",
"explode",
"(",
"','",
",",
"C",
"(",
"'THEME_LIST'",
")",
")",
")",
")",
"{",
"$",
"theme",
"=",
"C",
"(",
"'DEFAULT_THEME'",
")",
";",
"}",
"cookie",
"(",
"'think_template'",
",",
"$",
"theme",
",",
"864000",
")",
";",
"}",
"}",
"defined",
"(",
"'THEME_NAME'",
")",
"||",
"define",
"(",
"'THEME_NAME'",
",",
"$",
"theme",
")",
";",
"// 当前模板主题名称",
"return",
"$",
"theme",
"?",
"$",
"theme",
".",
"'/'",
":",
"''",
";",
"}"
] | 获取当前的模板主题
@access private
@return string | [
"获取当前的模板主题"
] | train | https://github.com/KDF5000/EasyThink/blob/86efc9c8a0d504e01e2fea55868227fdc8928841/src/ThinkPHP/Mode/Lite/View.php#L270-L291 |
artscorestudio/user-bundle | Form/Type/SearchUserType.php | SearchUserType.buildForm | public function buildForm(FormBuilderInterface $builder, array $options)
{
$user_transformer = new StringToUserTransformer($this->userManager);
$builder->addModelTransformer($user_transformer);
} | php | public function buildForm(FormBuilderInterface $builder, array $options)
{
$user_transformer = new StringToUserTransformer($this->userManager);
$builder->addModelTransformer($user_transformer);
} | [
"public",
"function",
"buildForm",
"(",
"FormBuilderInterface",
"$",
"builder",
",",
"array",
"$",
"options",
")",
"{",
"$",
"user_transformer",
"=",
"new",
"StringToUserTransformer",
"(",
"$",
"this",
"->",
"userManager",
")",
";",
"$",
"builder",
"->",
"addModelTransformer",
"(",
"$",
"user_transformer",
")",
";",
"}"
] | (non-PHPdoc)
@see \Symfony\Component\Form\AbstractType::buildForm() | [
"(",
"non",
"-",
"PHPdoc",
")"
] | train | https://github.com/artscorestudio/user-bundle/blob/83e660d1073e1cbfde6eed0b528b8c99e78a2e53/Form/Type/SearchUserType.php#L46-L50 |
heiglandreas/OrgHeiglFileFinder | src/Service/Tokenlist.php | Tokenlist.getClassName | public function getClassName()
{
foreach ($this->tokenlist as $key => $token) {
if (T_CLASS === $token[0]) {
return $this->tokenlist[$key + 2][1];
}
}
return '';
} | php | public function getClassName()
{
foreach ($this->tokenlist as $key => $token) {
if (T_CLASS === $token[0]) {
return $this->tokenlist[$key + 2][1];
}
}
return '';
} | [
"public",
"function",
"getClassName",
"(",
")",
"{",
"foreach",
"(",
"$",
"this",
"->",
"tokenlist",
"as",
"$",
"key",
"=>",
"$",
"token",
")",
"{",
"if",
"(",
"T_CLASS",
"===",
"$",
"token",
"[",
"0",
"]",
")",
"{",
"return",
"$",
"this",
"->",
"tokenlist",
"[",
"$",
"key",
"+",
"2",
"]",
"[",
"1",
"]",
";",
"}",
"}",
"return",
"''",
";",
"}"
] | Get the first classname
@return string | [
"Get",
"the",
"first",
"classname"
] | train | https://github.com/heiglandreas/OrgHeiglFileFinder/blob/189d15b95bec7dc186ef73681463c104831234d8/src/Service/Tokenlist.php#L58-L67 |
heiglandreas/OrgHeiglFileFinder | src/Service/Tokenlist.php | Tokenlist.getNamespace | public function getNamespace()
{
$class = array();
$inNamespace = false;
foreach ($this->tokenlist as $key => $token) {
if (T_NAMESPACE === $token[0]) {
$inNamespace = true;
continue;
}
if (T_STRING === $token[0] && $inNamespace) {
$class[] = $token[1];
}
if (';' === $token && $inNamespace) {
return $class;
}
}
return array();
} | php | public function getNamespace()
{
$class = array();
$inNamespace = false;
foreach ($this->tokenlist as $key => $token) {
if (T_NAMESPACE === $token[0]) {
$inNamespace = true;
continue;
}
if (T_STRING === $token[0] && $inNamespace) {
$class[] = $token[1];
}
if (';' === $token && $inNamespace) {
return $class;
}
}
return array();
} | [
"public",
"function",
"getNamespace",
"(",
")",
"{",
"$",
"class",
"=",
"array",
"(",
")",
";",
"$",
"inNamespace",
"=",
"false",
";",
"foreach",
"(",
"$",
"this",
"->",
"tokenlist",
"as",
"$",
"key",
"=>",
"$",
"token",
")",
"{",
"if",
"(",
"T_NAMESPACE",
"===",
"$",
"token",
"[",
"0",
"]",
")",
"{",
"$",
"inNamespace",
"=",
"true",
";",
"continue",
";",
"}",
"if",
"(",
"T_STRING",
"===",
"$",
"token",
"[",
"0",
"]",
"&&",
"$",
"inNamespace",
")",
"{",
"$",
"class",
"[",
"]",
"=",
"$",
"token",
"[",
"1",
"]",
";",
"}",
"if",
"(",
"';'",
"===",
"$",
"token",
"&&",
"$",
"inNamespace",
")",
"{",
"return",
"$",
"class",
";",
"}",
"}",
"return",
"array",
"(",
")",
";",
"}"
] | Get the first namespace of the given content
@return array | [
"Get",
"the",
"first",
"namespace",
"of",
"the",
"given",
"content"
] | train | https://github.com/heiglandreas/OrgHeiglFileFinder/blob/189d15b95bec7dc186ef73681463c104831234d8/src/Service/Tokenlist.php#L74-L94 |
bseddon/XPath20 | TreeComparer.php | TreeComparer.TextEqual | protected function TextEqual( $a, $b )
{
if ( $this->excludeWhitespace )
return strcasecmp( CoreFuncs::Normalizespace( $a ), CoreFuncs::Normalizespace( $b ) ) == 0;
else
return strcasecmp( $a, $b ) == 0;
} | php | protected function TextEqual( $a, $b )
{
if ( $this->excludeWhitespace )
return strcasecmp( CoreFuncs::Normalizespace( $a ), CoreFuncs::Normalizespace( $b ) ) == 0;
else
return strcasecmp( $a, $b ) == 0;
} | [
"protected",
"function",
"TextEqual",
"(",
"$",
"a",
",",
"$",
"b",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"excludeWhitespace",
")",
"return",
"strcasecmp",
"(",
"CoreFuncs",
"::",
"Normalizespace",
"(",
"$",
"a",
")",
",",
"CoreFuncs",
"::",
"Normalizespace",
"(",
"$",
"b",
")",
")",
"==",
"0",
";",
"else",
"return",
"strcasecmp",
"(",
"$",
"a",
",",
"$",
"b",
")",
"==",
"0",
";",
"}"
] | TextEqual
@param string $a
@param string $b
@return bool | [
"TextEqual"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/TreeComparer.php#L124-L131 |
bseddon/XPath20 | TreeComparer.php | TreeComparer.ItemEqual | protected function ItemEqual( $item1, $item2 )
{
$xTypeCode = $item1->getSchemaType()->TypeCode;
$yTypeCode = $item2->getSchemaType()->TypeCode;
$types = array( XmlTypeCode::Decimal, XmlTypeCode::Float, XmlTypeCode::Double, XmlTypeCode::Integer );
$x = $item1->GetTypedValue();
// BMS 2018-01-19 Could be numeric
// Added to support typed member comparisons in FactVariables
if ( $this->untypedCanBeNumeric && $x instanceof UntypedAtomic )
{
if ( is_numeric( $x->getValue() ) )
{
$x = floatval( $x->getValue() );
}
}
if ( $x instanceof UntypedAtomic || $x instanceof AnyUriValue )
{
// Special case
// If $x is AnyUriValue or the attribute name is 'scheme' then
// normalize by making sure the scheme starts with a scheme
// such as http:// https:// ftp:// etc
$special = /* $x instanceof AnyUriValue || */ ( $item1 instanceof XPathNavigator && $item1->getLocalName() == 'scheme' );
$x = $x->ToString();
$xTypeCode = XmlTypeCode::String;
if ( $special && strpos( $x, "://" ) === false )
{
$x = "http://" . $x;
}
}
$y = $item2->GetTypedValue();
// BMS 2018-01-19 Could be numeric
// Added to support typed member comparisons in FactVariables
if ( $this->untypedCanBeNumeric && $y instanceof UntypedAtomic )
{
if ( is_numeric( $y->getValue() ) )
{
$y = floatval( $y->getValue() );
}
}
if ( $y instanceof UntypedAtomic || $y instanceof AnyUriValue )
{
// Special case
// If $y is AnyUriValue or the attribute name is 'scheme' then
// normalize by making sure the scheme starts with a scheme
// such as http:// https:// ftp:// etc
$special = /* $y instanceof AnyUriValue || */( $item2 instanceof XPathNavigator && $item2->getLocalName() == 'scheme' );
$y = $y->ToString();
$yTypeCode = XmlTypeCode::String;
if ( $special && strpos( $y, "://" ) === false )
{
$y = "http://" . $y;
}
}
if ( $this->useValueCompare )
{
if ( is_string( $x ) )
{
$x = trim( $x );
}
}
if ( $this->useValueCompare )
{
if ( is_string( $y ) )
{
$y = trim( $y );
}
}
if ( is_double( $x ) && is_nan( $x ) && is_double( $y ) && is_nan( $y ) )
{
return true;
}
if ( is_double( $x ) && is_infinite( $x ) && is_double( $y ) && is_infinite( $y ) )
{
return true;
}
if ( $xTypeCode != $yTypeCode )
{
// Handle the exceptions
$exceptions = (
( $xTypeCode == XmlTypeCode::Integer && in_array( $yTypeCode, $types ) ) ||
( $yTypeCode == XmlTypeCode::Integer && in_array( $xTypeCode, $types ) ) ||
( $xTypeCode == XmlTypeCode::Decimal && in_array( $yTypeCode, $types ) ) ||
( $yTypeCode == XmlTypeCode::Decimal && in_array( $xTypeCode, $types ) )
);
if ( ! $exceptions )
{
return false;
}
}
if ( ! is_null( $this->collation ) && is_string( $x ) && is_string( $y ) )
{
if ( $this->collation == XmlReservedNs::collationCodepoint )
{
$x = \normalizer_normalize( $x, \Normalizer::FORM_C );
$y = \normalizer_normalize( $y, \Normalizer::FORM_C );
return strcmp( $x, $y );
}
else
{
return strcoll( $x, $y ) == 0;
}
}
if ( ! is_object( $x ) && ! is_object( $y ) )
{
if ( $x == $y )
{
return true;
}
}
else if ( is_object( $x ) && is_object( $y ) && method_exists( $x, "Equals" ) && method_exists( $y, "Equals" ) )
{
if ( $x->Equals( $y ) )
{
return true;
}
}
$res;
$result = ValueProxy::EqValues( $x, $y, $res) && $res;
return $result;
} | php | protected function ItemEqual( $item1, $item2 )
{
$xTypeCode = $item1->getSchemaType()->TypeCode;
$yTypeCode = $item2->getSchemaType()->TypeCode;
$types = array( XmlTypeCode::Decimal, XmlTypeCode::Float, XmlTypeCode::Double, XmlTypeCode::Integer );
$x = $item1->GetTypedValue();
// BMS 2018-01-19 Could be numeric
// Added to support typed member comparisons in FactVariables
if ( $this->untypedCanBeNumeric && $x instanceof UntypedAtomic )
{
if ( is_numeric( $x->getValue() ) )
{
$x = floatval( $x->getValue() );
}
}
if ( $x instanceof UntypedAtomic || $x instanceof AnyUriValue )
{
// Special case
// If $x is AnyUriValue or the attribute name is 'scheme' then
// normalize by making sure the scheme starts with a scheme
// such as http:// https:// ftp:// etc
$special = /* $x instanceof AnyUriValue || */ ( $item1 instanceof XPathNavigator && $item1->getLocalName() == 'scheme' );
$x = $x->ToString();
$xTypeCode = XmlTypeCode::String;
if ( $special && strpos( $x, "://" ) === false )
{
$x = "http://" . $x;
}
}
$y = $item2->GetTypedValue();
// BMS 2018-01-19 Could be numeric
// Added to support typed member comparisons in FactVariables
if ( $this->untypedCanBeNumeric && $y instanceof UntypedAtomic )
{
if ( is_numeric( $y->getValue() ) )
{
$y = floatval( $y->getValue() );
}
}
if ( $y instanceof UntypedAtomic || $y instanceof AnyUriValue )
{
// Special case
// If $y is AnyUriValue or the attribute name is 'scheme' then
// normalize by making sure the scheme starts with a scheme
// such as http:// https:// ftp:// etc
$special = /* $y instanceof AnyUriValue || */( $item2 instanceof XPathNavigator && $item2->getLocalName() == 'scheme' );
$y = $y->ToString();
$yTypeCode = XmlTypeCode::String;
if ( $special && strpos( $y, "://" ) === false )
{
$y = "http://" . $y;
}
}
if ( $this->useValueCompare )
{
if ( is_string( $x ) )
{
$x = trim( $x );
}
}
if ( $this->useValueCompare )
{
if ( is_string( $y ) )
{
$y = trim( $y );
}
}
if ( is_double( $x ) && is_nan( $x ) && is_double( $y ) && is_nan( $y ) )
{
return true;
}
if ( is_double( $x ) && is_infinite( $x ) && is_double( $y ) && is_infinite( $y ) )
{
return true;
}
if ( $xTypeCode != $yTypeCode )
{
// Handle the exceptions
$exceptions = (
( $xTypeCode == XmlTypeCode::Integer && in_array( $yTypeCode, $types ) ) ||
( $yTypeCode == XmlTypeCode::Integer && in_array( $xTypeCode, $types ) ) ||
( $xTypeCode == XmlTypeCode::Decimal && in_array( $yTypeCode, $types ) ) ||
( $yTypeCode == XmlTypeCode::Decimal && in_array( $xTypeCode, $types ) )
);
if ( ! $exceptions )
{
return false;
}
}
if ( ! is_null( $this->collation ) && is_string( $x ) && is_string( $y ) )
{
if ( $this->collation == XmlReservedNs::collationCodepoint )
{
$x = \normalizer_normalize( $x, \Normalizer::FORM_C );
$y = \normalizer_normalize( $y, \Normalizer::FORM_C );
return strcmp( $x, $y );
}
else
{
return strcoll( $x, $y ) == 0;
}
}
if ( ! is_object( $x ) && ! is_object( $y ) )
{
if ( $x == $y )
{
return true;
}
}
else if ( is_object( $x ) && is_object( $y ) && method_exists( $x, "Equals" ) && method_exists( $y, "Equals" ) )
{
if ( $x->Equals( $y ) )
{
return true;
}
}
$res;
$result = ValueProxy::EqValues( $x, $y, $res) && $res;
return $result;
} | [
"protected",
"function",
"ItemEqual",
"(",
"$",
"item1",
",",
"$",
"item2",
")",
"{",
"$",
"xTypeCode",
"=",
"$",
"item1",
"->",
"getSchemaType",
"(",
")",
"->",
"TypeCode",
";",
"$",
"yTypeCode",
"=",
"$",
"item2",
"->",
"getSchemaType",
"(",
")",
"->",
"TypeCode",
";",
"$",
"types",
"=",
"array",
"(",
"XmlTypeCode",
"::",
"Decimal",
",",
"XmlTypeCode",
"::",
"Float",
",",
"XmlTypeCode",
"::",
"Double",
",",
"XmlTypeCode",
"::",
"Integer",
")",
";",
"$",
"x",
"=",
"$",
"item1",
"->",
"GetTypedValue",
"(",
")",
";",
"// BMS 2018-01-19\tCould be numeric\r",
"//\t\t\t\t\tAdded to support typed member comparisons in FactVariables\r",
"if",
"(",
"$",
"this",
"->",
"untypedCanBeNumeric",
"&&",
"$",
"x",
"instanceof",
"UntypedAtomic",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"x",
"->",
"getValue",
"(",
")",
")",
")",
"{",
"$",
"x",
"=",
"floatval",
"(",
"$",
"x",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"x",
"instanceof",
"UntypedAtomic",
"||",
"$",
"x",
"instanceof",
"AnyUriValue",
")",
"{",
"// Special case\r",
"// If $x is AnyUriValue or the attribute name is 'scheme' then\r",
"// normalize by making sure the scheme starts with a scheme\r",
"// such as http:// https:// ftp:// etc\r",
"$",
"special",
"=",
"/* $x instanceof AnyUriValue || */",
"(",
"$",
"item1",
"instanceof",
"XPathNavigator",
"&&",
"$",
"item1",
"->",
"getLocalName",
"(",
")",
"==",
"'scheme'",
")",
";",
"$",
"x",
"=",
"$",
"x",
"->",
"ToString",
"(",
")",
";",
"$",
"xTypeCode",
"=",
"XmlTypeCode",
"::",
"String",
";",
"if",
"(",
"$",
"special",
"&&",
"strpos",
"(",
"$",
"x",
",",
"\"://\"",
")",
"===",
"false",
")",
"{",
"$",
"x",
"=",
"\"http://\"",
".",
"$",
"x",
";",
"}",
"}",
"$",
"y",
"=",
"$",
"item2",
"->",
"GetTypedValue",
"(",
")",
";",
"// BMS 2018-01-19\tCould be numeric\r",
"//\t\t\t\t\tAdded to support typed member comparisons in FactVariables\r",
"if",
"(",
"$",
"this",
"->",
"untypedCanBeNumeric",
"&&",
"$",
"y",
"instanceof",
"UntypedAtomic",
")",
"{",
"if",
"(",
"is_numeric",
"(",
"$",
"y",
"->",
"getValue",
"(",
")",
")",
")",
"{",
"$",
"y",
"=",
"floatval",
"(",
"$",
"y",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"}",
"if",
"(",
"$",
"y",
"instanceof",
"UntypedAtomic",
"||",
"$",
"y",
"instanceof",
"AnyUriValue",
")",
"{",
"// Special case\r",
"// If $y is AnyUriValue or the attribute name is 'scheme' then\r",
"// normalize by making sure the scheme starts with a scheme\r",
"// such as http:// https:// ftp:// etc\r",
"$",
"special",
"=",
"/* $y instanceof AnyUriValue || */",
"(",
"$",
"item2",
"instanceof",
"XPathNavigator",
"&&",
"$",
"item2",
"->",
"getLocalName",
"(",
")",
"==",
"'scheme'",
")",
";",
"$",
"y",
"=",
"$",
"y",
"->",
"ToString",
"(",
")",
";",
"$",
"yTypeCode",
"=",
"XmlTypeCode",
"::",
"String",
";",
"if",
"(",
"$",
"special",
"&&",
"strpos",
"(",
"$",
"y",
",",
"\"://\"",
")",
"===",
"false",
")",
"{",
"$",
"y",
"=",
"\"http://\"",
".",
"$",
"y",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"useValueCompare",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"x",
")",
")",
"{",
"$",
"x",
"=",
"trim",
"(",
"$",
"x",
")",
";",
"}",
"}",
"if",
"(",
"$",
"this",
"->",
"useValueCompare",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"y",
")",
")",
"{",
"$",
"y",
"=",
"trim",
"(",
"$",
"y",
")",
";",
"}",
"}",
"if",
"(",
"is_double",
"(",
"$",
"x",
")",
"&&",
"is_nan",
"(",
"$",
"x",
")",
"&&",
"is_double",
"(",
"$",
"y",
")",
"&&",
"is_nan",
"(",
"$",
"y",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"is_double",
"(",
"$",
"x",
")",
"&&",
"is_infinite",
"(",
"$",
"x",
")",
"&&",
"is_double",
"(",
"$",
"y",
")",
"&&",
"is_infinite",
"(",
"$",
"y",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"$",
"xTypeCode",
"!=",
"$",
"yTypeCode",
")",
"{",
"// Handle the exceptions\r",
"$",
"exceptions",
"=",
"(",
"(",
"$",
"xTypeCode",
"==",
"XmlTypeCode",
"::",
"Integer",
"&&",
"in_array",
"(",
"$",
"yTypeCode",
",",
"$",
"types",
")",
")",
"||",
"(",
"$",
"yTypeCode",
"==",
"XmlTypeCode",
"::",
"Integer",
"&&",
"in_array",
"(",
"$",
"xTypeCode",
",",
"$",
"types",
")",
")",
"||",
"(",
"$",
"xTypeCode",
"==",
"XmlTypeCode",
"::",
"Decimal",
"&&",
"in_array",
"(",
"$",
"yTypeCode",
",",
"$",
"types",
")",
")",
"||",
"(",
"$",
"yTypeCode",
"==",
"XmlTypeCode",
"::",
"Decimal",
"&&",
"in_array",
"(",
"$",
"xTypeCode",
",",
"$",
"types",
")",
")",
")",
";",
"if",
"(",
"!",
"$",
"exceptions",
")",
"{",
"return",
"false",
";",
"}",
"}",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"collation",
")",
"&&",
"is_string",
"(",
"$",
"x",
")",
"&&",
"is_string",
"(",
"$",
"y",
")",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"collation",
"==",
"XmlReservedNs",
"::",
"collationCodepoint",
")",
"{",
"$",
"x",
"=",
"\\",
"normalizer_normalize",
"(",
"$",
"x",
",",
"\\",
"Normalizer",
"::",
"FORM_C",
")",
";",
"$",
"y",
"=",
"\\",
"normalizer_normalize",
"(",
"$",
"y",
",",
"\\",
"Normalizer",
"::",
"FORM_C",
")",
";",
"return",
"strcmp",
"(",
"$",
"x",
",",
"$",
"y",
")",
";",
"}",
"else",
"{",
"return",
"strcoll",
"(",
"$",
"x",
",",
"$",
"y",
")",
"==",
"0",
";",
"}",
"}",
"if",
"(",
"!",
"is_object",
"(",
"$",
"x",
")",
"&&",
"!",
"is_object",
"(",
"$",
"y",
")",
")",
"{",
"if",
"(",
"$",
"x",
"==",
"$",
"y",
")",
"{",
"return",
"true",
";",
"}",
"}",
"else",
"if",
"(",
"is_object",
"(",
"$",
"x",
")",
"&&",
"is_object",
"(",
"$",
"y",
")",
"&&",
"method_exists",
"(",
"$",
"x",
",",
"\"Equals\"",
")",
"&&",
"method_exists",
"(",
"$",
"y",
",",
"\"Equals\"",
")",
")",
"{",
"if",
"(",
"$",
"x",
"->",
"Equals",
"(",
"$",
"y",
")",
")",
"{",
"return",
"true",
";",
"}",
"}",
"$",
"res",
";",
"$",
"result",
"=",
"ValueProxy",
"::",
"EqValues",
"(",
"$",
"x",
",",
"$",
"y",
",",
"$",
"res",
")",
"&&",
"$",
"res",
";",
"return",
"$",
"result",
";",
"}"
] | Test if two items are equal
@param XPathItem $item1
@param XPathItem $item2
@return bool | [
"Test",
"if",
"two",
"items",
"are",
"equal"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/TreeComparer.php#L139-L272 |
bseddon/XPath20 | TreeComparer.php | TreeComparer.NodeEqual | protected function NodeEqual( $nav1, $nav2 )
{
if ( $nav1->getNodeType() != $nav2->getNodeType() )
{
return false;
}
switch ( $nav1->getNodeType() )
{
case XPathNodeType::Element:
return $this->ElementEqual( $nav1, $nav2 );
case XPathNodeType::Attribute:
return $this->AttributeEqual( $nav1, $nav2 );
case XPathNodeType::Text:
case XPathNodeType::SignificantWhitespace:
case XPathNodeType::Whitespace:
case XPathNodeType::Comment:
if ( $this->useValueCompare )
{
if ( $nav1->getValue() == $nav2->getValue() )
{
// return true;
}
$value = $nav1->getValue();
$result = $this->ItemEqual( $nav1, $nav2);
return $result;
}
else
{
return $this->TextEqual( $nav1->getValue(), $nav2->getValue() );
}
case XPathNodeType::ProcessingInstruction:
return $this->ProcessingInstructionEqual( $nav1, $nav2 );
default:
return $this->DeepEqualByNavigator( $nav1, $nav2 );
}
} | php | protected function NodeEqual( $nav1, $nav2 )
{
if ( $nav1->getNodeType() != $nav2->getNodeType() )
{
return false;
}
switch ( $nav1->getNodeType() )
{
case XPathNodeType::Element:
return $this->ElementEqual( $nav1, $nav2 );
case XPathNodeType::Attribute:
return $this->AttributeEqual( $nav1, $nav2 );
case XPathNodeType::Text:
case XPathNodeType::SignificantWhitespace:
case XPathNodeType::Whitespace:
case XPathNodeType::Comment:
if ( $this->useValueCompare )
{
if ( $nav1->getValue() == $nav2->getValue() )
{
// return true;
}
$value = $nav1->getValue();
$result = $this->ItemEqual( $nav1, $nav2);
return $result;
}
else
{
return $this->TextEqual( $nav1->getValue(), $nav2->getValue() );
}
case XPathNodeType::ProcessingInstruction:
return $this->ProcessingInstructionEqual( $nav1, $nav2 );
default:
return $this->DeepEqualByNavigator( $nav1, $nav2 );
}
} | [
"protected",
"function",
"NodeEqual",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
"{",
"if",
"(",
"$",
"nav1",
"->",
"getNodeType",
"(",
")",
"!=",
"$",
"nav2",
"->",
"getNodeType",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"switch",
"(",
"$",
"nav1",
"->",
"getNodeType",
"(",
")",
")",
"{",
"case",
"XPathNodeType",
"::",
"Element",
":",
"return",
"$",
"this",
"->",
"ElementEqual",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
";",
"case",
"XPathNodeType",
"::",
"Attribute",
":",
"return",
"$",
"this",
"->",
"AttributeEqual",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
";",
"case",
"XPathNodeType",
"::",
"Text",
":",
"case",
"XPathNodeType",
"::",
"SignificantWhitespace",
":",
"case",
"XPathNodeType",
"::",
"Whitespace",
":",
"case",
"XPathNodeType",
"::",
"Comment",
":",
"if",
"(",
"$",
"this",
"->",
"useValueCompare",
")",
"{",
"if",
"(",
"$",
"nav1",
"->",
"getValue",
"(",
")",
"==",
"$",
"nav2",
"->",
"getValue",
"(",
")",
")",
"{",
"// return true;\r",
"}",
"$",
"value",
"=",
"$",
"nav1",
"->",
"getValue",
"(",
")",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"ItemEqual",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
";",
"return",
"$",
"result",
";",
"}",
"else",
"{",
"return",
"$",
"this",
"->",
"TextEqual",
"(",
"$",
"nav1",
"->",
"getValue",
"(",
")",
",",
"$",
"nav2",
"->",
"getValue",
"(",
")",
")",
";",
"}",
"case",
"XPathNodeType",
"::",
"ProcessingInstruction",
":",
"return",
"$",
"this",
"->",
"ProcessingInstructionEqual",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
";",
"default",
":",
"return",
"$",
"this",
"->",
"DeepEqualByNavigator",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
";",
"}",
"}"
] | NodeEqual
@param XPathNavigator $nav1
@param XPathNavigator $nav2
@return bool | [
"NodeEqual"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/TreeComparer.php#L280-L321 |
bseddon/XPath20 | TreeComparer.php | TreeComparer.ElementEqual | protected function ElementEqual( $nav1, $nav2 )
{
if ( $nav1->getLocalName() != $nav2->getLocalName() || $nav1->getNamespaceURI() != $nav2->getNamespaceURI() )
{
return false;
}
if ( ! $this->ElementAttributesEqual( $nav1->CloneInstance(), $nav2->CloneInstance() ) )
{
return false;
}
return $this->DeepEqualByNavigator( $nav1, $nav2 );
} | php | protected function ElementEqual( $nav1, $nav2 )
{
if ( $nav1->getLocalName() != $nav2->getLocalName() || $nav1->getNamespaceURI() != $nav2->getNamespaceURI() )
{
return false;
}
if ( ! $this->ElementAttributesEqual( $nav1->CloneInstance(), $nav2->CloneInstance() ) )
{
return false;
}
return $this->DeepEqualByNavigator( $nav1, $nav2 );
} | [
"protected",
"function",
"ElementEqual",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
"{",
"if",
"(",
"$",
"nav1",
"->",
"getLocalName",
"(",
")",
"!=",
"$",
"nav2",
"->",
"getLocalName",
"(",
")",
"||",
"$",
"nav1",
"->",
"getNamespaceURI",
"(",
")",
"!=",
"$",
"nav2",
"->",
"getNamespaceURI",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"ElementAttributesEqual",
"(",
"$",
"nav1",
"->",
"CloneInstance",
"(",
")",
",",
"$",
"nav2",
"->",
"CloneInstance",
"(",
")",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"DeepEqualByNavigator",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
";",
"}"
] | ElementEqual
@param XPathNavigator $nav1
@param XPathNavigator $nav2
@return bool | [
"ElementEqual"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/TreeComparer.php#L329-L341 |
bseddon/XPath20 | TreeComparer.php | TreeComparer.ElementAttributesEqual | protected function ElementAttributesEqual( $nav1, $nav2 )
{
if ( $nav1->getHasAttributes() != $nav2->getHasAttributes() )
{
return false;
}
if ( ! $nav1->getHasAttributes() ) return true;
// Check they have the same number of attributes
$flag1 = $nav1->MoveToFirstAttribute();
$flag2 = $nav2->MoveToFirstAttribute();
while ( $flag1 && $flag2 )
{
$flag1 = $nav1->MoveToNextAttribute();
$flag2 = $nav2->MoveToNextAttribute();
}
if ( $flag1 != $flag2 ) return false;
$nav1->MoveToParent();
$nav2->MoveToParent();
for ( $flag3 = $nav1->MoveToFirstAttribute(); $flag3; $flag3 = $nav1->MoveToNextAttribute() )
{
$flag4 = $nav2->MoveToFirstAttribute();
while ( $flag4 )
{
if ( $this->AttributeEqual( $nav1, $nav2 ) )
{
break;
}
$flag4 = $nav2->MoveToNextAttribute();
}
$nav2->MoveToParent();
if ( ! $flag4)
{
$nav1->MoveToParent();
return false;
}
}
// $nav1->MoveToParent();
return true;
} | php | protected function ElementAttributesEqual( $nav1, $nav2 )
{
if ( $nav1->getHasAttributes() != $nav2->getHasAttributes() )
{
return false;
}
if ( ! $nav1->getHasAttributes() ) return true;
// Check they have the same number of attributes
$flag1 = $nav1->MoveToFirstAttribute();
$flag2 = $nav2->MoveToFirstAttribute();
while ( $flag1 && $flag2 )
{
$flag1 = $nav1->MoveToNextAttribute();
$flag2 = $nav2->MoveToNextAttribute();
}
if ( $flag1 != $flag2 ) return false;
$nav1->MoveToParent();
$nav2->MoveToParent();
for ( $flag3 = $nav1->MoveToFirstAttribute(); $flag3; $flag3 = $nav1->MoveToNextAttribute() )
{
$flag4 = $nav2->MoveToFirstAttribute();
while ( $flag4 )
{
if ( $this->AttributeEqual( $nav1, $nav2 ) )
{
break;
}
$flag4 = $nav2->MoveToNextAttribute();
}
$nav2->MoveToParent();
if ( ! $flag4)
{
$nav1->MoveToParent();
return false;
}
}
// $nav1->MoveToParent();
return true;
} | [
"protected",
"function",
"ElementAttributesEqual",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
"{",
"if",
"(",
"$",
"nav1",
"->",
"getHasAttributes",
"(",
")",
"!=",
"$",
"nav2",
"->",
"getHasAttributes",
"(",
")",
")",
"{",
"return",
"false",
";",
"}",
"if",
"(",
"!",
"$",
"nav1",
"->",
"getHasAttributes",
"(",
")",
")",
"return",
"true",
";",
"// Check they have the same number of attributes\r",
"$",
"flag1",
"=",
"$",
"nav1",
"->",
"MoveToFirstAttribute",
"(",
")",
";",
"$",
"flag2",
"=",
"$",
"nav2",
"->",
"MoveToFirstAttribute",
"(",
")",
";",
"while",
"(",
"$",
"flag1",
"&&",
"$",
"flag2",
")",
"{",
"$",
"flag1",
"=",
"$",
"nav1",
"->",
"MoveToNextAttribute",
"(",
")",
";",
"$",
"flag2",
"=",
"$",
"nav2",
"->",
"MoveToNextAttribute",
"(",
")",
";",
"}",
"if",
"(",
"$",
"flag1",
"!=",
"$",
"flag2",
")",
"return",
"false",
";",
"$",
"nav1",
"->",
"MoveToParent",
"(",
")",
";",
"$",
"nav2",
"->",
"MoveToParent",
"(",
")",
";",
"for",
"(",
"$",
"flag3",
"=",
"$",
"nav1",
"->",
"MoveToFirstAttribute",
"(",
")",
";",
"$",
"flag3",
";",
"$",
"flag3",
"=",
"$",
"nav1",
"->",
"MoveToNextAttribute",
"(",
")",
")",
"{",
"$",
"flag4",
"=",
"$",
"nav2",
"->",
"MoveToFirstAttribute",
"(",
")",
";",
"while",
"(",
"$",
"flag4",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"AttributeEqual",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
")",
"{",
"break",
";",
"}",
"$",
"flag4",
"=",
"$",
"nav2",
"->",
"MoveToNextAttribute",
"(",
")",
";",
"}",
"$",
"nav2",
"->",
"MoveToParent",
"(",
")",
";",
"if",
"(",
"!",
"$",
"flag4",
")",
"{",
"$",
"nav1",
"->",
"MoveToParent",
"(",
")",
";",
"return",
"false",
";",
"}",
"}",
"// $nav1->MoveToParent();\r",
"return",
"true",
";",
"}"
] | ElementAttributesEqual
@param XPathNavigator $nav1
@param XPathNavigator $nav2
@return bool | [
"ElementAttributesEqual"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/TreeComparer.php#L349-L393 |
bseddon/XPath20 | TreeComparer.php | TreeComparer.ProcessingInstructionEqual | protected function ProcessingInstructionEqual( $nav1, $nav2 )
{
return $nav1->getLocalName() == $nav2->getLocalName() && $nav1->getValue() == $nav2->getValue();
} | php | protected function ProcessingInstructionEqual( $nav1, $nav2 )
{
return $nav1->getLocalName() == $nav2->getLocalName() && $nav1->getValue() == $nav2->getValue();
} | [
"protected",
"function",
"ProcessingInstructionEqual",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
"{",
"return",
"$",
"nav1",
"->",
"getLocalName",
"(",
")",
"==",
"$",
"nav2",
"->",
"getLocalName",
"(",
")",
"&&",
"$",
"nav1",
"->",
"getValue",
"(",
")",
"==",
"$",
"nav2",
"->",
"getValue",
"(",
")",
";",
"}"
] | ProcessingInstructionEqual
@param XPathNavigator $nav1
@param XPathNavigator $nav2
@return bool | [
"ProcessingInstructionEqual"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/TreeComparer.php#L401-L404 |
bseddon/XPath20 | TreeComparer.php | TreeComparer.AttributeEqual | protected function AttributeEqual($nav1, $nav2)
{
if ( $nav1->getLocalName() != $nav2->getLocalName() || $nav1->getNamespaceURI() != $nav2->getNamespaceURI() ) return false;
// BMS 2018-03-21 Add because a query like:
// xfi:nodes-correspond( //t:P1[@id='t1'], //t:P1[@id='t2'] )
// passes a pair of nodes including the attribute 'id' to the nodes-correspond
// function but by definition the id values are different
// The attributeToIgnore function allows the caller to define the selection attribute that should not affect equality.
if ( ! is_null( $this->attributeToIgnore ) )
{
if ( $nav1->getLocalName() == $this->attributeToIgnore ) return true;
}
return $this->ItemEqual( $nav1, $nav2 );
// return $nav1->GetTypedValue() == $nav2->GetTypedValue();
} | php | protected function AttributeEqual($nav1, $nav2)
{
if ( $nav1->getLocalName() != $nav2->getLocalName() || $nav1->getNamespaceURI() != $nav2->getNamespaceURI() ) return false;
// BMS 2018-03-21 Add because a query like:
// xfi:nodes-correspond( //t:P1[@id='t1'], //t:P1[@id='t2'] )
// passes a pair of nodes including the attribute 'id' to the nodes-correspond
// function but by definition the id values are different
// The attributeToIgnore function allows the caller to define the selection attribute that should not affect equality.
if ( ! is_null( $this->attributeToIgnore ) )
{
if ( $nav1->getLocalName() == $this->attributeToIgnore ) return true;
}
return $this->ItemEqual( $nav1, $nav2 );
// return $nav1->GetTypedValue() == $nav2->GetTypedValue();
} | [
"protected",
"function",
"AttributeEqual",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
"{",
"if",
"(",
"$",
"nav1",
"->",
"getLocalName",
"(",
")",
"!=",
"$",
"nav2",
"->",
"getLocalName",
"(",
")",
"||",
"$",
"nav1",
"->",
"getNamespaceURI",
"(",
")",
"!=",
"$",
"nav2",
"->",
"getNamespaceURI",
"(",
")",
")",
"return",
"false",
";",
"// BMS 2018-03-21 Add because a query like:\r",
"//\txfi:nodes-correspond( //t:P1[@id='t1'], //t:P1[@id='t2'] )\r",
"// passes a pair of nodes including the attribute 'id' to the nodes-correspond\r",
"// function but by definition the id values are different\r",
"// The attributeToIgnore function allows the caller to define the selection attribute that should not affect equality.\r",
"if",
"(",
"!",
"is_null",
"(",
"$",
"this",
"->",
"attributeToIgnore",
")",
")",
"{",
"if",
"(",
"$",
"nav1",
"->",
"getLocalName",
"(",
")",
"==",
"$",
"this",
"->",
"attributeToIgnore",
")",
"return",
"true",
";",
"}",
"return",
"$",
"this",
"->",
"ItemEqual",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
";",
"// return $nav1->GetTypedValue() == $nav2->GetTypedValue();\r",
"}"
] | AttributeEqual
@param XPathNavigator $nav1
@param XPathNavigator $nav2
@return bool | [
"AttributeEqual"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/TreeComparer.php#L412-L426 |
bseddon/XPath20 | TreeComparer.php | TreeComparer.DeepEqualByNavigator | public function DeepEqualByNavigator( $nav1, $nav2 )
{
/**
* @var XPathNodeIterator $iter1
* @var XPathNodeIterator $iter2
*/
// $iter1 = $nav1->SelectChildrenByType( XPathNodeType::All );
// $iter2 = $nav2->SelectChildrenByType( XPathNodeType::All );
$nodeTest = null; // XmlQualifiedNameTest::create();
$iter1 = ChildNodeIterator::fromNodeTest( $this->context, $nodeTest, XPath2NodeIterator::Create( $nav1 ) );
$iter1->excludeComments = true; // $this->excludeComments;
$iter1->excludeWhitespace = $this->excludeWhitespace;
$iter2 = ChildNodeIterator::fromNodeTest( $this->context, $nodeTest, XPath2NodeIterator::Create( $nav2 ) );
$iter2->excludeComments = true; // $this->excludeComments;
$iter2->excludeWhitespace = $this->excludeWhitespace;
$leftCount = $iter1->getCount();
$rightCount = $iter2->getCount();
if ( $leftCount != $rightCount )
{
// Maybe one or both iterators have skipped comments and all the nodes are text nodes.
// If this is the case join them to see if they compare.
$leftTextCount = $iter1->getCountType( XPathNodeType::Text );
$rightTextCount = $iter2->getCountType( XPathNodeType::Text );
if ( $leftTextCount != $leftCount ) return false;
if ( $rightTextCount != $rightCount ) return false;
// By this time all the nodes are text so see if when concatenated they are equal
$text1 = ExtFuncs::StringJoin( $iter1, "" );
$text2 = ExtFuncs::StringJoin( $iter2, "" );
return $text1 == $text2;
}
$leftElementCount = $iter1->getCountType( XPathNodeType::Element );
if ( $leftElementCount )
{
$textMatched = $nav1->getValue() == $nav2->getValue();
return $this->DeepEqualByIterator( $iter1, $iter2, $textMatched );
}
if ( ! $this->ItemEqual( $nav1, $nav2 ) )
{
return false;
}
return true;
} | php | public function DeepEqualByNavigator( $nav1, $nav2 )
{
/**
* @var XPathNodeIterator $iter1
* @var XPathNodeIterator $iter2
*/
// $iter1 = $nav1->SelectChildrenByType( XPathNodeType::All );
// $iter2 = $nav2->SelectChildrenByType( XPathNodeType::All );
$nodeTest = null; // XmlQualifiedNameTest::create();
$iter1 = ChildNodeIterator::fromNodeTest( $this->context, $nodeTest, XPath2NodeIterator::Create( $nav1 ) );
$iter1->excludeComments = true; // $this->excludeComments;
$iter1->excludeWhitespace = $this->excludeWhitespace;
$iter2 = ChildNodeIterator::fromNodeTest( $this->context, $nodeTest, XPath2NodeIterator::Create( $nav2 ) );
$iter2->excludeComments = true; // $this->excludeComments;
$iter2->excludeWhitespace = $this->excludeWhitespace;
$leftCount = $iter1->getCount();
$rightCount = $iter2->getCount();
if ( $leftCount != $rightCount )
{
// Maybe one or both iterators have skipped comments and all the nodes are text nodes.
// If this is the case join them to see if they compare.
$leftTextCount = $iter1->getCountType( XPathNodeType::Text );
$rightTextCount = $iter2->getCountType( XPathNodeType::Text );
if ( $leftTextCount != $leftCount ) return false;
if ( $rightTextCount != $rightCount ) return false;
// By this time all the nodes are text so see if when concatenated they are equal
$text1 = ExtFuncs::StringJoin( $iter1, "" );
$text2 = ExtFuncs::StringJoin( $iter2, "" );
return $text1 == $text2;
}
$leftElementCount = $iter1->getCountType( XPathNodeType::Element );
if ( $leftElementCount )
{
$textMatched = $nav1->getValue() == $nav2->getValue();
return $this->DeepEqualByIterator( $iter1, $iter2, $textMatched );
}
if ( ! $this->ItemEqual( $nav1, $nav2 ) )
{
return false;
}
return true;
} | [
"public",
"function",
"DeepEqualByNavigator",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
"{",
"/**\r\n\t\t * @var XPathNodeIterator $iter1\r\n\t\t * @var XPathNodeIterator $iter2\r\n\t\t */",
"// $iter1 = $nav1->SelectChildrenByType( XPathNodeType::All );\r",
"// $iter2 = $nav2->SelectChildrenByType( XPathNodeType::All );\r",
"$",
"nodeTest",
"=",
"null",
";",
"// XmlQualifiedNameTest::create();\r",
"$",
"iter1",
"=",
"ChildNodeIterator",
"::",
"fromNodeTest",
"(",
"$",
"this",
"->",
"context",
",",
"$",
"nodeTest",
",",
"XPath2NodeIterator",
"::",
"Create",
"(",
"$",
"nav1",
")",
")",
";",
"$",
"iter1",
"->",
"excludeComments",
"=",
"true",
";",
"// $this->excludeComments;\r",
"$",
"iter1",
"->",
"excludeWhitespace",
"=",
"$",
"this",
"->",
"excludeWhitespace",
";",
"$",
"iter2",
"=",
"ChildNodeIterator",
"::",
"fromNodeTest",
"(",
"$",
"this",
"->",
"context",
",",
"$",
"nodeTest",
",",
"XPath2NodeIterator",
"::",
"Create",
"(",
"$",
"nav2",
")",
")",
";",
"$",
"iter2",
"->",
"excludeComments",
"=",
"true",
";",
"// $this->excludeComments;\r",
"$",
"iter2",
"->",
"excludeWhitespace",
"=",
"$",
"this",
"->",
"excludeWhitespace",
";",
"$",
"leftCount",
"=",
"$",
"iter1",
"->",
"getCount",
"(",
")",
";",
"$",
"rightCount",
"=",
"$",
"iter2",
"->",
"getCount",
"(",
")",
";",
"if",
"(",
"$",
"leftCount",
"!=",
"$",
"rightCount",
")",
"{",
"// Maybe one or both iterators have skipped comments and all the nodes are text nodes.\r",
"// If this is the case join them to see if they compare.\r",
"$",
"leftTextCount",
"=",
"$",
"iter1",
"->",
"getCountType",
"(",
"XPathNodeType",
"::",
"Text",
")",
";",
"$",
"rightTextCount",
"=",
"$",
"iter2",
"->",
"getCountType",
"(",
"XPathNodeType",
"::",
"Text",
")",
";",
"if",
"(",
"$",
"leftTextCount",
"!=",
"$",
"leftCount",
")",
"return",
"false",
";",
"if",
"(",
"$",
"rightTextCount",
"!=",
"$",
"rightCount",
")",
"return",
"false",
";",
"// By this time all the nodes are text so see if when concatenated they are equal\r",
"$",
"text1",
"=",
"ExtFuncs",
"::",
"StringJoin",
"(",
"$",
"iter1",
",",
"\"\"",
")",
";",
"$",
"text2",
"=",
"ExtFuncs",
"::",
"StringJoin",
"(",
"$",
"iter2",
",",
"\"\"",
")",
";",
"return",
"$",
"text1",
"==",
"$",
"text2",
";",
"}",
"$",
"leftElementCount",
"=",
"$",
"iter1",
"->",
"getCountType",
"(",
"XPathNodeType",
"::",
"Element",
")",
";",
"if",
"(",
"$",
"leftElementCount",
")",
"{",
"$",
"textMatched",
"=",
"$",
"nav1",
"->",
"getValue",
"(",
")",
"==",
"$",
"nav2",
"->",
"getValue",
"(",
")",
";",
"return",
"$",
"this",
"->",
"DeepEqualByIterator",
"(",
"$",
"iter1",
",",
"$",
"iter2",
",",
"$",
"textMatched",
")",
";",
"}",
"if",
"(",
"!",
"$",
"this",
"->",
"ItemEqual",
"(",
"$",
"nav1",
",",
"$",
"nav2",
")",
")",
"{",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | DeepEqualByNavigator Iterate over nodes in order-sensitive manner
@param XPathNavigator $nav1
@param XPathNavigator $nav2
@return bool | [
"DeepEqualByNavigator",
"Iterate",
"over",
"nodes",
"in",
"order",
"-",
"sensitive",
"manner"
] | train | https://github.com/bseddon/XPath20/blob/69882b6efffaa5470a819d5fdd2f6473ddeb046d/TreeComparer.php#L434-L486 |
proem-components/service | AssetComposer.php | AssetComposer.compose | public function compose($single = false)
{
$reflection = new \ReflectionClass($this->class);
$constructArgs = $this->constructArgs;
$methodArgs = $this->methodArgs;
if ($single) {
static $obj;
if ($obj == null) {
$obj = (new Asset($this->class))->single(
function () use ($reflection, $constructArgs, $methodArgs) {
if ($constructArgs) {
$object = $reflection->newInstanceArgs($constructArgs);
} else {
$object = $reflection->newInstance();
}
foreach ($methodArgs as $method => $params) {
if ($reflection->hasMethod($method)) {
call_user_func_array([$object, $method], $params);
}
}
return $object;
}
);
}
return $obj;
} else {
return new Asset(
$this->class,
function () use ($reflection, $constructArgs, $methodArgs) {
if ($constructArgs) {
$object = $reflection->newInstanceArgs($constructArgs);
} else {
$object = $reflection->newInstance();
}
foreach ($methodArgs as $method => $params) {
if ($reflection->hasMethod($method)) {
call_user_func_array([$object, $method], $params);
}
}
return $object;
}
);
}
} | php | public function compose($single = false)
{
$reflection = new \ReflectionClass($this->class);
$constructArgs = $this->constructArgs;
$methodArgs = $this->methodArgs;
if ($single) {
static $obj;
if ($obj == null) {
$obj = (new Asset($this->class))->single(
function () use ($reflection, $constructArgs, $methodArgs) {
if ($constructArgs) {
$object = $reflection->newInstanceArgs($constructArgs);
} else {
$object = $reflection->newInstance();
}
foreach ($methodArgs as $method => $params) {
if ($reflection->hasMethod($method)) {
call_user_func_array([$object, $method], $params);
}
}
return $object;
}
);
}
return $obj;
} else {
return new Asset(
$this->class,
function () use ($reflection, $constructArgs, $methodArgs) {
if ($constructArgs) {
$object = $reflection->newInstanceArgs($constructArgs);
} else {
$object = $reflection->newInstance();
}
foreach ($methodArgs as $method => $params) {
if ($reflection->hasMethod($method)) {
call_user_func_array([$object, $method], $params);
}
}
return $object;
}
);
}
} | [
"public",
"function",
"compose",
"(",
"$",
"single",
"=",
"false",
")",
"{",
"$",
"reflection",
"=",
"new",
"\\",
"ReflectionClass",
"(",
"$",
"this",
"->",
"class",
")",
";",
"$",
"constructArgs",
"=",
"$",
"this",
"->",
"constructArgs",
";",
"$",
"methodArgs",
"=",
"$",
"this",
"->",
"methodArgs",
";",
"if",
"(",
"$",
"single",
")",
"{",
"static",
"$",
"obj",
";",
"if",
"(",
"$",
"obj",
"==",
"null",
")",
"{",
"$",
"obj",
"=",
"(",
"new",
"Asset",
"(",
"$",
"this",
"->",
"class",
")",
")",
"->",
"single",
"(",
"function",
"(",
")",
"use",
"(",
"$",
"reflection",
",",
"$",
"constructArgs",
",",
"$",
"methodArgs",
")",
"{",
"if",
"(",
"$",
"constructArgs",
")",
"{",
"$",
"object",
"=",
"$",
"reflection",
"->",
"newInstanceArgs",
"(",
"$",
"constructArgs",
")",
";",
"}",
"else",
"{",
"$",
"object",
"=",
"$",
"reflection",
"->",
"newInstance",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"methodArgs",
"as",
"$",
"method",
"=>",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"reflection",
"->",
"hasMethod",
"(",
"$",
"method",
")",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"object",
",",
"$",
"method",
"]",
",",
"$",
"params",
")",
";",
"}",
"}",
"return",
"$",
"object",
";",
"}",
")",
";",
"}",
"return",
"$",
"obj",
";",
"}",
"else",
"{",
"return",
"new",
"Asset",
"(",
"$",
"this",
"->",
"class",
",",
"function",
"(",
")",
"use",
"(",
"$",
"reflection",
",",
"$",
"constructArgs",
",",
"$",
"methodArgs",
")",
"{",
"if",
"(",
"$",
"constructArgs",
")",
"{",
"$",
"object",
"=",
"$",
"reflection",
"->",
"newInstanceArgs",
"(",
"$",
"constructArgs",
")",
";",
"}",
"else",
"{",
"$",
"object",
"=",
"$",
"reflection",
"->",
"newInstance",
"(",
")",
";",
"}",
"foreach",
"(",
"$",
"methodArgs",
"as",
"$",
"method",
"=>",
"$",
"params",
")",
"{",
"if",
"(",
"$",
"reflection",
"->",
"hasMethod",
"(",
"$",
"method",
")",
")",
"{",
"call_user_func_array",
"(",
"[",
"$",
"object",
",",
"$",
"method",
"]",
",",
"$",
"params",
")",
";",
"}",
"}",
"return",
"$",
"object",
";",
"}",
")",
";",
"}",
"}"
] | Build a configured Asset and return it.
This Asset can optionally be returned implementing a singleton.
@param bool $single
@return Proem\Service\AssetInterface | [
"Build",
"a",
"configured",
"Asset",
"and",
"return",
"it",
"."
] | train | https://github.com/proem-components/service/blob/8c8e9547f16ecaa2789482f34947618f96e453cc/AssetComposer.php#L142-L189 |
Kris-Kuiper/sFire-Framework | src/Validator/Form/Rules/Isdate.php | Isdate.check | private function check($value, $params) {
$timestamp = strtotime($value);
if(true === is_int($timestamp)) {
return true === (date($params[0], $timestamp) == $value);
}
return false;
} | php | private function check($value, $params) {
$timestamp = strtotime($value);
if(true === is_int($timestamp)) {
return true === (date($params[0], $timestamp) == $value);
}
return false;
} | [
"private",
"function",
"check",
"(",
"$",
"value",
",",
"$",
"params",
")",
"{",
"$",
"timestamp",
"=",
"strtotime",
"(",
"$",
"value",
")",
";",
"if",
"(",
"true",
"===",
"is_int",
"(",
"$",
"timestamp",
")",
")",
"{",
"return",
"true",
"===",
"(",
"date",
"(",
"$",
"params",
"[",
"0",
"]",
",",
"$",
"timestamp",
")",
"==",
"$",
"value",
")",
";",
"}",
"return",
"false",
";",
"}"
] | Check if rule passes
@param mixed $value
@param array $params
@return boolean | [
"Check",
"if",
"rule",
"passes"
] | train | https://github.com/Kris-Kuiper/sFire-Framework/blob/deefe1d9d2b40e7326381e8dcd4f01f9aa61885c/src/Validator/Form/Rules/Isdate.php#L68-L77 |
stubbles/stubbles-peer | src/main/php/Socket.php | Socket.connect | public function connect(float $connectTimeout = 1.0): Stream
{
$errno = 0;
$errstr = '';
$fsockopen = $this->fsockopen;
$resource = $fsockopen(
$this->prefix . $this->host,
$this->port,
$errno,
$errstr,
$connectTimeout
);
if (false === $resource) {
throw new ConnectionFailure(
'Connect to ' . $this->prefix . $this->host . ':'. $this->port
. ' within ' . $connectTimeout . ' second'
. (1 == $connectTimeout ? '' : 's') . ' failed: '
. $errstr . ' (' . $errno . ').'
);
}
return new Stream($resource, $this->usesSsl());
} | php | public function connect(float $connectTimeout = 1.0): Stream
{
$errno = 0;
$errstr = '';
$fsockopen = $this->fsockopen;
$resource = $fsockopen(
$this->prefix . $this->host,
$this->port,
$errno,
$errstr,
$connectTimeout
);
if (false === $resource) {
throw new ConnectionFailure(
'Connect to ' . $this->prefix . $this->host . ':'. $this->port
. ' within ' . $connectTimeout . ' second'
. (1 == $connectTimeout ? '' : 's') . ' failed: '
. $errstr . ' (' . $errno . ').'
);
}
return new Stream($resource, $this->usesSsl());
} | [
"public",
"function",
"connect",
"(",
"float",
"$",
"connectTimeout",
"=",
"1.0",
")",
":",
"Stream",
"{",
"$",
"errno",
"=",
"0",
";",
"$",
"errstr",
"=",
"''",
";",
"$",
"fsockopen",
"=",
"$",
"this",
"->",
"fsockopen",
";",
"$",
"resource",
"=",
"$",
"fsockopen",
"(",
"$",
"this",
"->",
"prefix",
".",
"$",
"this",
"->",
"host",
",",
"$",
"this",
"->",
"port",
",",
"$",
"errno",
",",
"$",
"errstr",
",",
"$",
"connectTimeout",
")",
";",
"if",
"(",
"false",
"===",
"$",
"resource",
")",
"{",
"throw",
"new",
"ConnectionFailure",
"(",
"'Connect to '",
".",
"$",
"this",
"->",
"prefix",
".",
"$",
"this",
"->",
"host",
".",
"':'",
".",
"$",
"this",
"->",
"port",
".",
"' within '",
".",
"$",
"connectTimeout",
".",
"' second'",
".",
"(",
"1",
"==",
"$",
"connectTimeout",
"?",
"''",
":",
"'s'",
")",
".",
"' failed: '",
".",
"$",
"errstr",
".",
"' ('",
".",
"$",
"errno",
".",
"').'",
")",
";",
"}",
"return",
"new",
"Stream",
"(",
"$",
"resource",
",",
"$",
"this",
"->",
"usesSsl",
"(",
")",
")",
";",
"}"
] | opens a connection to host
@param float $connectTimeout optional timeout for establishing the connection, defaults to 1 second
@return \stubbles\peer\Stream
@throws \stubbles\peer\ConnectionFailure | [
"opens",
"a",
"connection",
"to",
"host"
] | train | https://github.com/stubbles/stubbles-peer/blob/dc8b0a517dc4c84b615cc3c88f0d64a2b742f9cc/src/main/php/Socket.php#L85-L107 |
spryker/shopping-list-data-import | src/Spryker/Zed/ShoppingListDataImport/Business/ShoppingListDataImportFacade.php | ShoppingListDataImportFacade.importShoppingLists | public function importShoppingLists(?DataImporterConfigurationTransfer $dataImporterConfigurationTransfer = null): DataImporterReportTransfer
{
return $this->getFactory()
->getShoppingListDataImporter()
->import($dataImporterConfigurationTransfer);
} | php | public function importShoppingLists(?DataImporterConfigurationTransfer $dataImporterConfigurationTransfer = null): DataImporterReportTransfer
{
return $this->getFactory()
->getShoppingListDataImporter()
->import($dataImporterConfigurationTransfer);
} | [
"public",
"function",
"importShoppingLists",
"(",
"?",
"DataImporterConfigurationTransfer",
"$",
"dataImporterConfigurationTransfer",
"=",
"null",
")",
":",
"DataImporterReportTransfer",
"{",
"return",
"$",
"this",
"->",
"getFactory",
"(",
")",
"->",
"getShoppingListDataImporter",
"(",
")",
"->",
"import",
"(",
"$",
"dataImporterConfigurationTransfer",
")",
";",
"}"
] | {@inheritdoc}
@api
@param \Generated\Shared\Transfer\DataImporterConfigurationTransfer|null $dataImporterConfigurationTransfer
@return \Generated\Shared\Transfer\DataImporterReportTransfer | [
"{",
"@inheritdoc",
"}"
] | train | https://github.com/spryker/shopping-list-data-import/blob/6313fc39e8ee79a08f7b97d81da7f4056c066674/src/Spryker/Zed/ShoppingListDataImport/Business/ShoppingListDataImportFacade.php#L28-L33 |
spryker/shopping-list-data-import | src/Spryker/Zed/ShoppingListDataImport/Business/ShoppingListDataImportFacade.php | ShoppingListDataImportFacade.importShoppingListItems | public function importShoppingListItems(?DataImporterConfigurationTransfer $dataImporterConfigurationTransfer = null): DataImporterReportTransfer
{
return $this->getFactory()
->getShoppingListItemDataImporter()
->import($dataImporterConfigurationTransfer);
} | php | public function importShoppingListItems(?DataImporterConfigurationTransfer $dataImporterConfigurationTransfer = null): DataImporterReportTransfer
{
return $this->getFactory()
->getShoppingListItemDataImporter()
->import($dataImporterConfigurationTransfer);
} | [
"public",
"function",
"importShoppingListItems",
"(",
"?",
"DataImporterConfigurationTransfer",
"$",
"dataImporterConfigurationTransfer",
"=",
"null",
")",
":",
"DataImporterReportTransfer",
"{",
"return",
"$",
"this",
"->",
"getFactory",
"(",
")",
"->",
"getShoppingListItemDataImporter",
"(",
")",
"->",
"import",
"(",
"$",
"dataImporterConfigurationTransfer",
")",
";",
"}"
] | {@inheritdoc}
@api
@param \Generated\Shared\Transfer\DataImporterConfigurationTransfer|null $dataImporterConfigurationTransfer
@return \Generated\Shared\Transfer\DataImporterReportTransfer | [
"{",
"@inheritdoc",
"}"
] | train | https://github.com/spryker/shopping-list-data-import/blob/6313fc39e8ee79a08f7b97d81da7f4056c066674/src/Spryker/Zed/ShoppingListDataImport/Business/ShoppingListDataImportFacade.php#L44-L49 |
spryker/shopping-list-data-import | src/Spryker/Zed/ShoppingListDataImport/Business/ShoppingListDataImportFacade.php | ShoppingListDataImportFacade.importShoppingListCompanyUser | public function importShoppingListCompanyUser(?DataImporterConfigurationTransfer $dataImporterConfigurationTransfer = null): DataImporterReportTransfer
{
return $this->getFactory()
->getShoppingListCompanyUserDataImporter()
->import($dataImporterConfigurationTransfer);
} | php | public function importShoppingListCompanyUser(?DataImporterConfigurationTransfer $dataImporterConfigurationTransfer = null): DataImporterReportTransfer
{
return $this->getFactory()
->getShoppingListCompanyUserDataImporter()
->import($dataImporterConfigurationTransfer);
} | [
"public",
"function",
"importShoppingListCompanyUser",
"(",
"?",
"DataImporterConfigurationTransfer",
"$",
"dataImporterConfigurationTransfer",
"=",
"null",
")",
":",
"DataImporterReportTransfer",
"{",
"return",
"$",
"this",
"->",
"getFactory",
"(",
")",
"->",
"getShoppingListCompanyUserDataImporter",
"(",
")",
"->",
"import",
"(",
"$",
"dataImporterConfigurationTransfer",
")",
";",
"}"
] | {@inheritdoc}
@api
@param \Generated\Shared\Transfer\DataImporterConfigurationTransfer|null $dataImporterConfigurationTransfer
@return \Generated\Shared\Transfer\DataImporterReportTransfer | [
"{",
"@inheritdoc",
"}"
] | train | https://github.com/spryker/shopping-list-data-import/blob/6313fc39e8ee79a08f7b97d81da7f4056c066674/src/Spryker/Zed/ShoppingListDataImport/Business/ShoppingListDataImportFacade.php#L60-L65 |
AltCtrlSupr/ACSPanel-Settings | Controller/ConfigSettingController.php | ConfigSettingController.createObjectSettingsAction | public function createObjectSettingsAction($object_id)
{
$em = $this->getDoctrine()->getManager();
$class_name = $this->container->getParameter('acs_settings.setting_class');
// Get the object fields
$object = $em->getRepository('ACSACSPanelBundle:Service')->find($object_id);
$object_fields = $object->getType()->getFieldTypes();
$user = $this->get('security.context')->getToken()->getUser();
// Adding one form for each setting field
foreach($object_fields as $id => $field_config){
$setting = $em->getRepository('ACSACSPanelBundle:PanelSetting')->findOneBy(
array(
'user' => $user->getId(),
'setting_key' => $field_config->getSettingKey(),
'focus' => 'object_setting',
'service' => $object,
)
);
if (!count($setting)) {
$setting = new $class_name;
$setting->setSettingKey($field_config->getSettingKey());
$setting->setValue($field_config->getDefaultValue());
$setting->setContext($field_config->getContext());
$setting->setLabel($field_config->getLabel());
$setting->setType($field_config->getType());
$setting->setFocus('object_setting');
$setting->setService($object);
$user->addSetting($setting);
$em->persist($user);
$em->flush();
}
}
return $this->redirect($this->generateUrl('settings'));
} | php | public function createObjectSettingsAction($object_id)
{
$em = $this->getDoctrine()->getManager();
$class_name = $this->container->getParameter('acs_settings.setting_class');
// Get the object fields
$object = $em->getRepository('ACSACSPanelBundle:Service')->find($object_id);
$object_fields = $object->getType()->getFieldTypes();
$user = $this->get('security.context')->getToken()->getUser();
// Adding one form for each setting field
foreach($object_fields as $id => $field_config){
$setting = $em->getRepository('ACSACSPanelBundle:PanelSetting')->findOneBy(
array(
'user' => $user->getId(),
'setting_key' => $field_config->getSettingKey(),
'focus' => 'object_setting',
'service' => $object,
)
);
if (!count($setting)) {
$setting = new $class_name;
$setting->setSettingKey($field_config->getSettingKey());
$setting->setValue($field_config->getDefaultValue());
$setting->setContext($field_config->getContext());
$setting->setLabel($field_config->getLabel());
$setting->setType($field_config->getType());
$setting->setFocus('object_setting');
$setting->setService($object);
$user->addSetting($setting);
$em->persist($user);
$em->flush();
}
}
return $this->redirect($this->generateUrl('settings'));
} | [
"public",
"function",
"createObjectSettingsAction",
"(",
"$",
"object_id",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"class_name",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'acs_settings.setting_class'",
")",
";",
"// Get the object fields",
"$",
"object",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelBundle:Service'",
")",
"->",
"find",
"(",
"$",
"object_id",
")",
";",
"$",
"object_fields",
"=",
"$",
"object",
"->",
"getType",
"(",
")",
"->",
"getFieldTypes",
"(",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"// Adding one form for each setting field",
"foreach",
"(",
"$",
"object_fields",
"as",
"$",
"id",
"=>",
"$",
"field_config",
")",
"{",
"$",
"setting",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelBundle:PanelSetting'",
")",
"->",
"findOneBy",
"(",
"array",
"(",
"'user'",
"=>",
"$",
"user",
"->",
"getId",
"(",
")",
",",
"'setting_key'",
"=>",
"$",
"field_config",
"->",
"getSettingKey",
"(",
")",
",",
"'focus'",
"=>",
"'object_setting'",
",",
"'service'",
"=>",
"$",
"object",
",",
")",
")",
";",
"if",
"(",
"!",
"count",
"(",
"$",
"setting",
")",
")",
"{",
"$",
"setting",
"=",
"new",
"$",
"class_name",
";",
"$",
"setting",
"->",
"setSettingKey",
"(",
"$",
"field_config",
"->",
"getSettingKey",
"(",
")",
")",
";",
"$",
"setting",
"->",
"setValue",
"(",
"$",
"field_config",
"->",
"getDefaultValue",
"(",
")",
")",
";",
"$",
"setting",
"->",
"setContext",
"(",
"$",
"field_config",
"->",
"getContext",
"(",
")",
")",
";",
"$",
"setting",
"->",
"setLabel",
"(",
"$",
"field_config",
"->",
"getLabel",
"(",
")",
")",
";",
"$",
"setting",
"->",
"setType",
"(",
"$",
"field_config",
"->",
"getType",
"(",
")",
")",
";",
"$",
"setting",
"->",
"setFocus",
"(",
"'object_setting'",
")",
";",
"$",
"setting",
"->",
"setService",
"(",
"$",
"object",
")",
";",
"$",
"user",
"->",
"addSetting",
"(",
"$",
"setting",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"user",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'settings'",
")",
")",
";",
"}"
] | It creates the object settings specified | [
"It",
"creates",
"the",
"object",
"settings",
"specified"
] | train | https://github.com/AltCtrlSupr/ACSPanel-Settings/blob/b1e363bf98d4c74368b3063abba0c77bb3a61230/Controller/ConfigSettingController.php#L26-L64 |
AltCtrlSupr/ACSPanel-Settings | Controller/ConfigSettingController.php | ConfigSettingController.panelSettingsAction | public function panelSettingsAction()
{
$em = $this->getDoctrine()->getManager();
$user = $this->get('security.context')->getToken()->getUser();
$settingmanager = $this->get('acs.setting_manager');
$user_fields = $settingmanager->loadUserFields();
$object_settings = $settingmanager->getObjectSettingsPrototype($user);
array_merge($user_fields, $object_settings);
$form = $this->createForm(new ConfigSettingCollectionType($user_fields, $em), $user);
$contexts = $settingmanager->getContexts($user);
return $this->render('ACSACSPanelSettingsBundle:ConfigSetting:edit.html.twig', array(
'entity' => $user,
'contexts' => $contexts,
'form' => $form->createView(),
));
} | php | public function panelSettingsAction()
{
$em = $this->getDoctrine()->getManager();
$user = $this->get('security.context')->getToken()->getUser();
$settingmanager = $this->get('acs.setting_manager');
$user_fields = $settingmanager->loadUserFields();
$object_settings = $settingmanager->getObjectSettingsPrototype($user);
array_merge($user_fields, $object_settings);
$form = $this->createForm(new ConfigSettingCollectionType($user_fields, $em), $user);
$contexts = $settingmanager->getContexts($user);
return $this->render('ACSACSPanelSettingsBundle:ConfigSetting:edit.html.twig', array(
'entity' => $user,
'contexts' => $contexts,
'form' => $form->createView(),
));
} | [
"public",
"function",
"panelSettingsAction",
"(",
")",
"{",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"user",
"=",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"$",
"settingmanager",
"=",
"$",
"this",
"->",
"get",
"(",
"'acs.setting_manager'",
")",
";",
"$",
"user_fields",
"=",
"$",
"settingmanager",
"->",
"loadUserFields",
"(",
")",
";",
"$",
"object_settings",
"=",
"$",
"settingmanager",
"->",
"getObjectSettingsPrototype",
"(",
"$",
"user",
")",
";",
"array_merge",
"(",
"$",
"user_fields",
",",
"$",
"object_settings",
")",
";",
"$",
"form",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"ConfigSettingCollectionType",
"(",
"$",
"user_fields",
",",
"$",
"em",
")",
",",
"$",
"user",
")",
";",
"$",
"contexts",
"=",
"$",
"settingmanager",
"->",
"getContexts",
"(",
"$",
"user",
")",
";",
"return",
"$",
"this",
"->",
"render",
"(",
"'ACSACSPanelSettingsBundle:ConfigSetting:edit.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"user",
",",
"'contexts'",
"=>",
"$",
"contexts",
",",
"'form'",
"=>",
"$",
"form",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] | Displays a form with all the user settings | [
"Displays",
"a",
"form",
"with",
"all",
"the",
"user",
"settings"
] | train | https://github.com/AltCtrlSupr/ACSPanel-Settings/blob/b1e363bf98d4c74368b3063abba0c77bb3a61230/Controller/ConfigSettingController.php#L69-L91 |
AltCtrlSupr/ACSPanel-Settings | Controller/ConfigSettingController.php | ConfigSettingController.updateAction | public function updateAction(Request $request, $id)
{
$class_name = $this->container->getParameter('acs_settings.setting_class');
$settingmanager = $this->get('acs.setting_manager');
$user_fields = $settingmanager->loadUserFields();
$em = $this->getDoctrine()->getManager();
$entity = $this->get('security.context')->getToken()->getUser();
if (!$entity) {
throw $this->createNotFoundException('Unable to find ConfigSetting entity.');
}
$editForm = $this->createForm(new ConfigSettingCollectionType($user_fields,$em), $entity);
$editForm->bind($request);
$postData = $request->request->get('acs_settings_usersettings');
if ($editForm->isValid()) {
if (isset($postData['settings'])) {
$settings = $postData['settings'];
foreach ($settings as $setting) {
$args = array(
'user' => $entity->getId(),
'setting_key' => $setting['setting_key'],
);
if(isset($setting['service_id'])){
$service = $em->getRepository('ACSACSPanelBundle:Service')->find($setting['service_id']);
$args['service'] = $service;
}
$panelsetting = $em->getRepository('ACSACSPanelBundle:PanelSetting')->findOneBy($args);
if ($panelsetting && isset($setting['value'])) {
$panelsetting->setValue($setting['value']);
$em->persist($panelsetting);
$em->flush();
}
}
$em->flush();
}
return $this->redirect($this->generateUrl('settings'));
}
return $this->render('ACSACSPanelSettingsBundle:ConfigSetting:new.html.twig', array(
'entity' => $entity,
'form' => $editForm->createView(),
));
} | php | public function updateAction(Request $request, $id)
{
$class_name = $this->container->getParameter('acs_settings.setting_class');
$settingmanager = $this->get('acs.setting_manager');
$user_fields = $settingmanager->loadUserFields();
$em = $this->getDoctrine()->getManager();
$entity = $this->get('security.context')->getToken()->getUser();
if (!$entity) {
throw $this->createNotFoundException('Unable to find ConfigSetting entity.');
}
$editForm = $this->createForm(new ConfigSettingCollectionType($user_fields,$em), $entity);
$editForm->bind($request);
$postData = $request->request->get('acs_settings_usersettings');
if ($editForm->isValid()) {
if (isset($postData['settings'])) {
$settings = $postData['settings'];
foreach ($settings as $setting) {
$args = array(
'user' => $entity->getId(),
'setting_key' => $setting['setting_key'],
);
if(isset($setting['service_id'])){
$service = $em->getRepository('ACSACSPanelBundle:Service')->find($setting['service_id']);
$args['service'] = $service;
}
$panelsetting = $em->getRepository('ACSACSPanelBundle:PanelSetting')->findOneBy($args);
if ($panelsetting && isset($setting['value'])) {
$panelsetting->setValue($setting['value']);
$em->persist($panelsetting);
$em->flush();
}
}
$em->flush();
}
return $this->redirect($this->generateUrl('settings'));
}
return $this->render('ACSACSPanelSettingsBundle:ConfigSetting:new.html.twig', array(
'entity' => $entity,
'form' => $editForm->createView(),
));
} | [
"public",
"function",
"updateAction",
"(",
"Request",
"$",
"request",
",",
"$",
"id",
")",
"{",
"$",
"class_name",
"=",
"$",
"this",
"->",
"container",
"->",
"getParameter",
"(",
"'acs_settings.setting_class'",
")",
";",
"$",
"settingmanager",
"=",
"$",
"this",
"->",
"get",
"(",
"'acs.setting_manager'",
")",
";",
"$",
"user_fields",
"=",
"$",
"settingmanager",
"->",
"loadUserFields",
"(",
")",
";",
"$",
"em",
"=",
"$",
"this",
"->",
"getDoctrine",
"(",
")",
"->",
"getManager",
"(",
")",
";",
"$",
"entity",
"=",
"$",
"this",
"->",
"get",
"(",
"'security.context'",
")",
"->",
"getToken",
"(",
")",
"->",
"getUser",
"(",
")",
";",
"if",
"(",
"!",
"$",
"entity",
")",
"{",
"throw",
"$",
"this",
"->",
"createNotFoundException",
"(",
"'Unable to find ConfigSetting entity.'",
")",
";",
"}",
"$",
"editForm",
"=",
"$",
"this",
"->",
"createForm",
"(",
"new",
"ConfigSettingCollectionType",
"(",
"$",
"user_fields",
",",
"$",
"em",
")",
",",
"$",
"entity",
")",
";",
"$",
"editForm",
"->",
"bind",
"(",
"$",
"request",
")",
";",
"$",
"postData",
"=",
"$",
"request",
"->",
"request",
"->",
"get",
"(",
"'acs_settings_usersettings'",
")",
";",
"if",
"(",
"$",
"editForm",
"->",
"isValid",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"postData",
"[",
"'settings'",
"]",
")",
")",
"{",
"$",
"settings",
"=",
"$",
"postData",
"[",
"'settings'",
"]",
";",
"foreach",
"(",
"$",
"settings",
"as",
"$",
"setting",
")",
"{",
"$",
"args",
"=",
"array",
"(",
"'user'",
"=>",
"$",
"entity",
"->",
"getId",
"(",
")",
",",
"'setting_key'",
"=>",
"$",
"setting",
"[",
"'setting_key'",
"]",
",",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"setting",
"[",
"'service_id'",
"]",
")",
")",
"{",
"$",
"service",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelBundle:Service'",
")",
"->",
"find",
"(",
"$",
"setting",
"[",
"'service_id'",
"]",
")",
";",
"$",
"args",
"[",
"'service'",
"]",
"=",
"$",
"service",
";",
"}",
"$",
"panelsetting",
"=",
"$",
"em",
"->",
"getRepository",
"(",
"'ACSACSPanelBundle:PanelSetting'",
")",
"->",
"findOneBy",
"(",
"$",
"args",
")",
";",
"if",
"(",
"$",
"panelsetting",
"&&",
"isset",
"(",
"$",
"setting",
"[",
"'value'",
"]",
")",
")",
"{",
"$",
"panelsetting",
"->",
"setValue",
"(",
"$",
"setting",
"[",
"'value'",
"]",
")",
";",
"$",
"em",
"->",
"persist",
"(",
"$",
"panelsetting",
")",
";",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
"}",
"$",
"em",
"->",
"flush",
"(",
")",
";",
"}",
"return",
"$",
"this",
"->",
"redirect",
"(",
"$",
"this",
"->",
"generateUrl",
"(",
"'settings'",
")",
")",
";",
"}",
"return",
"$",
"this",
"->",
"render",
"(",
"'ACSACSPanelSettingsBundle:ConfigSetting:new.html.twig'",
",",
"array",
"(",
"'entity'",
"=>",
"$",
"entity",
",",
"'form'",
"=>",
"$",
"editForm",
"->",
"createView",
"(",
")",
",",
")",
")",
";",
"}"
] | Edits an existing ConfigSetting entity. | [
"Edits",
"an",
"existing",
"ConfigSetting",
"entity",
"."
] | train | https://github.com/AltCtrlSupr/ACSPanel-Settings/blob/b1e363bf98d4c74368b3063abba0c77bb3a61230/Controller/ConfigSettingController.php#L96-L148 |
stingus/phpdt | src/PHPdt/DataType/ObjectValidationTrait.php | ObjectValidationTrait.validateType | public static function validateType($value)
{
if (get_called_class() === $value) {
return true;
}
if (array_key_exists($value, class_implements(get_called_class()))) {
return true;
}
if (array_key_exists($value, class_parents(get_called_class()))) {
return true;
}
throw new InvalidDataTypeException(__CLASS__, new static);
} | php | public static function validateType($value)
{
if (get_called_class() === $value) {
return true;
}
if (array_key_exists($value, class_implements(get_called_class()))) {
return true;
}
if (array_key_exists($value, class_parents(get_called_class()))) {
return true;
}
throw new InvalidDataTypeException(__CLASS__, new static);
} | [
"public",
"static",
"function",
"validateType",
"(",
"$",
"value",
")",
"{",
"if",
"(",
"get_called_class",
"(",
")",
"===",
"$",
"value",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"value",
",",
"class_implements",
"(",
"get_called_class",
"(",
")",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"if",
"(",
"array_key_exists",
"(",
"$",
"value",
",",
"class_parents",
"(",
"get_called_class",
"(",
")",
")",
")",
")",
"{",
"return",
"true",
";",
"}",
"throw",
"new",
"InvalidDataTypeException",
"(",
"__CLASS__",
",",
"new",
"static",
")",
";",
"}"
] | Validate object type
@param $value
@return bool
@throws InvalidDataTypeException | [
"Validate",
"object",
"type"
] | train | https://github.com/stingus/phpdt/blob/931088dd8a04ace0bc83ff85cfc1707c6edbdc95/src/PHPdt/DataType/ObjectValidationTrait.php#L23-L35 |
fond-of/spryker-product-list-company | src/FondOfSpryker/Zed/ProductListCompany/Communication/Plugin/ProductListTransferExpanderPlugin.php | ProductListTransferExpanderPlugin.expandTransfer | public function expandTransfer(ProductListTransfer $productListTransfer): ProductListTransfer
{
$productListTransfer = $this->getFacade()
->expandProductListTransferWithProductListCompanyRelationTransfer($productListTransfer);
return $productListTransfer;
} | php | public function expandTransfer(ProductListTransfer $productListTransfer): ProductListTransfer
{
$productListTransfer = $this->getFacade()
->expandProductListTransferWithProductListCompanyRelationTransfer($productListTransfer);
return $productListTransfer;
} | [
"public",
"function",
"expandTransfer",
"(",
"ProductListTransfer",
"$",
"productListTransfer",
")",
":",
"ProductListTransfer",
"{",
"$",
"productListTransfer",
"=",
"$",
"this",
"->",
"getFacade",
"(",
")",
"->",
"expandProductListTransferWithProductListCompanyRelationTransfer",
"(",
"$",
"productListTransfer",
")",
";",
"return",
"$",
"productListTransfer",
";",
"}"
] | Specification
- Expands the provided product list transfer object's data and returns the modified object.
@api
@param \Generated\Shared\Transfer\ProductListTransfer $productListTransfer
@return \Generated\Shared\Transfer\ProductListTransfer | [
"Specification",
"-",
"Expands",
"the",
"provided",
"product",
"list",
"transfer",
"object",
"s",
"data",
"and",
"returns",
"the",
"modified",
"object",
"."
] | train | https://github.com/fond-of/spryker-product-list-company/blob/59228ae716e5e23b442bdd669be2ad5282eb32cc/src/FondOfSpryker/Zed/ProductListCompany/Communication/Plugin/ProductListTransferExpanderPlugin.php#L24-L30 |
ColibriPlatform/admin | Module.php | Module.bootstrap | public function bootstrap($app)
{
$app->urlManager->addRules([
$this->id . '/login' => '/user/security/login',
// $this->id . '/logout' => '/user/security/logout',
$this->id . '/users/<action:\w+>' => '/user/admin/<action>',
$this->id . '/rbac/<controller:\w+>/<action:\w+>' => '/rbac/<controller>/<action>',
]);
$app->getModule('user')->controllerMap['admin'] = [
'class' => 'dektrium\user\controllers\AdminController',
'layout' => '@vendor/colibri-platform/admin/views/layouts/main.php'
];
$app->getModule('rbac')->layout = '@vendor/colibri-platform/admin/views/layouts/main.php';
if (ltrim($app->getRequest()->url, '/') == $this->id . '/login') {
// Set the admin layout and override view to the login form
$app->getModule('user')->controllerMap['security'] = [
'class' => 'dektrium\user\controllers\SecurityController',
'layout' => '@vendor/colibri-platform/admin/views/layouts/login.php'
];
$view = $app->getView();
if (empty($view->theme)) {
$view->theme = Yii::createObject('yii\base\Theme');
}
$view->theme->pathMap['@dektrium/user/views'] = __DIR__ . '/views/user';
// Set the return url to the admin home
$app->getUser()->setReturnUrl('/' . $this->id);
}
if ($app->getModule('treemanager', false) === null) {
$app->setModule('treemanager', [
'class' => '\kartik\tree\Module',
// The list of asset bundles that would be unset when rendering the node detail form via ajax
'unsetAjaxBundles' => [
'yii\web\YiiAsset',
'yii\web\JqueryAsset',
'yii\widgets\ActiveFormAsset',
'kartik\form\ActiveFormAsset',
'yii\validators\ValidationAsset',
'yii\bootstrap\BootstrapAsset',
]
]);
}
} | php | public function bootstrap($app)
{
$app->urlManager->addRules([
$this->id . '/login' => '/user/security/login',
// $this->id . '/logout' => '/user/security/logout',
$this->id . '/users/<action:\w+>' => '/user/admin/<action>',
$this->id . '/rbac/<controller:\w+>/<action:\w+>' => '/rbac/<controller>/<action>',
]);
$app->getModule('user')->controllerMap['admin'] = [
'class' => 'dektrium\user\controllers\AdminController',
'layout' => '@vendor/colibri-platform/admin/views/layouts/main.php'
];
$app->getModule('rbac')->layout = '@vendor/colibri-platform/admin/views/layouts/main.php';
if (ltrim($app->getRequest()->url, '/') == $this->id . '/login') {
// Set the admin layout and override view to the login form
$app->getModule('user')->controllerMap['security'] = [
'class' => 'dektrium\user\controllers\SecurityController',
'layout' => '@vendor/colibri-platform/admin/views/layouts/login.php'
];
$view = $app->getView();
if (empty($view->theme)) {
$view->theme = Yii::createObject('yii\base\Theme');
}
$view->theme->pathMap['@dektrium/user/views'] = __DIR__ . '/views/user';
// Set the return url to the admin home
$app->getUser()->setReturnUrl('/' . $this->id);
}
if ($app->getModule('treemanager', false) === null) {
$app->setModule('treemanager', [
'class' => '\kartik\tree\Module',
// The list of asset bundles that would be unset when rendering the node detail form via ajax
'unsetAjaxBundles' => [
'yii\web\YiiAsset',
'yii\web\JqueryAsset',
'yii\widgets\ActiveFormAsset',
'kartik\form\ActiveFormAsset',
'yii\validators\ValidationAsset',
'yii\bootstrap\BootstrapAsset',
]
]);
}
} | [
"public",
"function",
"bootstrap",
"(",
"$",
"app",
")",
"{",
"$",
"app",
"->",
"urlManager",
"->",
"addRules",
"(",
"[",
"$",
"this",
"->",
"id",
".",
"'/login'",
"=>",
"'/user/security/login'",
",",
"// $this->id . '/logout' => '/user/security/logout',",
"$",
"this",
"->",
"id",
".",
"'/users/<action:\\w+>'",
"=>",
"'/user/admin/<action>'",
",",
"$",
"this",
"->",
"id",
".",
"'/rbac/<controller:\\w+>/<action:\\w+>'",
"=>",
"'/rbac/<controller>/<action>'",
",",
"]",
")",
";",
"$",
"app",
"->",
"getModule",
"(",
"'user'",
")",
"->",
"controllerMap",
"[",
"'admin'",
"]",
"=",
"[",
"'class'",
"=>",
"'dektrium\\user\\controllers\\AdminController'",
",",
"'layout'",
"=>",
"'@vendor/colibri-platform/admin/views/layouts/main.php'",
"]",
";",
"$",
"app",
"->",
"getModule",
"(",
"'rbac'",
")",
"->",
"layout",
"=",
"'@vendor/colibri-platform/admin/views/layouts/main.php'",
";",
"if",
"(",
"ltrim",
"(",
"$",
"app",
"->",
"getRequest",
"(",
")",
"->",
"url",
",",
"'/'",
")",
"==",
"$",
"this",
"->",
"id",
".",
"'/login'",
")",
"{",
"// Set the admin layout and override view to the login form",
"$",
"app",
"->",
"getModule",
"(",
"'user'",
")",
"->",
"controllerMap",
"[",
"'security'",
"]",
"=",
"[",
"'class'",
"=>",
"'dektrium\\user\\controllers\\SecurityController'",
",",
"'layout'",
"=>",
"'@vendor/colibri-platform/admin/views/layouts/login.php'",
"]",
";",
"$",
"view",
"=",
"$",
"app",
"->",
"getView",
"(",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"view",
"->",
"theme",
")",
")",
"{",
"$",
"view",
"->",
"theme",
"=",
"Yii",
"::",
"createObject",
"(",
"'yii\\base\\Theme'",
")",
";",
"}",
"$",
"view",
"->",
"theme",
"->",
"pathMap",
"[",
"'@dektrium/user/views'",
"]",
"=",
"__DIR__",
".",
"'/views/user'",
";",
"// Set the return url to the admin home",
"$",
"app",
"->",
"getUser",
"(",
")",
"->",
"setReturnUrl",
"(",
"'/'",
".",
"$",
"this",
"->",
"id",
")",
";",
"}",
"if",
"(",
"$",
"app",
"->",
"getModule",
"(",
"'treemanager'",
",",
"false",
")",
"===",
"null",
")",
"{",
"$",
"app",
"->",
"setModule",
"(",
"'treemanager'",
",",
"[",
"'class'",
"=>",
"'\\kartik\\tree\\Module'",
",",
"// The list of asset bundles that would be unset when rendering the node detail form via ajax",
"'unsetAjaxBundles'",
"=>",
"[",
"'yii\\web\\YiiAsset'",
",",
"'yii\\web\\JqueryAsset'",
",",
"'yii\\widgets\\ActiveFormAsset'",
",",
"'kartik\\form\\ActiveFormAsset'",
",",
"'yii\\validators\\ValidationAsset'",
",",
"'yii\\bootstrap\\BootstrapAsset'",
",",
"]",
"]",
")",
";",
"}",
"}"
] | Bootstrap method to be called during application bootstrap stage.
@param \yii\web\Application $app the application currently running | [
"Bootstrap",
"method",
"to",
"be",
"called",
"during",
"application",
"bootstrap",
"stage",
"."
] | train | https://github.com/ColibriPlatform/admin/blob/cd9b6e75aa36eceb8436f5a637a85ee6f0ac53f6/Module.php#L77-L128 |
ColibriPlatform/admin | Module.php | Module.migrateUp | public static function migrateUp()
{
$migration = new Migration(Yii::getAlias('@vendor/colibri-platform/admin/migrations'));
$migration->up();
return implode("\n", $migration->messages);
} | php | public static function migrateUp()
{
$migration = new Migration(Yii::getAlias('@vendor/colibri-platform/admin/migrations'));
$migration->up();
return implode("\n", $migration->messages);
} | [
"public",
"static",
"function",
"migrateUp",
"(",
")",
"{",
"$",
"migration",
"=",
"new",
"Migration",
"(",
"Yii",
"::",
"getAlias",
"(",
"'@vendor/colibri-platform/admin/migrations'",
")",
")",
";",
"$",
"migration",
"->",
"up",
"(",
")",
";",
"return",
"implode",
"(",
"\"\\n\"",
",",
"$",
"migration",
"->",
"messages",
")",
";",
"}"
] | Module migrateUp method (called during application installation)
@return string Migration messages | [
"Module",
"migrateUp",
"method",
"(",
"called",
"during",
"application",
"installation",
")"
] | train | https://github.com/ColibriPlatform/admin/blob/cd9b6e75aa36eceb8436f5a637a85ee6f0ac53f6/Module.php#L149-L155 |
Polosa/shade-framework-core | app/View/Php.php | Php.render | public function render($templates, array $data = array())
{
$__templates = (array) $templates;
extract($data);
ob_start();
foreach ($__templates as $__template) {
$__template = $this->templatesPath.$__template;
if (is_readable($__template) && is_file($__template)) {
include $__template;
} else {
ob_end_clean();
throw new \Shade\Exception('Template file "'.$__template.'" does not exists');
}
$content = ob_get_clean();
}
return $content;
} | php | public function render($templates, array $data = array())
{
$__templates = (array) $templates;
extract($data);
ob_start();
foreach ($__templates as $__template) {
$__template = $this->templatesPath.$__template;
if (is_readable($__template) && is_file($__template)) {
include $__template;
} else {
ob_end_clean();
throw new \Shade\Exception('Template file "'.$__template.'" does not exists');
}
$content = ob_get_clean();
}
return $content;
} | [
"public",
"function",
"render",
"(",
"$",
"templates",
",",
"array",
"$",
"data",
"=",
"array",
"(",
")",
")",
"{",
"$",
"__templates",
"=",
"(",
"array",
")",
"$",
"templates",
";",
"extract",
"(",
"$",
"data",
")",
";",
"ob_start",
"(",
")",
";",
"foreach",
"(",
"$",
"__templates",
"as",
"$",
"__template",
")",
"{",
"$",
"__template",
"=",
"$",
"this",
"->",
"templatesPath",
".",
"$",
"__template",
";",
"if",
"(",
"is_readable",
"(",
"$",
"__template",
")",
"&&",
"is_file",
"(",
"$",
"__template",
")",
")",
"{",
"include",
"$",
"__template",
";",
"}",
"else",
"{",
"ob_end_clean",
"(",
")",
";",
"throw",
"new",
"\\",
"Shade",
"\\",
"Exception",
"(",
"'Template file \"'",
".",
"$",
"__template",
".",
"'\" does not exists'",
")",
";",
"}",
"$",
"content",
"=",
"ob_get_clean",
"(",
")",
";",
"}",
"return",
"$",
"content",
";",
"}"
] | Render template
@param string|array $templates Path to template or array of paths to template and layouts
@param array $data Data for templates
@throws \Shade\Exception
@return string | [
"Render",
"template"
] | train | https://github.com/Polosa/shade-framework-core/blob/d735d3e8e0616fb9cf4ffc25b8425762ed07940f/app/View/Php.php#L94-L114 |
Vectrex/vxPHP | src/Database/Util.php | Util.unFormatDate | public static function unFormatDate($dateString, $locale = '') {
if(empty($dateString)) {
return '';
}
$tmp = preg_split('/( |\.|\/|-)/', $dateString);
if(count($tmp) === 3) {
switch($locale) {
case 'de':
$tmp[2] = substr(date('Y'), 0, 4 - strlen($tmp[2])).$tmp[2];
return sprintf('%04d-%02d-%02d', $tmp[2], $tmp[1], $tmp[0]);
case 'us':
$tmp[2] = substr(date('Y'), 0, 4 - strlen($tmp[2])).$tmp[2];
return sprintf('%04d-%02d-%02d', $tmp[2], $tmp[0], $tmp[1]);
case 'iso':
$tmp[0] = substr(date('Y'), 0, 4 - strlen($tmp[0])).$tmp[0];
return sprintf('%04d-%02d-%02d', $tmp[0], $tmp[1], $tmp[2]);
default:
if(($parsed = strtotime($dateString)) === FALSE) {
return '';
}
return date('Y-m-d', $parsed);
}
}
if(($parsed = strtotime($dateString)) === FALSE) {
return '';
}
return date('Y-m-d', $parsed);
} | php | public static function unFormatDate($dateString, $locale = '') {
if(empty($dateString)) {
return '';
}
$tmp = preg_split('/( |\.|\/|-)/', $dateString);
if(count($tmp) === 3) {
switch($locale) {
case 'de':
$tmp[2] = substr(date('Y'), 0, 4 - strlen($tmp[2])).$tmp[2];
return sprintf('%04d-%02d-%02d', $tmp[2], $tmp[1], $tmp[0]);
case 'us':
$tmp[2] = substr(date('Y'), 0, 4 - strlen($tmp[2])).$tmp[2];
return sprintf('%04d-%02d-%02d', $tmp[2], $tmp[0], $tmp[1]);
case 'iso':
$tmp[0] = substr(date('Y'), 0, 4 - strlen($tmp[0])).$tmp[0];
return sprintf('%04d-%02d-%02d', $tmp[0], $tmp[1], $tmp[2]);
default:
if(($parsed = strtotime($dateString)) === FALSE) {
return '';
}
return date('Y-m-d', $parsed);
}
}
if(($parsed = strtotime($dateString)) === FALSE) {
return '';
}
return date('Y-m-d', $parsed);
} | [
"public",
"static",
"function",
"unFormatDate",
"(",
"$",
"dateString",
",",
"$",
"locale",
"=",
"''",
")",
"{",
"if",
"(",
"empty",
"(",
"$",
"dateString",
")",
")",
"{",
"return",
"''",
";",
"}",
"$",
"tmp",
"=",
"preg_split",
"(",
"'/( |\\.|\\/|-)/'",
",",
"$",
"dateString",
")",
";",
"if",
"(",
"count",
"(",
"$",
"tmp",
")",
"===",
"3",
")",
"{",
"switch",
"(",
"$",
"locale",
")",
"{",
"case",
"'de'",
":",
"$",
"tmp",
"[",
"2",
"]",
"=",
"substr",
"(",
"date",
"(",
"'Y'",
")",
",",
"0",
",",
"4",
"-",
"strlen",
"(",
"$",
"tmp",
"[",
"2",
"]",
")",
")",
".",
"$",
"tmp",
"[",
"2",
"]",
";",
"return",
"sprintf",
"(",
"'%04d-%02d-%02d'",
",",
"$",
"tmp",
"[",
"2",
"]",
",",
"$",
"tmp",
"[",
"1",
"]",
",",
"$",
"tmp",
"[",
"0",
"]",
")",
";",
"case",
"'us'",
":",
"$",
"tmp",
"[",
"2",
"]",
"=",
"substr",
"(",
"date",
"(",
"'Y'",
")",
",",
"0",
",",
"4",
"-",
"strlen",
"(",
"$",
"tmp",
"[",
"2",
"]",
")",
")",
".",
"$",
"tmp",
"[",
"2",
"]",
";",
"return",
"sprintf",
"(",
"'%04d-%02d-%02d'",
",",
"$",
"tmp",
"[",
"2",
"]",
",",
"$",
"tmp",
"[",
"0",
"]",
",",
"$",
"tmp",
"[",
"1",
"]",
")",
";",
"case",
"'iso'",
":",
"$",
"tmp",
"[",
"0",
"]",
"=",
"substr",
"(",
"date",
"(",
"'Y'",
")",
",",
"0",
",",
"4",
"-",
"strlen",
"(",
"$",
"tmp",
"[",
"0",
"]",
")",
")",
".",
"$",
"tmp",
"[",
"0",
"]",
";",
"return",
"sprintf",
"(",
"'%04d-%02d-%02d'",
",",
"$",
"tmp",
"[",
"0",
"]",
",",
"$",
"tmp",
"[",
"1",
"]",
",",
"$",
"tmp",
"[",
"2",
"]",
")",
";",
"default",
":",
"if",
"(",
"(",
"$",
"parsed",
"=",
"strtotime",
"(",
"$",
"dateString",
")",
")",
"===",
"FALSE",
")",
"{",
"return",
"''",
";",
"}",
"return",
"date",
"(",
"'Y-m-d'",
",",
"$",
"parsed",
")",
";",
"}",
"}",
"if",
"(",
"(",
"$",
"parsed",
"=",
"strtotime",
"(",
"$",
"dateString",
")",
")",
"===",
"FALSE",
")",
"{",
"return",
"''",
";",
"}",
"return",
"date",
"(",
"'Y-m-d'",
",",
"$",
"parsed",
")",
";",
"}"
] | Re-formats a date strings depending on a supplied input locale to yyyy-mm-dd
does not check validity of date
supported locales are "us" | "iso" | "de"
if no locale is provided, strtotime() tries to interpret the date string
an empty string is returned if date string could not be parsed
@param string $dateString
@param string $locale
@return string | [
"Re",
"-",
"formats",
"a",
"date",
"strings",
"depending",
"on",
"a",
"supplied",
"input",
"locale",
"to",
"yyyy",
"-",
"mm",
"-",
"dd",
"does",
"not",
"check",
"validity",
"of",
"date",
"supported",
"locales",
"are",
"us",
"|",
"iso",
"|",
"de",
"if",
"no",
"locale",
"is",
"provided",
"strtotime",
"()",
"tries",
"to",
"interpret",
"the",
"date",
"string",
"an",
"empty",
"string",
"is",
"returned",
"if",
"date",
"string",
"could",
"not",
"be",
"parsed"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Database/Util.php#L34-L72 |
Vectrex/vxPHP | src/Database/Util.php | Util.unFormatDecimal | public static function unFormatDecimal($decimalString) {
if(trim($decimalString) == '') {
return NAN;
}
// remove a leading "+"
$decimalString = rtrim('+', trim($decimalString));
// only a decimal separator ("," or ".")
if(preg_match('/^\-?\d+([,.]\d+)?$/', $decimalString)) {
return (float) (str_replace(',', '.', $decimalString));
}
// "," as thousands separator "." as decimal separator
if(preg_match('/^\-?[1-9]\d{0,2}((,|\')\d{3})*(\.\d+)?$/', $decimalString)) {
return (float) (str_replace(array(',', '\''), array('', ''), $decimalString));
}
// "." as thousands separator "," as decimal separator
if(preg_match('/^\-?[1-9]\d{0,2}(\.\d{3})*(,\d+)?$/', $decimalString)) {
return (float) (str_replace(array('.', ','), array('', '.'), $decimalString));
}
// try type casting
return (float) $decimalString;
} | php | public static function unFormatDecimal($decimalString) {
if(trim($decimalString) == '') {
return NAN;
}
// remove a leading "+"
$decimalString = rtrim('+', trim($decimalString));
// only a decimal separator ("," or ".")
if(preg_match('/^\-?\d+([,.]\d+)?$/', $decimalString)) {
return (float) (str_replace(',', '.', $decimalString));
}
// "," as thousands separator "." as decimal separator
if(preg_match('/^\-?[1-9]\d{0,2}((,|\')\d{3})*(\.\d+)?$/', $decimalString)) {
return (float) (str_replace(array(',', '\''), array('', ''), $decimalString));
}
// "." as thousands separator "," as decimal separator
if(preg_match('/^\-?[1-9]\d{0,2}(\.\d{3})*(,\d+)?$/', $decimalString)) {
return (float) (str_replace(array('.', ','), array('', '.'), $decimalString));
}
// try type casting
return (float) $decimalString;
} | [
"public",
"static",
"function",
"unFormatDecimal",
"(",
"$",
"decimalString",
")",
"{",
"if",
"(",
"trim",
"(",
"$",
"decimalString",
")",
"==",
"''",
")",
"{",
"return",
"NAN",
";",
"}",
"// remove a leading \"+\"",
"$",
"decimalString",
"=",
"rtrim",
"(",
"'+'",
",",
"trim",
"(",
"$",
"decimalString",
")",
")",
";",
"// only a decimal separator (\",\" or \".\")",
"if",
"(",
"preg_match",
"(",
"'/^\\-?\\d+([,.]\\d+)?$/'",
",",
"$",
"decimalString",
")",
")",
"{",
"return",
"(",
"float",
")",
"(",
"str_replace",
"(",
"','",
",",
"'.'",
",",
"$",
"decimalString",
")",
")",
";",
"}",
"// \",\" as thousands separator \".\" as decimal separator",
"if",
"(",
"preg_match",
"(",
"'/^\\-?[1-9]\\d{0,2}((,|\\')\\d{3})*(\\.\\d+)?$/'",
",",
"$",
"decimalString",
")",
")",
"{",
"return",
"(",
"float",
")",
"(",
"str_replace",
"(",
"array",
"(",
"','",
",",
"'\\''",
")",
",",
"array",
"(",
"''",
",",
"''",
")",
",",
"$",
"decimalString",
")",
")",
";",
"}",
"// \".\" as thousands separator \",\" as decimal separator",
"if",
"(",
"preg_match",
"(",
"'/^\\-?[1-9]\\d{0,2}(\\.\\d{3})*(,\\d+)?$/'",
",",
"$",
"decimalString",
")",
")",
"{",
"return",
"(",
"float",
")",
"(",
"str_replace",
"(",
"array",
"(",
"'.'",
",",
"','",
")",
",",
"array",
"(",
"''",
",",
"'.'",
")",
",",
"$",
"decimalString",
")",
")",
";",
"}",
"// try type casting",
"return",
"(",
"float",
")",
"$",
"decimalString",
";",
"}"
] | Strips decimal strings from everything but decimal point and negative prefix
and returns the result as float
@param string $decimalString
@return float | NaN | [
"Strips",
"decimal",
"strings",
"from",
"everything",
"but",
"decimal",
"point",
"and",
"negative",
"prefix",
"and",
"returns",
"the",
"result",
"as",
"float"
] | train | https://github.com/Vectrex/vxPHP/blob/295c21b00e7ef6085efcdf5b64fabb28d499b5a6/src/Database/Util.php#L81-L112 |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.