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
|
---|---|---|---|---|---|---|---|---|---|---|
chemel/dom-parser-helper | src/HtmlDomParserHelper.php | HtmlDomParserHelper.getPageMetas | public function getPageMetas()
{
if (!$this->parser) {
return;
}
$nodes = $this->parser->find('meta');
$metas = array();
foreach ($nodes as $node) {
if ($node->hasAttribute('name')) {
$metas[ $node->getAttribute('name') ] = $node->getAttribute('content');
} elseif ($node->hasAttribute('property')) {
$metas[ $node->getAttribute('property') ] = $node->getAttribute('content');
}
}
return $metas;
} | php | public function getPageMetas()
{
if (!$this->parser) {
return;
}
$nodes = $this->parser->find('meta');
$metas = array();
foreach ($nodes as $node) {
if ($node->hasAttribute('name')) {
$metas[ $node->getAttribute('name') ] = $node->getAttribute('content');
} elseif ($node->hasAttribute('property')) {
$metas[ $node->getAttribute('property') ] = $node->getAttribute('content');
}
}
return $metas;
} | [
"public",
"function",
"getPageMetas",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"parser",
")",
"{",
"return",
";",
"}",
"$",
"nodes",
"=",
"$",
"this",
"->",
"parser",
"->",
"find",
"(",
"'meta'",
")",
";",
"$",
"metas",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"if",
"(",
"$",
"node",
"->",
"hasAttribute",
"(",
"'name'",
")",
")",
"{",
"$",
"metas",
"[",
"$",
"node",
"->",
"getAttribute",
"(",
"'name'",
")",
"]",
"=",
"$",
"node",
"->",
"getAttribute",
"(",
"'content'",
")",
";",
"}",
"elseif",
"(",
"$",
"node",
"->",
"hasAttribute",
"(",
"'property'",
")",
")",
"{",
"$",
"metas",
"[",
"$",
"node",
"->",
"getAttribute",
"(",
"'property'",
")",
"]",
"=",
"$",
"node",
"->",
"getAttribute",
"(",
"'content'",
")",
";",
"}",
"}",
"return",
"$",
"metas",
";",
"}"
] | Get meta description
@return array metas | [
"Get",
"meta",
"description"
] | train | https://github.com/chemel/dom-parser-helper/blob/0ec7df13b19e3f3df4453023b37cba6bb16eb10a/src/HtmlDomParserHelper.php#L226-L245 |
chemel/dom-parser-helper | src/HtmlDomParserHelper.php | HtmlDomParserHelper.getPageFeeds | public function getPageFeeds()
{
if (!$this->parser) {
return;
}
$nodes = $this->parser->find('link');
$feeds = array();
$types = array(
'application/rss+xml',
'application/atom+xml',
'text/xml',
);
foreach ($nodes as $node) {
$type = strtolower($node->getAttribute('type'));
if (in_array($type, $types)) {
$feeds[] = $node->getAttribute('href');
}
}
return $feeds;
} | php | public function getPageFeeds()
{
if (!$this->parser) {
return;
}
$nodes = $this->parser->find('link');
$feeds = array();
$types = array(
'application/rss+xml',
'application/atom+xml',
'text/xml',
);
foreach ($nodes as $node) {
$type = strtolower($node->getAttribute('type'));
if (in_array($type, $types)) {
$feeds[] = $node->getAttribute('href');
}
}
return $feeds;
} | [
"public",
"function",
"getPageFeeds",
"(",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"parser",
")",
"{",
"return",
";",
"}",
"$",
"nodes",
"=",
"$",
"this",
"->",
"parser",
"->",
"find",
"(",
"'link'",
")",
";",
"$",
"feeds",
"=",
"array",
"(",
")",
";",
"$",
"types",
"=",
"array",
"(",
"'application/rss+xml'",
",",
"'application/atom+xml'",
",",
"'text/xml'",
",",
")",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"$",
"type",
"=",
"strtolower",
"(",
"$",
"node",
"->",
"getAttribute",
"(",
"'type'",
")",
")",
";",
"if",
"(",
"in_array",
"(",
"$",
"type",
",",
"$",
"types",
")",
")",
"{",
"$",
"feeds",
"[",
"]",
"=",
"$",
"node",
"->",
"getAttribute",
"(",
"'href'",
")",
";",
"}",
"}",
"return",
"$",
"feeds",
";",
"}"
] | Get rss feeds urls
@return array feeds | [
"Get",
"rss",
"feeds",
"urls"
] | train | https://github.com/chemel/dom-parser-helper/blob/0ec7df13b19e3f3df4453023b37cba6bb16eb10a/src/HtmlDomParserHelper.php#L252-L277 |
chemel/dom-parser-helper | src/HtmlDomParserHelper.php | HtmlDomParserHelper.findAll | public function findAll($selector, $function, $arguments = array())
{
if (!$this->parser) {
return;
}
$nodes = $this->parser->find($selector);
if (!$nodes) {
return;
}
if (!is_array($arguments)) {
$arguments = array($arguments);
}
$results = array();
foreach ($nodes as $node) {
$results[] = call_user_func_array(array($node, $function), $arguments);
}
return $results;
} | php | public function findAll($selector, $function, $arguments = array())
{
if (!$this->parser) {
return;
}
$nodes = $this->parser->find($selector);
if (!$nodes) {
return;
}
if (!is_array($arguments)) {
$arguments = array($arguments);
}
$results = array();
foreach ($nodes as $node) {
$results[] = call_user_func_array(array($node, $function), $arguments);
}
return $results;
} | [
"public",
"function",
"findAll",
"(",
"$",
"selector",
",",
"$",
"function",
",",
"$",
"arguments",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"parser",
")",
"{",
"return",
";",
"}",
"$",
"nodes",
"=",
"$",
"this",
"->",
"parser",
"->",
"find",
"(",
"$",
"selector",
")",
";",
"if",
"(",
"!",
"$",
"nodes",
")",
"{",
"return",
";",
"}",
"if",
"(",
"!",
"is_array",
"(",
"$",
"arguments",
")",
")",
"{",
"$",
"arguments",
"=",
"array",
"(",
"$",
"arguments",
")",
";",
"}",
"$",
"results",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"$",
"nodes",
"as",
"$",
"node",
")",
"{",
"$",
"results",
"[",
"]",
"=",
"call_user_func_array",
"(",
"array",
"(",
"$",
"node",
",",
"$",
"function",
")",
",",
"$",
"arguments",
")",
";",
"}",
"return",
"$",
"results",
";",
"}"
] | Find all
@param string selector
@param string results
@param array arguments
@return array results | [
"Find",
"all"
] | train | https://github.com/chemel/dom-parser-helper/blob/0ec7df13b19e3f3df4453023b37cba6bb16eb10a/src/HtmlDomParserHelper.php#L288-L311 |
chemel/dom-parser-helper | src/HtmlDomParserHelper.php | HtmlDomParserHelper.clear | public function clear()
{
$this->response = null;
if ($this->parser) {
$this->parser->clear();
}
$this->parser = null;
} | php | public function clear()
{
$this->response = null;
if ($this->parser) {
$this->parser->clear();
}
$this->parser = null;
} | [
"public",
"function",
"clear",
"(",
")",
"{",
"$",
"this",
"->",
"response",
"=",
"null",
";",
"if",
"(",
"$",
"this",
"->",
"parser",
")",
"{",
"$",
"this",
"->",
"parser",
"->",
"clear",
"(",
")",
";",
"}",
"$",
"this",
"->",
"parser",
"=",
"null",
";",
"}"
] | Clean up memory | [
"Clean",
"up",
"memory"
] | train | https://github.com/chemel/dom-parser-helper/blob/0ec7df13b19e3f3df4453023b37cba6bb16eb10a/src/HtmlDomParserHelper.php#L336-L345 |
hametuha/wpametu | src/WPametu/DB/Column.php | Column.data_type | private static function data_type($column){
/** @var $wpdb \wpdb */
global $wpdb;
// Let's create query
$sql = $column['type'];
// Is DECIMAL?
if( self::DECIMAL == $column['type'] ){
$sql .= sprintf('(%d, %d)', $column['max_digit'], $column['float']);
}
// Add length
if( isset($column['length']) ){
$sql .= sprintf('(%d)', $column['length']);
}
// Is enum or set?
if( self::is_set($column['type']) ){
$values = [];
foreach($column['values'] as $val){
$values[] = $wpdb->prepare('%s', $val);
}
$sql .= sprintf('(%s)', implode(', ', $values));
}
// Is unsigned?
if( self::is_numeric($column['type']) && isset($column['signed']) && !$column['signed'] ){
$sql .= ' UNSIGNED';
}
// Is not null?
if( !$column['null'] ){
$sql .= ' NOT NULL';
}
// Is auto increment?
if( isset($column['auto_increment']) && $column['auto_increment'] ){
$sql .= ' AUTO_INCREMENT';
}
// Is primary key?
if( isset($column['primary']) && $column['primary'] ){
$sql .= ' PRIMARY KEY';
}
// Has default?
if( isset($column['default']) ){
if( self::is_numeric($column['default']) ){
$repl = ' DEFAULT '.$column['default'];
}else{
switch( $column['default'] ){
case 'CURRENT_TIMESTAMP':
// Without replace
$sql .= " DEFAULT {$column['default']}";
break;
default:
// Replace
$sql .= $wpdb->prepare(' DEFAULT %s', $column['default']);
break;
}
}
}
return $sql;
} | php | private static function data_type($column){
/** @var $wpdb \wpdb */
global $wpdb;
// Let's create query
$sql = $column['type'];
// Is DECIMAL?
if( self::DECIMAL == $column['type'] ){
$sql .= sprintf('(%d, %d)', $column['max_digit'], $column['float']);
}
// Add length
if( isset($column['length']) ){
$sql .= sprintf('(%d)', $column['length']);
}
// Is enum or set?
if( self::is_set($column['type']) ){
$values = [];
foreach($column['values'] as $val){
$values[] = $wpdb->prepare('%s', $val);
}
$sql .= sprintf('(%s)', implode(', ', $values));
}
// Is unsigned?
if( self::is_numeric($column['type']) && isset($column['signed']) && !$column['signed'] ){
$sql .= ' UNSIGNED';
}
// Is not null?
if( !$column['null'] ){
$sql .= ' NOT NULL';
}
// Is auto increment?
if( isset($column['auto_increment']) && $column['auto_increment'] ){
$sql .= ' AUTO_INCREMENT';
}
// Is primary key?
if( isset($column['primary']) && $column['primary'] ){
$sql .= ' PRIMARY KEY';
}
// Has default?
if( isset($column['default']) ){
if( self::is_numeric($column['default']) ){
$repl = ' DEFAULT '.$column['default'];
}else{
switch( $column['default'] ){
case 'CURRENT_TIMESTAMP':
// Without replace
$sql .= " DEFAULT {$column['default']}";
break;
default:
// Replace
$sql .= $wpdb->prepare(' DEFAULT %s', $column['default']);
break;
}
}
}
return $sql;
} | [
"private",
"static",
"function",
"data_type",
"(",
"$",
"column",
")",
"{",
"/** @var $wpdb \\wpdb */",
"global",
"$",
"wpdb",
";",
"// Let's create query",
"$",
"sql",
"=",
"$",
"column",
"[",
"'type'",
"]",
";",
"// Is DECIMAL?",
"if",
"(",
"self",
"::",
"DECIMAL",
"==",
"$",
"column",
"[",
"'type'",
"]",
")",
"{",
"$",
"sql",
".=",
"sprintf",
"(",
"'(%d, %d)'",
",",
"$",
"column",
"[",
"'max_digit'",
"]",
",",
"$",
"column",
"[",
"'float'",
"]",
")",
";",
"}",
"// Add length",
"if",
"(",
"isset",
"(",
"$",
"column",
"[",
"'length'",
"]",
")",
")",
"{",
"$",
"sql",
".=",
"sprintf",
"(",
"'(%d)'",
",",
"$",
"column",
"[",
"'length'",
"]",
")",
";",
"}",
"// Is enum or set?",
"if",
"(",
"self",
"::",
"is_set",
"(",
"$",
"column",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"column",
"[",
"'values'",
"]",
"as",
"$",
"val",
")",
"{",
"$",
"values",
"[",
"]",
"=",
"$",
"wpdb",
"->",
"prepare",
"(",
"'%s'",
",",
"$",
"val",
")",
";",
"}",
"$",
"sql",
".=",
"sprintf",
"(",
"'(%s)'",
",",
"implode",
"(",
"', '",
",",
"$",
"values",
")",
")",
";",
"}",
"// Is unsigned?",
"if",
"(",
"self",
"::",
"is_numeric",
"(",
"$",
"column",
"[",
"'type'",
"]",
")",
"&&",
"isset",
"(",
"$",
"column",
"[",
"'signed'",
"]",
")",
"&&",
"!",
"$",
"column",
"[",
"'signed'",
"]",
")",
"{",
"$",
"sql",
".=",
"' UNSIGNED'",
";",
"}",
"// Is not null?",
"if",
"(",
"!",
"$",
"column",
"[",
"'null'",
"]",
")",
"{",
"$",
"sql",
".=",
"' NOT NULL'",
";",
"}",
"// Is auto increment?",
"if",
"(",
"isset",
"(",
"$",
"column",
"[",
"'auto_increment'",
"]",
")",
"&&",
"$",
"column",
"[",
"'auto_increment'",
"]",
")",
"{",
"$",
"sql",
".=",
"' AUTO_INCREMENT'",
";",
"}",
"// Is primary key?",
"if",
"(",
"isset",
"(",
"$",
"column",
"[",
"'primary'",
"]",
")",
"&&",
"$",
"column",
"[",
"'primary'",
"]",
")",
"{",
"$",
"sql",
".=",
"' PRIMARY KEY'",
";",
"}",
"// Has default?",
"if",
"(",
"isset",
"(",
"$",
"column",
"[",
"'default'",
"]",
")",
")",
"{",
"if",
"(",
"self",
"::",
"is_numeric",
"(",
"$",
"column",
"[",
"'default'",
"]",
")",
")",
"{",
"$",
"repl",
"=",
"' DEFAULT '",
".",
"$",
"column",
"[",
"'default'",
"]",
";",
"}",
"else",
"{",
"switch",
"(",
"$",
"column",
"[",
"'default'",
"]",
")",
"{",
"case",
"'CURRENT_TIMESTAMP'",
":",
"// Without replace",
"$",
"sql",
".=",
"\" DEFAULT {$column['default']}\"",
";",
"break",
";",
"default",
":",
"// Replace",
"$",
"sql",
".=",
"$",
"wpdb",
"->",
"prepare",
"(",
"' DEFAULT %s'",
",",
"$",
"column",
"[",
"'default'",
"]",
")",
";",
"break",
";",
"}",
"}",
"}",
"return",
"$",
"sql",
";",
"}"
] | Build data type on create statement
@param array $column
@return string | [
"Build",
"data",
"type",
"on",
"create",
"statement"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/Column.php#L149-L204 |
hametuha/wpametu | src/WPametu/DB/Column.php | Column.filter | public static function filter($column){
$column = wp_parse_args($column, [
'type' => '',
'null' => false,
]);
// Type required.
if( !self::exists($column['type']) ){
throw new \Exception('You must properly specify the data type of column.');
}
// Check varchar length
if( self::is_length_required($column['type']) && !isset($column['length']) ){
throw new \Exception(sprintf('Column %s requires length property.', $column['type']));
}
// Signed or Unsigned?
if( self::is_numeric($column['type']) ){
$column['signed'] = isset($column['signed']) ? (bool)$column['signed'] : true;
}
// If decimal, test_required params
if( $column['type'] == self::DECIMAL ){
if( !isset($column['max_digit'], $column['float']) ){
throw new \Exception(sprintf('Column %s requires max_digit and float property.', self::DECIMAL));
}
}
// If enum or set, test required properties.
if( self::is_set($column['type']) && ( !is_array($column['values']) || empty($column['values']) ) ){
throw new \Exception(sprintf('Column %s requires values property as array.', $column['type']));
}
return $column;
} | php | public static function filter($column){
$column = wp_parse_args($column, [
'type' => '',
'null' => false,
]);
// Type required.
if( !self::exists($column['type']) ){
throw new \Exception('You must properly specify the data type of column.');
}
// Check varchar length
if( self::is_length_required($column['type']) && !isset($column['length']) ){
throw new \Exception(sprintf('Column %s requires length property.', $column['type']));
}
// Signed or Unsigned?
if( self::is_numeric($column['type']) ){
$column['signed'] = isset($column['signed']) ? (bool)$column['signed'] : true;
}
// If decimal, test_required params
if( $column['type'] == self::DECIMAL ){
if( !isset($column['max_digit'], $column['float']) ){
throw new \Exception(sprintf('Column %s requires max_digit and float property.', self::DECIMAL));
}
}
// If enum or set, test required properties.
if( self::is_set($column['type']) && ( !is_array($column['values']) || empty($column['values']) ) ){
throw new \Exception(sprintf('Column %s requires values property as array.', $column['type']));
}
return $column;
} | [
"public",
"static",
"function",
"filter",
"(",
"$",
"column",
")",
"{",
"$",
"column",
"=",
"wp_parse_args",
"(",
"$",
"column",
",",
"[",
"'type'",
"=>",
"''",
",",
"'null'",
"=>",
"false",
",",
"]",
")",
";",
"// Type required.",
"if",
"(",
"!",
"self",
"::",
"exists",
"(",
"$",
"column",
"[",
"'type'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'You must properly specify the data type of column.'",
")",
";",
"}",
"// Check varchar length",
"if",
"(",
"self",
"::",
"is_length_required",
"(",
"$",
"column",
"[",
"'type'",
"]",
")",
"&&",
"!",
"isset",
"(",
"$",
"column",
"[",
"'length'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Column %s requires length property.'",
",",
"$",
"column",
"[",
"'type'",
"]",
")",
")",
";",
"}",
"// Signed or Unsigned?",
"if",
"(",
"self",
"::",
"is_numeric",
"(",
"$",
"column",
"[",
"'type'",
"]",
")",
")",
"{",
"$",
"column",
"[",
"'signed'",
"]",
"=",
"isset",
"(",
"$",
"column",
"[",
"'signed'",
"]",
")",
"?",
"(",
"bool",
")",
"$",
"column",
"[",
"'signed'",
"]",
":",
"true",
";",
"}",
"// If decimal, test_required params",
"if",
"(",
"$",
"column",
"[",
"'type'",
"]",
"==",
"self",
"::",
"DECIMAL",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"column",
"[",
"'max_digit'",
"]",
",",
"$",
"column",
"[",
"'float'",
"]",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Column %s requires max_digit and float property.'",
",",
"self",
"::",
"DECIMAL",
")",
")",
";",
"}",
"}",
"// If enum or set, test required properties.",
"if",
"(",
"self",
"::",
"is_set",
"(",
"$",
"column",
"[",
"'type'",
"]",
")",
"&&",
"(",
"!",
"is_array",
"(",
"$",
"column",
"[",
"'values'",
"]",
")",
"||",
"empty",
"(",
"$",
"column",
"[",
"'values'",
"]",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"sprintf",
"(",
"'Column %s requires values property as array.'",
",",
"$",
"column",
"[",
"'type'",
"]",
")",
")",
";",
"}",
"return",
"$",
"column",
";",
"}"
] | Filter column array
@param array $column
@return array
@throws \Exception | [
"Filter",
"column",
"array"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/DB/Column.php#L213-L241 |
f1nder/SolutionPipelineBuilder | src/Solution/MongoAggregation/Pipeline/Query.php | Query.convertArgs | protected function convertArgs($step)
{
if ($step instanceof Operator) {
$arguments = $step->getArguments();
} else {
$arguments = $step;
}
if (is_array($arguments)) {
$values = [];
foreach ($arguments as $key => $args) {
if ($args instanceof Operator) {
if (is_string($key)) {
$values[$key] = [$this->cmd.$args->getOperatorName() => $this->convertArgs($args)];
} else {
$values[] = [$this->cmd.$args->getOperatorName() => $this->convertArgs($args)];
}
} else {
if (is_string($key)) {
$values[$key] = $this->convertArgs($args);
} else {
$values[] = $args;
}
}
}
return $values;
} elseif ($arguments instanceof Operator) {
return [$this->cmd.$arguments->getOperatorName() => $this->convertArgs($arguments)];
} else {
return $arguments;
}
} | php | protected function convertArgs($step)
{
if ($step instanceof Operator) {
$arguments = $step->getArguments();
} else {
$arguments = $step;
}
if (is_array($arguments)) {
$values = [];
foreach ($arguments as $key => $args) {
if ($args instanceof Operator) {
if (is_string($key)) {
$values[$key] = [$this->cmd.$args->getOperatorName() => $this->convertArgs($args)];
} else {
$values[] = [$this->cmd.$args->getOperatorName() => $this->convertArgs($args)];
}
} else {
if (is_string($key)) {
$values[$key] = $this->convertArgs($args);
} else {
$values[] = $args;
}
}
}
return $values;
} elseif ($arguments instanceof Operator) {
return [$this->cmd.$arguments->getOperatorName() => $this->convertArgs($arguments)];
} else {
return $arguments;
}
} | [
"protected",
"function",
"convertArgs",
"(",
"$",
"step",
")",
"{",
"if",
"(",
"$",
"step",
"instanceof",
"Operator",
")",
"{",
"$",
"arguments",
"=",
"$",
"step",
"->",
"getArguments",
"(",
")",
";",
"}",
"else",
"{",
"$",
"arguments",
"=",
"$",
"step",
";",
"}",
"if",
"(",
"is_array",
"(",
"$",
"arguments",
")",
")",
"{",
"$",
"values",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"arguments",
"as",
"$",
"key",
"=>",
"$",
"args",
")",
"{",
"if",
"(",
"$",
"args",
"instanceof",
"Operator",
")",
"{",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"$",
"values",
"[",
"$",
"key",
"]",
"=",
"[",
"$",
"this",
"->",
"cmd",
".",
"$",
"args",
"->",
"getOperatorName",
"(",
")",
"=>",
"$",
"this",
"->",
"convertArgs",
"(",
"$",
"args",
")",
"]",
";",
"}",
"else",
"{",
"$",
"values",
"[",
"]",
"=",
"[",
"$",
"this",
"->",
"cmd",
".",
"$",
"args",
"->",
"getOperatorName",
"(",
")",
"=>",
"$",
"this",
"->",
"convertArgs",
"(",
"$",
"args",
")",
"]",
";",
"}",
"}",
"else",
"{",
"if",
"(",
"is_string",
"(",
"$",
"key",
")",
")",
"{",
"$",
"values",
"[",
"$",
"key",
"]",
"=",
"$",
"this",
"->",
"convertArgs",
"(",
"$",
"args",
")",
";",
"}",
"else",
"{",
"$",
"values",
"[",
"]",
"=",
"$",
"args",
";",
"}",
"}",
"}",
"return",
"$",
"values",
";",
"}",
"elseif",
"(",
"$",
"arguments",
"instanceof",
"Operator",
")",
"{",
"return",
"[",
"$",
"this",
"->",
"cmd",
".",
"$",
"arguments",
"->",
"getOperatorName",
"(",
")",
"=>",
"$",
"this",
"->",
"convertArgs",
"(",
"$",
"arguments",
")",
"]",
";",
"}",
"else",
"{",
"return",
"$",
"arguments",
";",
"}",
"}"
] | Recursive convert args
@todo refactor
@param $step
@return array|string | [
"Recursive",
"convert",
"args"
] | train | https://github.com/f1nder/SolutionPipelineBuilder/blob/aca3cdfb2262fb3ceea82310b903c908c4c9b983/src/Solution/MongoAggregation/Pipeline/Query.php#L70-L103 |
impensavel/essence | src/SOAP.php | SOAP.makeCall | public function makeCall(array $input)
{
$input = array_replace_recursive(array(
'function' => null,
), $input, array(
'arguments' => array(),
'options' => array(),
'headers' => array(),
));
if (empty($input['function'])) {
throw new EssenceException('The SOAP function is not set');
}
try {
$this->client->__soapCall(
$input['function'],
array($input['arguments']),
$input['options'],
$input['headers'],
$this->lastResponseHeaders
);
$this->lastRequest = $this->client->__getLastRequest();
$this->lastResponse = $this->client->__getLastResponse();
return $this->lastResponse;
} catch (SoapFault $e) {
$this->lastRequest = $this->client->__getLastRequest();
$this->lastResponse = $this->client->__getLastResponse();
throw new EssenceException($e->getMessage(), $e->getCode(), $e);
}
} | php | public function makeCall(array $input)
{
$input = array_replace_recursive(array(
'function' => null,
), $input, array(
'arguments' => array(),
'options' => array(),
'headers' => array(),
));
if (empty($input['function'])) {
throw new EssenceException('The SOAP function is not set');
}
try {
$this->client->__soapCall(
$input['function'],
array($input['arguments']),
$input['options'],
$input['headers'],
$this->lastResponseHeaders
);
$this->lastRequest = $this->client->__getLastRequest();
$this->lastResponse = $this->client->__getLastResponse();
return $this->lastResponse;
} catch (SoapFault $e) {
$this->lastRequest = $this->client->__getLastRequest();
$this->lastResponse = $this->client->__getLastResponse();
throw new EssenceException($e->getMessage(), $e->getCode(), $e);
}
} | [
"public",
"function",
"makeCall",
"(",
"array",
"$",
"input",
")",
"{",
"$",
"input",
"=",
"array_replace_recursive",
"(",
"array",
"(",
"'function'",
"=>",
"null",
",",
")",
",",
"$",
"input",
",",
"array",
"(",
"'arguments'",
"=>",
"array",
"(",
")",
",",
"'options'",
"=>",
"array",
"(",
")",
",",
"'headers'",
"=>",
"array",
"(",
")",
",",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"input",
"[",
"'function'",
"]",
")",
")",
"{",
"throw",
"new",
"EssenceException",
"(",
"'The SOAP function is not set'",
")",
";",
"}",
"try",
"{",
"$",
"this",
"->",
"client",
"->",
"__soapCall",
"(",
"$",
"input",
"[",
"'function'",
"]",
",",
"array",
"(",
"$",
"input",
"[",
"'arguments'",
"]",
")",
",",
"$",
"input",
"[",
"'options'",
"]",
",",
"$",
"input",
"[",
"'headers'",
"]",
",",
"$",
"this",
"->",
"lastResponseHeaders",
")",
";",
"$",
"this",
"->",
"lastRequest",
"=",
"$",
"this",
"->",
"client",
"->",
"__getLastRequest",
"(",
")",
";",
"$",
"this",
"->",
"lastResponse",
"=",
"$",
"this",
"->",
"client",
"->",
"__getLastResponse",
"(",
")",
";",
"return",
"$",
"this",
"->",
"lastResponse",
";",
"}",
"catch",
"(",
"SoapFault",
"$",
"e",
")",
"{",
"$",
"this",
"->",
"lastRequest",
"=",
"$",
"this",
"->",
"client",
"->",
"__getLastRequest",
"(",
")",
";",
"$",
"this",
"->",
"lastResponse",
"=",
"$",
"this",
"->",
"client",
"->",
"__getLastResponse",
"(",
")",
";",
"throw",
"new",
"EssenceException",
"(",
"$",
"e",
"->",
"getMessage",
"(",
")",
",",
"$",
"e",
"->",
"getCode",
"(",
")",
",",
"$",
"e",
")",
";",
"}",
"}"
] | Make SOAP call
@param array $input Input data
@throws EssenceException
@return string | [
"Make",
"SOAP",
"call"
] | train | https://github.com/impensavel/essence/blob/e74969e55ac889e8c2cab9a915f82e93a72e629e/src/SOAP.php#L110-L143 |
impensavel/essence | src/SOAP.php | SOAP.extract | public function extract($input, array $config = array(), &$data = null)
{
if (! is_array($input)) {
throw new EssenceException('The input must be an associative array');
}
$response = $this->makeCall($input);
return parent::extract($response, $config, $data);
} | php | public function extract($input, array $config = array(), &$data = null)
{
if (! is_array($input)) {
throw new EssenceException('The input must be an associative array');
}
$response = $this->makeCall($input);
return parent::extract($response, $config, $data);
} | [
"public",
"function",
"extract",
"(",
"$",
"input",
",",
"array",
"$",
"config",
"=",
"array",
"(",
")",
",",
"&",
"$",
"data",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"input",
")",
")",
"{",
"throw",
"new",
"EssenceException",
"(",
"'The input must be an associative array'",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"makeCall",
"(",
"$",
"input",
")",
";",
"return",
"parent",
"::",
"extract",
"(",
"$",
"response",
",",
"$",
"config",
",",
"$",
"data",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/impensavel/essence/blob/e74969e55ac889e8c2cab9a915f82e93a72e629e/src/SOAP.php#L148-L157 |
impensavel/essence | src/SOAP.php | SOAP.dump | public function dump($input, array $config = array())
{
if (! is_array($input)) {
throw new EssenceException('The input must be an associative array');
}
$response = $this->makeCall($input);
return parent::dump($response, $config);
} | php | public function dump($input, array $config = array())
{
if (! is_array($input)) {
throw new EssenceException('The input must be an associative array');
}
$response = $this->makeCall($input);
return parent::dump($response, $config);
} | [
"public",
"function",
"dump",
"(",
"$",
"input",
",",
"array",
"$",
"config",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"!",
"is_array",
"(",
"$",
"input",
")",
")",
"{",
"throw",
"new",
"EssenceException",
"(",
"'The input must be an associative array'",
")",
";",
"}",
"$",
"response",
"=",
"$",
"this",
"->",
"makeCall",
"(",
"$",
"input",
")",
";",
"return",
"parent",
"::",
"dump",
"(",
"$",
"response",
",",
"$",
"config",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/impensavel/essence/blob/e74969e55ac889e8c2cab9a915f82e93a72e629e/src/SOAP.php#L162-L171 |
Yurunsoft/YurunEvent | Src/ClassEvent.php | ClassEvent.register | public function register($event, $callback, $first = false, $once = false)
{
if (!isset($this->yurunEvents[$event]))
{
$this->yurunEvents[$event] = array();
}
$item = array(
'callback' => $callback,
'once' => $once,
);
if($first)
{
array_unshift($this->yurunEvents[$event], $item);
}
else
{
$this->yurunEvents[$event][] = $item;
}
} | php | public function register($event, $callback, $first = false, $once = false)
{
if (!isset($this->yurunEvents[$event]))
{
$this->yurunEvents[$event] = array();
}
$item = array(
'callback' => $callback,
'once' => $once,
);
if($first)
{
array_unshift($this->yurunEvents[$event], $item);
}
else
{
$this->yurunEvents[$event][] = $item;
}
} | [
"public",
"function",
"register",
"(",
"$",
"event",
",",
"$",
"callback",
",",
"$",
"first",
"=",
"false",
",",
"$",
"once",
"=",
"false",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"this",
"->",
"yurunEvents",
"[",
"$",
"event",
"]",
")",
")",
"{",
"$",
"this",
"->",
"yurunEvents",
"[",
"$",
"event",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"item",
"=",
"array",
"(",
"'callback'",
"=>",
"$",
"callback",
",",
"'once'",
"=>",
"$",
"once",
",",
")",
";",
"if",
"(",
"$",
"first",
")",
"{",
"array_unshift",
"(",
"$",
"this",
"->",
"yurunEvents",
"[",
"$",
"event",
"]",
",",
"$",
"item",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"yurunEvents",
"[",
"$",
"event",
"]",
"[",
"]",
"=",
"$",
"item",
";",
"}",
"}"
] | 注册事件(监听)
@param string $event 事件名称
@param mixed $callback 回调
@param bool $first 是否优先执行,以靠后设置的为准
@param bool $once 是否只执行一次 | [
"注册事件",
"(",
"监听",
")"
] | train | https://github.com/Yurunsoft/YurunEvent/blob/7957f7d048ac0614f45e279e2b54d72ced67867c/Src/ClassEvent.php#L18-L36 |
Yurunsoft/YurunEvent | Src/ClassEvent.php | ClassEvent.on | public function on($event, $callback, $first = false)
{
$this->register($event, $callback, $first);
} | php | public function on($event, $callback, $first = false)
{
$this->register($event, $callback, $first);
} | [
"public",
"function",
"on",
"(",
"$",
"event",
",",
"$",
"callback",
",",
"$",
"first",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"register",
"(",
"$",
"event",
",",
"$",
"callback",
",",
"$",
"first",
")",
";",
"}"
] | 注册事件(监听),register的别名
@param string $event 事件名称
@param mixed $callback 回调
@param bool $first 是否优先执行,以靠后设置的为准 | [
"注册事件",
"(",
"监听",
")",
",register的别名"
] | train | https://github.com/Yurunsoft/YurunEvent/blob/7957f7d048ac0614f45e279e2b54d72ced67867c/Src/ClassEvent.php#L44-L47 |
Yurunsoft/YurunEvent | Src/ClassEvent.php | ClassEvent.once | public function once($event, $callback, $first = false)
{
$this->register($event, $callback, $first, true);
} | php | public function once($event, $callback, $first = false)
{
$this->register($event, $callback, $first, true);
} | [
"public",
"function",
"once",
"(",
"$",
"event",
",",
"$",
"callback",
",",
"$",
"first",
"=",
"false",
")",
"{",
"$",
"this",
"->",
"register",
"(",
"$",
"event",
",",
"$",
"callback",
",",
"$",
"first",
",",
"true",
")",
";",
"}"
] | 注册一次性事件(监听)
@param string $event 事件名称
@param mixed $callback 回调
@param boolean $first 是否优先执行,以靠后设置的为准 | [
"注册一次性事件",
"(",
"监听",
")"
] | train | https://github.com/Yurunsoft/YurunEvent/blob/7957f7d048ac0614f45e279e2b54d72ced67867c/Src/ClassEvent.php#L55-L58 |
Yurunsoft/YurunEvent | Src/ClassEvent.php | ClassEvent.trigger | protected function trigger($event, $params = array())
{
if (isset($this->yurunEvents[$event]))
{
$args = func_get_args();
array_shift($args);
foreach ($this->yurunEvents[$event] as $key => $item)
{
if(true === $item['once'])
{
unset($this->yurunEvents[$event][$key]);
}
if(true === call_user_func_array($item['callback'], $args))
{
// 事件返回true时不继续执行其余事件
return true;
}
}
return false;
}
return true;
} | php | protected function trigger($event, $params = array())
{
if (isset($this->yurunEvents[$event]))
{
$args = func_get_args();
array_shift($args);
foreach ($this->yurunEvents[$event] as $key => $item)
{
if(true === $item['once'])
{
unset($this->yurunEvents[$event][$key]);
}
if(true === call_user_func_array($item['callback'], $args))
{
// 事件返回true时不继续执行其余事件
return true;
}
}
return false;
}
return true;
} | [
"protected",
"function",
"trigger",
"(",
"$",
"event",
",",
"$",
"params",
"=",
"array",
"(",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"yurunEvents",
"[",
"$",
"event",
"]",
")",
")",
"{",
"$",
"args",
"=",
"func_get_args",
"(",
")",
";",
"array_shift",
"(",
"$",
"args",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"yurunEvents",
"[",
"$",
"event",
"]",
"as",
"$",
"key",
"=>",
"$",
"item",
")",
"{",
"if",
"(",
"true",
"===",
"$",
"item",
"[",
"'once'",
"]",
")",
"{",
"unset",
"(",
"$",
"this",
"->",
"yurunEvents",
"[",
"$",
"event",
"]",
"[",
"$",
"key",
"]",
")",
";",
"}",
"if",
"(",
"true",
"===",
"call_user_func_array",
"(",
"$",
"item",
"[",
"'callback'",
"]",
",",
"$",
"args",
")",
")",
"{",
"// 事件返回true时不继续执行其余事件",
"return",
"true",
";",
"}",
"}",
"return",
"false",
";",
"}",
"return",
"true",
";",
"}"
] | 触发事件
@param name $event 事件名称
@param array $params 参数
@return mixed | [
"触发事件"
] | train | https://github.com/Yurunsoft/YurunEvent/blob/7957f7d048ac0614f45e279e2b54d72ced67867c/Src/ClassEvent.php#L66-L87 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_insert.php | ezcQueryInsert.insertInto | public function insertInto( $table )
{
$table = $this->getIdentifier( $table );
$table = $this->getPrefixedTableNames($table);
$this->table = $table;
return $this;
} | php | public function insertInto( $table )
{
$table = $this->getIdentifier( $table );
$table = $this->getPrefixedTableNames($table);
$this->table = $table;
return $this;
} | [
"public",
"function",
"insertInto",
"(",
"$",
"table",
")",
"{",
"$",
"table",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"table",
")",
";",
"$",
"table",
"=",
"$",
"this",
"->",
"getPrefixedTableNames",
"(",
"$",
"table",
")",
";",
"$",
"this",
"->",
"table",
"=",
"$",
"table",
";",
"return",
"$",
"this",
";",
"}"
] | Opens the query and sets the target table to $table.
insertInto() returns a pointer to $this.
@param string $table
@return ezcQueryInsert | [
"Opens",
"the",
"query",
"and",
"sets",
"the",
"target",
"table",
"to",
"$table",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_insert.php#L78-L84 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_insert.php | ezcQueryInsert.set | public function set( $column, $expression )
{
$column = $this->getIdentifier( $column );
$expression = $this->getIdentifier( $expression );
if ( $this->db->getName() == 'oracle' )
{
// This is "quick fix" for the case of setting sequence value in Oracle.
// Assume that set( 'columnName', "nextval('sequenceName')") was called.
// Converting sequence SQL "nextval('sequenceName')" that valid for PostgreSQL
// to "sequenceName.nextval" that valid for Oracle.
if ( preg_match( "/nextval\('(.*)'\)/", $expression, $matches ) )
{
$sequenceName = $matches[1];
$expression = $sequenceName.'.nextval';
$this->values[$column] = $expression;
return $this;
}
}
$this->values[$column] = $expression;
return $this;
} | php | public function set( $column, $expression )
{
$column = $this->getIdentifier( $column );
$expression = $this->getIdentifier( $expression );
if ( $this->db->getName() == 'oracle' )
{
// This is "quick fix" for the case of setting sequence value in Oracle.
// Assume that set( 'columnName', "nextval('sequenceName')") was called.
// Converting sequence SQL "nextval('sequenceName')" that valid for PostgreSQL
// to "sequenceName.nextval" that valid for Oracle.
if ( preg_match( "/nextval\('(.*)'\)/", $expression, $matches ) )
{
$sequenceName = $matches[1];
$expression = $sequenceName.'.nextval';
$this->values[$column] = $expression;
return $this;
}
}
$this->values[$column] = $expression;
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"column",
",",
"$",
"expression",
")",
"{",
"$",
"column",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"column",
")",
";",
"$",
"expression",
"=",
"$",
"this",
"->",
"getIdentifier",
"(",
"$",
"expression",
")",
";",
"if",
"(",
"$",
"this",
"->",
"db",
"->",
"getName",
"(",
")",
"==",
"'oracle'",
")",
"{",
"// This is \"quick fix\" for the case of setting sequence value in Oracle.",
"// Assume that set( 'columnName', \"nextval('sequenceName')\") was called.",
"// Converting sequence SQL \"nextval('sequenceName')\" that valid for PostgreSQL",
"// to \"sequenceName.nextval\" that valid for Oracle.",
"if",
"(",
"preg_match",
"(",
"\"/nextval\\('(.*)'\\)/\"",
",",
"$",
"expression",
",",
"$",
"matches",
")",
")",
"{",
"$",
"sequenceName",
"=",
"$",
"matches",
"[",
"1",
"]",
";",
"$",
"expression",
"=",
"$",
"sequenceName",
".",
"'.nextval'",
";",
"$",
"this",
"->",
"values",
"[",
"$",
"column",
"]",
"=",
"$",
"expression",
";",
"return",
"$",
"this",
";",
"}",
"}",
"$",
"this",
"->",
"values",
"[",
"$",
"column",
"]",
"=",
"$",
"expression",
";",
"return",
"$",
"this",
";",
"}"
] | The insert query will set the column $column to the value $expression.
set() returns a pointer to $this.
@param string $column
@param string $expression
@return ezcQueryInsert | [
"The",
"insert",
"query",
"will",
"set",
"the",
"column",
"$column",
"to",
"the",
"value",
"$expression",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_insert.php#L95-L119 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_insert.php | ezcQueryInsert.getQuery | public function getQuery()
{
if ( $this->table == null || empty( $this->values ) )
{
$problem = $this->table == null ? 'table' : 'values';
throw new ezcQueryInvalidException( "INSERT", "No " . $problem . " set." );
}
$query = "INSERT INTO {$this->table}";
$columns = implode( ', ', array_keys( $this->values ) );
$values = implode( ', ', array_values( $this->values ) );
$query .= " ( {$columns} ) VALUES ( {$values} )";
return $query;
} | php | public function getQuery()
{
if ( $this->table == null || empty( $this->values ) )
{
$problem = $this->table == null ? 'table' : 'values';
throw new ezcQueryInvalidException( "INSERT", "No " . $problem . " set." );
}
$query = "INSERT INTO {$this->table}";
$columns = implode( ', ', array_keys( $this->values ) );
$values = implode( ', ', array_values( $this->values ) );
$query .= " ( {$columns} ) VALUES ( {$values} )";
return $query;
} | [
"public",
"function",
"getQuery",
"(",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"table",
"==",
"null",
"||",
"empty",
"(",
"$",
"this",
"->",
"values",
")",
")",
"{",
"$",
"problem",
"=",
"$",
"this",
"->",
"table",
"==",
"null",
"?",
"'table'",
":",
"'values'",
";",
"throw",
"new",
"ezcQueryInvalidException",
"(",
"\"INSERT\"",
",",
"\"No \"",
".",
"$",
"problem",
".",
"\" set.\"",
")",
";",
"}",
"$",
"query",
"=",
"\"INSERT INTO {$this->table}\"",
";",
"$",
"columns",
"=",
"implode",
"(",
"', '",
",",
"array_keys",
"(",
"$",
"this",
"->",
"values",
")",
")",
";",
"$",
"values",
"=",
"implode",
"(",
"', '",
",",
"array_values",
"(",
"$",
"this",
"->",
"values",
")",
")",
";",
"$",
"query",
".=",
"\" ( {$columns} ) VALUES ( {$values} )\"",
";",
"return",
"$",
"query",
";",
"}"
] | Returns the query string for this query object.
@throws ezcQueryInvalidException if no table or no values have been set.
@return string | [
"Returns",
"the",
"query",
"string",
"for",
"this",
"query",
"object",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Database/src/sqlabstraction/query_insert.php#L127-L139 |
mothership-ec/composer | src/Composer/EventDispatcher/EventDispatcher.php | EventDispatcher.dispatch | public function dispatch($eventName, Event $event = null)
{
if (null == $event) {
$event = new Event($eventName);
}
return $this->doDispatch($event);
} | php | public function dispatch($eventName, Event $event = null)
{
if (null == $event) {
$event = new Event($eventName);
}
return $this->doDispatch($event);
} | [
"public",
"function",
"dispatch",
"(",
"$",
"eventName",
",",
"Event",
"$",
"event",
"=",
"null",
")",
"{",
"if",
"(",
"null",
"==",
"$",
"event",
")",
"{",
"$",
"event",
"=",
"new",
"Event",
"(",
"$",
"eventName",
")",
";",
"}",
"return",
"$",
"this",
"->",
"doDispatch",
"(",
"$",
"event",
")",
";",
"}"
] | Dispatch an event
@param string $eventName An event name
@param Event $event
@return int return code of the executed script if any, for php scripts a false return
value is changed to 1, anything else to 0 | [
"Dispatch",
"an",
"event"
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/EventDispatcher/EventDispatcher.php#L70-L77 |
mothership-ec/composer | src/Composer/EventDispatcher/EventDispatcher.php | EventDispatcher.doDispatch | protected function doDispatch(Event $event)
{
$listeners = $this->getListeners($event);
$return = 0;
foreach ($listeners as $callable) {
if (!is_string($callable) && is_callable($callable)) {
$event = $this->checkListenerExpectedEvent($callable, $event);
$return = false === call_user_func($callable, $event) ? 1 : 0;
} elseif ($this->isPhpScript($callable)) {
$className = substr($callable, 0, strpos($callable, '::'));
$methodName = substr($callable, strpos($callable, '::') + 2);
if (!class_exists($className)) {
$this->io->writeError('<warning>Class '.$className.' is not autoloadable, can not call '.$event->getName().' script</warning>');
continue;
}
if (!is_callable($callable)) {
$this->io->writeError('<warning>Method '.$callable.' is not callable, can not call '.$event->getName().' script</warning>');
continue;
}
try {
$return = false === $this->executeEventPhpScript($className, $methodName, $event) ? 1 : 0;
} catch (\Exception $e) {
$message = "Script %s handling the %s event terminated with an exception";
$this->io->writeError('<error>'.sprintf($message, $callable, $event->getName()).'</error>');
throw $e;
}
} else {
$args = implode(' ', array_map(array('Composer\Util\ProcessExecutor','escape'), $event->getArguments()));
if (0 !== ($exitCode = $this->process->execute($callable . ($args === '' ? '' : ' '.$args)))) {
$this->io->writeError(sprintf('<error>Script %s handling the %s event returned with an error</error>', $callable, $event->getName()));
throw new \RuntimeException('Error Output: '.$this->process->getErrorOutput(), $exitCode);
}
}
if ($event->isPropagationStopped()) {
break;
}
}
return $return;
} | php | protected function doDispatch(Event $event)
{
$listeners = $this->getListeners($event);
$return = 0;
foreach ($listeners as $callable) {
if (!is_string($callable) && is_callable($callable)) {
$event = $this->checkListenerExpectedEvent($callable, $event);
$return = false === call_user_func($callable, $event) ? 1 : 0;
} elseif ($this->isPhpScript($callable)) {
$className = substr($callable, 0, strpos($callable, '::'));
$methodName = substr($callable, strpos($callable, '::') + 2);
if (!class_exists($className)) {
$this->io->writeError('<warning>Class '.$className.' is not autoloadable, can not call '.$event->getName().' script</warning>');
continue;
}
if (!is_callable($callable)) {
$this->io->writeError('<warning>Method '.$callable.' is not callable, can not call '.$event->getName().' script</warning>');
continue;
}
try {
$return = false === $this->executeEventPhpScript($className, $methodName, $event) ? 1 : 0;
} catch (\Exception $e) {
$message = "Script %s handling the %s event terminated with an exception";
$this->io->writeError('<error>'.sprintf($message, $callable, $event->getName()).'</error>');
throw $e;
}
} else {
$args = implode(' ', array_map(array('Composer\Util\ProcessExecutor','escape'), $event->getArguments()));
if (0 !== ($exitCode = $this->process->execute($callable . ($args === '' ? '' : ' '.$args)))) {
$this->io->writeError(sprintf('<error>Script %s handling the %s event returned with an error</error>', $callable, $event->getName()));
throw new \RuntimeException('Error Output: '.$this->process->getErrorOutput(), $exitCode);
}
}
if ($event->isPropagationStopped()) {
break;
}
}
return $return;
} | [
"protected",
"function",
"doDispatch",
"(",
"Event",
"$",
"event",
")",
"{",
"$",
"listeners",
"=",
"$",
"this",
"->",
"getListeners",
"(",
"$",
"event",
")",
";",
"$",
"return",
"=",
"0",
";",
"foreach",
"(",
"$",
"listeners",
"as",
"$",
"callable",
")",
"{",
"if",
"(",
"!",
"is_string",
"(",
"$",
"callable",
")",
"&&",
"is_callable",
"(",
"$",
"callable",
")",
")",
"{",
"$",
"event",
"=",
"$",
"this",
"->",
"checkListenerExpectedEvent",
"(",
"$",
"callable",
",",
"$",
"event",
")",
";",
"$",
"return",
"=",
"false",
"===",
"call_user_func",
"(",
"$",
"callable",
",",
"$",
"event",
")",
"?",
"1",
":",
"0",
";",
"}",
"elseif",
"(",
"$",
"this",
"->",
"isPhpScript",
"(",
"$",
"callable",
")",
")",
"{",
"$",
"className",
"=",
"substr",
"(",
"$",
"callable",
",",
"0",
",",
"strpos",
"(",
"$",
"callable",
",",
"'::'",
")",
")",
";",
"$",
"methodName",
"=",
"substr",
"(",
"$",
"callable",
",",
"strpos",
"(",
"$",
"callable",
",",
"'::'",
")",
"+",
"2",
")",
";",
"if",
"(",
"!",
"class_exists",
"(",
"$",
"className",
")",
")",
"{",
"$",
"this",
"->",
"io",
"->",
"writeError",
"(",
"'<warning>Class '",
".",
"$",
"className",
".",
"' is not autoloadable, can not call '",
".",
"$",
"event",
"->",
"getName",
"(",
")",
".",
"' script</warning>'",
")",
";",
"continue",
";",
"}",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"callable",
")",
")",
"{",
"$",
"this",
"->",
"io",
"->",
"writeError",
"(",
"'<warning>Method '",
".",
"$",
"callable",
".",
"' is not callable, can not call '",
".",
"$",
"event",
"->",
"getName",
"(",
")",
".",
"' script</warning>'",
")",
";",
"continue",
";",
"}",
"try",
"{",
"$",
"return",
"=",
"false",
"===",
"$",
"this",
"->",
"executeEventPhpScript",
"(",
"$",
"className",
",",
"$",
"methodName",
",",
"$",
"event",
")",
"?",
"1",
":",
"0",
";",
"}",
"catch",
"(",
"\\",
"Exception",
"$",
"e",
")",
"{",
"$",
"message",
"=",
"\"Script %s handling the %s event terminated with an exception\"",
";",
"$",
"this",
"->",
"io",
"->",
"writeError",
"(",
"'<error>'",
".",
"sprintf",
"(",
"$",
"message",
",",
"$",
"callable",
",",
"$",
"event",
"->",
"getName",
"(",
")",
")",
".",
"'</error>'",
")",
";",
"throw",
"$",
"e",
";",
"}",
"}",
"else",
"{",
"$",
"args",
"=",
"implode",
"(",
"' '",
",",
"array_map",
"(",
"array",
"(",
"'Composer\\Util\\ProcessExecutor'",
",",
"'escape'",
")",
",",
"$",
"event",
"->",
"getArguments",
"(",
")",
")",
")",
";",
"if",
"(",
"0",
"!==",
"(",
"$",
"exitCode",
"=",
"$",
"this",
"->",
"process",
"->",
"execute",
"(",
"$",
"callable",
".",
"(",
"$",
"args",
"===",
"''",
"?",
"''",
":",
"' '",
".",
"$",
"args",
")",
")",
")",
")",
"{",
"$",
"this",
"->",
"io",
"->",
"writeError",
"(",
"sprintf",
"(",
"'<error>Script %s handling the %s event returned with an error</error>'",
",",
"$",
"callable",
",",
"$",
"event",
"->",
"getName",
"(",
")",
")",
")",
";",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"'Error Output: '",
".",
"$",
"this",
"->",
"process",
"->",
"getErrorOutput",
"(",
")",
",",
"$",
"exitCode",
")",
";",
"}",
"}",
"if",
"(",
"$",
"event",
"->",
"isPropagationStopped",
"(",
")",
")",
"{",
"break",
";",
"}",
"}",
"return",
"$",
"return",
";",
"}"
] | Triggers the listeners of an event.
@param Event $event The event object to pass to the event handlers/listeners.
@param string $additionalArgs
@return int return code of the executed script if any, for php scripts a false return
value is changed to 1, anything else to 0
@throws \RuntimeException
@throws \Exception | [
"Triggers",
"the",
"listeners",
"of",
"an",
"event",
"."
] | train | https://github.com/mothership-ec/composer/blob/fa6ad031a939d8d33b211e428fdbdd28cfce238c/src/Composer/EventDispatcher/EventDispatcher.php#L143-L187 |
michaelcooke/laravel-eseye | src/LaravelEseyeServiceProvider.php | LaravelEseyeServiceProvider.register | public function register()
{
$this->mergeConfigurations();
$this->app->singleton('eseye', function($app) {
$authentication = new EsiAuthentication([
'client_id' => config('eseye.client_id'),
'secret' => config('eseye.secret_key'),
'refresh_token' => config('eseye.refresh_token'),
]);
return new Eseye($authentication);
});
} | php | public function register()
{
$this->mergeConfigurations();
$this->app->singleton('eseye', function($app) {
$authentication = new EsiAuthentication([
'client_id' => config('eseye.client_id'),
'secret' => config('eseye.secret_key'),
'refresh_token' => config('eseye.refresh_token'),
]);
return new Eseye($authentication);
});
} | [
"public",
"function",
"register",
"(",
")",
"{",
"$",
"this",
"->",
"mergeConfigurations",
"(",
")",
";",
"$",
"this",
"->",
"app",
"->",
"singleton",
"(",
"'eseye'",
",",
"function",
"(",
"$",
"app",
")",
"{",
"$",
"authentication",
"=",
"new",
"EsiAuthentication",
"(",
"[",
"'client_id'",
"=>",
"config",
"(",
"'eseye.client_id'",
")",
",",
"'secret'",
"=>",
"config",
"(",
"'eseye.secret_key'",
")",
",",
"'refresh_token'",
"=>",
"config",
"(",
"'eseye.refresh_token'",
")",
",",
"]",
")",
";",
"return",
"new",
"Eseye",
"(",
"$",
"authentication",
")",
";",
"}",
")",
";",
"}"
] | Register bindings in the container.
@return void | [
"Register",
"bindings",
"in",
"the",
"container",
"."
] | train | https://github.com/michaelcooke/laravel-eseye/blob/f009b8fe85c5ac9b6e023508a17bfc07fec607bf/src/LaravelEseyeServiceProvider.php#L26-L39 |
unclecheese/silverstripe-blubber | code/Outputter.php | Outputter.format | public static function format($text) {
$text = preg_replace_callback('/<b>(.+?)<\/b>/', function($matches) {
return SS_Cli::text($matches[1], null, null, true);
}, $text);
$text = preg_replace_callback('/<success>(.+?)<\/success>/', function($matches) {
return SS_Cli::text($matches[1], 'green', null, true);
}, $text);
$text = preg_replace_callback('/<error>(.+?)<\/error>/', function($matches) {
return SS_Cli::text($matches[1], 'red', null, true);
}, $text);
$text = preg_replace_callback('/<caution>(.+?)<\/caution>/', function($matches) {
return SS_Cli::text($matches[1], 'yellow', null, true);
}, $text);
$text = preg_replace_callback('/<info>(.+?)<\/info>/', function($matches) {
return SS_Cli::text($matches[1], 'cyan', null, true);
}, $text);
return $text;
} | php | public static function format($text) {
$text = preg_replace_callback('/<b>(.+?)<\/b>/', function($matches) {
return SS_Cli::text($matches[1], null, null, true);
}, $text);
$text = preg_replace_callback('/<success>(.+?)<\/success>/', function($matches) {
return SS_Cli::text($matches[1], 'green', null, true);
}, $text);
$text = preg_replace_callback('/<error>(.+?)<\/error>/', function($matches) {
return SS_Cli::text($matches[1], 'red', null, true);
}, $text);
$text = preg_replace_callback('/<caution>(.+?)<\/caution>/', function($matches) {
return SS_Cli::text($matches[1], 'yellow', null, true);
}, $text);
$text = preg_replace_callback('/<info>(.+?)<\/info>/', function($matches) {
return SS_Cli::text($matches[1], 'cyan', null, true);
}, $text);
return $text;
} | [
"public",
"static",
"function",
"format",
"(",
"$",
"text",
")",
"{",
"$",
"text",
"=",
"preg_replace_callback",
"(",
"'/<b>(.+?)<\\/b>/'",
",",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"SS_Cli",
"::",
"text",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"null",
",",
"null",
",",
"true",
")",
";",
"}",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace_callback",
"(",
"'/<success>(.+?)<\\/success>/'",
",",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"SS_Cli",
"::",
"text",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"'green'",
",",
"null",
",",
"true",
")",
";",
"}",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace_callback",
"(",
"'/<error>(.+?)<\\/error>/'",
",",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"SS_Cli",
"::",
"text",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"'red'",
",",
"null",
",",
"true",
")",
";",
"}",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace_callback",
"(",
"'/<caution>(.+?)<\\/caution>/'",
",",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"SS_Cli",
"::",
"text",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"'yellow'",
",",
"null",
",",
"true",
")",
";",
"}",
",",
"$",
"text",
")",
";",
"$",
"text",
"=",
"preg_replace_callback",
"(",
"'/<info>(.+?)<\\/info>/'",
",",
"function",
"(",
"$",
"matches",
")",
"{",
"return",
"SS_Cli",
"::",
"text",
"(",
"$",
"matches",
"[",
"1",
"]",
",",
"'cyan'",
",",
"null",
",",
"true",
")",
";",
"}",
",",
"$",
"text",
")",
";",
"return",
"$",
"text",
";",
"}"
] | Formats simple html-like markup into coloured text
Supports:
- <b>bold text</b>
- <success>Green text</success>
- <error>Red text</error>
- <caution>Yellow text</caution>
- <info>Cyan text</info>
@param string $text
@return string | [
"Formats",
"simple",
"html",
"-",
"like",
"markup",
"into",
"coloured",
"text",
"Supports",
":",
"-",
"<b",
">",
"bold",
"text<",
"/",
"b",
">",
"-",
"<success",
">",
"Green",
"text<",
"/",
"success",
">",
"-",
"<error",
">",
"Red",
"text<",
"/",
"error",
">",
"-",
"<caution",
">",
"Yellow",
"text<",
"/",
"caution",
">",
"-",
"<info",
">",
"Cyan",
"text<",
"/",
"info",
">"
] | train | https://github.com/unclecheese/silverstripe-blubber/blob/f2549bd5eddeb0ca0303a3c09be4a8136fcc6661/code/Outputter.php#L30-L53 |
unclecheese/silverstripe-blubber | code/Outputter.php | Outputter.ask | public function ask($question, $weight = "y") {
$question = self::format($question);
$y = $weight == 'y' ? 'Y' : 'y';
$n = $weight == 'n' ? 'N' : 'n';
$answer = $this->prompt("$question [$y/$n]");
$line = trim(strtolower($answer));
if(empty($line)) {
$line = $weight;
}
return in_array($line, array('y','yes'));
} | php | public function ask($question, $weight = "y") {
$question = self::format($question);
$y = $weight == 'y' ? 'Y' : 'y';
$n = $weight == 'n' ? 'N' : 'n';
$answer = $this->prompt("$question [$y/$n]");
$line = trim(strtolower($answer));
if(empty($line)) {
$line = $weight;
}
return in_array($line, array('y','yes'));
} | [
"public",
"function",
"ask",
"(",
"$",
"question",
",",
"$",
"weight",
"=",
"\"y\"",
")",
"{",
"$",
"question",
"=",
"self",
"::",
"format",
"(",
"$",
"question",
")",
";",
"$",
"y",
"=",
"$",
"weight",
"==",
"'y'",
"?",
"'Y'",
":",
"'y'",
";",
"$",
"n",
"=",
"$",
"weight",
"==",
"'n'",
"?",
"'N'",
":",
"'n'",
";",
"$",
"answer",
"=",
"$",
"this",
"->",
"prompt",
"(",
"\"$question [$y/$n]\"",
")",
";",
"$",
"line",
"=",
"trim",
"(",
"strtolower",
"(",
"$",
"answer",
")",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"line",
")",
")",
"{",
"$",
"line",
"=",
"$",
"weight",
";",
"}",
"return",
"in_array",
"(",
"$",
"line",
",",
"array",
"(",
"'y'",
",",
"'yes'",
")",
")",
";",
"}"
] | Asks the user a question. If a 'y' value is entered, returns true
@param string $question
@param string $weight Either 'y' or 'n' can have the default value (on enter key)
@return boolean | [
"Asks",
"the",
"user",
"a",
"question",
".",
"If",
"a",
"y",
"value",
"is",
"entered",
"returns",
"true"
] | train | https://github.com/unclecheese/silverstripe-blubber/blob/f2549bd5eddeb0ca0303a3c09be4a8136fcc6661/code/Outputter.php#L79-L91 |
unclecheese/silverstripe-blubber | code/Outputter.php | Outputter.prompt | public function prompt($question) {
$question = self::format($question);
$this->write("$question: ");
$handle = fopen("php://stdin","r");
return fgets($handle);
} | php | public function prompt($question) {
$question = self::format($question);
$this->write("$question: ");
$handle = fopen("php://stdin","r");
return fgets($handle);
} | [
"public",
"function",
"prompt",
"(",
"$",
"question",
")",
"{",
"$",
"question",
"=",
"self",
"::",
"format",
"(",
"$",
"question",
")",
";",
"$",
"this",
"->",
"write",
"(",
"\"$question: \"",
")",
";",
"$",
"handle",
"=",
"fopen",
"(",
"\"php://stdin\"",
",",
"\"r\"",
")",
";",
"return",
"fgets",
"(",
"$",
"handle",
")",
";",
"}"
] | Prompts the user for input
@param string $question
@return string | [
"Prompts",
"the",
"user",
"for",
"input"
] | train | https://github.com/unclecheese/silverstripe-blubber/blob/f2549bd5eddeb0ca0303a3c09be4a8136fcc6661/code/Outputter.php#L99-L105 |
unclecheese/silverstripe-blubber | code/Outputter.php | Outputter.updateProgress | public function updateProgress($text) {
$text = self::format($text);
if($this->progressValue) {
$len = strlen($this->progressValue);
fwrite(STDOUT, "\033[{$len}D");
}
$this->progressValue = $text;
fwrite(STDOUT, $this->progressValue);
} | php | public function updateProgress($text) {
$text = self::format($text);
if($this->progressValue) {
$len = strlen($this->progressValue);
fwrite(STDOUT, "\033[{$len}D");
}
$this->progressValue = $text;
fwrite(STDOUT, $this->progressValue);
} | [
"public",
"function",
"updateProgress",
"(",
"$",
"text",
")",
"{",
"$",
"text",
"=",
"self",
"::",
"format",
"(",
"$",
"text",
")",
";",
"if",
"(",
"$",
"this",
"->",
"progressValue",
")",
"{",
"$",
"len",
"=",
"strlen",
"(",
"$",
"this",
"->",
"progressValue",
")",
";",
"fwrite",
"(",
"STDOUT",
",",
"\"\\033[{$len}D\"",
")",
";",
"}",
"$",
"this",
"->",
"progressValue",
"=",
"$",
"text",
";",
"fwrite",
"(",
"STDOUT",
",",
"$",
"this",
"->",
"progressValue",
")",
";",
"}"
] | Updates the output with new text
@param string $text | [
"Updates",
"the",
"output",
"with",
"new",
"text"
] | train | https://github.com/unclecheese/silverstripe-blubber/blob/f2549bd5eddeb0ca0303a3c09be4a8136fcc6661/code/Outputter.php#L112-L121 |
gedex/php-janrain-api | lib/Janrain/Api/Engage/ConfigureRP.php | ConfigureRP.setBackplaneProperties | public function setBackplaneProperties(array $params)
{
if (!isset($params['server'])) {
throw new MissingArgumentException('server');
}
if (!isset($params['bus'])) {
throw new MissingArgumentException('bus');
}
return $this->post('set_backplane_properties', $params);
} | php | public function setBackplaneProperties(array $params)
{
if (!isset($params['server'])) {
throw new MissingArgumentException('server');
}
if (!isset($params['bus'])) {
throw new MissingArgumentException('bus');
}
return $this->post('set_backplane_properties', $params);
} | [
"public",
"function",
"setBackplaneProperties",
"(",
"array",
"$",
"params",
")",
"{",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'server'",
"]",
")",
")",
"{",
"throw",
"new",
"MissingArgumentException",
"(",
"'server'",
")",
";",
"}",
"if",
"(",
"!",
"isset",
"(",
"$",
"params",
"[",
"'bus'",
"]",
")",
")",
"{",
"throw",
"new",
"MissingArgumentException",
"(",
"'bus'",
")",
";",
"}",
"return",
"$",
"this",
"->",
"post",
"(",
"'set_backplane_properties'",
",",
"$",
"params",
")",
";",
"}"
] | Configures Backplane server used to communicate with all of the Backplane
enabled widgets on a page.
@param array $params
@link http://developers.janrain.com/documentation/api-methods/engage/configure-rp/set_backplane_properties/ | [
"Configures",
"Backplane",
"server",
"used",
"to",
"communicate",
"with",
"all",
"of",
"the",
"Backplane",
"enabled",
"widgets",
"on",
"a",
"page",
"."
] | train | https://github.com/gedex/php-janrain-api/blob/6283f68454e0ad5211ac620f1d337df38cd49597/lib/Janrain/Api/Engage/ConfigureRP.php#L64-L75 |
dave-redfern/laravel-doctrine-entity-audit | src/Support/TableConfiguration.php | TableConfiguration.getTableName | public function getTableName(ClassMetadataInfo $metadata)
{
$tableName = $metadata->getTableName();
//## Fix for doctrine/orm >= 2.5
if (method_exists($metadata, 'getSchemaName') && $metadata->getSchemaName()) {
$tableName = $metadata->getSchemaName() . '.' . $tableName;
}
return $this->getTablePrefix() . $tableName . $this->getTableSuffix();
} | php | public function getTableName(ClassMetadataInfo $metadata)
{
$tableName = $metadata->getTableName();
//## Fix for doctrine/orm >= 2.5
if (method_exists($metadata, 'getSchemaName') && $metadata->getSchemaName()) {
$tableName = $metadata->getSchemaName() . '.' . $tableName;
}
return $this->getTablePrefix() . $tableName . $this->getTableSuffix();
} | [
"public",
"function",
"getTableName",
"(",
"ClassMetadataInfo",
"$",
"metadata",
")",
"{",
"$",
"tableName",
"=",
"$",
"metadata",
"->",
"getTableName",
"(",
")",
";",
"//## Fix for doctrine/orm >= 2.5",
"if",
"(",
"method_exists",
"(",
"$",
"metadata",
",",
"'getSchemaName'",
")",
"&&",
"$",
"metadata",
"->",
"getSchemaName",
"(",
")",
")",
"{",
"$",
"tableName",
"=",
"$",
"metadata",
"->",
"getSchemaName",
"(",
")",
".",
"'.'",
".",
"$",
"tableName",
";",
"}",
"return",
"$",
"this",
"->",
"getTablePrefix",
"(",
")",
".",
"$",
"tableName",
".",
"$",
"this",
"->",
"getTableSuffix",
"(",
")",
";",
"}"
] | @param ClassMetadataInfo $metadata
@return string | [
"@param",
"ClassMetadataInfo",
"$metadata"
] | train | https://github.com/dave-redfern/laravel-doctrine-entity-audit/blob/ab79e305fe512ceefbc14d585fefe0a40cf911ab/src/Support/TableConfiguration.php#L74-L84 |
NuclearCMS/Hierarchy | src/Builders/FormBuilder.php | FormBuilder.build | public function build($name, Collection $fields = null)
{
$path = $this->getClassFilePath($name);
$contents = view('_hierarchy::entities.form', [
'name' => $this->getClassName($name),
'fields' => $fields ?: []
])->render();
$this->write($path, $contents);
} | php | public function build($name, Collection $fields = null)
{
$path = $this->getClassFilePath($name);
$contents = view('_hierarchy::entities.form', [
'name' => $this->getClassName($name),
'fields' => $fields ?: []
])->render();
$this->write($path, $contents);
} | [
"public",
"function",
"build",
"(",
"$",
"name",
",",
"Collection",
"$",
"fields",
"=",
"null",
")",
"{",
"$",
"path",
"=",
"$",
"this",
"->",
"getClassFilePath",
"(",
"$",
"name",
")",
";",
"$",
"contents",
"=",
"view",
"(",
"'_hierarchy::entities.form'",
",",
"[",
"'name'",
"=>",
"$",
"this",
"->",
"getClassName",
"(",
"$",
"name",
")",
",",
"'fields'",
"=>",
"$",
"fields",
"?",
":",
"[",
"]",
"]",
")",
"->",
"render",
"(",
")",
";",
"$",
"this",
"->",
"write",
"(",
"$",
"path",
",",
"$",
"contents",
")",
";",
"}"
] | Builds a source form
@param string $name
@param Collection|null $fields | [
"Builds",
"a",
"source",
"form"
] | train | https://github.com/NuclearCMS/Hierarchy/blob/535171c5e2db72265313fd2110aec8456e46f459/src/Builders/FormBuilder.php#L20-L30 |
highday/glitter | src/Http/Middleware/Office/ShareVariables.php | ShareVariables.handle | public function handle($request, Closure $next)
{
$me = $this->auth->guard('member')->user();
$store = $me->activeStore;
$extends = 'glitter.office::layouts.guest';
$this->view->share(compact('me', 'store', 'extends'));
return $next($request);
} | php | public function handle($request, Closure $next)
{
$me = $this->auth->guard('member')->user();
$store = $me->activeStore;
$extends = 'glitter.office::layouts.guest';
$this->view->share(compact('me', 'store', 'extends'));
return $next($request);
} | [
"public",
"function",
"handle",
"(",
"$",
"request",
",",
"Closure",
"$",
"next",
")",
"{",
"$",
"me",
"=",
"$",
"this",
"->",
"auth",
"->",
"guard",
"(",
"'member'",
")",
"->",
"user",
"(",
")",
";",
"$",
"store",
"=",
"$",
"me",
"->",
"activeStore",
";",
"$",
"extends",
"=",
"'glitter.office::layouts.guest'",
";",
"$",
"this",
"->",
"view",
"->",
"share",
"(",
"compact",
"(",
"'me'",
",",
"'store'",
",",
"'extends'",
")",
")",
";",
"return",
"$",
"next",
"(",
"$",
"request",
")",
";",
"}"
] | Handle an incoming request.
@param \Illuminate\Http\Request $request
@param \Closure $next
@return mixed | [
"Handle",
"an",
"incoming",
"request",
"."
] | train | https://github.com/highday/glitter/blob/d1c7a227fd2343806bd3ec0314e621ced57dfe66/src/Http/Middleware/Office/ShareVariables.php#L48-L58 |
ekuiter/feature-php | FeaturePhp/File/FileContent.php | FileContent.copy | public function copy($target) {
if (!file_exists(dirname($target)))
if (!mkdir(dirname($target), 0777, true))
return false;
return true;
} | php | public function copy($target) {
if (!file_exists(dirname($target)))
if (!mkdir(dirname($target), 0777, true))
return false;
return true;
} | [
"public",
"function",
"copy",
"(",
"$",
"target",
")",
"{",
"if",
"(",
"!",
"file_exists",
"(",
"dirname",
"(",
"$",
"target",
")",
")",
")",
"if",
"(",
"!",
"mkdir",
"(",
"dirname",
"(",
"$",
"target",
")",
",",
"0777",
",",
"true",
")",
")",
"return",
"false",
";",
"return",
"true",
";",
"}"
] | Copies file's content to the local filesystem.
This is expected to be called only be a {@see \FeaturePhp\Exporter\LocalExporter}.
@param string $target the file target in the filesystem | [
"Copies",
"file",
"s",
"content",
"to",
"the",
"local",
"filesystem",
".",
"This",
"is",
"expected",
"to",
"be",
"called",
"only",
"be",
"a",
"{"
] | train | https://github.com/ekuiter/feature-php/blob/daf4a59098802fedcfd1f1a1d07847fcf2fea7bf/FeaturePhp/File/FileContent.php#L37-L42 |
endorphin-studio/browser-detector-data | src/Storage/FileStorage.php | FileStorage.getFileNames | protected function getFileNames(string $directory = 'default'): array
{
$directoryIterator = $this->getDirectoryIterator($directory);
$files = [];
foreach ($directoryIterator as $file) {
$this->resolveFile($file, $files);
}
return $files;
} | php | protected function getFileNames(string $directory = 'default'): array
{
$directoryIterator = $this->getDirectoryIterator($directory);
$files = [];
foreach ($directoryIterator as $file) {
$this->resolveFile($file, $files);
}
return $files;
} | [
"protected",
"function",
"getFileNames",
"(",
"string",
"$",
"directory",
"=",
"'default'",
")",
":",
"array",
"{",
"$",
"directoryIterator",
"=",
"$",
"this",
"->",
"getDirectoryIterator",
"(",
"$",
"directory",
")",
";",
"$",
"files",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"directoryIterator",
"as",
"$",
"file",
")",
"{",
"$",
"this",
"->",
"resolveFile",
"(",
"$",
"file",
",",
"$",
"files",
")",
";",
"}",
"return",
"$",
"files",
";",
"}"
] | Get list of paths in directory
@param string $directory
@return array | [
"Get",
"list",
"of",
"paths",
"in",
"directory"
] | train | https://github.com/endorphin-studio/browser-detector-data/blob/cb1ace9f52f9677616c89f3b80c5148936d47b82/src/Storage/FileStorage.php#L35-L43 |
endorphin-studio/browser-detector-data | src/Storage/FileStorage.php | FileStorage.resolveFile | private function resolveFile(\DirectoryIterator $file, array &$files)
{
if ($file->isDir() && !$file->isDot()) {
$files = Tools::resolvePath($files, $this->getFileNames());
}
if ($file->isFile() && !$file->isLink() && $file->isReadable()) {
$files = Tools::resolvePath($files, $file->getRealPath());
}
} | php | private function resolveFile(\DirectoryIterator $file, array &$files)
{
if ($file->isDir() && !$file->isDot()) {
$files = Tools::resolvePath($files, $this->getFileNames());
}
if ($file->isFile() && !$file->isLink() && $file->isReadable()) {
$files = Tools::resolvePath($files, $file->getRealPath());
}
} | [
"private",
"function",
"resolveFile",
"(",
"\\",
"DirectoryIterator",
"$",
"file",
",",
"array",
"&",
"$",
"files",
")",
"{",
"if",
"(",
"$",
"file",
"->",
"isDir",
"(",
")",
"&&",
"!",
"$",
"file",
"->",
"isDot",
"(",
")",
")",
"{",
"$",
"files",
"=",
"Tools",
"::",
"resolvePath",
"(",
"$",
"files",
",",
"$",
"this",
"->",
"getFileNames",
"(",
")",
")",
";",
"}",
"if",
"(",
"$",
"file",
"->",
"isFile",
"(",
")",
"&&",
"!",
"$",
"file",
"->",
"isLink",
"(",
")",
"&&",
"$",
"file",
"->",
"isReadable",
"(",
")",
")",
"{",
"$",
"files",
"=",
"Tools",
"::",
"resolvePath",
"(",
"$",
"files",
",",
"$",
"file",
"->",
"getRealPath",
"(",
")",
")",
";",
"}",
"}"
] | Add file to list or scan directory
@param \DirectoryIterator $file
@param array $files | [
"Add",
"file",
"to",
"list",
"or",
"scan",
"directory"
] | train | https://github.com/endorphin-studio/browser-detector-data/blob/cb1ace9f52f9677616c89f3b80c5148936d47b82/src/Storage/FileStorage.php#L50-L59 |
endorphin-studio/browser-detector-data | src/Storage/FileStorage.php | FileStorage.getDirectoryIterator | private function getDirectoryIterator(string $directory): \DirectoryIterator
{
if ($directory === 'default') {
return new \DirectoryIterator($this->dataDirectory);
}
return new \DirectoryIterator($directory);
} | php | private function getDirectoryIterator(string $directory): \DirectoryIterator
{
if ($directory === 'default') {
return new \DirectoryIterator($this->dataDirectory);
}
return new \DirectoryIterator($directory);
} | [
"private",
"function",
"getDirectoryIterator",
"(",
"string",
"$",
"directory",
")",
":",
"\\",
"DirectoryIterator",
"{",
"if",
"(",
"$",
"directory",
"===",
"'default'",
")",
"{",
"return",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"this",
"->",
"dataDirectory",
")",
";",
"}",
"return",
"new",
"\\",
"DirectoryIterator",
"(",
"$",
"directory",
")",
";",
"}"
] | Get Directory Iterator
@param string $directory
@return \DirectoryIterator | [
"Get",
"Directory",
"Iterator"
] | train | https://github.com/endorphin-studio/browser-detector-data/blob/cb1ace9f52f9677616c89f3b80c5148936d47b82/src/Storage/FileStorage.php#L66-L72 |
philiplb/Valdi | src/Valdi/Validator/AbstractDateTimeComparator.php | AbstractDateTimeComparator.getDateTimeFormat | protected function getDateTimeFormat($parameters) {
$format = 'Y-m-d H:i:s';
$parametersCount = count($parameters);
if ($parametersCount > $this->amountOfParameters) {
$format = $parameters[$parametersCount - 1];
}
return $format;
} | php | protected function getDateTimeFormat($parameters) {
$format = 'Y-m-d H:i:s';
$parametersCount = count($parameters);
if ($parametersCount > $this->amountOfParameters) {
$format = $parameters[$parametersCount - 1];
}
return $format;
} | [
"protected",
"function",
"getDateTimeFormat",
"(",
"$",
"parameters",
")",
"{",
"$",
"format",
"=",
"'Y-m-d H:i:s'",
";",
"$",
"parametersCount",
"=",
"count",
"(",
"$",
"parameters",
")",
";",
"if",
"(",
"$",
"parametersCount",
">",
"$",
"this",
"->",
"amountOfParameters",
")",
"{",
"$",
"format",
"=",
"$",
"parameters",
"[",
"$",
"parametersCount",
"-",
"1",
"]",
";",
"}",
"return",
"$",
"format",
";",
"}"
] | Gets a date time format from the parameters if given or a default one.
@param string[] $parameters
the parameters
@return string
the date time format | [
"Gets",
"a",
"date",
"time",
"format",
"from",
"the",
"parameters",
"if",
"given",
"or",
"a",
"default",
"one",
"."
] | train | https://github.com/philiplb/Valdi/blob/9927ec34a2cb00cec705e952d3c2374e2dc3c972/src/Valdi/Validator/AbstractDateTimeComparator.php#L63-L70 |
philiplb/Valdi | src/Valdi/Validator/AbstractDateTimeComparator.php | AbstractDateTimeComparator.getDateTimes | protected function getDateTimes(array $parameters, $format) {
if (!$this->dateTimeParameters) {
return [];
}
$datetimes = [];
for ($i = 0; $i < $this->amountOfParameters; ++$i) {
$datetime = \DateTime::createFromFormat($format, $parameters[$i]);
if ($datetime === false) {
throw new ValidationException('"'.$this->type.'" expects a date of the format "'.$format.'".');
}
$datetimes[] = $datetime;
}
return $datetimes;
} | php | protected function getDateTimes(array $parameters, $format) {
if (!$this->dateTimeParameters) {
return [];
}
$datetimes = [];
for ($i = 0; $i < $this->amountOfParameters; ++$i) {
$datetime = \DateTime::createFromFormat($format, $parameters[$i]);
if ($datetime === false) {
throw new ValidationException('"'.$this->type.'" expects a date of the format "'.$format.'".');
}
$datetimes[] = $datetime;
}
return $datetimes;
} | [
"protected",
"function",
"getDateTimes",
"(",
"array",
"$",
"parameters",
",",
"$",
"format",
")",
"{",
"if",
"(",
"!",
"$",
"this",
"->",
"dateTimeParameters",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"datetimes",
"=",
"[",
"]",
";",
"for",
"(",
"$",
"i",
"=",
"0",
";",
"$",
"i",
"<",
"$",
"this",
"->",
"amountOfParameters",
";",
"++",
"$",
"i",
")",
"{",
"$",
"datetime",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"parameters",
"[",
"$",
"i",
"]",
")",
";",
"if",
"(",
"$",
"datetime",
"===",
"false",
")",
"{",
"throw",
"new",
"ValidationException",
"(",
"'\"'",
".",
"$",
"this",
"->",
"type",
".",
"'\" expects a date of the format \"'",
".",
"$",
"format",
".",
"'\".'",
")",
";",
"}",
"$",
"datetimes",
"[",
"]",
"=",
"$",
"datetime",
";",
"}",
"return",
"$",
"datetimes",
";",
"}"
] | Interprets the given parameters as date times and returns them.
@param array $parameters
the parameters
@param string $format
the date time format
@return \DateTime[]
the date times
@throws ValidationException
thrown if one of the parameters is not a date in the given format | [
"Interprets",
"the",
"given",
"parameters",
"as",
"date",
"times",
"and",
"returns",
"them",
"."
] | train | https://github.com/philiplb/Valdi/blob/9927ec34a2cb00cec705e952d3c2374e2dc3c972/src/Valdi/Validator/AbstractDateTimeComparator.php#L86-L99 |
philiplb/Valdi | src/Valdi/Validator/AbstractDateTimeComparator.php | AbstractDateTimeComparator.isValid | public function isValid($value, array $parameters) {
if (count($parameters) < $this->amountOfParameters) {
throw new ValidationException('"'.$this->type.'" expects at least '.$this->amountOfParameters.' parameter.');
}
if (in_array($value, ['', null], true)) {
return true;
}
$format = $this->getDateTimeFormat($parameters);
$datetimes = $this->getDateTimes($parameters, $format);
$date = \DateTime::createFromFormat($format, $value);
if ($date === false) {
return false;
}
return $this->isValidComparison($date, $datetimes, $parameters);
} | php | public function isValid($value, array $parameters) {
if (count($parameters) < $this->amountOfParameters) {
throw new ValidationException('"'.$this->type.'" expects at least '.$this->amountOfParameters.' parameter.');
}
if (in_array($value, ['', null], true)) {
return true;
}
$format = $this->getDateTimeFormat($parameters);
$datetimes = $this->getDateTimes($parameters, $format);
$date = \DateTime::createFromFormat($format, $value);
if ($date === false) {
return false;
}
return $this->isValidComparison($date, $datetimes, $parameters);
} | [
"public",
"function",
"isValid",
"(",
"$",
"value",
",",
"array",
"$",
"parameters",
")",
"{",
"if",
"(",
"count",
"(",
"$",
"parameters",
")",
"<",
"$",
"this",
"->",
"amountOfParameters",
")",
"{",
"throw",
"new",
"ValidationException",
"(",
"'\"'",
".",
"$",
"this",
"->",
"type",
".",
"'\" expects at least '",
".",
"$",
"this",
"->",
"amountOfParameters",
".",
"' parameter.'",
")",
";",
"}",
"if",
"(",
"in_array",
"(",
"$",
"value",
",",
"[",
"''",
",",
"null",
"]",
",",
"true",
")",
")",
"{",
"return",
"true",
";",
"}",
"$",
"format",
"=",
"$",
"this",
"->",
"getDateTimeFormat",
"(",
"$",
"parameters",
")",
";",
"$",
"datetimes",
"=",
"$",
"this",
"->",
"getDateTimes",
"(",
"$",
"parameters",
",",
"$",
"format",
")",
";",
"$",
"date",
"=",
"\\",
"DateTime",
"::",
"createFromFormat",
"(",
"$",
"format",
",",
"$",
"value",
")",
";",
"if",
"(",
"$",
"date",
"===",
"false",
")",
"{",
"return",
"false",
";",
"}",
"return",
"$",
"this",
"->",
"isValidComparison",
"(",
"$",
"date",
",",
"$",
"datetimes",
",",
"$",
"parameters",
")",
";",
"}"
] | {@inheritdoc} | [
"{"
] | train | https://github.com/philiplb/Valdi/blob/9927ec34a2cb00cec705e952d3c2374e2dc3c972/src/Valdi/Validator/AbstractDateTimeComparator.php#L104-L123 |
maestroprog/saw-php | src/Service/Commander.php | Commander.runSync | public function runSync(AbstractCommand $command, int $timeout): AbstractCommand
{
$started = microtime(true);
$this->send($command);
do {
$this->workDispatcher->work();
} while (!$command->isAccomplished() && (microtime(true) - $started) < $timeout);
return $command;
} | php | public function runSync(AbstractCommand $command, int $timeout): AbstractCommand
{
$started = microtime(true);
$this->send($command);
do {
$this->workDispatcher->work();
} while (!$command->isAccomplished() && (microtime(true) - $started) < $timeout);
return $command;
} | [
"public",
"function",
"runSync",
"(",
"AbstractCommand",
"$",
"command",
",",
"int",
"$",
"timeout",
")",
":",
"AbstractCommand",
"{",
"$",
"started",
"=",
"microtime",
"(",
"true",
")",
";",
"$",
"this",
"->",
"send",
"(",
"$",
"command",
")",
";",
"do",
"{",
"$",
"this",
"->",
"workDispatcher",
"->",
"work",
"(",
")",
";",
"}",
"while",
"(",
"!",
"$",
"command",
"->",
"isAccomplished",
"(",
")",
"&&",
"(",
"microtime",
"(",
"true",
")",
"-",
"$",
"started",
")",
"<",
"$",
"timeout",
")",
";",
"return",
"$",
"command",
";",
"}"
] | Выполняет синхронный запуск команды,
т.е. дожидается результата выполнения команды.
@param AbstractCommand $command
@param int $timeout Время ожидания выполнения команды
@return AbstractCommand
@throws \RuntimeException | [
"Выполняет",
"синхронный",
"запуск",
"команды",
"т",
".",
"е",
".",
"дожидается",
"результата",
"выполнения",
"команды",
"."
] | train | https://github.com/maestroprog/saw-php/blob/159215a4d7a951cca2a9c2eed3e1aa4f5b624cfb/src/Service/Commander.php#L32-L40 |
maestroprog/saw-php | src/Service/Commander.php | Commander.send | private function send(AbstractCommand $command)
{
$cmdId = $this->generateId();
$this->commands->add($cmdId, $command);
if (!$command->getClient()->send($this->serializeCommand($command, $cmdId))) {
throw new \RuntimeException(sprintf('Fail run command "%s".', $command->getCommandName()));
}
} | php | private function send(AbstractCommand $command)
{
$cmdId = $this->generateId();
$this->commands->add($cmdId, $command);
if (!$command->getClient()->send($this->serializeCommand($command, $cmdId))) {
throw new \RuntimeException(sprintf('Fail run command "%s".', $command->getCommandName()));
}
} | [
"private",
"function",
"send",
"(",
"AbstractCommand",
"$",
"command",
")",
"{",
"$",
"cmdId",
"=",
"$",
"this",
"->",
"generateId",
"(",
")",
";",
"$",
"this",
"->",
"commands",
"->",
"add",
"(",
"$",
"cmdId",
",",
"$",
"command",
")",
";",
"if",
"(",
"!",
"$",
"command",
"->",
"getClient",
"(",
")",
"->",
"send",
"(",
"$",
"this",
"->",
"serializeCommand",
"(",
"$",
"command",
",",
"$",
"cmdId",
")",
")",
")",
"{",
"throw",
"new",
"\\",
"RuntimeException",
"(",
"sprintf",
"(",
"'Fail run command \"%s\".'",
",",
"$",
"command",
"->",
"getCommandName",
"(",
")",
")",
")",
";",
"}",
"}"
] | Отправляет клиенту команду на выполнение.
@param AbstractCommand $command
@throws \RuntimeException | [
"Отправляет",
"клиенту",
"команду",
"на",
"выполнение",
"."
] | train | https://github.com/maestroprog/saw-php/blob/159215a4d7a951cca2a9c2eed3e1aa4f5b624cfb/src/Service/Commander.php#L75-L82 |
ouropencode/dachi | src/Model.php | Model.jsonSerialize | public function jsonSerialize() {
$json = array();
foreach(get_object_vars($this) as $var => $val) {
if($val instanceof \DateTime)
$json[$var] = $val->getTimestamp();
else
$json[$var] = $val;
}
return $json;
} | php | public function jsonSerialize() {
$json = array();
foreach(get_object_vars($this) as $var => $val) {
if($val instanceof \DateTime)
$json[$var] = $val->getTimestamp();
else
$json[$var] = $val;
}
return $json;
} | [
"public",
"function",
"jsonSerialize",
"(",
")",
"{",
"$",
"json",
"=",
"array",
"(",
")",
";",
"foreach",
"(",
"get_object_vars",
"(",
"$",
"this",
")",
"as",
"$",
"var",
"=>",
"$",
"val",
")",
"{",
"if",
"(",
"$",
"val",
"instanceof",
"\\",
"DateTime",
")",
"$",
"json",
"[",
"$",
"var",
"]",
"=",
"$",
"val",
"->",
"getTimestamp",
"(",
")",
";",
"else",
"$",
"json",
"[",
"$",
"var",
"]",
"=",
"$",
"val",
";",
"}",
"return",
"$",
"json",
";",
"}"
] | Get a json serialized version of this object.
@return array | [
"Get",
"a",
"json",
"serialized",
"version",
"of",
"this",
"object",
"."
] | train | https://github.com/ouropencode/dachi/blob/a0e1daf269d0345afbb859ce20ef9da6decd7efe/src/Model.php#L18-L29 |
josh-taylor/migrations-generator | src/GenerateCommand.php | GenerateCommand.handle | public function handle()
{
$generator = new Generator(
new Describer($this->db), $this->db
);
foreach ($generator->tables() as $schema) {
$this->callSilent('make:migration:schema', [
'name' => 'create_' . $schema['table'] . '_table',
'--schema' => (new SchemaArgumentBuilder)->create($schema['columns']),
'--model' => false
]);
}
$this->info('Migrations created successfully');
} | php | public function handle()
{
$generator = new Generator(
new Describer($this->db), $this->db
);
foreach ($generator->tables() as $schema) {
$this->callSilent('make:migration:schema', [
'name' => 'create_' . $schema['table'] . '_table',
'--schema' => (new SchemaArgumentBuilder)->create($schema['columns']),
'--model' => false
]);
}
$this->info('Migrations created successfully');
} | [
"public",
"function",
"handle",
"(",
")",
"{",
"$",
"generator",
"=",
"new",
"Generator",
"(",
"new",
"Describer",
"(",
"$",
"this",
"->",
"db",
")",
",",
"$",
"this",
"->",
"db",
")",
";",
"foreach",
"(",
"$",
"generator",
"->",
"tables",
"(",
")",
"as",
"$",
"schema",
")",
"{",
"$",
"this",
"->",
"callSilent",
"(",
"'make:migration:schema'",
",",
"[",
"'name'",
"=>",
"'create_'",
".",
"$",
"schema",
"[",
"'table'",
"]",
".",
"'_table'",
",",
"'--schema'",
"=>",
"(",
"new",
"SchemaArgumentBuilder",
")",
"->",
"create",
"(",
"$",
"schema",
"[",
"'columns'",
"]",
")",
",",
"'--model'",
"=>",
"false",
"]",
")",
";",
"}",
"$",
"this",
"->",
"info",
"(",
"'Migrations created successfully'",
")",
";",
"}"
] | Execute the console command | [
"Execute",
"the",
"console",
"command"
] | train | https://github.com/josh-taylor/migrations-generator/blob/bb6edc78773d11491881f12265a658bf058cb218/src/GenerateCommand.php#L45-L60 |
grozzzny/catalog | components/ItemQuery.php | ItemQuery.category | public function category(Category $category)
{
$this->_category = $category;
$this->joinWith('categories');
$this->andFilterWhere([$category::tableName().'.id' => $this->_category->id]);
return $this;
} | php | public function category(Category $category)
{
$this->_category = $category;
$this->joinWith('categories');
$this->andFilterWhere([$category::tableName().'.id' => $this->_category->id]);
return $this;
} | [
"public",
"function",
"category",
"(",
"Category",
"$",
"category",
")",
"{",
"$",
"this",
"->",
"_category",
"=",
"$",
"category",
";",
"$",
"this",
"->",
"joinWith",
"(",
"'categories'",
")",
";",
"$",
"this",
"->",
"andFilterWhere",
"(",
"[",
"$",
"category",
"::",
"tableName",
"(",
")",
".",
"'.id'",
"=>",
"$",
"this",
"->",
"_category",
"->",
"id",
"]",
")",
";",
"return",
"$",
"this",
";",
"}"
] | Установит категорию. И осуществит поиск элементов определенной категории
@param Category $category
@return $this | [
"Установит",
"категорию",
".",
"И",
"осуществит",
"поиск",
"элементов",
"определенной",
"категории"
] | train | https://github.com/grozzzny/catalog/blob/ff1cac10a5f3a89f3ef2767f9ede6b2d74e1849a/components/ItemQuery.php#L28-L36 |
grozzzny/catalog | components/ItemQuery.php | ItemQuery.whereSearch | public function whereSearch($search)
{
if(!empty($search)){
$this->andFilterWhere([
'OR',
['LIKE', static::getTableNameItem() . '.title', $search],
[static::getTableNameItem() . '.id' => $search],
['LIKE', static::getTableNameItem() . '.description', $search],
]);
}
return $this;
} | php | public function whereSearch($search)
{
if(!empty($search)){
$this->andFilterWhere([
'OR',
['LIKE', static::getTableNameItem() . '.title', $search],
[static::getTableNameItem() . '.id' => $search],
['LIKE', static::getTableNameItem() . '.description', $search],
]);
}
return $this;
} | [
"public",
"function",
"whereSearch",
"(",
"$",
"search",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"search",
")",
")",
"{",
"$",
"this",
"->",
"andFilterWhere",
"(",
"[",
"'OR'",
",",
"[",
"'LIKE'",
",",
"static",
"::",
"getTableNameItem",
"(",
")",
".",
"'.title'",
",",
"$",
"search",
"]",
",",
"[",
"static",
"::",
"getTableNameItem",
"(",
")",
".",
"'.id'",
"=>",
"$",
"search",
"]",
",",
"[",
"'LIKE'",
",",
"static",
"::",
"getTableNameItem",
"(",
")",
".",
"'.description'",
",",
"$",
"search",
"]",
",",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Условия поиска по title и description
@param $search
@return $this | [
"Условия",
"поиска",
"по",
"title",
"и",
"description"
] | train | https://github.com/grozzzny/catalog/blob/ff1cac10a5f3a89f3ef2767f9ede6b2d74e1849a/components/ItemQuery.php#L50-L61 |
grozzzny/catalog | components/ItemQuery.php | ItemQuery.whereRange | public function whereRange(Array $attributes)
{
foreach ($attributes as $attribute => $value){
$from = $value[0];
$to = $value[1];
if(!empty($from) || !empty($to)){
if(!empty($from) && empty($to)){
$this->andFilterWhere(['>=', $attribute, (int)$from]);
} elseif(!empty($to) && empty($from)) {
$this->andFilterWhere(['<=', $attribute, (int)$to]);
} else {
$this->andFilterWhere(['between', $attribute, (int)$from, (int)$to]);
}
}
}
return $this;
} | php | public function whereRange(Array $attributes)
{
foreach ($attributes as $attribute => $value){
$from = $value[0];
$to = $value[1];
if(!empty($from) || !empty($to)){
if(!empty($from) && empty($to)){
$this->andFilterWhere(['>=', $attribute, (int)$from]);
} elseif(!empty($to) && empty($from)) {
$this->andFilterWhere(['<=', $attribute, (int)$to]);
} else {
$this->andFilterWhere(['between', $attribute, (int)$from, (int)$to]);
}
}
}
return $this;
} | [
"public",
"function",
"whereRange",
"(",
"Array",
"$",
"attributes",
")",
"{",
"foreach",
"(",
"$",
"attributes",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"$",
"from",
"=",
"$",
"value",
"[",
"0",
"]",
";",
"$",
"to",
"=",
"$",
"value",
"[",
"1",
"]",
";",
"if",
"(",
"!",
"empty",
"(",
"$",
"from",
")",
"||",
"!",
"empty",
"(",
"$",
"to",
")",
")",
"{",
"if",
"(",
"!",
"empty",
"(",
"$",
"from",
")",
"&&",
"empty",
"(",
"$",
"to",
")",
")",
"{",
"$",
"this",
"->",
"andFilterWhere",
"(",
"[",
"'>='",
",",
"$",
"attribute",
",",
"(",
"int",
")",
"$",
"from",
"]",
")",
";",
"}",
"elseif",
"(",
"!",
"empty",
"(",
"$",
"to",
")",
"&&",
"empty",
"(",
"$",
"from",
")",
")",
"{",
"$",
"this",
"->",
"andFilterWhere",
"(",
"[",
"'<='",
",",
"$",
"attribute",
",",
"(",
"int",
")",
"$",
"to",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"andFilterWhere",
"(",
"[",
"'between'",
",",
"$",
"attribute",
",",
"(",
"int",
")",
"$",
"from",
",",
"(",
"int",
")",
"$",
"to",
"]",
")",
";",
"}",
"}",
"}",
"return",
"$",
"this",
";",
"}"
] | Условия диапазона значений
@param array $attributes
@return $this | [
"Условия",
"диапазона",
"значений"
] | train | https://github.com/grozzzny/catalog/blob/ff1cac10a5f3a89f3ef2767f9ede6b2d74e1849a/components/ItemQuery.php#L68-L85 |
grozzzny/catalog | components/ItemQuery.php | ItemQuery.whereProperties | public function whereProperties($condition)
{
$this->distinct(static::getTableNameItem() . '.id');
$properties = (isset($this->_category)) ? $this->_category->allProperties : [];
$filtersApplied = 0;
$subQuery = Data::find()->select('item_id, COUNT(*) as filter_matched')->groupBy('item_id');
/**
* Если установлена категория и определены свойства
*/
if(!empty($properties)) {
foreach ($properties as $property) {
if ($property->settings->filter_range) {
$value_from = ArrayHelper::getValue($condition, $property->slug . '_from', '');
$value_to = ArrayHelper::getValue($condition, $property->slug . '_to', '');
if (empty($value_from) && empty($value_to)) {
continue;
}
if (!$value_from) {
$additionalCondition = ['<=', 'value', (int)$value_to];
} elseif (!$value_to) {
$additionalCondition = ['>=', 'value', (int)$value_from];
} else {
$additionalCondition = ['between', 'value', (int)$value_from, (int)$value_to];
}
$subQuery->orFilterWhere(['and', ['property_slug' => $property->slug], $additionalCondition]);
$filtersApplied++;
} else {
$value = ArrayHelper::getValue($condition, $property->slug, '');
if ($value == '') continue;
switch ($property->type) {
case Properties::TYPE_DATETIME:
$subQuery->orFilterWhere([
'and',
['property_slug' => $property->slug],
['=', 'FROM_UNIXTIME(`value`,\'%Y-%m-%d\')', date('Y-m-d', $value)]
]);
break;
case Properties::TYPE_CHECKBOX:
$subQuery->orFilterWhere([
'and',
['property_slug' => $property->slug],
['not', ['value' => null]]
]);
break;
case Properties::TYPE_FILE:
case Properties::TYPE_IMAGE:
$filtersApplied += -1;
$newQuery = Data::find()
->select('item_id')
->groupBy('item_id')
->where(['property_slug' => $property->slug])
->andWhere('`item_id` = `'.static::getTableNameItem().'`.`id`');
if($value == '0') {
$this->andWhere(['NOT IN', static::getTableNameItem() . '.id', $newQuery]);
} else {
$this->andWhere(['IN', static::getTableNameItem() . '.id', $newQuery]);
}
continue;
default:
$subQuery->orFilterWhere([
'and',
['property_slug' => $property->slug],
['value' => $value]
]);
}
$filtersApplied += is_array($value) ? count($value) : 1;
}
}
}else{
$properties_slug = ArrayHelper::getColumn(Properties::find()->select(['slug'])->asArray()->all(), 'slug');
foreach ($condition as $attribute => $value){
if(!in_array($attribute, $properties_slug)) continue;
$subQuery->orFilterWhere([
'and',
['property_slug' => $attribute],
['value' => $value]
]);
$filtersApplied += is_array($value) ? count($value) : 1;
}
}
if($filtersApplied) {
$this->join('LEFT JOIN', ['f' => $subQuery], 'f.item_id = '. static::getTableNameItem() .'.id');
$this->andFilterWhere(['f.filter_matched' => $filtersApplied]);
}
return $this;
} | php | public function whereProperties($condition)
{
$this->distinct(static::getTableNameItem() . '.id');
$properties = (isset($this->_category)) ? $this->_category->allProperties : [];
$filtersApplied = 0;
$subQuery = Data::find()->select('item_id, COUNT(*) as filter_matched')->groupBy('item_id');
/**
* Если установлена категория и определены свойства
*/
if(!empty($properties)) {
foreach ($properties as $property) {
if ($property->settings->filter_range) {
$value_from = ArrayHelper::getValue($condition, $property->slug . '_from', '');
$value_to = ArrayHelper::getValue($condition, $property->slug . '_to', '');
if (empty($value_from) && empty($value_to)) {
continue;
}
if (!$value_from) {
$additionalCondition = ['<=', 'value', (int)$value_to];
} elseif (!$value_to) {
$additionalCondition = ['>=', 'value', (int)$value_from];
} else {
$additionalCondition = ['between', 'value', (int)$value_from, (int)$value_to];
}
$subQuery->orFilterWhere(['and', ['property_slug' => $property->slug], $additionalCondition]);
$filtersApplied++;
} else {
$value = ArrayHelper::getValue($condition, $property->slug, '');
if ($value == '') continue;
switch ($property->type) {
case Properties::TYPE_DATETIME:
$subQuery->orFilterWhere([
'and',
['property_slug' => $property->slug],
['=', 'FROM_UNIXTIME(`value`,\'%Y-%m-%d\')', date('Y-m-d', $value)]
]);
break;
case Properties::TYPE_CHECKBOX:
$subQuery->orFilterWhere([
'and',
['property_slug' => $property->slug],
['not', ['value' => null]]
]);
break;
case Properties::TYPE_FILE:
case Properties::TYPE_IMAGE:
$filtersApplied += -1;
$newQuery = Data::find()
->select('item_id')
->groupBy('item_id')
->where(['property_slug' => $property->slug])
->andWhere('`item_id` = `'.static::getTableNameItem().'`.`id`');
if($value == '0') {
$this->andWhere(['NOT IN', static::getTableNameItem() . '.id', $newQuery]);
} else {
$this->andWhere(['IN', static::getTableNameItem() . '.id', $newQuery]);
}
continue;
default:
$subQuery->orFilterWhere([
'and',
['property_slug' => $property->slug],
['value' => $value]
]);
}
$filtersApplied += is_array($value) ? count($value) : 1;
}
}
}else{
$properties_slug = ArrayHelper::getColumn(Properties::find()->select(['slug'])->asArray()->all(), 'slug');
foreach ($condition as $attribute => $value){
if(!in_array($attribute, $properties_slug)) continue;
$subQuery->orFilterWhere([
'and',
['property_slug' => $attribute],
['value' => $value]
]);
$filtersApplied += is_array($value) ? count($value) : 1;
}
}
if($filtersApplied) {
$this->join('LEFT JOIN', ['f' => $subQuery], 'f.item_id = '. static::getTableNameItem() .'.id');
$this->andFilterWhere(['f.filter_matched' => $filtersApplied]);
}
return $this;
} | [
"public",
"function",
"whereProperties",
"(",
"$",
"condition",
")",
"{",
"$",
"this",
"->",
"distinct",
"(",
"static",
"::",
"getTableNameItem",
"(",
")",
".",
"'.id'",
")",
";",
"$",
"properties",
"=",
"(",
"isset",
"(",
"$",
"this",
"->",
"_category",
")",
")",
"?",
"$",
"this",
"->",
"_category",
"->",
"allProperties",
":",
"[",
"]",
";",
"$",
"filtersApplied",
"=",
"0",
";",
"$",
"subQuery",
"=",
"Data",
"::",
"find",
"(",
")",
"->",
"select",
"(",
"'item_id, COUNT(*) as filter_matched'",
")",
"->",
"groupBy",
"(",
"'item_id'",
")",
";",
"/**\n * Если установлена категория и определены свойства\n */",
"if",
"(",
"!",
"empty",
"(",
"$",
"properties",
")",
")",
"{",
"foreach",
"(",
"$",
"properties",
"as",
"$",
"property",
")",
"{",
"if",
"(",
"$",
"property",
"->",
"settings",
"->",
"filter_range",
")",
"{",
"$",
"value_from",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"condition",
",",
"$",
"property",
"->",
"slug",
".",
"'_from'",
",",
"''",
")",
";",
"$",
"value_to",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"condition",
",",
"$",
"property",
"->",
"slug",
".",
"'_to'",
",",
"''",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"value_from",
")",
"&&",
"empty",
"(",
"$",
"value_to",
")",
")",
"{",
"continue",
";",
"}",
"if",
"(",
"!",
"$",
"value_from",
")",
"{",
"$",
"additionalCondition",
"=",
"[",
"'<='",
",",
"'value'",
",",
"(",
"int",
")",
"$",
"value_to",
"]",
";",
"}",
"elseif",
"(",
"!",
"$",
"value_to",
")",
"{",
"$",
"additionalCondition",
"=",
"[",
"'>='",
",",
"'value'",
",",
"(",
"int",
")",
"$",
"value_from",
"]",
";",
"}",
"else",
"{",
"$",
"additionalCondition",
"=",
"[",
"'between'",
",",
"'value'",
",",
"(",
"int",
")",
"$",
"value_from",
",",
"(",
"int",
")",
"$",
"value_to",
"]",
";",
"}",
"$",
"subQuery",
"->",
"orFilterWhere",
"(",
"[",
"'and'",
",",
"[",
"'property_slug'",
"=>",
"$",
"property",
"->",
"slug",
"]",
",",
"$",
"additionalCondition",
"]",
")",
";",
"$",
"filtersApplied",
"++",
";",
"}",
"else",
"{",
"$",
"value",
"=",
"ArrayHelper",
"::",
"getValue",
"(",
"$",
"condition",
",",
"$",
"property",
"->",
"slug",
",",
"''",
")",
";",
"if",
"(",
"$",
"value",
"==",
"''",
")",
"continue",
";",
"switch",
"(",
"$",
"property",
"->",
"type",
")",
"{",
"case",
"Properties",
"::",
"TYPE_DATETIME",
":",
"$",
"subQuery",
"->",
"orFilterWhere",
"(",
"[",
"'and'",
",",
"[",
"'property_slug'",
"=>",
"$",
"property",
"->",
"slug",
"]",
",",
"[",
"'='",
",",
"'FROM_UNIXTIME(`value`,\\'%Y-%m-%d\\')'",
",",
"date",
"(",
"'Y-m-d'",
",",
"$",
"value",
")",
"]",
"]",
")",
";",
"break",
";",
"case",
"Properties",
"::",
"TYPE_CHECKBOX",
":",
"$",
"subQuery",
"->",
"orFilterWhere",
"(",
"[",
"'and'",
",",
"[",
"'property_slug'",
"=>",
"$",
"property",
"->",
"slug",
"]",
",",
"[",
"'not'",
",",
"[",
"'value'",
"=>",
"null",
"]",
"]",
"]",
")",
";",
"break",
";",
"case",
"Properties",
"::",
"TYPE_FILE",
":",
"case",
"Properties",
"::",
"TYPE_IMAGE",
":",
"$",
"filtersApplied",
"+=",
"-",
"1",
";",
"$",
"newQuery",
"=",
"Data",
"::",
"find",
"(",
")",
"->",
"select",
"(",
"'item_id'",
")",
"->",
"groupBy",
"(",
"'item_id'",
")",
"->",
"where",
"(",
"[",
"'property_slug'",
"=>",
"$",
"property",
"->",
"slug",
"]",
")",
"->",
"andWhere",
"(",
"'`item_id` = `'",
".",
"static",
"::",
"getTableNameItem",
"(",
")",
".",
"'`.`id`'",
")",
";",
"if",
"(",
"$",
"value",
"==",
"'0'",
")",
"{",
"$",
"this",
"->",
"andWhere",
"(",
"[",
"'NOT IN'",
",",
"static",
"::",
"getTableNameItem",
"(",
")",
".",
"'.id'",
",",
"$",
"newQuery",
"]",
")",
";",
"}",
"else",
"{",
"$",
"this",
"->",
"andWhere",
"(",
"[",
"'IN'",
",",
"static",
"::",
"getTableNameItem",
"(",
")",
".",
"'.id'",
",",
"$",
"newQuery",
"]",
")",
";",
"}",
"continue",
";",
"default",
":",
"$",
"subQuery",
"->",
"orFilterWhere",
"(",
"[",
"'and'",
",",
"[",
"'property_slug'",
"=>",
"$",
"property",
"->",
"slug",
"]",
",",
"[",
"'value'",
"=>",
"$",
"value",
"]",
"]",
")",
";",
"}",
"$",
"filtersApplied",
"+=",
"is_array",
"(",
"$",
"value",
")",
"?",
"count",
"(",
"$",
"value",
")",
":",
"1",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"properties_slug",
"=",
"ArrayHelper",
"::",
"getColumn",
"(",
"Properties",
"::",
"find",
"(",
")",
"->",
"select",
"(",
"[",
"'slug'",
"]",
")",
"->",
"asArray",
"(",
")",
"->",
"all",
"(",
")",
",",
"'slug'",
")",
";",
"foreach",
"(",
"$",
"condition",
"as",
"$",
"attribute",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"!",
"in_array",
"(",
"$",
"attribute",
",",
"$",
"properties_slug",
")",
")",
"continue",
";",
"$",
"subQuery",
"->",
"orFilterWhere",
"(",
"[",
"'and'",
",",
"[",
"'property_slug'",
"=>",
"$",
"attribute",
"]",
",",
"[",
"'value'",
"=>",
"$",
"value",
"]",
"]",
")",
";",
"$",
"filtersApplied",
"+=",
"is_array",
"(",
"$",
"value",
")",
"?",
"count",
"(",
"$",
"value",
")",
":",
"1",
";",
"}",
"}",
"if",
"(",
"$",
"filtersApplied",
")",
"{",
"$",
"this",
"->",
"join",
"(",
"'LEFT JOIN'",
",",
"[",
"'f'",
"=>",
"$",
"subQuery",
"]",
",",
"'f.item_id = '",
".",
"static",
"::",
"getTableNameItem",
"(",
")",
".",
"'.id'",
")",
";",
"$",
"this",
"->",
"andFilterWhere",
"(",
"[",
"'f.filter_matched'",
"=>",
"$",
"filtersApplied",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Поиск элементов по свойствам
@param $condition
@return $this | [
"Поиск",
"элементов",
"по",
"свойствам"
] | train | https://github.com/grozzzny/catalog/blob/ff1cac10a5f3a89f3ef2767f9ede6b2d74e1849a/components/ItemQuery.php#L92-L196 |
andromeda-framework/doctrine | src/Doctrine/Cache/Cache.php | Cache.doFetch | protected function doFetch($id)
{
$cached = $this->cache->load($id);
return $cached === NULL ? FALSE : $cached;
} | php | protected function doFetch($id)
{
$cached = $this->cache->load($id);
return $cached === NULL ? FALSE : $cached;
} | [
"protected",
"function",
"doFetch",
"(",
"$",
"id",
")",
"{",
"$",
"cached",
"=",
"$",
"this",
"->",
"cache",
"->",
"load",
"(",
"$",
"id",
")",
";",
"return",
"$",
"cached",
"===",
"NULL",
"?",
"FALSE",
":",
"$",
"cached",
";",
"}"
] | Fetches an entry from the cache.
@param string $id the id of the cache entry to fetch
@return mixed|FALSE the cached data or FALSE, if no cache entry exists for the given id | [
"Fetches",
"an",
"entry",
"from",
"the",
"cache",
"."
] | train | https://github.com/andromeda-framework/doctrine/blob/46924d91c09e0b9fbe5764518cbad70e467ffad4/src/Doctrine/Cache/Cache.php#L63-L67 |
andromeda-framework/doctrine | src/Doctrine/Cache/Cache.php | Cache.doSave | protected function doSave($id, $data, $lifeTime = 0)
{
if ($this->debug !== TRUE) {
return $this->doSaveDependingOnFiles($id, $data, [], $lifeTime);
}
$files = [];
if ($data instanceof Doctrine\ORM\Mapping\ClassMetadata) {
$files[] = (new ReflectionClass($data->name))->getFileName();
foreach ($data->parentClasses as $class) {
$files[] = (new ReflectionClass($class))->getFileName();
}
}
if (!empty($data)){
if (($m = Strings::match($id, '~(?P<class>[^@$[\].]+)(?:\$(?P<prop>[^@$[\].]+))?\@\[Annot\]~i')) && class_exists($m['class'])) {
$files[] = (new ReflectionClass($m['class']))->getFileName();
}
}
return $this->doSaveDependingOnFiles($id, $data, $files, $lifeTime);
} | php | protected function doSave($id, $data, $lifeTime = 0)
{
if ($this->debug !== TRUE) {
return $this->doSaveDependingOnFiles($id, $data, [], $lifeTime);
}
$files = [];
if ($data instanceof Doctrine\ORM\Mapping\ClassMetadata) {
$files[] = (new ReflectionClass($data->name))->getFileName();
foreach ($data->parentClasses as $class) {
$files[] = (new ReflectionClass($class))->getFileName();
}
}
if (!empty($data)){
if (($m = Strings::match($id, '~(?P<class>[^@$[\].]+)(?:\$(?P<prop>[^@$[\].]+))?\@\[Annot\]~i')) && class_exists($m['class'])) {
$files[] = (new ReflectionClass($m['class']))->getFileName();
}
}
return $this->doSaveDependingOnFiles($id, $data, $files, $lifeTime);
} | [
"protected",
"function",
"doSave",
"(",
"$",
"id",
",",
"$",
"data",
",",
"$",
"lifeTime",
"=",
"0",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"debug",
"!==",
"TRUE",
")",
"{",
"return",
"$",
"this",
"->",
"doSaveDependingOnFiles",
"(",
"$",
"id",
",",
"$",
"data",
",",
"[",
"]",
",",
"$",
"lifeTime",
")",
";",
"}",
"$",
"files",
"=",
"[",
"]",
";",
"if",
"(",
"$",
"data",
"instanceof",
"Doctrine",
"\\",
"ORM",
"\\",
"Mapping",
"\\",
"ClassMetadata",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"(",
"new",
"ReflectionClass",
"(",
"$",
"data",
"->",
"name",
")",
")",
"->",
"getFileName",
"(",
")",
";",
"foreach",
"(",
"$",
"data",
"->",
"parentClasses",
"as",
"$",
"class",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"(",
"new",
"ReflectionClass",
"(",
"$",
"class",
")",
")",
"->",
"getFileName",
"(",
")",
";",
"}",
"}",
"if",
"(",
"!",
"empty",
"(",
"$",
"data",
")",
")",
"{",
"if",
"(",
"(",
"$",
"m",
"=",
"Strings",
"::",
"match",
"(",
"$",
"id",
",",
"'~(?P<class>[^@$[\\].]+)(?:\\$(?P<prop>[^@$[\\].]+))?\\@\\[Annot\\]~i'",
")",
")",
"&&",
"class_exists",
"(",
"$",
"m",
"[",
"'class'",
"]",
")",
")",
"{",
"$",
"files",
"[",
"]",
"=",
"(",
"new",
"ReflectionClass",
"(",
"$",
"m",
"[",
"'class'",
"]",
")",
")",
"->",
"getFileName",
"(",
")",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"doSaveDependingOnFiles",
"(",
"$",
"id",
",",
"$",
"data",
",",
"$",
"files",
",",
"$",
"lifeTime",
")",
";",
"}"
] | Puts data into the cache.
@param string $id the cache id
@param string $data the cache entry/data
@param int $lifeTime the lifetime. If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime)
@return bool TRUE if the entry was successfully stored in the cache, FALSE otherwise | [
"Puts",
"data",
"into",
"the",
"cache",
"."
] | train | https://github.com/andromeda-framework/doctrine/blob/46924d91c09e0b9fbe5764518cbad70e467ffad4/src/Doctrine/Cache/Cache.php#L92-L113 |
andromeda-framework/doctrine | src/Doctrine/Cache/Cache.php | Cache.doSaveDependingOnFiles | protected function doSaveDependingOnFiles($id, $data, array $files, $lifeTime = 0)
{
$dependencies = [
NetteCache::TAGS => ['doctrine'],
NetteCache::FILES => $files
];
if ($lifeTime != 0) {
$dependencies[NetteCache::EXPIRE] = time() + $lifeTime;
}
$this->cache->save($id, $data, $dependencies);
return TRUE;
} | php | protected function doSaveDependingOnFiles($id, $data, array $files, $lifeTime = 0)
{
$dependencies = [
NetteCache::TAGS => ['doctrine'],
NetteCache::FILES => $files
];
if ($lifeTime != 0) {
$dependencies[NetteCache::EXPIRE] = time() + $lifeTime;
}
$this->cache->save($id, $data, $dependencies);
return TRUE;
} | [
"protected",
"function",
"doSaveDependingOnFiles",
"(",
"$",
"id",
",",
"$",
"data",
",",
"array",
"$",
"files",
",",
"$",
"lifeTime",
"=",
"0",
")",
"{",
"$",
"dependencies",
"=",
"[",
"NetteCache",
"::",
"TAGS",
"=>",
"[",
"'doctrine'",
"]",
",",
"NetteCache",
"::",
"FILES",
"=>",
"$",
"files",
"]",
";",
"if",
"(",
"$",
"lifeTime",
"!=",
"0",
")",
"{",
"$",
"dependencies",
"[",
"NetteCache",
"::",
"EXPIRE",
"]",
"=",
"time",
"(",
")",
"+",
"$",
"lifeTime",
";",
"}",
"$",
"this",
"->",
"cache",
"->",
"save",
"(",
"$",
"id",
",",
"$",
"data",
",",
"$",
"dependencies",
")",
";",
"return",
"TRUE",
";",
"}"
] | Puts data into the cache and makes them depending on the files.
@param string $id the cache id
@param string $data the cache entry/data
@param string[] $files the list of files the data are depending on
@param int $lifeTime the lifetime. If != 0, sets a specific lifetime for this cache entry (0 => infinite lifeTime)
@return bool TRUE | [
"Puts",
"data",
"into",
"the",
"cache",
"and",
"makes",
"them",
"depending",
"on",
"the",
"files",
"."
] | train | https://github.com/andromeda-framework/doctrine/blob/46924d91c09e0b9fbe5764518cbad70e467ffad4/src/Doctrine/Cache/Cache.php#L126-L138 |
thupan/framework | src/Service/Record.php | Record.merge | public static function merge($table1, $table2, $pk = [])
{
// join de 1 - n
$false = 0;
foreach($table1 as $key => $field) {
foreach($table2 as $k => $f) {
if($field[$pk[0]] == $f[$pk[1]]) {
$array[] = array_merge($field, $f);
$false = 0;
break; // para quando achar
}else{
$false = 1;
}
}
// Verificar se tem resultado
if($false == 1){
$array[] = $field;
$false = 0;
}
}
if(!$array){$array = [];}
return $array;
} | php | public static function merge($table1, $table2, $pk = [])
{
// join de 1 - n
$false = 0;
foreach($table1 as $key => $field) {
foreach($table2 as $k => $f) {
if($field[$pk[0]] == $f[$pk[1]]) {
$array[] = array_merge($field, $f);
$false = 0;
break; // para quando achar
}else{
$false = 1;
}
}
// Verificar se tem resultado
if($false == 1){
$array[] = $field;
$false = 0;
}
}
if(!$array){$array = [];}
return $array;
} | [
"public",
"static",
"function",
"merge",
"(",
"$",
"table1",
",",
"$",
"table2",
",",
"$",
"pk",
"=",
"[",
"]",
")",
"{",
"// join de 1 - n",
"$",
"false",
"=",
"0",
";",
"foreach",
"(",
"$",
"table1",
"as",
"$",
"key",
"=>",
"$",
"field",
")",
"{",
"foreach",
"(",
"$",
"table2",
"as",
"$",
"k",
"=>",
"$",
"f",
")",
"{",
"if",
"(",
"$",
"field",
"[",
"$",
"pk",
"[",
"0",
"]",
"]",
"==",
"$",
"f",
"[",
"$",
"pk",
"[",
"1",
"]",
"]",
")",
"{",
"$",
"array",
"[",
"]",
"=",
"array_merge",
"(",
"$",
"field",
",",
"$",
"f",
")",
";",
"$",
"false",
"=",
"0",
";",
"break",
";",
"// para quando achar",
"}",
"else",
"{",
"$",
"false",
"=",
"1",
";",
"}",
"}",
"// Verificar se tem resultado",
"if",
"(",
"$",
"false",
"==",
"1",
")",
"{",
"$",
"array",
"[",
"]",
"=",
"$",
"field",
";",
"$",
"false",
"=",
"0",
";",
"}",
"}",
"if",
"(",
"!",
"$",
"array",
")",
"{",
"$",
"array",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"array",
";",
"}"
] | Método público retorna um JOIN de PDO por um ID.
@method merge()
@param Aarray
@param Aarray
@param Aarray
@return Array | [
"Método",
"público",
"retorna",
"um",
"JOIN",
"de",
"PDO",
"por",
"um",
"ID",
"."
] | train | https://github.com/thupan/framework/blob/43193c67e87942930fb0cbc53aa069b60b27e749/src/Service/Record.php#L23-L48 |
thupan/framework | src/Service/Record.php | Record.sortCol | public static function sortCol($result,$array)
{
foreach ($result as $key => $fields) {
$dados[] = self::sortkeys($fields,$array);
}
if(!$dados){ $dados = [];}
return $dados;
} | php | public static function sortCol($result,$array)
{
foreach ($result as $key => $fields) {
$dados[] = self::sortkeys($fields,$array);
}
if(!$dados){ $dados = [];}
return $dados;
} | [
"public",
"static",
"function",
"sortCol",
"(",
"$",
"result",
",",
"$",
"array",
")",
"{",
"foreach",
"(",
"$",
"result",
"as",
"$",
"key",
"=>",
"$",
"fields",
")",
"{",
"$",
"dados",
"[",
"]",
"=",
"self",
"::",
"sortkeys",
"(",
"$",
"fields",
",",
"$",
"array",
")",
";",
"}",
"if",
"(",
"!",
"$",
"dados",
")",
"{",
"$",
"dados",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"dados",
";",
"}"
] | Método público retorna um sort de um array definido.
Organizar as colunas na visualização do grid.
@method sortCol()
@param Aarray
@param Aarray
@return Array | [
"Método",
"público",
"retorna",
"um",
"sort",
"de",
"um",
"array",
"definido",
".",
"Organizar",
"as",
"colunas",
"na",
"visualização",
"do",
"grid",
"."
] | train | https://github.com/thupan/framework/blob/43193c67e87942930fb0cbc53aa069b60b27e749/src/Service/Record.php#L59-L68 |
thupan/framework | src/Service/Record.php | Record.sortKeys | private static function sortKeys($array, $order)
{
uksort($array, function ($a, $b) use ($order) {
$pos_a = array_search($a, $order);
$pos_b = array_search($b, $order);
if ($pos_a === false)
return 1;
if ($pos_b === false)
return -1;
return $pos_a - $pos_b;
});
return $array;
} | php | private static function sortKeys($array, $order)
{
uksort($array, function ($a, $b) use ($order) {
$pos_a = array_search($a, $order);
$pos_b = array_search($b, $order);
if ($pos_a === false)
return 1;
if ($pos_b === false)
return -1;
return $pos_a - $pos_b;
});
return $array;
} | [
"private",
"static",
"function",
"sortKeys",
"(",
"$",
"array",
",",
"$",
"order",
")",
"{",
"uksort",
"(",
"$",
"array",
",",
"function",
"(",
"$",
"a",
",",
"$",
"b",
")",
"use",
"(",
"$",
"order",
")",
"{",
"$",
"pos_a",
"=",
"array_search",
"(",
"$",
"a",
",",
"$",
"order",
")",
";",
"$",
"pos_b",
"=",
"array_search",
"(",
"$",
"b",
",",
"$",
"order",
")",
";",
"if",
"(",
"$",
"pos_a",
"===",
"false",
")",
"return",
"1",
";",
"if",
"(",
"$",
"pos_b",
"===",
"false",
")",
"return",
"-",
"1",
";",
"return",
"$",
"pos_a",
"-",
"$",
"pos_b",
";",
"}",
")",
";",
"return",
"$",
"array",
";",
"}"
] | Método privado retorna um sort de um array definido.
@method sortKeys()
@param Aarray
@param Aarray
@return Array | [
"Método",
"privado",
"retorna",
"um",
"sort",
"de",
"um",
"array",
"definido",
"."
] | train | https://github.com/thupan/framework/blob/43193c67e87942930fb0cbc53aa069b60b27e749/src/Service/Record.php#L77-L92 |
thupan/framework | src/Service/Record.php | Record.sortRecord | public static function sortRecord($records, $field, $order=true)
{
$new_array = array();
$sortable_array = array();
if (count($records) > 0) {
foreach ($records as $k => $v) {
if (is_array($v)) {
foreach ($v as $k2 => $v2) {
if ($k2 == $field) {
$sortable_array[$k] = $v2;
}
}
} else {
$sortable_array[$k] = $v;
}
}
switch ($order) {
case true:
asort($sortable_array);
break;
case false:
arsort($sortable_array);
break;
}
foreach ($sortable_array as $k => $v) {
$new_array[$k] = $records[$k];
}
}
return $new_array;
} | php | public static function sortRecord($records, $field, $order=true)
{
$new_array = array();
$sortable_array = array();
if (count($records) > 0) {
foreach ($records as $k => $v) {
if (is_array($v)) {
foreach ($v as $k2 => $v2) {
if ($k2 == $field) {
$sortable_array[$k] = $v2;
}
}
} else {
$sortable_array[$k] = $v;
}
}
switch ($order) {
case true:
asort($sortable_array);
break;
case false:
arsort($sortable_array);
break;
}
foreach ($sortable_array as $k => $v) {
$new_array[$k] = $records[$k];
}
}
return $new_array;
} | [
"public",
"static",
"function",
"sortRecord",
"(",
"$",
"records",
",",
"$",
"field",
",",
"$",
"order",
"=",
"true",
")",
"{",
"$",
"new_array",
"=",
"array",
"(",
")",
";",
"$",
"sortable_array",
"=",
"array",
"(",
")",
";",
"if",
"(",
"count",
"(",
"$",
"records",
")",
">",
"0",
")",
"{",
"foreach",
"(",
"$",
"records",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"v",
")",
")",
"{",
"foreach",
"(",
"$",
"v",
"as",
"$",
"k2",
"=>",
"$",
"v2",
")",
"{",
"if",
"(",
"$",
"k2",
"==",
"$",
"field",
")",
"{",
"$",
"sortable_array",
"[",
"$",
"k",
"]",
"=",
"$",
"v2",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"sortable_array",
"[",
"$",
"k",
"]",
"=",
"$",
"v",
";",
"}",
"}",
"switch",
"(",
"$",
"order",
")",
"{",
"case",
"true",
":",
"asort",
"(",
"$",
"sortable_array",
")",
";",
"break",
";",
"case",
"false",
":",
"arsort",
"(",
"$",
"sortable_array",
")",
";",
"break",
";",
"}",
"foreach",
"(",
"$",
"sortable_array",
"as",
"$",
"k",
"=>",
"$",
"v",
")",
"{",
"$",
"new_array",
"[",
"$",
"k",
"]",
"=",
"$",
"records",
"[",
"$",
"k",
"]",
";",
"}",
"}",
"return",
"$",
"new_array",
";",
"}"
] | Método público retorna uma orderna um array em PDO.
@method sortRecord()
@param Aarray
@param String
@param boolean
@return Array | [
"Método",
"público",
"retorna",
"uma",
"orderna",
"um",
"array",
"em",
"PDO",
"."
] | train | https://github.com/thupan/framework/blob/43193c67e87942930fb0cbc53aa069b60b27e749/src/Service/Record.php#L102-L135 |
thupan/framework | src/Service/Record.php | Record.findRecord | public static function findRecord($dados,$coluna,$valor)
{
$cont = 0;
if($valor){
foreach ($dados as $key => $value) {
if(strpos($value[$coluna],$valor)!== false){
$obj[$cont] = $value;
$cont++;
}else if(strpos($value[$coluna],mb_strtoupper($valor))!== false){
$obj[$cont] = $value;
$cont++;
} else if(strpos($value[$coluna],ucwords(strtolower($valor)))!== false){
$obj[$cont] = $value;
$cont++;
}else if(strpos($value[$coluna],mb_strtolower($valor))!== false){
$obj[$cont] = $value;
$cont++;
}else if(strpos($value[$coluna],ucfirst(strtolower($valor)))!== false){
$obj[$cont] = $value;
$cont++;
}
}
}else{
$obj = $dados;
}
if(!$obj){ $obj = [];}
return $obj;
} | php | public static function findRecord($dados,$coluna,$valor)
{
$cont = 0;
if($valor){
foreach ($dados as $key => $value) {
if(strpos($value[$coluna],$valor)!== false){
$obj[$cont] = $value;
$cont++;
}else if(strpos($value[$coluna],mb_strtoupper($valor))!== false){
$obj[$cont] = $value;
$cont++;
} else if(strpos($value[$coluna],ucwords(strtolower($valor)))!== false){
$obj[$cont] = $value;
$cont++;
}else if(strpos($value[$coluna],mb_strtolower($valor))!== false){
$obj[$cont] = $value;
$cont++;
}else if(strpos($value[$coluna],ucfirst(strtolower($valor)))!== false){
$obj[$cont] = $value;
$cont++;
}
}
}else{
$obj = $dados;
}
if(!$obj){ $obj = [];}
return $obj;
} | [
"public",
"static",
"function",
"findRecord",
"(",
"$",
"dados",
",",
"$",
"coluna",
",",
"$",
"valor",
")",
"{",
"$",
"cont",
"=",
"0",
";",
"if",
"(",
"$",
"valor",
")",
"{",
"foreach",
"(",
"$",
"dados",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"if",
"(",
"strpos",
"(",
"$",
"value",
"[",
"$",
"coluna",
"]",
",",
"$",
"valor",
")",
"!==",
"false",
")",
"{",
"$",
"obj",
"[",
"$",
"cont",
"]",
"=",
"$",
"value",
";",
"$",
"cont",
"++",
";",
"}",
"else",
"if",
"(",
"strpos",
"(",
"$",
"value",
"[",
"$",
"coluna",
"]",
",",
"mb_strtoupper",
"(",
"$",
"valor",
")",
")",
"!==",
"false",
")",
"{",
"$",
"obj",
"[",
"$",
"cont",
"]",
"=",
"$",
"value",
";",
"$",
"cont",
"++",
";",
"}",
"else",
"if",
"(",
"strpos",
"(",
"$",
"value",
"[",
"$",
"coluna",
"]",
",",
"ucwords",
"(",
"strtolower",
"(",
"$",
"valor",
")",
")",
")",
"!==",
"false",
")",
"{",
"$",
"obj",
"[",
"$",
"cont",
"]",
"=",
"$",
"value",
";",
"$",
"cont",
"++",
";",
"}",
"else",
"if",
"(",
"strpos",
"(",
"$",
"value",
"[",
"$",
"coluna",
"]",
",",
"mb_strtolower",
"(",
"$",
"valor",
")",
")",
"!==",
"false",
")",
"{",
"$",
"obj",
"[",
"$",
"cont",
"]",
"=",
"$",
"value",
";",
"$",
"cont",
"++",
";",
"}",
"else",
"if",
"(",
"strpos",
"(",
"$",
"value",
"[",
"$",
"coluna",
"]",
",",
"ucfirst",
"(",
"strtolower",
"(",
"$",
"valor",
")",
")",
")",
"!==",
"false",
")",
"{",
"$",
"obj",
"[",
"$",
"cont",
"]",
"=",
"$",
"value",
";",
"$",
"cont",
"++",
";",
"}",
"}",
"}",
"else",
"{",
"$",
"obj",
"=",
"$",
"dados",
";",
"}",
"if",
"(",
"!",
"$",
"obj",
")",
"{",
"$",
"obj",
"=",
"[",
"]",
";",
"}",
"return",
"$",
"obj",
";",
"}"
] | Método público retorna uma pesquisa em um PDO.
@method findRecord()
@param Aarray
@param String
@param String
@return Array | [
"Método",
"público",
"retorna",
"uma",
"pesquisa",
"em",
"um",
"PDO",
"."
] | train | https://github.com/thupan/framework/blob/43193c67e87942930fb0cbc53aa069b60b27e749/src/Service/Record.php#L145-L176 |
nabab/bbn | src/bbn/str/charset.php | utf8.loadCharset | function loadCharset($charset)
{
if ( stripos($charset,'ISO-') !== false ){
$filename = BBN_LIB_PATH . 'bbn/bbn/src/bbn/str/charset/' . substr($charset, stripos($charset, 'ISO-')+4) . '.txt';
}
else {
return false;
}
$lines = @file_get_contents($filename)
or exit($this->onError(ERR_OPEN_MAP_FILE,"Error openning file: " . $this->filename));
$this->charset = $charset;
$lines = preg_replace("/#.*$/m","",$lines);
$lines = preg_replace("/\n\n/","",$lines);
$lines = explode("\n",$lines);
foreach($lines as $line){
$parts = explode('0x',$line);
if(\count($parts)==3){
$asc=hexdec(substr($parts[1],0,2));
$utf=hexdec(substr($parts[2],0,4));
$this->ascMap[$charset][$asc]=$utf;
}
}
$this->utfMap = array_flip($this->ascMap[$charset]);
return true;
} | php | function loadCharset($charset)
{
if ( stripos($charset,'ISO-') !== false ){
$filename = BBN_LIB_PATH . 'bbn/bbn/src/bbn/str/charset/' . substr($charset, stripos($charset, 'ISO-')+4) . '.txt';
}
else {
return false;
}
$lines = @file_get_contents($filename)
or exit($this->onError(ERR_OPEN_MAP_FILE,"Error openning file: " . $this->filename));
$this->charset = $charset;
$lines = preg_replace("/#.*$/m","",$lines);
$lines = preg_replace("/\n\n/","",$lines);
$lines = explode("\n",$lines);
foreach($lines as $line){
$parts = explode('0x',$line);
if(\count($parts)==3){
$asc=hexdec(substr($parts[1],0,2));
$utf=hexdec(substr($parts[2],0,4));
$this->ascMap[$charset][$asc]=$utf;
}
}
$this->utfMap = array_flip($this->ascMap[$charset]);
return true;
} | [
"function",
"loadCharset",
"(",
"$",
"charset",
")",
"{",
"if",
"(",
"stripos",
"(",
"$",
"charset",
",",
"'ISO-'",
")",
"!==",
"false",
")",
"{",
"$",
"filename",
"=",
"BBN_LIB_PATH",
".",
"'bbn/bbn/src/bbn/str/charset/'",
".",
"substr",
"(",
"$",
"charset",
",",
"stripos",
"(",
"$",
"charset",
",",
"'ISO-'",
")",
"+",
"4",
")",
".",
"'.txt'",
";",
"}",
"else",
"{",
"return",
"false",
";",
"}",
"$",
"lines",
"=",
"@",
"file_get_contents",
"(",
"$",
"filename",
")",
"or",
"exit",
"(",
"$",
"this",
"->",
"onError",
"(",
"ERR_OPEN_MAP_FILE",
",",
"\"Error openning file: \"",
".",
"$",
"this",
"->",
"filename",
")",
")",
";",
"$",
"this",
"->",
"charset",
"=",
"$",
"charset",
";",
"$",
"lines",
"=",
"preg_replace",
"(",
"\"/#.*$/m\"",
",",
"\"\"",
",",
"$",
"lines",
")",
";",
"$",
"lines",
"=",
"preg_replace",
"(",
"\"/\\n\\n/\"",
",",
"\"\"",
",",
"$",
"lines",
")",
";",
"$",
"lines",
"=",
"explode",
"(",
"\"\\n\"",
",",
"$",
"lines",
")",
";",
"foreach",
"(",
"$",
"lines",
"as",
"$",
"line",
")",
"{",
"$",
"parts",
"=",
"explode",
"(",
"'0x'",
",",
"$",
"line",
")",
";",
"if",
"(",
"\\",
"count",
"(",
"$",
"parts",
")",
"==",
"3",
")",
"{",
"$",
"asc",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"parts",
"[",
"1",
"]",
",",
"0",
",",
"2",
")",
")",
";",
"$",
"utf",
"=",
"hexdec",
"(",
"substr",
"(",
"$",
"parts",
"[",
"2",
"]",
",",
"0",
",",
"4",
")",
")",
";",
"$",
"this",
"->",
"ascMap",
"[",
"$",
"charset",
"]",
"[",
"$",
"asc",
"]",
"=",
"$",
"utf",
";",
"}",
"}",
"$",
"this",
"->",
"utfMap",
"=",
"array_flip",
"(",
"$",
"this",
"->",
"ascMap",
"[",
"$",
"charset",
"]",
")",
";",
"return",
"true",
";",
"}"
] | /* Load charset | [
"/",
"*",
"Load",
"charset"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/str/charset.php#L22-L46 |
nabab/bbn | src/bbn/str/charset.php | utf8.strToUtf8 | function strToUtf8($str)
{
$chars = unpack('C*', $str);
$cnt = \count($chars);
for($i=1;$i<=$cnt;$i++)
$this->_charToUtf8($chars[$i]);
return implode("",$chars);
} | php | function strToUtf8($str)
{
$chars = unpack('C*', $str);
$cnt = \count($chars);
for($i=1;$i<=$cnt;$i++)
$this->_charToUtf8($chars[$i]);
return implode("",$chars);
} | [
"function",
"strToUtf8",
"(",
"$",
"str",
")",
"{",
"$",
"chars",
"=",
"unpack",
"(",
"'C*'",
",",
"$",
"str",
")",
";",
"$",
"cnt",
"=",
"\\",
"count",
"(",
"$",
"chars",
")",
";",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"$",
"cnt",
";",
"$",
"i",
"++",
")",
"$",
"this",
"->",
"_charToUtf8",
"(",
"$",
"chars",
"[",
"$",
"i",
"]",
")",
";",
"return",
"implode",
"(",
"\"\"",
",",
"$",
"chars",
")",
";",
"}"
] | /* Translate string ($str) to UTF-8 from given charset | [
"/",
"*",
"Translate",
"string",
"(",
"$str",
")",
"to",
"UTF",
"-",
"8",
"from",
"given",
"charset"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/str/charset.php#L55-L62 |
nabab/bbn | src/bbn/str/charset.php | utf8.utf8ToStr | function utf8ToStr($utf)
{
$chars = unpack('C*', $utf);
$cnt = \count($chars);
$res = ""; /* No simple way to do it in place... concatenate char by char */
for ($i=1;$i<=$cnt;$i++)
$res .= $this->_utf8ToChar($chars, $i);
return $res;
} | php | function utf8ToStr($utf)
{
$chars = unpack('C*', $utf);
$cnt = \count($chars);
$res = ""; /* No simple way to do it in place... concatenate char by char */
for ($i=1;$i<=$cnt;$i++)
$res .= $this->_utf8ToChar($chars, $i);
return $res;
} | [
"function",
"utf8ToStr",
"(",
"$",
"utf",
")",
"{",
"$",
"chars",
"=",
"unpack",
"(",
"'C*'",
",",
"$",
"utf",
")",
";",
"$",
"cnt",
"=",
"\\",
"count",
"(",
"$",
"chars",
")",
";",
"$",
"res",
"=",
"\"\"",
";",
"/* No simple way to do it in place... concatenate char by char */",
"for",
"(",
"$",
"i",
"=",
"1",
";",
"$",
"i",
"<=",
"$",
"cnt",
";",
"$",
"i",
"++",
")",
"$",
"res",
".=",
"$",
"this",
"->",
"_utf8ToChar",
"(",
"$",
"chars",
",",
"$",
"i",
")",
";",
"return",
"$",
"res",
";",
"}"
] | /* Translate UTF-8 string to single byte string in the given charset | [
"/",
"*",
"Translate",
"UTF",
"-",
"8",
"string",
"to",
"single",
"byte",
"string",
"in",
"the",
"given",
"charset"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/str/charset.php#L65-L73 |
nabab/bbn | src/bbn/str/charset.php | utf8._charToUtf8 | function _charToUtf8(&$char)
{
$c = (int)$this->ascMap[$this->charset][$char];
if ($c < 0x80)
$char = \chr($c);
else if($c<0x800) /* 2 bytes */
$char = (\chr(0xC0 | $c>>6) . \chr(0x80 | $c & 0x3F));
else if($c<0x10000) /* 3 bytes */
$char = (\chr(0xE0 | $c>>12) . \chr(0x80 | $c>>6 & 0x3F) . \chr(0x80 | $c & 0x3F));
else if($c<0x200000) /* 4 bytes */
$char = (\chr(0xF0 | $c>>18) . \chr(0x80 | $c>>12 & 0x3F) . \chr(0x80 | $c>>6 & 0x3F) . \chr(0x80 | $c & 0x3F));
} | php | function _charToUtf8(&$char)
{
$c = (int)$this->ascMap[$this->charset][$char];
if ($c < 0x80)
$char = \chr($c);
else if($c<0x800) /* 2 bytes */
$char = (\chr(0xC0 | $c>>6) . \chr(0x80 | $c & 0x3F));
else if($c<0x10000) /* 3 bytes */
$char = (\chr(0xE0 | $c>>12) . \chr(0x80 | $c>>6 & 0x3F) . \chr(0x80 | $c & 0x3F));
else if($c<0x200000) /* 4 bytes */
$char = (\chr(0xF0 | $c>>18) . \chr(0x80 | $c>>12 & 0x3F) . \chr(0x80 | $c>>6 & 0x3F) . \chr(0x80 | $c & 0x3F));
} | [
"function",
"_charToUtf8",
"(",
"&",
"$",
"char",
")",
"{",
"$",
"c",
"=",
"(",
"int",
")",
"$",
"this",
"->",
"ascMap",
"[",
"$",
"this",
"->",
"charset",
"]",
"[",
"$",
"char",
"]",
";",
"if",
"(",
"$",
"c",
"<",
"0x80",
")",
"$",
"char",
"=",
"\\",
"chr",
"(",
"$",
"c",
")",
";",
"else",
"if",
"(",
"$",
"c",
"<",
"0x800",
")",
"/* 2 bytes */",
"$",
"char",
"=",
"(",
"\\",
"chr",
"(",
"0xC0",
"|",
"$",
"c",
">>",
"6",
")",
".",
"\\",
"chr",
"(",
"0x80",
"|",
"$",
"c",
"&",
"0x3F",
")",
")",
";",
"else",
"if",
"(",
"$",
"c",
"<",
"0x10000",
")",
"/* 3 bytes */",
"$",
"char",
"=",
"(",
"\\",
"chr",
"(",
"0xE0",
"|",
"$",
"c",
">>",
"12",
")",
".",
"\\",
"chr",
"(",
"0x80",
"|",
"$",
"c",
">>",
"6",
"&",
"0x3F",
")",
".",
"\\",
"chr",
"(",
"0x80",
"|",
"$",
"c",
"&",
"0x3F",
")",
")",
";",
"else",
"if",
"(",
"$",
"c",
"<",
"0x200000",
")",
"/* 4 bytes */",
"$",
"char",
"=",
"(",
"\\",
"chr",
"(",
"0xF0",
"|",
"$",
"c",
">>",
"18",
")",
".",
"\\",
"chr",
"(",
"0x80",
"|",
"$",
"c",
">>",
"12",
"&",
"0x3F",
")",
".",
"\\",
"chr",
"(",
"0x80",
"|",
"$",
"c",
">>",
"6",
"&",
"0x3F",
")",
".",
"\\",
"chr",
"(",
"0x80",
"|",
"$",
"c",
"&",
"0x3F",
")",
")",
";",
"}"
] | /* Char to UTF-8 sequence | [
"/",
"*",
"Char",
"to",
"UTF",
"-",
"8",
"sequence"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/str/charset.php#L76-L87 |
nabab/bbn | src/bbn/str/charset.php | utf8._utf8ToChar | function _utf8ToChar(&$chars, &$idx)
{
if(($chars[$idx] >= 240) && ($chars[$idx] <= 255))
/* 4 bytes */
$utf = ((int)($chars[$idx]-240) << 18) +
((int)($chars[++$idx]-128) << 12) +
((int)($chars[++$idx]-128) << 6) +
((int)($chars[++$idx]-128) << 0);
else if (($chars[$idx] >= 224) && ($chars[$idx] <= 239))
/* 3 bytes */
$utf = ((int)($chars[$idx]-224) << 12) +
((int)($chars[++$idx]-128) << 6) +
((int)($chars[++$idx]-128) << 0);
else if (($chars[$idx] >= 192) && ($chars[$idx] <= 223))
/* 2 bytes */
$utf = ((int)($chars[$idx]-192) << 6) +
((int)($chars[++$idx]-128) << 0);
else
/* 1 byte */
$utf = $chars[$idx];
if(array_key_exists($utf,$this->utfMap))
return \chr($this->utfMap[$utf]);
else
return "?";
} | php | function _utf8ToChar(&$chars, &$idx)
{
if(($chars[$idx] >= 240) && ($chars[$idx] <= 255))
/* 4 bytes */
$utf = ((int)($chars[$idx]-240) << 18) +
((int)($chars[++$idx]-128) << 12) +
((int)($chars[++$idx]-128) << 6) +
((int)($chars[++$idx]-128) << 0);
else if (($chars[$idx] >= 224) && ($chars[$idx] <= 239))
/* 3 bytes */
$utf = ((int)($chars[$idx]-224) << 12) +
((int)($chars[++$idx]-128) << 6) +
((int)($chars[++$idx]-128) << 0);
else if (($chars[$idx] >= 192) && ($chars[$idx] <= 223))
/* 2 bytes */
$utf = ((int)($chars[$idx]-192) << 6) +
((int)($chars[++$idx]-128) << 0);
else
/* 1 byte */
$utf = $chars[$idx];
if(array_key_exists($utf,$this->utfMap))
return \chr($this->utfMap[$utf]);
else
return "?";
} | [
"function",
"_utf8ToChar",
"(",
"&",
"$",
"chars",
",",
"&",
"$",
"idx",
")",
"{",
"if",
"(",
"(",
"$",
"chars",
"[",
"$",
"idx",
"]",
">=",
"240",
")",
"&&",
"(",
"$",
"chars",
"[",
"$",
"idx",
"]",
"<=",
"255",
")",
")",
"/* 4 bytes */",
"$",
"utf",
"=",
"(",
"(",
"int",
")",
"(",
"$",
"chars",
"[",
"$",
"idx",
"]",
"-",
"240",
")",
"<<",
"18",
")",
"+",
"(",
"(",
"int",
")",
"(",
"$",
"chars",
"[",
"++",
"$",
"idx",
"]",
"-",
"128",
")",
"<<",
"12",
")",
"+",
"(",
"(",
"int",
")",
"(",
"$",
"chars",
"[",
"++",
"$",
"idx",
"]",
"-",
"128",
")",
"<<",
"6",
")",
"+",
"(",
"(",
"int",
")",
"(",
"$",
"chars",
"[",
"++",
"$",
"idx",
"]",
"-",
"128",
")",
"<<",
"0",
")",
";",
"else",
"if",
"(",
"(",
"$",
"chars",
"[",
"$",
"idx",
"]",
">=",
"224",
")",
"&&",
"(",
"$",
"chars",
"[",
"$",
"idx",
"]",
"<=",
"239",
")",
")",
"/* 3 bytes */",
"$",
"utf",
"=",
"(",
"(",
"int",
")",
"(",
"$",
"chars",
"[",
"$",
"idx",
"]",
"-",
"224",
")",
"<<",
"12",
")",
"+",
"(",
"(",
"int",
")",
"(",
"$",
"chars",
"[",
"++",
"$",
"idx",
"]",
"-",
"128",
")",
"<<",
"6",
")",
"+",
"(",
"(",
"int",
")",
"(",
"$",
"chars",
"[",
"++",
"$",
"idx",
"]",
"-",
"128",
")",
"<<",
"0",
")",
";",
"else",
"if",
"(",
"(",
"$",
"chars",
"[",
"$",
"idx",
"]",
">=",
"192",
")",
"&&",
"(",
"$",
"chars",
"[",
"$",
"idx",
"]",
"<=",
"223",
")",
")",
"/* 2 bytes */",
"$",
"utf",
"=",
"(",
"(",
"int",
")",
"(",
"$",
"chars",
"[",
"$",
"idx",
"]",
"-",
"192",
")",
"<<",
"6",
")",
"+",
"(",
"(",
"int",
")",
"(",
"$",
"chars",
"[",
"++",
"$",
"idx",
"]",
"-",
"128",
")",
"<<",
"0",
")",
";",
"else",
"/* 1 byte */",
"$",
"utf",
"=",
"$",
"chars",
"[",
"$",
"idx",
"]",
";",
"if",
"(",
"array_key_exists",
"(",
"$",
"utf",
",",
"$",
"this",
"->",
"utfMap",
")",
")",
"return",
"\\",
"chr",
"(",
"$",
"this",
"->",
"utfMap",
"[",
"$",
"utf",
"]",
")",
";",
"else",
"return",
"\"?\"",
";",
"}"
] | /* UTF-8 sequence to single byte character | [
"/",
"*",
"UTF",
"-",
"8",
"sequence",
"to",
"single",
"byte",
"character"
] | train | https://github.com/nabab/bbn/blob/439fea2faa0de22fdaae2611833bab8061f40c37/src/bbn/str/charset.php#L90-L114 |
dragonmantank/fillet | src/Fillet/Writer/AbstractWriter.php | AbstractWriter.toMarkdown | protected function toMarkdown($content)
{
$tmpfname = tempnam(sys_get_temp_dir(), 'fillet'); // good
file_put_contents($tmpfname, $content);
$cmd = $this->config['pandoc']['bin'] . ' --no-wrap -f html -t markdown ' . $tmpfname;
$content = shell_exec($cmd);
unlink($tmpfname);
return $content;
} | php | protected function toMarkdown($content)
{
$tmpfname = tempnam(sys_get_temp_dir(), 'fillet'); // good
file_put_contents($tmpfname, $content);
$cmd = $this->config['pandoc']['bin'] . ' --no-wrap -f html -t markdown ' . $tmpfname;
$content = shell_exec($cmd);
unlink($tmpfname);
return $content;
} | [
"protected",
"function",
"toMarkdown",
"(",
"$",
"content",
")",
"{",
"$",
"tmpfname",
"=",
"tempnam",
"(",
"sys_get_temp_dir",
"(",
")",
",",
"'fillet'",
")",
";",
"// good",
"file_put_contents",
"(",
"$",
"tmpfname",
",",
"$",
"content",
")",
";",
"$",
"cmd",
"=",
"$",
"this",
"->",
"config",
"[",
"'pandoc'",
"]",
"[",
"'bin'",
"]",
".",
"' --no-wrap -f html -t markdown '",
".",
"$",
"tmpfname",
";",
"$",
"content",
"=",
"shell_exec",
"(",
"$",
"cmd",
")",
";",
"unlink",
"(",
"$",
"tmpfname",
")",
";",
"return",
"$",
"content",
";",
"}"
] | Converts content from HTML to Markdown via pandoc
@param $content
@return string | [
"Converts",
"content",
"from",
"HTML",
"to",
"Markdown",
"via",
"pandoc"
] | train | https://github.com/dragonmantank/fillet/blob/b197947608c05ac2318e8f6b296345494004d9c6/src/Fillet/Writer/AbstractWriter.php#L44-L52 |
willhoffmann/domuserp-php | src/Resources/Addresses/Secondary/Streets.php | Streets.getList | public function getList(array $query = [])
{
$resource = self::$BASE_URI . '/' . $this->cityId . '/bairros/' . $this->neighborhoodId . '/logradouro';
$list = $this->pagination($resource);
return $list;
} | php | public function getList(array $query = [])
{
$resource = self::$BASE_URI . '/' . $this->cityId . '/bairros/' . $this->neighborhoodId . '/logradouro';
$list = $this->pagination($resource);
return $list;
} | [
"public",
"function",
"getList",
"(",
"array",
"$",
"query",
"=",
"[",
"]",
")",
"{",
"$",
"resource",
"=",
"self",
"::",
"$",
"BASE_URI",
".",
"'/'",
".",
"$",
"this",
"->",
"cityId",
".",
"'/bairros/'",
".",
"$",
"this",
"->",
"neighborhoodId",
".",
"'/logradouro'",
";",
"$",
"list",
"=",
"$",
"this",
"->",
"pagination",
"(",
"$",
"resource",
")",
";",
"return",
"$",
"list",
";",
"}"
] | List of neighborhoods
@param array $query
@return array|string
@throws \GuzzleHttp\Exception\GuzzleException | [
"List",
"of",
"neighborhoods"
] | train | https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/Addresses/Secondary/Streets.php#L49-L55 |
willhoffmann/domuserp-php | src/Resources/Addresses/Secondary/Streets.php | Streets.get | public function get($id)
{
$resource = self::$BASE_URI . '/' . $this->cityId . '/bairros/' . $this->neighborhoodId . '/logradouro/' . $id;
$data = $this->execute(self::HTTP_GET, $resource);
return $data;
} | php | public function get($id)
{
$resource = self::$BASE_URI . '/' . $this->cityId . '/bairros/' . $this->neighborhoodId . '/logradouro/' . $id;
$data = $this->execute(self::HTTP_GET, $resource);
return $data;
} | [
"public",
"function",
"get",
"(",
"$",
"id",
")",
"{",
"$",
"resource",
"=",
"self",
"::",
"$",
"BASE_URI",
".",
"'/'",
".",
"$",
"this",
"->",
"cityId",
".",
"'/bairros/'",
".",
"$",
"this",
"->",
"neighborhoodId",
".",
"'/logradouro/'",
".",
"$",
"id",
";",
"$",
"data",
"=",
"$",
"this",
"->",
"execute",
"(",
"self",
"::",
"HTTP_GET",
",",
"$",
"resource",
")",
";",
"return",
"$",
"data",
";",
"}"
] | Gets the street data according to the id parameter
@param int $id
@return array|string
@throws \GuzzleHttp\Exception\GuzzleException | [
"Gets",
"the",
"street",
"data",
"according",
"to",
"the",
"id",
"parameter"
] | train | https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/Addresses/Secondary/Streets.php#L64-L70 |
willhoffmann/domuserp-php | src/Resources/Addresses/Secondary/Streets.php | Streets.save | public function save(DataReceiver $data)
{
$resource = self::$BASE_URI . '/' . $this->cityId . '/bairros/' . $this->neighborhoodId . '/logradouro';
return $this->execute(self::HTTP_POST, $resource, ['json' => $data->toArray()]);
} | php | public function save(DataReceiver $data)
{
$resource = self::$BASE_URI . '/' . $this->cityId . '/bairros/' . $this->neighborhoodId . '/logradouro';
return $this->execute(self::HTTP_POST, $resource, ['json' => $data->toArray()]);
} | [
"public",
"function",
"save",
"(",
"DataReceiver",
"$",
"data",
")",
"{",
"$",
"resource",
"=",
"self",
"::",
"$",
"BASE_URI",
".",
"'/'",
".",
"$",
"this",
"->",
"cityId",
".",
"'/bairros/'",
".",
"$",
"this",
"->",
"neighborhoodId",
".",
"'/logradouro'",
";",
"return",
"$",
"this",
"->",
"execute",
"(",
"self",
"::",
"HTTP_POST",
",",
"$",
"resource",
",",
"[",
"'json'",
"=>",
"$",
"data",
"->",
"toArray",
"(",
")",
"]",
")",
";",
"}"
] | Send the save request
@param DataReceiver $data
@return string
@throws \GuzzleHttp\Exception\GuzzleException | [
"Send",
"the",
"save",
"request"
] | train | https://github.com/willhoffmann/domuserp-php/blob/44e77a4f02b0252bc26cae4c0e6b2b7d578f10a6/src/Resources/Addresses/Secondary/Streets.php#L89-L93 |
Eresus/EresusCMS | src/core/Event/Dispatcher.php | Eresus_Event_Dispatcher.addListener | public function addListener($eventName, $listener, $priority = 0)
{
$eventName = strval($eventName);
if (!is_callable($listener))
{
throw Eresus_Exception_InvalidArgumentType::factory(__METHOD__, 2, 'callable',
$listener);
}
if (!array_key_exists($eventName, $this->listeners))
{
$this->listeners[$eventName] = array();
}
if (!array_key_exists($priority, $this->listeners[$eventName]))
{
$this->listeners[$eventName][$priority] = array();
}
$this->listeners[$eventName][$priority] []= $listener;
} | php | public function addListener($eventName, $listener, $priority = 0)
{
$eventName = strval($eventName);
if (!is_callable($listener))
{
throw Eresus_Exception_InvalidArgumentType::factory(__METHOD__, 2, 'callable',
$listener);
}
if (!array_key_exists($eventName, $this->listeners))
{
$this->listeners[$eventName] = array();
}
if (!array_key_exists($priority, $this->listeners[$eventName]))
{
$this->listeners[$eventName][$priority] = array();
}
$this->listeners[$eventName][$priority] []= $listener;
} | [
"public",
"function",
"addListener",
"(",
"$",
"eventName",
",",
"$",
"listener",
",",
"$",
"priority",
"=",
"0",
")",
"{",
"$",
"eventName",
"=",
"strval",
"(",
"$",
"eventName",
")",
";",
"if",
"(",
"!",
"is_callable",
"(",
"$",
"listener",
")",
")",
"{",
"throw",
"Eresus_Exception_InvalidArgumentType",
"::",
"factory",
"(",
"__METHOD__",
",",
"2",
",",
"'callable'",
",",
"$",
"listener",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"eventName",
",",
"$",
"this",
"->",
"listeners",
")",
")",
"{",
"$",
"this",
"->",
"listeners",
"[",
"$",
"eventName",
"]",
"=",
"array",
"(",
")",
";",
"}",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"priority",
",",
"$",
"this",
"->",
"listeners",
"[",
"$",
"eventName",
"]",
")",
")",
"{",
"$",
"this",
"->",
"listeners",
"[",
"$",
"eventName",
"]",
"[",
"$",
"priority",
"]",
"=",
"array",
"(",
")",
";",
"}",
"$",
"this",
"->",
"listeners",
"[",
"$",
"eventName",
"]",
"[",
"$",
"priority",
"]",
"[",
"]",
"=",
"$",
"listener",
";",
"}"
] | Регистрирует подписчика события
@param string $eventName имя события
@param callable $listener подписчик
@param int $priority приоритет (чем больше, тем раньше будет вызван этот подписчик)
@throws Eresus_Exception_InvalidArgumentType
@since 3.01 | [
"Регистрирует",
"подписчика",
"события"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Event/Dispatcher.php#L55-L73 |
Eresus/EresusCMS | src/core/Event/Dispatcher.php | Eresus_Event_Dispatcher.dispatch | public function dispatch($eventName, Eresus_Event $event = null)
{
if (!array_key_exists($eventName, $this->listeners))
{
return;
}
if (null === $event)
{
$event = new Eresus_Event();
}
$event->setName($eventName);
krsort($this->listeners[$eventName]);
foreach ($this->listeners[$eventName] as $listeners)
{
foreach ($listeners as $listener)
{
call_user_func($listener, $event);
if ($event->isPropagationStopped())
{
break 2;
}
}
}
} | php | public function dispatch($eventName, Eresus_Event $event = null)
{
if (!array_key_exists($eventName, $this->listeners))
{
return;
}
if (null === $event)
{
$event = new Eresus_Event();
}
$event->setName($eventName);
krsort($this->listeners[$eventName]);
foreach ($this->listeners[$eventName] as $listeners)
{
foreach ($listeners as $listener)
{
call_user_func($listener, $event);
if ($event->isPropagationStopped())
{
break 2;
}
}
}
} | [
"public",
"function",
"dispatch",
"(",
"$",
"eventName",
",",
"Eresus_Event",
"$",
"event",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"array_key_exists",
"(",
"$",
"eventName",
",",
"$",
"this",
"->",
"listeners",
")",
")",
"{",
"return",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"event",
")",
"{",
"$",
"event",
"=",
"new",
"Eresus_Event",
"(",
")",
";",
"}",
"$",
"event",
"->",
"setName",
"(",
"$",
"eventName",
")",
";",
"krsort",
"(",
"$",
"this",
"->",
"listeners",
"[",
"$",
"eventName",
"]",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"listeners",
"[",
"$",
"eventName",
"]",
"as",
"$",
"listeners",
")",
"{",
"foreach",
"(",
"$",
"listeners",
"as",
"$",
"listener",
")",
"{",
"call_user_func",
"(",
"$",
"listener",
",",
"$",
"event",
")",
";",
"if",
"(",
"$",
"event",
"->",
"isPropagationStopped",
"(",
")",
")",
"{",
"break",
"2",
";",
"}",
"}",
"}",
"}"
] | Отправляет событие подписчикам
@param string $eventName имя события
@param Eresus_Event $event опциональный объект события
@since 3.01 | [
"Отправляет",
"событие",
"подписчикам"
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/Event/Dispatcher.php#L83-L110 |
zhouyl/mellivora | Mellivora/Support/MessageBag.php | MessageBag.has | public function has($key)
{
if (is_null($key)) {
return $this->any();
}
$keys = is_array($key) ? $key : func_get_args();
foreach ($keys as $key) {
if ($this->first($key) === '') {
return false;
}
}
return true;
} | php | public function has($key)
{
if (is_null($key)) {
return $this->any();
}
$keys = is_array($key) ? $key : func_get_args();
foreach ($keys as $key) {
if ($this->first($key) === '') {
return false;
}
}
return true;
} | [
"public",
"function",
"has",
"(",
"$",
"key",
")",
"{",
"if",
"(",
"is_null",
"(",
"$",
"key",
")",
")",
"{",
"return",
"$",
"this",
"->",
"any",
"(",
")",
";",
"}",
"$",
"keys",
"=",
"is_array",
"(",
"$",
"key",
")",
"?",
"$",
"key",
":",
"func_get_args",
"(",
")",
";",
"foreach",
"(",
"$",
"keys",
"as",
"$",
"key",
")",
"{",
"if",
"(",
"$",
"this",
"->",
"first",
"(",
"$",
"key",
")",
"===",
"''",
")",
"{",
"return",
"false",
";",
"}",
"}",
"return",
"true",
";",
"}"
] | Determine if messages exist for all of the given keys.
@param array|string $key
@return bool | [
"Determine",
"if",
"messages",
"exist",
"for",
"all",
"of",
"the",
"given",
"keys",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Support/MessageBag.php#L109-L124 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx.getConfig | public function getConfig($name = null)
{
if (!is_null($name)) {
if (isset($this->_config[$name])) {
return $this->_config[$name];
} else {
return null;
}
}
return $this->_config;
} | php | public function getConfig($name = null)
{
if (!is_null($name)) {
if (isset($this->_config[$name])) {
return $this->_config[$name];
} else {
return null;
}
}
return $this->_config;
} | [
"public",
"function",
"getConfig",
"(",
"$",
"name",
"=",
"null",
")",
"{",
"if",
"(",
"!",
"is_null",
"(",
"$",
"name",
")",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"this",
"->",
"_config",
"[",
"$",
"name",
"]",
")",
")",
"{",
"return",
"$",
"this",
"->",
"_config",
"[",
"$",
"name",
"]",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}",
"return",
"$",
"this",
"->",
"_config",
";",
"}"
] | 获取微信配置.
@param string $name 配置名称
@return string|array | [
"获取微信配置",
"."
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L37-L48 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx.getCachedValue | public function getCachedValue($key, $call = null)
{
// 从自己配置中取出未过期数据
if ($this->getConfig($key) and $this->getConfig("{$key}_expiresed_at") > time()) {
return $this->getConfig($key);
}
// 自己的配置中没有就从缓存文件中取
$prefix = $this->getConfig('file_prefix');
$cacheFile = $this->getConfig('dataPath')."/{$prefix}{$key}_cache.json"; // 缓存文件名
$result = $this->_getCache($cacheFile);
// 缓存文件也没有或者过期了,就从闭包获取
if (!$result or !isset($result[$key]) and !is_null($call)) {
$result = $call();
// 获取成功了写入缓存文件
if ($result and isset($result[$key])) {
$result['time'] = time();
$result['expires_in'] = 6200; // 6200 秒就更新
file_put_contents($cacheFile, json_encode($result));
}
}
// 更新自己的配置并返回
if ($result and isset($result[$key])) {
$this->_config[$key] = $result[$key];
$this->_config["{$key}_expiresed_at"] = $result['expires_in'] + $result['time'];
return $this->getConfig($key);
}
return null;
} | php | public function getCachedValue($key, $call = null)
{
// 从自己配置中取出未过期数据
if ($this->getConfig($key) and $this->getConfig("{$key}_expiresed_at") > time()) {
return $this->getConfig($key);
}
// 自己的配置中没有就从缓存文件中取
$prefix = $this->getConfig('file_prefix');
$cacheFile = $this->getConfig('dataPath')."/{$prefix}{$key}_cache.json"; // 缓存文件名
$result = $this->_getCache($cacheFile);
// 缓存文件也没有或者过期了,就从闭包获取
if (!$result or !isset($result[$key]) and !is_null($call)) {
$result = $call();
// 获取成功了写入缓存文件
if ($result and isset($result[$key])) {
$result['time'] = time();
$result['expires_in'] = 6200; // 6200 秒就更新
file_put_contents($cacheFile, json_encode($result));
}
}
// 更新自己的配置并返回
if ($result and isset($result[$key])) {
$this->_config[$key] = $result[$key];
$this->_config["{$key}_expiresed_at"] = $result['expires_in'] + $result['time'];
return $this->getConfig($key);
}
return null;
} | [
"public",
"function",
"getCachedValue",
"(",
"$",
"key",
",",
"$",
"call",
"=",
"null",
")",
"{",
"// 从自己配置中取出未过期数据",
"if",
"(",
"$",
"this",
"->",
"getConfig",
"(",
"$",
"key",
")",
"and",
"$",
"this",
"->",
"getConfig",
"(",
"\"{$key}_expiresed_at\"",
")",
">",
"time",
"(",
")",
")",
"{",
"return",
"$",
"this",
"->",
"getConfig",
"(",
"$",
"key",
")",
";",
"}",
"// 自己的配置中没有就从缓存文件中取",
"$",
"prefix",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'file_prefix'",
")",
";",
"$",
"cacheFile",
"=",
"$",
"this",
"->",
"getConfig",
"(",
"'dataPath'",
")",
".",
"\"/{$prefix}{$key}_cache.json\"",
";",
"// 缓存文件名",
"$",
"result",
"=",
"$",
"this",
"->",
"_getCache",
"(",
"$",
"cacheFile",
")",
";",
"// 缓存文件也没有或者过期了,就从闭包获取",
"if",
"(",
"!",
"$",
"result",
"or",
"!",
"isset",
"(",
"$",
"result",
"[",
"$",
"key",
"]",
")",
"and",
"!",
"is_null",
"(",
"$",
"call",
")",
")",
"{",
"$",
"result",
"=",
"$",
"call",
"(",
")",
";",
"// 获取成功了写入缓存文件",
"if",
"(",
"$",
"result",
"and",
"isset",
"(",
"$",
"result",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"result",
"[",
"'time'",
"]",
"=",
"time",
"(",
")",
";",
"$",
"result",
"[",
"'expires_in'",
"]",
"=",
"6200",
";",
"// 6200 秒就更新",
"file_put_contents",
"(",
"$",
"cacheFile",
",",
"json_encode",
"(",
"$",
"result",
")",
")",
";",
"}",
"}",
"// 更新自己的配置并返回",
"if",
"(",
"$",
"result",
"and",
"isset",
"(",
"$",
"result",
"[",
"$",
"key",
"]",
")",
")",
"{",
"$",
"this",
"->",
"_config",
"[",
"$",
"key",
"]",
"=",
"$",
"result",
"[",
"$",
"key",
"]",
";",
"$",
"this",
"->",
"_config",
"[",
"\"{$key}_expiresed_at\"",
"]",
"=",
"$",
"result",
"[",
"'expires_in'",
"]",
"+",
"$",
"result",
"[",
"'time'",
"]",
";",
"return",
"$",
"this",
"->",
"getConfig",
"(",
"$",
"key",
")",
";",
"}",
"return",
"null",
";",
"}"
] | 获取缓存的值,access_token, jsapi_ticket
@param string $key 键
@param Closure $call 如果缓存获取不到备用
@return mixed 值 | [
"获取缓存的值,access_token",
"jsapi_ticket"
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L93-L126 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx.sendTextMsg | public function sendTextMsg($text, $toUserList, $agentId)
{
$to = $this->_parseUserList($toUserList);
$postData = [
'msgtype' => 'text',
'agentid' => (string) $agentId,
'text' => [
'content' => $text,
],
'safe' => $this->getConfig('safe'),
];
return $this->sendMsg(array_merge($to, $postData));
} | php | public function sendTextMsg($text, $toUserList, $agentId)
{
$to = $this->_parseUserList($toUserList);
$postData = [
'msgtype' => 'text',
'agentid' => (string) $agentId,
'text' => [
'content' => $text,
],
'safe' => $this->getConfig('safe'),
];
return $this->sendMsg(array_merge($to, $postData));
} | [
"public",
"function",
"sendTextMsg",
"(",
"$",
"text",
",",
"$",
"toUserList",
",",
"$",
"agentId",
")",
"{",
"$",
"to",
"=",
"$",
"this",
"->",
"_parseUserList",
"(",
"$",
"toUserList",
")",
";",
"$",
"postData",
"=",
"[",
"'msgtype'",
"=>",
"'text'",
",",
"'agentid'",
"=>",
"(",
"string",
")",
"$",
"agentId",
",",
"'text'",
"=>",
"[",
"'content'",
"=>",
"$",
"text",
",",
"]",
",",
"'safe'",
"=>",
"$",
"this",
"->",
"getConfig",
"(",
"'safe'",
")",
",",
"]",
";",
"return",
"$",
"this",
"->",
"sendMsg",
"(",
"array_merge",
"(",
"$",
"to",
",",
"$",
"postData",
")",
")",
";",
"}"
] | 发送文本消息.
@param string $text 要发送的内容
@param array $toUserList 发送给的对象例
[
'touser' => ['userid1', 'userid2'], // 可选,或者字符串形式 'userid1|userid2',下同,@all,则向关注该企业应用的全部成员发送
'topart' => ['partid1', 'partid1'],
'totag' => ['tag1', 'tag2'],
]
参考 http://qydev.weixin.qq.com/wiki/index.php?title=%E6%B6%88%E6%81%AF%E7%B1%BB%E5%9E%8B%E5%8F%8A%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F#text.E6.B6.88.E6.81.AF
@param string $agentId 企业应用的ID
@return array json 参考 http://qydev.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E | [
"发送文本消息",
"."
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L143-L156 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx.sendNewsMsg | public function sendNewsMsg($articles, $toUserList, $agentId)
{
$to = $this->_parseUserList($toUserList);
$postData = [
'msgtype' => 'news',
'agentid' => (string) $agentId,
'news' => [
'articles' => $articles,
],
'safe' => $this->getConfig('safe'),
];
return $this->sendMsg(array_merge($to, $postData));
} | php | public function sendNewsMsg($articles, $toUserList, $agentId)
{
$to = $this->_parseUserList($toUserList);
$postData = [
'msgtype' => 'news',
'agentid' => (string) $agentId,
'news' => [
'articles' => $articles,
],
'safe' => $this->getConfig('safe'),
];
return $this->sendMsg(array_merge($to, $postData));
} | [
"public",
"function",
"sendNewsMsg",
"(",
"$",
"articles",
",",
"$",
"toUserList",
",",
"$",
"agentId",
")",
"{",
"$",
"to",
"=",
"$",
"this",
"->",
"_parseUserList",
"(",
"$",
"toUserList",
")",
";",
"$",
"postData",
"=",
"[",
"'msgtype'",
"=>",
"'news'",
",",
"'agentid'",
"=>",
"(",
"string",
")",
"$",
"agentId",
",",
"'news'",
"=>",
"[",
"'articles'",
"=>",
"$",
"articles",
",",
"]",
",",
"'safe'",
"=>",
"$",
"this",
"->",
"getConfig",
"(",
"'safe'",
")",
",",
"]",
";",
"return",
"$",
"this",
"->",
"sendMsg",
"(",
"array_merge",
"(",
"$",
"to",
",",
"$",
"postData",
")",
")",
";",
"}"
] | 发送 News 消息.
@param array $articles 要发送的文章
@param array $toUserList 发送给的对象例
[
'touser' => ['userid1', 'userid2'], // 可选,或者字符串形式 'userid1|userid2',下同,@all,则向关注该企业应用的全部成员发送
'topart' => ['partid1', 'partid1'],
'totag' => ['tag1', 'tag2'],
]
参考 http://qydev.weixin.qq.com/wiki/index.php?title=%E6%B6%88%E6%81%AF%E7%B1%BB%E5%9E%8B%E5%8F%8A%E6%95%B0%E6%8D%AE%E6%A0%BC%E5%BC%8F#text.E6.B6.88.E6.81.AF
@param string $agentId 企业应用的ID
@return string 腾讯服务器返回的 json 参考 http://qydev.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E | [
"发送",
"News",
"消息",
"."
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L173-L186 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx.sendMsg | public function sendMsg($msg)
{
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token='
.$this->getAccessToken();
$postStr = json_encode($msg, JSON_UNESCAPED_UNICODE);
return $this->_curl($apiUrl, $postStr, 'post');
} | php | public function sendMsg($msg)
{
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token='
.$this->getAccessToken();
$postStr = json_encode($msg, JSON_UNESCAPED_UNICODE);
return $this->_curl($apiUrl, $postStr, 'post');
} | [
"public",
"function",
"sendMsg",
"(",
"$",
"msg",
")",
"{",
"$",
"apiUrl",
"=",
"'https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token='",
".",
"$",
"this",
"->",
"getAccessToken",
"(",
")",
";",
"$",
"postStr",
"=",
"json_encode",
"(",
"$",
"msg",
",",
"JSON_UNESCAPED_UNICODE",
")",
";",
"return",
"$",
"this",
"->",
"_curl",
"(",
"$",
"apiUrl",
",",
"$",
"postStr",
",",
"'post'",
")",
";",
"}"
] | 发送消息.
@param array $msg 要发送的内容 json
@return array 腾讯服务器返回的 json 参考 http://qydev.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E | [
"发送消息",
"."
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L215-L222 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx.getDepartments | public function getDepartments($departmentId)
{
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/department/list';
$result = $this->_curl($apiUrl, [
'access_token' => $this->getAccessToken(),
'id' => $departmentId,
]);
return ($result and isset($result['department'])) ? $result['department'] : null;
} | php | public function getDepartments($departmentId)
{
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/department/list';
$result = $this->_curl($apiUrl, [
'access_token' => $this->getAccessToken(),
'id' => $departmentId,
]);
return ($result and isset($result['department'])) ? $result['department'] : null;
} | [
"public",
"function",
"getDepartments",
"(",
"$",
"departmentId",
")",
"{",
"$",
"apiUrl",
"=",
"'https://qyapi.weixin.qq.com/cgi-bin/department/list'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"_curl",
"(",
"$",
"apiUrl",
",",
"[",
"'access_token'",
"=>",
"$",
"this",
"->",
"getAccessToken",
"(",
")",
",",
"'id'",
"=>",
"$",
"departmentId",
",",
"]",
")",
";",
"return",
"(",
"$",
"result",
"and",
"isset",
"(",
"$",
"result",
"[",
"'department'",
"]",
")",
")",
"?",
"$",
"result",
"[",
"'department'",
"]",
":",
"null",
";",
"}"
] | 获取部门列表.
@param string $departmentId 部门ID
@return array 获取到的数据 | [
"获取部门列表",
"."
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L231-L241 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx.getDepartmentMembers | public function getDepartmentMembers($departmentId, $fetchChild = false, $fetchDetail = false, $status = 0)
{
$fetchChild = (int) $fetchChild;
$apiUrl = $fetchDetail
? 'https://qyapi.weixin.qq.com/cgi-bin/user/list'
: 'https://qyapi.weixin.qq.com/cgi-bin/user/simplelist';
$result = $this->_curl($apiUrl, [
'access_token' => $this->getAccessToken(),
'department_id' => $departmentId,
'fetch_child' => $fetchChild,
'status' => $status,
]);
return ($result and isset($result['userlist'])) ? $result['userlist'] : null;
} | php | public function getDepartmentMembers($departmentId, $fetchChild = false, $fetchDetail = false, $status = 0)
{
$fetchChild = (int) $fetchChild;
$apiUrl = $fetchDetail
? 'https://qyapi.weixin.qq.com/cgi-bin/user/list'
: 'https://qyapi.weixin.qq.com/cgi-bin/user/simplelist';
$result = $this->_curl($apiUrl, [
'access_token' => $this->getAccessToken(),
'department_id' => $departmentId,
'fetch_child' => $fetchChild,
'status' => $status,
]);
return ($result and isset($result['userlist'])) ? $result['userlist'] : null;
} | [
"public",
"function",
"getDepartmentMembers",
"(",
"$",
"departmentId",
",",
"$",
"fetchChild",
"=",
"false",
",",
"$",
"fetchDetail",
"=",
"false",
",",
"$",
"status",
"=",
"0",
")",
"{",
"$",
"fetchChild",
"=",
"(",
"int",
")",
"$",
"fetchChild",
";",
"$",
"apiUrl",
"=",
"$",
"fetchDetail",
"?",
"'https://qyapi.weixin.qq.com/cgi-bin/user/list'",
":",
"'https://qyapi.weixin.qq.com/cgi-bin/user/simplelist'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"_curl",
"(",
"$",
"apiUrl",
",",
"[",
"'access_token'",
"=>",
"$",
"this",
"->",
"getAccessToken",
"(",
")",
",",
"'department_id'",
"=>",
"$",
"departmentId",
",",
"'fetch_child'",
"=>",
"$",
"fetchChild",
",",
"'status'",
"=>",
"$",
"status",
",",
"]",
")",
";",
"return",
"(",
"$",
"result",
"and",
"isset",
"(",
"$",
"result",
"[",
"'userlist'",
"]",
")",
")",
"?",
"$",
"result",
"[",
"'userlist'",
"]",
":",
"null",
";",
"}"
] | 获取部门成员列表.
@param string $departmentId 部门ID
@param bool $fetchChild 是否递归获取子部门的成员
@param bool $fetchDetail 是否获取成员详情
@param int $status 0获取全部成员,1获取已关注成员列表
2获取禁用成员列表,4获取未关注成员列表。status可叠加
@return array 获取到的数据 | [
"获取部门成员列表",
"."
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L254-L269 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx.getTags | public function getTags()
{
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/tag/list';
$result = $this->_curl($apiUrl, [
'access_token' => $this->getAccessToken(),
]);
return ($result and isset($result['taglist'])) ? $result['taglist'] : null;
} | php | public function getTags()
{
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/tag/list';
$result = $this->_curl($apiUrl, [
'access_token' => $this->getAccessToken(),
]);
return ($result and isset($result['taglist'])) ? $result['taglist'] : null;
} | [
"public",
"function",
"getTags",
"(",
")",
"{",
"$",
"apiUrl",
"=",
"'https://qyapi.weixin.qq.com/cgi-bin/tag/list'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"_curl",
"(",
"$",
"apiUrl",
",",
"[",
"'access_token'",
"=>",
"$",
"this",
"->",
"getAccessToken",
"(",
")",
",",
"]",
")",
";",
"return",
"(",
"$",
"result",
"and",
"isset",
"(",
"$",
"result",
"[",
"'taglist'",
"]",
")",
")",
"?",
"$",
"result",
"[",
"'taglist'",
"]",
":",
"null",
";",
"}"
] | 获取标签列表.
@return array 获取到的数据 | [
"获取标签列表",
"."
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L276-L285 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx.getTagMembers | public function getTagMembers($tagId, $fetchDetail = false)
{
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/tag/get';
$result = $this->_curl($apiUrl, [
'access_token' => $this->getAccessToken(),
'tagid' => $tagId,
]);
if ($result and isset($result['userlist']) and isset($result['partylist'])) {
if ($fetchDetail) {
$result['userlist'] = array_map(function ($item) {
return $this->getUserInfo($item['userid']);
}, $result['userlist']);
}
return ['userlist' => $result['userlist'], 'partylist' => $result['partylist']];
}
return null;
} | php | public function getTagMembers($tagId, $fetchDetail = false)
{
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/tag/get';
$result = $this->_curl($apiUrl, [
'access_token' => $this->getAccessToken(),
'tagid' => $tagId,
]);
if ($result and isset($result['userlist']) and isset($result['partylist'])) {
if ($fetchDetail) {
$result['userlist'] = array_map(function ($item) {
return $this->getUserInfo($item['userid']);
}, $result['userlist']);
}
return ['userlist' => $result['userlist'], 'partylist' => $result['partylist']];
}
return null;
} | [
"public",
"function",
"getTagMembers",
"(",
"$",
"tagId",
",",
"$",
"fetchDetail",
"=",
"false",
")",
"{",
"$",
"apiUrl",
"=",
"'https://qyapi.weixin.qq.com/cgi-bin/tag/get'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"_curl",
"(",
"$",
"apiUrl",
",",
"[",
"'access_token'",
"=>",
"$",
"this",
"->",
"getAccessToken",
"(",
")",
",",
"'tagid'",
"=>",
"$",
"tagId",
",",
"]",
")",
";",
"if",
"(",
"$",
"result",
"and",
"isset",
"(",
"$",
"result",
"[",
"'userlist'",
"]",
")",
"and",
"isset",
"(",
"$",
"result",
"[",
"'partylist'",
"]",
")",
")",
"{",
"if",
"(",
"$",
"fetchDetail",
")",
"{",
"$",
"result",
"[",
"'userlist'",
"]",
"=",
"array_map",
"(",
"function",
"(",
"$",
"item",
")",
"{",
"return",
"$",
"this",
"->",
"getUserInfo",
"(",
"$",
"item",
"[",
"'userid'",
"]",
")",
";",
"}",
",",
"$",
"result",
"[",
"'userlist'",
"]",
")",
";",
"}",
"return",
"[",
"'userlist'",
"=>",
"$",
"result",
"[",
"'userlist'",
"]",
",",
"'partylist'",
"=>",
"$",
"result",
"[",
"'partylist'",
"]",
"]",
";",
"}",
"return",
"null",
";",
"}"
] | 获取标签成员列表,注意权限问题.
@param int $tagId 标签ID
@param bool $fetchDetail 是否获取成员详情
@link http://qydev.weixin.qq.com/wiki/index.php?title=%E7%AE%A1%E7%90%86%E6%A0%87%E7%AD%BE
@return array 获取到的数据 ['userlist', 'partylist'] | [
"获取标签成员列表,注意权限问题",
"."
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L297-L317 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx.getTagAllMembers | public function getTagAllMembers($tagId, $fetchDetail = false)
{
$tagMembers = $this->getTagMembers($tagId, $fetchDetail);
if (is_null($tagMembers)) {
return null;
}
return $tagMembers['userlist'] + array_reduce($tagMembers['partylist'], function ($result, $item) use ($fetchDetail) {
return $result + (array)$this->getDepartmentMembers($item, true, $fetchDetail);
}, []);
} | php | public function getTagAllMembers($tagId, $fetchDetail = false)
{
$tagMembers = $this->getTagMembers($tagId, $fetchDetail);
if (is_null($tagMembers)) {
return null;
}
return $tagMembers['userlist'] + array_reduce($tagMembers['partylist'], function ($result, $item) use ($fetchDetail) {
return $result + (array)$this->getDepartmentMembers($item, true, $fetchDetail);
}, []);
} | [
"public",
"function",
"getTagAllMembers",
"(",
"$",
"tagId",
",",
"$",
"fetchDetail",
"=",
"false",
")",
"{",
"$",
"tagMembers",
"=",
"$",
"this",
"->",
"getTagMembers",
"(",
"$",
"tagId",
",",
"$",
"fetchDetail",
")",
";",
"if",
"(",
"is_null",
"(",
"$",
"tagMembers",
")",
")",
"{",
"return",
"null",
";",
"}",
"return",
"$",
"tagMembers",
"[",
"'userlist'",
"]",
"+",
"array_reduce",
"(",
"$",
"tagMembers",
"[",
"'partylist'",
"]",
",",
"function",
"(",
"$",
"result",
",",
"$",
"item",
")",
"use",
"(",
"$",
"fetchDetail",
")",
"{",
"return",
"$",
"result",
"+",
"(",
"array",
")",
"$",
"this",
"->",
"getDepartmentMembers",
"(",
"$",
"item",
",",
"true",
",",
"$",
"fetchDetail",
")",
";",
"}",
",",
"[",
"]",
")",
";",
"}"
] | 获取标签所有成员,包括在部门的,可能会有重叠,注意权限问题
@param int $tagId 标签ID
@param bool $fetchDetail 是否获取成员详情
@return array|null 取得的数据 | [
"获取标签所有成员,包括在部门的,可能会有重叠,注意权限问题"
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L327-L337 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx.getUserId | public function getUserId($code)
{
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo';
$result = $this->_curl($apiUrl, [
'access_token' => $this->getAccessToken(),
'code' => $code,
]);
return ($result and isset($result['UserId'])) ? $result['UserId'] : null;
} | php | public function getUserId($code)
{
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo';
$result = $this->_curl($apiUrl, [
'access_token' => $this->getAccessToken(),
'code' => $code,
]);
return ($result and isset($result['UserId'])) ? $result['UserId'] : null;
} | [
"public",
"function",
"getUserId",
"(",
"$",
"code",
")",
"{",
"$",
"apiUrl",
"=",
"'https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"_curl",
"(",
"$",
"apiUrl",
",",
"[",
"'access_token'",
"=>",
"$",
"this",
"->",
"getAccessToken",
"(",
")",
",",
"'code'",
"=>",
"$",
"code",
",",
"]",
")",
";",
"return",
"(",
"$",
"result",
"and",
"isset",
"(",
"$",
"result",
"[",
"'UserId'",
"]",
")",
")",
"?",
"$",
"result",
"[",
"'UserId'",
"]",
":",
"null",
";",
"}"
] | 由 OAth 认证的 code 获取 userid.
@param string $code
@return string|null | [
"由",
"OAth",
"认证的",
"code",
"获取",
"userid",
"."
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L360-L370 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx.getUserInfo | public function getUserInfo($userid)
{
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/user/get';
if ($result = $this->_curl($apiUrl, [
'access_token' => $this->getAccessToken(),
'userid' => $userid,
])) {
unset($result['errcode'], $result['errmsg']);
return $result;
} else {
return null;
}
} | php | public function getUserInfo($userid)
{
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/user/get';
if ($result = $this->_curl($apiUrl, [
'access_token' => $this->getAccessToken(),
'userid' => $userid,
])) {
unset($result['errcode'], $result['errmsg']);
return $result;
} else {
return null;
}
} | [
"public",
"function",
"getUserInfo",
"(",
"$",
"userid",
")",
"{",
"$",
"apiUrl",
"=",
"'https://qyapi.weixin.qq.com/cgi-bin/user/get'",
";",
"if",
"(",
"$",
"result",
"=",
"$",
"this",
"->",
"_curl",
"(",
"$",
"apiUrl",
",",
"[",
"'access_token'",
"=>",
"$",
"this",
"->",
"getAccessToken",
"(",
")",
",",
"'userid'",
"=>",
"$",
"userid",
",",
"]",
")",
")",
"{",
"unset",
"(",
"$",
"result",
"[",
"'errcode'",
"]",
",",
"$",
"result",
"[",
"'errmsg'",
"]",
")",
";",
"return",
"$",
"result",
";",
"}",
"else",
"{",
"return",
"null",
";",
"}",
"}"
] | 获取某个用户的信息.
@param string $userid 腾讯关联的userid
@return array | [
"获取某个用户的信息",
"."
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L379-L392 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx.deleteUser | public function deleteUser($userid)
{
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/user/delete';
$result = $this->_curl($apiUrl, [
'access_token' => $this->getAccessToken(),
'userid' => $userid,
]);
return $result !== false;
} | php | public function deleteUser($userid)
{
$apiUrl = 'https://qyapi.weixin.qq.com/cgi-bin/user/delete';
$result = $this->_curl($apiUrl, [
'access_token' => $this->getAccessToken(),
'userid' => $userid,
]);
return $result !== false;
} | [
"public",
"function",
"deleteUser",
"(",
"$",
"userid",
")",
"{",
"$",
"apiUrl",
"=",
"'https://qyapi.weixin.qq.com/cgi-bin/user/delete'",
";",
"$",
"result",
"=",
"$",
"this",
"->",
"_curl",
"(",
"$",
"apiUrl",
",",
"[",
"'access_token'",
"=>",
"$",
"this",
"->",
"getAccessToken",
"(",
")",
",",
"'userid'",
"=>",
"$",
"userid",
",",
"]",
")",
";",
"return",
"$",
"result",
"!==",
"false",
";",
"}"
] | 删除某个用户.
@param string $userid 腾讯关联的userid
@return array | [
"删除某个用户",
"."
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L401-L411 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx.downloadMedia | public function downloadMedia($mediaId)
{
$result = $this->_curl("https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token={$this->getAccessToken()}&media_id={$mediaId}");
$match = [];
preg_match_all('/\nContent-disposition: ?attachment; ?filename="([^"]*?)"/ism', $result['head'], $match);
return [
'filename' => $match[1][0],
'content' => $result['body'],
];
} | php | public function downloadMedia($mediaId)
{
$result = $this->_curl("https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token={$this->getAccessToken()}&media_id={$mediaId}");
$match = [];
preg_match_all('/\nContent-disposition: ?attachment; ?filename="([^"]*?)"/ism', $result['head'], $match);
return [
'filename' => $match[1][0],
'content' => $result['body'],
];
} | [
"public",
"function",
"downloadMedia",
"(",
"$",
"mediaId",
")",
"{",
"$",
"result",
"=",
"$",
"this",
"->",
"_curl",
"(",
"\"https://qyapi.weixin.qq.com/cgi-bin/media/get?access_token={$this->getAccessToken()}&media_id={$mediaId}\"",
")",
";",
"$",
"match",
"=",
"[",
"]",
";",
"preg_match_all",
"(",
"'/\\nContent-disposition: ?attachment; ?filename=\"([^\"]*?)\"/ism'",
",",
"$",
"result",
"[",
"'head'",
"]",
",",
"$",
"match",
")",
";",
"return",
"[",
"'filename'",
"=>",
"$",
"match",
"[",
"1",
"]",
"[",
"0",
"]",
",",
"'content'",
"=>",
"$",
"result",
"[",
"'body'",
"]",
",",
"]",
";",
"}"
] | 媒体文件下载
@param $mediaId
@return array | [
"媒体文件下载"
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L455-L467 |
purocean/php-wechat-sdk | src/Qywx.php | Qywx._curl | private function _curl($url, $data = '', $method = 'get')
{
if (is_array($data)) {
$parStr = http_build_query($data);
} else {
$parStr = $data;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
//除get请求外默认为post
if (strtolower($method) == 'get') {
curl_setopt($ch, CURLOPT_URL, rtrim($url, '?') . '?' . $parStr);
} else {
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parStr);
}
$content = curl_exec($ch);
curl_close($ch);
//0是头部内容1是body内容
list($head, $body) = explode("\r\n\r\n", $content, 2);
if (! preg_match('/\ncontent-type: ?application\/json/ism', $head)) {
return [
'body' => $body,
'head' => $head
];
} else {
$result = json_decode($body, true);
if (isset($result['errcode']) and $result['errcode'] != 0) {
$this->_log("Error-{$method}-{$url}", $body, $data);
return false;
}
return $result;
}
} | php | private function _curl($url, $data = '', $method = 'get')
{
if (is_array($data)) {
$parStr = http_build_query($data);
} else {
$parStr = $data;
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
//除get请求外默认为post
if (strtolower($method) == 'get') {
curl_setopt($ch, CURLOPT_URL, rtrim($url, '?') . '?' . $parStr);
} else {
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $parStr);
}
$content = curl_exec($ch);
curl_close($ch);
//0是头部内容1是body内容
list($head, $body) = explode("\r\n\r\n", $content, 2);
if (! preg_match('/\ncontent-type: ?application\/json/ism', $head)) {
return [
'body' => $body,
'head' => $head
];
} else {
$result = json_decode($body, true);
if (isset($result['errcode']) and $result['errcode'] != 0) {
$this->_log("Error-{$method}-{$url}", $body, $data);
return false;
}
return $result;
}
} | [
"private",
"function",
"_curl",
"(",
"$",
"url",
",",
"$",
"data",
"=",
"''",
",",
"$",
"method",
"=",
"'get'",
")",
"{",
"if",
"(",
"is_array",
"(",
"$",
"data",
")",
")",
"{",
"$",
"parStr",
"=",
"http_build_query",
"(",
"$",
"data",
")",
";",
"}",
"else",
"{",
"$",
"parStr",
"=",
"$",
"data",
";",
"}",
"$",
"ch",
"=",
"curl_init",
"(",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_TIMEOUT",
",",
"30",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_RETURNTRANSFER",
",",
"1",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_HEADER",
",",
"1",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_BINARYTRANSFER",
",",
"1",
")",
";",
"//除get请求外默认为post",
"if",
"(",
"strtolower",
"(",
"$",
"method",
")",
"==",
"'get'",
")",
"{",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_URL",
",",
"rtrim",
"(",
"$",
"url",
",",
"'?'",
")",
".",
"'?'",
".",
"$",
"parStr",
")",
";",
"}",
"else",
"{",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_URL",
",",
"$",
"url",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_SSL_VERIFYPEER",
",",
"false",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_SSL_VERIFYHOST",
",",
"false",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POST",
",",
"1",
")",
";",
"curl_setopt",
"(",
"$",
"ch",
",",
"CURLOPT_POSTFIELDS",
",",
"$",
"parStr",
")",
";",
"}",
"$",
"content",
"=",
"curl_exec",
"(",
"$",
"ch",
")",
";",
"curl_close",
"(",
"$",
"ch",
")",
";",
"//0是头部内容1是body内容",
"list",
"(",
"$",
"head",
",",
"$",
"body",
")",
"=",
"explode",
"(",
"\"\\r\\n\\r\\n\"",
",",
"$",
"content",
",",
"2",
")",
";",
"if",
"(",
"!",
"preg_match",
"(",
"'/\\ncontent-type: ?application\\/json/ism'",
",",
"$",
"head",
")",
")",
"{",
"return",
"[",
"'body'",
"=>",
"$",
"body",
",",
"'head'",
"=>",
"$",
"head",
"]",
";",
"}",
"else",
"{",
"$",
"result",
"=",
"json_decode",
"(",
"$",
"body",
",",
"true",
")",
";",
"if",
"(",
"isset",
"(",
"$",
"result",
"[",
"'errcode'",
"]",
")",
"and",
"$",
"result",
"[",
"'errcode'",
"]",
"!=",
"0",
")",
"{",
"$",
"this",
"->",
"_log",
"(",
"\"Error-{$method}-{$url}\"",
",",
"$",
"body",
",",
"$",
"data",
")",
";",
"return",
"false",
";",
"}",
"return",
"$",
"result",
";",
"}",
"}"
] | 简化的 HTTP 通信函数.
@param string $url 目标 URL
@param array|string $data 发送的数据
@param string $method 发送方式
@return array|bool|mixed 获得的内容 | [
"简化的",
"HTTP",
"通信函数",
"."
] | train | https://github.com/purocean/php-wechat-sdk/blob/a369c4f8b8a24e54ecc505d0432b4479c0a9e827/src/Qywx.php#L497-L543 |
ShaoZeMing/laravel-merchant | src/Grid/Filter.php | Filter.conditions | public function conditions()
{
$inputs = array_dot(Input::all());
$inputs = array_filter($inputs, function ($input) {
return $input !== '' && !is_null($input);
});
if (empty($inputs)) {
return [];
}
$params = [];
foreach ($inputs as $key => $value) {
array_set($params, $key, $value);
}
$conditions = [];
$this->removeIDFilterIfNeeded();
foreach ($this->filters() as $filter) {
$conditions[] = $filter->condition($params);
}
return array_filter($conditions);
} | php | public function conditions()
{
$inputs = array_dot(Input::all());
$inputs = array_filter($inputs, function ($input) {
return $input !== '' && !is_null($input);
});
if (empty($inputs)) {
return [];
}
$params = [];
foreach ($inputs as $key => $value) {
array_set($params, $key, $value);
}
$conditions = [];
$this->removeIDFilterIfNeeded();
foreach ($this->filters() as $filter) {
$conditions[] = $filter->condition($params);
}
return array_filter($conditions);
} | [
"public",
"function",
"conditions",
"(",
")",
"{",
"$",
"inputs",
"=",
"array_dot",
"(",
"Input",
"::",
"all",
"(",
")",
")",
";",
"$",
"inputs",
"=",
"array_filter",
"(",
"$",
"inputs",
",",
"function",
"(",
"$",
"input",
")",
"{",
"return",
"$",
"input",
"!==",
"''",
"&&",
"!",
"is_null",
"(",
"$",
"input",
")",
";",
"}",
")",
";",
"if",
"(",
"empty",
"(",
"$",
"inputs",
")",
")",
"{",
"return",
"[",
"]",
";",
"}",
"$",
"params",
"=",
"[",
"]",
";",
"foreach",
"(",
"$",
"inputs",
"as",
"$",
"key",
"=>",
"$",
"value",
")",
"{",
"array_set",
"(",
"$",
"params",
",",
"$",
"key",
",",
"$",
"value",
")",
";",
"}",
"$",
"conditions",
"=",
"[",
"]",
";",
"$",
"this",
"->",
"removeIDFilterIfNeeded",
"(",
")",
";",
"foreach",
"(",
"$",
"this",
"->",
"filters",
"(",
")",
"as",
"$",
"filter",
")",
"{",
"$",
"conditions",
"[",
"]",
"=",
"$",
"filter",
"->",
"condition",
"(",
"$",
"params",
")",
";",
"}",
"return",
"array_filter",
"(",
"$",
"conditions",
")",
";",
"}"
] | Get all conditions of the filters.
@return array | [
"Get",
"all",
"conditions",
"of",
"the",
"filters",
"."
] | train | https://github.com/ShaoZeMing/laravel-merchant/blob/20801b1735e7832a6e58b37c2c391328f8d626fa/src/Grid/Filter.php#L127-L154 |
gitiki/Gitiki | src/RouteCollection.php | RouteCollection.addBefore | public function addBefore($before, $name, SymfonyRoute $route)
{
$newRoute = $route;
foreach ($this->all() as $routeName => $route) {
if (null !== $newRoute && $before === $routeName) {
$this->add($name, $newRoute);
$newRoute = null;
}
if (null === $newRoute) {
// move the existing route onto the end of collection
$this->add($routeName, $route);
}
}
if (null !== $newRoute) {
throw new \InvalidArgumentException(sprintf('The route "%s" cannot be added before "%s", because the route "%2$s" was not found.', $name, $before));
}
} | php | public function addBefore($before, $name, SymfonyRoute $route)
{
$newRoute = $route;
foreach ($this->all() as $routeName => $route) {
if (null !== $newRoute && $before === $routeName) {
$this->add($name, $newRoute);
$newRoute = null;
}
if (null === $newRoute) {
// move the existing route onto the end of collection
$this->add($routeName, $route);
}
}
if (null !== $newRoute) {
throw new \InvalidArgumentException(sprintf('The route "%s" cannot be added before "%s", because the route "%2$s" was not found.', $name, $before));
}
} | [
"public",
"function",
"addBefore",
"(",
"$",
"before",
",",
"$",
"name",
",",
"SymfonyRoute",
"$",
"route",
")",
"{",
"$",
"newRoute",
"=",
"$",
"route",
";",
"foreach",
"(",
"$",
"this",
"->",
"all",
"(",
")",
"as",
"$",
"routeName",
"=>",
"$",
"route",
")",
"{",
"if",
"(",
"null",
"!==",
"$",
"newRoute",
"&&",
"$",
"before",
"===",
"$",
"routeName",
")",
"{",
"$",
"this",
"->",
"add",
"(",
"$",
"name",
",",
"$",
"newRoute",
")",
";",
"$",
"newRoute",
"=",
"null",
";",
"}",
"if",
"(",
"null",
"===",
"$",
"newRoute",
")",
"{",
"// move the existing route onto the end of collection",
"$",
"this",
"->",
"add",
"(",
"$",
"routeName",
",",
"$",
"route",
")",
";",
"}",
"}",
"if",
"(",
"null",
"!==",
"$",
"newRoute",
")",
"{",
"throw",
"new",
"\\",
"InvalidArgumentException",
"(",
"sprintf",
"(",
"'The route \"%s\" cannot be added before \"%s\", because the route \"%2$s\" was not found.'",
",",
"$",
"name",
",",
"$",
"before",
")",
")",
";",
"}",
"}"
] | Adds a route before another.
@param string $before The before route name
@param string $name The route name
@param Route $route A Route instance
@throws \InvalidArgumentException If the before route name cannot be found | [
"Adds",
"a",
"route",
"before",
"another",
"."
] | train | https://github.com/gitiki/Gitiki/blob/f017672d4f5d0ef6015fad44724f05e3b1f08463/src/RouteCollection.php#L20-L38 |
hametuha/wpametu | src/WPametu/Utility/IteratorWalker.php | IteratorWalker.key_search | public function key_search( array $array, $key, $value ) {
foreach ( $array as $key => $a ) {
if ( isset( $a[ $key ] ) && $a[ $key ] == $value ) {
return $key;
}
}
return false;
} | php | public function key_search( array $array, $key, $value ) {
foreach ( $array as $key => $a ) {
if ( isset( $a[ $key ] ) && $a[ $key ] == $value ) {
return $key;
}
}
return false;
} | [
"public",
"function",
"key_search",
"(",
"array",
"$",
"array",
",",
"$",
"key",
",",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"a",
")",
"{",
"if",
"(",
"isset",
"(",
"$",
"a",
"[",
"$",
"key",
"]",
")",
"&&",
"$",
"a",
"[",
"$",
"key",
"]",
"==",
"$",
"value",
")",
"{",
"return",
"$",
"key",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Get index of array member with specified key
@param array $array
@param string $key
@param mixed $value
@return false|int|string | [
"Get",
"index",
"of",
"array",
"member",
"with",
"specified",
"key"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/Utility/IteratorWalker.php#L36-L44 |
hametuha/wpametu | src/WPametu/Utility/IteratorWalker.php | IteratorWalker.prop_search | public function prop_search( array $array, $property, $value ) {
foreach ( $array as $key => $a ) {
if ( property_exists( $a, $property ) && $a->{$property} == $value ) {
return $key;
}
}
return false;
} | php | public function prop_search( array $array, $property, $value ) {
foreach ( $array as $key => $a ) {
if ( property_exists( $a, $property ) && $a->{$property} == $value ) {
return $key;
}
}
return false;
} | [
"public",
"function",
"prop_search",
"(",
"array",
"$",
"array",
",",
"$",
"property",
",",
"$",
"value",
")",
"{",
"foreach",
"(",
"$",
"array",
"as",
"$",
"key",
"=>",
"$",
"a",
")",
"{",
"if",
"(",
"property_exists",
"(",
"$",
"a",
",",
"$",
"property",
")",
"&&",
"$",
"a",
"->",
"{",
"$",
"property",
"}",
"==",
"$",
"value",
")",
"{",
"return",
"$",
"key",
";",
"}",
"}",
"return",
"false",
";",
"}"
] | Search array member with specified property
@param array $array
@param string $property
@param mixed $value
@return false|int|string | [
"Search",
"array",
"member",
"with",
"specified",
"property"
] | train | https://github.com/hametuha/wpametu/blob/0939373800815a8396291143d2a57967340da5aa/src/WPametu/Utility/IteratorWalker.php#L68-L76 |
krakphp/job | src/Kernel.php | Kernel.queueConfigs | private function queueConfigs() {
$config = $this->getConfig();
if (!isset($config['schedulers'])) {
yield $config;
return;
}
foreach ($config['schedulers'] as $child_config) {
yield mergeConfigOptions($config, $child_config);
}
} | php | private function queueConfigs() {
$config = $this->getConfig();
if (!isset($config['schedulers'])) {
yield $config;
return;
}
foreach ($config['schedulers'] as $child_config) {
yield mergeConfigOptions($config, $child_config);
}
} | [
"private",
"function",
"queueConfigs",
"(",
")",
"{",
"$",
"config",
"=",
"$",
"this",
"->",
"getConfig",
"(",
")",
";",
"if",
"(",
"!",
"isset",
"(",
"$",
"config",
"[",
"'schedulers'",
"]",
")",
")",
"{",
"yield",
"$",
"config",
";",
"return",
";",
"}",
"foreach",
"(",
"$",
"config",
"[",
"'schedulers'",
"]",
"as",
"$",
"child_config",
")",
"{",
"yield",
"mergeConfigOptions",
"(",
"$",
"config",
",",
"$",
"child_config",
")",
";",
"}",
"}"
] | return only the normalized queue configurations | [
"return",
"only",
"the",
"normalized",
"queue",
"configurations"
] | train | https://github.com/krakphp/job/blob/0c16020c1baa13d91f819ecba8334861ba7c4d6c/src/Kernel.php#L65-L75 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/rfc822_digest_parser.php | ezcMailRfc822DigestParser.parseBody | public function parseBody( $line )
{
$this->mailParser->parseBody( $line );
$this->size += strlen( $line );
} | php | public function parseBody( $line )
{
$this->mailParser->parseBody( $line );
$this->size += strlen( $line );
} | [
"public",
"function",
"parseBody",
"(",
"$",
"line",
")",
"{",
"$",
"this",
"->",
"mailParser",
"->",
"parseBody",
"(",
"$",
"line",
")",
";",
"$",
"this",
"->",
"size",
"+=",
"strlen",
"(",
"$",
"line",
")",
";",
"}"
] | Parses each line of the digest body.
Every line is part of the digested mail. It is sent directly to the mail parser.
@param string $line | [
"Parses",
"each",
"line",
"of",
"the",
"digest",
"body",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/rfc822_digest_parser.php#L63-L67 |
Eresus/EresusCMS | src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/rfc822_digest_parser.php | ezcMailRfc822DigestParser.finish | public function finish()
{
$digest = new ezcMailRfc822Digest( $this->mailParser->finish() );
ezcMailPartParser::parsePartHeaders( $this->headers, $digest );
$digest->size = $this->size;
return $digest;
} | php | public function finish()
{
$digest = new ezcMailRfc822Digest( $this->mailParser->finish() );
ezcMailPartParser::parsePartHeaders( $this->headers, $digest );
$digest->size = $this->size;
return $digest;
} | [
"public",
"function",
"finish",
"(",
")",
"{",
"$",
"digest",
"=",
"new",
"ezcMailRfc822Digest",
"(",
"$",
"this",
"->",
"mailParser",
"->",
"finish",
"(",
")",
")",
";",
"ezcMailPartParser",
"::",
"parsePartHeaders",
"(",
"$",
"this",
"->",
"headers",
",",
"$",
"digest",
")",
";",
"$",
"digest",
"->",
"size",
"=",
"$",
"this",
"->",
"size",
";",
"return",
"$",
"digest",
";",
"}"
] | Returns a ezcMailRfc822Digest with the digested mail in it.
@return ezcMailRfc822Digest | [
"Returns",
"a",
"ezcMailRfc822Digest",
"with",
"the",
"digested",
"mail",
"in",
"it",
"."
] | train | https://github.com/Eresus/EresusCMS/blob/b0afc661105f0a2f65d49abac13956cc93c5188d/src/core/framework/core/3rdparty/ezcomponents/Mail/src/parser/parts/rfc822_digest_parser.php#L74-L80 |
zhouyl/mellivora | Mellivora/Database/Schema/Grammars/PostgresGrammar.php | PostgresGrammar.typeEnum | protected function typeEnum(Fluent $column)
{
$allowed = array_map(function ($a) {
return "'{$a}'";
}, $column->allowed);
return "varchar(255) check (\"{$column->name}\" in (" . implode(', ', $allowed) . '))';
} | php | protected function typeEnum(Fluent $column)
{
$allowed = array_map(function ($a) {
return "'{$a}'";
}, $column->allowed);
return "varchar(255) check (\"{$column->name}\" in (" . implode(', ', $allowed) . '))';
} | [
"protected",
"function",
"typeEnum",
"(",
"Fluent",
"$",
"column",
")",
"{",
"$",
"allowed",
"=",
"array_map",
"(",
"function",
"(",
"$",
"a",
")",
"{",
"return",
"\"'{$a}'\"",
";",
"}",
",",
"$",
"column",
"->",
"allowed",
")",
";",
"return",
"\"varchar(255) check (\\\"{$column->name}\\\" in (\"",
".",
"implode",
"(",
"', '",
",",
"$",
"allowed",
")",
".",
"'))'",
";",
"}"
] | Create the column definition for an enum type.
@param \Mellivora\Support\Fluent $column
@return string | [
"Create",
"the",
"column",
"definition",
"for",
"an",
"enum",
"type",
"."
] | train | https://github.com/zhouyl/mellivora/blob/79f844c5c9c25ffbe18d142062e9bc3df00b36a1/Mellivora/Database/Schema/Grammars/PostgresGrammar.php#L449-L456 |
xiewulong/yii2-fileupload | oss/libs/guzzle/http/Guzzle/Http/Curl/RequestMediator.php | RequestMediator.receiveResponseHeader | public function receiveResponseHeader($curl, $header)
{
static $normalize = array("\r", "\n");
$length = strlen($header);
$header = str_replace($normalize, '', $header);
if (strpos($header, 'HTTP/') === 0) {
$startLine = explode(' ', $header, 3);
$code = $startLine[1];
$status = isset($startLine[2]) ? $startLine[2] : '';
// Only download the body of the response to the specified response
// body when a successful response is received.
if ($code >= 200 && $code < 300) {
$body = $this->request->getResponseBody();
} else {
$body = EntityBody::factory();
}
$response = new Response($code, null, $body);
$response->setStatus($code, $status);
$this->request->startResponse($response);
$this->request->dispatch('request.receive.status_line', array(
'request' => $this,
'line' => $header,
'status_code' => $code,
'reason_phrase' => $status
));
} elseif ($pos = strpos($header, ':')) {
$this->request->getResponse()->addHeader(
trim(substr($header, 0, $pos)),
trim(substr($header, $pos + 1))
);
}
return $length;
} | php | public function receiveResponseHeader($curl, $header)
{
static $normalize = array("\r", "\n");
$length = strlen($header);
$header = str_replace($normalize, '', $header);
if (strpos($header, 'HTTP/') === 0) {
$startLine = explode(' ', $header, 3);
$code = $startLine[1];
$status = isset($startLine[2]) ? $startLine[2] : '';
// Only download the body of the response to the specified response
// body when a successful response is received.
if ($code >= 200 && $code < 300) {
$body = $this->request->getResponseBody();
} else {
$body = EntityBody::factory();
}
$response = new Response($code, null, $body);
$response->setStatus($code, $status);
$this->request->startResponse($response);
$this->request->dispatch('request.receive.status_line', array(
'request' => $this,
'line' => $header,
'status_code' => $code,
'reason_phrase' => $status
));
} elseif ($pos = strpos($header, ':')) {
$this->request->getResponse()->addHeader(
trim(substr($header, 0, $pos)),
trim(substr($header, $pos + 1))
);
}
return $length;
} | [
"public",
"function",
"receiveResponseHeader",
"(",
"$",
"curl",
",",
"$",
"header",
")",
"{",
"static",
"$",
"normalize",
"=",
"array",
"(",
"\"\\r\"",
",",
"\"\\n\"",
")",
";",
"$",
"length",
"=",
"strlen",
"(",
"$",
"header",
")",
";",
"$",
"header",
"=",
"str_replace",
"(",
"$",
"normalize",
",",
"''",
",",
"$",
"header",
")",
";",
"if",
"(",
"strpos",
"(",
"$",
"header",
",",
"'HTTP/'",
")",
"===",
"0",
")",
"{",
"$",
"startLine",
"=",
"explode",
"(",
"' '",
",",
"$",
"header",
",",
"3",
")",
";",
"$",
"code",
"=",
"$",
"startLine",
"[",
"1",
"]",
";",
"$",
"status",
"=",
"isset",
"(",
"$",
"startLine",
"[",
"2",
"]",
")",
"?",
"$",
"startLine",
"[",
"2",
"]",
":",
"''",
";",
"// Only download the body of the response to the specified response",
"// body when a successful response is received.",
"if",
"(",
"$",
"code",
">=",
"200",
"&&",
"$",
"code",
"<",
"300",
")",
"{",
"$",
"body",
"=",
"$",
"this",
"->",
"request",
"->",
"getResponseBody",
"(",
")",
";",
"}",
"else",
"{",
"$",
"body",
"=",
"EntityBody",
"::",
"factory",
"(",
")",
";",
"}",
"$",
"response",
"=",
"new",
"Response",
"(",
"$",
"code",
",",
"null",
",",
"$",
"body",
")",
";",
"$",
"response",
"->",
"setStatus",
"(",
"$",
"code",
",",
"$",
"status",
")",
";",
"$",
"this",
"->",
"request",
"->",
"startResponse",
"(",
"$",
"response",
")",
";",
"$",
"this",
"->",
"request",
"->",
"dispatch",
"(",
"'request.receive.status_line'",
",",
"array",
"(",
"'request'",
"=>",
"$",
"this",
",",
"'line'",
"=>",
"$",
"header",
",",
"'status_code'",
"=>",
"$",
"code",
",",
"'reason_phrase'",
"=>",
"$",
"status",
")",
")",
";",
"}",
"elseif",
"(",
"$",
"pos",
"=",
"strpos",
"(",
"$",
"header",
",",
"':'",
")",
")",
"{",
"$",
"this",
"->",
"request",
"->",
"getResponse",
"(",
")",
"->",
"addHeader",
"(",
"trim",
"(",
"substr",
"(",
"$",
"header",
",",
"0",
",",
"$",
"pos",
")",
")",
",",
"trim",
"(",
"substr",
"(",
"$",
"header",
",",
"$",
"pos",
"+",
"1",
")",
")",
")",
";",
"}",
"return",
"$",
"length",
";",
"}"
] | Receive a response header from curl
@param resource $curl Curl handle
@param string $header Received header
@return int | [
"Receive",
"a",
"response",
"header",
"from",
"curl"
] | train | https://github.com/xiewulong/yii2-fileupload/blob/3e75b17a4a18dd8466e3f57c63136de03470ca82/oss/libs/guzzle/http/Guzzle/Http/Curl/RequestMediator.php#L38-L77 |
surebert/surebert-framework | src/sb/SSH2/Client.php | Client.login | public function login($uname, $pass)
{
if (!@ssh2_auth_password($this->connection, $uname, $pass)){
throw new \Exception("Could not authenticate with credentials given.");
}
return true;
} | php | public function login($uname, $pass)
{
if (!@ssh2_auth_password($this->connection, $uname, $pass)){
throw new \Exception("Could not authenticate with credentials given.");
}
return true;
} | [
"public",
"function",
"login",
"(",
"$",
"uname",
",",
"$",
"pass",
")",
"{",
"if",
"(",
"!",
"@",
"ssh2_auth_password",
"(",
"$",
"this",
"->",
"connection",
",",
"$",
"uname",
",",
"$",
"pass",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not authenticate with credentials given.\"",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Login to a remote server with uname and pass based credentials
@param string $uname The user name to log in with
@param <type> $pass The password to login in with | [
"Login",
"to",
"a",
"remote",
"server",
"with",
"uname",
"and",
"pass",
"based",
"credentials"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/SSH2/Client.php#L49-L57 |
surebert/surebert-framework | src/sb/SSH2/Client.php | Client.loginWithKey | public function loginWithKey($uname, $public_key_file, $private_key_file, $pass='')
{
if (!ssh2_auth_pubkey_file($this->connection, $uname, $public_key_file, $private_key_file, $pass)) {
throw new \Exception("Could not authenticate with credentials given.");
}
return true;
} | php | public function loginWithKey($uname, $public_key_file, $private_key_file, $pass='')
{
if (!ssh2_auth_pubkey_file($this->connection, $uname, $public_key_file, $private_key_file, $pass)) {
throw new \Exception("Could not authenticate with credentials given.");
}
return true;
} | [
"public",
"function",
"loginWithKey",
"(",
"$",
"uname",
",",
"$",
"public_key_file",
",",
"$",
"private_key_file",
",",
"$",
"pass",
"=",
"''",
")",
"{",
"if",
"(",
"!",
"ssh2_auth_pubkey_file",
"(",
"$",
"this",
"->",
"connection",
",",
"$",
"uname",
",",
"$",
"public_key_file",
",",
"$",
"private_key_file",
",",
"$",
"pass",
")",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"\"Could not authenticate with credentials given.\"",
")",
";",
"}",
"return",
"true",
";",
"}"
] | Login with public key
@param string $uname The username to login in as
@param string $public_key_file The path to the public key file to use (id_rsa.pub), make sure it is readible by your script
@param string $private_key_file The private key file to use id (id_rsa), make sure it is readible by your script
@param string $pass The passphrase of the keyfile to use if one is required | [
"Login",
"with",
"public",
"key"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/SSH2/Client.php#L66-L73 |
surebert/surebert-framework | src/sb/SSH2/Client.php | Client.tunnel | public function tunnel($host, $port)
{
$stream = @ssh2_tunnel($this->connection, $command);
if(!$stream){
throw new \Exception('Cannot create tunnel to: '.$host.' on port'.$port);
}
return $stream;
} | php | public function tunnel($host, $port)
{
$stream = @ssh2_tunnel($this->connection, $command);
if(!$stream){
throw new \Exception('Cannot create tunnel to: '.$host.' on port'.$port);
}
return $stream;
} | [
"public",
"function",
"tunnel",
"(",
"$",
"host",
",",
"$",
"port",
")",
"{",
"$",
"stream",
"=",
"@",
"ssh2_tunnel",
"(",
"$",
"this",
"->",
"connection",
",",
"$",
"command",
")",
";",
"if",
"(",
"!",
"$",
"stream",
")",
"{",
"throw",
"new",
"\\",
"Exception",
"(",
"'Cannot create tunnel to: '",
".",
"$",
"host",
".",
"' on port'",
".",
"$",
"port",
")",
";",
"}",
"return",
"$",
"stream",
";",
"}"
] | Tunnels a connection
@param string $host The host to tunnel to via the ssh2 client
@param integer $port The port to tunnel to via the ssh2 client
@return stream The tunnel stream | [
"Tunnels",
"a",
"connection"
] | train | https://github.com/surebert/surebert-framework/blob/f2f32eb693bd39385ceb93355efb5b2a429f27ce/src/sb/SSH2/Client.php#L109-L117 |
colorium/web | src/Colorium/Web/Rest.php | Rest.set | public function set($name, $specs)
{
$this->logics[$name] = is_callable($specs)
? Logic::resolve($name, $specs)
: new Logic($name, $specs);
if($this->logics[$name]->http) {
$this->router->add($this->logics[$name]->http, $this->logics[$name]);
}
return $this;
} | php | public function set($name, $specs)
{
$this->logics[$name] = is_callable($specs)
? Logic::resolve($name, $specs)
: new Logic($name, $specs);
if($this->logics[$name]->http) {
$this->router->add($this->logics[$name]->http, $this->logics[$name]);
}
return $this;
} | [
"public",
"function",
"set",
"(",
"$",
"name",
",",
"$",
"specs",
")",
"{",
"$",
"this",
"->",
"logics",
"[",
"$",
"name",
"]",
"=",
"is_callable",
"(",
"$",
"specs",
")",
"?",
"Logic",
"::",
"resolve",
"(",
"$",
"name",
",",
"$",
"specs",
")",
":",
"new",
"Logic",
"(",
"$",
"name",
",",
"$",
"specs",
")",
";",
"if",
"(",
"$",
"this",
"->",
"logics",
"[",
"$",
"name",
"]",
"->",
"http",
")",
"{",
"$",
"this",
"->",
"router",
"->",
"add",
"(",
"$",
"this",
"->",
"logics",
"[",
"$",
"name",
"]",
"->",
"http",
",",
"$",
"this",
"->",
"logics",
"[",
"$",
"name",
"]",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Add logic
@param string $name
@param mixed $specs
@return $this | [
"Add",
"logic"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Rest.php#L47-L58 |
colorium/web | src/Colorium/Web/Rest.php | Rest.merge | public function merge(array $logics)
{
foreach($logics as $name => $specs) {
$this->set($name, $specs);
}
return $this;
} | php | public function merge(array $logics)
{
foreach($logics as $name => $specs) {
$this->set($name, $specs);
}
return $this;
} | [
"public",
"function",
"merge",
"(",
"array",
"$",
"logics",
")",
"{",
"foreach",
"(",
"$",
"logics",
"as",
"$",
"name",
"=>",
"$",
"specs",
")",
"{",
"$",
"this",
"->",
"set",
"(",
"$",
"name",
",",
"$",
"specs",
")",
";",
"}",
"return",
"$",
"this",
";",
"}"
] | Merge multiple logics
@param array $logics
@return $this | [
"Merge",
"multiple",
"logics"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Rest.php#L67-L74 |
colorium/web | src/Colorium/Web/Rest.php | Rest.context | public function context()
{
$this->logger->debug('kernel.context: generate Context instance');
$request = Request::globals();
$response = new Response;
return new Context($request, $response);
} | php | public function context()
{
$this->logger->debug('kernel.context: generate Context instance');
$request = Request::globals();
$response = new Response;
return new Context($request, $response);
} | [
"public",
"function",
"context",
"(",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.context: generate Context instance'",
")",
";",
"$",
"request",
"=",
"Request",
"::",
"globals",
"(",
")",
";",
"$",
"response",
"=",
"new",
"Response",
";",
"return",
"new",
"Context",
"(",
"$",
"request",
",",
"$",
"response",
")",
";",
"}"
] | Generate context
@return Context | [
"Generate",
"context"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Rest.php#L82-L89 |
colorium/web | src/Colorium/Web/Rest.php | Rest.before | protected function before(Context $context)
{
// set context forwarder
$context->forwarder = $context->forwarder ?: [$this, 'forward'];
return parent::before($context);
} | php | protected function before(Context $context)
{
// set context forwarder
$context->forwarder = $context->forwarder ?: [$this, 'forward'];
return parent::before($context);
} | [
"protected",
"function",
"before",
"(",
"Context",
"$",
"context",
")",
"{",
"// set context forwarder",
"$",
"context",
"->",
"forwarder",
"=",
"$",
"context",
"->",
"forwarder",
"?",
":",
"[",
"$",
"this",
",",
"'forward'",
"]",
";",
"return",
"parent",
"::",
"before",
"(",
"$",
"context",
")",
";",
"}"
] | Setup context before process
@param Context $context
@return Context | [
"Setup",
"context",
"before",
"process"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Rest.php#L98-L104 |
colorium/web | src/Colorium/Web/Rest.php | Rest.proceed | public function proceed(Context $context)
{
$context = $this->route($context);
$context = $this->resolve($context);
$context = $this->guard($context);
$context = $this->execute($context);
$context = $this->render($context);
return $context;
} | php | public function proceed(Context $context)
{
$context = $this->route($context);
$context = $this->resolve($context);
$context = $this->guard($context);
$context = $this->execute($context);
$context = $this->render($context);
return $context;
} | [
"public",
"function",
"proceed",
"(",
"Context",
"$",
"context",
")",
"{",
"$",
"context",
"=",
"$",
"this",
"->",
"route",
"(",
"$",
"context",
")",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"resolve",
"(",
"$",
"context",
")",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"guard",
"(",
"$",
"context",
")",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"execute",
"(",
"$",
"context",
")",
";",
"$",
"context",
"=",
"$",
"this",
"->",
"render",
"(",
"$",
"context",
")",
";",
"return",
"$",
"context",
";",
"}"
] | Handle context
@param Context $context
@return Context
@throws AccessDeniedException
@throws NotFoundException
@throws NotImplementedException | [
"Handle",
"context"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Rest.php#L117-L126 |
colorium/web | src/Colorium/Web/Rest.php | Rest.forward | public function forward(Context $context, $logic)
{
// resolve logic instance
if(!$logic instanceof Logic) {
// stored logic
if(is_string($logic) and isset($this->logics[$logic])) {
$logic = $this->logics[$logic];
}
// resolve callback
else {
$name = ($context->error instanceof HttpException) ? $context->error->getCode() : uniqid();
$logic = Logic::resolve($name, $logic);
}
}
$context->logic = $logic;
return $this->proceed($context);
} | php | public function forward(Context $context, $logic)
{
// resolve logic instance
if(!$logic instanceof Logic) {
// stored logic
if(is_string($logic) and isset($this->logics[$logic])) {
$logic = $this->logics[$logic];
}
// resolve callback
else {
$name = ($context->error instanceof HttpException) ? $context->error->getCode() : uniqid();
$logic = Logic::resolve($name, $logic);
}
}
$context->logic = $logic;
return $this->proceed($context);
} | [
"public",
"function",
"forward",
"(",
"Context",
"$",
"context",
",",
"$",
"logic",
")",
"{",
"// resolve logic instance",
"if",
"(",
"!",
"$",
"logic",
"instanceof",
"Logic",
")",
"{",
"// stored logic",
"if",
"(",
"is_string",
"(",
"$",
"logic",
")",
"and",
"isset",
"(",
"$",
"this",
"->",
"logics",
"[",
"$",
"logic",
"]",
")",
")",
"{",
"$",
"logic",
"=",
"$",
"this",
"->",
"logics",
"[",
"$",
"logic",
"]",
";",
"}",
"// resolve callback",
"else",
"{",
"$",
"name",
"=",
"(",
"$",
"context",
"->",
"error",
"instanceof",
"HttpException",
")",
"?",
"$",
"context",
"->",
"error",
"->",
"getCode",
"(",
")",
":",
"uniqid",
"(",
")",
";",
"$",
"logic",
"=",
"Logic",
"::",
"resolve",
"(",
"$",
"name",
",",
"$",
"logic",
")",
";",
"}",
"}",
"$",
"context",
"->",
"logic",
"=",
"$",
"logic",
";",
"return",
"$",
"this",
"->",
"proceed",
"(",
"$",
"context",
")",
";",
"}"
] | Forward to logic
@param Context $context
@param $logic
@return Context | [
"Forward",
"to",
"logic"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Rest.php#L136-L154 |
colorium/web | src/Colorium/Web/Rest.php | Rest.route | protected function route(Context $context)
{
$this->logger->debug('kernel.route: find route from http query');
// logic already specified
if($context->logic) {
$this->logger->debug('kernel.route: forward to #' . $context->logic->name . ', skip routing');
return $context;
}
// find route
$query = $context->request->method . ' ' . $context->request->uri->path;
$route = $this->router->find($query);
// 404
if(!$route) {
throw new NotFoundException('No route found for query ' . $query);
}
// update context
$context->route = $route;
$context->params = $route->params;
$context->logic = $route->resource;
$this->logger->debug('kernel.route: #' . $context->logic->name . ' found for query ' . $query);
return $context;
} | php | protected function route(Context $context)
{
$this->logger->debug('kernel.route: find route from http query');
// logic already specified
if($context->logic) {
$this->logger->debug('kernel.route: forward to #' . $context->logic->name . ', skip routing');
return $context;
}
// find route
$query = $context->request->method . ' ' . $context->request->uri->path;
$route = $this->router->find($query);
// 404
if(!$route) {
throw new NotFoundException('No route found for query ' . $query);
}
// update context
$context->route = $route;
$context->params = $route->params;
$context->logic = $route->resource;
$this->logger->debug('kernel.route: #' . $context->logic->name . ' found for query ' . $query);
return $context;
} | [
"protected",
"function",
"route",
"(",
"Context",
"$",
"context",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.route: find route from http query'",
")",
";",
"// logic already specified",
"if",
"(",
"$",
"context",
"->",
"logic",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.route: forward to #'",
".",
"$",
"context",
"->",
"logic",
"->",
"name",
".",
"', skip routing'",
")",
";",
"return",
"$",
"context",
";",
"}",
"// find route",
"$",
"query",
"=",
"$",
"context",
"->",
"request",
"->",
"method",
".",
"' '",
".",
"$",
"context",
"->",
"request",
"->",
"uri",
"->",
"path",
";",
"$",
"route",
"=",
"$",
"this",
"->",
"router",
"->",
"find",
"(",
"$",
"query",
")",
";",
"// 404",
"if",
"(",
"!",
"$",
"route",
")",
"{",
"throw",
"new",
"NotFoundException",
"(",
"'No route found for query '",
".",
"$",
"query",
")",
";",
"}",
"// update context",
"$",
"context",
"->",
"route",
"=",
"$",
"route",
";",
"$",
"context",
"->",
"params",
"=",
"$",
"route",
"->",
"params",
";",
"$",
"context",
"->",
"logic",
"=",
"$",
"route",
"->",
"resource",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.route: #'",
".",
"$",
"context",
"->",
"logic",
"->",
"name",
".",
"' found for query '",
".",
"$",
"query",
")",
";",
"return",
"$",
"context",
";",
"}"
] | Find route from context
@param Context $context
@return Context
@throws NotFoundException | [
"Find",
"route",
"from",
"context"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Rest.php#L165-L192 |
colorium/web | src/Colorium/Web/Rest.php | Rest.guard | protected function guard(Context $context)
{
$this->logger->debug('kernel.guard: check user rank');
// 401
if($context->logic->access and $context->logic->access > Auth::rank()) {
throw new AccessDeniedException('Access denied (#' . $context->logic->name . ': ' . $context->logic->access . ', user: ' . $context->logic->access . ')');
}
// set user
if(Auth::valid()) {
$context->user = Auth::user();
}
$this->logger->debug('kernel.guard: access granted (#' . $context->logic->name . ': ' . $context->logic->access . ', user: ' . $context->logic->access . ')');
return $context;
} | php | protected function guard(Context $context)
{
$this->logger->debug('kernel.guard: check user rank');
// 401
if($context->logic->access and $context->logic->access > Auth::rank()) {
throw new AccessDeniedException('Access denied (#' . $context->logic->name . ': ' . $context->logic->access . ', user: ' . $context->logic->access . ')');
}
// set user
if(Auth::valid()) {
$context->user = Auth::user();
}
$this->logger->debug('kernel.guard: access granted (#' . $context->logic->name . ': ' . $context->logic->access . ', user: ' . $context->logic->access . ')');
return $context;
} | [
"protected",
"function",
"guard",
"(",
"Context",
"$",
"context",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.guard: check user rank'",
")",
";",
"// 401",
"if",
"(",
"$",
"context",
"->",
"logic",
"->",
"access",
"and",
"$",
"context",
"->",
"logic",
"->",
"access",
">",
"Auth",
"::",
"rank",
"(",
")",
")",
"{",
"throw",
"new",
"AccessDeniedException",
"(",
"'Access denied (#'",
".",
"$",
"context",
"->",
"logic",
"->",
"name",
".",
"': '",
".",
"$",
"context",
"->",
"logic",
"->",
"access",
".",
"', user: '",
".",
"$",
"context",
"->",
"logic",
"->",
"access",
".",
"')'",
")",
";",
"}",
"// set user",
"if",
"(",
"Auth",
"::",
"valid",
"(",
")",
")",
"{",
"$",
"context",
"->",
"user",
"=",
"Auth",
"::",
"user",
"(",
")",
";",
"}",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.guard: access granted (#'",
".",
"$",
"context",
"->",
"logic",
"->",
"name",
".",
"': '",
".",
"$",
"context",
"->",
"logic",
"->",
"access",
".",
"', user: '",
".",
"$",
"context",
"->",
"logic",
"->",
"access",
".",
"')'",
")",
";",
"return",
"$",
"context",
";",
"}"
] | Check access
@param Context $context
@return Context
@throws AccessDeniedException | [
"Check",
"access"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Rest.php#L232-L249 |
colorium/web | src/Colorium/Web/Rest.php | Rest.execute | protected function execute(Context $context)
{
$this->logger->debug('kernel.execute: execute logic');
// prepare params
$params = $context->params;
$params[] = $context;
// execute logic method
$result = call_user_func_array($context->logic->method, $params);
$this->logger->debug('kernel.execute: #' . $context->logic->name . ' executed');
// user response
if($result instanceof Response) {
$context->response = $result;
$this->logger->debug('kernel.execute: response provided as result of execution');
}
// raw response
else {
$context->response->raw = true;
$context->response->content = $result;
$this->logger->debug('kernel.execute: raw content provided as result of execution');
}
return $context;
} | php | protected function execute(Context $context)
{
$this->logger->debug('kernel.execute: execute logic');
// prepare params
$params = $context->params;
$params[] = $context;
// execute logic method
$result = call_user_func_array($context->logic->method, $params);
$this->logger->debug('kernel.execute: #' . $context->logic->name . ' executed');
// user response
if($result instanceof Response) {
$context->response = $result;
$this->logger->debug('kernel.execute: response provided as result of execution');
}
// raw response
else {
$context->response->raw = true;
$context->response->content = $result;
$this->logger->debug('kernel.execute: raw content provided as result of execution');
}
return $context;
} | [
"protected",
"function",
"execute",
"(",
"Context",
"$",
"context",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.execute: execute logic'",
")",
";",
"// prepare params",
"$",
"params",
"=",
"$",
"context",
"->",
"params",
";",
"$",
"params",
"[",
"]",
"=",
"$",
"context",
";",
"// execute logic method",
"$",
"result",
"=",
"call_user_func_array",
"(",
"$",
"context",
"->",
"logic",
"->",
"method",
",",
"$",
"params",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.execute: #'",
".",
"$",
"context",
"->",
"logic",
"->",
"name",
".",
"' executed'",
")",
";",
"// user response",
"if",
"(",
"$",
"result",
"instanceof",
"Response",
")",
"{",
"$",
"context",
"->",
"response",
"=",
"$",
"result",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.execute: response provided as result of execution'",
")",
";",
"}",
"// raw response",
"else",
"{",
"$",
"context",
"->",
"response",
"->",
"raw",
"=",
"true",
";",
"$",
"context",
"->",
"response",
"->",
"content",
"=",
"$",
"result",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.execute: raw content provided as result of execution'",
")",
";",
"}",
"return",
"$",
"context",
";",
"}"
] | Execute logic
@param Context $context
@return Context | [
"Execute",
"logic"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Rest.php#L258-L283 |
colorium/web | src/Colorium/Web/Rest.php | Rest.render | protected function render(Context $context)
{
$this->logger->debug('kernel.render: render Response');
// resolve output format
if($context->response->raw) {
// json
if($context->logic->render = 'json') {
$context->response = new Response\Json($context->response->content, $context->response->code, $context->response->headers);
$this->logger->debug('kernel.render: json response generated');
}
// remove auto-generated flag
$context->response->raw = false;
}
return $context;
} | php | protected function render(Context $context)
{
$this->logger->debug('kernel.render: render Response');
// resolve output format
if($context->response->raw) {
// json
if($context->logic->render = 'json') {
$context->response = new Response\Json($context->response->content, $context->response->code, $context->response->headers);
$this->logger->debug('kernel.render: json response generated');
}
// remove auto-generated flag
$context->response->raw = false;
}
return $context;
} | [
"protected",
"function",
"render",
"(",
"Context",
"$",
"context",
")",
"{",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.render: render Response'",
")",
";",
"// resolve output format",
"if",
"(",
"$",
"context",
"->",
"response",
"->",
"raw",
")",
"{",
"// json",
"if",
"(",
"$",
"context",
"->",
"logic",
"->",
"render",
"=",
"'json'",
")",
"{",
"$",
"context",
"->",
"response",
"=",
"new",
"Response",
"\\",
"Json",
"(",
"$",
"context",
"->",
"response",
"->",
"content",
",",
"$",
"context",
"->",
"response",
"->",
"code",
",",
"$",
"context",
"->",
"response",
"->",
"headers",
")",
";",
"$",
"this",
"->",
"logger",
"->",
"debug",
"(",
"'kernel.render: json response generated'",
")",
";",
"}",
"// remove auto-generated flag",
"$",
"context",
"->",
"response",
"->",
"raw",
"=",
"false",
";",
"}",
"return",
"$",
"context",
";",
"}"
] | Render response
@param Context $context
@return Context | [
"Render",
"response"
] | train | https://github.com/colorium/web/blob/2a767658b8737022939b0cc4505b5f652c1683d2/src/Colorium/Web/Rest.php#L292-L310 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.